Debian Codegraph @

texmf-dist/doc/latex/exsheets/exsheets_en.tex

raw
1 % !arara: pdflatex
2 % !arara: biber
3 % arara: pdflatex
4 % arara: pdflatex
5 % arara: pdflatex
6 % --------------------------------------------------------------------------
7 % the EXSHEETS package
8 %
9 % Yet another package for the creation of exercise sheets
10 %
11 % --------------------------------------------------------------------------
12 % Clemens Niederberger
13 % Web: https://bitbucket.org/cgnieder/exsheets/
14 % E-Mail: [email protected]
15 % --------------------------------------------------------------------------
16 % Copyright 2011-2019 Clemens Niederberger
17 %
18 % This work may be distributed and/or modified under the
19 % conditions of the LaTeX Project Public License, either version 1.3
20 % of this license or (at your option) any later version.
21 % The latest version of this license is in
22 % http://www.latex-project.org/lppl.txt
23 % and version 1.3 or later is part of all distributions of LaTeX
24 % version 2005/12/01 or later.
25 %
26 % This work has the LPPL maintenance status `maintained'.
27 %
28 % The Current Maintainer of this work is Clemens Niederberger.
29 % --------------------------------------------------------------------------
30 % If you have any ideas, questions, suggestions or bugs to report, please
31 % feel free to contact me.
32 % --------------------------------------------------------------------------
33 \documentclass[load-preamble+]{cnltx-doc}
34
35 \usepackage{exsheets}
36 \usepackage{bookmark}
37
38 \setcnltx{
39 package = {exsheets} ,
40 authors = Clemens Niederberger ,
41 email = [email protected] ,
42 url = {http://www.mychemistry.eu/forums/forum/exsheets/} ,
43 title = the \ExSheets\ bundle ,
44 info = {%
45 the packages \ExSheets{} and \ExSheetslistings \\
46 \emph{or}\\
47 Yet another package for the creation of exercise sheets and exams.%
48 } ,
49 module-sep = {\,>>\,} ,
50 index-setup = { othercode=\footnotesize,level=\section} ,
51 abstract = {%
52 \ExSheets\ provides means to create exercises or questions and their
53 corresponding solutions. The questions can be divided into classes and
54 can be printed selectively. Meta-data to questions can be added and
55 recovered.
56 \par
57 The solutions may be printed where they are, can be collected and printed
58 at a later point in the document alltogether or section-wise or
59 selectively by \acs{id}.\par
60 \ExSheets\ provides a comprehensive interface for styling the headings of
61 questions and solutions.%
62 } ,
63 add-cmds = {
64 % exsheets:
65 addpoints,
66 blank,
67 C,
68 checkedchoicebox,choice,choicebox,
69 correct,
70 CurrentQuestionID,
71 DebugExSheets,
72 DeclareExSheetsHeadingContainer,
73 DeclareQuestionClass,DeclareQuestionProperty,
74 examspace,
75 exlabel,
76 ForEachQuestion,
77 GetQuestionClass,
78 GetQuestionProperty,
79 grade,
80 includequestions,iflastquestion,
81 IfQuestionPropertyF,IfQuestionPropertyT,IfQuestionPropertyTF,
82 IfQuestionSubtitleF,IfQuestionSubtitleT,IfQuestionSubtitleTF,
83 lastvariant,
84 NewQuSolPair,NewLstQuSolPair,
85 numberofquestions,
86 points,pointssum,
87 PrintIfIncludeActiveF,PrintIfIncludeActiveT,PrintIfIncludeActiveTF,
88 PrintQuestionClassF,PrintQuestionClassT,PrintQuestionClassTF,
89 printsolutions,
90 PrintSolutionsF,PrintSolutionsTF,PrintSolutionsT,
91 questionsincludedlast,QuestionNumber,RenewQuSolPair,
92 S,
93 SetQuestionProperties,
94 SetupExSheets,
95 SetVariations,
96 startnewitemline,
97 sumpoints,
98 totalpoints,
99 variant,vary,
100 % cntformats:
101 @cntfmts@parsed@pattern,
102 AddCounterPattern,
103 eSaveCounterPattern,
104 NewCounterPattern,
105 ReadCounterFrom,
106 ReadCounterPattern,ReadCounterPatternFrom,
107 SaveCounterPattern,
108 % tasks:
109 NewTasks,
110 settasks,
111 task
112 } ,
113 add-envs = {
114 question,
115 solution,
116 tasks
117 } ,
118 add-silent-cmds = {
119 acs,
120 bigstar,bottomrule,
121 citetitle,cs,color,
122 DeclareInstance,DeclareTemplateInterface,
123 endmdframed,endspacing,
124 keyis,
125 leftthumbsup,
126 mdframed,midrule,
127 rightarrow,rlap,
128 s,sample,setlength,
129 spacing,square,
130 tabcolsep,
131 textcite,
132 textcolor,
133 tmpa,tmpb,
134 toprule
135 }
136 }
137 \usepackage{exsheets-listings}
138
139 \microtypesetup{tracking=scshape}
140
141 \defbibheading{bibliography}[\bibname]{\section{#1}}
142
143 \usepackage[biblatex]{embrac}[2012/06/29]
144 \ChangeEmph{[}[,.02em]{]}[.055em,-.08em]
145 \ChangeEmph{(}[-.01em,.04em]{)}[.04em,-.05em]
146 \usepackage{booktabs,array,ragged2e}
147
148 \newpackagename\ExSheets{ExSheets}
149 \newpackagename\ExSheetslistings{ExSheets-listings}
150 \newpackagename\cntformats{cntformats}
151 \newpackagename\Tasks{tasks}
152
153 % ----------------------------------------------------------------------------
154 % other packages, bibliography, index
155 \usepackage{xcoffins,wasysym,enumitem,siunitx}
156
157 \usepackage[accsupp]{acro}
158 \DeclareAcronym{faq}{
159 short = faq ,
160 long = Frequently Asked Questions ,
161 format = \scshape ,
162 pdfstring = FAQ ,
163 accsupp = FAQ
164 }
165 \DeclareAcronym{id}{
166 short = id ,
167 long = Identifier ,
168 format = \scshape ,
169 pdfstring = ID ,
170 accsupp = ID
171 }
172 \DeclareAcronym{ctan}{
173 short = ctan ,
174 long = Comprehensive \TeX\ Archive Network ,
175 format = \scshape ,
176 pdfstring = CTAN ,
177 accsupp = CTAN
178 }
179
180 \usepackage{filecontents}
181
182 \usepackage{csquotes}
183
184 \addbibresource{biblatex-examples.bib}
185 \addbibresource{\jobname.bib}
186
187 \begin{filecontents*}{\jobname.bib}
188 @online{tex.sx:131546,
189 title = {Fixing lstlisting inside \ExSheets\ \code{question} and
190 \code{solution} environments} ,
191 author = {Stefano Bragaglia} ,
192 url = {http://tex.stackexchange.com/q/131546/5049} ,
193 date = {2013-09-04} ,
194 urldate = {2013-09-22}
195 }
196 @online{tex.sx:133907,
197 title = {How do I extract repeated functionality (\ExSheets\ workaround) to
198 make it reusable?} ,
199 author = {Forkrul Assail} ,
200 url = {http://tex.stackexchange.com/q/133907/5049} ,
201 date = {2013-09-18} ,
202 urldate = {2013-09-22}
203 }
204 \end{filecontents*}
205
206 % ----------------------------------------------------------------------------
207 % example definitions that have to be done in the preamble:
208 \DeclareQuestionClass{difficulty}{difficulties}
209 \DeclareQuestionProperty{notes}
210 \DeclareQuestionProperty{reference}
211 \DeclareQuestionProperty{topic}
212
213 \DeclareRelGrades{
214 1 = 1 ,
215 {1,5} = .9167 ,
216 2 = .8333 ,
217 {2,5} = .75 ,
218 3 = .6667 ,
219 {3,5} = .5833 ,
220 4 = .5
221 }
222
223 \usepackage{amssymb}
224 \let\checkmark\relax
225 \usepackage{dingbat}
226
227 \DeclareRobustCommand*\questionstar{\texorpdfstring{\bonusquestionsign}{* }}
228 \DeclareRobustCommand*\bonusquestionsign{\llap{$\bigstar$\space}}
229
230 \NewQuSolPair
231 {question*}[name=\questionstar Bonus Question]
232 {solution*}[name=\questionstar Solution]
233
234 \NewTasks[style=multiplechoice]{multiplechoice}[\choice](3)
235 \newcommand*\correct{\PrintSolutionsTF{\checkedchoicebox}{\choicebox}}
236
237 \usepackage{alphalph}
238 \NewPatternFormat{aa}{\alphalph}
239 \NewCounterPattern{testa}{ta}
240
241 % \AfterPackage!{hyperref}{%
242 % \pdfstringdefDisableCommands{\def\questionstar{* }}%
243 % }
244
245 \begin{document}
246
247 \part{Preliminaries}
248 \section{Licence and Requirements}
249 \license
250
251 \ExSheets\ loads and needs the following packages:
252 \needpackage{l3kernel}~\cite{bnd:l3kernel}, \pkg{xparse}, \pkg{xtemplate},
253 \pkg{l3keys2e}\footnote{all three \CTANurl{l3packages}}~\cite{bnd:l3packages},
254 \pkg{l3sort}\footnote{\CTANurl{l3experimental}}~\cite{bnd:l3experimental},
255 \needpackage{xcolor}~\cite{pkg:xcolor}, \needpackage{ulem}~\cite{pkg:ulem},
256 \needpackage{etoolbox}~\cite{pkg:etoolbox},
257 \needpackage{environ}~\cite{pkg:environ}, and
258 \pkg{pgfcore}\footnote{\CTANurl[graphics]{pgf}}~\cite{pkg:pgf}. \ExSheets\
259 calls \cs*{normalem} (from the \pkg{ulem} package).
260
261 \section{Motivation}
262 There are already quite a number of packages that allow the creation of
263 exercise sheets or written exams. Just to name the most common ones:
264 \pkg{eqexam}~\cite{pkg:eqexam}, \pkg{exam}~\cite{cls:exam},
265 \pkg{examdesign}~\cite{pkg:examdesign}, \pkg{exercise}~\cite{pkg:exercise},
266 \pkg{probsoln}~\cite{pkg:probsoln}, \pkg{answers}~\cite{pkg:answers},
267 \pkg{esami}~\cite{pkg:esami}, \pkg{exsol}~\cite{pkg:exsol} (and many
268 more \ldots).
269
270 One thing I missed in all packages that I've tried out\footnote{Well, probably
271 I didn't try hard enough\ldots} was a high flexibility in choosing which
272 questions and solutions should be printed, where which solutions should be
273 printed and so on, combined with the possibility to assign questions to
274 different classes so one could for example create two versions of an exam out
275 of the box. And --~I can't get enough~-- I also want to be able to use/design
276 different layouts for questions additional to a standard section-like format.
277 All these points are realized in \ExSheets.
278
279 Additionally one should be able to assign some sort of meta-data to questions
280 that of course should be easily reusable. How this can be done is explained
281 in section~\ref{sec:additional_info}.
282
283 Then there is --~at least in Germany~-- the habit of having lists of exercises
284 aligned in columns but counting from the left to the right instead from up to
285 down. That's why the \pkg{tasks} package was developed as part of \ExSheets{}
286 and was distributed as part of the bundle\changedversion{0.15}. Now it is a
287 package of its own but is loaded by \ExSheets{} automatically with the
288 necessary setup to make them work together nicely.
289
290 \ExSheets{} has no native support for multiple choice tests but that doesn't
291 mean that you can't create them with \ExSheets. It just means that they may
292 be a bit more work with \ExSheets{} than with other packages.
293
294 I had the idea for this package in 2008. Back then my \TeX{} skills were by
295 far not good enough to write it. Actually, even today I wouldn't have been
296 able to realize it without all the l3 packages like \pkg{l3kernel} and
297 \pkg{l3packages}. I actively began to develop \ExSheets\ in spring~2011 but
298 it wasn't until now (September~2012) that I consider it stable enough for
299 wider usage. At the time of writing (\today) there still are probably lots of
300 rough edges let alone bugs so I am very interested in all kinds of feedback.
301
302 \section{Additional Packages}
303 \ExSheets\ actually bundles two packages: \ExSheets, \ExSheetslistings.
304 \ExSheetslistings\ is an add-on to \ExSheets\ that offers some functionality
305 to use \pkg{listings} with \ExSheets. It is presented in
306 part~\ref{part:listings}.
307
308 \ExSheets\ used to bundle the \pkg{translations} package,
309 too\changedversion{0.9i}, but doesn't any more. You can find the
310 \pkg{translations} package as a package of it's own on the \ac{ctan}. It also
311 used to bundle the packages \pkg{tasks} and
312 \pkg{cntformats}\changedversion{0.15}. They're available now as packages of
313 their own as well.
314
315 % \section{Installation and Documentation}
316 % If you install \ExSheets\ manually beware to put the files
317 % \begin{itemize}
318 % \item[]\verb+exsheets_headings.def+
319 % \item[]\verb+exsheets_headings.cfg+
320 % \end{itemize}
321 % in the same directory as the \code{exsheets.sty} file\footnote{That is, a
322 % directory like \code{texmf-local/tex/latex/exsheets}, probably}.
323
324 % As with every manual package installation you need to make sure to put the
325 % files in a directory where \TeX\ can find them and afterwards update the
326 % database.
327
328 % \subsection{The \pkg*{tasks} Package}
329 % The \pkg{tasks} package~\cite{pkg:tasks} used to be part of the \ExSheets\
330 % bundle but is a package of its own now\changedversion{0.15} and released
331 % independently. You can find it as every other package on \ctan\ and in a full
332 % \TeX~Live or \hologo{MiKTeX} installation.
333
334 % \subsection{The \pkg*{cntformats} Package}
335 % The \pkg{cntformats} package~\cite{pkg:cntformats} used to be part of the
336 % \ExSheets\ bundle but is a package of its own now\changedversion{0.15} and
337 % released independently. You can find it as every other package on \ctan\ and
338 % in a full \TeX~Live or \hologo{MiKTeX} installation.
339
340 % \subsection{The \pkg*{translations} Package}
341 % The \pkg{translations} package~\cite{pkg:translations} used to be part of the
342 % \ExSheets\ bundle but is a package of its own now\changedversion{0.9i} and
343 % released independently. You can find it as every other package on \ctan\ and
344 % in a full \TeX~Live or \hologo{MiKTeX} installation.
345
346 % \section{News}
347 % \begin{description}
348 % \item[Version 0.7]
349 % With version~0.7 there has been a potentially breaking change: the
350 % \code{tasks} environment previously provided by \ExSheets\ has been
351 % extracted into a package of its own. This does not change any syntax
352 % \emph{per se}. However, if you used custom settings then you'll probably run
353 % into some problems. The options for the environment are no longer set with
354 % \cs{SetupExSheets} but with \cs{settasks}. Also the object that is used for
355 % the list template and its instances has been renamed from
356 % \code{exsheets-tasks} into \code{tasks}.
357
358 % What's probably even more of a breaking change is a syntax difference of the
359 % \code{tasks} environment: the optional argument for the number of columns is
360 % \emph{no longer set in braces but parentheses}. This is deliberate as it
361 % reflects the optional nature of the argument better and is consistent with
362 % the syntax of \cs{NewTasks}, too.
363
364 % Additionally the labels of the list got an additional offset of \code{1ex}
365 % from the items which will lead to slightly different output. In some cases
366 % this might actually lead to the most annoying changes. In this case say
367 % \cs{settasks}\Marg{label-offset=0pt} which should cure things again.
368
369 % I am very sorry for any inconvenience! I am trying to keep such changes as
370 % minimal and rare as possibly. However, it is not always avoidable when a
371 % package is new and still a child. It will grow up eventually.
372
373 % \ExSheets' other packages -- \href{tasks_en.pdf}{\Tasks} and
374 % \href{cntformats_en.pdf}{\cntformats} -- have gotten their own documentation
375 % which are essentially extracted from this very document you're reading now.
376 % This manual contains links to the respective manuals.
377
378 % \item[Version v0.9i]
379 % The \pkg{translations} package~\cite{pkg:translations} is no longer part of
380 % the \ExSheets\ bundle. From now on (July~17.\@ 2013) it is provided as a
381 % package of its own.
382
383 % \item[Version 0.10]
384 % The \ExSheets\ family has got a new member: \ExSheetslistings. This package
385 % proposes a solution for the problem of using verbatim material in \ExSheets'
386 % \env{question} and \env{solution} environments. It is presented in
387 % part~\ref{part:listings}.
388
389 % Question now can get subtitles that are printed if the heading instance
390 % supports it, see section~\ref{sec:subtitles-questions}.
391
392 % \item[Version 0.11]
393 % The commands \cs{GetQuestionClass} and \cs{PrintQuestionClassTF} have been
394 % added. They're explained in section~\ref{sec:retr-class-value}.
395
396 % \item[Version 0.12]
397 % The \option{auto-label} is now more flexible to allow the use together with
398 % packages \pkg{cleveref}.
399
400 % Question properties can now be retrieved before the question is printed (by
401 % writing the properties to the \code{aux} file).
402
403 % \item[Version 0.13]
404 % New options:
405 % \begin{itemize}
406 % \item \option{chapter-hook} allows to add code to the list of solutions
407 % when the solutions of a new chapter are printed, see
408 % section~\ref{sec:solutions-print-all}.
409 % \item \option{section-hook} allows to add code to the list of solutions
410 % when the solutions of a new section are printed, see
411 % section~\ref{sec:solutions-print-all}.
412 % \end{itemize}
413
414 % \item[Version 0.14]
415 % New options:
416 % \begin{itemize}
417 % \item New option \option{pre-hook} to the \env{question} environment that
418 % allows to add code directly before the question body, see
419 % section~\ref{sec:opti-ques-envir}.
420 % \item New option \option{post-hook} to the \env{question} environment that
421 % allows to add code directly after the question body, see
422 % section~\ref{sec:opti-ques-envir}.
423 % \item New command \cs{ExSheetsHeading}, see
424 % section~\ref{sec:using-an-exsheets}.
425 % \item New pre-defined question properties \code{question-body},
426 % \code{bonus-points} and \code{counter}, see
427 % section~\ref{sec:additional_info}.
428 % \item New option \option{save-to-aux}, see
429 % section~\ref{sec:additional_info}.
430 % \end{itemize}
431
432 % \item[Version 0.15]
433 % \begin{itemize}
434 % \item The packages \pkg{tasks} and \pkg{cntformats} have been removed from
435 % the bundle and are now distributed as packages of their own.
436 % \item The options \option*{load-headings} and \option*{load-tasks} have
437 % been dropped. The optional functionality they provided is now provided
438 % all the time.
439 % \item New command \cs{IfQuestionPropertyTF}, see
440 % section~\ref{sec:additional_info}.
441 % \end{itemize}
442
443 % \item[Version 0.16]
444 % New options/changes:
445 % \begin{itemize}
446 % \item The option \option{pre-hook} to the \env{question} environment now
447 % places its contents before the question heading, see
448 % section~\ref{sec:opti-ques-envir}.
449 % \item New option \option{pre-body-hook} to the \env{question} environment
450 % which adds its contents before the question body, see
451 % section~\ref{sec:opti-ques-envir}.
452 % \item New option \option{post-body-hook} to the \env{question} environment
453 % which adds its contents after the question body, see
454 % section~\ref{sec:opti-ques-envir}.
455 % \item New option \option{pre-hook} to the \env{solution} environment which
456 % adds code before a solution, see section~\ref{sec:opti-soli-envir}.
457 % \item New option \option{post-hook} to the \env{solution} environment which
458 % adds code after a solution, see section~\ref{sec:opti-soli-envir}.
459 % \item New option \option{pre-body-hook} to the \env{solution} environment
460 % which adds its contents before the solution body, see
461 % section~\ref{sec:opti-soli-envir}.
462 % \item New option \option{post-body-hook} to the \env{solution} environment
463 % which adds its contents after the solution body, see
464 % section~\ref{sec:opti-soli-envir}.
465 % \end{itemize}
466
467 % \item[Version 0.17]
468 % New option:
469 % \begin{itemize}
470 % \item The option \option{use-saved-counter-format} has been introduced. It
471 % is described in section~\ref{sec:solutions} on
472 % page~\pageref{option:use-saved-counter-format}.
473 % \end{itemize}
474
475 % \item[Version 0.18]
476 % The package now provides the correct Danish translations, thanks to Jonas
477 % Nyrup.
478
479 % The macro \cs{exsheetsprintsolution} is introduced, see
480 % page~\pageref{exsheetsprintsolution} for a little bit of an explanation.
481
482 % The option \option{no-skip-below} is introduced which disables the insertion
483 % of vertical space after the question and solution environments.
484
485 % \item[Version 0.20]
486 % New command \cs{DeclareExSheetsHeadingContainer}.
487
488 % \item[Version 0.21] Changes:
489 % \begin{itemize}
490 % \item \cs{includequestions} issues an error if it can't find the file to
491 % include.
492 % \item question properties are now also accessable when the corresponding
493 % question isn't printed.
494 % \item The variables \verbcode+\l_exsheets_counter_qu_int+ and \\
495 % \verbcode+\g_exsheets_question_identification_prop+ are now public.
496 % \end{itemize}
497 % \end{description}
498
499 \section{Thanks}
500 I need to thank the many users who gave me feedback so far! For one thing
501 this shows me that \ExSheets\ is useful to people. It also led to many
502 improvements like new features and countless bug fixes.
503
504 \part{The \ExSheets\ package}\label{part:exsheets}
505 \section{Setup}
506 The \ExSheets\ package has three different types of options, kind of. The
507 first type are the classic package options which are used when you load
508 \ExSheets:
509 \begin{sourcecode}
510 \usepackage[<options>]{exsheets}
511 \end{sourcecode}
512 All general options can be used this way and most of them are described in
513 section~\ref{sec:options}. All of those options also can be set via the setup
514 command:
515 \begin{commands}
516 \command{SetupExSheets}[\oarg{module}\marg{options}]
517 \end{commands}
518
519 The second type are options that belong to a specific environment or command.
520 These options are either used directly with the environment/command
521 \begin{sourcecode}
522 \begin{env}[<options>]
523 ...
524 \end{env}
525 \end{sourcecode}
526 or can also be set with the setup command. In the first case they only act
527 upon the environment or command where they're used. In the second case they
528 are set for all following uses of the corresponding environment or command.
529
530 The options of the second type all belong to \module*{modules}. Let's say you
531 want to specify some options of the \env{question} environment. You can then
532 say the following:
533 \begin{sourcecode}
534 \SetupExSheets[question]{option1,option2=value2}
535 % or:
536 \SetupExSheets{question/option1,question/option2=value2}
537 \end{sourcecode}
538 The \module*{module} an option belongs to is written in the left margin next
539 to the when the option is described.
540
541 The third type aren't options at all, actually. However, thanks to the great
542 \pkg{xtemplate} package you are able to define your own instances of some of
543 the objects used by \ExSheets. This is explained in a little more detail in
544 part~\ref{part:style} on page~\pageref{part:style}\,ff. This third type,
545 however, brings in a possible instability: the \pkg{xtemplate} package is in
546 an experimental and developing state. This means that the sytax of the
547 package may and possibly will change sometime in the future. I cannot foresee
548 what any consequences of that will be for \ExSheets.
549
550 \section{General Options}\label{sec:options}
551 The package \ExSheets\ has some options, namely the following ones:
552 \begin{options}
553 %% counter-format
554 \keyval{counter-format}{counter-format}\Default{qu.}
555 Formatting of the counter of the questions. This option takes a special
556 kind of string that is described in section~\ref{ssec:counter}.
557 \keyval{counter-within}{counter}\Default
558 Resets the \code{question} counter with every step of \meta{counter}.
559 %% auto-label
560 \keybool{auto-label}\Default{false}
561 If set to \code{true} \ExSheets\ will automatically place a
562 \cs*{label}\Marg{qu:\meta{id}} for each question. See
563 section~\ref{sec:auto-label-opti} for ways to customize this. It will
564 also create the question properties \code{ref} and \code{pageref}, see
565 section~\ref{sec:additional_info} for more on this.
566 %% headings
567 \keyval{headings}{instance}\Default{block}
568 Choose the style of the questions' and solutions' headings. There are two
569 predefined styles: \code{block} and \code{runin}.
570 %% headings-format
571 \keyval{headings-format}{code}\Default{\cs*{normalsize}\cs*{bfseries}}
572 This code is placed immediately before the headings of the questions and
573 solutions.
574 \keyval{subtitle-format}{code}\Default{\cs*{normalsize}\cs*{itshape}}
575 This code is placed immediately before the subtitle of the questions and
576 solutions. It only has an effect with a title instance that uses the
577 subtitle coffin, see section~\ref{sec:exsheets-headings}.
578 % skip-below
579 \keyval{skip-below}{dim}\Default{.5\cs*{baselineskip}}
580 \sinceversion{0.18}Sets the vertical space that is inserted after the
581 question and solution environments.
582 % no-skip-below
583 \keybool{no-skip-below}\Default{false}
584 \sinceversion{0.18}Disables the insertion of vertical space after the
585 question and solution environments.
586 %% totoc
587 \keybool{totoc}\Default{false}
588 This option adds the questions and solutions with their names and numbers
589 to the table of contents.
590 %% questions-totoc
591 \keybool{questions-totoc}\Default{false}
592 This option adds the questions with their names and numbers to the table
593 of contents.
594 %% solutions-totoc
595 \keybool{solutions-totoc}\Default{false}
596 This option adds the solutions with their names and numbers to the table
597 of contents.
598 %% toc-level
599 \keyval{toc-level}{toc level}\Default{subsection}
600 This option sets the level in which questions and solutions should appear
601 in the table of contents.
602 %% questions-toc-level
603 \keyval{questions-toc-level}{toc level}\Default{subsection}
604 This option sets the level in which questions should appear in the table
605 of contents.
606 %% solutions-toc-level
607 \keyval{solutions-toc-level}{toc level}\Default{subsection}
608 This option sets the level in which solutions should appear in the table
609 of contents.
610 %% use-ref
611 \keybool{use-ref}\Default{false}
612 enable referencing to sections and chapters in a way that the references
613 can be used with \cs{printsolutions}, see
614 section~\ref{sssec:print_specific_section} for details.
615 \end{options}
616 The \code{toc} options are demonstrated with section~\ref{sec:solutions:list}
617 and the solutions printed there being listed in the table of contents.
618
619
620 \section{Create Questions/Exercises and their Solutions}
621 Now, let's start with the most important part: the questions and (possibly)
622 their respective solutions.
623 \subsection{The \env*{question} Environment}\label{ssec:questions}
624 Questions are written inside the \env{question} environment:
625 \begin{environments}
626 \environment{question}[\oarg{options}\marg{points}]
627 The main environment: creates a new exercise/question. Both arguments are
628 optional!
629 \end{environments}
630 \begin{example}
631 \begin{question}
632 This is our very first very difficult to solve question!
633 \end{question}
634 \end{example}
635 As you can see a heading is automatically created and the question is
636 numbered. You can of course change both the numbering and the naming, but
637 more on that later.
638
639 The \env{question} environment takes an optional argument \marg{points} that
640 can be used to assign points to the question (as is common in written exams):
641 \begin{example}
642 \begin{question}{3}
643 This is our first difficult question that is worth 3 points!
644 \end{question}
645 \end{example}
646 These points are saved internally (see section~\ref{sec:points} for reasons
647 why) and are written to the right margin next to the question heading in the
648 default setting.
649
650 You can also assign bonus points by inserting \code{\meta{point}+\meta{bonus
651 points}} as argument.
652 \begin{example}
653 \begin{question}{1+1}
654 This question is worth 1 point and 1 bonus point.
655 \end{question}
656 \begin{question}{+3}
657 This question is a bonus question. It is worth 3 bonus points.
658 \end{question}
659 \end{example}
660
661 The points are counted and added to the total sum of points, see
662 section~\ref{sec:points} for details on this. \sinceversion{0.12}Should you
663 want that the points of a specific question \emph{should not be added} to the
664 total sum then precede it with a bang \code{!}:
665 \begin{example}
666 \begin{question}{!3}
667 This question's points won't be added to the total sum.
668 \end{question}
669 \end{example}
670 Beware that this also prevents bonus points. The points simply will be
671 written where the heading instance puts them.
672
673 \sinceversion{0.3}One additional thing: you might want to define custom
674 commands that should behave differently if they're inside or outside of the
675 \env{question} environment. In this case you can use these commands:
676 \begin{commands}
677 \expandable\command{IfInsideQuestionTF}[\marg{true code}\marg{false code}]
678 Check if inside of a question and either leave \meta{true code} or
679 \meta{false code} in the input stream.
680 \expandable\command{IfInsideQuestionT}[\marg{true code}]
681 Check if inside of a question and either leave \meta{true code} in the
682 input stream if true.
683 \expandable\command{IfInsideQuestionF}[\marg{false code}]
684 Check if inside of a question and either leave \meta{false code} in the
685 input stream if not.
686 \end{commands}
687
688 \subsection{Options to the \env*{question} Environment}\label{sec:opti-ques-envir}
689 The \env{question} environment takes one or more of the following options:
690 \begin{options}
691 \keychoice{type}{exam,exercise}\Module{question}\Default{exercise}
692 Determines the type of question and changes the default name of a question
693 from ``Exercise'' to ``Question''. These default names are language
694 dependent.\par
695 If you use \cs*{usepackage}\oarg{ngerman}\marg{babel}, for example, then
696 the names are ``Übung'' and ``Aufgabe''.
697 \keyval{name}{name}\Module{question}\Default
698 Sets a custom name. All predefined names are discarded.
699 \keyval{subtitle}{subtitle}\Module{question}\Default
700 Adds a subtitle \meta{subtitle} for the question that is used by headings
701 instances that make use of the subtitle coffin, see
702 section~\ref{sec:exsheets-headings}.
703 \keyval{skip-below}{dim}\Module{question}\Default{.5\cs*{baselineskip}}
704 \sinceversion{0.18}Sets the vertical space that is inserted after the
705 question environment.
706 \keybool{no-skip-below}\Module{question}\Default{false}
707 \sinceversion{0.18}Disables the insertion of vertical space after the
708 question environment.
709 \keybool{print}\Module{question}\Default{true}
710 Prints or hides the question.
711 \keyval{ID}{id}\Module{question}\Default
712 Assigns a custom \acs{id} to the question. See section~\ref{ssec:ids} for
713 further information.
714 \keyval{label}{label}\Module{question}\Default
715 Places a \cs*{label}\marg{label} for the question. This will overwrite
716 any label that is placed by the \option{auto-label} option.
717 \keyval{class}{class}\Module{question}\Default
718 Assigns a class \meta{class} to the question. See
719 section~\ref{sec:classes} for further information.
720 \keyval{topic}{topic}\Module{question}\Default
721 Assigns a topic \meta{topic} to the question. See
722 section~\ref{sec:topics} for further information.
723 \keybool{use}\Module{question}\Default{true}
724 Discards the question. Or not.
725 \keyval{pre-hook}{code}\Module{question}\Default
726 \changedversion{0.16}Adds \meta{code} directly before the question title.
727 \keyval{post-hook}{code}\Module{question}\Default
728 \changedversion{0.16}Adds \meta{code} directly after the question.
729 \keyval{pre-body-hook}{code}\Module{question}\Default
730 \sinceversion{0.16}Adds \meta{code} directly before the question body.
731 \keyval{post-body-hook}{code}\Module{question}\Default
732 \sinceversion{0.16}Adds \meta{code} directly after the question body.
733 \end{options}
734
735 \begin{example}
736 \begin{question}[type=exam]
737 This question has the type \keyis{type}{exam}. The default name has changed
738 from ``Exercise'' to ``Question''.
739 \end{question}
740 \begin{question}[name=Fancy name]
741 This question has a custom name.
742 \end{question}
743 \begin{question}[print=false]
744 This question is not printed.
745 \end{question}
746 \end{example}
747
748 The difference between \option{print} and \option{use} lies behind the scenes:
749 with \keyis{print}{false} the question is not printed, but it still gets an
750 individual \ac{id}, is numbered, and a possible solution is saved. This is
751 for example useful when you want to print a sample solution for an exam. With
752 \keyis{use}{false} it is fully discarded which means it is not accessible
753 through an \acs{id} and a possible solution will not be saved.
754
755 \subsection{Subtitles to Questions}\label{sec:subtitles-questions}
756 The \option{subtitle} option mentioned in section~\ref{sec:opti-ques-envir}
757 can be used to add a subtitle to a question. However, unless you choose a
758 suitable heading (see section~\ref{sec:exsheets-headings}) it won't be
759 printed. Currently there is \emph{one} heading instance that uses the
760 subtitles but it should be easy to create a custom heading using one of the
761 existing ones as a starter example. When creating such a heading you may want
762 to distinguish between the cases when a subtitle has been given and when no
763 subtitle is present. This can be done with the following commands:
764 \begin{commands}
765 \expandable\command{IfQuestionSubtitleTF}[\marg{true code}\marg{false code}]
766 Tests if the current question has a subtitle. Leaves either \meta{true
767 code} or \meta{false code} in the input stream.
768 \expandable\command{IfQuestionSubtitleT}[\marg{true code}]
769 Tests if the current question has a subtitle. Leaves \meta{true code} in
770 the input stream if it has.
771 \expandable\command{IfQuestionSubtitleF}[\marg{false code}]
772 Tests if the current question has a subtitle. Leaves \meta{false code} in
773 the input stream if it hasn't.
774 \end{commands}
775
776 A subtitle is also a property of a question in the sense of
777 section~\ref{sec:additional_info}. That means if a subtitle is given it can
778 be retrieved with \cs{GetQuestionProperty}.
779
780 As an example you could define your own heading instance that prints the
781 \acs{id} of a question and (if given) the subtitle:
782
783 \begin{sourcecode}
784 \DeclareInstance{exsheets-heading}{QE}{default}{
785 join = {
786 title[r,B]number[l,B](.333em,0pt) ;
787 title[r,B]subtitle[l,B](1em,0pt)
788 } ,
789 attach = {
790 main[l,vc]title[l,vc](0pt,0pt) ;
791 main[r,vc]points[l,vc](\marginparsep,0pt)
792 } ,
793 subtitle-post-code = {ID: \CurrentQuestionID} ,
794 number-post-code = {\IfQuestionSubtitleF{ID: \CurrentQuestionID}}
795 }
796 \end{sourcecode}
797
798 Please see section~\ref{sec:exsheets-headings} for more details on heading
799 instances.
800
801 \subsection{The \env*{solution} Environment}
802 If you want to save/print (more on the exact usage in
803 section~\ref{sec:solutions}) a solution you have to use the \env{solution}
804 environment \emph{after} the question it belongs to and \emph{before} the next
805 question.
806 \begin{environments}
807 \environment{solution}[\oarg{options}]
808 The main environment for adding solutions to exercises/questions.
809 \end{environments}
810 \begin{example}
811 \begin{question}[ID=first]\label{qu:question_with_solution}
812 This is our first question that gets a solution!
813 \end{question}
814 \begin{solution}
815 This is the solution to exercise~\ref{qu:question_with_solution}!
816 \end{solution}
817 \end{example}
818 You can see that in the default settings the solution is \emph{not} written to
819 the document. It has been saved, though, for possible later usage. We will
820 see the solution later!
821
822 \subsection{Options to the \env*{solution} Environment}\label{sec:opti-soli-envir}
823 The \env{solutions} environment also has options, namely these:
824 \begin{options}
825 \keyval{name}{name}\Module{solution}\Default
826 Sets a custom name.
827 \keybool{print}\Module{solution}\Default{false}
828 Prints or hides the solution.
829 \keyval{skip-below}{dim}\Module{solution}\Default{.5\cs*{baselineskip}}
830 \sinceversion{0.18}Sets the vertical space that is inserted after the
831 solution environment.
832 \keybool{no-skip-below}\Module{solution}\Default{false}
833 \sinceversion{0.18}Disables the insertion of vertical space after the
834 solution environment.
835 \keyval{pre-hook}{code}\Module{solution}\Default
836 \sinceversion{0.16}Adds \meta{code} directly before the solution title.
837 \keyval{post-hook}{code}\Module{solution}\Default
838 \sinceversion{0.16}Adds \meta{code} directly after the solution.
839 \keyval{pre-body-hook}{code}\Module{solution}\Default
840 \sinceversion{0.16}Adds \meta{code} directly before the solution body.
841 \keyval{post-body-hook}{code}\Module{solution}\Default
842 \sinceversion{0.16}Adds \meta{code} directly after the solution body.
843 \end{options}
844 Their meaning is the same as those for the \code{question} environment.
845 \begin{example}
846 \begin{question}{5}
847 The solution to this questions gets printed where it is.
848 \end{question}
849 \begin{solution}[print]
850 See? This solution gets printed where you have put it in the code of
851 your document.
852 \end{solution}
853 \begin{question}{2.5}
854 The solution to this questions gets printed where it is \emph{and}
855 has a fancy name. Have you noticed that you can assign partial
856 points?
857 \end{question}
858 \begin{solution}[print,name=Fancy name]
859 See? This solution gets printed where you have put it and has a fancy
860 name!
861 \end{solution}
862 \end{example}
863
864 \subsection{Setting the Counter}\label{ssec:counter}
865 The package option \option{counter-format} allows you to specify how the question
866 counter (a counter unsurprisingly name \code{question}) is formatted.
867
868 The input is an arbitrary string which means you can have anything as counter
869 number. However, the letter combinations \code{ch}, \code{se}, \code{qu} and
870 \code{tsk} are replaced with the counters for the chapter, section, question
871 or tasks (see the \Tasks\ package), respectively. While the last one is not
872 really useful in this case the others allow for a combined numbering. Each of
873 these letter combinations can have an optional argument that specifies the
874 format of the respective counter. \code{1}: \cs*{arabic}, \code{a}:
875 \cs*{alph}, \code{A}: \cs*{Alph}, \code{r}: \cs*{roman} and \code{R}:
876 \cs*{Roman}.
877 \begin{example}
878 \SetupExSheets{counter-format=Nr~se~(qu[a])}
879 \begin{question}
880 A question with a differently formatted number.
881 \end{question}
882 \end{example}
883 Since the strings associated with the counters are replaced one has to hide
884 them if they are actually wanted in the counter format. The easiest way would
885 to hide them in braces.
886 \begin{example}
887 \SetupExSheets{counter-format={section}\,se~{question}\,(qu[a])}
888 \begin{question}
889 A question with a yet differently formatted number.
890 \end{question}
891 \end{example}
892
893 \subsection{Language Settings}
894 The names of the questions and solutions are language dependent. If you use
895 \pkg{babel} or \pkg{polyglossia} \ExSheets\ will adapt to the document language.
896 \ExSheets\ has a number of translations but surely not all! If you miss a
897 language please drop me a line in an
898 email\footnote{\href{mailto:[email protected]}{[email protected]}}
899 containing the \pkg{babel} language name and the correct translations for
900 questions (possibly distinguishing between exercises and exam questions) and
901 solutions.
902
903 Until I implement it you can add something like this to your preamble (example
904 for Danish) and try if it works:
905 \begin{sourcecode}
906 \DeclareTranslation{Danish}{exsheets-exercise-name}{\O{}velse}
907 \DeclareTranslation{Danish}{exsheets-question-name}{Opgave}
908 \DeclareTranslation{Danish}{exsheets-solution-name}{Opl\o{}sning}
909 \end{sourcecode}
910 If this isn't working it means that the language you're using is unknown to
911 the \pkg{translations} package. In this case please notify me, too. You then
912 can still use the \option{name} options.
913
914 \section{Counting Points}\label{sec:points}
915 \subsection{The Commands}
916 You have seen in section~\ref{ssec:questions} that you can assign points to a
917 question. If you do so these points are printed into the
918 margin\footnote{Well, not necessarily. It depends on the heading style you
919 have chosen.} and are counted internally. But there are additional commands
920 to assign points or bonus points and a number of commands to retrieve the sum
921 of points and/or bonus points.
922 \begin{commands}
923 \command{addpoints}[\sarg\marg{num}]
924 This command can be used to add points assigned to subquestions.
925 \cs{addpoints} will print the points (with ``unit'') \emph{and} add them
926 to the sum of all points, \cs{addpoints}\sarg\ will only add them but print
927 nothing.
928 \command{points}[\sarg\marg{num}]
929 This command will only print the points (with ``unit'') but won't add them
930 to the sum of points.
931 \command{addbonus}[\sarg\marg{num}]
932 This command can be used to add bonus points assigned to subquestions.
933 \cs{addbonus} will print the points (with ``unit'') \emph{and} add them
934 to the sum of all bonus points, \cs{addbonus}\sarg\ will only add them but
935 print nothing.
936 \command{bonus}[\sarg\marg{num}]
937 This command will only print the bonus points (with ``unit'') but won't
938 add them to the sum of bonus points.
939 \command{pointssum}[\sarg]
940 Prints the sum of all points with or without (starred version) ``unit'':
941 \pointssum
942 \command{currentpointssum}[\sarg]
943 Prints the current sum of points with or without (starred version)
944 ``unit'': \currentpointssum
945 \command{bonussum}[\sarg]
946 Prints the sum of all bonus points with or without (starred version)
947 ``unit'': \bonussum
948 \command{currentbonussum}[\sarg]
949 Prints the current sum of bonus points with or without (starred version)
950 ``unit'': \currentbonussum
951 \command{totalpoints}[\sarg]
952 prints the sum of the points \emph{and} the sum of the bonus points with
953 ``unit'': \totalpoints\space The starred version prints the sum of the
954 points without ``unit'': \totalpoints*.
955 \end{commands}
956 The commands \cs{pointssum}, \cs{bonussum} and \cs{totalpoints} need at
957 least \emph{two} \LaTeX\ runs to get the sum right.
958
959 Suppose you have an exercise worth \points{4} which consists of four questions
960 listed with an \env{enumerate} environment that are all worth \points{1}
961 each. You have two possibilities to display and count them:
962 \begin{example}
963 % uses package `enumitem'
964 \begin{question}{4}
965 \begin{enumerate}[label=\alph*)]
966 \item blah (\points{1})
967 \item blah (\points{1})
968 \item blah (\points{1})
969 \item blah (\points{1})
970 \end{enumerate}
971 \end{question}
972 \begin{question}
973 \begin{enumerate}[label=\alph*)]
974 \item blah (\addpoints{1})
975 \item blah (\addpoints{1})
976 \item blah (\addpoints{1})
977 \item blah (\addpoints{1})
978 \end{enumerate}
979 \end{question}
980 \end{example}
981
982 \subsection{Options}
983 \begin{options}
984 \keyval{name}{name}\Module{points}\Default{P.}
985 Choose the ``unit'' for the points. If you like to differentiate between
986 a single point and more than one point you can give a plural ending
987 separated with a slash: \keyis{name}{point/s}. This sets also the name of
988 the bonus points.
989 \keyval{name-plural}{plural form of name}\Module{points}\Default
990 Instead of forming the plural form with an ending to the singular form
991 this option allows to set an extra word for it. This sets also the plural
992 form for the bonus points.
993 \keyval{bonus-name}{name}\Module{points}\Default{P.}
994 Choose the ``unit'' for the bonus points. If you like to differentiate
995 between a single point and more than one point you can give a plural
996 ending separated with a slash: \key{bonus-name}{point/s}.
997 \keyval{bonus-plural}{plural form of name}\Module{points}\Default
998 Instead of forming the plural form with an ending to the singular form
999 this option allows to set an extra word for it.
1000 \keybool{use-name}\Module{points}\Default{true}
1001 Don't display the name at all. Or do.
1002 \keyval{format}{code}\Module{points}\Default{\cs*{@firtsofone}}
1003 \sinceversion{0.9d}Format number plus name as a whole. Ideally
1004 \meta{code} would end with a command that takes an argument. Else
1005 number plus name will be braced.
1006 \keyval{number-format}{any code}\Module{points}\Default
1007 This option allows formatting of the number, \eg, italics:
1008 \keyis{number-format}{\cs*{textit}}.
1009 \keyval{bonus-format}{any code}\Module{points}\Default
1010 This option allows formatting of the number of the bonus points, \eg,
1011 italics: \keyis{bonus-format}{\cs*{textit}}.
1012 \keybool{parse}\Module{points}\Default{true}
1013 If set to \code{false} the points are not counted and the
1014 \cs{totalpoints}, \cs{pointssum} and \cs{bonussum} commands won't know
1015 their value.
1016 \keybool{separate-bonus}\Module{points}\Default{false}
1017 This option determines whether points and bonus points each get their own
1018 unit when they appear together (in the margin or with \cs{totalpoints}).
1019 \keyval{pre-bonus}{tokens}\Module{points}\Default{\cs*{space}(+}
1020 Code to be inserted before the bonus points when they follow normal
1021 points.
1022 \keyval{post-bonus}{tokens}\Module{points}\Default{)}
1023 Code to be inserted after the bonus points when they follow normal
1024 points.
1025 \end{options}
1026
1027 \begin{example}[add-sourcecode-options={literate=}]
1028 \SetupExSheets[points]{name=point/s,number-format=\color{red}}
1029 \begin{question}{1}
1030 This one's easy so only 1 point can be earned.
1031 \end{question}
1032 \begin{question}{7.5}
1033 But this one's hard! 7.5 points are in there for you!
1034 \end{question}
1035 \end{example}
1036
1037 \section{Printing Solutions}\label{sec:solutions}
1038 You have already seen that you can print solutions where they are using the
1039 \option{print} option. But \ExSheets\ offers you quite more
1040 possibilities.
1041
1042 In the next subsections the usage of the following command is discussed.
1043 \begin{commands}
1044 \command{printsolutions}[\oarg{setting}]
1045 Print solutions of questions/exercises.
1046 \end{commands}
1047
1048 Before we do that a hint: remember that you can set the option \option{print}
1049 globally:
1050 \begin{sourcecode}
1051 % in the preamble
1052 \SetupExSheets{solution/print=true}
1053 \end{sourcecode}
1054
1055 Now if you want to typeset some text depending on the option being true or not
1056 you can use the following commands:
1057 \begin{commands}
1058 \expandable\command{PrintSolutionsTF}[\marg{true code}\marg{false code}]
1059 Either leaves \meta{true code} or \meta{false code} in the input stream
1060 depending on wether solutions are printed or not, \ie, on the value of the
1061 solution's option \option{print}. Inside a \env{solution} environment
1062 this always prints \meta{true code}.
1063 \expandable\command{PrintSolutionsT}[\marg{true code}]
1064 Either leaves \meta{true code} or nothing in the input stream depending on
1065 wether solutions are printed or not, \ie, on the value of the solution's
1066 option \option{print}. Inside a \env{solution} environment this always
1067 prints \meta{true code}.
1068 \expandable\command{PrintSolutionsF}[\marg{false code}]
1069 Either leaves nothing or \meta{false code} in the input stream depending
1070 on wether solutions are printed or not, \ie, on the value of the
1071 solution's option \option{print}. Inside a \env{solution}environment this
1072 always prints nothing.
1073 \end{commands}
1074 They might come in handy if you want two versions of an exercise sheet, one
1075 with the exercises and one with the solutions, and you want to add different
1076 titles to these versions, for instance.
1077
1078 % When solutions are saved a lot of information is saved. One of them is the
1079 % current counter format. The following option determines wether the saved
1080 % counter format or the currently active one is used when \cs{printsolutions} is
1081 % called:
1082 % \begin{options}
1083 % \keybool{use-saved-counter-format}\Default{true}
1084 % \changedversion{0.21}When set to true the counter format of solutions
1085 % printed by \cs{printsolutions}\label{option:use-saved-counter-format} are
1086 % independent from the setting of \option{counter-format}. The saved format
1087 % is used instead.
1088 % \end{options}
1089
1090 \subsection{Print all}\label{sec:solutions-print-all}
1091 The first and easiest usage of \cs{printsolutions} is the following:
1092 \begin{sourcecode}
1093 \printsolutions
1094 \end{sourcecode}
1095 There is nothing more to say, really. It prints all solutions you have
1096 specified except those belonging to a question with option \keyis{use}{false}.
1097 Yes, there's one more point: \cs{printsolutions} only knows the solutions
1098 that have been set \emph{before} its usage! This is also true for every usage
1099 explained in the next sections.
1100
1101 \begin{example}
1102 \printsolutions
1103 \end{example}
1104
1105 Two options allow to add code to the list of solutions when used with
1106 \cs{printsolutions}\Oarg{all} (which is the same as using it without option):
1107
1108 \begin{options}
1109 \keyval{chapter-hook}{code}
1110 \sinceversion{0.13}Adds \meta{code} to the list of solutions every time
1111 solutions from a new chapter are printed (before the solutions of the
1112 corresponding chapter are printed).
1113 \keyval{section-hook}{code}
1114 \sinceversion{0.13}Adds \meta{code} to the list of solutions every time
1115 solutions from a new section are printed (before the solutions of the
1116 corresponding section are printed).
1117 \end{options}
1118
1119 \subsection{Print per chapter/section}
1120 \minisec{Current chapter/section}
1121 If you are not creating an exercise sheet or an exam but are writing a
1122 textbook you maybe want a section at the end of each chapter showing the
1123 solution to the exercises presented in that chapter. In this case use the
1124 command as follows:
1125 \begin{sourcecode}
1126 \printsolutions[section]
1127 % or
1128 \printsolutions[chapter]
1129 \end{sourcecode}
1130 Again, this is pretty much self-explaining. The solutions to the questions of
1131 the current chapter\footnote{Only if the document class you're using
1132 \emph{has} chapters, of course!} or section are printed.
1133 \begin{example}
1134 \begin{question}
1135 This is the first and only question in this section.
1136 \end{question}
1137 \begin{solution}
1138 This will be one of a few solutions printed by the following call of
1139 \cs{printsolutions}.
1140 \end{solution}
1141 And now:
1142 \printsolutions[section]
1143 \end{example}
1144
1145 \minisec{Specific chapter/section}\label{sssec:print_specific_section}
1146 You can also print only the solutions from chapters or sections other than the
1147 current ones. The syntax is fairly easy:
1148 \begin{example}
1149 \printsolutions[section={1-7,10}]
1150 % the same for chapters:
1151 % \printsolutions[chapter={1-7,10}]
1152 \end{example}
1153 Don't forget that \cs{printsolutions} cannot know the solutions from
1154 section~10 yet. It is just used to demonstrate the syntax. You can also use
1155 an open range, \eg, something like
1156 \begin{sourcecode}
1157 \printsolutions[section={-4,10-}]
1158 \end{sourcecode}
1159 This would print the solutions from sections~1--4 and from all sections with
1160 number 10\footnote{Or rather where \cs*{value}\Marg{section} is 10 or greater --
1161 the actual counter formatting is irrelevant.} and greater.
1162
1163 There is an obvious disadvantage: you have to know the section numbers! But
1164 there is a solution: use the package option \keyis{use-ref}{true}. Then you
1165 can do something like
1166 \begin{sourcecode}
1167 % in the preamble:
1168 \usepackage[use-ref]{exsheets}
1169 % somewhere in your code after \section{A really cool section title}:
1170 \label{sec:ReallyCool}
1171 % somewhere later in your code:
1172 \printsolutions[section={-\S{sec:ReallyCool}}]
1173 % which will print all solutions from questions up to and
1174 % including the really cool section
1175 \end{sourcecode}
1176 With the package option \keyis{use-ref}{true} each usage of \cs*{label} will
1177 create additional labels (one preceded with \code{exse:} and another one with
1178 \code{exch:}) which store the section number and the chapter number,
1179 respectively. These are used internally by two commands \cs{S} and \cs{C}
1180 which refer to the section number and the chapter number the label was created
1181 in. \emph{These commands are only available as arguments of}
1182 \cs{printsolutions}.
1183
1184 Since some packages like the well known \pkg{hyperref} for example redefine
1185 \cs*{label} \option{use-ref} won't work in together with it. In this case
1186 don't use \option{use-ref} and set \cs{exlabel}\marg{label} instead to
1187 remember the section/the chapter number. Its usage is just like \cs*{label}.
1188 So the safest way is as follows:
1189 \begin{sourcecode}
1190 % in the preamble:
1191 \usepackage{exsheets}
1192 % somewhere in your code after \section{A really cool section title}:
1193 \exlabel{sec:ReallyCool}
1194 % somewhere later in your code:
1195 \printsolutions[section={-\S{sec:ReallyCool}}]
1196 % which will print all solutions from questions up to and
1197 % including the really cool section
1198 \end{sourcecode}
1199 Please be aware that the labels must be processed in a previous \LaTeX\ run
1200 before \cs{S} and \cs{C} can pass them on to \cs{printsolutions}.
1201
1202 \subsection{Print by \acs{id}}\label{ssec:ids}
1203 Now comes the best part: you can also print selected solutions! Every
1204 question has an \acs{id}. To see which \acs{id} a question has you can call
1205 the following command:
1206 \begin{commands}
1207 % \command{DebugExSheets}[\Marg{\choices{true,false}}]
1208 % Enable or disable visual \ExSheets' debugging.
1209 \expandable\command{CurrentQuestionID}
1210 \sinceversion{0.4a}Expands to the current question \acs{id}.
1211 \end{commands}
1212 \begin{options}
1213 \keybool{debug}
1214 Enable or disable visual \ExSheets' debugging.
1215 \end{options}
1216 Let's create some more questions and take a look what this command does:
1217 \begin{example}
1218 \SetupExSheets{debug=true}
1219 \begin{question}[ID=nice!]
1220 A question with a nice \acs{id}!
1221 \end{question}
1222 \begin{solution}
1223 The solution to the question with the nice \acs{id}.
1224 \end{solution}
1225 \begin{question}{3.75}
1226 Yet another question. But this time with quarter points!
1227 \end{question}
1228 \begin{solution}
1229 Yet another solution.
1230 \end{solution}
1231 \end{example}
1232
1233 So now we can call some specific solutions:
1234 \begin{example}
1235 \printsolutions[byID={first,nice!,10,14}]
1236 \end{example}
1237 This makes use of the \pkg{l3sort} package which at the time of writing is
1238 still considered experimental. In case you wonder where solution~14 is:
1239 question~14 has no solution given.
1240
1241 If you don't want that the solutions are sorted automatically but appear in
1242 the order given you can use the option
1243 \begin{options}
1244 \keybool{sorted}\Module{solution}\Default{true}
1245 Sort solutions given by \acs{id} or don't.
1246 \end{options}
1247
1248 \section{Conditional Printing of Questions}\label{sec:cond-print-quest}
1249 \subsection{Using Classes}\label{sec:classes}
1250 For creating different variants of a written exam or different difficulty
1251 levels of an exercise sheet it comes in handy if one can assign certain
1252 classes to questions and then tell \ExSheets\ only to use one ore more
1253 specific classes.
1254 \begin{options}
1255 \keyval{use-classes}{list of classes}\Default
1256 When this option is used only the questions belonging to the specified
1257 classes are printed and have their solutions saved.
1258 \end{options}
1259 \begin{example}
1260 \SetupExSheets{use-classes={A,C}}
1261 \begin{question}[class=A]
1262 Belonging to class A.
1263 \end{question}
1264 \begin{question}[class=B]
1265 Belonging to class B.
1266 \end{question}
1267 \begin{question}[class=C]
1268 Belonging to class C!
1269 \end{question}
1270 \end{example}
1271 Questions of classes that are not used are fully discarded. \emph{This also
1272 means that questions that don't have a class assigned are discarded.}
1273
1274 \ExplSyntaxOn
1275 \bool_set_false:N \g__exsheets_use_classes_bool
1276 \ExplSyntaxOff
1277
1278 \subsection{Using Topics}\label{sec:topics}
1279 Similarly to classes one can assign topics to questions. The usage is
1280 practically identical, the semantic meaning is different.
1281 \begin{options}
1282 \keyval{use-topics}{list of topics}\Default
1283 When this option is used only the questions belonging to the specified
1284 topics are printed and have their solutions saved.
1285 \end{options}
1286 \begin{example}
1287 \SetupExSheets{use-topics={trigonometry}}
1288 \begin{question}[topic=trigonometry]
1289 A trigonometry question.
1290 \end{question}
1291 \begin{question}[topic=arithmetics]
1292 A arithmetics question
1293 \end{question}
1294 \end{example}
1295 Questions of topics that are not used are fully discarded. \emph{This also
1296 means that questions that don't have a topic assigned are discarded.}
1297
1298 If you set both \option{use-classes} and \option{use-topics} then only
1299 questions will be used that \emph{match both categories}.
1300
1301 Ideally one could assign more than one topic to a question but this is
1302 \emph{not} supported yet.
1303
1304 \ExplSyntaxOn
1305 \bool_set_false:N \g__exsheets_use_topics_bool
1306 \ExplSyntaxOff
1307
1308 \subsection{Own Dividing Concepts}
1309 Actually\sinceversion{0.8} both classes and topics are introduced into
1310 \ExSheets\ internally this way:
1311 \begin{sourcecode}
1312 \DeclareQuestionClass{class}{classes}
1313 \DeclareQuestionClass{topic}{topics}
1314 \end{sourcecode}
1315 which means you can do the same introducing your own dividing concepts.
1316 \begin{commands}
1317 \command{DeclareQuestionClass}[\marg{singular name}\marg{plural name}]
1318 Introduces a new dividing concept and defines both new options for the
1319 \env{question} environment and new global options.
1320 \end{commands}
1321
1322 For example you could decide you want to group your questions according to
1323 their difficulty. You could place the following line in your preamble:
1324 \begin{sourcecode}
1325 \DeclareQuestionClass{difficulty}{difficulties}
1326 \end{sourcecode}
1327 This would define an option \option*{use-difficulties} analogous to
1328 \option{use-classes} and \option{use-topics}. It would also define an option
1329 \option{difficulty} for the \env{question} environment. This means you could
1330 now do something like the following:
1331 \begin{example}
1332 \SetupExSheets{use-difficulties={easy,hard}}
1333 \begin{question}[difficulty=easy]
1334 An easy question.
1335 \end{question}
1336 \begin{question}[difficulty=medium]
1337 This one's a bit harder.
1338 \end{question}
1339 \begin{question}[difficulty=hard]
1340 Now let's see if you can solve this one.
1341 \end{question}
1342 \end{example}
1343
1344 \subsection{Retrieving the Class Value in a Question}\label{sec:retr-class-value}
1345 Sometimes it may be desirable to retrieve the value of a class defined by
1346 \cs{DeclareQuestionClass} that a question has in order to be able to print,
1347 say. This is possible with the following commands:
1348 \begin{commands}
1349 \expandable\command{GetQuestionClass}[\marg{class}]
1350 Prints the value of \meta{class} a question has. The command is
1351 expandable. If the class does not exist or the value is empty the command
1352 expands to nothing.
1353 \command{PrintQuestionClassTF}[\marg{class}\marg{true}\marg{false}]
1354 Test if a question has a non-empty value for class \meta{class} and either
1355 leaves \meta{true} or \meta{false} in the input stream. In the
1356 \meta{true} argument you can refer to the value with \code{\#1} where you
1357 want it printed.
1358 \command{PrintQuestionClassT}[\marg{class}\marg{true}]
1359 Like \cs{PrintQuestionClassTF} but only has the \meta{true} branch.
1360 \command{PrintQuestionClassF}[\marg{class}\marg{false}]
1361 Like \cs{PrintQuestionClassTF} but only has the \meta{false} branch.
1362 \end{commands}
1363
1364 \begin{example}
1365 \begin{question}[difficulty=hard]
1366 This question has the difficulty level
1367 ``\PrintQuestionClassTF{difficulty}{#1}{??}''.
1368 \end{question}
1369 \end{example}
1370
1371 \ExplSyntaxOn
1372 \bool_set_false:N \g__exsheets_use_difficulties_bool
1373 \ExplSyntaxOff
1374
1375 \subsection{Tagging Questions}
1376 There\sinceversion{0.20} is another way of dividing questions: you can assign
1377 tags to questions:
1378 \begin{sourcecode}
1379 \begin{question}[tags={foo,bar,baz}]
1380 ...
1381 \end{question}
1382 \end{sourcecode}
1383 You can then decide to print only questions with certain tags by using the
1384 following option:
1385 \begin{options}
1386 \keyval{use-tags}{csv list of tags to include}
1387 Select tags. When used only questions being tagged with at least one of
1388 the tags in \meta{csv list of tags to include} are printed.
1389 \end{options}
1390
1391 \section{Adding and Using Additional Information to
1392 Questions}\label{sec:additional_info}
1393 \subsection{Question Properties -- the Basics}
1394
1395 For managing lots of questions and corresponding solutions it can be very
1396 useful to be able to save and recover additional information to the questions.
1397 This is possible with the following commands. First the ones for saving:
1398 \begin{commands}
1399 \command{DeclareQuestionProperty}[\marg{name}]
1400 This command defines a question property \meta{name}. It can only be
1401 used in the document preamble.
1402 \command{SetQuestionProperties}[\Marg{\meta{name}=\meta{value},...}]
1403 Set the properties for a specific question. this command can only be used
1404 inside the \env{question} environment.
1405 \end{commands}
1406 Now the commands for recovering the properties:
1407 \begin{commands}
1408 \command{QuestionNumber}[\marg{id}]
1409 Recover the number of the question with the \acs{id} \meta{id}. The
1410 number is displayed according to the format set with
1411 \option{counter-format}.
1412 \expandable\command{GetQuestionProperty}[\marg{name}\marg{id}]
1413 Recover the property \meta{name} of the question with the \acs{id}
1414 \meta{id}. Of course the property must have been declared before. The
1415 command is expandable. Since\changedversion{0.12} the properties of a
1416 question are written to the \code{aux} file it is possible to retrieve
1417 them before the corresponding \env{question} environment has been used.
1418 \expandable\command{IfQuestionPropertyTF}[\marg{name}\marg{id}\marg{true}\marg{false}]
1419 A command\sinceversion{0.15} that returns \meta{true} if the question with
1420 the \acs{id} \meta{id} has the property \meta{name} and \meta{false}
1421 otherwise. The variants \cs{IfQuestionPropertyT} and
1422 \cs{IfQuestionPropertyF} also exist which only have the \meta{true} or the
1423 \meta{false} branch.
1424 \end{commands}
1425
1426 Let's say we have declared the properties \code{notes}, \code{reference} and
1427 \code{topic}. By default the property \code{points} is available and gets the
1428 value of the optional argument of the \code{question} environment.
1429
1430 We can now do the following:
1431 \begin{example}
1432 % uses `biblatex'
1433 \begin{question}[ID=center,topic=LaTeX]{3}
1434 Explain how you could center text in a \LaTeX\ document.
1435 \SetQuestionProperties{
1436 topic = \TeX/\LaTeX ,
1437 notes = {How to center text.},
1438 reference = {\textcite{companion}}}
1439 \end{question}
1440 \begin{solution}
1441 To center a short part of the text body one can use the \env*{center}
1442 environment (\points{1}). Inside an environment like \env*{table} one
1443 should use \cs*{centering} (\points{1}). For single lines there is also
1444 the \cs*{centerline} command (\points{1}).
1445 \end{solution}
1446 \begin{question}[ID=knuthbooks,topic=LaTeX]{2}
1447 Name two books by D.\,E.\,Knuth.
1448 \SetQuestionProperties{
1449 topic = \TeX/\LaTeX ,
1450 notes = {Books by Knuth.},
1451 reference = {\textcite{knuth:ct:a,knuth:ct:b,knuth:ct:c,knuth:ct:d,knuth:ct:e}}}
1452 \end{question}
1453 \begin{solution}
1454 For example two volumes from \citetitle{knuth:ct}:
1455 \citetitle{knuth:ct:a,knuth:ct:b,knuth:ct:c,knuth:ct:d,knuth:ct:e}. Each
1456 valid answer is worth \points{1}
1457 \end{solution}
1458 \end{example}
1459
1460 It is now possible to recover these values later:
1461 \begin{example}
1462 % uses `booktabs'
1463 \begin{center}
1464 \begin{tabular}{lll}
1465 \toprule
1466 Question & Property & \\
1467 \midrule
1468 \QuestionNumber{center}
1469 & Points & \GetQuestionProperty{points}{center} \\
1470 & Topic & \GetQuestionProperty{topic}{center} \\
1471 & References & \GetQuestionProperty{reference}{center} \\
1472 & Note & \GetQuestionProperty{notes}{center} \\
1473 \midrule
1474 \QuestionNumber{knuthbooks}
1475 & Points & \GetQuestionProperty{points}{knuthbooks} \\
1476 & Topic & \GetQuestionProperty{topic}{knuthbooks} \\
1477 & References & \GetQuestionProperty{reference}{knuthbooks} \\
1478 & Note & \GetQuestionProperty{notes}{knuthbooks} \\
1479 \bottomrule
1480 \end{tabular}
1481 \end{center}
1482 \end{example}
1483
1484 Please note that properties \emph{are not the same} as the dividing concepts
1485 explained in section~\ref{sec:cond-print-quest} although they may seem
1486 similar in meaning or even have the same name.
1487
1488 When properties are set they are also written to the \code{aux} file which
1489 means they can be retrieved \emph{before} the corresponding question. Of
1490 course this means that two compilation runs are necessary.
1491
1492 \subsection{Pre-defined Properties}
1493
1494 A few properties are already defined by \ExSheets:
1495 \begin{itemize}
1496 \item \code{counter}:\sinceversion{0.14} this property holds the actual
1497 question number formatted according to the formatting set with option
1498 \option{counter-format}.
1499 \item \code{subtitle}:\sinceversion{0.12} this property holds the subtitle
1500 of the question if given.
1501 \item \code{question-body}:\sinceversion{0.14} this property holds the body
1502 of the corresponding \env{question} environment. Unlike the other
1503 properties it is per default \emph{not} written to the \code{aux} file.
1504 \item \code{points}: this property holds the sum of points given to a
1505 question.
1506 \item \code{bonus-points}:\sinceversion{0.14} this property holds the sum of
1507 bonus points given to a question.
1508 \item \code{ref}:\sinceversion{0.7f} when the option \option{auto-label} is
1509 used this property is defined and expands to the corresponding \cs*{ref}.
1510 Also see section~\ref{sec:auto-label-opti}.
1511 \item \code{page-ref}:\sinceversion{0.7f} when the option
1512 \option{auto-label} is used this property is defined and expands to the
1513 corresponding \cs*{pageref}. Also see section~\ref{sec:auto-label-opti}.
1514 \end{itemize}
1515
1516 There is one option affecting the property \code{question-body}:
1517 \begin{options}
1518 \keybool{save-to-aux}\Module{question}\Default{false}
1519 When set to \code{true} the property \code{question-body} is also written
1520 to the \code{aux} file.
1521 \end{options}
1522
1523 \subsection{Advanced Usage}
1524
1525 There are additional commands\sinceversion{0.3} that might prove useful. They
1526 allow advanced usage of defined properties. Below an example is shown how
1527 they can be used to generate a grading table.
1528 \begin{commands}
1529 \command{ForEachQuestion}[\marg{code to be executed for each used question}]
1530 \changedversion{0.14}Inside the argument one can refer to the \ac{id} of a
1531 question with \code{\#1}. You can also refer to the number of the
1532 question with \code{\#2}. \emph{Number} means that if you \emph{use}
1533 seven questions then those questions have numbers~1 to~7.
1534 \expandable\command{numberofquestions}
1535 \changedversion{0.14} returns the complete number of used questions.
1536 \expandable\command{iflastquestion}[\marg{true code}\marg{false code}]
1537 Although this command is available in the whole document it is only useful
1538 inside \cs{ForEachQuestion}. It tells you if the end of the loop is
1539 reached or not.
1540 \end{commands}
1541
1542 One could use these commands to create a grading table, for instance:
1543 \begin{sourcecode}
1544 \begin{tabular}{|l|*{\numberofquestions}{c|}c|}\hline
1545 Question &
1546 \ForEachQuestion{\QuestionNumber{#1}\iflastquestion{}{&}} &
1547 Total \\ \hline
1548 Points &
1549 \ForEachQuestion{\GetQuestionProperty{points}{#1}\iflastquestion{}{&}} &
1550 \pointssum* \\ \hline
1551 Reached &
1552 \ForEachQuestion{\iflastquestion{}{&}} & \\ \hline
1553 \end{tabular}
1554 \end{sourcecode}
1555 For four questions the table now would look similar to
1556 figure~\ref{fig:grading-table}.
1557
1558 \begin{figure}[ht]
1559 \centering
1560 \begin{tabular}{|l|*{4}{c|}c|}\hline
1561 Question & 1. & 2. & 3. & 4. & Total \\ \hline
1562 Points & 3 & 5 & 10 & 8 & 26 \\ \hline
1563 Reached & & & & & \\ \hline
1564 \end{tabular}
1565 \caption{An example for a grading table. (Actually this is a fake. See the
1566 \code{grading-table.tex} file shipped with exsheets for the real use case.)}
1567 \label{fig:grading-table}
1568 \end{figure}
1569
1570
1571 \section{Variations of an Exam}
1572
1573 It is a quite common task\sinceversion{0.6} to design an exam in two different
1574 variants. This is of course possible with \ExSheets' classes (see
1575 section~\ref{sec:classes}). However, often not the whole question is to be
1576 different but only small details, the numbers in a maths exam, say. For this
1577 purpose \ExSheets\ provides the following commands:
1578 \begin{commands}
1579 \command{SetVariations}[\marg{num}]
1580 Set the number of different variants. This will determine how many
1581 arguments the command \cs{vary} will get. \meta{num} must at least be
1582 \code{2} and is initially set to \code{2}.
1583 \command{variant}[\marg{num}]
1584 Choose the active variant. The argument must be a number between \code{1}
1585 and the number set with \cs{SetVariations}. Initially set to \code{1}.
1586 \command{vary}[\marg{variant 1}\marg{variant 2}]
1587 This command is the one actually used in the document. It has a number of
1588 required arguments equal to the number set with \cs{SetVariations}. All
1589 of its arguments are discarded except the one specified with
1590 \cs{variant}.
1591 \command{lastvariant}
1592 \sinceversion{0.7b}Each time \cs{vary} is called it stores the value it
1593 chose in \cs{lastversion}. This might be convenient to use if one
1594 otherwise would have to repeatedly write the same \cs{vary}.
1595 \end{commands}
1596
1597 \begin{example}
1598 \SetVariations{6}%
1599 \variant{6}\vary{A}{B}{C}{D}{E}{F}
1600 (last variant: \lastvariant)
1601 \variant{1}\vary{A}{B}{C}{D}{E}{F}
1602 (last variant: \lastvariant)
1603 \variant{5}\vary{A}{B}{C}{D}{E}{F}
1604 (last variant: \lastvariant)
1605 \variant{2}\vary{A}{B}{C}{D}{E}{F}
1606 (last variant: \lastvariant)
1607 \variant{4}\vary{A}{B}{C}{D}{E}{F}
1608 (last variant: \lastvariant)
1609 \variant{3}\vary{A}{B}{C}{D}{E}{F}
1610 (last variant: \lastvariant)
1611 \end{example}
1612
1613 \section{A Grade Distribution}
1614 Probably this is a rather esoteric feature but it could proof useful in some
1615 cases. Suppose you are a German math teacher and want to grade exactly
1616 corresponding to the number of points relative to the sum of total points,
1617 regardless of how big that might be. You could do something like this to
1618 present your grading decisions for the exam:
1619 \begin{example}
1620 % preamble:
1621 % \DeclareRelGrades{
1622 % 1 = 1 ,
1623 % {1,5} = .9167 ,
1624 % 2 = .8333 ,
1625 % {2,5} = .75 ,
1626 % 3 = .6667 ,
1627 % {3,5} = .5833 ,
1628 % 4 = .5
1629 % }
1630 \small\setlength\tabcolsep{2pt}
1631 \begin{tabular}{r|*8c}
1632 Punkte
1633 & $\grade*{1}$ & $\le\grade*{1}$ & $\le\grade*{1,5}$ & $\le\grade*{2}$
1634 & $\le\grade*{2,5}$ & $\le\grade*{3}$ & $\le\grade*{3,5}$ & $<\grade*{4}$ \\
1635 Note
1636 & 1 & 1--2 & 2 & 2--3 & 3 & 3--4 & 4 & 5
1637 \end{tabular}
1638 \end{example}
1639
1640 These are the available commands and options:
1641 \begin{commands}
1642 \command{DeclareRelGrades}[\Marg{\meta{grade}=\meta{num},...}]
1643 This command is used to define grades and assign the percentage of total
1644 points to them.
1645 \command{grade}[\sarg\marg{grade}]
1646 Gives the number of points corresponding to a grade depending on the value
1647 of \cs{pointssum} with or without (starred version) ``unit''.
1648 \end{commands}
1649 \begin{options}
1650 \keyval{round}{num}\Module{grades}\Default{0}
1651 The number of decimals the points of a grade are rounded to. This doesn't
1652 apply to the maximum number of points if the rounded number would be
1653 bigger than the actual sum.
1654 \keybool{half}\Module{grades}\Default{false}
1655 If set to \code{true} points are rounded either to full or to half
1656 points.
1657 \end{options}
1658
1659 \section{Selectively Include Questions from External Files}\label{sec:include}
1660 \subsection{Caveat}
1661 I need to say some words of caution: the \cs{includequestions} that will be
1662 presented shortly is probably \ExSheets' most experimental one at the time of
1663 writing (\today). Thanks to feedback of users it is constantly improved and
1664 bugs are fixed. It is not a very efficient way to insert question regarding
1665 performance and you shouldn't wonder if compilation slows down when you use
1666 it. It probably needs to be re-written all over but on the one hand that
1667 would introduce new bugs and on the other hand for the time being I don't have
1668 the capacities, anyway, so you'll have to live it, I'm afraid.
1669
1670 \subsection{How it works}
1671 Suppose you have one or more files with questions prepared to use them as a
1672 kind of database. One for class A, say, one for class B, one for class C and
1673 so one, something like this:
1674 \begin{sourcecode}
1675 % this is file classA.tex
1676 \begin{question}[class=A,ID=A1,topic=X]
1677 First question of class A, topic X.
1678 \end{question}
1679 \begin{solution}
1680 First solution of class A.
1681 \end{solution}
1682 \begin{question}[class=A,ID=A2,topic=Y]
1683 Second question of class A, topic Y.
1684 \end{question}
1685 \begin{solution}
1686 Second solution of class A.
1687 \end{solution}
1688 ...
1689 % end of file classA.tex
1690 \endinput
1691 \end{sourcecode}
1692 You can of course just \cs*{input} or \cs*{include} it but that would of
1693 course include the whole file into your document. But would't it be nice to
1694 just include selected questions? Or maybe a five random questions from the
1695 file? That is possible with the following command:
1696 \begin{commands}
1697 \command{includequestions}[\oarg{options}\marg{list of filenames}]
1698 Include questions from external files.
1699 \end{commands}
1700 If you use it without options it will have the same effect as \cs*{input}.
1701 There are however the following options:
1702 \begin{options}
1703 \keybool{all}\Module{include}
1704 \keyval{IDs}{list of IDs}\Module{include}\Default
1705 Includes only the specified questions.
1706 \keyval{random}{num}\Module{include}\Default
1707 Includes \meta{num} randomly selected questions. This option uses the
1708 \pkg{pgfcore} package to create the pseudo-random numbers.
1709 \keyval{exclude}{list of IDs}\Module{include}\Default
1710 Questions who's \acp{id} are specified here are \emph{not} included. This
1711 option can be combined with the \option{random} option.
1712 \end{options}
1713
1714 The usage should be self-explainable:
1715 \begin{sourcecode}
1716 % include questions A1, A3 and A4:
1717 \includequestions[IDs={A1,A3,A4}]{classA.tex}
1718 % or include 3 random questions:
1719 \includequestions[random=3]{classA}
1720 \end{sourcecode}
1721 In order to be able to select the questions \ExSheets\ needs to \cs*{input}
1722 the file twice. The first time the available questions are determined, the
1723 second time the selected questions are used. This unfortunately means that
1724 anything that is \emph{not} part of a question or solution is also input
1725 twice. Either don't put anything else into the file or use one of the
1726 following commands for control:
1727 \begin{commands}
1728 \command{PrintIfIncludeActiveTF}[\marg{true code}\marg{false code}]
1729 Checks if the questions are actively included or not and puts \meta{true
1730 code} or \meta{false code} in the input stream depending on the answer.
1731 \command{PrintIfIncludeActiveT}[\marg{true code}]
1732 Checks if the questions are actively included or not and puts \meta{true
1733 code} in the input stream if the answer is yes.
1734 \command{PrintIfIncludeActiveF}[\marg{false code}]
1735 Checks if the questions are actively included or not and puts \meta{false
1736 code} in the input stream if the answer is no.
1737 \end{commands}
1738
1739 The selection can be refined further by selecting questions belonging to a
1740 specific class of questions (see section~\ref{sec:cond-print-quest}) before
1741 using \cs{includequestions}.
1742
1743 \sinceversion{0.8}After you've used \cs{includequestions} the \acp{id} of the
1744 included questions is available as an unordered comma separated list in the
1745 following macro:
1746 \begin{commands}
1747 \command{questionsincludedlast}
1748 Unordered comma separated list of question \acp{id} included with the last
1749 usage of \cs{includequestions}.
1750 \end{commands}
1751
1752 \section{The \option*{auto-label} Option}\label{sec:auto-label-opti}
1753 The\sinceversion{0.12} package option \option{auto-label} sets a
1754 \cs*{label}\Marg{qu:\meta{id}} every time the question environment is used.
1755 Both the used command and the automated label can be customized using the
1756 following options:
1757
1758 \begin{options}
1759 \keyval{label-format}{code}\Default{qu:\#1}
1760 The pattern for generating the automatic label. \code{\#1} gets replaced
1761 by the \ac{id} of the corresponding question.
1762 \keyval{label-cmd}{macro}\Default{\cs*{label}}
1763 The command used for generating the label. A command that should take one
1764 mandatory argument.
1765 \keyval{ref-cmd}{macro}\Default{\cs*{ref}}
1766 The command used in the \code{ref} property created by the
1767 \option{auto-label} option, also see section \ref{sec:additional_info}.
1768 The command should take one mandatory argument.
1769 \keyval{pageref-cmd}{macro}\Default{\cs*{pageref}}
1770 The command used in the \code{pageref} property created by the
1771 \option{auto-label} option, also see section \ref{sec:additional_info}.
1772 The command should take one mandatory argument.
1773 \end{options}
1774
1775 \section{Own Question/Solution Pairs}
1776 \ExSheets\changedversion{0.9} provides the possibility to create new
1777 environments that behave like the \env{question} and \env{solution}
1778 environments. This would allow, for example, to define a
1779 \env*{question*}/\env*{solution*} environment pair for bonus questions. The
1780 following commands may be used in the document preamble:
1781 \begin{commands}
1782 \command{NewQuSolPair}[\marg{question}\oarg{question options}\oarg{general
1783 options}\marg{solution}\oarg{solution options}\oarg{general options}]
1784 Define a new pair of question and solution environments.
1785 \command{RenewQuSolPair}[\marg{question}\oarg{question options}\oarg{general
1786 options}\marg{solution}\oarg{solution options}\oarg{general options}]
1787 Redefine an existing pair of question and solution environments.
1788 \end{commands}
1789 The standard environments are defined as follows:
1790 \begin{sourcecode}
1791 \NewQuSolPair{question}{solution}
1792 \end{sourcecode}
1793
1794 Let's say we want the possibility to add bonus questions. A simple way would
1795 be to define starred variants that add a star in the margin left to the title:
1796 \begin{example}
1797 % preamble:
1798 % - \texorpdfstring is provided by `hyperref'
1799 % - \bigstar is provided by `amssymb'
1800 % \DeclareRobustCommand*\questionstar{\texorpdfstring{\bonusquestionsign}{* }}
1801 % \DeclareRobustCommand*\bonusquestionsign{\llap{$\bigstar$\space}}
1802 %
1803 % \NewQuSolPair
1804 % {question*}[name=\questionstar Bonus Question]
1805 % {solution*}[name=\questionstar Solution]
1806 \begin{question*}
1807 This is a bonus question.
1808 \end{question*}
1809 \begin{solution*}[print]
1810 This is what the solution looks like.
1811 \end{solution*}
1812 \end{example}
1813 As you can see the environments take the same options as are described for the
1814 standard \env{question} and \env{solution} environments.
1815
1816 \section{Filling in the Blanks}
1817 \subsection{Cloze}
1818 Both\changedversion{0.4} in exercise sheets and in exams it is sometimes
1819 desirable to be able to create \blank{blanks} that have to be filled in. Or
1820 maybe some more lines: \blank[width=5\linewidth]{}
1821
1822 \begin{commands}
1823 \command{blank}[\sarg\oarg{options}\marg{text to be filled in}]
1824 creates a blank in normal text or in a question but fills the text of its
1825 argument if inside a solution. If used at the \emph{begin of a paragraph}
1826 \cs{blank} will do two things: it will set the linespread according to an
1827 option explained below and will insert \cs*{par} after the lines. If you
1828 don't want that use the starred version.
1829 \end{commands}
1830
1831 The options are these:
1832 \begin{options}
1833 \keychoice{style}{line,wave,dline,dotted,dashed}\Module{blank}\Default{line}
1834 The style of the line. This uses the corresponding command from the
1835 \pkg{ulem} package and is the whole reason why \ExSheets\ loads it in the
1836 first place.
1837 \keyval{scale}{num}\Module{blank}\Default{1}
1838 Scales the width of the blank by factor \meta{num} unless the width is
1839 explicitly set.
1840 \keyval{width}{dim}\Module{blank}\Default
1841 The width of the line. If it is not used the width of the filled in text
1842 is used.
1843 \keyval{linespread}{num}\Module{blank}\Default{1}
1844 Set the linespread for the blank lines. This only has an effect if
1845 \cs{blank} is used at the begin of a paragraph.
1846 \keyval{line-increment}{dim}\Module{blank}\Default{1pt}
1847 \sinceversion{0.21h}When the blank line ist built it is built in multiples
1848 of this value. If the value is too large you may end up with uneven
1849 lines. If the value is too small you may end up with a non-ending
1850 compilation.
1851 \keyval{line-minimum-length}{dim}\Module{blank}\Default{2em}
1852 \sinceversion{0.21h}The minimal length a line must have before it is built
1853 step by step.
1854 \end{options}
1855 \begin{example}
1856 \begin{question}
1857 Try to fill in \blank[width=4cm]{these} blanks. All of them
1858 \blank[style=dotted]{are created} by using the \cs{blank}
1859 \blank[style=dashed]{command}.
1860 \end{question}
1861 \begin{solution}[print]
1862 Try to fill in \blank[width=4cm]{these} blanks. All of them
1863 \blank[style=dotted]{are created} by using the \cs{blank}
1864 \blank[style=dashed]{command}.
1865 \end{solution}
1866 \end{example}
1867 A number of empty lines are easily created by setting the width option:
1868 \begin{example}
1869 \blank[width=4.8\linewidth,linespread=1.5]{}
1870 \end{example}
1871
1872 \subsection{Vertical Space for answers}
1873 When\sinceversion{0.3} you're creating an exam you might want to add some
1874 vertical space where the students can write down their answers. While you can
1875 always use \cs*{vspace} this is not always handy when the space left on the
1876 page is less than you want. In this case it would be nice if a) there would
1877 be no warning and b) the rest of the space would be added at the top of the
1878 next page. This is what the following command is for:
1879 \begin{commands}
1880 \command{examspace}[\sarg\marg{dim}]
1881 Add space as specified in \meta{dim}. If the space available on the
1882 current page is not enough the rest of the space will be added at the top
1883 of the next page. The starred version will silently drop any leftover
1884 space instead of adding it to the next page.
1885 \end{commands}
1886 \begin{example}[side-by-side]
1887 \begin{question}
1888 What do you think of this feature?
1889 \examspace{3cm}
1890 \end{question}
1891 This line comes after the space.
1892 \end{example}
1893
1894 \section{Styling your Exercise/Exam Sheets}\label{part:style}
1895 \subsection{Background}
1896 The \ExSheets\ package makes extensive use of \LaTeX3's coffins\footnote{See
1897 the documentation to the \pkg{xcoffins} package for more information on
1898 that.} as well as its templates concept\footnote{Have a look into the
1899 documentation to the \pkg{xtemplate} package.}. The latter allows a
1900 rather easy extension and customization of some of \ExSheets' environments.
1901 To be more precise: you can define your own instances for the headings used
1902 for questions and solutions.
1903
1904 What this package doesn't provide is changing the background of questions or
1905 framing them. But this is easily possible using the \pkg{mdframed} package
1906 and its \cs*{surroundwithmdframed} command.
1907
1908 \ExSheets{} also provides the options \option{pre-hook}, \option{post-hook},
1909 \option{pre-body-hook} and \option{post-body-hook} to both the question and
1910 the solution environment. With them it is rather straightforward to add a
1911 \pkg{mdframed} frame for instance:
1912 \begin{sourcecode}
1913 \SetupExSheets{
1914 solution/pre-hook = \mdframed ,
1915 solution/post-hook = \endmdframed
1916 }
1917 \end{sourcecode}
1918
1919 Then\sinceversion{0.18} there is the macro
1920 \cs{exsheetsprintsolution}\marg{heading}\marg{body}\label{exsheetsprintsolution}
1921 which may be redefined to suit your needs. The default definition is
1922 equivalent to
1923 \begin{sourcecode}
1924 \newcommand\exsheetsprintsolution[2]{#1#2}
1925 \end{sourcecode}
1926
1927 \subsection{The \code{exsheets-headings} Object}\label{sec:exsheets-headings}
1928 \ExSheets\ defines the object \code{exsheets-headings} and one template for it,
1929 the `default' template. The package also defines two instances of this
1930 template, the `block' instance and the `runin' instance.
1931
1932 \begin{example}
1933 \SetupExSheets{headings=block}
1934 \begin{question}{1}
1935 a `block' heading
1936 \end{question}
1937 \SetupExSheets{headings=runin}
1938 \begin{question}{1}
1939 a `runin' heading
1940 \end{question}
1941 \end{example}
1942
1943 \subsubsection{Available Options}
1944 This section only lists the options that can be used when defining an instance
1945 of the `default' template. The following subsections will give loads of
1946 examples of their usage. The options are listed in the definition for the
1947 template interface:
1948
1949 \begin{sourcecode}
1950 \DeclareTemplateInterface{exsheets-heading}{default}{3}{
1951 % option : type = default
1952 inline : boolean = false ,
1953 runin : boolean = false ,
1954 indent-first : boolean = false ,
1955 toc-reversed : boolean = false ,
1956 vscale : real = 1 ,
1957 above : length = 2pt ,
1958 below : length = 2pt ,
1959 main : tokenlist = ,
1960 pre-code : tokenlist = ,
1961 post-code : tokenlist = ,
1962 title-format : tokenlist = ,
1963 title-pre-code : tokenlist = ,
1964 title-post-code : tokenlist = ,
1965 number-format : tokenlist = ,
1966 number-pre-code : tokenlist = ,
1967 number-post-code : tokenlist = ,
1968 subtitle-format : tokenlist = ,
1969 subtitle-pre-code : tokenlist = ,
1970 subtitle-post-code : tokenlist = ,
1971 points-format : tokenlist = ,
1972 points-pre-code : tokenlist = ,
1973 points-post-code : tokenlist = ,
1974 join : tokenlist = ,
1975 attach : tokenlist =
1976 }
1977 \end{sourcecode}
1978
1979 Each heading is built with at most five coffins available with the names
1980 `main', `title', `subtitle', `number' and `points'. Those coffins place
1981 possibly the whole heading, the title, the subtitle, the question number and
1982 the assigned points. The only coffin that's always typeset is the `main'
1983 coffin, which is empty per default.
1984
1985 Coffins can be joined (two become one, the first extends its bounding box to
1986 contain the second) using the following syntax:
1987 \begin{sourcecode}
1988 join = coffin1[handle11,handle12]coffin2[handle21,handle22](x-offset,y-offset)
1989 \end{sourcecode}
1990 The syntax for attaching (two become one, the first does \emph{not} extend its
1991 bounding box around the second) is the same.
1992
1993 More on coffin handles is described in the documentation for the
1994 \pkg{xcoffins}. Figure~\ref{fig:handles} briefly demonstrates the available
1995 handle pairs.
1996
1997 \begin{figure}[ht]
1998 \centering
1999 \parbox{4.5cm}{%
2000 \NewCoffin\ExampleCoffin
2001 \SetHorizontalCoffin\ExampleCoffin{\color{gray!30}\rule{4cm}{4cm}}%
2002 \DisplayCoffinHandles\ExampleCoffin{blue}%
2003 }
2004 \caption{Available handles for a horizontal coffin.}\label{fig:handles}
2005 \end{figure}
2006
2007 It is possible\sinceversion{0.20} to add own static coffins:
2008 \begin{commands}
2009 \command{DeclareExSheetsHeadingContainer}[\marg{name}\marg{code}]
2010 Defines a new coffin \meta{name} containing \meta{code}. You can refer to
2011 the current question's \ac{id} with \cs{CurrentQuestionID}.
2012 \end{commands}
2013
2014 The following subsections will show all definitions of the instances available
2015 and how they look. This will hopefully give you enough ideas to create your
2016 own instance if you want to have another heading style than the ones
2017 available. Each of the following instances is available through the option
2018 \key{headings}{instance}.
2019
2020 The following examples use a sample text defined as follows:
2021 \begin{sourcecode}
2022 \def\s{This is some sample text we will use to create a somewhat
2023 longer text spanning a few lines.}
2024 \def\sample{\s\ \s\par\s}
2025 \end{sourcecode}
2026 \def\s{This is some sample text we will use to create a somewhat longer text
2027 spanning a few lines.}
2028 \def\sample{\s\ \s\par\s}
2029
2030 All of the following examples use the same question call:
2031 \begin{sourcecode}
2032 \SetupExSheets{headings=<name>}
2033 \begin{question}[subtitle=The subtitle of the question]{1}
2034 A `<name>' heading. \sample
2035 \end{question}
2036 \end{sourcecode}
2037
2038 \subsubsection{The `block' Instance}
2039 \begin{sourcecode}
2040 \DeclareInstance{exsheets-heading}{block}{default}{
2041 join = { title[r,B]number[l,B](.333em,0pt) } ,
2042 attach =
2043 {
2044 main[l,vc]title[l,vc](0pt,0pt) ;
2045 main[r,vc]points[l,vc](\marginparsep,0pt)
2046 }
2047 }
2048 \end{sourcecode}
2049 \SetupExSheets{headings=block}
2050 \begin{question}[subtitle=The subtitle of the question]{1}
2051 A `block' heading. \sample
2052 \end{question}
2053
2054 \subsubsection{The `runin' Instance}
2055 \begin{sourcecode}
2056 \DeclareInstance{exsheets-heading}{runin}{default}{
2057 runin = true ,
2058 number-post-code = \space ,
2059 attach =
2060 { main[l,vc]points[l,vc](\linewidth+\marginparsep,0pt) } ,
2061 join =
2062 {
2063 main[r,vc]title[r,vc](0pt,0pt) ;
2064 main[r,vc]number[l,vc](.333em,0pt)
2065 }
2066 }
2067 \end{sourcecode}
2068 \SetupExSheets{headings=runin}
2069 \begin{question}[subtitle=The subtitle of the question]{1}
2070 A `runin' heading. \sample
2071 \end{question}
2072
2073 \subsubsection{The `simple' Instance}
2074 \begin{sourcecode}
2075 \DeclareInstance{exsheets-heading}{simple}{default}{
2076 title-format = \normalsize ,
2077 points-pre-code = ( ,
2078 points-post-code = ) ,
2079 attach = { main[l,t]number[l,t](0pt,0pt) } ,
2080 join =
2081 {
2082 number[r,b]title[l,b](.333em,0pt) ;
2083 main[l,b]points[l,t](1em,0pt)
2084 }
2085 }
2086 \end{sourcecode}
2087 \SetupExSheets{headings=simple}
2088 \begin{question}[subtitle=The subtitle of the question]{1}
2089 A `simple' heading. \sample
2090 \end{question}
2091
2092 \subsubsection{The `empty' Instance}
2093 \sinceversion{0.9a}
2094 \begin{sourcecode}
2095 \DeclareInstance{exsheets-heading}{empty}{default}{
2096 runin = true ,
2097 above = \parskip ,
2098 below = \parskip ,
2099 attach = { main[l,vc]points[l,vc](\linewidth+\marginparsep,0pt) }
2100 }
2101 \end{sourcecode}
2102 \SetupExSheets{headings=empty}
2103 \begin{question}[subtitle=The subtitle of the question]{1}
2104 An `empty' heading. \sample
2105 \end{question}
2106
2107 \subsubsection{The `block-rev' Instance}
2108 \begin{sourcecode}
2109 \DeclareInstance{exsheets-heading}{block-rev}{default}{
2110 toc-reversed = true ,
2111 join = { number[r,B]title[l,B](.333em,0pt) } ,
2112 attach =
2113 {
2114 main[l,vc]number[l,vc](0pt,0pt) ;
2115 main[r,vc]points[l,vc](\marginparsep,0pt)
2116 }
2117 }
2118 \end{sourcecode}
2119 \SetupExSheets{headings=block-rev}
2120 \begin{question}[subtitle=The subtitle of the question]{1}
2121 A `block-rev' heading. \sample
2122 \end{question}
2123
2124 \subsubsection{The `block-subtitle' Instance}
2125 \sinceversion{0.10}
2126 \begin{sourcecode}
2127 \DeclareInstance{exsheets-heading}{block-subtitle}{default}{
2128 join = {
2129 title[r,B]number[l,B](.333em,0pt) ;
2130 title[r,B]subtitle[l,B](1em,0pt)
2131 } ,
2132 attach = {
2133 main[l,vc]title[l,vc](0pt,0pt) ;
2134 main[r,vc]points[l,vc](\marginparsep,0pt)
2135 }
2136 }
2137 \end{sourcecode}
2138 \SetupExSheets{headings=block-subtitle}
2139 \begin{question}[subtitle=The subtitle of the question]{1}
2140 A `block-subtitle' heading. \sample
2141 \end{question}
2142 \subsubsection{The `block-wp' Instance}
2143 \begin{sourcecode}
2144 \DeclareInstance{exsheets-heading}{block-wp}{default}{
2145 points-pre-code = ( ,
2146 points-post-code = ) ,
2147 join =
2148 {
2149 title[r,B]number[l,B](.333em,0pt) ;
2150 title[r,B]points[l,B](.333em,0pt)
2151 } ,
2152 attach = { main[l,vc]title[l,vc](0pt,0pt) }
2153 }
2154 \end{sourcecode}
2155 \SetupExSheets{headings=block-wp}
2156 \begin{question}[subtitle=The subtitle of the question]{1}
2157 A `block-wp' heading. \sample
2158 \end{question}
2159
2160 \subsubsection{The `block-wp-rev' Instance}
2161 \begin{sourcecode}
2162 \DeclareInstance{exsheets-heading}{block-wp-rev}{default}{
2163 toc-reversed = true ,
2164 points-pre-code = ( ,
2165 points-post-code = ) ,
2166 join =
2167 {
2168 number[r,B]title[l,B](.333em,0pt) ;
2169 number[r,B]points[l,B](.333em,0pt)
2170 } ,
2171 attach = { main[l,vc]number[l,vc](0pt,0pt) }
2172 }
2173 \end{sourcecode}
2174 \SetupExSheets{headings=block-wp-rev}
2175 \begin{question}[subtitle=The subtitle of the question]{1}
2176 A `block-wp-rev' heading. \sample
2177 \end{question}
2178
2179 \subsubsection{The `block-nr' Instance}
2180 \begin{sourcecode}
2181 \DeclareInstance{exsheets-heading}{block-nr}{default}{
2182 attach =
2183 {
2184 main[l,vc]number[l,vc](0pt,0pt) ;
2185 main[r,vc]points[l,vc](\marginparsep,0pt)
2186 }
2187 }
2188 \end{sourcecode}
2189 \SetupExSheets{headings=block-nr}
2190 \begin{question}[subtitle=The subtitle of the question]{1}
2191 A `block-nr' heading. \sample
2192 \end{question}
2193
2194 \subsubsection{The `block-nr-wp' Instance}
2195 \begin{sourcecode}
2196 \DeclareInstance{exsheets-heading}{block-nr-wp}{default}{
2197 points-pre-code = ( ,
2198 points-post-code = ) ,
2199 join = { number[r,vc]points[l,vc](.333em,0pt) } ,
2200 attach = { main[l,vc]number[l,vc](0pt,0pt) }
2201 }
2202 \end{sourcecode}
2203 \SetupExSheets{headings=block-nr-wp}
2204 \begin{question}[subtitle=The subtitle of the question]{1}
2205 A `block-nr-wp' heading. \sample
2206 \end{question}
2207
2208 \subsubsection{The `runin-rev' Instance}
2209 \begin{sourcecode}
2210 \DeclareInstance{exsheets-heading}{runin-rev}{default}{
2211 toc-reversed = true ,
2212 runin = true ,
2213 title-post-code = \space ,
2214 attach =
2215 { main[l,vc]points[l,vc](\linewidth+\marginparsep,0pt) } ,
2216 join =
2217 {
2218 main[r,vc]number[r,vc](0pt,0pt) ;
2219 main[r,vc]title[l,vc](.333em,0pt)
2220 }
2221 }
2222 \end{sourcecode}
2223 \SetupExSheets{headings=runin-rev}
2224 \begin{question}[subtitle=The subtitle of the question]{1}
2225 A `runin-rev' heading. \sample
2226 \end{question}
2227
2228 \subsubsection{The `runin-wp' Instance}
2229 \begin{sourcecode}
2230 \DeclareInstance{exsheets-heading}{runin-wp}{default}{
2231 runin = true ,
2232 points-pre-code = ( ,
2233 points-post-code = )\space ,
2234 join =
2235 {
2236 main[r,vc]title[r,vc](0pt,0pt) ;
2237 main[r,vc]number[l,vc](.333em,0pt) ;
2238 main[r,vc]points[l,vc](.333em,0pt)
2239 }
2240 }
2241 \end{sourcecode}
2242 \SetupExSheets{headings=runin-wp}
2243 \begin{question}[subtitle=The subtitle of the question]{1}
2244 A `runin-wp' heading. \sample
2245 \end{question}
2246
2247 \subsubsection{The `runin-wp-rev' Instance}
2248 \begin{sourcecode}
2249 \DeclareInstance{exsheets-heading}{runin-wp-rev}{default}{
2250 toc-reversed = true ,
2251 runin = true ,
2252 points-pre-code = ( ,
2253 points-post-code = )\space ,
2254 join =
2255 {
2256 main[r,vc]number[r,vc](0pt,0pt) ;
2257 main[r,vc]title[l,vc](.333em,0pt) ;
2258 main[r,vc]points[l,vc](.333em,0pt)
2259 }
2260 }
2261 \end{sourcecode}
2262 \SetupExSheets{headings=runin-wp-rev}
2263 \begin{question}[subtitle=The subtitle of the question]{1}
2264 A `runin-wp-rev' heading. \sample
2265 \end{question}
2266
2267 \subsubsection{The `runin-nr' Instance}
2268 \begin{sourcecode}
2269 \DeclareInstance{exsheets-heading}{runin-nr}{default}{
2270 runin = true ,
2271 number-post-code = \space ,
2272 attach =
2273 { main[l,vc]points[l,vc](\linewidth+\marginparsep,0pt) } ,
2274 join = { main[r,vc]number[l,vc](0pt,0pt) }
2275 }
2276 \end{sourcecode}
2277 \SetupExSheets{headings=runin-nr}
2278 \begin{question}[subtitle=The subtitle of the question]{1}
2279 A `runin-nr' heading. \sample
2280 \end{question}
2281
2282 \subsubsection{The `runin-fixed-nr' Instance}
2283 \begin{sourcecode}
2284 \DeclareInstance{exsheets-heading}{runin-fixed-nr}{default}{
2285 runin = true ,
2286 number-pre-code = \hbox to 2em \bgroup ,
2287 number-post-code = \hfil\egroup ,
2288 attach =
2289 { main[l,vc]points[l,vc](\linewidth+\marginparsep,0pt) } ,
2290 join = { main[r,vc]number[l,vc](0pt,0pt) }
2291 }
2292 \end{sourcecode}
2293 \SetupExSheets{headings=runin-fixed-nr}
2294 \begin{question}[subtitle=The subtitle of the question]{1}
2295 A `runin-fixed-nr' heading. \sample
2296 \end{question}
2297
2298 \subsubsection{The `runin-nr-wp' Instance}
2299 \begin{sourcecode}
2300 \DeclareInstance{exsheets-heading}{runin-nr-wp}{default}{
2301 runin = true ,
2302 points-pre-code = ( ,
2303 points-post-code = )\space ,
2304 join =
2305 {
2306 main[r,vc]number[l,vc](0pt,0pt) ;
2307 main[r,vc]points[l,vc](.333em,0pt)
2308 }
2309 }
2310 \end{sourcecode}
2311 \SetupExSheets{headings=runin-nr-wp}
2312 \begin{question}[subtitle=The subtitle of the question]{1}
2313 A `runin-nr-wp' heading. \sample
2314 \end{question}
2315
2316 \subsubsection{The `inline' Instance}
2317 \sinceversion{0.5}
2318 \begin{sourcecode}
2319 \DeclareInstance{exsheets-heading}{inline}{default}{
2320 inline = true ,
2321 number-pre-code = \space ,
2322 number-post-code = \space ,
2323 join =
2324 {
2325 main[r,vc]title[r,vc](0pt,0pt) ;
2326 main[r,vc]number[l,vc](0pt,0pt)
2327 }
2328 }
2329 \end{sourcecode}
2330 \SetupExSheets{headings=inline}
2331 Text before
2332 \begin{question}[subtitle=The subtitle of the question]{1}
2333 An `inline' heading. \sample
2334 \end{question}
2335 Text after
2336
2337 \subsubsection{The `inline-wp' Instance}
2338 \sinceversion{0.5}
2339 \begin{sourcecode}
2340 \DeclareInstance{exsheets-heading}{inline-wp}{default}{
2341 inline = true ,
2342 number-pre-code = \space ,
2343 number-post-code = \space ,
2344 points-pre-code = ( ,
2345 points-post-code = )\space ,
2346 join =
2347 {
2348 main[r,vc]title[r,vc](0pt,0pt) ;
2349 main[r,vc]number[l,vc](0pt,0pt) ;
2350 main[r,vc]points[l,vc](0pt,0pt)
2351 }
2352 }
2353 \end{sourcecode}
2354 \SetupExSheets{headings=inline-wp}
2355 Text before
2356 \begin{question}[subtitle=The subtitle of the question]{1}
2357 An `inline-wp' heading. \sample
2358 \end{question}
2359 Text after
2360
2361 \subsubsection{The `inline-nr' Instance}
2362 \sinceversion{0.5}
2363 \begin{sourcecode}
2364 \DeclareInstance{exsheets-heading}{inline-nr}{default}{
2365 inline = true ,
2366 number-post-code = \space ,
2367 join = { main[r,vc]number[l,vc](0pt,0pt) }
2368 }
2369 \end{sourcecode}
2370 \SetupExSheets{headings=inline-nr}
2371 Text before
2372 \begin{question}[subtitle=The subtitle of the question]{1}
2373 An `inline-nr' heading. \sample
2374 \end{question}
2375 Text after
2376
2377 \subsubsection{The `centered' Instance}
2378 \begin{sourcecode}
2379 \DeclareInstance{exsheets-heading}{centered}{default}{
2380 join = { title[r,B]number[l,B](.333em,0pt) } ,
2381 attach =
2382 {
2383 main[hc,vc]title[hc,vc](0pt,0pt) ;
2384 main[r,vc]points[l,vc](\marginparsep,0pt)
2385 }
2386 }
2387 \end{sourcecode}
2388 \SetupExSheets{headings=centered}
2389 \begin{question}[subtitle=The subtitle of the question]{1}
2390 A `centered' heading. \sample
2391 \end{question}
2392
2393 \subsubsection{The `centered-wp' Instance}
2394 \begin{sourcecode}
2395 \DeclareInstance{exsheets-heading}{centered-wp}{default}{
2396 points-pre-code = ( ,
2397 points-post-code = ) ,
2398 join =
2399 {
2400 title[r,B]number[l,B](.333em,0pt) ;
2401 title[r,B]points[l,B](.333em,0pt)
2402 } ,
2403 attach = { main[hc,vc]title[hc,vc](0pt,0pt) }
2404 }
2405 \end{sourcecode}
2406 \SetupExSheets{headings=centered-wp}
2407 \begin{question}[subtitle=The subtitle of the question]{1}
2408 A `centered-wp' heading. \sample
2409 \end{question}
2410
2411 \subsubsection{The `margin' Instance}
2412 \begin{sourcecode}
2413 \DeclareInstance{exsheets-heading}{margin}{default}{
2414 runin = true ,
2415 number-post-code = \space ,
2416 points-pre-code = ( ,
2417 points-post-code = )\space ,
2418 join = { title[r,b]number[l,b](.333em,0pt) } ,
2419 attach =
2420 {
2421 main[l,vc]title[r,vc](0pt,0pt) ;
2422 main[l,b]points[r,t](0pt,0pt)
2423 }
2424 }
2425 \end{sourcecode}
2426 \SetupExSheets{headings=margin}
2427 \begin{question}[subtitle=The subtitle of the question]{1}
2428 A `margin' heading. \sample
2429 \end{question}
2430
2431 \subsubsection{The `margin-nr' Instance}
2432 \begin{sourcecode}
2433 \DeclareInstance{exsheets-heading}{margin-nr}{default}{
2434 runin = true ,
2435 attach =
2436 {
2437 main[l,vc]number[r,vc](-.333em,0pt) ;
2438 main[r,vc]points[l,vc](\linewidth+\marginparsep,0pt)
2439 }
2440 }
2441 \end{sourcecode}
2442 \SetupExSheets{headings=margin-nr}
2443 \begin{question}[subtitle=The subtitle of the question]{1}
2444 A `margin-nr' heading. \sample
2445 \end{question}
2446
2447 \subsubsection{The `raggedleft' Instance}
2448 \begin{sourcecode}
2449 \DeclareInstance{exsheets-heading}{raggedleft}{default}{
2450 join = { title[r,B]number[l,B](.333em,0pt) } ,
2451 attach =
2452 {
2453 main[r,vc]title[r,vc](0pt,0pt) ;
2454 main[r,vc]points[l,vc](\marginparsep,0pt)
2455 }
2456 }
2457 \end{sourcecode}
2458 \SetupExSheets{headings=raggedleft}
2459 \begin{question}[subtitle=The subtitle of the question]{1}
2460 A `raggedleft' heading. \sample
2461 \end{question}
2462
2463 \subsubsection{The `fancy' Instance}
2464 \begin{sourcecode}
2465 \DeclareInstance{exsheets-heading}{fancy}{default}{
2466 toc-reversed = true ,
2467 indent-first = true ,
2468 vscale = 2 ,
2469 pre-code = \rule{\linewidth}{1pt} ,
2470 post-code = \rule{\linewidth}{1pt} ,
2471 title-format = \large\scshape\color{rgb:red,0.65;green,0.04;blue,0.07} ,
2472 number-format = \large\bfseries\color{rgb:red,0.02;green,0.04;blue,0.48} ,
2473 points-format = \itshape ,
2474 join = { number[r,B]title[l,B](.333em,0pt) } ,
2475 attach =
2476 {
2477 main[hc,vc]number[hc,vc](0pt,0pt) ;
2478 main[l,vc]points[r,vc](-\marginparsep,0pt)
2479 }
2480 }
2481 \end{sourcecode}
2482 \SetupExSheets{headings=fancy}
2483 \begin{question}[subtitle=The subtitle of the question]{1}
2484 A `fancy' heading. \sample
2485 \end{question}
2486
2487 \subsubsection{The `fancy-wp' Instance}
2488 \begin{sourcecode}
2489 \DeclareInstance{exsheets-heading}{fancy-wp}{default}{
2490 toc-reversed = true ,
2491 indent-first = true ,
2492 vscale = 2 ,
2493 pre-code = \rule{\linewidth}{1pt} ,
2494 post-code = \rule{\linewidth}{1pt} ,
2495 title-format = \large\scshape\color{rgb:red,0.65;green,0.04;blue,0.07} ,
2496 number-format = \large\bfseries\color{rgb:red,0.02;green,0.04;blue,0.48} ,
2497 points-format = \itshape ,
2498 points-pre-code = ( ,
2499 points-post-code = ) ,
2500 join =
2501 {
2502 number[r,B]title[l,B](.333em,0pt) ;
2503 number[r,B]points[l,B](.333em,0pt)
2504 } ,
2505 attach = { main[hc,vc]number[hc,vc](0pt,0pt) }
2506 }
2507 \end{sourcecode}
2508 \SetupExSheets{headings=fancy-wp}
2509 \begin{question}[subtitle=The subtitle of the question]{1}
2510 A `fancy-wp' heading. \sample
2511 \end{question}
2512
2513 \subsection{Using an \ExSheets{} Heading in Custom Code}\label{sec:using-an-exsheets}
2514
2515 It can be useful to have access to \ExSheets{} headings in custom code. This
2516 is possible with the following command\sinceversion{0.14}:
2517
2518 \begin{commands}
2519 \command{ExSheetsHeading}[\marg{instance}\marg{title}\marg{number}%
2520 \marg{points}\marg{bonus}\marg{id}]
2521 The meaning of the arguments is as follows:
2522 \begin{itemize}
2523 \item \meta{instance}: the name of the headings instance to be used.
2524 \item \meta{title}: the contents of the \code{title} coffin.
2525 \item \meta{number}: the contents of the \code{number} coffin.
2526 \item \meta{points}: The number of points given to the question. If
2527 non-zero this will cause the points to be printed in the \code{points}
2528 coffin.
2529 \item \meta{bonus}: the same as \meta{points} but for bonus points.
2530 \item \meta{id}: the \acs{id} of the question this heading belongs to.
2531 \end{itemize}
2532 \end{commands}
2533
2534 In combination with \cs{ForEachQuestion} the command can be used to build a
2535 custom list of questions. An example of its usage can be seen at the German
2536 Q\&A~site \TeX welt: \url{http://texwelt.de/wissen/fragen/6698#6738}.
2537
2538 \subsection{Load Custom Configurations}
2539 If you have custom configurations you want to be loaded automatically then save
2540 them in a file \code{exsheets\_configurations.cfg}. If this file is present it
2541 will be loaded \cs*{AtBeginDocument}.
2542
2543 \SetupExSheets{headings=block}
2544
2545 \part{The \ExSheetslistings\ Package}\label{part:listings}
2546 \section{The Problem}
2547 I knew the day would come when people would ask how to include verbatim
2548 material in the \env{question} and \env{solution} environments. Since they're
2549 defined with the \pkg{environ} package they're reading their environment
2550 bodies like macros read their arguments. This makes it impossible to use
2551 verbatim material inside them\footnote{See the \TeX\ \acs{faq}
2552 \url{http://www.tex.ac.uk/cgi-bin/texfaq2html?label=verbwithin} for reasons
2553 why.}. Now the day has come~\cite{tex.sx:131546}. Soon after the first
2554 question appeared I wrote the first draft for \ExSheetslistings\ for a question
2555 on \TeX.sx~\cite{tex.sx:133907}.
2556
2557 \section{The Proposed Solution}
2558
2559 The \ExSheetslistings\ package defines \pkg{listings} environments that place
2560 their contents inside \env{question} and \env{solution} environments. They do
2561 this by writing the listing to a unique auxiliary file --
2562 questions to \code{\cs*{jobname}-ex\meta{num}.lst} and solutions to
2563 \code{\cs*{jobname}-sol\meta{num}.lst} where \meta{num} is an increasing
2564 integer that ensures that each listing gets a unique file name. Those files
2565 are then included with \cs{lstinputlisting} if and when the question or
2566 solution is printed.
2567
2568 \begin{environments}
2569 \environment{lstquestion}[\oarg{options}]
2570 A \pkg{listings} environment placed in a \env{question}.
2571 \environment{lstsolution}[\oarg{options}]
2572 A \pkg{listings} environment placed in a \env{solution}.
2573 \end{environments}
2574
2575 All you have to do to use the package is loading it the usual way:
2576 \begin{sourcecode}
2577 \usepackage{exsheets-listings}
2578 \end{sourcecode}
2579 This will also load the packages \ExSheets\ and \pkg{listings} if they're not
2580 loaded already.
2581
2582 \begin{example}
2583 % this uses my listings style used in this documentation for all pieces of
2584 % code:
2585 \begin{lstquestion}[%
2586 pre=Explain what this piece of \TeX\ code does:,
2587 listings={style=cnltx}]
2588 \begingroup\expandafter\expandafter\expandafter\endgroup
2589 \expandafter\ifx\csname foo\endcsname\relax
2590 ...
2591 \else
2592 ...
2593 \fi
2594 \end{lstquestion}
2595 \end{example}
2596
2597 The example already shows two options of these environments. Here is the
2598 complete list:
2599 \begin{options}
2600 \keyval{pre}{text}
2601 \meta{text} is placed before the code in the \env{question} or
2602 \env{solution} environment.
2603 \keyval{post}{text}
2604 \meta{text} is placed after the code in the \env{question} or
2605 \env{solution} environment.
2606 \keyval{options}{options}
2607 Options passed to underlying the \env{question} or \env{solution}
2608 environment.
2609 \keyval{points}{points}
2610 The points assigned to the underlying \env{question} environment.
2611 \keyval{listings}{options}
2612 Options passed to the underlying \pkg{listings} environment.
2613 \end{options}
2614
2615 There are also two new options for \ExSheets\ that can be set with
2616 \cs{SetupExSheets}:
2617 \begin{options}
2618 \keyval{listings}{options}\Module{question}
2619 Options passed to the underlying \pkg{listings} environment of
2620 \env{lstquestion}.
2621 \keyval{listings}{options}\Module{solution}
2622 Options passed to the underlying \pkg{listings} environment of
2623 \env{lstsolution}.
2624 \end{options}
2625
2626 \section{Own Environments}
2627
2628 \begin{commands}
2629 \command{NewLstQuSolPair}[\oarg{options for both environments}\marg{lst question
2630 env}\marg{question env}\oarg{options for lst question env}\marg{lst
2631 solution env}\marg{solution env}\oarg{options for lst solution env}]
2632 Defines two new \pkg{listings} environments that place the listing in a
2633 question environment \meta{question env} or a solution environment
2634 \meta{solution env}. Those underlying environments should be
2635 environments as defined by \cs{NewQuSolPair}. The different options
2636 allow to preset options for the newly defined environments.
2637 \end{commands}
2638
2639 The existing environments have been defined like this:
2640 \begin{sourcecode}
2641 \NewLstQuSolPair{lstquestion}{question}{lstsolution}{solution}
2642 \end{sourcecode}
2643
2644 \appendix
2645 \part{Appendix}
2646 \section{A List of all Solutions used in this Manual}\label{sec:solutions:list}
2647 \SetupExSheets{headings=block-wp,solutions-totoc}
2648 \printsolutions
2649
2650 \end{document}