forked from fzampirolli/mctest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexam.cls
6994 lines (6378 loc) · 229 KB
/
exam.cls
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
% exam.cls
%
% A LaTeX2e document class for preparing exams.
%% exam.cls
%% Copyright (c) 1994, 1997, 2000, 2004, 2008, 2011, 2015 Philip S. Hirschhorn
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
%
% This work has the LPPL maintenance status "author-maintained".
%
% This work consists of the files exam.cls and examdoc.tex.
% The user's guide for exam.cls is in the file examdoc.tex.
%%% Philip Hirschhorn
%%% Department of Mathematics
%%% Wellesley College
%%% Wellesley, MA 02481
% The newest version of this documentclass should always be available
% from my web page: http://www-math.mit.edu/~psh/
\def\fileversion{2.5}
\def\filedate{2015/05/07}
%---------------------------------------------------------------------
%---------------------------------------------------------------------
%
% If there's some feature that you'd like that this file doesn't
% provide, tell me about it.
%
%
%
%
%
% Thanks to:
%
% Piet van Oostrum, from whose excellent ``fancyheadings.sty'' we
% shamelessly stole most of the code for setting the headers and
% footers.
%
% Mate Wierdl <[email protected]>, who contributed the
% code so that if the number of points is ``1'', then the default
% value of \pointname will print ``1 point'' instead of ``1 points''.
%
% Tom Brikowski <[email protected]>, who contributed the code for
% making the number of points and number of questions available as
% macros (as well as the idea of putting the number of points in a
% box, instead of in parentheses). (I changed his code to make this
% all optional, so if there are errors there, it's my fault and not
% his.)
%
% Ottmar Beucher <[email protected]>, Dan Drake
% <[email protected]>, and Justus Piater <[email protected]> who
% contributed ideas and code for the \pointsofquestion and \gradetable
% commands for printing a Grading Table. (I changed all the code to
% make this compatible with hyperref.sty, so if there are errors there,
% it's my fault and not theirs.)
%
% Justus Piater <[email protected]>, who contributed the code for
% the solution environment. (I changed his code to allow page breaks
% inside solutions so, once again, if it's buggy, it's my fault.)
%
% Donald Arseneau <[email protected]>, who created the excellent
% ``framed.sty'' and generously allowed me to include basically the
% whole thing in exam.cls, making the few changes needed for it to
% work well with question environments:
% framed.sty v 0.8a 21-Jul-2003
% Copyright (C) 1992-2003 by Donald Arseneau
% These macros may be freely transmitted, reproduced, or modified
% provided that this notice is left intact.
%
%--------------------------------------------------------------------
%--------------------------------------------------------------------
% Changelog since version 2.4:
%--------------------------------------------------------------------
% Version 2.5 2015/05/07
% No longer betatest.
%--------------------------------------------------------------------
% Version 2.408$\beta$ 2013/11/17
% New commands:
%
% \firstqinrange{whatever}
% \lastqinrange{whatever}
% \numqinrange{whatever}
%
% where ``whatever'' is the name of a grading range.
%
% \firstqinrange{whatever} prints the number of the first question in
% the range.
%
% \lastqinrange{whatever} prints the number of the last question in the
% range.
%
% \numqinrange{whatever} prints the number of questions in the range.
%
% We changed a couple of internal command name related to grading
% ranges. If the user defines the range `myrange', then we now use
% \range@myrange@firstp
% \range@myrange@lastp
% \range@myrange@firstq
% \range@myrange@lastq
%
% where we used to use
%
% \tbl@myrange@firstp
% \tbl@myrange@lastp
% \tbl@myrange@firstq
% \tbl@myrange@lastq
%--------------------------------------------------------------------
% Version 2.407$\beta$ 2012/12/19
% New environment:
%
% solutionbox
%
% The solutionbox environment is different from the other solution
% environments (solution, solutionorbox, solutionorlines,
% solutionordottedlines, and solutionorgrid), in that
%
% (1) The box is always printed, whether answers are being printed
% or not.
%
% (2) The argument giving the size of the box is a required
% argument, not an optional argument, and so it should be enclosed
% in braces, not in brackets. It can be either a length or
% \stretch{number}.
%
% (3) We make no use of the TheSolution environment; the solutionbox
% environment is completely freestanding.
%
% If answers are not being printed then only the box is printed, with
% nothing in it. If answers are being printed, then the solution is
% printed inside of the box.
%
% Note: It's the user's responsibility to be sure that the box is
% large enough to hold the solution! If the solution takes up too
% much vertical space, then it will spill out of the bottom of the
% box, overwriting whatever follows the box.
%
%--------------------------------------------------------------------
% Version 2.406$\beta$, 2012/12/16
%
% New command:
%
% \noquestionsonthispage
%
% This command tells the \ifcontinuation and \ifincomplete commands
% to assume that no part of any question is on this page. This is
% similar to the job done by the \nomorequestions command for the
% pages that follow the end of all of the questions.
%
%
% If you give the command \noquestionsonthispage on a page, then
%
% (1) \ifcontinuation on that page will expand to its second
% argument,
% (2) \ifincomplete on that page will expand to its second
% argument, and
% (3) an \ifincomplete on an earlier page will not assume that a
% question from that earlier page continues onto this page.
%
% The way that this command affects the \ifincomplete command on
% earlier pages is as follows: If there is a page with no questions or
% parts or subparts or subsubparts, then the last page before that
% with a question (or part, etc.) would normally be deemed incomplete;
% if, however, the page with no questions (or parts, etc.) (along with
% all adjacent pages with no questions or parts etc.) has a
% \noquestionsonthispage command, then that last page with a question
% (or part, etc.) will not be deemed incomplete.
%
% Note that if you're tempted to use this command on a page that follows
% the end of all of the questions, then you should probably use the
% command \nomorequestions instead.
%
%--------------------------------------------------------------------
% Version 2.405$\beta$, 2012/10/21
%
% It is now possible to use a parts, subparts, or subsubparts
% environment inside one of the solution environments (solution,
% solutionorbox, solutionorlines, solutionordottedlines, or
% solutionorgrid) without getting problems from multiply defined
% labels or having its points (if any) counted as being actual points
% on the exam.
%
% Any \part, \subpart, or \subsubpart command inside one of the
% solution environments now writes a \PgInfo command in the .aux file
% of the form question2@object3, but no labels and no other \PgInfo
% commands. In addition, if there are points assigned to any of these
% commands inside any of the solution environments, those points are
% not added to the points of the question or the points on the page,
% and do not affect any gradetables or pointtables.
%
%--------------------------------------------------------------------
% Version 2.404$\beta$, 2012/09/03
%
% New command:
%
% \fillwithgrid{length}
%
% New environment:
%
% solutionorgrid
%
% These are similar to the \fillwithlines command and the
% solutionorlines environment.
%
% By default, the created grids are in black. However, if you give the
% commands
%
% \usepackage{color}
% \colorgrids
%
% then the grids will be in color, by default a light gray. That
% default color was defined by the command
%
% \definecolor{GridColor}{gray}{0.8}
%
% You can change the color by redefining the color GridColor, and you
% can return to using black grids by giving the command
%
% \nocolorgrids
%
% The default grid size and grid line thickness were set by the
% commands
%
% \setlength{\gridsize}{5mm}
% \setlength{\gridlinewidth}{0.1pt}
%
% You can change either or both of those by giving new \setlength
% commands. The period of the grid is \gridsize (both horizontally
% and vertically). That is, the horizontal distance from the left
% edge of one vertical line to the left edge of the next vertical line
% is \gridsize, as is the vertical distance from the top edge of one
% horizontal line to the top edge of the next horizontal line. Thus,
% each square has outer side length equal to \gridsize+\gridlinewidth.
%
%--------------------------------------------------------------------
% Version 2.403$\beta$, 2012/08/29:
%
% We changed the code for the command \fillin (which had been modified
% in version 2.402beta) so that if only one optional argument is used,
% a space following that optional argument will not be ignored. We
% did this in such a way that the second optional argument will be
% recognized even when spaces appear in between the optional
% arguments.
%
%--------------------------------------------------------------------
% Version 2.402$\beta$, 2012/08/21:
%
% We modified the command \fillin that we had created in version
% 2.401beta. \fillin now takes two optional arguments (and no required
% arguments).
%
% \fillin can take two optional arguments, as in
%
% \fillin[Answer][Length]
%
% The first optional argument is the answer to be printed above the line
% when \printanswers is in effect; the default value is empty. That
% line is printed a distance of \answerclearance below the baseline.
%
% The second optional argument is the length of the line that we print;
% the default value is \fillinlinelength. The value of
% \fillinlinelength is set with the command
%
% \setlength\fillinlinelength{1in}
%
% and can be changed by giving a new \setlength command.
%
% When answers are being printed, the first optional argument is
% printed subject to the declarations in the argument of the last
% \CorrectChoiceEmphasis command. It is centered on the line unless
% it is too long, in which case it extends to the right of the line.
%
%--------------------------------------------------------------------
% Version 2.401$\beta$, 2012/08/20:
%
%
% New command:
%
% \fillin[CorrectAnswer]{width}
%
% This is for use in fill in the blank questions. This command inserts
% a blank line of width ``width''. If answers are being printed and if
% the optional argument ``CorrectAnswer'' appears, then the optional
% argument is printed subject to the declarations in the argument of the
% last \CorrectChoiceEmphasis command, and it is printed a distance of
% \answerclearance above the line. It is centered on the line unless it
% is too long, in which case it extends to the right of the line.
%
% Note: We changed this command in version 2.401beta.
%
%--------------------------------------------------------------------
%--------------------------------------------------------------------
%--------------------------------------------------------------------
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{exam}[\filedate\space Version \fileversion\space by
Philip Hirschhorn]
\RequirePackage{ifthen}
\newif\ifprintanswers
\printanswersfalse
\DeclareOption{answers}{\printanswerstrue}
\DeclareOption{noanswers}{\printanswersfalse}
\newif\ifcancelspace
\cancelspacefalse
\DeclareOption{cancelspace}{\cancelspacetrue}
\DeclareOption{nocancelspace}{\cancelspacefalse}
% The following keeps track of whether the user has requested that we
% add up the points on the exam. We make the default false so that
% users who put other than numbers into the points argument of a
% question (or part, or subpart) won't get error messages.
% We use \if@printtotalpoints as a flag to signal that we are counting
% points, so that we will know to print the total on the screen (and
% in the log file). We use this separate flag so that the user can
% use both \addpoints and \noaddpoints to count some points and not
% others, but still have the total printed when we finish the file no
% matter what the state of \if@addpoints.
\newif\if@addpoints
\newif\if@printtotalpoints
\def\addpoints{\global\@addpointstrue\global\@printtotalpointstrue}
\def\noaddpoints{\global\@addpointsfalse}
\@addpointsfalse
\@printtotalpointsfalse
\DeclareOption{addpoints}{\addpoints}
\DeclareOption*{%
\PassOptionsToClass{\CurrentOption}{article}%
}
\ProcessOptions\relax
\LoadClass{article}
% *****************
% ** PAGE LAYOUT **
% *****************
% We set the parameters in terms of \paperwidth and \paperheight
% so that the options
% a4paper
% a5paper
% b5paper
% letterpaper
% legalpaper
% executivepaper
% landscape
% will all work:
\setlength{\textwidth}{\paperwidth}
\addtolength{\textwidth}{-2in}
\setlength{\oddsidemargin}{0pt}
\setlength{\evensidemargin}{0pt}
\setlength{\headheight}{15pt}
\setlength{\headsep}{15pt}
\setlength{\topmargin}{0in}
\addtolength{\topmargin}{-\headheight}
\addtolength{\topmargin}{-\headsep}
\setlength{\footskip}{29pt}
\setlength{\textheight}{\paperheight}
\addtolength{\textheight}{-2.2in}
\setlength{\marginparwidth}{.5in}
\setlength{\marginparsep}{5pt}
%--------------------------------------------------------------------
% ****************
% ** EXTRAWIDTH **
% ****************
\newlength\@extrawidth
% \@rightmargin is needed for \pointsinrightmargin and
% \pointsdroppedatright, so that we can right justify the points:
\newlength\@rightmargin
\setlength{\@rightmargin}{1in}
% We put the argument of \extrawidth into a length so that it will
% work correctly even if it's negative:
\def\extrawidth#1{%
\@extrawidth=#1
\advance \textwidth by \@extrawidth
\divide\@extrawidth by 2
\advance\oddsidemargin by -\@extrawidth
\advance\evensidemargin by -\@extrawidth
% Bug fix, 13 April 2004:
%\advance\@rightmargin by \@extrawidth
\advance\@rightmargin by -\@extrawidth
}
%--------------------------------------------------------------------
%--------------------------------------------------------------------
% Making room for large headers and footers
% The following are used to save the effect of any changes to
% \topmargin and \textheight caused by \extraheadheight or
% \extrafootheight commands. They hold the values currently in effect.
% We put them into lengths so that it will work correctly even if the
% argument is negative:
\newlength\@extrahead
\newlength\@extrafoot
\setlength{\@extrahead}{0in}
\setlength{\@extrafoot}{0in}
% The following are used to hold the requested values for extrahead and
% extrafoot, first page and all pages after the first, and then the
% similar things requested for the cover pages:
\newlength\run@exhd
\newlength\fp@exhd
\newlength\run@exft
\newlength\fp@exft
\newlength\covrun@exhd
\newlength\covfp@exhd
\newlength\covrun@exft
\newlength\covfp@exft
\setlength{\run@exhd}{0in}
\setlength{\fp@exhd}{0in}
\setlength{\run@exft}{0in}
\setlength{\fp@exft}{0in}
\setlength{\covrun@exhd}{0in}
\setlength{\covfp@exhd}{0in}
\setlength{\covrun@exft}{0in}
\setlength{\covfp@exft}{0in}
\newcommand*\adj@hdht@ftht{%
\if@coverpages
\ifnum\value{page}=1\relax
\@setheadheight{\covfp@exhd}%
\@setfootheight{\covfp@exft}%
\else
\@setheadheight{\covrun@exhd}%
\@setfootheight{\covrun@exft}%
\fi
\else
\ifnum\value{page}=1\relax
\@setheadheight{\fp@exhd}%
\@setfootheight{\fp@exft}%
\else
\@setheadheight{\run@exhd}%
\@setfootheight{\run@exft}%
\fi
\fi
}
\newcommand*\extraheadheight{%
\@ifnextchar[{\@xtrahd}{\@ytrahd}%
}
\def\@xtrahd[#1]#2{%
\setlength{\fp@exhd}{#1}%
\setlength{\run@exhd}{#2}%
\adj@hdht@ftht
}
\def\@ytrahd#1{%
\setlength{\fp@exhd}{#1}%
\setlength{\run@exhd}{#1}%
\adj@hdht@ftht
}
\newcommand*\extrafootheight{%
\@ifnextchar[{\@xtraft}{\@ytraft}%
}
\def\@xtraft[#1]#2{%
\setlength{\fp@exft}{#1}%
\setlength{\run@exft}{#2}%
\adj@hdht@ftht
}
\def\@ytraft#1{%
\setlength{\fp@exft}{#1}%
\setlength{\run@exft}{#1}%
\adj@hdht@ftht
}
\newcommand*\coverextraheadheight{%
\@ifnextchar[{\cov@xtrahd}{\cov@ytrahd}%
}
\def\cov@xtrahd[#1]#2{%
\setlength{\covfp@exhd}{#1}%
\setlength{\covrun@exhd}{#2}%
\adj@hdht@ftht
}
\def\cov@ytrahd#1{%
\setlength{\covfp@exhd}{#1}%
\setlength{\covrun@exhd}{#1}%
\adj@hdht@ftht
}
\newcommand*\coverextrafootheight{%
\@ifnextchar[{\cov@xtraft}{\cov@ytraft}%
}
\def\cov@xtraft[#1]#2{%
\setlength{\covfp@exft}{#1}%
\setlength{\covrun@exft}{#2}%
\adj@hdht@ftht
}
\def\cov@ytraft#1{%
\setlength{\covfp@exft}{#1}%
\setlength{\covrun@exft}{#1}%
\adj@hdht@ftht
}
\def\@appendoutput#1{%
\output=\expandafter{\the\output #1}%
}
\@appendoutput{\adj@hdht@ftht}
%--------------------------------------------------------------------
% \@setheadheight and \@setfootheight:
\def\@setheadheight#1{%
\begingroup % Avoid trouble from using \@temp and \@spaces
% Reset the effect of the most recent change:
\global\advance\topmargin by -\@extrahead
\global\advance\textheight by \@extrahead
% Save the newly set value:
\def\@temp{#1}
\def\@spaces{ }
\ifx\@temp\@empty
\global\@extrahead=0in
\else
\ifx\@temp\@spaces
\global\@extrahead=0in
\else
\global\@extrahead=#1
\fi
\fi
% Set the new values:
\global\advance\topmargin by \@extrahead
\global\advance\textheight by -\@extrahead
% Make it take effect RIGHT NOW!:
% (The following stuff isn't necessary if \@setheadheight is
% executed only in the preamble or as we return from the output
% routine, but we're leaving it in so that this will still work if
% we use this at some random point in the middle of composing a
% page).
% Bugfix, Version 2.306beta, 2009/03/28:
% We don't do this!!
% If the user had a figure environment that floated to the
% top of a page, then this would cause that page to run
% over the footer and off the bottom of the page, because
% this somehow caused a full page's worth of stuff to be
% placed after the figure, as if the figure wasn't taking
% up space on the page.
% We *do* need to put \@colht at the correct new value, though,
% apparently because \@colht is set near the end of the
% output routine.
\global\@colht=\textheight
% \global\@colroom=\textheight
% \global\vsize=\textheight
% \global\pagegoal=\textheight
\endgroup
}
\def\@setfootheight#1{%
\begingroup % Avoid trouble from using \@temp and \@spaces
% Reset the effect of the most recent change:
\global\advance\textheight by \@extrafoot
% Save the newly set value:
\def\@temp{#1}
\def\@spaces{ }
\ifx\@temp\@empty
\global\@extrafoot=0in
\else
\ifx\@temp\@spaces
\global\@extrafoot=0in
\else
\global\@extrafoot=#1
\fi
\fi
% Set the new values:
\global\advance\textheight by -\@extrafoot
% Make it take effect RIGHT NOW!:
% (The following stuff isn't necessary if \@setfootheight is
% executed only in the preamble or as we return from the output
% routine, but we're leaving it in so that this will still work if
% we use this at some random point in the middle of composing a
% page).
% Bugfix, Version 2.306beta, 2009/03/28:
% We don't do this!!
% If the user had a figure environment that floated to the
% top of a page, then this would cause that page to run
% over the footer and off the bottom of the page, because
% this somehow caused a full page's worth of stuff to be
% placed after the figure, as if the figure wasn't taking
% up space on the page.
% We *do* need to put \@colht at the correct new value, though,
% apparently because \@colht is set near the end of the
% output routine.
\global\@colht=\textheight
% \global\@colroom=\textheight
% \global\vsize=\textheight
% \global\pagegoal=\textheight
\endgroup
}
%---------------------------------------------------------------------
%
% *************************
% ** HEADERS AND FOOTERS **
% *************************
%
% The pagestyles available are head, foot, headandfoot, and empty.
% \pagestyle{head} prints the head, and gives an empty foot.
% \pagestyle{foot} prints the foot, and gives an empty head.
% \pagestyle{headandfoot} prints both the head and the foot.
% \pagestyle{empty} gives an empty head and an empty foot.
%
% Pagestyles:
\newcommand*\ps@head{%
\@dohead
\@nofoot
}
\newcommand*\ps@headandfoot{%
\@dohead
\@dofoot
}
\newcommand*\ps@foot{%
\@nohead
\@dofoot
}
% \ps@empty is already defined by article.cls, so we'll
% say \def instead of \newcommand*:
\def\ps@empty{%
\@nohead
\@nofoot
}
\newif\if@coverpages
\@coverpagesfalse
\newcounter{num@coverpages}
% We'll set this to zero in case there is no coverpages environment:
\setcounter{num@coverpages}{0}
\newenvironment{coverpages}{%
\ifnum \value{numquestions}>0\relax
\ClassError{exam}{%
Coverpages cannot be used after questions have begun.\MessageBreak
}{%
All question, part, subpart, and subsubpart environments
\MessageBreak
must begin after the cover pages are complete.\MessageBreak
}%
\fi
\@coverpagestrue
\pagenumbering{roman}%
\adj@hdht@ftht
}{%
\clearpage
\setcounter{num@coverpages}{\value{page}}%
\addtocounter{num@coverpages}{-1}%
\pagenumbering{arabic}%
% Bugfix, Version 2.307\beta, 2009/06/11:
% We have to say \@coverpagesfalse before \adj@hdht@ftht
% because we're still inside the group created by the
% coverpages environment and we want to set the
% extraheadheight and extrafootheight to the values correct
% for the first non-cover page:
\@coverpagesfalse
\adj@hdht@ftht
}
\newcommand*\cover@question@error{%
\ClassError{exam}{%
No questions are allowed in the cover pages.\MessageBreak
}{%
All question, part, subpart, and subsubpart environments
\MessageBreak
must begin after the cover pages are complete.\MessageBreak
}%
}
\newcommand*\@dohead{%
\def\@oddhead{%
\if@coverpages
\ifnum\value{page}=1\relax
\cov@fullhead
\else
\covrun@fullhead
\fi
\else
\ifnum\value{page}=1\relax
\@fullhead
\else
\run@fullhead
\fi
\fi
}% @oddhead
\let\@evenhead=\@oddhead
}
\newcommand*\@dofoot{%
\def\@oddfoot{%
\if@coverpages
\ifnum\value{page}=1\relax
\cov@fullfoot
\else
\covrun@fullfoot
\fi
\else
\ifnum\value{page}=1\relax
\@fullfoot
\else
\run@fullfoot
\fi
\fi
}% @oddfoot
\let\@evenfoot=\@oddfoot
}
\newcommand*\@nohead{%
\def\@oddhead{}%
\let\@evenhead=\@oddhead
}
\newcommand*\@nofoot{%
\def\@oddfoot{}%
\let\@evenfoot=\@oddfoot
}
%--------------------------------------------------------------------
% \@fullhead, \run@fullhead, \@fullfoot, and \run@fullfoot:
\newcommand*\@fullhead{%
\vbox to \headheight{%
\vss
\hbox to \textwidth{%
\normalfont\rlap{\parbox[b]{\textwidth}{\raggedright\@lhead\strut}}%
\hss\parbox[b]{\textwidth}{\centering\@chead\strut}\hss
\llap{\parbox[b]{\textwidth}{\raggedleft\@rhead\strut}}%
}% hbox
\if@headrule
\hrule
\else
% an invisible hrule, to keep positioning constant:
\hrule width 0pt
\fi
}% vbox
}
\newcommand*\run@fullhead{%
\vbox to \headheight{%
\vss
\hbox to \textwidth{%
\normalfont\rlap{\parbox[b]{\textwidth}{\raggedright\run@lhead\strut}}%
\hss\parbox[b]{\textwidth}{\centering\run@chead\strut}\hss
\llap{\parbox[b]{\textwidth}{\raggedleft\run@rhead\strut}}%
}% hbox
\ifrun@headrule
\hrule
\else
% an invisible hrule, to keep positioning constant:
\hrule width 0pt
\fi
}% vbox
}
% We arrange it so that the very top of first line of text in the
% foot is at a fixed position on the page, whether or not there's
% a footrule:
\newcommand*\@fullfoot{%
\vbox to 0pt{%
\if@footrule
\hrule
\else
% an invisible hrule, to keep positioning constant:
\hrule width 0pt
\fi
\vskip 3pt
\hbox to \textwidth{%
\normalfont\rlap{\parbox[t]{\textwidth}{\raggedright\@lfoot}}%
\hss\parbox[t]{\textwidth}{\centering\@cfoot}\hss
\llap{\parbox[t]{\textwidth}{\raggedleft\@rfoot}}%
}% hbox
\vss
}% vbox
}
\newcommand*\run@fullfoot{%
\vbox to 0pt{%
\ifrun@footrule
\hrule
\else
% an invisible hrule, to keep positioning constant:
\hrule width 0pt
\fi
\vskip 3pt
\hbox to \textwidth{%
\normalfont\rlap{\parbox[t]{\textwidth}{\raggedright\run@lfoot}}%
\hss\parbox[t]{\textwidth}{\centering\run@cfoot}\hss
\llap{\parbox[t]{\textwidth}{\raggedleft\run@rfoot}}%
}% hbox
\vss
}% vbox
}
%--------------------------------------------------------------------
% \cov@fullhead, \covrun@fullhead, \cov@fullfoot, and
% \covrun@fullfoot:
\newcommand*\cov@fullhead{%
\vbox to \headheight{%
\vss
\hbox to \textwidth{%
\normalfont\rlap{\parbox[b]{\textwidth}{\raggedright\cov@lhead\strut}}%
\hss\parbox[b]{\textwidth}{\centering\cov@chead\strut}\hss
\llap{\parbox[b]{\textwidth}{\raggedleft\cov@rhead\strut}}%
}% hbox
\ifcov@headrule
\hrule
\else
% an invisible hrule, to keep positioning constant:
\hrule width 0pt
\fi
}% vbox
}
\newcommand*\covrun@fullhead{%
\vbox to \headheight{%
\vss
\hbox to \textwidth{%
\normalfont\rlap{\parbox[b]{\textwidth}{\raggedright\covrun@lhead\strut}}%
\hss\parbox[b]{\textwidth}{\centering\covrun@chead\strut}\hss
\llap{\parbox[b]{\textwidth}{\raggedleft\covrun@rhead\strut}}%
}% hbox
\ifcovrun@headrule
\hrule
\else
% an invisible hrule, to keep positioning constant:
\hrule width 0pt
\fi
}% vbox
}
% We arrange it so that the very top of first line of text in the
% foot is at a fixed position on the page, whether or not there's
% a footrule:
\newcommand*\cov@fullfoot{%
\vbox to 0pt{%
\ifcov@footrule
\hrule
\else
% an invisible hrule, to keep positioning constant:
\hrule width 0pt
\fi
\vskip 3pt
\hbox to \textwidth{%
\normalfont\rlap{\parbox[t]{\textwidth}{\raggedright\cov@lfoot}}%
\hss\parbox[t]{\textwidth}{\centering\cov@cfoot}\hss
\llap{\parbox[t]{\textwidth}{\raggedleft\cov@rfoot}}%
}% hbox
\vss
}% vbox
}
\newcommand*\covrun@fullfoot{%
\vbox to 0pt{%
\ifcovrun@footrule
\hrule
\else
% an invisible hrule, to keep positioning constant:
\hrule width 0pt
\fi
\vskip 3pt
\hbox to \textwidth{%
\normalfont\rlap{\parbox[t]{\textwidth}{\raggedright\covrun@lfoot}}%
\hss\parbox[t]{\textwidth}{\centering\covrun@cfoot}\hss
\llap{\parbox[t]{\textwidth}{\raggedleft\covrun@rfoot}}%
}% hbox
\vss
}% vbox
}
%--------------------------------------------------------------------
%--------------------------------------------------------------------
%
% ********************************************
% ** COMMANDS TO DEFINE HEADERS AND FOOTERS **
% ********************************************
%
% \lhead[#1]{#2} sets the first page left head to #1, and the
% running left head to #2
%
% \lhead{#1} sets both the first page left head and the running
% left head to #1
%
% \chead, \rhead, \lfoot, \cfoot, and \rfoot work similarly.
%
%
% \@lhead is the left head for Page 1
% \run@lhead is the running left head
% (i.e., for all pages other than the first)
%
% \@chead is the center head for Page 1
% \run@chead is the running center head
% (i.e., for all pages other than the first)
%
% etc.
%
% Alternative commands are:
% \firstpageheader{LEFT}{CENTER}{RIGHT}
% \runningheader{LEFT}{CENTER}{RIGHT}
% or
% \header{LEFT}{CENTER}{RIGHT}
% which is equivalent to the two commands
% \firstpageheader{LEFT}{CENTER}{RIGHT}
% \runningheader{LEFT}{CENTER}{RIGHT}
%
% Alternative commands are:
% \firstpagefooter{LEFT}{CENTER}{RIGHT}
% \runningfoother{LEFT}{CENTER}{RIGHT}
% or
% \footer{LEFT}{CENTER}{RIGHT}
% which is equivalent to the two commands
% \firstpagefooter{LEFT}{CENTER}{RIGHT}
% \runningfoother{LEFT}{CENTER}{RIGHT}
\def\firstpageheader#1#2#3{%
\def\@lhead{#1}%
\def\@chead{#2}%
\def\@rhead{#3}%
}
\def\runningheader#1#2#3{%
\def\run@lhead{#1}%
\def\run@chead{#2}%
\def\run@rhead{#3}%
}
\def\header#1#2#3{%
\firstpageheader{#1}{#2}{#3}%
\runningheader{#1}{#2}{#3}%
}
\def\firstpagefooter#1#2#3{%
\def\@lfoot{#1}%
\def\@cfoot{#2}%
\def\@rfoot{#3}%
}
\def\runningfooter#1#2#3{%
\def\run@lfoot{#1}%
\def\run@cfoot{#2}%
\def\run@rfoot{#3}%
}
\def\footer#1#2#3{%
\firstpagefooter{#1}{#2}{#3}%
\runningfooter{#1}{#2}{#3}%
}