Debian Codegraph @

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

raw
1 % !TEX encoding = UTF-8 Unicode
2 % !TEX program = pdflatex
3 %
4 %% exercisepoints.tex
5 %% Documentation for the exercisepoints package
6 %%
7 %% Copyright (c) 2017-2019 Henning Kerstan
8 %
9 % This work may be distributed and/or modified under the
10 % conditions of the LaTeX Project Public License, either version 1.3
11 % of this license or (at your option) any later version.
12 % The latest version of this license is in
13 % http://www.latex-project.org/lppl.txt
14 % and version 1.3 or later is part of all distributions of LaTeX
15 % version 2005/12/01 or later.
16 %
17 % This work has the LPPL maintenance status `maintained'.
18 %
19 % The Current Maintainer of this work is Henning Kerstan.
20 %
21 % This work consists of the files `exercisepoints.sty' and `exercisepoints.tex'.
22 %
23
24
25 % use KOMA article in twocolumn layout
26 \documentclass[
27 twocolumn,%
28 fontsize=9pt,% this gives roughly 80 characters per line in twocolumns
29 DIV=calc,% calculate typearea
30 numbers=noendperiod% don't print periods at end of numbers
31 ]{scrartcl}
32
33
34 % font selection & set up
35 \usepackage{charter} % Charter as serif font (main text)
36 \usepackage{biolinum} % Linux Biolinum as sans serif font (headings)
37 \usepackage[scaled=0.85]{beramono} % Bera Mono as monospace font (code listings)
38 \usepackage{eulervm} % Euler virtual math fonts
39 \RequirePackage[T1]{fontenc} % T1 fontenc
40 \usepackage[final]{microtype}
41 \setkomafont{captionlabel}{\sffamily\small\bfseries}
42 \setkomafont{caption}{\sffamily\small}
43 \usepackage[english]{babel}
44
45
46 % load the exercisepoints package
47 \usepackage{exercisepoints}
48
49
50 % load xcolor for colors in code listings
51 \usepackage[dvipsnames]{xcolor}
52
53
54 % set up code listings
55 % - highlight standard LaTeX keywords in bold gray
56 % - highlight exercisepoints keywords in bold navy blue
57 \newcommand{\emphstyle}{\ttfamily\color{NavyBlue}\bfseries}%
58 \newcommand{\keyword}[1]{{\emphstyle#1}}%
59 \usepackage{listings}
60 \lstset{%
61 language=[LaTeX]TeX,%
62 basicstyle=\small\ttfamily,%
63 keywordstyle=,%\color{black!70},%
64 keywords={equal},%
65 identifierstyle=,%
66 commentstyle=\itshape\color{OliveGreen},%
67 stringstyle=,%
68 showstringspaces=false,%
69 emphstyle=\emphstyle,%
70 breaklines=true,%
71 backgroundcolor=\color{black!5},%
72 numbers=none,
73 xleftmargin=1ex,
74 xrightmargin=1ex,
75 numberstyle=\small\ttfamily,
76 numbersep=1ex,
77 emph={%
78 exercisepoints,
79 AtBeginExercise,%
80 AtEndExercise,
81 AtBeginSubexercise,%
82 AtEndSubexercise,%
83 points,%
84 itempoints,%
85 totalpoints,%
86 numberofexercises,%
87 currentexercisetitle,%
88 currentexercisepoints,%
89 currentexercisenumber,%
90 exercise,%
91 currentsubexercisetitle,%
92 currentsubexercisepoints,%
93 currentsubexercisenumber,%
94 subexercise,%
95 bonuspoints,%
96 getbonuspoints,%
97 customlayout,%
98 totalpointswithbonus,%
99 setitempointsunit
100 }
101 }
102
103
104 % obtain package version using xstring package to obtain 17 leftmost characters in the internal package version string
105 \makeatletter
106 \usepackage{xstring}
107 \newcommand{\packageversion}{\StrBefore[2]{\expandafter\csname [email protected]\endcsname}{ }}
108 \makeatother
109
110
111 % use forloop package to automatically loop through all exercises
112 \usepackage{forloop}
113
114
115 % use gitinfo2 package for displaying git commit information in footer
116 \usepackage[mark]{gitinfo2}
117
118
119 % math examples
120 \usepackage{amsmath,amssymb}
121
122
123 % set up metadata
124 \author{Henning Kerstan}
125 \title{%
126 The exercisepoints Package\thanks{%
127 \url{https://github.com/henningkerstan/exercisepoints}%
128 }
129 }
130 \subtitle{\packageversion}
131 \date{}
132
133
134 % use enumitem package and set up enumerate/itemize layout
135 \usepackage{enumitem}
136 \setlist[itemize]{%
137 leftmargin=*,%
138 itemsep=5pt,%
139 topsep=5pt,%
140 parsep=0pt,%
141 partopsep=0pt,%
142 label=\textcolor{black}{$\triangleright$}%
143 }%
144 \setlist[enumerate]{%
145 leftmargin=*,%
146 itemsep=5pt,%
147 topsep=5pt,%
148 parsep=0pt,%
149 partopsep=0pt,%
150 label=\textcolor{black}{\arabic*.},%
151 ref=\arabic*%
152 }%
153
154
155 % use hyperref for hyperlinks
156 \usepackage[
157 unicode=true,%
158 pdfa,%
159 colorlinks=false,%
160 linktoc=page,
161 pdfauthor={Henning Kerstan},
162 pdftitle={The exercisepoints Package}
163 ]{hyperref}
164
165
166 % start of the actual document
167 \begin{document}
168 \maketitle
169 \begin{abstract}
170 \noindent\itshape The exercisepoints package provides an exercise environment and several macros to count points for exercises. The actual typesetting of an exercise can be defined by the user.
171 \end{abstract}
172
173 \section{Introduction and Basic Usage}
174 This package can be used to facilitate exercise counting and exercise point counting in a \LaTeX-document. It counts the number of exercises (for example, it counted that this document has \emph{\numberofexercises\ exercises}) and it sums all the points of all exercises (for example, the package determined that the exercises in this document have a total of \emph{\totalpoints\ points}).
175
176 Especially for exams it is also common to have an overview of all exercises and their maximal points. This is also supported by this package by providing a macro to retrieve the points of each exercise. For example, the exercise overview for this document is given in Figure~\ref{fig:exercise-overview} below.
177
178 \newcounter{exercisenumber}
179 \newcounter{exercisedisplaynumber}
180 \setcounter{exercisedisplaynumber}{0}
181
182 \begin{figure}[h]\centering
183 \begin{tabular}{l|p{1cm}|r}
184 \textbf{Exercise} & \textbf{Points} & \textbf{Max. Points}\\
185 \hline
186 \forloop{exercisenumber}{0}{\value{exercisenumber} < \numberofexercises}{%
187 \stepcounter{exercisedisplaynumber}%
188 \theexercisedisplaynumber && \getpoints{\theexercisenumber}\\%
189 }%
190 Sum && \totalpoints\\\hline%
191 Bonus && \getbonuspoints\\\hline%
192 Sum with Bonus && \totalpointswithbonus%
193 \end{tabular}
194 \label{fig:exercise-overview}
195 \caption{Overview of all exercises}
196 \end{figure}
197
198 \noindent This package only provides functionality for counting and adding points, the actual typesetting of the exercise can be entirely determined by the user.
199
200 \subsection{Load the Package}
201 To use this package type
202 \begin{lstlisting}
203 \usepackage{exercisepoints}
204 \end{lstlisting}
205 anywhere in your document's preamble. If this does not work because the package is not contained in your \LaTeX-distribution, simply copy the file `exercisepoints.sty' into the same folder as your document (or, if you plan to use it more often, copy it into your local texmf directory).
206
207 \subsection{Typeset a First Exercise}
208 Now you can typeset your first exercise using the following code.
209
210 \begin{lstlisting}
211 \begin{exercise}[Simple Addition]
212 What is 1+1?\points{2.5}
213 \end{exercise}
214 \end{lstlisting}
215
216 \noindent If you typeset this without further modifications it will yield the following result.\vspace{1cm}
217
218 \begin{exercise}[Simple Addition]
219 What is $1+1$?\points{2.5}
220 \end{exercise}
221 %
222 As you can see, inside the code we used \textcolor{NavyBlue}{\ttfamily\bfseries \textbackslash points\{2.5\}} to assign this exercise a total of 2.5 points. These points were printed flushed right in the exercise header.
223
224 \subsection{Play with the Points}
225 If you issue the \textcolor{NavyBlue}{\ttfamily\bfseries \textbackslash points\{...\}} macro multiple times within an exercise environment, the points will add up. Thus let us consider the following code.
226
227 \begin{lstlisting}
228 \begin{exercise}[Simple Equation]
229 Determine a number $x$ such that $3 \cdot x = 15$\points{1.5} and explain how you did that.\points{3}
230 \end{exercise}
231 \end{lstlisting}
232
233 \noindent This code will typeset as follows.
234
235 \begin{exercise}[Simple Equation]
236 Determine a number $x$ such that $3 \cdot x = 15$\points{1.5} and explain how you did that.\points{3}
237 \end{exercise}
238
239 \noindent As expected, the points were added to obtain the total 1.5 + 3 = 4.5 points which again is printed in the exercise's header.
240
241 This feature is especially handy if you have an exercise with several subparts (items). In this case you can also use the \textcolor{NavyBlue}{\ttfamily\bfseries \textbackslash itempoints\{...\}} macro which does the same as the \textcolor{NavyBlue}{\ttfamily\bfseries \textbackslash points\{...\}} macro but additionally also prints the supplied points flush right. We rewrite our previous exercise with an enumerate environment as follows.
242
243 \begin{lstlisting}
244 \begin{exercise}[Simple Equation]\vspace{-1.5em}
245 \begin{enumerate}
246 \item Determine $x$ such that $3 \cdot x = 15$.\itempoints{1.5}
247 \item Explain how you arrived at your solution in the previous part.\itempoints{3}
248 \end{enumerate}
249 \end{exercise}
250 \end{lstlisting}
251
252 \noindent This code results in the following output.
253 \begin{exercise}[Simple Equation]\vspace{-1.5em}
254 \begin{enumerate}
255 \item Determine $x$ such that $3 \cdot x = 15$.\itempoints{1.5}
256 \item Explain how you arrived at your solution in the previous part.\itempoints{3}
257 \end{enumerate}
258 \end{exercise}
259
260 Note that by default this only displays the number of points in parentheses. If you want to add a unit, you can use
261 \begin{lstlisting}
262 \setitempointsunit{pt}{pts}
263 \end{lstlisting}
264 anywhere in your document which sets \emph{pt} (singular form) and \emph{pts} (plural form) as units for the itempoints. Afterwards, all itempoints will display this unit right of the number.\setitempointsunit{pt}{pts}
265
266 \noindent In fact, if we do this and assign the first part of the above exercise just one point instead of 1.5 (replacing \texttt{\textbackslash\keyword{itempoints}\{1.5\}} by \texttt{\textbackslash \keyword{itempoints}\{1\}}), it will be displayed as follows.
267 \begin{exercise}[Simple Equation]\vspace{-1.5em}
268 \begin{enumerate}
269 \item Determine $x$ such that $3 \cdot x = 15$.\itempoints{1}
270 \item Explain how you arrived at your solution in the previous part.\itempoints{3}
271 \end{enumerate}
272 \end{exercise}
273
274 \subsection{Obtain the Total Points}
275 If you have typeset your exercises, there are a few commands to obtain the total number of points.
276
277 \begin{itemize}
278 \item \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash numberofexercises} expands to the number of all exercises in the document.
279 \item \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash totalpoints} expands to the sum of all points of all exercises in the document.
280 \item \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash getpoints\{x\}} expands to the total points of the exercise number x (starting with $0$).
281 \end{itemize}
282 Note that the information for these macros is retrieved from the .aux file so to get the right numbers here, you have to compile your document twice. As a simple example for the above macros we take the following code.
283
284
285 \begin{lstlisting}[emph={numberofexercises,totalpoints,getpoints}]
286 Exercise 0 has \getpoints{0} points, there are \numberofexercises\ exercises with a total of \totalpoints\ points.
287 \end{lstlisting}
288
289 \noindent This compiles to the following sentence.\smallskip
290
291 Exercise 0 has \getpoints{0} points, there are \numberofexercises\ exercises with a total of \totalpoints\ points.
292
293 \subsection{Use Bonus Points}
294 In some courses it is possible to obtain a bonus for the exam. This is supported by providing the commands
295 \begin{lstlisting}
296 \bonuspoints{x}
297 \end{lstlisting}
298 which will set the total amount of bonus points to $x$ bonuspoints (in this document we have used it with $x=10$\bonuspoints{10}) and
299 \begin{lstlisting}
300 \getbonuspoints
301 \end{lstlisting}
302 which retrieves the current bonus points (in this document it expands to \getbonuspoints). Please note that the {bonuspoint} command differs from the \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash points} and \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash itempoint} commands in two aspects:
303 \begin{itemize}
304 \item Bonus points are \emph{not additive}, i.e., if you use \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash bonuspoints} multiple times in your document, only the last occurence will set the bonus points.
305 \item Bonus points are \emph{not} added to the total points. However, there is an additional macro
306 \begin{lstlisting}
307 \totalpointswithbonus
308 \end{lstlisting}
309 which will expand to the sum of \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash totalpoints} and \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash getbonuspoints}. In this document it thus expands to \totalpointswithbonus.
310 \end{itemize}
311
312 \subsection{Subexercises}
313 If you have an exercise with many different parts (for example, if you have one overall topic with several areas), you can use the subexercise environment to structure your exercise. Subexercises work exactly as exercises, but can only be used within an exercise environment. The following is a compiled example of such an exercise.
314
315 \begin{exercise}[Calculus]
316 \vspace{-1em}
317 \begin{subexercise}[Derivatives]
318 Determine the derivatives of the following functions.
319 \begin{enumerate}
320 \item $f\colon \mathbb{R} \to \mathbb{R}$, $f(x) = x^2+2x+3$ \itempoints{1}
321 \item $g\colon \mathbb{R} \to \mathbb{R}$, $g(x) = \exp(x^2)$ \itempoints{3}
322 \end{enumerate}
323 \end{subexercise}\vspace{-1em}
324 \begin{subexercise}[Maxima and Minima]
325 Determine the local maximum or minimum of the function $f\colon \mathbb{R} \to \mathbb{R}, f(x) = x^2+2x+3$.\points{3}
326 \end{subexercise}\vspace{-1em}
327 \end{exercise}
328
329 \noindent It was typeset using the following code.
330
331 \begin{lstlisting}
332 \begin{exercise}[Calculus]
333 \vspace{-1em}
334 \begin{subexercise}[Derivatives]
335 Determine the derivatives of the following functions.
336 \begin{enumerate}
337 \item $f\colon \mathbb{R} \to \mathbb{R}$,
338 $f(x) = x^2+2x+3$ \itempoints{1}
339 \item $g\colon \mathbb{R} \to \mathbb{R}$,
340 $g(x) = \exp(x^2)$ \itempoints{3}
341 \end{enumerate}
342 \end{subexercise}\vspace{-1em}
343 \begin{subexercise}[Maxima and Minima]
344 Determine the local maximum or minimum of the function
345 $f\colon \mathbb{R} \to \mathbb{R},
346 f(x) = x^2+2x+3$.\points{3}
347 \end{subexercise}
348 \end{exercise}
349 \end{lstlisting}
350
351 \noindent Note that it is only possible to use the subexercise environment within an exercise environment and it is not possible to nest subexercise environments.
352
353 \section{Exercise Layout}
354 This package only provides a minimal layout style for an exercise which is \emph{not meant to be actually used}. It is just included to test the package functionality.
355
356 \subsection{Disable the Built In Layout}
357 If you define your own layout, you can load the package (but it is not necessary) with the \textcolor{NavyBlue}{\ttfamily\bfseries customlayout} option, i.e. by issuing the command
358 \begin{lstlisting}
359 \usepackage[customlayout]{exercisepoints}
360 \end{lstlisting}
361 which disables the built in exercise style. Note that in this case your document will only compile exercises or subexercises if you have defined the respective layout. Otherwise compilation will stop with a package error message.
362
363 \subsection{Define Your Own Layout}
364 In order to define how your exercise looks like, you can use the two commands listed below.
365 \begin{lstlisting}
366 \AtBeginExercise{%
367 % your code
368 }
369
370 \AtEndExercise{%
371 % your code
372 }
373 \end{lstlisting}
374 For example, the minimal example style is implemented using the following code.
375 \begin{lstlisting}
376 \AtBeginExercise{%
377 ~\smallskip\\\sffamily%
378 \ifthenelse{\equal{\currentexercisetitle}{}}%
379 {\textbf{Exercise~\currentexercisenumber}}%
380 {%
381 \textbf{Exercise~\currentexercisenumber:} %
382 \currentexercisetitle%
383 }%
384 \,~\hfill\textbf{(\currentexercisepoints~Points)}%
385 \smallskip\\\noindent\normalfont%
386 }
387 \AtEndExercise{~\smallskip\\}%
388 \end{lstlisting}
389 As you can see, there are three useful macros that can be used for defining the exercise layout:
390 \begin{itemize}
391 \item \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash currentexercisetitle} expands to the exercise title supplied as (optional) argument to the exercise environment.
392 \item \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash currentexercisenumber} expands to the current internal exercise number (starting at $0$).
393 \item \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash currentexercisepoints} expands to the current exercise total points. Note that this is retrieved from the .aux file so to get the right number here, you have to compile your document twice.
394 \end{itemize}
395
396 \noindent For subexercises you have essentially the same commands, i.e., you have the commands
397 \begin{itemize}
398 \item \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash AtBeginSubexercise\{...\}},
399 \item \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash AtEndSubexercise\{...\}},
400 \item \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash currentsubexercisenumber},
401 \item \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash currentsubexercisepoints} and
402 \item \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash currentsubexercisetitle}
403 \end{itemize}
404 which work as their counterparts for exercises.
405
406 \subsection{Example Layout Using (Sub-)Sections}
407 One option for a custom layout could be to use sections for exercises and subsections for subexercises. This can be achieved using the following code.
408
409 \begin{lstlisting}
410 \usepackage[customlayout]{exercisepoints}
411 \AtBeginExercise{%
412 \section{\texorpdfstring{%
413 \currentexercisetitle\hfill%
414 (\currentexercisepoints~Points)}{%
415 \currentexercisetitle (\currentexercisepoints~Points)}%
416 }
417 }
418 \AtEndExercise{\clearpage}
419 \AtBeginSubexercise{%
420 \subsection{\texorpdfstring{%
421 \currentsubexercisetitle\hfill%
422 (\currentsubexercisepoints~Points)}{%
423 \currentsubexercisetitle %
424 (\currentsubexercisepoints~Points)}%
425 }
426 }
427 \AtEndSubexercise{}
428 \end{lstlisting}
429
430 \section{Copyright and License}
431 Copyright \copyright\ 2017--2019 Henning Kerstan.\medskip
432
433 \noindent This work may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3 of this license or (at your option) any later version. The latest version of this license is in\medskip
434
435 \url{http://www.latex-project.org/lppl.txt}\medskip
436
437 \noindent and version 1.3 or later is part of all distributions of LaTeX version 2005/12/01 or later.\medskip
438
439 \noindent This work has the LPPL maintenance status `maintained'.\medskip
440
441 \noindent The Current Maintainer of this work is Henning Kerstan.\medskip
442
443 \noindent This work consists of the files `exercisepoints.sty' and `exercisepoints.tex'.
444
445
446 \section{Version History}
447 \begin{description}
448 \item[\packageversion] Revised README.md.
449 \item[2019/01/02 v1.2.2] Slight revision of documentation.
450 \item[2018/08/15 v1.2.1] Renamed the package from \emph{hkexercise} to \emph{exercisepoints} to comply with CTAN rules (see \url{https://ctan.org/file/help/ctan/CTAN-upload-addendum})
451 \item[2017/02/27 v1.2.0] Added the \texttt{\textbackslash\keyword{setitempointsunit}\{...\}} command.
452 \item[2017/07/02 v1.1.0] This version introduces subexercises. Moreover several checks were added to avoid use of commands like \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash currentexercisepoints} outside of exercise environments and to prevent nesting of exercises. New option \textcolor{NavyBlue}{\ttfamily\bfseries customlayout} disables built in exercise layout. Added \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash bonuspoint} commands.
453 \item[2017/06/26 v1.0.1] Redefined \textcolor{NavyBlue}{\ttfamily\bfseries\textbackslash currentexercisepoints} so it can be used within section command.
454 \item[2017/06/26 v1.0] The initial version of this package is published on GitHub.
455 \end{description}
456 \end{document}