summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/exercises/exercises.dtx
blob: 4ec2313f34eac39657663facf0cd04d0bfa92c4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
% \iffalse meta-comment
%
% Copyright (C) 2000 by Roger Jud <rogerjud@outlook.com>
% -------------------------------------------------------
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.2 or later is part of all distributions of LaTeX 
% version 1999/12/01 or later.
%
% \fi
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{exercises}[2000/05/17 v1.1 .dtx exercises file]
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage{doctools}
\usepackage{hyperref}
\hypersetup{colorlinks,%
citecolor=black,%
filecolor=black,%
linkcolor=black,%
urlcolor=black,%
}
\usepackage[printsolution=true]{exercises}[2000/05/17]
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{units}
\usepackage{xcolor}
\usepackage[toc]{multitoc}
\usepackage[T1]{fontenc}
\usepackage[mono=false]{libertine}
\usepackage[scaled=0.8]{DejaVuSansMono}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}
\EnableCrossrefs         
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{exercises.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% 
% \changes{v1.0}{2015/09/19}{Initial version}
% \changes{v1.1}{2000/05/17}{Add the command ifsolutionthenelse}
%
% \GetFileInfo{exercises.sty}
%
% \DoNotIndex{\newcommand,\newenvironment}
% 
%
% \title{The \textsf{exercises} package\thanks{This document
%   corresponds to \textsf{exercises}~\fileversion, dated \filedate.}}
% \author{Roger Jud \\ \texttt{rogerjud@outlook.com}}
%
% \maketitle
%
% 
%
%
%
% \begin{abstract}
%  The package |exercises| defines the environments |exercise| and |solution|. They can be used to typeset exercices and solutions. The package allows you to customize the layout of those environments. The optional points in exercises can be added automatically.  In addition you're able to hide the solutions.
% \end{abstract}
%
%  \tableofcontents
%
%
% \newpage
%
%
% \section{Usage}
%  Install the package and put |\usepackage{exercises}| in your preamble. Notice that |exercises| loads |verbatim|, |ifthen|, |kvoptions| and |xparse|. If you have already loaded these packages using |\usepackage{verbatim, ifthen, ...}|, you should unload these therefore.
%
% Now you are able to use the environments |exercise| and |solution|. The two following sections show some code examples and the corresponding output. This is followed by some explanations and a list of all the options.
%
%
% \subsection{Basic example}
%
% The following example shows the basic usage of the two environmets. There are two exercises and two solutions. Notice that the exercises and the solutions are automatically numbered.
%
% It is important to put |printsolution=true| as an option of the package, because otherwise the solutions won't be printed. (The default value is |false|.)
%
% \iffalse
%<*example>
% \fi
\begin{latexcode}
\usepackage[printsolution=true]{exercises}

\begin{exercise}
  Calculate $1 + 1 =$
\end{exercise}

\begin{solution}
  The result is $1 + 1 = 2$
\end{solution}

\begin{exercise}
  Is this $2 + 3 = 6$ true or false. Give a reason why.
\end{exercise}

\begin{solution}
  It is false, because $2 + 3 = 5$
\end{solution}
\end{latexcode}
% \iffalse
%</example>
% \fi
%
% \emph{produces}
% 
% \begin{exercise}
% 	Calculate $1 + 1 =$
%
%
% \end{exercise}
%
% \begin{solution}
%   The result is $1 + 1 = 2$
%
%
% \end{solution}
%
% \begin{exercise}
%   Is this $2 + 3 = 6$ true or false. Give a reason why.
% \end{exercise}
%
% \begin{solution}
%   It is false, because $2 + 3 = 5$
% \end{solution}
%
%
%
% \subsection{Optional arguments}
%
% The |exercise|-environment has a optional argument -- the points. The |solution|-environment has also a optional argument -- the space which is left blank, if the solutions are hidden.
%
% \iffalse
%<*example>
% \fi
\begin{latexcode}
\usepackage[printsolution=true]{exercises}

\begin{exercise}[2]
  Calculate $1 + 1 =$
\end{exercise}

\begin{solution}[3cm]
  The result is $1 + 1 = 2$
\end{solution}

\begin{exercise}[2]
  Is this $2 + 3 = 6$ true or false. Give a reason why.
\end{exercise}

\begin{solution}[2cm]
  It is false, because $2 + 3 = 5$
\end{solution}
\end{latexcode}
% \iffalse
%</example>
% \fi
%
% \emph{produces}
%
% \begin{exercise}[1]
%   Calculate $1 + 1 =$
% \end{exercise}
% 
% \begin{solution}[3cm]
%   The result is $1 + 1 = 2$
% \end{solution}
%
%
% \begin{exercise}[2]
%   Is this $2 + 3 = 6$ true or false. Give a reason why.
% \end{exercise}
%
% \begin{solution}[2cm]
%   It is false, because $2 + 3 = 5$
% \end{solution}
%
%
%
% \subsection{Sum of points}
%
% The points of all exercises are added. The command \cs{totalpoints} can be used to print the sum of the points. The word |Pt.| will be added automatically. You can customize it using the package option |totalpointsname=|\meta{string}. (See also the following section.)
% 
% \iffalse
%<*example>
% \fi
\begin{latexcode}
Sum of points: \totalpoints
\end{latexcode}
% \iffalse
%</example>
% \fi
% 
% \emph{produces}
%
% Sum of points: \totalpoints
%
%
%
%
%
%
%
%
% \section{Options}
% This package uses the key-value-format for the package options. You can choose them while loading the package.
% 
% \cs{usepackage}\oarg{option}|{exercises}|
%
% The following options are available:
% \begin{itemize}
%   \item |printsolution=|\meta{boolean}:  
%   \begin{itemize}
%     \item |printsolution=false| \emph{(default)}\hspace{0.5em} The content between |\begin{solution}| and |\end{solution}| is not printed.
%     \item |printsolution=true|\hspace{2ex}  The solutions are printed.
%   \end{itemize}
%   \item |exercisespaceabove=|\meta{length} \hspace{0.5em} Space above the |exercise|-environment. \newline \hspace*{0.5em} \emph{default value:} \unit[2.0]{ex} plus \unit[1.0]{ex} minus \unit[0.5]{ex}
%   \item |exercisespacebelow=|\meta{length} \hspace{0.5em} Space below the |exercise|-environment. \newline \hspace*{0.5em} \emph{default value:} \unit[1.5]{ex} plus \unit[1.0]{ex} minus \unit[0.5]{ex}
%   \item |solutionspaceabove=|\meta{length} \hspace{0.5em} Space above the |solution|-environment. \newline \hspace*{0.5em} \emph{default value:} \unit[2.0]{ex} plus \unit[1.0]{ex} minus \unit[0.5]{ex}
%   \item |solutionspacebelow=|\meta{length} \hspace{0.5em} Space below the |solution|-environment. \newline \hspace*{0.5em} \emph{default value:} \unit[1.5]{ex} plus \unit[1.0]{ex} minus \unit[0.5]{ex}
%   \item |blockspace=|\meta{length} \hspace{0.5em} Space below |exercisename| respectively |solutionname|, if |exercisenameposition| respectively |solutionnameposition| is set to |block|. \newline \hspace*{0.5em} \emph{default value:} \unit[0.25]{ex}
%   \item |inlinespace=|\meta{length} \hspace{0.5em} Space after |exercisename| respectively |solutionname|, if |exercisenameposition| respectively |solutionnameposition| is set to  |inline|. \newline \hspace*{0.5em} \emph{default value:} \unit[0.5]{em}
%   \item |exercisenumberformat=|\meta{string} \hspace{0.5em} It defines the number format for the numbering of the exercises and the solutions. You can choose from the following:
%   \begin{itemize}
%     \item |exercisenumberformat=arabic| \emph{(default)}\hspace{0.5em} arabic numbers
%     \item |exercisenumberformat=roman| \hspace{0.5em} small roman numbers
%     \item |exercisenumberformat=Roman| \hspace{0.5em} large roman numbers
%     \item |exercisenumberformat=alph| \hspace{0.5em} small latin letters
%     \item |exercisenumberformat=Alph| \hspace{0.5em} large latin letters
%   \end{itemize}
%   \item |pointsposition=|\meta{string}\hspace{0.5em} If you use points for the |exercise|-Environment, you can tell the package where to put them. You can choose from the following:
%   \begin{itemize}
%     \item |pointsposition=aftername| \emph{(default)} \hspace{0.5em} after the double point (Exercise 1: (3 Pt.))
%     \item |pointsposition=margin| \hspace{0.5em} at the right margin
%   \end{itemize}
%   \item |pointsfontsize=|\meta{string} \hspace{0.5em} You can shoose between two fontsizes for the points:
%   \begin{itemize}
%     \item |pointsfontsize=normalsize| \emph{(default)} \hspace{0.5em} normal fontsize (like \cs{normalsize})
%     \item |pointsfontsize=footnotesize| \hspace{0.5em} smaller fontsize (like \cs{footnotesize})
%   \end{itemize}
%   \item |pointsname=|\meta{string} \hspace{0.5em} You can select which text is displayed after the points of an exercise. \emph{(default: Pt.)}
%   \item |exercisename=|\meta{string} \hspace{0.5em} You can select which text is displayed at the beginning of an exercise. \emph{(default: Exercise)}
%   \item |exercisenameposition=|\meta{string} \hspace{0.5em} There are two ways to position the |exercisename|:
%   \begin{itemize}
%     \item |exercisenameposition=block| \emph{(default)} \hspace{0.5em} There is a line break after |exercisename| and optionally an additional vertical space (|blockspace|). 
%     \item |exercisenameposition=inline| \hspace{0.5em} There is only a horizontal space (|inlinespace|) after |exercisename|.
%   \end{itemize}
%   \item |solutionname=|\meta{string} \hspace{0.5em} You can select which text is displayed at the beginning of a solution. \emph{(default: Solution)}
%   \item |solutionnameposition=|\meta{string} \hspace{0.5em} There are two ways to position the |solutionname|:
%   \begin{itemize}
%     \item |solutionnameposition=block|: \emph{(default)} \hspace{0.5em} There is a line break after |solutionname| and optionally an additional vertical space (|blockspace|).
%     \item |solutionnameposition=inline| \hspace{0.5em} There is only a horizontal space (|inlinespace|) after |solutionname|.
%   \end{itemize}
%   \item |totalpointsname=|\meta{string} \hspace{0.5em} You can select which text is displayed after the points using the command \cs{totalpoints}. \emph{(default: Pt.)}
%   \item |braces=|\meta{string} \hspace{0.5em} You can choose between three types of braces embracing the points of an exercise:
%   \begin{itemize}
%     \item |braces=nobraces| \hspace{0.5em} no braces
%     \item |braces=round| \emph{(default)} \hspace{0.5em} round braces like (1 Pt.)
%     \item |braces=square| \hspace{0.5em} square braces like [1 Pt.]
%   \end{itemize}
%   \item |starpoints=|\meta{boolean}:  
%   \begin{itemize}
%     \item |starpoints=false| \emph{(default)} \hspace{0.5em} The points are printed as normal arabic numbers.
%     \item |starpoints=true| \hspace{0.5em} Stars (for exmaple **** for five points) are printed instead of numbers.
%   \end{itemize}
% \end{itemize}
% 
%
% \section{Special commands}
%
% \subsection{Sum of points}
% You can print the sum of points anywhere in the document using \cs{totalpoints}. \LaTeX{} needs two runs to calculate the sum. 
% 
%
% \subsection{Special page breaks}
% Custom page breaks using \cs{newpage} will move depending on wether or not to print the solutions. Because of that two new commands are available.
%
% \cs{exercisenewpage} inserts only a page break if |printsolution=false|, so if the solutions are \emph{not} printed. \cs{solutionnewpage} -- on the other hand -- inserts a page break if |printsolution=true|, so if the solutions are printed.
% 
%
%
% \subsection{Print text depending on wether the solution is printed or not}
% With the command |\ifsolutionthenelse{}{}| you can print text depending on wether the solution is printed or not. 
%	
% \iffalse
%<*example>
% \fi
\begin{latexcode}
\usepackage[printsolution=true]{exercises}
\ifsolutionthenelse{%
		\subsection*{This is the header for the solutions}%
	}%
	{%
		\subsection*{This is the header for the exercises}%
	}
\end{latexcode}
% \iffalse
%</example>
% \fi
% 
% \emph{produces}
%
% \subsection*{This is the header for the solutions}
%
%
% \emph{while}
%
%
%
%
% \iffalse
%<*example>
% \fi
\begin{latexcode}
\usepackage[printsolution=false]{exercises}
\ifsolutionthenelse{%
		\subsection*{This is the header for the solutions}%
	}%
	{%
		\subsection*{This is the header for the exercises}%
	}
\end{latexcode}
% \iffalse
%</example>
% \fi
% 
% \emph{produces}
%
% \subsection*{This is the header for the exercises}
%
% \StopEventually{\PrintChanges}
%
% \section[Implementation]{Implementation -- how I've done it (only in German)}
%
% \subsection{Benötigte Pakete}
%
% Zuerst lade ich alle benötigten Pakete. Das Paket |verbatim| benutze ich, um die Lösungen mit den Befehlen |\comment| und |\endcomment| auszukommentieren.
%    \begin{macrocode}
\RequirePackage{verbatim}
%    \end{macrocode}
% Das Paket |ifthen| hilft mit Befehlen wie |\ifthenelse|, |\equal|, |\boolean| und anderen.
%    \begin{macrocode}
\RequirePackage{ifthen}
%    \end{macrocode}
% Um eine Komma-separierte Liste von \meta{key}=\meta{value}-Optionen erstellen zu können, benötige ich das Paket |kvoptions|.
%    \begin{macrocode}
\RequirePackage{kvoptions}
%    \end{macrocode}
% Das Paket |xparse| erlaubt mir das erstellen von Befehlen und Umgebungen mit mehreren (optionalen) Argumenten.
%    \begin{macrocode}
\RequirePackage{xparse}
%    \end{macrocode}
% Das Paket |marginnote| erlaubt mir die Erstellung von Bemerkungen am Rand. Ich benutze dieses Pakte anstelle des Befehls |marginpar|, weil |marginpar| die Notiz manchmal auf einer Seite platziert. (Paket-Warnung: marginpar on page xy moved.)
%    \begin{macrocode}
\RequirePackage{marginnote}
%    \end{macrocode}
%
% In einem ersten Schritt weise ich den Wert \meta{family} (am besten der Name des Pakets) sowie \meta{prefix} (das Präfix, welches vor jeden Variabelnnamen gesetzt wird) zu. Weitere Informationen können der Dokumentation von |kvoptions| entnommen werden.
%    \begin{macrocode}
\SetupKeyvalOptions{
  family=exercises,
  prefix=exercises@}
%    \end{macrocode}
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
% \subsection{Paket-Optionen definieren}
%
% Jetzt definiere und initialisiere ich alle Paket-Optionen. Wenn der Benutzer keine Option wählt, wir der Standard-Wert (in eckigen Klammern) benutzt. Dann benutze ich den Befehl |\ProcessKeyvalOptions| um die Optionen dem Paket |exercises| zugänglich zu machen.
%    \begin{macrocode}
\DeclareBoolOption{printsolution}
\DeclareStringOption[2.0ex plus 1.0ex minus 0.5ex]{exercisespaceabove}
\DeclareStringOption[1.5ex plus 1.0ex minus 0.5ex]{exercisespacebelow}
\DeclareStringOption[2.0ex plus 1.0ex minus 0.5ex]{solutionspaceabove}
\DeclareStringOption[1.5ex plus 1.0ex minus 0.5ex]{solutionspacebelow}
\DeclareStringOption[0.25ex]{blockspace}
\DeclareStringOption[0.5em]{inlinespace}
\DeclareStringOption[arabic]{exercisenumberformat}
\DeclareStringOption[aftername]{pointsposition}
\DeclareStringOption[normalsize]{pointsfontsize}
\DeclareStringOption[Pt.]{pointsname}
\DeclareStringOption[Exercise]{exercisename}
\DeclareStringOption[block]{exercisenameposition}
\DeclareStringOption[Solution]{solutionname}
\DeclareStringOption[block]{solutionnameposition}
\DeclareStringOption[Pt.]{totalpointsname}
\DeclareStringOption[round]{braces}
\DeclareBoolOption[false]{starpoints}
\ProcessKeyvalOptions{exercises}
%    \end{macrocode}
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
% \subsection{Formatierung der Nummerierung}
%
% Ich \DescribeMacro{\exercises@formatnumbers}\ definiere einen Befehl um die Nummerierung der Übungen zu formatieren. 
%
% Wird für die Option \meta{exercisenumberformat} \meta{arabic} verwendet, so wird |\exercises@formatnumbers| so definiert, dass die Nummerierung als arabische Ziffern ausgegeben wird.
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@exercisenumberformat}{arabic}}%
  {\newcommand{\exercises@formatnumbers}[1]{\arabic{#1}}}{}%
%    \end{macrocode}
%
% Wird für die Option \meta{exercisenumberformat} \meta{roman} verwendet, so wird |\exercises@formatnumbers| so definiert, dass die Nummerierung als kleine römische Ziffern ausgegeben wird.
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@exercisenumberformat}{roman}}%
  {\newcommand{\exercises@formatnumbers}[1]{\roman{#1}}}{}%
%    \end{macrocode}
%
% Wird für die Option \meta{exercisenumberformat} \meta{Roman} verwendet, so wird |\exercises@formatnumbers| so definiert, dass die Nummerierung als grosse römische Ziffern ausgegeben wird.
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@exercisenumberformat}{Roman}}%
  {\newcommand{\exercises@formatnumbers}[1]{\Roman{#1}}}{}%
%    \end{macrocode}
%
% Wird für die Option \meta{exercisenumberformat} \meta{alph} verwendet, so wird |\exercises@formatnumbers| so definiert, dass die Nummerierung als Buchstaben ausgegeben wird.
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@exercisenumberformat}{alph}}%
  {\newcommand{\exercises@formatnumbers}[1]{\alph{#1}}}{}%
%    \end{macrocode}
%
% Wird für die Option \meta{exercisenumberformat} \meta{Alph} verwendet, so wird |\exercises@formatnumbers| so definiert, dass die Nummerierung als grosse Buchstaben ausgegeben wird.
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@exercisenumberformat}{Alph}}%
  {\newcommand{\exercises@formatnumbers}[1]{\Alph{#1}}}{}%
%    \end{macrocode}
%
% Wird für die Option \meta{exercisenumberformat} weder \meta{arabic} noch \meta{roman} noch \meta{Roman} noch \meta{alph} noch \meta{Alph} verwendet, so wird eine Fehlermeldung ausgegeben und \meta{exercisenumberformat} auf \meta{arabic} gesetzt.
%    \begin{macrocode}
\ifthenelse{\not\equal{\exercises@exercisenumberformat}{arabic}%
  \and \not\equal{\exercises@exercisenumberformat}{roman}%
  \and \not\equal{\exercises@exercisenumberformat}{Roman}%
  \and \not\equal{\exercises@exercisenumberformat}{alph}%  
  \and \not\equal{\exercises@exercisenumberformat}{Alph}}%
  {\PackageError{exercises}%
  {"\exercises@exercisenumberformat" ist als Option von "exercisenumberformat" nicht erlaubt. %
    Stattdessen wurde "arabic" verwendet.}%
  {"\exercises@exercisenumberformat" ist als Option von "exercisenumberformat" nicht erlaubt. %
  Stattdessen wurde "arabic" verwendet.}%
  \newcommand{\exercises@formatnumbers}[1]{\arabic{#1}}}{}%
%    \end{macrocode}
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
% \subsection{Positionierung der Überschriften}
%
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@exercisenameposition}{block}}%
  {\newcommand{\exercises@placeexercise}{\noindent\par\vspace{\exercises@blockspace}}}{}%
%    \end{macrocode}
%
%
%
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@exercisenameposition}{inline}}%
  {\newcommand{\exercises@placeexercise}{\hspace{\exercises@inlinespace}}}{}%
%    \end{macrocode}
%
%
%
%    \begin{macrocode}
\ifthenelse{\not\equal{\exercises@exercisenameposition}{block}%
  \and \not\equal{\exercises@exercisenameposition}{inline}}%
  {\PackageError{exercises}%
  {"\exercises@exercisenameposition" ist als Option von "exercisenameposition" nicht erlaubt. %
    Stattdessen wurde "block" verwendet.}%
  {"\exercises@exercisenameposition" ist als Option von "exercisenameposition" nicht erlaubt. %
  Stattdessen wurde "block" verwendet.}
  \newcommand{\exercises@placeexercise}{\noindent\par\vspace{\exercises@blockspace}}}{}%
%    \end{macrocode}
%
%
%
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@solutionnameposition}{block}}%
  {\newcommand{\exercises@placesolution}{\noindent\par\vspace{\exercises@blockspace}}}{}%
%    \end{macrocode}
%
%
%
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@solutionnameposition}{inline}}%
  {\newcommand{\exercises@placesolution}{\hspace{\exercises@inlinespace}}}{}%
%    \end{macrocode}
%
%
%
%    \begin{macrocode}
\ifthenelse{\not\equal{\exercises@solutionnameposition}{block}%
  \and \not\equal{\exercises@solutionnameposition}{inline}}%
  {\PackageError{exercises}%
  {"\exercises@solutionnameposition" ist als Option von "solutionnameposition" nicht erlaubt. %
    Stattdessen wurde "block" verwendet.}%
  {"\exercises@solutionnameposition" ist als Option von "solutionnameposition" nicht erlaubt. %
  Stattdessen wurde "block" verwendet.}%
  \newcommand{\exercises@placesolution}{\noindent\par\vspace{\exercises@blockspace}}}{}%
%    \end{macrocode}
%
%
%
%
%
%
%
%
%
%
%
%
% \subsection{Positionierung der Punktzahlen}
%
% Nun\DescribeMacro{\exercises@placepoints}\ werden die Befehle zur Positionierung der Punkte (falls vorhanden) definiert. Falls für die Option \meta{pointsplace} keine der Werte \meta{aftername} (Position der Punkte rechts des Doppelpunktes nach \emph{Exercise}) oder \meta{margin} (am rechten Rand) verwendet wird, gibt das Paket eine Fehlermeldung aus und verwendet die Option \meta{aftername}.
%
% Wird für die Option \meta{aftername} verwendet, so wird |\exercises@placepoints| so definiert, dass lediglich die Punktzahl ausgegeben wird.
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@pointsposition}{aftername}}%
  {\newcommand{\exercises@placepoints}[1]{ #1}}{}%
%    \end{macrocode}
%
% Wird für die Option \meta{margin} verwendet, so wird |\exercises@placepoints| so definiert, dass die Punktzahl mit Hilfe von |\marginnote| am rechten Rand ausgegeben wird.
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@pointsposition}{margin}}%
  {\newcommand{\exercises@placepoints}[1]%
    {\marginnote{#1}}}{}%
%    \end{macrocode}
%
% Wird für die Option \meta{pointsposition} weder \meta{aftername} noch \meta{margin} verwendet, so wird eine Fehlermeldung ausgegeben und \meta{pointsposition} auf \meta{aftername} gesetzt.
%    \begin{macrocode}
\ifthenelse{\not\equal{\exercises@pointsposition}{aftername}%
  \and \not\equal{\exercises@pointsposition}{margin}}%
  {\PackageError{exercises}%
  {"\exercises@pointsposition" ist als Option von "pointsposition" nicht erlaubt. %
    Stattdessen wurde "aftername" verwendet.}%
  {"\exercises@pointsposition" ist als Option von "pointsposition" nicht erlaubt. %
  Stattdessen wurde "aftername" verwendet.}%
  \newcommand{\exercises@placepoints}[1]{ #1}}{}%
%    \end{macrocode}
%
%
%
%
%
%
%
%
%

%
% \subsection{Formatierung der Punktzahlen}
%
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@pointsfontsize}{normalsize}}%
  {\newcommand{\exercises@formatpoints}[1]{\normalsize #1}}{}%
%    \end{macrocode}
%
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@pointsfontsize}{footnotesize}}%
  {\newcommand{\exercises@formatpoints}[1]{\footnotesize #1 \normalsize}}{}%
%    \end{macrocode}
%%
%    \begin{macrocode}
\ifthenelse{\not\equal{\exercises@pointsfontsize}{normalsize}%
  \and \not\equal{\exercises@pointsfontsize}{footnotesize}}%
  {\PackageError{exercises}%
  {"\exercises@pointsfontsize" ist als Option von "pointsfontsize" nicht erlaubt. %
    Stattdessen wurde "normalsize" verwendet.}%
  {"\exercises@pointsfontsize" ist als Option von "pointsfontsize" nicht erlaubt. %
  Stattdessen wurde "normalsize" verwendet.}%
  \newcommand{\exercises@formatpoints}[1]{\normalsize #1}}{}%
%    \end{macrocode}
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
% \subsection{Klammern formatieren}
%
% Nun\DescribeMacro{\exercises@braces}\ werden die Befehle zur Ausgabe der Klammern (falls vorhanden) definiert. Falls für die Option \meta{braces} keine der Werte \meta{nobraces}, \meta{round} oder \meta{square} verwendet wird, gibt das Paket eine Fehlermeldung aus und verwendet die Option \meta{round}.
%
% Wird für die Option \meta{braces} \meta{nobraces} verwendet, so wird |\exercises@braces| so definiert, dass keine Klammern ausgegeben werden.
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@braces}{nobraces}}%
  {\newcommand{\exercises@openbrace}{}%
  \newcommand{\exercises@closebrace}{}}{}%
%    \end{macrocode}
%
% Wird für die Option \meta{braces} \meta{round} verwendet, so wird |\exercises@braces| so definiert, dass runde Klammern ausgegeben werden.
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@braces}{round}}%
  {\newcommand{\exercises@openbrace}{(}%
  \newcommand{\exercises@closebrace}{)}}{}%
%    \end{macrocode}
%
% Wird für die Option \meta{braces} \meta{square} verwendet, so wird |\exercises@braces| so definiert, dass eckige Klammern ausgegeben werden.
%    \begin{macrocode}
\ifthenelse{\equal{\exercises@braces}{square}}%
  {\newcommand{\exercises@openbrace}{[}%
  \newcommand{\exercises@closebrace}{]}}{}%
%    \end{macrocode}
%
% Wird für die Option \meta{braces} weder \meta{nobraces} noch \meta{round} noch \meta{square} verwendet, so wird eine Fehlermeldung ausgegeben und \meta{braces} auf \meta{round} gesetzt.
%    \begin{macrocode}
\ifthenelse{\not\equal{\exercises@braces}{nobraces}%
  \and \not\equal{\exercises@braces}{round}%
  \and \not\equal{\exercises@braces}{square}}%
  {%
    \PackageError{exercises}%
    {"\exercises@braces" ist als Option von "braces" nicht erlaubt. %
      Stattdessen wurde "round" verwendet.}%
    {"\exercises@braces" ist als Option von "braces" nicht erlaubt. %
      Stattdessen wurde "round" verwendet.}%
    \newcommand{\exercises@openbrace}{(}%
    \newcommand{\exercises@closebrace}{)}%
  }{}%
%    \end{macrocode}
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
% \subsection{Definition von Zählern}
%
% Nun werden die Zähler zur Nummerierung der Aufgaben (\meta{exercises@exercisenumber}) und Lösungen (\meta{exercises@solutionnumber}) sowie zur Zählung der Punkte (\meta{exercises@totalpoints} und \meta{exercises@finaltotalpoints}) definiert und initialisiert.
%    \begin{macrocode}
\newcounter{exercises@totalpoints}
\setcounter{exercises@totalpoints}{0}
\newcounter{exercises@finaltotalpoints}
\newcounter{exercises@exercisenumber}
\setcounter{exercises@exercisenumber}{1}
\newcounter{exercises@solutionnumber}
\setcounter{exercises@solutionnumber}{1}
\newcounter{i}
\newlength{\exercises@parskipsave}
%    \end{macrocode}
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
% \subsection{Umgebung \texttt{exercise}}
%
%\begin{macro}{exercise}
% Der eigentliche Code folgt nun. Die Umgebung |exercise| definiert ein optionales Argument (die Punktzahl).
%    \begin{macrocode}
\DeclareDocumentEnvironment{exercise}{o}{%
\setlength{\exercises@parskipsave}{0cm}
\setlength{\exercises@parskipsave}{\parskip}
\setlength{\parskip}{0cm}
%    \end{macrocode}
%
% Der obere Abstand wird eingefügt.
%    \begin{macrocode}
  \vspace{\exercises@exercisespaceabove}%
%    \end{macrocode}
%
% Ist das optionale Argument leer (|\IfNoValueTF| also wahr), wird lediglich \meta{exercisename} (standarmässig Exercise) sowie \meta{exercisenumber} ausgegeben.
%    \begin{macrocode}
  \IfNoValueTF{#1}%
    {\textbf{\exercises@exercisename\ \exercises@formatnumbers{exercises@exercisenumber}:}\exercises@placeexercise}%
%    \end{macrocode}
%
% Ist das optionale Argument vorhanden (|\IfNoValueTF| also nicht wahr), wird zuerst \meta{totalpoints} um die Punktzahel erhöht und anschliessend \meta{exercisename} sowie \meta{exercisenumber} ausgegeben.
%    \begin{macrocode}
    {\addtocounter{exercises@totalpoints}{#1}%
    \textbf{\exercises@exercisename\ \exercises@formatnumbers{exercises@exercisenumber}:}%
%    \end{macrocode}
%
% Falls \meta{starpoints} wahr ist, wird eine Schleife zur Ausgabe der Sterne -- entsprechend der Anzahl Punkt -- gestartet.
%    \begin{macrocode}
    \ifthenelse{\boolean{exercises@starpoints}}%
      {\exercises@placepoints{\exercises@openbrace%
      \setcounter{i}{0}\whiledo{#1>\thei}{*\stepcounter{i}}%
      \exercises@closebrace}}%
%    \end{macrocode}
%
% Ist \meta{starpoints} nicht wahr ist, wird die Punktzahl ausgegeben.
%    \begin{macrocode}
      {\exercises@placepoints{\exercises@formatpoints{\exercises@openbrace#1 \exercises@pointsname\exercises@closebrace}}}\exercises@placeexercise%
  }%
\setlength{\parskip}{\exercises@parskipsave}%
}{%
\setlength{\parskip}{0cm}%
%    \end{macrocode}
% \end{macro}
%
% Der Zähler \meta{exercisenumber} wird um 1 hochgezählt und der untere Abstand wird eingefügt.
%    \begin{macrocode}
  \stepcounter{exercises@exercisenumber}%
  \vspace{\exercises@exercisespacebelow}%
\setlength{\parskip}{\exercises@parskipsave}%
}%
%    \end{macrocode}
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
% \subsection{Berechnung und Ausgabe der Gesamtpunktzahl}
%
% \begin{macro}{\totalpoints}
% Der Befehle |\totalpoints| zur Ausgabe der Gesamtpunktzahl im Dokument wird definiert. Es wird eine Referenz auf den Zähler \meta{exercises@finaltotalpoints} erstellt, welcher am Ende des Dokuments mit Hilfe von |\AtEndDocument| in die |aux|-Datei geschrieben wird.
%    \begin{macrocode}
\newcommand\totalpoints{\theexercises@finaltotalpoints\ \exercises@totalpointsname}%
%    \end{macrocode}
%
% |\immediate\write\@auxout| sorgt dafür, dass der String |\setcounter{exercises@finaltotalpoints}{\theexercises@totalpoints}| in die |aux|-Datei geschrieben wird. So wird dem Zähler \meta{exercises@finaltotalpoints} der Wert von \meta{exercises@totalpoints} übergeben. Die direkte Speicherung von \meta{exercises@totalpoints} in der |aux|-Datei ist nicht möglich, denn dann würde bei einem \LaTeX\-Lauf folgendes passieren:
% \begin{enumerate}
%   \item Das Paket |exercises| wird geladen und \meta{exercises@totalpoints} wird mit 0 initialisiert.
%   \item Bei |\begin{document}| wird die |aux|-Datei gelesen. Beim ersten Lauf ändert sich \meta{exercises@totalpoints} nicht.
%   \item Zu \meta{exercises@totalpoints} werden die Punktzahlen der einzelnen Aufgaben addiert.
%   \item Am Ende des Dokumentes wird mit |\AtEndDocument| bzw. |\immediate\write\@auxout| der aktuelle Wert von \meta{exercises@totalpoints} in die |aux|-Datei geschreiben.
%   \item Beim zweiten \LaTeX\-Lauf würde wiederum das Paket |exercises| geladen und \meta{exercises@totalpoints} mit 0 initialisiert werden.
%   \item Bei |\begin{document}| wird wiederum die |aux|-Datei gelesen. Beim diesem zweiten \LaTeX\-Lauf würde  \meta{exercises@totalpoints} nun den Wert der Gesamtpunktzahl aus dem ersten Lauf bekommen.
%   \item Zu \meta{exercises@totalpoints} werden die Punktzahlen der einzelnen Aufgaben addiert.
%   \item usw.
% \end{enumerate}
% Man erkennt, dass sich so die Gesamtpunktzahl bei jedem \LaTeX\-Lauf verdoppeln, verdreifachen usw. würde. Entsprechend wird \meta{exercises@totalpoints} jeweils am Schluss des Dokuments an \meta{exercises@finaltotalpoints} übergeben.
%    \begin{macrocode}
\AtEndDocument{\immediate\write\@auxout%
{\string\setcounter{exercises@finaltotalpoints}{\theexercises@totalpoints}}}%
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
% \subsection{Umgebung \texttt{solution}}
%
% \begin{macro}{solution}
% Die Umgebung |solution| definiert ein optionales Argument: der Abstand, welcher freigelassen werden soll, falls die Lösung nicht ausgegeben wird.
%    \begin{macrocode}
\DeclareDocumentEnvironment{solution}{o}{%
\setlength{\exercises@parskipsave}{0cm}
\setlength{\exercises@parskipsave}{\parskip}
\setlength{\parskip}{0cm}
%    \end{macrocode}
%
% Der obere Abstand wird eingefügt, falls die Lösungen ausgegeben werden.
%    \begin{macrocode}
\ifthenelse{\boolean{exercises@printsolution}}%
	{\vspace{\exercises@solutionspaceabove}}{}%
%    \end{macrocode}
%
% \meta{solutionname} und die Lösungsnummer werden ausgegeben, sofern die Lösungen überhaupt ausgegeben. Andernfalls wird der Leerraum (das optionale Argument) sowie |\comment| ausgegeben. 
%    \begin{macrocode}
\ifthenelse{\boolean{exercises@printsolution}}%
  {\textbf{\exercises@solutionname\ \exercises@formatnumbers{exercises@solutionnumber}:\exercises@placesolution}}%
  {\IfNoValueTF{#1}{}{\vspace{#1}}\comment}%
\setlength{\parskip}{\exercises@parskipsave}%
}%
%    \end{macrocode}
% Werden die Lösungen ausgegeben, so wird \meta{solutionspacebelow} ausgegeben. Andern falls folgt die Ausgabe von |\endcomment|. Zu guter Letzt wird der Zähler \meta{solutionnumber} eins hochgezählt.
%    \begin{macrocode}
{%
\setlength{\parskip}{0cm}%
\ifthenelse{\boolean{exercises@printsolution}}{\vspace{\exercises@solutionspacebelow}}%
  {\endcomment}\stepcounter{exercises@solutionnumber}\setlength{\parskip}{\exercises@parskipsave}%
\setlength{\parskip}{\exercises@parskipsave}%
}%
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
% \subsection{Befehle für die Seitenumbrüche}
%
% \begin{macro}{\exercisenewpage}
% \begin{macro}{\solutionnewpage}
% Die Befehle |exercisenewpage| und |solutionnewpage| erlauben es, einen Seitenumbruch in Abhängigkeit der Lösungsausgabe einzufügen.
%    \begin{macrocode}
\newcommand{\exercisenewpage}{\ifthenelse{\boolean{exercises@printsolution}}{}{\newpage}}
%    \end{macrocode}
%
%    \begin{macrocode}
\newcommand{\solutionnewpage}{\ifthenelse{\boolean{exercises@printsolution}}{\newpage}{}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Befehl für die bedingte Textausgabe}
%
% \begin{macro}{\ifsolutionthenelse}
% Der Befehl |ifsolutionthenelse{}{}| erlaubt es, Text in Abhängigkeit der Lösungsausgabe auszugeben.
%    \begin{macrocode}
\newcommand{\ifsolutionthenelse}[2]{\ifthenelse{\boolean{exercises@printsolution}}{#1}{#2}}
%    \end{macrocode}
%
% \end{macro}

%
% \Finale
\endinput