From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- macros/latex/contrib/exam/README | 50 + macros/latex/contrib/exam/exam.cls | 8306 +++++++++++++++++++++++++++++++ macros/latex/contrib/exam/exam.md5 | 3 + macros/latex/contrib/exam/examdoc.pdf | Bin 0 -> 481243 bytes macros/latex/contrib/exam/examdoc.tex | 8770 +++++++++++++++++++++++++++++++++ 5 files changed, 17129 insertions(+) create mode 100644 macros/latex/contrib/exam/README create mode 100644 macros/latex/contrib/exam/exam.cls create mode 100644 macros/latex/contrib/exam/exam.md5 create mode 100644 macros/latex/contrib/exam/examdoc.pdf create mode 100644 macros/latex/contrib/exam/examdoc.tex (limited to 'macros/latex/contrib/exam') diff --git a/macros/latex/contrib/exam/README b/macros/latex/contrib/exam/README new file mode 100644 index 0000000000..01b54c4184 --- /dev/null +++ b/macros/latex/contrib/exam/README @@ -0,0 +1,50 @@ +This is version 2.603 of the exam document class, dated December 17, +2017. + +The exam document class, together with its user's guide examdoc.tex, +attempts to make it easy for even a LaTeX novice to prepare exams. +Simple commands are provided to: + +1. Create questions, parts of questions, subparts of parts, and +subsubparts of subparts, all with optional point values. + +2. Create a grading table, indexed either by question number (listing +each question and the total possible points for that question) or by +page number (listing each page with points and the total possible +points for that page). A grading table can cover the entire exam or +just a part of the exam. Grading tables can have multiple rows or +multiple columns. + +3. Create headers and footers that are each specified in three parts: +One part to be left justified, one part to be centered, and one part +to be right justified. + +4. Have headers and/or footers that are different on the first page of +the exam, different on the last page of the exam, and that vary +depending on whether the page number is odd or even, or on whether the +current page continues a question from a previous page, or on whether +the last question on the current page continues onto the following +page. + +5. Have multiple line headers and/or footers, and to increase the part +of the page devoted to headers and/or footers to allow for this. + +6. Include solutions and have these solutions either printed or +ignored (or replaced automatically by space in which the students can +write their answers) depending on a single command. + +7. Leave blank space, or space in a box, or lined space, or dotted +lined space, or space filled with a grid. + +8. Change the words that are inserted by the document class (for, +e.g., point values, or table headings), so that they can be adapted to +personal taste and/or languages other than English. + +The user's guide examdoc.tex attempts to explain all of the +possibilities in a readable way, with many examples. + +-------------------------------------------------------------------- + +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. diff --git a/macros/latex/contrib/exam/exam.cls b/macros/latex/contrib/exam/exam.cls new file mode 100644 index 0000000000..cc587b3d65 --- /dev/null +++ b/macros/latex/contrib/exam/exam.cls @@ -0,0 +1,8306 @@ +% exam.cls +% +% A LaTeX2e document class for preparing exams. + +%% exam.cls +%% Copyright (c) 1994, 1997, 2000, 2004, 2008, 2011, +%% 2015, 2017 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 +%%% psh@math.mit.edu + +% The newest version of this documentclass should always be available +% from my web page: http://www-math.mit.edu/~psh/ + + +\def\fileversion{2.603} +\def\filedate{2017/12/17} +%--------------------------------------------------------------------- +%--------------------------------------------------------------------- +% +% 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 , 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 , 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 , Dan Drake +% , and Justus Piater 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 , 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 , 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.603, 2017/12/15 + +% No longer betatest. + +%-------------------------------------------------------------------- +% Version 2.602$\beta$, 2017/12/15 + +% We changed the code for multicolumn grade and point tables to remove +% the incompatibility with colortbl.sty and other packages that load +% colortbl.sty (e.g., xcolor.sty with the "table" option). + +%-------------------------------------------------------------------- +% Version 2.601$\beta$, 2017/09/22 + +% We changed command and environment names in the code from framed.sty +% that's included (slightly modified) in exam.cls so that the user can +% say \usepackage{framed} without creating conflicts. This also allows +% the user to use packages, such as minted.sty, that load framed.sty + +%-------------------------------------------------------------------- +% Version 2.6, 2017/09/19 + +% No longer betatest. + +%-------------------------------------------------------------------- +% Version 2.510$\beta$, 2016/10/11 + +% Bugfix: We changed \@setheadheight and \@setfootheight to fix a bug +% that was introduced by the bugfix in version 2.306beta, 2009/03/28: +% If the second page has a different \textheight (because of a change +% in either headheight or footheight between pages 1 and 2), then page +% 2 would use the \textheight of page 1. Pages 3 and beyond would get +% the correct \textheight. The original version of this set \@colroom +% and \vsize to the new \textheight, but that had a bug in that if a +% float appeared at the top of a page, there would be no notice taken +% of the space lost to the float, and so the text would overrun the +% bottom of the page. The bugfix in version 2.306beta eliminated the +% changes to \@colht and \vsize. In this bugfix, we adjust \@colroom, +% \@colht, and \vsize in the same way that we adjust \textheight. + +%-------------------------------------------------------------------- +% Version 2.509$\beta$, 2016/09/12 + +% Multicolumn grade and point tables, and a new syntax for multirow +% grade and point tables (which were introduced in version +% 2.508beta). + +% Multicolumn tables are vertically oriented, while multirow tables +% are horizontally oriented, and so they do not take the optional +% argument choosing between horizontal and vertical. They all take +% one required argument specifying the number of columns (for +% multicolumn) or the number of rows (for multirow). + +% The tables can be: + +% grade tables or point tables, + +% plain, bonus, or combined, + +% indexed by questions or by pages, + +% complete or partial. + +% As usual, if you omit the optional argument that chooses between +% questions and pages, you get questions. + +% The new commands are: + +% \def\multirowgradetable{numrows}[questions or pages] +% \def\multirowpointtable{numrows}[questions or pages] +% \def\multirowbonusgradetable{numrows}[questions or pages] +% \def\multirowbonuspointtable{numrows}[questions or pages] +% \def\multirowcombinedgradetable{numrows}[questions or pages] +% \def\multirowcombinedpointtable{numrows}[questions or pages] + +% \def\multirowpartialgradetable{numrows}{rangename}[questions or pages] +% \def\multirowpartialpointtable{numrows}{rangename}[questions or pages] +% \def\multirowpartialbonusgradetable{numrows}{rangename}[questions or pages] +% \def\multirowpartialbonuspointtable{numrows}{rangename}[questions or pages] +% \def\multirowpartialcombinedgradetable{numrows}{rangename}[questions or pages] +% \def\multirowpartialcombinedpointtable{numrows}{rangename}[questions or pages] + +% \def\multicolumngradetable{numcols}[questions or pages] +% \def\multicolumnpointtable{numcols}[questions or pages] +% \def\multicolumnbonusgradetable{numcols}[questions or pages] +% \def\multicolumnbonuspointtable{numcols}[questions or pages] +% \def\multicolumncombinedgradetable{numcols}[questions or pages] +% \def\multicolumncombinedpointtable{numcols}[questions or pages] + +% \def\multicolumnpartialgradetable{numcols}{rangename}[questions or pages] +% \def\multicolumnpartialpointtable{numcols}{rangename}[questions or pages] +% \def\multicolumnpartialbonusgradetable{numcols}{rangename}[questions or pages] +% \def\multicolumnpartialbonuspointtable{numcols}{rangename}[questions or pages] +% \def\multicolumnpartialcombinedgradetable{numcols}{rangename}[questions or pages] +% \def\multicolumnpartialcombinedpointtable{numcols}{rangename}[questions or pages] + +% The older grade and point table commands can still be used. For +% example, the commands + +% \gradetable[h][questions] +% \multirowgradetable{1}[questions] + +% are equivalent. + +% The distance between the rows of a multirow table and between the +% columns of a multicolumn table is \doublerulesep, the default value +% of which is 2.0pt. You can change that using a \setlength command, +% as in + +% \setlength{\doublerulesep}{0.5in} + +%-------------------------------------------------------------------- +% Version 2.508$\beta$, 2016/08/06 + +% New commands: Multirow grade and point tables. + +% These are all horizontally oriented tables, and so do not take the +% optional argument choosing between horizontal and vertical. They all +% take one required argument specifying the number of columns, which is +% the number of columns used for the point values (including the total), +% but not counting the column of row headings. + +% Note: The syntax was changed in version 2.509beta, so that you now +% specify the number of *rows* rather than the number of *columns*! For +% example, the first command below should now be + +% \multirowgradetable{numrows}[questions or pages] + +% The tables can be: + +% grade tables or point tables, + +% plain, bonus, or combined, + +% indexed by questions or by pages, + +% complete or partial. + +% The new commands are: + + +% \multirowgradetable{numcols}[questions or pages] +% \multirowpointtable{numcols}[questions or pages] +% \multirowbonusgradetable{numcols}[questions or pages] +% \multirowbonuspointtable{numcols}[questions or pages] +% \multirowcombinedgradetable{numcols}[questions or pages] +% \multirowcombinedpointtable{numcols}[questions or pages] + +% \multirowpartialgradetable{numcols}{rangename}[questions or pages] +% \multirowpartialpointtable{numcols}{rangename}[questions or pages] +% \multirowpartialbonusgradetable{numcols}{rangename}[questions or pages] +% \multirowpartialbonuspointtable{numcols}{rangename}[questions or pages] +% \multirowpartialcombinedgradetable{numcols}{rangename}[questions or pages] +% \multirowpartialcombinedpointtable{numcols}{rangename}[questions or pages] + +%-------------------------------------------------------------------- +% Version 2.507$\beta$, 2016/07/14 + +% New commands: + +% \pointstwosided +% \pointstwosidedreversed + +% The first causes points to be in the right margin on odd numbered +% pages and in the left margin on even numbered pages. + +% The second causes points to be in the left margin on odd numbered +% pages and in the right margin on even numbered pages. + +% Also: Some minor edits (e.g., deleting the unused \thebonuspoints). + +%-------------------------------------------------------------------- +% Version 2.506$\beta$, 2016/05/12 + +% Fixed an obscure bug that arose only when \CorrectChoiceEmphasis +% used color and a \CorrectChoice (in a choices or checkboxes +% environment) followed a \choice whose text completely filled its +% last line, and which was not separated from the \CorrectChoice by a +% blank line, in which case an extra (blank) line was inserted by that +% \choice. We fixed this by adding an improvised "\leavehmode" +% (styled after \leavevmode) to the \CorrectChoice command in both the +% choices and checkboxes environments, which caused the text of the +% previous \choice to be broken into lines *before* the \special +% inserted by the \color command was added. + +%-------------------------------------------------------------------- +% Version 2.505$\beta$, 2016/05/10 + +% We fixed a bug in the choices and checkboxes environments that arose +% only when \CorrectChoiceEmphasis used color. If it did, and if the +% text of a correct choice exactly filled a line, and if there was no +% blank line in the latex file separating this correct choice from the +% following choice, there would be an extra blank line inserted after +% the correct choice. We did this by inserting \color@begingroup and +% \color@endgroup as needed. (We're pretty sure the actual fix was +% the \endgraf in the expansion of \color@endgroup.) + +%-------------------------------------------------------------------- +% Version 2.504$\beta$, 2016/05/09 + +% We fixed a bug in the solutionbox environment that caused enumerate, +% itemize, or description environments to have their text stick into +% the right margin. We did this by resetting \@totalleftmargin and +% \linewidth in the box containing the solution. + +%-------------------------------------------------------------------- +% Version 2.503$\beta$, 2016/03/25 + +% New commands: + +% \colorfillwithlines +% \colorfillwithdottedlines + +% The first causes the lines drawn by the \fillwithlines command to be +% drawn in color. The default color is set by the command + +% \definecolor{FillWithLinesColor}{gray}{0.8} + +% and the color can be changed by giving a new \definecolor command. +% You can return to black lines by giving the command + +% \nocolorfillwithlines + +% \colorfillwithdottedlines causes the lines drawn by the +% \fillwithdottedlines command to be drawn in color. The default +% color is set by the command + +% \definecolor{FillWithDottedLinesColor}{gray}{0.8} + +% and the color can be changed by giving a new \definecolor command. +% You can return to black dotted lines by giving the command + +% \nocolorfillwithdottedlines + +%-------------------------------------------------------------------- +% Version 2.502$\beta$, 2016/03/23 + +% The command + +% \colorsolutionboxes + +% that was created in version 2.501beta now affects not only the boxes +% created by \solutionbox, but also by \makeemptybox, \solutionorbox, +% and all of the boxes printed by all of the various solution +% environments when solutions are being printed surrounded by a box. + +%-------------------------------------------------------------------- +% Version 2.501$\beta$, 2016/02/08 + +% Changed the \solutionbox environment so that it works correctly +% inside a tabular. + +% Also: The \solutionbox frame can now be printed in color, as long as +% you load color.sty in the preamble. +% +% Usage: Say +% +% \usepackage{color} +% +% in the preamble, and then give the command +% +% \colorsolutionboxes +% +% to have the frame around a solutionbox in color. The default color +% was created by the command +% +% \definecolor{SolutionBoxColor}{gray}{0.8} +% +% and you can change the color by giving a new \definecolor command +% (which must be done *after* the \colorsolutionboxes command). +% +% To cancel color solutionbox frames and return to black, give the +% command +% +% \nocolorsolutionboxes + +%-------------------------------------------------------------------- +% 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 + % Bugfix, Version 2.510beta, 2016/10/11: + \global\advance\@colroom by \@extrahead + \global\advance\@colht by \@extrahead + \global\advance\vsize 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 + % Bugfix, Version 2.510beta, 2016/10/11: + \global\advance\@colroom by -\@extrahead + \global\advance\@colht by -\@extrahead + \global\advance\vsize by -\@extrahead + % + % Bugfix, Version 2.510beta, 2016/10/11: + % We're fixing a bug that was introduced by the bugfix in version + % 2.306beta, 2009/03/28: If the second page has a different + % \textheight (because of a change in either headheight or + % footheight between pages 1 and 2), then page 2 would use the + % \textheight of page 1. Pages 3 and beyond would get the correct + % \textheight. + % The original version of this set \@colroom and \vsize to the new + % \textheight, but that had a bug in that if a float appeared at + % the top of a page, there would be no notice taken of the space + % lost to the float, and so the text would overrun the bottom of + % the page. + % In this bugfix, we adjust \@colroom, \@colht, and \vsize in the + % same way that we adjust \textheight. + % + % 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 +}% @setheadheight + +\def\@setfootheight#1{% + \begingroup % Avoid trouble from using \@temp and \@spaces + % Reset the effect of the most recent change: + \global\advance\textheight by \@extrafoot + % Bugfix, Version 2.510beta, 2016/10/11: + \global\advance\@colroom by \@extrafoot + \global\advance\@colht by \@extrafoot + \global\advance\vsize 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 + % Bugfix, Version 2.510beta, 2016/10/11: + \global\advance\@colroom by -\@extrafoot + \global\advance\@colht by -\@extrafoot + \global\advance\vsize by -\@extrafoot + % + % Bugfix, Version 2.510beta, 2016/10/11: + % We're fixing a bug that was introduced by the bugfix in version + % 2.306beta, 2009/03/28: If the second page has a different + % \textheight (because of a change in either headheight or + % footheight between pages 1 and 2), then page 2 would use the + % \textheight of page 1. Pages 3 and beyond would get the correct + % \textheight. + % The original version of this set \@colroom and \vsize to the new + % \textheight, but that had a bug in that if a float appeared at + % the top of a page, there would be no notice taken of the space + % lost to the float, and so the text would overrun the bottom of + % the page. + % In this bugfix, we adjust \@colroom, \@colht, and \vsize in the + % same way that we adjust \textheight. + % + % 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 +}% @setfootheight + + +%--------------------------------------------------------------------- +% +% ************************* +% ** 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}% +} + +\def\lhead{\@ifnextchar[{\@xlhead}{\@ylhead}} +\def\@xlhead[#1]#2{\def\@lhead{#1}\def\run@lhead{#2}} +\def\@ylhead#1{\def\run@lhead{#1}\def\@lhead{#1}} + +\def\chead{\@ifnextchar[{\@xchead}{\@ychead}} +\def\@xchead[#1]#2{\def\@chead{#1}\def\run@chead{#2}} +\def\@ychead#1{\def\run@chead{#1}\def\@chead{#1}} + +\def\rhead{\@ifnextchar[{\@xrhead}{\@yrhead}} +\def\@xrhead[#1]#2{\def\@rhead{#1}\def\run@rhead{#2}} +\def\@yrhead#1{\def\run@rhead{#1}\def\@rhead{#1}} + +\def\lfoot{\@ifnextchar[{\@xlfoot}{\@ylfoot}} +\def\@xlfoot[#1]#2{\def\@lfoot{#1}\def\run@lfoot{#2}} +\def\@ylfoot#1{\def\run@lfoot{#1}\def\@lfoot{#1}} + +\def\cfoot{\@ifnextchar[{\@xcfoot}{\@ycfoot}} +\def\@xcfoot[#1]#2{\def\@cfoot{#1}\def\run@cfoot{#2}} +\def\@ycfoot#1{\def\run@cfoot{#1}\def\@cfoot{#1}} + +\def\rfoot{\@ifnextchar[{\@xrfoot}{\@yrfoot}} +\def\@xrfoot[#1]#2{\def\@rfoot{#1}\def\run@rfoot{#2}} +\def\@yrfoot#1{\def\run@rfoot{#1}\def\@rfoot{#1}} + + +% Initialize head and foot: + +\pagestyle{headandfoot} + +\lhead{} +\chead{} +\rhead{} +\lfoot{} +\cfoot[]{Page \thepage} +\rfoot{} + +%-------------------------------------------------------------------- +% Coverpage headers and footers +% +% \coverlhead[#1]{#2} sets the first cover page left head to #1, and the +% running cover left head to #2 +% +% \coverlhead{#1} sets both the first cover page left head and the running +% cover left head to #1 +% +% \coverchead, \coverrhead, \coverlfoot, \covercfoot, and \coverrfoot +% work similarly. +% +% +% \cov@lhead is the left head for Page 1 +% \covrun@lhead is the running left head +% (i.e., for all pages other than the first) +% +% \cov@chead is the center head for Page 1 +% \covrun@chead is the running center head +% (i.e., for all pages other than the first) +% +% etc. +% +% Alternative commands are: +% \coverfirstpageheader{LEFT}{CENTER}{RIGHT} +% \coverrunningheader{LEFT}{CENTER}{RIGHT} +% or +% \coverheader{LEFT}{CENTER}{RIGHT} +% which is equivalent to the two commands +% \coverfirstpageheader{LEFT}{CENTER}{RIGHT} +% \coverrunningheader{LEFT}{CENTER}{RIGHT} +% +% Alternative commands are: +% \coverfirstpagefooter{LEFT}{CENTER}{RIGHT} +% \coverrunningfoother{LEFT}{CENTER}{RIGHT} +% or +% \coverfooter{LEFT}{CENTER}{RIGHT} +% which is equivalent to the two commands +% \coverfirstpagefooter{LEFT}{CENTER}{RIGHT} +% \coverrunningfoother{LEFT}{CENTER}{RIGHT} + +\def\coverfirstpageheader#1#2#3{% + \def\cov@lhead{#1}% + \def\cov@chead{#2}% + \def\cov@rhead{#3}% +} + +\def\coverrunningheader#1#2#3{% + \def\covrun@lhead{#1}% + \def\covrun@chead{#2}% + \def\covrun@rhead{#3}% +} + +\def\coverheader#1#2#3{% + \coverfirstpageheader{#1}{#2}{#3}% + \coverrunningheader{#1}{#2}{#3}% +} + +\def\coverfirstpagefooter#1#2#3{% + \def\cov@lfoot{#1}% + \def\cov@cfoot{#2}% + \def\cov@rfoot{#3}% +} + +\def\coverrunningfooter#1#2#3{% + \def\covrun@lfoot{#1}% + \def\covrun@cfoot{#2}% + \def\covrun@rfoot{#3}% +} + +\def\coverfooter#1#2#3{% + \coverfirstpagefooter{#1}{#2}{#3}% + \coverrunningfooter{#1}{#2}{#3}% +} + +\def\coverlhead{\@ifnextchar[{\cov@xlhead}{\cov@ylhead}} +\def\cov@xlhead[#1]#2{\def\cov@lhead{#1}\def\covrun@lhead{#2}} +\def\cov@ylhead#1{\def\covrun@lhead{#1}\def\cov@lhead{#1}} + +\def\coverchead{\@ifnextchar[{\cov@xchead}{\cov@ychead}} +\def\cov@xchead[#1]#2{\def\cov@chead{#1}\def\covrun@chead{#2}} +\def\cov@ychead#1{\def\covrun@chead{#1}\def\cov@chead{#1}} + +\def\coverrhead{\@ifnextchar[{\cov@xrhead}{\cov@yrhead}} +\def\cov@xrhead[#1]#2{\def\cov@rhead{#1}\def\covrun@rhead{#2}} +\def\cov@yrhead#1{\def\covrun@rhead{#1}\def\cov@rhead{#1}} + +\def\coverlfoot{\@ifnextchar[{\cov@xlfoot}{\cov@ylfoot}} +\def\cov@xlfoot[#1]#2{\def\cov@lfoot{#1}\def\covrun@lfoot{#2}} +\def\cov@ylfoot#1{\def\covrun@lfoot{#1}\def\cov@lfoot{#1}} + +\def\covercfoot{\@ifnextchar[{\cov@xcfoot}{\cov@ycfoot}} +\def\cov@xcfoot[#1]#2{\def\cov@cfoot{#1}\def\covrun@cfoot{#2}} +\def\cov@ycfoot#1{\def\covrun@cfoot{#1}\def\cov@cfoot{#1}} + +\def\coverrfoot{\@ifnextchar[{\cov@xrfoot}{\cov@yrfoot}} +\def\cov@xrfoot[#1]#2{\def\cov@rfoot{#1}\def\covrun@rfoot{#2}} +\def\cov@yrfoot#1{\def\covrun@rfoot{#1}\def\cov@rfoot{#1}} + + +% Initialize coverpage head and foot: + +\coverlhead{} +\coverchead{} +\coverrhead{} +\coverlfoot{} +\covercfoot{} +\coverrfoot{} + + + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- + +% Headrules and footrules: + +\newif\if@headrule +\newif\ifrun@headrule + +\def\firstpageheadrule{\@headruletrue} +\def\nofirstpageheadrule{\@headrulefalse} + +\def\runningheadrule{\run@headruletrue} +\def\norunningheadrule{\run@headrulefalse} + +\def\headrule{\@headruletrue\run@headruletrue} +\def\noheadrule{\@headrulefalse\run@headrulefalse} + +\newif\if@footrule +\newif\ifrun@footrule + +\def\firstpagefootrule{\@footruletrue} +\def\nofirstpagefootrule{\@footrulefalse} + +\def\runningfootrule{\run@footruletrue} +\def\norunningfootrule{\run@footrulefalse} + +\def\footrule{\@footruletrue\run@footruletrue} +\def\nofootrule{\@footrulefalse\run@footrulefalse} + +% Initialize: + +\noheadrule +\nofootrule + +% Cover page headrules and footrules: + +\newif\ifcov@headrule +\newif\ifcovrun@headrule + +\def\coverfirstpageheadrule{\cov@headruletrue} +\def\nocoverfirstpageheadrule{\cov@headrulefalse} + +\def\coverrunningheadrule{\covrun@headruletrue} +\def\nocoverrunningheadrule{\covrun@headrulefalse} + +\def\coverheadrule{\cov@headruletrue\covrun@headruletrue} +\def\nocoverheadrule{\cov@headrulefalse\covrun@headrulefalse} + +\newif\ifcov@footrule +\newif\ifcovrun@footrule + +\def\coverfirstpagefootrule{\cov@footruletrue} +\def\nocoverfirstpagefootrule{\cov@footrulefalse} + +\def\coverrunningfootrule{\covrun@footruletrue} +\def\nocoverrunningfootrule{\covrun@footrulefalse} + +\def\coverfootrule{\cov@footruletrue\covrun@footruletrue} +\def\nocoverfootrule{\cov@footrulefalse\covrun@footrulefalse} + +% Initialize: + +\nocoverheadrule +\nocoverfootrule + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- + +% \numpages, \iflastpage, and \oddeven +% Also: \numpoints, \numquestions, \numparts, and \numsubparts +% Also also: \pointsofquestion +% Also: \numcoverpages and \totalnumpages + +% Make the number of pages available as the macro \numpages, +% the number of points as \numpoints, +% the number of questions as \numquestions, +% the number of parts as \numparts, and +% the number of subparts as \numsubparts + +% This was previously done with \pageref commands. When I stopped +% using \pageref for this (in order to make this compatible with +% hyperref.sty), this stuff was created: + +% \gdef commands for exam@lastpage, exam@numpoints, +% exam@numbonuspoints, exam@numquestions, exam@numparts, +% exam@numsubparts and exam@numsubsubparts are written to the .aux +% file via \AtEndDocument. + +% \gdef commands for pointsofq@i, pointsofq@ii, etc. and +% bonuspointsofq@i, bonuspointsofq@ii, etc. are written to the .aux +% file as each question is completed (see the definition of the +% questions environment). + +% \gdef commands for pointsonpage@i, pointsonpage@ii, etc. and +% bonuspointsonpage@i, bonuspointsonpage@ii, etc. are written to the +% .aux file as we encounter points defined for a later page, and for +% the last such page with AtEndDocument. + +\def\numpages{\@ifundefined{exam@lastpage}% + {\mbox{\normalfont\bfseries ??}}% + \exam@lastpage +}% numpages + +% Change 2011/04/01: We added a ``0'' in front of the +% mbox when \exam@lastcoverpage isn't defined. This is +% so that the construction \romannumeral\numcoverpages +% won't generate an error on the first run of latex. +\def\numcoverpages{\@ifundefined{exam@lastcoverpage}% + {0\mbox{\normalfont\bfseries ??}}% + \exam@lastcoverpage +}% numpages + +\def\totalnumpages{\@ifundefined{exam@totalpages}% + {\mbox{\normalfont\bfseries ??}}% + \exam@totalpages +}% numpages + +\def\numpoints{\@ifundefined{exam@numpoints}% + {\mbox{\normalfont\bfseries ??}}% + \exam@numpoints +}% numpoints +\def\numbonuspoints{\@ifundefined{exam@numbonuspoints}% + {\mbox{\normalfont\bfseries ??}}% + \exam@numbonuspoints +}% numbonuspoints + +\def\numquestions{\@ifundefined{exam@numquestions}% + {\mbox{\normalfont\bfseries ??}}% + \exam@numquestions +}% numquestions + +\def\numparts{\@ifundefined{exam@numparts}% + {\mbox{\normalfont\bfseries ??}}% + \exam@numparts +}% numparts + +\def\numsubparts{\@ifundefined{exam@numsubparts}% + {\mbox{\normalfont\bfseries ??}}% + \exam@numsubparts +}% numsubparts + +\def\numsubsubparts{\@ifundefined{exam@numsubsubparts}% + {\mbox{\normalfont\bfseries ??}}% + \exam@numsubsubparts +}% numsubsubparts + +\def\pointsofquestion#1{\@ifundefined{pointsofq@\romannumeral #1}% + {\mbox{\normalfont\bfseries ??}}% + {\csname pointsofq@\romannumeral #1\endcsname}% +}% pointsofquestion +\def\bonuspointsofquestion#1{\@ifundefined{bonuspointsofq@\romannumeral #1}% + {\mbox{\normalfont\bfseries ??}}% + {\csname bonuspointsofq@\romannumeral #1\endcsname}% +}% bonuspointsofquestion + +% For use in \combinedgradetable and \combinedpointtable, we're +% changing the defintions of \pointsonpage and \bonuspointsonpage +% so that when, e.g., pointsonpage@ii is undefined, we just produce +% 0. This comes up because the final page of the exam may have either +% points with no bonus point or bonus points with no points, in which +% case the combined table will try to list both points and bonus points +% for that last page, and one of those will be undefined. +% +% \def\pointsonpage#1{\@ifundefined{pointsonpage@\romannumeral #1}% +% {\mbox{\normalfont\bfseries ??}}% +% {\csname pointsonpage@\romannumeral #1\endcsname}% +% }% pointsonpage +% \def\bonuspointsonpage#1{\@ifundefined{bonuspointsonpage@\romannumeral #1}% +% {\mbox{\normalfont\bfseries ??}}% +% {\csname bonuspointsonpage@\romannumeral #1\endcsname}% +% }% bonuspointsonpage +% +% spanish.ldf redefines \@roman, so we'll avoid using \roman: +\def\pointsonpage#1{\@ifundefined{pointsonpage@\romannumeral #1}% + {0}% + {\csname pointsonpage@\romannumeral #1\endcsname}% +}% pointsonpage +\def\bonuspointsonpage#1{\@ifundefined{bonuspointsonpage@\romannumeral #1}% + {0}% + {\csname bonuspointsonpage@\romannumeral #1\endcsname}% +}% bonuspointsonpage + + +\newif\if@pointschanged +\@pointschangedfalse + +\newcommand*{\CheckIfChanged@hlf}[2]{% + % The first argument is the name of a half counter. + % The second argument expands to the name (without the escape + % character, and not assumed to be defined) of the control sequence + % holding the previous value. + \@ifundefined{#2}% + {\global\@pointschangedtrue}% + {% + % OK; it's defined. See if it's changed: + \begingroup + \set@hlfcntr{tmp@hlfcntr}{\csname #2\endcsname}% + \edef\othpt@check{\prtaux@hlfcntr{tmp@hlfcntr}}% + \edef\pt@check{\prtaux@hlfcntr{#1}}% + \ifx \pt@check \othpt@check + % Do nothing + \else + \global\@pointschangedtrue + \fi + \endgroup + }% +}% CheckIfChanged@hlf + + +%%%\let\@realenddocument=\enddocument +%%%\def\enddocument{\clearpage +%%% \if@filesw +%%% {\advance\c@page-1 \immediate\write\@mainaux +%%% {\string\newlabel{@lastpage}{{}{\arabic{page}}}}% +%%% } +%%% \fi +%%% \@realenddocument +%%%} + +\AtEndDocument{% + \clearpage + \if@filesw + \advance\c@page-1 + \immediate\write\@mainaux + {\string\gdef\string\exam@lastpage{\arabic{page}}}% + \immediate\write\@mainaux + {\string\gdef\string\exam@lastcoverpage{\arabic{num@coverpages}}}% + % We can now trash the value of num@coverpages: + \addtocounter{num@coverpages}{\value{page}}% + \immediate\write\@mainaux + {\string\gdef\string\exam@totalpages{\arabic{num@coverpages}}}% + \advance\c@page+1 % In case some other package looks at \c@page + % + \immediate\write\@mainaux + {\string\gdef\string\exam@numpoints{% + \prtaux@hlfcntr{numpoints}}}% + % See if this has changed from the last run of LaTeX: + \CheckIfChanged@hlf{numpoints}{exam@numpoints}% + \immediate\write\@mainaux + {\string\gdef\string\exam@numbonuspoints{% + \prtaux@hlfcntr{numbonuspoints}}}% + % See if this has changed from the last run of LaTeX: + \CheckIfChanged@hlf{numbonuspoints}{exam@numbonuspoints}% + \immediate\write\@mainaux + {\string\gdef\string\exam@numquestions{\thenumquestions}}% + \immediate\write\@mainaux + {\string\gdef\string\exam@numparts{\thenumparts}}% + \immediate\write\@mainaux + {\string\gdef\string\exam@numsubparts{\thenumsubparts}}% + \immediate\write\@mainaux + {\string\gdef\string\exam@numsubsubparts{\thenumsubsubparts}}% + \ifnum \thepageof@pagepoints > 0\relax + \immediate\write\@mainaux + {\string\gdef\string\pointsonpage@\romannumeral + \csname c@pageof@pagepoints\endcsname + {\prtaux@hlfcntr{@pagepoints}}}% + % See if this has changed from the last run of LaTeX: + \CheckIfChanged@hlf{@pagepoints}{pointsonpage@\romannumeral + \csname c@pageof@pagepoints\endcsname}% + \fi + \ifnum \thepageof@pagebonuspoints > 0\relax + \immediate\write\@mainaux + {\string\gdef\string\bonuspointsonpage@\romannumeral + \csname c@pageof@pagebonuspoints\endcsname + {\prtaux@hlfcntr{@pagebonuspoints}}}% + \CheckIfChanged@hlf{@pagebonuspoints}{bonuspointsonpage@\romannumeral + \csname c@pageof@pagebonuspoints\endcsname}% + \fi + \immediate\write\@mainaux + {\string\gdef\string\lastpage@withpoints{\page@withpoints}}% + % See if this has changed from the last run of LaTeX: + \@ifundefined{lastpage@withpoints}% + {\global\@pointschangedtrue}% + {% + % OK; it's defined. See if it's changed: + \begingroup + \edef\othpt@check{\page@withpoints}% + \edef\pt@check{\lastpage@withpoints}% + \ifx \pt@check \othpt@check + % Do nothing + \else + \global\@pointschangedtrue + \fi + \endgroup + }% + \immediate\write\@mainaux + {\string\gdef\string\lastpage@withbonuspoints{\page@withbonuspoints}}% + % See if this has changed from the last run of LaTeX: + \@ifundefined{lastpage@withbonuspoints}% + {\global\@pointschangedtrue}% + {% + % OK; it's defined. See if it's changed: + \begingroup + \edef\othpt@check{\page@withbonuspoints}% + \edef\pt@check{\lastpage@withbonuspoints}% + \ifx \pt@check \othpt@check + % Do nothing + \else + \global\@pointschangedtrue + \fi + \endgroup + }% + \fi + % Echo numbers of questions, parts, and subparts: + \typeout{This exam contains \thenumquestions\space questions + with \thenumparts\space parts, \thenumsubparts\space subparts, + and \thenumsubsubparts\space subsubparts.} + % If counting points, echo total points: + \if@printtotalpoints + \begingroup + \def\typ@expnd{% + \thenumpoints + \ifnumpoints@half + \space and a half% + \fi + } + \typeout{This exam has a total of \typ@expnd\space points.} + \def\typ@expnd{% + \thenumbonuspoints + \ifnumbonuspoints@half + \space and a half% + \fi + } + \typeout{This exam has a total of \typ@expnd\space bonus points.} + \endgroup + \fi + \if@pointschanged + \ClassWarningNoLine{exam}{Point totals have changed. + Rerun to get point totals right}% + \fi +}% AtEndDocument + + +% We define \iflastpage so that it can safely be used +% in headers and footers: +\def\iflastpage#1#2{% + \@ifundefined{exam@lastpage}{\def\@@lastpage{-1}}% + {\edef\@@lastpage{\exam@lastpage}}% + \ifnum\value{page}=\@@lastpage\relax + #1% + \else + #2% + \fi +}% iflastpage + + +% The macro \oddeven takes two arguments. If the page number is odd, +% then you get the first argument; otherwise, you get the second +% argument. +\def\oddeven#1#2{% + \ifodd\value{page}% + #1% + \else + #2% + \fi +}% oddeven + + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% \ifcontinuation, \ContinuedQuestion, +% \ifincomplete, and \IncompleteQuestion + +% The commands \ifcontinuation, \ContinuedQuestion, \ifincomplete, and +% \IncompleteQuestion assume that there is only one questions +% environment in the entire document. (Actually, \ContinuedQuestion +% should work even if there are multiple questions environments, but +% none of the other three will work in general.) + + + +% \PgInfo@write, \PgInfo and \PgInfo@get are our replacements +% for \label, \newlabel, and \pageref. (We're avoiding using +% \label, \newlabel, and \pageref so that we will be compatible +% with hyperref.sty, which redefines those commands.) + +% We use \PgInfo, \PgInfo@write, and \PgInfo@get to know on which page +% each question, part, subpart, subsubpart, and choice appears. + +% We use \PgInfo@write to write \PgInfo commands to the .aux file. The +% \PgInfo command takes two arguments: A question (or part, or subpart, +% or subsubpart) label, and the number of the page on which it appears. + +% The label for a question is of the form `question@2' (if it's question +% 2). + +% The label for a part is of the form `part@2@1' (if it's part a of +% question 2). + +% The label for a subpart is of the form `subpart@2@1@3' (if it's +% subpart iii of part a of question 2). + +% The label for a subsubpart is of the form `subsubpart@2@1@3@4' (if +% it's subsubpart $\delta$ of subpart iii of part a of question 2). + +% Each question, part, subpart, subsubpart, and choice also gets a +% \PgInfo@write command using a label of the form question2@object3 (if +% it's the third object of the second question). + +% Inside one of the solution environments (solution, solutionorbox, +% etc.) each part, subpart, subsubpart, and choice get only the +% \PgInfo@write command using a label of the form question2@object3 +% (if it's the third object of the second question). + +% When read in from the .aux file, the \PgInfo command defines a +% control sequence of the form `Pg@label' that expands to the page +% number for the corresponding question. For example, +% \PgInfo{subsubpart@2@1@3@4}{7} defines \csname +% Pg@subsubpart@2@1@3@4\endcsname to expand to 7. + +% The \PgInfo@get{label} command returns the value of the macro Pg@label, +% but it *doesn't* check whether that macro is defined. Thus, it's +% important to check that the macro Pg@label is defined before giving the +% command \PgInfo@get{label}. + + + +% The token list to a \write command isn't expanded until +% it's shipped out. Since the argument to PgInfo@write +% generally contains macros, we want to expand those macros +% now, rather than waiting until this is shipped out, at which +% point the macros may have different values. Thus, we use +% \edef to force expansion of the argument, and we put +% a \noexpand in front of \thepage so that the \thepage +% will not be expanded now. (This may not get shipped out +% until a later page, and so we want the \thepage to be expanded +% only when it's shipped out.) +% We use the \begingroup \endgroup pair so that our use +% of \reserved@a won't affect its use anywhere else. +\def\PgInfo@write#1{% + \begingroup + \edef\reserved@a{\write\@mainaux + {\string\PgInfo{#1}{\noexpand\thepage}}}% + \reserved@a + \endgroup +} + +%\PgInfo commands are written to the .aux file by the \PgInfo@write +%command; that's the only place that \PgInfo commands appear. +\def\PgInfo#1#2{\expandafter\gdef\csname Pg@#1\endcsname{#2}} + +% Note: PgInfo@get assumes that the control sequence being +% constructed is already defined; you have to make sure of this +% *before* calling \Pginfo@get +\def\PgInfo@get#1{\csname Pg@#1\endcsname} + +% \set@counter@to@pageof takes two arguments: The first is the name of a +% counter, and the second (expands to) the label of a question, part, +% subpart, subsubpart, or choice. If that label exists, then we set the +% counter equal to the page on which the question (or part, etc.) +% appears. If that label doesn't exist, we set the counter equal to -1. +% (No labels exist on the first run of LaTeX on the file, and if a new +% question (or part, etc.) was created by editing the file, then the +% label will not exist until the run of LaTeX after that.) +\def\set@counter@to@pageof#1#2{% + \@ifundefined{Pg@#2}% + {\setcounter{#1}{-1}}% + {\setcounter{#1}{\csname Pg@#2\endcsname}}% +} + + +%-------------------------------------------------------------------- + +% \ifcontinuation#1#2 expands to #2 if either: +% (1) The command \noquestionsonthispage has been given on this page, +% or +% (2) The current page is before the page containing question number +% 1, or +% (3) A question begins on this page before any part, subpart, +% subsubpart, or choice begins, or +% (4) The current page is later than a page with the \nomorequestions +% command. +% Otherwise, it expands to #1. +% +% Thus, for example, if there are no questions, parts, subparts, +% subsubparts, or choices on this page, and no \noquestionsonthispage +% command, and we're not before question 1, and not after a +% \nomorequestions command, then \ifcontinuation will expand to #1. + + +\def\ifcontinuation#1#2{% + % If there's a \noquestionsonthispage command on this page, then + % we assume that we're not continuing anything: + \@ifundefined{No@Questions@Pg@\thepage}% + {\chk@contin{#1}{#2}}% + {#2}% +}% \ifcontinuation + +\def\chk@contin#1#2{% + % We check whether we're on a page *before* the page on which the + % first question appears. If we don't yet know which page has + % question number 1, then we must be doing an early run of LaTeX, + % and we'll assume we're not a continuation. + \expandafter\ifx\csname Pg@question@1\endcsname\relax + % No page info yet; assume not a continuation + #2% + \else + % Note: The ``\relax'' at the end of the following \ifnum + % serves an entirely different purpose from the one at the + % end of the above \expandafter\ifx. That one (above) + % is one of the things being compared, whereas the + % one we're about to use is just to clearly mark the + % end of the second number being compared by the \ifnum + % (since it's conceivable that the ``#2'' would begin + % with a digit). + \ifnum \thepage < \csname Pg@question@1\endcsname\relax + % We're before the page with question 1: + #2% + \else + % The current page begins a new question if Contin@\thepage + % has been defined as a macro that expands to \relax (Note + % that this is different from if Contin@\thepage has never + % been defined at all, in which case it will be let equal to + % \relax (temporarily) by the \csname command.) + \expandafter\ifx\csname Contin@\thepage\endcsname\ref@relax + #2% + \else + % See if we're after a \nomorequestions command: + \@ifundefined{Pg@@endquestions}% + {#1}% + {\ifnum \thepage > \PgInfo@get{@endquestions}\relax + % We're after a \nomorequestions: + #2% + \else + % We actually are incomplete: + #1% + \fi + }% + \fi + \fi + \fi +}% chk@contin + +\def\nomorequestions{% + \PgInfo@write{@endquestions}% +}% nomorequestions + +\def\noquestionsonthispage{% + \write\@mainaux{\string\expandafter\string\gdef + \string\csname\space No@Questions@Pg@\thepage\string\endcsname + {No questions here}}% +}% noquestionsonthispage + + +%-------------------------------------------------------------------- +% \ContinuedQuestion is for use in headers and footers, where we can +% assume that \thepage is the number of the page on which we'll +% actually appear. + +% \ContinuedQuestion expands to the number of the question that +% continues onto this page, or to -1 if this page begins with a new +% question. + +% ACTUALLY: \ContinuedQuestion expands to a positive number if either +% (1) this page doesn't contain the beginning of any question, part, +% subpart, subsubpart, or choice, or (2) this page has a part, subpart, +% subsubpart, or choice that appears before any question. That means +% that if the current page actually begins with space for a continuation +% of the previous question (but doesn't begin any part, subpart, +% subsubpart, or choice of that question) and then has a question, then +% we'll be asserting that this page begins with a new question, but the +% actual top of the page will begin with some blank space that's +% intended for the previous question. + +% \ContinuedQuestion works by examining the value of the macro +% Contin@\thepage. If this page starts with a question (i.e., if no +% question continues onto this page), then the macro Contin@\thepage +% will be defined, and will expand to `\relax' (and so an \ifx between +% \csname Contin@\thepage\endcsname and \ref@relax will be true). + +% If Contin@\thepage is undefined, then when it is used in an \ifx +% command it will be temporarily set equal to \relax (which is +% *different* from being a macro that expands to \relax); in this case, +% there is no question, part, subpart, subsubpart, or choice that begins +% on this page, and so \ContinuedQuestion will be set equal to the last +% question that was begun on a page before this one. + +% The last possibility is that this page begins with either a part, +% subpart, subsubpart, or choice. In this case, Contin@\thepage is +% defined, and it expands to the number of the question that is +% continued onto this page. + + +\def\ref@relax{\relax} + +\def\ContinuedQuestion{% + \expandafter\ifx\csname Contin@\thepage\endcsname\relax + % We get here if there's no question, part, subpart, + % subsubpart, or choice on this page, and so Contin@\thepage has + % never been defined at all. In that case, this page + % continues whichever question was last begun on or + % before this page. + \find@latestques + \thelatest@ques + \else + \expandafter\ifx\csname Contin@\thepage\endcsname\ref@relax + % We get here if this page begins with a new question, + % which is why Contin@\thepage has been defined to be + % a macro that expands to \relax. + % ACTUALLY: We get here if this page has a question that + % appears before any part, subpart, subsubpart, or choice. That + % means that if the current page actually begins with space + % for a continuation of the previous question but doesn't begin + % any part, subpart, subsubpart, or choice of that question, then + % we'll be asserting that this page begins with a new question, + % but the actual top of the page will begin with some space + % that's intended for the previous question. + -1\relax + \else + % We get here if we didn't get anywhere above. This happens + % if Contin@\thepage has been defined to be a macro that expands + % to something other than \relax, in which case it has been + % defined to be a macro that expands to the number of the + % question that continues onto this page. + \csname Contin@\thepage\endcsname + \fi + \fi +} + +%-------------------------------------------------------------------- +% \find@latestques is for use in headers and footers, where we can +% assume that \thepage actually equals the page on which we'll appear. +% We find the last question that was started on or before the current +% page. + +\newcounter{latest@ques} + +\newcommand\find@latestques{% + % \find@latestques is for use in headers and footers. + % \find@latestques will set the counter latest@ques + % to the number of the last question + % that was begun on the exam from page 1 through the current + % page. This may well be the value of the question counter, + % but it may be less than that if the page following this one + % begins a new question and that question beginning was + % typeset before the present page was shipped out. + % Note: This macro is called both by \ContinuedQuestion and by + % \find@quesend, which is why it has to find the last question + % begun on or before the current page, rather than just before + % the current page. + \ifnum 1 > \value{question}\relax + % Oops; probably because we're before the first question + % Just set latest@ques to -1: + \setcounter{latest@ques}{-1}% + \else + % If question latest@ques actually begins on this page (rather + % than on the next page, but early enough on the next page + % that the counter was advanced before we ran off into the + % output routine to output the page and set the header and + % footer), then that's the correct question number. + \expandafter\ifx\csname Pg@question@\arabic{question}\endcsname\relax + % We don't know what page that question is on; + % this must be an early run, before the aux file + % is helpful. Just set it equal to -1 and wait until the next + % run to get it right. + \setcounter{latest@ques}{-1}% + \else + % We now know that \PgInfo@get can tell us the page number + % of \arabic{question} and of all earlier questions. + % Set latest@ques equal to the current question number, and + % then call \decr@latest@ques to recursively decrement + % latest@ques as needed to find a question that begins on + % or before the current page: + \setcounter{latest@ques}{\value{question}}% + \decr@latest@ques + \fi + \fi +} + +\def\decr@latest@ques{% + % If we get here, then we've already checked that the reference + % Pg@question@\thelatest@ques is defined at least for a value of + % \thelatest@ques greater than or equal to it's present value, + % so we assume it's defined for all lesser values as well: + \ifnum \thepage < \PgInfo@get{question@\thelatest@ques}\relax + % Nope; latest@ques starts on a later page + % Decrement latest@ques and see if that one's right: + \addtocounter{latest@ques}{-1}% + \ifnum \thelatest@ques < 1\relax + \setcounter{latest@ques}{-1}% + \let\next@dlq=\relax + \else + \let\next@dlq=\decr@latest@ques + \fi + \else + % latest@ques starts on this page or earlier, so + % that's the correct question number! Exit: + \let\next@dlq=\relax + \fi + \next@dlq +} + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +\newcounter{ques@end} +\newcounter{last@object} + +\def\find@quesend{% + % We find the last question started on or before the current page + % and then find the page containing the last part (or subpart, or + % subsubpart, or choice) of that question, and set the counter + % ques@end to that page number. + % Set latest@ques equal to the correct question number: + \find@latestques + \ifnum \value{latest@ques} < 0\relax + % This must be an early run of LaTeX, before we have + % \PgInfo commands in the .aux file: + \setcounter{ques@end}{-1}% + \else + % We now know that this question has at least one object (since + % we know that latest@ques isn't negative). + % We'll find its highest numbered object by setting last@object + % equal to 2 and then calling \find@lastobject to recursively + % test whether that object number exists and, if so, incrementing + % last@object to test for a higher numbered one: + \setcounter{last@object}{2}% + \find@lastobject + \setcounter{ques@end}{\PgInfo@get{question\thelatest@ques + @object\thelast@object}}% + \fi +}% find@quesend + +\def\find@lastobject{% + % We check whether this question has an object numbered last@object + % and recursively increment last@object to find the highest + % numbered value for which the object exists: + \@ifundefined{Pg@question\thelatest@ques @object\thelast@object}% + {\addtocounter{last@object}{-1}% + \let\nextfind@lastobject=\relax + }% + {\addtocounter{last@object}{1}% + \let\nextfind@lastobject=\find@lastobject + }% + \nextfind@lastobject +}% find@lastobject + + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- + +\newcounter{incmp@ques} + +\def\IncompleteQuestion{% + \Find@Incmp@ques + % If there's no incomplete question, the counter incmp@ques will be + % set to -1: + \theincmp@ques +} + +\def\Find@Incmp@ques{% + % If we're on the last page, then there's no incomplete question: + \iflastpage{\setcounter{incmp@ques}{-1}}{\chk@incomp}% +}% Find@Incmp@ques +\newcounter{next@ques} +\newcounter{next@page} + +\def\chk@incomp{% + % If we get here, we're not on the last page. + % \find@quesend calls \find@latestques to set the counter + % latest@ques equal to the number of the last question begun on or + % before the current page, and then it sets the counter ques@end to + % the page containing the last ques@object of that question: + \find@quesend + \ifnum \theques@end > \thepage\relax + % This question has a part (or sub...) starting on a later page + \setcounter{incmp@ques}{\value{latest@ques}}% + \else + \chk@incompi + \fi +}% chk@incomp + +\def\chk@incompi{% + % If there are any pages after the current one and before the next + % question (if there is a next question) that lack a + % \noquestionsonthispage and that aren't following the page of a + % \nomorequestions command, then question latest@ques is incomplete. + % Otherwise, there is no incomplete question: + \setcounter{next@ques}{\thelatest@ques}% + \addtocounter{next@ques}{1}% + % We use next@page as a scratch counter. We start by setting it + % to the last page we want to check for a \noquestionsonthispage + % command: + \expandafter\ifx\csname Pg@question@\thenext@ques \endcsname\relax + % This isn't the last page but there is no next question: +% + \@ifundefined{exam@lastpage}% + {\setcounter{next@page}{-1}}% + {\setcounter{next@page}{\exam@lastpage}}% +% +% \setcounter{next@page}{\exam@lastpage}% + \else + \setcounter{next@page}{\PgInfo@get{question@\thenext@ques}}% + \addtocounter{next@page}{-1}% + \fi + % See if that's after a \nomorequestions command: + \@ifundefined{Pg@@endquestions}% + {}% + {\ifnum \PgInfo@get{@endquestions} < \value{next@page}\relax + \setcounter{next@page}{\PgInfo@get{@endquestions}}% + \fi + }% + % OK, the counter next@page now contains the last page to check. + \chk@incompii +}% chk@incompi + +\def\chk@incompii{% + \ifnum \value{next@page} > \value{page}\relax + % We need to check the page next@page: + \@ifundefined{No@Questions@Pg@\arabic{next@page}}% + {\setcounter{incmp@ques}{\value{latest@ques}}% + \let\next@incompii=\relax + }% + {\addtocounter{next@page}{-1}% + \let\next@incompii = \chk@incompii + }% + \else + % There's no incomplete question: + \setcounter{incmp@ques}{-1}% + \let\next@incompii=\relax + \fi + \next@incompii +}% chk@incompii + +\def\ifincomplete#1#2{% + % We need to pass the arguments to \chk@ifincomp; we save them in + % macros so they won't be messed up by the call to \Find@Incmp@ques: + \def\incomp@first{#1}% + \def\incomp@second{#2}% + % If there's a \noquestionsonthispage command on this page, then + % we assume nothing from this page is incomplete: + \@ifundefined{No@Questions@Pg@\thepage}% + {\chk@ifincomp}% + {\incomp@second}% +}% ifincomplete + +\def\chk@ifincomp{% + \Find@Incmp@ques + % If there's no incomplete question, \Find@Incmp@ques sets the + % counter incmp@ques to -1: + \ifnum \theincmp@ques < 0\relax + \incomp@second + \else + % Are we after a page with \nomorequestions? + \@ifundefined{Pg@@endquestions}% + {\incomp@first}% + {\ifnum \thepage < \PgInfo@get{@endquestions}\relax + \incomp@first + \else + \incomp@second + \fi + }% + \fi +}% chk@ifincomp + +%-------------------------------------------------------------------- +% These are the commands for dealing with hlfcntr's, i.e., the things +% used to count points. +% +% A point value is a nonnegative integer with an optional half integer. +% A hlfcntr consists of a regular counter together with an \if: If the +% regular counter is called ``counter'', then the \if is called +% ``\ifcounter@half''; it's set true by ``\counter@halftrue'' and set +% false by ``\counter@halffalse''. +% +% The commands: +% +% \new@hlfcntr{countername} +% \set@hlfcntr{countername}{value} +% \copy@hlfcntr{tocounter}{fromcounter} +% \addto@hlfcntr{countername}{value} +% \add@hlfcntrtohlfcntr{getsaddedto}{whatsadded} +% \ifhlfcntr@pos{countername} +% \prtaux@hlfcntr{countername} +% \prt@hlfcntr{countername} +% +% ``value'' can be either a (nonnegative) integer, an integer followed by +% ``\half'', or just plain ``\half''. (Actually, ``value'' can be empty +% (although the braces must be present), in which case it's interpreted +% as ``0''.) +% +% Examples of valid values: +% 0 +% 0\half +% 1 +% 1\half +% 2 +% 2\half +% etc. + +% Note on using ``\global'': LaTeX's \setcounter and \addtocounter +% commands are already \global (i.e., you don't have to say +% ``\global''), but \somethingtrue and \somethingfalse (used to set +% \ifsomething) aren't. Thus, we need to say ``\global'' when setting +% these things. + +% To create a hlfcntr: +\newcommand*\new@hlfcntr[1]{% + \newcounter{#1}% + \expandafter\newif\csname if#1@half\endcsname +}% new@hlfcntr + + +% A scratch hlfcntr: +\new@hlfcntr{tmp@hlfcntr} + +\newcommand*\horiz@half{$\frac{1}{2}$} +\newcommand*\slanted@half{% + $\raise0.6ex\hbox{$\scriptstyle 1$}\kern -.2em/\kern -.2em + \raise-0.5ex\hbox{$\scriptstyle 2$}$% +}% slanted@half +\newcommand*\useslantedhalf{\global\let\half\slanted@half} +\newcommand*\usehorizontalhalf{\global\let\half\horiz@half} +\newcommand*\half{\slanted@half} + + +\newcommand*\set@hlfcntr[2]{% + \begingroup + \global\csname #1@halffalse\endcsname + % If there as a `\half' present, it will be executed + % right after the assignment of the digit part of #2 + % to the counter #1. + \def\half{% + \global\csname #1@halftrue\endcsname + }% + % We insert a `0' in case there are no digits present: + % We avoid using \setcounter, because calc.sty redefines + % \setcounter in a way that conflicts with the \half trick + % we're using: + % \setcounter{#1}{0#2}\relax + \global\csname c@#1\endcsname 0#2\relax + \endgroup +}% set@hlfcntr + +\newcommand*\copy@hlfcntr[2]{% + % We set #1 to the value of #2 + \setcounter{#1}{\value{#2}}% + \csname if#2@half\endcsname + \global\csname #1@halftrue\endcsname + \else + \global\csname #1@halffalse\endcsname + \fi +}% copy@hlfcntr + +\newcommand*\addto@hlfcntr[2]{% + % We add the valueandhalf #2 to hlfcntr #1 + \begingroup + \def\half{\add@half{#1}}% + % We insert a `0' in case there are no digits present: + % We avoid using \addtocounter, because calc.sty redefines + % \addtocounter in a way that conflicts with the \half trick + % we're using: + % \addtocounter{#1}{0#2}\relax + \global\advance\csname c@#1\endcsname 0#2\relax + \endgroup +}% addto@hlfcntr + +\newcommand*\add@hlfcntrtohlfcntr[2]{% + % We add the hlfcntr #2 to the hlfcntr #1 + \addtocounter{#1}{\value{#2}}% + \csname if#2@half\endcsname + \add@half{#1}% + \fi +}% add@hlfcntrtohlfcntr + +\newcommand*\add@half[1]{% + % We add one half to hlfcntr #1: + \csname if#1@half\endcsname + \addtocounter{#1}{1}% + \global\csname #1@halffalse\endcsname + \else + \global\csname #1@halftrue\endcsname + \fi +}% add@half + +% Important reminder about \ifhlfcntr@pos: Do not use it inside +% another conditional! The construction +% \ifhlfcntr@pos{somecounter} +% do some stuff... +% \fi +% is perfectly fine as long as it's expanded, but: If it's inside +% another conditional, and the condition is not satisfied, then it's +% read through without expansion. In that case, TeX sees the +% \ifhlfcntr@pos but does *not* recognize it as being part of a +% conditional, but when it sees the concluding \fi it does recognize +% that, and so TeX completes the outer conditional at that \fi, which +% causes an error. +\newcounter{ifpos@cntr} +\def\ifhlfcntr@pos#1{% + % The argument must be a hlfcntr (which, of course, + % can never be negative); we'll be true if and only if + % that halfcntr is positive: + \setcounter{ifpos@cntr}{\value{#1}}% + \csname if#1@half\endcsname + \addtocounter{ifpos@cntr}{1}% + \fi + \ifnum \value{ifpos@cntr} > 0\relax +}% ifhlfnctr@pos + +% \prtaux@hlfcntr is used inside the argument of a \write command for +% writing to the .aux file: +\newcommand*\prtaux@hlfcntr[1]{% + % We don't want a \relax after the 0 in the following + % line, because it would sometimes appear in the aux file: + \ifnum \value{#1} = 0 + % We have to make the following a macro, because if we + % don't do this part, the \fi will cause confusion, since + % there's no \if visible until the \csname is expanded: + \prtaux@halforzero{#1}% + \else + \arabic{#1}% + % We have to make the following a macro, because if we + % don't do this part, the \fi will cause confusion, since + % there's no \if visible until the \csname is expanded: + \prtaux@halforblank{#1}% + \fi +}% prtaux@hlfcntr +\newcommand*\prtaux@halforzero[1]{% + \csname if#1@half\endcsname + \string\half + \else + 0% + \fi +}% prtaux@hlforzero +\newcommand*\prtaux@halforblank[1]{% + \csname if#1@half\endcsname + \string\half + \fi +}% prtaux@halforblank + +\newcommand*\prt@hlfcntr[1]{% + % We don't want a \relax after the 0 in the following + % line, because it would sometimes appear in the aux file: + \ifnum \value{#1} = 0 + % We have to make the following a macro, because if we + % don't do this part, the \fi will cause confusion, since + % there's no \if visible until the \csname is expanded: + \prt@halforzero{#1}% + \else + \arabic{#1}% + % We have to make the following a macro, because if we + % don't do this part, the \fi will cause confusion, since + % there's no \if visible until the \csname is expanded: + \prt@halforblank{#1}% + \fi +}% prt@hlfcntr +\newcommand*\prt@halforzero[1]{% + \csname if#1@half\endcsname + \half + \else + 0% + \fi +}% prt@hlforzero +\newcommand*\prt@halforblank[1]{% + \csname if#1@half\endcsname + \half + \fi +}% prt@halforblank + +% End of the commands for dealing with hlfcntr's + +%-------------------------------------------------------------------- +%--------------------------------------------------------------------- +% +% *************************** +% ** QUESTION ENVIRONMENTS ** +% *************************** +% +% +% + +% We define the command \part only inside of a parts environment, so +% that we don't interfere with the meaning of the standard article +% documentclass command \part if that is used inside of a questions +% environment. The commands \question, \subpart, and \subsubpart are +% defined everywhere inside of a questions environment. If the user +% accidentally gives a \subpart command outside of a subparts +% environment, then an error will be created. + + + + +% We use the counter name `partno' for the parts environment so that +% we will not interfere with the counter `part' used by the article +% document class. + +\newcounter{question} +\newcounter{partno} +\newcounter{subpart} +\newcounter{subsubpart} +\newcounter{choice} +\new@hlfcntr{numpoints} +\set@hlfcntr{numpoints}{0} +\new@hlfcntr{numbonuspoints} +\set@hlfcntr{numbonuspoints}{0} +\new@hlfcntr{pointsof@thisquestion} +\set@hlfcntr{pointsof@thisquestion}{0} +\new@hlfcntr{bonuspointsof@thisquestion} +\set@hlfcntr{bonuspointsof@thisquestion}{0} +\newcounter{numquestions} +\newcounter{numparts} +\newcounter{numsubparts} +\newcounter{numsubsubparts} +\newcounter{Curr@Page} + +% @pagepoints accumulates the points on a single page: +\new@hlfcntr{@pagepoints} +\set@hlfcntr{@pagepoints}{0} +\new@hlfcntr{@pagebonuspoints} +\set@hlfcntr{@pagebonuspoints}{0} +\newcounter{pageof@pagepoints} +\setcounter{pageof@pagepoints}{0} +\newcounter{pageof@pagebonuspoints} +\setcounter{pageof@pagebonuspoints}{0} + +% latest@points is a holding area for points until we know +% whether they'll land on the same page as the points +% currently counted in @pagepoints: +\new@hlfcntr{latest@points} +\set@hlfcntr{latest@points}{0} +\new@hlfcntr{latest@bonuspoints} +\set@hlfcntr{latest@bonuspoints}{0} + +% Whenever we meet a new page on which points are defined, we'll +% redefine \page@withpoints to expand to that page. At the end of the +% document, it will hold the last page that has points, and we'll write +% a \gdef\lastpage@withpoints command to the .aux file. +% We initialize \page@withpoints here: +\def\page@withpoints{0}% +\def\page@withbonuspoints{0}% + +% \pageinfo@commands is used by each question, part, subpart, and +% subsubpart to insert into everypar the \PgInfo@write command to put +% its page number into the .aux file, the \PgInfo@get command to read +% the page number into the counter Curr@Page, and to test and set +% \Contin@\theCurr@Page. \temp@toks is used by part, subpart, and +% subsubpart to append all that to \pageinfo@commands, rather than +% deleting whatever may have been put into \pageinfo@commands by the +% current question and/or part and/or subpart. +\newtoks\pageinfo@commands +\newtoks\temp@toks + +% \pagepoint@commands holds the commands to manage the counting of the +% number of points defined on each page. +\newtoks\pagepoint@commands + +% \point@toks holds the commands to print the points at the proper +% location on the page (except that it's not used by the \qformat +% option). +\newtoks\point@toks + +% We'll use \greeknum to number subsubparts +\def\greeknum#1{\expandafter\lc@greek\csname c@#1\endcsname} +\def\lc@greek#1{% + \ifcase #1\or $\alpha$\or $\beta$\or $\gamma$\or $\delta$\or + $\epsilon$\or $\zeta$\or $\eta$\or $\theta$\or $\iota$\or + $\kappa$\or $\lambda$\or $\mu$\or $\nu$\or $\xi$\or o\or $\pi$\or + $\rho$\or $\sigma$\or $\tau$\or $\upsilon$\or $\phi$\or $\chi$\or + $\psi$\or $\omega$\else \@ctrerr + \fi +}% lc@greek + + +% The following macros are a variation on a trick from Victor +% Eijkhout's ``TeX by Topic'', page 142: +% Both \prepend@toklist and \append@toklist take two arguments, +% both of which should be token lists. +% \prepend@toklist prepends #2 to #1 +% \append@toklist appends #2 to #1 + +\def\prepend@toklist#1#2{% + \edef\do@it{\noexpand#1={\the#2\the#1}}% + \do@it +}% prepend@toklist + +\def\append@toklist#1#2{% + \edef\do@it{\noexpand#1={\the#1\the#2}}% + \do@it +}% append@toklist + + +% The command \qformat is provided for the user who wants to +% design a nonstandard question line. If this command is used, +% then the usual line containing the question number and the beginning +% of the question will be replaced by the line specified by the +% \qformat command, and the question will begin on the following +% line. +% Within the argument of the \qformat command: +% \thequestion will be replaced by the question number, and +% \thepoints will be replaced by ``\@points \@pointname'' if the +% number of points has been specified for this question, and otherwise +% it inserts nothing at all. (The conditional @placepoints is used to +% determine if there were points specified for this question.) +% The argument to the \qformat command *must* contain some +% stretch, i.e., at least one \hfil or \dotfill or ... +% +% The command \noqformat cancels the effect of \qformat and returns us +% to the default situation. +% +% The commands \bonusqformat and \nobonusformat are analogous. +\newif\if@qformat +\@qformatfalse +\newif\if@bonusqformat +\@bonusqformatfalse + +\def\qformat#1{% + \global\@qformattrue + \gdef\@questionformat{#1}% +}% qformat +\def\bonusqformat#1{% + \global\@bonusqformattrue + \gdef\@bonusquestionformat{#1}% +}% bonusqformat + +\newcommand\noqformat{% + \global\@qformatfalse +}% noqformat +\newcommand\nobonusqformat{% + \global\@bonusqformatfalse +}% nobonusqformat + + +% \thepoints is for use in either a \qformat command +% or a \pointformat command (or a \bonusqformat command). +% It needs to have the +% \if@placepoints so that if it's used in a \qformat command +% it won't print anything if there are no points: +\newcommand\thepoints{% + \if@placepoints + \if@bonus + \@points \@bonuspointname + \else + \@points \@pointname + \fi + \fi +}% thepoints + +% \themarginpoints is for use only in a \pointformat command, +% and so it doesn't need the \if@placepoints bit in \thepoints: +\newcommand\themarginpoints{% + \if@bonus + \@points \@marginbonuspointname + \else + \@points \@marginpointname + \fi +}% themarginpoints + +% We define the \subpart and \subsubpart commands when we enter a +% questions environment (rather than waiting until we enter a subparts +% of subsubparts environment) so that we can signal an error if a +% \subpart or \subsubpart command appears outside of the corresponding +% environment. (We don't do this for the \part command so that the user +% can use the standard sectioning \part command outside of a parts +% environment.) + +% The counter ques@object will count the items in each question, where +% an item is defined as either the question itself, or a part, or a +% subpart, or a subsubpart, or a choice. This will be used by +% \find@quesend to find the last page occupied by the last question +% begun on or before the current page: +\newcounter{ques@object} + +% \first@questionobject will be used by the \question command. +% That is, it will be used only once, but we want to keep its +% definition here, near the definitions of \addquestionobject and +% \questionobject@pluspagecheck. +\newcommand{\first@questionobject}{% + \setcounter{ques@object}{1}% + % \PgInfo@write expands it's argument, so we don't need edef: +% \edef\q@object@label{% +% question\arabic{question}@object\arabic{ques@object}}% +% \PgInfo@write{\q@object@label}% + \PgInfo@write{question\arabic{question}@object\arabic{ques@object}}% +}% first@questionobject + +% \addquestionobject will be used by each part, subpart, and +% subsubpart, and can also be used by the user to mark the end of a +% question that spills over onto the next page without any part, +% subpart, etc. starting on that page: +\newcommand{\addquestionobject}{% + \addtocounter{ques@object}{1}% + % \PgInfo@write expands it's argument, so we don't need edef: +% \edef\q@object@label{% +% question\arabic{question}@object\arabic{ques@object}}% +% \PgInfo@write{\q@object@label}% + \PgInfo@write{question\arabic{question}@object\arabic{ques@object}}% +}% addquestionobject + +% \questionobject@pluspagecheck will be used by each choice, as well +% as by any \part, \subpart, or \subsubpart that's inside of a +% solution. It uses the questionobject to check if we're the first +% one on the current page, since choices (and questions etc. inside of +% solution environments) don't have labels the way that questions, +% parts, subparts, and subsubparts do (those things use the label to +% check if they're the first thing on the page). +\newcommand{\questionobject@pluspagecheck}{% + % We don't want to do any of this if we're both inside a solution + % environment and not printing answers (because we want to avoid + % incrementing ques@object): + \if@insolution + \ifprintanswers + \doqobj@ppchk + \fi + \else + \doqobj@ppchk + \fi +}% questionobject@pluspagecheck +\newcommand{\doqobj@ppchk}{% + \addtocounter{ques@object}{1}% + % We need the edef because we check the page of \q@object@label: + \edef\q@object@label{% + question\arabic{question}@object\arabic{ques@object}}% + \PgInfo@write{\q@object@label}% + \set@counter@to@pageof{Curr@Page}{\q@object@label}% + \expandafter\ifx\csname Contin@\theCurr@Page\endcsname\relax + % We're the first \question, \part, \subpart, \subsubpart, + % or choice on this page: + \global\expandafter\edef\csname + Contin@\theCurr@Page\endcsname{\arabic{question}}% + \fi +}% doqobj@ppchk + + + +% if@bonus will be true when we're doing a bonusquestion or bonuspart +% or etc., and it will also be used also to distinguish between +% \gradetable and \bonusgradetable (and between \pointtable and +% \bonuspointtable, etc.), and also to distinguish between +% \pointsinrange and \bonuspointsinrange: +\newif\if@bonus +\@bonusfalse + +% The following are for advanced users who want to customize the list +% parameters (\topsep, \partopsep, \itemsep, \parsep, etc.) for the +% lists that these environments create. They are all defined to be +% empty, but the user can change them using \renewcommand. +\newcommand\questionshook{} +\newcommand\partshook{} +\newcommand\subpartshook{} +\newcommand\subsubpartshook{} +\newcommand\choiceshook{} +\newcommand\checkboxeshook{} + + +\newenvironment{questions}{% + % \@queslevel is used for two purposes: + % (1) We check that every \question, \part, \subpart, and + % \subsubpart command appears inside the appropriate environment, + % and generate an error if one appears in the wrong place. + % (2) If a \qformat is being used and if \@queslevel tells us + % that we're currently processing a question, then we set + % \global \point@toks={} to avoid setting the points for a + % question other than via the qformat command. + \def\@queslevel{question}% + \def\titledquestion##1{% + \@bonusfalse + \def\thequestiontitle{##1}% + \process@question + }% + \def\bonustitledquestion##1{% + \@bonustrue + \def\thequestiontitle{##1}% + \process@question + }% + \def\question{% + \@bonusfalse + \def\thequestiontitle{\csname p@question\endcsname + \csname thequestion\endcsname}% + \process@question + }% + \def\bonusquestion{% + \@bonustrue + \def\thequestiontitle{\csname p@question\endcsname + \csname thequestion\endcsname}% + \process@question + }% + \def\process@question{% + \if@coverpages + \cover@question@error + \fi + \@checkqueslevel{question}% + \addtocounter{numquestions}{1}% + % Write the sum of points of the previous question (if any) + % to the .aux file. (At this point, the question counter + % has not yet been incremented, so \value{question} is the + % number of the question that was just completed.) + \if@filesw + \ifnum \value{question} > 0\relax + % First do regular points: + \immediate\write\@mainaux + {\string\gdef\string\pointsofq@ + \romannumeral \csname c@question\endcsname + {\prtaux@hlfcntr{pointsof@thisquestion}}}% + % See if this has changed from the last run of LaTeX: + \CheckIfChanged@hlf{pointsof@thisquestion}{pointsofq@\romannumeral + \csname c@question\endcsname}% + % Now do bonus points: + \immediate\write\@mainaux + {\string\gdef\string\bonuspointsofq@ + \romannumeral \csname c@question\endcsname + {\prtaux@hlfcntr{bonuspointsof@thisquestion}}}% + % See if this has changed from the last run of LaTeX: + \CheckIfChanged@hlf{bonuspointsof@thisquestion}% + {bonuspointsofq@\romannumeral + \csname c@question\endcsname}% + \fi + \fi + \set@hlfcntr{pointsof@thisquestion}{0}% + \set@hlfcntr{bonuspointsof@thisquestion}{0}% + % If there was a question with points immediately preceding + % this question (i.e., there were no parts in the previous + % question), then @placepoints will still be true, and we need to + % cancel it. (We used to do this inside of the \thepoints macro, + % but that allowed for an error if the user specified points for a + % question but had a \qformat that didn't mention \thepoints.) We + % also set @placepoints to be false when entering a parts + % environment. + \global \@placepointsfalse + % point@toks will normally be empty at this point, but it might be + % nonempty if there were points somewhere in the previous question + % that never made it onto the page because we never entered + % horizontal mode (perhaps because the user was weird and let the + % text of a question (or part, etc.) consist entirely of an + % enumerate environment, or description environment, or etc.). + \global \point@toks={}% + % Important: Don't leave any blank lines inside of + % \pageinfo@commands!! This token list will be dumped into + % horizontal mode by \everypar, and so any blank lines will + % cause paragraph breaks. + \pageinfo@commands={% + \edef\@queslabel{question@\arabic{question}}% + \PgInfo@write{\@queslabel}% + \first@questionobject + % In addition to the \PgInfo@write we use an actual \label + % command. We do this in order to make the question numbers in + % the grade tables into \ref's, so that if the user says + % \usepackage{hyperref}, those question numbers will be clickable. + % + % A further purpose of these labels (which we actually do for all + % questions, parts, subparts, and subsubparts) is that if a + % question (or part, etc.) is, e.g., moved from one page to + % another, LaTeX will notice this and warn the user that LaTeX + % must be run one more time to be sure everything is correct. + % + % We need to do this even though we've already included code to + % check when point totals change because questions (and parts, + % etc.) know what page they're on from reading the info written to + % the .aux file on the previous run. Thus, if a question (or + % part, etc.) is moved to a different page, then the pointsonpage + % totals won't notice until the *second* subsequent run of LaTeX, + % and so there'll be no warning to the user on the *first* run. + % Including these labels gives the user a warning on that first + % run. + % + % Further futzing required: Since this is being put into the + % token list \pageinfo@commands, the contents of which won't + % actually be executed until we enter horizontal mode (which + % may well be in the first part of a parts environment), we need + % to make sure that \@currentlabel is the number of the + % question: + \begingroup % to confine the change to \@currentlabel +% \def\@currentlabel{\csname p@question\endcsname +% \csname thequestion\endcsname}% + \def\@currentlabel{\thequestiontitle}% + \label{\@queslabel}% + \endgroup + \set@counter@to@pageof{Curr@Page}{\@queslabel}% + \expandafter\ifx\csname Contin@\theCurr@Page\endcsname\relax + % We're the first \question, \part, \subpart, \subsubpart, + % or choice on this page: + \global\expandafter\edef + \csname Contin@\theCurr@Page\endcsname{\relax}% + \fi + \the\pagepoint@commands + \global \pageinfo@commands={}% + }% pageinfo@commands + \ifhmode + % Remove any skips at the end of the previous paragraph + % that might cause a blank line, and then end that paragraph: + \unskip\unskip \par + \fi + \@doitem + }% process@question + \def\subpart{% + \@bonusfalse + \process@subpart + }% + \def\bonussubpart{% + \@bonustrue + \process@subpart + }% + \def\process@subpart{% + \if@coverpages + \cover@question@error + \fi + \@checkqueslevel{subpart}% + \if@insolution + % We don't count this subpart, so no addtocounter{numsubparts}. + \temp@toks={% + \questionobject@pluspagecheck + \global \pageinfo@commands={}% + % We omit the pagepoint@commands + }% temp@toks + \else + \addtocounter{numsubparts}{1}% + % Important: Don't leave any blank lines inside of + % \pageinfo@commands!! This token list will be dumped into + % horizontal mode by \everypar, and so any blank lines will + % cause paragraph breaks. + \temp@toks={% + \edef\@subpartlabel{subpart@\arabic{question}% + @\arabic{partno}@\arabic{subpart}}% + \PgInfo@write{\@subpartlabel}% + \addquestionobject + % In addition to the \PgInfo@write we use an actual \label + % command. We do this in order to make the question numbers in + % the grade tables into \ref's, so that if the user says + % \usepackage{hyperref}, those question numbers will be clickable. + % + % A further purpose of these labels (which we actually do for all + % questions, parts, subparts, and subsubparts) is that if a + % question (or part, etc.) is, e.g., moved from one page to + % another, LaTeX will notice this and warn the user that LaTeX + % must be run one more time to be sure everything is correct. + % + % We need to do this even though we've already included code to + % check when point totals change because questions (and parts, + % etc.) know what page they're on from reading the info written to + % the .aux file on the previous run. Thus, if a question (or + % part, etc.) is moved to a different page, then the pointsonpage + % totals won't notice until the *second* subsequent run of LaTeX, + % and so there'll be no warning to the user on the *first* run. + % Including these labels gives the user a warning on that first + % run. + \label{\@subpartlabel}% + \set@counter@to@pageof{Curr@Page}{\@subpartlabel}% + \expandafter\ifx\csname Contin@\theCurr@Page\endcsname\relax + % We're the first \question, \part, \subpart, \subsubpart, + % or choice on this page: + \global\expandafter\edef\csname + Contin@\theCurr@Page\endcsname{\arabic{question}}% + \fi + \the\pagepoint@commands + \global \pageinfo@commands={}% + }% temp@toks + \fi + \append@toklist \pageinfo@commands \temp@toks + \ifhmode + % Remove any skips at the end of the previous paragraph + % that might cause a blank line, and then end that paragraph: + \unskip\unskip \par + \fi + \@doitem + }% process@subpart + \def\subsubpart{% + \@bonusfalse + \process@subsubpart + }% + \def\bonussubsubpart{% + \@bonustrue + \process@subsubpart + }% + \def\process@subsubpart{% + \if@coverpages + \cover@question@error + \fi + \@checkqueslevel{subsubpart}% + \if@insolution + % We don't count this subsubpart, so no addtocounter{numsubsubparts}. + \temp@toks={% + \questionobject@pluspagecheck + \global \pageinfo@commands={}% + % We omit the pagepoint@commands + }% temp@toks + \else + \addtocounter{numsubsubparts}{1}% + % Important: Don't leave any blank lines inside of + % \pageinfo@commands!! This token list will be dumped into + % horizontal mode by \everypar, and so any blank lines will + % cause paragraph breaks. + \temp@toks={% + \edef\@subsubpartlabel{subsubpart@\arabic{question}% + @\arabic{partno}@\arabic{subpart}@\arabic{subsubpart}}% + \PgInfo@write{\@subsubpartlabel}% + \addquestionobject + % In addition to the \PgInfo@write we use an actual \label + % command. We do this in order to make the question numbers in + % the grade tables into \ref's, so that if the user says + % \usepackage{hyperref}, those question numbers will be clickable. + % + % A further purpose of these labels (which we actually do for all + % questions, parts, subparts, and subsubparts) is that if a + % question (or part, etc.) is, e.g., moved from one page to + % another, LaTeX will notice this and warn the user that LaTeX + % must be run one more time to be sure everything is correct. + % + % We need to do this even though we've already included code to + % check when point totals change because questions (and parts, + % etc.) know what page they're on from reading the info written to + % the .aux file on the previous run. Thus, if a question (or + % part, etc.) is moved to a different page, then the pointsonpage + % totals won't notice until the *second* subsequent run of LaTeX, + % and so there'll be no warning to the user on the *first* run. + % Including these labels gives the user a warning on that first + % run. + \label{\@subsubpartlabel}% + \set@counter@to@pageof{Curr@Page}{\@subsubpartlabel}% + \expandafter\ifx\csname Contin@\theCurr@Page\endcsname\relax + % We're the first \question, \part, \subpart, \subsubpart, + % or choice on this page: + \global\expandafter\edef\csname + Contin@\theCurr@Page\endcsname{\arabic{question}}% + \fi + \the\pagepoint@commands + \global \pageinfo@commands={}% + }% temp@toks + \fi + \append@toklist \pageinfo@commands \temp@toks + \ifhmode + % Remove any skips at the end of the previous paragraph + % that might cause a blank line, and then end that paragraph: + \unskip\unskip \par + \fi + \@doitem + }% process@subsubpart + \list{\question@number}% + {\usecounter{question}% + % We use the default definition of \makelabel + % so as not to interfere with \qformat commands. + % \def\makelabel##1{\hss\llap{##1}}% + \settowidth{\leftmargin}{10.\hskip\labelsep}% + \labelwidth\leftmargin\advance\labelwidth-\labelsep + \partopsep=0pt + \questionshook + }% + }% End of the first argument of \newenvironment{questions} + {% + \endlist + % Write the number of points of the final question + % to the .aux file: + \if@filesw + \ifnum \value{question} > 0\relax + % First do the regular points: + \immediate\write\@mainaux + {\string\gdef\string\pointsofq@\romannumeral + \csname c@question\endcsname + {\prtaux@hlfcntr{pointsof@thisquestion}}}% + % See if this has changed from the last run of LaTeX: + \CheckIfChanged@hlf{pointsof@thisquestion}% + {pointsofq@\romannumeral + \csname c@question\endcsname}% + % Now do the bonus points: + \immediate\write\@mainaux + {\string\gdef\string\bonuspointsofq@\romannumeral + \csname c@question\endcsname + {\prtaux@hlfcntr{bonuspointsof@thisquestion}}}% + % See if this has changed from the last run of LaTeX: + \CheckIfChanged@hlf{bonuspointsof@thisquestion}% + {bonuspointsofq@\romannumeral + \csname c@question\endcsname}% + \fi + \fi + }% End of the second argument of \newenvironment{questions} + +% \question@number is used as the label in the question list (instead +% of \questionlabel) so that if the user uses a \qformat command, +% we'll use the \@questionformat specified by the \qformat command: + +\def\question@number{% + \if@bonus + \if@bonusqformat + \makebox[\hsize][s]{\@bonusquestionformat}\hskip-\labelsep + \else + \questionlabel + \fi + \else + \if@qformat + \makebox[\hsize][s]{\@questionformat}\hskip-\labelsep + \else + \questionlabel + \fi + \fi +} +\newcommand\questionlabel{\thequestion.} + +% We want the \part command to be defined *only* inside of a parts +% environment, so that the user can use the standard sectioning \part +% command inside of a questions environment (as long as it's outside of +% a parts environment). + +\newenvironment{parts}{% + \def\@queslevel{part}% + % If the question numbers are being inserted via a \qformat, + % and if a question is beginning with a parts environment, then + % we need to enter horizonal mode to get the qformat printed + % on the page, rather than saving up the question label (and + % possible points) to be combined with the label of the first + % part. (\if@inlabel tells us if we are still waiting to enter + % horizontal mode after seeing a \question command.) + \if@bonus + \if@bonusqformat + \if@inlabel + \leavevmode + \@inlabelfalse + \fi + % The following is just in case the question had points, + % in which case @placepoints will still be true. + % (We used to do this inside of the \thepoints macro, + % but that allowed for an error if the user specified points for + % a question but had a \qformat that didn't mention \thepoints.) + % We also set @placepoints to be false in the \question command, + % in case one queation follows a previous one that had no parts. + \global \@placepointsfalse + \fi + \else + \if@qformat + \if@inlabel + \leavevmode + \@inlabelfalse + \fi + % The following is just in case the question had points, + % in which case @placepoints will still be true. + % (We used to do this inside of the \thepoints macro, + % but that allowed for an error if the user specified points for + % a question but had a \qformat that didn't mention \thepoints.) + % We also set @placepoints to be false in the \question command, + % in case one queation follows a previous one that had no parts. + \global \@placepointsfalse + \fi + \fi + \def\part{% + \@bonusfalse + \process@part + }% + \def\bonuspart{% + \@bonustrue + \process@part + }% + \def\process@part{% + \if@coverpages + \cover@question@error + \fi + \@checkqueslevel{part}% + \if@insolution + % We don't count this part, so no addtocounter{numparts}. + \temp@toks={% + \questionobject@pluspagecheck + \global \pageinfo@commands={}% + % We omit the pagepoint@commands + }% temp@toks + \else + \addtocounter{numparts}{1}% + % Important: Don't leave any blank lines inside of + % \pageinfo@commands!! This token list will be dumped into + % horizontal mode by \everypar, and so any blank lines will + % cause paragraph breaks. + \temp@toks={% + \edef\@partlabel{part@\arabic{question}@\arabic{partno}}% + \PgInfo@write{\@partlabel}% + \addquestionobject + % In addition to the \PgInfo@write we use an actual \label + % command. We do this in order to make the question numbers in + % the grade tables into \ref's, so that if the user says + % \usepackage{hyperref}, those question numbers will be clickable. + % + % A further purpose of these labels (which we actually do for all + % questions, parts, subparts, and subsubparts) is that if a + % question (or part, etc.) is, e.g., moved from one page to + % another, LaTeX will notice this and warn the user that LaTeX + % must be run one more time to be sure everything is correct. + % + % We need to do this even though we've already included code to + % check when point totals change because questions (and parts, + % etc.) know what page they're on from reading the info written to + % the .aux file on the previous run. Thus, if a question (or + % part, etc.) is moved to a different page, then the pointsonpage + % totals won't notice until the *second* subsequent run of LaTeX, + % and so there'll be no warning to the user on the *first* run. + % Including these labels gives the user a warning on that first + % run. + \label{\@partlabel}% + \set@counter@to@pageof{Curr@Page}{\@partlabel}% + \expandafter\ifx\csname Contin@\theCurr@Page\endcsname\relax + \global\expandafter\edef\csname + Contin@\theCurr@Page\endcsname{\arabic{question}}% + \fi + \the\pagepoint@commands + \global \pageinfo@commands={}% + }% temp@toks + \fi + \append@toklist \pageinfo@commands \temp@toks + \ifhmode + % Remove any skips at the end of the previous paragraph + % that might cause a blank line, and then end that paragraph: + \unskip\unskip \par + \fi + \@doitem + }% process@part + \list{\partlabel}% + {% + \usecounter{partno}\def\makelabel##1{\hss\llap{##1}}% + \settowidth{\leftmargin}{(m)\hskip\labelsep}% + \labelwidth\leftmargin\advance\labelwidth-\labelsep + \topsep=0pt + \partopsep=0pt + \partshook + }% + }% newenvironment{parts} + {\endlist} +\newcommand\partlabel{(\thepartno)} +\def\thepartno{\alph{partno}} + +\newenvironment{subparts}{% + \def\@queslevel{subpart}% + \list{\subpartlabel}% + {% + \usecounter{subpart}\def\makelabel##1{\hss\llap{##1}}% + \settowidth{\leftmargin}{vii.\hskip\labelsep}% + \labelwidth\leftmargin\advance\labelwidth-\labelsep + \topsep=0pt + \partopsep=0pt + \subpartshook + }% + }% + {\endlist} +\newcommand\subpartlabel{\thesubpart.} +\def\thesubpart{\roman{subpart}} + +\newenvironment{subsubparts}{% + \def\@queslevel{subsubpart}% + \list{\subsubpartlabel}% + {% + \usecounter{subsubpart}\def\makelabel##1{\hss\llap{##1}}% + \settowidth{\leftmargin}{($\psi$)\hskip\labelsep}% + \labelwidth\leftmargin\advance\labelwidth-\labelsep + \topsep=0pt + \partopsep=0pt + \subsubpartshook + }% + }% + {\endlist} +\newcommand\subsubpartlabel{\thesubsubpart)} +\def\thesubsubpart{\greeknum{subsubpart}} + + + + +\pagepoint@commands={% + \ifhlfcntr@pos{latest@points}% + % We're putting a question (or part, etc.) + % with points onto this page: + \ifnum \theCurr@Page > \thepageof@pagepoints\relax + % These points go on a later page than + % the points currently counted in @pagepoints: + \ifnum \thepageof@pagepoints = 0\relax + % Do nothing... + \else + \immediate\write\@mainaux + {\string\gdef\string\pointsonpage@ + \romannumeral \csname c@pageof@pagepoints\endcsname + {\prtaux@hlfcntr{@pagepoints}}}% + % See if this has changed from the last run of LaTeX: + \CheckIfChanged@hlf{@pagepoints}{pointsonpage@\romannumeral + \csname c@pageof@pagepoints\endcsname}% + \fi + % The following is a macro because \theCurr@Page and + % \thepageof@pagepoints might differ by more than 1: + \increment@pageof@pagepoints + % The following label is so that we can make the page + % numbers in a grade table indexed by page into \pageref's + % so that \usepackage{hyperref} and pdflatex will + % make them clickable: + \label{firstpoints@onpage@\arabic{Curr@Page}}% + \else + % These points go on the same page as the points + % currently counted in @pagepoints: + \add@hlfcntrtohlfcntr{@pagepoints}{latest@points}% + \set@hlfcntr{latest@points}{0}% + \fi + \fi + \ifhlfcntr@pos{latest@bonuspoints}% + % We're putting a question (or part, etc.) + % with bonus points onto this page: + \ifnum \theCurr@Page > \thepageof@pagebonuspoints\relax + % These bonus points go on a later page than + % the points currently counted in @pagebonuspoints: + \ifnum \thepageof@pagebonuspoints = 0\relax + % Do nothing... + \else + \immediate\write\@mainaux + {\string\gdef\string\bonuspointsonpage@ + \romannumeral \csname c@pageof@pagebonuspoints\endcsname + {\prtaux@hlfcntr{@pagebonuspoints}}}% + % See if this has changed from the last run of LaTeX: + \CheckIfChanged@hlf{@pagebonuspoints}% + {bonuspointsonpage@\romannumeral + \csname c@pageof@pagebonuspoints\endcsname}% + \fi + % The following is a macro because \theCurr@Page and + % \thepageof@pagebonuspoints might differ by more than 1: + \increment@pageof@pagebonuspoints + % The following label is so that we can make the page + % numbers in a bonus grade table indexed by page into \pageref's + % so that \usepackage{hyperref} and pdflatex will + % make them clickable: + \label{firstbonuspoints@onpage@\arabic{Curr@Page}}% + \else + % These points go on the same page as the points + % currently counted in @pagebonuspoints: + \add@hlfcntrtohlfcntr{@pagebonuspoints}{latest@bonuspoints}% + \set@hlfcntr{latest@bonuspoints}{0}% + \fi + \fi +}% pagepoint@commands +\def\increment@pageof@pagepoints{% + \addtocounter{pageof@pagepoints}{1}% + \ifnum \theCurr@Page > \thepageof@pagepoints\relax + \immediate\write\@mainaux + {\string\gdef\string\pointsonpage@ + \romannumeral \csname c@pageof@pagepoints\endcsname{0}}% + % See if this has changed from the last run of LaTeX: + \@ifundefined{pointsonpage@\romannumeral + \csname c@pageof@pagepoints\endcsname} + {\global\@pointschangedtrue}% + {% + % OK; it's defined. See if it's changed: + \begingroup + \set@hlfcntr{tmp@hlfcntr}{\csname pointsonpage@\romannumeral + \csname c@pageof@pagepoints\endcsname\endcsname}% + \edef\othpt@check{\prtaux@hlfcntr{tmp@hlfcntr}}% + \def\pt@check{0}% + \ifx \pt@check \othpt@check + % Do nothing + \else + \global\@pointschangedtrue + \fi + \endgroup + }% + \let\next@incr@pageof = \increment@pageof@pagepoints + \else + \copy@hlfcntr{@pagepoints}{latest@points}% + \set@hlfcntr{latest@points}{0}% + % \page@withpoints will be used to find the last + % page that has points, which will be written to + % the .aux file via \AtEndDocument: + \global\edef\page@withpoints{\thepageof@pagepoints}% + \let\next@incr@pageof = \relax + \fi + \next@incr@pageof +}% increment@pageof@pagepoints +\def\increment@pageof@pagebonuspoints{% + \addtocounter{pageof@pagebonuspoints}{1}% + \ifnum \theCurr@Page > \thepageof@pagebonuspoints\relax + \immediate\write\@mainaux + {\string\gdef\string\bonuspointsonpage@ + \romannumeral \csname c@pageof@pagebonuspoints\endcsname{0}}% + % See if this has changed from the last run of LaTeX: + \@ifundefined{bonuspointsonpage@\romannumeral + \csname c@pageof@pagebonuspoints\endcsname} + {\global\@pointschangedtrue}% + {% + % OK; it's defined. See if it's changed: + \begingroup + \set@hlfcntr{tmp@hlfcntr}{\csname bonuspointsonpage@\romannumeral + \csname c@pageof@pagebonuspoints\endcsname\endcsname}% + \edef\othpt@check{\prtaux@hlfcntr{tmp@hlfcntr}}% + \def\pt@check{0}% + \ifx \pt@check \othpt@check + % Do nothing + \else + \global\@pointschangedtrue + \fi + \endgroup + }% + \let\next@incr@pageof = \increment@pageof@pagebonuspoints + \else + \copy@hlfcntr{@pagebonuspoints}{latest@bonuspoints}% + \set@hlfcntr{latest@bonuspoints}{0}% + % \page@withbonuspoints will be used to find the last + % page that has bonus points, which will be written to + % the .aux file via \AtEndDocument: + \global\edef\page@withbonuspoints{\thepageof@pagebonuspoints}% + \let\next@incr@pageof = \relax + \fi + \next@incr@pageof +}% increment@pageof@pagebonuspoints + + + + + + +\def\@checkqueslevel#1{% + \begingroup + \def\exam@temp{#1}% + \ifx\exam@temp\@queslevel + % Everything's fine; do nothing. + \else + \ClassError{exam}{% + I found a #1 where I expected to find a + \@queslevel\MessageBreak + }{% + Both #1 and \@queslevel \space can be used only inside the + correct \MessageBreak \space \space + environment and outside of any smaller environment + \MessageBreak + }% + \fi + \endgroup +} + +\def\@doitem{\@ifnextchar[{\@readpoints}% + {\item@points@pageinfo}% +} + +\def\@readpoints[#1]{% +% We use \def for \@points instead of \edef because we don't want +% \half (if present) to be expanded yet, so that the command \points +% can figure out how to deal with it: + \def\@points{#1}% + \global \@placepointstrue + \if@addpoints + \if@bonus + \addto@hlfcntr{numbonuspoints}{\@points}% + \addto@hlfcntr{bonuspointsof@thisquestion}{\@points}% + % latest@bonuspoints is a holding area for bonus points to be + % added to @pagepoints after we check whether they're + % on the same page as the points currently counted + % by @pagepoints: + \addto@hlfcntr{latest@bonuspoints}{\@points}% + \else + \addto@hlfcntr{numpoints}{\@points}% + \addto@hlfcntr{pointsof@thisquestion}{\@points}% + % latest@points is a holding area for points to be + % added to @pagepoints after we check whether they're + % on the same page as the points currently counted + % by @pagepoints: + \addto@hlfcntr{latest@points}{\@points}% + \fi + \fi + \item@points@pageinfo +} + + + + +% Bug fix, 5 April 2004: \item@points@pageinfo +% Appending \point@toks and \pageinfo@commands to \everypar: +% Instead of appending the contents of \point@toks and +% \pageinfo@commands to \everypar using \append@toklist, +% we instead want to append only the two tokens +% \the\point@toks +% and the two tokens +% \the\pageinfo@commands +% to \everypar. We need to do this because if a questions environment +% immediately follows a \section command, then @nobreak will be true, +% and so the \if@nobreak inside of \everypar will *not* execute the +% \everypar={} that we had been counting on to keep the points from +% being inserted a second time in the second paragraph of a question. +% Since we've put the command \global \point@toks={} inside of +% \point@toks and the command \pageinfo@commands={} inside of +% \pageinfo@commands, when the contents of \point@toks and of +% \pageinfo@commands are executed (when we enter horizontal mode and +% \everypar is dumped in), the contents of \point@toks and +% \pageinfo@commands will be made empty, and so if +% the second paragraph also gets \the\point@toks and +% \the\pageinfo@commands, it won't matter. + +\def\item@points@pageinfo{% + \item + % Also: We need to do this here, *after* the \item command, rather + % than inside the macro \@readpoints, because the \item command + % puts the result of the \qformat command into an \hbox (with the + % command ``\sbox\@tempboxa{\makelabel{#1}}%''), expanding the + % argument of \qformat as it does so. Thus, @placepoints will be + % true when the argument of \qformat is expanded, and so if the + % user put a \thepoints command inside that argument it will + % correctly expand to the number of points. (When @placepoints is + % false, \thepoints expands to nothing at all). + % + % We also want to define \padded@point@block when @placepoints is + % true even if qformat and bonusqformat are true just in case the + % user, for some deranged reason, says \droppoints immediately + % following a \question. + % + \if@placepoints + % Since we want the user to be able to say \thepoints in the + % argument to a \pointformat command, we need \@placepointstrue + % when \point@block is expanded so that \thepoints will actually + % print something. (After setting up \point@toks, we do + % \@placepointsfalse, but \point@block isn't actually expanded + % until we enter horizontal mode.) Thus, we define + % \padded@point@block, and use that instead of \point@block. We + % put \begingroup and \endgroup around this to confine the + % effect of \@placepointstrue and also to confine the effect of + % any declarations like, e.g., \bfseries that the user might put + % in the argument of a \pointformat command. + % + % Note: We first tried using an \edef to expand \point@block right + % here, while @placepoints is true, but that causes problems if + % the user puts a \boldmath declaration in the argument of a + % \pointformat command. Apparently, expanding \boldmath (without + % executing anything) gives you bunches of undefined control + % sequence errors. + \if@bonus + \def\padded@point@block{% + \begingroup + \@placepointstrue + \bonuspoint@block + \endgroup + }% + \else + \def\padded@point@block{% + \begingroup + \@placepointstrue + \point@block + \endgroup + }% + \fi + % \setup@point@toks puts commands into \point@toks to place + % \padded@point@block at the correct spot. It doesn't append + % anything to \everypar (we do that in this macro, below). + % + % If @qformat is true, and if we're currently doing a question (or + % if @bonusqformat is true and we're doing a bonusquestion) + % (rather than a part, subpart, or subsubpart), then we don't want + % to set the points (if any), since the points of a question will + % appear only if the user chooses to cause that by putting a + % \thepoints in the argument of the \qformat command. + \if@pointsdropped + % Do nothing! + \else + \if@bonus + \if@bonusqformat + \ifx\ques@ref\@queslevel + % Do nothing + \else + \setup@point@toks + \fi + \else + \setup@point@toks + \fi + \else + \if@qformat + \ifx\ques@ref\@queslevel + % Do nothing + \else + \setup@point@toks + \fi + \else + \setup@point@toks + \fi + \fi + \fi + \global \@placepointsfalse + \fi + % We *don't* use \append@toklist; see the Bug fixnote above + % (Bug fix, 5 April 2004). + % We can append the tokens ``\the\point@toks'' whether or not we're + % setting any points because if we're not setting them, \point@toks + % will be empty. + % Also: It's important to do this *after* the \item command above, + % since the \item command discards the previous contents of + % \everypar. + % Version 2.218$\beta$, 2007/10/31 changes: + % Instead of appending + % \the \pageinfo@commands \the \point@toks + % to \everypar, we insert them into the box \@labels. This corrects + % the problem that arose when a question (or part, etc.) begins with + % a list environment (including verbatim, flushleft, center, + % flushright, and possibly others that are implemented as trivlist + % environments). The \item command in those environments throws + % away the previous contents of \everypar, and so the tokens \the + % \pageinfo@commands \the \point@toks didn't get inserted where we + % expected. List environments *do* preserve the contents of the box + % \@labels, though. + \global\setbox\@labels\hbox{\unhbox\@labels + \the \pageinfo@commands + \the \point@toks}% + % \edef\append@everypar{\noexpand\everypar={\the\everypar + % \noexpand\the \noexpand\pageinfo@commands + % \noexpand\the \noexpand\point@toks}}% + % \append@everypar +} + + + + + + + +% Initialize \@points: +% (The only reason I think this is necessary is in case the user uses +% a \qformat command, puts \themarginpoints into the format (which is +% *not* the intended use of \themarginpoints), and then doesn't have +% any points for the first question.) +\def\@points{0} + + +\def\setup@point@toks{% +% We set the token list \point@toks equal to the sequence of commands +% needed to put \padded@point@block at the correct location, followed +% by the tokens ``\global \point@toks={}''. The \question, \part, +% \subpart, or \subsubpart command then adds the two tokens +% ``\the\point@toks'' to \everypar. +% +% Note: It is not the *contents* of \point@toks that is added to +% \everypar; just the two tokens ``\the\point@toks''. This difference +% is the bug fix of 2 April 2004, described above (the bug was that in +% earlier versions, we used to append the contents). +% +% The result of this is that whenever we finally enter horizontal mode +% (because we finally encountered the text of a question, part, +% subpart, or subsubpart) the contents of \point@toks will be dumped +% into horizontal mode and executed, and so the points will be placed +% and the token list \point@toks will be set to empty. Thus, in the +% occasional circumstances in which \everypar is *not* set to empty +% after being added to the first paragraph (which occurs when a +% questions environment immediately follows a \section command), and +% so \everypar will still contain ``\the\point@toks'' when it +% encounters a possible second paragraph of the first question, the +% tokens ``\the\point@toks'' will insert an *empty* token list, which +% will do no harm. +% + \if@pointstwosided + % Set \csname \q@label \endcsname equal to the thing + % that expands to the page number of the current (question or + % part or subpart or subsubpar; whatever it is), but do it + % carefully because, if we don't yet have page info, then it won't + % be defined: + \ifx\@queslevel\ques@ref + \def\q@label{Pg@question@\arabic{question}} + \else + \ifx\@queslevel\part@ref + \def\q@label{Pg@part@\arabic{question}@\arabic{partno}} + \else + \ifx\@queslevel\subpart@ref + \def\q@label{Pg@subpart@\arabic{question}% + @\arabic{partno}@\arabic{subpart}} + \else + \ifx\@queslevel\subsubpart@ref + \def\q@label{Pg@subsubpart@\arabic{question}% + @\arabic{partno}@\arabic{subpart}@\arabic{subsubpart}} + \else + \ClassError{exam}{% + This can't happen in function \protect\setup@point@toks + \MessageBreak + }{% + An unexplained error occurred in exam.cls;\MessageBreak + please inform the package maintainer, and send along + \MessageBreak + the LaTeX file that shows the error.\MessageBreak + }% + \fi + \fi + \fi + \fi + % + \expandafter\ifx \csname \q@label \endcsname\relax + % No page info yet; put it into the right margin + \@pointsinrightmargintrue + \@pointsinleftmarginfalse + \else + \ifodd \csname \q@label \endcsname\relax + \if@pointsinoutsidemargin + \@pointsinrightmargintrue + \@pointsinleftmarginfalse + \else + \@pointsinrightmarginfalse + \@pointsinleftmargintrue + \fi + \else + \if@pointsinoutsidemargin + \@pointsinrightmarginfalse + \@pointsinleftmargintrue + \else + \@pointsinrightmargintrue + \@pointsinleftmarginfalse + \fi + \fi + \fi + \fi + % That ends the \if@pointstwosided. + % Now we actually setup \point@toks: + \if@pointsinleftmargin + \point@toks={% + \llap{\padded@point@block + \hskip\@totalleftmargin + \hskip\marginpointssep + }% + \global \point@toks={}% + }% + \else + \if@pointsinrightmargin + \point@toks={% + \rlap{\hskip-\@totalleftmargin + \hskip\textwidth + \hskip\@rightmargin + \hskip-\rightpointsmargin + \llap{\padded@point@block}% + }% + \global \point@toks={}% + }% + \else + % The points just go after the question number: + \point@toks={% + \padded@point@block + \enspace + \global \point@toks={}% + }% + \fi + \fi +}% setup@point@toks + +\def\droppoints{% + \leavevmode\unskip\nobreak\hfill + \rlap{\hskip\rightmargin % Defined by the list environment + \hskip\@rightmargin % Defined by exam.cls + \hskip-\rightpointsmargin + \llap{\padded@point@block}% + }% rlap + \par +} + +\def\droptotalpoints{% + \leavevmode\unskip\nobreak\hfill + \rlap{\hskip\rightmargin % Defined by the list environment + \hskip\@rightmargin % Defined by exam.cls + \hskip-\rightpointsmargin + \llap{\total@block}% + }% rlap + \par +}% droptotalpoints +\def\droptotalbonuspoints{% + \leavevmode\unskip\nobreak\hfill + \rlap{\hskip\rightmargin % Defined by the list environment + \hskip\@rightmargin % Defined by exam.cls + \hskip-\rightpointsmargin + \llap{\bonustotal@block}% + }% rlap + \par +}% droptotalbonuspoints + +% The following is the default definition; +% it can be changed by a \totalformat command. +\def\total@block{% + Total for Question \thequestion: \totalpoints\@marginpointname +}% total@block +\def\bonustotal@block{% + Total for Question \thequestion: \totalbonuspoints\@marginbonuspointname +}% bonustotal@block + +\def\totalformat#1{% + \gdef\total@block{\begingroup #1\endgroup}% +}% totalformat +\def\bonustotalformat#1{% + \gdef\bonustotal@block{\begingroup #1\endgroup}% +}% bonustotalformat +% The following is for use in the argument to a \totalformat command: +\def\totalpoints{\pointsofquestion{\arabic{question}}} +\def\totalbonuspoints{\bonuspointsofquestion{\arabic{question}}} + + + +% @placepoints is set true when we encounter a question (or part, etc.) +% that has points. It is set to false (1) when we set \point@toks equal +% to the sequence of commands required to put the properly formatted +% points onto the page (this happens only if @qformat is false or if +% @qformat is true but we're not doing a question), or (2) by a +% \question command or entering a parts environment (since if we're +% doing a question and @qformat is true, we need to leave @placepoints +% true so that the \thepoints command can tell if it should expand to +% points or to nothing, and encountering a \question command or parts +% environment tells us that we no longer have to deal with a possible +% \thepoints, since we won't be expanding a qformat). +\newif\if@placepoints +\@placepointsfalse + + +% \marginpointssep will be used if the user says +% \pointsinleftmargin. It will be the distance from whatever encloses +% the points (parentheses, brackets, or a box) to the left margin: +\newlength\marginpointssep +\setlength{\marginpointssep}{5pt} + +% \rightpointsmargin will be used if the user says \pointsinrightmargin. +% It will be the distance from whatever encloses the point (parentheses, +% brackets, or a box) to the right edge of the paper: +\newlength\rightpointsmargin +\setlength{\rightpointsmargin}{1cm} + + +\newif\if@pointsdropped +\newif\if@pointsinleftmargin +\newif\if@pointsinrightmargin +\newif\if@pointstwosided +\newif\if@pointsinoutsidemargin + +% If we have \@pointstwosidedtrue and \@pointsinoutsidemarginfalse, +% then the points will be printed on the inside margin (left on odd +% numbered pages, right on even numbered pages). If we have +% \@pointstwosidedfalse, then \if@pointsinoutsidemargin is ignored. + +% If we have \@pointstwosidedtrue, then both \@pointsinleftmargin and +% \@pointsinrightmargin will be flipped back and forth, as needed, in +% \setup@point@toks. + +\def\pointsinleftmargin{\global\@pointsinleftmargintrue + \global\@pointsinrightmarginfalse + \global\@pointsdroppedfalse + \global\@pointstwosidedfalse + \gdef\pt@name{\@marginpointname}% + \gdef\bnspt@name{\@marginbonuspointname}} +\def\pointsinrightmargin{\global\@pointsinrightmargintrue + \global\@pointsinleftmarginfalse + \global\@pointsdroppedfalse + \global\@pointstwosidedfalse + \gdef\pt@name{\@marginpointname}% + \gdef\bnspt@name{\@marginbonuspointname}} +\def\nopointsinmargin{\global\@pointsinleftmarginfalse + \global\@pointsinrightmarginfalse + \global\@pointsdroppedfalse + \global\@pointstwosidedfalse + \gdef\pt@name{\@pointname}% + \gdef\bnspt@name{\@bonuspointname}} +\def\pointsdroppedatright{\global\@pointsdroppedtrue + \global\@pointsinleftmarginfalse + \global\@pointsinrightmarginfalse + \global\@pointstwosidedfalse + \gdef\pt@name{\@marginpointname}% + \gdef\bnspt@name{\@marginbonuspointname}} +\def\pointstwosided{\global\@pointstwosidedtrue + \global\@pointsinoutsidemargintrue + \global\@pointsdroppedfalse + \gdef\pt@name{\@marginpointname}% + \gdef\bnspt@name{\@marginbonuspointname}} +\def\pointstwosidedreversed{\global\@pointstwosidedtrue + \global\@pointsinoutsidemarginfalse + \global\@pointsdroppedfalse + \gdef\pt@name{\@marginpointname}% + \gdef\bnspt@name{\@marginbonuspointname}} +\let\pointsinmargin=\pointsinleftmargin +\let\nopointsinrightmargin=\nopointsinmargin +\let\nopointsinleftmargin=\nopointsinmargin + +\nopointsinmargin + + +% Will the points be displayed inside parentheses (the default), or +% will they be boxed or bracketed, or customized using pointformat: +\def\boxedpoints{% + \gdef\point@block{\fbox{\@points\pt@name}}% + \gdef\bonuspoint@block{\fbox{\@points\bnspt@name}}% +} +\def\noboxedpoints{% + \gdef\point@block{(\@points\pt@name)}% + \gdef\bonuspoint@block{(\@points\bnspt@name)}% +} +\def\bracketedpoints{% + \gdef\point@block{[\@points\pt@name]}% + \gdef\bonuspoint@block{[\@points\bnspt@name]}% +} +\let\nobracketedpoints=\noboxedpoints + +\def\pointformat#1{% + % We don't have to worry about the user putting things + % like \bfseries, etc. into \point@block, because + % \padded@point@block encloses \point@block in a group, + % which confines the effects of anything here: + \gdef\point@block{#1}% +} + +\def\bonuspointformat#1{% + % We don't have to worry about the user putting things + % like \bfseries, etc. into \point@block, because + % \padded@point@block encloses \point@block in a group, + % which confines the effects of anything here: + \gdef\bonuspoint@block{#1}% +} + +%Initialize: +\noboxedpoints + + + + +\def\pointname#1{\gdef\@pointname{#1}} +\def\bonuspointname#1{\gdef\@bonuspointname{#1}} +% Initialize to leave a space, and then the word `points': +%%\pointname{ points} +% The following improvement was contributed by +% Mate Wierdl +% If the number of points is ``1'', then the default value of +% \pointname will print `` point'' instead of `` points'' (and this +% version of the command doesn't generate an error message if the +% points entry is something other than a number): +% Note the space before the \points in the following; it's +% intentional!) +\pointname{ \points} +\bonuspointname{ \bonuspoints} +\newcommand\point@sing{point} +\newcommand\point@plur{points} +\newcommand\pointpoints[2]{% + \renewcommand\point@sing{#1}% + \renewcommand\point@plur{#2}% +} +%\newcommand\bonuspoint@sing{bonus point} +%\newcommand\bonuspoint@plur{bonus points} +\newcommand\bonuspoint@sing{point (bonus)} +\newcommand\bonuspoint@plur{points (bonus)} +\newcommand\bonuspointpoints[2]{% + \renewcommand\bonuspoint@sing{#1}% + \renewcommand\bonuspoint@plur{#2}% +} + + + +% The command \points: +% We use \ifthenelse and \equal so that if the user types something +% other than a legit point value, there still won't be any error +% messages. We rig it so that if the point value looks like it's +% intended to be One or one or ONE, or some strange way of attempting +% one half, then it will expand to the singular value. Alas, this is +% only useful for English, but I'm hoping few or no users will try doing +% this anyway. + +% 0 points, one half point, 1 point, 1 and a half points, etc.: +\newcommand\points{% + \begingroup + \let\half=\relax + \edef\pt@string{\@points}% + \ifthenelse{\equal{\pt@string}{1} \or \equal{\pt@string}{\half}} + {\point@sing}{\point@plur}% + \endgroup +}% \points +\newcommand\bonuspoints{% + \begingroup + \let\half=\relax + \edef\pt@string{\@points}% + \ifthenelse{\equal{\pt@string}{1} \or \equal{\pt@string}{\half}} + {\bonuspoint@sing}{\bonuspoint@plur}% + \endgroup +}% \bonuspoints +%\newcommand\points{% +% \begingroup +% \let\half=\relax +% \edef\pt@string{\@points}% +% \ifthenelse{\equal{\pt@string}{1} \or \equal{\pt@string}{\half} \or +% \equal{\pt@string}{0\half} \or \equal{\pt@string}{0 \half} +% \equal{\pt@string}{one} \or \equal{\pt@string}{One} \or +% \equal{\pt@string}{ONE}} +% {\point@sing}{\point@plur}% +% \endgroup +%} + +%\newcommand\points{\ifthenelse{\equal{\@points}{1}}{\point@sing}{\point@plur}} +% If we used the following line instead, then you'd get an error +% message if the point value contained something other than a valid +% integer: +%\pointname{ \ifthenelse{\@points = 1}{point}{points}} + +% We used to define a command named \marks that works like \points, +% except that it expands to either ``mark'' or ``marks'', but that +% conflicts with some package or other. Thus, we'll implement +% \marksnotpoints using the \pointpoints command instead: +\newcommand\marksnotpoints{% + \pointpoints{mark}{marks}% + \bonuspointpoints{mark (bonus)}{marks (bonus)}% +}% \marksnotpoints + + +% \@marginpointname is used in place of \@pointname if any of +% \@pointsinmargin, \@pointsinrightmargin, and \@pointsdropped are +% true: +\def\marginpointname#1{\gdef\@marginpointname{#1}} +\marginpointname{} +\def\marginbonuspointname#1{\gdef\@marginbonuspointname{#1}} +\marginbonuspointname{ (bonus)} + + +%-------------------------------------------------------------------- +% choices (for multiple choice) and checkboxes + + +\renewcommand\thechoice{\Alph{choice}} +\newcommand\choicelabel{\thechoice.} + +% We will have \@correctchoicetrue when we're printing solutions +% and we're printing the correct choice of a choices or +% oneparchoices environment. +% We'll say \begingroup before saying \@correctchoicetrue +% and we'll say \endgroup at either the next \choice or \correctchoice +% or the end of the choices or oneparchoices environment. +% Thus, we'll never again need to say \@correctchoicefalse +\newif\if@correctchoice +\@correctchoicefalse + +\newcommand\CorrectChoiceEmphasis[1]{% + \def\CorrectChoice@Emphasis{#1}% +} +\CorrectChoiceEmphasis{\bfseries} +\let\correctchoiceemphasis\CorrectChoiceEmphasis + +% Note: \do@choice@pageinfo is used in both the choices and +% the checkboxes environments. +\newtoks\choice@toks +\def\do@choice@pageinfo{% + \choice@toks={% + \questionobject@pluspagecheck + \choice@toks={}% + }% + % Version 2.217-beta changes: + % Instead of appending stuff to \everypar, we insert + % \the \pageinfo@commands and \the \point@toks + % into the box \@labels: + \global\setbox\@labels\hbox{\unhbox\@labels + \the \choice@toks}% + % \edef\append@everypar{\noexpand\everypar={\the\everypar + % \noexpand\the \noexpand\choice@toks}}% + % \append@everypar +}% do@choice@pageinfo + + + +% Added 22 April 2004: Increased the \leftmargin by 2.5em, +% so the choices will be visibly indented. +\newenvironment{choices}% + {\list{\choicelabel}% + {\usecounter{choice}\def\makelabel##1{\hss\llap{##1}}% + \settowidth{\leftmargin}{W.\hskip\labelsep\hskip 2.5em}% + \def\choice{% + \if@correctchoice + \color@endgroup + \endgroup + \fi + \item + \do@choice@pageinfo + } % choice + \def\CorrectChoice{% + \if@correctchoice + \color@endgroup + \endgroup + \fi + \ifprintanswers + % We can't say \choice here, because that would + % insert an \endgroup: + % 2016/05/10: We say \color@begingroup in addition to + % \begingroup in case \CorrectChoiceEmphasis involves color + % and the text exactly fills the line (which would + % otherwise create a blank line after this choice): + % 2016/05/11: We leave hmode if we're in it, + % i.e., if there's no blank line preceding this + % \CorrectChoice command. (Without this, the + % \special created by a \color{whatever} command that might + % be inserted by \CorrectChoice@Emphasis would be appended + % to the previous \choice, which could cause an extra + % (blank) line to be inserted before this \CorrectChoice.) + % Since \par and \endgraf seem to cancel \@totalleftmargin + % (for reasons I don't understand), we'll do the following: + % Motivated by the def of \leavevmode, + % \def\leavevmode{\unhbox\voidb@x} + % we will now leave hmode (if we're in hmode): + \ifhmode \unskip\unskip\unvbox\voidb@x \fi + \begingroup \color@begingroup \@correctchoicetrue + \CorrectChoice@Emphasis + \fi + \item + \do@choice@pageinfo + } % CorrectChoice + \let\correctchoice\CorrectChoice + \labelwidth\leftmargin\advance\labelwidth-\labelsep + \topsep=0pt + \partopsep=0pt + \choiceshook + }% + }% + {\if@correctchoice \color@endgroup \endgroup \fi \endlist} + +\newenvironment{oneparchoices}% + {% + \setcounter{choice}{0}% + \def\choice{% + \if@correctchoice \endgroup \fi + \refstepcounter{choice}% + \ifnum\value{choice}>1\relax + \penalty -50\hskip 1em plus 1em\relax + \fi + \choicelabel + % No need to put the following into a token string; we just put + % the choicelabel onto the page, so we're at the spot whose page + % number we want to record: + \questionobject@pluspagecheck + \nobreak\enskip + }% choice + \def\CorrectChoice{% + \if@correctchoice \endgroup \fi + \refstepcounter{choice}% + \ifprintanswers + \begingroup \@correctchoicetrue + \CorrectChoice@Emphasis + \fi + \ifnum\value{choice}>1\relax + \penalty -50\hskip 1em plus 1em\relax + \fi + \choicelabel + % No need to put the following into a token string; we just put + % the choicelabel onto the page, so we're at the spot whose page + % number we want to record: + \questionobject@pluspagecheck + \nobreak\enskip + }% CorrectChoice + \let\correctchoice\CorrectChoice + \let\par\@empty + % If we're continuing the paragraph containing the question, + % then leave a bit of space before the first choice: + \ifvmode\else\enskip\fi + \ignorespaces + }% + {\if@correctchoice \endgroup \fi} + +\newcommand{\checkboxchar}[1]{\def\checkbox@char{#1}} +\newcommand{\checkedchar}[1]{\def\checked@char{#1}} +\checkboxchar{$\bigcirc$} +\checkedchar{$\surd$} + +\newenvironment{checkboxes}% + {\list{\checkbox@char}% + {% + \settowidth{\leftmargin}{W.\hskip\labelsep\hskip 2.5em}% + \def\choice{% + \if@correctchoice + \color@endgroup \endgroup + \fi + \item + \do@choice@pageinfo + } % choice + \def\CorrectChoice{% + \if@correctchoice + \color@endgroup \endgroup + \fi + \ifprintanswers + % We can't say \choice here, because that would + % insert an \endgroup. + % 2016/05/10: We say \color@begingroup in addition to + % \begingroup in case \CorrectChoiceEmphasis involves color + % and the text exactly fills the line (which would + % otherwise create a blank line after this choice): + % 2016/05/11: We leave hmode if we're in it, + % i.e., if there's no blank line preceding this + % \CorrectChoice command. (Without this, the + % \special created by a \color{whatever} command that might + % be inserted by \CorrectChoice@Emphasis would be appended + % to the previous \choice, which could cause an extra + % (blank) line to be inserted before this \CorrectChoice.) + % Since \par and \endgraf seem to cancel \@totalleftmargin + % (for reasons I don't understand), we'll do the following: + % Motivated by the def of \leavevmode, + % \def\leavevmode{\unhbox\voidb@x} + % we will now leave hmode (if we're in hmode): + \ifhmode \unskip\unskip\unvbox\voidb@x \fi + \begingroup \color@begingroup \@correctchoicetrue + \CorrectChoice@Emphasis + \item[\checked@char] + \else + \item + \fi + \do@choice@pageinfo + } % CorrectChoice + \let\correctchoice\CorrectChoice + \labelwidth\leftmargin\advance\labelwidth-\labelsep + \topsep=0pt + \partopsep=0pt + \checkboxeshook + }% + }% + {\if@correctchoice \color@endgroup \endgroup \fi \endlist} + +\newenvironment{oneparcheckboxes}% + {% + % Although we're not printing numbers for the choices, we use the + % choice counter to keep track of whether a choice is the first + % one (in which case we don't leave any additional space) or a + % later one (in which case we do leave additional space): + \setcounter{choice}{0}% + \def\choice{% + \if@correctchoice \endgroup \fi + \stepcounter{choice}% + \ifnum\value{choice}>1\relax + \penalty -50\hskip 1em plus 1em\relax + \fi + \checkbox@char + % No need to put the following into a token string; we just put + % \checkbox@char onto the page, so we're at the spot whose page + % number we want to record: + \questionobject@pluspagecheck + \nobreak\enskip + }% choice + \def\CorrectChoice{% + \if@correctchoice \endgroup \fi + \stepcounter{choice}% + \ifprintanswers + \begingroup \@correctchoicetrue + \CorrectChoice@Emphasis + \fi + \ifnum\value{choice}>1\relax + \penalty -50\hskip 1em plus 1em\relax + \fi + \ifprintanswers + \checked@char + \else + \checkbox@char + \fi + % No need to put the following into a token string; we just put + % the choicelabel onto the page, so we're at the spot whose page + % number we want to record: + \questionobject@pluspagecheck + \nobreak\enskip + }% CorrectChoice + \let\correctchoice\CorrectChoice + \let\par\@empty + % If we're continuing the paragraph containing the question, + % then leave a bit of space before the first choice: + \ifvmode\else\enskip\fi + \ignorespaces + }% + {\if@correctchoice \endgroup \fi} + + +%-------------------------------------------------------------------- +% Answer Lines (for short answer questions) + +% Note: \ques@ref is also used in \item@points@pageinfo, and all four +% of the following are used in \setup@point@toks + +\def\ques@ref{question} +\def\part@ref{part} +\def\subpart@ref{subpart} +\def\subsubpart@ref{subsubpart} + +% Note: \answerclearance is also used by \fillin + +\newlength\answerlinelength +\newlength\answerskip +\newlength\answerclearance +\setlength\answerlinelength{1in} +\setlength\answerskip{2ex} +\setlength\answerclearance{0.2ex} + +\newcommand\answerline[1][{}]{% + % One optional argument, the default value of which is empty. + \ifx\@queslevel\ques@ref + \let\ans@l=\questionlabel + \else + \ifx\@queslevel\part@ref + \let\ans@l=\partlabel + \else + \ifx\@queslevel\subpart@ref + \let\ans@l=\subpartlabel + \else + \ifx\@queslevel\subsubpart@ref + \let\ans@l=\subsubpartlabel + \else + % Oops; no question level defined. + % We must be outide of the questions environment. + % Just leave out the label, I guess: + \def\ans@l{}% + \fi + \fi + \fi + \fi + \par \nobreak \vskip \answerskip + \hfill + \ifprintanswers + \ans@l~\hbox to 0pt{\hbox to \answerlinelength{\hrulefill}\hss}% + \raise \answerclearance\hbox to \answerlinelength{% + % 2016/05/10: Added \color@begingroup and \color@endgroup: + \color@begingroup + \CorrectChoice@Emphasis \hfil #1\hss + \color@endgroup}% + \else + \ans@l~\hbox to \answerlinelength{\hrulefill}% + \fi + \par +}% answerline + +%-------------------------------------------------------------------- +% \fillin, for fill-in-the-blank questions + +\newlength\fillinlinelength +\setlength\fillinlinelength{1in} + +% \fillin can take two optional arguments. +% +% 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 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. +% +% \fillin eats (and ignores) space characters appearing before the +% first optional argument. It also eats (and ignores) space +% characters appearing after the first optional argument and before +% the second optional argument. However, if exactly one optional +% argument appears, and if there are one or more space characters +% following that one optional argument, then those spaces are replaced +% by a single space character, but not eaten. + +\newcommand\fillin[1][{}]{% + \def\fillin@ans{#1}% + \fillin@relay +}% fillin + +\newcommand\fillin@relay{% + % We use \exam@ifnextchar, a variation on \@ifnextchar. + % If \exam@ifnextchar encounters one or more space characters + % followed by a [, then those spaces are ignored (just as they would + % be by \@ifnextchar). However, if one or more space characters are + % followed by a non-space character other than [, then + % \exam@ifnextchar inserts a space following the + % {\@fillin@relay[\fillinlinelength]} that is the third argument to + % \exam@ifnextchar. + \exam@ifnextchar[{\@fillin@relay} + {\@fillin@relay[\fillinlinelength]}% +}% fillin@relay + +\def\@fillin@relay[#1]{% + % The first argument is in \fillin@ans, the second is #1. + \leavevmode + \ifprintanswers + \rlap{\raise -\answerclearance \hbox to #1{\hrulefill}}% + \begingroup + \setbox0 \hbox{\color@begingroup + \CorrectChoice@Emphasis \fillin@ans \color@endgroup}% + \ifdim\wd0 > #1\relax + \hbox{\color@begingroup\CorrectChoice@Emphasis \fillin@ans + \color@endgroup}% + \else + \hbox to #1{\color@begingroup\CorrectChoice@Emphasis + \hfil \fillin@ans \hfil\color@endgroup}% + \fi + \endgroup + \else + \raise -\answerclearance \hbox to #1{\hrulefill}% + \fi +}% @fillin@relay + +% \exam@ifnextchar is used by \fillin. +% \exam@ifnextchar is a variation of \@ifnextchar that does not always +% ignore space tokens. If \exam@ifnextchar encounters one or more +% space tokens, it makes note of that (with the command +% \@tempswatrue). If the first non-space character encountered +% matches argument #1, then any spaces that had been encountered are +% ignored. However, if one or more spaces are encountered and the +% first non-space character found does not match argument #1, then +% \exam@ifnextchar produces argument #3 followed by a space character. +% (This differs from the behavior of \new@ifnextchar in amsgen.sty, +% which does lookahead for any character, including a space.) This +% code (as well as the idea for it) is due to Dan Luecking and Ulrich +% Diez. +\long\def\exam@ifnextchar#1#2#3{% + \let\reserved@d=#1% + \def\reserved@a{#2}% + \def\reserved@b{#3}% + % The following says we haven't yet seen any spaces: + \@tempswafalse + \futurelet\@let@token\exam@ifnch +}% exam@ifnextchar + +\def\exam@ifnch{% + \ifx\@let@token\@sptoken + % Signal that we've found a space: + \@tempswatrue + \let\reserved@c\exam@xifnch % this gobbles the space + \else + \ifx\@let@token\reserved@d + \let\reserved@c\reserved@a + \else + \if@tempswa + \def\reserved@c{\expandafter\reserved@b\space}% + \else + \let\reserved@c\reserved@b + \fi + \fi + \fi + \reserved@c +}% exam@ifnch + +% The following defines \exam@xifnch so that it will eat a space +% following it and then call \exam@ifnch: +{% keep redefinition of \: local + \def\:{\exam@xifnch} + \expandafter\gdef\: {\futurelet\@let@token\exam@ifnch} +} + +%-------------------------------------------------------------------- +% \fillwithlines + + +% \fillwithlines takes one argument, which is either a length or \fill +% or \stretch{number}, and it fills that much vertical space with +% horizontal lines that run the length of the current line. That is, +% they extend from the current left margin (which depends on whether +% we're in a question, part, subpart, or subsubpart) to the right +% margin. +% +% The distance between the lines is \linefillheight, whose default value +% is set with the command +% +% \setlength\linefillheight{.25in} +% +% This value can be changed by giving a new \setlength command. +% +% The thickness of the lines is \linefillthickness, whose default value +% is set with the command +% +% \setlength\linefillthickness{.1pt} +% +% This value can be changed by giving a new \setlength command. +% +% As of version 2.503, 2016/03/25, the lines drawn by the +% \fillwithlines command will be drawn in color if the user has given +% the command +% +% \colorfillwithlines. +% +% The actual drawing of the lines is now done by the command +% \do@fillwithlines, after the \fillwithlines command decides whether +% they will be in color. The default color is set by the command +% +% \definecolor{FillWithLinesColor}{gray}{0.8} +% +% and the color can be changed by giving a new \definecolor command. +% You can return to black lines by giving the command +% +% \nocolorfillwithlines + +\newlength\linefillheight +\newlength\linefillthickness +\setlength\linefillheight{.25in} +\setlength\linefillthickness{0.1pt} + + + + +\newif\if@colorfillwithlines +\@colorfillwithlinesfalse +\def\colorfillwithlines{% + \@ifundefined{definecolor} + {% + \ClassError{exam}{% + You must load the color package with the command\MessageBreak + \space\space\protect\usepackage{color}\MessageBreak + in order to use the command \protect\colorfillwithlines + \MessageBreak + }{% + This command makes use of the package color.sty,\MessageBreak + and so you have to load color.sty before your\MessageBreak + \protect\begin{document} command.\MessageBreak + }% + }% + {% + \definecolor{FillWithLinesColor}{gray}{0.8} + \@colorfillwithlinestrue + }% +}% \colorfillwithlines +\def\nocolorfillwithlines{\@colorfillwithlinesfalse} + +\newcommand\fillwithlines[1]{% + \if@colorfillwithlines + \color@begingroup + \color{FillWithLinesColor}% + \do@fillwithlines{#1}% + \color@endgroup + \else + \do@fillwithlines{#1}% + \fi +}% \fillwithlines + +\newcommand\linefill{\leavevmode + \leaders\hrule height \linefillthickness \hfill\kern\z@} + +% \do@fillwithlines is called only by \fillwithlines +\def\do@fillwithlines#1{% + \begingroup + \ifhmode + \par + \fi + \hrule height \z@ + \nobreak + \setbox0=\hbox to \hsize{\hskip \@totalleftmargin + \vrule height \linefillheight depth \z@ width \z@ + \linefill}% + % We use \cleaders (rather than \leaders) so that a given + % vertical space will always produce the same number of lines + % no matter where on the page it happens to start: + \cleaders \copy0 \vskip #1 \hbox{}% + \endgroup +}% \do@fillwithlines + +%-------------------------------------------------------------------- +% \fillwithdottedlines + + +% \fillwithdottedlines is similar to \fillwithlines, except that it +% fills the space with dotted lines (created by \dotfill) rather than +% with solid lines. + +% \fillwithdottedlines takes one argument, which is either a length or +% \fill or \stretch{number}, and it fills that much vertical space +% with dotted lines that run the length of the current line. That is, +% they extend from the current left margin (which depends on whether +% we're in a question, part, subpart, or subsubpart) to the right +% margin. +% +% The distance between the lines is \dottedlinefillheight, whose +% default value is set with the command +% +% \setlength\dottedlinefillheight{.25in} +% +% This value can be changed by giving a new \setlength command. + +% As of version 2.503, 2016/03/25, the dotted lines drawn by the +% \fillwithdottedlines command will be drawn in color if the user has +% given the command +% +% \colorfillwithdottedlines. +% +% The actual drawing of the lines is now done by the command +% \do@fillwithdottedlines, after the \fillwithdottedlines command +% decides whether they will be in color. The default color is set by +% the command +% +% \definecolor{FillWithDottedLinesColor}{gray}{0.8} +% +% and the color can be changed by giving a new \definecolor command. +% You can return to black lines by giving the command +% +% \nocolorfillwithdottedlines + + +\newlength\dottedlinefillheight +\setlength\dottedlinefillheight{.25in} + +\newif\if@colorfillwithdottedlines +\@colorfillwithdottedlinesfalse +\def\colorfillwithdottedlines{% + \@ifundefined{definecolor} + {% + \ClassError{exam}{% + You must load the color package with the command\MessageBreak + \space\space\protect\usepackage{color}\MessageBreak + in order to use the command \protect\colorfillwithdottedlines + \MessageBreak + }{% + This command makes use of the package color.sty,\MessageBreak + and so you have to load color.sty before your\MessageBreak + \protect\begin{document} command.\MessageBreak + }% + }% + {% + \definecolor{FillWithDottedLinesColor}{gray}{0.8} + \@colorfillwithdottedlinestrue + }% +}% \colorfillwithdottedlines +\def\nocolorfillwithdottedlines{\@colorfillwithdottedlinesfalse} + +\newcommand\fillwithdottedlines[1]{% + \if@colorfillwithdottedlines + \color@begingroup + \color{FillWithDottedLinesColor}% + \do@fillwithdottedlines{#1}% + \color@endgroup + \else + \do@fillwithdottedlines{#1}% + \fi +}% \fillwithdottedlines + +% \do@fillwithdottedlines is called only by \fillwithdottedlines +\def\do@fillwithdottedlines#1{% + \begingroup + \ifhmode + \par + \fi + \hrule height \z@ + \nobreak + \setbox0=\hbox to \hsize{\hskip \@totalleftmargin + \vrule height \dottedlinefillheight depth \z@ width \z@ + \dotfill}% + % We use \cleaders (rather than \leaders) so that a given + % vertical space will always produce the same number of lines + % no matter where on the page it happens to start: + \cleaders \copy0 \vskip #1 \hbox{}% + \endgroup +}% \do@fillwithdottedlines + +%-------------------------------------------------------------------- +% \fillwithgrid + + +% \fillwithgrid is similar to \fillwithlines, except that it +% fills the space with a grid. + +% \fillwithgrid takes one argument, which is either a length or \fill +% or \stretch{number}, and it fills that much vertical space with a +% grid that runs the length of the current line. That is, it extends +% from the current left margin (which depends on whether we're in a +% question, part, subpart, or subsubpart) to the right margin. +% +% 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. + +% 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 by giving +% a new \definecolor command. + +\newif\if@colorgrids +\newcommand\colorgrids{% + \@ifundefined{definecolor} + {% + \ClassError{exam}{% + You must load the color package with the command\MessageBreak + \space\space\protect\usepackage{color}\MessageBreak + in order to use the command \protect\colorgrids + }{% + This command makes use of the package color.sty,\MessageBreak + and so you have to load color.sty before your\MessageBreak + \protect\begin{document} command.\MessageBreak + }% + }% + {% + \definecolor{GridColor}{gray}{0.8} + \@colorgridstrue + }% +}% \colorgrids +\newcommand\nocolorgrids{\@colorgridsfalse} +\nocolorgrids + +\newlength\gridsize +\newlength\gridlinewidth +\setlength{\gridsize}{5mm} +\setlength{\gridlinewidth}{0.1pt} + +\def\fillwithgrid#1{% + \begingroup + \ifhmode + \par + \fi + \hrule height \z@ + \nobreak + + % We first set box0 equal to an \hbox which, when printed, is a + % square with width and height equal to \gridsize+\gridlinewidth, + % but which has + % width equal to \gridsize, + % height equal to \gridsize, and + % depth equal to 0pt. + % When we put multiple copies of it together using \leaders or + % \cleaders, the right edge will coincide with the left edge of the + % next box and the bottom edge will coincide with the top edge of + % the box below it. + \setlength{\@tempdima}{\gridsize} + \addtolength{\@tempdima}{\gridlinewidth} + \setlength{\@tempdimb}{\gridsize} + \addtolength{\@tempdimb}{-\gridlinewidth} + \setbox0=\hbox{% + \rlap{\vrule height \gridsize depth \gridlinewidth width \gridlinewidth}% + \rlap{\vrule height \gridsize depth -\@tempdimb width \@tempdima}% + \vrule height 0pt depth \gridlinewidth width \@tempdima + \llap{\vrule height \gridsize depth \gridlinewidth width \gridlinewidth}% + }% + \wd0=\gridsize + \dp0=0pt + % Now we set box1 equal to an \hbox containing a single line of + % copies of box0. We use \leaders (instead of \cleaders) so that + % if we use it twice on a page, once with a question and once + % with a part, the boxes will line up vertically. We add a kern of + % \gridlinewidth at the right because the rightmost vertical line + % appears to the right of where the \leaders command thinks that it + % appears. + \setbox1=\hbox to \textwidth{% + \color@begingroup + \if@colorgrids + \color{GridColor}% + \fi + \hskip \@totalleftmargin \leaders\copy0\hfil \kern\gridlinewidth + \color@endgroup + }% + % Finally: We create the grid, using \cleaders: We use \cleaders + % (rather than \leaders) so that a given vertical space will always + % produce the same number of lines no matter where on the page it + % happens to start. We add a kern of \gridlinewidth because the + % bottommost horizontal line appears below where the \cleaders + % command thinks that it appears. + \cleaders \copy1 \vskip #1 \kern \gridlinewidth \hbox{}% + \endgroup +}% fillwithgrid + +%-------------------------------------------------------------------- +% \makeemptybox + +% \makeemptybox takes one argument, which is a length, and it creates +% an empty box of width the length of the current line and of height +% equal to the argument. That is, the box extends from the current +% left margin (which depends on whether we're in a question, part, +% subpart, or subsubpart) to the right margin. + +% As of version 2.304, the argument of \makeemptybox can be either +% a length, or \fill, or \stretch{number}. + +% \newcommand\makeemptybox[1]{ +% \par +% \begingroup +% \setlength{\fboxsep}{0pt}% +% \framebox[\linewidth]{% +% \vrule height 0pt depth #1 width 0pt +% }% +% \endgroup +% } + +\newlength\minboxheight +\setlength\minboxheight{.1in} + + +% As of version 2.502, 2016/03/23, the frame drawn by the +% \makeemptybox command will be drawn in color if the user has given +% the command \colorsolutionboxes. The actual drawing of the box is +% now done by the command \do@emptybox, after the \makeemptybox +% command decides whether it will be in color. + +\newcommand\makeemptybox[1]{% + \if@colorsolutionboxes + \color@begingroup + \color{SolutionBoxColor}% + \do@emptybox{#1}% + \color@endgroup + \else + \do@emptybox{#1}% + \fi +} + +% The command \do@emptybox is called only by \makeemptybox. +\newcommand\do@emptybox[1]{% + \par + \hbox to \hsize{\hskip\@totalleftmargin \leaders\hrule\hfill}% + \nointerlineskip + \begingroup + \setbox0=\hbox to \hsize{\hskip\@totalleftmargin + \vrule height\minboxheight \hfill \vrule}% + % The vertical size desired may not be an exact multiple of + % \minboxheight, and so \cleaders might leave a gap between the + % vertical lines and the horizontal lines above and below it. + % Thus, we put a single copy of \box0 immediately below the + % horizontal line above and we'll also put a single copy of \box0 + % immediately above the horizontal line below. + \copy0 + \nobreak + \vskip -\minboxheight + \cleaders \copy0 \vskip #1 + \vskip -\minboxheight + \nointerlineskip + \copy0 + \endgroup + \nointerlineskip + \hbox to \hsize{\hskip\@totalleftmargin \leaders\hrule\hfill}% +} + +%-------------------------------------------------------------------- +% \uplevel and \fullwidth +% and the EnvUplevel and EnvFullwidth environments: + +% \uplevel is used to print text at the indentation level of the +% enclosing environment. For example, to precede a question with +% directions about how that question should be answered, you would +% say \uplevel{Answer this question correctly.} +% +% \fullwidth is similar, but uses the full page of text on the page. + +% The EnvUplevel environment is similar to the \uplevel command, but it +% has the advantage that you can include verbatim material (using, e.g., +% the \verb command) in the environment. (You can't include verbatim +% material in the argument of an \uplevel command.) + +% The EnvFullwidth environment is similar to the \fullwidth command, but +% it has the advantage that you can include verbatim material (using, +% e.g., the \verb command) in the environment. (You can't include +% verbatim material in the argument of an \fullwidth command.) + + +\long\def\uplevel#1{% + \par\bigskip + \vbox{% + % We entered internal vertical mode, and so we get \parshape=0. + % We set \leftskip to provide the correct left margin for whatever + % is in the argument of the \uplevel command: + \leftskip=\@totalleftmargin + \advance\leftskip-\leftmargin + % We adjust \@totalleftmargin and linewidth in case there's a + % solution environment inside of the argument to the \uplevel: + \advance\@totalleftmargin-\leftmargin + \advance\linewidth\leftmargin + #1% + }% vbox + \nobreak +} + +\newenvironment{EnvUplevel} + {\par\bigskip\vbox\bgroup + % We set \leftskip to provide the correct left margin for whatever + % is inside of the environment: + \leftskip=\@totalleftmargin + \advance\leftskip-\leftmargin + % We adjust \@totalleftmargin (and linewidth?) in case there's a + % solution environment inside of the environment: + \advance\@totalleftmargin-\leftmargin + \advance\linewidth\leftmargin + } + {\egroup\nobreak} + + +\long\def\fullwidth#1{% + \par\bigskip + \vbox{% + % We entered internal vertical mode, and so we get \parshape=0. + \leftskip=0pt \rightskip=0pt + \advance\linewidth\@totalleftmargin + \@totalleftmargin=0pt + #1% + }% vbox + \nobreak +} + +\newenvironment{EnvFullwidth} + {\par\bigskip\vbox\bgroup + % We entered internal vertical mode, and so we get \parshape=0. + \leftskip=0pt \rightskip=0pt + % We adjust \@totalleftmargin (and linewidth?) in case there's a + % solution environment inside of the environment: + \advance\linewidth\@totalleftmargin + \@totalleftmargin=0pt + } + {\egroup\nobreak} + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% +% ******************** +% ** GRADING TABLES ** +% ******************** + + + +\newcounter{@iterator} +\newlength\@cellwidth + +\def\cellwidth#1{\@cellwidth=#1} +\def\gradetablestretch#1{\def\@gtblstretch{#1}} + +% \settabletotalpoints allows the user to specify a total +% number of points to appear in a table that may be different +% from the sum of the points in the table: +\newcommand\prt@tablepoints{\prt@hlfcntr{tbl@points}} +\newcommand\settabletotalpoints[1]{% + \def\prt@tablepoints{#1}% +}% \settabletotalpoints + +% \settabletotalbonuspoints is similar to \settabletotalpoints: +\newcommand\prt@tablebonuspoints{\prt@hlfcntr{tbl@bonuspoints}} +\newcommand\settabletotalbonuspoints[1]{% + \def\prt@tablebonuspoints{#1}% +}% \settabletotalbonuspoints + +% All of the following that begin with `h' are for horizontal tables, +% and all of them that begin with `v' are for vertical tables: +\def\hqword#1{\def\@hqword{#1}} +\def\hpword#1{\def\@hpword{#1}} +\def\hsword#1{\def\@hsword{#1}} +\def\htword#1{\def\@htword{#1}} +\def\hpgword#1{\def\@hpgword{#1}} + +\def\vqword#1{\def\@vqword{#1}} +\def\vpword#1{\def\@vpword{#1}} +\def\vsword#1{\def\@vsword{#1}} +\def\vtword#1{\def\@vtword{#1}} +\def\vpgword#1{\def\@vpgword{#1}} + + +% The following are the versions for bonusgradetable: +\def\bhqword#1{\def\@bhqword{#1}} +\def\bhpword#1{\def\@bhpword{#1}} +\def\bhsword#1{\def\@bhsword{#1}} +\def\bhtword#1{\def\@bhtword{#1}} +\def\bhpgword#1{\def\@bhpgword{#1}} + +\def\bvqword#1{\def\@bvqword{#1}} +\def\bvpword#1{\def\@bvpword{#1}} +\def\bvsword#1{\def\@bvsword{#1}} +\def\bvtword#1{\def\@bvtword{#1}} +\def\bvpgword#1{\def\@bvpgword{#1}} + +% The following are the versions for combinedgradetable: +\def\chqword#1{\def\@chqword{#1}} +\def\chpword#1{\def\@chpword{#1}} +\def\chbpword#1{\def\@chbpword{#1}} +\def\chsword#1{\def\@chsword{#1}} +\def\chtword#1{\def\@chtword{#1}} +\def\chpgword#1{\def\@chpgword{#1}} + +\def\cvqword#1{\def\@cvqword{#1}} +\def\cvpword#1{\def\@cvpword{#1}} +\def\cvbpword#1{\def\@cvbpword{#1}} +\def\cvsword#1{\def\@cvsword{#1}} +\def\cvtword#1{\def\@cvtword{#1}} +\def\cvpgword#1{\def\@cvpgword{#1}} + + + +% Initialize: +\cellwidth{2em} +\gradetablestretch{1.5} + +\hqword{Question:} +\hpgword{Page:} +\hpword{Points:} +\hsword{Score:} +\htword{Total} +\vpword{Points} +\vsword{Score} +\vtword{Total:} +\vqword{Question} +\vpgword{Page} + +\bhqword{Question:} +\bhpgword{Page:} +\bhpword{Bonus Points:} +\bhsword{Score:} +\bhtword{Total} +\bvqword{Question} +\bvpgword{Page} +\bvpword{Bonus Points} +\bvsword{Score} +\bvtword{Total:} + +\chqword{Question:} +\chpgword{Page:} +\chpword{Points:} +\chbpword{Bonus Points:} +\chsword{Score:} +\chtword{Total} +\cvqword{Question} +\cvpgword{Page} +\cvpword{Points} +\cvbpword{Bonus Points} +\cvsword{Score} +\cvtword{Total:} + +% Before we created multirow and multicolumn tables, he only commands +% here accessible to the user were \gradetable, \bonusgradetable, +% \combinedgradetable, \pointtable, \bonuspointtable, +% \combinedpointtable, \partialgradetable, +% \partialbonusgradetable, \partialcombinedtable, \partialpointtable, +% \partialbonuspointtable, \partialcombinedpointtable, +% \begingradingrange, \endgradingrange, \pointsinrange, +% \bonuspointsinrange, \firstqinrange, \lastqinrange, and +% \numqinrange. The new user commands are +% +% \def\multirowgradetable +% \def\multirowpointtable +% \def\multirowbonusgradetable +% \def\multirowbonuspointtable +% \def\multirowcombinedgradetable +% \def\multirowcombinedpointtable +% +% \def\multirowpartialgradetable +% \def\multirowpartialpointtable +% \def\multirowpartialbonusgradetable +% \def\multirowpartialbonuspointtable +% \def\multirowpartialcombinedgradetable +% \def\multirowpartialcombinedpointtable +% +% \def\multicolumngradetable +% \def\multicolumnpointtable +% \def\multicolumnbonusgradetable +% \def\multicolumnbonuspointtable +% \def\multicolumncombinedgradetable +% \def\multicolumncombinedpointtable +% +% \def\multicolumnpartialgradetable +% \def\multicolumnpartialpointtable +% \def\multicolumnpartialbonusgradetable +% \def\multicolumnpartialbonuspointtable +% \def\multicolumnpartialcombinedgradetable +% \def\multicolumnpartialcombinedpointtable + + +% The possibilities are + +% \gradetable[v][questions] +% \gradetable[v][pages] +% \gradetable[h][questions] +% \gradetable[h][pages] + +% \bonusgradetable[v][questions] +% \bonusgradetable[v][pages] +% \bonusgradetable[h][questions] +% \bonusgradetable[h][pages] + +% \combinedgradetable[v][questions] +% \combinedgradetable[v][pages] +% \combinedgradetable[h][questions] +% \combinedgradetable[h][pages] + +% \pointtable[v][questions] +% \pointtable[v][pages] +% \pointtable[h][questions] +% \pointtable[h][pages] + +% \bonuspointtable[v][questions] +% \bonuspointtable[v][pages] +% \bonuspointtable[h][questions] +% \bonuspointtable[h][pages] + +% \combinedpointtable[v][questions] +% \combinedpointtable[v][pages] +% \combinedpointtable[h][questions] +% \combinedpointtable[h][pages] + +% \partialgradetable{whatever}[v][questions] +% \partialgradetable{whatever}[v][pages] +% \partialgradetable{whatever}[h][questions] +% \partialgradetable{whatever}[h][pages] + +% \partialbonusgradetable{whatever}[v][questions] +% \partialbonusgradetable{whatever}[v][pages] +% \partialbonusgradetable{whatever}[h][questions] +% \partialbonusgradetable{whatever}[h][pages] + +% \partialcombinedgradetable{whatever}[v][questions] +% \partialcombinedgradetable{whatever}[v][pages] +% \partialcombinedgradetable{whatever}[h][questions] +% \partialcombinedgradetable{whatever}[h][pages] + +% \partialpointtable{whatever}[v][questions] +% \partialpointtable{whatever}[v][pages] +% \partialpointtable{whatever}[h][questions] +% \partialpointtable{whatever}[h][pages] + +% \partialbonuspointtable{whatever}[v][questions] +% \partialbonuspointtable{whatever}[v][pages] +% \partialbonuspointtable{whatever}[h][questions] +% \partialbonuspointtable{whatever}[h][pages] + +% \partialcombinedpointtable{whatever}[v][questions] +% \partialcombinedpointtable{whatever}[v][pages] +% \partialcombinedpointtable{whatever}[h][questions] +% \partialcombinedpointtable{whatever}[h][pages] + +% \begingradingrange{whatever} +% \endgradingrange{whatever} +% +% \pointsinrange{whatever} +% \bonuspointsinrange{whatever} +% +% \firstqinrange{whatever} +% \lastqinrange{whatever} +% \numqinrange{whatever} +% +% where ``whatever'' is a label chosen by the user. +% +% \def\multirowgradetable{numcols}[questions or pages] +% \def\multirowpointtable{numcols}[questions or pages] +% \def\multirowbonusgradetable{numcols}[questions or pages] +% \def\multirowbonuspointtable{numcols}[questions or pages] +% \def\multirowcombinedgradetable{numcols}[questions or pages] +% \def\multirowcombinedpointtable{numcols}[questions or pages] +% +% \def\multirowpartialgradetable{numcols}{rangename}[questions or pages] +% \def\multirowpartialpointtable{numcols}{rangename}[questions or pages] +% \def\multirowpartialbonusgradetable{numcols}{rangename}[questions or pages] +% \def\multirowpartialbonuspointtable{numcols}{rangename}[questions or pages] +% \def\multirowpartialcombinedgradetable{numcols}{rangename}[questions or pages] +% \def\multirowpartialcombinedpointtable{numcols}{rangename}[questions or pages] +% +% \def\multicolumngradetable{numrows}[questions or pages] +% \def\multicolumnpointtable{numrows}[questions or pages] +% \def\multicolumnbonusgradetable{numrows}[questions or pages] +% \def\multicolumnbonuspointtable{numrows}[questions or pages] +% \def\multicolumncombinedgradetable{numrows}[questions or pages] +% \def\multicolumncombinedpointtable{numrows}[questions or pages] + +% \def\multicolumnpartialgradetable{numrows}{rangename}[questions or pages] +% \def\multicolumnpartialpointtable{numrows}{rangename}[questions or pages] +% \def\multicolumnpartialbonusgradetable{numrows}{rangename}[questions or pages] +% \def\multicolumnpartialbonuspointtable{numrows}{rangename}[questions or pages] +% \def\multicolumnpartialcombinedgradetable{numrows}{rangename}[questions or pages] +% \def\multicolumnpartialcombinedpointtable{numrows}{rangename}[questions or pages] + + +% If one or both optional arguments are omitted, the defaults are +% `[v]' and `[questions]'. + +% \@scorestrue means we're doing \gradetable +% \@scoresfalse mans we're doing \pointtable +\newif\if@scores + +% \@partialtrue means we're doing \partialgradetable, +% \partialbonusgradetable, \partialcombinedgradetable, +% \partialpointtable, \partialbonuspointtable, or +% \partialcombinedpointtable: +\newif\if@partial + +% \@combinedtrue means we're doing \combinedgradetable, +% \combinedpointtable, \partialcombinedgradetable, or +% \partialcombinedpointtable: +\newif\if@combined + +% It's OK to use the counter num@cols as a scratch counter +% in \begingradingrange and \endgradingrange because +% it's only used in typesetting tables: +\def\begingradingrange#1{% + \setcounter{num@cols}{\value{question}}% + \addtocounter{num@cols}{1}% + \immediate\write\@mainaux + {\string\expandafter\string\gdef + \string\csname\space range@#1@firstq\string\endcsname + {\arabic{num@cols}}}% + \write\@mainaux + {\string\expandafter\string\gdef + \string\csname\space range@#1@firstp\string\endcsname + {\thepage}}% +}% begingradingrange + +\def\endgradingrange#1{% + \setcounter{num@cols}{\value{question}}% + \immediate\write\@mainaux + {\string\expandafter\string\gdef + \string\csname\space range@#1@lastq\string\endcsname + {\arabic{num@cols}}}% + \write\@mainaux + {\string\expandafter\string\gdef + \string\csname\space range@#1@lastp\string\endcsname + {\thepage}}% +}% endgradingrange + + +% Now that grading tables may be for only part of the exam, +% we need the counter tbl@points to add up the total points +% for the questions (or pages) that appear on the table: +\new@hlfcntr{tbl@points} + +% We'll use the counter tbl@bonuspoints to add up the total bonus +% points for the questions (or pages) that appear on the table: +\new@hlfcntr{tbl@bonuspoints} + +%-------------------------------------------------------------------- +% multirow tables, non-partial: + +\def\multirowgradetable#1{% + \@scorestrue + \@bonusfalse + \@partialfalse + \@combinedfalse + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +\def\multirowpointtable#1{% + \@scoresfalse + \@bonusfalse + \@partialfalse + \@combinedfalse + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +\def\multirowbonusgradetable#1{% + \@scorestrue + \@bonustrue + \@partialfalse + \@combinedfalse + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +\def\multirowbonuspointtable#1{% + \@scoresfalse + \@bonustrue + \@partialfalse + \@combinedfalse + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +\def\multirowcombinedgradetable#1{% + \@scorestrue + \@bonusfalse + \@partialfalse + \@combinedtrue + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +\def\multirowcombinedpointtable#1{% + \@scoresfalse + \@bonusfalse + \@partialfalse + \@combinedtrue + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +%-------------------------------------------------------------------- +% multirow tables, partial: + +\def\multirowpartialgradetable#1#2{% + \@scorestrue + \@bonusfalse + \@partialtrue + \@combinedfalse + \def\tbl@range{#2}% + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +\def\multirowpartialpointtable#1#2{% + \@scoresfalse + \@bonusfalse + \@partialtrue + \@combinedfalse + \def\tbl@range{#2}% + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +\def\multirowpartialbonusgradetable#1#2{% + \@scorestrue + \@bonustrue + \@partialtrue + \@combinedfalse + \def\tbl@range{#2}% + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +\def\multirowpartialbonuspointtable#1#2{% + \@scoresfalse + \@bonustrue + \@partialtrue + \@combinedfalse + \def\tbl@range{#2}% + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +\def\multirowpartialcombinedgradetable#1#2{% + \@scorestrue + \@bonusfalse + \@partialtrue + \@combinedtrue + \def\tbl@range{#2}% + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +\def\multirowpartialcombinedpointtable#1#2{% + \@scoresfalse + \@bonusfalse + \@partialtrue + \@combinedtrue + \def\tbl@range{#2}% + \setcounter{num@rows}{#1}% + \i@gtable[h]% +} + +%-------------------------------------------------------------------- +% multicolumn tables, non-partial: + +\def\multicolumngradetable#1{% + \@scorestrue + \@bonusfalse + \@partialfalse + \@combinedfalse + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +\def\multicolumnpointtable#1{% + \@scoresfalse + \@bonusfalse + \@partialfalse + \@combinedfalse + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +\def\multicolumnbonusgradetable#1{% + \@scorestrue + \@bonustrue + \@partialfalse + \@combinedfalse + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +\def\multicolumnbonuspointtable#1{% + \@scoresfalse + \@bonustrue + \@partialfalse + \@combinedfalse + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +\def\multicolumncombinedgradetable#1{% + \@scorestrue + \@bonusfalse + \@partialfalse + \@combinedtrue + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +\def\multicolumncombinedpointtable#1{% + \@scoresfalse + \@bonusfalse + \@partialfalse + \@combinedtrue + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +%-------------------------------------------------------------------- +% multicolumn tables, partial: + +\def\multicolumnpartialgradetable#1#2{% + \@scorestrue + \@bonusfalse + \@partialtrue + \@combinedfalse + \def\tbl@range{#2}% + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +\def\multicolumnpartialpointtable#1#2{% + \@scoresfalse + \@bonusfalse + \@partialtrue + \@combinedfalse + \def\tbl@range{#2}% + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +\def\multicolumnpartialbonusgradetable#1#2{% + \@scorestrue + \@bonustrue + \@partialtrue + \@combinedfalse + \def\tbl@range{#2}% + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +\def\multicolumnpartialbonuspointtable#1#2{% + \@scoresfalse + \@bonustrue + \@partialtrue + \@combinedfalse + \def\tbl@range{#2}% + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +\def\multicolumnpartialcombinedgradetable#1#2{% + \@scorestrue + \@bonusfalse + \@partialtrue + \@combinedtrue + \def\tbl@range{#2}% + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +\def\multicolumnpartialcombinedpointtable#1#2{% + \@scoresfalse + \@bonusfalse + \@partialtrue + \@combinedtrue + \def\tbl@range{#2}% + \setcounter{num@cols}{#1}% + \i@gtable[v]% +} + +%-------------------------------------------------------------------- +% partial single row (and column) tables: + +\def\partialgradetable#1{% + \@scorestrue + \@bonusfalse + \@partialtrue + \@combinedfalse + \def\tbl@range{#1}% + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% partialgradetable + +\def\partialbonusgradetable#1{% + \@scorestrue + \@bonustrue + \@partialtrue + \@combinedfalse + \def\tbl@range{#1}% + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% partialbonusgradetable + +\def\partialcombinedgradetable#1{% + \@scorestrue + \@bonusfalse + \@partialtrue + \@combinedtrue + \def\tbl@range{#1}% + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% partialcombinedgradetable + +\def\partialpointtable#1{% + \@scoresfalse + \@bonusfalse + \@partialtrue + \@combinedfalse + \def\tbl@range{#1}% + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% partialpointtable + +\def\partialbonuspointtable#1{% + \@scoresfalse + \@bonustrue + \@partialtrue + \@combinedfalse + \def\tbl@range{#1}% + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% partialbonuspointtable + +\def\partialcombinedpointtable#1{% + \@scoresfalse + \@bonusfalse + \@partialtrue + \@combinedtrue + \def\tbl@range{#1}% + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% partialcombinedpointtable + +%-------------------------------------------------------------------- +% single row (and column) tables, non-partial: + +\def\gradetable{% + \@scorestrue + \@bonusfalse + \@partialfalse + \@combinedfalse + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% gradetable + +\def\bonusgradetable{% + \@scorestrue + \@bonustrue + \@partialfalse + \@combinedfalse + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% bonusgradetable + +\def\combinedgradetable{% + \@scorestrue + \@bonusfalse + \@partialfalse + \@combinedtrue + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% bonusgradetable + +\def\pointtable{% + \@scoresfalse + \@bonusfalse + \@partialfalse + \@combinedfalse + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% pointtable + +\def\bonuspointtable{% + \@scoresfalse + \@bonustrue + \@partialfalse + \@combinedfalse + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% bonuspointtable + +\def\combinedpointtable{% + \@scoresfalse + \@bonusfalse + \@partialfalse + \@combinedtrue + % We don't yet know if the table is vertical or horizontal, and so + % we don't know if we need to set num@cols or num@rows. We'll set + % them both, and we'll later on just ignore the value of the one + % that we didn't need to set here: + \setcounter{num@cols}{1}% + \setcounter{num@rows}{1}% + % If the user doesn't include the optional argument + % choosing between vertical and horizontal, + % we give them vertical: + \@ifnextchar[{\i@gtable}{\i@gtable[v]}% +}% bonuspointtable + +%-------------------------------------------------------------------- + +% \i@gtable and \ii@gtable insert any missing optional arguments +% (the defaults being [v] and [questions]) and then make sure +% that the user said \addpoints and that this isn't the +% first run of LaTeX. +% \find@p@or@q@range then branches, depending on whether the user +% selected [questions] or [pages]. + +\def\i@gtable[#1]{% + % If the user doesn't include the second optional argument, + % which chooses between questions and pages, + % we give them questions: + \@ifnextchar[{\ii@gtable{#1}}{\ii@gtable{#1}[questions]}% +} +\def\ii@gtable#1[#2]{% + % We get here from \i@gtable. + % We make sure the user said \addpoints, and then make sure + % that this isn't the first run of LaTeX (by checking that + % \exam@numpoints is defined). If both of those are OK, + % we go to \find@p@or@q@range to see whether we're doing a table + % indexed by questions or by pages. + \if@addpoints + \@ifundefined{exam@numpoints}% + {\ClassWarning{exam}% + {% + You must run LaTeX again to produce the + table.\MessageBreak + }% + \fbox{Run \LaTeX{} again to produce the table}% + }% + {\find@p@or@q@range{#1}{#2}}% + \else + \ClassError{exam}{% + You must give the command \protect\addpoints\MessageBreak + \space\space in order to create a grade table.\MessageBreak + }{% + If you don't give the command \protect\addpoints\MessageBreak + \space\space then we're not keeping track of point values. + \MessageBreak + }% + \fi +}% ii@gtable + +\def\@questionsref{questions} +\def\@pagesref{pages} +\def\find@p@or@q@range#1#2{% + % We get here from \ii@gtable. + % The first argument should be ``v'' or ``h''; + % the second argument should be ``questions'' or ``pages''. + % See whether we're doing a table indexed by + % questions (in which case we go to \find@qrange) or by pages (in + % which case we go to \find@prange): + \begingroup + % We've begun a group that will contain the construction of the + % table, to confine the effect of any \def's that we use. + \def\exam@temp{#2}% + \ifx\exam@temp\@questionsref + \tbl@pgsfalse + \find@qrange{#1}% + \else + \ifx\exam@temp\@pagesref + \tbl@pgstrue + \find@prange{#1}% + \else + \ClassError{exam}{% + Grade and point tables can be indexed\MessageBreak + \space\space by either `questions' or `pages',\MessageBreak + \space\space but not by `#2'.\MessageBreak + }{% + Grade tables and point tables can be indexed by questions or + pages;\MessageBreak + \space\space for others, you're on your own.\MessageBreak + }% + \fbox{\textbf{Error:} grade or point table: Invalid argument + `#2' must be `questions' or `pages'.}% + \fi + \fi + \endgroup +}% find@p@or@q@range + +% \range@undefined can be called from either \find@qrange or +% \find@prange +\def\range@undefined{% + \fbox{Warning: grading range `\tbl@range ' not defined; + run \LaTeX{} again.}% + \ClassWarning{exam}{% + Grading range `\tbl@range' not defined.\MessageBreak + \space\space Run LaTeX again to produce the table.\MessageBreak + }% +}% range@undefined + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% Grade and point tables indexed by question numbers: + +% When we get to \find@qrange, we know we're doing a table indexed by +% question numbers and that this is not the first run of latex. The +% argument is either ``v'' or ``h''. If we're not doing a partial +% table, then \find@qrange sets \tbl@firstq and \first@pq@index to 1 +% and \tbl@lastq and \last@pq@index to \numquestions. Otherwise, +% \find@qrange makes sure the grading range is defined and that its +% last question isn't before its first question. \find@qrange then +% calls \tbl@v@or@h, passing along the argument that is either ``v'' +% or ``h''. + +\def\find@qrange#1{% + % We get here from \find@p@or@q@range. + % We're doing a table indexed by question numbers. + \if@partial + \@ifundefined{range@\tbl@range @firstq}% + {% + \range@undefined + }% + {% + \@ifundefined{range@\tbl@range @lastq}% + {% + \range@undefined + }% + {% + \edef\tbl@firstq{\csname range@\tbl@range @firstq\endcsname}% + \edef\tbl@lastq{\csname range@\tbl@range @lastq\endcsname}% + \let\first@pq@index=\tbl@firstq + \let\last@pq@index=\tbl@lastq + % Check that firstq precedes or equals lastq: + \ifnum \tbl@firstq > \tbl@lastq\relax + \fbox{\textbf{Error:} Grading Range `\tbl@range': + Last question precedes first question.}% + \ClassError{exam}{% + In grading range `\tbl@range', + the last question\MessageBreak + \space\space comes before the first question.\MessageBreak + }{% + \string\begingradingrange \space must precede + \string\endgradingrange \space by at + least one question.\MessageBreak + }% + \else + \tbl@v@or@h{#1}% + \fi + }% + }% + \else + \def\tbl@firstq{1}% + \let\first@pq@index=\tbl@firstq + % \numquestions is always defined, even if this is the first + % run of LaTeX and \exam@numquestions isn't defined. + % If it's the first run of LaTeX, then its value isn't useful, + % but it's never used until a later run (when its value is useful). + \def\tbl@lastq{\numquestions}% + \let\last@pq@index=\tbl@lastq + \tbl@v@or@h{#1}% + \fi +}% find@qrange + +\def\@vref{v} +\def\@href{h} +\def\tbl@v@or@h#1{% + % \first@pq@index=\tbl@firstq or \tbl@firstp and + % \last@pq@index=\tbl@lastq or \tbl@lastp have already been set. + % The argument should be either `v' or `h', and we branch + % accordingly. + \def\exam@temp{#1}% + \ifx\exam@temp\@vref + \check@num@cols@v + \else + \ifx\exam@temp\@href + \check@num@rows@h + \else + \ClassError{exam}{% + Grade or point table: the argument `#1'\MessageBreak + \space\space must be `v' or `h'. + \MessageBreak + }{% + Grade tables and point tables can be either vertical or + horizontal;\MessageBreak + \space\space no diagonals allowed.\MessageBreak + }% + \fbox{\textbf{Error:} grade or point table: Invalid argument + `#1' must be `v' or `h'.}% + \fi + \fi +}% tbl@v@or@h + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% Grade and point tables indexed by page numbers: + + +% The only pages listed are those on which there are a nonzero number +% of points. We check pages \tbl@firstp through \tbl@lastp +% Once we've checked that, e.g., \lastpage@withpoints and +% \pointsonpage@\romannumeral{\lastpage@withpoints} are defined, we +% can safely (we think) check \pointsonpage@\romannumeral{n} for all n +% between \tbl@firstp and \tbl@lastp without generating errors. +% +% Actually: Since we added the notion of half points and half counters +% (a long time ago), there won't be any errors even if +% \pointsonpage@\romannumeral{n} isn't defined, since it's tested by the +% lines: +% \set@hlfcntr{tmp@hlfcntr}{\csname pointsonpage@\romannumeral +% \csname c@@iterator\endcsname\endcsname}% +% \ifhlfcntr@pos{tmp@hlfcntr}% +% and if +% \csname pointsonpage@\romannumeral +% \csname c@@iterator\endcsname\endcsname +% isn't defined, tmp@hlfcntr gets the value zero (because of the way +% that \set@hlfcntr is written). + +% \find@prange makes sure the grading range is defined and that its +% last page isn't before its first page (if it's a partial table). In +% any case, it then sets \tbl@firstp and \tbl@lastp, and calls +% \check@secondrun. + +\def\find@prange#1{% + % We get here from \find@p@or@q@range. + % We're doing a table indexed by pages. + % The argument is either ``v'' or ``h''. + % We first determine the first and last page of the range, storing + % those in \first@pq@index=\tbl@firstp and + % \last@pq@index=\tbl@lastp. If not a partial table, we set + % \first@pq@index=\tbl@firstp to 1 and \last@pq@index=\tbl@lastp to + % the last page with the appropriate points (and so if it's a + % combined table, it's the last page to have either bonus or + % non-bonus points). + % We then call \check@secondrun, passing it the argument that we + % received (i.e., we say \check@secondrun{#1}) to make sure + % we've done at least two runs of latex (so that we'll have the + % information we need about which pages have points on them). + \if@partial + \@ifundefined{range@\tbl@range @firstp}% + {% + \range@undefined + }% + {% + \@ifundefined{range@\tbl@range @lastp}% + {% + \range@undefined + }% + {% + \edef\tbl@firstp{\csname range@\tbl@range @firstp\endcsname}% + \edef\tbl@lastp{\csname range@\tbl@range @lastp\endcsname}% + \let\first@pq@index=\tbl@firstp + \let\last@pq@index=\tbl@lastp + % Check that firstp precedes or equals lastp: + \ifnum \tbl@firstp > \tbl@lastp\relax + \fbox{\textbf{Error:} Grading Range `\tbl@range ': + Last page precedes first page.}% + \ClassError{exam}{% + In grading range `\tbl@range', the last page\MessageBreak + \space\space comes before the first page.\MessageBreak + }{% + \string\begingradingrange \space must precede + \string\endgradingrange.\MessageBreak + }% + \else + \check@secondrun{#1}% + \fi + }% + }% + \else + % It's not a partial table: + \def\tbl@firstp{1}% + \let\first@pq@index=\tbl@firstp + % We never get here on the first run of LaTeX, and + % \lastpage@withbonuspoints is defined on the second and later runs. + \def\tbl@lastp{\lastpage@withpoints}% + \let\last@pq@index=\tbl@lastp + \if@bonus + \def\tbl@lastp{\lastpage@withbonuspoints}% + \let\last@pq@index=\tbl@lastp + \fi + \if@combined + \ifnum \lastpage@withbonuspoints > \lastpage@withpoints\relax + \def\tbl@lastp{\lastpage@withbonuspoints}% + \let\last@pq@index=\tbl@lastp + \fi + \fi + \check@secondrun{#1}% + \fi +}% find@prange + +\def\check@secondrun#1{% + % The function \ii@gtable already made sure that this isn't the + % first run of latex. To do a table indexed by pages, though, we + % have to also make sure it's not the second run of latex. + % We get here from \find@prange; the argument is either ``v'' or + % ``h''. + % Check that there's enough info from the .aux file to do a page + % indexed grade table. If so, call \tbl@v@or@h{#1}: + \@ifundefined{pointsonpage@\romannumeral + \csname lastpage@withpoints\endcsname}% + {\@ifundefined{bonuspointsonpage@\romannumeral + \csname lastpage@withbonuspoints\endcsname}% + {\ClassWarning{exam}{% + You must run LaTeX again to produce the table.\MessageBreak}% + \fbox{Run \LaTeX{} again to produce the table}% + }% + {\tbl@v@or@h{#1}% + }% + }% + {\tbl@v@or@h{#1}% + }% +}% check@secondrun + +%-------------------------------------------------------------------- +% Indexed by pages: + +% For a table indexed by pages, we need to know how many pages there +% are with points on them. The argument to \count@pgswpts should be +% the name of a counter; we set that counter equal to the number of +% pages with the appropriate kind of points. + +\def\count@pgswpts#1{% + % Set the counter #1 equal to the number of pages in the range with + % the appropriate type of points. + % We're called by \@computenumcols@h and \@computenumrows@v. + \setcounter{#1}{0}% + \setcounter{@iterator}{\tbl@firstp}% + \addtocounter{@iterator}{-1}% + \if@bonus + \docount@pgswbpts{#1}% + \else + \if@combined + \docount@pgswcpts{#1}% + \else + \docount@pgswpts{#1}% + \fi + \fi +}% count@pgswpts + +\def\docount@pgswcpts#1{% + % Called by \count@pgswpts + % Count the number of pages in range with any kind of point (bonus + % or non-bonus): + \addtocounter{@iterator}{1}% + \set@hlfcntr{tmp@hlfcntr}{\pointsonpage{\the@iterator}}% + \ifhlfcntr@pos{tmp@hlfcntr}% + \addtocounter{#1}{1}% + \else + \check@bnsptpage{#1}% + \fi + \ifnum \the@iterator < \tbl@lastp\relax + \def\nextdocount@pgswcpts{\docount@pgswcpts{#1}}% + \else + \let\nextdocount@pgswcpts=\relax + \fi + \nextdocount@pgswcpts +}% docount@pgswcpts +\def\check@bnsptpage#1{% + % We need to hide this inside of a macro because if \ifhlfcntr@pos + % isn't expanded (because this stuff is being skipped in the outer + % conditional), then TeX doesn't see the \ifnum hidden inside the + % \ifhlfcntr@pos, but it does see the \fi, and so it get confused. + \set@hlfcntr{tmp@hlfcntr}{\bonuspointsonpage{\the@iterator}}% + \ifhlfcntr@pos{tmp@hlfcntr}% + \addtocounter{#1}{1}% + \fi +}% check@bnsptpage + +\def\docount@pgswpts#1{% + % Called by \count@pgswpts. + % Count the number of pages in range with regular points. + \addtocounter{@iterator}{1}% + \set@hlfcntr{tmp@hlfcntr}{\pointsonpage{\the@iterator}}% + \ifhlfcntr@pos{tmp@hlfcntr}% + \addtocounter{#1}{1}% + \fi + \ifnum \the@iterator < \tbl@lastp\relax + \def\nextdocount@pgswpts{\docount@pgswpts{#1}}% + \else + \let\nextdocount@pgswpts=\relax + \fi + \nextdocount@pgswpts +}% docount@pgswpts + +\def\docount@pgswbpts#1{% + % Called by \count@pgswpts + % Count the number of pages in range with bonus points. + \addtocounter{@iterator}{1}% + \set@hlfcntr{tmp@hlfcntr}{\bonuspointsonpage{\the@iterator}}% + \ifhlfcntr@pos{tmp@hlfcntr}% + \addtocounter{#1}{1}% + \fi + \ifnum \the@iterator < \tbl@lastp\relax + \def\nextdocount@pgswbpts{\docount@pgswbpts{#1}}% + \else + \let\nextdocount@pgswbpts=\relax + \fi + \nextdocount@pgswbpts +}% docount@pgswbpts + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% Multirow horizontal tables, indexed by question numbers: + +\newcounter{pq@index}% In tables indexed by page numbers, it holds a +% page number. In tables indexed by question numbers, it holds a +% question number. + +\newcounter{pq@index@pts}% In horizontal tables, this holds either the +% current page number or the current question number as we put the +% point values for that page or question number into the table. In +% vertical tables, this holds the index for the first column of the +% current row. + +\newcounter{pq@index@bpts}% used to set bonus point values in +% horizontal tables. Often used as scratch elsewhere. + +\def\hidden@ampersand{&}% Needed because an ampersand can't appear in +% the replacement text of a conditional. + +\newif\iftbl@pgs +% \tbl@pgstrue means a table indexed by page numbers +% \tbl@pgsfalse means a table indexed by question numbers + +\newcounter{num@cols} +\newcounter{num@rows} +\newcounter{current@row} +\newcounter{cols@done}% Holds the number of columns done in the +% current row. + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% Stuff to unify tables indexed by questions and tables indexed by +% pages: + +% \first@pq@index and \last@pq@index will hold either \tbl@firstq and +% \tbl@lastq or \tbl@firstp and \tbl@lastp. + +\def\increment@index#1{% + % If we're doing a table indexed by question numbers, we increment + % the counter #1. + % If we're doing a table indexed by page numbers, + % we increase the counter #1 by at least 1 to either the number of the + % next page containing the appropriate kind of points, or to + % something greater than \tbl@lastp. + \iftbl@pgs + \find@nextpagewithpoints{#1}% + \else + \addtocounter{#1}{1}% + \fi +}% increment@index + +\def\nextcolumn@index@v#1{% + % Used only for multicolumn tables. + % If we're doing a table indexed by question numbers, we increase + % the counter #1 by num@cols. + % If we're doing a table indexed by page numbers, + % we use \find@nextcolumnpage@v to increment the counter #1 to either + % the (num@rows)'th page number after #1 that contains the + % appropriate kind of points or to a value greater than \tbl@lastp. + \iftbl@pgs + \find@nextcolumnpage@v{#1}% + \else + \addtocounter{#1}{\value{num@rows}}% + \fi +}% nextcolumn@index@v + +\def\pointsof@index#1{% + \iftbl@pgs + \pointsonpage{\arabic{#1}}% + \else + \pointsofquestion{\arabic{#1}}% + \fi +}% pointsof@index + +\def\bonuspointsof@index#1{% + \iftbl@pgs + \bonuspointsonpage{\arabic{#1}}% + \else + \bonuspointsofquestion{\arabic{#1}}% + \fi +}% bonuspointsof@index + +\def\refto@index#1{% + \iftbl@pgs + \if@combined + % Need to hide this inside of a macro: + \refto@comb@index{#1}% + \else + \if@bonus + \pageref{firstbonuspoints@onpage@\arabic{#1}}% + \else + \pageref{firstpoints@onpage@\arabic{#1}}% + \fi + \fi + \else + \ref{question@\arabic{#1}}% + \fi +}% refto@index + +\def\refto@comb@index#1{% + % We're called only by \refto@index. + % We can't have the \ifhlfcntr@pos...\fi inside of another + % conditional, so we're hiding it in this macro. + \set@hlfcntr{tmp@hlfcntr}{\pointsonpage{\arabic{#1}}}% + \ifhlfcntr@pos{tmp@hlfcntr}% + \pageref{firstpoints@onpage@\arabic{#1}}% + \else + % In theory, there *must* be bonus points on this page, because + % there aren't any plain points, but there are allegedly *some* + % points. We're being brave and assuming that's correct, and not + % checking (which we'd have to hide inside a macro, because it + % would use \ifhlfcntr@pos): + \pageref{firstbonuspoints@onpage@\arabic{#1}}% + \fi +}% refto@comb@index + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% Multirow tables: + + +%-------------------------------------------------------------------- +% Check that the number of rows is OK, and compute the number of +% columns: + +\def\check@num@rows@h{% + % We get here from \tbl@v@or@h. + % We make sure the number of rows is a positive integer. If it + % is, we go on to \@computenumcols@h + \ifnum \value{num@rows} < 1\relax + \ClassError{exam}{% + The number of rows in a table must be positive.\MessageBreak + }{% + The number of rows must be a positive integer.\MessageBreak + }% + \fbox{\textbf{Error:} Multirow table with no rows!}% + \else + \@computenumcols@h + \fi +}% check@num@rows@h + +\def\@computenumcols@h{% + % We get here from \check@num@rows@h. + % Compute the number of columns. + % First: set num@cols to one more than either (the number of pages + % with the appropriate type of points) or (the number of questions), + % to have slots for the total along with the questions: + \iftbl@pgs + \count@pgswpts{num@cols}% + \addtocounter{num@cols}{1}% + \else + \setcounter{num@cols}{\tbl@lastq}% + \addtocounter{num@cols}{-\tbl@firstq}% + \addtocounter{num@cols}{2}% + \fi + % Save the number of slots needed in pq@index (used for scratch), to + % check for truncation: + \setcounter{pq@index}{\value{num@cols}}% + % Divide the number of slots needed by num@rows: + \divide \csname c@num@cols\endcsname by + \csname c@num@rows\endcsname + % Division truncates: See if there was truncation. + % Use @iterator as a scratch counter. + \setcounter{@iterator}{\value{num@cols}}% + \multiply \csname c@@iterator\endcsname by + \csname c@num@rows\endcsname + \ifnum \value{@iterator} < \value{pq@index}\relax + % There was truncation; add a column to num@cols: + \addtocounter{num@cols}{1}% + \fi + \@multirowtable +}% @computenumcols@h + +%-------------------------------------------------------------------- +% Construct the actual table: + +\def\@multirowtable{% + % We get here from \@computenumcols@h. + % All multirow tables! + \renewcommand\arraystretch{\@gtblstretch}% + \set@hlfcntr{tbl@points}{0}% + \set@hlfcntr{tbl@bonuspoints}{0}% + \setcounter{pq@index}{\first@pq@index}% + \addtocounter{pq@index}{-1}% + \setcounter{pq@index@pts}{\value{pq@index}}% + \setcounter{pq@index@bpts}{\value{pq@index}}% + \setcounter{current@row}{0}% + \begin{tabular}{|l|*{\value{num@cols}}{c|}} + \hline + \if@combined + \do@comblines@h + \else + \do@lines@h + \fi +}% @multirowtable + + +\def\do@lines@h{% + % Called only by \@multirowtable. + % It's either bonus or regular, but not combined: + \addtocounter{current@row}{1}% Set to the number of the current row + \iftbl@pgs + \if@bonus + \@bhpgword + \else + \@hpgword + \fi + \else + \if@bonus + \@bhqword + \else + \@hqword + \fi + \fi + \setcounter{cols@done}{0}% + \do@pq@indexloop@h + % When we finish \do@pq@indexloop@h, either we've finished a + % complete row of page numbers (or questions), or we've done all + % the page numbers (or questions) through \last@pq@index, or both: + \ifnum \value{cols@done} < \value{num@cols}\relax + % We've inserted all the page or question numbers, and there's + % room remaining on the current line for \@htword (or \@bhtword): + \ifnum \value{current@row} = \value{num@rows}\relax + % This is the last row; put in the total: + \do@htword@h + \else + % This isn't the last row. We insert (\value{num@cols} - + % \value{cols@done}) ampersands. + \setcounter{@iterator}{\value{num@cols}}% + \addtocounter{@iterator}{-\value{cols@done}}% + \do@emptycols@h + \fi + \fi + \\ + \hline + % Point values go here! + \setcounter{cols@done}{0}% + \if@bonus + \@bhpword + \do@bptloop@h + \else + \@hpword + \do@ptloop@h + \fi + % When we finish \do@ptloop@h or \do@bptloop@h, either + % we've finished a complete row of point values, or we've done all + % the question (or page) numbers through \last@pq@index, or both: + \ifnum \value{cols@done} < \value{num@cols}\relax + % We've inserted all the point values, and there's room + % remaining on the current line for Total Points: + \ifnum \value{current@row} = \value{num@rows}\relax + % This is the last row; put in the total: + \if@bonus + \do@totalbpts@h + \else + \do@totalpts@h + \fi + \else + % This isn't the last row. We insert (\value{num@cols} - + % \value{cols@done}) ampersands. + \setcounter{@iterator}{\value{num@cols}}% + \addtocounter{@iterator}{-\value{cols@done}}% + \do@emptycols@h + \fi + \fi + % We hold off on putting in the "\\ \hline" because we may want to + % immediately follow it with either an "\end{tabular}" or another + % "\hline". + % Scores? + \if@scores + \\ + \hline + \if@bonus + \@bhsword \hidden@ampersand + \else + \@hsword \hidden@ampersand + \fi + \setcounter{cols@done}{0}% + \do@sloop@h + \fi + \ifnum \value{current@row} = \value{num@rows}\relax + % This is the last line! End the tabular: + \\ + \hline + \end{tabular}% + \else + % Don't end the tabular: + \\ + \hline\hline + \fi + % Check if we should repeat: + \ifnum \value{current@row} < \value{num@rows}\relax + \let\nextdo@lines@h=\do@lines@h + \else + \let\nextdo@lines@h=\relax + \fi + \nextdo@lines@h +}% do@lines@h + +\def\do@comblines@h{% + % Called only by \@multirowtable. + % Combined tables. + \addtocounter{current@row}{1}% Set to the number of the current row + \iftbl@pgs + \@chpgword + \else + \@chqword + \fi + \setcounter{cols@done}{0}% + \do@pq@indexloop@h + % When we finish \do@pq@indexloop@h, either we've finished a + % complete row of page (or question) numbers, or we've done all + % the page (or question) numbers through \last@pq@index, or both: + \ifnum \value{cols@done} < \value{num@cols}\relax + % We've inserted all the question (or page) numbers, and there's + % room remaining on the current line for \@chtword: + \ifnum \value{current@row} = \value{num@rows}\relax + % This is the last row; put in the total: + \do@htword@h + \else + % This isn't the last row. We insert (\value{num@cols} - + % \value{cols@done}) ampersands. + \setcounter{@iterator}{\value{num@cols}}% + \addtocounter{@iterator}{-\value{cols@done}}% + \do@emptycols@h + \fi + \fi + \\ + \hline + % Point values go here! + \@chpword + \setcounter{cols@done}{0}% + \do@ptloop@h + % When we finish \do@ptloop@h, either we've finished a complete + % row of point values, or we've done all the question (or page) + % numbers through \last@pq@index, or both: + \ifnum \value{cols@done} < \value{num@cols}\relax + % We've inserted all the point values, and there's room + % remaining on the current line for Total Points: + \ifnum \value{current@row} = \value{num@rows}\relax + % This is the last row; put in the total: + \do@totalpts@h + \else + % This isn't the last row. We insert (\value{num@cols} - + % \value{cols@done}) ampersands. + \setcounter{@iterator}{\value{num@cols}}% + \addtocounter{@iterator}{-\value{cols@done}}% + \do@emptycols@h + \fi + \fi + \\ + \hline + % Bonus point values go here! + \@chbpword + \setcounter{cols@done}{0}% + \do@bptloop@h + % When we finish \do@bptloop@h, either + % we've finished a complete row of point values, or we've done all + % the question (or page) numbers through \last@pq@index, or both: + \ifnum \value{cols@done} < \value{num@cols}\relax + % We've inserted all the point values, and there's room + % remaining on the current line for Total Points: + \ifnum \value{current@row} = \value{num@rows}\relax + % This is the last row; put in the total: + \do@totalbpts@h + \else + % This isn't the last row. We insert (\value{num@cols} - + % \value{cols@done}) ampersands. + \setcounter{@iterator}{\value{num@cols}}% + \addtocounter{@iterator}{-\value{cols@done}}% + \do@emptycols@h + \fi + \fi + % We hold off on putting in the "\\ \hline" because we may want to + % immediately follow it with either an "\end{tabular}" or another + % "\hline". + % Scores? + \if@scores + \\ + \hline + \@chsword \hidden@ampersand + \setcounter{cols@done}{0}% + \do@sloop@h + \fi + \ifnum \value{current@row} = \value{num@rows}\relax + % This is the last line! End the tabular: + \\ + \hline + \end{tabular}% + \else + % Don't end the tabular: + \\ + \hline\hline + \fi + % Check if we should repeat: + \ifnum \value{current@row} < \value{num@rows}\relax + \let\nextdo@comblines@h=\do@comblines@h + \else + \let\nextdo@comblines@h=\relax + \fi + \nextdo@comblines@h +}% do@comblines@h + +\def\do@pq@indexloop@h{% + % Called by both \do@lines@h and \do@comblines@h. + % We insert at most one row of pq@index: + \increment@index{pq@index}% + \ifnum \value{pq@index} > \last@pq@index\relax + % Do nothing! + \else + \hidden@ampersand + \refto@index{pq@index}% + \addtocounter{cols@done}{1}% + \fi + \ifnum \value{pq@index} < \last@pq@index\relax + \ifnum \value{cols@done} < \value{num@cols}\relax + \let\nextdo@pq@indexloop@h=\do@pq@indexloop@h + \else + \let\nextdo@pq@indexloop@h=\relax + \fi + \else + \let\nextdo@pq@indexloop@h=\relax + \fi + \nextdo@pq@indexloop@h +}% do@pq@indexloop@h + +\def\do@ptloop@h{% + % Called by both \do@lines@h and \do@comblines@h. + % We insert at most one row of non-bonus point values: + \increment@index{pq@index@pts}% + \ifnum \value{pq@index@pts} > \last@pq@index\relax + % Do nothing! + \else + \hidden@ampersand + \addtocounter{cols@done}{1}% + \pointsof@index{pq@index@pts}% + \addto@hlfcntr{tbl@points}{\pointsof@index{pq@index@pts}}% + \fi + \ifnum \value{pq@index@pts} < \last@pq@index\relax + \ifnum \value{cols@done} < \value{num@cols}\relax + \let\nextdo@ptloop@h=\do@ptloop@h + \else + \let\nextdo@ptloop@h=\relax + \fi + \else + \let\nextdo@ptloop@h=\relax + \fi + \nextdo@ptloop@h +}% do@ptloop@h + +\def\do@bptloop@h{% + % Called by both \do@lines@h and \do@comblines@h. + % We insert at most one row of bonus point values: + \increment@index{pq@index@bpts}% + \ifnum \value{pq@index@bpts} > \last@pq@index\relax + % Do nothing! + \else + \hidden@ampersand + \addtocounter{cols@done}{1}% + \bonuspointsof@index{pq@index@bpts}% + \addto@hlfcntr{tbl@bonuspoints}{\bonuspointsof@index{pq@index@bpts}}% + \fi + \ifnum \value{pq@index@bpts} < \last@pq@index\relax + \ifnum \value{cols@done} < \value{num@cols}\relax + \let\nextdo@bptloop@h=\do@bptloop@h + \else + \let\nextdo@bptloop@h=\relax + \fi + \else + \let\nextdo@bptloop@h=\relax + \fi + \nextdo@bptloop@h +}% do@bptloop@h + +\def\do@htword@h{% + % Called by both \do@lines@h and \do@comblines@h. + % We insert (\value{num@cols} - \value{cols@done}) ampersands, + % and then either \@htword or \@bhtword or \@chtword: + \setcounter{@iterator}{\value{num@cols}}% + \addtocounter{@iterator}{-\value{cols@done}}% + \do@emptycols@h + \if@combined + \@chtword + \else + \if@bonus + \@bhtword + \else + \@htword + \fi + \fi +}% do@htword@h + +\def\do@totalpts@h{% + % Called by both \do@lines@h and \do@comblines@h. + % We insert (\value{num@cols} - \value{cols@done}) ampersands + % and then the total points: + \setcounter{@iterator}{\value{num@cols}}% + \addtocounter{@iterator}{-\value{cols@done}}% + \do@emptycols@h + \prt@tablepoints +}% do@totalpts@h + +\def\do@totalbpts@h{% + % Called by both \do@lines@h and \do@comblines@h. + % We insert (\value{num@cols} - \value{cols@done}) ampersands, + % and then the total bonus points: + \setcounter{@iterator}{\value{num@cols}}% + \addtocounter{@iterator}{-\value{cols@done}}% + \do@emptycols@h + \prt@tablebonuspoints +}% do@totalbpts@h + +\def\do@emptycols@h{% + % Called by \do@lines@h, \do@comblines@h, \do@htword@h, + % \do@totalpts@h, and \do@totalbpts@h. + % We insert \value{@iterator} ampersands: + \ifnum \value{@iterator} > 0\relax + \hidden@ampersand + \addtocounter{@iterator}{-1}% + \let\nextdo@emptycols@h=\do@emptycols@h + \else + \let\nextdo@emptycols@h=\relax + \fi + \nextdo@emptycols@h +}% do@emptycols@h + +\def\do@sloop@h{% + % Called by both \do@lines@h and \do@comblines@h. + % We assume that cols@done has been set to zero. + % We insert num@cols \hbox to \@cellwidth, + % separated by ampersands. + \addtocounter{cols@done}{1}% + \hbox to \@cellwidth{\hfill}% + \ifnum \value{cols@done} < \value{num@cols}\relax + \hidden@ampersand + \let\nextdo@sloop@h=\do@sloop@h + \else + \let\nextdo@sloop@h=\relax + \fi + \nextdo@sloop@h +}% do@sloop@h + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% Multicolumn tables + + +%-------------------------------------------------------------------- +% Here's an example of a multicolumn grade table indexed by questions. + +% Every line of \cline's is followed by a +% \noalign{\vskip\arrayrulewidth} to cancel the +% \noalign{\vskip-\arrayrulewidth} that ends the definition of +% \cline. + +% \begin{tabular}{*2{|c|c|c|c}} +% \cline{1-3} \cline{5-7} +% \noalign{\vskip\arrayrulewidth} +% Question% +% & Points% +% & Score% +% & \hspace*{-\arrayrulewidth}\hspace*{\doublerulesep}% +% & Question% +% & Points% +% & Score% +% \\ +% \cline{1-3} \cline{5-7} +% \noalign{\vskip\arrayrulewidth} +% 1% +% & 5% +% & \hbox to \@cellwidth{\hfill}% +% & \hspace*{-\arrayrulewidth}\hspace*{\doublerulesep}% +% & 4% +% & 20% +% & \hbox to \@cellwidth{\hfill}% +% \\ +% \cline{1-3} \cline{5-7} +% \noalign{\vskip\arrayrulewidth} +% 2% +% & 10% +% & \hbox to \@cellwidth{\hfill}% +% & \hspace*{-\arrayrulewidth}\hspace*{\doublerulesep}% +% & 5% +% & 25% +% & \hbox to \@cellwidth{\hfill}% +% \\ +% \cline{1-3} \cline{5-7} +% \noalign{\vskip\arrayrulewidth} +% 3% +% & 15% +% & \hbox to \@cellwidth{\hfill}% +% & \hspace*{-\arrayrulewidth}\hspace*{\doublerulesep}% +% & Total:% +% & 75% +% & \hbox to \@cellwidth{\hfill}% +% \\ +% \cline{1-3} \cline{5-7} +% \noalign{\vskip\arrayrulewidth} +% \end{tabular} +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% Check that the number of cols is OK, and compute the number of rows: + +\def\check@num@cols@v{% + % We get here from \tbl@v@or@h. + % We make sure the number of cols is between 1 and 10 (since we + % can't handle more than 10 cols in a multicolumn table). + % If it is, we go on to \@computenumrows@v + \ifnum \value{num@cols} < 1\relax + \ClassError{exam}{% + The number of columns in a table must be positive.\MessageBreak + }{% + The number of columns must be a positive integer.\MessageBreak + }% + \fbox{\textbf{Error:} Multicolumn table with no columns!}% + \else + \ifnum \value{num@cols} > 10\relax + \ClassError{exam}{% + Multicolumn tables can have at most 10 columns.\MessageBreak + }{% + Multicolumn tables can have at most 10 columns.\MessageBreak + }% + \fbox{\textbf{Error:} Multicolumn table with more than 10 columns!}% + \else + \@computenumrows@v + \fi + \fi +}% check@num@cols@v + +\def\@computenumrows@v{% + % We get here from \check@num@cols@v. + % Compute the number of rows. + % First: set num@rows to one more than the number of either + % (questions) or (pages with the appropriate type of points), to + % have slots for the total along with the questions or page numbers: + \iftbl@pgs + \count@pgswpts{num@rows}% + \addtocounter{num@rows}{1}% + \else + \setcounter{num@rows}{\last@pq@index}% + \addtocounter{num@rows}{-\first@pq@index}% + \addtocounter{num@rows}{2}% + \fi + % Save the number of slots needed, using pq@index@bpts as a scratch + % counter, to check for truncation on division: + \setcounter{pq@index@bpts}{\value{num@rows}}% + % Divide the number of slots needed by num@cols: + \divide \csname c@num@rows\endcsname by + \csname c@num@cols\endcsname + % Division truncates: See if there was truncation. + % Use the counter @iterator as a scratch counter: + \setcounter{@iterator}{\value{num@rows}}% + \multiply \csname c@@iterator\endcsname by + \csname c@num@cols\endcsname + \ifnum \value{@iterator} < \value{pq@index@bpts}\relax + % There was truncation; add one to num@rows: + \addtocounter{num@rows}{1}% + \fi + \@multicolumntable +}% @computenumrows@v + +%-------------------------------------------------------------------- +% Construct the actual table: + +\def\@multicolumntable{% + % We get here from \@computenumrows@v. + % Set \cline@stuff@v equal to the line of \cline's: + \create@cline@stuff@v + \renewcommand\arraystretch{\@gtblstretch}% + \set@hlfcntr{tbl@points}{0}% + \set@hlfcntr{tbl@bonuspoints}{0}% + \if@combined + \if@scores + % combinedgradetable, possibly partial. + % Note: We'll never use the final "c" in the format of the + % tabular, but there's no harm in that. + \begin{tabular}{*{\value{num@cols}}{|c|c|c|c|c}} + % We need to make sure that the \cline@stuff@v commands come + % *immediately* following the \\ or \begin{tabular} (with no + % conditionals evaluated, even if those conditionals expand to + % the empty string)! + % Put in the row of column headings, with \cline@stuff@v above and + % below: + \cline@stuff@v + \setcounter{@iterator}{0}% + \docolumn@heads@comb@v + \\ + \cline@stuff@v + \else + % combinedpointtable, possibly partial. + % Note: We'll never use the final "c" in the format of the + % tabular, but there's no harm in that. + \begin{tabular}{*{\value{num@cols}}{|c|c|c|c}} + % We need to make sure that the \cline@stuff@v commands come + % *immediately* following the \\ or \begin{tabular} (with no + % conditionals evaluated, even if those conditionals expand to + % the empty string)! + % Put in the row of column headings, with \cline@stuff@v above and + % below: + \cline@stuff@v + \setcounter{@iterator}{0}% + \docolumn@heads@comb@noscores@v + \\ + \cline@stuff@v + \fi + % pq@index@pts will hold the question number (or page number) in + % the first column of the row. + \setcounter{pq@index@pts}{\first@pq@index}% + \iftbl@pgs + % If we're indexed by pages, we need to make sure there are + % points of the appropriate type on the first page listed: + \addtocounter{pq@index@pts}{-1}% + \find@nextpagewithpoints{pq@index@pts}% + \fi + \setcounter{current@row}{0}% + \do@lines@v + \else + % It's not combined: + \if@scores + % Note: We'll never use the final "c" in the format of the + % tabular, but there's no harm in that. + \begin{tabular}{*{\value{num@cols}}{|c|c|c|c}} + % We need to make sure that the \cline@stuff@v commands come + % *immediately* following the \\ or \begin{tabular} (with no + % conditionals evaluated, even if those conditionals expand to + % the empty string)! + % Put in the row of column headings, with \cline@stuff@v above and + % below: + \cline@stuff@v + \setcounter{@iterator}{0}% + \docolumn@heads@v + \\ + \cline@stuff@v + \else + % Note: We'll never use the final "c" in the format of the + % tabular, but there's no harm in that. + \begin{tabular}{*{\value{num@cols}}{|c|c|c}} + % We need to make sure that the \cline@stuff@v commands come + % *immediately* following the \\ or \begin{tabular} (with no + % conditionals evaluated, even if those conditionals expand to + % the empty string)! + % Put in the row of column headings, with \cline@stuff@v above and + % below: + \cline@stuff@v + \setcounter{@iterator}{0}% + \docolumn@heads@noscores@v + \\ + \cline@stuff@v + \fi + % pq@index@pts will hold the question number (or page number) in + % the first column of the row. + \setcounter{pq@index@pts}{\first@pq@index}% + \iftbl@pgs + % If we're indexed by pages, we need to make sure there are + % points of the appropriate type on the first page listed: + \addtocounter{pq@index@pts}{-1}% + \find@nextpagewithpoints{pq@index@pts}% + \fi + \setcounter{current@row}{0}% + \do@lines@v + \fi +}% @multicolumntable + +%-------------------------------------------------------------------- +% \create@cline@stuff@v + +% The function \create@cline@stuff@v defines \cline@stuff@v to be whatever's +% appropriate given the values of num@cols, \if@bonus, \if@combined, and +% \if@scores. + +% We wimped out of generating \cline@stuff@v on the fly because we didn't +% see how to get the correct expansions/nonexpansions without using a +% primitive of e-TeX. + +% \clines@ii@whatever is for tables in which a logical column consists +% of two columns; it's used for pointtable and bonuspointtable. + +\def\clines@ii@i{\cline{1-2}} +\def\clines@ii@ii{\cline{1-2} \cline{4-5}} +\def\clines@ii@iii{\cline{1-2} \cline{4-5} \cline{7-8}} +\def\clines@ii@iv{\cline{1-2} \cline{4-5} \cline{7-8} \cline{10-11}} +\def\clines@ii@v{\cline{1-2} \cline{4-5} \cline{7-8} \cline{10-11} + \cline{13-14}} +\def\clines@ii@vi{\cline{1-2} \cline{4-5} \cline{7-8} \cline{10-11} + \cline{13-14} \cline{16-17}} +\def\clines@ii@vii{\cline{1-2} \cline{4-5} \cline{7-8} \cline{10-11} + \cline{13-14} \cline{16-17} \cline{19-20}} +\def\clines@ii@viii{\cline{1-2} \cline{4-5} \cline{7-8} \cline{10-11} + \cline{13-14} \cline{16-17} \cline{19-20} \cline{22-23}} +\def\clines@ii@vix{\cline{1-2} \cline{4-5} \cline{7-8} \cline{10-11} + \cline{13-14} \cline{16-17} \cline{19-20} \cline{22-23} + \cline{25-26}} +\def\clines@ii@x{\cline{1-2} \cline{4-5} \cline{7-8} \cline{10-11} + \cline{13-14} \cline{16-17} \cline{19-20} \cline{22-23} + \cline{25-26} \cline{28-29}} + +% \clines@iii@whatever is for tables in which a logical column consists +% of three columns; it's are used for gradetable, bonusgradetable, and +% combinedpointtable: + +\def\clines@iii@i{\cline{1-3}} +\def\clines@iii@ii{\cline{1-3} \cline{5-7}} +\def\clines@iii@iii{\cline{1-3} \cline{5-7} \cline{9-11}} +\def\clines@iii@iv{\cline{1-3} \cline{5-7} \cline{9-11} \cline{13-15}} +\def\clines@iii@v{\cline{1-3} \cline{5-7} \cline{9-11} \cline{13-15} + \cline{17-19}} +\def\clines@iii@vi{\cline{1-3} \cline{5-7} \cline{9-11} \cline{13-15} + \cline{17-19} \cline{21-23}} +\def\clines@iii@vii{\cline{1-3} \cline{5-7} \cline{9-11} \cline{13-15} + \cline{17-19} \cline{21-23} \cline{25-27}} +\def\clines@iii@viii{\cline{1-3} \cline{5-7} \cline{9-11} \cline{13-15} + \cline{17-19} \cline{21-23} \cline{25-27} \cline{29-31}} +\def\clines@iii@ix{\cline{1-3} \cline{5-7} \cline{9-11} \cline{13-15} + \cline{17-19} \cline{21-23} \cline{25-27} \cline{29-31} + \cline{33-35}} +\def\clines@iii@x{\cline{1-3} \cline{5-7} \cline{9-11} \cline{13-15} + \cline{17-19} \cline{21-23} \cline{25-27} \cline{29-31} + \cline{33-35} \cline{37-39}} + + +% \clines@iv@whatever is for tables in which a logical column +% consists of four columns; it's used for combinedgradetable. + +\def\clines@iv@i{\cline{1-4}} +\def\clines@iv@ii{\cline{1-4} \cline{6-9}} +\def\clines@iv@iii{\cline{1-4} \cline{6-9} \cline{11-14}} +\def\clines@iv@iv{\cline{1-4} \cline{6-9} \cline{11-14} \cline{16-19}} +\def\clines@iv@v{\cline{1-4} \cline{6-9} \cline{11-14} \cline{16-19} + \cline{21-24}} +\def\clines@iv@vi{\cline{1-4} \cline{6-9} \cline{11-14} \cline{16-19} + \cline{21-24} \cline{26-29}} +\def\clines@iv@vii{\cline{1-4} \cline{6-9} \cline{11-14} \cline{16-19} + \cline{21-24} \cline{26-29} \cline{31-34}} +\def\clines@iv@viii{\cline{1-4} \cline{6-9} \cline{11-14} \cline{16-19} + \cline{21-24} \cline{26-29} \cline{31-34} \cline{36-39}} +\def\clines@iv@ix{\cline{1-4} \cline{6-9} \cline{11-14} \cline{16-19} + \cline{21-24} \cline{26-29} \cline{31-34} \cline{36-39} + \cline{41-44}} +\def\clines@iv@x{\cline{1-4} \cline{6-9} \cline{11-14} \cline{16-19} + \cline{21-24} \cline{26-29} \cline{31-34} \cline{36-39} + \cline{41-44} \cline{46-49}} + +% The definition of \cline ends with \noalign{\vskip-\arrayrulewidth}, +% and so we want to throw in a \noalign{\vskip\arrayrulewidth} to +% cancel that. +\def\cline@correction{\noalign{\vskip\arrayrulewidth}} + +\def\create@cline@stuff@v{% + % Called by \@multicolumntable. + \if@combined + \if@scores + \edef\cline@stuff@v{\expandafter\noexpand\csname + clines@iv@\romannumeral \c@num@cols\endcsname + \noexpand\cline@correction}% + \else + \edef\cline@stuff@v{\expandafter\noexpand\csname + clines@iii@\romannumeral \c@num@cols\endcsname + \noexpand\cline@correction}% + \fi + \else + \if@scores + \edef\cline@stuff@v{\expandafter\noexpand\csname + clines@iii@\romannumeral \c@num@cols\endcsname + \noexpand\cline@correction}% + \else + \edef\cline@stuff@v{\expandafter\noexpand\csname + clines@ii@\romannumeral \c@num@cols\endcsname + \noexpand\cline@correction}% + \fi + \fi +}% create@cline@stuff@v + +%-------------------------------------------------------------------- +% The various \docolumn@heads@something@v + +\def\docolumn@heads@v{% + % Called by \@multicolumntable. + % multicolumngradetable or multicolumnbonusgradetable, possibly + % partial. + \iftbl@pgs + \if@bonus + \@bvpgword + \else + \@vpgword + \fi + \else + \if@bonus + \@bvqword + \else + \@vqword + \fi + \fi + & \if@bonus + \@bvpword + \else + \@vpword + \fi + & \if@bonus + \@bvsword + \else + \@vsword + \fi + \addtocounter{@iterator}{1}% + \ifnum \value{@iterator} < \value{num@cols}\relax + \hidden@ampersand + \hspace*{-\arrayrulewidth}\hspace*{\doublerulesep}% + \hidden@ampersand + \let\nextdocolumn@heads@v=\docolumn@heads@v + \else + \let\nextdocolumn@heads@v=\relax + \fi + \nextdocolumn@heads@v +}% docolumn@heads@v + +\def\docolumn@heads@noscores@v{% + % Called by \@multicolumntable. + % multicolumnpointtable or multicolumnbonuspointtable, possibly + % partial. + \iftbl@pgs + \if@bonus + \@bvpgword + \else + \@vpgword + \fi + \else + \if@bonus + \@bvqword + \else + \@vqword + \fi + \fi + & + \if@bonus + \@bvpword + \else + \@vpword + \fi + \addtocounter{@iterator}{1}% + \ifnum \value{@iterator} < \value{num@cols}\relax + \hidden@ampersand + \hspace*{-\arrayrulewidth}\hspace*{\doublerulesep}% + \hidden@ampersand + \let\nextdocolumn@heads@noscores@v=\docolumn@heads@noscores@v + \else + \let\nextdocolumn@heads@noscores@v=\relax + \fi + \nextdocolumn@heads@noscores@v +}% docolumn@heads@noscores@v + +\def\docolumn@heads@comb@v{% + % Called by \@multicolumntable. + % multicolumncombinedgradetable, possibly partial. + \iftbl@pgs + \@cvpgword + \else + \@cvqword + \fi + & \@cvpword + & \@cvbpword + & \@cvsword + \addtocounter{@iterator}{1}% + \ifnum \value{@iterator} < \value{num@cols}\relax + \hidden@ampersand + \hspace*{-\arrayrulewidth}\hspace*{\doublerulesep}% + \hidden@ampersand + \let\nextdocolumn@heads@comb@v=\docolumn@heads@comb@v + \else + \let\nextdocolumn@heads@comb@v=\relax + \fi + \nextdocolumn@heads@comb@v +}% docolumn@heads@comb@v + +\def\docolumn@heads@comb@noscores@v{% + % Called by \@multicolumntable. + % multicolumncombinedpointtable, possibly partial. + \iftbl@pgs + \@cvpgword + \else + \@cvqword + \fi + & \@vpword + & \@bvpword + \addtocounter{@iterator}{1}% + \ifnum \value{@iterator} < \value{num@cols}\relax + \hidden@ampersand + \hspace*{-\arrayrulewidth}\hspace*{\doublerulesep}% + \hidden@ampersand + \let\nextdocolumn@heads@comb@noscores@v=\docolumn@heads@comb@noscores@v + \else + \let\nextdocolumn@heads@comb@noscores@v=\relax + \fi + \nextdocolumn@heads@comb@noscores@v +}% docolumn@heads@comb@noscores@v + +%-------------------------------------------------------------------- +% \do@lines@v is used by *all* multicolumn tables. +% It calls \do@oneline@v for all non-combined tables and +% \do@oneline@comb@v for all combined tables. + +\def\do@lines@v{% + % We get here from \@multicolumntable. + % ALL MULTICOLUMN TABLES!!!! + % pq@index@pts holds the question number or page number in the first + % column of the current row. + \addtocounter{current@row}{1}% + \setcounter{pq@index}{\value{pq@index@pts}}% + \setcounter{cols@done}{0}% Number of columns done + % We're doing both grade tables and point tables!! + \if@combined + \do@oneline@comb@v + \else + \do@oneline@v + \fi + \increment@index{pq@index@pts}% + % We need the "\\ \cline@stuff@v" to *immediately* precede the + % \end{tabular} (i.e., with no \ifnum separating them), to avoid + % having crap after the \cline@stuff@v that + % causes there to be an extra row at the end of the table. We also + % need there to be nothing between \\ and \cline@stuff@v. + \ifnum \value{current@row} = \value{num@rows}\relax + \\ + \cline@stuff@v + \end{tabular}% + \let\nextdo@lines@v=\relax + \else + \\ + \cline@stuff@v + \let\nextdo@lines@v=\do@lines@v + \fi + \nextdo@lines@v +}% do@lines@v + +\def\do@oneline@v{% + % Called by \do@lines@v. + % Used for all multicolumn non-combined tables. + % pq@index holds the question or page number we're about to do. + \ifnum \value{pq@index} > \last@pq@index\relax + % See if we're in the last column; use pq@index@bpts as a scratch + % counter: + \setcounter{pq@index@bpts}{\value{cols@done}}% + \addtocounter{pq@index@bpts}{1}% + \ifnum \value{pq@index@bpts} = \value{num@cols}\relax + % We're in the last column; are we in the last row? + \ifnum \value{current@row} = \value{num@rows}\relax + % We're in the last column, last row! + % Print the total: + \if@bonus + \@bvtword + \else + \@vtword + \fi + \hidden@ampersand + \if@scores + \if@bonus + \prt@tablebonuspoints + \else + \prt@tablepoints + \fi + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \else + \hspace*{\fill}% + \if@bonus + \prt@tablebonuspoints + \else + \prt@tablepoints + \fi + \fi + \else + % Not last column last row; insert empty space: + \hbox to \@cellwidth{\hfill}% + \if@scores + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \fi + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \fi + \else + % Not last column; insert empty space: + \hbox to \@cellwidth{\hfill}% + \if@scores + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \fi + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \fi + \else + % We need to do question (or page) number pq@index: + \refto@index{pq@index}% + \hidden@ampersand + \if@scores + \if@bonus + \bonuspointsof@index{pq@index}% + \addto@hlfcntr{tbl@bonuspoints}{\bonuspointsof@index{pq@index}}% + \else + \pointsof@index{pq@index}% + \addto@hlfcntr{tbl@points}{\pointsof@index{pq@index}}% + \fi + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \else + \if@bonus + \bonuspointsof@index{pq@index}% + \addto@hlfcntr{tbl@bonuspoints}{\bonuspointsof@index{pq@index}}% + \else + \pointsof@index{pq@index}% + \addto@hlfcntr{tbl@points}{\pointsof@index{pq@index}}% + \fi + \fi + \fi + \addtocounter{cols@done}{1}% Number of columns done + \ifnum \value{cols@done} < \value{num@cols}\relax + \hidden@ampersand + \hspace*{-\arrayrulewidth}\hspace*{\doublerulesep}% + \nextcolumn@index@v{pq@index}% + \hidden@ampersand + \let\nextdo@oneline@v=\do@oneline@v + \else + \let\nextdo@oneline@v=\relax + \fi + \nextdo@oneline@v +}% do@oneline@v + +\def\do@oneline@comb@v{% + % Called by \do@lines@v. + % All combined multicolumn tables. + % pq@index holds the question (or page) we're about to do. + \ifnum \value{pq@index} > \last@pq@index\relax + % See if we're in the last column; use pq@index@bpts as a scratch + % counter: + \setcounter{pq@index@bpts}{\value{cols@done}}% + \addtocounter{pq@index@bpts}{1}% + \ifnum \value{pq@index@bpts} = \value{num@cols}\relax + % We're in the last column; are we in the last row? + \ifnum \value{current@row} = \value{num@rows}\relax + % We're in the last column, last row! + % Print the total: + \@cvtword + \hidden@ampersand + \prt@tablepoints + \hidden@ampersand + \if@scores + \prt@tablebonuspoints + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \else + \prt@tablebonuspoints + \fi + \else + % Last column, but not last row; insert empty space: + \hbox to \@cellwidth{\hfill}% + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \if@scores + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \fi + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \fi + \else + % Not last column; insert empty space: + \hbox to \@cellwidth{\hfill}% + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \if@scores + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \fi + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \fi + \else + % We need to do question number pq@index: + \refto@index{pq@index}% + \hidden@ampersand + \pointsof@index{pq@index}% + \addto@hlfcntr{tbl@points}{\pointsof@index{pq@index}}% + \hidden@ampersand + \if@scores + \bonuspointsof@index{pq@index}% + \addto@hlfcntr{tbl@bonuspoints}{\bonuspointsof@index{pq@index}}% + \hidden@ampersand + \hbox to \@cellwidth{\hfill}% + \else + \bonuspointsof@index{pq@index}% + \addto@hlfcntr{tbl@bonuspoints}{\bonuspointsof@index{pq@index}}% + \fi + \fi + \addtocounter{cols@done}{1}% Number of columns done + \ifnum \value{cols@done} < \value{num@cols}\relax + \hidden@ampersand + \hspace*{-\arrayrulewidth}\hspace*{\doublerulesep}% + \nextcolumn@index@v{pq@index}% + \hidden@ampersand + \let\nextdo@oneline@comb@v=\do@oneline@comb@v + \else + \let\nextdo@oneline@comb@v=\relax + \fi + \nextdo@oneline@comb@v +}% do@oneline@comb@v + +%-------------------------------------------------------------------- +% \find@nextpagewithpoints and \find@nextcolumnpage@v: + +\def\find@nextpagewithpoints#1{% + % Called by \dofind@nextcolumnpage@v, \increment@index, and + % \@multicolumntable. + % The argument #1 should be the name of a counter with a nonnegative + % value. + % We increase #1 by at least 1 to either the number of the + % next page containing the appropriate kind of points, or to something + % greater than \tbl@lastp. + \addtocounter{#1}{1}% + \if@combined + \set@hlfcntr{tmp@hlfcntr}{\pointsonpage{\value{#1}}}% + \addto@hlfcntr{tmp@hlfcntr}{\bonuspointsonpage{\value{#1}}}% + % The sum is positive when at least one of them is positive. + \else + \if@bonus + \set@hlfcntr{tmp@hlfcntr}{\bonuspointsonpage{\value{#1}}}% + \else + \set@hlfcntr{tmp@hlfcntr}{\pointsonpage{\value{#1}}}% + \fi + \fi + \ifhlfcntr@pos{tmp@hlfcntr}% + \let\nextfind@nextpagewithpoints=\relax + \else + \ifnum \value{#1} > \tbl@lastp\relax + \let\nextfind@nextpagewithpoints=\relax + \else + \def\nextfind@nextpagewithpoints{\find@nextpagewithpoints{#1}}% + \fi + \fi + \nextfind@nextpagewithpoints +}% find@nextpagewithpoints + +\def\find@nextcolumnpage@v#1{% + % Called by \nextcolumn@index@v. + % This is used for all multicolumn tables that are indexed by + % pages. + % We use \find@nextpagewithpoints to increment #1 to either + % the (num@rows)'th page number after #1 that contains the + % appropriate kind of points or to a value greater than \tbl@lastp. + % We use pq@index@bpts as a scratch counter. + \setcounter{pq@index@bpts}{0}% + \dofind@nextcolumnpage@v{#1}% +}% find@nextcolumnpage@v +\def\dofind@nextcolumnpage@v#1{% + % Called only by \find@nextcolumnpage@v. + \addtocounter{pq@index@bpts}{1}% + \find@nextpagewithpoints{#1}% + \ifnum \value{pq@index@bpts} = \value{num@rows}\relax + \let\nextdofind@nextcolumnpage@v=\relax + \else + % The following test shouldn't be needed, in theory, because the + % computation of num@cols should prevent trouble, but we're being + % paranoid. + \ifnum \value{#1} > \tbl@lastp\relax + \let\nextdofind@nextcolumnpage@v=\relax + \else + % Note: this is a \def, and not a \let, because we need to put + % in the argument #1: + \def\nextdofind@nextcolumnpage@v{\dofind@nextcolumnpage@v{#1}}% + \fi + \fi + \nextdofind@nextcolumnpage@v +}% dofind@nextcolumnpage@v + +%-------------------------------------------------------------------- +% \pointsinrange and \bonuspointsinrange, and then +% \firstqinrange, \lastqinrange, and \numqinrange. + + +% We say either \@bonusfalse or \@bonustrue, and then we check it only +% in \do@countloop: +\def\pointsinrange#1{% + \@bonusfalse + \def\tbl@range{#1}% + \@ifundefined{exam@numpoints}% + {\mbox{\normalfont\bfseries ??}}% + {\read@range}% +}% pointsinrange + +\def\bonuspointsinrange#1{% + \@bonustrue + \def\tbl@range{#1}% + \@ifundefined{exam@numpoints}% + {\mbox{\normalfont\bfseries ??}}% + {\read@range}% +}% bonuspointsinrange + +\def\bad@range{% + % Called by \read@range, \firstqinrange, \lastqinrange, and + % \numqinrange. + {\mbox{\normalfont\bfseries ??}}% + \ClassWarning{exam}{% + Grading range `\tbl@range' not defined.\MessageBreak + \space\space Run LaTeX again.\MessageBreak + }% +}% bad@range + +\def\read@range{% + % Called by \pointsinrange and \bonuspointsinrange. + \@ifundefined{range@\tbl@range @firstq}% + {% + \bad@range + }% + {% + \@ifundefined{range@\tbl@range @lastq}% + {% + \bad@range + }% + {% + \edef\tbl@firstq{\csname range@\tbl@range @firstq\endcsname}% + \edef\tbl@lastq{\csname range@\tbl@range @lastq\endcsname}% + % Check that firstq precedes or equals lastq: + \ifnum \tbl@firstq > \tbl@lastq\relax + \fbox{\textbf{Error:} Grading Range `\tbl@range ': + Last question precedes first question.}% + \ClassError{exam}{% + In grading range `\tbl@range ', + the last question\MessageBreak + \space\space comes before the first question.\MessageBreak + }{% + \string\begingradingrange \space must precede + \string\endgradingrange \space by at + least one question.\MessageBreak + }% + \else + \count@pointsinrange + \fi + }% + }% +}% read@range + +\def\count@pointsinrange{% + % Used for both \pointsinrange and \bonuspointsinrange: + \set@hlfcntr{tbl@points}{0}% + \setcounter{@iterator}{\tbl@firstq}% + \addtocounter{@iterator}{-1}\do@countloop + \prt@hlfcntr{tbl@points}% +}% count@pointsinrange +\def\do@countloop{% + % We check \if@bonus here when needed: + \addtocounter{@iterator}{1}% + \if@bonus + \@ifundefined{bonuspointsofq@\romannumeral \c@@iterator}% + {}% + {\addto@hlfcntr{tbl@points} + {\csname bonuspointsofq@\romannumeral \c@@iterator\endcsname}}% + \else + \@ifundefined{pointsofq@\romannumeral \c@@iterator}% + {}% + {\addto@hlfcntr{tbl@points} + {\csname pointsofq@\romannumeral \c@@iterator\endcsname}}% + \fi + \ifnum \value{@iterator} < \tbl@lastq\relax + \let\next@countloop=\do@countloop + \else + \let\next@countloop=\relax + \fi + \next@countloop +}% do@countloop + +%-------------------------------------------------------------------- +% \firstqinrange, \lastqinrange, and \numqinrange. + +\newcommand{\firstqinrange}[1]{% + \def\tbl@range{#1}% + \@ifundefined{range@\tbl@range @firstq}% + {\bad@range}% + {\csname range@#1@firstq\endcsname}% +}% firstqinrange + +\newcommand{\lastqinrange}[1]{% + \def\tbl@range{#1}% + \@ifundefined{range@\tbl@range @lastq}% + {\bad@range}% + {\csname range@#1@lastq\endcsname}% +}% lastqinrange + +\newcommand{\numqinrange}[1]{% + \def\tbl@range{#1}% + \@ifundefined{range@#1@firstq}% + {% + \bad@range + }% + {% + \@ifundefined{range@#1@lastq}% + {% + \bad@range + }% + {% + \setcounter{@iterator}{\csname range@#1@lastq\endcsname}% + \addtocounter{@iterator}{-\csname range@#1@firstq\endcsname}% + \stepcounter{@iterator}% + \arabic{@iterator}% + }% + }% +}% numqinrange + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% +% *************************** +% ** SOLUTION ENVIRONMENTS ** +% *************************** + + + +% If the documentclass options include ``answers'', then the command +% \printanswerstrue is given at the beginning of the run. + +% If the documentclass options include ``noanswers'', then the command +% \printanswersfalse is given at the beginning of the run. + +\def\printanswers{\printanswerstrue} +\def\noprintanswers{\printanswersfalse} + +% If the documentclass options include ``cancelspace'', then the +% command \cancelspacetrue is given at the beginning of the run. + +% If the documentclass options include ``nocancelspace'', then the +% command \cancelspacefalse is given at the beginning of the run. + +\def\cancelspace{\cancelspacetrue} +\def\nocancelspace{\cancelspacefalse} + +% \if@insolution will be true while we're inside of any of the +% solution environments. This is used to supress \PgInfo@write and +% \label commands generated if there's a parts (or subparts, or +% subsubparts) environment inside of a solution. (It won't suppress +% the labels for the question objects, since a question object is +% never a label that's been used before.) +\newif\if@insolution +\@insolutionfalse + +\newcommand\SolutionEmphasis[1]{% + \def\Solution@Emphasis{#1}% +} +\SolutionEmphasis{} + +% If printanswers is true, we print the solution using a TheSolution +% environment. If printanswers is false and cancelspace is false, we +% insert blank vertical space equal to the optional argument (the +% default value of which is 0pt). +\newenvironment{solution}[1][0pt]% + {% + \@insolutiontrue % cancelled by the end of the environment + \@addpointsfalse % cancelled by the end of the environment + \ifprintanswers + \begingroup + \Solution@Emphasis + \begin{TheSolution}% + \else + \ifcancelspace + % Do nothing + \else + \par + \penalty 0 + \vspace*{#1}% + \fi + \setbox\z@\vbox\bgroup + \fi + }{% + \ifprintanswers + \end{TheSolution}% + \endgroup + \else + \egroup + \fi + }% + +% If printanswers is true, we print the solution using a TheSolution +% environment. If printanswers is false and cancelspace is false, +% we insert an empty box of width the current line width and of +% height equal to the optional argument, which can be a length, or +% \fill, or \stretch{number}. If the optional argument is omitted, +% then the box is entirely omitted when printanswers is false. +\newenvironment{solutionorbox}[1][-1pt]% + {% + \@insolutiontrue % cancelled by the end of the environment + \@addpointsfalse % cancelled by the end of the environment + \ifprintanswers + \begingroup + \Solution@Emphasis + \begin{TheSolution}% + \else + \ifcancelspace + % Do nothing + \else + \par + % Note: It's important that the following test be + % ``\ifdim 0pt > #1'' rather than ``\ifdim #1 < 0pt'' + % That's because if the user says + % ``\begin{solutionorbox}{\stretch{1}}'' + % (or \stretch{anythingelse}), then this will expand to + % ``\ifdim 0pt > \z@ plus 1fill\relax''. + % The \ifdim will be ``\ifdim 0pt > \z@'', and we'll have + % ``plus 1fill\relax'' left over. This is OK because if the + % \ifdim is false, that leftover stuff will be ignored, + % and it will only be true if the user omitted the optional + % argument, in which case there's no \stretch and thus no + % left over part. + % If we said ``\ifdim #1 < 0pt'', then we'd get an error + % when the user used \stretch, since the leftover stuff + % would appear when TeX was looking for <, =, or >. + \ifdim 0pt > #1 + % do nothing + \else + \makeemptybox{#1}% + \fi + \fi + \setbox\z@\vbox\bgroup + \fi + }{% + \ifprintanswers + \end{TheSolution}% + \endgroup + \else + \egroup + \fi + }% + +% If printanswers is true, we print the solution using a TheSolution +% environment. If printanswers is false and cancelspace is false, +% we insert lined vertical space equal to the optional argument (the +% default value of which is 0pt). +\newenvironment{solutionorlines}[1][0pt]% + {% + \@insolutiontrue % cancelled by the end of the environment + \@addpointsfalse % cancelled by the end of the environment + \ifprintanswers + \begingroup + \Solution@Emphasis + \begin{TheSolution}% + \else + \ifcancelspace + % Do nothing + \else + \par + \penalty 0 + \fillwithlines{#1}% + \fi + \setbox\z@\vbox\bgroup + \fi + }{% + \ifprintanswers + \end{TheSolution}% + \endgroup + \else + \egroup + \fi + }% + +% If printanswers is true, we print the solution using a TheSolution +% environment. If printanswers is false and cancelspace is false, +% we insert dotted lined vertical space equal to the optional +% argument (the default value of which is 0pt). +\newenvironment{solutionordottedlines}[1][0pt]% + {% + \@insolutiontrue % cancelled by the end of the environment + \@addpointsfalse % cancelled by the end of the environment + \ifprintanswers + \begingroup + \Solution@Emphasis + \begin{TheSolution}% + \else + \ifcancelspace + % Do nothing + \else + \par + \penalty 0 + \fillwithdottedlines{#1}% + \fi + \setbox\z@\vbox\bgroup + \fi + }{% + \ifprintanswers + \end{TheSolution}% + \endgroup + \else + \egroup + \fi + }% + +% If printanswers is true, we print the solution using a TheSolution +% environment. If printanswers is false and cancelspace is false, +% we insert a grid occupying vertically the optional argument (the +% default value of which is 0pt). +\newenvironment{solutionorgrid}[1][0pt]% + {% + \@insolutiontrue % cancelled by the end of the environment + \@addpointsfalse % cancelled by the end of the environment + \ifprintanswers + \begingroup + \Solution@Emphasis + \begin{TheSolution}% + \else + \ifcancelspace + % Do nothing + \else + \par + \penalty 0 + \fillwithgrid{#1}% + \fi + \setbox\z@\vbox\bgroup + \fi + }{% + \ifprintanswers + \end{TheSolution}% + \endgroup + \else + \egroup + \fi + }% + + +% The environment TheSolution is called from the solution, +% solutionorbox, solutionorlines, solutionordottedlines, and +% solutionorgrid environments when printanswers is true. It uses +% Donald Arseneau's framed.sty macros (included at the end of this +% file) to allow the solution to be broken across pages and have each +% piece enclosed in an fbox (or a colorbox, if the user has given the +% command \shadedsolutions), (or no box at all, if the user has given +% the command \unframedsolutions). + +% Of course, the user can change TheSolution with a \renewenvironment +% command. +\newcommand{\solutiontitle}{\noindent\textbf{Solution:}\enspace} +\newenvironment{TheSolution}% + {% + \vspace{\parskip}% + % If we don't set \leftskip and \rightskip to 0pt, then if we + % appear inside of an \uplevel command we'd have indentation + % inside of the solution box: + \leftskip=0pt + \rightskip=0pt + % If the user said \unframedsolutions, then both + % \if@framedsolutions and \if@shadedsolutions are false: + \if@framedsolutions + % We'll use the default \exam@FrameCommand + \else + \if@shadedsolutions + \def\exam@FrameCommand{\colorbox{SolutionColor}}% + \else + % It's \unframedsolutions: + \def\exam@FrameCommand{}% + \fi + \fi + \exam@MakeFramed{\advance\hsize-\exam@width}% + \solutiontitle + \ignorespaces + }% + {% + \unskip + \endexam@MakeFramed + }% + +\newif\if@framedsolutions +\@framedsolutionstrue +\newif\if@shadedsolutions +\@shadedsolutionsfalse +% If the user said \unframedsolutions, then both +% \if@framedsolutions and \if@shadedsolutions are false. + +\def\framedsolutions{\@framedsolutionstrue\@shadedsolutionsfalse} +\def\shadedsolutions{% + \@ifundefined{definecolor} + {% + \ClassError{exam}{% + You must load the color package with the command\MessageBreak + \space\space\protect\usepackage{color}\MessageBreak + in order to use the command \protect\shadedsolutions + \MessageBreak + }{% + This command makes use of the package color.sty,\MessageBreak + and so you have to load color.sty before your\MessageBreak + \protect\begin{document} command.\MessageBreak + }% + }% + {% + \definecolor{SolutionColor}{gray}{0.8} + \@shadedsolutionstrue + \@framedsolutionsfalse + }% +} +\def\unframedsolutions{\@framedsolutionsfalse\@shadedsolutionsfalse} + + +% 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. + +% 2016/02/08: The solutionbox frame can now be printed in color, as +% long as you load color.sty in the preamble. +% +% Usage: Say +% +% \usepackage{color} +% +% in the preamble, and then give the command +% +% \colorsolutionboxes +% +% to have the frame around a solutionbox in color. The default color +% was created by the command +% +% \definecolor{SolutionBoxColor}{gray}{0.8} +% +% and you can change the color by giving a new \definecolor command +% (which must be done *after* the \colorsolutionboxes command). +% +% To cancel color solutionbox frames and return to black, give the +% command +% +% \nocolorsolutionboxes + +\newif\if@colorsolutionboxes +\@colorsolutionboxesfalse +\def\colorsolutionboxes{% + \@ifundefined{definecolor} + {% + \ClassError{exam}{% + You must load the color package with the command\MessageBreak + \space\space\protect\usepackage{color}\MessageBreak + in order to use the command \protect\colorsolutionboxes + \MessageBreak + }{% + This command makes use of the package color.sty,\MessageBreak + and so you have to load color.sty before your\MessageBreak + \protect\begin{document} command.\MessageBreak + }% + }% + {% + \definecolor{SolutionBoxColor}{gray}{0.8} + \@colorsolutionboxestrue + }% +} +\def\nocolorsolutionboxes{\@colorsolutionboxesfalse} + +\newbox\exam@box +\newenvironment{solutionbox}[1]{% + \@insolutiontrue % cancelled by the end of the environment + \@addpointsfalse % cancelled by the end of the environment + \def\solutionbox@size{#1}% saved for end of environment +% Change, 2016/02/08: So that the solutionbox environment will work +% correctly inside of a tabular environment, we use \hsize instead of +% \textwidth: +% \@tempdima=\textwidth + \@tempdima=\hsize + \advance\@tempdima -\@totalleftmargin + \advance\@tempdima -6\fboxsep + \advance\@tempdima -2\fboxrule + % Confine the \Solution@Emphasis, as well as anything the user puts + % into the solution (e.g., \color{red}, or whatever); don't say + % \endgroup until after using \box\exam@box: + \begingroup + \Solution@Emphasis + % We save the solution in a box of the proper width. We'll either + % print it (if we're printing solutions) or throw it away by just + % not using it before the environment ends: + \setbox\exam@box=\vtop\bgroup + \hsize=\@tempdima + \leftskip=0pt + \rightskip=0pt + \vskip 2\fboxsep +% Change, 2016/05/09: We change \@totalleftmargin and \linewidth in +% case there are enumerate, itemize, or description environments +% inside the solution: + \@totalleftmargin=0pt + \linewidth=\hsize + \solutiontitle + \ignorespaces + }% + {% + \unskip + \egroup + % OK, the solution is now inside \box\exam@box. + % Set the height and depth to 0pt, so that if we use it we won't + % be advancing our position on the page: + \ht\exam@box=0pt + \dp\exam@box=0pt + \par + \vspace{\parskip} + \ifprintanswers + % We enclose the \vtop in an \hbox to avoid having the + % indentation of the enclosing list environment (implemented via + % \parshape) shift us to the right when we enter horizontal + % mode. If we don't use this \hbox, then we'd have to comment + % out the \hskip \@totalleftmargin: + % 2016/02/08: Changed \textwidth to \hsize: + \hbox to \hsize{% + \noindent + \hskip\@totalleftmargin + \hskip3\fboxsep\hskip\fboxrule + \box\exam@box\hfill + }% + \par\nointerlineskip + \fi + \endgroup % Finish confining the \Solution@Emphasis +% Starting in version 2.502, 2016/03/23,the decision of whether to +% color the box is made in the \makeemptybox command: + \makeemptybox{\solutionbox@size} + }% End of the second argument of \newenvironment{solutionbox} + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% Added in version 2.502: 2016/03/23, \colorfbox + +% The \colorfbox command is used in our modification of framed.sty +% that allows us to print the frame around the solution in color when +% the user has given the command \colorsolutionboxes. It takes two +% arguments, the first being the color for the frame, and the second +% being the stuff to be framed. + +% If we had assumed that xcolor.sty was used (instead of just +% color.sty), then the line that saves the current color in +% saved@color could have been just + +% \colorlet{saved@color}{.} + +% but we wanted to make this work even if color.sty is being used. + +% When you define a color mycolor using either color.sty or +% xcolor.sty, a macro \csname\string\color@ mycolor\endcsname is +% defined (i.e., the macro name is \\color@mycolor). +\newcommand{\colorfbox}[2]{% + % Save the current color in saved@color: + \expandafter\let\csname\string\color@saved@color\endcsname\current@color + % Create the box in color #1, with the text in saved@color + % (the braces are to confine the color change commands): + {\color{#1}\fbox{\color{saved@color}#2}}% +}% colorfbox + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- + +% The following stuff is lifted from: +% +% 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. +% +% The modifications I made are marked with ``psh'' in a comment: +% +% Further modifications, 2017-09-21 +% I changed the names of many commands by prepending ``exam@'', so +% that the user can use the framed.sty package with exam.cls and not +% have conflicts. (I also renamed the framed, shaded, and leftbar +% environments to examframed, examshaded, and examleftbar.) I didn't +% mark these name changes. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Create framed or shaded regions that can break across pages using +% \begin{examframed} ... \end{examframed} -- ordinary frame box +% (box at margin) +% \begin{examshaded} ... \end{examshaded} -- shaded background +% (into margin) +% ... examleftbar ... -- line on left side +% \begin{MakeFramed}{settings} ... \end{MakeFramed} +% -- generic frame (for new environments) +% +% The "examframed" environment puts the text into "\fbox" with the +% settings "\fboxrule=\exam@FrameRule" and "\fboxsep=\exam@FrameSep". +% You can change these lengths (using "\setlength") and you +% can even change the definition of "\exam@FrameCommand" to use +% much fancier boxes. +% +% In fact, the "shaded" environment just redefines "\exam@FrameCommand" +% to use "\colorbox{shadecolor}" (and you have to define the +% color "shadecolor": \newcolor{shadecolor}...). +% +% A page break is allowed, and even encouraged, before the framed +% environment. If you want to attach some text (a box title) to the +% frame, then the text should be inserted by \exam@FrameCommand +% +% The contents of the framed regions are restricted: +% Floats, footnotes, marginpars and head-line entries will be lost. +% (Some of these may be handled in a later version.) +% This package will not work with the page breaking of multicol.sty, +% or other systems that perform column-balancing. +% +% The MakeFramed environment does the work. Its "settings" argument +% should contain any adjustments to the text width (applied to \hsize, +% and using the "\exam@width" of the frame itself) as well as a `restore' +% command -- \@parboxrestore or \exam@FrameRestore or something similar. +% +% Expert commands: +% \exam@MakeFramed, \endexam@MakeFramed: the "MakeFramed" environment +% \exam@FrameCommand: command to draw the frame around its argument +% \exam@FrameRestore: restore some text settings, but fewer than +% \@parboxrestore +% \exam@FrameRule: length register; \fboxrule for default "framed". +% \exam@FrameSep: length register; \fboxsep for default "framed". +% \exam@frameHeightAdjust: macro; height of frame above baseline at +% top of page +% +% This is still a `pre-production' version because I can think of many +% features/improvements that should be made. Nevertheless, starting +% with version 0.5 it should be bug-free. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%psh: Commented out \ProvidesPackage: +%\ProvidesPackage{framed}[2003/07/21 v 0.8a: +% framed or shaded text with page breaks] + +%psh: Created \saved@totalleftmargin and \@sollistdepth: +\newdimen\saved@totalleftmargin +\newcount\@sollistdepth + +\newenvironment{examframed}% using default \exam@FrameCommand + {\exam@MakeFramed {\advance\hsize-\exam@width \exam@FrameRestore}}% + {\endexam@MakeFramed} + +\newenvironment{examshaded}{% + \def\exam@FrameCommand{\colorbox{shadecolor}}% + \exam@MakeFramed {\exam@FrameRestore}}% + {\endexam@MakeFramed} + +\newenvironment{examleftbar}{% + \def\exam@FrameCommand{\vrule width 3pt \hspace{10pt}}% + \exam@MakeFramed {\advance\hsize-\exam@width \exam@FrameRestore}}% + {\endexam@MakeFramed} + +\chardef\exam@FrameRestore=\catcode`\| % for debug +\catcode`\|=\catcode`\% % (debug: insert space after backslash) + +\def\exam@MakeFramed#1{\par + % measure added width and height; call result \exam@width and \exam@height + \setbox\z@\vbox{\vskip-1in \hbox{\hskip-1in + \exam@FrameCommand{\hbox{\vrule \@height .7in \@depth.3in \@width 1in}}}% + \vskip\z@skip}% + \def\exam@width{\wd\z@}\def\exam@height{\ht\z@}% + \edef\exam@fb@frw{\the\exam@width}\edef\exam@fb@frh{\the\exam@height}% + % insert pre-penalties and skips + \begingroup + \skip@\lastskip + \if@nobreak\else + \penalty9999 % updates \page parameters + \ifdim\pagefilstretch=\z@ \ifdim\pagefillstretch=\z@ + \edef\@tempa{\the\skip@}% + \ifx\@tempa\exam@zero@glue \penalty-30 + \else \vskip-\skip@ \penalty-30 \vskip\skip@ + \fi\fi\fi + \penalty\z@ + % Give a stretchy breakpoint that will always be taken in preference + % to the \penalty 9999 used to update page parameters. The cube root + % of 10000/100 indicates a multiplier of 0.21545, but the maximum + % calculated badness is really 8192, not 10000, so the multiplier + % is 0.2301. + \advance\skip@ \z@ plus-.5\baselineskip + \advance\skip@ \z@ plus-.231\exam@height + \advance\skip@ \z@ plus-.231\skip@ + \advance\skip@ \z@ plus-.231\topsep + \vskip-\skip@ \penalty 1800 \vskip\skip@ + \fi + \addvspace{\topsep}% + \endgroup + % clear out pending page break + \penalty\@M \vskip 2\baselineskip \vskip\exam@height + \penalty9999 \vskip -2\baselineskip \vskip-\exam@height + \penalty9999 % updates \pagetotal +|\message{After clearout, \pagetotal=\the\pagetotal, \pagegoal=\the\pagegoal. }% + \exam@fb@adjheight +%psh: Added commands: + \advance\hsize-\@totalleftmargin + \saved@totalleftmargin=\@totalleftmargin + \@totalleftmargin=0pt + \parshape 0 + \let\@listdepth=\@sollistdepth + \@sollistdepth=0 + \leftmargin=0pt +%psh: end of added commands + \setbox\@tempboxa\vbox\bgroup + #1% Modifications to \hsize (can use \exam@width and \exam@height) + \textwidth\hsize \columnwidth\hsize +%psh: added one line: + \linewidth=\hsize +} + +\def\endexam@MakeFramed{\par + \kern\z@ \penalty-100 % put depth into height + \egroup + \begingroup \exam@put@frame \endgroup +%psh: Added one line: + \@totalleftmargin=\saved@totalleftmargin +} + +% \exam@put@frame takes the contents of \@tempboxa and puts all, or a +% piece, of it on the page with a frame (\exam@FrameCommand). It +% recurses until all of \@tempboxa has been used up. (\@tempboxa must +% have zero depth.) + +\def\exam@put@frame{\relax + \ifdim\pagegoal=\maxdimen \pagegoal\vsize \fi +| \message{=============== Entering putframe ====================^^J +| \pagegoal=\the\pagegoal, \pagetotal=\the\pagetotal. }% + \ifinner \else + \dimen@\pagegoal \advance\dimen@-\pagetotal % natural space left on page + \ifdim\dimen@<2\baselineskip +| \message{Page has only \the\dimen@\space room left; eject. }% + \eject \exam@fb@adjheight \exam@put@frame + \else % there's appreciable room left on the page +| \message{\string\pagetotal=\the\pagetotal, +| \string\pagegoal=\the\pagegoal, +| \string\pagestretch=\the\pagestretch, +| \string\pageshrink=\the\pageshrink, +| \string\exam@fb@frh=\exam@fb@frh. \space} +| \message{Box of size \the\ht\@tempboxa\space + \exam@fb@frh}% + \begingroup % temporarily set \dimen@ to be... + \advance\dimen@.8\pageshrink % maximum space available on page + \advance\dimen@-\exam@fb@frh\relax % space available for frame's contents + \expandafter\endgroup + % restore \dimen@ to real room left on page + \ifdim\dimen@>\ht\@tempboxa % whole box does fit +| \message{fits in \the\dimen@. }% + \else % box must be split +| \message{must be split to fit in \the\dimen@. }% + \setbox\@tempboxa\vbox{% simulate frame and flexiblity of the page: + \vskip \exam@fb@frh \@plus\pagestretch \@minus.8\pageshrink + \kern137sp\kern-137sp\penalty-30 + \unvbox\@tempboxa}% + \edef\exam@fb@resto@set{\boxmaxdepth\the\boxmaxdepth + \splittopskip\the\splittopskip}% + \boxmaxdepth\z@ \splittopskip\z@ + \setbox\tw@\vsplit\@tempboxa to\dimen@ + \setbox\tw@\vbox{\unvbox\tw@}% natural-sized +| \message{Box of size \the\ht\@tempboxa\space split to \the\dimen@. +| Natural height of split box is \the\ht\tw@. }% + % If the split-to size > (\vsize-\topskip), then set box to full size + \begingroup + \advance\dimen@\topskip + \expandafter\endgroup + \ifdim\dimen@>\pagegoal +| \message{Frame is big -- Use up the full column. }% + \dimen@ii\pagegoal + \advance\dimen@ii -\topskip + \advance\dimen@ii \exam@frameHeightAdjust\relax + \else % suspect this is wrong: + % If the split-to size > feasible room_on_page, rebox it smaller. + \advance\dimen@.8\pageshrink + \ifdim\ht\tw@>\dimen@ +| \message{Box too tall; rebox it to \the\dimen@. }% + \dimen@ii\dimen@ + \else % use natural size + \dimen@ii\ht\tw@ + \fi + \fi + % Re-box contents to desired size \dimen@ii + \advance\dimen@ii -\exam@fb@frh + \setbox\tw@\vbox to\dimen@ii \bgroup + % remove simulated frame and page flexibility: + \vskip -\exam@fb@frh \@plus-\pagestretch \@minus-.8\pageshrink + \unvbox\tw@ \unpenalty\unpenalty + \ifdim\lastkern=-137sp % whole box went to next page +| \message{box split at beginning! }% + \egroup \exam@fb@resto@set \eject % (\vskip for frame size + % was discarded) + \exam@fb@adjheight + \else % + \egroup \exam@fb@resto@set + \ifvoid\@tempboxa % it all fit after all +| \message{box split at end! }% + \setbox\@tempboxa\box\tw@ + \else % it really did split +| \message{box split as expected. Its reboxed height is \the\ht\tw@. }% + \ifdim\wd\tw@>\z@ +%psh: Changed the command that inserts the box: +% Instead of \centerline, we shift right by \saved@totalleftmargin: +% \centerline{\exam@FrameCommand{\box\tw@}}% ??? \centerline bad idea + \hbox{\hskip \saved@totalleftmargin\exam@FrameCommand{\box\tw@}}% + \else +| \message{Zero width means likely blank. Don't frame it (guess)}% + \box\tw@ + \fi + \hrule \@height\z@ + \eject + \exam@fb@adjheight + \exam@put@frame + \fi\fi\fi\fi\fi + \ifvoid\@tempboxa\else +%psh: Changed the command that inserts the box: +% Instead of \centerline, we shift right by \saved@totalleftmargin: +% \centerline{\exam@FrameCommand{\box\@tempboxa}}% + \hbox{\hskip\saved@totalleftmargin\exam@FrameCommand{\box\@tempboxa}}% + \nointerlineskip \null %{\showoutput \showlists} + \penalty-30 \vskip\topsep + \fi} + +\def\exam@fb@adjheight{% + \vbox to\exam@frameHeightAdjust{}% get proper baseline skip from above. + \penalty\@M \nointerlineskip + \vskip-\exam@frameHeightAdjust + \penalty\@M} % useful for tops of pages + +\edef\exam@zero@glue{\the\z@skip} + +\catcode`\|=\exam@FrameRestore + +% Provide configuration commands: +%psh: Version 2.502, 2016/03/23, changed \exam@FrameCommand so that the +% frame is printed in color if the user has said +% \colorsolutionboxes: +%\providecommand\exam@FrameCommand{\fboxrule=\exam@FrameRule +%\fboxsep=\exam@FrameSep \fbox} +\def\exam@FrameCommand{\fboxrule=\exam@FrameRule \fboxsep=\exam@FrameSep + \if@colorsolutionboxes + \def\box@it{\colorfbox{SolutionBoxColor}}% + \else + \def\box@it{\fbox}% + \fi + \box@it +}% \exam@FrameCommand + +\@ifundefined{FrameRule}{\newdimen\exam@FrameRule \exam@FrameRule=\fboxrule}{} +\@ifundefined{FrameSep} {\newdimen\exam@FrameSep \exam@FrameSep =3\fboxsep}{} + +% Height of frame above first baseline when frame starts a page: +\providecommand\exam@frameHeightAdjust{6pt} + +% \exam@FrameRestore has parts of \@parboxrestore. See how it is used in the +% "settings" argument of \MakeFrame. Previous behavior can be restored by +% using \@parboxrestore there, or redefining: +% \makeatletter \renewcommand\exam@FrameRestore{\@parboxrestore} \makeatother +\def\exam@FrameRestore{% + \let\if@nobreak\iffalse + \let\if@noskipsec\iffalse +% \let\par\@@par ?? + \let\-\@dischyph + \let\'\@acci\let\`\@accii\let\=\@acciii +% \parindent\z@ \parskip\z@skip Definitely omit! +% \everypar{}% ?? + \linewidth\hsize +% \@totalleftmargin\z@ +% \leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip +% \parfillskip\@flushglue \lineskip\normallineskip +% \baselineskip\normalbaselineskip + \sloppy +% \let\\\@normalcr +} + +% Compatibility with previous versions (temporary!): +% psh: we'll remove this 2017-09-21 +%\let\fram@d=\MakeFramed \let\endfram@d=\endMakeFramed + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This ends the stuff that's lifted from: +% % framed.sty v 0.8a 21-Jul-2003 +% % Copyright (C) 1992-2003 by Donald Arseneau + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- + +\endinput +%--------------------------------------------------------------------- +%--------------------------------------------------------------------- +%--------------------------------------------------------------------- +%--------------------------------------------------------------------- +%--------------------------------------------------------------------- diff --git a/macros/latex/contrib/exam/exam.md5 b/macros/latex/contrib/exam/exam.md5 new file mode 100644 index 0000000000..38fd1b65a1 --- /dev/null +++ b/macros/latex/contrib/exam/exam.md5 @@ -0,0 +1,3 @@ +08a9755a8f51d31edf6b4124c9b710f9 exam.cls +a9273b3443c367000e4a71b572c58a62 examdoc.pdf +a9a481f4f36ec3dbf90ffe63f57ce803 examdoc.tex diff --git a/macros/latex/contrib/exam/examdoc.pdf b/macros/latex/contrib/exam/examdoc.pdf new file mode 100644 index 0000000000..9386d25eac Binary files /dev/null and b/macros/latex/contrib/exam/examdoc.pdf differ diff --git a/macros/latex/contrib/exam/examdoc.tex b/macros/latex/contrib/exam/examdoc.tex new file mode 100644 index 0000000000..cbcfb377a5 --- /dev/null +++ b/macros/latex/contrib/exam/examdoc.tex @@ -0,0 +1,8770 @@ +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +% examdoc.tex +% +% This is the user's guide for the exam documentclass, +% by Philip Hirschhorn. +% +% The exam documentclass itself is in the file exam.cls. + + +%%% Copyright (c) 1997, 2000, 2004, 2008, 2011, 2015, 2017 +% 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 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 +%%% psh@math.mit.edu + +% The newest version of this documentclass should always be available +% from my web page: http://www-math.mit.edu/~psh/ + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- + +\documentclass[12pt]{exam} +\usepackage{amssymb} + +\usepackage{makeidx} + +\usepackage[colorlinks]{hyperref} + +% In case we're not using hyperref.sty: +\providecommand{\texorpdfstring}[2]{#1} +% The following can be used in \section commands +% without generating pdf warnings: +\newcommand{\bs}{\texorpdfstring{\char`\\}{}} + +\newcommand{\docversion}{2.6} +\newcommand{\docdate}{November 5, 2017} +%\newcommand{\docdate}{Draft: \today} + +%-------------------------------------------------------------------- +% +% Changes since version 2.4 are described in the comments +% near the beginning of the file exam.cls. +% +%-------------------------------------------------------------------- + +\makeindex + +\newcommand{\indc}[1]{\index{#1@\texttt{\char`\\#1}}} +\newcommand{\indcsub}[2]{\index{#1@\texttt{\char`\\#1}!#2}} +\newcommand{\indcstart}[1]{\index{#1@\texttt{\char`\\#1}|(}} +\newcommand{\indcstop}[1]{\index{#1@\texttt{\char`\\#1}|)}} + +\newcommand{\indt}[1]{\index{#1@\texttt{#1}}} +\newcommand{\indtsub}[2]{\index{#1@\texttt{#1}!#2}} +\newcommand{\indtstart}[1]{\index{#1@\texttt{#1}|(}} +\newcommand{\indtstop}[1]{\index{#1@\texttt{#1}|)}} + +%--------------------------------------------------------------------- +\newenvironment{example}% + {\bigskip\filbreak + \subsubsection{Example:} + }% + {} + +\def\samplehead#1#2#3#4{% + \begin{trivlist} + \item[] + \leavevmode + \hbox to \textwidth{% + \rlap{\parbox[b]{\textwidth}{\raggedright#1\strut}}% + \hfil\parbox[b]{\textwidth}{\centering#2\strut}\hfil + \llap{\parbox[b]{\textwidth}{\raggedleft#3\strut}}% + }% hbox + #4 + \end{trivlist} +} + +\def\samplefoot#1#2#3#4{% + \begin{trivlist} + \item[] + \leavevmode + #1 + \vskip 3pt + + \hbox to \textwidth{% + \rlap{\parbox[t]{\textwidth}{\raggedright#2}}% + \hfil\parbox[t]{\textwidth}{\centering#3}\hfil + \llap{\parbox[t]{\textwidth}{\raggedleft#4}}% + }% hbox + \end{trivlist} +} + +% \makeatletter +% \@ifundefined{AmS}{\def\AmS{{\protect\the\textfont\tw@ +% A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}}} +% {} +% \makeatother + + +%--------------------------------------------------------------------- +%--------------------------------------------------------------------- +%--------------------------------------------------------------------- +%--------------------------------------------------------------------- + +\begin{document} + +\title{Using the exam document class} + +\author{Philip Hirschhorn\\ + Department of Mathematics\\ + Wellesley College\\ + Wellesley, MA 02481\\ + psh@math.mit.edu\\[\bigskipamount] + Copyright \copyright~1994, 1997, 2000, 2004, 2008, 2011, 2015, 2017\\ + Philip Hirschhorn\\ + All rights reserved} + +\date{\docdate} + +\maketitle + +\begin{center} + \small + This is the user's guide for version~\docversion{} of the + \verb"exam" document class. +\end{center} + +\tableofcontents + +%-------------------------------------------------------------------- +\section{Introduction} + +The file \verb"exam.cls" provides the \verb"exam" document class, +which attempts to make it easy for even a \LaTeX{} novice to prepare +exams. Specifically, \verb"exam.cls" sets the page layout so that +there are one inch margins\index{margins} all around (no matter what +size paper you're using) and provides commands that make it easy to +format questions, create flexible headers and footers, change the +margins, and create grading tables. In more detail: +\begin{itemize} +\item The class will automatically format and number the questions, + parts of questions, subparts of parts, and subsubparts of subparts + (see sections \ref{sec:Questions} and~\ref{sec:parts}). +\item You can include the point value\index{points} of each question + (or part, or subpart, or subsubpart), with your choice of having the + point values printed at the beginning of the text of the question, + opposite that in the left margin, opposite that in the right margin, + or in the right margin opposite the end of the question (see + section~\ref{sec:points}). +\item The class will add up the total points for each question (and + all of its parts, subparts, and subsubparts) and the total + points\index{points!total} on each page, and make those totals + available in macros (see sections \ref{sec:addup}, + \ref{sec:pointsofq} and~\ref{sec:pointsonp}). +\item You can have the class print a grading table, indexed either by + question number or by page number (see + section~\ref{sec:GradeTables}). +\item You specify the header in three parts: One part to be left + justified, one part to be centered, and one part to be right + justified, and one or all of these can be omitted (see + section~\ref{sec:header}). +\item The footer is also specified in three parts: Left justified, + centered, and right justified (see section~\ref{sec:footer}). +\item The header and footer for the first page can be different from + the ones used on other pages (see sections \ref{sec:runningheader}, + \ref{sec:lhead}, \ref{sec:runningfooter}, and \ref{sec:lfoot}). +\item Both headers and footers can contain more than one line. To + accommodate headers and footers with several lines, simple commands + are provided to enlarge the part of the page devoted to the header + and/or footer, and these commands can give one amount of space on + the first page and a different amount of space on all other pages + (see section~\ref{sec:extra-room}). +\item Macros are defined to enable you to state the total number of + pages in the exam (see section~\ref{sec:numpages}) and to change the + header and/or footer that appears on the last page of the exam (see + section~\ref{sec:lastpage}). +\item Macros are defined so that the headers and footers can vary + depending on whether the current page begins a new question or + continues a question that started on an earlier page (and, if one + continues onto the current page, to say what the number of that + question is). Macros are also defined so that the headers and + footers can vary depending on whether a question is complete on the + current page or continues on to the next page (and, if one + continues, to say what the number of that question is) (see + section~\ref{sec:QuesSpan}). +\item You can have a horizontal rule at the base of the header and/or + at the top of the footer (see section~\ref{sec:rules}). +\item The exam can begin with one or more cover pages, which are + numbered separately from the main pages of the exam and which can + have headers and footers different from the ones in the main pages + of the exam (see section~\ref{sec:coverpages}). +\item You can include solutions in your \LaTeX{} file and have these + solutions either printed or ignored (or replaced automatically by + space in which the students can write their answers) depending on a + single command (see section~\ref{sec:solutions}, + section~\ref{sec:CorrectChoice}, and section~\ref{sec:AnsShortAns}). +\end{itemize} + +The latest version of \verb"exam.cls" (possibly a +% +beta\index{beta test} test version) should always be available at +\verb"http://www-math.mit.edu/~psh/"\index{web page}. + +%-------------------------------------------------------------------- +\subsection{License} + +\begin{itemize} +\item This work may be distributed and/or modified under the + % + \index{Latex Project Public License@\LaTeX{} Project Public License} + % + conditions of the \LaTeX{} Project Public + License\index{license},\index{LPPL} either version~1.3 of this + license or (at your option) any later version. The latest version + of this license is in \verb"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. +\item This work has the LPPL maintenance status ``author-maintained''. +\item This work consists of the files \verb"exam.cls" and + \verb"examdoc.tex". +\end{itemize} + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +\section{Simple instructions for a basic exam} +\label{sec:Basic} + +Producing a basic exam with the \texttt{exam} document class is fairly +easy. After you learn to do that, you can read the parts of this +user's guide that describe how to customize whatever you want to +change. +%-------------------------------------------------------------------- +\subsection{The \texttt{\bs documentclass} command} +\label{sec:BasicDocumentclass} + +To use the \texttt{exam} document class, your \verb"\documentclass" +command should be\indc{documentclass} +\begin{center} + \verb"\documentclass[addpoints]{exam}" +\end{center} +or, if you want to use 12~point type, +\begin{center} + \verb"\documentclass[addpoints,12pt]{exam}" +\end{center} +There are other options; for the full story, see +section~\ref{sec:Documentclass}. + +%-------------------------------------------------------------------- +\subsection{Asking for the student's name} +\label{sec:BasicName} + +If you'll be leaving space for the answers on the question pages (see +sections~\ref{sec:BasicSpace} and \ref{sec:LeaveSpace}), then you'll +probably also want to leave space for the student's name% +\index{name}\index{student's name}. If you type +\begin{verbatim} +\begin{center} + \fbox{\fbox{\parbox{5.5in}{\centering + Answer the questions in the spaces provided on the + question sheets. If you run out of room for an answer, + continue on the back of the page.}}} +\end{center} + +\vspace{0.1in} + +\makebox[\textwidth]{Name and section:\enspace\hrulefill} + +\vspace{0.2in} + +\makebox[\textwidth]{Instructor's name:\enspace\hrulefill} +\end{verbatim} +after the \verb"\begin{document}" command and before the +\verb"\begin{questions}" command (see section~\ref{sec:Questions}), +then you'll get\\ +\noindent +\parbox{\textwidth}{ +\begin{center} + \fbox{\fbox{\parbox{5.5in}{\centering + Answer the questions in the spaces provided on the + question sheets. If you run out of room for an answer, + continue on the back of the page.}}} +\end{center} + +\vspace{0.1in} + +\makebox[\textwidth]{Name and section:\enspace\hrulefill} + +\vspace{0.2in} + +\makebox[\textwidth]{Instructor's name:\enspace\hrulefill} +} + +%-------------------------------------------------------------------- +\subsection{Asking questions} +\label{sec:BasicQuestions} + +Once you've typed \verb"\begin{document}" and (if the students will be +writing their answers on the question pages) asked for the student's +name (see section~\ref{sec:BasicName}), you can list the questions +on the exam in a \texttt{questions} environment. You begin each +question with a \verb"\question"\indc{question} command, which is +optionally followed by a number of points inside of square brackets. +For example, if you type +% +\index{questions environment}\index{environment!questions} +\indt{questions} +\begin{verbatim} +\begin{questions} + +\question[10] +Why is there air? + +\question[15] + +How much wood would a woodchuck chuck if a woodchuck could chuck +wood? + +\question[10] Compute $\displaystyle\int_0^1 x^2 \, dx$. +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + +\question[10] +Why is there air? + +\question[15] + +How much wood would a woodchuck chuck if a woodchuck could chuck +wood? + +\question[10] Compute $\displaystyle\int_0^1 x^2 \, dx$. +\end{questions} + +\bigskip + +As the above example illustrates, you can leave blank lines +% +\index{blank lines} between the \verb"\question" command and the +actual beginning of the question, or before the first \verb"\question" +command in the environment, and they will be ignored. The point +values are entirely optional; if you omit the point values, you should +also omit the square brackets containing them. + +If you give the command \verb"\marksnotpoints"\indc{marksnotpoints}, +then the words ``point'' and ``points'' will be replaced by the words +``mark'' and ``marks''. There are many other customizations possible +for the points, including using a different language, changing the way +the points are printed, and by having them printed in one of the +margins. For the full story, see section~\ref{sec:points}. + + +%-------------------------------------------------------------------- +\subsection{Questions with parts, and subparts, and subsubparts} +\label{sec:BasicParts} + +If you want to create a question with parts, you use a +\texttt{parts}\indt{parts} environment and begin each part with the +command \verb"\part"\indc{part}. The \texttt{parts} environment can +be at the beginning of a question or after some text that begins the +question. (There are also \texttt{subparts} and \texttt{subsubparts} +environments; for the full details, see section~\ref{sec:parts}.) For +example, if you type +% +\index{parts environment}\index{environment!parts} +\begin{verbatim} +\begin{questions} +\question[10] +Why is there air? + +\question +What if there were no air? + +\begin{parts} +\part[5] +Describe the effect on the balloon industry. + +\part[5] +Describe the effect on the aircraft industry. +\end{parts} + +\question[20] + +\begin{parts} +\part +Define the universe. Give three examples. + +\part +If the universe were to end, how would you know? + +\end{parts} + + +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} +\question[10] +Why is there air? + +\question +What if there were no air? + +\begin{parts} +\part[5] +Describe the effect on the balloon industry. + +\part[5] +Describe the effect on the aircraft industry. +\end{parts} + +\question[20] + +\begin{parts} +\part +Define the universe. Give three examples. + +\part +If the universe were to end, how would you know? + +\end{parts} + + +\end{questions} + +\bigskip + +The above example illustrates several things: +\begin{itemize} +\item Parts of a question should be put into a + \verb"parts"\indt{parts}\index{parts environment}% + \index{environment!parts} environment. +\item If a question begins with a \verb"parts" environment, then the + first part will appear on the same line with the question number. +\item You can leave blank + % + lines\index{blank lines} before and after the \verb"\part" command, + and they will be ignored. +\item You can assign points either to the question or to the parts of + a question. +\end{itemize} + +%-------------------------------------------------------------------- +\subsection{Leaving space for the answers} +\label{sec:BasicSpace} +\index{space!for answers} +\index{answer space} + +To leave blank space after a question you use the \verb"\vspace" +command, and you end a page with the \verb"\newpage" command. For +example, if you wanted to leave 3~inches of space after the first +question and 2~inches of space after each of the parts of the second +question, your \texttt{questions} environment would contain the +following: +% +\index{blank space}\index{space!blank} +\begin{verbatim} +\question[10] +Why is there air? + +\vspace{3in} + +\question +What if there were no air? + +\begin{parts} +\part[5] +Describe the effect on the balloon industry. +\vspace{2in} + +\part[5] +Describe the effect on the aircraft industry. +\vspace{2in} +\end{parts} +\newpage +\end{verbatim} +If you want to equally distribute the space on a page among several +questions (or parts, or subparts, or subsubparts), you should +type\indc{stretch}\index{space!allocating} +% +\index{allocating space} +\begin{center} + \verb"\vspace{\stretch{1}}" +\end{center} +after each of the questions (or parts, etc.\@) and end the page with +\verb"\newpage". If you'd like one of those questions to receive +twice as much space as each of the others, then follow that one +question with \verb"\vspace{\stretch{2}}" and follow each of the +others with \verb"\vspace{\stretch{1}}". (You can use any decimal +number for the \verb"\stretch" value. For example, +\verb"\vspace{\stretch{1.5}}" will allocate 1.5 times the amount of +space allocated by \verb"\vspace{\stretch{1}}".) + +In addition to leaving blank space, it's also possible to leave lined +space, dotted lined space, space printed with a grid, or an empty box. +For the full story, see section~\ref{sec:LeaveSpace}. + +%-------------------------------------------------------------------- +\subsection{Headers and footers} +\label{sec:BasicHeadFoot} +\index{header|(} +\index{footer|(} + +To produce headers and footers, you give the command\indc{pagestyle} +\begin{center} + \verb"\pagestyle{headandfoot}" +\end{center} +in the preamble (i.e., after the \verb"\documentclass" command and +before the \verb"\begin{document}" command), followed by the commands +that say what will be in the headers and footers. Headers and +footers each have three parts: One part on the left, one centered +part, and one part on the right, and any of these can be empty. + +The headers and footers are determined by the commands% +\indc{firstpageheader}\indc{firstpagefooter}\indc{firstpageheadrule}% +\indc{firstpagefootrule}\indc{runningheader}\indc{runningfooter}% +\indc{runningheadrule}\indc{runningfootrule} +\begin{center} + \begin{tabular}{l@{\qquad}l} + \verb"\firstpageheader"& for the header on the first page,\\ + \verb"\firstpagefooter"& for the footer on the first page,\\ + \verb"\firstpageheadrule"& to put a horizontal rule in the head of + the first page,\\ + \verb"\firstpagefootrule"& to put a horizontal rule in the foot of + the first page,\\[0.5ex] + \verb"\runningheader"& for the header after the first page,\\ + \verb"\runningfooter"& for the footer after the first page\\ + \verb"\runningheadrule"& to put a horizontal rule in the head + after the first page, and\\ + \verb"\runningfootrule"& to put a horizontal rule in the foot + after the first page.\\ + \end{tabular} +\end{center} + +For example, to have the header +% +\samplehead{Math 115}{First Exam}{July 4, 1776}{} +% +on the first page, the header +% +\samplehead{Math 115}{First Exam, Page 2 of 5}{July 4, 1776}{\hrule} +% +on all pages after the first, and no footer on any page, give the +commands +\begin{verbatim} +\pagestyle{headandfoot} +\runningheadrule +\firstpageheader{Math 115}{First Exam}{July 4, 1776} +\runningheader{Math 115} + {First Exam, Page \thepage\ of \numpages} + {July 4, 1776} +\firstpagefooter{}{}{} +\runningfooter{}{}{} +\end{verbatim} + +For another example, to have the header +% +\samplehead{Math 115}{First Exam}{July 4, 1776}{} +% +on the first page, no header on the pages after the first, no footer +on the first page, and the footer +% +\samplefoot{\hrule}{Math 115}{First Exam}{Page 2 of 5} +% +on all pages after the first, give the commands +\begin{verbatim} +\pagestyle{headandfoot} +\firstpageheader{Math 115}{First Exam}{July 4, 1776} +\runningheader{}{}{} +\firstpagefooter{}{}{} +\runningfooter{Math 115}{First Exam}{Page \thepage\ of \numpages} +\runningfootrule +\end{verbatim} + +Sections~\ref{sec:beginexamples} through \ref{sec:endexamples} contain +many other examples of headers and footers, and the full explanation +of the commands for headers and footers is in +sections~\ref{sec:pagestyle}--\ref{sec:QuesSpan}. + +\index{header|)} +\index{footer|)} + +%--------------------------------------------------------------------- +%-------------------------------------------------------------------- +\section{The \texttt{\bs documentclass} command} +\label{sec:Documentclass} + +To use the \verb"exam" document class, you should specify \verb"exam" +as the required argument to your +\verb"\documentclass"\indc{documentclass} +command, as in +\begin{center} + \verb"\documentclass{exam}" +\end{center} +or, e.g., if you want to use 12~point type, +\begin{center} + \verb"\documentclass[12pt]{exam}" +\end{center} +There are two possible optional arguments that are specific to the +\verb"exam" document class: +\verb"addpoints"\indcsub{documentclass}{options} and \verb"solutions". +Most documents that use the \verb"exam" document class should use the +option \verb"addpoints" (see section~\ref{sec:addpoints}); the option +\verb"answers" is used when you want to print solutions to the +questions (see section~\ref{sec:answers}). + +%-------------------------------------------------------------------- +\subsection{The option \texttt{addpoints}} +\label{sec:addpoints} + +The \verb"\documentclass" option +\verb"addpoints"\indt{addpoints}\indcsub{documentclass}{options}, used +as in +\begin{center} + \verb"\documentclass[addpoints]{exam}" +\end{center} +or +\begin{center} + \verb"\documentclass[12pt,addpoints]{exam}" +\end{center} +enables the commands that add up the points (see sections +\ref{sec:addup}, \ref{sec:Count}, \ref{sec:pointsofq}, +and~\ref{sec:pointsonp}) and that produce grading tables and point +tables (see sections \ref{sec:GradeTables} and~\ref{sec:PointTables}). +This is an option, rather than the default, mainly for the sake of +maintaining backward compatibility; most documents that use the +\verb"exam" document class should use this option. The only reason +\emph{not} to use the \verb"addpoints" option is that this option +creates an error if you include any words in an argument that assigns +points to a question (see section~\ref{sec:points}). If +\verb"addpoints" is not in effect you can put whatever you want in the +argument for the points, but if \verb"addpoints" \emph{is} in effect +then the argument that contains the points must contain only digits +and the command \verb"\half" (see section~\ref{sec:Half}). + +You can also turn \verb"addpoints" on and off wherever you like in the +exam by using the commands\indc{addpoints}\indc{noaddpoints} +\begin{center} + \begin{tabular}{l} + \verb"\addpoints"\\ + \verb"\noaddpoints" + \end{tabular} +\end{center} +Using the document class option \verb"addpoints" is equivalent to +giving the command \verb"\addpoints" at the beginning of the exam. + +%-------------------------------------------------------------------- +\subsection{The option \texttt{answers}} +\label{sec:answers} + +If you will be typing solutions into the exam (see sections +\ref{sec:solutions}, \ref{sec:CorrectChoice}, +and~\ref{sec:AnsShortAns}) and you'd like the solutions to be printed +on the next run of \LaTeX, you should include the document class +option \verb"answers"\indt{answers}\indcsub{documentclass}{options}, +as in +\begin{center} + \verb"\documentclass[answers]{exam}" +\end{center} +or +\begin{center} + \verb"\documentclass[answers,12pt]{exam}" +\end{center} +or +\begin{center} + \verb"\documentclass[12pt,addpoints,answers]{exam}" +\end{center} +Using the document class option \verb"answers" is equivalent to giving +the command \verb"\printanswers"\indc{printanswers} at the beginning +of the exam (see section~\ref{sec:solutions}). The effect of this is +that +\begin{itemize} +\item the contents of the environments + % + \index{solution environment@\texttt{solution} environment}% + % + \indt{solutionorbox}% + \indt{solutionorlines}\indt{solutionordottedlines}% + \indt{solutionorgrid}\indt{solutionbox} + \begin{center} + \begin{tabular}{l} + \verb"solution",\\ + \verb"solutionorbox",\\ + \verb"solutionorlines",\\ + \verb"solutionordottedlines",\\ + \verb"solutionorgrid", and\\ + \verb"solutionbox" + \end{tabular} + \end{center} + (see section~\ref{sec:solutions}) will be printed, +\item any choices of a \texttt{choices}\indt{choices}, + \texttt{oneparchoices}\indt{oneparchoices}, + \texttt{checkboxes}\indt{checkboxes}, or + \texttt{oneparcheckboxes}\indt{oneparcheckboxes} environment (see + section~\ref{sec:MulChc}) that are created using a + \verb"\CorrectChoice"\indc{CorrectChoice} command (see + section~\ref{sec:CorrectChoice}) instead of a + \verb"\choice"\indc{choice} command will be printed with emphasis as + determined by the argument of the most recent + \verb"\CorrectChoiceEmphasis"\indc{CorrectChoiceEmphasis} command + (which by default is \verb"\bfseries"), and +\item any \verb"\answerline"\indc{answerline} commands (see + section~\ref{sec:ShortAns})\indcsub{answerline}{optional~argument} + that include an optional argument containing the answer (see + section~\ref{sec:AnsShortAns}) will have the answer printed on the + answer line. +\end{itemize} + + +%--------------------------------------------------------------------- +%-------------------------------------------------------------------- +\section{Questions and points} +\label{sec:QuestionsPoints} + +To create questions, you use a \verb"questions"\indt{questions} +% +environment\index{questions environment}\index{environment!questions} +(see section~\ref{sec:Questions}); each question is begun with a +\verb"\question"\indc{question} command, which takes an optional +argument to assign some number of points\index{points} to the question +(see section~\ref{sec:points}). The questions are numbered +automatically. Point values can include half points (see +section~\ref{sec:Half}). + +If you want a question to have several parts, you use a +% +\verb"parts"\indt{parts}% +\index{parts environment}\index{environment!parts} environment (see +section~\ref{sec:parts}); each part is begun with a +\verb"\part"\indc{part} command, which takes an optional argument to +assign some number of points to the part (see +section~\ref{sec:points}). The parts are numbered automatically. +Similarly, parts can have subparts, and subparts can have subsubparts +(see section~\ref{sec:parts}). + +The points for a question (or part, or subpart, or subsubpart) appear +by default at the beginning of the question (or part, etc.), but there +are commands to have the points appear instead in either the left +margin or in the right margin (see section~\ref{sec:whereprint} and +section~\ref{sec:DrpPts}). The formatting of the points can also be +customized (see sections \ref{sec:Boxed}, \ref{sec:pointname}, +\ref{sec:margins}, and~\ref{sec:pointformat}). It's also possible to +have questions (or parts, etc.) that are worth ``bonus points'', which +are added up separately from the non-bonus points (see +section~\ref{sec:Bonus}). + + +%-------------------------------------------------------------------- +\subsection{Questions} +\label{sec:Questions} + +To type the questions on the exam you use the +% +\verb"questions"\indt{questions}\index{questions environment}% +\index{environment!questions} environment. Each question is then +begun with the command \verb"\question"\indc{question}, and the +questions are numbered automatically. + +For example, if you type +\begin{verbatim} +\begin{questions} + +\question +Why is there air? + +\question + +How much wood would a woodchuck chuck if a woodchuck could chuck +wood? + +\question Compute $\displaystyle\int_0^1 x^2 \, dx$. +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + +\question +Why is there air? + +\question + +How much wood would a woodchuck chuck if a woodchuck could chuck +wood? + +\question Compute $\displaystyle\int_0^1 x^2 \, dx$. +\end{questions} + +\bigskip + +As the above example illustrates, you can leave blank lines +% +\index{blank lines} between the \verb"\question" command and the +actual beginning of the question, or before the first \verb"\question" +command in the environment, and they will be ignored. + + +%--------------------------------------------------------------------- +\subsection{Questions with parts and subparts (and subsubparts)} +\label{sec:parts} + +If you want a question to have several parts, then you use the +% +\verb"parts"\indt{parts}\index{parts environment}% +\index{environment!parts} environment. For example, if you type +\begin{verbatim} +\begin{questions} +\question +Why is there air? + +\question +What if there were no air? + +\begin{parts} +\part +Describe the effect on the balloon industry. + +\part +Describe the effect on the aircraft industry. +\end{parts} + +\question + +\begin{parts} +\part +Define the universe. Give three examples. + +\part +If the universe were to end, how would you know? + +\end{parts} + + +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} +\question +Why is there air? + +\question +What if there were no air? + +\begin{parts} +\part +Describe the effect on the balloon industry. + +\part +Describe the effect on the aircraft industry. +\end{parts} + +\question + +\begin{parts} +\part +Define the universe. Give three examples. + +\part +If the universe were to end, how would you know? + +\end{parts} + + +\end{questions} + +\bigskip + +The above example illustrates several things: +\begin{itemize} +\item Parts of a question should be put into a + \verb"parts"\indt{parts}\index{parts environment}% + \index{environment!parts} environment. +\item If a question begins with a \verb"parts" environment, then the + first part will appear on the same line with the question number. +\item You can leave blank + % + lines\index{blank lines} before and after the \verb"\part" command, + and they will be ignored. +\end{itemize} + +\bigskip + +There is also a \verb"subparts"\indt{subparts}% +\index{subparts environment}\index{environment!subparts} environment, +and even a \verb"subsubparts"\indt{subsubparts}% +\index{subsubparts environment}\index{environment!subsubparts} +environment, and they work just as you would expect. For example, if +you type\indc{subpart}\indc{subsubpart} +\begin{verbatim} +\begin{questions} +\question +\begin{parts} +\part +What do you do with a drunken sailor? + +\part +Is your answer different if it is before noon? + +\end{parts} + +\question +This is the second question. + +\begin{parts} +\part +This is a part. + +\part +This is also a part. + +\begin{subparts} +\subpart +This is a subpart. + +\subpart +This is a periscope. + +\subpart +This is a pair of diving planes. + +\subpart +\begin{subsubparts} +\subsubpart +This is a subsubpart. + +\subsubpart +The lower surface of a diving plane? + +\subsubpart +The ocean floor, perhaps? + +\end{subsubparts} +\end{subparts} + +\part +It's sad to be apart. + +\end{parts} + +\question +\begin{parts} +\part +\begin{subparts} +\subpart +This is a subpart. + +\subpart +This is another subpart. +\end{subparts} +\part +This is another part. + +\end{parts} + + +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} +\question +\begin{parts} +\part +What do you do with a drunken sailor? + +\part +Is your answer different if it is before noon? + +\end{parts} + +\question +This is the second question. + +\begin{parts} +\part +This is a part. + +\part +This is also a part. + +\begin{subparts} +\subpart +This is a subpart. + +\subpart +This is a periscope. + +\subpart +This is a pair of diving planes. + +\subpart +\begin{subsubparts} +\subsubpart +This is a subsubpart. + +\subsubpart +The lower surface of a diving plane? + +\subsubpart +The ocean floor, perhaps? + +\end{subsubparts} +\end{subparts} + +\part +It's sad to be apart. + +\end{parts} + +\question +\begin{parts} +\part +\begin{subparts} +\subpart +This is a subpart. + +\subpart +This is another subpart. +\end{subparts} +\part +This is another part. + +\end{parts} + + +\end{questions} + +The numbers and letters used to number questions, parts, subparts, and +subsubparts can be customized; see section~\ref{sec:CustNumb}. + +%--------------------------------------------------------------------- +\subsection{Point values for the questions} +\label{sec:points} +\indcsub{question}{optional argument} +\indcsub{part}{optional argument} +\indcsub{subpart}{optional argument} +\indcsub{subsubpart}{optional argument} +\index{points|(} + +Each of the commands \verb"\question", \verb"\part", \verb"\subpart", +and \verb"\subsubpart" takes an optional argument, which is the number +of points for that question, part, subpart, or subsubpart. The +default setup is that +\begin{itemize} +\item the point value is printed at the beginning of the question (or + part, or subpart, or subsubpart) (this can be changed to printing in + either the left or right margins on the first line of the question + or in the right margin at the end of the question; see + section~\ref{sec:whereprint} and section~\ref{sec:DrpPts}), and +\item the point value is enclosed in parentheses (this can be changed + to either square brackets or a box; see section~\ref{sec:Boxed}). +\end{itemize} +Both of these things can be further customized; see +section~\ref{sec:qformat} and section~\ref{sec:pointformat}. + +%-------------------------------------------------------------------- +\subsubsection{Where the points will be printed} +\label{sec:whereprint} +\index{points!where printed|(} + +The default is that the point value will be inserted at the beginning +of the question (or part, or subpart, or subsubpart) in parentheses, +but +\begin{itemize} +\item the command \verb"\pointsinmargin"\indc{pointsinmargin} (or, + equivalently, the command + \verb"\pointsinleftmargin"\indc{pointsinleftmargin}) will cause the + point values to be set in the left margin, +\item the command + \verb"\pointsinrightmargin"\indc{pointsinrightmargin} will cause the + point values to be set in the right margin, +\item the command + \verb"\pointstwosided"\indc{pointstwosided} will cause the + point values to be set + \begin{itemize} + \item in the right margin on odd numbered pages and + \item in the left margin on even numbered pages, + \end{itemize} +\item the command + \verb"\pointstwosidedreversed"\indc{pointstwosidedreversed} will + cause the point values to be set + \begin{itemize} + \item in the left margin on odd numbered pages and + \item in the right margin on even numbered pages, and + \end{itemize} +\item the commands \verb"\nopointsinmargin"\indc{nopointsinmargin} and + \verb"\nopointsinrightmargin"\indc{nopointsinrightmargin} are + equivalent, and either of them will revert to the default situation. +\end{itemize} +All of these print the point values on the first line of the question +(or part, or subpart, or subsubpart). There is also a way to print +the point values on the \emph{last} line of the question (or part, +etc.); for this, see section~\ref{sec:DrpPts}. + +\medbreak + +For example, if you type +\begin{verbatim} +\begin{questions} +\question[20] +Why is there air? + + +\question +What if there were no air? + +\begin{parts} +\part[10] +Describe the effect on the balloon industry. + +\part[10] +Describe the effect on the aircraft industry. +\end{parts} + +\end{questions} +\end{verbatim} +then, with the default setup, you'll get +\nopointsinmargin +\begin{questions} +\question[20] +Why is there air? + + +\question +What if there were no air? + +\begin{parts} +\part[10] +Describe the effect on the balloon industry. + +\part[10] +Describe the effect on the aircraft industry. +\end{parts} + +\end{questions} +(To change the word ``points'', see the commands described in +section~\ref{sec:pointname}.) + +\bigskip If you give the command +\verb"\pointsinmargin"\indc{pointsinmargin} (or, equivalently, +\verb"\pointsinleftmargin"\indc{pointsinleftmargin}), then the above input +will produce instead \pointsinmargin +\begin{questions} +\question[20] +Why is there air? + + +\question +What if there were no air? + +\begin{parts} +\part[10] +Describe the effect on the balloon industry. + +\part[10] +Describe the effect on the aircraft industry. +\end{parts} + +\end{questions} +(To have a word (e.g., ``points'', or ``\%'') inside the parentheses +with the point values, see the +\verb"\marginpointname"\indc{marginpointname} command in +section~\ref{sec:pointname}.) + + +\bigskip + +If you give the command +\verb"\pointsinrightmargin"\indc{pointsinrightmargin}, then the above +input will produce instead +% +\pointsinrightmargin +\begin{questions} +\question[20] +Why is there air? + + +\question +What if there were no air? + +\begin{parts} +\part[10] +Describe the effect on the balloon industry. + +\part[10] +Describe the effect on the aircraft industry. +\end{parts} + +\end{questions} + +%-------------------------------------------------------------------- +\subsubsection{Printing the points at the end of the question} +\label{sec:DrpPts} +\index{points!at the end of the question|(} +\indcstart{pointsdroppedatright} +\indcstart{droppoints} + + +Instead of having the point value of a question (or part, or subpart, +or subsubpart) printed on the first line of a question, you can have +it printed in the right margin opposite the \emph{last} line, or even +opposite a blank line following the paragraph. This is done with the +\begin{center} + \verb"\pointsdroppedatright" + \quad and \quad + \verb"\droppoints" +\end{center} +commands. + +If you give the command +\begin{center} + \verb"\pointsdroppedatright" +\end{center} +then point values are not printed until you give the command +\verb"\droppoints" (and they're not printed at all if you don't give +the command \verb"\droppoints"). The only exception to this rule is +that if you've given a \verb"\qformat"\indc{qformat} command (see +section~\ref{sec:qformat}), then question number lines are printed as +specified by the argument to the \verb"\qformat" command even if you +have given the command +\verb"\pointsdroppedatright" + +The command \verb"\droppoints" should be given only at the end of a +paragraph or between paragraphs; if you give it within a paragraph, it +causes the paragraph to end. \verb"\droppoints" prints the point +value in the right margin, formatted as it is when you give the +command \verb"\pointsinrightmargin"\indc{pointsinrightmargin}, except +that the points appear opposite the last line of the paragraph (or, if +the command \verb"\droppoints" is given between paragraphs, then +additional vertical space is left between the paragraphs and the +points are printed opposite the blank space). The formatting can be +changed by giving the commands +\verb"\bracketedpoints"\indc{bracketedpoints}, +\verb"\boxedpoints"\indc{boxedpoints}, or +\verb"\marginpointname"\indc{marginpointname} (see +section~\ref{sec:pointname}) just as if \verb"\pointsinrightmargin" +were in effect. The command \verb"\droppoints" actually works this +way even if one of the commands +\begin{center} + \verb"\nopointsinmargin",\quad \verb"\pointsinmargin",\quad or\quad + \verb"\pointsinrightmargin" +\end{center} +is in effect, but if you use it that way the points will appear twice +on the page, which is probably not what you want. + + +For example, if you give the command \verb"\pointsdroppedatright" and +then type +\begin{verbatim} +\begin{questions} +\question[10] +Describe the implications of the Michelson-Morley ink drop experiment +for the use of punctuation marks such as colons and semicolons that +require multiple drops of ink. +\droppoints + +\question[10] +Prove that the second dual of a finite dimensional real vector space +is naturally isomorphic to the given vector space, except when the +weapon chosen is a single shot pistol.\droppoints + +\end{questions} +\end{verbatim} +then you'll get +\pointsdroppedatright +\begin{questions} +\question[10] +Describe the implications of the Michelson-Morley ink drop experiment +for the use of punctuation marks such as colons and semicolons that +require multiple drops of ink. +\droppoints + +\question[10] +Prove that the second dual of a finite dimensional real vector space +is naturally isomorphic to the given vector space, except when the +weapon chosen is a single shot pistol.\droppoints + +\end{questions} +and if you type +\begin{verbatim} +\begin{questions} +\question[10] +Describe the implications of the Michelson-Morley ink drop experiment +for the use of punctuation marks such as colons and semicolons that +require multiple drops of ink. + +\droppoints + +\question[10] +Prove that the second dual of a finite dimensional real vector space +is naturally isomorphic to the given vector space, except when the +weapon chosen is a single shot pistol. + +\droppoints +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} +\question[10] +Describe the implications of the Michelson-Morley ink drop experiment +for the use of punctuation marks such as colons and semicolons that +require multiple drops of ink. + +\droppoints + +\question[10] +Prove that the second dual of a finite dimensional real vector space +is naturally isomorphic to the given vector space, except when the +weapon chosen is a single shot pistol. + +\droppoints +\end{questions} +\nopointsinmargin + +\indcstop{droppoints} +\indcstop{pointsdroppedatright} +\index{points!at the end of the question|)} +\index{points!where printed|)} + +%-------------------------------------------------------------------- +\subsubsection{Half points} +\label{sec:Half} +\index{points!half|(} +\index{half points|(} + +The point values of questions, parts, subparts, and subsubparts can +include half points. To specify half points, you either +type\indc{half} +\begin{center} + \verb"\half" +\end{center} +immediately following the integer part of the point value or just type +\verb"\half" as the entire point value. That is, the valid point +values and their (default) printed appearances are:\indc{half} +\begin{center} + \begin{tabular}{@{\extracolsep{0.1in}}rccccccc} + Typed:& \verb"0"& \verb"\half"& \verb"1"& \verb"1\half"& \verb"2"& + \verb"2\half"& $\cdots$\\[1ex] + Printed:& 0& \half& 1& 1\half& 2& 2\half& $\cdots$ + \end{tabular} +\end{center} +If you prefer, you can cause the fraction \half{} to be printed as +\makeatletter +\horiz@half. +\makeatother +To do this, you give the +command\indc{usehorizontalhalf}% +\index{customization!\texttt{\char`\\half}}% +\indcsub{half}{customization} +\begin{center} + \verb"\usehorizontalhalf" +\end{center} +after which the printed appearance of point values will be +\usehorizontalhalf +\begin{center} + \begin{tabular}{@{\extracolsep{0.1in}}rccccccc} + Typed:& \verb"0"& \verb"\half"& \verb"1"& \verb"1\half"& \verb"2"& + \verb"2\half"& $\cdots$\\[1ex] + Printed:& 0& \half& 1& 1\half& 2& 2\half& $\cdots$ + \end{tabular} +\end{center} +If you want to return to using the default appearance, you can do that +by giving the command\indc{useslantedhalf} +\begin{center} + \verb"\useslantedhalf" +\end{center} +\useslantedhalf + +\index{half points|)} +\index{points!half|)} + + +%-------------------------------------------------------------------- +\subsubsection{Surrounding the points: Parentheses, brackets, or a box} +\label{sec:Boxed} +\index{customization!points|(} +\index{points!customization|(} + +If you prefer having the points enclosed in brackets instead of in +parentheses, give the command\indc{bracketedpoints} +\begin{center} + \verb"\bracketedpoints" +\end{center} +For example, if you give the command \verb"\bracketedpoints", then the +questions typed above will produce +\nopointsinmargin +\bracketedpoints +\begin{questions} +\question[20] +Why is there air? + + +\question +What if there were no air? + +\begin{parts} +\part[10] +Describe the effect on the balloon industry. + +\part[10] +Describe the effect on the aircraft industry. +\end{parts} + +\end{questions} + + +If you prefer having the points enclosed in a box instead of in +parentheses, give the command\indc{boxedpoints} +\begin{center} + \verb"\boxedpoints" +\end{center} +For example, if you give the command \verb"\boxedpoints", then the +questions typed above will produce +\nopointsinmargin +\boxedpoints +\begin{questions} +\question[20] +Why is there air? + + +\question +What if there were no air? + +\begin{parts} +\part[10] +Describe the effect on the balloon industry. + +\part[10] +Describe the effect on the aircraft industry. +\end{parts} + +\end{questions} +If you give the commands \verb"\boxedpoints"\indc{boxedpoints} and +\verb"\pointsinmargin"\indc{pointsinmargin}, then the above questions +will produce +% +\boxedpoints \pointsinmargin +\begin{questions} +\question[20] +Why is there air? + + +\question +What if there were no air? + +\begin{parts} +\part[10] +Describe the effect on the balloon industry. + +\part[10] +Describe the effect on the aircraft industry. +\end{parts} + +\end{questions} +If you give the commands \verb"\bracketedpoints"\indc{bracketedpoints} +and \verb"\pointsinrightmargin"\indc{pointsinrightmargin}, then the +above questions will produce +% +\bracketedpoints +\pointsinrightmargin +\begin{questions} +\question[20] +Why is there air? + + +\question +What if there were no air? + +\begin{parts} +\part[10] +Describe the effect on the balloon industry. + +\part[10] +Describe the effect on the aircraft industry. +\end{parts} + +\end{questions} +Other combinations of these commands will produce similar effects. + +If you want to switch back and forth between formats during the exam, +you can do so by giving one of the +commands\indc{boxedpoints}\indc{bracketedpoints}\indc{noboxedpoints} +\indc{nobracketedpoints} +\begin{center} + \begin{tabular}{l} + \verb"\boxedpoints"\\ + \verb"\bracketedpoints"\\ + \verb"\noboxedpoints"\\ + \verb"\nobracketedpoints" + \end{tabular} +\end{center} +whenever you want to switch. (The commands +\verb"\nobracketedpoints" and \verb"\noboxedpoints" are equivalent; +they both return to the default of putting parentheses around the +points.) + +If you want some text (e.g., `` points'', or ``\%'') automatically +inserted along with the point values when using either +\verb"\pointsinmargin", \verb"\pointsinrightmargin", +\verb"\pointstwosided", or \verb"\pointstwosidedreversed", see the +command \verb"\marginpointname" in section~\ref{sec:pointname}. + + + +%--------------------------------------------------------------------- +\subsubsection{Using a substitute for the word ``points''} +\label{sec:pointname} +\index{points!substitute words|(} +\index{points!language|(} + +With the default setup, the number of points is inserted before the +text of the question followed by a single space and the word ``point'' +if the number of points is either \half{} or 1 and by the word +``points'' otherwise. That is, the default is +\verb"\nopointsinmargin"\indc{nopointsinmargin} and +\verb"\noboxedpoints"\indc{noboxedpoints} (see sections +\ref{sec:whereprint} and \ref{sec:Boxed}), and if you type +% +\nopointsinmargin +\noboxedpoints +\begin{verbatim} +\begin{questions} + \question[1] + This is a short question. + + \question[5] + This is a longer question, requiring more thought. +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question[1] + This is a short question. + + \question[5] + This is a longer question, requiring more thought. +\end{questions} +The way this is achieved is: +\begin{itemize} +\item There is a command\indc{points} + \begin{center} + \verb"\points" + \end{center} + whose default definition expands to the word `point' if the number + of points is either \half{} or 1 and to `points' otherwise. (This + behavior can be modified by the command + \verb"\pointpoints"\indc{pointpoints}; see below.) +\item There is a command\indc{pointname} + \begin{center} + \verb"\pointname{Text}" + \end{center} + that causes `Text' to be inserted following the number of points of + a question, part, subpart, or subsubpart. The default setup is the + result of the command\indc{pointname}\indc{points} + \begin{center} + \verb"\pointname{ \points}" + \end{center} + (Note the single space before the command \verb"\points".) +\end{itemize} + +There is also a command\indc{pointpoints} +\begin{center} + \verb"\pointpoints{SingularText}{PluralText}" +\end{center} +that changes the behavior of the \verb"\points" command so that it +expands to `SingularText' if the number of points is \half{} or 1 and +to `PluralText' otherwise. (The default is the result of the command +\verb"\pointpoints{point}{points}"\indc{pointpoints}.) Thus, if you +give the command +\begin{center} + \verb"\pointpoints{Punkt}{Punkte}" +\end{center} +then typing the questions above would result in +\pointpoints{Punkt}{Punkte} +\begin{questions} + \question[1] + This is a short question. + + \question[5] + This is a longer question, requiring more thought. +\end{questions} +There is also a command\indc{marksnotpoints}\index{marks} +\begin{center} + \verb"\marksnotpoints" +\end{center} +that is equivalent to the two +commands\indc{pointpoints}\indc{bonuspointpoints}\index{marks} +\begin{center} + \begin{tabular}{l} + \verb"\pointpoints{mark}{marks}"\\ + \verb"\bonuspointpoints{mark (bonus)}{marks (bonus)}" + \end{tabular} +\end{center} +(the command \verb"\bonuspointpoints" is described in +section~\ref{sec:Bonus}). That command would cause the above +questions to be printed as +% +\pointpoints{mark}{marks} +\begin{questions} + \question[1] + This is a short question. + + \question[5] + This is a longer question, requiring more thought. +\end{questions} + +\bigskip + +For another example, if you give the command\indc{pointname} +\begin{center} +\verb"\pointname{\%}" +\end{center} +then the above questions would be printed as +% +\pointname{\%} +\nopointsinmargin +\noboxedpoints +\begin{questions} + \question[1] + This is a short question. + + \question[5] + This is a longer question, requiring more thought. +\end{questions} +\pointname{ \points} + + +\subsubsection*{Using \texttt{\char`\\marginpointname}} + +Similarly, the command \verb"\marginpointname"\indc{marginpointname} +can be used to affect the text set with the number of points when +\verb"\pointsinmargin"\indc{pointsinmargin} or +\verb"\pointsinrightmargin"\indc{pointsinrightmargin} is in effect. +For example, if you give the commands +\begin{center} + \begin{tabular}{l} + \verb"\pointsinmargin"\\ + \verb"\marginpointname{\%}" + \end{tabular} +\end{center} +and then type +\begin{verbatim} +\question[25] +Where, oh where, has my little dog gone? +\end{verbatim} +then you'll get +\pointsinmargin +\noboxedpoints +\marginpointname{\%} +\begin{questions} +\question[25] +Where, oh where, has my little dog gone? +\end{questions} +unless, e.g., you've also given the command +\verb"\boxedpoints"\indc{boxedpoints} (see section~\ref{sec:Boxed}), +in which case you'll get +% +\pointsinmargin +\boxedpoints +\marginpointname{\%} +\begin{questions} +\question[25] +Where, oh where, has my little dog gone? +\end{questions} +If you give the commands +\begin{center} + \begin{tabular}{l} + \verb"\marksnotpoints"\\ + \verb"\marginpointname{ \points}" + \end{tabular} +\end{center} +then the above will print +\noboxedpoints +\marginpointname{ \points} +\marksnotpoints +\begin{questions} +\question[25] +Where, oh where, has my little dog gone? +\end{questions} +\nopointsinmargin +\marginpointname{} +\pointpoints{point}{points} +\bonuspointpoints{point (bonus)}{points (bonus)} + +Using the default is equivalent to giving the +command\indc{marginpointname} +\begin{center} + \verb"\marginpointname{}" +\end{center} + + +%-------------------------------------------------------------------- +\subsubsection{Using \texttt{\bs marginpointname} and enlarging the + margins} +\label{sec:margins} + +The default margins are not very large, and so if you use +\verb"\marginpointname"\indc{marginpointname} (see +section~\ref{sec:pointname}) to place any words along with the point +values in the margin, you may run out of room. The solution to this +problem is to enlarge the margins\index{margins!enlarge} by using the +\verb"\extrawidth"\indc{extrawidth} command with a negative argument +to \emph{decrease} the width of the text area, and thus +\emph{increase} the width of the margins. For example, the commands +\begin{center} + \begin{tabular}{ll} + \verb"\extrawidth{-1in}"\\ + \verb"\marginpointname{ \points}" + \end{tabular} +\end{center} +will increase each of the left and right margins by one half inch, +which will easily leave room for the word ``points''. (See +section~\ref{sec:pagesize} for a discussion of the \verb"\extrawidth" +command.) + +%-------------------------------------------------------------------- +\subsubsection{Completely customizing the points} +\label{sec:pointformat} + +If the customizations described in section~\ref{sec:Boxed} and +section~\ref{sec:pointname} (using \verb"\bracketedpoints", +\verb"\boxedpoints", \verb"\pointpoints", \verb"\pointname", and +\verb"\marginpointname") aren't sufficient, and you don't want to use +the \verb"\qformat" command to create a customized question number +line (see section~\ref{sec:qformat}), you can completely customize the +way the points are printed by using the +commands\indc{pointformat}\indc{bonuspointformat} +\begin{center} + \begin{tabular}{l} + \verb"\pointformat"\\ + \verb"\bonuspointformat" +\end{tabular} +\end{center} +The \verb"\pointformat" command controls the printing of ``regular'' +points (i.e., non-bonus points) and the \verb"\bonuspointformat" +command controls the printing of bonus points (see +section~\ref{sec:Bonus}). + +Each of the commands \verb"\pointformat" and \verb"\bonuspointformat" +takes one argument, and that argument is what actually appears on the +page whether the points are being printed at the beginning of the +question (the default), in the left margin (because of +\verb"\pointsinmargin"), in the right margin (because of +\verb"\pointsinrightmargin"), or dropped in the right margin at the +end of the question (because of \verb"\pointsdroppedatright"). The +arguments to \verb"\pointformat" and \verb"\bonuspointformat" should +contain either the command\indc{thepoints} +\begin{center} + \verb"\thepoints" +\end{center} +(which for non-bonus points prints the number of points followed by +the argument to the last \verb"\pointname"\indc{pointname} command and +for bonus points prints the number of bonus points followed by the +argument to the last \verb"\bonuspointname"\indc{bonuspointname} +command; see section~\ref{sec:pointname}) or the +command\indc{themarginpoints} +\begin{center} + \verb"\themarginpoints" +\end{center} +(which for non-bonus points prints the number of points followed by +the argument to the last \verb"\marginpointname"\indc{marginpointname} +command and for bonus points prints the number of bonus points +followed by the argument to the last +\verb"\marginbonuspointname"\indc{marginbonuspointname} command; see +section~\ref{sec:pointname}). If the argument doesn't contain either +\verb"\thepoints" or \verb"\themarginpoints", then the number of +points will not appear. + +For example, the command \verb"\bracketedpoints" is equivalent to +either\indc{bracketedpoints}\indc{pointformat}% +\indc{bonuspointformat}\indc{thepoints} +\begin{center} + \begin{tabular}{l} + \verb"\pointformat{[\thepoints]}"\\ + \verb"\bonuspointformat{[\thepoints]}" + \end{tabular} +\end{center} +if the points are being printed at the beginning of the question, or +\indc{pointformat}\indc{bonuspointformat}\indc{themarginpoints} +\begin{center} + \begin{tabular}{l} + \verb"\pointformat{[\themarginpoints]}"\\ + \verb"\bonuspointformat{[\themarginpoints]}" + \end{tabular} +\end{center} +if the points are being printed in one of the margins. + +For another example, the command \verb"\boxedpoints" is equivalent to +either\indc{pointformat}\indc{bonuspointformat}\indc{thepoints} +\begin{center} + \begin{tabular}{l} + \verb"\pointformat{\fbox{\thepoints}}"\\ + \verb"\bonuspointformat{\fbox{\thepoints}}" + \end{tabular} +\end{center} +if the points are being printed at the beginning of the question, or +\indc{pointformat}\indc{bonuspointformat}\indc{themarginpoints} +\begin{center} + \begin{tabular}{l} + \verb"\pointformat{\fbox{\themarginpoints}}"\\ + \verb"\bonuspointformat{\fbox{\themarginpoints}}" + \end{tabular} +\end{center} +if the points are being printed in one of the margins. + +For another example, the +commands\indc{marginpointname}\indc{pointsinmargin}\indc{pointformat}% +\indc{pointsinmargin} +\begin{verbatim} +\begin{questions} + \pointsinmargin + \marginpointname{\%} + \pointformat{\slshape (\themarginpoints)} + \question[3] What is the point? +\end{questions} +\end{verbatim} +will produce +\begin{questions} + \pointsinmargin + \marginpointname{\%} + \pointformat{\slshape (\themarginpoints)} + \question[3] What is the point? +\end{questions} + +For another example, the +commands\indc{marginpointname}\indc{pointsinmargin}\indc{pointformat}% +\indc{pointsinrightmargin} +\begin{verbatim} +\begin{questions} + \pointsinrightmargin + \marginpointname{\%} + \pointformat{\fbox{\bfseries\boldmath\themarginpoints}} + \question[3\half] What is the point? +\end{questions} +\end{verbatim} +will produce +\begin{questions} + \pointsinrightmargin + \marginpointname{\%} + \pointformat{\fbox{\bfseries\boldmath\themarginpoints}} + \question[3\half] What is the point? +\end{questions} +\nopointsinmargin (Note: The commands \verb"\bfseries" and +\verb"\boldmath"\indc{boldmath} are both needed here because the +\half{} printed when you use half points is printed in math mode while +the rest of the points are printed in text mode.) + +For another example, the commands\indc{pointformat}\indc{boldmath} +\begin{verbatim} +\begin{questions} + \pointname{} + \pointformat{\bfseries\boldmath(Points for this problem: \thepoints)} + \question[3\half] What is the point? +\end{questions} +\end{verbatim} +will produce +\begin{questions} + \pointname{} + \pointformat{\bfseries\boldmath(Points for this problem: \thepoints)} + \question[3\half] What is the point? +\end{questions} +% Put things back to the default situation, so we don't mess up +% later examples: +\noboxedpoints +\nopointsinmargin +\pointname{ \points} + +\index{points!language|)} +\index{points!substitute words|)} +\index{points!customization|)} +\index{customization!points|)} + +%--------------------------------------------------------------------- +\subsubsection{Questions that begin with a parts environment} +\index{questions!that begin with a parts environment} +\index{points!for both question and part} + +If a question begins with a parts environment, then the question +number and the number of the first part in the parts environment will +be printed on the same line (see section~\ref{sec:parts}). Thus, if +points are assigned to both the question and to the first part, both +of those point values will be printed on the same line. (Note: This +was not true in versions of the \verb"exam" document class earlier +than 2.3. In those versions, only the later of the two point values +would actually be printed.) If \verb"\pointsinmargin" or +\verb"\pointsinrightmargin" are in effect (see +section~\ref{sec:whereprint}), then the two point values will be +printed on top of each other, which is probably not what you want. +The same problem arises if a part begins with a subparts environment +or if a subpart begins with a subsubparts environment. + +If you want to assign points to both a question and to each part of a +parts environment, and if the first part will begin on the same line +as the question, the solution is to either use the default location +(i.e., \verb"\nopointsinmargin") or to put some of the points in the +margin and others not. For example, if you type +\begin{verbatim} +\begin{questions} + \pointsinmargin + \noaddpoints + \question[10] + \begin{parts} + \nopointsinmargin + \addpoints + \part[5] Who put the ``bop'' in the ``bop, sh-bop, sh-bop''? + \part[5] Who put the ``ram'' in the ``rama, rama ding-dong''? + \end{parts} +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \pointsinmargin + \noaddpoints + \question[10] + \begin{parts} + \nopointsinmargin + \addpoints + \part[5] Who put the ``bop'' in the ``bop, sh-bop, sh-bop''? + \part[5] Who put the ``ram'' in the ``rama, rama ding-dong''? + \end{parts} +\end{questions} + + + + +%-------------------------------------------------------------------- +\subsubsection{Adding up the points for a question} +\label{sec:addup} +\indt{addpoints} +\indc{addpoints} + +If you use the document class option \verb"addpoints" (as in +\verb"\documentclass[addpoints]{exam}") or give the command +\verb"\addpoints" (see section~\ref{sec:addpoints}), then you can use +the command\indc{droptotalpoints} +\begin{center} + \verb"\droptotalpoints" +\end{center} +to put into the right margin the total number of points for the +current question (including the points for all parts, subparts, and +subsubparts). (Section~\ref{sec:adding} describes a different way to +print the total number of points for a question.) The command +\verb"\droptotalpoints" should be used only at the end of a paragraph +or between paragraphs; if you use it within a paragraph, it causes the +paragraph to end. \verb"\droptotalpoints" prints the total points for +the current question in the right margin, formatted by default as: +% +\par\nobreak\medskip +\makeatletter +\leavevmode\nobreak\hfill +\rlap{%\hskip\rightmargin % Defined by the list environment + \hskip\@rightmargin % Defined by exam.cls + \hskip-\rightpointsmargin + \llap{Total for Question 2: 25}% +}% rlap +\makeatother +\par\medskip\noindent +% +(Note: The number of points is followed by the argument to the most +recently executed \verb"\marginpointname"\indc{marginpointname} +command (see section~\ref{sec:pointname}), which by default is empty.) + +If the current question is worth any bonus points (see +section~\ref{sec:Bonus}), then those bonus points will not be counted +by the \verb"\droptotalpoints" command, but they will be counted by +the\indc{droptotalbonuspoints} +\begin{center} + \verb"\droptotalbonuspoints" +\end{center} +command, which puts into the right margin the total number of bonus +points for the current question, formatted by default as: +\par\nobreak\medskip +\makeatletter +\leavevmode\nobreak\hfill +\rlap{%\hskip\rightmargin % Defined by the list environment + \hskip\@rightmargin % Defined by exam.cls + \hskip-\rightpointsmargin + \llap{Total for Question 2: 10 (bonus)}% +}% rlap +\makeatother +\par\medskip\noindent +(Note: The number of bonus points is followed by the argument to the +most recently executed +\verb"\marginbonuspointname"\indc{marginbonuspointname} command (see +section~\ref{sec:Bonus}), which by default is `` (bonus)''.) + +You can change the format used by the +\verb"\droptotalpoints"\indc{droptotalpoints} command with +the\indc{totalformat} +\begin{center} + \verb"\totalformat" +\end{center} +command. It takes one argument, and that argument becomes the command +to print the total points, right justified a distance of +\verb"\rightpointsmargin"\indc{rightpointsmargin} from the right edge +of the paper. The argument can contain the +command\indc{totalpoints}\indc{thequestion} +\begin{center} + \begin{tabular}{ll} + \verb"\totalpoints"& to print the number of points, and\\ + \verb"\thequestion"& to print the question number. + \end{tabular} +\end{center} +(\verb"\totalpoints" expands to +\verb"\pointsofquestion{\arabic{question}}"\indc{pointsofquestion}; +see section~\ref{sec:pointsofq} for a discussion of the +\verb"\pointsofquestion" command.) For example, if you give the +command\indc{totalformat}\indc{thequestion}\indc{totalpoints} +\begin{center} + \verb"\totalformat{Question \thequestion: \totalpoints}" +\end{center} +then the total number of points will be printed in the format +% +\par\nobreak\medskip +\makeatletter +\leavevmode\nobreak\hfill +\rlap{%\hskip\rightmargin % Defined by the list environment + \hskip\@rightmargin % Defined by exam.cls + \hskip-\rightpointsmargin + \llap{Question 2: 25}% +}% rlap +\makeatother +\par\medskip\noindent +% +and if you give the command\indc{totalformat}\indc{totalpoints} +\begin{center} +\verb"\totalformat{\fbox{Total: \totalpoints}}" +\end{center} +then the total number of points will be printed as +% +\par\nobreak\medskip +\makeatletter +\leavevmode\nobreak\hfill +\rlap{%\hskip\rightmargin % Defined by the list environment + \hskip\@rightmargin % Defined by exam.cls + \hskip-\rightpointsmargin + \llap{\fbox{Total: 25}}% +}% rlap +\makeatother +\par\medskip\noindent + +Thus, if you've given the +commands\indc{addpoints}\indc{bracketedpoints}\indc{pointsdroppedatright} +\begin{center} + \begin{tabular}{l} + \verb"\addpoints"\\ + \verb"\bracketedpoints"\\ + \verb"\pointsdroppedatright" + \end{tabular} +\end{center} +and you type +\begin{verbatim} +\question +\begin{parts} +\part[10] +In no more than one paragraph, explain why the earth is round. +\droppoints +\part[10] +What changes to the van Allen radiation belt are needed to +make the earth into a regular icosahedron? +\droppoints +\end{parts} +\droptotalpoints +\end{verbatim} +then you'll get +\addpoints +\pointsdroppedatright +\bracketedpoints +\begin{questions} +\question +\begin{parts} +\part[10] +In no more than one paragraph, explain why the earth is round. +\droppoints +\part[10] +What changes to the van Allen radiation belt are needed to +make the earth into a regular icosahedron? +\droppoints +\end{parts} + \leavevmode\unskip\nobreak\hfill +\makeatletter + \rlap{\hskip\rightmargin % Defined by the list environment + \hskip\@rightmargin % Defined by exam.cls + \hskip-\rightpointsmargin + \llap{Total for Question 1: 20}% + }% rlap +\makeatother + \par +%\droptotalpoints +\end{questions} +\noaddpoints \nopointsinmargin \nobracketedpoints If you've also given +the command\indc{totalformat}\indc{totalpoints}\indc{thequestion} +\begin{center} + \verb"\totalformat{Total for Question \thequestion: [\totalpoints]}" +\end{center} +then you'll get +\addpoints +\pointsdroppedatright +\bracketedpoints +\begin{questions} +\question +\begin{parts} +\part[10] +In no more than one paragraph, explain why the earth is round. +\droppoints +\part[10] +What changes to the van Allen radiation belt are needed to +make the earth into a regular icosahedron? +\droppoints +\end{parts} +%\droptotalpoints + \leavevmode\unskip\nobreak\hfill +\makeatletter + \rlap{\hskip\rightmargin % Defined by the list environment + \hskip\@rightmargin % Defined by exam.cls + \hskip-\rightpointsmargin + \llap{Total for Question 1: [20]}% + }% rlap +\makeatother + \par +\end{questions} +\noaddpoints +\nopointsinmargin +\nobracketedpoints + +To change the format used by the +\verb"\droptotalbonuspoints"\indc{droptotalbonuspoints} command, you +use the command\indc{bonustotalformat} +\begin{center} + \verb"\bonustotalformat" +\end{center} +which is analogous to the \verb"\totalformat" command. The argument +to \verb"\bonustotalformat" can contain the +command\indc{totalbonuspoints}\indc{thequestion} +\begin{center} + \begin{tabular}{ll} + \verb"\totalbonuspoints"& to print the number of bonus points, and\\ + \verb"\thequestion"& to print the question number. + \end{tabular} +\end{center} +(\verb"\totalbonuspoints" expands to +\verb"\bonuspointsofquestion{\arabic{question}}"; see +section~\ref{sec:BonusTables} for a discussion of the +\verb"\bonuspointsofquestion"\indc{bonuspointsofquestion} command.) + +\index{points|)} + +%-------------------------------------------------------------------- +\subsubsection{Margin sizes when using \texttt{\bs pointsinmargin} and + \texttt{\bs pointsinrightmargin}} +\index{margins!enlarge|(} + +\begin{itemize} +\item If you give the command + \verb"\pointsinmargin"\indc{pointsinmargin}, then the points are + printed right justified in the left margin, with the right edge a + distance of \verb"\marginpointssep"\indc{marginpointssep} from the + left edge of the text area. The default value of + \verb"\marginpointssep" is the result of the command + \begin{center} + \verb"\setlength{\marginpointssep}{5pt}" + \end{center} + and you can change it by giving a new \verb"\setlength" command. + +\item If you give the command + \verb"\pointsinrightmargin"\indc{pointsinrightmargin}, then the + points are printed right justified in the right margin, with the + right edge a distance of + \verb"\rightpointsmargin"\indc{rightpointsmargin} from the right + edge of the paper. The default value of \verb"\rightpointsmargin" + is the result of the command + \begin{center} + \verb"\setlength{\rightpointsmargin}{1cm}" + \end{center} + and you can change it by giving a new \verb"\setlength" command. +\end{itemize} + +You can change the width of the text area (and, thus, change the width +of the margins) with the \verb"\extrawidth"\indc{extrawidth} command +(see section~\ref{sec:margins}). + +\index{margins!enlarge|)} + +%-------------------------------------------------------------------- +\subsection{Custom question number lines: The \texttt{\bs qformat} + command} +\label{sec:qformat} +\indc{qformat} +\index{questions!customization|(} + +The default setup is for the question number to appear in the left +margin and for the text of the question to begin on that line. It's +possible to change this so that the text of the question starts on the +line following the question number, and the format of the line +containing the question number is determined by the user. This is +done using the \verb"\qformat" command. There is also a +\verb"\noqformat"\indc{noqformat} command, which reverts to the +default setup. + +To use the \verb"\qformat"\indc{qformat} command, you give the command +\begin{center} + \verb"\qformat{Format specification}" +\end{center} +where \texttt{Format specification} must contain some stretchability +(e.g., at least one \verb"\hfill" or \verb"\dotfill" or +\verb"\hrulefill" or \ldots) and can contain the commands +\begin{itemize} +\item \verb"\thequestion"\indc{thequestion}, which expands to the + question number, +\item \verb"\thequestiontitle"\indc{thequestiontitle} (see + section~\ref{sec:questiontitle}), which expands to + \begin{itemize} + \item the title of the question, if this question was defined using + a \verb"\titledquestion"\indc{titledquestion} command (see + section~\ref{sec:TitledQues}) instead of a \verb"\question" + command, or + \item the number of the question, if this question was defined using + a \verb"\question" command, + \end{itemize} +\item \verb"\thepoints"\indc{thepoints}, which expands to + \begin{itemize} + \item the number of points followed by the argument to the last + \verb"\pointname"\indc{pointname} command, if there were points + specified for the question, or + \item nothing, if no points were specified for the question + \end{itemize} + (see section~\ref{sec:pointname} for a discussion of the + \verb"\pointname" command), and +\item \verb"\totalpoints"\indc{totalpoints}, which expands to the + total number of points specified for the question and all of its + parts, subparts, and subsubparts (see section~\ref{sec:addup}). The + command \verb"\totalpoints" expands to + \verb"\pointsofquestion{\arabic{question}}"\indc{pointsofquestion} + (see section~\ref{sec:pointsofq}). +\end{itemize} +For example, if you give the +commands\indc{pointpoints}\indc{points}\indc{thepoints}\indc{thequestion} +% +\pointname{ \points} +\pointpoints{point}{points} +\begin{verbatim} +\qformat{Question \thequestion \dotfill \thepoints} +\begin{questions} +\question[10] +What did Billy Joe MacAllister throw off the Tallahatchie Bridge? +\end{questions} +\end{verbatim} +then you'll get +\qformat{Question \thequestion \dotfill \thepoints} +\begin{questions} +\question[10] +What did Billy Joe MacAllister throw off the Tallahatchie Bridge? +\end{questions} +% +\medskip +If you instead use the command +\begin{verbatim} +\qformat{\textbf{Question \thequestion}\quad (\thepoints)\hfill} +\end{verbatim} +then you'll get +\begin{questions} +\qformat{\textbf{Question \thequestion}\quad (\thepoints)\hfill} +\question[10] +What did Billy Joe MacAllister throw off the Tallahatchie Bridge? +\end{questions} +% +\medskip If you instead use the +command\indc{qformat}\indc{thequestion}\indc{thepoints} +\begin{verbatim} +\qformat{\hfill Question \thequestion\hfill (\thepoints)} +\end{verbatim} +then you'll get +\begin{questions} +\qformat{\hfill Question \thequestion\hfill (\thepoints)} +\question[10] +What did Billy Joe MacAllister throw off the Tallahatchie Bridge? +\end{questions} +\noqformat + +If you use a \verb"\qformat"\indc{qformat} (and, if there are any +bonus questions, also a \verb"\bonusqformat"\indc{bonusqformat}; see +section~\ref{sec:Bonus}), so that there are no labels on any of the +questions, and you'd like to remove the +indentation\index{indentation!remove} of the questions, you should +give the command +\begin{verbatim} +\renewcommand{\questionshook}{% + \setlength{\leftmargin}{0pt}% + \setlength{\labelwidth}{-\labelsep}% +} +\end{verbatim} +(see section~\ref{sec:CustList}) before the \texttt{questions} +environment. + +\index{questions!customization|)} + +%-------------------------------------------------------------------- +\subsubsection{Adding up the points for a question} +\label{sec:adding} +\index{points!adding} + +You can combine \verb"\qformat"\indc{qformat} with the +\verb"\totalpoints"\indc{totalpoints} command (see +section~\ref{sec:addup}): If you assign points only to parts, +subparts, and subsubparts of questions, but none to the questions +themselves, and you give the +command\indc{thequestion}\indc{totalpoints} +\begin{verbatim} +\qformat{Question \thequestion\dotfill \emph{\totalpoints\ points}} +\end{verbatim} +(you must have used the document class option +\verb"addpoints"\indt{addpoints} or given the command +\verb"\addpoints"\indc{addpoints} in order to use the +\verb"\totalpoints" command; see section~\ref{sec:addpoints}), then +you can type +\begin{verbatim} +\begin{questions} + \question + \begin{parts} + \part[10] + In no more than one paragraph, explain why the earth is round. + \part[10] + What changes to the van Allen radiation belt are needed to make + the earth into a regular icosahedron? + \end{parts} +\end{questions} +\end{verbatim} +and you'll get +% +\nopointsinmargin +\qformat{Question \thequestion\dotfill \emph{20 points}} +\begin{questions} + \question + \begin{parts} + \part[10] + In no more than one paragraph, explain why the earth is round. + \part[10] + What changes to the van Allen radiation belt are needed to make + the earth into a regular icosahedron? + \end{parts} +\end{questions} +\noqformat + +For another method of printing the total points for a question, see +the \verb"\droptotalpoints" command in section~\ref{sec:addup}. + + +%-------------------------------------------------------------------- +\subsection{Titled questions} +\label{sec:Titled} + +The \verb"\titledquestion"\indc{titledquestion} command (see +section~\ref{sec:TitledQues}) allows you to assign a \emph{title} to a +question, and to have the question title replace the question number +in a grading table or point table indexed by question number (see +sections \ref{sec:GradeTables} and~\ref{sec:PointTables}). If you use +a \verb"\qformat"\indc{qformat} (see section~\ref{sec:qformat}) then +you can include the question title in the question by using the +\verb"\thequestiontitle"\indc{thequestiontitle} command (see the +example in section~\ref{sec:questiontitle}). + + +%-------------------------------------------------------------------- +\subsubsection{\texttt{\bs titledquestion}} +\label{sec:TitledQues} + +The command \verb"\titledquestion"\indc{titledquestion} is a +replacement for \verb"\question"\indc{question}; it takes one required +argument, the title, and one optional argument, the point value, as in +\begin{center} + \verb"\titledquestion{Question \thequestion: Concepts}" +\end{center} +which sets the question title to ``Question 2: Concepts'' (if this is +the second question) and doesn't set any point values, or +\begin{center} + \verb"\titledquestion{Design}[10]" +\end{center} +which sets the question title to ``Design'' and sets the point value +to ``10''. Note that the question title doesn't include the number of +the question unless you put it there using the +\verb"\thequestion"\indc{thequestion} command. + +Using \verb"\titledquestion"\indc{titledquestion} instead of +\verb"\question" doesn't change the appearance of the question (unless +you use \verb"\thequestiontitle"\indc{thequestiontitle} in the +argument of a \verb"\qformat"\indc{qformat} command; see +section~\ref{sec:questiontitle}). The only direct effect of using +\verb"\titledquestion" instead of \verb"\question" is that if you +print a grading table or point table indexed by question number (see +section~\ref{sec:GradeTables}), then the title of the question will +replace the number of the question in the table. To have the title of +the question appear in the question itself, see the example in +section~\ref{sec:questiontitle}. + +If you create a grading table or point table indexed by question +number and you create a question using the +\verb"\titledquestion"\indc{titledquestion} command, then the number +of the +% +question\index{question number} won't appear in the table unless you +include \verb"\thequestion"\indc{thequestion} in the title of the +question. + +%-------------------------------------------------------------------- +\subsubsection{\texttt{\bs thequestiontitle}} +\label{sec:questiontitle} + +The command \verb"\thequestiontitle"\indc{thequestiontitle} expands to +\begin{itemize} +\item the title of the question (if the question was defined using a + \verb"\titledquestion"\indc{titledquestion} command) or +\item the number of the +% + question\index{question number} (if the question was defined using a + \verb"\question"\indc{question} command). +\end{itemize} +This is for use in the argument of a \verb"\qformat"\indc{qformat} +command (see section~\ref{sec:qformat}), so that you can have the +question title appear in the question itself, and not just in a +grading table or point table. + +The contents of \verb"\thequestiontitle"\indc{thequestiontitle} don't +appear anywhere in the question itself unless you do something to make +them appear. For example, if you give the command +\begin{center} +\verb"\qformat{Question \thequestion: \thequestiontitle\dotfill\thepoints}" +\end{center} +and then type\indc{titledquestion} +\begin{verbatim} +\begin{questions} + \titledquestion{History of Empirical Aerodynamics}[10] + What did Billy Joe MacAllister throw off the Tallahatchie Bridge? +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \qformat{Question \thequestion: \thequestiontitle\dotfill\thepoints} + \titledquestion{History of Empirical Aerodynamics}[10] + What did Billy Joe MacAllister throw off the Tallahatchie Bridge? +\end{questions} +\noqformat + +If the command \verb"\thequestiontitle" is never used, then the only +effect of using the command \verb"\titledquestion" instead of the +command \verb"\question" is that, in a grading table or point table +indexed by question number, this question will be indexed by the title +of the question rather than by the question number, and the title of +the question will never appear except in the table. + +%-------------------------------------------------------------------- +\subsection{Bonus points} +\label{sec:Bonus} +\index{bonus points|(} +\index{points!bonus|(} + +It's possible to create questions, parts, subparts, or subsubparts +that are worth \emph{bonus points}, instead of regular points. To do +this, you use the +command\indc{bonusquestion}\indc{bonustitledquestion}% +\indc{bonuspart}\indc{bonussubpart}\indc{bonussubsubpart} +\begin{center} + \begin{tabular}{l@{\qquad instead of\qquad}l} + \verb"\bonusquestion"& \verb"\question",\\ + \verb"\bonustitledquestion"& \verb"\titledquestion",\\ + \verb"\bonuspart"& \verb"\part",\\ + \verb"\bonussubpart"& \verb"\subpart", and\\ + \verb"\bonussubsubpart"& \verb"\subsubpart". + \end{tabular} +\end{center} +There is also a \verb"\bonusqformat"\indc{bonusqformat} command that +affects the \verb"\bonusquestion"\indc{bonusquestion} command in the +same way that the \verb"\qformat"\indc{qformat} command affects the +\verb"\question" command (see section~\ref{sec:qformat}), and a +\verb"\nobonusqformat"\indc{nobonusqformat} command that cancels the +effect of \verb"\bonusqformat" in the same way that +\verb"\noqformat"\indc{noqformat} cancels the effect of +\verb"\qformat". Note that the command +\verb"\thepoints"\indc{thepoints} is defined so that it works equally +well in \verb"\qformat" and \verb"\bonusqformat"\indc{bonusqformat} +commands (see section~\ref{sec:qformat}). + +If \indc{bonusquestion}\indc{bonustitledquestion}% +\indc{bonuspart}\indc{bonussubpart}\indc{bonussubsubpart}% +you don't assign any points to a \verb"\bonusquestion", +\verb"\bonuspart", \verb"\bonussubpart", or \verb"\bonussubsubpart" +then, aside from the fact that \verb"\bonusqformat" alters +\verb"\bonusquestion" while \verb"\qformat" alters \verb"\question", +then they're printed in the same way that they would be printed if you +had used the corresponding non-bonus command. However, if you assign +points, then +\begin{itemize} +\item the points are typeset differently (see below), +\item {\sloppy the points are not counted by the + \verb"\gradetable"\indc{gradetable}\indc{pointtable}% + \indc{bonusgradetable}\indc{bonuspointtable}% + \indc{combinedgradetable}\indc{combinedpointtable}% + or \verb"\pointtable" commands (see sections \ref{sec:GradeTables} + and~\ref{sec:PointTables}) or their partial variants (see + section~\ref{sec:PartialTable}), though they \emph{are} counted by + the \verb"\bonusgradetable", \verb"\bonuspointtable", + \verb"\combinedgradetable", and \verb"\combinedpointtable" + commands and their partial variants (see + sections~\ref{sec:BonusTables} and \ref{sec:CombinedTables}),\par} +\item the points are not counted by the + \verb"\droptotalpoints"\indc{droptotalpoints} command (see + section~\ref{sec:addup}), though they are counted by the + \verb"\droptotalbonuspoints"\indc{droptotalbonuspoints} command (see + below), +\item the points are not counted by the + \verb"\pointsofquestion"\indc{pointsofquestion} (see + section~\ref{sec:pointsofq}) or + \verb"\pointsonpage"\indc{pointsonpage} (see + section~\ref{sec:pointsonp}) commands, though they \emph{are} + counted by the + \verb"\bonuspointsofquestion"\indc{bonuspointsofquestion} and + \verb"\bonuspointsonpage"\indc{bonuspointsonpage} (see + section~\ref{sec:BonusTables}) commands, and +\item the points are not counted by the + \verb"\numpoints"\indc{numpoints} command (see + section~\ref{sec:Count}), though they \emph{are} counted by the + \verb"\numbonuspoints"\indc{numbonuspoints} command (see + section~\ref{sec:Count}). +\end{itemize} + +The default setup is that if you type +\begin{verbatim} +\begin{questions} + \question[10] Who discovered America? + \bonusquestion[1] On what day of the week did he do it? + \bonusquestion[2] What color shirt was he wearing? +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question[10] Who discovered America? + \bonusquestion[1] On what day of the week did he do it? + \bonusquestion[2] What color shirt was he wearing? +\end{questions} + +There is also a command +\verb"\bonuspointpoints"\indc{bonuspointpoints} that is analogous to +\verb"\pointpoints" (see section~\ref{sec:pointname}); the default +setup was created by the command +\begin{center} + \verb"\bonuspointpoints{point (bonus)}{points (bonus)}" +\end{center} +and if you give the command +\begin{center} + \verb"\bonuspointpoints{bonus point}{bonus points}" +\end{center} +then typing the above would produce\indc{bonuspointpoints} +\begin{questions} + \bonuspointpoints{bonus point}{bonus points} + \question[10] Who discovered America? + \bonusquestion[1] On what day of the week did he do it? + \bonusquestion[2] What color shirt was he wearing? +\end{questions} +There are also +commands\indc{bonuspointname}\indc{marginbonuspointname} +\begin{center} + \begin{tabular}{l} + \verb"\bonuspointname" and\\ + \verb"\marginbonuspointname" + \end{tabular} + \qquad that are analogous to\qquad + \begin{tabular}{l} + \verb"\pointname" and\\ + \verb"\marginpointname" + \end{tabular} +\end{center} +(see section~\ref{sec:pointname}), and +commands\indc{droptotalpoints}\indc{bonustotalformat}% +\indc{totalbonuspoints} +\begin{center} + \begin{tabular}{l} + \verb"\droptotalbonuspoints",\\ + \verb"\bonustotalformat", and\\ + \verb"\totalbonuspoints" + \end{tabular} + \qquad that are analogous to\qquad + \begin{tabular}{l} + \verb"\droptotalpoints",\\ + \verb"\totalformat", and\\ + \verb"\totalpoints" + \end{tabular} +\end{center} +(see section~\ref{sec:addup}). + +\index{points!bonus|)} +\index{bonus points|)} + + +%-------------------------------------------------------------------- +\subsection{Counting the questions and adding up the points} +\label{sec:Count} +\index{questions!counting|(} + + +The \verb"exam" document class automatically counts the numbers of +questions, parts, and subparts, and makes these numbers available as +the macros\indc{numquestions}\indc{numparts}\indc{numsubparts}% +\indc{numsubsubparts} +\begin{center} + \begin{tabular}{l} + \verb"\numquestions"\\ + \verb"\numparts"\\ + \verb"\numsubparts"\\ + \verb"\numsubsubparts" + \end{tabular} +\end{center} +These numbers are also printed on the screen when you run \LaTeX{} and +they are placed into the \verb".log" file as well. If you have more +than one \verb"questions" environment (for example, if your exam has +several parts, with the questions in each part numbered beginning with +``1''), then \verb"\numquestions" will hold the total number of +questions on the exam. If you do have more than one \verb"questions" +environment, though, you won't be able to use the +\verb"\gradetable"\indc{gradetable} or +\verb"\pointtable"\indc{pointtable} commands (see +section~\ref{sec:Tables}). + +If you use the document class option \verb"addpoints"\indt{addpoints} +or give the command \verb"\addpoints"\indc{addpoints} (see +section~\ref{sec:addpoints}), then the class will add the total number +of points and the total number of bonus points (see +section~\ref{sec:Bonus}) that you've given to all of the questions, +parts, subparts, and subsubparts of the exam, and make those totals +available in the macros\indc{numpoints}\indc{numbonuspoints} +\begin{center} + \begin{tabular}{l} + \verb"\numpoints"\\ + \verb"\numbonuspoints" + \end{tabular} +\end{center} +as well as displaying those totals on the screen when you run \LaTeX{} +and placing them into the \texttt{.log} file. You can then type +\begin{verbatim} +\begin{center} + This exam has \numquestions\ questions, for a total of \numpoints\ + points and \numbonuspoints\ bonus points. +\end{center} +\end{verbatim} +and you'll get +\begin{center} + This exam has 8 questions, for a total of 120 points and 10 bonus + points. +\end{center} + +\emph{Warning}: If \verb"addpoints"\indt{addpoints} is in effect, your +point values for questions, parts, subparts, and subsubparts must not +contain anything other than digits and the command \verb"\half" (see +section~\ref{sec:Half}). For example, if you \emph{don't} give the +command \verb"\addpoints", then you can +% +type\index{points!acceptable entries} +\begin{center} + \verb"\question[10\%]" +\end{center} +with no problems, but this will cause errors if you've given the +command \verb"\addpoints"\indc{addpoints}. The correct way to +accomplish what you want is to give the command +\verb"\marginpointname{\%}"\indc{marginpointname} or +\verb"\pointname{\%}"\indc{pointname} and then type +\verb"\question[10]" (see section~\ref{sec:pointname}). + +If you want to temporarily turn off the adding of points (for example, +if you list both the total points for each question and the points for +each part, but you don't want to count the points twice), you can give +the command\indc{noaddpoints} +\begin{center} + \verb"\noaddpoints" +\end{center} +to turn off the adding of points and the command \verb"\addpoints" to +turn it back on. + +If \verb"addpoints"\indc{addpoints} is in effect, then you can create +grading tables (see section~\ref{sec:GradeTables}) and point tables +(see section~\ref{sec:PointTables}) and use the commands +\verb"\pointsofquestion" (see section~\ref{sec:pointsofq}) and +\verb"\pointsonpage" (see section~\ref{sec:pointsonp}). + +\index{questions!counting|)} + +%--------------------------------------------------------------------- +\subsection{Referring to specific questions by number (cross + references)} +\index{cross references|(} + +You can use the standard \LaTeX{} commands \verb"\label" and +\verb"\ref" to refer to questions (or parts, or subparts, or +subsubparts) by number. For example, if you type +\begin{verbatim} +The first question is question number~\ref{ques:first}. +Question number~\ref{ques:second} has both a good part +(part~\ref{part:good}) and a bad part (part~\ref{part:bad}). + +\begin{questions} +\question +\label{ques:first} +This is the first question. + +\question +\label{ques:second} +\begin{parts} +\part +\label{part:good} +This is the good part. + +\part +\label{part:bad} +This is the \emph{bad} part. +\end{parts} + +\question +Is there a question? +\end{questions} +\end{verbatim} +then you'll get: + +\medskip + +The first question is question number~\ref{ques:first}. +Question number~\ref{ques:second} has both a good part +(part~\ref{part:good}) and a bad part (part~\ref{part:bad}). + +\begin{questions} +\question +\label{ques:first} +This is the first question. + +\question +\label{ques:second} +\begin{parts} +\part +\label{part:good} +This is the good part. + +\part +\label{part:bad} +This is the \emph{bad} part. +\end{parts} + +\question +Is there a question? +\end{questions} + + + +\bigskip + +As with all other cross references in \LaTeX, you'll have to run your +file through \LaTeX{} \emph{twice} to be sure that all the cross +references are correct. + +\index{cross references|)} + +%-------------------------------------------------------------------- +\subsection{Customizing the numbers} +\label{sec:CustNumb} +\index{customization!question numbers|(} + + +The default setup is that: +\begin{questions} + \question Question numbers are arabic, and are followed by a period. + \begin{parts} + \part Part numbers are lower case letters, and are enclosed in + parentheses. + \begin{subparts} + \subpart Subpart numbers are lower case roman, and are followed + by a period. + \begin{subsubparts} + \subsubpart Subsubpart numbers are greek, and are followed by + a right parenthesis. + \begin{choices} + \choice Choices are upper case letters, and are followed by + a period. + \end{choices} + \end{subsubparts} + \end{subparts} + \end{parts} +\end{questions} +All of this can be changed. + +\bigskip + +To change the type of numbering, you would redefine the +commands\indc{thequestion}\indc{thepartno}\indc{thesubpart}% +\indc{thesubsubpart}\indc{thechoice} +\begin{center} + \begin{tabular}{l} + \verb"\thequestion"\\ + \verb"\thepartno"\\ + \verb"\thesubpart"\\ + \verb"\thesubsubpart"\\ + \verb"\thechoice" + \end{tabular} +\end{center} +(Note: The second one listed there is \verb"\thepartno", \emph{not} +\verb"\thepart". The command \verb"\thepart" refers to the counter +used in the article document class standard sectioning command +\verb"\part".) The numbering commands available +are\indc{arabic}\indc{alph}\indc{Alph}\indc{roman}% +\indc{Roman}\indc{greeknum} +\begin{center} + \begin{tabular}{ll} + \verb"\arabic"& Regular arabic integers\\ + \verb"\alph"& Lower case letters\\ + \verb"\Alph"& Upper case letters\\ + \verb"\roman"& Lower case roman numbers\\ + \verb"\Roman"& Upper case roman numbers\\ + \verb"\greeknum"& Greek letters + \end{tabular} +\end{center} +and any of these can be applied to the +counters\index{question counter}\index{part counter}% +\index{subpart counter}\index{subsubpart counter}% +\index{choice counter}% +\verb"question"\indt{question}, \verb"partno"\indt{partno}, +\verb"subpart"\indt{subpart}, \verb"subsubpart"\indt{subsubpart}, and +\verb"choice"\indt{choice}. (The \verb"\greeknum"\indc{greeknum} +command is defined by the exam document class, but all of the others +are standard \LaTeX{} commands.) + +For example, to have questions numbered using upper case roman numbers +and parts numbered using upper case letters, you would give the +commands\indc{thequestion}\indc{thepartno} +\begin{center} + \begin{tabular}{l} + \verb"\renewcommand{\thequestion}{\Roman{question}}"\\ + \verb"\renewcommand{\thepartno}{\Alph{partno}}" + \end{tabular} +\end{center} + +\bigskip + + +The ``decorations'' around the numbers (i.e., the periods, or +parentheses, or \ldots) are determined by the +commands\indc{questionlabel}\indc{partlabel}\indc{subpartlabel}% +\indc{subsubpartlabel}\indc{choicelabel} +\begin{center} + \begin{tabular}{l} + \verb"\questionlabel"\\ + \verb"\partlabel"\\ + \verb"\subpartlabel"\\ + \verb"\subsubpartlabel"\\ + \verb"\choicelabel" + \end{tabular} +\end{center} +the default definitions of which are: +\begin{center} + \begin{tabular}{l} + \verb"\newcommand{\questionlabel}{\thequestion.}"\\ + \verb"\newcommand{\partlabel}{(\thepartno)}"\\ + \verb"\newcommand{\subpartlabel}{\thesubpart.}"\\ + \verb"\newcommand{\subsubpartlabel}{\thesubsubpart)}"\\ + \verb"\newcommand{\choicelabel}{\thechoice.}" + \end{tabular} +\end{center} +You can change any of these by giving \verb"\renewcommand" commands to +redefine them. This can, of course, be used to change the +``decorations'' around the numbers, but there are other uses as well. +For example, if you use the Fourier project's Utopia +font\index{Utopia~font} by including the commands +\begin{center} + \begin{tabular}{l} + \verb"\usepackage[T1]{fontenc}"\\ + \verb"\usepackage{fourier}" + \end{tabular} +\end{center} +after your \verb"\documentclass" command, then you'll see that the +kerning\index{kerning} makes ``\verb"F."" look so much like +``\verb"E"" that a student could confuse the two. You can turn off +the kerning with the command +\verb"\renewcommand{\choicelabel}{\thechoice{}.}"\indc{choicelabel}. + +\index{customization!question numbers|)} + + +%-------------------------------------------------------------------- +\subsection{Customizing the list parameters} +\label{sec:CustList} +\index{list environment|(} +\index{environment!list|(} +\index{customization!list parameters|(} + +The environments \texttt{questions}, \texttt{parts}, +\texttt{subparts}, \texttt{subsubparts}, \texttt{choices}, and +\texttt{checkboxes} are all implemented as \LaTeX{} \texttt{list} +environments. This section describes commands for advanced users who +want to customize the list parameters (\verb"\topsep"\indc{topsep}, +\verb"\partopsep"\indc{partopsep}, \verb"\itemsep"\indc{itemsep}, +\verb"\parsep"\indc{parsep}, etc.) for the lists that those +environments create. + +The \verb"exam" document class includes the expansion +of\indc{questionshook}\indc{partshook}\indc{subpartshook}% +\indc{subsubpartshook}\indc{choiceshook}\indc{checkboxeshook} +\begin{center} + \begin{tabular}{l@{\qquad when creating a\qquad}l@{\qquad}l} + \verb"\questionshook"&\verb"questions"&environment,\\ + \verb"\partshook"&\verb"parts"&environment,\\ + \verb"\subpartshook"&\verb"subparts"&environment,\\ + \verb"\subsubpartshook"&\verb"subsubparts"&environment,\\ + \verb"\choiceshook"&\verb"choices"&environment, and\\ + \verb"\checkboxeshook"&\verb"checkboxes"&environment. + \end{tabular} +\end{center} +The \verb"exam" document class defines these as follows: +\begin{center} + \begin{tabular}{ll} + \verb"\newcommand{\questionshook}{}"\\ + \verb"\newcommand{\partshook}{}"\\ + \verb"\newcommand{\subpartshook}{}"\\ + \verb"\newcommand{\subsubpartshook}{}"\\ + \verb"\newcommand{\choiceshook}{}"\\ + \verb"\newcommand{\checkboxeshook}{}" + \end{tabular} +\end{center} +Thus, the default is that these commands have no effect, but you can +change any of them with a \verb"\renewcommand" command. Thus, if you +redefine, e.g., \verb"\questionshook" to expand to commands that set +values for some of the list parameters, then those values will be used +in the \verb"questions" environment. + +For example, if you give the command\indc{questionshook} +\begin{center} + \verb"\renewcommand{\questionshook}{\setlength{\itemsep}{1in}}" +\end{center} +then there will be an additional one inch of blank space inserted +between questions (since the questions are the items in a +\verb"questions" environment). For another example, if you give the +command\indc{partshook} +\begin{center} + \verb"\renewcommand{\partshook}{\setlength{\topsep}{0.5in}}" +\end{center} +then each parts environment will have an additional one half inch of +space before and after the environment. + +For another example, if you're using a \verb"\qformat"\indc{qformat} +(see section~\ref{sec:qformat}) (and, if there are any bonus +questions, also a \verb"\bonusqformat"\indc{bonusqformat}; see +section~\ref{sec:Bonus}), so that there are no labels on any of the +questions, and you'd like to remove the indentation of the questions, +give the +command\index{indentation!remove}\indc{leftmargin}\indc{labelsep} +\begin{verbatim} +\renewcommand{\questionshook}{% + \setlength{\leftmargin}{0pt}% + \setlength{\labelwidth}{-\labelsep}% +} +\end{verbatim} + +\index{customization!list parameters|)} +\index{environment!list|)} +\index{list environment|)} + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +\section{Multiple choice and fill in the blank questions} +\label{sec:MulChc} +\index{multiple choice} + +There are four environments for listing the possible answers to a +multiple choice question: two of them label the choices, and the other +two print checkboxes in front of the choices for the student to place +checks next to the chosen answers. +\begin{itemize} +\item The first two environments use upper case letters (i.e., ``A'', + ``B'', ``C'', \ldots) to label the choices. (To change the + appearance of the labels, see section~\ref{sec:CustNumb}.) + \begin{itemize} + \item The \verb"choices"\indt{choices}\index{choices environment}% + \index{environment!choices} environment creates a list environment + with the choices as the items in the list (see + section~\ref{sec:choices}). + \item The \verb"oneparchoices"\indt{oneparchoices}% + \index{oneparchoices environment}% + \index{environment!oneparchoices} environment lists all of the + choices in a single paragraph which is a continuation of the + paragraph preceding the environment unless you leave a blank line + before beginning the environment (see + section~\ref{sec:oneparchoices}). + \end{itemize} + If you don't want the students to just circle the correct choices, + you can use the \verb"\answerline"\indc{answerline} command to print + a line on which the answer should be written (see + section~\ref{sec:ShortAns}). The + \verb"\anwerline"\indcsub{answerline}{optional~argument} + command allows you to include as an optional argument the answer to + the question, and the answer will be printed on the line when + solutions are bing printed (see section~\ref{sec:AnsShortAns}). +\item The last two environments print checkboxes in front of the + choices for the students to use to place checks next to the chosen + answers. + \begin{itemize} + \item The \verb"checkboxes"\indt{checkboxes}% + \index{checkboxes environment}% + \index{environment!checkboxes} environment creates a list + environment with the choices as the items in the list (see + section~\ref{sec:checkboxes}). + \item The \verb"oneparcheckboxes"\indt{oneparcheckboxes}% + \index{oneparcheckboxes environment}% + \index{environment!oneparcheckboxes} environment lists all of the + choices in a single paragraph which is a continuation of the + paragraph preceding the environment unless you leave a blank line + before beginning the environment (see + section~\ref{sec:oneparcheckboxes}). + \end{itemize} +\end{itemize} +All of those environments allow you to designate one or more choices +as correct choices and to have the correct choices printed with +emphasis when solutions are being printed (see +section~\ref{sec:CorrectChoice}). + +%-------------------------------------------------------------------- +\subsection{The \texttt{choices} environment} +\label{sec:choices} +\indt{choices} +\indc{choice} +\index{choices environment} +\index{environment!choices} + +For example, if you type +\begin{verbatim} +\begin{questions} +\question +One of these things is not like the others; one of these things is not +the same. Which one is different? +\begin{choices} +\choice John +\choice Paul + +\choice + +George + +\choice Ringo + +\choice Socrates + +\end{choices} + +\end{questions} +\end{verbatim} +Then you'll get +\begin{questions} +\question +One of these things is not like the others; one of these things is not +the same. Which one is different? +\begin{choices} +\choice John +\choice Paul + +\choice + +George + +\choice Ringo + +\choice Socrates + +\end{choices} + +\end{questions} +As that example illustrates, you can leave blank lines between the +\verb"\choice" command and the text of the choice, or between the +various choices, and those blank lines will be ignored. + +%-------------------------------------------------------------------- +\subsection{The \texttt{oneparchoices} environment} +\label{sec:oneparchoices} +\indt{oneparchoices} +\indc{choice} +\index{oneparchoices environment} +\index{environment!oneparchoices} + +If you use a \verb"oneparchoices" environment instead of the +\verb"choices" environment in the example of +section~\ref{sec:choices}, then you'll get +\begin{questions} +\question +One of these things is not like the others; one of these things is not +the same. Which one is different? +\begin{oneparchoices} +\choice John +\choice Paul + +\choice + +George + +\choice Ringo + +\choice Socrates + +\end{oneparchoices} + +\end{questions} + +If you insert a blank line before the \verb"\begin{oneparchoices}", + then you'll get +\begin{questions} +\question +One of these things is not like the others; one of these things is not +the same. Which one is different? + +\begin{oneparchoices} +\choice John +\choice Paul + +\choice + +George + +\choice Ringo + +\choice Socrates + +\end{oneparchoices} + +\end{questions} + + +If you insert a blank line before the \verb"\begin{oneparchoices}" and + \verb"\answerline" after the \verb"\end{oneparchoices}" (see +section~\ref{sec:ShortAns} for a description of the +\verb"\answerline"\indc{answerline} command), then you'll get +\begin{questions} +\question +One of these things is not like the others; one of these things is not +the same. Which one is different? + +\begin{oneparchoices} +\choice John +\choice Paul + +\choice + +George + +\choice Ringo + +\choice Socrates + +\end{oneparchoices} +\answerline + +\end{questions} + +%-------------------------------------------------------------------- +\subsection{The \texttt{checkboxes} environment} +\label{sec:checkboxes} +\indt{checkboxes} +\indc{choice} +\index{checkboxes environment} +\index{environment!checkboxes} + +If you use a \texttt{checkboxes} environment instead of the +\texttt{choices} environment in the example of +section~\ref{sec:choices}, then you'll get +\begin{questions} +\question +One of these things is not like the others; one of these things is not +the same. Which one is different? +\begin{checkboxes} +\choice John +\choice Paul + +\choice + +George + +\choice Ringo + +\choice Socrates + +\end{checkboxes} + +\end{questions} +The appearance of the checkbox can be customized (see +section~\ref{sec:MulChceCust}). + + +%-------------------------------------------------------------------- +\subsection{The \texttt{oneparcheckboxes} environment} +\label{sec:oneparcheckboxes} +\indt{oneparcheckboxes} +\indc{choice} +\index{oneparcheckboxes environment} +\index{environment!oneparcheckboxes} + +If you use a \verb"oneparcheckboxes" environment instead of the +\verb"choices" environment in the example of +section~\ref{sec:choices}, then you'll get +\begin{questions} +\question +One of these things is not like the others; one of these things is not +the same. Which one is different? +\begin{oneparcheckboxes} +\choice John +\choice Paul + +\choice + +George + +\choice Ringo + +\choice Socrates + +\end{oneparcheckboxes} + +\end{questions} + +If you insert a blank line before the \verb"\begin{oneparcheckboxes}", + then you'll get +\begin{questions} +\question +One of these things is not like the others; one of these things is not +the same. Which one is different? + +\begin{oneparcheckboxes} +\choice John +\choice Paul + +\choice + +George + +\choice Ringo + +\choice Socrates + +\end{oneparcheckboxes} + +\end{questions} +The appearance of the checkbox can be customized (see +section~\ref{sec:MulChceCust}). + + + +%-------------------------------------------------------------------- +\subsection{Solutions to multiple choice questions} +\label{sec:CorrectChoice} +\index{solutions} +\index{choices environment!correct choice} +\index{environment!choices!correct choice} +\index{oneparchoices environment!correct choice} +\index{environment!oneparchoices!correct choice} +\index{checkboxes environment!correct choice} +\index{environment!checkboxes!correct choice} +\index{oneparcheckboxes environment!correct choice} +\index{environment!oneparcheckboxes!correct choice} + + +The \verb"exam" document class defines several environments for +solutions (see section~\ref{sec:solutions}), the contents of which +will be printed only if you use the document class option +\verb"answers"\indt{answers} (as in +\verb"\documentclass[answers]{exam}") or give the command +\verb"\printanswers"\indc{printanswers} (see +section~\ref{sec:answers}). Each of the environments for multiple +choice questions (see +sections~\ref{sec:choices}--\ref{sec:oneparcheckboxes}) allows you to +designate one or more of the choices as \emph{correct choices}, and to +have the correct choices printed with emphasis when solutions are +being printed. + +The command to define a correct choice is +\verb"\CorrectChoice"\indc{CorrectChoice}, which is used in place of +the command \verb"\choice"\indc{choice}. (To avoid confusion, +\verb"\correctchoice"\indc{correctchoice} is defined to be a synonym +for \verb"\CorrectChoice".) When solutions are not being printed, +\verb"\CorrectChoice" is equivalent to \verb"\choice". When solutions +are being printed, though, any choices that were created with +\verb"\CorrectChoice" (rather than with \verb"\choice") will be +printed in bold. (This can be changed; see +section~\ref{sec:MulChceCust}.) In addition, in the +\texttt{checkboxes}\indt{checkboxes} and +\texttt{oneparcheckboxes}\indt{oneparcheckboxes} environments, each +correct choice will have its checkbox replaced by a check. + +For example, if \verb"\printanswers"\indc{printanswers} is in effect +and you type\indc{CorrectChoice} +\begin{verbatim} +\begin{questions} + \question One of these things is not like the others; one of these + things is not the same. Which one is different? + \begin{oneparchoices} + \choice John + \choice Paul + \choice George + \choice Ringo + \CorrectChoice Socrates + \end{oneparchoices} +\end{questions} +\end{verbatim} +then you'll get +\printanswers +\begin{questions} + \question One of these things is not like the others; one of these + things is not the same. Which one is different? + \begin{oneparchoices} + \choice John + \choice Paul + \choice George + \choice Ringo + \CorrectChoice Socrates + \end{oneparchoices} +\end{questions} +\noprintanswers +% +If you use a \texttt{oneparcheckboxes}\indt{oneparcheckboxes} +environment instead of the \texttt{oneparchoices}\indt{oneparchoices} +environment in that example, then you'll get\indc{printanswers} +% +\printanswers +\begin{questions} + \question One of these things is not like the others; one of these + things is not the same. Which one is different? + \begin{oneparcheckboxes} + \choice John + \choice Paul + \choice George + \choice Ringo + \CorrectChoice Socrates + \end{oneparcheckboxes} +\end{questions} +\noprintanswers + +%-------------------------------------------------------------------- +\subsection{Fill in the blank questions} +\label{sec:Fillin} + +\indcstart{fillin} +\index{fill in the blank|(} + +There is a \verb"\fillin" command that prints underlined empty space +for creating ``fill in the blank'' questions. The \verb"\fillin" +command can take two optional arguments: +\begin{itemize} +\item the first optional argument is the answer to the question, which + will be printed above the line when answers are being printed, and +\item the second optional argument is the length of line to be + printed, if you want some length other than the default. +\end{itemize} +If answers are being printed and you supply the answer as the first +(and possibly only) optional argument, then the answer is printed +subject to the declarations in the argument of the most recent +\verb"\CorrectChoiceEmphasis" command. It is centered on the line +unless it is too long, in which case it extends to the right of the +line. The default length of the line and the distance down from the +baseline of the text to the empty line can both be customized (see +section~\ref{sec:CustFillin}). + +For example, if you type +\begin{verbatim} +\begin{questions} + \question \fillin is the color of my true love's hair. +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question \fillin is the color of my true love's hair. +\end{questions} +If, instead, you type +\begin{verbatim} +\begin{questions} + \question \fillin[Black] is the color of my true love's hair. +\end{questions} +\end{verbatim} +then if answers are not being printed you'll get +\begin{questions} + \question \fillin[Black] is the color of my true love's hair. +\end{questions} +and if answers are being printed you'll get +\printanswers +\begin{questions} + \question \fillin[Black] is the color of my true love's hair. +\end{questions} +\noprintanswers + +For another example, if answers are being printed and you type +\begin{verbatim} +\begin{questions} + \question The magic word is \fillin[prestidigitator]. +\end{questions} +\end{verbatim} +then you'll get +\printanswers +\begin{questions} + \question The magic word is \fillin[prestidigitator]. +\end{questions} +\noprintanswers +which shows what happens when the answer is too long for the fillin +line. If, however, you type +\begin{verbatim} +\begin{questions} + \question The magic word is \fillin[prestidigitator][2in]. +\end{questions} +\end{verbatim} +then you'll get +\printanswers +\begin{questions} + \question The magic word is \fillin[prestidigitator][2in]. +\end{questions} +\noprintanswers + +\verb"\fillin" eats (and ignores) space characters appearing before +the first optional argument. It also eats (and ignores) space +characters appearing after the first optional argument and before the +second optional argument. However, if exactly one optional argument +appears, and if there are one or more space characters following that +one optional argument, then those spaces are replaced by a single +space character, but not eaten. +%-------------------------------------------------------------------- +\subsubsection{True/False questions} +\label{sec:truefalse} + +\index{true/false questions|(} +The \verb"\fillin" command can also be used to create True/False +questions. If you give the command +\begin{verbatim} +\newcommand{\tf}[1][{}]{% + \fillin[#1][0.25in]% +} +\end{verbatim} +then you can type +\begin{verbatim} +\begin{questions} + \question \tf[T] The world is all that is the case. + \question \tf[F] My favorite color is blue. +\end{questions} +\end{verbatim} +\newcommand{\tf}[1][{}]{% + \fillin[#1][0.25in]% +} +and if answers are not being printed you'll get +\begin{questions} + \question \tf[T] The world is all that is the case. + \question \tf[F] My favorite color is blue. +\end{questions} +but if answers are being printed then you'll get +\printanswers +\begin{questions} + \question \tf[T] The world is all that is the case. + \question \tf[F] My favorite color is blue. +\end{questions} +\noprintanswers + +\index{true/false questions|)} + +%-------------------------------------------------------------------- +\subsubsection{Customizing the \texttt{\bs fillin} command} +\label{sec:CustFillin} +\index{customization!\texttt{\char`\\fillin}|(} + +You can customize the \verb"\fillin" command by changing +\begin{itemize} +\item the default length of the underlined space, +\item the distance below the text baseline that the line is printed, and +\item the emphasis applied to the answer (when answers are being + printed). +\end{itemize} +The default length of the underlined space is called +\verb"\fillinlinelength"\indc{fillinlinelength}, and its value was set +by the command +\begin{center} + \verb"\setlength\fillinlinelength{1in}" +\end{center} +You can change this by giving a new \verb"\setlength" command. + +The line is printed a distance of +\verb"\answerclearance"\indc{answerclearance} below the baseline, and +its value was set by the command +\begin{center} + \verb"\setlength\answerclearance{0.2ex}" +\end{center} +You can change this by giving a new \verb"\setlength" command. Note: +\verb"\answerclearance" is also used by the \verb"\answerline" command +(see section~\ref{sec:ShortAns}). + +When answers are being printed and you include the optional argument +containing the answer, then the answer is printed subject to the +declarations in the argument of the most recent +\verb"\CorrectChoiceEmphasis"\indc{CorrectChoiceEmphasis} command. +The default situation was created by the command +\begin{center} + \verb"\CorrectChoiceEmphasis{\bfseries}" +\end{center} +and you can change this by giving a new \verb"\CorrectChoiceEmphasis" +command (see section~\ref{sec:MulChceCust}). + +\index{customization!\texttt{\char`\\fillin}|)} +\index{fill in the blank|)} +\indcstop{fillin} + + +%-------------------------------------------------------------------- +\subsection{Customizing the multiple choice environments} +\label{sec:MulChceCust} +\index{customization!multiple choice questions|(} + +When solutions are being printed, the correct choices in any of the +environments \texttt{choices}\indt{choices}, +\texttt{oneparchoices}\indt{oneparchoices}, +\texttt{checkboxes}\indt{checkboxes}, and +\texttt{oneparcheckboxes}\indt{oneparcheckboxes} will be printed +subject to the declarations in the argument of the most +recent\indc{CorrectChoiceEmphasis} +\begin{center} + \verb"\CorrectChoiceEmphasis" +\end{center} +command. The default situation is created by the command +\begin{center} + \verb"\CorrectChoiceEmphasis{\bfseries}" +\end{center} +and so when solutions are being printed the correct choices are +printed in boldface by default. You can change this, for example, by +giving the command +\begin{center} + \verb"\CorrectChoiceEmphasis{\itshape}" +\end{center} +which would cause correct choices to be printed in italics when +solutions are being printed. + +For another example, if you give the command +\verb"\usepackage{color}"\indt{color} in the preamble\index{preamble} +of your document (i.e., after the \verb"\documentclass" command and +before the \verb"\begin{document}"), and then give the + command\indc{CorrectChoiceEmphasis}\indc{color} +\begin{center} + \verb"\CorrectChoiceEmphasis{\color{red}}" +\end{center} +then when solutions are being printed the correct choices will be +printed in red (assuming your printer can produce that color). + +For another example, if you give the command +\verb"\usepackage{color}"\indt{color} in the preamble of your document +(i.e., after the \verb"\documentclass" command and before the +\verb"\begin{document}" command) and then give the command\indc{color} +\begin{center} + \verb"\CorrectChoiceEmphasis{\color{red}\bfseries}" +\end{center} +then the correct choices will be printed in boldface red (again +assuming that your printer can produce that color). + +{\sloppy To avoid confusion, + \verb"\correctchoiceemphasis"\indc{correctchoiceemphasis} is defined + to be a synonym for + \verb"\CorrectChoiceEmphasis"\indc{CorrectChoiceEmphasis}.\par} + +\bigskip + +The \texttt{checkboxes}\indt{checkboxes} and +\texttt{oneparcheckboxes}\indt{oneparcheckboxes} environments also +allow customization of the characters used for checkboxes and checks: +\begin{itemize} +\item The checkbox\index{checkbox} that is printed in the + \texttt{checkboxes} and \texttt{oneparcheckboxes} environments is + the argument of the most recent + \verb"\checkboxchar"\indc{checkboxchar} command. The default is + created by the command + \begin{center} + \verb"\checkboxchar{$\bigcirc$}" + \end{center} + For example, if you give the command + \verb"\usepackage{amssymb}"\indt{amssymb} in the + preamble\index{preamble} of your document (i.e., after the + \verb"\documentclass" command and before the + \verb"\begin{document}"), then the command\indc{Box} + \begin{center} + \verb"\checkboxchar{$\Box$}" + \end{center} + will cause squares to be printed instead of circles. + + \item The check that is printed for correct choices in the + \texttt{checkboxes}\indt{checkboxes} and + \texttt{oneparcheckboxes}\indt{oneparcheckboxes} environments + when solutions are being printed is the argument of the most + recent \verb"\checkedchar"\indc{checkedchar} command. The + default is created by the command\indc{surd} + \begin{center} + \verb"\checkedchar{$\surd$}" + \end{center} +\end{itemize} + +For example, if you've given the command +\verb"\usepackage{amssymb}"\indt{amssymb} in the +preamble\index{preamble} of your document (i.e., after the +\verb"\documentclass" command and before the \verb"\begin{document}"), + then the commands\indc{Box}\indc{blacksquare} +\begin{center} + \begin{tabular}{l} + \verb"\checkboxchar{$\Box$}"\\ + \verb"\checkedchar{$\blacksquare$}" + \end{tabular} +\end{center} +will cause the example in section~\ref{sec:CorrectChoice} to appear as +% +\printanswers +\checkboxchar{$\Box$} +\checkedchar{$\blacksquare$} +\begin{questions} + \question One of these things is not like the others; one of + these things is not the same. Which one is different? + \begin{oneparcheckboxes} + \choice John + \choice Paul + \choice George + \choice Ringo + \CorrectChoice Socrates + \end{oneparcheckboxes} +\end{questions} +\noprintanswers + +\index{customization!multiple choice questions|)} +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +\section{Escaping the indentation: \texttt{\bs uplevel} and + \texttt{\bs fullwidth}} +\label{sec:uplevel} +\index{indentation|(} + +There are two commands provided for printing text with a left margin +smaller than the one currently in effect: +\verb"\uplevel"\indc{uplevel} and \verb"\fullwidth"\indc{fullwidth}. +Each of these commands takes one argument and typesets the argument +with an altered left margin. + +The \verb"\fullwidth" command prints its argument using the full width +of the printed region, temporarily canceling the indentation created +by the \texttt{questions} environment (and the \texttt{parts}, +\texttt{subparts}, and \texttt{subsubparts} environments, if you're +inside any of those). The \verb"\uplevel" command prints its argument +using the indentation in effect before you entered the current +innermost environment. + +There are also two environments, +\texttt{EnvUplevel}\indt{EnvUplevel}\index{environment!EnvUplevel}% +\index{EnvUplevel environment} and +\texttt{EnvFullwidth}\indt{EnvFullwidth}\index{environment!EnvFullwidth}% +\index{EnvFullwidth environment}. The \texttt{EnvUplevel} environment +is similar to the \verb"\uplevel" command and the +\texttt{EnvFullwidth} environment is similar to the \verb"\fullwidth" +command. The environments have the advantage that you can have +verbatim material inside of the environment, while there cannot be any +verbatim material in the argument of \verb"\uplevel" or +\verb"\fullwidth". + +The main uses for these commands are including instructions for a +group of questions (see section~\ref{sec:Instructions}) and naming the +parts of a long exam (see section~\ref{sec:Naming}), but you can use +them however you like. + +%-------------------------------------------------------------------- +\subsection{Including instructions for a group of questions} +\label{sec:Instructions} +\index{instructions|(} +\indcstart{uplevel} +\indtstart{EnvUplevel} +\index{EnvUplevel environment|(} +\index{environment!EnvUplevel|(} + + +If you are inside of a parts environment and you want to give +directions for the next few parts, then those directions should be +indented to the level of the question of which they are parts, i.e., +up one level. If you type +\begin{verbatim} +\begin{questions} + \question + Why did you come to Casablanca? + + \question + \begin{parts} + \part + Why, Oh why, Oh why, Oh; why did I ever leave Ohio? + + \uplevel{The following two parts should be answered in classical + Greek:} + \part + Why do birds sing? + + \part + Why do fools fall in love? + + \end{parts} +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question + Why did you come to Casablanca? + + \question + \begin{parts} + \part + Why, Oh why, Oh why, Oh; why did I ever leave Ohio? + + \uplevel{The following two parts should be answered in classical + Greek:} + \part + Why do birds sing? + + \part + Why do fools fall in love? + + \end{parts} +\end{questions} +You can accomplish exactly the same thing by replacing +\begin{verbatim} + \uplevel{The following two parts should be answered in classical + Greek:} +\end{verbatim} +by +\begin{verbatim} + \begin{EnvUplevel} + The following two parts should be answered in classical Greek: + \end{EnvUplevel} +\end{verbatim} + +If you want to give instructions for a group of questions, then the +indenting for those instructions should be to the outer left margin, +i.e., up one level. For example, if you type +\begin{verbatim} +\begin{questions} + \question + Approximate $\displaystyle \int_0^1 \sin x^2 \, dx$ within $.001$ of + its true value. + + \uplevel{Questions \ref{exact-start} through~\ref{exact-end} should + be evaluated completely, not just approximated.} + + \question + \label{exact-start} + $\displaystyle \int_0^1 \frac{x^2 \, dx}{\sqrt{1-x^2}}$ + + \question + $\displaystyle \int_0^1 \frac{1}{1+x^2}\, dx$ + + \question + \label{exact-end} + $\displaystyle \int_0^{\frac{\pi}{2}} \sin^3 x \cos x \, dx$ +\end{questions} +\end{verbatim} +you'll get +\begin{questions} + \question + Approximate $\displaystyle \int_0^1 \sin x^2 \, dx$ within $.001$ of + its true value. + + \uplevel{Questions \ref{exact-start} through~\ref{exact-end} should + be evaluated completely, not just approximated.} + + \question + \label{exact-start} + $\displaystyle \int_0^1 \frac{x^2 \, dx}{\sqrt{1-x^2}}$ + + \question + $\displaystyle \int_0^1 \frac{1}{1+x^2}\, dx$ + + \question + \label{exact-end} + $\displaystyle \int_0^{\frac{\pi}{2}} \sin^3 x \cos x \, dx$ +\end{questions} +You can accomplish exactly the same thing by replacing +\begin{verbatim} + \uplevel{Questions \ref{exact-start} through~\ref{exact-end} should + be evaluated completely, not just approximated.} +\end{verbatim} +by +\begin{verbatim} + \begin{EnvUplevel} + Questions \ref{exact-start} through~\ref{exact-end} should be + evaluated completely, not just approximated. + \end{EnvUplevel} +\end{verbatim} +\indcstop{uplevel} +\indtstop{EnvUplevel} +\index{EnvUplevel environment|)} +\index{environment!EnvUplevel|)} + +\indcstart{fullwidth} +\indtstart{EnvFullwidth} +\index{EnvFullwidth environment|(} +\index{environment!EnvFullwidth|(} +If you want to give instructions that use the full width of the page +(rather than just going up one level of indentation), then use the +\verb"\fullwidth" command. For example, if you type +\begin{verbatim} +\begin{questions} + \question + This is the first question. + + \question + \begin{parts} + \part + This is the first part. + + \part + This is the second part. + \begin{subparts} + \subpart + This is a subpart. + + \fullwidth{When you finish this exam, you should go back and + reexamine your work, both on this exam and in your life up + until the day of this exam, for any errors that you may have + made.} + + \subpart + This is another subpart. + \end{subparts} + \end{parts} +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question + This is the first question. + + \question + \begin{parts} + \part + This is the first part. + + \part + This is the second part. + \begin{subparts} + \subpart + This is a subpart. + + \fullwidth{When you finish this exam, you should go back and + reexamine your work, both on this exam and in your life up + until the day of this exam, for any errors that you may have + made.} + + \subpart + This is another subpart. + \end{subparts} + \end{parts} +\end{questions} +You can accomplish exactly the same thing by replacing +\begin{verbatim} + \fullwidth{When you finish this exam, you should go back and + reexamine your work, both on this exam and in your life up + until the day of this exam, for any errors that you may have + made.} +\end{verbatim} +by +\begin{verbatim} + \begin{EnvFullwidth} + When you finish this exam, you should go back and + reexamine your work, both on this exam and in your life up + until the day of this exam, for any errors that you may have + made. + \end{EnvFullwidth} +\end{verbatim} +\indcstop{fullwidth} +\indtstop{EnvFullwidth} +\index{EnvFullwidth environment|)} +\index{environment!EnvFullwidth|)} + +\index{instructions|)} + +%--------------------------------------------------------------------- +\subsection{Naming the parts of a long exam} +\label{sec:Naming} +\index{naming parts of the exam|(} + +There are two ways of naming the parts of a long exam. The first way +uses the \verb"\fullwidth"\indc{fullwidth} and +\verb"\uplevel"\indc{uplevel} commands (see +section~\ref{sec:Namefullwidth}), and the other way uses the standard +% +\verb"\part"\indcsub{part}{standard sectioning command} +% +and \verb"\section"\indc{section} commands (see +section~\ref{sec:NameSection}). + +%-------------------------------------------------------------------- +\subsubsection{Using \texttt{\bs uplevel} and \texttt{\bs fullwidth}} +\label{sec:Namefullwidth} +\indcstart{uplevel} +\indcstart{fullwidth} +\indtstart{EnvFullwidth} +\index{EnvFullwidth environment|(} +\index{environment!EnvFullwidth|(} + +To place a section name in the exam, just use a \verb"\fullwidth" +command (see section~\ref{sec:uplevel}) and include whatever font +changing commands that you want to use. For example, if you type +\begin{verbatim} +\begin{questions} + \question + Is there, is there balm in Gilead? + + \fullwidth{\Large \textbf{Essay questions}} + + \question + Explain how the cooling of matter in the centuries following the big + bang has influenced the British parliamentary system of government. + + \fullwidth{\Large \textbf{Laboratory questions}} + + \question + In the cabinet below your laboratory bench you will find a single + edged razor blade, several C-clamps, and a bottle of whiskey. + Remove your appendix. Do not suture until your work has been + inspected. +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question + Is there, is there balm in Gilead? + + \fullwidth{\Large \textbf{Essay questions}} + + \question + Explain how the cooling of matter in the centuries following the big + bang has influenced the British parliamentary system of government. + + \fullwidth{\Large \textbf{Laboratory questions}} + + \question + In the cabinet below your laboratory bench you will find a single + edged razor blade, several C-clamps, and a bottle of whiskey. + Remove your appendix. Do not suture until your work has been + inspected. +\end{questions} +You can accomplish exactly the same thing by replacing +\begin{verbatim} + \fullwidth{\Large \textbf{Essay questions}} +\end{verbatim} +by +\begin{verbatim} + \begin{EnvFullwidth} + \Large \textbf{Essay questions} + \end{EnvFullwidth} +\end{verbatim} +and replacing +\begin{verbatim} + \fullwidth{\Large \textbf{Laboratory questions}} +\end{verbatim} +by +\begin{verbatim} + \begin{EnvFullwidth} + \Large \textbf{Laboratory questions} + \end{EnvFullwidth} +\end{verbatim} + + +\indcstop{fullwidth} +\indtstop{EnvFullwidth} +\index{EnvFullwidth environment|)} +\index{environment!EnvFullwidth|)} +\indcstop{uplevel} + +%-------------------------------------------------------------------- +\subsubsection{Using the standard sectioning commands} +\label{sec:NameSection} + +The exam document class is built upon the standard article document +class, and so the sectioning commands used with the article document +class can be used here as well. In particular, you can give the +commands \verb"\part", +% +\verb"\part"\indcsub{part}{standard sectioning command} +% +\verb"\part*", \verb"\section"\indc{section}, and \verb"\section*". +The definitions made in \verb"exam.cls" ensure that if a \verb"\part" +command appears \emph{outside of a parts environment} it will be +interpreted as a sectioning command, while if it appears \emph{inside + of a parts environment} it will be interpreted as beginning a new +part of a question. + +You can give these commands in the middle of a questions environment +so as not to interrupt the numbering of the questions, or you can end +a questions environment, give a sectioning command, and then start a +new questions environment (which would reset the question counter to +start again with number~1). If you have more than one questions +environment, though, then you will be unable to use any of the +commands that create grading\indc{gradetable} tables or +point\indc{pointtable} tables (see section~\ref{sec:Tables}) or the +commands that change the headers and footers depending on whether or +not a question spans multiple pages (see +section~\ref{sec:QuesSpan}).\indc{ifincomplete}\indc{ifcontinuation} + +If you give any of these commands while inside of a questions +environment, then the section titles will be indented to the same +extent that questions are indented unless they are given as the +argument of a \verb"\fullwidth"\indc{fullwidth} or +\verb"\uplevel"\indc{uplevel} command. These commands have the +advantage, however, that the unstarred versions provide automatic +numbering of the parts or sections. + + +\index{naming parts of the exam|)} +\index{indentation|)} + + +%-------------------------------------------------------------------- +%--------------------------------------------------------------------- +\section{Leaving space for the answers} +\label{sec:LeaveSpace} +\index{space!for answers|(} +\index{answer space|(} + +There are five different kinds of space that you can create: +\begin{itemize} +\item Blank space (see section~\ref{sec:BlankSpace}), +\item an empty box (see section~\ref{sec:EmptyBox}), +\item space filled with lines (see section~\ref{sec:FillLines}), +\item space filled with dotted lines (see + section~\ref{sec:FillDotLines}), and +\item space filled with a grid (see section~\ref{sec:FillGrid}). +\end{itemize} +You can also create answer lines for short answer questions (see +section~\ref{sec:ShortAns}). +In section~\ref{sec:solutions} we describe five environments for +typing solutions to questions: +\begin{itemize} +\item \texttt{solution}, +\item \texttt{solutionorbox}, +\item \texttt{solutionorlines}, +\item \texttt{solutionordottedlines}, and +\item \texttt{solutionorgrid}. +\end{itemize} +Each of those environments can take an optional argument specifying an +amount of space to be created when solutions are not being printed; +see section~\ref{sec:SolSpace}. + + +%-------------------------------------------------------------------- +\subsection{Leaving blank space} +\label{sec:BlankSpace} +\index{blank space|(} +\index{space!blank|(} + +To leave blank space on the page for the answer to a question, you +should use the \verb"\vspace*"\indc{vspace*} command. For example, +the command \verb"\vspace*{1in}" inserts one inch of vertical space +after the line in which it appears. (If it appears in between +paragraphs, then it inserts the space right there.) You can also use +the \verb"\vspace"\indc{vspace} command, the difference being that +space inserted by \verb"\vspace" will be deleted if it occurs at the +top of a new page, whereas space inserted by \verb"\vspace*" will +never be deleted. + +If you want to leave all the remaining space on the page blank, you +should give the commands\indc{stretch} +\begin{center} + \begin{tabular}{l} + \verb"\vspace*{\stretch{1}}"\\ + \verb"\newpage" + \end{tabular} +\end{center} +If you want to equally distribute the blank space among several +questions on the page, then just put +\verb"\vspace*{\stretch{1}}"\index{space!allocating} after each of the +questions and use \verb"\newpage"\indc{newpage} to end the page. You +can also distribute the available space in some other ratio. For +example, to give one of the questions on the page twice as much space +as any of the others, put \verb"\vspace*{\stretch{2}}" after that +question and \verb"\vspace*{\stretch{1}}" after each of the others. + +You can also leave blank space when solutions are not being printed by +using an optional argument with a \verb"solution" environment; see +section~\ref{sec:SolSpace}. + +\index{space!blank|)} +\index{blank space|)} + +%-------------------------------------------------------------------- +\subsection{Printing an empty box} +\label{sec:EmptyBox} +\index{space!empty box|(} +\index{empty box|(} +\indcstart{makeemptybox} + +You can print an empty box with the command +\begin{center} + \verb"\makeemptybox{length}" +\end{center} +which prints an empty box of height \verb"length" whose width equals +that of the current line. That is, the left edge is at the current +left margin (which depends on whether we're in a question, part, +subpart, or subsubpart) and the right edge is at the right margin. +(The box printed by the \verb"\makeemptybox" command can be printed in +color; for that, see section~\ref{sec:colorboxes}.) + + +\medskip + +For example, if you type +\begin{verbatim} +\begin{questions} + \question + In no more than one paragraph, explain why the earth is round. + + \makeemptybox{1in} + + \question + \begin{parts} + \part + What changes to the van Allen radiation belt are needed to make + the earth into a regular icosahedron? + + \makeemptybox{1in} + + \part + Where should the field generator be constructed if you want one of + the vertices to be located at the Royal Observatory at Greenwich? + + \makeemptybox{1in} + + \end{parts} +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question + In no more than one paragraph, explain why the earth is round. + + \makeemptybox{1in} + + \question + \begin{parts} + \part + What changes to the van Allen radiation belt are needed to make + the earth into a regular icosahedron? + + \makeemptybox{1in} + + \part + Where should the field generator be constructed if you want one of + the vertices to be located at the Royal Observatory at Greenwich? + + \makeemptybox{1in} + + \end{parts} +\end{questions} + +\medskip + +If you want to fill the remaining space on the page with an empty box, +you should give the commands\indc{stretch} +\begin{center} + \begin{tabular}{l} + \verb"\makeemptybox{\stretch{1}}"\\ + \verb"\newpage" + \end{tabular} +\end{center} +If you want to equally distribute the space for the answers among +several questions on the page, then just put +\verb"\makeemptybox{\stretch{1}}"\index{space!allocating} after each +of those questions and use \verb"\newpage"\indc{newpage} to end the +page. You can also distribute the available space in some other +ratio. For example, to give one of the questions on the page twice as +much space as any of the others, put \verb"\makeemptybox{\stretch{2}}" +after that question, \verb"\makeemptybox{\stretch{1}}" after each of +the others, and use \verb"\newpage" to end the page. + +You can also insert an empty box when solutions are not being printed +by including an optional argument with the \verb"solutionoremptybox" +environment; see section~\ref{sec:SolSpace}. + + +\indcstop{makeemptybox} +\index{empty box|)} +\index{space!empty box|)} + +%-------------------------------------------------------------------- +\subsection{Printing lined space} +\label{sec:FillLines} +\index{space!lined|(} +\index{lined space|(} +\indcstart{fillwithlines} + + +You can fill space with lines with the command +\begin{center} + \verb"\fillwithlines{length}" +\end{center} +which fills vertical space of height \verb"length" with horizontal +lines that run the length of the current line. That is, they extend +from the current left margin (which depends on whether we're in a +question, part, subpart, or subsubpart) to the right margin. + +By default, the lines are in black. However, if you give the +commands\indc{colorfillwithlines}\index{color package} +\begin{center} + \begin{tabular}{l} + \verb"\usepackage{color}"\\ + \verb"\colorfillwithlines" + \end{tabular} +\end{center} +then the lines will be in color, by default a light gray. That +default color was defined by the +command\indc{definecolor}\indt{FillWithLinesColor} +\begin{center} + \verb"\definecolor{FillWithLinesColor}{gray}{0.8}" +\end{center} +\index{customization!\texttt{\char`\\fillwithlines}} You can change +the color by giving a new \verb"\definecolor" command to redefine the +color \texttt{FillWithLinesColor}. + +\medskip + +For example, if you type +\begin{verbatim} +\begin{questions} + \question + In no more than one paragraph, explain why the earth is round. + + \fillwithlines{1in} + + \question + \begin{parts} + \part + What changes to the van Allen radiation belt are needed to make + the earth into a regular icosahedron? + + \fillwithlines{1in} + + \part + Where should the field generator be constructed if you want one of + the vertices to be located at the Royal Observatory at Greenwich? + + \fillwithlines{1in} + + \end{parts} +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question + In no more than one paragraph, explain why the earth is round. + + \fillwithlines{1in} + + \question + \begin{parts} + \part + What changes to the van Allen radiation belt are needed to make + the earth into a regular icosahedron? + + \fillwithlines{1in} + + \part + Where should the field generator be constructed if you want one of + the vertices to be located at the Royal Observatory at Greenwich? + + \fillwithlines{1in} + + \end{parts} +\end{questions} + +\medskip The distance between the lines is +\verb"\linefillheight"\indc{linefillheight}, the default value of +which is set with the +command\index{customization!\texttt{\char`\\fillwithlines}} +\begin{center} + \verb"\setlength\linefillheight{.25in}" +\end{center} +That value can be changed by giving a new \verb"\setlength" command. +The thickness of the lines is +\verb"\linefillthickness"\indc{linefillthickness}, the default value +of which is set with the command +\begin{center} + \verb"\setlength\linefillthickness{0.1pt}" +\end{center} +and that value can also be changed by giving a new \verb"\setlength" +command. + +If you want to fill the remaining space on the page with lines, you +should give the commands\indc{stretch} +\begin{center} + \begin{tabular}{l} + \verb"\fillwithlines{\stretch{1}}"\\ + \verb"\newpage" + \end{tabular} +\end{center} +If you want to equally distribute the space for the answers among +several questions on the page, then just put +\verb"\fillwithlines{\stretch{1}}"\index{space!allocating} after each +of those questions and use \verb"\newpage" to end the page. You can +also distribute the available space in some other ratio. For example, +to give one of the questions on the page twice as much space as any of +the others, put \verb"\fillwithlines{\stretch{2}}" after that +question, \verb"\fillwithlines{\stretch{1}}" after each of the others, +and use \verb"\newpage" to end the page. + +You can also insert lined space when solutions are not being printed +by including an optional argument with the \verb"solutionorlines" +environment; see section~\ref{sec:SolSpace}. + +\indcstop{fillwithlines} +\index{lined space|)} +\index{space!lined|)} + +%-------------------------------------------------------------------- +\subsection{Printing dotted lined space} +\label{sec:FillDotLines} +\index{space!dotted lined|(} +\index{dotted lined space|(} +\indcstart{fillwithdottedlines} + + +You can fill space with dotted lines with the command +\begin{center} + \verb"\fillwithdottedlines{length}" +\end{center} +which fills vertical space of height \verb"length" with dotted +horizontal lines that run the length of the current line. That is, +they extend from the current left margin (which depends on whether +we're in a question, part, subpart, or subsubpart) to the right +margin. The command \verb"\fillwithdottedlines" is almost identical +to the \verb"\fillwithlines" command (see +section~\ref{sec:FillLines}), except that the lines created are dotted +and the distance between the lines is +\verb"\dottedlinefillheight"\indc{dottedlinefillheight}. The default +value of \verb"\dottedlinefillheight" is set by the +command\index{customization!\texttt{\char`\\fillwithdottedlines}} +\begin{center} + \verb"\setlength\dottedlinefillheight{.25in}" +\end{center} +and that value can be changed by giving a new \verb"\setlength" +command. + +By default, the dotted lines are in black. However, if you give the +commands\indc{colorfillwithdottedlines}\index{color package} +\begin{center} + \begin{tabular}{l} + \verb"\usepackage{color}"\\ + \verb"\colorfillwithdottedlines" + \end{tabular} +\end{center} +then the dotted lines will be in color, by default a light gray. That +default color was defined by the +command\indc{definecolor}\indt{FillWithDottedLinesColor} +\begin{center} + \verb"\definecolor{FillWithDottedLinesColor}{gray}{0.8}" +\end{center} +\index{customization!\texttt{\char`\\fillwithdottedlines}} You can +change the color by giving a new \verb"\definecolor" command to +redefine the color \texttt{FillWithDottedLinesColor}. + +\medskip + +For example, if you type +\begin{verbatim} +\begin{questions} + \question + In no more than one paragraph, explain why the earth is round. + + \fillwithdottedlines{1in} + + \question + \begin{parts} + \part + What changes to the van Allen radiation belt are needed to make + the earth into a regular icosahedron? + + \fillwithdottedlines{1in} + + \part + Where should the field generator be constructed if you want one of + the vertices to be located at the Royal Observatory at Greenwich? + + \fillwithdottedlines{1in} + + \end{parts} +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question + In no more than one paragraph, explain why the earth is round. + + \fillwithdottedlines{1in} + + \question + \begin{parts} + \part + What changes to the van Allen radiation belt are needed to make + the earth into a regular icosahedron? + + \fillwithdottedlines{1in} + + \part + Where should the field generator be constructed if you want one of + the vertices to be located at the Royal Observatory at Greenwich? + + \fillwithdottedlines{1in} + + \end{parts} +\end{questions} + +If you want to fill the remaining space on the page with dotted lines, +you should give the commands\indc{stretch} +\begin{center} + \begin{tabular}{l} + \verb"\fillwithdottedlines{\stretch{1}}"\\ + \verb"\newpage" + \end{tabular} +\end{center} +If you want to equally distribute the space for the answers among +several questions on the page, then just put +\verb"\fillwithdottedlines{\stretch{1}}"\index{space!allocating} after +each question on the page and use \verb"\newpage" to end the page. +You can also distribute the available space in some other ratio. For +example, to give one of the questions on the page twice as much space +as any of the others, put \verb"\fillwithdottedlines{\stretch{2}}" +after that question, \verb"\fillwithdottedlines{\stretch{1}}" after +each of the others, and use \verb"\newpage" to end the page. + +You can also insert dotted lined space when solutions are not being +printed by including an optional argument with the +\verb"solutionordottedlines" environment; see +section~\ref{sec:SolSpace}. + +\indcstop{fillwithdottedlines} +\index{dotted lined space|)} +\index{space!dotted lined|)} + +%-------------------------------------------------------------------- +\subsection{Printing space filled with a grid} +\label{sec:FillGrid} +\index{space!grid|(} +\index{grid space|(} +\indcstart{fillwithgrid} + + +You can fill space with a grid with the command +\begin{center} + \verb"\fillwithgrid{length}" +\end{center} +which fills vertical space of height \texttt{length} with a grid that +runs the length of the current line. That is, it extends from the +current left margin (which depends on whether we're in a question, +part, subpart, or subsubpart) to the right margin. +The default grid size and grid line thickness were set by the +commands +\begin{center} + \begin{tabular}{l} + \verb"\setlength{\gridsize}{5mm}"\\ + \verb"\setlength{\gridlinewidth}{0.1pt}" + \end{tabular} +\end{center} +\index{customization!\texttt{\char`\\fillwithgrid}} You can change +either or both of those by giving new \verb"\setlength" commands. The +period of the grid is \verb"\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 +\verb"\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 +\verb"\gridsize+\gridlinewidth". + +By default, the created grids are in black. However, if you give the +commands\indc{colorgrids}\index{color package} +\begin{center} + \begin{tabular}{l} + \verb"\usepackage{color}"\\ + \verb"\colorgrids" + \end{tabular} +\end{center} +then the grids will be in color, by default a light gray. That +default color was defined by the +command\indc{definecolor}\indt{GridColor} +\begin{center} + \verb"\definecolor{GridColor}{gray}{0.8}" +\end{center} +\index{customization!\texttt{\char`\\fillwithgrid}} You can change the +color by giving a new \verb"\definecolor" command to redefine the +color \texttt{GridColor}. + + +For example, if you type +\begin{verbatim} +\begin{questions} + \question + In no more than one paragraph, explain why the earth is round. + + \smallskip\fillwithgrid{1in} + + \question + \begin{parts} + \part + What changes to the van Allen radiation belt are needed to make + the earth into a regular icosahedron? + + \smallskip\fillwithgrid{1in} + + \part + Where should the field generator be constructed if you want one of + the vertices to be located at the Royal Observatory at Greenwich? + + \smallskip\fillwithgrid{1in} + + \end{parts} +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question + In no more than one paragraph, explain why the earth is round. + + \smallskip\fillwithgrid{1in} + + \question + \begin{parts} + \part + What changes to the van Allen radiation belt are needed to make + the earth into a regular icosahedron? + + \smallskip\fillwithgrid{1in} + + \part + Where should the field generator be constructed if you want one of + the vertices to be located at the Royal Observatory at Greenwich? + + \smallskip\fillwithgrid{1in} + + \end{parts} +\end{questions} + +If you want to fill the remaining space on the page with a grid, you +should give the commands\indc{stretch} +\begin{center} + \begin{tabular}{l} + \verb"\fillwithgrid{\stretch{1}}"\\ + \verb"\newpage" + \end{tabular} +\end{center} +If you want to equally distribute the space for the answers among +several questions on the page, then just put +\verb"\fillwithgrid{\stretch{1}}"\index{space!allocating} after each +question on the page and use \verb"\newpage" to end the page. You can +also distribute the available space in some other ratio. For example, +to give one of the questions on the page twice as much space as any of +the others, put \verb"\fillwithgrid{\stretch{2}}" after that question, +\verb"\fillwithgrid{\stretch{1}}" after each of the others, and use +\verb"\newpage" to end the page. + +You can also insert a grid only when solutions are not being +printed by including an optional argument with the +\verb"solutionorgrid" environment; see +section~\ref{sec:SolSpace}. + +%-------------------------------------------------------------------- +\subsubsection{Covering every page with a grid} +\label{sec:CoverWGrid} +\index{grid!covering every page} + +If you'd like \emph{every} page to be completely covered by a grid, +with the exam printed right on top of that grid, you can do that by +using a \verb"\fillwithgrid" command in the footer. For this, make +sure you're using either \verb"\pagestyle{headandfoot}" (the default) +or \verb"\pagestyle{foot}" (see section~\ref{sec:pagestyle}), and put +the following into your preamble (i.e., after the +\verb"\documentclass" command and before the \verb"\begin{document}" + command):\index{color package}\indc{gridfromfoot} +\begin{verbatim} +\usepackage{color} +\colorgrids +\newlength{\scratchlength} +\newcommand{\gridfromfoot}{% + \setlength{\scratchlength}{\textheight}% + \addtolength{\scratchlength}{\baselineskip}% + \leavevmode\rlap{\vbox to 0pt{% + \vss + \fillwithgrid{\scratchlength}% + \vspace*{\footskip}% + }% vbox + }% rlap +}% gridfromfoot + +\footer{\gridfromfoot Math 115} + {} + {Page \thepage\ of \numpages} +\end{verbatim} + + +%-------------------------------------------------------------------- +\subsubsection{Printing graph paper} +\label{sec:GraphPaper} + +You can also use the \verb"\fillwithgrid" command to print graph +paper:\index{graph paper} +\begin{verbatim} +\documentclass{exam} +\pagestyle{empty} +\begin{document} + +\fillwithgrid{\stretch{1}} + +\newpage + +\fillwithgrid{\stretch{1}} + +\end{document} +\end{verbatim} + + + +\indcstop{fillwithgrid} +\index{grid space|)} +\index{space!grid|)} + + +%-------------------------------------------------------------------- +\subsection{Short answer questions} +\label{sec:ShortAns} +\indcstart{answerline} +\index{short answers|(} + +The exam class can print answer lines for short answer questions. The +command +\begin{center} + \verb"\answerline" +\end{center} +leaves blank vertical space of length +\verb"\answerskip"\indc{answerskip} and then inserts a horizontal line +of length \verb"\answerlinelength"\indc{answerlinelength}% +\index{customization!\texttt{\char`\\answerline}} at the right margin, +preceded by the number of the current question, part, subpart, or +subsubpart. The default values of \verb"\answerskip" and +\verb"\answerlinelength" are set by the +commands\index{customization!\texttt{\char`\\answerline}} +\begin{center} + \begin{tabular}{l} + \verb"\setlength\answerskip{2ex}"\\ + \verb"\setlength\answerlinelength{1in}" + \end{tabular} +\end{center} +and these can be changed by giving new \verb"\setlength" commands. +If you use the command \verb"\answerline" outside of a +\verb"questions" environment, then the number before the line will be +omitted. + +For example, if you type +\begin{verbatim} +\begin{questions} + \question + Who's buried in Grant's tomb? + \answerline + + \question + What was the color of George Washington's white horse? + \answerline + + \question + Which is heavier: A pound of feathers, or a pound of lead? + \answerline +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question + Who's buried in Grant's tomb? + \answerline + + \question + What was the color of George Washington's white horse? + \answerline + + \question + Which is heavier: A pound of feathers, or a pound of lead? + \answerline +\end{questions} +and if you type +\begin{verbatim} +\begin{questions} + \question + Answer the following questions on the lines at the right: + \begin{parts} + \part + Who's buried in Grant's tomb? \answerline + + \part + \begin{subparts} + \subpart + What light through yonder window breaks? \answerline + + \subpart + To be, or not to be; that is the question? \answerline + \end{subparts} + + \part + What was the color of George Washington's white horse? \answerline + \end{parts} +\end{questions} +\end{verbatim} +then you'll get +\begin{questions} + \question + Answer the following questions on the lines at the right: + \begin{parts} + \part + Who's buried in Grant's tomb? \answerline + + \part + \begin{subparts} + \subpart + What light through yonder window breaks? \answerline + + \subpart + To be, or not to be; that is the question? \answerline + \end{subparts} + + \part + What was the color of George Washington's white horse? \answerline + \end{parts} +\end{questions} + +%-------------------------------------------------------------------- +\subsection{Printing the answers to short answer questions} +\label{sec:AnsShortAns} +\index{short answers!answers to|(} +\index{answers!to short answers|(} + +The \verb"\answerline"\indcsub{answerline}{optional~argument} command +can take an optional argument so that you can have the answer to the +question printed on the answer line when answers are being printed +(see section~\ref{sec:answers}). When answers are not being printed, +the optional argument is ignored. + +When answers are being printed, the optional argument is printed +subject to the declarations in the argument of the last +\verb"\CorrectChoiceEmphasis"\indc{CorrectChoiceEmphasis} command +(which by default is +\verb"\bfseries"\index{customization!\texttt{\char`\\CorrectChoice}}; +see section~\ref{sec:CorrectChoice}), and it is printed a distance of +\verb"\answerclearance"\indc{answerclearance}% +\index{customization!\texttt{\char`\\answerline}} above the line. The +default value of \verb"\answerclearance" is set with the command +\begin{center} + \verb"\setlength\answerclearance{0.2ex}" +\end{center} +and it can be changed with a \verb"\setlength" command. The optional +argument is centered on the answer line unless it is longer than the +line, in which case it extends to the right of the line. + +For example, if you type +\begin{verbatim} +\begin{questions} + \question Who was the fifth Beatle? \answerline[Murray the K] + \question What is the answer to the ultimate question of life, the + universe, and everything? \answerline[42] +\end{questions} +\end{verbatim} +and if \verb"\noprintanswers" (the default) is in effect, you'll get +\begin{questions} + \question Who was the fifth Beatle? \answerline[Murray the K] + \question What is the answer to the ultimate question of life, the + universe, and everything? \answerline[42] +\end{questions} +while if \verb"\printanswers" is in effect, you'll get \printanswers +\begin{questions} + \question Who was the fifth Beatle? \answerline[Murray the K] + \question What is the answer to the ultimate question of life, the + universe, and everything? \answerline[42] +\end{questions} +\noprintanswers + +\index{answers!to short answers|)} +\index{short answers!answers to|)} + +\index{short answers|)} +\indcstop{answerline} + +\index{answer space|)} +\index{space!for answers|)} + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +\section{Solutions} +\label{sec:solutions} + +%-------------------------------------------------------------------- +\subsection{Solution environments} +\label{sec:SolEnv} +\index{solutions|(} +\index{solution environment@\texttt{solution} environment|(} +\index{answers|(} +\index{environment!solution@\texttt{solution}|(} +\index{environment!solutionorbox@\texttt{solutionorbox}|(} +\index{environment!solutionorlines@\texttt{solutionorlines}|(} +\index{environment!solutionordottedlines@\texttt{solutionordottedlines}|(} +\index{environment!solutionorgrid@\texttt{solutionorgrid}|(} +\index{solutionorbox environment|(} +\index{solutionorlines environment|(} +\index{solutionordottedlines environment|(} + + +There are six environments for typing solutions to the problems. +These environments all allow you to either print the solutions or omit +them with a single command. Whether or not solutions are +printed is controlled by the two +commands\indc{printanswers}\indc{noprintanswers} +\begin{center} + \begin{tabular}{l} + \verb"\printanswers"\\ + \verb"\noprintanswers" + \end{tabular} +\end{center} +Using these commands to turn printing of solutions on and off, you can +print the solutions for the entire exam or for only certain parts of +it. The default is that solutions are \emph{not} printed. There is +also an \verb"answers"\indt{answers}\indcsub{documentclass}{options} +option to the \verb"exam" document class, used as in +\begin{center} + \verb"\documentclass[answers]{exam}" +\end{center} +that is equivalent to giving the command +\verb"\printanswers"\indc{printanswers} at the beginning of the +document (see section~\ref{sec:answers}). + +The six environments for solutions are divided into two types. +\begin{itemize} +\item The \texttt{solutionbox} environment (see + section~\ref{sec:solutionbox}) always prints a box, of whatever size + you choose, and if solutions are being printed it prints the + solution inside of the box. +\item Each of the remaining five (see section~\ref{sec:SolSpace}), + \begin{center} + \begin{tabular}{rll} + the& \verb"solution"& environment,\\ + the& \verb"solutionorbox"& environment,\\ + the& \verb"solutionorlines"& environment,\\ + the& \verb"solutionordottedlines"& environment, and\\ + the& \verb"solutionorgrid"& environment, + \end{tabular} + \end{center} + by default prints either the solution or nothing at all. However, + they all can take one optional argument, which is an amount of space + to be left when solutions are not being printed. If you use these + environments without any optional arguments, then they are + identical: They print either the solution or nothing at all. They + differ only in the type of space they leave when you do include the + optional argument and solutions are not being printed. + + The differences between these five environments are that if the + optional argument is used and solutions are not being printed, then + % + \index{solution environment@\texttt{solution} environment!optional argument} + % + \begin{itemize} + \item the \verb"solution" enviroment inserts that amount of blank + space, as if you had given a \verb"\vspace*"\indc{vspace*} command + (see section~\ref{sec:BlankSpace}), + \item the \verb"solutionorbox" environment inserts an empty box of + that height, as if you had given a + \verb"\makeemptybox"\indc{makeemptybox} command (see + section~\ref{sec:EmptyBox}), + \item the \verb"solutionorlines" environment inserts that amount of + space with ruled lines, as if you had given a + \verb"\fillwithlines"\indc{fillwithlines} command (see + section~\ref{sec:FillLines}), + \item the \verb"solutionordottedlines" environment inserts that + amount of space with dotted lines, as if you had given a + \verb"\fillwithdottedlines"\indc{fillwithdottedlines} command (see + section~\ref{sec:FillDotLines}), and + \item the \verb"solutionorgrid" environment inserts that amount of + space filled with a grid, as if you had given a + \verb"\fillwithgrid"\indc{fillwithgrid} command (see + section~\ref{sec:FillGrid}). + \end{itemize} +\end{itemize} + +You can use a parts, subparts, or subsubparts environment inside any +of the solution environments without having their points (if any) +counted as actual points on the exam. 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. + + +\index{solutionorbox environment|)} +\index{solutionorlines environment|)} +\index{solutionordottedlines environment|)} +\index{environment!solution@\texttt{solution}|)} +\index{environment!solutionorbox@\texttt{solutionorbox}|)} +\index{environment!solutionorlines@\texttt{solutionorlines}|)} +\index{environment!solutionordottedlines@\texttt{solutionordottedlines}|)} +\index{environment!solutionorgrid@\texttt{solutionorgrid}|)} + +%-------------------------------------------------------------------- +\subsection{The appearance of the solution} +\label{sec:SolAppear} +\index{solution!appearance|(} + +The solutions printed by the +\begin{center} + \begin{tabular}{l} + \verb"solution",\\ + \verb"solutionorbox",\\ + \verb"solutionorlines",\\ + \verb"solutionordottedlines", and\\ + \verb"solutionorgrid" + \end{tabular} +\end{center} +environments can be printed either +\begin{itemize} +\item in a box (i.e., an \verb"\fbox") (see section~\ref{sec:SolBox}; + this is the default), +\item on a shaded background (see section~\ref{sec:shaded}), or +\item with no framing or shading (see section~\ref{sec:SolPlain}). +\end{itemize} +In all of these cases, solutions can be broken across pages, and the +part on each page will be boxed or shaded as appropriate. In +addition, the \verb"\SolutionEmphasis" command can be used to +highlight the text of the solution (using, e.g., boldface, or italics, +or color); see section~\ref{sec:SolEmph}. + + +%-------------------------------------------------------------------- +\subsubsection{Printing the solution in a box} +\label{sec:SolBox} +\index{solution!in a box|(} + +By default, the solution is printed inside of a box (i.e., an +\verb"\fbox"\indc{fbox}), and if the solution is broken across pages, +then each piece is enclosed in a box. (The box can be printed in +color; for that, see section~\ref{sec:colorboxes}.) There is also a +\verb"\shadedsolutions"\indc{shadedsolutions} command to instead have +the solution printed in a \verb"\colorbox"\indc{colorbox} (i.e., +printed on a shaded background); for this, you must load the +% +\verb"color"\index{color package} package and your printer must be +capable of printing color, or at least grayscale (see +section~\ref{sec:shaded}). + +\medskip + +For example, if you type +\begin{verbatim} +\begin{questions} + \question Did you mutter something? + + \begin{solution} + Once upon a midnight dreary, while I pondered, weak and weary, + Over many a quaint and curious volume of forgotten lore--- While I + nodded, nearly napping, suddenly there came a tapping, As of some + one gently rapping, rapping at my chamber door. ``\,'Tis some + visitor,'' I muttered, ``tapping at my chamber door--- Only this + and nothing more.'' + \end{solution} +\end{questions} +\end{verbatim} +and you've given the command \verb"\printanswers"\indc{printanswers} +or used the document class option \verb"answers"\indt{answers} (see +section~\ref{sec:answers}), then you'll get \bigskip +\begin{questions} + \question Did you mutter something? + + \begin{TheSolution} + Once upon a midnight dreary, while I pondered, weak and weary, + Over many a quaint and curious volume of forgotten lore--- While I + nodded, nearly napping, suddenly there came a tapping, As of some + one gently rapping, rapping at my chamber door. ``\,'Tis some + visitor,'' I muttered, ``tapping at my chamber door--- Only this + and nothing more.'' + \end{TheSolution} +\end{questions} +The result would be exactly the same if that \texttt{solution} +environment were replaced by a \texttt{solutionorbox}, +\texttt{solutionorlines}, \texttt{solutionordottedlines}, or +\texttt{solutionorgrid} environment. + +By default, the solution is printed in a box whose width equals that +of the text of the current question (or part, or subpart, or +subsubpart). That is, the indentation at the left of the solution +equals the current level of indentation. You can change this by +enclosing the \texttt{solution}, \texttt{solutionorbox}, +\texttt{solutionorlines}, \texttt{solutionordottedlines}, or +\texttt{solutionorgrid} environment in the argument of a +\verb"\fullwidth"\indc{fullwidth} or \verb"\uplevel"\indc{uplevel} +command, or inside of a \texttt{EnvFullwidth}\indt{EnvFullwidth}% +\index{EnvFullwidth environment}\index{environment!EnvFullwidth} or +% +\texttt{EnvUplevel}\indt{EnvUplevel}\index{EnvUplevel environment}% +\index{environment!EnvUplevel}% +environment (see section~\ref{sec:uplevel}). For example, if you type +\begin{verbatim} +\begin{questions} + \question Did you mutter something? + + \begin{EnvFullwidth} + \begin{TheSolution} + Once upon a midnight dreary, while I pondered, weak and weary, + Over many a quaint and curious volume of forgotten lore--- While + I nodded, nearly napping, suddenly there came a tapping, As of + some one gently rapping, rapping at my chamber door. ``\,'Tis + some visitor,'' I muttered, ``tapping at my chamber door--- Only + this and nothing more.'' + \end{TheSolution} + \end{EnvFullwidth} +\end{questions} +\end{verbatim} +and you've given the command \verb"\printanswers"\indc{printanswers} +or used the document class option \verb"answers"\indt{answers}, then +you'll get \bigskip +\begin{questions} + \question Did you mutter something? + + \begin{EnvFullwidth} + \begin{TheSolution} + Once upon a midnight dreary, while I pondered, weak and weary, + Over many a quaint and curious volume of forgotten lore--- While + I nodded, nearly napping, suddenly there came a tapping, As of + some one gently rapping, rapping at my chamber door. ``\,'Tis + some visitor,'' I muttered, ``tapping at my chamber door--- Only + this and nothing more.'' + \end{TheSolution} + \end{EnvFullwidth} +\end{questions} + +With all of these environments, if solutions are not being printed +then the contents of the environment are ignored. If, however, you +include the optional argument (see section~\ref{sec:SolSpace}), then +the requested amount of space (blank, lined, or dotted lined) will be +inserted when the solution isn't printed. + +\index{solution!in a box|)} + +%-------------------------------------------------------------------- +\subsubsection{Printing the solution on a shaded background} +\label{sec:shaded} +\index{solution!shaded|(} + +If you load the \verb"color" package with the +command\index{color package} +\begin{center} + \verb"\usepackage{color}" +\end{center} +in the preamble of your document (i.e., after the +\verb"\documentclass" command and before the \verb"\begin{document}" + command), then you can give the command\indc{shadedsolutions} +\begin{center} + \verb"\shadedsolutions" +\end{center} +This will cause solutions to be printed on a shaded background, which +by default is a light gray. (Most laser printers can at least print +grayscale when printing with the correct driver.) If you want to +change the color of the shading, you can do so by redefining the color +\verb"SolutionColor"\indc{SolutionColor}. For example, if you give +the command +\begin{center} + \verb"\definecolor{SolutionColor}{rgb}{0.8,0.9,1}" +\end{center} +then the solutions will be printed on a light blue background +(assuming that your printer is capable of producing that color). + +If you want to switch back to printing solutions inside of an +\verb"\fbox"\indc{fbox}, you can do so by giving the +command\indc{framedsolutions} +\begin{center} + \verb"\framedsolutions" +\end{center} +which returns you to the default situation. + +\index{solution!shaded|)} + +%-------------------------------------------------------------------- +\subsubsection{Printing the solution with no framing or shading} +\label{sec:SolPlain} +\index{solution!no framing or shading|(} + +If you give the command\indc{unframedsolutions} +\begin{center} + \verb"\unframedsolutions" +\end{center} +then solutions will be printed as normal text, with no framing or +shading. If you use this option, you'll almost certainly want to use +the command \verb"\SolutionEmphasis"\indc{SolutionEmphasis} (see +section~\ref{sec:SolEmph}) to distinguish the solution from the +surrounding text. + +If you want to switch back to printing solutions inside of an +\verb"\fbox", you can do so by giving the +command\indc{framedsolutions} +\begin{center} + \verb"\framedsolutions" +\end{center} +which returns you to the default situation. + +\index{solution!no framing or shading|)} + +%-------------------------------------------------------------------- +\subsection{Imported graphics in solutions} +\label{sec:graphics} +\index{graphics|(} +\indc{includegraphics} + +Graphics can be included inside solution environments using the +\verb"\includegraphics" command, as long as you've given the command +\verb"\usepackage{graphicx}" in the preamble (i.e., after the +\verb"\documentclass" command and before the \verb"\begin{document}" + command). + +A problem sometimes arises because many \LaTeX{} manuals say that you +should put an \verb"\includegraphics" command inside of a +\texttt{figure} environment, so that it will float to a convenient +place on a page. The problem with this is that floating environments +can't appear inside of a solution environment. + +There are (at least) two solutions to this problem, depending on +whether you really want the graphic to float away from the location at +which you've typed it. +\begin{itemize} +\item If you want the graphic to float, put the \texttt{figure} + environment \emph{outside} of the solution environment, using + \verb"\ifprintanswers" to ensure that it's printed only when + solutions are being printed, as in +\begin{verbatim} +\ifprintanswers + \begin{figure} + \includegraphics[width=7cm]{myfigure.pdf} + \caption{This is a lovely figure} + \label{fig:lovely} + \end{figure} +\fi +\end{verbatim} +\item If you \emph{don't} want the graphic to float, then omit the + \texttt{figure} environment and just put the \verb"\includegraphics" + command wherever you want the graphic to appear. If you want the + graphic to have a caption, then put the command + \verb"\usepackage{caption}" in your preamble and then use the + \verb"\captionof" command, as in +\begin{verbatim} +\includegraphics[width=7cm]{myfigure.pdf} +\captionof{figure}{This is a lovely figure} +\label{fig:lovely} +\end{verbatim} +\end{itemize} + +\index{graphics|)} + +%-------------------------------------------------------------------- +\subsection{Customizing the solution} +\label{sec:SolCust} +\index{customization!solution|(} +\index{solution!customizing|(} + +The solutions printed by any of the solution environments (see +section~\ref{sec:SolEnv}) can be customized: +\begin{itemize} +\item the title (by default, ``\textbf{Solution:}'') can be changed + (see section~\ref{sec:SolTitle}), +\item emphasis can be applied to the solution to distinguish it from + the surrounding text (see section~\ref{sec:SolEmph}), and +\item advanced users can entirely change the appearance of the + solutions by defining a \LaTeX{} environment (see + section~\ref{sec:AdvCust}). +\end{itemize} + +%-------------------------------------------------------------------- +\subsubsection{The title} +\label{sec:SolTitle} + +The word ``\textbf{Solution:}'' that you see at the beginning of the +solutions printed by the \texttt{solution}, \texttt{solutionorbox}, +\texttt{solutionorlines}, and \texttt{solutionordottedlines} +environments can be changed by redefining the command +\verb"\solutiontitle"\indc{solutiontitle}. The default value was +created by the command +\begin{center} +\verb"\newcommand{\solutiontitle}{\noindent\textbf{Solution:}\enspace}" +\end{center} +If, for example, you give the command +\begin{center} +\verb"\renewcommand{\solutiontitle}{\noindent\textbf{Solution:}\par\noindent}" +\end{center} +then the \verb"solution" environment above would print +\renewcommand{\solutiontitle}{\noindent\textbf{Solution:}\par\noindent} +\par\bigskip +\begin{questions} +\question Did you mutter something? + +\begin{TheSolution} + Once upon a midnight dreary, while I pondered, weak and weary, Over + many a quaint and curious volume of forgotten lore--- While I + nodded, nearly napping, suddenly there came a tapping, As of some + one gently rapping, rapping at my chamber door. ``\,'Tis some + visitor,'' I muttered, ``tapping at my chamber door--- Only this and + nothing more.'' +\end{TheSolution} +\end{questions} +\renewcommand{\solutiontitle}{\noindent\textbf{Solution:}\enspace} + +%-------------------------------------------------------------------- +\subsubsection{Solution emphasis} +\label{sec:SolEmph} + +You can change the appearance of the text of the solution with the +\verb"\SolutionEmphasis"\indc{SolutionEmphasis} command. The contents +of the solution are enclosed in a group, and that group is begun with +the argument of the most recent +\verb"\SolutionEmphasis"\indc{SolutionEmphasis} command. The default +was created by the command +\begin{center} + \verb"\SolutionEmphasis{}" +\end{center} +That is, the default is not to add any emphasis at all. If, for +example, you give the command +\begin{center} + \verb"\SolutionEmphasis{\itshape\small}" +\end{center} +then the solutions will be set in italics, in small type. For another +example, if you've given the command \verb"\usepackage{color}" in the +preamble of your document (i.e., after the \verb"\documentclass" +command and before the \verb"\begin{document}") and you give the +command\indc{SolutionEmphasis} +\begin{center} + \verb"\SolutionEmphasis{\color{red}}" +\end{center} +then the solutions will be printed in red (assuming your printer is +capable of producing that color). + +\textbf{Note:} If you've given the command +\verb"\unframedsolutions"\indc{unframedsolutions} (see +section~\ref{sec:SolPlain}), so that solutions are printed as normal +text with no framing or shading, then you'll almost certainly want to +use the \verb"\SolutionEmphasis"\indc{SolutionEmphasis} command to +create some visible difference between the solutions and the +surrounding text. + + +%-------------------------------------------------------------------- +\subsubsection{Advanced customizations} +\label{sec:AdvCust} +\index{TheSolution environment} +\index{environment!TheSolution} + +The appearance of all of these solution environments can actually be +totally customized, if you're up to defining a \LaTeX{} environment. +The appearance of the solution typed into any of these environments is +defined by an environment called \verb"TheSolution"\indt{TheSolution}, +and you can change the definition of \verb"TheSolution" with a +\verb"\renewenvironment" command. That is, the \verb"solution" +environment decides whether the command \verb"\printanswers" has been +given and, if so, it feeds the contents of the \verb"solution" +environment into a \verb"TheSolution" environment. (The behavior of a +\texttt{solutionorbox}, \texttt{solutionorlines} or +\texttt{solutionordottedlines} environment is similar.) If you use +\verb"\renewenvironment" to change the definition of the +\verb"TheSolution" environment, you'll be changing the way the +solution is printed. For the default definition of the +\verb"TheSolution" environment, see the file \verb"exam.cls". + +\index{solution!customizing|)} +\index{customization!solution|)} + +\index{solution!appearance|)} + +%-------------------------------------------------------------------- +\subsection{Leaving space for the answers when solutions aren't + printed} +\label{sec:SolSpace} +\index{space!for answers|(} +\index{answer space|(} +\index{solution environment@\texttt{solution} environment!optional argument|(} + +Each of the \texttt{solution}, \texttt{solutionorbox}, +\texttt{solutionorlines}, \texttt{solutionordottedlines}, and +\texttt{solutionorgrid} environments takes an optional argument: +\begin{itemize} +\item In a + % + \verb"solution" + % + \index{solution environment@\texttt{solution} environment!optional argument} + % + environment this is an amount of blank space to be left (just as if + you had used a \verb"\vspace*"\indc{vspace*} command; see + section~\ref{sec:BlankSpace}) when solutions are not being printed, +\item in a + % + \verb"solutionorbox"\indtsub{solutionorbox}{optional argument} + % + environment this is the height of an empty box to be drawn (just as + if you had used a \verb"\makeemptybox"\indc{makeemptybox} command; + see section~\ref{sec:EmptyBox}) when solutions are not being + printed, +\item in a + % + \verb"solutionorlines"\indtsub{solutionorlines}{optional argument} + % + environment this is an amount of lined space to be left (just as if + you had used a \verb"\fillwithlines"\indc{fillwithlines} command; + see section~\ref{sec:FillLines}) when solutions are not being + printed, +\item in a\indtsub{solutionordottedlines}{optional argument} + \verb"solutionordottedlines" environment this is an amount of dotted + lined space to be left (just as if you had used a + \verb"\fillwithdottedlines"\indc{fillwithdottedlines} command; see + section~\ref{sec:FillDotLines}) when solutions are not being + printed. +\item in a\indtsub{solutionorgrid}{optional argument} + \verb"solutionorgrid" environment this is an amount of space to be + filled with a grid (just as if you had used a + \verb"\fillwithgrid"\indc{fillwithgrid} command; see + section~\ref{sec:FillGrid}) when solutions are not being + printed. +\end{itemize} +For example, if you type +\begin{verbatim} +\begin{solution}[2in] + Once upon a midnight dreary, while I pondered, weak and weary, Over + many a quaint and curious volume of forgotten lore--- While I + nodded, nearly napping, suddenly there came a tapping, As of some + one gently rapping, rapping at my chamber door. ``\,'Tis some + visitor,'' I muttered, ``tapping at my chamber door--- Only this and + nothing more.'' +\end{solution} +\end{verbatim} +then there will be 2 inches of blank space inserted (as if you had +given the command \verb"\vspace*{2in}"; see +section~\ref{sec:BlankSpace}) when solutions are not being printed, if +you type +\begin{verbatim} +\begin{solutionorbox}[2in] + Once upon a midnight dreary, while I pondered, weak and weary, Over + many a quaint and curious volume of forgotten lore--- While I + nodded, nearly napping, suddenly there came a tapping, As of some + one gently rapping, rapping at my chamber door. ``\,'Tis some + visitor,'' I muttered, ``tapping at my chamber door--- Only this and + nothing more.'' +\end{solutionorbox} +\end{verbatim} +then there will be an empty box 2 inches tall inserted (as if you had +given the command \verb"\makeemptybox{2in}"; see +section~\ref{sec:EmptyBox}) when solutions are not being printed, if +you type +\begin{verbatim} +\begin{solutionorlines}[2in] + Once upon a midnight dreary, while I pondered, weak and weary, Over + many a quaint and curious volume of forgotten lore--- While I + nodded, nearly napping, suddenly there came a tapping, As of some + one gently rapping, rapping at my chamber door. ``\,'Tis some + visitor,'' I muttered, ``tapping at my chamber door--- Only this and + nothing more.'' +\end{solutionorlines} +\end{verbatim} +then there will be 2 inches of lined space inserted (as if you had +given the command \verb"\fillwithlines{2in}"; see +section~\ref{sec:FillLines}) when solutions are not being printed, if +you type +\begin{verbatim} +\begin{solutionordottedlines}[2in] + Once upon a midnight dreary, while I pondered, weak and weary, Over + many a quaint and curious volume of forgotten lore--- While I + nodded, nearly napping, suddenly there came a tapping, As of some + one gently rapping, rapping at my chamber door. ``\,'Tis some + visitor,'' I muttered, ``tapping at my chamber door--- Only this and + nothing more.'' +\end{solutionordottedlines} +\end{verbatim} +then there will be 2 inches of dotted lined space inserted (as if you +had given the command \verb"\fillwithdottedlines{2in}"; see +section~\ref{sec:FillDotLines}) when solutions are not being printed. +and if you type +\begin{verbatim} +\begin{solutionorgrid}[2in] + Once upon a midnight dreary, while I pondered, weak and weary, Over + many a quaint and curious volume of forgotten lore--- While I + nodded, nearly napping, suddenly there came a tapping, As of some + one gently rapping, rapping at my chamber door. ``\,'Tis some + visitor,'' I muttered, ``tapping at my chamber door--- Only this and + nothing more.'' +\end{solutionordottedlines} +\end{verbatim} +then there will be 2 inches of grid inserted (as if you had given the +command \verb"\fillwithgrid{2in}"; see section~\ref{sec:FillGrid}) +when solutions are not being printed. + + +%-------------------------------------------------------------------- +\subsubsection{Cancelling the space from the optional arguments} +\label{sec:cancelspace} +\indcstart{cancelspace} +\indcstart{nocancelspace} + +If you've typed any of the environments \texttt{solution}, +\texttt{solutionorbox}, \texttt{solutionorlines}, +\texttt{solutionordottedlines}, or \texttt{solutionorgrid} (see +section~\ref{sec:SolEnv}), and you've +\begin{itemize} +\item included an optional argument to leave space for answers when + solutions are not being printed, but +\item you would now like to print the exam \emph{without} printing the + solutions and \emph{without} leaving space for the answers, +\end{itemize} +then you can cancel the space that would be created by the optional +arguments by using the +\texttt{cancelspace}\indt{cancelspace}\indcsub{documentclass}{options} +document class option. That is, if you use the \verb"\documentclass" +command +\begin{center} + \verb"\documentclass[cancelspace]{exam}" +\end{center} +then optional arguments to any of the four solution environments will +be ignored. There are also commands \verb"\cancelspace" and +\verb"\nocancelspace"; using the document class option +\texttt{cancelspace} is equivalent to giving the command +\verb"\cancelspace" at the beginning of the file. The command +\verb"\nocancelspace" reverts to the default situation (in which the +optional arguments are not ignored). + +The document class option \texttt{cancelspace} has no effect at all if +solutions are being printed. + +\emph{Note:} The document class option \texttt{cancelspace} and the +command \verb"\cancelspace" only affect the optional arguments of of +the five solution environments \texttt{solution}, +\texttt{solutionorbox}, \texttt{solutionorlines}, +\texttt{solutionordottedlines}, and \texttt{solutionorgrid}; they do +\emph{not} affect any \verb"\vspace" commands that you put into the +file. + +\indcstop{nocancelspace} +\indcstop{cancelspace} + +\index{solution environment@\texttt{solution} environment!optional argument|)} + +%-------------------------------------------------------------------- +\subsection{The solutionbox environment} +\label{sec:solutionbox} +\indt{solutionbox} +\index{solution!in a box} + +The solutionbox environment is different from the other solution +environments (\texttt{solution}, \texttt{solutionorbox}, +\texttt{solutionorlines}, \texttt{solutionordottedlines}, and +\texttt{solutionorgrid}), in that +\begin{enumerate} +\item The box is always printed, whether answers are being printed or + not. +\item 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 + \verb"\stretch{number}". Note: \emph{It is 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. +\item The \texttt{solutionbox} environment makes no use of the + \texttt{TheSolution} environment; the \texttt{solutionbox} + environment is completely freestanding. +\end{enumerate} +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. (The box printed by the +\texttt{solutionbox} environment can be printed in color; for that, +see section~\ref{sec:colorboxes}.) + + + +For example, if you type +\begin{verbatim} +\begin{solutionbox}{2in} + Once upon a midnight dreary, while I pondered, weak and weary, Over + many a quaint and curious volume of forgotten lore--- While I + nodded, nearly napping, suddenly there came a tapping, As of some + one gently rapping, rapping at my chamber door. ``\,'Tis some + visitor,'' I muttered, ``tapping at my chamber door--- Only this and + nothing more.'' +\end{solutionbox} +\end{verbatim} +(note that the amount of space is required, and is typed as +``\verb"{2in}"'', rather than ``\verb"[2in]"'') and solutions are not +being printed, then you'll get +\begin{solutionbox}{2in} + Once upon a midnight dreary, while I pondered, weak and weary, Over + many a quaint and curious volume of forgotten lore--- While I + nodded, nearly napping, suddenly there came a tapping, As of some + one gently rapping, rapping at my chamber door. ``\,'Tis some + visitor,'' I muttered, ``tapping at my chamber door--- Only this and + nothing more.'' +\end{solutionbox} +If solutions \emph{are} being printed, then the exact same box would +be printed, but it would have the solution printed inside of it. + +\index{answer space|)} +\index{space!for answers|)} + +%-------------------------------------------------------------------- +\subsection{Solution box frames in color} +\label{sec:colorboxes} + +The frames that are printed by the commands that create solution boxes +can be printed in color. (By ``frame'' we mean the four lines that +constitute the box, not any solution that may appear inside that box.) +This includes +\begin{itemize} +\item the box printed by the \texttt{solutionbox} + environment\index{customization!\texttt{solutionbox}} + (see section~\ref{sec:solutionbox}), +\item the box printed by the \verb"\makeemptybox" + command\index{customization!\texttt{\char`\\makeemptybox}} + (see section~\ref{sec:EmptyBox}), +\item the box printed by the optional argument of the + \texttt{solutionorbox} + environment\index{customization!\texttt{solutionorbox}} (see + section~\ref{sec:SolEnv}), and +\item the box printed around the solution by + the\index{customization!\texttt{solution} environments} + \begin{itemize} + \item \texttt{solution}, + \item \texttt{solutionorbox}, + \item \texttt{solutionorlines}, + \item \texttt{solutionordottedlines}, and + \item \texttt{solutionorgrid} + \end{itemize} + environments when solutions are being printed and the default + solution appearance (\verb"\framedsolutions") is being used (see + section~\ref{sec:SolBox}). +\end{itemize} + +If you've given the command +\begin{center} + \verb"\usepackage{color}"\index{color package} +\end{center} +in the preamble of your document (i.e., after the +\verb"\documentclass" command and before the \verb"\begin{document}" +command), then you can give the command\indc{colorsolutionboxes} +\begin{center} + \verb"\colorsolutionboxes" +\end{center} +to have the frame printed in color. The color of the frame will be +\texttt{SolutionBoxColor}, the default value of which was created by +the command\indc{definecolor}\indt{SolutionBoxColor} +\begin{center} + \verb"\definecolor{SolutionBoxColor}{gray}{0.8}" +\end{center} +You can change the color by giving a new \verb"\definecolor" command, +but you must do this \emph{after} the \verb"\colorsolutionboxes" +command. + +To cancel color \texttt{solutionbox} frames and return to black, give +the command\indc{nocolorsolutionboxes} +\begin{center} + \verb"\nocolorsolutionboxes" +\end{center} + + + +%-------------------------------------------------------------------- +\subsection{Changes depending on whether or not solutions are + being printed} +\label{sec:ifprintanswers} +\indcstart{ifprintanswers} + +The command \verb"\ifprintanswers" is provided in case you want to +vary what appears on the exam in ways other than those provided by the +solution environments (see section~\ref{sec:solutions}), the +\verb"\CorrectChoice" command in multiple choice environments (see +section~\ref{sec:CorrectChoice}), and the optional argument to the +\verb"\answerline" command (see section~\ref{sec:AnsShortAns}). You +use this command by typing +\begin{verbatim} +\ifprintanswers + Stuff to appear only when answers are being printed. +\else + Stuff to appear only when answers are not being printed. +\fi +\end{verbatim} +The \verb"\else" clause is optional; you can also type +\begin{verbatim} +\ifprintanswers + Stuff to appear only when answers are being printed. +\fi +\end{verbatim} +If you want something printed only when answers are not being printed, +you can type +\begin{verbatim} +\ifprintanswers +\else + Stuff to appear only when answers are not being printed. +\fi +\end{verbatim} +Since the \verb"exam" document class automatically loads the +\verb"ifthen" package, you can accomplish the same things using the +\verb"\ifthenelse" command: +\begin{verbatim} +\ifthenelse{\boolean{printanswers}} + {Stuff to appear only when answers are being printed.} + {Stuff to appear only when answers are not being printed.} +\end{verbatim} +If you use \verb"\ifthenelse", then \verb"both" cases must be present, +even if you leave one of them empty. Thus, e.g., if you want to print +something only when answers are not being printed, you'd type +\begin{verbatim} +\ifthenelse{\boolean{printanswers}} + {} + {Stuff to appear only when answers are not being printed.} +\end{verbatim} + + +%-------------------------------------------------------------------- +\subsubsection{Printing only selected solutions} +\label{sec:selectedsolutions} +\index{selected solution} +\index{solution!selected} + +The \verb"\ifprintanswers" command can be used to print only certain +of the solutions in an exam. To do that, you'd put the lines +\begin{verbatim} +\newif\ifprintselected +\printselectedtrue +%\printselectedfalse + +\newenvironment{select} +{\ifprintselected + \printanswers + \fi +} +{} +\end{verbatim} +into your preamble (i.e., after the \verb"\documentclass" command and +before the \verb"\begin{document}" command). That defines a + \texttt{select} environment, in which you can wrap any of the + solution environments, as in +\begin{verbatim} +\begin{select} + \begin{solutionorlines}[1in] + Only when the number is two. + \end{solutionorlines} +\end{select} +\end{verbatim} +As long as you leave the command \verb"\printselectedtrue" +uncommented, then everything wrapped in a \texttt{select} environment +will be printed. If you comment out \verb"\printselectedtrue" and +uncomment \verb"\printselectedfalse", then the \texttt{select} +environment will have no effect. + +\indcstop{ifprintanswers} + +\index{answers|)} +\index{solution environment@\texttt{solution} environment|)} +\index{solutions|)} + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +\section{Grading tables and point tables} +\label{sec:Tables} +\index{grading table|(} +\index{point table|(} +\indcstart{gradetable} +\indcstart{pointtable} + +\newlength\cwidth + +The \verb"exam" document class can print either +\begin{itemize} +\item a grading table, indexed either by question number or by page + number, which lists the points possible and leaves space for you to + fill in (by hand) the points earned (see + section~\ref{sec:GradeTables}), or +\item a point table, indexed either by question number or by page + number, which lists the points possible but does not leave space for + you to fill in the points earned (see + section~\ref{sec:PointTables}). +\end{itemize} +It's also possible to print either a grading table or point table to +cover only part of the exam (see section~\ref{sec:PartialTable}). + +If the exam has any bonus points (see section~\ref{sec:Bonus}), then +the bonus points will be ignored by the tables described in sections +\ref{sec:GradeTables}, \ref{sec:PointTables}, +and~\ref{sec:PartialTable}, but it's possible to print bonus grading +tables and bonus point tables that list the bonus points and ignore +the non-bonus points (see section~\ref{sec:BonusTables}) or combined +grading tables and combined point tables that list both regular points +and bonus points (see section~\ref{sec:CombinedTables}). + +%-------------------------------------------------------------------- +\subsection{Grading tables indexed by question number or by page + number} +\label{sec:GradeTables} +\index{grading table!by question number or page number|(} + +The \verb"exam" document class can print a grading table, indexed +either by question number or by page number. That is, you can print +\begin{itemize} +\item a table listing the question numbers (or question titles for + questions created using the \verb"\titledquestion" command instead + of the \verb"\question" command; see section~\ref{sec:Titled}) and + the total points possible for each question (including all of its + parts, subparts, and subsubparts) and leaving space for you to fill + in (by hand) the points earned on each question, or +\item a table listing each page that has at least one question, part, + subpart, or subsubpart with points assigned to it, the total number + of points possible on that page, and leaving space for you to fill + in (by hand) the points earned on that page. +\end{itemize} +In order to use this feature you must either include the optional +argument +\verb"addpoints"\indt{addpoints}\indcsub{documentclass}{options} in +your \verb"\documentclass" command (as in +\verb"\documentclass[addpoints]{exam}") or give the command +\verb"\addpoints"\indc{addpoints} (see section~\ref{sec:addpoints}), +and there must be only one \verb"questions" +% +environment\index{questions environment!only one} in the entire exam. +In addition, you must run \LaTeX{} twice after making any changes to +the file in order to make sure that the point values are correct on a +grading table indexed by question number and at least three times for +a grading table indexed by page number. (Since the table appears on +the third run of \LaTeX{}, and the space it occupies can change the +page on which each question falls, it may take a fourth run of +\LaTeX{} for the table to have the points per page correct.) + +The command to create a grading table is +\begin{center} + \verb"\gradetable" +\end{center} +and it takes two optional +arguments:\indc{gradetable[v]}\indc{gradetable[h]} +\begin{enumerate} +\item The first optional argument can be either \verb"[v]" or + \verb"[h]", to choose between a vertically oriented table and a + horizontally oriented table, and +\item the second optional argument can be either \verb"[questions]" or + \verb"[pages]", to choose between a table indexed by question number + and a table indexed by page number. +\end{enumerate} +That is,\indc{gradetable[v][questions]}\indc{gradetable[v][pages]}% +\indc{gradetable[h][questions]}\indc{gradetable[h][pages]} +\begin{itemize} +\item \verb"\gradetable[v][questions]" prints a vertically oriented + table indexed by question number, +\item \verb"\gradetable[h][questions]" prints a horizontally oriented + table indexed by question number, +\item \verb"\gradetable[v][pages]" prints a vertically oriented table + indexed by page number, and +\item \verb"\gradetable[h][pages]" prints a horizontally oriented + table indexed by page number. +\end{itemize} +If you leave out the optional arguments (i.e., if you give the command +as ``\verb"\gradetable"'') you'll get a vertically oriented table +indexed by question number. + +For example, if the exam has 8 questions, each worth a total of 15 +points, and you type +\begin{verbatim} +\begin{center} + \gradetable[v][questions] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|c|c|c|} + \hline + Question& Points& Score\\ + \hline + 1& 15& \hbox to \cwidth{\hfill}\\ + \hline + 2& 15& \hbox to \cwidth{\hfill}\\ + \hline + 3& 15& \hbox to \cwidth{\hfill}\\ + \hline + 4& 15& \hbox to \cwidth{\hfill}\\ + \hline + 5& 15& \hbox to \cwidth{\hfill}\\ + \hline + 6& 15& \hbox to \cwidth{\hfill}\\ + \hline + 7& 15& \hbox to \cwidth{\hfill}\\ + \hline + 8& 15& \hbox to \cwidth{\hfill}\\ + \hline + Total:& 120&\\ + \hline + \end{tabular} +\end{center} +and if you type +\begin{verbatim} +\begin{center} + \gradetable[h][questions] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|l|c|c|c|c|c|c|c|c|c|} + \hline + Question:& 1& 2& 3& 4& 5& 6& 7& 8& Total\\ + \hline + Points:& + 15& + 15& + 15& + 15& + 15& + 15& + 15& + 15& + 120\\ + \hline + Score:& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \\ + \hline + \end{tabular} +\end{center} +The number of points listed for a question is the sum of the point +values for that question and all of its parts, subparts, and +subsubparts. + +If those 8 questions are distributed two to a page on each of pages 2 +through 5 and if you type +\begin{verbatim} +\begin{center} + \gradetable[v][pages] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|c|c|c|} + \hline + Page& Points& Score\\ + \hline + 2& 30& \hbox to \cwidth{\hfill}\\ + \hline + 3& 30& \hbox to \cwidth{\hfill}\\ + \hline + 4& 30& \hbox to \cwidth{\hfill}\\ + \hline + 5& 30& \hbox to \cwidth{\hfill}\\ + \hline + Total:& 120&\\ + \hline + \end{tabular} +\end{center} +and if you type +\begin{verbatim} +\begin{center} + \gradetable[h][pages] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|l|c|c|c|c|c|} + \hline + Page:& 2& 3& 4& 5& Total\\ + \hline + Points:& + 30& + 30& + 30& + 30& + 120\\ + \hline + Score:& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill} + \\ + \hline + \end{tabular} +\end{center} + +\emph{Warning:} If you have a large number of questions on +the exam, then these tables can easily become too large to fit on the +page. If this becomes a problem, then you can either +\begin{itemize} +\item create grading ranges (see section~\ref{sec:PartialTable}) and + print several partial grading tables, making each one small enough + to fit on the page, or +\item use the \verb"\multirowgradetable" or + \verb"\multicolumngradetable" command (see section~\ref{sec:MulRows} + and section~\ref{sec:MulCols}) to create a grading table with + multiple rows or multiple columns. +\end{itemize} +\index{grading table!by question number or page number|)} + +%-------------------------------------------------------------------- +\subsubsection{Grading tables with multiple rows} +\label{sec:MulRows} + +If you want to print a horizontal grading table but the table would be +too large for the page, you can print a grading table with multiple +rows by giving the command +\begin{center} + \verb"\multirowgradetable{numrows}[questions or pages]" +\end{center} +\indc{multirowgradetable}Note that the first argument +(\texttt{numrows}) is \emph{required}, and so it is enclosed in +braces, but the second argument (\texttt{questions} or \texttt{pages}) +is optional, and is enclosed in square brackets, just as in the +\verb"\gradetable" command (see section~\ref{sec:GradeTables}). For +example, to print a grading table with 3 rows indexed by questions, +you would give the command +\begin{center} + \verb"\multirowgradetable{3}[questions]" +\end{center} +The command +\begin{center} + \verb"\gradetable[h][questions]" +\end{center} +is equivalent to +\begin{center} + \verb"\multirowgradetable{1}[questions]" +\end{center} + +The distance between the rows of a multirow table is +\verb"\doublerulesep", the default value of which is 2.0pt. You can +change that using a \verb"\setlength" command, as in +\begin{center} + \verb"\setlength{\doublerulesep}{0.5in}" +\end{center} +(see section~\ref{sec:CustTable}). + +For example, if an exam has 16 questions, each worth a total of 15 +points, and you type +\begin{verbatim} +\begin{center} + \setlength{\doublerulesep}{0.25in} + \multirowgradetable{2}[questions] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \setlength{\doublerulesep}{0.25in} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|l|c|c|c|c|c|c|c|c|c|} + \hline + Question:& 1& 2& 3& 4& 5& 6& 7& 8& 9\\ + \hline + Points:& + 15& + 15& + 15& + 15& + 15& + 15& + 15& + 15& + 15\\ + \hline + Score:& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \\ + \hline + \hline + Question:& 10& 11& 12& 13& 14& 15& 16&& Total\\ + \hline + Points:& + 15& + 15& + 15& + 15& + 15& + 15& + 15& + & + 240\\ + \hline + Score:& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \\ + \hline + \end{tabular} +\end{center} + + +%-------------------------------------------------------------------- +\subsubsection{Grading tables with multiple columns} +\label{sec:MulCols} + +If you want to print a vertical grading table but the table would be +too large for the page, you can print a grading table with multiple +columns by giving the command +\begin{center} + \verb"\multicolumngradetable{numcols}[questions or pages]" +\end{center} +\indc{multicolumngradetable}Note that the first argument +(\texttt{numcols}) is \emph{required}, and so it is enclosed in +braces, but the second argument (\texttt{questions} or \texttt{pages}) +is optional, and is enclosed in square brackets, just as in the +\verb"\gradetable" command (see section~\ref{sec:GradeTables}). For +example, to print a grading table with 3 columns indexed by questions, +you would give the command +\begin{center} + \verb"\multicolumngradetable{3}[questions]" +\end{center} +The command +\begin{center} + \verb"\gradetable[v][questions]" +\end{center} +is equivalent to +\begin{center} + \verb"\multicolumngradetable{1}[questions]" +\end{center} + +The distance between the columns of a multicolumn table is +\verb"\doublerulesep", the default value of which is 2.0pt. You can +change that using a \verb"\setlength" command, as in +\begin{center} + \verb"\setlength{\doublerulesep}{0.5in}" +\end{center} +(see section~\ref{sec:CustTable}). + +For example, if an exam has 10 questions, each worth a total of 15 +points, and you type +\begin{verbatim} +\begin{center} + \setlength{\doublerulesep}{0.5in} + \multicolumngradetable{2}[questions] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2em + \setlength{\doublerulesep}{0.5in} + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|c|c|c|c|c|c|c|} + \cline{1-3}\cline{5-7} + Question& Points& Score& + \hspace*{-\arrayrulewidth}\hspace*{\doublerulesep}& + Question& Points& Score\\ + \cline{1-3}\cline{5-7} + 1& 15& \hbox to \cwidth{\hfill}&&7& 15& \hbox to \cwidth{\hfill}\\ + \cline{1-3}\cline{5-7} + 2& 15& \hbox to \cwidth{\hfill}&&8& 15& \hbox to \cwidth{\hfill}\\ + \cline{1-3}\cline{5-7} + 3& 15& \hbox to \cwidth{\hfill}&&9& 15& \hbox to \cwidth{\hfill}\\ + \cline{1-3}\cline{5-7} + 4& 15& \hbox to \cwidth{\hfill}&&10& 15& \hbox to \cwidth{\hfill}\\ + \cline{1-3}\cline{5-7} + 5& 15& \hbox to \cwidth{\hfill}&& & & \hbox to \cwidth{\hfill}\\ + \cline{1-3}\cline{5-7} + 6& 15& \hbox to \cwidth{\hfill}&&Total:& 150& \hbox to \cwidth{\hfill}\\ + \cline{1-3}\cline{5-7} + + \cline{1-3}\cline{5-7} + \end{tabular} +\end{center} + + + +%-------------------------------------------------------------------- +\subsection{Point tables indexed by question number or by page + number} +\label{sec:PointTables} +\index{point table!by question number or page number|(} + +Point tables are similar to grading tables (see +section~\ref{sec:GradeTables}), except that there is no place in the +table to fill in the points earned. + +The command to create a point table is +\begin{center} + \verb"\pointtable" +\end{center} +and it takes two optional +arguments:\indc{pointtable[v]}\indc{pointtable[h]} +\begin{enumerate} +\item The first optional argument can be either \verb"[v]" or + \verb"[h]", to choose between a vertically oriented table and a + horizontally oriented table, and +\item the second optional argument can be either \verb"[questions]" or + \verb"[pages]", to choose between a table indexed by question number + and a table indexed by page number. +\end{enumerate} +That is,\indc{pointtable[v][questions]}\indc{pointtable[v][pages]}% +\indc{pointtable[h][questions]}\indc{pointtable[h][pages]} +\begin{itemize} +\item \verb"\pointtable[v][questions]" prints a vertically oriented + table indexed by question number, +\item \verb"\pointtable[h][questions]" prints a horizontally oriented + table indexed by question number, +\item \verb"\pointtable[v][pages]" prints a vertically oriented table + indexed by page number, and +\item \verb"\pointtable[h][pages]" prints a horizontally oriented + table indexed by page number. +\end{itemize} +If you leave out the optional arguments (i.e., if you give the command +as ``\verb"\pointtable"'') you'll get a vertically oriented table +indexed by question number. + +For example, if the exam has 8 questions, each worth a total of 15 +points, and you type +\begin{verbatim} +\begin{center} + \pointtable[v][questions] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|c|c|} + \hline + Question& Points\\ + \hline + 1& 15\\ + \hline + 2& 15\\ + \hline + 3& 15\\ + \hline + 4& 15\\ + \hline + 5& 15\\ + \hline + 6& 15\\ + \hline + 7& 15\\ + \hline + 8& 15\\ + \hline + Total:& 120\\ + \hline + \end{tabular} +\end{center} +and if you type +\begin{verbatim} +\begin{center} + \pointtable[h][questions] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|l|c|c|c|c|c|c|c|c|c|} + \hline + Question:& 1& 2& 3& 4& 5& 6& 7& 8& Total\\ + \hline + Points:& + 15& + 15& + 15& + 15& + 15& + 15& + 15& + 15& + 120\\ + \hline + \end{tabular} +\end{center} +The number of points listed for a question is the sum of the point +values for that question and all of its parts, subparts, and +subsubparts. + +If those 8 questions are distributed two to a page on each of pages 2 +through 5 and if you type +\begin{verbatim} +\begin{center} + \pointtable[v][pages] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|c|c|} + \hline + Page& Points\\ + \hline + 2& 30\\ + \hline + 3& 30\\ + \hline + 4& 30\\ + \hline + 5& 30\\ + \hline + Total:& 120\\ + \hline + \end{tabular} +\end{center} +and if you type +\begin{verbatim} +\begin{center} + \pointtable[h][pages] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|l|c|c|c|c|c|} + \hline + Page:& 2& 3& 4& 5& Total\\ + \hline + Points:& + 30& + 30& + 30& + 30& + 120\\ + \hline + \end{tabular} +\end{center} + +\emph{Warning:} If you have a large number of questions on +the exam, then these tables can easily become too large to fit on the +page. If this becomes a problem, then you can either +\begin{itemize} +\item create grading ranges (see section~\ref{sec:PartialTable}) and + print several partial point tables, making each one small enough + to fit on the page, or +\item use the \verb"\multirowpointtable" or + \verb"\multicolumnpointtable" command (see + section~\ref{sec:PtMulRows} and section~\ref{sec:PtMulCols}) to + create a point table with multiple rows or multiple columns. +\end{itemize} +\index{point table!by question number or page number|)} + +%-------------------------------------------------------------------- +\subsubsection{Point tables with multiple rows} +\label{sec:PtMulRows} + +If you want to print a horizontal point table but the table would be +too large for the page, you can print a point table with multiple +rows by giving the command +\begin{center} + \verb"\multirowpointtable{numrows}[questions or pages]" +\end{center} +\indc{multirowpointtable}Note that the first argument +(\texttt{numrows}) is \emph{required}, and so it is enclosed in +braces, but the second argument (\texttt{questions} or \texttt{pages}) +is optional, and is enclosed in square brackets, just as in the +\verb"\pointtable" command (see section~\ref{sec:PointTables}). For +example, to print a point table with 3 rows indexed by questions, you +would give the command +\begin{center} + \verb"\multirowpointtable{3}[questions]" +\end{center} +The command +\begin{center} + \verb"\pointtable[h][questions]" +\end{center} +is equivalent to +\begin{center} + \verb"\multirowpointtable{1}[questions]" +\end{center} + +The distance between the rows of a multirow table is +\verb"\doublerulesep", the default value of which is 2.0pt. You can +change that using a \verb"\setlength" command, as in +\begin{center} + \verb"\setlength{\doublerulesep}{0.5in}" +\end{center} +(see section~\ref{sec:CustTable}). + +%-------------------------------------------------------------------- +\subsubsection{Point tables with multiple columns} +\label{sec:PtMulCols} + +If you want to print a vertical point table but the table would be +too large for the page, you can print a point table with multiple +columns by giving the command +\begin{center} + \verb"\multicolumnpointtable{numcols}[questions or pages]" +\end{center} +\indc{multicolumnpointtable}Note that the first argument +(\texttt{numcols}) is \emph{required}, and so it is enclosed in +braces, but the second argument (\texttt{questions} or \texttt{pages}) +is optional, and is enclosed in square brackets, just as in the +\verb"\pointtable" command (see section~\ref{sec:PointTables}). For +example, to print a point table with 3 columns indexed by questions, +you would give the command +\begin{center} + \verb"\multicolumnpointtable{3}[questions]" +\end{center} +The command +\begin{center} + \verb"\pointtable[v][questions]" +\end{center} +is equivalent to +\begin{center} + \verb"\multicolumnpointtable{1}[questions]" +\end{center} + +The distance between the columns of a multicolumn table is +\verb"\doublerulesep", the default value of which is 2.0pt. You can +change that using a \verb"\setlength" command, as in +\begin{center} + \verb"\setlength{\doublerulesep}{0.5in}" +\end{center} +(see section~\ref{sec:CustTable}). + +%-------------------------------------------------------------------- +\subsection{Table entries as clickable links} +\label{sec:Clickable} +\index{grading table!clickable links} +\index{point table!clickable links} +\index{clickable links} + +If you put the command\indc{usepackage\{hyperref\}}\indt{hyperref} +\begin{center} + \verb"\usepackage{hyperref}" +\end{center} +into the preamble of your document (i.e., after the +\verb"\documentclass" command and before the \verb"\begin{document}" +command) and then produce a pdf file (either using dvipdf or +directly by using pdflatex), then +\begin{itemize} +\item in a grading table or point table indexed by question number the + question numbers in the table will be clickable links that take you + to the corresponding question, and +\item in a grading table or point table indexed by page number the + page numbers in the table will be clickable links that take you to + the corresponding page. +\end{itemize} +If you create questions using the \verb"\titledquestion" command +instead of the \verb"\question" command (see +section~\ref{sec:Titled}), then a grading table or point table indexed +by question number will show the \emph{titles} of those questions +instead of the numbers of those questions, and those question titles +will be clickable links that take you to the corresponding question. + +%-------------------------------------------------------------------- +\subsection{Grading ranges, partial grading tables, and partial point + tables} +\label{sec:PartialTable} +\index{grading range|(} +\indcstart{begingradingrange} +\indcstart{endgradingrange} +\index{range!grading|(} + +It is possible to define one or more ``grading ranges'', and then to +count the points in a range and create grading tables and point tables +that cover only that range. + +In more detail: You can define a grading range by choosing a name with +which to label the range, e.g., ``myrange'', and then putting the +command +\begin{itemize} +\item[] \verb"\begingradingrange{myrange}" at the start of the range + and the command +\item[] \verb"\endgradingrange{myrange}" at the end of the range. +\end{itemize} +You can then use the commands +\begin{itemize} +\item \verb"\pointsinrange{myrange}"\indc{pointsinrange}, which will + expand to the number of points in the range, +\item \verb"\firstqinrange{myrange}"\indc{firstqinrange}, which will + expand to the number of the first question in the range, +\item \verb"\lastqinrange{myrange}"\indc{lastqinrange}, which will + expand to the number of the last question in the range, and +\item \verb"\numqinrange{myrange}"\indc{numqinrange}, which will + expand to the number of questions in the range. +\end{itemize} +You can define as many grading ranges as you like, wherever you like. +That is, grading ranges do \emph{not} need to be nested; you can begin +the range \texttt{otherrange} somewhere in the middle of the range +\texttt{myrange} and then end the range \texttt{otherrange} after the +end of \texttt{myrange}. + +You can create a grading table or point table that covers only the +questions in a range by using the +\verb"\partialgradetable"\indc{partialgradetable} or +\verb"\partialpointtable"\indc{partialpointtable} command. These are +similar to the \verb"\gradetable" and \verb"\pointtable" commands, +except that they each have one required argument (the name of the +grading range) before the two optional arguments (the first of which +must be either \verb"[v]" or \verb"[h]" and the second of which must +be either \verb"[questions]" or \verb"[pages]"). For example, the +command +\begin{center} + \verb"\partialgradetable{myrange}[v][questions]" +\end{center} +would create a vertically grading oriented table indexed by the +questions in the range, and the command +\begin{center} + \verb"\partialgradetable{myrange}[v][pages]" +\end{center} +would create a vertically oriented grading table indexed by all pages +with points starting with the page containing the command +\verb"\begingradingrange{myrange}" and ending with the page containing +the command \verb"\endgradingrange{myrange}" + +If the exam has any bonus points (see section~\ref{sec:Bonus}), then +the bonus points will be ignored by the \verb"\pointsinrange", +\verb"\partialgradetable", and \verb"\partialpointtable" commands, but +they will be counted by the \verb"\bonuspointsinrange" command (see +section~\ref{sec:BonusTables}) and tabulated by the +\verb"\partialbonusgradetable", \verb"\partialbonuspointtable", +\verb"\partialcombinedgradetable", and +\verb"\partialcombinedponttable" commands (see +section~\ref{sec:BonusTables} and section~\ref{sec:CombinedTables}). + +\index{range!grading|)} +\indcstop{endgradingrange} +\indcstop{begingradingrange} +\index{grading range|)} + + +%-------------------------------------------------------------------- +\subsubsection{Partial grading tables and partial point tables with + multiple rows} +\label{sec:PartMulRows} + +If you want to print a horizontal partial grading table or partial +point table but the table would be too large for the page, you can +print a partial grading table or partial point table with multiple +rows by giving the one of the commands +\begin{center} + \verb"\multirowpartialgradetable{numrows}{rangename}[questions or pages]" + \verb"\multirowpartialpointtable{numrows}{rangename}[questions or pages]" +\end{center} +\indc{multirowpartialgradetable}\indc{multirowpartialpointtable}Note +that the first two arguments (\texttt{numrows} and \texttt{rangename}) +are \emph{required}, and so they are enclosed in braces, but the third +argument (\texttt{questions} or \texttt{pages}) is optional, and is +enclosed in square brackets, just as in the \verb"\partialgradetable" +and \verb"\partialpointtable" commands (see +section~\ref{sec:PartialTable}). For example, to print a partial +grading table with 3 rows covering the range \texttt{myrange} indexed +by questions, you would give the command +\begin{center} + \verb"\multirowpartialgradetable{3}{myrange}[questions]" +\end{center} +The command +\begin{center} + \verb"\partialgradetable{myrange}[h][questions]" +\end{center} +is equivalent to +\begin{center} + \verb"\multirowpartialgradetable{1}{myrange}[questions]" +\end{center} + +The distance between the rows of a multirow table is +\verb"\doublerulesep", the default value of which is 2.0pt. You can +change that using a \verb"\setlength" command, as in +\begin{center} + \verb"\setlength{\doublerulesep}{0.5in}" +\end{center} +(see section~\ref{sec:CustTable}). + +%-------------------------------------------------------------------- +\subsubsection{Partial grading tables and partial point tables with + multiple columns} +\label{sec:PartMulCols} + +If you want to print a vertical partial grading table or partial point +table but the table would be too large for the page, you can print a +partial grading table or partial point table with multiple columns by +giving one of the commands +\begin{center} +\verb"\multicolumnpartialgradetable{numcols}{rangename}[questions or pages]"\\ +\verb"\multicolumnpartialpointtable{numcols}{rangename}[questions or pages]" +\end{center} +\indc{multicolumnpartialgradetable}\indc{multicolumnpartialpointtable}Note +that the first two arguments (\texttt{numcols} and +\texttt{rangename}) are \emph{required}, and so they are enclosed in +braces, but the third argument (\texttt{questions} or \texttt{pages}) +is optional, and is enclosed in square brackets, just as in the +\verb"\partialgradetable" and \verb"\partialpointtable" commands (see +section~\ref{sec:PartialTable}). For example, to print a partial +grading table with 3 columns covering the range \texttt{myrange} +indexed by questions, you would give the command +\begin{center} + \verb"\multicolumnpartialgradetable{3}{myrange}[questions]" +\end{center} +The command +\begin{center} + \verb"\partialgradetable{myrange}[v][questions]" +\end{center} +is equivalent to +\begin{center} + \verb"\multicolumnpartialgradetable{1}{myrange}[questions]" +\end{center} + +The distance between the columns of a multicolumn table is +\verb"\doublerulesep", the default value of which is 2.0pt. You can +change that using a \verb"\setlength" command, as in +\begin{center} + \verb"\setlength{\doublerulesep}{0.5in}" +\end{center} +(see section~\ref{sec:CustTable}). + +%-------------------------------------------------------------------- +\subsection{\texttt{\bs pointsofquestion}} +\label{sec:pointsofq} + +If you use the document class option \verb"addpoints"\indt{addpoints} +(as in +\verb"\documentclass[addpoints]{exam}"\indcsub{documentclass}{options}) +or give the command \verb"\addpoints"\indc{addpoints} (see +section~\ref{sec:addpoints}), then you can use +the\indc{pointsofquestion} +\begin{center} + \verb"\pointsofquestion" +\end{center} +command. This command takes one argument, which must be the number of +a question on the exam, and it prints the total number of points for +that question. That is: +\begin{itemize} +\item \verb"\pointsofquestion{1}" prints the sum of the point values + for question 1 and all of its parts, subparts, and subsubparts. +\item \verb"\pointsofquestion{2}" prints the sum of the point values + for question 2 and all of its parts, subparts, and subsubparts. +\item Etc. +\end{itemize} +The \verb"\pointsofquestion" command is used by the \verb"\gradetable" +and \verb"\pointtable" commands (see section~\ref{sec:Tables}), +and it can be used to create a table using \LaTeX's \verb"tabular" +environment when the tables produced using the \verb"\gradetable" and +\verb"\pointtable" commands either don't fit on the page or are +unsuitable for some other reason. It can also be used in a +\verb"\qformat" command to list the total number of points of all +parts, subparts, and subsubparts of a question on the line with the +question number (see section~\ref{sec:adding}). + +The \verb"\pointsofquestion"\indc{pointsofquestion} command ignores +any bonus points that you may have created (see +section~\ref{sec:Bonus}). The \verb"\bonuspointsofquestion" command, +however, counts the bonus points (see section~\ref{sec:BonusTables}). + +%-------------------------------------------------------------------- +\subsection{\texttt{\bs pointsonpage}} +\label{sec:pointsonp} + +If you use the document class option \verb"addpoints"\indt{addpoints} +(as in +\verb"\documentclass[addpoints]{exam}"\indcsub{documentclass}{options}) +or give the command \verb"\addpoints"\indc{addpoints} (see +section~\ref{sec:addpoints}), then you can use the +\verb"\pointsonpage"\indc{pointsonpage} command. This command takes +one argument, which must be the number of a page of the exam, and it +prints the total number of points for all the questions, parts, +subparts, and subsubparts on that page. That is: +\begin{itemize} +\item \verb"\pointsonpage{1}" prints the sum of the point values for + all questions, etc., on page 1, +\item \verb"\pointsonpage{2}" prints the sum of the point values for + all questions, etc., on page 2, +\item Etc. +\end{itemize} +This command can be used to create a table using \LaTeX's +\verb"tabular" environment when the tables produced using the +\verb"\gradetable" and \verb"\pointtable" commands either don't fit on +the page or are unsuitable for some other reason. It can also be used +in headers and footers to print on each page the total number of +points available on that page; for example, the command +\begin{verbatim} + \runningfooter{} + {} + {Points earned: \makebox[1in]{\hrulefill} + out of a possible \pointsonpage{\thepage} points} +\end{verbatim} +\indcsub{pointsonpage}{in footer} (see +section~\ref{sec:runningfooter}) will produce the footer +\samplefoot{}{}{}{Points earned: \makebox[1in]{\hrulefill} out of a + possible 20 points} on all pages after the first. (For another +example, see section~\ref{sec:PtsPgEx}) + +\textbf{Caution:} The command \verb"\pointsonpage{\thepage}" will work +reliably only in headers and footers, since the command +% +\verb"\thepage"\indcsub{thepage}{reliable only in headers and footers} +will work reliably only in headers and footers. + +The \verb"\pointsonpage" command ignores any bonus points that you may +have created (see section~\ref{sec:Bonus}). The +\verb"\bonuspointsonpage" command, however, counts the bonus points +(see section~\ref{sec:BonusTables}). + +%-------------------------------------------------------------------- +\subsection{Bonus grading tables and bonus point tables} +\label{sec:BonusTables} +\index{grading table!bonus|(} +\index{point table!bonus|(} + +If your exam contains any bonus +% +points\index{bonus points}\index{points!bonus} (see +section~\ref{sec:Bonus}), then those bonus points will be ignored by +the grading table and point table commands described in sections +\ref{sec:GradeTables}, \ref{sec:PointTables}, +and~\ref{sec:PartialTable} and by the +\verb"\pointsofquestion"\indc{pointsofquestion} (see +section~\ref{sec:pointsofq}) and +\verb"\pointsonpage"\indc{pointsonpage} (see +section~\ref{sec:pointsonp}) commands. There are, however, analogous +commands that count only the bonus points and ignore the non-bonus +points. (There are also commands that create tables listing both +non-bonus and bonus points; see section~\ref{sec:CombinedTables}.) +These commands, and the non-bonus commands to which they correspond, +are as follows: +\begin{center} + \begin{tabular}{l@{\qquad\qquad}l} + Bonus points& Non-bonus points\\[\bigskipamount] + \verb"\bonusgradetable"& \verb"\gradetable"\\ + \verb"\multirowbonusgradetable"& \verb"\multirowgradetable"\\ + \verb"\multicolumnbonusgradetable"& \verb"\multicolumngradetable"\\ + \verb"\bonuspointtable"& \verb"\pointtable"\\ + \verb"\multirowbonuspointtable"& \verb"\multirowpointtable"\\ + \verb"\multicolumnbonuspointtable"& + \verb"\multicolumnpointtable"\\[\medskipamount] + \verb"\partialbonusgradetable"& \verb"\partialgradetable"\\ + \verb"\multirowpartialbonusgradetable"& + \verb"\multirowpartialgradetable"\\ + \verb"\multicolumnpartialbonusgradetable"& + \verb"\multicolumnpartialgradetable"\\ + \verb"\partialbonuspointtable"& + \verb"\partialpointtable"\\ + \verb"\multirowpartialbonuspointtable"& + \verb"\multirowpartialpointtable"\\ + \verb"\multicolumnpartialbonuspointtable"& + \verb"\multicolumnpartialpointtable"\\[\medskipamount] + \verb"\bonuspointsinrange"& \verb"\pointsinrange"\\ + \verb"\bonuspointsofquestion"& \verb"\pointsofquestion"\\ + \verb"\bonuspointsonpage"& \verb"\pointsonpage" + \end{tabular} +\end{center} +\indc{bonusgradetable}\indc{bonuspointtable}% +\indc{bonuspointsinrange}\indc{partialbonusgradetable}% +\indc{partialbonuspointtable}\indc{bonuspointsofquestion}% +\indc{bonuspointsonpage}% +\indc{multirowbonusgradetable}% +\indc{multicolumnbonusgradetable}% +\indc{multirowbonuspointtable}% +\indc{multicolumnbonuspointtable}% +\indc{multirowpartialbonusgradetable}% +\indc{multicolumnpartialbonusgradetable}% +\indc{multirowpartialbonuspointtable}% +\indc{multicolumnpartialbonuspointtable}% +All of the the commands in the first column count bonus points and +ignore non-bonus points, while all of the commands in the second +column count non-bonus points and ignore bonus points. The commands +\begin{center} + \begin{tabular}{l} + \verb"\partialbonusgradetable",\\ + \verb"\multirowpartialbonusgradetable",\\ + \verb"\multicolumnpartialbonusgradetable",\\ + \verb"\partialbonuspointtable",\\ + \verb"\multirowpartialbonuspointtable", and\\ + \verb"\multicolumnpartialbonuspointtable" + \end{tabular} +\end{center} +use the same \verb"\begingradingrange"\indc{begingradingrange} and +\verb"\endgradingrange"\indc{endgradingrange} commands that are used +by the corresponding non-bonus versions (see +section~\ref{sec:PartialTable}). Just as is described in +section~\ref{sec:Clickable} for their non-bonus counterparts, if you +put the command\indc{usepackage\{hyperref\}}\indt{hyperref} +\begin{center} + \verb"\usepackage{hyperref}" +\end{center} +into the preamble of your document (i.e., after the +\verb"\documentclass" command and before the \verb"\begin{document}" +command) and then produce a pdf file (either using dvipdf or +directly by using pdflatex), +% +then\index{clickable links} +\begin{itemize} +\item in a bonus grading table or bonus point table indexed by + question number, the question numbers (or question titles, if you + used \verb"\bonustitledquestion"; see section~\ref{sec:Bonus}) in + the table will be clickable links that take you to the corresponding + question, and +\item in a bonus grading table or bonus point table indexed by page + number the page numbers in the table will be clickable links that + take you to the corresponding page. +\end{itemize} + +For example, if the exam has 8 questions, with each odd numbered +question worth a total of 10 regular points and each even numbered +question worth a total of 5 bonus points, and you type +\begin{verbatim} +\begin{center} + \bonusgradetable[h][questions] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|l|c|c|c|c|c|c|c|c|c|} + \hline + Question:& 1& 2& 3& 4& 5& 6& 7& 8& Total\\ + \hline + Bonus Points:& + 0& + 5& + 0& + 5& + 0& + 5& + 0& + 5& + 20\\ + \hline + Score:& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}&\\ + \hline + \end{tabular} +\end{center} + +\index{point table!bonus|)} +\index{grading table!bonus|)} + +%-------------------------------------------------------------------- +\subsection{Combined grading tables and combined point tables} +\label{sec:CombinedTables} +\index{grading table!combined|(} +\index{point table!combined|(} + + +There are commands for producing \emph{combined} grading and point +tables, both partial and full, that tabulate both regular points and +bonus points (see section~\ref{sec:Bonus}). The single-row and +single-column versions of these commands, and the +non-bonus and bonus commands to which they correspond, are +\indc{combinedgradetable}\indc{combinedpointtable}% +\indc{partialcombinedgradetable}\indc{partialcombinedpointtable}% +\begin{center} + \begin{tabular}{l@{\enskip}l@{\enskip}l} + Non-Bonus points only& \multicolumn{1}{c}{Bonus points only}& + \multicolumn{1}{c}{Combined}\\[\medskipamount] + \verb"\gradetable"& \verb"\bonusgradetable"& + \verb"\combinedgradetable"\\ + \verb"\pointtable"& \verb"\bonuspointtable"& + \verb"\combinedpointtable"\\ + \verb"\partialgradetable"& \verb"\partialbonusgradetable"& + \verb"\partialcombinedgradetable"\\ + \verb"\partialpointtable"& \verb"\partialbonuspointtable"& + \verb"\partialcombinedpointtable" + \end{tabular} +\end{center} +The first two commands in each column take two optional arguments, the +first being either \verb"[v]" or \verb"[h]" and the second being +either \verb"[questions]" or \verb"[pages]". The last two commands in +each column take one required argument, the name of the grading range +(defined using the \verb"\begingradingrange" and +\verb"\endgradingrange" commands; see section~\ref{sec:PartialTable}), +and then the same two optional arguments as the other commands (the +first being either \verb"[v]" or \verb"[h]" and the second being +either \verb"[questions]" or \verb"[pages]"). + +The multirow and multicolumn versions of combined grading tables and +combined point tables are produced by the commands +\indc{multirowcombinedgradetable}% +\indc{multirowcombinedpointtable}% +\indc{multirowpartialcombinedgradetable}% +\indc{multirowpartialcombinedpointtable}% +\indc{multicolumncombinedgradetable}% +\indc{multicolumncombinedpointtable}% +\indc{multicolumnpartialcombinedgradetable}% +\indc{multicolumnpartialcombinedpointtable}% +\begin{verbatim} +\multirowcombinedgradetable{numrows}[questions or pages] +\multirowcombinedpointtable{numrows}[questions or pages] +\multirowpartialcombinedgradetable{numrows}{rangename}[questions or pages] +\multirowpartialcombinedpointtable{numrows}{rangename}[questions or pages] +\multicolumncombinedgradetable{numcols}[questions or pages] +\multicolumncombinedpointtable{numcols}[questions or pages] +\multicolumnpartialcombinedgradetable{numcols}{rangename}[questions or pages] +\multicolumnpartialcombinedpointtable{numcols}{rangename}[questions or pages] +\end{verbatim} +The distance between the rows of a multirow table and between the +columns of a multicolumn table is \verb"\doublerulesep", the default +value of which is 2.0pt. You can change that using a +\verb"\setlength" command, as in +\begin{center} + \verb"\setlength{\doublerulesep}{0.5in}" +\end{center} +(see section~\ref{sec:CustTable}). + + + +Just as is described in section~\ref{sec:Clickable} for their regular +points and section~\ref{sec:BonusTables} for bonus points, if you put +the +% +command\index{clickable links}\indc{usepackage\{hyperref\}}% +\indt{hyperref} +\begin{center} + \verb"\usepackage{hyperref}" +\end{center} +into the preamble of your document (i.e., after the +\verb"\documentclass" command and before the \verb"\begin{document}" +command) and then produce a pdf file (either using dvipdf or +directly by using pdflatex), then +\begin{itemize} +\item in a combined grading table or combined point table indexed by + question number, the question numbers (or question titles, if you + used either \verb"\titledquestion" (see section~\ref{sec:Titled}) or + \verb"\bonustitledquestion" (see section~\ref{sec:Bonus})) in the + table will be clickable links that take you to the corresponding + question, and +\item in a combined grading table or combined point table indexed by + page number the page numbers in the table will be clickable links + that take you to the corresponding page. +\end{itemize} + +For example, if the exam has 8 questions, with each odd numbered +question worth a total of 10 regular points and each even numbered +question worth a total of 5 bonus points, and you type +\begin{verbatim} +\begin{center} + \combinedgradetable[h][questions] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|l|c|c|c|c|c|c|c|c|c|} + \hline + Question:& 1& 2& 3& 4& 5& 6& 7& 8& Total\\ + \hline + Points:& + 10& + 0& + 10& + 0& + 10& + 0& + 10& + 0& + 40\\ + \hline + Bonus Points:& + 0& + 5& + 0& + 5& + 0& + 5& + 0& + 5& + 20\\ + \hline + Score:& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}&\\ + \hline + \end{tabular} +\end{center} + +\index{point table!combined|)} +\index{grading table!combined|)} + +%-------------------------------------------------------------------- +\subsection{Changing the total points in a table} +\label{sec:Totalpoints} +\index{grading table!changing total points|(} +\index{point table!changing total points|(} + + +There are commands for changing the total points and total bonus +points in grading and point tables, so that the stated point total +will not equal the sum of the point values in the table. These +commands are intended for exams in which the students are required to +do some subset of the problems, but not all of them, and so the total +number of points possible on the exam is less than the sum of the +points for all of the questions. The commands +are\indc{settabletotalpoints}\indc{settabletotalbonuspoints} +\begin{center} + \begin{tabular}{l} + \verb"\settabletotalpoints"\\ + \verb"\settabletotalbonuspoints" + \end{tabular} +\end{center} +Each of those commands takes one argument. After giving the command +\begin{center} + \verb"\settabletotalpoints{number}" +\end{center} +any grading or point table (regular or combined, partial or full) will +list the total points as \texttt{number} instead of the actual total +number of points in the table. After giving the command +\begin{center} + \verb"\settabletotalbonuspoints{number}" +\end{center} +any grading or point table (bonus or combined, partial or full) will +list the total bonus points as \texttt{number} instead of the actual +total number of bonus points in the table. + +To have these commands affect only a single table, confine the command +and the command to create the table inside of a group (possibly by +just placing those commands inside of a \texttt{center} environment). +For example, if an exam has 8 questions, each worth 10 points, and the +students are required to do any 6 of the 8, then the commands +\begin{verbatim} +\begin{center} + \settabletotalpoints{60} + \gradetable[h][questions] +\end{center} +\end{verbatim} +will produce +\begin{center} + \cwidth=2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|l|c|c|c|c|c|c|c|c|c|} + \hline + Question:& 1& 2& 3& 4& 5& 6& 7& 8& Total\\ + \hline + Points:& + 10& + 10& + 10& + 10& + 10& + 10& + 10& + 10& + 60\\ + \hline + Score:& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}&\\ + \hline + \end{tabular} +\end{center} +and no other tables will be affected by that +\verb"\settabletotalpoints" command. + +\index{point table!changing total points|)} +\index{grading table!changing total points|)} + +%-------------------------------------------------------------------- +\subsection{Customizing the tables} +\label{sec:CustTable} +\index{customization!grading table|(} +\index{customization!point table|(} +\index{grade table!customization|(} +\index{point table!customization|(} + +There are four ways in which you can customize the appearance of +grading tables and point tables: +\begin{itemize} +\item You can change the words (and the fonts) that appear in the + table. +\item You can change the minimum width of the blank cells into which + you will write the scores. +\item You can change the value of + \verb"\baselinestretch"\indc{baselinestretch} used for the table. +\item You can change the distance between the rows in a multirow table + and the distance between the columns in a multicolumn table. +\end{itemize} +For all grading and point tables:\indc{gradetablestretch}\indc{cellwidth} +\indc{doublerulesep}% +\begin{center} + \begin{tabular}{l@{\qquad}p{3in}} + \verb"\cellwidth{length}"& sets the minimum width of the blank cells to + \verb"length"\\[\medskipamount] + \verb"\gradetablestretch{number}"& uses \verb"number" as the + \verb"\baselinestretch"\\[\medskipamount] + \verb"\setlength{\doublerulesep}{length}"& sets the distance + between the columns of a multicolumn table and the distance + between the rows of a multirow table to \verb"length". + \end{tabular} +\end{center} +For vertical non-bonus tables: +% (i.e., tables created by +% \verb"\gradetable[v]", \verb"\multicolumngradetable", +% \verb"\pointtable[v]", \verb"\multicolumnpointtable", +% \verb"\partialgradetable{rangename}[v]", +% \verb"\multicolumnpartialgradetable", +% \verb"\partialpointtable{rangename}[v]", or +% \verb"\multicolumnpartialpointtable"):% +\indc{vqword}\indc{vpgword}\indc{vpword}\indc{vsword}\indc{vtword} +\begin{center} + \begin{tabular}{l@{\qquad}l} + Command& \multicolumn{1}{c}{Effect}\\[\medskipamount] + \verb"\vqword{text}"& substitutes \verb"text" for ``Question''\\ + \verb"\vpgword{text}"& substitutes \verb"text" for ``Page''\\ + \verb"\vpword{text}"& substitutes \verb"text" for ``Points''\\ + \verb"\vsword{text}"& substitutes \verb"text" for ``Score''\\ + \verb"\vtword{text}"& substitutes \verb"text" for ``Total:'' + \end{tabular} +\end{center} +For horizontal non-bonus tables: +% (i.e., tables created by +% \verb"\gradetable[h]", \verb"\pointtable[h]", +% \verb"\partialgradetable{rangename}[h]", or +% \verb"\partialpointtable{rangename}[h]"):% +\indc{hqword}\indc{hpgword}\indc{hpword}\indc{hsword}\indc{htword} +\begin{center} + \begin{tabular}{l@{\qquad}l} + Command& \multicolumn{1}{c}{Effect}\\[\medskipamount] + \verb"\hqword{text}"& substitutes \verb"text" for ``Question:''\\ + \verb"\hpgword{text}"& substitutes \verb"text" for ``Page:''\\ + \verb"\hpword{text}"& substitutes \verb"text" for ``Points:''\\ + \verb"\hsword{text}"& substitutes \verb"text" for ``Score:''\\ + \verb"\htword{text}"& substitutes \verb"text" for ``Total'' + \end{tabular} +\end{center} +For vertical bonus tables: +% (i.e., tables created by +% \verb"\bonusgradetable[v]", \verb"\bonuspointtable[v]", +% \verb"\partialbonusgradetable{rangename}[v]", or +% \verb"\partialbonuspointtable{rangename}[v]"): +\indc{bvqword}\indc{bvpgword}\indc{bvpword}\indc{bvsword}% +\indc{bvtword} +\begin{center} + \begin{tabular}{l@{\qquad}l} + Command& \multicolumn{1}{c}{Effect}\\[\medskipamount] + \verb"\bvqword{text}"& substitutes \verb"text" for ``Question''\\ + \verb"\bvpgword{text}"& substitutes \verb"text" for ``Page''\\ + \verb"\bvpword{text}"& substitutes \verb"text" for ``Bonus Points''\\ + \verb"\bvsword{text}"& substitutes \verb"text" for ``Score''\\ + \verb"\bvtword{text}"& substitutes \verb"text" for ``Total:'' + \end{tabular} +\end{center} +For horizontal bonus tables: +% (i.e., tables created by +% \verb"\bonusgradetable[h]", \\ +% \verb"\bonuspointtable[h]", +% \verb"\partialbonusgradetable{rangename}[h]", or\\ +% \verb"\partialbonuspointtable{rangename}[h]"): +\indc{bhqword}% +\indc{bhpgword}\indc{bhpword}\indc{bhsword}\indc{bhtword} +\begin{center} + \begin{tabular}{l@{\qquad}l} + Command& \multicolumn{1}{c}{Effect}\\[\medskipamount] + \verb"\bhqword{text}"& substitutes \verb"text" for ``Question:''\\ + \verb"\bhpgword{text}"& substitutes \verb"text" for ``Page:''\\ + \verb"\bhpword{text}"& substitutes \verb"text" for ``Bonus Points:''\\ + \verb"\bhsword{text}"& substitutes \verb"text" for ``Score:''\\ + \verb"\bhtword{text}"& substitutes \verb"text" for ``Total'' + \end{tabular} +\end{center} +For vertical combined tables: +% (i.e., tables created by +% \verb"\combinedgradetable[v]",\\ +% \verb"\combinedpointtable[v]", +% \verb"\partialcombinedgradetable{rangename}[v]", or\\ +% \verb"\partialcombinedpointtable{rangename}[v]"): +\indc{cvqword}% +\indc{cvpgword}\indc{cvpword}\indc{cvbpword}\indc{cvsword}% +\indc{cvtword} +\begin{center} + \begin{tabular}{l@{\qquad}l} + Command& \multicolumn{1}{c}{Effect}\\[\medskipamount] + \verb"\cvqword{text}"& substitutes \verb"text" for ``Question''\\ + \verb"\cvpgword{text}"& substitutes \verb"text" for ``Page''\\ + \verb"\cvpword{text}"& substitutes \verb"text" for ``Points''\\ + \verb"\cvbpword{text}"& substitutes \verb"text" for ``Bonus Points''\\ + \verb"\cvsword{text}"& substitutes \verb"text" for ``Score''\\ + \verb"\cvtword{text}"& substitutes \verb"text" for ``Total:'' + \end{tabular} +\end{center} +For horizontal combined tables: +% (i.e., tables created by +% \verb"\combinedgradetable[h]", \\ +% \verb"\combinedpointtable[h]", +% \verb"\partialcombinedgradetable{rangename}[h]", or\\ +% \verb"\partialcombinedpointtable{rangename}[h]"): +\indc{chqword}% +\indc{chpgword}\indc{chpword}\indc{chbpword}\indc{chsword}% +\indc{chtword} +\begin{center} + \begin{tabular}{l@{\qquad}l} + Command& \multicolumn{1}{c}{Effect}\\[\medskipamount] + \verb"\chqword{text}"& substitutes \verb"text" for ``Question:''\\ + \verb"\chpgword{text}"& substitutes \verb"text" for ``Page:''\\ + \verb"\chpword{text}"& substitutes \verb"text" for ``Points:''\\ + \verb"\chbpword{text}"& substitutes \verb"text" for ``Bonus Points:''\\ + \verb"\chsword{text}"& substitutes \verb"text" for ``Score:''\\ + \verb"\chtword{text}"& substitutes \verb"text" for ``Total'' + \end{tabular} +\end{center} +If you don't use any of these commands then you get the default +values, which are defined by the commands in the following +table:\indc{doublerulesep}\indc{gradetablestretch}\indc{cellwidth} +\begin{center} + \begin{tabular}{l@{\quad}l} + \multicolumn{2}{c}{\bfseries Defaults for grading and point + tables}\\*[\bigskipamount] + \verb"\hqword{Question:}"& \verb"\vqword{Question}"\\ + \verb"\hpgword{Page:}"& \verb"\vpgword{Page}"\\ + \verb"\hpword{Points:}"& \verb"\vpword{Points}"\\ + \verb"\hsword{Score:}"& \verb"\vsword{Score}"\\ + \verb"\htword{Total}"& \verb"\vtword{Total:}"\\[\medskipamount] +% + \verb"\bhqword{Question:}"& \verb"\bvqword{Question}"\\ + \verb"\bhpgword{Page:}"& \verb"\bvpgword{Page}"\\ + \verb"\bhpword{Bonus Points:}"& \verb"\bvpword{Bonus Points}"\\ + \verb"\bhsword{Score:}"& \verb"\bvsword{Score}"\\ + \verb"\bhtword{Total}"& \verb"\bvtword{Total:}"\\[\medskipamount] +% + \verb"\chqword{Question:}"& \verb"\cvqword{Question}"\\ + \verb"\chpgword{Page:}"& \verb"\cvpgword{Page}"\\ + \verb"\chpword{Points:}"& \verb"\cvpword{Points}"\\ + \verb"\chbpword{Bonus Points:}"& \verb"\cvbpword{Bonus Points}"\\ + \verb"\chsword{Score:}"& \verb"\cvsword{Score}"\\ + \verb"\chtword{Total}"& \verb"\cvtword{Total:}"\\[\medskipamount] + \verb"\cellwidth{2em}"\\ + \verb"\gradetablestretch{1.5}"\\ + \verb"\setlength{\doublerulesep}{2.0pt}" + \end{tabular} +\end{center} + +\bigskip +For example, if you type +\begin{verbatim} +\begin{center} + \hqword{Aufgabe Nr.:} + \hpword{Punktzahl:} + \htword{\textbf{Summe}} + \hsword{Davon erreicht:} + \cellwidth{2.2em} + \gradetable[h][questions] +\end{center} +\end{verbatim} +then you'll get +\begin{center} + \cwidth=2.2em + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|l|c|c|c|c|c|c|c|c|c|} + \hline + Aufgabe Nr.:& 1& 2& 3& 4& 5& 6& 7& 8& \textbf{Summe}\\ + \hline + Punktzahl:& + 15& + 15& + 15& + 15& + 15& + 15& + 15& + 15& + 120\\ + \hline + Davon erreicht:& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \hbox to \cwidth{\hfill}& + \\ + \hline + \end{tabular} +\end{center} + +\index{point table!customization|)} +\index{grade table!customization|)} +\index{customization!point table|)} +\index{customization!grading table|)} + + +\indcstop{pointtable} +\indcstop{gradetable} +\index{point table|)} +\index{grading table|)} + + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +\section{Changing the page margins} +\label{sec:pagesize} +\index{margins|(} +\index{customization!margins|(} + +The exam document class arranges things so that you get one inch +margins at the top, bottom, and sides no matter what size paper you +use, as long as you use the corresponding document class option +(\verb"a4paper", \verb"a5paper", \verb"b5paper", \verb"letterpaper", +\verb"legalpaper", \verb"executivepaper", or \verb"landscape"). You +can change the sizes of these margins by using the commands that +change the size of the printed area. + +To change the width of the printed area, you would use the +\verb"\extrawidth"\indc{extrawidth} command. The \verb"\extrawidth" +command takes one argument, and enlarges the width of the printed area +by the amount of the argument. It keeps the printed area centered as +it changes its width. If the argument is negative, then the width of +the printed area is decreased. + +For example, to enlarge the left and right margins by one half inch +each, you would use the command +\begin{center} + \verb"\extrawidth{-1in}" +\end{center} +since the printed region must shrink by one inch to allow an +additional one half inch on both sides. To decrease the left and +right margins to three quarters of an inch each, you would use the +command +\begin{center} + \verb"\extrawidth{.5in}" +\end{center} +since the printed region must grow by one half inch to decrease both +margins by one quarter of an inch. + +To change the height of the printed area, you must choose whether the +top or the bottom of the printed area (or possibly both) should move. +The commands for this are principally intended to allow additional +room for large headers and footers, and so they are called +\verb"\extraheadheight"\indc{extraheadheight} and +\verb"\extrafootheight"\indc{extrafootheight}. For a full description +of these commands, see section~\ref{sec:extra-room}. + +To move the top of the printed region (and any header that's present) +downwards, you use the command \verb"\extraheadheight". This command +takes one argument, and moves the top of the text and the header down +by this amount (keeping the distance between the header and the text +constant). Thus, to increase the top margin by three quarters of an +inch, you would give the command +\begin{center} + \verb"\extraheadheight{.75in}" +\end{center} +To decrease the top margin by one half inch, you would give the +command +\begin{center} + \verb"\extraheadheight{-.5in}" +\end{center} +The +% +\verb"\extraheadheight"\indcsub{extraheadheight}{optional argument}% +\index{head height!first page different} command takes an optional +argument to provide a top margin on the first page that's different +from that on all other pages. For an explanation of this, see +section~\ref{sec:extra-room}. + +To move the bottom of the printed region (and any footer that's +present) upwards, you use the command +\verb"\extrafootheight"\indc{extrafootheight}. This command takes one +argument, and moves the bottom of the text and the footer up by this +amount (keeping the distance between the footer and the text +constant). Thus, to increase the bottom margin by three quarters of +an inch, you would give the command +\begin{center} + \verb"\extrafootheight{.75in}" +\end{center} +To decrease the bottom margin by one half inch, you would give the +command +\begin{center} + \verb"\extrafootheight{-.5in}" +\end{center} +The +% +\verb"\extrafootheight"\indcsub{extrafootheight}{optional argument}% +\index{foot height!first page different} command takes an optional +argument to provide a bottom margin on the first page that's different +from that on all other pages. For an explanation of this, see +section~\ref{sec:extra-room}. + +\index{customization!margins|)} +\index{margins|)} + + +%-------------------------------------------------------------------- +%--------------------------------------------------------------------- +\section{Headers and footers} +\label{sec:headfoot} +\index{header|(} +\index{footer|(} + +The following sections explain all of the commands that deal with +headers and footers. There are a number of things to explain here, +and so you may find it easier to skip these sections and instead look +at the examples in sections~\ref{sec:beginexamples} +through~\ref{sec:endexamples} (on pages~\pageref{sec:beginexamples} +through~\pageref{sec:endexamples}). You can then refer back to these +sections for the full story on whatever isn't clear from the examples. +All of the commands described in these sections should be given in the +preamble, i.e., after the \verb"\documentclass" command and before the +\verb"\begin{document}" command. + +It's also important to remember that if you use a \verb"coverpages" +environment (described in section~\ref{sec:coverpages}), then the +commands described here affect only the pages in the main section of +the exam, and not the pages of the \verb"coverpages" environment. +There are commands for headers and footers in the cover pages that are +analogous to the commands described in this section; for that, see +section~\ref{sec:Coverhdft}. + +%--------------------------------------------------------------------- +\subsection{Page styles: Headers and/or footers} +\label{sec:pagestyle} +\indcstart{pagestyle} +\index{header!on or off} +\index{footer!on or off} + +It's the \verb"\pagestyle" command that determines whether the exam +will have headers, footers, both, or neither. The contents of the +header and footer are specified using the commands described in +sections~\ref{sec:header} through~\ref{sec:rules}, but it's the +\verb"\pagestyle" command that determines whether the header and +footer that you construct will actually be placed onto the page. The +\verb"\pagestyle" command should be given in the preamble, i.e., after +the \verb"\documentclass" command and before the +\verb"\begin{document}" command. + +To have both a header and a footer, give the +command\indt{headandfoot}\indc{pagestyle\{headandfoot\}} +\begin{center} + \verb"\pagestyle{headandfoot}" +\end{center} +If you want every page to have a header but no footer, give the +command\indt{head}\indc{pagestyle\{head\}} +\begin{center} + \verb"\pagestyle{head}" +\end{center} +To give every page a footer but no header, give the +command\indt{foot}\indc{pagestyle\{foot\}} +\begin{center} + \verb"\pagestyle{foot}" +\end{center} +Finally, to omit both the header and the footer from the page, give +the command\indt{empty}\indc{pagestyle\{empty\}} +\begin{center} + \verb"\pagestyle{empty}" +\end{center} + + +As is true for all \LaTeX{} document classes, you can change the page +style used on a single page by giving the command\indc{thispagestyle} +\begin{center} + \verb"\thispagestyle{somestyle}" +\end{center} +somewhere on that page (where \verb"somestyle" is the style that you +want to use on that page). This is most often needed if you use the +\verb"\maketitle"\indc{maketitle}\indcsub{maketitle}{overriding} +command, since that command inserts a \verb"\thispagestyle{plain}" +immediately following the title. If you use the \verb"\maketitle" +command and you want the entire document to use +\verb"\pagestyle{headandfoot}", then you'll need to put the command +\verb"\thispagestyle{headandfoot}"\indc{thispagestyle\{headandfoot\}} +immediately after the \verb"\maketitle" command to override the +\verb"\thispagestyle{plain}" that is inserted by \verb"\maketitle". + +The default page style is +\verb"headandfoot"\indcsub{pagestyle}{default}. That is, if you don't +give any \verb"\pagestyle" commands, then the header and footer will +appear on every page. The default header is empty, and the default +footer consists of ``Page $n$'' centered in the footer (where $n$ is +the page number). + +\indcstop{pagestyle} + +%--------------------------------------------------------------------- +\subsection{The three parts of the header} +\label{sec:header} +\index{header!three parts|(} + +The header is specified in three parts: +\begin{itemize} +\item One part to be left justified. +\item One part to be centered. +\item One part to be right justified. +\end{itemize} +There are two different ways in which you can specify the three parts +of the header. The first uses the single command \verb"\header" to +specify all three parts of the header, or the commands +\verb"\firstpageheader" and \verb"\runningheader" to specify a +different header for the first page (see +section~\ref{sec:runningheader}). The second uses the commands +\verb"\lhead", \verb"\chead", and \verb"\rhead", each of which can +have an optional argument to specify a different header for the first +page (see section~\ref{sec:lhead}). All of these commands should be +given in the preamble, i.e., after the \verb"\documentclass" command +and before the \verb"\begin{document}" command. + +%-------------------------------------------------------------------- +\subsubsection{Using \texttt{\bs header}, \texttt{\bs firstpageheader} and + \texttt{\bs runningheader}} +\label{sec:runningheader} +\indcstart{header} +\indcstart{firstpageheader} +\indcstart{runningheader} + +The command \verb"\header{Text 1}{Text 2}{Text 3}" puts ``Text~1'' +into the left justified header, ``Text~2'' into the centered header, +and ``Text~3'' into the right justified header on every page. If you +want the header on the first page to be different from that on the +other pages, then you should use the commands \verb"\firstpageheader" +and +% +\verb"\runningheader"\index{header!different on first page}, which +also take three arguments and affect either the first page or all +pages except the first. + + +For example, to put the header +\samplehead{Math 115}{Second Exam}{July 4, 1776}{} +on every page of the exam, you would give the command +\begin{verbatim} +\header{Math 115}{Second Exam}{July 4, 1776} +\end{verbatim} + +If you want to use a header on the first page that's different from +the header used on all other pages, you would use the commands +\verb"\firstpageheader" and \verb"\runningheader" instead of +\verb"\header". For example, if you want the above header for the +first page, but on all pages after the first you want to have the +header \samplehead{Math 115}{Second Exam (Continued)}{July 4, 1776}{} +then you would give the commands +\begin{verbatim} +\firstpageheader{Math 115}{Second Exam}{July 4, 1776} +\runningheader{Math 115}{Second Exam (Continued)}{July 4, 1776} +\end{verbatim} + +You can leave one or more of the three parts empty. To have the +header +\samplehead{Math 115}{Second Exam}{July 4, 1776}{} +on the first page, with the header +\samplehead{Math 115}{}{Second Exam (Continued)}{} +on all other pages, you would give the commands +\begin{verbatim} +\firstpageheader{Math 115}{Second Exam}{July 4, 1776} +\runningheader{Math 115}{}{Second Exam (Continued)} +\end{verbatim} + +Any of the three parts of the header can have multiple lines. To +specify where the line breaks should go, you just type \verb"\\". +Thus, to have the header +\samplehead{\bfseries\large Math 115\\Professor Hilbert}{} + {\bfseries\large First Exam\\July 4, 1776}{} +appear on every page, you would give the command +\begin{verbatim} +\header{\bfseries\large Math 115\\Professor Hilbert} + {} + {\bfseries\large First Exam\\July 4, 1776} +\end{verbatim} + +\indcstop{header} +\indcstop{firstpageheader} +\indcstop{runningheader} + +%-------------------------------------------------------------------- +\subsubsection{Using \texttt{\bs lhead}, \texttt{\bs chead} and + \texttt{\bs rhead}} +\label{sec:lhead} +\indcstart{lhead} +\indcstart{chead} +\indcstart{rhead} + + +The command \verb"\lhead{Text}" puts ``Text'' into the left justified +part of the header on every page. The command +\index{header!different on first page}% +\indcsub{lhead}{optional argument}% +\indcsub{chead}{optional argument}% +\indcsub{rhead}{optional argument}% +\indcsub{lhead}{different on first page}% +\indcsub{chead}{different on first page}% +\indcsub{rhead}{different on first page}% +\verb"\lhead[Text 1]{Text 2}" puts ``Text~1'' into the left justified +header on the first page and ``Text~2'' into the left justified header +on all other pages. The commands \verb"\chead" and \verb"\rhead" have +similar effects on the centered and right justified parts of the +header. + + +For example, to put the header +\samplehead{Math 115}{Second Exam}{July 4, 1776}{} +on every page of the exam, you would give the commands +\begin{verbatim} +\lhead{Math 115} +\chead{Second Exam} +\rhead{July 4, 1776} +\end{verbatim} + +If you want any of the three parts to have a special version to be +used only on the first page, then you just include that special +version as an optional argument (enclosed in square brackets) to the +command. For example, if you want the above header for the first +page, but on all pages after the first you want to have the header +\samplehead{Math 115}{Second Exam (Continued)}{July 4, 1776}{} +then you would give the commands +\begin{verbatim} +\lhead{Math 115} +\chead[Second Exam]{Second Exam (Continued)} +\rhead{July 4, 1776} +\end{verbatim} + +You can leave one or more of the three parts empty. To have the +header +\samplehead{Math 115}{Second Exam}{July 4, 1776}{} +on the first page, with the header +\samplehead{Math 115}{}{Second Exam (Continued)}{} +on all other pages, you would give the commands +\begin{verbatim} +\lhead{Math 115} +\chead[Second Exam]{} +\rhead[July 4, 1776]{Second Exam Continued)} +\end{verbatim} + +Any of the three parts of the header can have multiple lines. To +specify where the line breaks should go, you just type \verb"\\". +Thus, to have the +% +header\index{header!multiple lines} +\samplehead{\bfseries\large Math 115\\Professor Hilbert}{} + {\bfseries\large First Exam\\July 4, 1776}{} +appear on every page, you would give the commands +\begin{verbatim} +\lhead{\bfseries\large Math 115\\Professor Hilbert} +\chead{} +\rhead{\bfseries\large First Exam\\July 4, 1776} +\end{verbatim} + +\indcstop{lhead} +\indcstop{chead} +\indcstop{rhead} + +\index{header!three parts|)} + + +%--------------------------------------------------------------------- +\subsubsection*{Leaving extra room for multiple line headers} + +See section~\ref{sec:extra-room} for a description of the +% +\verb"\extraheadheight"\index{header!multiple lines} command. + +%--------------------------------------------------------------------- +\subsection{The three parts of the footer} +\label{sec:footer} +\index{footer!three parts|(} + +The footer is composed of three parts, the whole setup being similar +to that for the header (see section~\ref{sec:header}). There are two +different ways in which you can specify the three parts of the footer. +The first uses the single command \verb"\footer" to specify all three +parts of the footer, or the commands \verb"\firstpagefooter" and +\verb"\runningfooter" to specify a different footer for the first page +(see section~\ref{sec:runningfooter}). The second uses the commands +\verb"\lfoot", \verb"\cfoot", and \verb"\rfoot", each of which can +have an optional argument to specify a different footer for the first +page (see section~\ref{sec:lfoot}). All of these commands should be +given in the preamble, i.e., after the \verb"\documentclass" command +and before the \verb"\begin{document}" command. + +%-------------------------------------------------------------------- +\subsubsection{Using \texttt{\bs footer}, \texttt{\bs firstpagefooter} + and \texttt{\bs runningfooter}} +\label{sec:runningfooter} +\indcstart{footer} +\indcstart{firstpagefooter} +\indcstart{runningfooter} + +The command \verb"\footer{Text 1}{Text 2}{Text 3}" puts ``Text~1'' +into the left justified footer, ``Text~2'' into the centered footer +and ``Text~3'' into the right justified footer on every page. If you +want the footer on the first page to be different from that on the +other pages, then you should use the commands \verb"\firstpagefooter" +and \verb"\runningfooter", which also take three arguments and affect +either the first page or all pages except the first. + +For example, to have an empty footer on the first page and the footer +\samplefoot{}{}{Page 3 of 5}{} +on all pages after the first, you would give the commands +\begin{verbatim} +\firstpagefooter{}{}{} +\runningfooter{}{Page \thepage\ of \numpages}{} +\end{verbatim} +(For an explanation of the \verb"\numpages" command, see +section~\ref{sec:numpages}.) + +\indcstop{footer} +\indcstop{firstpagefooter} +\indcstop{runningfooter} + +%-------------------------------------------------------------------- +\subsubsection{Using \texttt{\bs lfoot}, \texttt{\bs cfoot}, and + \texttt{\bs rfoot}} +\label{sec:lfoot} +\indcstart{lfoot} +\indcstart{cfoot} +\indcstart{rfoot} + + +The command \verb"\lfoot{Text}" puts ``Text'' into the left justified +part of the footer on every page. The command +\verb"\lfoot[Text 1]{Text 2}" puts ``Text~1'' into the left justified +footer on the first page and ``Text~2'' into the left justified footer +on all other pages. The commands \verb"\cfoot" and \verb"\rfoot" have +similar effects on the centered and right justified parts of the +footer. + +For example, to have an empty footer on the first page and the footer +\samplefoot{}{}{Page 3 of 5}{} +on all pages after the first, you would give the commands +\begin{verbatim} +\lfoot{} +\cfoot{} +\rfoot[]{Page \thepage\ of \numpages} +\end{verbatim} +(For an explanation of the \verb"\numpages" command, see +section~\ref{sec:numpages}.) + +\indcstop{lfoot} +\indcstop{cfoot} +\indcstop{rfoot} + +\index{footer!three parts|)} + +%--------------------------------------------------------------------- +\subsubsection*{Leaving extra room for multiple line footers} + +See section~\ref{sec:extra-room} for a description of the +\verb"\extrafootheight" command. + +%--------------------------------------------------------------------- +\subsection{Leaving extra room for multiple line headers and footers} +\label{sec:extra-room} + +\subsubsection*{Headers} +\index{header!with multiple lines|(} + +If you specify more than one or two lines for any part of the header, +then you may want to move the header down slightly so that it doesn't +run off of the top of the paper. The command for this is +\verb"\extraheadheight"\indc{extraheadheight}. You can also use the +\verb"\extraheadheight" command to adjust the size of the text area. +The \verb"\extraheadheight" command never changes the distance between +the header and the text. + +For example, to move the header and the text an additional half inch +down from the top of the page, you would give the command +\begin{center} + \verb"\extraheadheight{.5in}" +\end{center} +You can also specify a negative distance to \verb"\extraheadheight" to +move the header up closer to the top of the paper. For example, the +command +\begin{center} + \verb"\extraheadheight{-.25in}" +\end{center} +moves the header one quarter inch closer to the top of the paper. + +If you want to have a different value for \verb"\extraheadheight" on +the first page from that on the pages after the first, then use the +same syntax as in the \verb"\lhead", \verb"\chead", and \verb"\rhead" +commands (see section~\ref{sec:lhead}): Include an optional argument +giving the extra head height for the first page, and the required +argument will apply only to those pages after the first. For example, +the +% +command\indcsub{extraheadheight}{different on first page} +\begin{center} + \verb"\extraheadheight[.5in]{.25in}" +\end{center} +gives a half inch of extra head height on the first page and a +quarter inch of extra head height on all pages after the first. + +If you give an \verb"\extraheadheight"\indc{extraheadheight} command, +it should be in the preamble, i.e., after the \verb"\documentclass" +command and before the \verb"\begin{document}" command. The + \verb"\extraheadheight" command can also be used to change the size + of the text region (see section~\ref{sec:pagesize}). + +\index{header!with multiple lines|)} + +%-------------------------------------------------------------------- +\subsubsection*{Footers} +\index{footer!with multiple lines|(} + + +To leave extra room for multiple line footers, you use the command +\verb"\extrafootheight". To move the footer one half inch higher up +on the paper, you would give the command\indc{extrafootheight} +\begin{center} + \verb"\extrafootheight{.5in}" +\end{center} +If you wanted to move the footer an eighth of an inch lower down on +the paper, you would give the command +\begin{center} + \verb"\extrafootheight{-.125in}" +\end{center} + +If you want to have a different value for \verb"\extrafootheight" on +the first page from that on the pages after the first, then use the +same syntax as in the \verb"\lfoot", \verb"\cfoot", and \verb"\rfoot" +commands (see section~\ref{sec:lfoot}): Include an optional argument +giving the extra foot height for the first page, and the required +argument will apply only to those pages after the first. For example, +the +% +command\indcsub{extrafootheight}{different on first page} +\begin{center} + \verb"\extrafootheight[.5in]{.25in}" +\end{center} +gives a half inch of extra foot height on the first page and a +quarter inch of extra foot height on all pages after the first. + +If you give an \verb"\extrafootheight"\indc{extrafootheight} command, +it should be in the preamble, i.e., after the \verb"\documentclass" +command and before the \verb"\begin{document}" command. The + \verb"\extrafootheight" command can also be used to change the size + of the text region (see section~\ref{sec:pagesize}). + +\index{footer!with multiple lines|)} + + +%--------------------------------------------------------------------- +\subsection{Horizontal rules} +\label{sec:rules} +\index{rule!in header or footer|(} +\index{header!rule|(} +\index{footer!rule|(} + +The \verb"exam" document class make it easy to put a horizontal rule +under the header and one above the footer. It is also easy to do +this for the pages after the first page without affecting the first +page. + +\begin{itemize} +\item The command \verb"\runningheadrule"\indc{runningheadrule} puts a + horizontal rule below the header on all pages after the first. +\item The command \verb"\firstpageheadrule"\indc{firstpageheadrule} + puts a rule under the header of only the first page. +\item The command \verb"\headrule"\indc{headrule} is equivalent to the + two commands \verb"\firstpageheadrule" and \verb"\runningheadrule". +\item The command \verb"\runningfootrule"\indc{runningfootrule} puts a + horizontal rule above the footer on all pages after the first. +\item The command \verb"\firstpagefootrule"\indc{firstpagefootrule} + puts a rule above the footer of only the first page. +\item The command \verb"\footrule"\indc{footrule} is equivalent to the + two commands \verb"\firstpagefootrule" and \verb"\runningfootrule". +\end{itemize} +For example, to have the header +\samplehead{Math 115}{First Exam}{July 4, 1776}{} +on the first page, with the header +\samplehead{Math 115}{First Exam}{July 4, 1776}{\hrule} +on all pages after the first, give either the commands +\begin{verbatim} +\runningheadrule +\header{Math 115}{First Exam}{July 4, 1776} +\end{verbatim} +or the commands +\begin{verbatim} +\runningheadrule +\lhead{Math 115} +\chead{First Exam} +\rhead{July 4, 1776} +\end{verbatim} +For a description of the command \verb"\header" see +section~\ref{sec:runningheader}; for a description of the commands +\verb"\lhead", \verb"\chead", and \verb"\rhead", see +section~\ref{sec:lhead}. + +\bigskip + +To have no footer on the first page, and the footer +\samplefoot{\hrule}{}{Page 3 of 5}{} +on all pages after the first, give the commands +\begin{verbatim} +\runningfootrule +\lfoot{} +\cfoot[]{Page \thepage\ of \numpages} +\rfoot{} +\end{verbatim} +(For an explanation of the \verb"\numpages" command, see +section~\ref{sec:numpages}.) + +\index{rule!in header or footer|)} +\index{header!rule|)} +\index{footer!rule|)} + + +%--------------------------------------------------------------------- +\subsection{Listing the number of pages in the exam} +\label{sec:numpages} + +The \verb"exam" document class defines the command +\verb"\numpages"\indc{numpages} so that it will expand to the number +of pages in the exam. Thus, to have the footer +% +\samplefoot{}{}{Page \thepage\ of \numpages}{} +% +you should either give the command +\begin{verbatim} +\footer{}{Page \thepage\ of \numpages}{} +\end{verbatim} +or the commands +\begin{verbatim} +\lfoot{} +\cfoot{Page \thepage\ of \numpages} +\rfoot{} +\end{verbatim} +For a description of the command \verb"\footer" see +section~\ref{sec:runningfooter}; for a description of the commands +\verb"\lfoot", \verb"\cfoot", and \verb"\rfoot", see +section~\ref{sec:lfoot}. + +Note that if your document has a \texttt{coverpages} environment (see +section~\ref{sec:coverpages}), then those pages will not be counted in +% +\verb"\numpages"\indcsub{numpages}{doesn't count cover pages}; the +\texttt{exam} document class defines the command +\verb"\numcoverpages"\indc{numcoverpages} so that it will expand to +the number of cover pages in the exam. If there is no +\texttt{coverpages}\indt{coverpages}\index{environment!coverpages} +environment, then \verb"\numcoverpages" expands to 0. The +\texttt{exam} class also defines the command +\verb"\totalnumpages"\indc{totalnumpages}, which expands to the sum of +\verb"\numpages" and \verb"\numcoverpages". Note that if there are +pages preceding a \texttt{coverpages} environment, then those pages +will not be counted by \verb"\totalnumpages". + +As with all other cross referencing commands in \LaTeX, you'll have to +run the file through \LaTeX{} \emph{twice} to be sure that +\verb"\numpages", \verb"\numcoverpages", and \verb"\totalnumpages" are +correct. + + + +%--------------------------------------------------------------------- +\subsection{Treating the last page differently} +\label{sec:lastpage} +\index{last page|(} + +If you want to vary the text that appears in the header or footer on +the last page of the exam, you should use the command +\verb"\iflastpage"\indc{iflastpage}. The command +\begin{center} + \verb"\iflastpage{Text 1}{Text 2}" +\end{center} +expands to `Text~1' on the last page and to `Text~2' on all pages +before the last. Thus, to have the footer +% +\samplefoot{}{}{Please go on to the next page\ldots}{} +% +on all pages before the last page and the footer +% +\samplefoot{}{}{End of exam}{} +% +on the last page, you should give the command +\begin{verbatim} +\footer{} + {\iflastpage{End of exam}{Please go on to the next page\ldots}} + {} +\end{verbatim} +or the commands +\begin{verbatim} +\lfoot{} +\cfoot{\iflastpage{End of exam}{Please go on to the next page\ldots}} +\rfoot{} +\end{verbatim} +For a description of the command \verb"\footer" see +section~\ref{sec:runningfooter}; for a description of the commands +\verb"\lfoot", \verb"\cfoot", and \verb"\rfoot", see +section~\ref{sec:lfoot}. + +As with all other cross referencing commands in \LaTeX, you'll have to +run the file through \LaTeX{} \emph{twice} to be sure that +\verb"\iflastpage"\indc{iflastpage} correctly detects the last page. + +\index{last page|)} + +%-------------------------------------------------------------------- +\subsection{Treating odd and even numbered pages differently} +\index{odd pages!different from even pages|(} +\index{even pages!different from odd pages|(} + +If you'd like odd and even numbered pages to be treated differently +(perhaps because you'll be printing onto both sides of the paper), you +should use the \verb"\oddeven"\indc{oddeven} command. The command +\begin{center} + \verb"\oddeven{Text 1}{Text 2}" +\end{center} +expands to `Text~1' on odd numbered pages and to `Text~2' on even +numbered pages. + +For example, to have the page number printed in the right head on odd +numbered pages and in the left head on even numbered pages, you should +give the command\indc{oddeven} +\begin{verbatim} +\header{\oddeven{}{\thepage}}% + {}% + {\oddeven{\thepage}{}} +\end{verbatim} +or the commands +\begin{center} +\begin{verbatim} +\lhead{\oddeven{}{\thepage}} +\rhead{\oddeven{\thepage}{}} +\chead{} +\end{verbatim} +\end{center} +If you want the footer of the even numbered pages to be empty and the +footer of the odd numbered pages to contain the centered message +``Please continue\dots'', except that the last page of the exam should +have an empty footer whether its page number is even or odd, then you +should give the command\indc{iflastpage} +\begin{verbatim} +\footer{} + {\oddeven{\iflastpage{}{Please continue\ldots}}{}} + {} +\end{verbatim} +or the commands +\begin{center} +\begin{verbatim} +\lfoot{} +\rfoot{} +\cfoot{\oddeven{\iflastpage{}{Please continue\dots}}{}} +\end{verbatim} +\end{center} +(see section~\ref{sec:lastpage} for an explanation of +\verb"\iflastpage"). + +The \verb"\oddeven"\indcsub{oddeven}{only in headers and footers} +command can be used reliably only in headers and footers. This is +because \LaTeX{} generally processes more text than can fit on the +current page before chooses a page break it outputs a page. When the +\verb"\oddeven" command is encountered it will act as though it will +appear on the current page whether it will actually be printed on that +page or on the following page; in headers and footers this never +creates a problem. + +\index{odd pages!different from even pages|)} +\index{even pages!different from odd pages|)} + +%-------------------------------------------------------------------- +\subsection{Questions that span multiple pages} +\label{sec:QuesSpan} +\index{questions!that span multiple pages|(} + +The exam document class provides the commands +\begin{itemize} +\item \verb"\ifcontinuation"\indc{ifcontinuation} and + \verb"\ContinuedQuestion"\indc{ContinuedQuestion} to enable headers + and footers that announce whether the current page is continuing a + question begun on an earlier page and, if so, the number of that + question (see section~\ref{sec:ifcontin}), and +\item \verb"\ifincomplete"\indc{ifincomplete} and + \verb"\IncompleteQuestion"\indc{IncompleteQuestion} to enable + headers and footers that announce whether the question at the bottom + of the current page continues onto the next page and, if so, the + number of that question (see section~\ref{sec:ifincomp}). +\end{itemize} +\emph{These commands are only guaranteed to work reliably in headers + and footers.}% +\indcsub{ifcontinuation}{reliable only in headers and footers}% +\indcsub{ContinuedQuestion}{reliable only in headers and footers}% +\indcsub{ifincomplete}{reliable only in headers and footers}% +\indcsub{IncompleteQuestion}{reliable only in headers and footers} If +you use any of them elsewhere, they may be fooled by \LaTeX's practice +of typesetting a bit too much material to fit on a page before it +chooses a page break and ships out the page. They also assume that +there is only one \verb"questions" environment in the entire exam. + +%-------------------------------------------------------------------- +\subsubsection{Questions continuing from the previous page} +\label{sec:ifcontin} + +Headers and footers can announce whether the current page continues a +question begun on an earlier page. The command\indc{ifcontinuation} +\begin{center} + \verb"\ifcontinuation{Text 1}{Text 2}" +\end{center} +expands to `Text 1' if the current page begins with a continuation of +a question begun on an earlier page, and to `Text 2' otherwise. If +the current page does continue a question begun on an earlier page, +then the command\indc{ContinuedQuestion} +\begin{center} + \verb"\ContinuedQuestion" +\end{center} +expands to the number of that question. + +For example, to have the header +\samplehead{}{First Exam}{Page 4}{} +% +on all pages that begin a new question and the header +\samplehead{Question 6 continues\ldots}{First Exam}{Page 4}{} +% +on all pages that continue a question begun on a previous page, you +would give the commands\indc{ContinuedQuestion}\indc{ifcontinuation} +\begin{verbatim} +\lhead{\ifcontinuation{Question \ContinuedQuestion\ continues\ldots}{}} +\chead{First Exam} +\rhead{Page \thepage} +\end{verbatim} +(See section~\ref{sec:lhead} for an explanation of \verb"\lhead", +\verb"\chead" and \verb"\rhead".) + + + + + +The \verb"\ifcontinuation" command figures out which text to use by +checking whether there is a \verb"\question" command appearing on the +page before any of the commands \verb"\part", \verb"\subpart", +\verb"\subsubpart", \verb"\choice", or \verb"\CorrectChoice", and this +works well for most pages. However, the \verb"\ifcontinuation" +command can make mistakes on pages on which none of those commands +appear. The default is to assume that a page with none of those +commands continues a question begun on an earlier page, but there are +two commands you can use to tell the \verb"\ifcontinuation" command +that it should \emph{not} assume that: +\begin{itemize} +\item the \verb"\nomorequestions"\indc{nomorequestions} command can be + used to mark the point at which the last question ends. This can be + useful if you want to include supplementary material (e.g., tables + or figures) at the end of the exam but you don't want that material + to be described as continuing the last question. The + \verb"\nomorequestions" command also tells the \verb"\ifincomplete" + command (see section~\ref{sec:ifincomp}) that all questions are now + complete. +\item The \verb"\noquestionsonthispage" command tells the + \verb"\ifcontinuation" command (and the \verb"\ifincomplete" + command; see section~\ref{sec:ifincomp}) that this page does not + continue a question begun on an earlier page. This is similar to + the job done by the \verb"\nomorequestions" command for the pages + that follow the end of all of the questions. 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 + \verb"\nomorequestions" instead. +\end{itemize} + +Thus, in more detail, the command +\verb"\ifcontinuation{Text 1}{Text 2}" +\begin{itemize} +\item expands to `Text 2' if + \begin{itemize} + \item a \verb"\question" appears on this page before any + \verb"\part", \verb"\subpart", \verb"\subsubpart", \verb"\choice", + or \verb"\CorrectChoice", or + \item the command \verb"\noquestionsonthispage" has been given on + this page, or + \item the current page is before the page containing question number + 1, or + \item the current page is later than a page with the + \verb"\nomorequestions" command, + \end{itemize} +\item and otherwise it expands to `Text 1'. +\end{itemize} + + +%-------------------------------------------------------------------- +\subsubsection{Questions that continue onto a later page} +\label{sec:ifincomp} +\indcstart{ifincomplete} + +Headers and footers can announce whether a question on the current +page continues onto a later page. The command\indc{ifincomplete} +\begin{center} + \verb"\ifincomplete{Text 1}{Text 2}" +\end{center} +expands to `Text 1' if the last question begun on or before the +current page continues onto a page after this one, and to `Text~2' +otherwise. If the last question begun on or before the current page +does continue onto a later page, then the +command\indc{IncompleteQuestion} +\begin{center} + \verb"\IncompleteQuestion" +\end{center} +expands to the number of that question. + +For example, to have the footer +\samplefoot{\hrule}{}{Question 3 continues\ldots}{} +% +on all pages that end with a question that will be continued onto the +next page, the footer +\samplefoot{\hrule}{}{End of Exam}{} +% +on the last page, and the footer +\samplefoot{\hrule}{}{Exam continues\ldots}{} +% +on all other pages, you would give the +commands\indc{ifincomplete}\indc{IncompleteQuestion}\indc{iflastpage} +\begin{verbatim} +\footrule +\lfoot{} +\newcommand{\continues}{\ifincomplete + {Question \IncompleteQuestion\ continues\ldots} + {Exam continues\ldots}} +\cfoot{\iflastpage{End of Exam}{\continues}} +\rfoot{} +\end{verbatim} +(See section~\ref{sec:lfoot} for an explanation of \verb"\lfoot", +\verb"\cfoot" and \verb"\rfoot", and section~\ref{sec:lastpage} for an +explanation of \verb"\iflastpage"). + +There are two situations in which you may have to give an additional +command for the \verb"\ifincomplete" command to correctly decide if +the current question is incomplete: +\begin{enumerate} +\item The \verb"\ifincomplete" command expands to `Text~2' if there is + a \verb"\part", \verb"\subpart", \verb"\subsubpart", \verb"\choice", + or \verb"\CorrectChoice" command belonging to this question on the + following page. For those situations in which the current question + flows onto the next page, but there is no \verb"\part", + \verb"\subpart", \verb"\subsubpart", \verb"\choice", or + \verb"\CorrectChoice" belonging to this question on that page, you + should give the command\indc{addquestionobject} + \begin{center} + \verb"\addquestionobject" + \end{center} + at the end of the text of the question to inform the + \verb"\ifincomplete" command that some portion of the question + appears on that following page. + +\item If there are pages on which none of those commands appear, the + default is to assume that that page continues a question begun on an + earlier page. There are two commands that you can use to tell the + \verb"\ifincomplete" command that it should \emph{not} assume that: + \begin{itemize} + \item the \verb"\nomorequestions"\indc{nomorequestions} command can + be used to mark the point at which the last question ends. This + can be useful if you want to include supplementary material (e.g., + tables or figures) at the end of the exam but you don't want the + last question on the exam to be described as incomplete. The + \verb"\nomorequestions" command also tells the + \verb"\ifcontinuation" command (see section~\ref{sec:ifcontin}) + that all questions are now complete. + \item The \verb"\noquestionsonthispage"\indc{noquestionsonthispage} + command tells the \verb"\ifincomplete" command (and the + \verb"\ifcontinuation" command; see section~\ref{sec:ifcontin}) + that this page does not contain any incomplete questions, and does + not continue a question begun on an earlier page. This is similar + to the job done by the \verb"\nomorequestions" command for the + pages that follow the end of all of the questions. 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 + \verb"\nomorequestions" instead. + \end{itemize} +\end{enumerate} +If you give the command +\verb"\noquestionsonthispage"\indc{noquestionsonthispage} on a page, +then +\begin{itemize} +\item an \verb"\ifcontinuation"\indc{ifcontinuation} command on that + page will expand to its second argument, +\item an \verb"\ifincomplete" on that page will expand to its second + argument, and +\item an \verb"\ifincomplete" command on an earlier page will not + assume that a question from that earlier page continues onto this + page. +\end{itemize} +The way that this command affects the \verb"\ifincomplete" command on +earlier pages is as follows: If there is a page with no +\verb"\question", \verb"\part", \verb"\subpart", \verb"\subsubparts", +\verb"\choice", \verb"\CorrectChoice", or +\verb"\addquestionobject"\indc{addquestionobject} commands, then the +last page before that with a \verb"\question" (or \verb"\part", etc.) +would normally be deemed to have an incomplete question; if, however, +the page with no \verb"\question" (or \verb"\part", etc.) (along with +all adjacent pages with no \verb"\question" or \verb"\part" etc.) has +a \verb"\noquestionsonthispage" command, then that last page with a +\verb"\question" (or \verb"\part", etc.) will not be deemed +incomplete. + + +\indcstop{ifincomplete} + +\index{questions!that span multiple pages|)} + +%-------------------------------------------------------------------- +\subsection{Examples} +\indcstart{lhead} +\indcstart{chead} +\indcstart{rhead} +\indcstart{lfoot} +\indcstart{cfoot} +\indcstart{rfoot} + +\begin{example} + \label{sec:beginexamples} + To have the header + \samplehead{Math 115}{First Exam}{July 4, 1776}{} + on the first page, the header + \samplehead{Math 115}{First Exam, Page 2 of 5}{July 4, 1776}{\hrule} + on all pages after the first, and no footer on any page, give the + commands\indc{firstpageheader}\indc{runningheader}% + \indc{runningheadrule} +\begin{verbatim} +\pagestyle{head} +\runningheadrule +\firstpageheader{Math 115}{First Exam}{July 4, 1776} +\runningheader{Math 115} + {First Exam, Page \thepage\ of \numpages} + {July 4, 1776} +\end{verbatim} + Alternatively, you could give the commands +\begin{verbatim} +\pagestyle{head} +\runningheadrule +\lhead{Math 115} +\chead[First Exam]{First Exam, Page \thepage\ of \numpages} +\rhead{July 4, 1776} +\end{verbatim} +\end{example} + +%-------------------------------------------------------------------- + +\begin{example} + To have the header + \samplehead{Math 115}{First Exam}{July 4, 1776}{} + on the first page, no header on the pages after the first, no footer + on the first page, and the footer + \samplefoot{\hrule}{Math 115}{First Exam}{Page 2 of 5} + on all pages after the first, give the + commands\indc{runningfootrule}\indc{firstpageheader}% + \indc{runningheader}\indc{firstpagefooter}\indc{runningfooter} +\begin{verbatim} +\pagestyle{headandfoot} +\runningfootrule +\firstpageheader{Math 115}{First Exam}{July 4, 1776} +\runningheader{}{}{} +\firstpagefooter{}{}{} +\runningfooter{Math 115}{First Exam}{Page \thepage\ of \numpages} +\end{verbatim} + Alternatively, you could give the commands +\begin{verbatim} +\pagestyle{headandfoot} +\runningfootrule +\lhead[Math 115]{} +\chead[First Exam]{} +\rhead[July 4, 1776]{} +\lfoot[]{Math 115} +\cfoot[]{First Exam} +\rfoot[]{Page \thepage\ of \numpages} +\end{verbatim} +\end{example} + +%-------------------------------------------------------------------- + +\begin{example} + To have the header + \samplehead{\large\bfseries Mathematics 115\\ + First Exam, July 4, 1776}% + {}{\large\bfseries Name:\enspace\makebox[2in]{\hrulefill}}{} + on the first page, the header + \samplehead{\large\bfseries Mathematics 115\\ + First Exam, July 4, 1776}% + {}{}{} + on all pages after the first, an empty footer on the first page, and + the footer + \samplefoot{}{}{Page 2}{} + on all pages after the first, give the + commands\indc{firstpageheader}\indc{runningheader}% + \indc{firstpagefooter}\indc{runningfooter} +\begin{verbatim} +\pagestyle{headandfoot} +\firstpageheader{\large\bfseries Mathematics 115\\ + First Exam, July 4, 1776} + {} + {\large\bfseries Name:\enspace\makebox[2in]{\hrulefill}} +\runningheader{\large\bfseries Mathematics 115\\ + First Exam, July 4, 1776}{}{} +\firstpagefooter{}{}{} +\runningfooter{}{Page \thepage}{} +\end{verbatim} + Alternatively, you could give the commands +\begin{verbatim} +\pagestyle{headandfoot} +\lhead{\large\bfseries Mathematics 115\\ First Exam, July 4, 1776} +\chead{} +\rhead[\large\bfseries Name:\enspace\makebox[2in]{\hrulefill}]{} +\lfoot{} +\cfoot[]{Page \thepage} +\rfoot{} +\end{verbatim} +\end{example} + +%-------------------------------------------------------------------- + +\begin{example} + To have the header + \samplehead{} + {Wellesley College\\ + Second Semester Final Examination, Spring 1993\\ + Mathematics 115} + {} + {} + on the first page, the header + \samplehead{} + {Wellesley College\\ + Second Semester Final Examination, Spring 1993\\ + Mathematics 115 (Continued)} + {} + {} + on all pages after the first, the footer + \samplefoot{}{}{Page 3 of 10}{Please go on to the next page\ldots} + on all pages \emph{except the last} page, and the footer + \samplefoot{}{}{Page 10 of 10}{End of exam.} + on the last page, give the + commands\indc{extraheadheight}\indc{firstpageheader}% + \indc{runningheader}\indc{footer}\indc{numpages}\indc{thepage}% + \indc{iflastpage} +\begin{verbatim} +\pagestyle{headandfoot} +\extraheadheight{.25in} +\firstpageheader{} + {Wellesley College\\ + Second Semester Final Examination, Spring 1993\\ + Mathematics 115} + {} +\runningheader{} + {Wellesley College\\ + Second Semester Final Examination, Spring 1993\\ + Mathematics 115 (Continued)} + {} +\footer{} + {Page \thepage\ of \numpages} + {\iflastpage{End of exam.}{Please go on to the next page\ldots}} +\end{verbatim} + Alternatively, you could give the commands +\begin{verbatim} +\pagestyle{headandfoot} +\extraheadheight{.25in} +\lhead{} +\chead[Wellesley College\\ + Second Semester Final Examination, Spring 1993\\ + Mathematics 115] + {Wellesley College\\ + Second Semester Final Examination, Spring 1993\\ + Mathematics 115 (Continued)} +\rhead{} +\lfoot{} +\cfoot{Page \thepage\ of \numpages} +\rfoot{\iflastpage{End of exam.}{Please go on to the next page\ldots}} +\end{verbatim} +\end{example} + +%-------------------------------------------------------------------- + +\begin{example} + To have the header + \samplehead{} + {Wellesley College\\ + Second Semester Final Examination, Spring 1993\\ + Mathematics 115} + {} + {} + on the first page, the header + \samplehead{Mathematics 115 (Continued)}{}{Spring, 1993}{} + on all pages after the first, the footer + \samplefoot{}{}{Page 3 of 10}{Please go on to the next page\ldots} + on all pages \emph{except the last} page, and the footer + \samplefoot{}{}{Page 10 of 10}{End of exam.} + on the last page, give the commands\indc{extraheadheight}% + \indc{firstpageheader}\indc{runningheader}\indc{footer} +\begin{verbatim} +\pagestyle{headandfoot} +\extraheadheight[.25in]{} +\firstpageheader{} + {Wellesley College\\ + Second Semester Final Examination, Spring 1993\\ + Mathematics 115} + {} +\runningheader{Mathematics 115 (Continued)}{}{Spring, 1993} +\footer{} + {Page \thepage\ of \numpages} + {\iflastpage{End of exam.}{Please go on to the next page\ldots}} +\end{verbatim} + Alternatively, you could give the commands +\begin{verbatim} +\pagestyle{headandfoot} +\extraheadheight[.25in]{} +\lhead[]{Mathematics 115 (Continued)} +\chead[Wellesley College\\ + Second Semester Final Examination, Spring 1993\\ + Mathematics 115] + {} +\rhead[]{Spring, 1993} +\lfoot{} +\cfoot{Page \thepage\ of \numpages} +\rfoot{\iflastpage{End of exam.}{Please go on to the next page\ldots}} +\end{verbatim} +\end{example} + +%-------------------------------------------------------------------- + +\begin{example} + To have the header +% + \samplehead{Math 115}{First Exam}{July 4, 1776}{} + on the first page, the header +% + \samplehead{Question 3 continues\ldots}{First Exam}{Page 3 of 10}{\hrule} +% + on all pages after the first that continue a question begun on an + earlier page, the header +% + \samplehead{}{First Exam}{Page 3 of 10}{\hrule} + on all pages after the first that don't continue a question begun on + an earlier page, the footer +% + \samplefoot{}{}{}{Question 6 continues on the next page\ldots} +% + on all pages whose last question continues onto the following page, + and no footer on pages that don't have a question that continues + onto the following page, give the + commands\indc{runningheadrule}\indc{ifcontinuation}% + \indc{ContinuedQuestion}\indc{firstpageheader}\indc{runningheader}% + \indc{footer}\indc{thepage}\indc{numpages}\indc{ifincomplete}% + \indc{IncompleteQuestion} +\begin{verbatim} +\pagestyle{headandfoot} +\runningheadrule +\newcommand{\continuedmessage}{% + \ifcontinuation{Question \ContinuedQuestion\ continues\ldots}{}% +} +\firstpageheader{Math 115}{First Exam}{July 4, 1776} +\runningheader{\continuedmessage} + {First Exam} + {Page \thepage\ of \numpages} +\footer{} + {} + {\ifincomplete{Question \IncompleteQuestion\ continues + on the next page\ldots}{}} +\end{verbatim} + Alternatively, you could give the commands +\begin{verbatim} +\pagestyle{headandfoot} +\runningheadrule +\newcommand{\continuedmessage}{% + \ifcontinuation{Question \ContinuedQuestion\ continues\ldots}{}% +} +\lhead[Math 115]{\continuedmessage} +\chead[First Exam]{First Exam} +\rhead[July 4, 1776]{Page \thepage\ of \numpages} +\lfoot{} +\cfoot{} +\rfoot{\ifincomplete{Question \IncompleteQuestion\ continues + on the next page\ldots}{}} +\end{verbatim} +\end{example} + +%-------------------------------------------------------------------- +\begin{example} + \label{sec:PtsPgEx} + To have the header +% + \samplehead{Math 115}{Second Exam}{July 4, 1776}{} +% + on the first page, the header +% + \samplehead{Second Exam}{}{July 4, 1776}{} +% + on all pages after the first, no footer on the first page, and the + footer +% + \samplefoot{}{Page 3 of 5}{}{Points earned: \makebox[.5in]{\hrulefill}\\ + out of a possible 20 points} +% + on all pages after the first, give the commands\indc{firstpageheader}% + \indc{runningheader}\indc{runningfooter}\indc{pointsonpage}% + \indc{thepage}\indc{numpages} +\begin{verbatim} +\pagestyle{headandfoot} +\firstpageheader{Math 115}{Second Exam}{July 4, 1776} +\runningheader{Second Exam}{}{July 4, 1776} +\runningfooter{Page \thepage\ of \numpages} + {} + {Points earned: \makebox[.5in]{\hrulefill}\\ + out of a possible \pointsonpage{\thepage} points} +\end{verbatim} + Alternatively, you could give the commands +\begin{verbatim} +\pagestyle{headandfoot} +\lhead[Math 115]{Second Exam} +\chead[Second Exam]{} +\rhead{July 4, 1776} +\lfoot[]{Page \thepage\ of \numpages} +\cfoot{} +\rfoot[]{Points earned: \makebox[.5in]{\hrulefill}\\ + out of a possible \pointsonpage{\thepage} points} +\end{verbatim} +\end{example} + +%-------------------------------------------------------------------- + +\begin{example} + \label{sec:endexamples} + To have the header +% + \samplehead{Math 115}{Second Exam}{July 4, 1776}{} +% + on the first page, the header +% + \samplehead{}{Second Exam}{July 4, 1776}{} +% + on all odd numbered pages after the first, the header +% + \samplehead{Question 3 continues\ldots}{Math 115}{}{} +% + on all even numbered pages that continue a question begun on an + earlier page, the header +% + \samplehead{}{Math 115}{}{} +% + on all even numbered pages that don't continue a question begun on + an earlier page, the footer +% + \samplefoot{}{}{}{Page 5 of 10\\Question 6 continues\ldots} +% + on all odd numbered pages that have a question that continues onto + the following page, the footer +% + \samplefoot{}{}{}{Page 5 of 10} +% + on all odd numbered pages that don't have a question that continues + onto the following page, and the footer +% + \samplefoot{}{Page 4 of 10}{}{} +% + on all even numbered pages, give the commands\indc{ifcontinuation}% + \indc{thepage}\indc{numpages}\indc{IncompleteQuestion}% + \indc{firstpageheader}\indc{runningheader}\indc{oddeven}% + \indc{footer} +\begin{verbatim} +\pagestyle{headandfoot} +\newcommand{\continuedmessage}{% + \ifcontinuation{Question \ContinuedQuestion\ continues\ldots}{}% +} +\newcommand{\oddrightfoot}{% + \ifincomplete{Page \thepage\ of \numpages\\ + Question \IncompleteQuestion\ continues\ldots}% + {Page \thepage\ of \numpages} +} +\firstpageheader{Math 115}{Second Exam}{July 4, 1776} +\runningheader{\oddeven{}{\continuedmessage}} + {\oddeven{Second Exam}{Math 115}} + {\oddeven{July 4, 1776}{}} +\footer{\oddeven{}{Page \thepage\ of \numpages}} + {} + {\oddeven{\oddrightfoot}{}} +\end{verbatim} + Alternatively, you could give the commands +\begin{verbatim} +\pagestyle{headandfoot} +\newcommand{\continuedmessage}{% + \ifcontinuation{Question \ContinuedQuestion\ continues\ldots}{}% +} +\newcommand{\oddrightfoot}{% + \ifincomplete{Page \thepage\ of \numpages\\ + Question \IncompleteQuestion\ continues\ldots}% + {Page \thepage\ of \numpages} +} +\lhead[Math 115]{\oddeven{}{\continuedmessage}} +\chead{\oddeven{Second Exam}{Math 115}} +\rhead{\oddeven{July 4, 1776}{}} +\lfoot{\oddeven{}{Page \thepage\ of \numpages}} +\cfoot{} +\rfoot{\oddeven{\oddrightfoot}{}} +\end{verbatim} +\end{example} + + +\indcstop{lhead} +\indcstop{chead} +\indcstop{rhead} +\indcstop{lfoot} +\indcstop{cfoot} +\indcstop{rfoot} +\index{footer|)} +\index{header|)} + +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +\section{Cover pages} +\label{sec:coverpages} +\index{cover pages|(} +\index{environment!coverpages|(} +\indtstart{coverpages} + +There is a \verb"coverpages" environment that allows you to have one +or more pages before page~1 of the exam. By default, there are no +headers or footers printed on the cover pages, but if you put the page +number into the headers and/or footers (using the commands described +in section~\ref{sec:Coverhdft}), the page numbers of cover pages are +printed in roman numerals. + +The \verb"coverpages" environment must begin and end \emph{before} the +beginning of the \verb"questions" environment. You begin the +environment with the command +\begin{center} + \verb"\begin{coverpages}" +\end{center} +and you end it with the command +\begin{center} + \verb"\end{coverpages}" +\end{center} +In between those two commands you can put whatever you want, except +that you are not allowed to begin the \verb"questions" environment +until you've ended the \verb"coverpages" environment. The command +\verb"\begin{coverpages}" sets the page number to 1 and causes any +page numbers printed (using the commands described in +section~\ref{sec:Coverhdft}) to appear as roman numerals. The command +\verb"\end{coverpages}" causes the current page to end, sets the page +number of the following page to 1, and changes page numbering back to +arabic numerals. + +%-------------------------------------------------------------------- +\subsection{Headers and footers} +\label{sec:Coverhdft} +\index{header!on cover pages|(} +\index{footer!on cover pages|(} + +By default, the headers and footers on the cover pages are empty. If +you'd like to have headers and/or footers on the cover pages, there +are commands to create them that are completely analogous to the +commands described in section~\ref{sec:headfoot} for headers and +footers in the main part of the document. The commands for headers +and footers in cover pages and the corresponding commands for the main +exam pages are:\indc{coverheader}\indc{coverrunningheader}% +\indc{coverfirstpageheader}\indc{coverlhead}\indc{coverchead}% +\indc{coverrhead}\indc{coverfooter}\indc{coverrunningfooter}% +\indc{coverfirstpagefooter}\indc{coverlfoot}\indc{covercfoot}% +\indc{coverrfoot}\indc{coverextraheadheight}% +\indc{coverextrafootheight} +\begin{center} + \begin{tabular}{l@{\qquad\qquad}l} +Cover Pages Commands& Main Pages Commands\\[\medskipamount] +\verb"\coverheader"&\verb"\header"\\ +\verb"\coverrunningheader"&\verb"\runningheader"\\ +\verb"\coverfirstpageheader"&\verb"\firstpageheader"\\[\medskipamount] + +\verb"\coverlhead"&\verb"\lhead"\\ +\verb"\coverchead"&\verb"\chead"\\ +\verb"\coverrhead"&\verb"\rhead"\\[\medskipamount] + +\verb"\coverfooter"&\verb"\footer"\\ +\verb"\coverrunningfooter"&\verb"\runningheader"\\ +\verb"\coverfirstpagefooter"&\verb"\firstpageheader"\\[\medskipamount] + +\verb"\coverlfoot"&\verb"\lfoot"\\ +\verb"\covercfoot"&\verb"\cfoot"\\ +\verb"\coverrfoot"&\verb"\rfoot"\\[\medskipamount] + +\verb"\coverextraheadheight"&\verb"\extraheadheight"\\ +\verb"\coverextrafootheight"&\verb"\extrafootheight" + \end{tabular} +\end{center} +The commands \verb"\coverlhead", \verb"\coverchead", +\verb"\coverrhead", \verb"\coverlfoot", \verb"\covercfoot", +\verb"\coverrfoot", \verb"\coverextraheadheight", and +\verb"\coverextrafootheight" all all take the same optional arguments +(for special treatment of page number 1) as the corresponding commands +for the main pages. For an explanation of these commands, see +section~\ref{sec:headfoot}. + +\index{header!on cover pages|)} +\index{footer!on cover pages|)} + +%-------------------------------------------------------------------- +\subsection{Listing the number of cover pages} +\label{sec:NumCvrpgs} +\index{cover pages!counting|(} +\indcstart{numcoverpages} +\indcstart{totalnumpages} + +The \texttt{exam} document class defines the command +\verb"\numcoverpages" so that it will expand to the number of cover +pages in the exam. If there is no \texttt{coverpages} environment, +then \verb"\numcoverpages" expands to 0. The \texttt{exam} class also +defines the command \verb"\totalnumpages", which expands to the sum of +\verb"\numpages" and \verb"\numcoverpages". +\emph{Note:} if there are pages preceding a \texttt{coverpages} +environment, then those pages will not be counted by +\verb"\totalnumpages". + +For an example, to have the footer +% +\samplefoot{}{}{Page ii of iv}{} +on all cover pages you should either give the +command\indc{romannumeral} +\begin{verbatim} +\coverfooter{}{Page \thepage\ of \romannumeral\numcoverpages}{} +\end{verbatim} +or the commands +\begin{verbatim} +\coverlfoot{} +\covercfoot{Page \thepage\ of \romannumeral\numcoverpages} +\coverrfoot{} +\end{verbatim} +As with all other cross referencing commands in \LaTeX, you'll have to +run the file through \LaTeX{} \emph{twice} to be sure that +\verb"\numpages", \verb"\numcoverpages", and \verb"\totalnumpages" are +correct. + +\index{cover pages!counting|)} +\indcstop{numcoverpages} +\indcstop{totalnumpages} + +\indtstop{coverpages} +\index{environment!coverpages|)} +\index{cover pages|)} + +%-------------------------------------------------------------------- +\clearpage +\addcontentsline{toc}{section}{Index} +\printindex + +% The following is necessary to avoid warnings, since we have multiple +% questions environments in this documentation file: +\makeatletter +\@pointschangedfalse +\makeatother + + + + +\end{document} +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- +%-------------------------------------------------------------------- -- cgit v1.2.3