summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/exams/exam.dtx
blob: d3155edad7d3bdbd75fc6039f09c5a83a4162a5f (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
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
% \CheckSum{1040}
%
%\iffalse   % this is a METACOMMENT !
%
% File: exam.dtx Copyright (C) 1993-1996 Hans van der Meer
%
%    \begin{macrocode}
%<*driver>
\documentclass{ltxdoc}
\setlength\overfullrule{5pt}
\usepackage{verbatim}
\IfFileExists{exam.cls}{\def\noexamples{}}%
  {\ClassWarningNoLine{ltxdoc}{Install exam.cls first}%
    \def\noexamples{\fbox{\huge Install exam.cls first}\end{document}}}
\makeatletter
  \let\old@maketitle=\maketitle
  \let\LoadClass=\@gobble
  \let\@oldtableofcontents=\tableofcontents
  \input{exam.cls}%
  \let\tableofcontents=\@oldtableofcontents
  \let\maketitle=\old@maketitle
\makeatother
\noexamples
\ProvidesFile{exam.dtx}[1997/03/14 3.30  Slides and notes]
\GetFileInfo{exam.dtx}
\title{The \textsf{exam} package%
\thanks{This file has version \fileversion\space dated \filedate.}}
\author{Hans van der Meer\\hansm@wins.uva.nl}
\date{Printed \today}
\CodelineNumbered
\DisableCrossrefs
\RecordChanges
\begin{document}
\maketitle
\DocInput{exam.dtx}
\end{document}
%</driver>
%    \end{macrocode}
%\fi
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \changes{3.00}{1994/02/13}{First version for LaTeX2E and docstrip}
% \changes{3.01}{1994/03/24}{added mbox{} to Copyright (missing item error)}
% \changes{3.10}{1994/10/19}{updated several features}
% \changes{3.11}{1994/10/21}{added dumpitemno and ignorespace in SRset}
% \changes{3.12}{1994/10/25}{changed pagenumbering index}
% \changes{3.13}{1994/11/10}{help shows class options}
% \changes{3.14}{1994/11/24}{empty default for mainfolder, etc.}
% \changes{3.15}{1994/12/10}{default language initialization added}
% \changes{3.16}{1995/01/19}{require latest latex because of box trouble}
% \changes{3.17}{1995/01/26}{maketitle redefinition better in exam.cfg}
% \changes{3.18}{1995/02/02}{options, documentation, checksquare->boxtimes}
% \changes{3.19}{1995/03/10}{pagestyle tuned, added options}
% \changes{3.20}{1995/07/12}{table of contents problem solved}
% \changes{3.21}{1995/08/07}{writing toc-entry in question displaced}
% \changes{3.22}{1995/08/09}{folders default set to @currdir}
% \changes{3.23}{1995/10/26}{help standard, textbo removed, small changes}
% \changes{3.24}{1995/10/30}{ignorespaces added to longanswer start}
% \changes{3.25}{1995/12/17}{error in altanswer repaired}
% \changes{3.26}{1996/08/10}{cleaning, fixing loose ends, simplified where possible}
% \changes{3.27}{1996/08/19}{dir path separator changed in folder macros}
% \changes{3.28}{1996/08/23}{shortanswer changed, documentation polished}
% \changes{3.29}{1997/03/08}{directory macros changed}
% \changes{3.30}{1997/03/14}{CurrentDirectory for @currdir added}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \DoNotIndex{\#}
% \DoNotIndex{\@@input}
% \DoNotIndex{\@dblarg}
% \DoNotIndex{\@depth}
% \DoNotIndex{\@empty}
% \DoNotIndex{\@firstoftwo}
% \DoNotIndex{\@height}
% \DoNotIndex{\@ifstar}
% \DoNotIndex{\@ifundefined}
% \DoNotIndex{\@m}
% \DoNotIndex{\@makeother}
% \DoNotIndex{\@namedef}
% \DoNotIndex{\@ne}
% \DoNotIndex{\@sanitize}
% \DoNotIndex{\@secondoftwo}
% \DoNotIndex{\@tempdima}
% \DoNotIndex{\@tempdimb}
% \DoNotIndex{\@title}
% \DoNotIndex{\@warning}
% \DoNotIndex{\@whilenum}
% \DoNotIndex{\@width}
% \DoNotIndex{\\}
% \DoNotIndex{\{}
% \DoNotIndex{\}}
% \DoNotIndex{\^}
% \DoNotIndex{\ }
% \DoNotIndex{\addtolength}
% \DoNotIndex{\addvspace}
% \DoNotIndex{\advance}
% \DoNotIndex{\begin}
% \DoNotIndex{\begingroup}
% \DoNotIndex{\bgroup}
% \DoNotIndex{\bigskip}
% \DoNotIndex{\bigskipamount}
% \DoNotIndex{\box}
% \DoNotIndex{\catcode}
% \DoNotIndex{\count@}
% \DoNotIndex{\csname}
% \DoNotIndex{\def}
% \DoNotIndex{\dimen@}
% \DoNotIndex{\divide}
% \DoNotIndex{\do}
% \DoNotIndex{\dotfill}
% \DoNotIndex{\dp}
% \DoNotIndex{\edef}
% \DoNotIndex{\egroup}
% \DoNotIndex{\else}
% \DoNotIndex{\emph}
% \DoNotIndex{\end}
% \DoNotIndex{\endcsname}
% \DoNotIndex{\endgroup}
% \DoNotIndex{\endlist}
% \DoNotIndex{\enskip}
% \DoNotIndex{\enspace}
% \DoNotIndex{\ensuremath}
% \DoNotIndex{\expandafter}
% \DoNotIndex{\f@baselineskip}
% \DoNotIndex{\fbox}
% \DoNotIndex{\fi}
% \DoNotIndex{\footnotesize}
% \DoNotIndex{\gdef}
% \DoNotIndex{\global}
% \DoNotIndex{\hbox}
% \DoNotIndex{\hfil}
% \DoNotIndex{\hfill}
% \DoNotIndex{\hrule}
% \DoNotIndex{\hskip}
% \DoNotIndex{\hspace}
% \DoNotIndex{\hss}
% \DoNotIndex{\ht}
% \DoNotIndex{\if}
% \DoNotIndex{\ifcase}
% \DoNotIndex{\ifdim}
% \DoNotIndex{\ifnum}
% \DoNotIndex{\ifodd}
% \DoNotIndex{\ifx}
% \DoNotIndex{\ignorespaces}
% \DoNotIndex{\item}
% \DoNotIndex{\itemsep}
% \DoNotIndex{\leavevmode}
% \DoNotIndex{\let}
% \DoNotIndex{\list}
% \DoNotIndex{\llap}
% \DoNotIndex{\m@ne}
% \DoNotIndex{\makebox}
% \DoNotIndex{\mbox}
% \DoNotIndex{\medskip}
% \DoNotIndex{\medskipamount}
% \DoNotIndex{\multiply}
% \DoNotIndex{\newcommand}
% \DoNotIndex{\newcount}
% \DoNotIndex{\newcounter}
% \DoNotIndex{\newenvironment}
% \DoNotIndex{\newif}
% \DoNotIndex{\newlength}
% \DoNotIndex{\newpage}
% \DoNotIndex{\newsavebox}
% \DoNotIndex{\newtoks}
% \DoNotIndex{\next}
% \DoNotIndex{\noexpand}
% \DoNotIndex{\noindent}
% \DoNotIndex{\null}
% \DoNotIndex{\number}
% \DoNotIndex{\or}
% \DoNotIndex{\p@}
% \DoNotIndex{\par}
% \DoNotIndex{\parbox}
% \DoNotIndex{\parsep}
% \DoNotIndex{\partopsep}
% \DoNotIndex{\phantom}
% \DoNotIndex{\protect}
% \DoNotIndex{\providecommand}
% \DoNotIndex{\raggedright}
% \DoNotIndex{\relax}
% \DoNotIndex{\renewcommand}
% \DoNotIndex{\rlap}
% \DoNotIndex{\rmfamily}
% \DoNotIndex{\romannumeral}
% \DoNotIndex{\selectfont}
% \DoNotIndex{\setbox}
% \DoNotIndex{\setcounter}
% \DoNotIndex{\setlength}
% \DoNotIndex{\settowidth}
% \DoNotIndex{\sffamily}
% \DoNotIndex{\sloppy}
% \DoNotIndex{\small}
% \DoNotIndex{\smallskip}
% \DoNotIndex{\smallskipamount}
% \DoNotIndex{\space}
% \DoNotIndex{\stepcounter}
% \DoNotIndex{\string}
% \DoNotIndex{\strut}
% \DoNotIndex{\test}
% \DoNotIndex{\textbf}
% \DoNotIndex{\textemdash}
% \DoNotIndex{\textsl}
% \DoNotIndex{\texttt}
% \DoNotIndex{\the}
% \DoNotIndex{\thinspace}
% \DoNotIndex{\tw@}
% \DoNotIndex{\topsep}
% \DoNotIndex{\typeout}
% \DoNotIndex{\undefined}
% \DoNotIndex{\underbar}
% \DoNotIndex{\uppercase}
% \DoNotIndex{\upshape}
% \DoNotIndex{\vadjust}
% \DoNotIndex{\value}
% \DoNotIndex{\vbox}
% \DoNotIndex{\vfil}
% \DoNotIndex{\vfill}
% \DoNotIndex{\vskip}
% \DoNotIndex{\vspace}
% \DoNotIndex{\vss}
% \DoNotIndex{\wd}
% \DoNotIndex{\xdef}
% \DoNotIndex{\z@}
% \DoNotIndex{\z@skip}
%
% \begin{abstract}
% This article describes the use and the implementation of the 
% \emph{exam class}.
% Its purpose is the typesetting of exams.
% Exam questions can be multiple choice or free long\slash short
% answer questions.
% Options are the typesetting of the exam itself, an exam
% showing all the answers and a collection of questions and answers.
% Questions can be parametrized.
% Use of a random generator provides for automatic shuffling
% of multiple choice items.
% \end{abstract}
%
% \tableofcontents
%
% \section{Usage}
%
% \subsection{Exam production}
%
% An exam can be built from the following template.
% For special issues as the use of default names for
% various directories, language selection, etc. see
% the implementation section.
%
% You may customize the typesetting by providing
% a file \emph{exam.cfg} in the search path; this file
% is read just before typesetting begins.
% The example of this file gives a language customization
% and an implementation for a title page.
%
% \medskip\noindent
% \DescribeEnv{exam}
% |\documentclass[options]{exam}|\\
% |\title{title of exam}|\\
% |\author{the examinator}|\\
% |\target{the students}|\\
% |\begin{document}|\\
% |\begin{exam}[startvalue random generator]{date of exam}|\\
% |\question{directory}{file}|\\
% |\question[parameter value]{directory}{file}|\\
% |....|\\
% |\end{exam}|\\
% |... % possibly other exams|\\
% |\end{document}|
%
% \subsection{Format of a problem}
%
% \DescribeEnv{problem}
% A problem is built by environment |problem|.
% In it several elements can be placed. These are:
% \begin{enumerate}
% \item \DescribeMacro{\parameterproblem}
% |\parameterproblem{text}|: used to communicate to the
% maintainer of the problems the possibilities offered
% by the transfer of macro |\parameter| on posing
% the question; an example of this will follow.
% Can also find a place before the problem declaration.
% \item |\begin{problem}[#1]|; the optional parameter
% can have the value |\compact| (no pagebreak within problem, default)
% or the value |\split| (pagebreak may occur in problem).
% \item |\problemdate{date}|: a macro to remember on which
% day the problem was born;
% \item \DescribeMacro{\score}
% |\score{value}|: use this macro for the number of
% points the answer is worth; it is possible to include
% several score items in one problem for partial rewards.
% The score value is not shown when an exam is typeset,
% the student must earn these points!
% \item text of the question.
% \item the answer or multiple choice list;
% see the description below.
% \item |\remark[h]{b}|: a boxed remark with heading h and body b.
% \item |\end{problem}|.
% \end{enumerate}
%
% \subsection{Examples of Question and Typesetting}
%
% \subsubsection{Simple Problem}
%
% \begin{center}
% \textbf{problem --- coding}
% \end{center}
% \medskip
% |\begin{problem}|\\
% |\problemdate{\today}|\\
% |What is the question?|\\
% |\score{2}|\\
% |\shortanswer{To be or not to be.}|\\
% |\end{problem}|
%
% \medskip
% \DescribeMacro{\question}
% This problem is called up with\\
% |\question{}{exampa}|\\
% which we show without |answers| option and with both the |answers| and 
% |series| option set.
% \begin{center}
% \textbf{problem --- result --- without answers}
% \end{center}
% \medskip
% \begin{center}
% \begin{minipage}{.9\linewidth}\setlength\linewidth{.8\linewidth}
% \answersfalse
% \MakePercentComment\question{}{exampa}\MakePercentIgnore
% \end{minipage}
% \end{center}
% \medskip
% \begin{center}
% \textbf{problem --- result --- with answers}
% \end{center}
% \medskip
% \begin{center}
% \begin{minipage}{.9\linewidth}\setlength\linewidth{.8\linewidth}
% \answerstrue\seriestrue
% \addtocounter{problemnum}{-1}
% \MakePercentComment\question{}{exampa}\MakePercentIgnore
% \end{minipage}
% \end{center}
%
% \subsubsection{Parametrized Problem}
%
% \DescribeMacro{\parameter}
% The next example shows the use of |\parameter| for the selection
% of alternate questions. It is given both value 1 and 2 and called
% with respectively:\\
% |\question[1]{}{exampb}|\\
% |\question[2]{}{exampb}|\\
% However, remember that |\parameter| can be defined to anything;
% e.g. the number that goes into a calculation, a word substituted
% at a specific place, etc.
%
% \medskip 
% \begin{center}
% \textbf{parameterproblem --- coding}
% \end{center}
% \medskip
% |\parameterproblem{1= to be\\2= not to be}|\\
% |\problemdate{\today}|\\
% |\begin{problem}|\\
% |\score{2}|\\
% |What is\ifnum\parameter=1\relax \else n't\fi\ the question?|\\
% |\shortanswer{\ifnum\parameter=1\relax To be or n\else N\fi ot to be.}|\\
% |\end{problem}|
% \medskip
% \begin{center}
% \textbf{parameterproblem --- result --- parameter = 1}
% \end{center}
% \medskip
% \begin{center}
% \begin{minipage}{.9\linewidth}\setlength\linewidth{.8\linewidth}
% \answerstrue\seriestrue
% \MakePercentComment\question[1]{}{exampb}\MakePercentIgnore
% \end{minipage}
% \end{center}
% \medskip
% \begin{center}
% \textbf{parameterproblem --- result --- parameter = 2}
% \end{center}
% \medskip
% \begin{center}
% \begin{minipage}{.9\linewidth}\setlength\linewidth{.8\linewidth}
% \answerstrue\seriestrue
% \addtocounter{problemnum}{-1}
% \MakePercentComment\question[2]{}{exampb}\MakePercentIgnore
% \end{minipage}
% \end{center}
%
% \subsection{Answers}
% \DescribeMacro{\answer}
% \DescribeMacro{\altanswer}
% The basic macros for showing and suppressing answers are
% |\answer| that shows its argument when the \emph{answers}
% option is chosen, and |\altanswer| that alternates its
% two arguments. Both macros have a first, optional argument
% for specifying the width of the box wherein the text
% is placed.
%
% \medskip 
% \begin{center}
% \textbf{answer --- coding}
% \end{center}
% \medskip
% |\answer{answer}|
%
% \medskip
% \begin{center}
% \textbf{answer --- result --- 
% left without, right with answers}
% \end{center}
% \medskip
% \begin{center}
% \fbox{\parbox[t]{.4\linewidth}{\strut\answersfalse
% \answer{answer}
% }}\qquad\fbox{\parbox[t]{.4\linewidth}{\strut\answerstrue
% \answer{answer}}}
% \end{center}
%
% \medskip 
% \begin{center}
% \textbf{altanswer --- coding}
% \end{center}
% \medskip
% |\altanswer{answer NO}{answer YES}|
%
% \medskip
% \begin{center}
% \textbf{altanswer --- result --- 
% left without, right with answers}
% \end{center}
% \medskip
% \begin{center}
% \fbox{\parbox[t]{.4\linewidth}{\strut\answersfalse
% \altanswer{answer NO}{answer YES}
% }}\qquad\fbox{\parbox[t]{.4\linewidth}{\strut\answerstrue
% \altanswer{answer NO}{answer YES}}}
% \end{center}
%
% \DescribeMacro{\shortanswer}
% Some questions can be answered by a few words, a short sentence.
% The command |\shortanswer| serves this purpose;
% its argument is the answer.
%
% \medskip 
% \begin{center}
% \textbf{short answer --- coding}
% \end{center}
% |\shortanswer{The answer.}|
%
% \medskip
% \begin{center}
% \textbf{short answer --- result --- 
% left without answers, right with answers}
% \end{center}
% \medskip
% \begin{center}
% \renewcommand*\shortwhite{2mm}
% \fbox{\parbox[t]{.4\linewidth}{\answersfalse
% Answer the next question:
% \shortanswer{The answer.}}}
% \qquad
% \fbox{\parbox[t]{.4\linewidth}{\answerstrue
% Answer the next question:
% \shortanswer{The answer.}}}
% \end{center}
%
% \DescribeEnv{longanswer}
% When however more space is needed by the student, the
% environment |longanswer| can be used. 
% This environment has one optional parameter, meant
% for specifying the amount of white space to be reserved
% for the students answer. 
%
% \medskip 
% \begin{center}
% \textbf{long answer --- coding}
% \end{center}
% \medskip
% |\begin{longanswer}[5mm]|\\
% |The answer.|\\
% |\end{longanswer}|
%
% \medskip
% \begin{center}
% \textbf{long answer --- result --- 
% left without answers, right with answers}
% \end{center}
% \medskip
% \begin{center}
% \fbox{\parbox[t]{.4\linewidth}{\answersfalse
% Answer the next question:
% \begin{longanswer}[5mm]
% The answer.
% \end{longanswer}}}
% \qquad
% \fbox{\parbox[t]{.4\linewidth}{\answerstrue
% Answer the next question:
% \begin{longanswer}[5mm]
% The answer.
% \end{longanswer}}}
% \end{center}
%
% \DescribeMacro{\answerstart}
% The answer is headed by a call to |\answerstart|; redefine
% to your taste.
%
% \DescribeMacro{\shortwhite}
% \DescribeMacro{\longwhite}
% The default of white space reserved for the depth of the short answer
% can be changed by redefinition of |\shortwhite|.
% The default for the white space of the long answer
% can be changed by redefinition of |\longwhite|.
%
% \subsection{Multiple Choice}
%
% \DescribeEnv{choice}
% Multiple choice is provided for by environment |choice|.
% Within this environment a itemized list of alternatives is given.
% \DescribeMacro{\baditem}
% \DescribeMacro{\gooditem}
% However instead of |\item| one codes |\baditem{text}| for wrong answers
% and |\gooditem{text}| for the correct one; the answer being put
% into the argument of these two macros.
% \DescribeMacro{\ordered}
% \DescribeMacro{\random}
% The optional parameter of this environment can be |\ordered| for
% production of the alternatives in the order specified, or
% |\random| for randomization; randomize is the default, unless
% the \emph{series} option is specified in the |\documentclass| call.
%
% \medskip 
% \begin{center}
% \textbf{multiple choice example --- coding}
% \end{center}
% \medskip
% |\begin{choice}[\ordered]|\\
% |\baditem{first wrong answer}|\\
% |\gooditem{the right answer}|\\
% |\baditem{second wrong answer}|\\
% |\end{choice}|
%
% \medskip
% \begin{center}
% \textbf{multiple choice --- result --- 
% left without answers, right with answers}
% \end{center}
% \medskip
% \begin{center}
% \fbox{\parbox[t]{.4\linewidth}{\answersfalse
% Choose appropriate alternative:
% \begin{choice}[\ordered]
% \baditem{first wrong answer}
% \gooditem{the right answer}
% \baditem{2nd wrong answer}
% \end{choice}}}
% \qquad
% \fbox{\parbox[t]{.45\linewidth}{\answerstrue
% Choose appropriate alternative:
% \begin{choice}[\ordered]
% \baditem{first wrong answer}
% \gooditem{the right answer}
% \baditem{2nd wrong answer}
% \end{choice}}}
% \end{center}
%
% \DescribeMacro{\badmark}
% \DescribeMacro{\goodmark}
% The marks for the multiple choice items are produced
% by the macros |\badmark| and |\goodmark|. For their
% redefinition see the implementation section of this
% document.
%
% \subsection{Shuffling it Yourself}
%
% \DescribeMacro{\loaditem}
% The selection of alternatives is implemented by the
% mechanism in macros |\loaditem| and friends.
% Pieces text can be loaded (in this implementation at most 5) and
% selectively dumped into the typeset input stream.
% It is a useful mechanism when one has to produce
% a whole series of variations on the same theme.
%
% Macro |\loaditem| can be used to load from one to five
% items in a data store. 
% \DescribeMacro{\shuffle}
% This data store can be shuffled
% by a call to |\shuffle|. 
% \DescribeMacro{\dumpitem}
% \DescribeMacro{\dumpitems}
% Popping items from the store
% is effected by macros |\dumpitem| (pop one item) and
% |\dumpitems| (all items). Clearing of the store
% is done by |\resetloadcounter|.
% \DescribeMacro{\SRtest}
% With |\SRtest{1}{2}| one can make a random choice between two
% alternatives.
%
% \medskip 
% \begin{center}
% \textbf{load and dump --- coding}
% \end{center}
% \medskip
% |\SRset{349}                     % start random generator|\\
% |\resetloadcounter               % initialize load stack|\\
% |\loaditem{\fbox{item 1}\space}  % load 4 items of text|\\
% |\loaditem{\fbox{item 2}\space}|\\
% |\loaditem{\fbox{item 3}\space}|\\
% |\loaditem{\fbox{item 4}\space}|\\
% |Here comes nr~2: \dumpitemno{2} % dump 2nd item|\\
% |\par|\\
% |\shuffle                        % randomize|\\
% |Here nr~2 again after randomization: \dumpitemno{2}|\\
% |\par|\\
% |Dump the whole lot: \dumpitems|
%
% \medskip
% \begin{center}
% \textbf{load and dump --- result}
% \end{center}
% \medskip
% \begin{center}
% \parbox[t]{.8\linewidth}{%
% \SRset{349}
% \resetloadcounter
% \loaditem{\fbox{item 1}\space}
% \loaditem{\fbox{item 2}\space}
% \loaditem{\fbox{item 3}\space}
% \loaditem{\fbox{item 4}\space}
% Here comes nr~2: \dumpitemno{2}\par
% \shuffle
% Nr~2 after randomization: \dumpitemno{2}\par
% Dump the whole lot: \dumpitems
% }
% \end{center}
%
%
% \section{Summary of Options and Macros}
%
% \subsection{Options}
%
% \begin{flushleft}\sloppy
% |answers| problems with answers\\
% |pages| each problen on a separate page\\
% |questiononly| suppress open space for answers\\
% |nosep| suppress separation between successive problems\\
% |scores| add score values\\
% |series| produce problem collection
% \end{flushleft}
%
% \subsection{Exam Production}
%
% \begin{flushleft}\sloppy
% |\target{name}| exam meant for these people\\
% |\begin{exam}[randomstart]{date}...\end{exam}| dated exam\\
% |\begin{exam}{date}...\end{exam}| randomstart=0, i.e. not random\\
% |\begin{exam}{}...\end{exam}| today's date\\
% |\question[variant]{dir}{file}| call problem variant from dir/file\\
% |\question{dir}{file}| no problem variants
% \end{flushleft}
%
% \subsection{Problem Definition}
%
% \begin{flushleft}\sloppy
% |\parameterproblem[param]{explication}| set default, show explication\\
% |\begin{problem}...\end{problem}| problem definition, kept wholly on page\\
% |\begin{problem}[\split]...\end{problem}| do not confine to one page\\
% |\problemdate{date}| reference date for problem\\
% |\score{value}| set problems worth in points\\
% |\remark[label]{text}| place remark if series option\\[\smallskipamount]
% |\answer[width]{answer}| coding in an answer\\
% |\altanswer[width]{alt}{answer}| alternate text instead of answer\\
% |\shortanswer{answer}| short answer or row of dots\\
% |\begin{longanswer}[height]...\end{longanswer}| long answer or space\\[\smallskipamount]
% |\begin{choice}...\end{choice}| randomly permuted multiple choice\\
% |\begin{choice}[\ordered]...\end{choice}| not permuted\\
% |\baditem{text}| inside a |choice| text for false item\\
% |\gooditem{text}| ditto for good item\\[\smallskipamount]
% |\loaditem{anything}| put `anything' to memory stack\\
% |\dumpitem| pop top from memory stack\\
% |\dumpitems| pop whole memory stack\\
% |\shuffle| randomize memory stack
% 
% \end{flushleft}
%
% \subsection{Styling and Customization}
%
% \begin{flushleft}\sloppy
% |\everyproblem| token register executed at start of each problem\\
% |\scoreboxsize{size}| set size of square score box\\
% |\shortwhite| default vertical space short answers, change |\renewcommand|\\
% |\longwhite| ditto for long answers\\
% |\marksize| size of multiple choice marks, |\selectfont| expression\\
% |\badmark| symbol for multiple choice item box\\
% |\goodmark| ditto for the good one\\
% |\headerfont| font for page header\\
% |\bodyfont| font for exam text\\
% |\titlefont| font for titles\\
% |\Mainfolder{dir}| set |\mainfolder| to dir\\
% |\Commonfolder{dir}| set |\commonfolder| to dir\\
% |\Figuresfolder{dir}| set |\figuresfolder| to dir
% \end{flushleft}
%
% \StopEventually{\PrintChanges}
%
% \newpage
%    \begin{macrocode}
%<*cls>
%    \end{macrocode}
%
% \section{Identification}
%
% This document class can only be used with \LaTeXe, so we make
% sure that an appropriate message is displayed when another \TeX{}
% format is used. We require the latest version that has no known
% troubles with this class.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
%    \end{macrocode}
%
% Announce the Class name and its version.
%    \begin{macrocode}
\ProvidesClass{exam}[1997/03/14 vs 3.30 exam package]
%    \end{macrocode}
%
% \section{Declaration of Class Options}
%
% In this part we define the options for this class that are additional
% to those of its parent class.
%
% \subsection{Switching answers on and off}
%
% \begin{macro}{\ifanswers}
% The flag |\ifanswers| governs the production of answers in the
% typesetting of problems. With the |answers| options in the
% optional argument of the document class this option is turned on.
% Then also we show the score values.
%
%    \begin{macrocode}
\newif\ifanswers
\answersfalse
\DeclareOption{answers}{\answerstrue\scorestrue}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Each problem on separate page}
%
% \begin{macro}{\ifproblempages}
% The flag |\ifproblempages| governs the typesetting of problems 
% on separate pages, or their collection of more than one to a page.
% If separate pages are chosen, a separator between problems
% is unnecessary.
%
%    \begin{macrocode}
\newif\ifproblempages
\problempagesfalse
\DeclareOption{pages}{\problempagestrue\problemsepfalse}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Suppress prompt for answer}
%
% \begin{macro}{\ifreservespace}
% The flag |\ifreservespace| governs the typesetting of space 
% for answers. If true, all reservation of answer space is
% suppressed. It is set by option |questiononly|;
% this option has no effect when the |answers| option is on.
%
%    \begin{macrocode}
\newif\ifreservespace
\reservespacetrue
\DeclareOption{questiononly}{\reservespacefalse}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Visible separation between problems}
%
% \begin{macro}{\ifproblemsep}
% The value of flag |\ifproblemsep| determines the appearance 
% of a visible separation between successive problems.
%
%    \begin{macrocode}
\newif\ifproblemsep
\problemseptrue
\DeclareOption{nosep}{\problemsepfalse}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Showing score values}
%
% \begin{macro}{\ifscores}
% The flag |\ifshowscores| determines when score values are printed.
%
%    \begin{macrocode}
\newif\ifscores
\scoresfalse
\DeclareOption{scores}{\scorestrue}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Typeset a Catalogue of Problems}
%
% \begin{macro}{\ifseries}
% The flag |\ifseries| initiates the production of a problem catalogue.
% In order to show answers and score values, the respective flags are set.
%
%    \begin{macrocode}
\newif\ifseries
\seriesfalse
\DeclareOption{series}{\seriestrue\answerstrue\scorestrue}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Show Options}
%
% Show options to the user with option |help|.
%
%    \begin{macrocode}
\DeclareOption{help}{\ClassWarningNoLine{exam}{%
    available options for exam:\MessageBreak
    answers:\space show questions with answers;\MessageBreak
    nosep:\space no separators between problems;\MessageBreak
    pages:\space each problem on a page;\MessageBreak
    questiononly:\space suppress answer space in exams;\MessageBreak
    scores:\space typeset score values always;\MessageBreak
    series:\space\space typeset catalogue of problems}}
%    \end{macrocode}
%
% \section{Loading of Parent Class}
%
% Since the \emph{exam class} is implemented as a modification
% of an existing document class, we must load the parent class.
% \begin{macro}{\parentclass}
% In order to make changes in parent class easy, the
% name of this class is parametrized in macro |\parentclass|.
% Obvious candidates are \emph{article} and \emph{report}.
% In order to provide some flexibility, we allow for the case
% that the user has already defined |\parentclass| (before
% the call to |\documentclass|. In that case we refrain
% from redefinition.
%
%    \begin{macrocode}
\providecommand\parentclass{article}
%    \end{macrocode}
% \end{macro}
%
% The options of the |\documentclass| call which are not specific for the
% \emph{exam class} must be passed to the parent class.
% We take the opportunity to select the production of a titlepage 
% (not automatically added if the parent class is \emph{article}.
% After this we process the local options.
%
%    \begin{macrocode}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\parentclass}}
\PassOptionsToClass{titlepage}{\parentclass}
\ProcessOptions
%    \end{macrocode}
%
% Then we load the parent class.
%
%    \begin{macrocode}
\LoadClass{\parentclass}
%    \end{macrocode}
%
% A table of contents can be produced when a series is run or when
% producing an exam including answers, otherwise kill the
% corresponding macro.
%
%    \begin{macrocode}
\ifseries\else\ifanswers\else\let\tableofcontents=\relax\fi\fi
%    \end{macrocode}
%
% \section{Helpfull Macros}
%
% \begin{macro}{\@ifemptyarg}
% Testing for the presence or absence of a parameter.
%
%    \begin{macrocode}
\providecommand\@ifemptyarg[1]{% {absence}{presence}
  \ifx\@empty#1\@empty
  \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\examerror}
% \begin{macro}{\examwarning}
% Define |\examerror| and |\examwarning| to issue proper 
% warnings in case of errors.
% Note that the error macro provides for a help text in its 
% second argument.
%
%    \begin{macrocode}
\newcommand*\examerror[2]{\ClassError{exam}{!!!! #1}{#2}}
\newcommand*\examwarning[1]{\ClassWarning{exam}{!!!! #1}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \section{Produce an Exam}
%
% \begin{macro}{\examnum}
% First we need a counter for exams, since in one run more than
% one exam can be produced.
% By stepping this counter we will effect the automatic reset of
% the counter that numbers the problems and 
% the counter that remembers the score value.
%
%    \begin{macrocode}
\newcounter{examnum}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{exam}
% Exams are produced within the |exam| environment. This environment takes
% 2 parameters. The first one is optional and provides the initial value
% of the random generator.\footnote{Not used when a series
% is run.} The default is 0, which effectively shuts off randomness.
% The second parameter must be present, but can be empty.
% It fixes the date for which the exam is planned; an empty argument
% fills in the current date.
%
%    \begin{macrocode}
\newenvironment{exam}[2][0]{%
  \stepcounter{examnum}%
  \@ifemptyarg{#2}{}{\date{#2}}%
%    \end{macrocode}
%
% When answers are requested we start with a titlepage.\footnote{%
% If not inhibited by the |notitlepage| option.}
% In the case of exam production, typesetting of the titlepage 
% is deferred to the end of the exam,
% so that we may print on it the number of problems.
% We write a few messages to the table of contents (date and initial 
% value of the random generator) when an exam with answers 
% is in production.
% Disable the random generator for a series.
%
%    \begin{macrocode}
  \ifanswers
    \pagenumbering{roman}%
    \maketitle\newpage\mbox{}\newpage
  \fi
  \pagenumbering{arabic}%
  \ifseries\SRset{0}\else
    \SRset{#1}%
    \addtocontents{toc}{\protect\contentsline{section}%
      {\Exam~\theexamnum~\textemdash~\@date~%
      \textemdash~random start #1}{}}%
  \fi
%    \end{macrocode}
%
% In each separate exam the first page gets the number one.
%
%    \begin{macrocode}
  \setcounter{page}{1}}%
%    \end{macrocode}
%
% At the end of the exam produced for the students
% a titlepage is made. If answers are given for the exam
% we also provide the total of the scores.
%
%    \begin{macrocode}
  {\ifseries\else
    \typeout{Total value scores = \thetotalscore}%
    \ifanswers
      \addtocontents{toc}{\protect\contentsline{section}%
        {Total value scores = \thetotalscore}{}}%
    \else\maketitle
    \fi\fi}
%    \end{macrocode}
% \end{environment}
%
% \section{Choosing Problems}
%
% \begin{macro}{\problemnum}
% We start with a counter |\problemnum| with which the problems
% of the exam are neatly numbered. This counter is automatically
% reset each time a new |exam| environment is entered.
% \begin{macro}{\problemid}
% A textual identification of the current problem is collected
% in token register |\problemid|.
%
%    \begin{macrocode}
\newcounter{problemnum}[examnum]
\newtoks\problemid
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\question}
% \textbf{Each question must reside in its own file} which is called up
% by macro |\question|. Of its three parameters the first is
% optional and provides a means of communication with the
% problem itself. To achieve this the first 
% argument of |\question| is cached 
% in macro |\parameter|.\footnote{As most uses of this mechanism
% boil down to a choice between several alternatives, the
% number~1 is provided by macro {\ttfamily\protect\bslash parameterproblem}
% as a convenient default value. See also the discussion
% under the heading ``Parametrized Problems''.}
% The default behaviour here is not touching the
% definition of |\parameter| in case of an empty argument;
% in many cases a forgotten argument will then lead to
% a ``missing something'' error. The benefit of not
% touching |\parameter| in case of an empty argument
% is that this macro now also can be initialized by
% other means, e.g. by definition earlier in the problem coding.
%
% The second parameter of |\question| is the name of the (sub)directory
% where the file named in the third parameter can be found.
% This second parameter doubles up as section name in the
% series production.\footnote{It is silently assumed
% that all problems of a given category reside in a common
% directory.}
%
%    \begin{macrocode}
\newcommand*\question[3][]{%
  \@ifemptyarg{#1}{}{\renewcommand\parameter{#1}}%
%    \end{macrocode}
%
% When a series is run we look for the start of a new section and
% perform the appropriate actions if indeed a new section is found.
% I.e.\ eject the page and then reset the section name 
% and the problem counter.
% Note the use of uppercase in order to smooth out differences in typing.
% The identification of the problem is set to its file name and,
% in the case of a series, is mentioned in the output.
% Then the problem number is incremented. 
%
%    \begin{macrocode}
  \ifseries
    \uppercase{\def\@namesection{#2}}%
    \ifx\namesection\@namesection
    \else
      \newpage
      \global\let\namesection=\@namesection
      \addcontentsline{toc}{subsection}{\namesection}%
      \setcounter{problemnum}{0}%
    \fi   
  \fi
  \problemid={\MakeUppercase{#3}}%
  \ifseries
    \noindent\underbar{\emph{File\,:}~\texttt{\the\problemid}}\par
    \nopagebreak\medskip\nopagebreak
  \fi
  \stepcounter{problemnum}%
%    \end{macrocode}
%
% If appropriate a summary of this problem is written to the table of contents.
%
%    \begin{macrocode}
  \ifanswers
    \addcontentsline{toc}{subsection}%
      {\hbox to1cm{\theproblemnum:\hss}#3}%
  \fi
%    \end{macrocode}
%
% Reading of the problem itself is surrounded by calculations
% on the score that this question will bring.
% Scores are mentioned on the console except when a series is run.
% In a problem all contributions from the various parts of the
% problem are collected in counter |scorecounter|.
% At the end of the problem |totalscore| is 
% updated with this value.\footnote{%
% Note the resets for |totalscore| with |examnum|
% and |scorecounter| with |problemnum| in their declaration.}
% The code guards against typing errors in the name of the file.
%
%    \begin{macrocode}
  \edef\@curquestion{\mainfolder\@ifemptyarg{#2}{}{#2\@currdir}#3}%
  \IfFileExists{\@curquestion}{\@@input \@curquestion}%
    {\examwarning{File \@curquestion: not found}}%
  \ifseries\else
    \addtocounter{totalscore}{\value{scorecounter}}%
    \typeout{\Problem\space\theproblemnum: score=\thescorecounter}%
  \fi
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{namesection}
% Macro |\namesection| gets its initial value here:
%
%    \begin{macrocode}
\newcommand*\namesection{\Collection}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Parametrized Problems}
%
% \begin{macro}{\reset@parameter}
% A parametrized problem gets its parameter from the first
% argument of macro |\question|, as already have been mentioned.
% This is effected by definition of macro |\parameter| to
% the value of that argument. 
% We add code here to (re)initialize this macro.
%
%    \begin{macrocode}
\newcommand*\reset@parameter{\gdef\parameter{}}
\reset@parameter
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\parameterproblem}
% The first argument of |\parameterproblem| is optional and 
% sets a default by for |\parameter|;
% set to the number~1 if not explicitely given.
% It is recommended that |\parameterproblem| is placed
% before the first use of |\parameter| or even before the
% |\begin{problem}|.
% Furthermore, in typesetting an exam this macro will print a warning
% if |\parameter| has not been set on the |\question| call.
%
% |\parameterproblem| will typeset its second argument in a framed box.
% Usually this tells the reader which selections are available; however,
% only in the case a series is run, otherwise `silence' is the word.
% The description is placed by macro |\remark| which does the
% necessary suppression.
% 
%    \begin{macrocode}
\newcommand\parameterproblem[2][1 ]{%
  \ifx\parameter\@empty
    \ifseries\else\examwarning{\string\parameter\space set to `#1'}\fi
    \renewcommand\parameter{#1}%
  \fi
  \remark[Parameter \Problem]{#2}}
%    \end{macrocode}
% \end{macro}
%
%
% \section{Typesetting a Problem}
%
% Each problem must be enclosed in an environment |problem|.
% Within this environment a default setup exists.
% \begin{macro}{\everyproblem}
% By supplying code in token register |\everyproblem| one
% can influence the typesetting of each problem.
%
%    \begin{macrocode}
\newtoks\everyproblem
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{problem}
% The |problem| environment also has one optional parameter
% for specific adjustments of the options setting.
% Execution of options occurs in the order:
% default setup, possible modification by |\everyproblem| and
% final customization through the optional parameter.
% This mechanism provides for maximum flexibility.
%
%    \begin{macrocode}
\newenvironment{problem}[1][]{%
%    \end{macrocode}
%
% Choose by default for keeping the whole problem on a page,
% execute any code in the token register and honor the
% option calls from the user.
%
%    \begin{macrocode}
\compact\the\everyproblem#1\relax
%    \end{macrocode}
%
% In order to keep everything on page we will enclose
% the problem in a |\vbox|, coded in
% macro |\@boxing|. Otherwise |\@boxing| is a noop and
% \TeX's pagebuilder can choose its breakpoint freely.
% For the declaration of |\@boxing| see section~\ref{ref:boxing}.
%
% The problem is typeset with a standard opening
% programmed in |\problemstart|, completing the
% opening manoeuvres of the environment.
%
%    \begin{macrocode}
  \@boxing\bgroup\noindent\problemstart\ignorespaces}%
%    \end{macrocode}
%
% After processing the body of the problem some postprocessing follows
% and the possible |\vbox| is closed by an |\egroup|.
%
% In particular a visual separation from the next problem is added,
% if not suppressed.
% In the case of series production the origin date
% of the problem is added too.\footnote{Only if it has been
% provided to it by the proper macro call, of course.}
%
%    \begin{macrocode}
  {\par\ifproblemsep
    \nopagebreak\smallskip\nopagebreak
    \hbox to\linewidth{\hrulefill
      \ifseries
        \emph{\footnotesize\thinspace\the\@problemdate}%
      \fi}\fi
  \egroup\par
%    \end{macrocode}
%
% Start a new page or separate the problem from the next one by a skip.
%
%    \begin{macrocode}
  \ifproblempages\newpage\else\bigskip\fi
%    \end{macrocode}
%  
% The origin date and the communicated value
% in macro |\parameter| are cleared for the next problem.
%
%    \begin{macrocode}
  \reset@problemdate\reset@parameter}
%    \end{macrocode}
% \end{environment}
% 
% \subsection{Code for Options to Problem}
% \label{ref:boxing}
%
% \begin{macro}{\compact}
% \begin{macro}{\split}
% The options to |problem| are |\compact| or |\split|. 
% These options govern the possibility for the problem 
% to be split between successive pages or the necessity 
% to keep everything on page; the last one being the 
% favoured behaviour in this implementation.
% Note the |\noident| before the |\vbox| that prevents
% an unwanted shift to the right.
% 
%    \begin{macrocode}
\newcommand*\compact{\def\@boxing{\noindent\vbox}}
\newcommand*\split{\def\@boxing{}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \subsection{Numbering the Problem}
%
% \begin{macro}{\problemstart}
% \begin{macro}{\@problemstart}
% A problem gets a standard opening clause, coded in
% macro |\@problemstart|. The opening code is used to
% format the first paragraph with a nice indentation.\footnote{%
% This indentation is also used in the left margin in multiple
% choice listings in order to limit the variation in margins.}
%
%    \begin{macrocode}
\newcommand*\problemstart{%
  \hangafter-2\settowidth\hangindent{\@problemstart}%
  \noindent\llap{\@problemstart}}
\newcommand*\@problemstart{%
  \textbf{\Problem\,\ifnum\value{problemnum}<10 \phantom{0}\fi
  \theproblemnum}.\enskip}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Date of Origin}
%
% \begin{macro}{\@problemdate}
% \begin{macro}{\problemdate}
% \begin{macro}{\@resetproblemdate}
% The user may specify an original date or date of last change
% for the problem to be printed when a series is produced.
% The global assignments are here just in case things happen in
% a deeper nested level.
%
%    \begin{macrocode}
\newtoks\@problemdate
\newcommand*\problemdate[1]{\global\@problemdate={#1}\ignorespaces}
\newcommand*\reset@problemdate{\global\@problemdate={}}
\reset@problemdate
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Score Values}
%
% Associated with each problem are of course the benefits the
% student receives for a good answer to (part of) the problem.
% \begin{macro}{\score}
% The |\score| macro exists for this purpose.
% If answers are not included, just an empty square is printed
% into which the teacher can express his satisfaction with
% the answer given. When answers are included in the printout
% the each call |\score{value}| shows up in the right margin
% of the document.\footnote{At the end of each problem a summary
% of its total score plus a grand total are presented
% on the console.}
%
% \begin{macro}{\totalscore}
% \begin{macro}{\scorecounter}
% These counters collect the values. Note that |\totalscore|
% is reset for each new exam and |\scorecounter| for each problem.
%
%    \begin{macrocode}
\newcounter{totalscore}[examnum]
\newcounter{scorecounter}[problemnum]
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\scoreboxsize}
% \begin{macro}{\scorebox}
% The next commands are used for the production of the box
% for the score value.
%
%    \begin{macrocode}
\newcommand*\scoreboxsize{6mm}
\newcommand*\scorebox[1]{%
  \fbox{\vbox to\scoreboxsize{\vss\hbox to
    \scoreboxsize{\hss#1\hss}\vss}}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% Finally the next code puts the score box on paper.
% It takes the value of the score as its argument and adds
% it to the running sum for this problem.
%
%    \begin{macrocode}
\newcommand*\score[1]{%
  \addtocounter{scorecounter}{#1}%
  \rightnote{\scorebox{\ifscores#1\fi}}%
  \ignorespaces}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\leftnote}
% \begin{macro}{\rightnote}
% We do not use |\marginpar| for the placement of the score values,
% because we do not want these items wandering around, as
% |\marginpar|'s sometimes do.
%
% \begin{macro}{\@rlnote}\mbox{}
%    \begin{macrocode}
\providecommand\leftnote{\@rlnote l}
\providecommand\rightnote{\@rlnote r}
\providecommand\@rlnote[2]{%
  \leavevmode\noindent
  \vadjust{\vbox to\z@{%
    \leftskip\z@skip\rightskip\z@skip
    \noindent
    \if#1l\llap{#2\hskip\marginparsep}%
    \else\hfill\rlap{\null\hskip\marginparsep\relax#2}\fi
    \vss\vskip\z@skip
  }}\ignorespaces}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Adding remarks}
%
% In making a catalogue of problems (option \emph{series} selected) 
% it is useful when remarks can be added that stand out against the rest
% of the text. 
% \begin{macro}{\remark}
% Macro |\remark| provides such a mechanism.
% Its first (optional) argument is set emphasized, its second argument
% hangs on the first. The complete remark is placed
% in a |\parbox| and then boxed and centered.
%
%    \begin{macrocode}
\newcommand\remark[2][]{%
  \ifseries
    \begin{center}%
      \fbox{\parbox{.9\linewidth}{%
        \sloppy\hangafter\@ne
        \sbox\@tempboxa{\emph{#1}\@ifemptyarg{#1}{}{:~}}%
        \hangindent=\wd\@tempboxa
        \strut\usebox{\@tempboxa}#2}}%
      \end{center}%
    \nopagebreak\addvspace{\bigskipamount}\nopagebreak
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \section{Answers}
%
% In this section various ways of typesetting answers are provided.
%
% \begin{macro}{\longwhite}
% \begin{macro}{\shortwhite}
% We start with two definitions for long and short stretches of white
% space. These are meant for leaving room for the students answer.
%
%    \begin{macrocode}
\newcommand*\longwhite{25mm}
\newcommand*\shortwhite{8mm}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\answerstart}
% Just as with the typesetting of the problem, we provide
% a macro to start an answer. Note that the text is
% parametrized in order to keep switching to other
% languages simple.
%
%    \begin{macrocode}
\newcommand*\answerstart{\noindent\emph{\Answer}:\enspace}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Switching Answer On and Off}
% 
% \begin{macro}{\answer}
% Macro call |\answer| holds the answer and shows it when
% answers are requested. The optional first argument specifies
% a width for the box into which the typesetting takes places.
% The answer is centered by default; change it with |\hfil|'s.
% Implementation of |\answer| is by the next macro |\altanswer|. 

%    \begin{macrocode}
\newcommand*\answer[2][]{\altanswer[#1]{}{#2}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Alternating Some Stuff and Answer}
% 
% \begin{macro}{\altanswer}
% With |\altanswer| the text alternates between two possibilities:
% the first one is typeset when answers are suppressed, the second
% one for the opposite case. Optional width argument and placement
% are the same as for |\answer|.
%
%    \begin{macrocode}
\newcommand*\altanswer[3][]{%
  \@ifemptyarg{#1}%
    {\mbox{\ifanswers#3\else#2\fi}}%
    {\makebox[#1]{\ifanswers#3\else#2\fi}}%
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Problem with a Short Answer}
% 
% \begin{macro}{\shortanswer}
% A question ``Give a short answer to \ldots'' is formatted
% in |\shortanswer|. Usually the answer will fit on one line.
% In the exam a row of dots is produced, otherwise the answer will show.
% The optional argument provides the width of the box into which
% the data are typeset.
%
%    \begin{macrocode}
\newcommand*\shortanswer[1]{\par
  \ifanswers
    \addvspace{\smallskipamount}%
    \settowidth\@tempdima{\answerstart\quad}%
    \setlength\@tempdimb{\linewidth}%
    \addtolength\@tempdimb{-\@tempdima}%
    \answerstart\parbox[t]{\@tempdimb}{\noindent#1}%
    \par\medskip
  \else\ifreservespace
    \addvspace{\shortwhite}%
    \answerstart\mbox{}\dotfill\quad\mbox{}\par
    \medskip
   \fi\fi
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Problem with a Long Answer}
% 
% \begin{environment}{longanswer}
% For elaborate questions, problems, etc.\ an environment is available.
% The |longanswer| environment takes as optional argument the length
% of white to be reserved for the student.
%
% Code for opening of the environment. 
% It opens a box in order to let the answer disappear
% and places a rule in order to guarantee sufficient
% white space.
%
%    \begin{macrocode}
\newenvironment{longanswer}[1][\longwhite]{
  \par
  \ifanswers
    \addvspace{\medskipamount}\answerstart
    \nopagebreak\par\noindent
  \else\ifreservespace
      \addvspace{\medskipamount}\answerstart
      \nopagebreak\par\noindent
      \hrule\@height#1\@width\z@\par
    \fi
    \setbox\z@\vbox\bgroup\leavevmode
   \fi\ignorespaces}
%    \end{macrocode}
%
% Aftermath of |longanswer|. If necessary close the box
% and empty it to get rid of the answer.
%    \begin{macrocode}
  {\ifanswers\par\medskip\else\egroup\setbox\z@\hbox{}\fi}
%    \end{macrocode}
% \end{environment}
%
% \section{Multiple Choice Questions}
%
% Multiple choice problems must be placed
% in an |choice| environment, a modification
% of |itemize|.
%
% We will make it possible to 
% shuffle the items of a multiple
% choice problem randomly. These items are held in a series
% of token registers declared below.
%
% \begin{macro}{\loadcounter}
% \begin{macro}{\resetloadcounter}
% \begin{macro}{\incloadcounter}
% \begin{macro}{\decloadcounter}
% We need a counter into which to keep the number of items
% at any time loaded into the token registers declared above.
% Also we provide for resetting, incrementing and decrementing
% of this register. Note the global assignments.
%
%    \begin{macrocode}
\newcount\loadcounter
\newcommand*\resetloadcounter{\global\loadcounter\z@}
\newcommand*\incloadcounter{\global\advance\loadcounter\@ne}
\newcommand*\decloadcounter{\global\advance\loadcounter\m@ne}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% We want a specific behaviour when the list of items is typeset.
% However, we cannot be sure at which listlevel this will occur.
% \begin{macro}{\@listk}
% Therefore we predeclare a replacement for |\@listi|, |\@listii|,
% or whatsoever, and swap the |\@list..| at the right time.
% Note the choice for the leftside margin, derived from the
% width of the text with which the problem starts. This choice
% diminishes the number of different margins. It is easily adapted
% to your own taste.
%
%    \begin{macrocode}
\newcommand*\@listk{%
  \settowidth{\leftmargin}{\@problemstart}%
  \topsep\medskipamount
  \partopsep\z@
  \itemsep\smallskipamount
  \parsep\z@}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Typesetting Multiple Choice}
%
% \begin{environment}{choice}
% The multiple choice environment |choice| takes one argument,
% the modifier options to the environment typesetting.
% Here the options are |\random| and |\ordered|; the names
% speak for themselves. Note that random permutation is not
% executed if a series is run. Furthermore the counter
% for the number of items loaded is reset.
%
%    \begin{macrocode}
\newenvironment{choice}[1][]{%
  \ifseries\ordered\else\random\fi#1\relax
  \resetloadcounter
%    \end{macrocode}
%
% The following code is taken from \LaTeX's |itemize|.
% I did not find a more elegant way to bend this environment
% to my whims.
%
%    \begin{macrocode}
  \ifnum\@itemdepth>3 \@toodeep \else
  \advance\@itemdepth\@ne
  \expandafter\let
    \csname @list\romannumeral\the\@itemdepth\endcsname=\@listk
  \list{\badmark}{\def\makelabel##1{\hss\llap{##1}}}%
  \fi}%
%    \end{macrocode}
%
% At the end of |choice| we dump all the items that may have been
% collected inbetween and finish the |list|.
%
%    \begin{macrocode}
  {\@dumpitems\endlist}
%    \end{macrocode}
% \end{environment}
% 
% \subsection{Code for Options to Choice}
%
% \begin{macro}{\random}
% The option |\random| codes macros |\@loaditem| and
% |\@dumpitems| so that the items are actually loaded,
% then shuffled and dumped afterwards.
% \begin{macro}{\ordered}
% The |\ordered| option makes them noops and thus the
% items will be typeset on the fly.
%
%    \begin{macrocode}
\newcommand*\random{%
  \def\@loaditem{\loaditem}%
  \def\@dumpitems{\shuffle\dumpitems}}
\newcommand*\ordered{\def\@loaditem{}\def\@dumpitems{}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% 
% \subsection{Formatting the Item Mark}
%
% \begin{macro}{\marksize}
% \begin{macro}{\badmark}
% \begin{macro}{\goodmark}
% We require two marks: one for the bad guys and one
% for the good guy. We use the two symbols |\square| and |\boxtimes|,
% but provide replacements (later on, after giving exam.cfg a chance
% to define them) in case these are undefined.
% Typeset these marks in fixed size (unchanged baselineskip) 
% provided by macro |\marksize|.
%
%    \begin{macrocode}
\newcommand*\marksize{\fontsize{12}{\f@baselineskip}\selectfont}
\newcommand*\badmark{{\marksize\ensuremath{\square}}}
\newcommand*\goodmark{%
  \ifanswers{\marksize\ensuremath{\boxtimes}}\else\badmark\fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\baditem}
% \begin{macro}{\gooditem}
% Each item can either be right or wrong. We take the precaution
% to suppress the difference when typesetting the actual exam.
% Enclose each item in your list in the argument to
% |\gooditem| and |\baditem|. They
% will load the item in memory prior to (possible) random shuffling.
%
%    \begin{macrocode}
\newcommand*\baditem[1]{\@loaditem{\item[\badmark]#1}}
\newcommand*\gooditem[1]{\@loaditem{\item[\goodmark]#1}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Loading and Dumping Items}
%
% \begin{macro}{\@itemA}
% \begin{macro}{\@itemB}
% \begin{macro}{\@itemC}
% \begin{macro}{\@itemD}
% \begin{macro}{\@itemE}
% This series of token registers
% can hold five alternatives. The mechanism that loads the
% items is sufficiently general to use it for other purposes too.
% Use your imagination!
% That there are five of them is remembered in a definition
% because we will need this number to prevent overfilling the store.
%
% \begin{macro}{\@itemstore}\mbox{}
%    \begin{macrocode}
\newtoks\@itemA
\newtoks\@itemB
\newtoks\@itemC
\newtoks\@itemD
\newtoks\@itemE
\newcommand\@itemstore{5}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\loaditem}
% According to the value of |loadcounter| the token registers
% |\@itemA|, etc.\ are filled. Argument to macro |\loaditem|
% is the contents of the item.
%
%    \begin{macrocode}
\newcommand\loaditem[1]{%
  \ifcase\loadcounter
    \@itemA={#1}%
    \or\@itemB={#1}%
    \or\@itemC={#1}%
    \or\@itemD={#1}%
    \or\@itemE={#1}%
  \fi
  \ifnum\loadcounter<\@itemstore \incloadcounter
  \else\examwarning{\string\loaditem\space ignored, too many}\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\dumpitemno}
% Produce items that were loaded.
%
%    \begin{macrocode}
\newcommand*\dumpitemno[1]{%
  \ifnum#1>\loadcounter
    \examwarning{\string\dumpitemno[#1] ignored, out range}%
  \else\ifcase#1\relax
    \or\the\@itemA
    \or\the\@itemB
    \or\the\@itemC
    \or\the\@itemD
    \or\the\@itemE
  \fi\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\dumpitem}
% \begin{macro}{\dumpitems}
% With |\dumpitem| the last one comes out and is chopped off
% from the stack, with |\dumpitems| the whole lot is dumped.
% By means of |\dumpitemno| one can peek inside the stack:
% its parameter gives the position to be produced, the item itself
% remains on the stack.
%    \begin{macrocode}
\newcommand*\dumpitem{\dumpitemno{\loadcounter}\decloadcounter}
\newcommand*\dumpitems{\@whilenum\loadcounter>\z@\do{\dumpitem}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{Shuffling Items}
%
% \begin{macro}{\shuffle}
% This macro permutes |loadcounter| items in the
% token registers |\@itemA|, etc. Undoubtedly it
% can be done better, but who's perfect?
%
%    \begin{macrocode}
\newcommand*\shuffle{%
  \ifcase\loadcounter
    \or
    \or\shuffle@ii
    \or\shuffle@\@itemA\@itemC \shuffle@ii \shuffle@\@itemB\@itemC
    \or\shuffle@iv
    \or\shuffle@\@itemD\@itemE \shuffle@iv \shuffle@\@itemD\@itemE
    \fi
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\shuffle@}
% \begin{macro}{\shuffle@ii}
% \begin{macro}{\shuffle@iv}
% \begin{macro}{\@item@}
% Random interchange of two and four items.
%
%    \begin{macrocode}
\newtoks\@item@
\newcommand*\shuffle@[2]{\SRtest{}{\@item@=#1 #1=#2 #2=\@item@}}
\newcommand*\shuffle@ii{\shuffle@\@itemA\@itemB}
\newcommand*\shuffle@iv{%
  \SRtest{\shuffle@\@itemA\@itemB}{\shuffle@\@itemC\@itemD}%
  \SRtest{\shuffle@\@itemA\@itemC}{\shuffle@\@itemB\@itemD}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsubsection{Random Generator Implementation}
%
% \begin{macro}{\SRset}
% \begin{macro}{\SRbit}
% \begin{macro}{\SRtest}
% \begin{macro}{\SRvalue}
% Not much commentary with these macros. They are
% described in Tugboat~1994, vol.~15.1, p.~57--58.
%
% \begin{macro}{\@SR}
% \begin{macro}{\@SRconst}
% \begin{macro}{\@SRadvance}\mbox{}
%    \begin{macrocode}
\ifx\@SR\undefined\newcount\@SR\fi
\providecommand\@SRconst{2097152}
\providecommand\SRset[1]{\global\@SR#1 \ignorespaces}
\providecommand\@SRadvance{%
  \begingroup
  \ifnum\@SR<\@SRconst\relax\count@\z@\else\count@\@ne\fi
  \ifodd\@SR\advance\count@\@ne\fi
  \global\divide\@SR\tw@
  \ifodd\count@\global\advance\@SR\@SRconst\relax\fi
  \endgroup}
\providecommand\SRbit{\@SRadvance\ifodd\@SR1\else0\fi}
\providecommand\SRtest[2]{\@SRadvance
  \ifodd\@SR#2\else#1\fi\ignorespaces}
\providecommand\SRvalue{\number\@SR }
\SRset{0}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \section{Page Style}
%
% \begin{macro}{\thehead}
% For a page style |examheadings| is offered.
% Choose it by supplying to |\pagestyle|.
%
% \begin{macro}{\ps@examheadings}\mbox{}
%    \begin{macrocode}
\newcommand*\thehead{%
  \textsl{\@title\enspace:\enspace
  \ifseries\namesection\else\@date\fi}}
\newcommand*\ps@examheadings{%
  \let\@oddfoot\@empty
  \let\@evenfoot\@empty
  \renewcommand*\@oddhead{%
    \vbox{%
    \hbox to\textwidth{\headerfont\thehead\hfil\upshape\thepage}%
    \vskip1.5\p@
    \hrule\@height.5\p@\@width\textwidth
    }}%
  \let\@evenhead\@oddhead}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \section{Titlepage}
%
% \begin{macro}{\target}
% With target we denote the group of students for whom
% the exam is meant. Defined with |\target| and called up
% with |\@target|, just like |\author|, etc.
%
%    \begin{macrocode}
\newcommand*\target[1]{\gdef\@target{#1}}\def\@target{}
%</cls>
%    \end{macrocode}
% \end{macro}
%
% The titlepage is best set by a redefined |\maketitle|. Of course it 
% needs to be suppressed if the \texttt{notitlepage} option is given
% on the |\documentclass| call. Provide two versions, one
% for a real exam and one for collections and/or answers.
% See the example below, supplied in \emph{exam.cfg}.
%
% The titlepage is set by a redefined |\maketitle|. Of course it 
% needs to be suppressed if the notitlepage option is given
% on the |\documentclass| call. Provided are two versions, one
% for a real exam and one for collections and/or answers.
%
% \subsection{Example titlepage}
%
%    \begin{macrocode}
%<*cfg>
%
\if@titlepage
\renewcommand*\maketitle{%
\begin{titlepage}
  \begin{center}\titlefont
    \vspace*{1cm}%
    \mbox{}\rule{2cm}{0.4pt}\mbox{}\par
    \addvspace{1cm}%
    \begin{Large}
      \textbf{\ifseries\Collection\else\Exam\fi}\\[10mm]
    \end{Large}
    \begin{large}
      \@title\\[5mm]
      \ifseries\@author\else\@target\fi\\[5mm]
      \@date\\[10mm]
    \end{large}
    \mbox{}\rule{2cm}{0.4pt}\mbox{}\par
    \addvspace{2cm}%
  \ifseries
    \vfill\vfill
    \begin{flushleft}\emph{Copyright notice, if any.}\end{flushleft}%
  \else\ifanswers
      \begin{huge}\Answers\end{huge}\par
    \else
      \begin{minipage}{.75\textwidth}%
      \raggedright\parindent\medskipamount
        Name:\enspace\dotfill\strut\par
        Address:\enspace\dotfill\strut\par
        City:\enspace\dotfill\strut\par
        Student number:\enspace\dotfill\strut\par
        \vspace{1cm}%
        \begin{itemize}%
        \item Please write legible, what cannot be read
            cannot be given credit.
        \item Put your name and student number on all
            on all separate sheets of paper.
        \item This exam has \theproblemnum\ problems.
        \end{itemize}%
      \end{minipage}\\[10mm]
      Good luck!\par
    \fi
  \fi
  \end{center}%
\end{titlepage}\let\maketitle=\relax}
%    \end{macrocode}
%
% And in case no title page requested:
%
%    \begin{macrocode}
\else\let\maketitle=\relax\fi
%</cfg>
%    \end{macrocode}
%
%
% \section{Language Dependent Items}
%
% \begin{macro}{\Exam}
% \begin{macro}{\Collection}
% \begin{macro}{\Answers}
% \begin{macro}{\Answer}
% \begin{macro}{\Problem}
% Predefine all language specific macros, 
% default is the English language.
%
%    \begin{macrocode}
%<*cls>
\newcommand*\Exam{EXAM}
\newcommand*\Collection{COLLECTION OF EXAMS}
\newcommand*\Answers{ANSWERS}
\newcommand*\Answer{Answer}
\newcommand*\Problem{Problem}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Dutch equivalents}
%
%    \begin{macrocode}
%</cls>
%<*cfg>
\renewcommand*\Answers{ANTWOORDEN}
\renewcommand*\Answer{Antwoord}
\renewcommand*\Exam{TENTAMEN}
\renewcommand*\Collection{TENTAMENBUNDEL}
\renewcommand*\Problem{Opgave}
%</cfg>
%<*cls>
%    \end{macrocode}
%
% \section{Initializations}
%
% \subsection{Fonts}
%
% \begin{macro}{\headerfont}
% \begin{macro}{\bodyfont}
% \begin{macro}{\titlefont}
% Fonts for pageheader, body of the text and on the titlepage.
%
%    \begin{macrocode}
\newcommand*\headerfont{\rmfamily\small}
\newcommand*\bodyfont{\sffamily}
\newcommand*\titlefont{\rmfamily\upshape}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% And initialize to |\bodyfont|.
%
%    \begin{macrocode}
\bodyfont
%    \end{macrocode}
%
% \subsection{Directory Localization}
%
% \begin{macro}{\CurrentDirectory}
% \begin{macro}{\DirectorySeparator}
% We can determine from |\@currdir| which
% character separates directories in a path name. 
% E.g. in UNIX this is |/| from the string |./|, but
% in the MacOS the current directory and the separator are both |:|.
% Therefore we extract from |\@currdir| the last character 
% (of two at most).\\
% Make |\CurrentDirectory| a synonyme for |\@currdir|.
%
%    \begin{macrocode}
\let\CurrentDirectory=\@currdir
\def\DirectorySeparator#1#2`\^^M{\@ifemptyarg{#2}{#1}{#2}}
\edef\DirectorySeparator{%
	\expandafter\DirectorySeparator\CurrentDirectory`\^^M}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\LastChar}
% Another macro delivers the last character of a string.
%
%    \begin{macrocode}
\providecommand*{\LastChar}[1]{%
  \@ifemptyarg{#1}{}{\expandafter\@lastchar#1`\^^M}}
\def\@lastchar#1#2`\^^M{\@ifemptyarg{#2}{#1}{\@lastchar#2`\^^M}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DirectoryName}
% The next macro ensures that a path name ends correctly, when
% a filename is concatenated with it.
% If the directory separator character isn't the last character,
% it is added.
%
%    \begin{macrocode}
\providecommand*{\DirectoryName}[1]{\@ifemptyarg{#1}{}%
  {\if\LastChar{#1}\DirectorySeparator\relax#1\else
    #1\DirectorySeparator\fi}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Setfolder}
% Macro |\Setfolder| can be used to install a standard
% folder (directory) name.
% E.g. a name |\figuresfolder| can be defined as the
% standard place for figures.
% Supply as first argument to |\Setfolder| the macro name
% for the folder. e.g. |\figuresfolder| and as second
% parameter its location on disk.
% Below three of these folders (here initialized 
% with empty names) are defined in the example configuration file.
%    \begin{macrocode}
\newcommand*\Setfolder[2]{\edef#1{\DirectoryName{#2}}}
%</cls>
%<*cfg>
\Setfolder{\mainfolder}{}
\Setfolder{\commonfolder}{}
\Setfolder{\figuresfolder}{}
%</cfg>
%<*cls>
%    \end{macrocode}
% \end{macro}
%
% \subsection{Configuration File}
%
% Last, but not least, see if there is a configuration
% file \texttt{exam.cfg} and read it for the final adjustments.
%
%    \begin{macrocode}
\InputIfFileExists{exam.cfg}{}{}
%    \end{macrocode}
%
% \subsection{Macros Needed but Possibly Missing}
%
% \begin{macro}{\square}
% \begin{macro}{\boxtimes}
% Possibly the following macros are still undefined; here we guarantee
% they are available. You may define them yourselves in
% \emph{exam.cfg} or in your document.
%
%    \begin{macrocode}
\providecommand\square{\bigcirc}
\providecommand\boxtimes{\surd}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%    \begin{macrocode}
%</cls>
%    \end{macrocode}
%
% \section{Coding of Example Questions}
%
%    \begin{macrocode}
%<*exa>
\begin{problem}
\problemdate{\today}
What is the question?
\score{2}
\shortanswer{To be or not to be.}
\end{problem}
%</exa>
%    \end{macrocode}
%
%    \begin{macrocode}
%<*exb>
\parameterproblem{1= to be\\2= not to be}
\problemdate{\today}
\begin{problem}
\score{2}
What is\ifnum\parameter=1\relax\else n't\fi\ the question?
\shortanswer{\ifnum\parameter=1\relax To be or n\else N\fi ot to be.}
\end{problem}
%</exb>
%    \end{macrocode}
% \Finale
%