| 1 |
% arara: pdflatex: { interaction: nonstopmode } |
| 2 |
% arara: biber |
| 3 |
% arara: pdflatex: { interaction: nonstopmode } |
| 4 |
% arara: pdflatex: { interaction: nonstopmode } |
| 5 |
% !arara: pdflatex: { interaction: nonstopmode } |
| 6 |
% ---------------------------------------------------------------------------- |
| 7 |
% the XSIM package |
| 8 |
% |
| 9 |
% eXercise Sheets IMproved |
| 10 |
% |
| 11 |
% ---------------------------------------------------------------------------- |
| 12 |
% Clemens Niederberger |
| 13 |
% Web: https://github.com/cgnieder/xsim |
| 14 |
% E-Mail: [email protected] |
| 15 |
% ---------------------------------------------------------------------------- |
| 16 |
% Copyright 2017--2021 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.3c |
| 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.3c or later is part of all distributions of LaTeX |
| 24 |
% version 2008/05/04 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{xsim-manual} |
| 34 |
|
| 35 |
\begin{filecontents*}[overwrite]{\jobname.bib} |
| 36 |
@online{texsx:tagged/exsheets, |
| 37 |
title = {Questions tagged `exsheets'} , |
| 38 |
author = {various} , |
| 39 |
url = {http://tex.stackexchange.com/questions/tagged/exsheets} , |
| 40 |
urldate = {2020-02-21} |
| 41 |
} |
| 42 |
\end{filecontents*} |
| 43 |
\addbibresource{\jobname.bib} |
| 44 |
|
| 45 |
\begin{document} |
| 46 |
|
| 47 |
\section{Licence, Requirements and \texorpdfstring{\textsc{readme}}{README}} |
| 48 |
\license |
| 49 |
|
| 50 |
\xsim\ loads the packages \pkg{expl3}~\cite{bnd:l3kernel}, |
| 51 |
\pkg{xparse}~\cite{bnd:l3packages}, \pkg{array}~\cite{pkg:array} |
| 52 |
\pkg{booktabs}~\cite{pkg:booktabs} and |
| 53 |
\pkg{translations}~\cite{pkg:translations}. All of these packages are present |
| 54 |
on a modern and up to date \TeX\ distribution such as \TeX~Live or MiK\TeX\ so |
| 55 |
no further action should be needed. When you are using \xsim\ you should be |
| 56 |
using an up to date \TeX\ distribution, anyway. |
| 57 |
|
| 58 |
\begin{bewareofthedog} |
| 59 |
Please be aware that \xsim\ is in an experimental state and actively |
| 60 |
developed. Many aspects may change from one update to another until a |
| 61 |
stable version~1 will be reached. However, I will try my best to keep the |
| 62 |
interface stable. |
| 63 |
|
| 64 |
Newer versions of \xsim\ may depend on newer versions of the support |
| 65 |
packages. Remember: it is always dangerous to update single packages. |
| 66 |
Always update your \TeX\ distribution if you want an up to date version of a |
| 67 |
package. Be careful: if you're in the middle of an important project it |
| 68 |
might be better to wait with the update until you've finished the project. |
| 69 |
Every update might be breaking some things. |
| 70 |
\end{bewareofthedog} |
| 71 |
|
| 72 |
\section{Motivation, Background} |
| 73 |
|
| 74 |
It has been quite a while since I first published |
| 75 |
\pkg{exsheets}~\cite{pkg:exsheets} in June 2012. Since then it has gained a |
| 76 |
user base and a little bit of popularity as the number of questions on tex.sx |
| 77 |
shows (151~at the time of writing)~\cite{texsx:tagged/exsheets}. User |
| 78 |
questions, bug reports and feature requests improved it over the time. It |
| 79 |
still has a version number starting with a zero, though, which in my |
| 80 |
versioning system means I still consider it experimental. |
| 81 |
|
| 82 |
This is due to several facts. It lacks a few features which I consider |
| 83 |
essential for a full version~1. For one thing it is not possible to have |
| 84 |
several kinds of exercises numbered independently. Using verbatim material |
| 85 |
such as listings inside exercises and solutions is not possible and the |
| 86 |
current workaround isn't that ideal either. One request which dates back |
| 87 |
quite a while now was to have different types of points to exercises\ldots |
| 88 |
|
| 89 |
All of those aren't easy to add due to the way \pkg{exsheets} is implemented |
| 90 |
right now. As a consequence I wanted to re-implement \pkg{exsheets} for a long |
| 91 |
time. This is what lead to \xsim. Internally the package works completely |
| 92 |
different. |
| 93 |
|
| 94 |
\begin{bewareofthedog} |
| 95 |
\xsim\ will be the official successor of \pkg{exsheets} which is now |
| 96 |
considered obsolete but will stay alive and will still receive bugfix |
| 97 |
releases. However, new features will not be added to \pkg{exsheets} any |
| 98 |
more. |
| 99 |
\end{bewareofthedog} |
| 100 |
|
| 101 |
\section{How to Read the Manual}\label{sec:how-read-manual} |
| 102 |
|
| 103 |
\subsection{Nomenclature} |
| 104 |
|
| 105 |
Throughout this manual certain terms are used. This section explains their |
| 106 |
meaning in this manual. |
| 107 |
|
| 108 |
\acuseall |
| 109 |
\printacronyms[heading=none] |
| 110 |
|
| 111 |
\subsection{Package Options}\label{sec:package-options} |
| 112 |
\xsim\ has these package options: |
| 113 |
\begin{options} |
| 114 |
\opt{verbose} |
| 115 |
Writes extensive information about what \xsim\ is doing into the log |
| 116 |
file. |
| 117 |
\opt{final} |
| 118 |
If used the exercise and solution environments will not rewrite the |
| 119 |
environment body files. |
| 120 |
\opt{clear-aux} |
| 121 |
If used every time the total number of exercise changes \xsim\ will write |
| 122 |
\emph{less} information to the auxiliary file on the next run and only if |
| 123 |
the number of exercises stays stable between compilations the needed |
| 124 |
information will be written to the auxiliary file. \emph{This needs more |
| 125 |
compilations until everything stabilizes but should reduce the |
| 126 |
probability of possibly faulty exercises after changes to the document.} |
| 127 |
The \option{final} option automatically disables this option. See also |
| 128 |
sections~\vref{sec:how-exerc-envir} and~\vref{sec:resolve-getting}. |
| 129 |
\opt{no-files}\Default{true} |
| 130 |
\sinceversion{0.13}This option prevents \xsim\ from writing the exercises |
| 131 |
and solutions to external files. This will keep your working folder |
| 132 |
``clean'' but will also prevent using verbatim material in exercises and |
| 133 |
solutions. |
| 134 |
\opt{use-files}\Default{false} |
| 135 |
\sinceversion{0.20}This is the opposite of the option \option{no-files}. |
| 136 |
\opt{use-aux} |
| 137 |
\sinceversion{0.15}With this option enabled \xsim\ will use the regular |
| 138 |
auxiliary file \cs*{jobname}\code{.aux} instead of its own auxiliary file |
| 139 |
\cs*{jobname}\code{.xsim}. |
| 140 |
\opt{blank} |
| 141 |
\sinceversion{0.17}With this option enabled \xsim\ will not define the |
| 142 |
default environments \env{exercise} and \env{solution}. |
| 143 |
\end{options} |
| 144 |
|
| 145 |
Those options are load-time options and are used the usual way as package |
| 146 |
options: |
| 147 |
\begin{sourcecode} |
| 148 |
\usepackage[use-files]{xsim} |
| 149 |
\end{sourcecode} |
| 150 |
\begin{bewareofthedog} |
| 151 |
Although those options technically belong to the \module{package} module |
| 152 |
(see also section~\vref{sec:setting-options}) it is \emph{not} possible to |
| 153 |
set them via \cs{xsimsetup}. |
| 154 |
\end{bewareofthedog} |
| 155 |
|
| 156 |
\subsection{Setting Options}\label{sec:setting-options} |
| 157 |
Apart from the package options already described in |
| 158 |
section~\vref{sec:package-options} \xsim\ has further options. All those |
| 159 |
options are set using the following command: |
| 160 |
\begin{commands} |
| 161 |
\command{xsimsetup}[\marg{options}] |
| 162 |
Set up \xsim's package options and all other options described at |
| 163 |
other places in the manual. |
| 164 |
\end{commands} |
| 165 |
Options can be \enquote{toplevel} options or options belonging to a module: |
| 166 |
\begin{options} |
| 167 |
\keyval*{toplevel}{value} |
| 168 |
A toplevel option. |
| 169 |
\keyval*{sublevel}{value}\Module*{module} |
| 170 |
A sublevel option belonging to the module \module*{module} |
| 171 |
\end{options} |
| 172 |
Both kinds of options are set with the setup command: |
| 173 |
\begin{sourcecode} |
| 174 |
\xsimsetup{ |
| 175 |
toplevel = {value} , |
| 176 |
module/sublevel = {value} |
| 177 |
} |
| 178 |
\end{sourcecode} |
| 179 |
|
| 180 |
\subsection{Command descriptions} |
| 181 |
|
| 182 |
Some commands do have a \expandablesymbol\ symbol printed next to their |
| 183 |
names. This indicates that the command is expandable, \ie, it is usable in an |
| 184 |
\cs*{edef} or \cs*{write} context and will expand according to its |
| 185 |
description. All other commands are engine protected, \ie, in the sense of |
| 186 |
\eTeX's \cs*{protected}. |
| 187 |
|
| 188 |
Some command name descriptions end with \code{\TF}. |
| 189 |
\begin{commands} |
| 190 |
\command*{SomeCommand\TF}[\meta{arguments}\marg{true}\marg{false}] |
| 191 |
A command with maybe some arguments and ending with the two arguments |
| 192 |
\meta{true} and \meta{false}. |
| 193 |
\end{commands} |
| 194 |
This means two things: the command is a conditional which tests something and |
| 195 |
depending on the outcome of the test leaves either the \meta{true} argument |
| 196 |
(\code{T}) or the \meta{false} argument (\code{F}) in the input stream. It |
| 197 |
also means two additional commands exist: |
| 198 |
\begin{commands} |
| 199 |
\command*{SomeCommandT}[\meta{arguments}\marg{true}] |
| 200 |
The same as \cs*{SomeCommandTF} but only with the \meta{true} argument and |
| 201 |
no \meta{false} argument. |
| 202 |
\command*{SomeCommandF}[\meta{arguments}\marg{false}] |
| 203 |
The same as \cs*{SomeCommandTF} but only with the \meta{false} argument and |
| 204 |
no \meta{true} argument. |
| 205 |
\end{commands} |
| 206 |
|
| 207 |
\section{Exercises and Solutions} |
| 208 |
|
| 209 |
The two predefined environments for exercises and solutions are the following |
| 210 |
ones\footnote{When you load \xsim\ with the \option{blank} those environments |
| 211 |
will \emph{not} be defined!}: |
| 212 |
\begin{environments} |
| 213 |
\environment{exercise}[\oarg{\acsp*{prop}}] |
| 214 |
Input and typeset an exercise. See section~\vref{sec:exercise-properties} |
| 215 |
for details on exercise \acsp*{prop}. |
| 216 |
\environment{solution}[\oarg{options}] |
| 217 |
Input and typeset the solution to the exercise of the previous |
| 218 |
\env{exercise} environment. See section~\vref{sec:printing-solutions} for |
| 219 |
details on options of solutions. |
| 220 |
\end{environments} |
| 221 |
|
| 222 |
\begin{example} |
| 223 |
\begin{exercise} |
| 224 |
A first example for an exercise. |
| 225 |
\end{exercise} |
| 226 |
\begin{solution} |
| 227 |
A first example for a solution. |
| 228 |
\end{solution} |
| 229 |
\end{example} |
| 230 |
|
| 231 |
As can be seen in the example a solution is not printed with the default |
| 232 |
setup. This can be changed using the following option. |
| 233 |
\begin{options} |
| 234 |
\keybool{print}\Module{solution}\Default{false} |
| 235 |
Set if solutions are printed or not. |
| 236 |
\end{options} |
| 237 |
|
| 238 |
The option (belonging to the module \module*{solution}) can either be set |
| 239 |
locally as option to the \env{solution} environment |
| 240 |
\begin{sourcecode} |
| 241 |
\begin{solution}[print=true] |
| 242 |
A first example for a solution. |
| 243 |
\end{solution} |
| 244 |
\end{sourcecode} |
| 245 |
or with the setup command for all following solutions: |
| 246 |
\begin{sourcecode} |
| 247 |
\xsimsetup{ |
| 248 |
solution/print = true |
| 249 |
} |
| 250 |
\end{sourcecode} |
| 251 |
|
| 252 |
There is an completely analoguous option for the \env{exercise} environment: |
| 253 |
\begin{options} |
| 254 |
\keybool{print}\Module{exercise}\Default{true} |
| 255 |
Set if exercises are printed or not. |
| 256 |
\end{options} |
| 257 |
More details on those two environments can be found in |
| 258 |
section~\vref{sec:using-printing}. |
| 259 |
|
| 260 |
\section{How the Exercise Environments Work}\label{sec:how-exerc-envir} |
| 261 |
\sinceversion{0.13}Depending on the options |
| 262 |
\option{no-files}/\option{use-files} the bodies of exercises and solutions is |
| 263 |
either just another property (see section~\vref{sec:exercise-properties}) -- |
| 264 |
this is the default behavior -- or is written to an external file. |
| 265 |
|
| 266 |
If the option \keyis{no-files}{true} is set the exercise and solution bodies |
| 267 |
are saved as properties \property{exercise-body} and |
| 268 |
\property{solution-body}. This is the default behavior of \xsim\ since |
| 269 |
version~0.20 and should work fine in most cases. One obvious downsise is that |
| 270 |
verbatim material cannot be used in exercises and solutions. |
| 271 |
|
| 272 |
If the option \keyis{use-files}{true} is set both the exercise and the |
| 273 |
solution environments write the contents of their bodies verbatim to external |
| 274 |
files following a certain naming structure: |
| 275 |
\begin{itemize} |
| 276 |
\item |
| 277 |
\code{\meta{jobname}-\meta{type}-\meta{id}-exercise|solution-body.tex} |
| 278 |
\end{itemize} |
| 279 |
The name starts with the name of the job (which is the name of the document |
| 280 |
itself) followed by type and id of the corresponding exercise and then |
| 281 |
followed by the environment type. For example both environments from the first |
| 282 |
example have been written to files named |
| 283 |
\begin{itemize} |
| 284 |
\item \verbcode+xsim-manual-exercise-1-exercise-body.tex+ and |
| 285 |
\item \verbcode+xsim-manual-exercise-1-solution-body.tex+, respectively. |
| 286 |
\end{itemize} |
| 287 |
These external files are input when the respective exercise or solution is |
| 288 |
printed. An advantage of using external files is that \emph{verbatim material |
| 289 |
is allowed} inside the environments. Details on the \meta{type} of an |
| 290 |
exercise will be given in section~\vref{sec:new-exercise-types}. \emph{The |
| 291 |
\meta{id} of an exercise is a positive integer unique to each exercise |
| 292 |
environment regardless if the exercise is being printed or used at all.} |
| 293 |
|
| 294 |
Each of those files contains some information about itself and where and why |
| 295 |
it was generated\footnote{In this example the sourcecode line number is |
| 296 |
misleading as the example where the file was generated itself was an |
| 297 |
external file where the \env{exercise} environment indeed \emph{was} on |
| 298 |
line~1.}: |
| 299 |
|
| 300 |
\inputsourcecode{exercises/xsim-manual-exercise-1-exercise-body.tex} |
| 301 |
|
| 302 |
Arguably one downside of the approach using external files for each exercise |
| 303 |
and its solution is that your project folder will be cluttered with files. In |
| 304 |
order to deal with this somehow \xsim\ offers the following option: |
| 305 |
\begin{options} |
| 306 |
\keyval{path}{path name}\Default |
| 307 |
With this option a subfolder or path within the main project folder can be |
| 308 |
given. Exercises will be written to and included from this path. |
| 309 |
\emph{The path must exist on your system before you can use it!} This |
| 310 |
document uses \keyis{path}{exercises}. |
| 311 |
\keyval{file-extension}{string}\Default{\code{tex}} |
| 312 |
\sinceversion{0.10}This option let's you choose the extension of the |
| 313 |
external files. |
| 314 |
\end{options} |
| 315 |
|
| 316 |
\begin{bewareofthedog} |
| 317 |
Another thing to keep in mind: the environment in many ways works the same |
| 318 |
way as the \env{filecontents} environment. \emph{This also means that you |
| 319 |
\emph{cannot} have comments or \cs*{label}s or anything else on the first |
| 320 |
line of the environments!} |
| 321 |
\end{bewareofthedog} |
| 322 |
\begin{sourcecode} |
| 323 |
\begin{exercise}[points=2] % this comment will cause trouble |
| 324 |
Lorem ipsum |
| 325 |
\end{exercise} |
| 326 |
\end{sourcecode} |
| 327 |
|
| 328 |
\begin{bewareofthedog} |
| 329 |
\xsimauxfileinfo |
| 330 |
\end{bewareofthedog} |
| 331 |
|
| 332 |
\begin{bewareofthedog} |
| 333 |
A lot of the lines \xsim\ writes to the auxiliary file and reads in a |
| 334 |
subsequent run look like this: |
| 335 |
\begin{sourcecode} |
| 336 |
\XSIM{points}{exercise-2=={4}||exercise-10=={2.5}||problem-11=={5}} |
| 337 |
\end{sourcecode} |
| 338 |
As you can see different entries of the various properties of exercises are |
| 339 |
separated with \code{||}. This means that you cannot use this symbol |
| 340 |
combination inside properties. For this reason \xsim\ provides an option to |
| 341 |
change the marker. |
| 342 |
\end{bewareofthedog} |
| 343 |
\begin{options} |
| 344 |
\keyval{split-aux-lists}{string}\Default{\code{||}} |
| 345 |
Set\sinceversion{0.11} the string that is used to separate the property |
| 346 |
entries in the auxiliary file. |
| 347 |
\end{options} |
| 348 |
|
| 349 |
\section{New Exercise Types}\label{sec:new-exercise-types} |
| 350 |
|
| 351 |
It is easy to define new exercise environments together with a corresponding |
| 352 |
solution environment using the following command: |
| 353 |
\begin{commands} |
| 354 |
\command{DeclareExerciseType}[\marg{type}\marg{parameters}] |
| 355 |
Declare a new exercise type analoguous to the \env{exercise} and |
| 356 |
\env{solution} environments. |
| 357 |
\end{commands} |
| 358 |
Declaring a new exercise type will also define a new command: |
| 359 |
\begin{commands} |
| 360 |
\command{numberof\meta{exercise-env}s} |
| 361 |
These commands hold the absolut number of used exercises of type |
| 362 |
\meta{type}. The meaning of \meta{exercise-env} will become clear below |
| 363 |
when the exercise parameters are explained. It is always the same as the |
| 364 |
exercise environment name. |
| 365 |
\end{commands} |
| 366 |
\begin{example} |
| 367 |
There are \numberofexercises~exercises and \numberofproblems~problem in this |
| 368 |
manual. |
| 369 |
\end{example} |
| 370 |
\xsim's pre-defined environment pair\changedversion{0.14} has been defined as |
| 371 |
follows: |
| 372 |
\begin{sourcecode} |
| 373 |
\DeclareExerciseType{exercise}{ |
| 374 |
exercise-env = exercise , |
| 375 |
solution-env = solution , |
| 376 |
exercise-name = \XSIMtranslate{exercise} , |
| 377 |
exercises-name = \XSIMtranslate{exercises} , |
| 378 |
solution-name = \XSIMtranslate{solution} , |
| 379 |
solutions-name = \XSIMtranslate{solutions} , |
| 380 |
exercise-template = default , |
| 381 |
solution-template = default , |
| 382 |
exercise-heading = \subsection* , |
| 383 |
solution-heading = \subsection* |
| 384 |
} |
| 385 |
\end{sourcecode} |
| 386 |
|
| 387 |
The above already is an example for almost all parameters that can (and often |
| 388 |
must) be set. Here is the complete list: |
| 389 |
\begin{parameters} |
| 390 |
\paraval{exercise-env}{exercise environment name} |
| 391 |
The name for the environment used for the exercises of type \meta{type}. |
| 392 |
\emph{This parameter is mandatory.} It can't be changed afterwards. |
| 393 |
\paraval{solution-env}{solution environment name} |
| 394 |
The name for the environment used for the solutions of type \meta{type}. |
| 395 |
\emph{This parameter is mandatory.} It can't be changed afterwards. |
| 396 |
\paraval{exercise-name}{exercise name} |
| 397 |
The name of the exercises of type \meta{type} -- used for typesetting. |
| 398 |
\emph{This parameter is mandatory.} |
| 399 |
\paraval{exercises-name}{exercises name} |
| 400 |
The\sinceversion{0.12} plural name of the exercises of type \meta{type} -- |
| 401 |
used for typesetting. If this is not set explicitly an \code{s} is |
| 402 |
appended to the singular name. |
| 403 |
\paraval{solution-name}{solution name} |
| 404 |
The name of the solutions of type \meta{type} -- used for typesetting. |
| 405 |
\emph{This parameter is mandatory.} |
| 406 |
\paraval{solutions-name}{solutions name} |
| 407 |
The\sinceversion{0.12} plural name of the solutions of type \meta{type} -- |
| 408 |
used for typesetting. If this is not set explicitly an \code{s} is |
| 409 |
appended to the singular name. |
| 410 |
\paraval{exercise-template}{exercise template} |
| 411 |
The template used for typesetting the exercises of type \meta{type}. |
| 412 |
\emph{This parameter is mandatory.} See |
| 413 |
section~\vref{sec:styl-exerc-templ} for details on templates. |
| 414 |
\paraval{solution-template}{solution template} |
| 415 |
The template used for typesetting the exercises of type \meta{type}. |
| 416 |
\emph{This parameter is mandatory.} See |
| 417 |
section~\vref{sec:styl-exerc-templ} for details on templates. |
| 418 |
\paraval{counter}{counter name} |
| 419 |
The counter used for the exercises of type \meta{type}. If not explicitly |
| 420 |
set the counter with the same name as \parameter{exercise-env} is used. |
| 421 |
Otherwise the specified counter is used. This enables to have different |
| 422 |
types of exercises sharing a common counter. \emph{This parameter can't |
| 423 |
be changed afterwards.} If the explicit or implicit counter does not |
| 424 |
exist, yet, it will be defined. |
| 425 |
\paraval{within}{counter name} |
| 426 |
\sinceversion{0.20}Adds \parameter{counter} to the reset list of |
| 427 |
\meta{counter name} by applying \cs*{counterwithin}. |
| 428 |
\paraval{the-counter}{code} |
| 429 |
\sinceversion{0.20}Redefines the corresponding representation command |
| 430 |
\cs*{the...} of \parameter{counter} to \meta{code}. |
| 431 |
\paraval{solution-counter}{counter name} |
| 432 |
The counter used for the solutions of type \meta{type}. If not explicitly |
| 433 |
set the counter with the same name as \parameter{solution-env} is used. |
| 434 |
Otherwise the specified counter is used. This enables to have different |
| 435 |
types of solutions sharing a common counter although this doesn't actually |
| 436 |
make much sense. But it can be useful to avoid using an already existing |
| 437 |
counter. \emph{This parameter can't be changed afterwards.} If the |
| 438 |
explicit or implicit counter does not exist, yet, it will be defined. The |
| 439 |
sole purpose of this counter is to be able to label solutions so they can |
| 440 |
be \cs*{pageref}ed. |
| 441 |
\paraval{number}{integer} |
| 442 |
An internal parameter that is used to keep track of the number of |
| 443 |
exercises of a type. This parameter cannot be set or changed by the |
| 444 |
user. |
| 445 |
\paraval{exercise-heading}{exercise heading command} |
| 446 |
The\sinceversion{0.14} command used for typesetting of the heading of |
| 447 |
exercises of type \meta{type} -- used for typesetting with the command |
| 448 |
\cs{GetExerciseHeadingF}. |
| 449 |
\paraval{solution-heading}{solution heading command} |
| 450 |
The\sinceversion{0.14} command used for typesetting of the heading of |
| 451 |
solutions of type \meta{type} -- used for typesetting with the command |
| 452 |
\cs{GetExerciseHeadingF}. |
| 453 |
\end{parameters} |
| 454 |
|
| 455 |
It is possible to change some of the parameters after an exercise type has |
| 456 |
been defined. Those include \parameter{exercise-name}, |
| 457 |
\parameter{solution-name}, \parameter{exercise-template}, and |
| 458 |
\parameter{solution-template}. It is also possible to define new parameters. |
| 459 |
\begin{commands} |
| 460 |
\command{DeclareExerciseParameter}[\sarg\marg{parameter}] |
| 461 |
Declares the new parameter \meta{parameter}. The optional star declares a |
| 462 |
fixed parameter which cannot be changed once it is set. \emph{You |
| 463 |
probably will never need this command. Most tasks can be solved using |
| 464 |
properties (see section~\vref{sec:exercise-properties}) instead.} |
| 465 |
\command{SetExerciseParameter}[\marg{type}\marg{parameter}\marg{value}] |
| 466 |
Usable to set a single parameter to a new value. |
| 467 |
\command{SetExerciseParameters}[\marg{type}\marg{parameters}] |
| 468 |
Set several parameters at once. \meta{parameters} is a csv list of |
| 469 |
key/value pairs. |
| 470 |
\end{commands} |
| 471 |
If you try to set an already set but fixed parameter like |
| 472 |
\parameter{exercise-env} a warning will be written to the log file. For all |
| 473 |
parameters that can be changed also options exist wich can be set via |
| 474 |
\cs{xsimsetup}. They are explained in |
| 475 |
section~\vref{sec:environment-options-hooks}. |
| 476 |
|
| 477 |
\begin{bewareofthedog} |
| 478 |
All exercises of a type use the parameters |
| 479 |
(\eg, \parameter{exercise-template}) that are \emph{currently active}. If |
| 480 |
you want exercises with a different look or different names in the same |
| 481 |
document you should use different exercises types. |
| 482 |
\end{bewareofthedog} |
| 483 |
|
| 484 |
\section{Exercise Properties}\label{sec:exercise-properties} |
| 485 |
|
| 486 |
\subsection{Predefined Properties} |
| 487 |
|
| 488 |
Exercise like the \env{exercise} environment and possibly others defined with |
| 489 |
\cs{DeclareExerciseType} have a number of predefined \acsp*{prop}: |
| 490 |
\begin{properties} |
| 491 |
\propval{id}{integer} |
| 492 |
Holds the internal id of an exercise. \emph{Cannot be set by the user}. |
| 493 |
\propval{ID}{text} |
| 494 |
Holds the user id of an exercise if defined. Otherwise it is equal to |
| 495 |
\property{id}. |
| 496 |
\propval{counter}{text} |
| 497 |
Holds the counter value representation of an exercise (\ie, what you |
| 498 |
usually know as \cs*{the\meta{counter}}). \emph{Cannot be set by the |
| 499 |
user}. |
| 500 |
\propval{counter-value}{integer} |
| 501 |
Holds the counter value of an exercise (\ie, what you usually know as |
| 502 |
\cs*{the}\cs*{value}\marg{counter}). \emph{Cannot be set by the user}. |
| 503 |
\propval{subtitle}{text} |
| 504 |
Holds the subtitle of an exercise. |
| 505 |
\propval{points}{number} |
| 506 |
Holds the reachable points of an exercise. |
| 507 |
\propval{bonus-points}{number} |
| 508 |
Holds the reachable bonus-points of an exercise. |
| 509 |
\propbool{print} |
| 510 |
Holds the print boolean of an exercise. |
| 511 |
\propbool{print\bang} |
| 512 |
Holds a special print boolean of an exercise, see |
| 513 |
page~\pageref{property:print!}. |
| 514 |
\propbool{use} |
| 515 |
Holds the usage boolean of an exercise. |
| 516 |
\propbool{use\bang} |
| 517 |
Holds a special usage boolean of an exercise, see |
| 518 |
page~\pageref{property:print!}. |
| 519 |
\propbool{used} |
| 520 |
True if an exercise has been used at least once. For an existing exercise |
| 521 |
this is only false for exercises that have been collected |
| 522 |
(\cf~section~\vref{sec:collecting-exercises}). |
| 523 |
\propbool{solution} |
| 524 |
\sinceversion{0.17}Holds the solution boolean of an exercise. If this is |
| 525 |
true then a solution has the same text\slash environment body as the |
| 526 |
corresponding exercise. (This might be useful for multiple choice |
| 527 |
questions for example.) |
| 528 |
\propval{tags}{csv list of tags} |
| 529 |
Holds the list of tags the exercise should be associated with. |
| 530 |
\propval{topics}{csv list of topics} |
| 531 |
Holds the list of topics the exercise should be associated with. |
| 532 |
\propval{page}{text} |
| 533 |
Holds the page counter value representation of an exercise \\ |
| 534 |
(\ie, what you usually know as \cs*{thepage}). |
| 535 |
\propval{page-value}{integer} |
| 536 |
Holds the page counter value of an exercise \\ |
| 537 |
(\ie, what you usually know as \cs*{the}\cs*{value}\Marg{page}). |
| 538 |
\propval{section}{text} |
| 539 |
Holds the section counter value representation of an exercise \\ |
| 540 |
(\ie, what you usually know as \cs*{thesection}). |
| 541 |
\propval{section-value}{integer} |
| 542 |
Holds the section counter value of an exercise \\ |
| 543 |
(\ie, what you usually know as \cs*{the}\cs*{value}\Marg{section}). |
| 544 |
\propval{chapter}{text} |
| 545 |
Holds the chapter counter value representation of an exercise \\ |
| 546 |
(\ie, what you usually know as \cs*{thechapter}). \\ |
| 547 |
\emph{Only if a command \cs*{chapter} \emph{and} a counter \code{chapter} |
| 548 |
exist.} |
| 549 |
\propval{chapter-value}{integer} |
| 550 |
Holds the chapter counter value of an exercise \\ |
| 551 |
(\ie, what you usually know as \cs*{the}\cs*{value}\Marg{chapter}). \\ |
| 552 |
\emph{Only if a command \cs*{chapter} \emph{and} a counter \code{chapter} |
| 553 |
exist.} |
| 554 |
\propval{sectioning}{section numbers} |
| 555 |
Holds five brace groups which in turn hold the section numbers (integers) |
| 556 |
of the exercise in the order |
| 557 |
\marg{chapter}\marg{section}\marg{subsection}\marg{subsubsection}\marg{paragraph}. |
| 558 |
\propval{exercise-body}{\TeX code} |
| 559 |
When\sinceversion{0.13} the package option \option{no-files} is set this |
| 560 |
property is defined and holds the environment body of an exercise. |
| 561 |
\propval{solution-body}{\TeX code} |
| 562 |
When\sinceversion{0.13} the package option \option{no-files} is set this |
| 563 |
property is defined and holds the environment body of the corresponding |
| 564 |
solution. |
| 565 |
\end{properties} |
| 566 |
|
| 567 |
Some of these \acsp*{prop} are fixed and cannot be set by the user. Those |
| 568 |
include \property{id}, \property{counter}, and \property{counter-value}. The |
| 569 |
others can be set using the optional argument of the exercise environment. |
| 570 |
|
| 571 |
\begin{example} |
| 572 |
\begin{exercise}[subtitle={This is a subtitle},points=4,bonus-points=1] |
| 573 |
An exercise where some properties have been set. |
| 574 |
\end{exercise} |
| 575 |
\end{example} |
| 576 |
|
| 577 |
\subsection{Declaring Own Properties} |
| 578 |
|
| 579 |
\xsim\ offers the possibility to declare additional exercise properties: |
| 580 |
\begin{commands} |
| 581 |
\command{DeclareExerciseProperty}[\barg\sarg\narg\marg{property}] |
| 582 |
Declares the property \meta{property}. |
| 583 |
|
| 584 |
If used with the optional \barg\ a \textbf{unique property} is defined |
| 585 |
which means that each exercise must have a property value distinct from |
| 586 |
all other exercises (all means all -- \emph{independent from the exercise |
| 587 |
type}). |
| 588 |
|
| 589 |
If used with the optional \sarg\ a \textbf{boolean property} is defined |
| 590 |
which means that it only should get the values \code{true} or \code{false} |
| 591 |
and if used without value it gets the value \code{true} instead of an |
| 592 |
empty value. If any other value is used the property is set to |
| 593 |
\code{false}. A boolean property obviously cannot be unique. The |
| 594 |
optional \sarg\ takes precedence over the optional \barg, \ie, if both are |
| 595 |
present the property is boolean \emph{but not} unique. |
| 596 |
|
| 597 |
If used with the optional \narg\ a property is defined which won't get |
| 598 |
updated through subsequent compilation runs but is only set when the |
| 599 |
exercise is used. |
| 600 |
\command{DeclareExercisePropertyAlias}[\marg{property 1}\marg{property 2}] |
| 601 |
Declares \meta{property 1} to be an alias of \meta{property 2}. This |
| 602 |
means that each time \meta{property 2} is set \meta{property 1} will be |
| 603 |
set to the same value \emph{unless} it has been set already. As an |
| 604 |
example: property \property{ID} is an alias of property \property{id}. |
| 605 |
\end{commands} |
| 606 |
|
| 607 |
This is better demonstrated with an example: |
| 608 |
\begin{example} |
| 609 |
\begin{exercise} |
| 610 |
\verb+\GetExerciseProperty{id}+: \GetExerciseProperty{id} \par |
| 611 |
\verb+\GetExerciseAliasProperty{ID}+: \GetExerciseAliasProperty{ID} \par |
| 612 |
\verb+\GetExerciseProperty{ID}+: \GetExerciseProperty{ID} |
| 613 |
\end{exercise} |
| 614 |
\begin{exercise}[ID=foo-bar] |
| 615 |
\verb+\GetExerciseProperty{id}+: \GetExerciseProperty{id} \par |
| 616 |
\verb+\GetExerciseAliasProperty{ID}+: \GetExerciseAliasProperty{ID} \par |
| 617 |
\verb+\GetExerciseProperty{ID}+: \GetExerciseProperty{ID} |
| 618 |
\end{exercise} |
| 619 |
\end{example} |
| 620 |
|
| 621 |
The power of properties will get more clear when reading |
| 622 |
section~\vref{sec:styl-exerc-templ} about templates. |
| 623 |
|
| 624 |
\subsection[Exercise Goals]{A Special Kind of Property: Exercise Goals}\label{sec:goals} |
| 625 |
|
| 626 |
Exercise goals are a generic concept in \xsim\ for exercise properties like |
| 627 |
\property{points} or \property{bonus-points}. Those are properties which can |
| 628 |
(only) get a decimal number as value the sum of which is calculated and |
| 629 |
available (after a compilation) throughout the document. |
| 630 |
\begin{commands} |
| 631 |
\command{DeclareExerciseGoal}[\marg{goal}] |
| 632 |
Declare a new exercise goal named \meta{goal} and also a property called |
| 633 |
\meta{goal}. |
| 634 |
\command{TotalExerciseTypeGoal}[\marg{type}\marg{goal}\marg{singular}\marg{plural}] |
| 635 |
Get the sum of goal \meta{goal} for all exercises of type \meta{type}. |
| 636 |
\meta{singular} and \meta{plural} are placed after the sum in the input |
| 637 |
stream depending on whether the sum equals~$1$ or not. |
| 638 |
\command{TotalExerciseTypeGoals}[\marg{type}\marg{list of |
| 639 |
goals}\marg{singular}\marg{plural}] |
| 640 |
Get the sum of goal all goals in \meta{list of goals} for all exercises of |
| 641 |
type \meta{type}. The goal names in \meta{list of goals} must be |
| 642 |
separated with \code{+}. \meta{singular} and \meta{plural} are placed |
| 643 |
after the sum in the input stream depending on whether the sum equals~$1$ |
| 644 |
or not. |
| 645 |
\command{TotalExerciseGoal}[\marg{goal}\marg{singular}\marg{plural}] |
| 646 |
Get the sum of goal \meta{goal} for all exercises. \meta{singular} and |
| 647 |
\meta{plural} are placed after the sum in the input stream depending on |
| 648 |
whether the sum equals~$1$ or not. |
| 649 |
\command{TotalExerciseGoals}[\marg{list of |
| 650 |
goals}\marg{singular}\marg{plural}] |
| 651 |
Get the sum of goal all goals in \meta{list of goals} for all exercises. |
| 652 |
The goal names in \meta{list of goals} must be separated with |
| 653 |
\code{+}. \meta{singular} and \meta{plural} are placed after the sum in |
| 654 |
the input stream depending on whether the sum equals~$1$ or not. |
| 655 |
\command{AddtoExerciseTypeGoal}[\marg{type}\marg{goal}\marg{value}] |
| 656 |
Adds \meta{value} to the goal \meta{goal} of exercise type \meta{type}. |
| 657 |
\command{AddtoExerciseTypeGoalPrint}[\marg{type}\marg{goal}\marg{value}% |
| 658 |
\marg{singular}\marg{plural}] |
| 659 |
Adds \meta{value} to the goal \meta{goal} of exercise type \meta{type}. |
| 660 |
The value and -- depending on wether the value equals $1$ or not -- |
| 661 |
\meta{singular} or \meta{plural} are left in the input stream. |
| 662 |
\command{AddtoExerciseGoal}[\marg{goal}\marg{value}] |
| 663 |
Adds \meta{value} to the goal \meta{goal} of the current exercise |
| 664 |
type. (To be used within exercises.) |
| 665 |
\command{AddtoExerciseTypeGoalPrint}[\marg{goal}\marg{value}% |
| 666 |
\marg{singular}\marg{plural}] |
| 667 |
Adds \meta{value} to the goal \meta{goal} of the current exercise type. |
| 668 |
The value and -- depending on wether the value equals $1$ or not -- |
| 669 |
\meta{singular} or \meta{plural} are left in the input stream. (To be used |
| 670 |
within exercises.) |
| 671 |
\command{ExerciseGoalValuePrint}[\marg{value}\marg{singular}\marg{plural}] |
| 672 |
Print \meta{value} and -- depending on wether the value equals $1$ or not -- |
| 673 |
\meta{singular} or \meta{plural}. |
| 674 |
\command{printgoal}[\marg{value}] |
| 675 |
Print \meta{value} according to option \option{goal-print}. Defined in |
| 676 |
terms of \cs{ExerciseGoalValuePrint}. |
| 677 |
\command{printpoints}[\marg{type}] |
| 678 |
Print the sum of points for all exercises of type \meta{type} followed by |
| 679 |
an appropriate translation of the words \enquote{point} or |
| 680 |
\enquote{points}, respectively\footnote{See section~\vref{sec:exerc-transl} |
| 681 |
for details on the definition and usage of language dependent words.}. |
| 682 |
Defined in terms of \cs{TotalExerciseTypeGoal}. |
| 683 |
\command{printtotalpoints} |
| 684 |
Print the sum of points for all exercises followed by an appropriate |
| 685 |
translation of the words \enquote{point} or \enquote{points}, |
| 686 |
respectively. Defined in terms of \cs{TotalExerciseGoal}. |
| 687 |
\command{addpoints}[\sarg\marg{value}] |
| 688 |
Adds \meta{value} to the points of the current exercise type. (To be used |
| 689 |
within exercises.) Prints the value followed by an appropriate |
| 690 |
translation of the words \enquote{point} or \enquote{points}, |
| 691 |
respectively. The starred version prints nothing. Defined in terms of |
| 692 |
\cs{AddtoExerciseGoal} and \cs{AddtoExerciseGoalPrint}. |
| 693 |
\command{points}[\marg{value}] |
| 694 |
Print \meta{value} followed by an appropriate translation of the words |
| 695 |
\enquote{point} or \enquote{points}, respectively. Defined in terms of |
| 696 |
\cs{ExerciseGoalValuePrint}. |
| 697 |
\command{printbonus}[\marg{type}] |
| 698 |
Print the sum of bonus points for all exercises of type \meta{type} |
| 699 |
followed by an appropriate translation of the words \enquote{point} or |
| 700 |
\enquote{points}, respectively. Defined in terms of |
| 701 |
\cs{TotalExerciseTypeGoal}. |
| 702 |
\command{printtotalbonus} |
| 703 |
Print the sum of bonus points for all exercises followed by an appropriate |
| 704 |
translation of the words \enquote{point} or \enquote{points}, |
| 705 |
respectively. Defined in terms of \cs{TotalExerciseGoal}. |
| 706 |
\command{addbonus}[\sarg\marg{value}] |
| 707 |
Adds \meta{value} to the bonus points of the current exercise type. (To be |
| 708 |
used within exercises.) Prints the value followed by an appropriate |
| 709 |
translation of the words \enquote{point} or \enquote{points}, |
| 710 |
respectively. The starred version prints nothing. Defined in terms of |
| 711 |
\cs{AddtoExerciseGoal} and \cs{AddtoExerciseGoalPrint}. |
| 712 |
\end{commands} |
| 713 |
|
| 714 |
The two existing goals are defined with |
| 715 |
\begin{sourcecode} |
| 716 |
\DeclareExerciseGoal{points} |
| 717 |
\DeclareExerciseGoal{bonus-points} |
| 718 |
\end{sourcecode} |
| 719 |
|
| 720 |
When goal values are printed the decimal number is fed to a function which can |
| 721 |
be changed using the following option: |
| 722 |
\begin{options} |
| 723 |
\keyval{goal-print}{code}\Default{\#1} |
| 724 |
How to format goal values. Use \code{\#1} to refer to the actual number. |
| 725 |
\end{options} |
| 726 |
|
| 727 |
At last some examples for a custom command: let's say you want a command which |
| 728 |
prints the complete sum for all exercises of all exercise types of both |
| 729 |
\property{points} \emph{and} \property{bonus-points} added up: |
| 730 |
\begin{sourcecode} |
| 731 |
\NewDocumentCommand\printsumofpointsandbonus{}{% |
| 732 |
\TotalExerciseGoals{points+bonus-points} |
| 733 |
{\,\XSIMtranslate{point}} |
| 734 |
{\,\XSIMtranslate{points}}% |
| 735 |
} |
| 736 |
\end{sourcecode} |
| 737 |
Here is how you could mimick the command \cs*{totalpoints} from |
| 738 |
\pkg{exsheets}: |
| 739 |
\begin{sourcecode} |
| 740 |
\NewDocumentCommand\pointsandbonus{}{% |
| 741 |
\TotalExerciseGoal{points}{}{}% |
| 742 |
\IfExerciseGoalsSumF{bonus-points}{=0} |
| 743 |
{\,(+\,\TotalExerciseGoal{bonus-points}{}{})}% |
| 744 |
\,\XSIMtranslate{points}% |
| 745 |
} |
| 746 |
\end{sourcecode} |
| 747 |
|
| 748 |
|
| 749 |
\subsection[Exercise Tags]{A Special Kind of Property: Exercise Tags}\label{sec:tags} |
| 750 |
|
| 751 |
Exercise tags are a generic concept in \xsim\ for exercise properties like |
| 752 |
\property{tags} or \property{topics}. Those are properties which can (only) |
| 753 |
get a csv list of strings as value. Those strings can be used to selectively |
| 754 |
use exercises. See section~\vref{sec:using-printing} for details on |
| 755 |
\emph{usage} of exercises and the difference to \emph{printing} an exercise |
| 756 |
and how to use exercise tags for selection. |
| 757 |
\begin{commands} |
| 758 |
\command{DeclareExerciseTagging}[\marg{tag}] |
| 759 |
This defines an exercise tagging group named \meta{tag}. It also defines a |
| 760 |
property named \meta{tag}. In addition two options are defined: an option |
| 761 |
named \code{\meta{tag}} which can be used for selection and an boolean |
| 762 |
option \code{\meta{tag}/ignore-untagged}. |
| 763 |
\command{ProvideExerciseTagging}[\marg{tag}] |
| 764 |
The\sinceversion{0.11} same as \cs{DeclareExerciseTagging} but does |
| 765 |
nothing when \meta{tag} already exists. |
| 766 |
\end{commands} |
| 767 |
The two existing tagging groups have been defined and preset with the |
| 768 |
following code: |
| 769 |
\begin{sourcecode} |
| 770 |
\DeclareExerciseTagging{tags} |
| 771 |
\DeclareExerciseTagging{topics} |
| 772 |
\xsimsetup{tags/ignore-untagged=false} |
| 773 |
\end{sourcecode} |
| 774 |
For each new tag new options are defined and available. They are described |
| 775 |
for the two predefined tags: |
| 776 |
\begin{options} |
| 777 |
\keyval{tags}{csv list of tags} |
| 778 |
Choose the set of tags whose associated exercises should be printed. |
| 779 |
\keyval{topics}{csv list of topics} |
| 780 |
Choose the set of topics whose associated exercises should be printed. |
| 781 |
\keybool{ignore-untagged}\Module{tags}\Default{false} |
| 782 |
If set to true exercises with no tags will be printed even if tags have |
| 783 |
been chosen with the option \option{tags}. |
| 784 |
\keybool{ignore-untagged}\Module{topics}\Default{true} |
| 785 |
If set to true exercises with no topics will be printed even if topics |
| 786 |
have been chosen with the option \option{topics}. |
| 787 |
\keybool{use-unmatched}\Module{tags}\Default{false} |
| 788 |
\sinceversion{0.21}If set to true exercises with no matching tags will be |
| 789 |
used (i.e., for example the counter gets stepped). |
| 790 |
\keybool{use-untagged}\Module{topics}\Default{true} |
| 791 |
\sinceversion{0.21}If set to true exercises with no matching topics will |
| 792 |
be used (i.e., for example the counter gets stepped). |
| 793 |
\end{options} |
| 794 |
|
| 795 |
It may happen that you choose certain tags for printing and want one or two |
| 796 |
exercises to be printed or used even if they don't match the tagging |
| 797 |
criteria. For this reason two additional properties exist which can be set to |
| 798 |
an exercise:\label{property:print!} |
| 799 |
\begin{properties} |
| 800 |
\propbool{print\bang} |
| 801 |
If set to true the exercise will be printed (and thus used) regardless of |
| 802 |
other conditions. |
| 803 |
\propbool{use\bang} |
| 804 |
If set to true the exercise will be used regardless of other conditions. |
| 805 |
\end{properties} |
| 806 |
|
| 807 |
\section{Using and Printing an Exercise}\label{sec:using-printing} |
| 808 |
\subsection{What the Environments do} |
| 809 |
|
| 810 |
When an exercise is started with \environ{exercise} (or other environments |
| 811 |
defined through \cs{DeclareExerciseType}) then three things happen depending |
| 812 |
on the setup: |
| 813 |
\begin{enumerate} |
| 814 |
\item where the environment is placed in the document the \textbf{base |
| 815 |
setup} happens: this sets the \property{id} of the exercise and sets the |
| 816 |
properties chosen in the optional argument. |
| 817 |
\item in the default setting also the \textbf{usage setup} happens: this |
| 818 |
increments the counter and sets the counter related properties like |
| 819 |
\property{counter}. Also the properties related to section numbers and the |
| 820 |
\property{page} are set. |
| 821 |
\item in the default setting also the \textbf{print setup} happens: this |
| 822 |
mostly does nothing. It initiates recording goals that are set inside of |
| 823 |
the exercise body. |
| 824 |
\end{enumerate} |
| 825 |
|
| 826 |
Depending on wether the option \module{exercise}\code{/}\option{use} has been |
| 827 |
set to \code{false} or wether the property \property{use} has been set to |
| 828 |
\code{false} the \emph{usage setup} can be delayed. The usage the happens |
| 829 |
when the exercise is \emph{inserted} the first time elsewhere in the document, |
| 830 |
for example as part of a collection, see |
| 831 |
section~\vref{sec:collecting-exercises}. |
| 832 |
|
| 833 |
Depending on wether the option \module{exercise}\code{/}\option{print} has |
| 834 |
been set to \code{false} or if the property \property{print} has been set to |
| 835 |
\code{false} the \emph{print setup} can be suppressed. It happens each time |
| 836 |
an exercise is inserted. |
| 837 |
|
| 838 |
\begin{example} |
| 839 |
\begin{exercise}[print=false,ID=invisible] |
| 840 |
This exercise will not be printed but the exercise counter will be |
| 841 |
incremented nonetheless. Its solution will be printed in the list of |
| 842 |
solutions. |
| 843 |
\end{exercise} |
| 844 |
\begin{solution} |
| 845 |
The solution of the exercise that has not been printed. |
| 846 |
\end{solution} |
| 847 |
\end{example} |
| 848 |
|
| 849 |
The schematic structure of an exercise is shown in |
| 850 |
figure~\vref{fig:schematic-structure}. |
| 851 |
|
| 852 |
\begin{figure} |
| 853 |
\centering |
| 854 |
\begin{tikzpicture} |
| 855 |
\node[draw,minimum width=.7\linewidth] at (0,0) {pre hook}; |
| 856 |
\node[draw,minimum width=.7\linewidth] at (0,-1) {begin template code}; |
| 857 |
\node[draw,minimum width=.7\linewidth] at (0,-2) {begin hook}; |
| 858 |
\node[draw,minimum width=.7\linewidth] at (0,-3) {environment body}; |
| 859 |
\node[draw,minimum width=.7\linewidth] at (0,-4) {end hook}; |
| 860 |
\node[draw,minimum width=.7\linewidth] at (0,-5) {end template code}; |
| 861 |
\node[draw,minimum width=.7\linewidth] at (0,-6) {post hook}; |
| 862 |
\end{tikzpicture} |
| 863 |
\caption{Schematic structure of an exercise or solution.}\label{fig:schematic-structure} |
| 864 |
\end{figure} |
| 865 |
|
| 866 |
\subsection{Environment Options \& Hooks}\label{sec:environment-options-hooks} |
| 867 |
|
| 868 |
For each exercise type there are the following options for both environments, |
| 869 |
the environments' names are the module names for the options (here using the |
| 870 |
\enquote{exercise} type): |
| 871 |
\begin{options} |
| 872 |
\keybool{print}\Module{exercise}\Default{true} |
| 873 |
Determines if exercises of type \enquote{exercise} are printed. |
| 874 |
\keybool{use}\Module{exercise}\Default{true} |
| 875 |
Determines if exercises of type \enquote{exercise} are used. |
| 876 |
\keybool{collect}\Module{exercise}\Default{false} |
| 877 |
\sinceversion{0.20}Sets both \option{print} and \option{use} to |
| 878 |
\code{false} when \keyis{collect}{true} is set and vice versa. |
| 879 |
\keyval{within}{counter}\Module{exercise}\Default |
| 880 |
\changedversion{0.20}Adds the exercise counter to the reset list of the |
| 881 |
counter \meta{counter} using \cs*{counterwithin}. \emph{Beware that if |
| 882 |
the counter is a shared counter this will affect \emph{all objects} |
| 883 |
using this counter!} |
| 884 |
\keyval{the-counter}{code}\Module{exercise} |
| 885 |
An interface for redefining the counter representation command |
| 886 |
\cs*{the\meta{counter}}. |
| 887 |
\keyval{template}{template}\Module{exercise} |
| 888 |
An interface for \cs{SetExerciseParameter}\Marg{exercise}% |
| 889 |
\Marg{exercise-template}\marg{template}. |
| 890 |
\keyval{template}{template}\Module{solution} |
| 891 |
An interface for \cs{SetExerciseParameter}\Marg{exercise}% |
| 892 |
\Marg{solution-template}\marg{template}. |
| 893 |
\keyval{name}{name}\Module{exercise} |
| 894 |
An interface for \cs{SetExerciseParameter}\Marg{exercise}% |
| 895 |
\Marg{exercise-name}\marg{name}. |
| 896 |
\keyval{name}{name}\Module{solution} |
| 897 |
An interface for \cs{SetExerciseParameter}\Marg{exercise}% |
| 898 |
\Marg{solution-name}\marg{name}. |
| 899 |
\keyval{heading}{heading command}\Module{exercise} |
| 900 |
An\sinceversion{0.14} interface for \cs{SetExerciseParameter}% |
| 901 |
\Marg{exercise}\Marg{exercise-heading}\marg{heading command}. |
| 902 |
\keyval{heading}{heading command}\Module{solution} |
| 903 |
An\sinceversion{0.14} interface for \cs{SetExerciseParameter}% |
| 904 |
\Marg{exercise}\Marg{solution-heading}\marg{heading command}. |
| 905 |
\keyval{pre-hook}{code}\Module{exercise}\Default |
| 906 |
The code for the \emph{pre exercise hook} for exercises of the type |
| 907 |
\enquote{exercise}. |
| 908 |
\keyval{begin-hook}{code}\Module{exercise}\Default |
| 909 |
The code for the \emph{begin exercise hook} for exercises of the type |
| 910 |
\enquote{exercise}. |
| 911 |
\keyval{end-hook}{code}\Module{exercise}\Default |
| 912 |
The code for the \emph{end exercise hook} for exercises of the type |
| 913 |
\enquote{exercise}. |
| 914 |
\keyval{post-hook}{code}\Module{exercise}\Default |
| 915 |
The code for the \emph{post exercise hook} for exercises of the type |
| 916 |
\enquote{exercise}. |
| 917 |
\keybool{print}\Module{solution}\Default{false} |
| 918 |
Determines if solutions of type \enquote{exercise} are printed. |
| 919 |
\keyval{pre-hook}{code}\Module{solution}\Default |
| 920 |
The code for the \emph{pre solution hook} for solutions of the type |
| 921 |
\enquote{exercise}. |
| 922 |
\keyval{begin-hook}{code}\Module{solution}\Default |
| 923 |
The code for the \emph{begin solution hook} for solutions of the type |
| 924 |
\enquote{exercise}. |
| 925 |
\keyval{end-hook}{code}\Module{solution}\Default |
| 926 |
The code for the \emph{end solution hook} for solutions of the type |
| 927 |
\enquote{exercise}. |
| 928 |
\keyval{post-hook}{code}\Module{solution}\Default |
| 929 |
The code for the \emph{post solution hook} for solutions of the type |
| 930 |
\enquote{exercise}. |
| 931 |
% TODO |
| 932 |
\end{options} |
| 933 |
|
| 934 |
\subsection{(Re-) Inserting a Certain Exercise} |
| 935 |
If you know type and \property{id} of an exercise you can (re-)insert every |
| 936 |
existing exercise, \ie, every exercise whose external file exists. |
| 937 |
\begin{commands} |
| 938 |
\command{printexercise}[\marg{type}\marg{csv of ids}] |
| 939 |
\changedversion{0.17}Inserts the exercise or exercises of type |
| 940 |
\meta{type} with the \property{id}s or \property{ID}s given in \meta{csv |
| 941 |
of ids}. |
| 942 |
\command{xprintexercise}[\marg{type}\marg{csv of ids}] |
| 943 |
\sincechanged{0.16}{0.17}The same as \cs{printexercise} but expands |
| 944 |
\meta{type} and the items of \meta{csv of ids} before it uses them. |
| 945 |
\end{commands} |
| 946 |
\begin{example} |
| 947 |
\printexercise{exercise}{invisible} |
| 948 |
\end{example} |
| 949 |
|
| 950 |
\section{Collecting Exercises}\label{sec:collecting-exercises} |
| 951 |
|
| 952 |
\begin{bewareofthedog} |
| 953 |
The whole collection mechanism has been changed completely with |
| 954 |
version~0.20. Please check this section carefully and update and adapt your |
| 955 |
collections. |
| 956 |
\end{bewareofthedog} |
| 957 |
|
| 958 |
\subsection{Background} |
| 959 |
\xsim\ knows the concept of \emph{exercise collections}. A collection of |
| 960 |
exercises can be used in two cases, basically: |
| 961 |
\begin{enumerate} |
| 962 |
\item When you want to print a certain group of exercises several times. In |
| 963 |
this case you add the exercise to a collection while also using it in the |
| 964 |
running text. Somewhere later (or earlier actually) in the document you |
| 965 |
can the reprint the collection\footnote{There is another way to do that, |
| 966 |
but\dots}. |
| 967 |
\item If you only want to print exercises which have certain tags. Maybe |
| 968 |
you have some kind of exercise library in an external which you include |
| 969 |
into you document and want to print only those exercises which fit |
| 970 |
certain conditions. |
| 971 |
\end{enumerate} |
| 972 |
Each collection must have a unique name with which you can refer to the |
| 973 |
corresponding collection. A collection is realized by declaring the |
| 974 |
collection in the preamble and by activating the collection. |
| 975 |
|
| 976 |
\subsection{Usage} |
| 977 |
\subsubsection{Declaring collections} |
| 978 |
\emph{A collection must be declared in the preamble.} Using a pair of |
| 979 |
commands explained below exercises between those commands are added to the |
| 980 |
corresponding collection but not printed. After a collection is completed the |
| 981 |
collection can be printed as often as needed. |
| 982 |
\begin{commands} |
| 983 |
\command{DeclareExerciseCollection}[\oarg{tag values}\marg{collection name}] |
| 984 |
Define a new collection \meta{collection name} in the document preamble. |
| 985 |
An example could look like this: |
| 986 |
\cs{DeclareExerciseCollection}\Oarg{topics=algebra,level=1}\Marg{easy-algebra}. |
| 987 |
Choosing tags automatically activates the collection which means that all |
| 988 |
exercises which fit the tags are automatically added to the new |
| 989 |
collection. |
| 990 |
\end{commands} |
| 991 |
You\sinceversion{0.21} have a choice whether \emph{any} or \emph{all} of the |
| 992 |
tags sould match. So \Oarg{topics=algebra,level=1} should probably match |
| 993 |
\emph{all} conditions but the choice is up to you. For each defined collection |
| 994 |
an option exists: |
| 995 |
\begin{options} |
| 996 |
\keybool{match-all}\Module{collection/\meta{name}}\Default{true} |
| 997 |
If set to \code{true} \emph{all} conditions must be met. |
| 998 |
\keybool{match-any}\Module{collection/\meta{name}}\Default{false} |
| 999 |
The inverse option to \option{match-all}. If set to \code{true} \emph{any} of |
| 1000 |
the conditions must be met. |
| 1001 |
\end{options} |
| 1002 |
|
| 1003 |
\subsubsection{Activating collections} |
| 1004 |
If a collection is not activated per default in can be activated (or |
| 1005 |
deactivated in the opposite case) with these commands: |
| 1006 |
\begin{commands} |
| 1007 |
\command{activatecollection}[\marg{collection name}] |
| 1008 |
\sinceversion{0.20}Activates the collection \meta{collection name} which |
| 1009 |
now collects all exercises until the collection is |
| 1010 |
deactivated. \meta{collection name} can be a csv list of collection |
| 1011 |
names. |
| 1012 |
\command{deactivatecollection}[\marg{collection name}] |
| 1013 |
\sinceversion{0.20}Deactivates the collection \meta{collection name}. |
| 1014 |
\meta{collection name} can be a csv list of collection names. |
| 1015 |
\end{commands} |
| 1016 |
These commands do not influence exercises in other ways other than adding them |
| 1017 |
to collections. |
| 1018 |
\begin{commands} |
| 1019 |
\command{collectexercises}[\marg{collection name}] |
| 1020 |
Activates the collectiocollectexercisesn \meta{collection name} which now collects all |
| 1021 |
exercises until the collection is deactivated, starts a group with |
| 1022 |
\cs*{begingroup} and sets the option \option{collect}, see below. |
| 1023 |
\command{collectexercisesstop}[\marg{collection name}] |
| 1024 |
Deactivates the collection \meta{collection name} and ends a group with |
| 1025 |
\cs*{endgroup}. |
| 1026 |
\end{commands} |
| 1027 |
\begin{options} |
| 1028 |
\keybool{collect}\Default{false} |
| 1029 |
A shortcut option which sets the options |
| 1030 |
\module{\meta{type}}\code{/}\module{collect} for each exercise type. |
| 1031 |
\end{options} |
| 1032 |
|
| 1033 |
\subsubsection{Printing collections} |
| 1034 |
\begin{commands} |
| 1035 |
\command{printcollection}[\oarg{options}\marg{collection name}] |
| 1036 |
Prints the collection \meta{collection name}, \ie, all exercises collected |
| 1037 |
earlier. This command cannot be used before the corresponding collection |
| 1038 |
has been closed correctly. |
| 1039 |
\end{commands} |
| 1040 |
Valid options are the following: |
| 1041 |
\begin{options} |
| 1042 |
\keybool{headings}\Module{print-collection}\Default{false} |
| 1043 |
If true a heading for each exercise type is inserted. |
| 1044 |
\keyval{headings-template}{template}\Module{print-collection}\Default{collection} |
| 1045 |
The heading template used when \keyis{headings}{true}. |
| 1046 |
\keychoice{print}{exercises,solutions,both}\Module{print-collection}\Default{exercises} |
| 1047 |
Determines wether \cs{printcollection} prints the exercises or the |
| 1048 |
solutions of the collection. When you choose \code{both} exercises and |
| 1049 |
solutions are printed alternately. |
| 1050 |
\end{options} |
| 1051 |
|
| 1052 |
Those options can also be set via \cs{xsimsetup} using the module |
| 1053 |
\module{print-collection}. |
| 1054 |
|
| 1055 |
\begin{bewareofthedog} |
| 1056 |
Please be aware that exercises are not used or printed while they are |
| 1057 |
collected. Nonetheless the property \property{use} is set to \code{true} |
| 1058 |
(so that solutions can be printed even if the exercises are not) and the |
| 1059 |
property \property{print} is set to \code{false}. Also their counters are |
| 1060 |
\emph{not stepped} during the process. This only happens when they are |
| 1061 |
printed the first time, \cf~the \property{used} property. At that time |
| 1062 |
also the properties \property{page}, \property{section} and |
| 1063 |
\property{chapter} are set and the property \property{print} is set to |
| 1064 |
\code{true}. |
| 1065 |
\end{bewareofthedog} |
| 1066 |
|
| 1067 |
The usage should be clear: |
| 1068 |
\begin{example} |
| 1069 |
\collectexercises{foo} |
| 1070 |
\begin{exercise} |
| 1071 |
This exercise is added to the collection `foo'. |
| 1072 |
\end{exercise} |
| 1073 |
\begin{exercise} |
| 1074 |
This exercise is also added to the collection `foo'. |
| 1075 |
\end{exercise} |
| 1076 |
\begin{exercise} |
| 1077 |
So is this. |
| 1078 |
\end{exercise} |
| 1079 |
\begin{exercise} |
| 1080 |
As well as this one. |
| 1081 |
\end{exercise} |
| 1082 |
\collectexercisesstop{foo} |
| 1083 |
\end{example} |
| 1084 |
Once the collection is closed it can be printed: |
| 1085 |
\begin{example} |
| 1086 |
\printcollection{foo} |
| 1087 |
\end{example} |
| 1088 |
|
| 1089 |
You can open several collections at the same time: |
| 1090 |
\begin{sourcecode} |
| 1091 |
\collectexercises{foo} |
| 1092 |
... |
| 1093 |
\activatecollection{bar} |
| 1094 |
... |
| 1095 |
\deactivatecollection{foo} |
| 1096 |
... |
| 1097 |
\collectexercisesstop{bar} |
| 1098 |
\end{sourcecode} |
| 1099 |
Exercises will be added to each open collection. |
| 1100 |
|
| 1101 |
There is one generic collection called \enquote{\code{all exercises}}. As the |
| 1102 |
name already suggests it will hold all exercises. So if you say |
| 1103 |
\begin{sourcecode} |
| 1104 |
\printcollection{all exercises} |
| 1105 |
\end{sourcecode} |
| 1106 |
all exercises will be printed. |
| 1107 |
|
| 1108 |
\begin{bewareofthedog} |
| 1109 |
If you use \cs*{label}s inside of exercises and you print exercises more |
| 1110 |
than once in your document (by reusing a collection for example) you will |
| 1111 |
get |
| 1112 |
\begin{sourcecode} |
| 1113 |
LaTeX Warning: There were multiply-defined labels. |
| 1114 |
\end{sourcecode} |
| 1115 |
Equally if you have environments like \environ{equation} which step a |
| 1116 |
counter inside an exercise or solution the counter will be stepped each time |
| 1117 |
the exercise is used. |
| 1118 |
\end{bewareofthedog} |
| 1119 |
|
| 1120 |
At last now an example using external files, collections and tags: |
| 1121 |
\begin{sourcecode} |
| 1122 |
% preamble: |
| 1123 |
% \DeclareExerciseCollection{foo-easy} |
| 1124 |
% \DeclareExerciseCollection{foo-medium} |
| 1125 |
% \DeclareExerciseTagging{difficulty} |
| 1126 |
|
| 1127 |
% document: |
| 1128 |
\collectexercises{foo-easy} |
| 1129 |
\xsimsetup{difficulty=easy} |
| 1130 |
\input{foo.tex} |
| 1131 |
\collectexercisesstop{foo-easy} |
| 1132 |
% collection `foo-easy' now contains all exercises of file `foo.tex' tagged |
| 1133 |
% with `difficulty=easy' |
| 1134 |
|
| 1135 |
\collectexercises{foo-medium} |
| 1136 |
\xsimsetup{difficulty=medium} |
| 1137 |
\input{foo.tex} |
| 1138 |
\collectexercisesstop{foo-medium} |
| 1139 |
% collection `foo-medium' now contains all exercises of file `foo.tex' |
| 1140 |
% tagged with `difficulty=medium' |
| 1141 |
\end{sourcecode} |
| 1142 |
|
| 1143 |
\begin{bewareofthedog} |
| 1144 |
The recommended usage is similar to the last example. Actually a collection |
| 1145 |
can be printed \emph{before} it is opened, too. (This needs \emph{at least} |
| 1146 |
two compilations, though.) However, it is safer printing a collection only |
| 1147 |
once and only \emph{after it has been collected}. No guaranties are given |
| 1148 |
that properties are set correctly if you use the collection before. You |
| 1149 |
usually also will make sure that the exercises in a collection are unique, |
| 1150 |
\ie, that an exercise is not part of several collections -- at least not if |
| 1151 |
both collections are printed in the same document. |
| 1152 |
\end{bewareofthedog} |
| 1153 |
|
| 1154 |
\section{Printing Random Exercises From a Collection} |
| 1155 |
\xsim\ provides the possibility of selecting random exercises from a |
| 1156 |
collection (\cf~section~\vref{sec:collecting-exercises}). |
| 1157 |
\begin{bewareofthedog} |
| 1158 |
Please be aware that this feature is \emph{not} available in \XeLaTeX! |
| 1159 |
\end{bewareofthedog} |
| 1160 |
\begin{commands} |
| 1161 |
\command{printrandomexercises}[\oarg{options}\marg{number}] |
| 1162 |
This command prints \meta{number} random exercises from the collection |
| 1163 |
chosen with option \option{collection}, see below. When this command is |
| 1164 |
used it generates a random list of integers which is written to the |
| 1165 |
\code{aux} file. On the subsequent compilations the according exercises |
| 1166 |
are printed. \emph{If you want to regenerate the random list you have to |
| 1167 |
delete the \code{aux} file before compiling.} |
| 1168 |
\end{commands} |
| 1169 |
Valid options for this command are: |
| 1170 |
\begin{options} |
| 1171 |
\keybool{sort}\Module{random}\Default{true} |
| 1172 |
Determines wether the random chosen exercises should be sorted according |
| 1173 |
to their order of definition in the collection or not. |
| 1174 |
\keyval{collection}{collection}\Module{random}\Default{all exercises} |
| 1175 |
The collection from which the exercises are to be chosen from. |
| 1176 |
\keyval{exclude}{csv list of ids}\Module{random} |
| 1177 |
A list of \property{id}s or \property{ID}s of exercises \emph{not} to be |
| 1178 |
chosen. |
| 1179 |
\keychoice{print}{exercises,solutions,both}\Module{random}\Default{exercises} |
| 1180 |
Determines wether \cs{printrandomexercises} prints the exercises or the |
| 1181 |
solutions. When you choose \code{both} exercises and solutions are |
| 1182 |
printed alternately. |
| 1183 |
\end{options} |
| 1184 |
|
| 1185 |
\begin{example} |
| 1186 |
\printrandomexercises[collection=foo]{2} |
| 1187 |
\end{example} |
| 1188 |
|
| 1189 |
The example above of course doesn't make much sense but if you have a |
| 1190 |
collection which collects exercises from an external file and the exercises |
| 1191 |
haven't been printed in the document before then you will get a list of |
| 1192 |
subsequently numbered exercises. |
| 1193 |
|
| 1194 |
\section{Printing Solutions}\label{sec:printing-solutions} |
| 1195 |
|
| 1196 |
There are different commands for printing the solutions to exercises: |
| 1197 |
\begin{commands} |
| 1198 |
\command{printsolutionstype}[\sarg\oarg{options}\marg{exercise type}] |
| 1199 |
Prints the solutions of all used exercises of type \meta{exercise type}. |
| 1200 |
The starred version only prints the solutions of all printed exercises of |
| 1201 |
type \meta{exercise type}. |
| 1202 |
\command{printsolutions}[\sarg\oarg{options}] |
| 1203 |
Prints the solutions of all used exercises of all types ordered by type. |
| 1204 |
The starred version only prints the solutions of all printed exercises of |
| 1205 |
all types. |
| 1206 |
\command{printallsolutions}[\sarg\oarg{options}] |
| 1207 |
Prints the solutions of all used exercises of all types ordered by |
| 1208 |
appearance in the document. The starred version only prints the solutions |
| 1209 |
of all printed exercises of all types. |
| 1210 |
\command{printsolution}[\oarg{options}\marg{type}\marg{id}] |
| 1211 |
Prints the solution of the exercise of type \meta{type} with the |
| 1212 |
\property{id} \meta{id}. |
| 1213 |
\command{xprintsolution}[\marg{type}\marg{id}] |
| 1214 |
\sinceversion{0.16}The same as \cs{printsolution} but expands \meta{type} |
| 1215 |
and \meta{id} before it uses them. |
| 1216 |
\end{commands} |
| 1217 |
|
| 1218 |
\begin{example} |
| 1219 |
\printsolutionstype{exercise} |
| 1220 |
\end{example} |
| 1221 |
|
| 1222 |
The options can be divided into two groups. The ones in the first group |
| 1223 |
modify the layout. |
| 1224 |
\begin{options} |
| 1225 |
\keybool{headings}\Module{print-solutions}\Default{true} |
| 1226 |
If true a heading for each exercise type is inserted. |
| 1227 |
\keyval{headings-template}{template}\Module{print-solutions}\Default{default} |
| 1228 |
The heading template used when \keyis{headings}{true}. |
| 1229 |
\end{options} |
| 1230 |
|
| 1231 |
The ones in the second group set conditions selecting which solutions are |
| 1232 |
printed. If you combine those conditions a solution is printed if it meets |
| 1233 |
either of the conditions. |
| 1234 |
\begin{options} |
| 1235 |
\keychoice{section}{\default{true},false,\meta{integer}}\Module{print-solutions}% |
| 1236 |
\Default{false} |
| 1237 |
If you set \keyis{section}{true} only solutions of exercises of the |
| 1238 |
current section are printed. If you set \keyis{section}{4} only solutions |
| 1239 |
of exercises in a section with number~$4$ are printed. |
| 1240 |
\keychoice{chapter}{\default{true},false,\meta{integer}}\Module{print-solutions}% |
| 1241 |
\Default{false} |
| 1242 |
If you set \keyis{chapter}{true} only solutions of exercises of the |
| 1243 |
current chapter are printed. If you set \keyis{chapter}{4} only solutions |
| 1244 |
of exercises in a chapter with number~$4$ are printed. |
| 1245 |
\keychoice{collection}{false,\meta{collection name}}\Module{print-solutions}% |
| 1246 |
\Default{false} |
| 1247 |
If used only solutions of exercises belonging to collection |
| 1248 |
\meta{collection name} are printed. |
| 1249 |
\end{options} |
| 1250 |
|
| 1251 |
The conditions can be combined. The following call will only print solutions |
| 1252 |
from exercises in section~3 of chapter~2: |
| 1253 |
\begin{sourcecode} |
| 1254 |
\printsolutions[chapter=2,section=3] |
| 1255 |
\end{sourcecode} |
| 1256 |
|
| 1257 |
\begin{bewareofthedog} |
| 1258 |
The selection per section or per chapter relies on the \emph{counter |
| 1259 |
numbers} of the sections or chapters, respectively. This means if section |
| 1260 |
numbers are reset (\eg\ by \cs*{chapter} or \cs*{appendix}) and you have |
| 1261 |
exercises from \emph{different} sections with \emph{the same section number} |
| 1262 |
the solutions of \emph{all those exercises} will be printed. This means you |
| 1263 |
only should use the \option{section} selection when section are the top |
| 1264 |
document level headings (apart from parts) and you have no exercises in the |
| 1265 |
appendix. Similar considerations are valid for the \option{chapter} |
| 1266 |
selection. |
| 1267 |
\end{bewareofthedog} |
| 1268 |
|
| 1269 |
All options can also be set via \cs{xsimsetup} using the module |
| 1270 |
\module{print-solutions}. |
| 1271 |
|
| 1272 |
\begin{example} |
| 1273 |
\printsolutions[section=4,headings-template=per-section] |
| 1274 |
\end{example} |
| 1275 |
|
| 1276 |
\begin{example} |
| 1277 |
\printsolution{exercise}{5} |
| 1278 |
\end{example} |
| 1279 |
|
| 1280 |
\section{Grading Tables}\label{sec:grading-tables} |
| 1281 |
When you create exercises it may not only be desirable to be able to add |
| 1282 |
points and bonus-points to a question (see section~\vref{sec:goals} about |
| 1283 |
exercise goals) but also to be able to output a grading table. \xsim\ has |
| 1284 |
built-in means for this. |
| 1285 |
\begin{commands} |
| 1286 |
\command{gradingtable}[\oarg{options}] |
| 1287 |
Print a grading table. |
| 1288 |
\end{commands} |
| 1289 |
Valid options for this command are |
| 1290 |
\begin{options} |
| 1291 |
\keyval{template}{template}\Default{default} |
| 1292 |
Choose the template used for the grading table. |
| 1293 |
\keyval{type}{exercise type}\Default |
| 1294 |
Choose the exercise type for which the table is printed. |
| 1295 |
\end{options} |
| 1296 |
Both option defaults can be changed with \cs{xsimsetup} setting the options |
| 1297 |
using \module{grading-table}: |
| 1298 |
\begin{sourcecode} |
| 1299 |
\xsimsetup{ |
| 1300 |
grading-table/template = default* |
| 1301 |
} |
| 1302 |
\end{sourcecode} |
| 1303 |
|
| 1304 |
An example: |
| 1305 |
\begin{example} |
| 1306 |
\gradingtable[type=exercise] |
| 1307 |
\end{example} |
| 1308 |
|
| 1309 |
Or using the \enquote{\code{default*}} template: |
| 1310 |
\begin{example} |
| 1311 |
\gradingtable[template=default*,type=exercise] |
| 1312 |
\end{example} |
| 1313 |
|
| 1314 |
Available templates and how to define new ones are explained in |
| 1315 |
sections~\vref{sec:grad-table-templ} and~\vref{sec:template-examples}. \xsim\ |
| 1316 |
per default provides two templates \enquote{\code{default}} and |
| 1317 |
\enquote{\code{default*}}, the first one has a vertical layout, the second a |
| 1318 |
horizontal layout. Both templates can be used per type like in the examples |
| 1319 |
above or for all types at once by leaving the specification \option{type} |
| 1320 |
away: |
| 1321 |
\begin{example} |
| 1322 |
\gradingtable |
| 1323 |
\end{example} |
| 1324 |
|
| 1325 |
\section{Styling the Exercises -- Templates}\label{sec:styl-exerc-templ} |
| 1326 |
|
| 1327 |
\subsection{Background} |
| 1328 |
Whenever \xsim\ outputs something to be typeset it uses so-called templates |
| 1329 |
for the task. \xsim\ knows of three different kinds of templates: |
| 1330 |
\begin{itemize} |
| 1331 |
\item environment templates (see section~\vref{sec:envir-templ}), |
| 1332 |
\item heading templates (see section~\vref{sec:heading-templates}) and |
| 1333 |
\item grading table templates (see section~\vref{sec:grad-table-templ}) |
| 1334 |
\end{itemize} |
| 1335 |
|
| 1336 |
The most important one for the styling of the exercises are the environment |
| 1337 |
templates. Those templates give you complete control over the look and |
| 1338 |
arrangement of an exercise. To be able to do this \xsim\ provides a large |
| 1339 |
number of commands which can be used only inside template |
| 1340 |
definitions\footnote{The last sentence is wrong: those commands can be used |
| 1341 |
anywhere but most of them only give useful results inside of templates.}. |
| 1342 |
Those commands are explained in the next section. Their usage will hopefully |
| 1343 |
become clear in the examples in section~\vref{sec:template-examples}. Having |
| 1344 |
full control over the layout comes at a price: you need to be able to program |
| 1345 |
yourself in order to achieve certain layouts\footnote{I plan to incorporate |
| 1346 |
the most common layouts -- and maybe some fancy ones, too -- in the examples |
| 1347 |
section~\vref{sec:template-examples} but at the time of writing this is still |
| 1348 |
up in the air.}. |
| 1349 |
|
| 1350 |
\subsection{Templates Provided by the Package} |
| 1351 |
\xsim\ comes with a few predefined layouts: |
| 1352 |
\begin{description} |
| 1353 |
\item[\code{default}] The template activated per default and the only one |
| 1354 |
available without further action. |
| 1355 |
\item[\code{runin}] A layout rather similar to the one by package |
| 1356 |
\pkg{exsheets}, see section~\vref{sec:runin-template}. Available through |
| 1357 |
the style file \code{layouts} (see section~\vref{sec:style-files} for more |
| 1358 |
information on style files\index{style file}). |
| 1359 |
\item[\code{margin}] A layout rather similar to the one by package |
| 1360 |
\pkg{exsheets}, see section~\ref{sec:margin-template}. Available through |
| 1361 |
the style file \code{layouts}. |
| 1362 |
\item[\code{minimal}] A\sinceversion{0.13} minimalistic layout, see |
| 1363 |
section~\ref{sec:minimal-template}. As the others inspired by an |
| 1364 |
\pkg{exsheets} layout. Available through the style file \code{layouts}. |
| 1365 |
\item[\code{inline}] A\sinceversion{0.18} minimalistic layout, the same as |
| 1366 |
\code{minimal} but doesn't add \cs*{par} at the beginning and end. |
| 1367 |
Available through the style file \code{layouts}. |
| 1368 |
\item[\code{centered}] A\sinceversion{0.18} layout with a centered heading. |
| 1369 |
Available through the style file \code{layouts}. |
| 1370 |
\end{description} |
| 1371 |
|
| 1372 |
\collectexercises{layouts} |
| 1373 |
\begin{exercise}[subtitle=The Subtitle,points=2.5,ID=showlayout] |
| 1374 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, |
| 1375 |
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum |
| 1376 |
gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, |
| 1377 |
magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique |
| 1378 |
senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras |
| 1379 |
viverra metus rhoncus sem. |
| 1380 |
\end{exercise} |
| 1381 |
\collectexercisesstop{layouts} |
| 1382 |
|
| 1383 |
\listlayouts |
| 1384 |
|
| 1385 |
\subsection{Commands for Usage in Template Definitions} |
| 1386 |
\subsubsection{Goals} |
| 1387 |
\begin{commands} |
| 1388 |
\command{IfExerciseGoal\TF}[\marg{goal}\marg{relation and |
| 1389 |
value}\marg{true}\marg{false}] |
| 1390 |
Checks the sum of goal \meta{goal} against \meta{relation and value}. |
| 1391 |
\command{IfExerciseGoalSingular\TF}[\marg{goal}\marg{true}\marg{false}] |
| 1392 |
Checks if the value of the goal \meta{goal} of the current exercise |
| 1393 |
equals~$1$. This is the same as \\ |
| 1394 |
\cs{IfExerciseGoalTF}\marg{goal}\Marg{=1}\marg{true}\marg{false}. |
| 1395 |
\command{IfExerciseTypeGoalsSum\TF}[\marg{type}\marg{list of |
| 1396 |
goals}\marg{relation and value}\marg{true}\marg{false}] |
| 1397 |
Ckecks the sum of all goals in \meta{list of goals} for the exercises of |
| 1398 |
type \meta{type} against \meta{relation and value}. |
| 1399 |
\command{IfExerciseGoalsSum\TF}[\marg{type}\marg{list of |
| 1400 |
goals}\marg{relation and value}\marg{true}\marg{false}] |
| 1401 |
Ckecks the sum of all goals in \meta{list of goals} for all exercises of |
| 1402 |
all types against \meta{relation and value}. |
| 1403 |
\command{TotalExerciseTypeGoal}[\marg{goal}\marg{type}\marg{singular}\marg{plural}] |
| 1404 |
Print the sum of goal \meta{goal} for the exercises of type \meta{type} |
| 1405 |
and append \meta{singular} or \meta{plural} depending on wether the sum |
| 1406 |
equals~$1$ or not. |
| 1407 |
\command{TotalExerciseGoal}[\marg{goal}\marg{singular}\marg{plural}] |
| 1408 |
Print the sum of goal \meta{goal} for all exercises of all types |
| 1409 |
and append \meta{singular} or \meta{plural} depending on wether the sum |
| 1410 |
equals~$1$ or not. |
| 1411 |
\end{commands} |
| 1412 |
|
| 1413 |
\subsubsection{Properties} |
| 1414 |
\begin{commands} |
| 1415 |
\expandable\command{IfExercisePropertyExist\TF}[\marg{property}\marg{true}% |
| 1416 |
\marg{false}] |
| 1417 |
Tests wether an exercise property with the name \meta{property} is defined. |
| 1418 |
\expandable\command{IfExercisePropertySet\TF}[\marg{property}\marg{true}\marg{false}] |
| 1419 |
Tests wether the exercise property \meta{property} has been set for the |
| 1420 |
current exercise. |
| 1421 |
\expandable\command{GetExerciseProperty}[\marg{property}] |
| 1422 |
Retrieves the value of the property \meta{property} for the current |
| 1423 |
exercise. |
| 1424 |
\command{GetExerciseProperty\TF}[\marg{property}\marg{true}\marg{false}] |
| 1425 |
Tests wether the exercise property \meta{property} has been set for the |
| 1426 |
current exercise. Inside the \meta{true} branch you can refer to the |
| 1427 |
retrieved value either with \code{\#1} or with \cs{PropertyValue}. |
| 1428 |
\emph{This command expands its contents inside a group.} |
| 1429 |
\command{GetExerciseBody}[\Marg{exercise\textnormal{|}solution}] |
| 1430 |
\sinceversion{0.10}Retrieves the environment body of either the |
| 1431 |
\code{exercise} or the corresponding \code{solution} of the current |
| 1432 |
exercise. |
| 1433 |
\expandable\command{GetExerciseIdForProperty}[\marg{property}\marg{value}] |
| 1434 |
Retrieves the property \property{id} of the exercise where the property |
| 1435 |
\meta{property} has the value \meta{value}. \emph{This only works for |
| 1436 |
\emph{unique} properties!} |
| 1437 |
\command{GetExerciseTypeForProperty}[\marg{property}\marg{value}] |
| 1438 |
Retrieves the property \property{type} of the exercise where the |
| 1439 |
property \meta{property} has the value \meta{value}. \emph{This only |
| 1440 |
works for \emph{unique} properties!} |
| 1441 |
\command{SetExerciseProperty}[\marg{property}\marg{value}] |
| 1442 |
\changedversion{0.9}Set the property \meta{property} of the current |
| 1443 |
exercise to \meta{value}. |
| 1444 |
\command{SetExpandedExerciseProperty}[\marg{property}\marg{value}] |
| 1445 |
\sinceversion{0.9}Expand \meta{value} \cs*{edef}-like and set the property |
| 1446 |
\meta{property} of the current exercise to the result of the expansion. |
| 1447 |
\command{ExerciseSetProperty}[\marg{type}\marg{id}\marg{property}\marg{value}] |
| 1448 |
\sinceversion{0.9}Set the property \meta{property} of the exercise of type |
| 1449 |
\meta{type} and id \meta{id} to \meta{value}. |
| 1450 |
\command{ExerciseSetExpandedProperty}[\marg{type}\marg{id}\marg{property}\marg{value}] |
| 1451 |
\sinceversion{0.9}Expand \meta{value} \cs*{edef}-like and set the property |
| 1452 |
\meta{property} of the exercise of type \meta{type} and id \meta{id} to |
| 1453 |
the result of the expansion. |
| 1454 |
\expandable\command{IfExerciseBooleanProperty\TF}[\marg{property}% |
| 1455 |
\marg{true}\marg{false}] |
| 1456 |
Checks wether the boolean property \meta{property} has value \code{true} |
| 1457 |
or \meta{false} and leaves the corresponding argument in the input |
| 1458 |
stream. Gives an error if \meta{property} is not a boolean property. |
| 1459 |
\expandable\command{GetExerciseAliasProperty}[\marg{property}] |
| 1460 |
Retrieves the value of the property of which \meta{property} is an alias |
| 1461 |
of for the current exercise. |
| 1462 |
\command{SaveExerciseProperty}[\marg{property}\meta{macro}] |
| 1463 |
Saves the value of the property \meta{property} for the current |
| 1464 |
exercise in macro \meta{macro}. |
| 1465 |
\command{GlobalSaveExerciseProperty} |
| 1466 |
Globally saves the value of the property \meta{property} for the current |
| 1467 |
exercise in macro \meta{macro}. |
| 1468 |
\command{ExercisePropertyIfSet\TF}[\marg{type}\marg{id}\marg{property}% |
| 1469 |
\marg{true}\marg{false}] |
| 1470 |
Test if the property \meta{property} has been set for the exercise of type |
| 1471 |
\meta{type} with id \meta{id}. |
| 1472 |
\expandable\command{ExercisePropertyGet}[\marg{type}\marg{id}\marg{property}] |
| 1473 |
Retrieves the value of the property \meta{property} for the exercise of type |
| 1474 |
\meta{type} with id \meta{id}. |
| 1475 |
\expandable\command{ExercisePropertyGetAlias}[\marg{type}\marg{id}\marg{property}] |
| 1476 |
Retrieves the value of the property of which \meta{property} is an alias |
| 1477 |
of for the exercise of type \meta{type} with id \meta{id}. |
| 1478 |
\command{ExercisePropertySave}[\marg{type}\marg{id}\marg{property}\meta{macro}] |
| 1479 |
Saves the value of the property \meta{property} for the exercise of type |
| 1480 |
\meta{type} with id \meta{id} in macro \meta{macro}. |
| 1481 |
\command{ExercisePropertyGlobalSave}[\marg{type}\marg{id}\marg{property}\meta{macro}] |
| 1482 |
Globally saves the value of the property \meta{property} for the exercise |
| 1483 |
of type \meta{type} with id \meta{id} in macro \meta{macro}. |
| 1484 |
\end{commands} |
| 1485 |
|
| 1486 |
\subsubsection{Parameters} |
| 1487 |
\begin{commands} |
| 1488 |
\expandable\command{GetExerciseParameter}[\marg{parameter}] |
| 1489 |
Retrieves the value of the parameter \meta{paramater} for the current |
| 1490 |
exercise type. |
| 1491 |
\command{GetExerciseParameter\TF}[\marg{parameter}\marg{true}\marg{false}] |
| 1492 |
\sinceversion{0.9}Retrieves the value of the parameter \meta{paramater} |
| 1493 |
for the current exercise type. Inside the \meta{true} branch you can refer |
| 1494 |
to the retrieved value either with \code{\#1} or with \cs{ParameterValue}. |
| 1495 |
\emph{This command expands its contents inside a group.} |
| 1496 |
\expandable\command{GetExerciseName} |
| 1497 |
Retrieves the value of the parameter \parameter{exercise-name} for the |
| 1498 |
current exercise or of the parameter \parameter{solution-name} for the |
| 1499 |
current solution. |
| 1500 |
\expandable\command{GetExerciseHeadingF}[\marg{false}] |
| 1501 |
\sinceversion{0.14}Retrieves the value of the parameter |
| 1502 |
\parameter{exercise-heading} for the current exercise or of the parameter |
| 1503 |
\parameter{solution-heading} for the current solution. Inserts |
| 1504 |
\meta{false} if the corresponding parameter has not been set. |
| 1505 |
\expandable\command{ExerciseParameterGet}[\marg{type}\marg{parameter}] |
| 1506 |
Retrieves the value of the parameter \meta{parameter} for the exercise of type |
| 1507 |
\meta{type} with id \meta{id}. |
| 1508 |
\expandable\command{IfExerciseParameterSet\TF}[\marg{parameter}% |
| 1509 |
\marg{true}\marg{false}] |
| 1510 |
\sinceversion{0.9}Test if the parameter \meta{parameter} has been set for |
| 1511 |
the current exercise type. |
| 1512 |
\expandable\command{ExerciseParameterIfSet\TF}[\marg{type}\marg{parameter}% |
| 1513 |
\marg{true}\marg{false}] |
| 1514 |
\sinceversion{0.9}Test if the parameter \meta{parameter} has been set for |
| 1515 |
the exercise type \meta{type}. |
| 1516 |
\end{commands} |
| 1517 |
|
| 1518 |
\subsubsection{Tags} |
| 1519 |
\begin{commands} |
| 1520 |
\command{ForEachExerciseTag}[\marg{type}\marg{code}] |
| 1521 |
Loops over all tags of tag type \meta{type} for the current exercise |
| 1522 |
applying \meta{code} each time. Inside \meta{code} you can refer to the |
| 1523 |
corresponding tag with \code{\#1}. |
| 1524 |
\command{ListExerciseTags}[\marg{type}\marg{between}] |
| 1525 |
Lists all tags of tag type \meta{type} for the current exercise using |
| 1526 |
\meta{between} as a separator. |
| 1527 |
\command{UseExerciseTags}[\marg{type}\marg{between |
| 1528 |
two}\marg{between}\marg{between last two}] |
| 1529 |
Lists all tags of tag type \meta{type} for the current exercise using |
| 1530 |
\meta{between} as a separator and \meta{between last two} as separator |
| 1531 |
between the last two tags of the list. If the list only consists of two |
| 1532 |
tags \meta{between two} is used as separator. |
| 1533 |
\command{IfExerciseTagSet\TF}[\marg{value}\marg{true}\marg{false}] |
| 1534 |
In\sinceversion{0.11} order to insert text (also \emph{outside} of |
| 1535 |
exercises) depending on the chosen tags this command lets you check if |
| 1536 |
value \meta{value} has been set for \property{tags}. |
| 1537 |
\command{IfExerciseTopicSet\TF}[\marg{value}\marg{true}\marg{false}] |
| 1538 |
In\sinceversion{0.11} order to insert text (also \emph{outside} of |
| 1539 |
exercises) depending on the chosen tags this command lets you check if |
| 1540 |
value \meta{value} has been set for \property{topics}. |
| 1541 |
\end{commands} |
| 1542 |
|
| 1543 |
\subsubsection{Further Commands for Usage in Template Definitions} |
| 1544 |
\begin{commands} |
| 1545 |
\command{UseExerciseTemplate}[\marg{type}\marg{name}] |
| 1546 |
Retrieve template \meta{name} of type \meta{type}. This can be useful if |
| 1547 |
you want to define a template which just adds some code to an existing |
| 1548 |
template (an automated \cs*{label}, say). |
| 1549 |
\expandable\command{ExerciseType} |
| 1550 |
Can be used to refer to the current exercise type. |
| 1551 |
\expandable\command{ExerciseID} |
| 1552 |
Can be used to refer to the current exercise id. |
| 1553 |
\expandable\command{ExerciseText} |
| 1554 |
Can be used inside solutions to retrieve the text of the corresponding |
| 1555 |
solution. This is propably seldom useful as in most use cases the |
| 1556 |
exercise property \property{solution} is the easier alternative. |
| 1557 |
\expandable\command{ExerciseCollection} |
| 1558 |
Can be used in certain templates to refer to the collection that is |
| 1559 |
currently inserted. |
| 1560 |
\expandable\command{numberofusedexercises} |
| 1561 |
Holds the total number of used exercises. Useful in table template |
| 1562 |
definitions. |
| 1563 |
\expandable\command{ExerciseTableType}[\marg{code}] |
| 1564 |
In table template definitions this macro either expands to the given |
| 1565 |
exercise type or -- if no type has been given -- to \meta{code}. |
| 1566 |
\expandable\command{IfInsideSolution\TF}[\marg{true}\marg{false}] |
| 1567 |
Tests if the template is used inside a solution environment or not. |
| 1568 |
\expandable\command{IfSolutionPrint\TF}[\marg{true}\marg{false}] |
| 1569 |
Tests if the option \option{print} for the solutions of the current |
| 1570 |
\cs{ExerciseType} is set to \code{true} or \code{false}. |
| 1571 |
\command{IfExistSolution\TF}[\marg{true}\marg{false}] |
| 1572 |
\sinceversion{0.9}Tests if a solution for the current exercise exists. |
| 1573 |
\command{ForEachPrintedExerciseByType}[\marg{code}] |
| 1574 |
Loops over each \emph{printed} exercise ordered by the exercise types and |
| 1575 |
within each type by id. Inside \meta{code} you can refer to several |
| 1576 |
properties of the corresponding exercise: |
| 1577 |
\begin{itemize} |
| 1578 |
\item \code{\#1}: the type of the exercise |
| 1579 |
\item \code{\#2}: the id of the exercise |
| 1580 |
\item \code{\#3}: the \property{counter} property of the exercise |
| 1581 |
\item \code{\#4}: the \property{subtitle} property of the exercise |
| 1582 |
\item \code{\#5}: the \property{points} property of the exercise |
| 1583 |
\item \code{\#6}: the \property{bonus-points} property of the exercise |
| 1584 |
\end{itemize} |
| 1585 |
\command{ForEachUsedExerciseByType}[\marg{code}] |
| 1586 |
Loops over each \emph{used} exercise ordered by the exercise types and |
| 1587 |
within each type by id. Inside \meta{code} you can refer to several |
| 1588 |
properties of the corresponding exercise: |
| 1589 |
\begin{itemize} |
| 1590 |
\item \code{\#1}: the type of the exercise |
| 1591 |
\item \code{\#2}: the id of the exercise |
| 1592 |
\item \code{\#3}: the \property{counter} property of the exercise |
| 1593 |
\item \code{\#4}: the \property{subtitle} property of the exercise |
| 1594 |
\item \code{\#5}: the \property{points} property of the exercise |
| 1595 |
\item \code{\#6}: the \property{bonus-points} property of the exercise |
| 1596 |
\end{itemize} |
| 1597 |
\command{ForEachUsedExerciseByOrder}[\marg{code}] |
| 1598 |
Loops\sinceversion{0.21} over each \emph{used} exercise ordered by the |
| 1599 |
exercise types and within each type by the order they have been used in |
| 1600 |
the document. Inside \meta{code} you can refer to several properties of |
| 1601 |
the corresponding exercise: |
| 1602 |
\begin{itemize} |
| 1603 |
\item \code{\#1}: the type of the exercise |
| 1604 |
\item \code{\#2}: the id of the exercise |
| 1605 |
\item \code{\#3}: the \property{counter} property of the exercise |
| 1606 |
\item \code{\#4}: the \property{subtitle} property of the exercise |
| 1607 |
\item \code{\#5}: the \property{points} property of the exercise |
| 1608 |
\item \code{\#6}: the \property{bonus-points} property of the exercise |
| 1609 |
\end{itemize} |
| 1610 |
\command{ForEachPrintedExerciseByID}[\marg{code}] |
| 1611 |
Loops over each \emph{printed} exercise order by the exercise id. Inside |
| 1612 |
\meta{code} you can refer to several properties of the corresponding |
| 1613 |
exercise: |
| 1614 |
\begin{itemize} |
| 1615 |
\item \code{\#1}: the type of the exercise |
| 1616 |
\item \code{\#2}: the id of the exercise |
| 1617 |
\item \code{\#3}: the \property{counter} property of the exercise |
| 1618 |
\item \code{\#4}: the \property{subtitle} property of the exercise |
| 1619 |
\item \code{\#5}: the \property{points} property of the exercise |
| 1620 |
\item \code{\#6}: the \property{bonus-points} property of the exercise |
| 1621 |
\end{itemize} |
| 1622 |
\command{ForEachUsedExerciseByID}[\marg{code}] |
| 1623 |
Loops over each \emph{used} exercise order by the exercise id. Inside |
| 1624 |
\meta{code} you can refer to several properties of the corresponding |
| 1625 |
exercise: |
| 1626 |
\begin{itemize} |
| 1627 |
\item \code{\#1}: the type of the exercise |
| 1628 |
\item \code{\#2}: the id of the exercise |
| 1629 |
\item \code{\#3}: the \property{counter} property of the exercise |
| 1630 |
\item \code{\#4}: the \property{subtitle} property of the exercise |
| 1631 |
\item \code{\#5}: the \property{points} property of the exercise |
| 1632 |
\item \code{\#6}: the \property{bonus-points} property of the exercise |
| 1633 |
\end{itemize} |
| 1634 |
\command{XSIMprint}[\Marg{exercise|solution}\marg{type}\marg{id}] |
| 1635 |
\sincechanged{0.16}{0.17}Inserts the either the exercise or the solution |
| 1636 |
of type \meta{type} with the \property{id} or \property{ID} \meta{id}. |
| 1637 |
\command{XSIMxprint}[\Marg{exercise|solution}\marg{type}\marg{id}] |
| 1638 |
The same as \cs{XSIMprint} but expands \meta{type} and \meta{id} before it |
| 1639 |
uses them.\sincechanged{0.16}{0.17} |
| 1640 |
\expandable\command{XSIMtranslate}[\marg{keyword}] |
| 1641 |
Delivers the translation of \meta{keyword} according to the current |
| 1642 |
document language (in the meaning of a \pkg{babel}~\cite{pkg:babel} or |
| 1643 |
\pkg{polyglossia}~\cite{pkg:polyglossia} language). Existing keywords and |
| 1644 |
keyword translations (and how to add new ones) are explained in |
| 1645 |
section~\vref{sec:exerc-transl}. |
| 1646 |
\command{XSIMexpandcode}[\marg{code}] |
| 1647 |
Expands \meta{code} like \cs*{edef} does and leaves the result in the |
| 1648 |
input stream. |
| 1649 |
\expandable\command{XSIMifchapter\TF}[\marg{true}\marg{false}] |
| 1650 |
Returns \meta{true} if both a macro \cs*{chapter} and a counter |
| 1651 |
\code{chapter} are defined and \meta{false} otherwise. |
| 1652 |
\command{XSIMmixedcase}[\marg{code}] |
| 1653 |
Converts the full expansion of \meta{code} to mixed case: \\ |
| 1654 |
\verbcode+\XSIMmixedcase{this is some text}+ \XSIMmixedcase{this is some |
| 1655 |
text} \\ |
| 1656 |
\emph{This command expands \meta{code} before converting it}. |
| 1657 |
\command{XSIMputright}[\meta{macro}\marg{code}] |
| 1658 |
Extends the macro definition of \meta{macro} with \meta{code} putting it |
| 1659 |
to the right. This is more or less a local version of the LaTeX kernel |
| 1660 |
macro \cs*{g@addto@macro}. |
| 1661 |
\expandable\command{XSIMifeq\TF}[\marg{code 1}\marg{code |
| 1662 |
2}\marg{true}\marg{false}] |
| 1663 |
Checks if the full expansion of \meta{code 1} and \meta{code 2} is the |
| 1664 |
same tokenlist. |
| 1665 |
\expandable\command{XSIMifblank\TF}[\marg{code}\marg{true}\marg{false}] |
| 1666 |
Checks if the full expansion of \meta{code} is blank (\ie, if it is empty |
| 1667 |
or only consists of spaces). |
| 1668 |
\command{XSIMatbegindocument}[\marg{code}] |
| 1669 |
\sinceversion{0.16}Adds \meta{code} to \xsim's begin document hook. |
| 1670 |
Should be used inside style files instead of \cs*{AtBeginDocument}. |
| 1671 |
\command{XSIMatenddocument}[\marg{code}] |
| 1672 |
\sinceversion{0.16}Adds \meta{code} to \xsim's end document hook. |
| 1673 |
Should be used inside style files instead of \cs*{AtEndDocument}. |
| 1674 |
\end{commands} |
| 1675 |
|
| 1676 |
\subsection{Declaring Templates} |
| 1677 |
\subsubsection{Environment Templates}\label{sec:envir-templ} |
| 1678 |
\begin{commands} |
| 1679 |
\command{DeclareExerciseEnvironmentTemplate}[\marg{name}\marg{begin |
| 1680 |
code}\marg{end code}] |
| 1681 |
Declare the environment template \meta{name}. |
| 1682 |
\end{commands} |
| 1683 |
Environment templates are used by the exercise and solution environments. |
| 1684 |
Those are the templates set with the parameters \parameter{exercise-template} |
| 1685 |
and \parameter{solution-template}. |
| 1686 |
|
| 1687 |
The predefined template is called \enquote{\code{default}}, see |
| 1688 |
section~\vref{sec:exercise-templ-default}. |
| 1689 |
|
| 1690 |
\subsubsection{Heading Templates}\label{sec:heading-templates} |
| 1691 |
\begin{commands} |
| 1692 |
\command{DeclareExerciseHeadingTemplate}[\marg{name}\marg{code}] |
| 1693 |
Declare the heading template \meta{name}. |
| 1694 |
\end{commands} |
| 1695 |
Heading templates are used by \cs{printsolutions}, \cs{printsolutionstype} and |
| 1696 |
\cs{printcollection}. Those are the templates set with the option |
| 1697 |
\option{headings-template} of the modules \module{print-solutions} and |
| 1698 |
\module{print-collection}. |
| 1699 |
|
| 1700 |
The predefined templates are \enquote{\code{default}}, |
| 1701 |
\enquote{\code{collection}}, \enquote{\code{per-section}} and |
| 1702 |
\enquote{\code{per-chapter}} see section~\vref{sec:headings-templates}. |
| 1703 |
|
| 1704 |
\subsubsection{Grading Table Templates}\label{sec:grad-table-templ} |
| 1705 |
\begin{commands} |
| 1706 |
\command{DeclareExerciseTableTemplate}[\marg{name}\marg{code}] |
| 1707 |
Declare the grading table template \meta{name}. |
| 1708 |
\end{commands} |
| 1709 |
Table templates are used by \cs{gradingtable}. Those are the templates set |
| 1710 |
with the option \option{template} of module \module{grading-table} |
| 1711 |
|
| 1712 |
The predefined templates are \enquote{\code{default}} and |
| 1713 |
\enquote{\code{default*}}, see sections~\vref{sec:table-templ-default} |
| 1714 |
and~\vref{sec:table-templ-default*}. |
| 1715 |
|
| 1716 |
\subsection{Create and Use \xsim\ Style Files}\label{sec:style-files} |
| 1717 |
\index{style file|(} |
| 1718 |
|
| 1719 |
\xsim\changedversion{0.11} offers you the possibility to create own |
| 1720 |
\emph{style files}. Let's say you want to have a style called |
| 1721 |
\code{math-exam}. Then you need to save all necessary definitions in a file |
| 1722 |
called: |
| 1723 |
\begin{center} |
| 1724 |
\code{xsim.style.math-exam.code.tex} |
| 1725 |
\end{center} |
| 1726 |
The first command in the file should be \cs{xsimstyle}\Marg{math-exam}. This |
| 1727 |
file can now be loaded into your document using |
| 1728 |
\cs{loadxsimstyle}\Marg{math-exam} or by using |
| 1729 |
\cs{xsimsetup}\Marg{load-style=math-exam}: |
| 1730 |
\begin{sourcecode} |
| 1731 |
\documentclass[DIV=18,parskip=half]{scrartcl} |
| 1732 |
\usepackage[T1]{fontenc} |
| 1733 |
\usepackage[utf8]{inputenc} |
| 1734 |
|
| 1735 |
\usepackage[clear-aux]{xsim} |
| 1736 |
\loadxsimstyle{math-exam} |
| 1737 |
|
| 1738 |
\title{Math Exam \#3} |
| 1739 |
\date{2017-03-28} |
| 1740 |
\end{sourcecode} |
| 1741 |
|
| 1742 |
In this style file stuff like template and property definitions should |
| 1743 |
happen. This is more or less a convenient way to |
| 1744 |
\begin{itemize} |
| 1745 |
\item keep the preamble \enquote{clean} and |
| 1746 |
\item define re-usable styles without the need of copying the document |
| 1747 |
preamble to another document. |
| 1748 |
\end{itemize} |
| 1749 |
A style file is like a package or class file, \ie, \code{@} has category |
| 1750 |
code~11 (letter). |
| 1751 |
|
| 1752 |
The formal description of the commands: |
| 1753 |
\begin{commands} |
| 1754 |
\command{xsimstyle}[\sarg\marg{style name}] |
| 1755 |
The\changedversion{0.11} first command in a \xsim\ style file called |
| 1756 |
\code{xsim.style.\meta{style name}.code.tex} which defines the \xsim\ |
| 1757 |
style \meta{style name}. The starred version activates expl3 |
| 1758 |
syntax\footnote{Those users who want this will know what it means. If you |
| 1759 |
don't know what it means you will not need it.}. |
| 1760 |
\command{loadxsimstyle}[\marg{csv list of style names}] |
| 1761 |
Load one or more styles into the document. |
| 1762 |
\end{commands} |
| 1763 |
\begin{options} |
| 1764 |
\keyval{load-style}{csv list of style names} |
| 1765 |
Another\sinceversion{0.14} interface for \cs{loadxsimstyle}\marg{csv list |
| 1766 |
of style names}. |
| 1767 |
\end{options} |
| 1768 |
|
| 1769 |
\begin{bewareofthedog} |
| 1770 |
At the moment this mechanism offers no advantages over creating a custom |
| 1771 |
package or simply \cs*{input}ing a file. Future versions might provide |
| 1772 |
additional features. |
| 1773 |
\end{bewareofthedog} |
| 1774 |
|
| 1775 |
\index{style file|)} |
| 1776 |
|
| 1777 |
\subsection{Examples}\label{sec:template-examples} |
| 1778 |
|
| 1779 |
The repository of this package\footnote{GitHub: |
| 1780 |
\url{https://github.com/cgnieder/xsim/}, CTAN: |
| 1781 |
\url{http://www.ctan.org/pkg/xsim/}} currently includes |
| 1782 |
\theexamplefiles~example documents demonstrating how different aspects of this |
| 1783 |
package work or how different kinds of problems can be solved or how different |
| 1784 |
kinds of layouts can be achieved as well as how solve concrete problems that |
| 1785 |
have come up in different \LaTeX\ forums, see |
| 1786 |
section~\vref{sec:example-files}. |
| 1787 |
|
| 1788 |
\subsubsection{The \code{default} Exercise Template}\label{sec:exercise-templ-default} |
| 1789 |
|
| 1790 |
Below the definition\changedversion{0.14} of the \code{default} exercise |
| 1791 |
template provided by \xsim\ is shown: |
| 1792 |
|
| 1793 |
\begin{sourcecode} |
| 1794 |
\DeclareExerciseEnvironmentTemplate{default}{% |
| 1795 |
\GetExerciseHeadingF{\subsection*}% |
| 1796 |
{% |
| 1797 |
\XSIMmixedcase{\GetExerciseName}\nobreakspace |
| 1798 |
\GetExerciseProperty{counter}% |
| 1799 |
\IfInsideSolutionF |
| 1800 |
{% |
| 1801 |
\GetExercisePropertyT{subtitle} |
| 1802 |
{ {\normalfont\itshape\PropertyValue}}% |
| 1803 |
}% |
| 1804 |
} |
| 1805 |
\GetExercisePropertyT{points} |
| 1806 |
{% |
| 1807 |
\marginpar |
| 1808 |
{% |
| 1809 |
\IfInsideSolutionF{\rule{1.2cm}{1pt}\slash}% |
| 1810 |
\printgoal{\PropertyValue} |
| 1811 |
\GetExercisePropertyT{bonus-points}{~(+\printgoal{\PropertyValue})}% |
| 1812 |
~\XSIMtranslate {point-abbr}% |
| 1813 |
}% |
| 1814 |
}% |
| 1815 |
} |
| 1816 |
{\par} |
| 1817 |
\end{sourcecode} |
| 1818 |
|
| 1819 |
\subsubsection{A New Exercise Type Using \pkg*{tcolorbox}} |
| 1820 |
Let's say we want exercises to be put in a \env*{tcolorbox}. We want a bold |
| 1821 |
title and. if given, an italic subtitle. Exercises should also have the |
| 1822 |
points after the subtitle in parentheses if given. Let's also say we want |
| 1823 |
those to be an additional exercise type in addition to the ones \xsim\ already |
| 1824 |
provides. This is shown with the following code which is also how the |
| 1825 |
problems in this manual have been defined: |
| 1826 |
|
| 1827 |
\begin{sourcecode} |
| 1828 |
\DeclareExerciseEnvironmentTemplate{tcolorbox} |
| 1829 |
{% |
| 1830 |
\tcolorbox[ |
| 1831 |
colback = red!5!white , |
| 1832 |
colframe = red!75!black , |
| 1833 |
colbacktitle = yellow!50!red , |
| 1834 |
coltitle = red!25!black , |
| 1835 |
breakable , |
| 1836 |
drop shadow , |
| 1837 |
beforeafter skip = .5\baselineskip , |
| 1838 |
title = |
| 1839 |
\textbf{\GetExerciseName~\GetExerciseProperty{counter}}% |
| 1840 |
\GetExercisePropertyT{subtitle}{ \textit{\PropertyValue}}% |
| 1841 |
\IfInsideSolutionF{% |
| 1842 |
\GetExercisePropertyT{points}{ % notice the space |
| 1843 |
(% |
| 1844 |
\printgoal{\PropertyValue} |
| 1845 |
\IfExerciseGoalSingularTF{points} |
| 1846 |
{\XSIMtranslate{point}} |
| 1847 |
{\XSIMtranslate{points}}% |
| 1848 |
)% |
| 1849 |
}% |
| 1850 |
}% |
| 1851 |
]% |
| 1852 |
} |
| 1853 |
{\endtcolorbox} |
| 1854 |
|
| 1855 |
\DeclareExerciseType{problem}{ |
| 1856 |
exercise-env = problem , |
| 1857 |
solution-env = answer , |
| 1858 |
exercise-name = Problem , |
| 1859 |
solution-name = Answer , |
| 1860 |
exercise-template = tcolorbox , |
| 1861 |
solution-template = tcolorbox |
| 1862 |
} |
| 1863 |
\end{sourcecode} |
| 1864 |
|
| 1865 |
See it in action: |
| 1866 |
\begin{example} |
| 1867 |
\begin{problem}[subtitle=My subtitle,points=5] |
| 1868 |
This is a problem using a subtitle and points. |
| 1869 |
\end{problem} |
| 1870 |
\begin{answer} |
| 1871 |
This is the answer to problem~\GetExerciseProperty{counter}. |
| 1872 |
\end{answer} |
| 1873 |
\end{example} |
| 1874 |
|
| 1875 |
\subsubsection{Mimicking \pkg*{exsheets}' \code{runin} Template} |
| 1876 |
\label{sec:runin-template} |
| 1877 |
|
| 1878 |
The following example shows how you could mimick \pkg*{exsheets}' \code{runin} |
| 1879 |
template. The outcome isn't exactly the same since \pkg{exsheets} doesn't use |
| 1880 |
\cs*{marginpar} but the result should look very similar. A safer definition |
| 1881 |
would use a real sectioning command for the title. |
| 1882 |
|
| 1883 |
\begin{sourcecode} |
| 1884 |
\usepackage{needspace} |
| 1885 |
\DeclareExerciseEnvironmentTemplate{runin} |
| 1886 |
{% |
| 1887 |
\par\vspace{\baselineskip} |
| 1888 |
\Needspace*{2\baselineskip} |
| 1889 |
\noindent |
| 1890 |
\textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}}% |
| 1891 |
\GetExercisePropertyT{subtitle}{ \textit{#1}} % <<< notice the space |
| 1892 |
\IfInsideSolutionF{% |
| 1893 |
\GetExercisePropertyT{points}{% |
| 1894 |
\marginpar{% |
| 1895 |
\printgoal{\PropertyValue}% |
| 1896 |
\GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}% |
| 1897 |
\,\IfExerciseGoalSingularTF{points} |
| 1898 |
{\XSIMtranslate{point}} |
| 1899 |
{\XSIMtranslate{points}}% |
| 1900 |
}% |
| 1901 |
}% |
| 1902 |
}% |
| 1903 |
} |
| 1904 |
{} |
| 1905 |
\end{sourcecode} |
| 1906 |
|
| 1907 |
\subsubsection{Mimicking \pkg*{exsheets}' \code{margin} Template} |
| 1908 |
\label{sec:margin-template} |
| 1909 |
|
| 1910 |
The following example shows how you could mimick \pkg*{exsheets}' |
| 1911 |
\code{margin} template. |
| 1912 |
|
| 1913 |
\begin{sourcecode} |
| 1914 |
\DeclareExerciseEnvironmentTemplate{margin} |
| 1915 |
{% |
| 1916 |
\trivlist |
| 1917 |
\item[\llap{% |
| 1918 |
\smash{% |
| 1919 |
\tabular[t]{@{}r@{}} |
| 1920 |
\textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}} |
| 1921 |
\IfExercisePropertySetT{points}{% |
| 1922 |
\tabularnewline |
| 1923 |
(% |
| 1924 |
\printgoal{\GetExerciseProperty{points}}% |
| 1925 |
\GetExercisePropertyT{bonus-points}{+\printgoal{#1}}% |
| 1926 |
\,\XSIMtranslate{point-abbr}% |
| 1927 |
)% |
| 1928 |
}% |
| 1929 |
\endtabular |
| 1930 |
}% |
| 1931 |
}]\relax |
| 1932 |
} |
| 1933 |
{\endtrivlist} |
| 1934 |
\end{sourcecode} |
| 1935 |
|
| 1936 |
\subsubsection{A \code{minimal} Template} |
| 1937 |
\label{sec:minimal-template} |
| 1938 |
|
| 1939 |
This shows the implementation of the \code{minimal} template: |
| 1940 |
\begin{sourcecode} |
| 1941 |
\DeclareExerciseEnvironmentTemplate{minimal} |
| 1942 |
{% |
| 1943 |
\par |
| 1944 |
\textbf{\GetExerciseProperty{counter}}% |
| 1945 |
\IfInsideSolutionF{% |
| 1946 |
\GetExercisePropertyT{points}{% |
| 1947 |
\GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}% |
| 1948 |
\,\IfExerciseGoalSingularTF{points} |
| 1949 |
{\XSIMtranslate{point}} |
| 1950 |
{\XSIMtranslate{points}}% |
| 1951 |
}% |
| 1952 |
}% |
| 1953 |
} |
| 1954 |
{\par} |
| 1955 |
\end{sourcecode} |
| 1956 |
|
| 1957 |
\subsubsection{The Headings Templates}\label{sec:headings-templates} |
| 1958 |
\xsim\ defines four heading templates which only differ by which text they |
| 1959 |
output: |
| 1960 |
\begin{sourcecode} |
| 1961 |
\DeclareExerciseHeadingTemplate{default} |
| 1962 |
{\section*{\XSIMtranslate{default-heading}}} |
| 1963 |
\DeclareExerciseHeadingTemplate{collection} |
| 1964 |
{\section*{\XSIMtranslate{collection-heading}}} |
| 1965 |
\DeclareExerciseHeadingTemplate{per-section} |
| 1966 |
{\section*{\XSIMtranslate{per-section-heading}}} |
| 1967 |
\DeclareExerciseHeadingTemplate{per-chapter} |
| 1968 |
{\section*{\XSIMtranslate{per-chapter-heading}}} |
| 1969 |
\end{sourcecode} |
| 1970 |
Section~\vref{sec:exerc-transl} shows how the translations are defined. |
| 1971 |
|
| 1972 |
\subsubsection{The \code{default} Table Template}\label{sec:table-templ-default} |
| 1973 |
This template is the one used for grading tables per default. It has a |
| 1974 |
vertical layout. |
| 1975 |
|
| 1976 |
\begin{sourcecode} |
| 1977 |
\DeclareExerciseTableTemplate{default}{% |
| 1978 |
\XSIMputright\ExerciseTableCode{% |
| 1979 |
\toprule |
| 1980 |
\XSIMifblankF{\ExerciseType} |
| 1981 |
{\XSIMmixedcase{\GetExerciseParameter{exercise-name}}} |
| 1982 |
& |
| 1983 |
\XSIMmixedcase{\XSIMtranslate{points}} & |
| 1984 |
\XSIMtranslate{reached} \\ |
| 1985 |
\midrule |
| 1986 |
}% |
| 1987 |
\ForEachUsedExerciseByType{% |
| 1988 |
\XSIMifeqT{#1}{\ExerciseTableType{#1}} |
| 1989 |
{% |
| 1990 |
\XSIMifblankT{\ExerciseTableType{}} |
| 1991 |
{% |
| 1992 |
\XSIMputright\ExerciseTableCode{% |
| 1993 |
\XSIMmixedcase{\ExerciseParameterGet{#1}{exercise-name} }% |
| 1994 |
}% |
| 1995 |
}% |
| 1996 |
\XSIMputright\ExerciseTableCode |
| 1997 |
{#3 & \XSIMifblankTF{#5}{\printgoal{0}}{\printgoal{#5}} & \\ }% |
| 1998 |
}% |
| 1999 |
} |
| 2000 |
\XSIMputright\ExerciseTableCode{% |
| 2001 |
\midrule |
| 2002 |
\XSIMtranslate{total} & |
| 2003 |
\XSIMifblankTF{\ExerciseType} |
| 2004 |
{\TotalExerciseGoal{points}{}{}} |
| 2005 |
{\TotalExerciseTypeGoal{\ExerciseType}{points}{}{}} & |
| 2006 |
\\ \bottomrule |
| 2007 |
}% |
| 2008 |
\XSIMexpandcode{% |
| 2009 |
\noexpand\begin{tabular}{\XSIMifblankTF{\ExerciseType}{l}{c}cc} |
| 2010 |
\noexpand\ExerciseTableCode |
| 2011 |
\noexpand\end{tabular}% |
| 2012 |
}% |
| 2013 |
} |
| 2014 |
\end{sourcecode} |
| 2015 |
|
| 2016 |
The part |
| 2017 |
\begin{sourcecode} |
| 2018 |
\XSIMifblankTF{\ExerciseType}{ ... }{ ... } |
| 2019 |
\end{sourcecode} |
| 2020 |
repeatedly checks if an exercise type has been given for the table. This |
| 2021 |
makes it possible to design the table differently if it is for one exercise |
| 2022 |
type only (the \code{true} case) or for all exercise types (the \code{false} |
| 2023 |
case). \cs*{ExerciseTableType}\marg{code} either expands to the given |
| 2024 |
exercise type or to \meta{code}. |
| 2025 |
|
| 2026 |
\subsubsection{The \code{default*} Table Template}\label{sec:table-templ-default*} |
| 2027 |
The second of the predefined grading table templates. It has a horizontal |
| 2028 |
layout. |
| 2029 |
\begin{bewareofthedog} |
| 2030 |
If you have a lot of exercises the width of a table with this layout may |
| 2031 |
exceed the text width of the document! |
| 2032 |
\end{bewareofthedog} |
| 2033 |
|
| 2034 |
\begin{sourcecode} |
| 2035 |
\DeclareExerciseTableTemplate{default*}{% |
| 2036 |
\XSIMputright\ExerciseTableCode{% |
| 2037 |
\toprule |
| 2038 |
\XSIMifblankF{\ExerciseType} |
| 2039 |
{\XSIMmixedcase{\GetExerciseParameter{exercise-name}}} |
| 2040 |
&% |
| 2041 |
}% |
| 2042 |
\ForEachUsedExerciseByType{% |
| 2043 |
\XSIMifeqT{#1}{\ExerciseTableType{#1}} |
| 2044 |
{ |
| 2045 |
\XSIMifblankT{\ExerciseTableType{}} |
| 2046 |
{% |
| 2047 |
\XSIMputright\ExerciseTableCode{% |
| 2048 |
\XSIMmixedcase{\ExerciseParameterGet{#1}{exercise-name} }% |
| 2049 |
}% |
| 2050 |
}% |
| 2051 |
\XSIMputright\ExerciseTableCode{#3 &} |
| 2052 |
}% |
| 2053 |
}% |
| 2054 |
\XSIMputright\ExerciseTableCode{% |
| 2055 |
\XSIMtranslate{total} \\ |
| 2056 |
\midrule |
| 2057 |
\XSIMmixedcase{\XSIMtranslate{points}} & |
| 2058 |
}% |
| 2059 |
\ForEachUsedExerciseByType{% |
| 2060 |
\XSIMifeqT{#1}{\ExerciseTableType{#1}} |
| 2061 |
{% |
| 2062 |
\XSIMputright\ExerciseTableCode{% |
| 2063 |
\XSIMifblankTF{#5}{\printgoal{0}}{\printgoal{#5}} &}% |
| 2064 |
}% |
| 2065 |
}% |
| 2066 |
\XSIMputright\ExerciseTableCode{% |
| 2067 |
\XSIMifblankTF{\ExerciseType} |
| 2068 |
{\TotalExerciseGoal{points}{}{}} |
| 2069 |
{\TotalExerciseTypeGoal{\ExerciseType}{points}{}{}}% |
| 2070 |
\\ \midrule |
| 2071 |
\XSIMtranslate{reached} &% |
| 2072 |
}% |
| 2073 |
\ForEachUsedExerciseByType{% |
| 2074 |
\XSIMifeqT{#1}{\ExerciseTableType{#1}} |
| 2075 |
{\XSIMputright\ExerciseTableCode{&}}% |
| 2076 |
}% |
| 2077 |
\XSIMputright\ExerciseTableCode{ \\ \bottomrule }% |
| 2078 |
\edef\numberofcolumns{% |
| 2079 |
\XSIMifblankTF{\ExerciseType} |
| 2080 |
{\numberofusedexercises} |
| 2081 |
{\csname numberof \ExerciseType s\endcsname}% |
| 2082 |
}% |
| 2083 |
\XSIMifeqF{\numberofcolumns}{0} |
| 2084 |
{% |
| 2085 |
\begin{tabular}{l*{\numberofcolumns}{c}c} |
| 2086 |
\ExerciseTableCode |
| 2087 |
\end {tabular}% |
| 2088 |
}% |
| 2089 |
} |
| 2090 |
\end{sourcecode} |
| 2091 |
|
| 2092 |
The part |
| 2093 |
\begin{sourcecode} |
| 2094 |
\XSIMifblankTF{\ExerciseType}{ ... }{ ... } |
| 2095 |
\end{sourcecode} |
| 2096 |
repeatedly checks if an exercise type has been given for the table. This |
| 2097 |
makes it possible to design the table differently if it is for one exercise |
| 2098 |
type only (the \code{true} case) or for all exercise types (the \code{false} |
| 2099 |
case). \cs*{ExerciseTableType}\marg{code} either expands to the given |
| 2100 |
exercise type or to \meta{code}. |
| 2101 |
|
| 2102 |
\section{Exercise Translations}\label{sec:exerc-transl} |
| 2103 |
|
| 2104 |
\begin{commands} |
| 2105 |
\command{DeclareExerciseTranslation}[\marg{language}\marg{keyword}\marg{translation}] |
| 2106 |
Declare the translation of \meta{keyword} for language \meta{language}. |
| 2107 |
\command{DeclareExerciseTranslations}[\marg{keyword}\marg{translations}] |
| 2108 |
Declare the translations of \meta{keyword} for several languages at once. |
| 2109 |
See an example of the usage below. |
| 2110 |
\expandable\command{XSIMtranslate}[\marg{keyword}] |
| 2111 |
Delivers the translation of \meta{keyword} according to the current |
| 2112 |
document language (in the meaning of a \pkg{babel}~\cite{pkg:babel} or |
| 2113 |
\pkg{polyglossia}~\cite{pkg:polyglossia} language). |
| 2114 |
\command{ForEachExerciseTranslation}[\marg{code}] |
| 2115 |
Loops over all translations of all keywords known to \xsim. Inside |
| 2116 |
\meta{code} you can refer to the keyword with \code{\#1}, to the language |
| 2117 |
with \code{\#2}, and to the translation with \code{\#3}. |
| 2118 |
\end{commands} |
| 2119 |
|
| 2120 |
As an example how to use \cs{DeclareExerciseTranslations} here is how the |
| 2121 |
translations for \code{exercise} have been defined: |
| 2122 |
|
| 2123 |
\begin{sourcecode} |
| 2124 |
\DeclareExerciseTranslations{exercise}{ |
| 2125 |
Fallback = exercise , |
| 2126 |
English = exercise , |
| 2127 |
French = exercice , |
| 2128 |
German = \"Ubung |
| 2129 |
} |
| 2130 |
\end{sourcecode} |
| 2131 |
|
| 2132 |
Table~\vref{tab:translation-keys} shows all existing keywords with all |
| 2133 |
predefined translations. |
| 2134 |
|
| 2135 |
\ForEachExerciseTranslation{ |
| 2136 |
\appto\translationtable{\texttt{#1} & #2 & \texttt{\detokenize{#3}} \\} |
| 2137 |
} |
| 2138 |
|
| 2139 |
\begin{longtable}{llp{.55\linewidth}} |
| 2140 |
\caption{Translation keywords predefined by \xsim.} |
| 2141 |
\label{tab:translation-keys} \\ |
| 2142 |
\toprule |
| 2143 |
\bfseries keyword & \bfseries language & \bfseries translation \\ |
| 2144 |
\midrule |
| 2145 |
\endfirsthead |
| 2146 |
\toprule |
| 2147 |
\bfseries keyword & \bfseries language & \bfseries translation \\ |
| 2148 |
\midrule |
| 2149 |
\endhead |
| 2150 |
\bottomrule |
| 2151 |
\endlastfoot |
| 2152 |
\midrule |
| 2153 |
& & \hfill\emph{continues} \\ |
| 2154 |
\endfoot |
| 2155 |
\translationtable |
| 2156 |
\end{longtable} |
| 2157 |
|
| 2158 |
\section{Cloze Tests and Blank Lines} |
| 2159 |
|
| 2160 |
Similar to \pkg{exsheets} \xsim\ provides a command \cs{blank}: |
| 2161 |
\begin{commands} |
| 2162 |
\command{blank}[\sarg\oarg{options}\marg{text to be filled in}] |
| 2163 |
Creates a blank in normal text or in an exercise but fills the text of its |
| 2164 |
argument if inside a solution. If used at the \emph{begin of a paragraph} |
| 2165 |
\cs{blank} will do two things: it will set the linespread according to an |
| 2166 |
option explained below and will insert \cs*{par} after the lines. The |
| 2167 |
starred version doesn't do these things. |
| 2168 |
\end{commands} |
| 2169 |
|
| 2170 |
Those are the options for customization: |
| 2171 |
\begin{options} |
| 2172 |
\keyval{blank-style}{code}\Module{blank}\Default{\cs*{underline}\Marg{\#1}} |
| 2173 |
Instructions for typesetting the blank cloze. Refer to the filled in |
| 2174 |
space with \code{\#1}. |
| 2175 |
\keyval{filled-style}{code}\Module{blank}\Default{\cs*{underline}\Marg{\#1}} |
| 2176 |
Instructions for typesetting the filled cloze. Refer to the filled in text |
| 2177 |
with \code{\#1} |
| 2178 |
\keyval{style}{code} |
| 2179 |
Shortcut for setting both \option{blank-style} and \option{filled-style} |
| 2180 |
at once. |
| 2181 |
\keyval{scale}{decimal number}\Module{blank}\Default{\code{1}} |
| 2182 |
Scales the blank to \meta{decimal number} times its natural width. |
| 2183 |
\keyval{width}{dim}\Module{blank}\Default |
| 2184 |
Sets the blank to a width of \meta{dim}. This takes precendence over |
| 2185 |
\option{scale}. |
| 2186 |
\keyval{linespread}{decimal number}\Module{blank}\Default{\code{1}} |
| 2187 |
Set the linespread for the blank lines. This only has an effect if |
| 2188 |
\cs{blank} is used at the begin of a paragraph. |
| 2189 |
\keyval{line-increment}{dim}\Module{blank}\Default{\code{0.001\cs*{linewidth}}} |
| 2190 |
The blank line is built in multiples of this value. If the value is too |
| 2191 |
large you may end up with uneven lines. If the value is too small you may |
| 2192 |
end up with a non-ending compilation. Experiment with values to find the |
| 2193 |
suiting one for your use case. |
| 2194 |
\keyval{line-minimum-length}{dim}\Module{blank}\Default{\code{2em}} |
| 2195 |
The minimal length a line must have before it is built step by step. |
| 2196 |
\keybool{fill}\Module{blank}\Default{false} |
| 2197 |
If set to true, this will show the correct answers in the blanks within |
| 2198 |
an exercise as well. |
| 2199 |
\end{options} |
| 2200 |
|
| 2201 |
\begin{example} |
| 2202 |
This is a \blank{blank} outside in normal text. |
| 2203 |
\begin{exercise} |
| 2204 |
Try to fill in \blank[width=4cm]{these} blanks. All of them |
| 2205 |
\blank{are created} by using the \cs{blank} \blank{command}. |
| 2206 |
\end{exercise} |
| 2207 |
\xsimsetup{blank/filled-style=\textcolor{red}{#1}} |
| 2208 |
\begin{solution}[print] |
| 2209 |
Try to fill in \blank[width=4cm]{these} blanks. All of them |
| 2210 |
\blank{are created} by using the \cs{blank} \blank{command}. |
| 2211 |
\end{solution} |
| 2212 |
\end{example} |
| 2213 |
A number of empty lines are easily created by setting the \option{width} |
| 2214 |
option: |
| 2215 |
\begin{example} |
| 2216 |
Write up the pros and cons of \xsim\ over \pkg{exsheets}: |
| 2217 |
|
| 2218 |
\blank[width=4.8\linewidth,linespread=1.5]{} |
| 2219 |
\end{example} |
| 2220 |
|
| 2221 |
\edef\lastsection{\arabic{section}} |
| 2222 |
|
| 2223 |
\appendix |
| 2224 |
|
| 2225 |
\section{Future Plans} |
| 2226 |
|
| 2227 |
\xsim\ is complete in so far as it is perfectly usable to create exams or |
| 2228 |
exercise and solution sections in books with the most freedom in layout |
| 2229 |
already. But still there are features which would be useful additions. Below |
| 2230 |
I list all ideas that I currently plan to add to \xsim: |
| 2231 |
\begin{itemize} |
| 2232 |
\item a document class \code{xsim-exam} for creating exams; this class |
| 2233 |
should itself feature the possibility of creating different versions of an |
| 2234 |
exam, maybe already provide multiple choice questions and so on; one could |
| 2235 |
also think about automatic creation of running headers and footers, \ie, |
| 2236 |
means for changing the layout of the exam; following the spirit of \xsim\ |
| 2237 |
this should probably be done using templates as well. |
| 2238 |
\end{itemize} |
| 2239 |
I am very open to suggestions regarding features, both in general and |
| 2240 |
specifically regarding the document class. |
| 2241 |
|
| 2242 |
\section{FAQ \& How to\dots} |
| 2243 |
This section serves as a kind of gallery showing solutions to common |
| 2244 |
problems. I expect this section to grow over the years. Some examples |
| 2245 |
especially regarding other layouts are also shown in example files added to |
| 2246 |
this package. |
| 2247 |
|
| 2248 |
\subsection{\dots Know if \xsim\ Needs Another Compilation?} |
| 2249 |
If \xsim\ wants you to recompile your document it issues a warning and writes |
| 2250 |
the following to the logfile: |
| 2251 |
\begin{sourcecode} |
| 2252 |
Package xsim Warning: Exercise properties may have changed. Rerun to get them |
| 2253 |
(xsim) synchronized. |
| 2254 |
\end{sourcecode} |
| 2255 |
So just check the logfile regularly (which you should be doing anyway) and |
| 2256 |
keep your eyes open. |
| 2257 |
|
| 2258 |
\subsection{\dots Resolve Getting Repeatedly Wrong Exercise Properties or |
| 2259 |
Wrong Exercise Lists?}\label{sec:resolve-getting} |
| 2260 |
\xsimauxfileinfo |
| 2261 |
|
| 2262 |
\subsection{\dots Resolve Strange Errors After Updating?} |
| 2263 |
\xsim\ writes a lot of stuff to the auxiliary file. An update may well change |
| 2264 |
how this is done so deleting the auxiliary file and doing a few fresh |
| 2265 |
compilations may resolve your problems. |
| 2266 |
|
| 2267 |
\subsection{\code{! TeX capacity exceeded, sorry [text input levels=15].} |
| 2268 |
Why?} |
| 2269 |
Did you try to use an exercise or solution in a macro of some sort? This |
| 2270 |
generally will fail if you also use the option \option{use-files}\footnote{The |
| 2271 |
reasons are similar to the ones given here: |
| 2272 |
\url{https://tex.stackexchange.com/a/295422/}.}. But there should never be |
| 2273 |
the need to hide the environments inside of a macro, anyway. |
| 2274 |
|
| 2275 |
\subsection{\code{Runaway argument? !File ended while scanning use of \^{}\^{}M.} Why?} |
| 2276 |
Did you try to use an exercise or solution in a macro of some sort? This |
| 2277 |
generally will fail if you also use the option \option{use-files}. But there |
| 2278 |
should never be the need to hide the environments inside of a macro, anyway. |
| 2279 |
|
| 2280 |
\subsection{\dots Put a Star (or Another Symbol) in Headings of Exercises That |
| 2281 |
Are Special?} |
| 2282 |
|
| 2283 |
The code below shows one possible modification of an exercise template which |
| 2284 |
allows to easily create bonus exercises: |
| 2285 |
\begin{sourcecode} |
| 2286 |
% preamble: |
| 2287 |
\usepackage{amsymb} |
| 2288 |
% declare boolean property: |
| 2289 |
\DeclareExerciseProperty*{bonus} |
| 2290 |
\DeclareExerciseEnvironmentTemplate{bonus} |
| 2291 |
{% |
| 2292 |
\subsection* |
| 2293 |
{% |
| 2294 |
% test for boolean property and insert star symbol if true: |
| 2295 |
\IfExerciseBooleanPropertyT{bonus}{\llap{$\bigstar$ }Bonus }% |
| 2296 |
\XSIMmixedcase{\GetExerciseName}\nobreakspace |
| 2297 |
\GetExerciseProperty{counter}% |
| 2298 |
\IfInsideSolutionF |
| 2299 |
{% |
| 2300 |
\IfExercisePropertySetT{subtitle} |
| 2301 |
{ {\normalfont\itshape\GetExerciseProperty{subtitle}}}% |
| 2302 |
}% |
| 2303 |
} |
| 2304 |
\GetExercisePropertyT{points} |
| 2305 |
{% |
| 2306 |
\marginpar |
| 2307 |
{% |
| 2308 |
\IfInsideSolutionF{\rule{1.2cm}{1pt}\slash}% |
| 2309 |
\PropertyValue |
| 2310 |
\GetExercisePropertyT{bonus-points} |
| 2311 |
{\nobreakspace(+\PropertyValue)}% |
| 2312 |
\nobreakspace\XSIMtranslate{point-abbr}% |
| 2313 |
}% |
| 2314 |
}% |
| 2315 |
} |
| 2316 |
{} |
| 2317 |
\end{sourcecode} |
| 2318 |
|
| 2319 |
The usage is now as follows: |
| 2320 |
\begin{example} |
| 2321 |
\xsimsetup{exercise/template = bonus} |
| 2322 |
% set the boolean property to true |
| 2323 |
\begin{exercise}[bonus] |
| 2324 |
A bonus question. |
| 2325 |
\end{exercise} |
| 2326 |
\end{example} |
| 2327 |
|
| 2328 |
\subsection{\dots Print All Solutions Grouped by Section?} |
| 2329 |
Here is an idea how to get a list of all solutions grouped by the section the |
| 2330 |
corresponding exercises are appearing in. |
| 2331 |
\begin{sourcecode} |
| 2332 |
% preamble: |
| 2333 |
% \usepackage{etoolbox} |
| 2334 |
% \newcounter{sections} |
| 2335 |
|
| 2336 |
% document: |
| 2337 |
\setcounter{sections}{1} |
| 2338 |
\whileboolexpr |
| 2339 |
{ test {\ifnumless{\value{sections}}{\value{section}+1}} } |
| 2340 |
{ |
| 2341 |
\printsolutions[section=\value{sections},headings-template=per-section] |
| 2342 |
\stepcounter{sections} |
| 2343 |
} |
| 2344 |
\end{sourcecode} |
| 2345 |
For this manual we then get the following list\footnote{Taking care of the |
| 2346 |
fact that we're in the appendix now which means we can't use |
| 2347 |
\cs*{value}\Marg{section}. Therefore this manual does |
| 2348 |
\cs*{edef}\cs*{lastsection}\Marg{\cs*{arabic}\Marg{section}} right before |
| 2349 |
\cs*{appendix}}. |
| 2350 |
|
| 2351 |
\newcounter{sections} |
| 2352 |
\setcounter{sections}{1} |
| 2353 |
\whileboolexpr |
| 2354 |
{ test {\ifnumless{\value{sections}}{\lastsection+1}} } |
| 2355 |
{ |
| 2356 |
\printsolutions[section=\value{sections},headings-template=per-section] |
| 2357 |
\stepcounter{sections} |
| 2358 |
} |
| 2359 |
|
| 2360 |
\section{The \pkg*{xsimverb} package}\label{sec:xsimverb-package} |
| 2361 |
\xsim\ comes bundled with another package called |
| 2362 |
\pkg{xsimverb}\xsimverbversion. This package loads a very small subset of |
| 2363 |
\xsim\ which allows to create environments that write their contents verbatim |
| 2364 |
to external files. It provides the following commands (which of course are |
| 2365 |
also available in \xsim, too): |
| 2366 |
|
| 2367 |
\begin{commands} |
| 2368 |
\command{XSIMfilewritestart}[\sarg\marg{file name}] |
| 2369 |
Start writing to the file named \meta{file name}. This should be the |
| 2370 |
\emph{last} command in the \emph{begin} definition of an environment. If |
| 2371 |
is is used in an environment with arguments where the \emph{last} argument |
| 2372 |
is optional you should check if the optional argument is given and use |
| 2373 |
the starred version if the test is negative. This is demonstrated in an |
| 2374 |
example below using \pkg{xparse}'s \cs{NewDocumentEnvironment}. \emph{If |
| 2375 |
you want an environment with only an optional argument you \emph{should} |
| 2376 |
use \pkg{xparse}'s commands to define it. Due to the way how |
| 2377 |
\cs*{newenvironment} scans for optional arguments you'll otherwise may |
| 2378 |
end up with leading spaces gobbled from the first line in your |
| 2379 |
environment.} |
| 2380 |
\command{XSIMfilewritestop} |
| 2381 |
Stop writing to the file. This should be the \emph{first} command in the |
| 2382 |
\emph{end} definition of an environment. |
| 2383 |
\command{XSIMsetfilebegin}[\marg{code}] |
| 2384 |
This command can be used to write something to the external file |
| 2385 |
\emph{before} the environment contents. Must be set before |
| 2386 |
\cs{XSIMfilewritestart} in the \emph{begin} definition. |
| 2387 |
\command{XSIMsetfilebeginX}[\marg{code}] |
| 2388 |
\sinceversion{0.21}The same as \cs{XSIMsetfilebegin} but expands its |
| 2389 |
argument first. |
| 2390 |
\command{XSIMsetfileend}[\marg{code}] |
| 2391 |
This command can be used to write something to the external file |
| 2392 |
\emph{after} the environment contents. Must be set before |
| 2393 |
\cs{XSIMfilewritestart} in the \emph{begin} definition. |
| 2394 |
\command{XSIMsetfileendX}[\marg{code}] |
| 2395 |
\sinceversion{0.21}The same as \cs{XSIMsetfileend} but expands its |
| 2396 |
argument first. |
| 2397 |
\command{XSIMgobblechars}[\marg{integer}] |
| 2398 |
Determines how many characters are cut off of the beginning of each line |
| 2399 |
of the environment body before it is written to the file. The default |
| 2400 |
value is~$0$. |
| 2401 |
\end{commands} |
| 2402 |
|
| 2403 |
The following code shows an example of how to use those commands: |
| 2404 |
\begin{sourcecode} |
| 2405 |
\documentclass{article} |
| 2406 |
\usepackage{xsimverb,listings} |
| 2407 |
|
| 2408 |
\makeatletter |
| 2409 |
\NewDocumentEnvironment{example}{o} |
| 2410 |
{% |
| 2411 |
\XSIMsetfilebeginX{\@percentchar\space file `\jobname.tmp'}% |
| 2412 |
\XSIMsetfileendX{\@percentchar\space bye bye}% |
| 2413 |
\IfNoValueTF{#1} |
| 2414 |
{\XSIMfilewritestart*{\jobname.tmp}} |
| 2415 |
{\XSIMfilewritestart{\jobname.tmp}}% |
| 2416 |
} |
| 2417 |
{% |
| 2418 |
\XSIMfilewritestop |
| 2419 |
\lstinputlisting[language={[LaTeX]TeX}]{\jobname.tmp}% |
| 2420 |
\input{\jobname.tmp} |
| 2421 |
} |
| 2422 |
\makeatother |
| 2423 |
|
| 2424 |
\begin{document} |
| 2425 |
|
| 2426 |
\begin{example} |
| 2427 |
bla bla \LaTeX |
| 2428 |
\end{example} |
| 2429 |
|
| 2430 |
\end{document} |
| 2431 |
\end{sourcecode} |
| 2432 |
|
| 2433 |
The \code{tmp} file produced by the above example will contain the following |
| 2434 |
three lines (if the file itself was called \code{test.tex}): |
| 2435 |
\begin{sourcecode} |
| 2436 |
% file `test.tmp' |
| 2437 |
bla bla \LaTeX |
| 2438 |
% bye bye |
| 2439 |
\end{sourcecode} |
| 2440 |
|
| 2441 |
\section{All Exercise Examples} |
| 2442 |
|
| 2443 |
\begin{bewareofthedog} |
| 2444 |
You will notice that some exercises from |
| 2445 |
section~\vref{sec:template-examples} look differently in this section. That |
| 2446 |
is because all exercises of a type use the template that's \emph{currently |
| 2447 |
active}. If you want exercises with a different look you should use |
| 2448 |
different exercises types. |
| 2449 |
\end{bewareofthedog} |
| 2450 |
|
| 2451 |
The following list is created with this code: |
| 2452 |
\begin{sourcecode} |
| 2453 |
\xsimsetup{exercise/template = bonus} |
| 2454 |
\printcollection[headings]{all exercises} |
| 2455 |
\end{sourcecode} |
| 2456 |
|
| 2457 |
\xsimsetup{exercise/template = bonus} |
| 2458 |
\printcollection[headings]{all exercises} |
| 2459 |
|
| 2460 |
\section{All Solution Examples} |
| 2461 |
\printsolutions |
| 2462 |
|
| 2463 |
\section{Example Documents Coming With This Package}\label{sec:example-files} |
| 2464 |
The repository of this package\footnote{GitHub: |
| 2465 |
\url{https://github.com/cgnieder/xsim/}, CTAN: |
| 2466 |
\url{http://www.ctan.org/pkg/xsim/}} currently includes |
| 2467 |
\theexamplefiles~example documents demonstrating how different aspects of this |
| 2468 |
package work or how different kinds of problems can be solved or how different |
| 2469 |
kinds of layouts can be achieved as well as how to solve concrete problems |
| 2470 |
that have come up in different \LaTeX\ forums. |
| 2471 |
|
| 2472 |
Besides showing excerpts of the code and the resulting pdf the examples below |
| 2473 |
also link to both the \code{tex} source the resulting pdf. |
| 2474 |
|
| 2475 |
\listexamplefiles |
| 2476 |
|
| 2477 |
\printbibliography |
| 2478 |
|
| 2479 |
\end{document} |