Debian Codegraph @

texmf-dist/doc/latex/randexam/randexam.tex

raw
1 % -*- coding: utf-8 -*-
2
3 \documentclass[12pt,plain,math=most]{randexam}
4 \geometry{b5paper,margin=2cm}
5
6 \newcommand*{\myversion}{2024F}
7 \newcommand*{\mydate}{\the\year-\mylpad\month-\mylpad\day}
8 \newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi}
9
10 \cfoot{\small\thepage}
11
12 \setlength{\parindent}{0pt}
13 \setlength{\parskip}{7pt plus 1pt minus 1pt}
14
15 \usepackage{arevtext}
16 \usepackage{iftex}
17 \usepackage{ninecolors}
18 \usepackage{hyperref}
19 \hypersetup{
20 colorlinks=true,
21 urlcolor=blue3,
22 linkcolor=blue3,
23 }
24
25 \renewcommand\familydefault{\sfdefault}
26
27 \renewcommand{\baselinestretch}{1}
28 \renewcommand{\arraystretch}{1.3}
29
30 \usepackage{tabularx}
31 \usepackage{booktabs}
32
33 \usepackage{fancyvrb}
34
35 \DefineVerbatimEnvironment{code}{Verbatim}{%
36 formatcom=\color{blue!50!red}%
37 }
38
39 \usepackage{codehigh}
40
41 \NewDocumentCommand\mypkg{m}{\textcolor{blue3}{\mbox{#1}}}
42 \NewDocumentCommand\myopt{m}{\textcolor{yellow3}{\mbox{#1}}}
43 \NewDocumentCommand\mycmd{m}{\textcolor{green3}{\ttfamily\fakeverb{#1}}}
44 \NewDocumentCommand\myenv{m}{\textcolor{green3}{\ttfamily#1}}
45 \NewDocumentCommand\myfile{m}{\textcolor{purple3}{\mbox{#1}}}
46 \NewDocumentCommand\mykey{m}{\textcolor{brown3}{\mbox{\fakeverb{#1}}}}
47 \NewDocumentCommand\myval{m}{\textcolor{azure3}{\mbox{\fakeverb{#1}}}}
48 \NewDocumentCommand\myelem{m}{\textcolor{violet3}{\mbox{#1}}}
49
50 \begin{document}
51
52 {%
53 \renewcommand{\arraystretch}{2}%
54 \noindent\Large
55 \begin{tabularx}{\linewidth}{|X|}
56 \hline
57 Title: \ExamFillUlineText{\color{blue3}The randexam class for LaTeX}\\
58 Author: \ExamFillUlineText{Jianrui Lyu ([email protected])}\\
59 Version: \ExamFillUlineText{\myversion{} (\mydate)}\\
60 Code: \ExamFillUlineText{\url{https://github.com/lvjr/randexam}}\\
61 \hline
62 \end{tabularx}%
63 }
64
65 \tableofcontents
66
67 \section{Introduction}
68
69 Document class \mypkg{randexam} is an exam class for LaTeX.
70 With this class you could easily make an exam paper and its randomized variants.
71
72 The class mainly focuses on making math exam papers, but you could use it to make other exam papers.
73
74 The latest release of this package can be downloaded from here: \newline
75 \textcolor{blue}{\href{https://ctan.org/pkg/randexam}{\ttfamily https://ctan.org/pkg/randexam}}.
76
77 \section{Basic Structure}
78
79 \subsection{A randexam document}
80
81 The following is the basic structure of a \mypkg{randexam} document:
82 \begin{code}
83 \documentclass{randexam}
84 % document preamble
85 \begin{document}
86 % document body
87 \end{document}
88 \end{code}
89 In document preamble you could set some options for the exam.
90 In document body you write the contents of the exam.
91
92 \subsection{Document preamble}
93
94 In document preamble you normally set some class options with \mycmd{\SetExamOption} command.
95 For example, you could change the random seed with \myopt{seed} key. The seed is used only when
96 you add class option \myopt{random} (see Subsection \ref{opt:random}):
97 \begin{code}
98 \SetExamOption{
99 seed = 19061116, % random seed
100 }
101 \end{code}
102
103 \subsection{Document body}
104
105 In document body you normally write an \mycmd{\examtitle},
106 multiple \mycmd{\exampart}, and an optional \mycmd{\examdata} commands:
107
108 \begin{code}
109 \examtitle{name=Math Final Exam,date=2018-06-28,version=A}
110 ......
111 \exampart{Fill in the blanks.}[3 points for each.]
112 ......
113 \exampart{Select one answer.}[3 points for each.]
114 ......
115 \exampart{Work out math calculations.}[8 points for each.]
116 ......
117 \examdata{Some data may be used in the exam}
118 ......
119 \end{code}
120
121 \subsection{Exam title}
122
123 In calling \mycmd{\examtitle} command,
124 you need to provide some basic informations of the exam:
125
126 \begin{code}
127 \examtitle{name=Math Final Exam,date=2018-06-28,version=A}
128 \end{code}
129
130 If the \mykey{date} key is missing, it has the default value \myval{\today}.
131 When class option \myopt{random} is passed, the value of \mykey{version} key
132 will be modified from \myval{A} to \myval{B}.
133
134 \subsection{Exam parts}
135
136 The questions in an exam could be separated into several parts:
137
138 \begin{code}
139 \exampart{Fill in the blanks.}[3 points for each.]
140 ......
141 \exampart{Select one answer.}[3 points for each.]
142 ......
143 \exampart{Work out math calculations.}[8 points for each.]
144 ......
145 \end{code}
146
147 \subsection{Exam data}
148
149 At the end of the exam, you could add some appendix data with \mycmd{\examdata} command:
150
151 \begin{code}
152 \examdata{Some data may be used in the exam}
153 ......
154 \end{code}
155
156 You must put appendix data after \mycmd{\examdata} command,
157 or the exam variants will be incorrect.
158
159 \section{Types of questions}
160
161 \subsection{True-or-false questions}
162
163 \begin{code}
164 \exampart{True-or-false questions}[3 points for each.]
165
166 \begin{question}
167 The first true-or-false question. \tickout{T}
168 \end{question}
169
170 \begin{question}
171 The second true-or-false question. \tickout{F}
172 \end{question}
173 \end{code}
174
175 \begin{question}
176 The first true-or-false question. \tickout{T}
177 \end{question}
178
179 \begin{question}
180 The second true-or-false question. \tickout{F}
181 \end{question}
182
183 With \mycmd{\tickout{T}} and \mycmd{\tickout{F}}, you get \textcolor{blue}{\textsf{T}}
184 and \textcolor{blue}{\textsf{F}}; with \mycmd{\tickout{t}} and \mycmd{\tickout{f}},
185 you get \textcolor{blue}{$\checkmark$} and \textcolor{blue}{\large$\times$}.
186
187 You must put answers inside \mycmd{\tickout} command,
188 so as to make \mypkg{randexam} hide them in generating blank exam papers.
189
190 \subsection{Fill-in-the-blank questions}
191
192 \begin{code}
193 \exampart{Fill in the blanks.}[3 points for each.]
194
195 \begin{question}
196 The first fill-in-the-blank question \fillout{answer}.
197 \end{question}
198
199 \begin{question}
200 The second fill-in-the-blank question \fillout{answer}.
201 \end{question}
202 \end{code}
203
204 \begin{question}
205 The first fill-in-the-blank question \fillout{answer}.
206 \end{question}
207
208 \begin{question}
209 The second fill-in-the-blank question \fillout{answer}.
210 \end{question}
211
212 With \mycmd{\fillout} command, the underline will fill the whole line;
213 with \mycmd{\fillin} command, the underline will be minimal.
214
215 You must put answers inside \mycmd{\fillout} or \mycmd{\fillin} command,
216 so as to make \mypkg{randexam} hide them in generating blank exam papers.
217
218 \subsection{Multiple-choice questions}
219
220 \begin{code}
221 \exampart{Select one answer.}[3 points for each.]
222
223 \begin{question}
224 The first multiple-choice questions \pickout{A}.
225 \begin{abcd}
226 \item First
227 \item Second
228 \item Third
229 \item Fourth
230 \end{abcd}
231 \end{question}
232
233 \begin{question}
234 The second multiple-choice questions \pickout{C}.
235 \begin{abcd}
236 \item First choice
237 \item Second choice
238 \item Third choice
239 \item Fourth choice
240 \end{abcd}
241 \end{question}
242 \end{code}
243
244 \begin{question}
245 The first multiple-choice questions \pickout{A}.
246 \begin{abcd}
247 \item First
248 \item Second
249 \item Third
250 \item Fourth
251 \end{abcd}
252 \end{question}
253
254 \begin{question}
255 The second multiple-choice questions \pickout{C}.
256 \begin{abcd}
257 \item First choice
258 \item Second choice
259 \item Third choice
260 \item Fourth choice
261 \end{abcd}
262 \end{question}
263
264 With \mycmd{\pickout} command, the answer will be printed on the right edge of the line;
265 with \mycmd{\pickin} command, the answer will be printed on current position.
266
267 You must put answers inside \mycmd{\pickout} or \mycmd{\pickin} command,
268 so as to make \mypkg{randexam} hide them in generating blank exam papers.
269
270 The four choices of multiple-choice questions could be typeset with \myenv{abcd} environment.
271 And \myenv{abcd} environment will put them in one, two, or four rows
272 according to the lengths of the choices.
273
274 \subsection{Subjective questions}
275
276 For subjective questions, you could put answers inside \myenv{solution} environment.
277
278 \begin{code}
279 \exampart{Work out math calculations.}[8 points for each.]
280
281 \begin{question}
282 The first math calculation question.
283 \end{question}
284
285 \begin{solution}
286 Answer to the first question.
287 \end{solution}
288
289 \begin{question}
290 The second math calculation question.
291 \end{question}
292
293 \begin{solution}
294 Answer to the second question.
295 \end{solution}
296 \end{code}
297
298 \begin{question}
299 The first math calculation question.
300 \end{question}
301
302 \begin{solution}
303 Answer to the first question.
304 \end{solution}
305
306 \begin{question}
307 The second math calculation question.
308 \end{question}
309
310 \begin{solution}
311 Answer to the second question.
312 \end{solution}
313
314 \subsection{Other questions}
315
316 You can write other types of questions. For example:
317
318 \begin{code}
319 \exampart{Some question type}[4 points for each.]
320
321 \begin{question}
322 First question text. \answer{Answer text.}
323 \end{question}
324
325 \begin{question}
326 Second question text. \answer{Answer text.}
327 \end{question}
328 \end{code}
329
330 \begin{question}
331 First question text. \answer{Answer text.}
332 \end{question}
333
334 \begin{question}
335 Second question text. \answer{Answer text.}
336 \end{question}
337
338 You must put answer text inside \mycmd{\answer} command,
339 so as to make \mypkg{randexam} hide them in generating blank exam papers.
340
341 \section{Other components}
342
343 \subsection{Grade tables}
344
345 Normally you need a grade table after exam title.
346 You can get it by using \mycmd{\gradetable} command.
347
348 \begin{code}
349 \gradetable[total=6,strut=2em]
350 \end{code}
351
352 \vspace{-1.5em}\gradetable[total=6,strut=2em]
353
354 The meanings of keys in the \verb!\gradetable! command are:
355 \begin{description}
356 \item[total] total number of parts in this exam.
357 \item[strut] strut height of the score row; its default value is \verb!2.5em!.
358 \end{description}
359
360 \subsection{Answer tables}
361
362 Before true-or-false, fill-in-the-blank, or multiple-choice questions,
363 you may use \mycmd{\answertable} to generate a blank answer table:
364
365 \begin{code}
366 \answertable[total=6,column=3,strut=3em]
367 \end{code}
368
369 \answertable[total=6,column=3,strut=3em]
370
371 The meanings of keys in the \verb!\answertable! command are:
372 \begin{description}
373 \item[total] total number of questions in this exam part.
374 \item[column] number of questions in each row.
375 \item[strut] strut height of the answer rows; its default value is \verb!1em!.
376 \item[notice] notice text before the answer table.
377 \end{description}
378
379 \subsection{Vertical space}
380
381 You could leave some vertical space after a \myenv{question} or \myenv{solution} environment.
382 At this time \mypkg{randexam} class supports the following commands for adding vertical space:\par
383
384 \renewcommand{\arraystretch}{1.3}%
385 \begin{tabularx}{\linewidth}{l<{\qquad}X}
386 \hline
387 \texttt{\string\smallskip} & Add small vertical space\\
388 \hline
389 \texttt{\string\medskip} & Add medium vertical space\\
390 \hline
391 \texttt{\string\bigskip} & Add big vertical space\\
392 \hline
393 \texttt{\string\vfill} & Fill vertical space available\\
394 \hline
395 \end{tabularx}\par
396
397 Of course, you could use multiple commands in the above tables.
398
399 In the exam body, you could use \mycmd{\newpage} to make a page break,
400 but you should \underline{NOT} use other page breaking commands, such as \mycmd{\clearpage},
401 or the exam variants may be wrong.
402
403 \section{Writing questions}
404
405 \subsection{points key}
406
407 The \myenv{question} environment accepts a \mykey{points} key:
408
409 \begin{code}
410 \begin{question}[points=4]
411 This is a question.
412 \end{question}
413 \end{code}
414
415 \begin{question}[points=4]
416 This is a question.
417 \end{question}
418
419 \section{Writing solutions}
420
421 \subsection{Solution name}
422
423 If you would like to change the name of \myenv{solution} environment,
424 you could modify the translation of \mykey{solution-Solution} keyword
425 (see Subsection \ref{subsect:translation}).
426 The following example changes it from "Solution" to "Proof":
427
428 \begin{code}
429 \SetExamTranslation{solution-Solution=Proof}
430 \begin{solution}
431 This is the proof.
432 \end{solution}
433 \end{code}
434
435 \begingroup
436 \SetExamTranslation{solution-Solution=Proof}
437 \begin{solution}
438 This is the proof.
439 \end{solution}
440 \endgroup
441
442 \subsection{Points command}
443
444 Inside \myenv{solution} environment, you could use \mycmd{\points} to give points for each step.
445 For example:
446
447 \begin{code}
448 \begin{solution}
449 $1+1=2$ \points{4}
450 $2+2=4$ \points{8}
451 \end{solution}
452 \end{code}
453
454 \begin{solution}
455 $1+1=2$ \points{4}
456 $2+2=4$ \points{8}
457 \end{solution}
458
459 You can also use \mycmd{\points} command inside displayed formulas or \myenv{align*} environment.
460 And the point text will be printed at the right edge of the line.
461
462 \subsection{Alignment commands}
463
464 With class option \myopt{freealign}, \mypkg{randexam} loads \mypkg{freealign} package,
465 and \mypkg{freealign} package provides several commands for aligning math formulas in different lines.
466
467 Here is the first example:
468
469 \begin{code}
470 We have $(a+b)^2 \? = (a+b)(a+b)$ \\
471 \+$= a^2+2ab+b^2$ \points{2}
472 \end{code}
473
474 \hrule
475 We have $(a+b)^2 \? = (a+b)(a+b)$ \\
476 \+$= a^2+2ab+b^2$ \points{2}
477 \hrule\vskip0.5em
478
479 The \mycmd{\?} command \underline{inside} the first formula saves current horizontal position,
480 and the \mycmd{\+} command \underline{before} the second formula jumps to previously saved position.
481
482 Here is another example:
483
484 \begin{code}
485 We have \? $(a+b)^2 = (a+b)(a+b)$ \\
486 \< $= a^2+2ab+b^2$ \points{2}
487 \end{code}
488
489 \hrule
490 We have \? $(a+b)^2 = (a+b)(a+b)$ \\
491 \< $= a^2+2ab+b^2$ \points{2}
492 \hrule\vskip0.5em
493
494 The \mycmd{\?} command \underline{before} the first formula saves current horizontal position,
495 and the \mycmd{\<} command \underline{before} the second formula jumps to the left
496 of previously saved position by the width of $=$.
497
498 Because \mypkg{freealign} package uses \mypkg{zref} package to save positions,
499 you need two compilations to get correct results.
500
501 \section{Class options}
502
503 All options provided by \mypkg{randexam} class are listed in the following table:
504
505 \begin{tabularx}{\linewidth}{@{}lX@{}}
506 \toprule
507 \myopt{noanswer} & hide all answers in the exam paper \\
508 \myopt{random} & shuffle questions in each part \\
509 \myopt{seed} & the random seed used by \myopt{random} option \\
510 \midrule
511 \myopt{plain} & set page style \myval{plain} \\
512 \myopt{a3paper} & typeset a two-column paper of A3 size \\
513 \myopt{a3input} & input a paper of A4 size and change it to A3 size \\
514 \midrule
515 \myopt{mathdesign} & use \mypkg{mathdesign} utopia font \\
516 \myopt{freealign} & load \mypkg{freealign} package \\
517 \myopt{medmath} & load \mypkg{medmath} package \\
518 \myopt{moremath} & define more math commands \\
519 \myopt{math=many} & $\Leftrightarrow$ \myopt{mathdesign,freealign} \\
520 \myopt{math=most} & $\Leftrightarrow$ \myopt{mathdesign,freealign,medmath} \\
521 \myopt{math=all} & $\Leftrightarrow$ \myopt{mathdesign,freealign,medmath,moremath} \\
522 \midrule
523 \myopt{language} & set language and use corresponding translations \\
524 %\myopt{chinese} & select Chinese language and load \mypkg{ctex} package \\
525 \bottomrule
526 \end{tabularx}
527
528 Some of the options could also be modified with \mycmd{\SetExamOption}:
529 \myopt{noanswer}, \myopt{random}, and \myopt{seed}.
530
531 \subsection{Blank exam papers}
532
533 Assume \myfile{exam-a-answer.tex} is an exam paper with answers.
534 You can easily get a blank exam paper with answers removed,
535 by creating an \myfile{exam-a-blank.tex} file with the following lines:
536
537 \begin{code}
538 \PassOptionsToClass{noanswer}{randexam}
539 \input{exam-a-answer}
540 \end{code}
541
542 That is to say, when adding \myopt{noanswer} option to \mypkg{randexam} class,
543 The answers will be hidden in the compiled exam paper.
544
545 \subsection{Randomized variants}\label{opt:random}
546
547 Assume \myfile{exam-a-answer.tex} is an exam paper.
548 You could get a randomized variant with all questions in the same part shuffled,
549 by creating an \myfile{exam-b-answer.tex} file with the following lines:
550
551 \begin{code}
552 \PassOptionsToClass{random}{randexam}
553 \input{exam-a-answer}
554 \end{code}
555
556 That is to say, when adding \myopt{random} option to \mypkg{randexam} class,
557 The questions in the same part will be shuffled in the compiled exam paper.
558 Furthermore, four choices in an \myenv{abcd} environment will be shuffled too.
559
560 \subsection{Two column exam papers}
561
562 Assume \myfile{exam-a-blank.tex} is the TeX file of an exam paper of A4 size.
563 You could get an exam paper of A3 size,
564 by creating a new TeX file with the following lines:
565
566 \begin{code}
567 \PassOptionsToClass{a3paper}{randexam}
568 \input{exam-a-blank}
569 \end{code}
570
571 That is to say, when adding \myopt{a3paper} option to \mypkg{randexam} class,
572 The result paper will be a two column document in A3 size.
573
574 Assume \myfile{exam-a-blank.pdf} is the PDF file of an exam paper of A4 size.
575 You could get an exam paper of A3 size,
576 by creating a new TeX file with the following lines:
577 \begin{code}
578
579 \documentclass[a3input]{randexam}
580 \begin{document}
581 \includepdf[pages=-,nup=2x1]{exam-a-blank}
582 \end{document}
583 \end{code}
584
585 That is to say, you can make an exam of A3 size from an exam of A4 size,
586 even if you have only the PDF file.
587
588 \section{Customizations}
589
590 \subsection{Translations of keywords}\label{subsect:translation}
591
592 With \mycmd{\DeclareExamTranslation} you can define the translaitons of the keywords
593 in a \mypkg{randexam} paper.
594
595 \begin{code}
596 \DeclareExamTranslation{english}{
597 answertable-Answer = Answer
598 ,answertable-Number = Number
599 ,examdata-Appendix = Appendix
600 ,exampart-Part = Part
601 ,examtitle-Name = Name
602 ,examtitle-Solutions = Solutions
603 ,gradetable-Evaluator = Evaluator
604 ,gradetable-Part = Part
605 ,gradetable-Score = Score
606 ,gradetable-Total = Total
607 ,headfoot-Name = Name
608 ,headfoot-of = of
609 ,headfoot-Page = Page
610 ,headfoot-Solutions = Solutions
611 ,headfoot-Version = Version
612 ,points-point = point
613 ,points-points = points
614 ,question-Question = Question
615 ,solution-Solution = Solution
616 }
617 \end{code}
618
619 At this time only English and Chinese keywords are defined.
620 You could translate them for another language and enable them
621 with \mycmd{\SelectExamTranslation} command:
622
623 \begin{code}
624 \DeclareExamTranslation{somelang}{
625 question-Question = Questioooooon
626 ,solution-Solution = Soooooolution
627 }
628 \SelectExamTranslation{somelang}
629 \end{code}
630 \DeclareExamTranslation{somelang}{
631 question-Question = Questioooooon
632 ,solution-Solution = Soooooolution
633 }
634 \SelectExamTranslation{somelang}
635
636 After this, you could load current translation of some keywords with \mycmd{\UseExamTranslation} command:
637
638 \begin{code}
639 \UseExamTranslation{question-Question}
640 \UseExamTranslation{solution-Solution}
641 \end{code}
642 \hrule
643 \UseExamTranslation{question-Question}
644 \UseExamTranslation{solution-Solution}
645 \vspace{0.5em}
646 \hrule
647 \vspace{0.5em}
648
649 \SelectExamTranslation{english}
650
651 This command is useful in defining new templates for the exam (see Subsection \ref{subsect:template}).
652
653 \subsection{Checking current language}
654
655 There are commands \mycmd{\IfExamLanguageEqT},
656 \mycmd{\IfExamLanguageEqF}, and \mycmd{\IfExamLanguageEqTF},
657 with which you can execute code based on current language.
658
659 \subsection{Checking boolean flags}
660
661 There are several commands for creating, setting, or checking boolean flags:
662
663 \begin{tabularx}{\linewidth}{@{}lX@{}}
664 \toprule
665 \mycmd{\NewExamBool} & create a new boolean flag \\
666 \mycmd{\SetExamBoolTrue} & set the boolean flag to true \\
667 \mycmd{\SetExamBoolFalse} & set the boolean flag to false \\
668 \mycmd{\IfExamBoolT} & run code if the boolean flag is true \\
669 \mycmd{\IfExamBoolF} & run code if the boolean flag is false \\
670 \mycmd{\IfExamBoolTF} & run true-state code or false-state code \\
671 \bottomrule
672 \end{tabularx}
673
674 \subsection{Saving and reading key values}
675
676 With \mycmd{\SetExamValue} and \mycmd{\UseExamValue} you could save and read
677 the value of a key, respectively.
678
679 \begin{code}
680 \SetExamValue{somemodule}{somekey=SomeValue}
681 \UseExamValue{somemodule}{somekey}
682 \end{code}
683 \hrule
684 \SetExamValue{somemodule}{somekey=SomeValue}
685 \UseExamValue{somemodule}{somekey}
686 \vspace{0.5em}
687 \hrule
688 \vspace{0.5em}
689
690 The class also provides commands for conditional typesetting.
691
692 \begin{tabularx}{\linewidth}{@{}XXX@{}}
693 \toprule
694 \mycmd{\IfExamValueExistT} & \mycmd{\IfExamValueExistF} & \mycmd{\IfExamValueExistTF} \\
695 \mycmd{\IfExamValueEmptyT} & \mycmd{\IfExamValueEmptyF} & \mycmd{\IfExamValueEmptyTF} \\
696 \bottomrule
697 \end{tabularx}
698
699 \begin{code}
700 \IfExamValueExistTF{somemodule}{somekey}{True}{False}
701 \end{code}
702 \hrule
703 \IfExamValueExistTF{somemodule}{somekey}{True}{False}
704 \vspace{0.5em}
705 \hrule
706 \vspace{0.5em}
707
708 Furthermore, you may change typeset command of some counter with \mycmd{\SetExamValue}
709 and the counter is typeset with \mycmd{\TheExamCounter} command when needed.
710
711 \setcounter{exampart}{4}
712 \begin{code}
713 \SetExamValue{exampart}{number=\Roman}
714 \SetExamValue{question}{number=\arabic}
715 Part \TheExamCounter{exampart},
716 Question \TheExamCounter{question}
717 \end{code}
718 \hrule
719 \SetExamValue{exampart}{number=\Roman}
720 \SetExamValue{question}{number=\arabic}
721 Part \TheExamCounter{exampart},
722 Question \TheExamCounter{question}
723 \vspace{0.5em}
724 \hrule
725 \vspace{0.5em}
726
727 These commands are useful in defining new templates
728 for the exam (see Subsection \ref{subsect:template}).
729
730 \subsection{Templates of elements}\label{subsect:template}
731
732 With \mycmd{\DeclareExamTemplate} you could define a new template for some exam element,
733 which could be set as default template with \mycmd{\SelectExamTemplate}.
734 And with \mycmd{\UseExamTemplate} you could use the default template of the element.
735
736 To customize \myelem{examtitle} element for your school,
737 you can write the following code in document preamble:
738 \begin{code}
739 \DeclareExamTemplate{examtitle}{myschool}{%
740 \fbox{%
741 \UseExamValue{examtitle}{name}\quad%
742 \UseExamValue{examtitle}{date}%
743 }%
744 }%
745 \SelectExamTemplate{examtitle}{myschool}
746 \end{code}
747 \DeclareExamTemplate{examtitle}{myschool}{%
748 \fbox{%
749 \UseExamValue{examtitle}{name}\quad%
750 \UseExamValue{examtitle}{date}%
751 }%
752 }%
753 \SelectExamTemplate{examtitle}{myschool}
754
755 Then the \mycmd{\examtitle} command in document body will produce different result:
756 \begin{code}
757 \examtitle{name=Final Exam in My School,date=\today}
758 \end{code}
759 \vspace{-1em}
760 \examtitle{name=Final Exam in My School,date=\today}
761
762 Normally \mycmd{\examtitle} will call \mycmd{\UseExamTemplate{examtitle}{default}}.
763
764 All elements that could be customized with templates in an exam paper
765 are listed in the following table:
766
767 \begingroup\renewcommand\arraystretch{1.5}\noindent
768 \begin{tabularx}{\linewidth}{ll}
769 \hline
770 \myelem{examtitle} & for customizing \mycmd{\examtitle} command \\
771 \hline
772 \myelem{exampart} & for customizing \mycmd{\exampart} command \\
773 \hline
774 \myelem{examdata} & for customizing \mycmd{\examdata} command \\
775 \hline
776 \myelem{gradetable} & for customizing \mycmd{\gradetable} command \\
777 \hline
778 \myelem{answertable} & for customizing \mycmd{\answertable} command \\
779 \hline
780 \myelem{questionbegin} & for customizing \myenv{question} environment \\
781 \hline
782 \myelem{questionend} & for customizing \myenv{question} environment \\
783 \hline
784 \myelem{solutionbegin} & for customizing \myenv{solution} environment \\
785 \hline
786 \myelem{solutionend} & for customizing \myenv{solution} environment \\
787 \hline
788 \end{tabularx}\par
789 \endgroup
790
791 \subsection{Filling space with contents}
792
793 In defining exam templates, we may need the following filling commands.
794
795 \begin{tabularx}{\linewidth}{@{}lX@{}}
796 \toprule
797 \mycmd{\ExamFillCdot} & fill space with centered dots \\
798 \mycmd{\ExamFillUline} & fill space with an underline \\
799 \mycmd{\ExamFillUlineText} & fill space with underlined text \\
800 \mycmd{\ExamFillUlinePhantom} & fill space with underlined phantom text \\
801 \bottomrule
802 \end{tabularx}
803
804 \begin{code}
805 Hello\ExamFillCdot World\par
806 Hello\ExamFillUline World\par
807 Hello\ExamFillUlineText{Text}World\par
808 Hello\ExamFillUlinePhantom{\Huge Text}World\par
809 \end{code}
810
811 Hello\ExamFillCdot World\par
812 Hello\ExamFillUline World\par
813 Hello\ExamFillUlineText{Text}World\par
814 Hello\ExamFillUlinePhantom{\Huge Text}World\par
815
816 \subsection{Headers and Footers}
817
818 To customize headers and footers of the exam paper,
819 we could modify the following \myval{fancy} templates.
820
821 \begin{code}
822 \DeclareExamTemplate{headleft}{fancy}{
823 \UseExamValue{examtitle}{name}
824 }
825 \DeclareExamTemplate{headcenter}{fancy}{}
826 \DeclareExamTemplate{headright}{fancy}{
827 \IfExamBoolTF{answer}{
828 \UseExamTranslation{headfoot-Solutions}
829 }{
830 \UseExamTranslation{headfoot-Name}:\hspace{12em}
831 }
832 }
833 \DeclareExamTemplate{footleft}{fancy}{
834 \UseExamValue{examtitle}{date}
835 }
836 \DeclareExamTemplate{footcenter}{fancy}{
837 \UseExamTranslation{headfoot-Page} \thepage\space
838 \UseExamTranslation{headfoot-of} \zpageref{LastPage}
839 }
840 \DeclareExamTemplate{footright}{fancy}{
841 \UseExamTranslation{headfoot-Version}
842 \UseExamValue{examtitle}{version}
843 }
844 \end{code}
845
846 Actually, \mypkg{randexam} class uses \mypkg{fancyhdr} package
847 to customize headers and footers.
848
849 \subsection{Themes of exam papers}
850
851 With \mycmd{\DeclareExamTheme} command you can collect some templates into a theme,
852 which could be activated later with \mycmd{\SelectExamTheme} command.
853
854 \begin{code}
855 \DeclareExamTheme{mytheme}{
856 \SelectExamTemplate{examtitle}{mytheme}
857 \SelectExamTemplate{exampart}{mytheme}
858 \SelectExamTemplate{examdata}{mytheme}
859 }
860 ......
861 \SelectExamTheme{mytheme}
862 \end{code}
863
864 \end{document}