summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/examdesign/examdesign.dtx
blob: 77876612b4e0220065742e0e390e10003d6fbca9 (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
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
% \iffalse
% File: examdesign.dtx Copyright (C) 1997-2001 Jason Alexander
% Copyright (C) 19yy  name of author
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License along with
% this program; if not, write to the Free Software Foundation, Inc., 59 Temple
% Place - Suite 330, Boston, MA  02111-1307, USA.
%
% For error reports, or offers to help improve the 'examdesign' class 
% please contact me at jalex@uci.edu.
% \fi
%         \ProvidesFile{examdesign.dtx}
%          [1997/11/22 v1.02 `examdesign' class (JMA)]
% \iffalse
%<*driver>
\documentclass{ltxdoc}
\usepackage{tabularx}
\CodelineIndex
\EnableCrossrefs
\RecordChanges
\begin{document}
\DocInput{examdesign.dtx}% \PrintIndex
\end{document}
%</driver>
%\fi
% \MakeShortVerb{\|}
% \MakeShortVerb{\"}
%
% \def\fileversion{v1.1}
% \def\filedate{2001/3/26}
% \changes{v1.00}{1997/10/11}{Initial version.}
% \changes{v1.01}{1997/10/22}{Fixed several bugs, added
%      \texttt{StudentInfoLineSpacing}
%      command, included two example files
%      to better illustrate the class features.}
% \changes{v1.02}{1997/11/22}{Added the \textsf{block}, \textsf{frontmatter},
%       \textsf{endmatter}, \textsf{examtop}, \textsf{keytop}, \textsf{exampreface},
%       \textsf{keypreface}, \textsf{examclosing}, \textsf{keyclosing} environments
%       and the commands \texttt{word}, \texttt{exam}, \texttt{key},
%       \texttt{examvspace}, \texttt{examvspace*}, \texttt{examhspace},
%       \texttt{examhspace*}, \texttt{keyvspace}, \texttt{keyvspace*},
%       \texttt{keyhspace}, and \texttt{keyhspace*}. Fixed a bug that prevented
%       the \textsf{multiplechoice} environment from identifying the answer
%       in the answer key if the correct answer was the last choice.  Added
%       the \texttt{onekey} option. Fixed a careless bug that broke the
%       cedilla.}
% \changes{v1.1}{2001/3/26}{Reworked the internal code, added the
% \textsf{matching} environment, and changed the input syntax considerably to
% make it (I hope) more user-friendly. Questions can now be numbered
% continously across sections, plus more\ldots}
% \changes{v1.101}{2006/09/05}{Jim Hefferon Changed name of files and class to
% examdesign to avoid name clashes with another package, after getting OK
% from author.}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \title{The \textsf{examdesign} class\thanks{This file
%        has version number \fileversion, last
%        revised \filedate.}}
% \author{Jason Alexander}
% \date{\filedate}
% \maketitle
% \hfuzz=72pt
% \vfuzz=36pt
%
% \DoNotIndex{\if,\else,\fi,\expandafter}
% \DoNotIndex{\csname,\endcsname}
% \DoNotIndex{\addtocounter,\stepcounter,\advance,\Alph,\alph,\arabic}
% \DoNotIndex{\begin,\end,\begingroup,\endgroup,\catcode,\centerline,\day,\def}
% \DoNotIndex{\divide,\do,\edef,\endgroup,\evensidemargin,\fbox,\gdef,\global}
% \DoNotIndex{\headheight,\headsep,\hfill,\hphantom,\Huge,\ifnum,\ifx,\large}
% \DoNotIndex{\long,\m@ne,\mbox,\medskip,\message,\month,\multiply}
% \DoNotIndex{\noindent,\nopagebreak,\normalsize,\oddsidemargin,\pagebreak}
% \DoNotIndex{\par,\relax,\rightmargin,\roman,\setcounter,\setlength}
% \DoNotIndex{\smallskipamount,\space,\textheight,\textsf,\textwidth}
% \DoNotIndex{\the,\topmargin,\undefined,\underline,\value,\vspace}
% \DoNotIndex{\xdef,\year,\z@,\time,\topsep}
%
% \begin{abstract}
% A new class, \textsf{examdesign}, for \LaTeXe\ is defined.  It provides
% several features useful for designing tests or question sets: (1) it allows
% for an explicit markup of questions and answers; (2) the class will, at the
% user's request, automatically generate answer keys; (3) multiple versions of
% the same test can be generated automatically, with the ordering of questions
% within each section randomly permuted so as to minimize cheating; (4) the
% generated answer keys can be constructed either with or without the
% questions included; and (4) some environments are provided to assist in
% constructing the most common types of test question: matching,
% true/false, multiple-choice, fill-in-the-blank, and short answer/essay
% questions
% \end{abstract}
%
% \section{Description}
%
% Teaching is a rewarding and enjoyable profession, designing exams is not.
% \emph{Grading} exams is even worse, but for help with that last bit you'll
% need more than a \LaTeX\ class.  This class file started out with a
% relatively simply goal: randomize a collection of questions so that the
% author wouldn't need to do it by hand.  Since then, it has grown
% in functionality and size and is now (I hope) a reasonably complete
% general-purpose class for constructing exams and question sets.
%
%
% \section{Usage}
%
% To begin, simply create a new \LaTeXe\ document starting with
% \begin{verbatim}
% \documentclass{examdesign}
% \begin{document}\end{verbatim}
% If you want to create an exam in 12pt type, use
% "\documentclass[12pt]{examdesign}" instead.  If you need to load
% additional packages, they may be loaded via the command "\usepackage" as
% always.  The class includes a number of packages included with a standard \LaTeX\
% distribution: \textsf{keyval}, \textsf{multicol}, and \textsf{enumerate}.
% If you don't have these packages, your \LaTeX\ distribution is nonstandard
% (or incomplete), and you'll have to grab these packages from the nearest
% CTAN site in order to use \textsf{examdesign}.
%
% Most exams/questions sets are split into sections according to the type of
% question asked, and \textsf{examdesign} follows this practice.  There are five
% environments defined, one environment for each type of question: \textsf{matching},
% \textsf{shortanswer}, \textsf{truefalse}, \textsf{multiplechoice}, and
% \textsf{fillin}.  \textbf{N.B.} Previous versions of \textsf{examdesign} had
% starred forms of these environments of well.  The starred forms (as well as
% the \textsf{fixed} environment, have been eliminated in this new release.
% Their functionality has been incorporated into the standard environments.
%
% All the environments are designed to make binding answers to questions
% easier. This not only makes the job of writing the exam easier, 
% but it allows the automated generation of answer keys.
%
% \subsection{Switches}
% There are two ways to customize the output of the \textsf{exam}
% class: switches and special formatting environments.
% Descriptions of the special formatting environments (such as
% \textsf{frontmatter}, \textsf{endmatter}, etc.) can be found in section
% \ref{SFE}. 
%
% A switch is a single command that changes an internal parameter
% influencing the overall formatting of the exam.  Switches should be included
% in the preamble because doing so will guarantee that they will apply to the
% entire exam.  Putting
% switches elsewhere may result in odd results because \textsf{examdesign} shuffles
% around what you write quite a lot, and you won't always know when a
% switch will be executed.
%
% One change between this release and previous releases is that all of the
% class options unique to \textsf{examdesign} have been converted to switches for
% sake of consistency. 
%
% \DescribeMacro{\NoRearrange}
% Although the original reason behind writing \textsf{examdesign} was to automate
% the random rearranging of questions, people have pointed out that it would
% be nice to turn off the feature (say, when writing the exam).  The
% "\NoRearrange" switch suppresses the rearrangement of questions.  You can
% override this setting on a section-by-section basis, though, by setting the
% correct environment option (see the discussion of the options in
% section~\ref{env} for more details).  In addition, see the discussion of the
% "\setrandomseed" macro below for how to generate ``randomly rearranged''
% question sets in the \emph{same} order across runs.
%
% \DescribeMacro{\NoKey}
% \DescribeMacro{\OneKey}
% The switch "\NoKey" suppresses the generation of all answer keys, whereas
% "\OneKey" generates an answer key for the first exam only.  
%
% \DescribeMacro{\BoldfaceCorrectMultipleChoiceAnswer}
% \DescribeMacro{\UnderlineCorrectMultipleChoiceAnswer}
% The switch "\BoldfaceCorrectMultipleChoiceAnswer" identifies the correct
% answer in multiple choice questions by using boldface text instead of
% placing a box around the correct letter.  The switch
% "\UnderlineCorrectMultipleChoiceAnswer" identifies the correct answer in
% multiple 
% choice questions by underlining.  These two switches are cumulative:
% including both in your exam will 
% give you boldface underlined answers (the order doesn't matter).  If neither
% one is specified, 
% \textsf{examdesign} will default to boxing the letter of the correct answer.  This
% is shown in the examples below. 
%
% Technical note: The ordinary \LaTeXe\ "\underline" command does not work
% well when the underlined text spans several lines. Consequently,
% I've incorporated the \textsf{ulem} package, written
% by Donald Arseneau, for underlining.  Since this package is embedded
% in this class, you do not need to load it again if you should need it.
%
% \DescribeMacro{\NumberOfVersions}
% The "\NumberOfVersions" macro takes a single numerical argument---the number of
% different versions of the test to generate.  Under the default
% settings, if you request more than 26 versions of the test you will
% get an error.  This is because the forms are labelled according to letters of
% the alphabet, and \LaTeXe\ doesn't like it when you try to ask
% for the 27th letter of the alphabet.  If you \emph{really} need more than 27
% copies of an exam, you will need to use one of the
% special formatting environments redefine the material inserted at the top of
% each exam and key.
%
% \DescribeMacro{\class}
% The "\class" macro takes one argument: the name of the class to appear on
% the exam.  For example, "\class{Math 205A: Set Theory}" will cause the
% name of the class to appear in the appropriate place (if you are using the
% default setting).
%
% \DescribeMacro{\examname}
% |\examname| takes one argument, just like |\class|.  The argument is used to
% identify the type of test.  For example, |\examname{Final Exam}|,
% |\examname{Midterm Exam}|, |\examname{Pop Quiz}|,\ldots
%
% \DescribeMacro{\ConstantBlanks}
% |\ConstantBlanks| has one mandatory argument (a length).  It tells \TeX\ to
% typeset the underline in fill-in-the-blank environments using lines of a
% constant length, regardless of the length of the correct word.
%
% \DescribeMacro{\ProportionalBlanks}
% |\ProportionalBlanks| has one mandatory argument (a real number $r$). It tells \TeX\
% to typeset the underline in fill-in-the-blank environments using lines that
% are exactly $r$ times the length of the correct answer when the correct
% answer is typeset by \TeX.  The default setting is |\ProportionalBlanks{1}|.
% If you include both "\ConstantBlanks" and "\ProportionalBlanks" in the preamble,
% the exam will be typeset using whichever switch was last set.
%
% \DescribeMacro{\StudentInfoLineSpacing}
% |\StudentInfoLineSpacing| requires a length as its argument.  This value
% is used to determine the amount of additional spacing between lines in
% the student data box appearing in the upper right-hand corner of the exam.
% The default value is 6pt.  If you change the definitions these environments
% using \textsf{examtop} and \textsf{keytop}, this command will have no effect.
%
% \DescribeMacro{\SectionFont}
% This macro takes one argument, which can be any declarative font-changing
% commands (i.e., "\em" rather than "\emph").  It changes the default font
% used to typeset the section titles.
%
% \DescribeMacro{\ContinuousNumbering}
% This macro takes no argument.  It changes the default numbering behavior.
% Instead of resetting the numbers at the start of each section, it will
% continue the numbering from previous sections.  (Notice that the
% \textsf{matching} and \textsf{truefalse} environments are not affected by
% this, as they don't number their questions.)
%
% \DescribeMacro{\ShortKey}
% This macro takes no argument.  It changes the way answer keys are typeset.
% Basically, it will delete any question text, any instructions at the start
% of a block of questions (or at the start of a section), and only print the
% answer.  
%
% \DescribeMacro{\DefineAnswerWrapper}
% This macro takes two arguments.  For the \textsf{shortanswer} environment,
% the first argument will always be inserted before the answer, and the second
% argument will always be inserted after the answer.  
%
% \DescribeMacro{\SectionPrefix}
% This macro takes one argument, which specifies the default appearance of the
% section number preceding each title.  Its default setting is\hfil\break
% "\SectionPrefix{Section \arabic{sectionindex}. \space}"
%
%
% \subsubsection{Summary of Switches}
%
% \medskip
%
% \begin{tabular}{p{2in}l}
% {\large Switch Name} \rule[-3pt]{0pt}{15pt} & {\large Function} \\ \hline
% "\NoKey" &  Suppress all answer keys \\
% "\OneKey" & Generate only the first answer key, suppressing all others \\
% \multicolumn{2}{l}{\texttt \textbackslash BoldfaceCorrectMultipleChoiceAnswer See above}\\
% \multicolumn{2}{l}{\texttt \textbackslash UnderlineCorrectMultipleChoiceAnswer See above}\\
% "\NumberOfVersions" & specify number of exams to make \\ 
% "\class" & Class data (E.g., ``Philosophy 29'') \\ 
% "\examname" & Exam name (E.g., ``Midterm Exam'') \\ 
% "\ConstantBlanks" & See above \\ 
% "\ProportionalBlanks" & See above \\ 
% "\StudentInfoLineSpacing" & Set spacing in data box \\
% "\SectionFont" & Change section font\\
% "\ContinuousNumbering" & Change numbering style\\
% "\ShortKey" & Change key formatting\\
% "\DefineAnswerWrapper" & Change tags surrounding answers\\
% "\SectionPrefix" &  Change the appearance of the section number\\
% \end{tabular}
% \MakeShortVerb{\|}
%
% \subsection{Environments\label{env}}
%
% There has been a significant change in the environments between this version
% of \textsf{examdesign} and earlier versions.  In this version, all question
% environments can take an optional single argument which can be used to set a
% number of different parameters.  (Before, the optional argument was used to
% set the title for a section.)  Exams written for the previous version will
% have to be updated to work with the new version.  Sorry.
%
% The options available for each section are:
%
% \noindent
% \begin{tabularx}{\linewidth}{>{\tt}lX}
% Name & Function\\\hline
% title & Specifies the title for each section.  When no title is specified,
% no section number is displayed (giving an entirely blank header before the
% section). However, the section instructions will still be printed.  If you
% would like a section number \emph{without} a title, simply give a blank
% space for the title, or use "\relax", as in "title={ }" or "title={\relax}".\\
% rearrange & This option takes one of two values, either "yes" or "no".  If
% "yes",then the questions in that section are randomly rearranged; if "no",
% then questions in that section appear in the order in which they are
% written.  This option works for all environments (and hence replaces the old
% \textsf{fixed} environment).\\
% resetcounter & This option takes one of two values, either "yes" or "no".
% If "yes", then the question numbers for that section start at 1, overriding
% the "\ContinuousNumbering" switch.  If "no", then the question numbers for
% that section will not be reset.  This gives you section-level control over
% the numbering.\\
% keycolumns & This option should be set to a number.  It specifies the number
% of columns that should be used when typesetting the section in the answer
% key.  For example, if you use the "\ShortKey" switch to only include the
% correct answer for multiple-choice questions, each answer takes up very
% little space on the line.  If you have 40 questions, it would take 40
% lines---a waste of paper.  Setting "keycolumns=5" would typeset the answer
% key using 5 columns, requiring only 8 lines for the answers.  The section
% instructions will \emph{not} be typeset in columns, but will span the width
% of the page, instead.  Note that it is very easy to get overfull/underfull
% box messages with this option (and the next).\\
% examcolumns & Same as above, except it affects the exam.\\
% suppressprefix & Can be set to either "yes" or "no".  If "yes", it
% suppresses the section prefix for that particular section; if "no", the
% prefix will appear as always.  This option replaces the starred environments
% in the the previous release.\\
%\end{tabularx}
%
% \subsubsection{The \textsf{fillin} environment}
%
% This environment is for fill-in-the-blank questions.  
% The syntax is:
% \begin{verbatim}
% \begin{fillin}[title={Insert title here}]
%   \begin{question}
%     How much \blank{wood} could a \blank{woodchuck} chuck if a woodchuck could
%     \blank{chuck} wood?
%   \end{question}
% \end{fillin}\end{verbatim}
% When typeset using "\ProportionalBlanks", the questions will be printed in
% the exam as: 
% \def\blank#1{$\underline{\mbox{\hphantom{#1}}}$}
% \begin{enumerate}
%   \item How much \blank{wood} could a \blank{woodchuck} chuck if a woodchuck could
%         \blank{chuck} wood?
% \end{enumerate}
% but in the answer key as:
% \def\blank#1{$\underline{\mbox{#1}}$}
% \begin{enumerate}
%   \item How much \blank{wood} could a \blank{woodchuck} chuck if a woodchuck could
%         \blank{chuck} wood?
% \end{enumerate}
%
% \subsubsection{The \textsf{shortanswer} environment}
%
% The \textsf{shortanswer} environment does not format its questions in any
% way other than enumerating them.  (It is then a catch-all environment for
% any other type of question.)  It does allow the group of
% answers with questions. Including an answer is not mandatory (but you will get
% errors if you do not include an answer and ask for a "\ShortKey").
% The general syntax is:
% \begin{verbatim}
% \begin{shortanswer}[title={Interesting questions...},
%                     rearrange=yes]
%   \begin{question}
%     State Hobbes' definition of the state of nature and the role it plays in
%     his social philosophy.
%     \begin{answer}
%       The state of nature is\ldots
%     \end{answer}
%   \end{question}
%
%   \begin{question}
%     State several examples that seem to illustrate that Mill's theory of
%     Utilitarianism cannot be followed in practice, and explain why.
%     Afterwards, state Mill's response to the problems you raised.
%     \begin{answer}
%       Often times it appears we need to act on our moral instincts without
%       taking time to deliberate (as in the case of saving a drowning child).
%       According to Mill, though, it seems that before each moral action we
%       ought to deliberate in order to be sure that the action we take is such
%       as to maximize the overall general utility\ldots
%     \end{answer}
%   \end{question}
% \end{shortanswer}
% \end{verbatim}
% \vspace{-\baselineskip}
% Note that the \textsf{answer} environment appears inside the \textsf{question}
% environment.  
%
% In the exam, this will be typeset as:
% \begin{enumerate}%
%   \item State Hobbes' definition of the state of nature and the role it plays in
%         his social philosophy.
%   \item State several examples that seem to illustrate that Mill's theory of
%     Utilitarianism cannot be followed in practice, and explain why.
%     Afterwards, state Mill's response to the problems you raised.
% \end{enumerate}%
% The answer key, in normal form with the default definition of
% "\DefineAnswerWrapper", will appear as: 
% \begin{enumerate}%
%   \item State Hobbes' definition of the state of nature and the role it plays in
%         his social philosophy.
%         \begin{description}%
%            \item[Answer:] The state of nature is\ldots
%         \end{description}%
%   \item State several examples that seem to illustrate that Mill's theory of
%         Utilitarianism cannot be followed in practice, and explain why.
%         Afterwards, state Mill's response to the problems you raised.
%         \begin{description}%
%            \item[Answer:] Often times it appears we need to act on our moral
%                instincts without taking time to deliberate (as in the case of
%                saving a drowning child). According to Mill, though, it seems that
%                before each moral action we ought to deliberate in order to be sure
%                that the action we take is such as to maximize the overall general
%                utility\ldots
%         \end{description}%
% \end{enumerate}%
% If you specify a "\ShortKey", only the answers will be presented:
% \begin{enumerate}%
%   \item \begin{description}
%            \item[Answer:] The state of nature is\ldots
%         \end{description}
%   \item \begin{description}
%            \item[Answer:] Often times it appears we need to act on our moral
%                instincts without taking time to deliberate (as in the case of
%                saving a drowning child). According to Mill, though, it seems that
%                before each moral action we ought to deliberate in order to be sure
%                that the action we take is such as to maximize the overall general
%                utility\ldots
%         \end{description}
% \end{enumerate}
%
%
% \subsubsection{The \textsf{truefalse} environment}
%
% True/false questions.  The general syntax is:
% \begin{verbatim}
% \begin{truefalse}
%   \begin{question}
%     \answer{False} Laden swallows fly faster than unladen swallows,
%     especially if they carry coconuts.
%   \end{question}
%
%   \begin{question}
%     \answer{True} Quantum mechanics was first stated using the
%     mathematical tools of Hilbert spaces by John von~Neumann.
%   \end{question}
% \end{truefalse}\end{verbatim}
%
% Again, note that the \textsf{answer} environment appears within the
% \textsf{question} environment.  The above will be typeset in the exam as:
% \begin{list}{$\underline{\hskip.5in}$}{\setlength{\rightmargin}{0pt}
%                \setlength{\labelwidth}{.5in}
%                \setlength{\leftmargin}{.6in}
%                \setlength{\labelsep}{.1in}
%                \setlength{\itemindent}{0in}
%                \setlength{\topsep}{4pt}
%                \setlength{\itemsep}{.1in}}
%   \item Laden swallows fly faster than unladen swallows, especially if they
%     carry coconuts.
%   \item Quantum mechanics was first stated using the mathematical tools of Hilbert
%     spaces by John von~Neumann.
% \end{list}
% It will be typeset in the answer key as:
% \begin{list}{$\underline{\hphantom{False}}$}{\setlength{\rightmargin}{0pt}
%                \setlength{\labelwidth}{.5in}
%                \setlength{\leftmargin}{.6in}
%                \setlength{\labelsep}{.1in}
%                \setlength{\itemindent}{0in}
%                \setlength{\topsep}{4pt}
%                \setlength{\itemsep}{.1in}}
%   \item[$\underline{\makebox[.5in][c]{False}}$] Laden swallows fly faster than unladen
%     swallows, especially if they carry coconuts.
%   \item[$\underline{\makebox[.5in][c]{True}}$] Quantum mechanics was first
%   stated using the mathematical tools of Hilbert spaces by John von~Neumann.
% \end{list}
%
% \subsubsection{The \textsf{multiplechoice} Environment}
%
% It isn't difficult to format multiple choice questions in ordinary \LaTeX\ with
% multiply nested \textsf{enumerate}'s, but this environment provides for a
% simpler entry scheme, and the answer key can indicate the correct answer.
% The syntax is: 
% \begin{verbatim}
% \begin{multiplechoice}
%   \begin{question}
%     How much wood could a woodchuck chuck if a woodchuck could chuck wood?
%      \choice{A lot.}
%      \choice{More than most.}
%      \choice{Exactly $\pi$ cords.}
%      \choice[!]{It depends on the nature of the woodchuck.}
%   \end{question}
% \end{multiplechoice}
% \end{verbatim}
% \vspace{-\baselineskip}
% In the exam, this is typeset as:
% \begin{enumerate}
%  \item How much wood could a woodchuck chuck if a woodchuck could chuck wood?
% \begin{list}{$\underline{\hphantom{False}}$}{\setlength{\rightmargin}{0pt}
%                \setlength{\labelwidth}{.4in}
%                \setlength{\leftmargin}{.5in}
%                \setlength{\labelsep}{.1in}
%                \setlength{\itemindent}{0in}
%                \setlength{\topsep}{0pt}
%                \setlength{\itemsep}{0pt}}
% \item[(a)] A lot.
% \item[(b)] More than most.
% \item[(c)] Exactly $\pi$ cords.
% \item[(d)] It depends on the nature of the woodchuck.
% \end{list}
% \end{enumerate}
% In the answer key, if neither of the options |mcbold| nor |mcunderline|
% were given, the answer will be typeset as:
% \begin{enumerate}
%  \item How much wood could a woodchuck chuck if a woodchuck could chuck wood?
% \begin{list}{$\underline{\hphantom{False}}$}{\setlength{\rightmargin}{0pt}
%                \setlength{\labelwidth}{.4in}
%                \setlength{\leftmargin}{.5in}
%                \setlength{\labelsep}{.1in}
%                \setlength{\itemindent}{0in}
%                \setlength{\topsep}{0pt}
%                \setlength{\itemsep}{0pt}}
% \item[(a)] A lot.
% \item[(b)] More than most.
% \item[(c)] Exactly $\pi$ cords.
% \item[\fbox{(d)}\hspace{-\fboxsep}] It depends on the nature of the woodchuck.
% \end{list}
% \end{enumerate}
% You can have up to 26 choices. Also, notice that the correct answer was
% specified by giving the optional argument "[!]" to |\choice|. 
%
% \subsubsection{The \textsf{matching} environment}
%
% This environment is new in this release of \textsf{examdesign}.  It provides an
% environment for the creation of matching tests.  The syntax is:
% \begin{verbatim}
% \begin{matching}[title={Some matching questions}]
%   \pair{John Steinbeck}{\emph{The Grapes of Wrath}}
%   \pair{Will Self}{\emph{My Kind of Fun}}
%   \pair{Charles Darwin}{\emph{The Origin of Species}}
% \end{matching}\end{verbatim}
% In the exam, this will be typeset as:
% \begin{multicols}{2}
% \begin{quote}
% \begin{enumerate}
% \item[\underline{\hskip .5in}] Will Self
% \item[\underline{\hskip .5in}] Charles Darwin
% \item[\underline{\hskip .5in}] John Steinbeck
% \columnbreak
% \item[(a)] \emph{The Origin of Species}
% \item[(b)] \emph{The Grapes of Wrath}
% \item[(c)] \emph{My Kind of Fun}
% \end{enumerate}
% \end{quote}
% \end{multicols}
% In the answer key, this will be typeset as:
% \begin{multicols}{2}
% \begin{quote}
% \begin{enumerate}
% \item[\underline{\makebox[.5in][c]{(c)}}] Will Self
% \item[\underline{\makebox[.5in][c]{(a)}}] Charles Darwin
% \item[\underline{\makebox[.5in][c]{(b)}}] John Steinbeck
% \columnbreak
% \item[(a)] \emph{The Origin of Species}
% \item[(b)] \emph{The Grapes of Wrath}
% \item[(c)] \emph{My Kind of Fun}
% \end{enumerate}
% \end{quote}
% \end{multicols}
% The "\pair" macro preceeds the \emph{matched} pair of statements.  The
% environment will randomly shuffle the first and second columns in order to
% create the (hopefully randomized) lists.  Because of the way the randomizer
% is implemented, this environment will produce better results (i.e., more
% scrambled) results the longer the list of questions is.
%
% \textbf{N.B.} The \textsf{block} environment will break badly in this
% environment, so don't use it.
%
%
% \subsubsection{The \textsf{block} environment}
%
% The \textsf{block} environment lets you identify a group of questions,
% as well as some preceeding text, as a ``block'' that should be kept together
% even though the rest of the section gets rearranged.  (The questions inside
% the block will not be rearranged.  That's on my to-do list, but it will take
% more time than I have, and it's already been a long time since the last
% update.)  
%
% The syntax is straightforward. For example:
% \begin{verbatim}
% \begin{block}
% Here is a spot where you can put some instructions, a graph, or whatever
% you want to preceed the questions in this block.
%  \begin{question}
%    This is the first question.
%    \begin{answer}
%      This is the answer to the first question.
%    \end{answer}
%  \end{question}
%
%  \begin{question}
%    This is the second question.
%    \begin{answer}
%      This is the answer to the second question.
%    \end{answer}
%  \end{question}
%
%  \begin{question}
%    This is the third question.
%    \begin{answer}
%      This is the answer to the third question.
%    \end{answer}
%  \end{question}
% \end{block}\end{verbatim}
% Will keep those three questions together when the rearranging happens.
%
% The \textsf{block} environment may be used in \emph{any} of the previously
% described question environments, except for the \textsf{matching}
% environment.  (There were some problems with using blocks inside some of the
% other environments with earlier versions---I believe those bugs have been
% fixed.)
%
% The \textsf{block} environment can take a special optional argument,
% "questions", that specifies the number of questions in the block.
% Specifying this option sets two counters, "first" and "last", so that you
% can refer to the particular questions that fall within the block in the
% instructions.  So, for example:
% \begin{verbatim}
% \begin{block}[questions=3]
% \noindent For questions \thefirst--\thelast, consider the following data...\end{verbatim} 
% would, if the block appeared after question 13, be typeset as:
% 
% \bigskip
% \noindent For questions 14--16, consider the following data...\par\bigskip
%
% In previous versions of \textsf{examdesign}, blocks were typeset indented from the
% left margin.  This was undesireable because the block instructions could
% be misread as belonging to the end of the preceeding question.  As of this
% version, block instructions are typeset using no such indent.
%
%
% \section{Special Formatting Tools}
%
% The following environments, macros, and length parameters allow the user to
% customize virtually every aspect of the exam.  As I describe below, the default
% settings of the \textsf{examdesign} are defined using these environments.
%
% \subsection{Special Formatting Environments \label{SFE}}
%
% \DescribeEnv{frontmatter}
% Any material enclosed in the \textsf{frontmatter} environment will be
% typeset on a page (or pages) by itself before the exam (and the key, too).
% For example, if one
% wanted to make a cover sheet for the exam with the class name and a place for
% the student to write their name, i.d. number, and so forth.
%
% \DescribeEnv{endmatter}
% Any material enclosed in the \textsf{endmatter} environment will be
% typeset on a page (or pages) by itself after the exam (and the key, too).
% For example, if one wanted to place a page with several important equations,
% constants, and tables at the end of the exam for students to reference, if
% needed.
%
% \DescribeEnv{examtop}
% Any material enclosed in the \textsf{examtop} environment will be
% typeset on the next page following the \textsf{frontmatter} text, if an exam
% is being created, and will be omitted if an answer key is being created.  The
% default settings of the \textsf{examdesign} class use this environment to create
% the area for the class name, student name, etc. as follows:
% \begin{verbatim}
% \begin{examtop}
%   \@@line{\parbox{3in}{\classdata \\
%           \examtype, Form: \fbox{\textsf{\Alph{version}}}}
%           \hfill
%           \parbox{3in}{\normalsize \namedata}}
%           \bigskip
% \end{examtop}\end{verbatim}
% Where "\classdata" and "\examtype" are macros that use
% the current values assigned by the switches "\class" and "\examname".
% 
%
% The definition of "\namedata" is:
% \begin{verbatim}
% \def\namedata{Name: \hrulefill \\[\namedata@vspace]
%              Student Number: \hrulefill \\[\namedata@vspace]
%              TA: \hrulefill \\[\namedata@vspace]
%              Date: \hrulefill}\end{verbatim}
% Where "\namedata@vspace" is the length set by the switch
% "\StudentInfoLineSpacing".
%
% For those who don't know, "\@@line" is the \LaTeXe\ equivalent of Plain \TeX's
% "\line" command.  If you wish to use "\@@line" in defining your own \textsf{examtop}
% or \textsf{keytop}, please be sure to use "\makeatletter" and "\makeatother"
% in the appropriate places, otherwise you could get errors.
%
% \DescribeEnv{keytop}
% Any material enclosed in the \textsf{keytop} environment will be
% typeset on the next page following the \textsf{frontmatter} text, if a key
% is being created, and will be omitted if an exam is being created.  The
% default settings of the \textsf{examdesign} class use this environment to create
% the top of an answer key as follows:
%  \begin{verbatim}
%  \begin{keytop}
%  \@@line{\hfill \Huge Answer Key
%          for Exam \fbox{\textsf{\Alph{version}}}\fi \hfill}
%          \bigskip
%  \end{keytop}\end{verbatim}
%
% \DescribeEnv{exampreface}
% Any material enclosed in the \textsf{exampreface} environment will be
% typeset on the same page as the \textsf{examtop} text, right beneath it but
% before any sections of the exam are included.  In case you are wondering what
% this environment does that cannot be done with \textsf{examtop}, your question
% is very good.  The difference is this: The material enclosed in the
% \textsf{exampreface} environment is sensitive to whether the \texttt{twocolumn}
% option was given.  If the \texttt{twocolumn} option \emph{was} given, then
% the material in \textsf{exampreface} will be typeset at the start of the
% first column. By contrast, the material given in \textsf{examtop} is
% \emph{always} typeset in a single column spanning the entire textwidth of
% the page, at the top of the exam. 
%
% \DescribeEnv{keypreface}
% Any material enclosed in the \textsf{keypreface} environment will be
% typeset on the same page as the \textsf{keytop} text, right beneath it but
% before any sections are included.  As described above, if the
% \texttt{twocolumn} option \emph{was} given, then the material
% in \textsf{keypreface} will be typeset at the start of the first column. By
% contrast, the material given in \textsf{keytop} is \emph{always} typeset in a single
% column spanning the entire textwidth of the page, at the top of the key.
%
% \DescribeEnv{examclosing}
% Essentially the same as the \textsf{exampreface} environment, with the
% obvious change that the enclosed material is typeset at the end of the exam,
% on the same page as the rest of the exam (if possible), but before the
% \textsf{endmatter}.  (Any material enclosed in an \textsf{endmatter}
% environment is typeset on a page by itself after the exam or key.)
%
% \DescribeEnv{keyclosing}
% Essentially the same as the \textsf{keypreface} environment, with the
% obvious change that the enclosed material is typeset at the end of the key,
% on the same page as the rest of the key (if possible), but before the
% \textsf{endmatter}.
%
%
% \subsection{Special Formatting Macros}
%
% Due to the special way the \textsf{examdesign} class constructs a document (see the
% technical notes in section \ref{TN}), several special macros are provided
% which enable the user to easily take advantage of the way exams are
% constructed.  In addition, there are several lengths which the user can modify
% to further customize the appearance of the exam.
%
% \DescribeMacro{\exam}
% The "\exam" macro takes one argument, which can be any command or
% sequence of commands subject to the constraints described in the technical
% notes.  The argument will be included wherever it is if and only if an exam is
% being made, otherwise the argument will be ignored.
%
% \DescribeMacro{\key}
% The "\key" macro takes one argument, which can be any command or
% sequence of commands subject to the constraints described in the technical
% notes.  The argument will be included wherever it is if and only if a key is
% being made, otherwise the argument will be ignored.
%
% \DescribeMacro{\examvspace}
% Just like the ordinary \LaTeX\ command "\vspace", with the exception that the vertical
% space is included if and only if an exam is being typeset.
%
% \DescribeMacro{\examvspace*}
% Just like the ordinary \LaTeX\ command "\vspace*", with the exception that the vertical
% space is included if and only if an exam is being typeset.
%
% \DescribeMacro{\examhspace}
% Just like the ordinary \LaTeX\ command "\hspace", with the exception that the
% horizontal space is included if and only if an exam is being typeset.
%
% \DescribeMacro{\examhspace*}
% Just like the ordinary \LaTeX\ command "\hspace*", with the exception that the
% horizontal space is included if and only if an exam is being typeset.
%
% \DescribeMacro{\keyvspace}
% Just like the ordinary \LaTeX\ command "\hspace*", with the exception that the
% horizontal space is included if and only if a key is being typeset.
%
% \DescribeMacro{\keyvspace*}
% Just like the ordinary \LaTeX\ command "\hspace*", with the exception that the
% horizontal space is included if and only if a key is being typeset.
%
% \DescribeMacro{\keyhspace}
% Just like the ordinary \LaTeX\ command "\hspace*", with the exception that the
% horizontal space is included if and only if a key is being typeset.
%
% \DescribeMacro{\keyhspace*}
% Just like the ordinary \LaTeX\ command "\hspace*", with the exception that the
% horizontal space is included if and only if a key is being typeset.
%
% \DescribeMacro{\word}
% The last new command (in version 1.02) is "\word".  This command
% allows the user to insert inessential changes in the wording of a question
% between various versions of the exam.  Thus, not only will the order of the
% questions be different, but the actual \emph{wording} of the questions will be
% slightly different as well.  For example, if one includes:
% \begin{verbatim}
% \begin{question}
% Is the most well-known \word{{astronomer} {wrestler} {physicist}} in
% the world \word{{Carl Sagan} {Rowdy Roddy Piper} {Albert Einstein}}?
% \end{question}\end{verbatim}
% in an exam, the first version of the exam will include the question
% \begin{enumerate}
% \item Is the most well-known astronomer in the world Carl Sagan?
% \end{enumerate}
% but the second version of the exam will include
% \begin{enumerate}
% \item Is the most well-known wrestler in the world Rowdy Roddy Piper?
% \end{enumerate}
% and the third version of the exam will include
% \begin{enumerate}
% \item Is the most well-known physicist in the world Albert Einstein?
% \end{enumerate}
%
% Let's call the argument of "\word" an \emph{option-list}.  If one requests
% more versions of an exam than options in an option-list, "\word" will behave
% as if the option list you gave ``wrapped.''  That is, if one requests five
% copies of an exam but includes "\word{{A} {B}}" in the input file, "A" will be
% printed on the fifth version of the exam, because "\word" will act as if the
% option list was "\word{{A} {B} {A} {B} {A} {B}}", where "A" is the fifth
% option.
%
% If it turns out that your exams are becoming absolutely unreadable through
% excessive use of "\word", chances are you are not introducing inessential
% changes in the wording of a question, but are actually trying to write two
% different exams simultaneously.
%
% \subsection{Length Parameters}
%
% The following table describes lengths that the user may set to whatever value
% they wish, and the effect that it has upon the appearance of the exam (or
% key).
%
% \DeleteShortVerb{\|}
% \begin{center}
% \begin{tabular}{|l|l|p{1.8in}|} \hline
% {\large Length} & {\large Initial Value} & {\large Effect} \rule{0pt}{13pt} \\ \hline
% "\beforesectsep" & "\medskipamount"         & Space inserted before the
%                                               current section heading. \\
% "\aftersectsep"  & "\medskipamount"         & Space inserted after the
%                                               current section heading. \\
% "\beforeinstsep" & "\medskipamount"         & Space inserted before any
%                                               instructions for the current
%                                               section are typeset. \\
% "\afterinstsep"  & "\medskipamount-\topsep" & Space inserted after the
%                                               instructions for the current
%                                               section but before the
%                                               questions. \\ \hline
% \end{tabular}
% \end{center}
% \MakeShortVerb{\|}
%
% Given the above parameters, there are two rules that determine whether space
% is inserted.  (1) If the section heading is empty (as might happen if someone
% used a starred environment form and then did not include any optional
% argument), then \emph{neither} "\beforesectsep" \emph{nor} "\aftersecsep" are
% used to insert vertical space, and (2) if there are no instructions for a
% section, then \emph{neither} "\beforeinstsep" \emph{nor} "\afterinstsep" are
% used to insert vertical space.
%
% \section{Miscellaneous Goodies\label{TN}}
%
% \DescribeMacro{\setrandomseed}
% The "\setrandomseed" macro allows you to specify a random seed at the start
% of an exam.  This allows you to have a ``randomized'' exam that keeps
% questions in the same scrambled order across different runs.  
% If you set the random seed, it becomes possible to have crossreferences in
% the exam.  In this release, the ordinary \LaTeX\ commands "\label" and "\ref" 
% work as expected, even across different forms of the test (with the
% questions in a different order).
%
% Math environments using numbered equations should also work correctly
% in this version. 
%
% \DescribeMacro{\pagebreak}
% Having fixed the order of the questions, you might need to introduce a
% pagebreaks at certain points.  In this release, the "\pagebreak" command
% works as expected, with one caveat.  Putting a "\pagebreak" before a section
% will introduce a pagebreak before that section, and putting a "\pagebreak"
% before a question will introduce a pagebreak before that question---no
% matter where on the page that question may be.  
%
% \DescribeMacro{\BreakPageOnVersion}
% If you want to insert pagebreaks before questions or sections conditionally
% on the exam, you will need to use the "\BreakPageOnVersion{}" macro.  This
% macro, which takes a number as its argument, will conditionally insert a
% "\pagebreak" depending on whether number of the version currently being
% typeset equals the version given as an argument to the macro.
%
% \DescribeMacro{\IncludeFromFile}
% \DescribeMacro{\InsertChunk}
% \DescribeEnv{chunk}
% If you need to use any environment which changes the catcodes of the input
% characters (such as the \textsf{verbatim} environment, or XY-pic), you will
% have to employ the following hack.  The reason for this has to do with the
% way \textsf{examdesign} scrambles the order of the questions.  (Basically, each
% question is saved to a macro for later recall.  This assigns each character
% a catcode when it is saved, so it is not possible to change the catcode at a
% later time.)
%
% The hack is the following: create another file called ``foo.tex'' (you can
% name it whatever you like) and put "\IncludeFromFile{foo.tex}" in
% the preamble of your document.  For each bit of text that you need contained
% category code changes (like the \textsf{verbatim} environment) put, in
% foo.tex, a named chunk containing that code.  I.e.,
% \begin{quote}
% "\begin{chunk}{chunk name}"\\
% "\begin{verbatim}"\\
% "  This is some verbatim text"\\
% "  This is more verbatim text"\\
% "\end{verbatim}"\\
% "\end{chunk}"
% \end{quote}
% At the appropriate place in your exam, place "\InsertChunk{chunk name}".
% This macro inserts the named chunk into the exam (or key) at that place.
% All catcode changing commands, environments, etc., should be capable of
% being inserted this way.  (If you find one that doesn't, let me know.)
%
% All of the chunks for a given exam can be stored in the same file---you just
% need to give each chunk a unique name. Only the
% chunk you request will be inserted at a particular point.  If you have a lot
% of chunks, this can slow down considerably the overall processing of the exam,
% but there's no other general solution which will work.
% 
% The chunk names can be descriptive, but don't try anything too fancy.  ``Too
% fancy'' meaning: if it causes an error, it's too fancy. 
%
% \subsection{Bugs}
%
% No known bugs.
%
% \subsection{Changes}
%
% The changes between this version and previous versions are indicated in the
% above sections. Early releases of the \textsf{examdesign} class required that
% instructions 
% for a given section be specified as such by using the "\instructions"
% command. The need for using "\instructions" has been lifted as of release
% 1.02.  The rule is this: all material between the start of a section and
% the first "\begin{question}" or "\begin{block}" will be taken to be the
% instructions for that section.  Old exams created with "\instructions" should
% still work with the new release (the "\instructions" macro has simply been
% redefined as "\relax").
%
% Thus, if you are using
% \textsf{fixed} to format a series of essay questions, you might want to tell
% students that they only need to write answers to two of the following three
% questions.  The instruction text is always
% typeset at the beginning of a section, before any questions are typeset.
%
% \endinput
%
% \section{The Code}
%
% The following code is a bit messy, and the comments don't necessarily match
% up with the code that follows.  I thought it was more important to get the
% new version out than worry about making the source pretty.  If you need to
% figure out how something works, trust the code, not the description!
%
% First just some declarations and stuff that says we are building an
% extension to the ordinary \LaTeX\ class |article|.
%    \begin{macrocode}
%<*header>
\ProvidesFile{examdesign.dtx} 
\NeedsTeXFormat{LaTeX2e} 
\ProvidesClass{examdesign}
\newcounter{passes}\setcounter{passes}{2} 
\newif\ifmcbold \mcboldfalse
\newif\ifmcunder \mcunderfalse 
\newif\ifulem \ulemfalse 
\newif\ifbox \boxtrue
\newif\iftwocolumn \twocolumnfalse 
\gdef\@OneKeyHook{\relax}
%\DeclareOption{mcbold}{\mcboldtrue\boxfalse}
%\DeclareOption{mcunderline}{\mcundertrue \boxfalse}
%\DeclareOption{nokey}{\setcounter{passes}{1}}
%\DeclareOption{onekey}{\setcounter{passes}{2}%
%  \gdef\@OneKeyHook{\setcounter{passes}{1} 
%  \gdef\@OneKeyHook{\relax}}}
\DeclareOption{twocolumn}{\twocolumntrue}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}} 
\ProcessOptions
\LoadClass{article} 

\def\NoKey{\setcounter{passes}{1}}

\def\OneKey{\setcounter{passes}{2}%
  \gdef\@OneKeyHook{\setcounter{passes}{1}
    \gdef\@OneKeyHook{\relax}}}

\def\BoldfaceCorrectMultipleChoiceAnswer{%
  \mcboldtrue
  \boxfalse
  \exam@SetCorrectChoiceFont}

\def\UnderlineCorrectMultipleChoiceAnswer{%
  \mcundertrue
  \boxfalse
  \exam@SetCorrectChoiceFont}

\def\exam@SetCorrectChoiceFont{%
  \ifmcbold 
    \ifmcunder 
    \def\MCfont##1{\textbf{\uline{##1}}}%
    \else 
    \def\MCfont##1{\textbf{##1}}%
    \fi 
  \else 
    \ifmcunder
    \def\MCfont##1{\uline{##1}}%
    \else 
    \def\MCfont##1{\relax{##1}}%
    \fi 
  \fi}

% \ifmcbold 
%   \ifmcunder 
%   \def\MCfont#1{\textbf{\uline{#1}}}
%   \else 
%   \def\MCfont#1{\textbf{#1}} 
%   \fi 
% \else 
%   \ifmcunder
%   \def\MCfont#1{\uline{#1}} 
%   \else 
%   \def\MCfont#1{\relax{#1}} 
%   \fi 
% \fi


\RequirePackage{enumerate} 
\RequirePackage{multicol} 
\RequirePackage{keyval}
%</header>
%    \end{macrocode}
%
% \subsection{The random number generator}
%
% RANDOM.TEX       v.1   (Donald Arseneau)
% Generating "random" numbers in TeX.
%
% \DescribeMacro{\nextrandom}
% Random integers are generated in the range 1 to 2147483646 by the
% macro |\nextrandom|.  The result is returned in the counter |\randomi|.
% Do not change |\randomi| except, perhaps, to initialize it at some
% random value.  If you do not initialize it, it will be initialized
% using the time and date.  (This is a sparse initialization, giving
% fewer than a million different starting values, but you should use
% other sources of numbers if they are available--just remember that
% most of the numbers available to \TeX are not at all random.)
%
% \DescribeMacro{\setrannum}
% The |\nextrandom| command is not very useful by itself, unless you
% have exactly 2147483646 things to choose from.  Much more useful
% is the |\setrannum| command which sets a given counter to a random
% value within a specified range.  There are three parameters:
% |\setrannum{|\meta{counter}|}{|\meta{minimum}|}{|\meta{maximum}|}|.
% For example, to simulate a die-roll: |\setrannum{\die}{1}{6} \ifcase\die|\ldots
%
% \DescribeMacro{\setrandimen}
% \DescribeMacro{\pointless}
% If you need random numbers that are not integers, you will have to
% use dimen registers and |\setrandimen|.  For example, to set a random
% page width: |\setrandimen \hsize{3in}{6.5in}|.  The ``|\pointless|'' macro
% will remove the ``pt'' that TeX gives so you can use the dimensions
% as pure `real' numbers.  In that case, specify the range in pt units.
% For example, |\setrandimen\answer{2.71828pt}{3.14159pt}|
% The answer is |\pointless\answer|.
%
% The random number generator is the one by Lewis, Goodman, and Miller
% (1969) and used as "ran0" in "Numerical Recipies" using Schrage's
% method for avoiding overflows.  The multiplier is $16807 (7^5)$ the
% added constant is 0, and the modulus is $147483647 (2^{31}-1)$  The
% range of integers generated is $1 - 2147483646$.  A smaller range would
% reduce the complexity of the macros a bit, but not much--most of the
% code deals with initialization and type-conversion.  On the other hand,
% the large range may be wasted due to the sparse seed initialization.
%
% I do not include the code in the documentation.
%\iffalse
%    \begin{macrocode}
%<*random>
\newcount\randomi % the random number seed (while executing)
\global\randomi\catcode`\@  % scratch variable during definitions
\catcode`\@=11
% The following macro isn't part of Arseneau's original TeX package,
% but it comes in handy when users want to recover a particular run.
\def\setrandomseed#1{\global\randomi#1\relax
  \message{Randomizer initialized to \the\randomi.}%
  \nextrandom \nextrandom \nextrandom}

\def\nextrandom{\begingroup
 \ifnum\randomi<\@ne % then initialize with time
    \global\randomi\time
    \global\multiply\randomi388 \global\advance\randomi\year
    \global\multiply\randomi31 \global\advance\randomi\day
    \global\multiply\randomi97 \global\advance\randomi\month
    \message{Randomizer initialized to \the\randomi.}%
    \nextrandom \nextrandom \nextrandom
 \fi
 \count@ii\randomi
 \divide\count@ii 127773 % modulus = multiplier * 127773 + 2836
 \count@\count@ii
 \multiply\count@ii 127773
 \global\advance\randomi-\count@ii % random mod 127773
 \global\multiply\randomi 16807
 \multiply\count@ 2836
 \global\advance\randomi-\count@
 \ifnum\randomi<\z@ \global\advance\randomi 2147483647\relax\fi
 \endgroup
}

\countdef\count@ii=2 % use only in boxes!
\ifx\@tempcnta\undefined \csname newcount\endcsname \@tempcnta \fi
\ifx\@tempcntb\undefined \csname newcount\endcsname \@tempcntb \fi

\def\setrannum#1#2#3{% count register, minimum, maximum
 \@tempcnta#3\advance\@tempcnta-#2\advance\@tempcnta\@ne
 \@tempcntb 2147483645 %  =  m - 2  =  2^{31} - 3
 \divide\@tempcntb\@tempcnta
 \getr@nval
 \advance\ranval#2\relax
 #1\ranval
}

\def\setrandim#1#2#3{% dimen register, minimum length, maximum length
 \dimen@#2\dimen@ii#3\relax
 \setrannum\ranval\dimen@\dimen@ii
 #1\ranval sp\relax
}

\def\getr@nval{% The values in \@tempcnta and \@tempcntb are parameters
 \nextrandom
 \ranval\randomi \advance\ranval\m@ne \divide\ranval\@tempcntb
 \ifnum\ranval<\@tempcnta\else \expandafter\getr@nval \fi
}

\def\pointless{\expandafter\PoinTless\the}
{\catcode`p=12 \catcode`t=12
\gdef\PoinTless#1pt{#1}}

\catcode`\@=\randomi
\global\randomi=0
\newcount\ranval
%</random>
%    \end{macrocode}
%\fi
%
% \subsection{Incorporating the package \textsf{ulem}}
% This code is not listed in the documentation.
%\iffalse
%    \begin{macrocode}
%<*ulem>
\expandafter \ifx \csname UL@box\endcsname \relax \else
 \typeout{ulem.sty refuses to load twice. }\endinput \fi
\chardef\ULthickness\catcode\string`\@ % hold catcode temporarily
\catcode\string`\@=11
\def\uline{\relax \ifmmode\expandafter\underline
           \else \bgroup\expandafter\ULset\fi}
\newbox\UL@box
\newbox\UL@hyphenbox
\newskip\UL@skip
\newcount\UL@pe
\let\LA@space\ \let\LA@hskip\hskip
\def\UL@end *{\relax\relax}% something harmless unlikely to be found elsewhere
\def\ULset{\ifdim\ULdepth=\maxdimen\setbox\UL@box\hbox{(j}\ULdepth\dp\UL@box\fi
  \def\UL@leadtype{\leaders \hrule \@height\dimen@ \@depth\ULdepth}%
  \ifmmode \ULdepth-4\p@ \fi
  \dimen@-\ULdepth \advance\dimen@\ULthickness \ULon}
\def\ULon{\ifmmode \expandafter\UL@onmath\else \expandafter\UL@on\fi}
\def\UL@on#1{\leavevmode\UL@ender \let\UL@on\UL@onin
  \everymath{\UL@hrest}\everyvbox{\UL@hrest}\let\hskip\UL@hskip
  \let\\\UL@cr \let\-\UL@dischyp \let\newline\UL@newline \let\ \UL@space
  \def\hfil{\hskip\z@ plus1fil\relax}\def\hfill{\hskip\z@ plus1fill\relax}%
  \def\hss{\hskip\z@ plus1filminus1fil\relax}\let\penalty\UL@penalty
  \UL@word\@empty#1\xdef\UL@spfactor{\the\spacefactor} \UL@end * }
\def\UL@onin#1{\leavevmode\UL@ender % when nested, do multiple underlining
  \dimen@\ULthickness \advance\ULdepth\thr@@\dimen@ \advance\dimen@-\ULdepth
  \setbox\UL@box\hbox{{#1}}\let\UL@start\relax\UL@putbox\egroup}
\def\UL@onmath#1{\UL@ender\mathord{\UL@hrest\mathop{\kern\z@#1}\limits\sb
  {\UL@leadtype\LA@hskip\p@ plus1fill}}\egroup}
\def\UL@unegroup{}
\gdef\UL@ender{}
\def\UL@swender{\ifnum`{=\z@\fi\aftergroup}\gdef\UL@ender{}}
\def\UL@word#1 {\expandafter\UL@start#1 %
  \expandafter\ifx\expandafter\UL@end#1\egroup\egroup
   \unskip \unskip \unskip % remove extra leader at end
   \spacefactor\UL@spfactor \let\UL@word\egroup
  \else % not finished
   \ifmmode\else \ifdim\lastskip=\z@\else % allow syntactical spaces
     \global\UL@skip\lastskip \unskip
     \UL@stop \UL@leaders
   \fi\fi
  \fi \UL@word\@empty}% \@empty preserves braces in param
\def\UL@start{\setbox\UL@box\hbox\bgroup\everyhbox{\UL@hrest}%
  \let\UL@start\@empty \def\UL@unegroup{\bgroup\bgroup}\let\UL@leadtype\@empty
  \bgroup \kern-3sp\kern3sp % kerns so I can test for beginning of list
  \if@ignore \global\@ignorefalse \ignorespaces \fi}
\def\UL@stop{\global\UL@pe\lastpenalty \unpenalty % penalty in \UL@pe
  \ifnum\lastkern=\thr@@ \egroup\egroup % Nothing in hbox...but make sure:
    \ifdim\wd\UL@box=\z@ \else \UL@putbox \fi % something in box so print it
  \else  \egroup\egroup \UL@putbox % something in box so print it
  \fi \ifnum\UL@pe=\z@ \else \LA@penalty\UL@pe \fi % use penalty from inside box
  \UL@unegroup}
\def\UL@putbox{\ifx\UL@start\@empty \else % not inner
  \vrule\@width\z@ \LA@penalty\@M
  {\UL@skip\wd\UL@box \UL@leaders \kern-\UL@skip}%
  \box\UL@box  \fi}
\newdimen\UL@pixel \UL@pixel=1in \divide\UL@pixel 300
\def\UL@leaders{{\LA@hskip-\UL@pixel \advance\UL@skip\tw@\UL@pixel
   \UL@leadtype\LA@hskip\UL@skip  \LA@hskip-\UL@pixel}}
\def\UL@hrest{\let\ \LA@space \let\-\@empty \let\penalty\LA@penalty}
\def\UL@space{\LA@space \global\UL@skip\lastskip \unskip \UL@reskip}% \
\def\UL@dischyp{\global\setbox\UL@hyphenbox\hbox
   {\ifnum \hyphenchar\font<\z@ \string-\else \char\hyphenchar\font \fi}%
   \kern\wd\UL@hyphenbox \LA@penalty\@M \UL@stop \kern-\wd\UL@hyphenbox
   \discretionary{\box\UL@hyphenbox}{}{}\UL@start}
\let\LA@penalty\penalty
\def\UL@penalty{\relax\ifhmode \afterassignment\UL@@penalty\count@
  \else\LA@penalty\fi}
\def\UL@@penalty{\LA@penalty \ifnum\count@=\z@
  \@ne \else \count@ \fi % zero penalty => no penalty, so use 1 instead.
  \UL@stop \UL@start}
\def\UL@hskip{\ifx\ \LA@space \LA@hskip \else
  \afterassignment\UL@reskip \global\UL@skip \fi}
\def\UL@reskip{\UL@stop \UL@leaders \UL@start}
\def\UL@cr{\unskip \ifx\ \LA@space \let\UL@vad\@gobble
  \else \UL@stop \unskip\unskip\unskip \let\UL@vad\vadjust \fi
  \@ifstar{\UL@vad{\LA@penalty\@M}\UL@cra}\UL@cra}
\def\UL@cra{\@ifnextchar[\UL@crb\UL@newline}
\def\UL@crb[#1]{\UL@vad{\vskip#1}\UL@newline}
\def\UL@newline{\ifx\UL@start\@empty % (\UL@cr may have \UL@stop-ed already)
  \unskip \ifx\ \LA@space \else \UL@stop \unskip\unskip\unskip \fi\fi
  \LA@hskip \z@\@plus.0001fil\LA@penalty -\@M \UL@start}
\newbox\ULC@box
\def\markoverwith#1{\setbox\ULC@box\hbox{{#1}}\UL@pixel.5\wd\ULC@box
   \ifmmode \setbox\ULC@box\hbox{\raise1.4ex\box\ULC@box}%
    \dp\ULC@box-1.4ex\ht\ULC@box\z@ \def\UL@leadtype{\cleaders\copy\ULC@box}%
   \else
    \def\UL@leadtype{\leaders\copy\ULC@box}%
   \fi}
\def\uwave{\bgroup \markoverwith{\lower3.5\p@\hbox{\sixly
  \kern-.21\p@ \char58 \kern-.21\p@}}\ULon}
\font\sixly=lasy6 % does not re-load if already loaded, so no memory problem.
\def\uuline{\bgroup \markoverwith{\hbox
 {\kern-.03em\vtop{\kern.2ex\hrule width.2em\kern1.1\p@
 \hrule}\kern-.03em}}\ULon}
\def\sout{\bgroup \ULdepth=-.5ex \ULset}
\def\xout{\bgroup \markoverwith{\kern-.1em{/}\kern-.1em}\ULon}
\def\useunder#1#2#3{\relax
  \ifx\relax#2\relax\else % declaration command given
    \def#2{\def\@tempa{#1}\global\let\UL@ender\UL@swender
    \expandafter\@tempa\expandafter{\ifnum\z@=\string`}\fi}%
    \MakeRobust{#2}\fi
  \ifx\relax#3\relax\else % argumentative command
    \def#3{#1}\MakeRobust{#3}\fi}
\expandafter\ifx \csname @ifundefined\endcsname \relax
  \def\@height{height}
  \def\@depth{depth}
  \def\@width{width}
  \def\@empty{}
  \def\@gobble#1{}
  \def\MakeRobust#1{}
  \csname newif\expandafter\endcsname \csname if@ignore\endcsname
\else
 \def\MakeRobust#1{\expandafter\let
   \csname \expandafter\@gobble\string#1 \endcsname= #1%
  \edef#1{\noexpand\protect \expandafter\noexpand
   \csname\expandafter\@gobble\string#1 \endcsname}
  }
  \MakeRobust\uline
  \MakeRobust\uuline
  \MakeRobust\uwave
  \MakeRobust\sout
  \MakeRobust\xout
  \let\LA@em\em   \let\LA@emph\emph
  \expandafter\let\expandafter\LA@Pem \csname em \endcsname
  \expandafter\let\expandafter\LA@Pemph \csname emph \endcsname
  \def\ULforem{\useunder{\uline}{\em}{\emph}}
  \def\normalem{\let\em\LA@em \let\emph\LA@emph
    \expandafter\let\csname em \endcsname\LA@Pem
    \expandafter\let\csname emph \endcsname\LA@Pemph}
  \ULforem  %  default is to use underlining for \em,
\fi
\catcode`@=\ULthickness % Scratch meaning: restore catcode of @
\def\ULthickness{.4pt}% can change this with \renewcommand
\newdimen\ULdepth  \ULdepth=\maxdimen

\normalem
%</ulem>
%    \end{macrocode}
%\fi
%
% \subsection{The code for the \textsf{examdesign} class}
%
% We now define an environment \textsf{question} that saves the surrounded text
% to a macro |\sec@|\meta{section-number}|@qst|\meta{question-number}, where
% \meta{section-number} and \meta{question-number} are expressed as lower case
% roman numerals (this way they can be part of the macro name).  Note that we
% must use lower case roman numerals since, I believe, \LaTeXe\ the |\Roman|
% command uses the |\uppercase| command, which is not expanded fully until
% further along in \TeX's gullet than we want.
%
% First, define some new counters and token lists.
%    \begin{macrocode}
%<*othercode>
\newcounter{questionnumber}
\setcounter{questionnumber}{0}
\setcounter{section}{0}
\newcounter{extract}
\newcounter{question} \setcounter{question}{1}
\newcounter{length} \setcounter{length}{0}
\newcounter{temp} \setcounter{temp}{1}
\newcounter{wordtemp} \setcounter{wordtemp}{1}
\newcounter{form}
\newcounter{version}
\newcounter{current@section}
\newcounter{current@question}
\newcounter{innerloop}
\newcounter{sect}
\newcounter{sectionindex}
\newcounter{answer}
\newcounter{choice}
 \setcounter{choice}{1}
\newcounter{mcquestion} \setcounter{mcquestion}{1}
\newcounter{mcchoice} \setcounter{mcchoice}{1}
\newcounter{savelistcnt}
\newlength{\blank@length}
\newlength{\temp@length}
\newlength{\temp@@length}
\newlength{\namedata@vspace}
\newlength{\beforesectsep}
 \setlength{\beforesectsep}{\medskipamount}
\newlength{\aftersectsep}
 \setlength{\aftersectsep}{\medskipamount}
\newlength{\beforeinstsep}
 \setlength{\beforeinstsep}{\medskipamount}
\newlength{\afterinstsep}
 \setlength{\afterinstsep}{\medskipamount}
 \addtolength{\afterinstsep}{-\topsep}
\newif\ifchoice \choicefalse
\newif\ifanswer
\newif\ifnotfixed
\newif\ifcblanks \cblanksfalse
\newif\ifpblanks \pblankstrue
\newif\ifidentifier \identifierfalse
\newif\ifFirstQuestionInBlock \FirstQuestionInBlocktrue
\newif\ifcontinuousnumbering \continuousnumberingtrue
\newif\ifresetcounter\resetcounterfalse
\global\newtoks\temptoks
\global\newtoks\temp@toks
%    \end{macrocode}
% |\setrannum| requires a ``traditional'' counter (i.e., a non-\LaTeX counter (i.e., a
% counter whose name doesn't begin with |c@|.
%    \begin{macrocode}
\newcount\exam@c
\newcount\exam@n
\newcount\exam@m
\setrannum{\exam@m}{1}{10}
\newtoks\@toklist
%    \end{macrocode}
%
% \begin{environment}{section}
% Questions naturally occur in blocks which have, more-or-less, the same
% general format.  For example, one will naturally have a block of true/false
% questions together, followed by a block of short answer, and then a
% block of essay questions.  We don't want to mix questions between blocks (so
% that the true/false questions are interspersed between the short answer
% questions).  Thus we need to index the questions by section type as well as
% question number.
%
%    \begin{macrocode}
\def\section{\stepcounter{section}
  \setcounter{question}{1}}
%    \end{macrocode}
%
% \begin{macro}{\get@instructions}
% This macro collects everything between it and the next |\begin| token.  It then
% calls the |\find@instructions@end| macro to check whether the |\begin| token
% belongs to the \textsf{question} environment or some other environment.
%    \begin{macrocode}
\long\def\get@instructions#1\begin{\@toklist=\expandafter{\the\@toklist#1}%
  \find@instructions@end}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\find@instructions@end}
% If we are at |\begin{question}| or |\begin{block}|
% save everything to the appropriately named
% macro.  Otherwise, continue collecting tokens
%    \begin{macrocode}
\def\find@instructions@end#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\@Q
    \let\@next=\Qwrap@up@instructions
  \else
    \ifx\@tempa\@Block
      \let\@next=\Bwrap@up@instructions
    \else
      \@toklist=\expandafter{\the\@toklist\begin{#1}}%
      \let\@next=\get@instructions
   \fi\fi\@next}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Qwrap@up@instructions}
% Use the counters |section| and |question| to save the collected token list
% in a macro named as described earlier.
%    \begin{macrocode}
\def\Qwrap@up@instructions{%
 \expandafter\xdef\csname inst@sec\thesection\endcsname{\the\@toklist}
 \begin{question}}
% \end{macro}
%
% \begin{macro}{\Bwrap@up@instructions}
% Use the counters |section| and |question| to save the collected token list
% in a macro named as described earlier.
%    \begin{macrocode}
\def\Bwrap@up@instructions{%
 \expandafter\xdef\csname inst@sec\thesection\endcsname{\the\@toklist}
 \begin{block}}
% \end{macro}
%
% \begin{macro}{\endsection}
% At the end of a section, make a list of question indexes.
%    \begin{macrocode}
\def\endsection{\make@qlist}
%    \end{macrocode}
% \end{macro}
% \end{environment}
%
% \begin{macro}{\make@qlist}
% As described below, we need to create a token list containing the index
% numbers of each question.  This is done by a while-loop as follows:
%    \begin{macrocode}
\def\make@qlist{%
  \setcounter{temp}{1}
  \edef\@tempa{\thesection}%
%    \end{macrocode}
% We need to create a new token list to hold the question indexes.  While
% we are at it, might as well create the token list to hold the rearranged
% question indexes.  This saves us having to include a while-loop later.
%    \begin{macrocode}
  \global\expandafter\newtoks\csname qlist@sec\@tempa\endcsname
  \global\expandafter\newtoks\csname qlist@scr@sec\@tempa\endcsname
  \global\csname qlist@scr@sec\@tempa\endcsname={}
%    \end{macrocode}
% Now being a while-loop where each pass through the loop appends
% an index number to the question list.
%    \begin{macrocode}
  \@whilenum \value{question}>1 \do{%
    \edef\@questionnumber{\arabic{temp}}%
    \expandafter\append\expandafter{\@questionnumber}%
       {\csname qlist@sec\@tempa\endcsname}
    \addtocounter{question}{-1}
    \addtocounter{temp}{1}}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{question} environment}
%
% \begin{macro}{\question}
% We define |\question| so that it reads in and saves the surround text
% to a macro like in the \textsf{tabularx} environment.
%    \begin{macrocode}
\def\question{%
  \@toklist={\exam@ExecuteIfDefined{sec\thesection q\thequestion break}}%
%   \@ifundefined{sec\thesection q\thequestion break}
%     {\@toklist={}}
%     {\expandafter\@toklist\expandafter{\csname 
%         sec\thesection q\thequestion break\endcsname}}  
 \get@question@body}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endquestion}
% Increment the question counter so that the next question will be assigned the
% right name
%    \begin{macrocode}
\def\endquestion{\stepcounter{question}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\get@question@body}
% This macro collects everything between it and the next |\end| token.  It then
% calls the |\find@question@end| macro to check whether the |\end| token
% belongs to the \textsf{question} environment or some other environment.
%    \begin{macrocode}
\long\def\get@question@body#1\end{\@toklist=\expandafter{\the\@toklist#1}%
  \find@question@end}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\find@question@end}
% If we are at |\end{question}|, save everything to the appropriately named
% macro.  Otherwise, continue collecting tokens
%    \begin{macrocode}
\def\find@question@end#1{%
  \def\@tempa{#1}%
   \ifx\@tempa\@Q\expandafter\wrap@up
    \else\@toklist=\expandafter{\the\@toklist\end{#1}}%
     \expandafter\get@question@body\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\wrap@up}
% Use the counters |section| and |question| to save the collected token list
% in a macro named as described earlier.
%    \begin{macrocode}
\def\exam@ExecuteIfDefined#1{%
  \@ifundefined{#1}%
    {}%
    {\csname #1\endcsname}} 

\def\wrap@up{%
 \edef\@tempa{\thesection}%
 \edef\@tempb{\thequestion}%
 \ifx\@currentsectionname\@truefalse
   \expandafter\xdef\csname sec\@tempa @qst\@tempb\endcsname{%
     \noexpand\exam@ExecuteIfDefined{sec\thesection q\thequestion break}%
     \noexpand\exam@TFItem
     \noexpand\@beforequestionhook
     \noexpand\exam@TFGobbleQuestionHook
     \the\@toklist
     \noexpand\@endquestionhook}
   \else
     \ifx\@currentsectionname\@MC
       \expandafter\xdef\csname sec\@tempa @qst\@tempb\endcsname{%
         \noexpand\exam@ExecuteIfDefined{sec\thesection q\thequestion break}%
         \noexpand\@mcitem
         \noexpand\@beforequestionhook
         \noexpand\exam@MCGobbleQuestionHook
         \the\@toklist
         \noexpand\exam@EndChoiceListIfNecessary
         \noexpand\@mcenditem
         \noexpand\@endquestionhook}
       \else
         \ifx\@currentsectionname\@shortanswer
           \expandafter\xdef\csname sec\@tempa @qst\@tempb\endcsname{%
             \noexpand\exam@ExecuteIfDefined{sec\thesection q\thequestion break}%
             \noexpand\item
             \noexpand\@beforequestionhook
             \noexpand\exam@SAGobbleQuestionHook
             \the\@toklist
             \noexpand\@endquestionhook}
         \else
           \ifx\@currentsectionname\@fillin
             \expandafter\xdef\csname sec\@tempa @qst\@tempb\endcsname{%
               \noexpand\exam@ExecuteIfDefined{sec\thesection q\thequestion break}%
               \noexpand\item
               \noexpand\@beforequestionhook
               \noexpand\exam@FillinGobbleQuestionHook
               \the\@toklist
               \noexpand\@endquestionhook}
           \else
             \expandafter\xdef\csname sec\@tempa @qst\@tempb\endcsname{%
               \noexpand\exam@ExecuteIfDefined{sec\thesection q\thequestion break}%
               \noexpand\item
               \noexpand\@beforequestionhook
               \the\@toklist
               \noexpand\@endquestionhook}
   \fi\fi\fi\fi
   \end{question}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@Q}
% Store the name of the environment for comparison in |\find@question@end|
%    \begin{macrocode}
\def\@Q{question}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{block} environment}
%
% \begin{macro}{\block}
% This macro provides a ``block'' environment that prevents the questions
% it surrounds from being rearranged.
%
% The |\global\@newlistfalse| is required to prevent \LaTeX\ from barfing
% if the random rearrangement places the block at the beginning of the
% question list, in which case the |\end{enumerate}| would close a
% |\begin{enumerate}| without an intervening |\item|.
%    \begin{macrocode}
\newcounter{first}
\newcounter{last}
\def\exam@GobbleBlockInstructionsHook{\relax}
\newcounter{exam@tf}\setcounter{exam@tf}{0}

\newcommand{\block}[1][]{%
  % Break only if a pagebreak preceeded the block
  \@toklist={\exam@ExecuteIfDefined{sec\current@section q\current@question break}}%
  \@toklist=\expandafter{\the\@toklist
    \global\@newlistfalse
    \setcounter{questionnumber}{\value{enumi}}}%
  \ifx\@currentsectionname\@truefalse
    \@toklist=\expandafter{\the\@toklist
      \end{list}%
      \setcounter{exam@tf}{0}%
      \exam@TrueFalseGobbleBlockInstructionsHook}%
  \else
    \@toklist=\expandafter{\the\@toklist
      \end{enumerate}\exam@GobbleBlockInstructionsHook}%
  \fi
  \setkeys{block}{#1}%
  \exam@GetBlockToFirstQuestion}

\define@key{block}{questions}[0]{%
  \@toklist=\expandafter{\the\@toklist
    \setcounter{first}{\value{enumi}}
    \stepcounter{first}
    \setcounter{last}{\value{enumi}}
    \addtocounter{last}{#1}}}

\long\def\exam@GetBlockToFirstQuestion#1\begin{%
  \@toklist=\expandafter{\the\@toklist #1}%
  \exam@CheckForQuestion}

\def\exam@CheckForQuestion#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\@Q
    \ifx\@currentsectionname\@truefalse
      \@toklist=\expandafter{\the\@toklist
        \exam@StartTrueFalseList
        \begin{question}}
    \else
      \@toklist=\expandafter{\the\@toklist
        \begin{enumerate}
        \setcounter{enumi}{\value{questionnumber}}%
        \begin{question}}
    \fi
    \expandafter\get@block@body
  \else
    \expandafter\exam@GetBlockToFirstQuestion
  \fi}

\long\def\get@block@body#1\end{\@toklist=\expandafter{\the\@toklist #1}%
  \find@block@end}
\def\find@block@end#1{%
  \def\@tempa{#1}%
   \ifx\@tempa\@Block\expandafter\block@wrap@up
    \else\@toklist=\expandafter{\the\@toklist\end{#1}}%
     \expandafter\get@block@body\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\block@wrap@up}
%    \begin{macrocode}
\def\block@wrap@up{%
 \edef\@tempa{\thesection}%
 \edef\@tempb{\thequestion}%
 \expandafter\xdef\csname sec\@tempa @qst\@tempb\endcsname{%
   \noexpand\@startofblockhook
   \the\@toklist
   \noexpand\@endofblockhook}%
 \end{block}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@startofblockhook}
%    \begin{macrocode}
\def\@startofblockhook{\relax}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@endofblockhook}
%    \begin{macrocode}
\def\@endofblockhook{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@Block}
%    \begin{macrocode}
\def\@Block{block}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endblock}
%    \begin{macrocode}
\def\endblock{\stepcounter{question}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{frontmatter} environment}
%
% \begin{macro}{\frontmatter}
% We define "\frontmatter" so that it reads in and saves the surround text
% to a macro like in the \textsf{tabularx} environment.
%    \begin{macrocode}
\def\frontmatter{\@toklist={}
 \get@frontmatter@body}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endfrontmatter}
% This doesn't need to do anything.
%    \begin{macrocode}
\def\endfrontmatter{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\get@frontmatter@body}
% This macro collects everything between it and the next |\end| token.  It then
% calls the |\find@frontmatter@end| macro to check whether the |\end| token
% belongs to the \textsf{frontmatter} environment or some other environment.
%    \begin{macrocode}
\long\def\get@frontmatter@body#1\end{%
  \@toklist=\expandafter{\the\@toklist#1}%
  \find@frontmatter@end}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\find@frontmatter@end}
% If we are at |\end{frontmatter}|, save everything to the appropriately named
% macro.  Otherwise, continue collecting tokens
%    \begin{macrocode}
\def\find@frontmatter@end#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\@Frontmatter
    \expandafter\frontmatter@wrap@up
  \else
    \@toklist=\expandafter{\the\@toklist\end{#1}}%
    \expandafter\get@frontmatter@body
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\frontmatter@wrap@up}
% Save all the scanned text into an appropriately named macro for later
% recall.
%    \begin{macrocode}
\def\frontmatter@wrap@up{%
  \xdef\@frontmattertext{\the\@toklist}
  \end{frontmatter}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@Frontmatter}
% Store the name of the environment for comparison in |\find@frontmatter@end|
%    \begin{macrocode}
\def\@Frontmatter{frontmatter}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{endmatter} environment}
%
% The \textsf{endmatter} environment behaves just like the \textsf{frontmatter}
% environment, except the enclosed text is saved in a differently-named macro.
%
% \begin{macro}{\endmatter}
% We define "\endmatter" so that it reads in and saves the surround text
% to a macro like in the \textsf{tabularx} environment.
%    \begin{macrocode}
\def\endmatter{\@toklist={}
 \get@endmatter@body}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endendmatter}
% This doesn't need to do anything.
%    \begin{macrocode}
\def\endendmatter{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\get@endmatter@body}
% This macro collects everything between it and the next |\end| token.  It then
% calls the |\find@endmatter@end| macro to check whether the |\end| token
% belongs to the \textsf{endmatter} environment or some other environment.
%    \begin{macrocode}
\long\def\get@endmatter@body#1\end{%
  \@toklist=\expandafter{\the\@toklist#1}%
  \find@endmatter@end}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\find@endmatter@end}
% If we are at |\end{endmatter}|, save everything to the appropriately named
% macro.  Otherwise, continue collecting tokens
%    \begin{macrocode}
\def\find@endmatter@end#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\@Endmatter
    \expandafter\endmatter@wrap@up
  \else
    \@toklist=\expandafter{\the\@toklist\end{#1}}%
    \expandafter\get@endmatter@body
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endmatter@wrap@up}
% Save the scanned text to an appropriately named macro for later recall.
%    \begin{macrocode}
\def\endmatter@wrap@up{%
  \xdef\@endmattertext{\the\@toklist}
  \end{endmatter}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@Endmatter}
% Store the name of the environment for comparison in |\find@endmatter@end|
%    \begin{macrocode}
\def\@Endmatter{endmatter}
%    \end{macrocode}
% \end{macro}
%
% We now initialize "\@frontmattertext" and "\@endmattertext" to a randomly
% chosen garbage value that no user will ever use.  This enables us to test in
% the main loop whether the user has used \textsf{frontmatter} or
% \textsf{endmatter} in her document.
%
%    \begin{macrocode}
\begin{frontmatter}
  \relax
\end{frontmatter}
%    \end{macrocode}
%
%    \begin{macrocode}
\begin{endmatter}
  \relax
\end{endmatter}
%    \end{macrocode}
%
% \subsection{The \textsf{exampreface} environment}
%
% The \textsf{exampreface} environment behaves just like the \textsf{frontmatter}
% environment, except the enclosed text is saved in a differently-named
% macro---one that will be printed just beneath any text specified in the
% \textsf{examtop} environment.
%
% \begin{macro}{\exampreface}
% We define "\exampreface" so that it reads in and saves the surround text
% to a macro like in the \textsf{tabularx} environment.
%    \begin{macrocode}
\def\exampreface{\@toklist={}
 \get@exampreface@body}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endexampreface}
% This doesn't need to do anything.
%    \begin{macrocode}
\def\endexampreface{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\get@exampreface@body}
% This macro collects everything between it and the next |\end| token.  It then
% calls the |\find@exampreface@end| macro to check whether the |\end| token
% belongs to the \textsf{exampreface} environment or some other environment.
%    \begin{macrocode}
\long\def\get@exampreface@body#1\end{%
  \@toklist=\expandafter{\the\@toklist#1}%
  \find@exampreface@end}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\find@exampreface@end}
% If we are at |\end{exampreface}|, save everything to the appropriately named
% macro.  Otherwise, continue collecting tokens
%    \begin{macrocode}
\def\find@exampreface@end#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\@Exampreface
    \expandafter\exampreface@wrap@up
  \else
    \@toklist=\expandafter{\the\@toklist\end{#1}}%
    \expandafter\get@exampreface@body
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\exampreface@wrap@up}
% Save the scanned text to an appropriately named macro for later recall.
%    \begin{macrocode}
\def\exampreface@wrap@up{%
  \xdef\@examprefacetext{\the\@toklist}
  \end{exampreface}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@Exampreface}
% Store the name of the environment for comparison in |\find@exampreface@end|
%    \begin{macrocode}
\def\@Exampreface{exampreface}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{examclosing} environment}
%
% The \textsf{examclosing} environment behaves just like the \textsf{frontmatter}
% environment, except the enclosed text is saved in a differently-named
% macro.
%
% \begin{macro}{\examclosing}
% We define "\examclosing" so that it reads in and saves the surround text
% to a macro like in the \textsf{tabularx} environment.
%    \begin{macrocode}
\def\examclosing{\@toklist={}
 \get@examclosing@body}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endexamclosing}
% This doesn't need to do anything.
%    \begin{macrocode}
\def\endexamclosing{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\get@examclosing@body}
% This macro collects everything between it and the next |\end| token.  It then
% calls the |\find@examclosing@end| macro to check whether the |\end| token
% belongs to the \textsf{examclosing} environment or some other environment.
%    \begin{macrocode}
\long\def\get@examclosing@body#1\end{%
  \@toklist=\expandafter{\the\@toklist#1}%
  \find@examclosing@end}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\find@examclosing@end}
% If we are at |\end{examclosing}|, save everything to the appropriately named
% macro.  Otherwise, continue collecting tokens
%    \begin{macrocode}
\def\find@examclosing@end#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\@Examclosing
    \expandafter\examclosing@wrap@up
  \else
    \@toklist=\expandafter{\the\@toklist\end{#1}}%
    \expandafter\get@examclosing@body
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\examclosing@wrap@up}
% Save the scanned text to an appropriately named macro for later recall.
%    \begin{macrocode}
\def\examclosing@wrap@up{%
  \xdef\@examclosingtext{\the\@toklist}
  \end{examclosing}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@Examclosing}
% Store the name of the environment for comparison in |\find@examclosing@end|
%    \begin{macrocode}
\def\@Examclosing{examclosing}
%    \end{macrocode}
% \end{macro}
%
% We now initialize "\@\examprefacetext" and "\@examclosingtext" to "\relax"
% so that in case the user doesn't specify any special text, nothing will be
% typeset in the actual exam.
%
%    \begin{macrocode}
\begin{exampreface}
  \relax
\end{exampreface}
%    \end{macrocode}
%
%    \begin{macrocode}
\begin{examclosing}
  \relax
\end{examclosing}
%    \end{macrocode}
%
% \subsection{The \textsf{keypreface} environment}
%
% The \textsf{keypreface} environment behaves just like the \textsf{frontmatter}
% environment, except the enclosed text is saved in a differently-named
% macro---one that will be printed just beneath any text specified in the
% \textsf{keytop} environment.
%
% \begin{macro}{\keypreface}
% We define "\keypreface" so that it reads in and saves the surround text
% to a macro like in the \textsf{tabularx} environment.
%    \begin{macrocode}
\def\keypreface{\@toklist={}
 \get@keypreface@body}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endkeypreface}
% This doesn't need to do anything.
%    \begin{macrocode}
\def\endkeypreface{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\get@keypreface@body}
% This macro collects everything between it and the next |\end| token.  It then
% calls the |\find@keypreface@end| macro to check whether the |\end| token
% belongs to the \textsf{keypreface} environment or some other environment.
%    \begin{macrocode}
\long\def\get@keypreface@body#1\end{%
  \@toklist=\expandafter{\the\@toklist#1}%
  \find@keypreface@end}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\find@keypreface@end}
% If we are at "\end{keypreface}", save everything to the appropriately named
% macro.  Otherwise, continue collecting tokens
%    \begin{macrocode}
\def\find@keypreface@end#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\@Keypreface
    \expandafter\keypreface@wrap@up
  \else
    \@toklist=\expandafter{\the\@toklist\end{#1}}%
    \expandafter\get@keypreface@body
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\keypreface@wrap@up}
% Save the scanned text to an appropriately named macro for later recall.
%    \begin{macrocode}
\def\keypreface@wrap@up{%
  \xdef\@keyprefacetext{\the\@toklist}
  \end{keypreface}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@Keypreface}
% Store the name of the environment for comparison in "\find@keypreface@end"
%    \begin{macrocode}
\def\@Keypreface{keypreface}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \textsf{keyclosing} environment}
%
% The \textsf{keyclosing} environment behaves just like the \textsf{frontmatter}
% environment, except the enclosed text is saved in a differently-named
% macro.
%
% \begin{macro}{\keyclosing}
% We define "\keyclosing" so that it reads in and saves the surround text
% to a macro like in the \textsf{tabularx} environment.
%    \begin{macrocode}
\def\keyclosing{\@toklist={}
 \get@keyclosing@body}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endkeyclosing}
% This doesn't need to do anything.
%    \begin{macrocode}
\def\endkeyclosing{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\get@keyclosing@body}
% This macro collects everything between it and the next "\end" token.  It then
% calls the "\find@keyclosing@end" macro to check whether the "\end" token
% belongs to the \textsf{keyclosing} environment or some other environment.
%    \begin{macrocode}
\long\def\get@keyclosing@body#1\end{%
  \@toklist=\expandafter{\the\@toklist#1}%
  \find@keyclosing@end}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\find@keyclosing@end}
% If we are at |\end{keyclosing}|, save everything to the appropriately named
% macro.  Otherwise, continue collecting tokens
%    \begin{macrocode}
\def\find@keyclosing@end#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\@Keyclosing
    \expandafter\keyclosing@wrap@up
  \else
    \@toklist=\expandafter{\the\@toklist\end{#1}}%
    \expandafter\get@keyclosing@body
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\keyclosing@wrap@up}
% Save the scanned text to an appropriately named macro for later recall.
%    \begin{macrocode}
\def\keyclosing@wrap@up{%
  \xdef\@keyclosingtext{\the\@toklist}
  \end{keyclosing}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@Keyclosing}
% Store the name of the environment for comparison in "\find@keyclosing@end"
%    \begin{macrocode}
\def\@Keyclosing{keyclosing}
%    \end{macrocode}
% \end{macro}
%
% We now initialize "\@keyprefacetext" and "\@keyclosingtext" to "\relax"
% so that in case the user doesn't specify any special text, nothing will be
% typeset in the actual exam.
%
%    \begin{macrocode}
\begin{keypreface}
  \relax
\end{keypreface}
%    \end{macrocode}
%
%    \begin{macrocode}
\begin{keyclosing}
  \relax
\end{keyclosing}
%    \end{macrocode}
%
% \subsection{Macros for manipulating token lists}
% In order to make manipulation of token lists easier, (or, really, to just
% increase the overall readability of the syntax, we define some macros
% to manipulate token lists.
%
% \begin{macro}{\append}
% |\append{|\meta{string}|}{|\meta{token-list}|}| appends \meta{string}
% to the rightmost end of \meta{token-list}.
%
% Note that we use |\@separator| between entries in the list, rather than
% |\\| as recommended in the \TeX{}book, since we will later want to redefine
% the list separator and \emph{execute} the list.  If we used |\\|, we run into
% potential conflicts in executing the list, since \LaTeXe, at any given point
% during the execution of the list entry, might redefine |\\| in such a way as to
% screw things up.
%    \begin{macrocode}
\def\append#1#2{%
  \global\temp@toks=\expandafter{\the #2\@separator {#1}}%
  \global#2=\expandafter{\the\temp@toks}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\length}
% The usage is |\length{|\meta{token-list}|}|.  So |\length{\foo}| computes the
% length of the token list |\foo|, where it is assumed that the separator
% between list elements is |\@separator|.
%    \begin{macrocode}
\def\length#1{%
  \setcounter{length}{0}
  \def\@separator##1{\stepcounter{length}}\the#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\remove}
% |\remove{|\meta{number}|}{|\meta{token-list}|}| removes the \meta{number}th
% element from the token list \meta{token-list}, redefining \meta{token-list}
% to be that list.  As always, we assume that the list elements are separated
% by the token |\@separator|.
%    \begin{macrocode}
\def\remove#1#2{%
  \exam@c=0
  \temptoks={}
  \def\@separator##1{\advance\exam@c by 1\relax
     \ifnum\exam@c=#1\relax%
     \setcounter{extract}{##1}%
     \else\append{##1}{\temptoks}
     \fi}
  \the#2
  \global#2=\expandafter{\the\temptoks}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Scrambling the order of the questions}
%
% The general idea is that, for each section, we form a token list named
% |\qlist@sec|\meta{c} of the form:
% |{\@separator{1}\@separator{2}|\ldots|\@separator{|\meta{n}|}}|
% where \meta{c} is the number of the section (in roman numerals), and
% \meta{n} is the number of questions in section \meta{c}.  We call a while-loop
% to loop \meta{n} times, each time removing a randomly
%  chosen entry from the token list. This entry is appended to the list
% |\qlist@scr|\meta{m}@|sec|\meta{c}, where
% \meta{m} is the current value (in roman numerals) of the form we are
% generating. Once this list is built, we can then typeset the questions by
% simply redefining |\@separator| and executing the new scrambled list.
%
% \begin{macro}{\@enddocumenthook}
% Redefine the |\@enddocumenthook| so that the questions are automatically
% generated without the user needing to insert a command after all the question
% blocks.  This has the ironic effect that absolutely nothing the user sees in
% the input file causes the text to be created.  I haven't been real careful to
% prevent collisions occurring with other applications that use
% |\@enddocumenthook|, so this could be a source of problems.
%
% \medskip
%
% First, save any previously assigned meaning to
% |\@enddocumenthook| so that we don't clobber it.
%    \begin{macrocode}
\let\@oldenddocumenthook=\@enddocumenthook
\def\@enddocumenthook{%
  \global\let\pagebreak=\old@pagebreak
  \global\let\BreakPageOnVersion=\exam@DoneReadingBreakPageOnVersion
%    \end{macrocode}
% We need to create the number of forms specified, so we loop over the
% total number of forms.  Initialize the counter \texttt{version} to 1 (this
% is the value we will loop over) and step the counter \texttt{form} (so that 
% we actually generate all the forms that the user wants).
%    \begin{macrocode}
  \setcounter{version}{1} \stepcounter{form}
%    \end{macrocode}
% Loop until the value of \texttt{version} exceeds \texttt{form}.
%    \begin{macrocode}
  \@whilenum \value{version}<\value{form} \do{%
%    \end{macrocode}
% But two passes per exam are needed (once for the exam, once for the answers),
% so we create an ``inner-loop'' to take care of this problem.  Since we will
% want the answer key to have a slightly different format (where the
% answers are included!) it pays to make this on the second pass.
%    \begin{macrocode}
    \setcounter{innerloop}{0}
    \@whilenum \value{innerloop}<\value{passes} \do{%
%    \end{macrocode}
% Reset the page counter so that no new exams or answer keys start on page 17
% (for example).
%    \begin{macrocode}
        \setcounter{page}{1}
        \setcounter{questionnumber}{0}
        \setcounter{enumi}{0}
        \setcounter{equation}{0}
%    \end{macrocode}
% If |innerloop|=0, we are making an exam. If not, we are making an answer key,
% so take the appropriate action for the top of the form.  Since we won't want
% absent-minded professors to make 200+ copies of the answer key, print the
% title of the answer key using |\Huge| to call attention to it.
%    \begin{macrocode}
        \ifx\@frontmattertext\relax
          \relax
        \else
          \@frontmattertext \pagebreak
        \fi
        \ifnum \value{innerloop}=0 %
          \@examtopmatter
          \answerfalse
          \iftwocolumn \begin{multicols}{2}\fi
          \@examprefacetext
        \else%
          \@keytopmatter
          \answertrue
          \iftwocolumn \begin{multicols}{2}\fi
          \@keyprefacetext
        \fi
        \setcounter{sectionindex}{0}
%    \end{macrocode}
% And finally, once we have started making the exam, we need to loop over each
% individual section.
%    \begin{macrocode}
        \@whilenum \value{sectionindex}<\value{section} \do{%
            \addtocounter{sectionindex}{1}
%    \end{macrocode}
% Store the value of |sectionindex| in the macro
% |\current@section| so we can use it in |\csname|\ldots |\endcsname| pairs.
%    \begin{macrocode}
            \edef\current@section{\thesectionindex}
%    \end{macrocode}
% Compute the length of |\qlist@sec|\meta{current@section}
%    \begin{macrocode}
            \length{\csname qlist@sec\current@section\endcsname}
%    \end{macrocode}
% Here's the main meat of the code.  Pick a random number between 1 and the
% length of |\qlist@sec|\meta{current@section}.  Store it in the counter |\exam@m|.
% Remove the $m$th element from |\qlist@sec|\meta{current@section} and store it
% as the first element in |\qlist@scr@sec|\meta{current@section}.  Continuing to
% do this will rearrange the order of the questions.  The only thing we need to
% keep in mind is to change the requested range of the random number to keep in
% mind the fact that we removed an element from
% |\qlist@sec|\meta{current@section}.  Although there are faster ways to do
% this, I chose to opt for more readable code, since this part of the program is
% so complex anyway.
%    \begin{macrocode}
            \csname sec\current@section @fixed\endcsname
            \ifnotfixed
              \ifanswer \relax
              \else \typeout{Scrambling section \current@section, question: }\fi
              \exam@ScrambleQuestionList
            \else
              \csname qlist@scr@sec\current@section\endcsname=\expandafter{%
               \the\csname qlist@sec\current@section\endcsname}
            \fi
%    \end{macrocode}
% Finally, the code dealing with processing the different types of questions.  Each
% type of question is processed in the exact same way: we perform an |\ifx| to
% test to see what type of question it is, and if it is that type of question,
% execute the following code, which redefines |\begin{answer}|\ldots
% |\end{answer}| as necessary to achieve the desired effects.
%
% \medskip
%
% We now conduct a series of tests to see exactly what type of question the
% current section contains.  Once a match is made, the appropriate macro
% (defined below) is expanded, which typesets all the questions in that section.
%    \begin{macrocode}
        \csname RS@sec@\current@section\endcsname
        \@ifundefined{sec\current@section break}
          {\relax}
          {\pagebreak}
        \ifsection{\@matching}{\@matchingmain}
        \ifsection{\@shortanswer}{\@shortanswermain}
        \ifsection{\@fillin}{\@fillinmain}
        \ifsection{\@MC}{\@multiplechoicemain}
        \ifsection{\@truefalse}{\@truefalsemain}}
        \ifnum \value{innerloop}=0 %
          \@examclosingtext\par
        \else
          \@keyclosingtext\par
        \fi
        \iftwocolumn \end{multicols} \fi
        \ifx\@endmattertext\relax
          \relax
        \else
          \pagebreak \@endmattertext \par
        \fi
        \pagebreak
        \addtocounter{innerloop}{1}}
      \@OneKeyHook
%    \end{macrocode}
% This is the end of the code for the inner while-loop (that generates both
% exams and answer sheets. Toggle the value of "\ifanswer" so that
% on the second pass we generate answers to the questions.  Add one to
% "innerloop", too.
%    \begin{macrocode}
      \stepcounter{version}
      \setcounter{sectionindex}{0}
%    \end{macrocode}
% This is the end of the code for the form while-loop.  Add -1 to |form| to
% keep track of the number of copies we've made, and redefine the
% |\qlist@sec|\meta{section} lists, since they were eaten up by |\remove|
% during the randomization. (This is what the next loop does.)
%    \begin{macrocode}
      \@whilenum \value{sectionindex}<\value{section} \do{%
        \addtocounter{sectionindex}{1}
        \edef\current@section{\thesectionindex}
        \csname sec\current@section @fixed\endcsname
        \ifnotfixed
          \exam@RestoreSectionLists
        \else \notfixedtrue\fi}
      }}

 \def\exam@RestoreSectionLists{%
   \csname qlist@sec\current@section\endcsname=\expandafter{\the\csname
     qlist@scr@sec\current@section\endcsname}
   \csname qlist@scr@sec\current@section\endcsname={}}

\def\exam@ScrambleQuestionList{%
  \length{\csname qlist@sec\current@section\endcsname}%
  \@whilenum \value{length}>0 \do{%
    \setrannum{\exam@m}{1}{\value{length}}%
    \remove{\exam@m}{\csname qlist@sec\current@section\endcsname}%
    \edef\@TEMP{\theextract}%
    \ifnum \value{length}=1
      \message{\@TEMP.}%
    \else 
      \message{\@TEMP,}%
    \fi
    \expandafter\append\expandafter{\@TEMP}{\csname
      qlist@scr@sec\current@section\endcsname}
    \length{\csname qlist@sec\current@section\endcsname}}}
%    \end{macrocode}
% \end{macro}
%
% \section{The layout of the exam}
%
% \begin{macro}{\NumberOfVersions}
% A user-level command to specify the number of version to make. Originally
% initialized to 1.
%    \begin{macrocode}
\def\NumberOfVersions#1{\setcounter{form}{#1}}
 \NumberOfVersions{1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\instructions}
% Often one wants to preface a block of questions with a series of instructions
% for the student.  Previous releases had defined "\instructions" to do this,
% but that command is obsolete as of version 1.02.  Thus, we define
% "\instructions" to be "\relax".
%    \begin{macrocode}
\def\instructions{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\classdata}
% This command saves its argument in the macro |\classdata| (it is intended for
% data like the class name and course number. E.g., Phil 29: Critical
% Reasoning).  Originally initialized to |\relax|.
%    \begin{macrocode}
\def\class#1{\def\classdata{#1}}
\def\classdata{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\examtype}
% Allows one to specify the name of the exam (midterm, final, etc.)
%    \begin{macrocode}
\def\examname#1{\def\examtype{#1}}
 \examname{Exam}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\namedata}
% Placed in a |\parbox|, |\namedata| contains all the standard fields
% ordinarily required in a large university setting.  If you should be so lucky as
% to teach at a place where student numbers are not required, simply delete the
% appropriate line.
%    \begin{macrocode}
\def\namedata{Name: \hrulefill \\[\namedata@vspace]
              Student Number: \hrulefill \\[\namedata@vspace]
              TA: \hrulefill \\[\namedata@vspace]
              Date: \hrulefill}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Types of questions}
%
% Five types of questions have special
% formats: true/false, fill-in-the-blank, short answer, multiple choice, and
% fixed (meaning: don't swap the order of the questions).  Since we will want to
% distinguish between these types of questions when creating the exam, we need
% a way to identify a particular section with a particular type of question.
% We do this in the following way: for each section, we define a macro
% |\type@sec|\meta{section} consisting of a single string containing the name
% of the type of question.  That string will later be used to identify the 
% section as such and take appropriate action.
%
% First, some necessary definitions.
%    \begin{macrocode}
\define@key{section}{title}[\relax]{%
  \expandafter\gdef\csname head@sec\thesection\endcsname{#1}}

\define@key{section}{resetcounter}[yes]{%
  \def\exam@arg{#1}%
  \ifx\exam@arg\exam@c@yes
    \expandafter
    \gdef\csname RS@sec@\thesection\endcsname{\resetcountertrue}
  \else
    \expandafter
    \gdef\csname RS@sec@\thesection\endcsname{\resetcounterfalse}
  \fi}

\define@key{section}{suppressprefix}[yes]{%
  \def\exam@arg{#1}%
  \ifx\exam@arg\exam@c@yes
    \expandafter
    \gdef\csname SP@sec@\thesection\endcsname{\resetcountertrue}
  \fi}

\define@key{section}{rearrange}[yes]{%
  \def\exam@arg{#1}%
  \ifx\exam@arg\exam@c@yes
    \exam@SectionIsNotFixed
  \else
    \exam@SectionIsFixed
  \fi}

\define@key{section}{keycolumns}[1]{%
  \ifnum#1=1\relax\else
    \ifx\@currentsectionname\@matching
    \message{Column specification ignored for the `matching' environment.}
    \else
    \exam@SetKeyColumns{#1}
    \fi
  \fi}
\define@key{section}{examcolumns}[1]{%
  \ifnum#1=1\relax\else
    \ifx\@currentsectionname\@matching
    \message{Column specification ignored for the `message' environment.}
    \else
    \exam@SetExamColumns{#1}
    \fi
  \fi}

\def\exam@definesectiontype#1{%
  \expandafter\gdef\csname type@sec\thesection\endcsname{#1}}
%    \end{macrocode}
% These next three macros just makes some following code easier to read.
%    \begin{macrocode}
\def\exam@SetKeyColumns#1{%
  \expandafter\gdef\csname sec\thesection @KCol\endcsname{#1}}
\def\exam@SetExamColumns#1{%
  \expandafter\gdef\csname sec\thesection @ECol\endcsname{#1}}
\def\exam@SectionIsNotFixed{%
   \expandafter\gdef\csname sec\thesection @fixed\endcsname{\notfixedtrue}}
\def\exam@SectionIsFixed{%
   \expandafter\gdef\csname sec\thesection @fixed\endcsname{\notfixedfalse}}
\def\exam@SetDefaultSectionTitle#1{
   \expandafter\gdef\csname head@sec\thesection\endcsname{#1}}
\def\exam@SetDefaultRecountState#1{
   \expandafter\gdef\csname RS@sec@\thesection\endcsname{#1}}
\def\exam@notitle{\exam@notitle}
%    \end{macrocode}
%
% \begin{environment}{matching}
% The environment for matching questions.
%    \begin{macrocode}
\newenvironment{matching}[1][]
  {\begin{section}
   \def\@currentsectionname{matching}
   \exam@definesectiontype{matching}
   \exam@SetDefaultRearrangeBehavior
   \exam@SetDefaultSectionTitle{\exam@notitle}
   \exam@SetDefaultRecountState{\exam@DefaultNumberingBehavior}
   \setkeys{section}{#1}%
   \setcounter{temp}{0}%
   \exam@GetInstructionsForMatchingSection}
  {\end{section}}

\long\def\exam@GetInstructionsForMatchingSection#1\pair{%
  \@ifundefined{sec\thesection q\thequestion break}
    {\@toklist={}}
    {\@toklist={\old@pagebreak}}
  \expandafter
  \xdef\csname inst@sec\thesection\endcsname{\the\@toklist#1}\pair}

\def\exam@MatchingLineLength{.5in}
\def\exam@MatchingLineAfterSkip{6pt}
\def\pair#1#2{%
  \expandafter
  \xdef\csname sec\thesection @\thequestion @tag\endcsname{\thetemp}
  \expandafter
  \gdef\csname sec\thesection @qst\thequestion\endcsname{%
    \exam@PairA{\item[]\hskip-\leftmargin 
      \ifanswer
      \underline{\makebox[\exam@MatchingLineLength][c]{\exam@GetMatchingAnswer}}%
      \hskip\exam@MatchingLineAfterSkip #1
      \else
      \rule{\exam@MatchingLineLength}{.4pt}%
      \hskip\exam@MatchingLineAfterSkip #1
      \fi}}
  \stepcounter{question}
  \expandafter
  \xdef\csname sec\thesection @\thequestion @tag\endcsname{\thetemp}
  \expandafter
  \gdef\csname sec\thesection @qst\thequestion\endcsname{%
    \exam@PairB{\item\relax\exam@SaveMatchingAnswer #2}}
  \stepcounter{temp}
  \stepcounter{question}}

\def\exam@GetMatchingAnswer{%
  \edef\exam@tag{\csname sec\current@section @\current@question
  @tag\endcsname}%
  \csname matching@answer@\exam@tag\endcsname}
\def\exam@SaveMatchingAnswer{%
  \edef\exam@tag{\csname sec\current@section @\current@question
    @tag\endcsname}%
  \expandafter
  \xdef\csname matching@answer@\exam@tag\endcsname{(\alph{enumi})}}

%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{fillin}
% The environment for fill-in-the-blank questions.
%    \begin{macrocode}
\newenvironment{fillin}[1][]
  {\begin{section}
   \def\@currentsectionname{fillin}
   \exam@definesectiontype{fillin}
   \exam@SetDefaultRearrangeBehavior
   \exam@SetDefaultSectionTitle{\exam@notitle}
   \exam@SetDefaultRecountState{\exam@DefaultNumberingBehavior}
   \setkeys{section}{#1}%
   \get@instructions \relax}
  {\end{section}}
%    \end{macrocode}
% \end{environment}
%
%
% \begin{environment}{truefalse}
% The environment for true/false questions
%    \begin{macrocode}
\newenvironment{truefalse}[1][]
  {\begin{section}
   \def\@currentsectionname{truefalse}
   \exam@definesectiontype{truefalse}
   \exam@SetDefaultRearrangeBehavior
   \exam@SetDefaultSectionTitle{\exam@notitle}
   \exam@SetDefaultRecountState{\exam@DefaultNumberingBehavior}
   \setkeys{section}{#1}%
   \get@instructions \relax}
  {\end{section}}
%    \end{macrocode}
% \end{environment}
%
%
% \begin{environment}{shortanswer}
% The environment for short answer questions
%    \begin{macrocode}
\newenvironment{shortanswer}[1][]
  {\begin{section}
   \def\@currentsectionname{shortanswer}
   \exam@definesectiontype{shortanswer}
   \exam@SetDefaultRearrangeBehavior
   \exam@SetDefaultSectionTitle{\exam@notitle}
   \exam@SetDefaultRecountState{\exam@DefaultNumberingBehavior}   
   \setkeys{section}{#1}%
   \get@instructions \relax}
  {\end{section}}
%    \end{macrocode}
% \end{environment}
%
%
% \begin{environment}{multiplechoice}
% The environment for multiple choice questions
%    \begin{macrocode}
\newenvironment{multiplechoice}[1][]
  {\begin{section}
   \def\@currentsectionname{multiplechoice}
   \exam@definesectiontype{multiplechoice}
   \exam@SetDefaultRearrangeBehavior
   \exam@SetDefaultSectionTitle{\exam@notitle}
   \exam@SetDefaultRecountState{\exam@DefaultNumberingBehavior}   
   \setkeys{section}{#1}%
   \get@instructions \relax}
  {\end{section}}
%    \end{macrocode}
% \end{environment}
%
%
% \subsection{Loose Ends}
%
% The following macros just contain the environment names for identification in
% the main loop.
%    \begin{macrocode}
\def\@matching{matching}
\def\@fillin{fillin}
\def\@shortanswer{shortanswer}
\def\@truefalse{truefalse}
\def\@MC{multiplechoice}
%    \end{macrocode}
%
% \begin{macro}{\choice}
% This is one of the complicated macros in the package.  From the user's point
% of view, it indicates one answer to a multiple choice question.  Internally,
% |\choice| has to recognize whether it is the first or last question, taking
% different action depending on which it is.  Moreover, |\choice| has to format
% the label differently depending on whether or not we are creating an exam or a
% test. Note that, for reasons of sanity, I do not attempt to rearrange the order
% of the choices.
%    \begin{macrocode}
\newcommand{\exam@DefaultChoice}[2][]{%
  \ifchoice \relax
    \else \@mcstartlist \choicetrue
  \fi
  \ifanswer
    \if#1!%
      \ifbox \vspace{-\fboxsep}\item[\hfill\fbox{(\alph{choice})}\hfill] #2
        \vspace{-\fboxsep}%
      \else
         \item[\hfill\MCfont{(\alph{choice})}\hfill] \MCfont{#2}%
      \fi
    \else \item[\hfill(\alph{choice})\hfill] #2
    \fi 
    \stepcounter{choice}%
  \else
    \item[\hfill(\alph{choice})\hfill] #2
    \stepcounter{choice}%
  \fi}
\def\exam@EndChoiceListIfNecessary{%
  \ifchoice\end{list}\choicefalse\fi\setcounter{choice}{1}}
\let\choice=\exam@DefaultChoice
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@mcstartlist}
% The parameters used to start the |\begin{list}| environment used in
% the |\choice| macro.
%    \begin{macrocode}
\def\@mcstartlist{\begin{list}{}{%
 \setlength{\topsep}{6pt}
 \setlength{\rightmargin}{0pt}
 \setlength{\labelwidth}{.35in}
 \setlength{\leftmargin}{.5in}
 \setlength{\labelsep}{.15in}
 \setlength{\itemindent}{0in}
 \setlength{\itemsep}{0pt}}}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{More User-Level Macros}
%
% \begin{macro}{\Fullpages}
% Just a command so that people can automatically set the page margins to
% full-sized pages.  Only defined for US letter, sorry.
%    \begin{macrocode}
\newcommand{\Fullpages}{\setlength{\topmargin}{0pc}
                        \setlength{\oddsidemargin}{0pc}
                        \setlength{\evensidemargin}{0pc}
                        \setlength{\headheight}{0pc}
                        \setlength{\headsep}{0pc}
                        \setlength{\textwidth}{6.5in}
                        \setlength{\textheight}{9in}}
%</othercode>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ConstantBlanks}
% Sets the blanks in \textsf{fillin} to be of constant width
%    \begin{macrocode}
\def\ConstantBlanks#1{\setlength{\blank@length}{#1}\cblankstrue\pblanksfalse}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ProportionalBlanks}
% Sets the blanks in \textsf{fillin} to be proportional to the actual typeset
% width of the word.
%    \begin{macrocode}
\def\ProportionalBlanks#1{\edef\blank@multiplier{#1}\cblanksfalse\pblankstrue}
 \ProportionalBlanks{1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\StudentInfoLineSpacing}
% Sets the amount of spacing between the lines in the |\namedata| macro.
%    \begin{macrocode}
\newcommand{\StudentInfoLineSpacing}[1]{\setlength{\namedata@vspace}{#1}}
 \StudentInfoLineSpacing{6pt}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\examtop}
% We define "\examtop" so that it reads in and saves the surround text
% to a macro like in the \textsf{tabularx} environment.
%    \begin{macrocode}
\def\examtop{\@toklist={}
 \get@examtop@body}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endexamtop}
% This doesn't need to do much.
%    \begin{macrocode}
\def\endexamtop{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\get@examtop@body}
% This macro collects everything between it and the next |\end| token.  It then
% calls the |\find@examtop@end| macro to check whether the |\end| token
% belongs to the \textsf{question} environment or some other environment.
%    \begin{macrocode}
\long\def\get@examtop@body#1\end{%
  \@toklist=\expandafter{\the\@toklist#1}%
  \find@examtop@end}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\find@examtop@end}
% If we are at |\end{examtop}|, save everything to the appropriately named
% macro.  Otherwise, continue collecting tokens
%    \begin{macrocode}
\def\find@examtop@end#1{%
  \def\@tempa{#1}%
   \ifx\@tempa\@XMtop\expandafter\XMtop@wrap@up
    \else\@toklist=\expandafter{\the\@toklist\end{#1}}%
     \expandafter\get@examtop@body\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\XMtop@wrap@up}
% Save the gathered information to a macro for later use.
%    \begin{macrocode}
\def\XMtop@wrap@up{\xdef\@examtopmatter{\the\@toklist}%
 \end{examtop}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@XMtop}
% Store the name of the environment for comparison in |\find@question@end|
%    \begin{macrocode}
\def\@XMtop{examtop}
%    \end{macrocode}
% \end{macro}
%
% \DescribeEnv{examtop}
% This environment is defined via the macros below.  It allows the user
% to customize the text at the top of the exam.  The example here is the
% default definition.
%    \begin{macrocode}
\begin{examtop}
\@@line{\parbox{3in}{\classdata \\
        \examtype, Form:~\fbox{\textsf{\Alph{version}}}}
        \hfill
        \parbox{3in}{\normalsize \namedata}}
        \bigskip
\end{examtop}
%    \end{macrocode}
%
% \begin{macro}{\keytop}
% We define "\keytop" so that it reads in and saves the surround text
% to a macro like in the \textsf{tabularx} environment.
%    \begin{macrocode}
\def\keytop{\@toklist={}
 \get@keytop@body}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endkeytop}
% This doesn't need to do much.
%    \begin{macrocode}
\def\endkeytop{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\get@keytop@body}
% This macro collects everything between it and the next |\end| token.  It then
% calls the |\find@keytop@end| macro to check whether the |\end| token
% belongs to the \textsf{question} environment or some other environment.
%    \begin{macrocode}
\long\def\get@keytop@body#1\end{\@toklist=\expandafter{\the\@toklist#1}%
  \find@keytop@end}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\find@keytop@end}
% If we are at |\end{keytop}|, save everything to the appropriately named
% macro.  Otherwise, continue collecting tokens
%    \begin{macrocode}
\def\find@keytop@end#1{%
  \def\@tempa{#1}%
   \ifx\@tempa\@KYtop\expandafter\KYtop@wrap@up
    \else\@toklist=\expandafter{\the\@toklist\end{#1}}%
     \expandafter\get@keytop@body\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KYtop@wrap@up}
% Save the gathered information to a macro for later use.
%    \begin{macrocode}
\def\KYtop@wrap@up{\xdef\@keytopmatter{\the\@toklist}%
 \end{keytop}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@KYtop}
% Store the name of the environment for comparison in |\find@keytop@end|
%    \begin{macrocode}
\def\@KYtop{keytop}
%    \end{macrocode}
% \end{macro}
%
% \DescribeEnv{keytop}
% This environment is defined via the macros below.  It allows the user
% to customize the text at the top of the exam.  The example here is the
% default definition.
%    \begin{macrocode}
\begin{keytop}
\@@line{\hfill \Huge Answer Key
        for Exam \fbox{\textsf{\Alph{version}}}\hfill}
        \bigskip
\end{keytop}
%    \end{macrocode}
%
% \MakeShortVerb{\"}
% \DeleteShortVerb{\|}
% \begin{macro}{\word}
% This macro enables one to insert minor (read: inessential) changes in wording
% between different versions of the test.  For example, including the
% command "\word|{Carl Sagan} {Bob Dole}|" in the text will cause the phrase
% ``Carl Sagan'' to be printed in that place on every odd-numbered test and ``Bob Dole''
% to be printed in that place on every even-numbered test.  In the event that
% more versions of the test are requested than options given, "\word" acts as if
% the given list of options repeats itself.  I.e., in the above case, if we requested
% four different versions of the examn, "\word" will behave as if the
% command given were "\word|{Carl Sagan} {Bob Dole} {Carl Sagan} {Bob Dole}|".
%
% \smallskip
%
% First we define a string to be equal to a space so that we can allow for any
% number of spaces to be given in the option list.
%    \begin{macrocode}
\def\@Space{ }
%    \end{macrocode}
% The "\word" macro just saves the option-list in a macro named "\@wordlist" and
% invokes the macro "\@wordmain" which most of the work.
%    \begin{macrocode}
\def\word#1{\def\@wordlist{#1}\expandafter\@wordmain\@wordlist \stop}

\def\@wordmain#1{%
%    \end{macrocode}
% Check to see if the current argument is a space.  If so, ignore it.
%    \begin{macrocode}
  \ifx#1\@Space
   \let\@next=\@wordmain
  \else
%    \end{macrocode}
% If the current argument is not a space, but is "\stop", this means that
% fewer options were given than versions of the test were requested.  Thus we
% need to start "\@wordmain" again at the beginning of the option list.  This
% is what the "\@dumpthenstart" macro does.
%    \begin{macrocode}
   \ifx#1\stop
    \let\@next=\@dumpthenstart
   \else%
%    \end{macrocode}
% If the current argument is none of the above, then it is an actual option.
% However, we must check whether it is the option we want.  If it is, then
% typeset it and gobble everything up to (and including) "\stop".  If not, just
% throw the current argument away and get the next one.
%    \begin{macrocode}
    \ifnum\value{wordtemp}=\value{version}%
     #1\let\@next=\@gobbletostop
    \else
     \stepcounter{wordtemp}%
     \let\@next=\@wordmain
    \fi
   \fi
  \fi
  \@next}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@dumpthenstart}
%    \begin{macrocode}
\def\@dumpthenstart{\expandafter\@wordmain\@wordlist \stop}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@gobbletostop}
%    \begin{macrocode}
\def\@gobbletostop#1\stop{\relax\setcounter{wordtemp}{1}}
%    \end{macrocode}
% \end{macro}
%
% \section{Macros to format types of questions}
%
% \begin{macro}{\ifsection}
% This macro increases the readability of the code in the definition
% of "\@enddocumenthook" when we test to see just which type of questions
% the current section consists of.
%    \begin{macrocode}
\def\ifsection#1#2{%
 \expandafter\ifx\csname type@sec\current@section\endcsname#1#2\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\exam@AddSectionTitle}
% Typeset the section title, if there is one; otherwise, don't do anything.
%    \begin{macrocode}
\def\exam@AddSectionTitle{%
  \expandafter\ifx\csname head@sec\current@section\endcsname\exam@notitle
    \relax
  \else
    \par\vspace{\beforesectsep}
    \noindent {\exam@sectionfont \exam@sectionprefix
      \csname head@sec\current@section\endcsname}
    \par\vspace{\aftersectsep}
  \fi}


%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\exam@AddSectionInstructions}
% Add instructions for the section, if any were give; otherwise, don't
% do anything.
%    \begin{macrocode}
\def\exam@AddSectionInstructions{%
  \ifx\csname inst@sec\current@section\endcsname\relax
    \relax
  \else
    \vspace{\beforeinstsep}
    \csname inst@sec\current@section\endcsname
    \par\vspace{\afterinstsep}
  \fi}
\let\exam@AddSectionInstructionsHook=\exam@AddSectionInstructions
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\exam@MakeAnswerEnvironGobble}
% This macro redefines the \textsf{answer} environment so that it
% ignores (``gobbles'') everything inside it.  Used when typesetting
% the exam.
%    \begin{macrocode}
\def\exam@MakeAnswerEnvironGobble{%
  \def\answer{\get@noanswer@body}
  \def\endanswer{\relax}
  \def\@S{answer}
  \long\def\get@noanswer@body##1\end{\find@answer@end}
  \def\find@answer@end##1{\def\@tempa{##1}
    \ifx\@tempa\@S\expandafter\finish@up
    \else\expandafter\get@noanswer@body\fi}
  \def\finish@up{\end{answer}}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\exam@TypesetQuestions}
% With the exception of the \textsf{truefalse} environment, 
% all of the other kinds of questions are handled in the sam
% way.  (The \textsf{truefalse} environment is special because of
% the wide blanks it places at the left margin.)
%    \begin{macrocode}
\def\exam@PossiblyStartMultipleColumnsInKey{%
  \ifanswer
    \@ifundefined{sec\current@section @KCol}
      \relax
      {\begin{multicols}{\csname sec\current@section @KCol\endcsname}}
  \fi}
\def\exam@PossiblyEndMultipleColumnsInKey{%
  \ifanswer
    \@ifundefined{sec\current@section @KCol}
      \relax
      {\end{multicols}}
  \fi}
\def\exam@PossiblyStartMultipleColumnsInExam{%
  \ifanswer\relax\else
    \@ifundefined{sec\current@section @ECol}
      \relax
      {\begin{multicols}{\csname sec\current@section @ECol\endcsname}}
  \fi}
\def\exam@PossiblyEndMultipleColumnsInExam{%
  \ifanswer\relax\else
    \@ifundefined{sec\current@section @ECol}
      \relax
      {\end{multicols}}
  \fi}

\def\exam@EnumerateStyle{1.}
\def\exam@DefaultEnumerateStyle{1.}

\def\enumerate{%
  \ifnum \@enumdepth >3 \@toodeep\else
     \advance\@enumdepth \@ne
     \edef\@enumctr{enum\romannumeral\the\@enumdepth}\fi
  \@ifnextchar[{\exam@@enum@}{\@enum@}}
\def\exam@@enum@[#1]{\expandafter\@@enum@\expandafter[#1]}

\def\exam@TypesetQuestions{%
  \exam@PossiblyStartMultipleColumnsInKey
  \exam@PossiblyStartMultipleColumnsInExam
  \ifx\exam@EnumerateStyle\exam@DefaultEnumerateStyle
    \begin{enumerate}
  \else
    \begin{enumerate}[\exam@EnumerateStyle]
  \fi
    \ifresetcounter
      \setcounter{enumi}{0}
    \else
%      \message{QuestionNumber: \thequestionnumber}%
      \setcounter{enumi}{\value{questionnumber}}
    \fi
    \the\csname qlist@scr@sec\current@section\endcsname
    \setcounter{questionnumber}{\value{enumi}}
  \end{enumerate}
  \exam@PossiblyEndMultipleColumnsInKey
  \exam@PossiblyEndMultipleColumnsInExam}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@shortanswermain}
%
% Define |\@separator| in the appropriate fashion for this kind of question.
%    \begin{macrocode}
\def\@shortanswermain{%
  \def\question{%
    \item 
    \@beforequestionhook
    \exam@SAGobbleQuestionHook}
  \def\endquestion{\@endquestionhook}
  \def\@separator##1{\setcounter{temp}{##1}
    \edef\current@question{\thetemp}
    \csname sec\current@section @qst\current@question\endcsname}
%    \end{macrocode}
% If we are makingf a answer, set up the \textsf{answer} environment so that
% it prints the answer along with an identifier.
%    \begin{macrocode}
  \ifanswer
    \exam@DefineAnswerEnvironment
  \else
    \exam@MakeAnswerEnvironGobble
  \fi
  \exam@AddSectionTitle
  \exam@AddSectionInstructionsHook
  \exam@TypesetQuestions}
%
% \begin{macro}{\@matchingmain}
%
% Define |\@separator| in the appropriate fashion for this kind of question.
%    \begin{macrocode}
\def\@matchingmain{%
  \def\@separator##1{\setcounter{temp}{##1}
    \edef\current@question{\thetemp}
    \csname sec\current@section @qst\current@question\endcsname}
%    \end{macrocode}
% If we are makingf a answer, set up the \textsf{answer} environment so that
% it prints the answer along with an identifier.
%    \begin{macrocode}
  \exam@AddSectionTitle
  \exam@AddSectionInstructionsHook
  \def\exam@PairA##1{##1}
  \def\exam@PairB##1{}
  \edef\exam@questionnumber{\thequestionnumber}%
  \begin{multicols}{2}\raggedcolumns
  \exam@TypesetQuestions
  \def\exam@PairA##1{}
  \def\exam@PairB##1{##1}
  \def\exam@EnumerateStyle{(a)}
  \columnbreak
  \exam@TypesetQuestions
  \end{multicols}
  \setcounter{enumi}{\exam@questionnumber}%
  \setcounter{questionnumber}{\exam@questionnumber}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@fillinmain}
% As with all of the section routines, we need to
% define |\@separator| again.
%    \begin{macrocode}
\def\@fillinmain{%
  \def\question{%
    \item 
    \@beforequestionhook
    \exam@FillinBlockGobbleQuestionHook}
  \def\endquestion{\@endquestionhook}
  \def\@separator##1{\setcounter{temp}{##1}
    \edef\current@question{\thetemp}
    \csname sec\current@section @qst\current@question\endcsname}
%    \end{macrocode}
% Define |\blank| so that it either makes just an underline or an underline
% with the word printed over it.
%    \begin{macrocode}
  \ifanswer 
    \ifcblanks
    \def\blank##1{\mbox{\rule[-1pt]{\blank@length}{.4pt}%
        \hspace{-\blank@length}%
        \makebox[\blank@length]{##1}}}
    \fi
    \ifpblanks
    \def\blank##1{\settowidth{\temp@length}{##1}%
      \mbox{\rule[-1pt]{\blank@multiplier\temp@length}{.4pt}%
        \hspace{-\blank@multiplier\temp@length}%
        \makebox[\blank@multiplier\temp@length]{##1}}}
    \fi
  \else
    \ifcblanks
      \def\blank##1{\rule[-1pt]{\blank@length}{.4pt}}
    \fi
    \ifpblanks
      \def\blank##1{\settowidth{\temp@length}{##1}%
        \rule[-1pt]{\blank@multiplier\temp@length}{.4pt}}
    \fi
  \fi
  \exam@AddSectionTitle
  \exam@AddSectionInstructionsHook
  \exam@TypesetQuestions}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@multiplechoicemain}
% This contains all the commands to be invoked if the current section in
% the main loop is a multiple-choice environment.
%    \begin{macrocode}
\def\@multiplechoicemain{\setcounter{mcchoice}{1}
%    \end{macrocode}
% First, redefine the "\question", "\endquestion" pairs in case someone
% used the \textsf{block} environment within multiplechoice.
%    \begin{macrocode}
   \def\question{\@mcitem
     \@beforequestionhook
     \exam@MCGobbleQuestionHook}
   \def\endquestion{\@endquestionhook
     \exam@EndChoiceListIfNecessary\@mcenditem}
%    \end{macrocode}
% Now define "\@separator" so that it calls the appropriate macro.
%    \begin{macrocode}
   \def\@separator##1{\setcounter{temp}{##1}
     \edef\current@question{\thetemp}
     \csname sec\current@section @qst\current@question\endcsname}
   \exam@AddSectionTitle
   \exam@AddSectionInstructionsHook
   \exam@TypesetQuestions}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@truefalsemain}
% This contains all the commands to be invoked if the current section in the
% main loop is a true/false environment.
%    \begin{macrocode}
\def\@truefalsemain{%
%    \end{macrocode}
% First, define "\@separator" so that it calls the macro where the right
% question is saved.
%    \begin{macrocode}
   \def\@separator##1{\setcounter{temp}{##1}
     \edef\current@question{\thetemp}
     \csname sec\current@section @qst\current@question\endcsname}
%    \end{macrocode}
% Redefine "\question" and "\endquestion" to work properly in case someone
% used a \textsf{block} environment to keep a couple of true/false questions
% together
%    \begin{macrocode}
   \def\question{%
     \edef\current@question{\thetemp.\theexam@tf}%
     \exam@TFItem \@beforequestionhook}
   \def\endquestion{\stepcounter{exam@tf}\@endquestionhook}
%    \end{macrocode}
% Since the appearance of a true/false question depends heavily on whether we
% are typesetting an answer key or not, we have to make a number of definitions
% (or redefinitions) depending upon whether we are currently making an answer
% key.
%    \begin{macrocode}
     \ifanswer
%    \end{macrocode}
% If we are typesetting an answer, we don't want the argument given to
% "\answer" to do anything, so we define it so that it gobbles its argument.
%    \begin{macrocode}
       \def\answer##1{\relax}
%    \end{macrocode}
% If we aren't typesetting an answer, then we are typesetting a test. We
% must define "\answer" so that it saves the answer in
% a macro so that it can be recalled when the answer key is typeset.
%    \begin{macrocode}
     \else
       \def\answer##1{\expandafter\gdef
          \csname tf@sol\current@question\endcsname{##1}}
          \vspace{-\smallskipamount}
     \fi
     \exam@AddSectionTitle
     \exam@AddSectionInstructionsHook
     \exam@StartTrueFalseList
     \the\csname qlist@scr@sec\current@section\endcsname
     \end{list}}

\def\exam@StartTrueFalseList{%
  \ifanswer
  \begin{list}{}
    {\setlength{\rightmargin}{0pt}
      \setlength{\labelwidth}{.4in}
      \setlength{\leftmargin}{.5in}
      \setlength{\labelsep}{.1in}
      \setlength{\itemindent}{0in}
      \setlength{\itemsep}{3pt}}
%    \the\csname qlist@scr@sec\current@section\endcsname
%  \end{list}
  \else
  \begin{list}%{$\underline{\mbox{\hphantom{false}}}$}
    {\setlength{\rightmargin}{0pt}
      \setlength{\labelwidth}{.35in}
      \setlength{\leftmargin}{.5in}
      \setlength{\labelsep}{.15in}
      \setlength{\itemindent}{0in}
      \setlength{\itemsep}{3pt}}
%    \the\csname qlist@scr@sec\current@section\endcsname
%  \end{list}
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@endquestionhook}
% This provides a ``hook'' for inserting something (like a place to put points)
% at the end of every question.  Originally initialized to just "\relax"
%    \begin{macrocode}
\def\@endquestionhook{\relax}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@beforequestionhook}
% This provides a ``hook'' for inserting something (like a place to put points)
% at the start of every question.  Originally initialized to just "\relax".
%    \begin{macrocode}
\def\@beforequestionhook{\relax}
%    \end{macrocode}
% \end{macro}
%
%\def\@endquestionhook{\par\hfill Score: \fbox{\phantom{M}}}
%
% \begin{macro}{\exam@DefaultTFItem}
% This is a fancy version of "\item" that must be used for the true/false
% environment because of the way the exams and answers are printed.
%    \begin{macrocode}
\def\exam@DefaultTFItem{%
  \ifanswer
    \item[\uline{\makebox[.5in][c]{\csname tf@sol\current@question\endcsname}}]
  \else
    \item[\uline{\makebox[.5in][r]{\hss}}]
  \fi}
\let\exam@TFItem=\exam@DefaultTFItem
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@mcitem}
% This is a fancy version of "\item" that must be used for the multiple
% choice environment because we want to put the question text inside a
% minipage to keep it from being broken across pages.
%    \begin{macrocode}
\def\@mcitem{\item\begin{minipage}[t]{\linewidth}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@mcenditem}
% This completes the minipage environment begun above.
%    \begin{macrocode}
\def\@mcenditem{\end{minipage}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\answerspace}
% Inserts a particular amount of space for an answer to be given only on
% the actual exam.  The space is suppressed in the answer key.
%    \begin{macrocode}
\def\answerspace#1{\ifanswer \relax \else \vspace*{#1} \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\exam}
% Whatever is given as an argument to this macro will only be included if we
% are typesetting an exam.
%    \begin{macrocode}
\def\exam#1{\ifanswer\relax\else #1\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\key}
% Whatever is given as an argument to this macro will only be included if we
% are typesetting an answer key.
%    \begin{macrocode}
\def\key#1{\ifanswer#1\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\examvspace}
% Insert the specified amount of vertical space only if we are making an
% exam. At the same time, check to see if the command was a starred command or
% not.
%    \begin{macrocode}
\def\examvspace{\@ifnextchar*{\@examvspacestar}{\@examvspace}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@examvspacestar}
%    \begin{macrocode}
\def\@examvspacestar*#1{\exam{\vspace*{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@examvspace}
%    \begin{macrocode}
\def\@examvspace#1{\exam{\vspace{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\examhspace}
% Insert the specified amount of horizontal space only if we are making an
% exam. At the same time, check to see if the command was a starred command or
% not.
%    \begin{macrocode}
\def\examhspace{\@ifnextchar*{\@examhspacestar}{\@examhspace}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@examhspacestar}
%    \begin{macrocode}
\def\@examhspacestar*#1{\exam{\hspace*{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@examhspace}
%    \begin{macrocode}
\def\@examhspace#1{\exam{\hspace{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\keyvspace}
% Insert the specified amount of vertical space only if we are making an
% exam. At the same time, check to see if the command was a starred command or
% not.
%    \begin{macrocode}
\def\keyvspace{\@ifnextchar*{\@keyvspacestar}{\@keyvspace}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@keyvspacestar}
%    \begin{macrocode}
\def\@keyvspacestar*#1{\key{\vspace*{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@keyvspace}
%    \begin{macrocode}
\def\@keyvspace#1{\key{\vspace{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\keyhspace}
% Insert the specified amount of vertical space only if we are making an
% exam. At the same time, check to see if the command was a starred command or
% not.
%    \begin{macrocode}
\def\keyhspace{\@ifnextchar*{\@keyhspacestar}{\@keyhspace}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@keyhspacestar}
%    \begin{macrocode}
\def\@keyhspacestar*#1{\key{\hspace*{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@keyhspace}
%    \begin{macrocode}
\def\@keyhspace#1{\key{\hspace{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\label}
% The multiple processing of exams generates error messages if we use
% the default definition of |\label|.  The following hack lets one
% use |\label| inside of exams with the expected effect.
%    \begin{macrocode}
\let\exam@oldlabel=\label
\renewcommand{\label}[1]{\exam{\exam@oldlabel{\theversion @#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ref}
% And a similar hack to get |\ref| working as well\ldots
%    \begin{macrocode}
\let\exam@oldref=\ref
\renewcommand{\ref}[1]{\exam@oldref{\theversion @#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\problem}
% Occasionally one needs to put several different numbered questions
% inside of a single block (I didn't first encounter this until I wrote
% my first scantron exam).  This macro gives a way to do this consistently
% with the numbering scheme for the rest of the section.
%    \begin{macrocode}
\def\problem{\stepcounter{enumi}\theenumi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SectionFont}
% Here's an easy way to change the font used in section headings.
%    \begin{macrocode}
\def\SectionFont#1{\def\exam@sectionfont{#1}}
\SectionFont{\large} % The default value
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NoRearrange}
% The default behavior is to rearrange the questions.  This macro changes
% it.
%    \begin{macrocode}
\let\exam@SetDefaultRearrangeBehavior=\exam@SectionIsNotFixed
\def\NoRearrange{%
  \let\exam@SetDefaultRearrangeBehavior=\exam@SectionIsFixed}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\def\exam@resetcounter{%
  \ifresetcounter
    \setcounter{enumi}{0}
    \global\resetcounterfalse
  \else
    \setcounter{enumi}{\value{questionnumber}}
  \fi}
%    \end{macrocode}
%
% \begin{macro}{\SectionPrefix}
% This macro let's one change the appearance of the section number
% which preceeds the title.
%    \begin{macrocode}
\def\SectionPrefix#1{%
  \def\exam@sectionprefix{%
    \@ifundefined{SP@sec@\current@section}
      {#1}
      \relax}}
\SectionPrefix{Section \arabic{sectionindex}. \space}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ContinuousNumbering}
% When called, changes the default numbering behavior across sections.
%    \begin{macrocode}
\def\ContinuousNumbering{%
  \let\exam@DefaultNumberingBehavior=\resetcounterfalse}
\let\exam@DefaultNumberingBehavior=\resetcountertrue
%    \end{macrocode}
% \end{macro}
%

% \begin{macro}{\ShortKey}
% This macro only includes the answers in the key.
%    \begin{macrocode}
\def\exam@SAGobbleQuestionHook{\relax}% default values
\def\exam@MCGobbleQuestionHook{\relax}
\def\exam@TFGobbleQuestionHook{\relax}
\def\exam@FillinGobbleQuestionHook{\relax}
\def\exam@FillinBlockGobbleQuestionHook{\relax}
\def\exam@TrueFalseGobbleBlockInstructionsHook{\relax}
\def\exam@answer{answer}
\def\exam@enumerate{enumerate}
\def\exam@list{list}

\long\def\exam@BlockGobbleToBeginEnumerate#1\begin{%
  \exam@CheckNextTokenForEnumerate}
\def\exam@CheckNextTokenForEnumerate#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\exam@enumerate
    \exam@BeginEnumerate
  \else
    \expandafter\exam@BlockGobbleToBeginEnumerate
  \fi}
\def\exam@BeginEnumerate{\begin{enumerate}}

\long\def\exam@TrueFalseBlockInstructionsGobble#1\exam@StartTrueFalseList{%
  \exam@StartTrueFalseList}

\long\def\exam@GobbleUpToAnswer#1\begin{%
  \exam@CheckNextTokenForAnswer}
\def\exam@CheckNextTokenForAnswer#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\exam@answer
    \let\exam@next=\exam@PrepareToTypesetAnswer
  \else
    \ifx\@tempa\@endquestionhook
      \let\exam@next=\@endquestionhook
    \else
      \let\exam@next=\exam@GobbleUpToAnswer
  \fi\fi\exam@next}
\def\exam@PrepareToTypesetAnswer{\begin{answer}}

\long\def\exam@GobbleUpToEndQuestionHook#1\@endquestionhook{%
  \@endquestionhook}

\long\def\exam@GobbleUpToChoice#1\choice{\choice}

\def\exam@FillinGobbleNext#1{%
  \ifx #1\blank
    \let\exam@next=\exam@FillinInsertBlank
  \else
    \ifx #1\@endquestionhook
      \def\exam@insertedblank{no}%
      .\let\exam@next=\relax
    \else
      \let\exam@next=\exam@FillinGobbleNext
  \fi\fi\exam@next}

\def\exam@FillinBlockGobbleNext#1{%
  \ifx #1\blank
    \let\exam@next=\exam@FillinBlockInsertBlank
  \else
    \ifx #1\end
      \let\exam@next=\exam@CheckNextTokenForQuestion
    \else
      \let\exam@next=\exam@FillinBlockGobbleNext
  \fi\fi\exam@next}
\def\exam@CheckNextTokenForQuestion#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\@Q
    \expandafter\exam@FillinWrapupAndEndQuestion
  \else
    \expandafter\exam@FillinBlockGobbleNext
  \fi}
\def\exam@FillinWrapupAndEndQuestion{.\end{question}}

\def\exam@insertedblank{no}
\def\exam@FillinInsertBlank#1{%
  \ifx\exam@insertedblank\exam@c@no
    #1\def\exam@insertedblank{yes}%
  \else
    , #1\relax
  \fi\exam@FillinGobbleNext}
\def\exam@FillinBlockInsertBlank#1{%
  \ifx\exam@insertedblank\exam@c@no
    #1\def\exam@insertedblank{yes}%
  \else
    , #1\relax
  \fi\exam@FillinBlockGobbleNext}

\def\ShortKey{%
  \def\exam@AddSectionInstructionsHook{%
    \ifanswer\relax\else\exam@AddSectionInstructions\fi}
  \def\exam@SAGobbleQuestionHook{%
    \ifanswer\expandafter\exam@GobbleUpToAnswer\fi}
  \def\exam@MCGobbleQuestionHook{%
    \ifanswer\expandafter\exam@GobbleUpToChoice\fi}
  \def\exam@FillinGobbleQuestionHook{%
    \ifanswer\expandafter\exam@FillinGobbleNext\fi}
  \def\exam@FillinBlockGobbleQuestionHook{%
    \ifanswer\expandafter\exam@FillinBlockGobbleNext\fi}
  \def\exam@GobbleBlockInstructionsHook{%
    \ifanswer\expandafter\exam@BlockGobbleToBeginEnumerate\fi}
  \def\exam@TrueFalseGobbleBlockInstructionsHook{%
    \ifanswer\expandafter\exam@TrueFalseBlockInstructionsGobble\fi}
  \let\choice=\exam@ShortChoice}

\def\exam@ShortChoice{%
  \ifanswer
    \expandafter\exam@ShortKeyChoice
  \else
    \expandafter\exam@DefaultChoice
  \fi}

\newif\ifOneCorrectAnswerAlreadyGiven
\OneCorrectAnswerAlreadyGivenfalse
\def\MultipleChoiceShortKeyPrefix#1{%
  \def\exam@MultipleChoiceShortKeyPrefix{#1}}
\MultipleChoiceShortKeyPrefix{}

\newcommand{\exam@ShortKeyChoice}[2][]{%
  \if#1!%
    \ifOneCorrectAnswerAlreadyGiven
    , (\alph{choice})
    \else
    \exam@MultipleChoiceShortKeyPrefix
    (\alph{choice})%
    \OneCorrectAnswerAlreadyGiventrue
    \fi
   \else
     \stepcounter{choice}%
  \fi\ignorespaces}

\def\exam@ShortTFItem{%
  \ifanswer
    \item[\csname tf@sol\current@question\endcsname]
  \else
    \item
  \fi}

\def\exam@c@yes{yes}
\def\exam@c@no{no}

\def\exam@MCMinipageWrapperBegin{\begin{minipage}[t]{\noexpand\linewidth}}
\def\exam@MCMinipageWrapperEnd{\end{minipage}}

\def\DefineAnswerWrapper#1#2{%
  \def\exam@DefineAnswerEnvironment{%
    \def\answer{#1}\def\endanswer{#2}}}
\DefineAnswerWrapper{\begin{description}\item[Answer:]}{\end{description}}

\let\old@pagebreak=\pagebreak
\def\exam@none{none}
\def\pagebreak{%
  \ifx\@currentsectionname\exam@none
    \setcounter{temp}{\thesection}
    \stepcounter{temp}
    \expandafter\def\csname sec\thetemp break\endcsname{\old@pagebreak}
  \else
    \expandafter
    \gdef\csname sec\thesection q\thequestion break\endcsname{\old@pagebreak}
  \fi}

\def\exam@WhileReadingBreakPageOnVersion#1{%
  \ifx\@currentsectionname\exam@none
    \setcounter{temp}{\thesection}%
    \stepcounter{temp}%
    \expandafter\def\csname sec\thetemp break\endcsname{%
      \ifnum\value{version}=#1\relax
        \old@pagebreak
      \fi}
  \else
    \expandafter
    \gdef\csname sec\thesection q\thequestion break\endcsname{%
      \ifnum\c@version=#1
        \old@pagebreak
      \fi}
  \fi}
\def\exam@DoneReadingBreakPageOnVersion#1{%
  \ifnum\value{version}=#1\relax
    \old@pagebreak
    \fi}
\let\BreakPageOnVersion=\exam@WhileReadingBreakPageOnVersion

\def\@currentsectionname{none}

\def\IncludeFromFile#1{\def\exam@includefile{#1}}

\def\InsertChunk#1{%
  \def\exam@chunklookup{#1}%
  \input{\exam@includefile}}

\def\chunk#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\exam@chunklookup
    \relax
  \else
    \expandafter\exam@GobbleRestOfChunk
  \fi}
\def\endchunk{\relax}

\def\exam@chunk{chunk}
\long\def\exam@GobbleRestOfChunk#1\end{%
  \exam@CheckNextTokenForChunk}
\def\exam@CheckNextTokenForChunk#1{%
  \def\@tempa{#1}%
  \ifx\@tempa\exam@chunk
    \end{chunk}%
  \else
    \expandafter\exam@GobbleRestOfChunk
  \fi}


%    \end{macrocode}
% \end{macro}