Debian Codegraph @

texmf-dist/source/latex/exam-n/exam-n.dtx

raw
1 % \iffalse
2 % This is exam-n.dtx, which supports formatting exam papers.
3 %
4 % Generated file : DO NOT EDIT
5 %
6 %% Release version exam-n-1.4.0, 2022 October 10.
7 %% See https://purl.org/nxg/dist/exam-n
8 %% and https://heptapod.host/nxg/exam-n
9 %% and https://www.ctan.org/pkg/exam-n
10 %%
11 %%%% File: exam-n.dtx
12 %%%% Copyright 2005--2022, Norman Gray
13 %%
14 %% This work may be distributed and/or modified under the
15 %% conditions of the LaTeX Project Public License, either version 1.3
16 %% of this license or (at your option) any later version.
17 %% The latest version of this license is in
18 %% http://www.latex-project.org/lppl.txt
19 %% and version 1.3 or later is part of all distributions of LaTeX
20 %% version 2005/12/01 or later.
21 %%
22 %% This work has the LPPL maintenance status `maintained'.
23 %%
24 %% The Current Maintainer of this work is Norman Gray <https://nxg.me.uk>
25 %%
26 %% This work consists of the files exam-n.dtx and exam-n.ins,
27 %% the derived file exam-n.cls,
28 %% and the associated *.clo files.
29
30
31 %<+package|driver|example>%%%% Source: a91e9cff7cac, 2022-10-10T13:33:17+01:00
32 %%
33 %<*package|driver>
34
35 %</package|driver>
36 %<+package>\NeedsTeXFormat{LaTeX2e}
37 %<+package>\ProvidesClass{exam-n}[2022/10/10 exam-n-1.4.0]
38 %<+package>\typeout{Class: `exam-n-1.4.0 <2022/10/10>}
39 %
40 %<*driver>
41 \documentclass{ltxdoc}
42 \title{exam-n: exam papers}
43 \author{Norman Gray\\(\texttt{[email protected]})}
44 \date{Version exam-n-1.4.0, 2022 October 10}% ...rather than exam-n-1.4.0, which isn't reader-focused
45 \usepackage{url}
46 \newcommand\Lopt[1]{\textsf {#1}} % options
47 \newcommand\file[1]{\texttt {#1}}
48 \newcommand\Lcount[1]{\textsl {\small#1}}
49 \newcommand\Lenv[1]{\texttt{\{#1\}}} %environments
50 \newcommand\Lpackage[1]{[\textsf{#1}]} %packages
51 %Make command strings easier to write, with \cmd|\foo|
52 %{\catcode`\<=\active \gdef<#1>{\meta{#1}}}
53 {\catcode`\<=\active
54 \gdef<#1>{{\ensuremath\langle\normalfont\textsl{#1}\ensuremath\rangle}}}
55 \def\cmd{\begingroup
56 \catcode`\\=12 \catcode`\{=12 \catcode`\}=12 \catcode`\#=12
57 \catcode`\<=\active \catcode`\|=12
58 \docmd}
59 \def\docmd|#1|{\texttt{#1}\endgroup}
60
61 \def\secref#1{Sect.~\ref{#1}}
62
63 % Various definitions of this package, so we can document them.
64 \usepackage{examndefs}
65
66 % Uncomment \OnlyDescription to skip the implementation
67 %\OnlyDescription
68 \begin{document}
69 \maketitle
70 \tableofcontents
71 \bigskip
72 \DocInput{exam-n.dtx}
73 \end{document}
74 %</driver>
75 %
76 % \fi
77 %
78 % \noindent This class file supports creating exam papers.
79 % This is intended as part of a slightly larger system for assembling
80 % and managing the papers, by combining questions from multiple authors.
81 %
82 % This document is addressed to the exams convener, or someone
83 % responsible for the overall exam; it goes into complete detail about
84 % the class file, and how to customise it. There is more compact
85 % documentation for the class, addressed to the authors of individual
86 % questions, in the companion document `Notes for Authors'.
87 %
88 % The most up-to-date version of this class can be found at
89 % \url{http://purl.org/nxg/dist/exam-n}.
90 %
91 % \newpage
92 %
93 % \section{Description}
94 %
95 % Usage:
96 % \begin{verbatim}
97 % \documentclass[options...]{exam-n}
98 % <preamble declarations>
99 % \begin{document}
100 % \maketitle
101 % \begin{question}...\end{question}
102 % ...
103 % \end{document}
104 % \end{verbatim}
105 %
106 % \subsection{Class options}
107 % \label{s:options}
108 %
109 % The class takes the following options. Note that these options are
110 % processed in order, so if an option changes a default
111 % (for example, \Lopt{draft} sets \Lopt{showsolutions} by default),
112 % then it can be overridden by an option later in the list.
113 % \begin{description}
114 % \item[\Lopt{compose}, \Lopt{draft}, \Lopt{final}]
115 % When composing questions, you should give
116 % the \Lopt{compose} option to \Lenv{exam-n}; when assembling the paper, you
117 % should use \Lopt{draft}; and you should use \Lopt{final} only for
118 % the final version.
119 % The \Lopt{draft} option switches on the \Lopt{showsolutions}
120 % option (below), displays |\comment| remarks,
121 % and makes some mild layout changes.
122 % The \Lopt{compose} option implies the \Lopt{showsolutions} option,
123 % causes questions to be formatted one per page, and turns off
124 % various checks on the number of questions; the \Lopt{draft} option
125 % should have the same pagination as the final paper and shifts the
126 % body of the paper to the left so that marginal comments are
127 % easier to write and read; the \Lopt{final} option turns off the
128 % |\comment| command.
129 %
130 % \item[\Lopt{cmfonts}, \Lopt{psfonts}, \Lopt{mathptm},
131 % \Lopt{mathtime}, \Lopt{mtpro2}, \Lopt{stix2}]
132 % The \Lopt{cmfonts} option (the default) uses the Computer Modern fonts for the
133 % document, and the other options use PostScript or OpenType fonts.
134 %
135 % The \Lopt{mathtime} or \Lopt{mtpro2} options select PostScript
136 % Times Roman, Helvetica and Courier for the body text, plus either Mathtime or
137 % Mathtime Professional~2 to typeset maths (this is commercially
138 % distributed by
139 % PC\TeX\footnote{\url{https://www.pctex.com/mtpro2.html}}, and
140 % designed to be compatible with Times Roman). A broadly
141 % compatible alternative to this is to use the \Lopt{mathptm}
142 % option, but although this is free, the results aren't impressive.
143 %
144 % A final option is to use the \Lopt{stix2} option to choose
145 % specifically and exclusively the
146 % (free) STIX2 font set\footnote{\url{https://www.stixfonts.org}}
147 % for both text and maths.
148 % On this site, you will need to download and install
149 % the files in the \url{static_otf.zip} bundle.
150 % Note that the support for this option is somewhat experimental, and
151 % at present, this package simply uses (serif) STIX2 roman
152 % for all font shapes. Since the exam style doesn't use any sans serif by
153 % default, this doesn't matter, at some level. The
154 % \Lopt{sansserif} option is not compatible with this option (the option
155 % won't produce any error, but neither will it produce any effect).
156 %
157 % \textbf{FIXME: remove this when unicode-math is working.}
158 % \textbf{Note:} because of an unfortunate interaction between packages, the
159 % \Lpackage{stix2} and \Lpackage{siunitx} packages can produce unexpected
160 % results with some combinations of \TeX\ engine and package version
161 % (specifically, \Lpackage{stix2} plus \Lpackage{siunitx}
162 % and \cmd|\micro| or \cmd|\circ| can produce garbled characters
163 % without \LaTeX\ reporting an error). Before \TeX Live 2021, this
164 % worked correctly with Xe\LaTeX\ and Lua\LaTeX, but not with
165 % pdf\LaTeX; from \TeX Live 2021 this works as expected with
166 % pdf\LaTeX, but works with the other two \emph{only} if you load
167 % the \Lpackage{siunitx} package with
168 % \cmd|\usepackage{siunitx}[=v2]|. I hope that future versions of
169 % one or other of these packages will make clear how this package
170 % should handle them, in a way which avoids this special-casing.
171 % \iffalse See
172 % https://github.com/josephwright/siunitx/issues/550
173 % https://github.com/josephwright/siunitx/issues/547
174 % https://github.com/stipub/stixfonts/issues/235
175 % \fi
176 %
177 % The handling of non-standard fonts has always been slightly
178 % fragile in \LaTeX.
179 % The \Lopt{mtpro2} and \Lopt{stix2} options are those currently
180 % most used by the author, and are therefore the ones most likely
181 % to get the various font nuances correct.
182 %
183 % \item[\Lopt{uprightpi}]By default $\pi$ is set slanted, as is the
184 % usual \LaTeX\ default. When this is referring to the circular
185 % constant, however, this should (in some typesetting styles) be set as an upright letter, in
186 % fonts which support this. If the option \Lopt{uprightpi} is
187 % present, then |\pi| is defined to produce an upright letter, and
188 % the command |\italicpi| is defined to produce the slanted version.
189 % Whether this option is supplied or not, the macro |\uppi| will
190 % produce a single upright~$\pi$.
191 % Note: this is at present implemented
192 % only for the \Lopt{mtpro2} and \Lopt{stix2} options,
193 % and the combination of pdflatex+stix2 does not support |\uppi| at present.
194 %
195 % \item[\Lopt{(no)siunitx}] Load the \Lpackage{siunitx} package, or
196 % not. The default is yes. The |\units| macro, described below,
197 % still exists as an alternative, but will be removed in a
198 % forthcoming release (probably after 1.4.x).
199 %
200 % \item[\Lopt{(no)showsolutions}]
201 % These control whether the solutions to
202 % the questions are shown on the paper or not. \Lopt{showsolutions} is the
203 % default when the either \Lopt{draft} or \Lopt{compose} options is
204 % present, and \Lopt{noshowsolutions} in \Lopt{final} case,
205 % though this will be overridden by one of the
206 % \Lopt{\{no\}showsolutions} options later in the list.
207 %
208 % \item[\Lopt{(no)perquestionmarks} and \Lopt{(no)showmarktotals}]
209 % These control whether mark totals and subtotals are tracked within
210 % the question (perquestionmarks), and whether the total available
211 % marks are displayed at the end of the question (showmarktotals).
212 % See \secref{s:question} for more discussion (this
213 % option was called \Lopt{showmarks} up to release 0.15).
214 %
215 % \item[\Lopt{(no)pageperquestion}]
216 % If the option \Lopt{pageperquestion} is present, then each
217 % question is on a separate page. Option \Lopt{nopageperquestion}
218 % is the default. This is most often set by default by one of the
219 % other options, or by a \file{.clo} file.
220 %
221 % \item[\Lopt{oneside}, \Lopt{twoside}]
222 % These control whether the document is formatted for
223 % one- or twosided printing. This is a standard option, which is
224 % redundant in this case, since in this document style there is no
225 % difference in formatting. You may in principle use other
226 % {article} options, though you are encouraged not to.
227 %
228 % \item[\Lopt{fleqn}]
229 % Display equations flush-left, rather than centred. You generally
230 % won't set this in the |\documentclass| options -- it's here so
231 % that it can be set in a |.clo| file.
232 %
233 % \item[\Lopt{sloppydescription}]
234 % Disables the requirement that all exam metadata be present. See
235 % the discussion of |\universitycoursecode| below.
236 %
237 % \item[\Lopt{mono}, \Lopt{colour}]
238 % The university logo is typeset in colour by default, as is the
239 % solution text; the \Lopt{mono} option causes everything to be in
240 % mono instead. The \Lopt{colour} option does nothing, but is
241 % present for symmetry.
242 %
243 % \item[\Lopt{sansserif}]
244 % Use a sans serif font for the body text. This is plug-ugly, not
245 % least because it doesn't match the maths font; also, it may be
246 % easier or harder for dyslexic students to read (there seems to be
247 % a variety of advice here, in both directions, ranging from
248 % confident to dogmatic, but remarkably little solid evidence
249 % either way).
250 %
251 % \item[\Lopt{largefont}, or \Lopt{hugefont}]
252 % Produce a version of the paper in a `big' font (18pt) or `huge' font (36pt) for
253 % the benefit of students with visual impairments. See notes below.
254 %
255 % \end{description}
256 %
257 % Any other options are interpreted as an instruction to read in a
258 % \file{.clo} file, containing course-, department- or group-specific style
259 % modifications. Most typically, these changes will affect the
260 % rubric, and the sheet of physical constants.
261 % The only generic style option is \Lopt{myclass}
262 % (which is included as an example of how such a file is written).
263 % See \secref{s:custom} below.
264 %
265 % In some circumstances -- for example when processing exam scripts
266 % under the control of a Makefile or script -- it can be convenient to
267 % control package options from outside the package. If there is a
268 % file called \texttt{exam-n.config} in the input path (most likely in
269 % the same directory as the exam paper), then this is read in when any
270 % exam script is processed, and will supplement any
271 % options in the |\documentclass| line. For example, if this file were present
272 % and contained the line |\ExecuteOptions{showsolutions}|, then the
273 % typeset exam would include the solutions. Note that this will
274 % supplement, \emph{but not override}, options in the input file's |\documentclass|;
275 % it is therefore useful only for switching options away from the default.
276 %
277 % The exam-n class includes the \Lpackage{amsmath} package, so you can
278 % make immediate use of amsmath features if you wish (see
279 % \texttt{\small http://www.ams.org/tex/amslatex.html} for discussion).
280 %
281 % The change of font size with the \Lopt{hugefont} option requires a
282 % couple of minor layout changes. You may need to force some similar
283 % changes in the exam paper, in this case. You can do that by bracketing the
284 % adjusted text in \cmd|\ifbigfont<big font material>\else<normal font
285 % material>\fi|; the |\ifbigfont| flag is true in the case of
286 % \Lopt{hugefont}, but not \Lopt{largefont}. If you want the
287 % |\ifbigfont| flag to apply to \Lopt{largefont}, too, then you may
288 % set |\bigfonttrue| in a suitable place. The \Lpackage{amsmath}
289 % \texttt{multline} environment can be useful here. The exams
290 % convener should review the result carefully: a few judicious
291 % \cmd|\ifbigfont\newpage\fi| insertions can make the result look less
292 % awful. The \Lopt{largefont} and \Lopt{hugefont} options apply to
293 % the content of solutions if the \Lopt{showsolutions} option is
294 % present; this may or may not be the optimal choice.
295 %
296 % At the bottom of each page, you see a faint identification code, such
297 % as `QM/123-456'. This consists of an exam identifier, extracted from
298 % the exam preamble, plus a code which changes each time \LaTeX\ is
299 % run. This helps you avoid collation accidents, and to distinguish
300 % between slightly different versions of the printed document.
301 % The identifier is based on the date and time, so changes each time
302 % you run \LaTeX\ on the file (that is, it identifies a printing,
303 % rather than a source-file version).
304 %
305 % \subsection{The Question environment}
306 % \label{s:question}
307 %
308 % Within the document, you include questions within a \Lenv{question}
309 % environment, within which you may further have
310 % \Lenv{questiondata} and \Lenv{solution} environments.
311 %
312 % \DescribeEnv{question}
313 % The \Lenv{question} environment delimits a single exam question.
314 %
315 % Usage, with \Lopt{perquestionmarks}:
316 % \begin{quotation}
317 % \noindent
318 % |\begin{question}|\oarg{questionnumber}\marg{marks}\\
319 % \dots\\
320 % |\end{question}|
321 % \end{quotation}
322 % Or, with \Lopt{noperquestionmarks}:
323 % \begin{quotation}
324 % \noindent
325 % |\begin{question}|\oarg{questionnumber}\\
326 % \dots\\
327 % |\end{question}|
328 % \end{quotation}
329 %
330 % There are two variants of this environment, depending on whether the
331 % \Lopt{perquestionmarks} option is present or not. If it is present
332 % (the default) then the \Lenv{question} environment takes a non-empty
333 % argument showing the total marks available for a question.
334 % In addition, the class checks that the |\partmarks| commands within the
335 % question (see below) add up to this declared goal mark.
336 % If the \Lopt{showmarktotals} option is present, then this (expected and
337 % checked) total is displayed at the end of the question.
338 %
339 % If the \Lopt{perquestionmarks} option is \emph{not} present,
340 % then questions have no individual marks, the
341 % environment takes no marks argument, and no marks are shown (this is usual
342 % in essay-question exams, which typically comprise a sequence of
343 % short equal-valued questions with an explanatory rubric).
344 % Also, in this case the |\partmarks| command cannot be used within the question.
345 %
346 % The \Lenv{question} environment takes an optional argument, giving
347 % the expected question number. In \Lopt{compose} mode, this is used
348 % as the question number (unsurprisingly). In the two other modes,
349 % this is compared with the question number which would be generated based on the
350 % position in the sequence of \Lenv{question} environments in the file, so
351 % that the first \Lenv{question} environment is for question one, the
352 % second for question two, and so on. If these do not match, the exam
353 % class displays a warning in \Lopt{draft} mode, and produces a fatal
354 % error in \Lopt{final} mode.
355 % The intention is that this can act as a check that all expected
356 % questions are present; see also the |\numquestions| command.
357 % \iffalse XXX How useful is this in fact? Should I just discard this,
358 % especially since includequestion has a similar features? \fi
359 %
360 % \DescribeMacro{\QuestionNumberChecksOff}
361 % In some cases, the questions are not numbered in this
362 % straightforward fashion, so that you might have questions~`2A'
363 % and~`2B'. In this case, the check is not meaningful, and you must
364 % suppress it by calling the macro |\QuestionNumberChecksOff| in the
365 % preamble. After that, you must provide a question-number argument
366 % (in square brackets) for every question.
367 %
368 % Using |\label| within a question sets a label for the question number;
369 % using it within a |\part| (see below) labels the part number.
370 %
371 % In some odder circumstances, you might not want to have any question
372 % numbers at all; for example, you might want to require examinees to
373 % attempt \emph{all} of the questions, and so simply have a mark for
374 % the whole exam. There isn't a mode for this as such, but if you use
375 % the \cs{QuestionNumberChecksOff} macro, and give |[\space]| as the
376 % optional `question number' at the beginning of the \Lenv{question}
377 % environment, then this will have the desired effect.
378 %
379 % \DescribeEnv{solution}
380 % The \Lenv{solution} environment, contained within the \Lenv{question}
381 % environment, contains the solution to the question, or other
382 % notes. It is displayed by default in \Lopt{compose} mode, and
383 % suppressed by default in the others, though this behaviour may be
384 % overridden in either case with the \Lopt{(no)showsolutions}
385 % option. You can have one \Lenv{solution} at the end of your
386 % question, or have multiple ones scattered throughout it. You may
387 % use the |\partmarks| macro within the solution, to indicate the
388 % distribution of marks within (this part of) the solution --
389 % these, of course, do not count towards the total mark for the
390 % question. You must not have a solution inside a solution.
391 %
392 % \DescribeEnv{questiondata}
393 % At the end of a question, it is frequently useful to include further
394 % information, such as extra equations, or numerical data. These
395 % should be included within a \Lenv{questiondata} environment, in
396 % order for them to be formatted appropriately. You may include
397 % multiple paragraphs, equations, and displays in this environment, as
398 % appropriate. Typically, you will have only one such environment per
399 % question, appearing at the end, but may have several of them if you
400 % really wish to.
401 %
402 % \DescribeEnv{mcq}
403 % Some exams include multiple-choice questions rather than
404 % extended-answer ones. These are numbered in the same sequence as
405 % the other questions, but are formatted and marked-up differently.
406 % \begin{verbatim}
407 % \begin{mcq}
408 % In 1908, where was there an airburst `impact'?
409 % \answer Tunguska
410 % \item Arizona
411 % \item Off the Mexican coast
412 % \item Egypt
413 % \end{mcq}
414 % \end{verbatim}
415 % That is, the \Lenv{mcq} environment contains a list of possible
416 % answers, all of which are indicated by |\item|, except precisely one
417 % correct answer, indicated by |\answer|.
418 % \DescribeMacro{\multiplechoiceanswers}
419 % All multiple-choice questions must have the same number of possible
420 % answers, which is declared with the command \cmd|\multiplechoiceanswers{<n>}|
421 % The \Lenv{mcq} environment is permitted only after |\multiplechoiceanswers|.
422 % It's OK to have a \Lenv{solution} within an \Lenv{mcq} environment,
423 % which might provide further commentary on the correct answer.
424 %
425 % There are various other commands which you may or should use within
426 % the document.
427 %
428 % \DescribeMacro{\includequestion}
429 % It may be convenient to split your exam into a number of separate
430 % source files, such as having one \texttt{.tex} file for each
431 % question. You can include these various source files using the
432 % usual |\input| command.
433 %
434 % If the separate source files have the simple form:\label{s:includequestion}
435 % \begin{verbatim}
436 % \documentclass[compose]{exam-n}
437 % \usepackage{graphicx} % for example
438 % \begin{document}
439 % \begin{question}
440 % ...
441 % \end{question}
442 % \end{document}
443 % \end{verbatim}
444 % then they can be \LaTeX ed separately, for example by the authors of
445 % different questions, but cannot be |\input|
446 % unedited, as described above. If, however, they have \emph{only}
447 % these structures (that is, only the |\documentclass| command,
448 % the \Lenv{document} environment, and zero or more |\usepackage|
449 % or |\RequirePackage| commands),
450 % then you can most conveniently import them unedited using the
451 % |\includequestion| command.
452 % \begin{verbatim}
453 % \includequestion{dynamics2}
454 % \end{verbatim}
455 % This acts like the |\input| command, but disables the listed structures.
456 % It also puts the included command into a group, so that any
457 % (re)definitions of commands are made local-only.
458 %
459 % Recall that the definition of the |\includequestion| command means
460 % that any |\usepackage| commands will be ignored. If you, as a
461 % question author, need certain packages to be present for your
462 % question, you will have to make sure that whoever is assembling the
463 % master file includes those packages there, too.
464 %
465 % That is, we don't try too hard to support including just any old \LaTeX, here:
466 % any complicated preamble requirements in an included file should
467 % probably be managed by the exams convener transplanting them into
468 % the preamble of the main document. This may be an overly
469 % simple-minded approach, and may change in future versions.
470 %
471 % The |\includequestion| command takes an optional argument which
472 % overrides the question number. This caters for the case where
473 % question authors have (unhelpfully) included question numbers in the
474 % files' \Lenv{question} environments, and the case where questions
475 % are not numbered in a straightforward sequence, for example `1',
476 % `2A', `2B', and so on.
477 %
478 % \DescribeMacro{\section}
479 % \DescribeMacro{\subsection}
480 % Some exams are divided into sections, or have other structure which
481 % needs to be spelled out. These are described with the |\section|
482 % command, in a form such as |\section{II}|. You can also add smaller
483 % headers before individual questions with something like
484 % |\subsection{Second semester questions}|. These can appear only
485 % between questions; it is an error to include one of these commands
486 % within a \Lenv{question} or \Lenv{mcq} environment.
487 %
488 % \DescribeMacro{\part}
489 % Questions may be subdivided into parts, such as (a), (b),
490 % (c)..., or (i), (ii), (iii), and so on. Precede each of these with
491 % this |\part| command. The formatting of the part numbers is
492 % controlled by the exam style, as customised in
493 % \secref{s:custom}. This macro starts a new paragraph.
494 %
495 % You can use the |\part| macro within solutions: this is useful if
496 % you have the entire \Lenv{solution} environment at the end of the
497 % question, but distracting if you intersperse the \Lenv{solution}
498 % environments between question parts. The |\part| macro within
499 % solutions increments separately from the increments within the question,
500 % so if you use this in the solutions, you must have as many
501 % |\part|s in the solution as there are parts in the question.
502 %
503 % In some (rare) cases, you may want to force a particular part
504 % number. You can do that with an optional argument |\part[99]|
505 % which overrides the auto-incremented numbering. Note that this
506 % skips the auto-increment of the number but doesn't cancel it, so
507 % if you do this for one part number you should probably do it for
508 % all of them.
509 %
510 % \DescribeMacro{\partmarks}
511 % \DescribeMacro{\partmarks*}
512 % Macros \cmd|\partmarks{<num>}| and \cmd|\partmarks*{<num>}| announce
513 % the number of marks associated with the current part of a question.
514 % The class checks that the number of marks here does add up to the
515 % number declared at the beginning of the {question} environment.
516 % You will typically have just one |\partmarks| per |\part|, but
517 % you can have more if you want.
518 %
519 % The |\partmarks| command will most typically go at the end of a
520 % paragraph, but it may also appear inside an equation (that is, in
521 % |\[...\]|; don't use |$$...$$|), inside one or other
522 % \Lpackage{amsmath} display or \Lenv{equation} environments, or in
523 % a list or other environment. If it appears
524 % inside an environment, the indicator will appear at the
525 % \emph{end} of the environment, independent of where in the
526 % environment the command was typed (which implies that you can't
527 % have more than one inside an environment). The alignment of
528 % the partmarks indicator is not currently as good as I'd like it
529 % to be, in the case of \Lpackage{amsmath} alignments, but this
530 % turns out to be hard to improve.
531 %
532 % The starred version is similar, but budges its indicator upwards
533 % a little, and is a heuristic alternative which is useful in some
534 % cases \emph{after} a list or display, if the placement of the
535 % indicator is otherwise inaesthetic
536 % (if the style of the part-marks indicators happens to be such
537 % that the indicator may be mistaken for an equation number, then
538 % it would be wise to use either |\partmarks| or |\partmarks*|
539 % after the equation, instead). If you use |\partmarks*| within a
540 % display, you might be confronted by an error message, talking
541 % about |\eqno| in maths mode, which is even more incomprehensible
542 % than most \LaTeX\ messages.
543 %
544 % The unstarred version should only be used at the end of a
545 % paragraph, and in fact forces a paragraph end; the starred
546 % version should on stylistic grounds generally be used only at the
547 % end of a paragraph, but it doesn't force one.
548 %
549 % The |\partmarks| command has an optional argument which
550 % indicates the category of the question, thus `bookwork', `unseen',
551 % and so on. If this is present, then the category is included in the
552 % marks indicator.
553 %
554 % The |\partmarks| category/comment will typically be only one or two words
555 % long, and can sit comfortably in the margin. If an author wants to
556 % write more here, then it will be turned into a footnote on the
557 % page. This will obviously change the layout of the page, though
558 % since this text appears only in \Lopt{showsolutions} mode, that
559 % shouldn't be a problem.
560 %
561 % \DescribeMacro{\defaultpartmarkscategory}
562 % If the exams convener wishes to \emph{oblige} people to
563 % include such a category, then they might call
564 % |\defaultpartmarkscategory{category?}| in a package-options (|.clo|)
565 % file, to default the category with a highlighted remark to the question setter.
566 %
567 % \DescribeMacro{\comment}
568 % \cmd|\comment{<text>}| associates a comment with a part of the text.
569 % This is ignored in \Lopt{final} mode, but appears in the margin in the
570 % other modes.
571 %
572 % \DescribeMacro{\author}
573 % The |\author| command is a convenience. Used within a
574 % \Lenv{question} environment -- most naturally just after the
575 % |\begin{question}| -- it creates a comment with the author's
576 % name. Its functionality may be expanded in future, so you should
577 % use this command, rather than a generic |\comment|, when noting
578 % the authorship of a question.
579 %
580 % \DescribeMacro{\shout}
581 % If there is part of a question which is, for example, incomplete,
582 % and which needs a more prominent callout than `comment', then you
583 % should |\shout{...}| it. Shouts appear in all modes (\emph{including}
584 % \Lopt{final}) and appear whether or not the class is showing solutions.
585 % This makes a prominent remark in the text, and also in a list of
586 % shouts at the end of the text. Your co-authors, or the exam
587 % proof-checker, really have no excuse for missing it after that.
588 %
589 % \DescribeMacro{\leftnudge}
590 % For various reasons, most often because of printing problems, it can
591 % be useful to nudge the textblock left or right a little. You should
592 % call the |\leftnudge| command to do this, rather than fiddling with
593 % the underlying \LaTeX\ dimensions yourself. Give the command a dimension
594 % argument such as |\leftnudge{1cm}| to nudge the textblock leftwards
595 % by 1cm. You can give a negative dimension to nudge it rightwards
596 % instead. The \Lopt{draft} option automatically nudges the text
597 % block leftwards, to create a larger right-hand margin for notes.
598 %
599 % \DescribeMacro{\questionpreamble}
600 % If |\questionpreamble| is called, then its contents are displayed
601 % just before the start of the next question. This is useful for text like
602 % |\questionpreamble{And one of\dots}| which might reinforce information in
603 % the examination rubric.
604 %
605 % \subsection{Preamble}
606 % \label{s:preamble}
607 %
608 % \DescribeMacro{\exambanner}
609 % The |\exambanner| macro supplies text like `Examination for the
610 % degrees of\dots'.
611 % Since the contents of this command is automatically uppercased in
612 % some styles, and there are per-department specifics about the punctuation
613 % of abbreviations, you should use the commands |\BSc|, |\MSci|, and
614 % friends (see \secref{s:othercommands}) to set the degree names
615 % appropriately.
616 %
617 % \DescribeMacro{\universitycoursecode}
618 % \DescribeMacro{\degreedescriptions}
619 % \DescribeMacro{\coursetitle}
620 % Declare the identity of the exam with
621 % |\universitycoursecode|, |\schoolcoursecode|, |\coursetitle| and
622 % |\degreedescriptions|. The distinction between these is as follows:
623 % \begin{description}
624 % \item[University course code]
625 % This is the code for the course (and thus for the paper) as it
626 % appears in university information systems, and is a
627 % university-unique code such as `PHYS3031'.
628 % \item[Course title]
629 % This is just a textual name for the course, for example `Quantum Mechanics'.
630 % \item[Degree descriptions]
631 % This is a textual description of the qualifications that the
632 % students doing this exam are heading for. This text has little
633 % formal weight, but might help a lost student realise they're in
634 % completely the wrong exam room\dots. This is something like
635 % |{Physics 3\\Chemical Physics 3}| (separate each description
636 % using |\\|).
637 % \end{description}
638 % All of these are required elements, and the \LaTeX\ compilation will
639 % halt if they are absent. If for some reason the exam
640 % paper does not need these to be present -- perhaps it is a class
641 % test, for example -- then give the class option
642 % \Lopt{sloppydescription}, and the checks for these elements (and for
643 % |\rubric|) are suppressed. The layout may end up looking a little
644 % funny.
645 %
646 % \DescribeMacro{\schoolcoursecode}
647 % There is also a command |\schoolcoursecode|, which is a more
648 % informal, but possibly more recognisable, code for the course/paper,
649 % as it is generally recognised within the school; for example, the
650 % honours Quantum Mechanics course is known within the school as
651 % P304H. Its use is optional.
652 %
653 % \DescribeMacro{\paperident}
654 % It can be convenient to add some identification to each page, if for
655 % no other reason than to double-check that you haven't inserted a
656 % field theory question into an `astronomy for poets' exam. The command |\paperident|
657 % allows you to declare some text which appears at the bottom of each
658 % page of the exam. It will typically repeat some of the text in the
659 % |\schoolcoursecode| or |\degreedescriptions| arguments.
660 % This is generally not necessary, however, as in its absence the
661 % class generates an identifier. This identifier contains the name of
662 % the exam, plus a pair of counters (for example \emph{QM2/98-1177}). The
663 % function is two-fold: (i) since the counters increase monotonically
664 % (they actually encode the date and time when the document
665 % was \LaTeX ed), you can tell which of two superficially similar
666 % documents is the later; and (ii) if you drop a sheaf of papers on the
667 % photocopier floor, you can work out which one is which.
668 %
669 % \DescribeMacro{\examdate}
670 % \DescribeMacro{\examtime}
671 % Give the date and time of the exam with |\examdate| and |\examtime|.
672 % Sometimes an exam may
673 % have different time limits for different qualifications: this case,
674 % separate the various times with |\\|, as in
675 % \cmd|\examtime{9.30am -- 12 noon\\ (or) 9.30am -- 1.45am}|.
676 %
677 % \DescribeMacro{\rubric}
678 % \DescribeMacro{\norubric}
679 % The rubric, provided unsurprisingly by the command |\rubric|, may
680 % contain more than one paragraph,
681 % delimited by the usual blank line. Any emphasised words should be
682 % marked with |\emph| -- they are typically
683 % emphasised with a bold font. The class checks that a rubric has
684 % been specified (unless \Lopt{sloppydescription} is present); if you
685 % really wish to suppress this rubric -- perhaps because the
686 % |\baserubric| is sufficient -- then give the command |\norubric|.
687 % \DescribeMacro{\baserubric}
688 % As well as this exam-specific rubric, the style produces an additional
689 % boilerplate rubric, containing the usual material such as `Do not on
690 % any account attempt to write on both sides of the paper at once.
691 % Calculations may be done on the fingers, but candidates should avoid
692 % counting on their toes unless special permission has been obtained beforehand.'
693 % You will typically not have to change this, but if you do for some
694 % reason, you can override it with the |\baserubric| command.
695 %
696 % Note that the |\baserubric| command is typically used within a |.clo|
697 % file, within the argument to |\OverrideFormatting|. If you wish to
698 % further override this on a per-exam basis, then you will need to do
699 % so after |\OverrideFormatting| has done its work, and thus
700 % immediately after the |\begin{document}|.
701 %
702 % \DescribeMacro{\numquestions}
703 % Finally, declare the number of questions which are to be in the
704 % paper with |\numquestions|.
705 % The class issues a warning if we don't have this number, in draft or
706 % final mode. This is optional -- no check is done if this isn't present.
707 %
708 %
709 % \subsection{Other useful commands}
710 % \label{s:othercommands}
711 %
712 % \DescribeMacro{\BSc\ and friends}
713 % Macros |\BSc|, |\MSci|, |\MSc|, |\MA|, |\MEng| and |\BEng| are used
714 % within the preamble macros to give appropriately capitalised and punctuated
715 % versions of the degree types.
716 %
717 % \DescribeMacro{\vec}
718 % Macro |\vec| is redefined to give bold-font vectors, rather than
719 % vectors with arrows, which is the (weird) \LaTeX\ default. This
720 % should work for bold greek as well as roman.
721 %
722 % \DescribeMacro{\dd}
723 % Macros |\dd| and |\ddd|: |\dd| is a roman d, as used for
724 % differentials; |\ddd| is the same with a preceding thinspace,
725 % as used within integrals; for example
726 % \[
727 % |\int f(x)\ddd x = \int f(x)\,\dd x| = \int f(x)\ddd x
728 % \]
729 %
730 % \DescribeMacro{\Diffl}
731 % You can typeset derivatives neatly:
732 % \begin{center}
733 % \def\dd{\mathrm{d}}
734 % \begin{tabular}{ll}
735 % |\Diffl{a}{b}| & $\displaystyle \Diffl ab$ \\[2ex]
736 % |\Diffl[2]{a}{b}| & $\displaystyle \Diffl[2]ab$\\[2ex]
737 % |\Diffl*{a}{b}| & $\Diffl* ab$ \\
738 % |\Diffl*[2]{a}{b}| & $\Diffl*[2]ab$\\
739 % \end{tabular}
740 % \end{center}
741 % The unstarred versions are for displayed equations, the starred
742 % ones for inline maths.
743 % \DescribeMacro{\Partial}
744 % There is analogous support for partial derivatives with |\Partial|.
745 %
746 % \DescribeMacro{\units}
747 % You should generally type units, and numbers with units, using
748 % the \Lpackage{siunitx} package, which is loaded by the
749 % \Lopt{siunitx} option (which is now enabled by default). However
750 % this class currently also supports a basic |\units| command,
751 % described below. This macro will be removed in a future version
752 % of the class.
753 %
754 % Macros |\units|, |\units*|: you can typeset physical units in
755 % |\rm|, with tilde or dot
756 % acting as a separator between units. Since this is typeset in maths mode, all
757 % other spacing is ignored. The unstarred version includes
758 % leading |\thinspace|, as in |$v=10\units{m.s^{-1}}$|, giving
759 % $v=10\units{m.s^{-1}}$. The starred
760 % version can be used when referring to the unit by itself
761 % (eg axis is |$B/\units*T$|, or $B/\units*T$), and is not
762 % qualifying a number.
763 %
764 % \def\cs#1{$\backslash$\texttt{#1}}
765 % For other useful symbols, see table~\ref{t:symbols}.\footnote{The
766 % package used to support an \cs{au} macro, for astronomical
767 % unit, and \cs{lambdabar} for Compton wavelength, but these have
768 % since been removed. The former is available via
769 % \Lpackage{siunitx}.}
770 %
771 % \begin{table}
772 % \hrule \medskip
773 % \begin{tabular}{rlp{8cm}}
774 % |\e|&$\e^{i\pi}=-1$& the exponential is typeset in an upright rather than
775 % italic shape, as in |$\e^{i\pi}=-1$|.\\
776 % \end{tabular}
777 % \caption{\label{t:symbols}Miscellaneous symbols}
778 % \medskip\hrule
779 % \end{table}
780 %
781 %
782 % \section{Customising the exam style}
783 % \label{s:custom}
784 %
785 % As described in \secref{s:options} above, any unrecognised
786 % options are interpreted as an instruction to search for and include
787 % a class options file, formed from the name of the unrecognised
788 % option, suffixed with \file{.clo}, which can be anywhere in the
789 % \TeX\ include path. This options file has a fair amount of leeway
790 % to override and adjust the layout of the exam.
791 %
792 % The most typical changes here will be to adjust the exam rubric for
793 % a particular class, with the command |\baserubric|, and to change the
794 % sheet of physical constants, with the command |\constantssheet|.
795 % See the sample file |myclass.clo| for examples.
796 %
797 % Examine this sample \file{SpecialExam.clo} file:
798 % \begin{verbatim}
799 % \typeout{Physics Special exam options, for Special people}
800 % \ExecuteOptions{pageperquestion}
801 %
802 % \OverrideFormatting{
803 % \renewcommand\FormatPartMarks[1]{\{#1\}}
804 % \renewcommand\FormatPartNumber
805 % {\hbox to 0pt{\hss (\StylePartNumber{partnumber})\hskip1em}}
806 % \let\StylePartNumber\roman % as opposed to \alph
807 % \renewcommand\FormatQuestionNumber
808 % {\hbox to 0pt{\hss \textbf{\@currentquestion}\hskip2.5em}}
809 % }
810 %
811 % \constantssheet{
812 % \begin{center}
813 % $E=mc^2$ and $c=3\times10^8 {\rm m\,s^{-1}}$
814 % \end{center}
815 % }
816 % \end{verbatim}
817 % This announces itself, then invokes the exam style's \Lopt{pageperquestion}
818 % option.
819 %
820 % It then includes a number of formatting adjustments,
821 % enclosed within the |\OverrideFormatting| command; the formatting
822 % hooks are described below.
823 %
824 % Then it declares a `constants sheet', which is a display of
825 % constants or equations, or indeed anything else, which is to be
826 % displayed on the second page of the exam.
827 %
828 % The available formatting hooks are as follows:
829 % \begin{description}
830 %
831 % \item[FormatPartMarks]
832 % This formats the indication of the marks carried by a particular
833 % part of a question. In this case, we have chosen to have the marks
834 % contains inside curly brackets, rather than the default square
835 % brackets. By default, the part-marks text will be placed at the end
836 % of the paragraph it completes, flush right, and with at least 2em of
837 % space before it. You can change this default space with
838 % |\@partmarksspace|; as a special case, you can have the text sitting
839 % in the margin instead, by having |\FormatPartMarks| generate a
840 % zero-width box, and setting |\@partmarksspace=0pt|.
841 %
842 % \item[FormatPartNumber]
843 % This overrides how to format the various |\part| markers within a
844 % question, using the \texttt{partnumber} counter. In this case, the
845 % markers will jut into the left-hand margin, rather than being
846 % run-in.
847 %
848 % \item[StylePartNumber]
849 % This overrides how to style the |\part| markers. The default is
850 % |\alph|, but you might prefer, for example, |\Roman| or |\arabic|.
851 % Override this with |\let\StylePartNumber\Roman|.
852 %
853 % \item[FormatQuestionNumber]
854 % If you adjust the part marks, you should probably adjust the
855 % formatting of the question number also.
856 % \end{description}
857 %
858 % If you really want to go to town on reformatting, you can redefine
859 % the command |\maketitle|, which formats the front-page title. When
860 % formatting this, you have access to each of the fragments of text
861 % described in \secref{s:preamble}, via a macro named after the
862 % corresponding command. Thus the argument of the |\exambanner| command
863 % is available in the macro |\@exambanner|. The exception is
864 % |\numquestions|. If you find yourself needing to do this, it might
865 % be worth having a discussion with the style's maintainer -- there
866 % may be a simpler way to get what you want.
867 %
868 % \DescribeMacro{\CheckExamMetadata}
869 % One of the things you may change within the |\maketitle| is the
870 % checking of exam metadata -- which fields are required and which are
871 % optional. You can change these from the default (in
872 % \secref{s:preamble}) by defining a command |\CheckExamMetadata|.
873 % \DescribeMacro{\RequiredMetadata}
874 % This macro takes no arguments, and should use the command
875 % \cmd|\RequiredMetadata{<field>}{<description>}{<help-text>}| to
876 % perform its tests.
877 % {\catcode`\<=\active Here <field> is the metadata key, such as
878 % |{examdate}|, which corresponds to the macro |\examdate|, <description> is
879 % a brief description of the field, such as |{exam date}|, and
880 % <help-text> is a longer bit of explanation. If the corresponding
881 % data is missing, then \LaTeX\ stops with an error, and the user can
882 % examine the <help-text> by pressing the \texttt h key. You can
883 % adjust the test by examining the value of
884 % |\iffussydescription ... \fi|, which is set to |\false| if the \Lopt{sloppydescription}
885 % option was provided.}
886 %
887 % No more clues. If you want to hack at this, see the definition of
888 % |\maketitle| in the class file \file{exam-n.cls}.
889 % Aspire not to break things.
890
891 % \iffalse %%%CONFIGURE%%% change the following to iffalse for a locally-distributed version\fi
892 % \iftrue
893 % \section{A work-flow}
894 % This class file was developed as part of a move to `\LaTeX ify' the
895 % production of exams in the School of Physics and Astronomy, in the
896 % University of Glasgow. The work-flow which emerged was, roughly, as
897 % follows:
898 % \begin{enumerate}
899 % \item The exam convener (the person in charge of assembling the exam
900 % for a given course or lecture series) creates a Sharepoint directory
901 % which contains a master file
902 % (which consists mostly of |\includequestion| macros),
903 % plus subdirectories each containing a short template file for the
904 % benefit of question authors, and a copy of the
905 % \texttt{notes-for-authors.pdf} instructions.
906 % \item Each of those `question' directories is made visible to, and
907 % read-writable by, the lecturer responsible for that question. They
908 % write and \LaTeX ed their question, and upload it back to
909 % Sharepoint.
910 % \item The exam convener, who has access to the whole tree of
911 % questions, downloads or network-mounts the Sharepoint folder, and
912 % either edits the questions or negotiates with the authors, until
913 % the exam \LaTeX s successfully. The result can then be
914 % snapshotted, and sent off to the external examiner.
915 % \end{enumerate}
916 % This provides a centralised and easily manageable repository
917 % for a previously fiddly and error-prone process.
918 %
919 % In step one, the template file is just one with a \texttt{[compose]}
920 % option, following the brief example on p.\pageref{s:includequestion}.
921 % We had excellent secretarial help to manage this step; it was fiddly the
922 % first couple of times, but largely mechanical thereafter. In Sharepoint,
923 % this step can in principle be automated, though we concluded this
924 % was unnecessary in our case.
925 %
926 % Sharepoint (possibly slightly surprisingly) worked smoothly for us;
927 % in other circumstances a group-writable source code repository, or
928 % an institutional CMS, or even just a shared drive, would work just
929 % as well. The advantage of Sharepoint, from our point of view, was
930 % that it integrated with the university's existing authentication
931 % framework, and was (axiomatically) acceptably secure for the process
932 % of creating exams.
933 %
934 % The majority of our authors were habitual users of \LaTeX\ for
935 % writing journal articles, and with subsequently submitting them to
936 % journals or the arXiv; and when the process was presented in
937 % those terms, with the same advantages, it was readily accepted.
938 %
939 % Thanks to Graham Woan and Rachael MacLaughlan for the numerous
940 % iterations of this process until both it and the class file were stable.
941 % \fi
942
943 % \section{Example}
944 %
945 % Here is a short example file. There are further examples in the
946 % \texttt{sample/} directory of the distribution.
947 % \begin{macrocode}
948 %<*example>
949 %%%START example (Makefile strips out this block)
950 \documentclass{exam-n} % standard final version
951 %%\documentclass[draft,showsolutions]{exam-n} % draft style, showing solutions
952 %%\documentclass[compose]{exam-n} % compose (author's) style
953
954 \examdate{Wednesday, 18 May 2005}
955 \examtime{9.30am -- 12 noon\\(or) 9.30am -- 1.45am}
956
957 \exambanner{Examination for the Degrees of \BSc(Science) and
958 \MSci\ on the Honours Standard}
959 \schoolcoursecode{P304D and P304H}
960 \universitycoursecode{PHYS3031 and PHYS4025}
961 \coursetitle{Quantum Mechanics}
962 %\degreedescriptions{Physics 3, Chemical Physics 3, Physics with
963 % Astrophysics 3, Theoretical Physics 3M, Joint Physics 3}
964 \degreedescriptions{Physics 3\\Chemical Physics 3\\Physics with
965 Astrophysics 3\\Theoretical Physics 3M\\Joint Physics 3}
966 \paperident{GR/P304}
967
968 \rubric{Candidates for examination in \emph{Quantum Mechanics} should
969 answer question 1 (16 marks) and \emph{either 2A or 2B} (24 marks each)}
970
971 \numquestions{3}
972
973 \begin{document}
974 \maketitle
975
976 \section{I}
977
978 \begin{question}{20}
979 \part At various points in the development of the mathematical theory of
980 General Relativity, we pick a coordinate system in which
981 differentiation is simple, and do a calculation using non-covariant
982 differentiation, indicated by a comma. We then immediately deduce the
983 covariant result, replacing this comma with a semicolon.
984
985 Separately, the strong equivalence principle is sometimes
986 referred to as the `comma goes to semicolon' rule.
987
988 Explain the logic of each of these replacements of a comma with a
989 semicolon, putting particular stress on the distinction between
990 them.\partmarks{10}
991
992 \part The radial and angular coordinates, $r$ and $\phi$ respectively,
993 of a test particle moving in the Schwartzschild metric exterior to a
994 star of mass $M\ll r$, are related by the equation
995 \[
996 r = \frac{h^2}M \left(
997 1 + e\cos\phi + \frac{3M^2}{h^2}e\phi\sin\phi
998 \right)^{-1},
999 \]
1000 where $h$ and $e$ are constants. Show that this equation takes the
1001 form of a precessing ellipse, of semi-latus rectum $l=h^2/M$, in which
1002 the pericentre line advances each orbit by an amount
1003 $\Delta=6\pi M^2/h^2$, stating clearly any assumptions that
1004 you make.\partmarks{6}
1005
1006 The solar-mass star HD83443 has a 0.35 Jupiter-mass planet that
1007 follows a circular orbit of period 2.986 days and radius \SI{0.038}{\astronomicalunit}.
1008 Calculate the rate of precession, in arcseconds per year, of the
1009 pericentre line of the planet's orbit.\partmarks{4}
1010
1011 [Schwartzschild radius of the Sun: \SI{3e3}m; $\SI1\astronomicalunit = \SI{1.5e11}m$]
1012
1013 \begin{solution}
1014 In the first type of calculation, we do a calculation in the LIF, in
1015 which~$\Gamma^i_{jk}=0$, so that single partial differentiation is the
1016 same as covariant differentiation. If this process produces a
1017 geometrical object such as a scalar or a tensor, then we know that the
1018 result is frame-invariant. If the result involves only single partial
1019 differentiation -- that is, no second derivatives -- then since
1020 partial differentiation is the same as covariant differentiation in
1021 these coordinates, we cannot distinguish partial and covariant
1022 derivatives, and can replace the commas by semicolons. Since these
1023 are now manifestly covariant derivatives, so that the result is a
1024 tensor, and thus frame-invariant, the same expression would be true in
1025 any frame.
1026
1027 The second situation is the statement that the expressions of physical
1028 laws in SR, such as the conservation equation
1029 $T^{\mu\nu}_{,\nu}=0$, must take the same \emph{form} when written
1030 as a covariant equation in GR, crucially without any curvature
1031 coupling. The slogan `comma goes to semicolon' is just a mnemonic for
1032 this.
1033
1034 The distinction is that the first is a mathematical trick, of sorts,
1035 whereas the second is a version of the equivalence principle, and thus
1036 a statement with deep physical content.
1037
1038 They don't have to explain things at this length or with this
1039 coherence (?) to get quite a few marks. They just have to show they
1040 have a clue.
1041 \end{solution}
1042 \end{question}
1043
1044 \end{document}
1045 %%%END example
1046 %</example>
1047 % \end{macrocode}
1048 %
1049 % \section{Release notes}
1050 % Recent release notes are below. For older notes, see the source
1051 % distribution.
1052 %
1053 % \input{release-notes.dtx}
1054 %
1055 % \subsection*{Acknowledgements}
1056 % \addcontentsline{toc}{subsection}{Acknowledgements}
1057 %
1058 % This class has greatly benefitted from comments and bug-reports from
1059 % Harry Ward, Graham Woan, and Nicolas Labrosse;
1060 % and it has received code contributions from Morag Casey.
1061 %
1062 % \StopEventually{}
1063
1064 % \section{Implementation}
1065 %
1066 % \subsection{\LaTeX3 compatibility}\label{s:compatibility}
1067 %
1068 % As of release 1.4.0, we depend on the \LaTeX3 hooks mechanism, which
1069 % was introduced in 2020. We therefore cannot work with versions
1070 % older than that.
1071 %
1072 % Note that we can't use the (apparently preferable)
1073 % |\IfFormatAtLeastTF| command to do this test: we want to continue to
1074 % work even when we're using a \LaTeX\ which is too old for this
1075 % command to be defined.
1076 % \begin{macrocode}
1077 \@ifl@t@r\fmtversion{2020/10/01}
1078 {\typeout{Format is \fmtversion -- OK!}}
1079 {\ClassError{exam-n}
1080 {You need a more recent version of LaTeX}
1081 {This class now requires a
1082 LaTeX version at least 2020/10/01; version
1083 \fmtversion\ is too old}}
1084 % \end{macrocode}
1085 %
1086 % \subsection{Options}
1087 %
1088 % First, process the compose/draft/final option.
1089 % Flag |\@draftstatus| 0 represents the final version; 1 is a draft exam; 2 is a
1090 % single question being composed
1091 % \begin{macrocode}
1092 %<*package>
1093 \newcount\@draftstatus
1094 \@draftstatus=0 % default is final
1095 \DeclareOption{compose}{\@draftstatus=2
1096 \@showsolutionstrue
1097 \@pageperquestiontrue}
1098 \DeclareOption{draft}{\@draftstatus=1
1099 \@showsolutionstrue
1100 \@pageperquestionfalse}
1101 \DeclareOption{final}{\@draftstatus=0
1102 \@showsolutionsfalse
1103 \@pageperquestionfalse}
1104 % \end{macrocode}
1105 %
1106 % Set true to use PostScript fonts
1107 % \begin{macrocode}
1108 \newif\if@psfonts\@psfontsfalse
1109 \DeclareOption{psfonts}{\@psfontstrue}
1110 \DeclareOption{cmfonts}{\@psfontsfalse}
1111 % \end{macrocode}
1112 %
1113 % Given that we're using PS fonts, should we use the mathtime fonts,
1114 % rather than just the mathptm ones (which aren't really ideal)? It
1115 % turns out that we can't test for the presence of the mathtime fonts
1116 % from within this class file -- the only reliable way of checking if
1117 % they're present is to look for something like rmtmi.pfa, but
1118 % |\IfFileExists| isn't able to search for any of those files, only ones
1119 % on the \texttt{TEXINPUTS} path such as \texttt{mathtime.sty}, which can be, and are
1120 % often, installed without the fonts themselves being present.
1121 % \begin{macrocode}
1122 \newcount\examn@mtselect \examn@mtselect=0
1123 \DeclareOption{mathptm}{\@psfontstrue\examn@mtselect=0}
1124 \DeclareOption{mathtime}{\@psfontstrue\examn@mtselect=1}
1125 \DeclareOption{mtpro2}{\@psfontstrue\examn@mtselect=2}
1126 \DeclareOption{stix2}{\@psfontstrue\examn@mtselect=3}
1127 % \end{macrocode}
1128 %
1129 % The letter $\pi$ is usually the circular constant, and as such
1130 % should be set in an upright greek font. Don't this by default,
1131 % since that goes against the usual \LaTeX\ default, but instead
1132 % define the [uprightpi] option to support this, where possible.
1133 % Not all fonts make this easy.
1134 % \begin{macrocode}
1135 \newif\ifexamn@uprightpi \examn@uprightpifalse
1136 \DeclareOption{uprightpi}{\examn@uprightpitrue}
1137 % \end{macrocode}
1138 %
1139 % Load the \Lpackage{siunitx} package, or not, defaulting yes.
1140 % This is now preferred to the |\units| macro, and the latter will be
1141 % removed in a forthcoming release.
1142 % \begin{macrocode}
1143 \newif\ifexamn@siunitx \examn@siunitxtrue
1144 \DeclareOption{siunitx}{\examn@siunitxtrue}
1145 \DeclareOption{nosiunitx}{\examn@siunitxfalse}
1146 % \end{macrocode}
1147 %
1148 % Switch between serif and sans serif fonts. We make little attempt
1149 % to make the latter attractive; this is purely to conform to the
1150 % superstition (there seem no more grounds than that) that this is
1151 % better for dyslexic students.
1152 % \begin{macrocode}
1153 \newif\ifexamn@serif
1154 \examn@seriftrue
1155 \DeclareOption{serif}{\examn@seriftrue}
1156 \DeclareOption{sansserif}{\examn@seriffalse}
1157 % \end{macrocode}
1158 %
1159 % Set |\if@showsolutions| true if we are to show the contents of {solution} environments
1160 % \begin{macrocode}
1161 \newif\if@showsolutions
1162 \@showsolutionsfalse
1163 \DeclareOption{showsolutions}{\@showsolutionstrue}
1164 \DeclareOption{noshowsolutions}{\@showsolutionsfalse}
1165 % \end{macrocode}
1166 %
1167 % Set |\if@pageperquestion| true if we want a new page after each question
1168 % (set when printing solutions)
1169 % \begin{macrocode}
1170 \newif\if@pageperquestion
1171 \@pageperquestionfalse
1172 \DeclareOption{pageperquestion}{\@pageperquestiontrue}
1173 \DeclareOption{nopageperquestion}{\@pageperquestionfalse}
1174 % \end{macrocode}
1175 %
1176 % Set |\if@perquestionmarks| true if we are to expect a marks total to
1177 % be specified in the question, subtotals to be specified in the
1178 % question, and to include a check, at the end, that the two match up.
1179 % \begin{macrocode}
1180 \newif\if@perquestionmarks
1181 \@perquestionmarkstrue
1182 \DeclareOption{perquestionmarks}{\@perquestionmarkstrue}
1183 \DeclareOption{noperquestionmarks}{\@perquestionmarksfalse}
1184 % \end{macrocode}
1185 %
1186 % Set |\if@showmarktotals| true if we are to display the expected (and
1187 % checked to be actual) total marks at the end of the question.
1188 % \begin{macrocode}
1189 \newif\if@showmarktotals
1190 \@showmarktotalstrue
1191 \DeclareOption{showmarktotals}{\@showmarktotalstrue}
1192 \DeclareOption{noshowmarktotals}{\@showmarktotalsfalse}
1193 % \end{macrocode}
1194 %
1195 % Support the standard article oneside/twoside options, even though
1196 % they do nothing in this class.
1197 % \begin{macrocode}
1198 \newif\if@twosidepages
1199 \@twosidepagesfalse
1200 \DeclareOption{twoside}{\@twosidepagestrue}
1201 \DeclareOption{oneside}{\@twosidepagesfalse}
1202 % \end{macrocode}
1203 %
1204 % Some options styles want \Lopt{fleqn}, so make it an option to this
1205 % class, to be passed on to article and amsmath.
1206 % \begin{macrocode}
1207 \newif\if@fleqn
1208 \@fleqnfalse
1209 \DeclareOption{fleqn}{
1210 \@fleqntrue
1211 \PassOptionsToPackage{fleqn}{amsmath}
1212 \PassOptionsToClass{fleqn}{article}
1213 }
1214 % \end{macrocode}
1215 %
1216 % If \Lopt{sloppydescription} is given, then we don't demand that all
1217 % the required exam metadata is provided. Failing this, we object, fatally, to
1218 % missing information.
1219 % \begin{macrocode}
1220 \newif\iffussydescription
1221 \fussydescriptiontrue
1222 \DeclareOption{sloppydescription}{\fussydescriptionfalse}
1223 % \end{macrocode}
1224 %
1225 % The university logo is typeset in colour by default; the \Lopt{mono}
1226 % option causes everything to be in mono instead. The \Lopt{colour}
1227 % option does nothing, but is present for symmetry. These have to be
1228 % |\def|s, by the way, not |\let|s, since the size macros aren't
1229 % defined until after \Lpackage{article} has been loaded. It seems
1230 % prudent to make the `showing solutions' text a bit more shouty in
1231 % this monochrome case.
1232 % \begin{macrocode}
1233 \def\examn@header@shoutformat#1{{\Large\bfseries #1}}
1234 \DeclareOption{mono}{
1235 \PassOptionsToPackage{monochrome}{xcolor}
1236 \def\examn@header@shoutformat#1{{\Huge\bfseries #1}}
1237 }
1238 \DeclareOption{colour}{}
1239 % \end{macrocode}
1240 %
1241 % Options \Lopt{largefont} and \Lopt{hugefont} print versions of the
1242 % exam in `big' or `huge' font sizes, to help students with visual impairments.
1243 % The available font variants are represented as numbers.
1244 % Note: the |\examn@fontvariant| mechanism is in principle more
1245 % general than simply size variants, but some of the code below
1246 % assumes that |\examn@fontvariant| greater than zero means large
1247 % text, and so would need to be adjusted if this becomes untrue.
1248 %
1249 % The flag |\ifbigfont| is true if the font is `significantly large',
1250 % in the sense that exam text, or hyphenation or layout, may have to
1251 % be adjusted in this case:
1252 % option \Lopt{hugefont} sets it true, option \Lopt{largefont} does
1253 % not. It's intended to be a user-visible and -settable flag.
1254 %
1255 % \emph{Note:} the \Lopt{hugefont} option used to be \Lopt{bigfont};
1256 % the latter is deprecated and may be removed in v1.2.
1257 % \begin{macrocode}
1258 \newcount\examn@fontvariant
1259 \examn@fontvariant=0 % the default
1260 \newif\ifbigfont
1261 \bigfontfalse
1262 \DeclareOption{largefont}{\examn@fontvariant=1 \bigfontfalse}
1263 % Deprecate [bigfont]; consider removing in v1.2
1264 \DeclareOption{bigfont}{%
1265 \ClassWarning{exam-n}{OPTION [bigfont] HAS BEEN DEPRECATED; use [hugefont] instead}
1266 \examn@fontvariant=2 \bigfonttrue}
1267 \DeclareOption{hugefont}{\examn@fontvariant=2 \bigfonttrue}
1268 % \end{macrocode}
1269 %
1270 % This class is based on the article class. Load it, and pass the \texttt{a4paper}
1271 % option to it.
1272 % \begin{macrocode}
1273 \PassOptionsToClass{a4paper}{article}
1274 % \end{macrocode}
1275 %
1276 % We allow \file{.clo} files to override elements of the formatting,
1277 % such as |\maketitle| and the various |\Format...| hooks. They must
1278 % do this within a |\OverrideFormatting| command, using a sequence of
1279 % |\renewcommand|s. Carefully.
1280 % \begin{macrocode}
1281 \newtoks\@styleoverrides
1282 \@styleoverrides={}
1283 \def\OverrideFormatting{\@styleoverrides=}
1284 % \end{macrocode}
1285 %
1286 % There are a few other settings which may be defaulted within a
1287 % \file{.clo} file:
1288 % \begin{itemize}
1289 % \item |\constantsheet{...}|: is a table of, for example, physical
1290 % constants which should appear in exams associated with a particular
1291 % course. Despite the name, this can be any text which should appear
1292 % on the first non-cover sheet of the exam.
1293 % \item |\baserubric|: a modified `base rubric' -- see the
1294 % documentation of |\rubric| below.
1295 % \end{itemize}
1296 %
1297 % If \@constantssheet is defined (using |\constantsheet{...}| in a
1298 % .clo file), then display it on a page by itself.
1299 % \begin{macrocode}
1300 \newtoks\@constantstoks
1301 \def\@@displayconstants{%
1302 \clearpage
1303 \begingroup
1304 \the\@constantstoks
1305 \endgroup
1306 \clearpage }
1307 % \end{macrocode}
1308 % The macro |\constantssheet| has to be declared here, rather in the
1309 % more natural place below, with \@exambanner and friends, so that
1310 % it's usable within .clo files.
1311 % \begin{macrocode}
1312 \newtoks\@constantstoks
1313 \@constantstoks={}
1314 \let\@displayconstants\relax
1315 \def\constantssheet{\let\@displayconstants\@@displayconstants
1316 \@constantstoks=}
1317 % \end{macrocode}
1318 %
1319 % Similarly for the |\baserubric| and |\rubric| commands.
1320 %
1321 % The rubric is typically a per-exam thing. The `base rubric' is
1322 % more-or-less common to all exams, though it's possible to override
1323 % it in a .clo file.
1324 % \begin{macrocode}
1325 \def\@rubric{}
1326 \def\rubric{\long\def\@rubric}
1327 \def\norubric{\let\@rubric\@nnil}
1328 % \end{macrocode}
1329 % \dots and the base rubric:
1330 % \begin{macrocode}
1331 \def\@baserubric{%
1332 \textbf{Answer each question in a separate booklet}\par
1333 Candidates are reminded that devices able to store or display text or
1334 images may not be used in examinations without prior arrangement.
1335 \if@perquestionmarks
1336 \par
1337 Approximate marks are indicated in brackets as a guide for candidates.
1338 \fi
1339 }
1340 \def\baserubric{\long\def\@baserubric}
1341 % \end{macrocode}
1342 %
1343 % The |\defaultpartmarkscategory| macro creates a default partmarks
1344 % `category'. See below. This is declared here, so that it can be
1345 % used in a |.clo| file without error.
1346 % \begin{macrocode}
1347 \let\examn@defaultpartmarkscategory\relax
1348 \def\defaultpartmarkscategory#1{\def\examn@defaultpartmarkscategory{#1}}
1349 % \end{macrocode}
1350 %
1351 % Spit out the style overrides at the beginning of the document,
1352 % rather than here.
1353 % \begin{macrocode}
1354 \AtBeginDocument{\the\@styleoverrides}
1355 % \end{macrocode}
1356 %
1357 % Any remaining options are interpreted as filenames, and the
1358 % corresponding \file{.clo} file is read in. We do not permit any
1359 % other options, for example standard |{article}| options.
1360 % There's a complication here (which I haven't resolved, to my
1361 % puzzlement): if the .clo file includes for example
1362 % |\ExecuteOptions{pageperquestion}|, then a \Lopt{nopageperquestion}
1363 % appearing after the .clo option in the |\documentclass| line appears
1364 % to be ignored or overwritten, which is odd, since I thought that
1365 % options were executed in order; are these file options executed
1366 % later than others, perhaps?
1367 % \begin{macrocode}
1368 \DeclareOption*{\InputIfFileExists{\CurrentOption.clo}{}
1369 {\ClassError{exam-n}
1370 {Bad option \CurrentOption}
1371 {I don't understand the option \CurrentOption\MessageBreak
1372 (I didn't find file \CurrentOption.clo, if that's what you meant)}}}
1373 % \end{macrocode}
1374 %
1375 % The default options are set when the options are declared, above.
1376 %
1377 % If a file called \texttt{exam-n.config} exists, read it in. It may
1378 % usefully contain other |\ExecuteOptions{foo}| commands. Note that
1379 % these supplement but \emph{will not override} any options in the
1380 % |\documentclass| command; thus these are really only useful for
1381 % changing away from the default. This last behaviour is
1382 % unsatisfactory: it would be better if this would reliably override
1383 % any options supplied in |\documentclass|, but that turns out to be
1384 % hard to fix, given the \LaTeX\ option logic.
1385 % \begin{macrocode}
1386 \InputIfFileExists{exam-n.config}{}{}
1387 % \end{macrocode}
1388 % And finally process all the options marked so far.
1389 % \begin{macrocode}
1390 \ProcessOptions
1391 % \end{macrocode}
1392 %
1393 % \subsection{Dependencies}
1394 %
1395 % We depend on the \Lpackage{article} class.
1396 %
1397 % Note: we have to do this this way, so that
1398 % |\PassOptionsToClass{*side}{article}| is invoked only once --
1399 % \Lenv{article} gets confused if both options are passed to it
1400 % \begin{macrocode}
1401 \if@twosidepages
1402 \PassOptionsToClass{twoside}{article}
1403 \else
1404 \PassOptionsToClass{oneside}{article}
1405 \fi
1406 \PassOptionsToClass{12pt}{article}
1407 % \end{macrocode}
1408 %
1409 % If the document includes
1410 % the \Lpackage{graphicx} or \Lpackage{pdfpages} packages,
1411 % then we don't want the \Lopt{draft} option to be passed on.
1412 % So explicitly pass the \Lopt{final} option to these packages.
1413 % \begin{macrocode}
1414 \PassOptionsToPackage{final}{graphicx}
1415 \PassOptionsToPackage{final}{pdfpages}
1416 % \end{macrocode}
1417 %
1418 % %%%CONFIGURE%%%
1419 % Define a logo for the University, which will appear in the exam header.
1420 % This should be a macro which takes a single argument giving the
1421 % required width of the logo, and which produces a |\vbox|.
1422 % \begin{macrocode}
1423 \def\UniLogo#1{\vbox to 15.5mm{%
1424 \hrule
1425 \vss\hbox to #1{% Aspect ratio of logo is 100x31
1426 \hss no logo available\hss
1427 }%
1428 \vss
1429 \hrule}}
1430 % \end{macrocode}
1431 %
1432 % Other required packages.
1433 % \begin{macrocode}
1434 \RequirePackage[english]{babel} % UK hyphenation
1435 \RequirePackage{amsmath}
1436 \ifexamn@siunitx
1437 \RequirePackage{siunitx}
1438 \fi
1439 % \end{macrocode}
1440 % We use the \Lpackage{xcolor} package, in preference to
1441 % \Lpackage{color}, so that we are compatible with TikZ (TikZ loads
1442 % the \Lpackage{xcolor} package internally, and that isn't compatible
1443 % with \Lpackage{color}). We could probably work around this some
1444 % other way, but \Lpackage{xcolor} seems to be relatively standard,
1445 % and appears to be backward compatible with \Lpackage{color},
1446 % so this change is harmless.
1447 % \begin{macrocode}
1448 \RequirePackage{xcolor}
1449 % \end{macrocode}
1450 %
1451 % I think flush-left equations look MUCH better than centred, but
1452 % Harry disagrees, so it's not the default.
1453 % \begin{macrocode}
1454 \LoadClass{article}
1455 % \end{macrocode}
1456 %
1457 % \subsection{Layout}
1458 %
1459 % \subsubsection{The \TeX\ engine}
1460 % Identify the \TeX\ engine we're using. If we are using pdf\TeX,
1461 % Xe\TeX, or Lua\TeX, we presume we're generating PDF. The
1462 % \Lpackage{ifpdf} package exists, and evaluates to true for Lua\TeX,
1463 % but doesn't distinguish between Xe- and Lua\TeX.
1464 % It would be nice to use a package such as \Lpackage{iftex}, but (as of late
1465 % 2017) this seems to do something sufficiently exotic with
1466 % respect to |\if| nesting, that it confuses the logic here.
1467 % It seems safer to do this test ourselves, so (a) we know what
1468 % we're getting, and (b) we have the result in a convenient integer form.
1469 % \begin{macrocode}
1470 \newcount\examn@engine
1471 \examn@engine=0
1472 \expandafter\ifx\csname pdfmatch\endcsname\relax
1473 \expandafter\ifx\csname XeTeXinterchartoks\endcsname\relax
1474 \expandafter\ifx\csname directlua\endcsname\relax
1475 \examn@engine=0 % this is presumably original-TeX (how unutterably retro!)
1476 \else
1477 \examn@engine=3
1478 \fi
1479 \else
1480 \examn@engine=2
1481 \fi
1482 \else
1483 \ifnum\pdfoutput>0
1484 \examn@engine=1
1485 \else
1486 % this _is_ pdftex, but it's in generate-dvi mode
1487 % (we decide not to detect this case with the other engines)
1488 \examn@engine=0
1489 \fi
1490 \fi
1491 % \end{macrocode}
1492 %
1493 % \subsubsection{Fonts}
1494 %
1495 % Choose the font set, based on |\if@psfonts| and |\examn@mtselect|.
1496 % The following is \emph{messy}, and it's not clear to me if it's
1497 % irreducibly so, or whether I'm just doing it the wrong way.
1498 %
1499 % Case |\examn@mtselect| is 0: the rather hacky \Lpackage{mathptm} solution.
1500 % \begin{macrocode}
1501 \def\ex@fontlabel{???}
1502 \if@psfonts
1503 \ifcase\examn@mtselect
1504 \def\ex@fontlabel{mathptm}
1505 \ifexamn@serif
1506 \RequirePackage{times}
1507 \else
1508 \RequirePackage{helvet}
1509 \fi
1510 \RequirePackage{mathptm}
1511 \ClassWarningNoLine{exam-n}{Using mathptm fonts}
1512 % \end{macrocode}
1513 %
1514 % Case |\examn@mtselect| is 1 or 2: use mathtime or Mathtime Pro 2 fonts
1515 % for maths. We use postscript Times and Helvetica for the body fonts
1516 % in both cases.
1517 % \begin{macrocode}
1518 \or
1519 \def\ex@fontlabel{mathtime}
1520 \RequirePackage[LY1]{fontenc} % specify text font encoding
1521 \RequirePackage[LY1,mtbold]{mathtime} % switch math fonts
1522 \ifexamn@serif
1523 \RequirePackage{times}
1524 \else
1525 \RequirePackage{helvet}
1526 \fi
1527 \ClassWarningNoLine{exam-n}{Using Mathtime fonts}
1528 \or % use mtpro2 fonts
1529 \def\ex@fontlabel{mtpro2}
1530 \RequirePackage[T1]{fontenc}
1531 \RequirePackage{textcomp}
1532 \ifexamn@serif
1533 \renewcommand\rmdefault{ptm} % the default
1534 \else
1535 \RequirePackage[scaled=0.9]{helvet}
1536 \renewcommand\rmdefault{phv}
1537 \fi
1538 \RequirePackage[mtpbb]{mtpro2}
1539 \ClassWarningNoLine{exam-n}{Using MTPro2 fonts}
1540 % \end{macrocode}
1541 %
1542 % Finally, case |\examn@mtselect| is 3: use STIX2 fonts: \url{http://www.stixfonts.org}.
1543 % Since this requires fontspec, it also requires either XeLaTeX or
1544 % LuaLaTeX. If we are in this branch, and not using either
1545 % engine, then fail with what we hope is a reasonably clear error.
1546 %
1547 % First off, refuse to work with original TeX.
1548 % \begin{macrocode}
1549 \or
1550 \def\ex@fontlabel{stix2}
1551 \ifcase\examn@engine
1552 \ClassError{exam-n}
1553 {You can't use STIX fonts with original/DVI LaTeX}
1554 {You must use either XeLaTeX or LuaLaTeX}
1555 % \end{macrocode}
1556 %
1557 % Use of the STIX fonts with pdflatex mostly works, but there is a
1558 % tricky current/legacy issue here.
1559 % The \Lpackage{stix2} package is intended to use the STIX2
1560 % fonts with `legacy' \TeX\ engines. Does this apply to pdflatex, now
1561 % it defaults to unicode input? See the discussion of
1562 % \Lpackage{unicode-math} below.
1563 %
1564 % As of TeXLive 2022, this mostly works, in the sense that we do use STIX
1565 % fonts, but the upright-pi support below fails (no LaTeX errors, but
1566 % |\uppi| produces slanted pi).
1567 % \begin{macrocode}
1568 \or % pdflatex
1569 \RequirePackage{stix2}
1570 % \end{macrocode}
1571 %
1572 % We support only Xe\TeX\ and Lua\TeX\ here, since only these can use
1573 % `system' fonts. For Xe\LaTeX\ we use `system' Helvetica and Courier
1574 % fonts (slightly scaled) as the sans and mono fonts, respectively, for the sake of
1575 % completeness.
1576 %
1577 % Note: unicode-math is a little complicated. As I (unfortunately)
1578 % discovered via mistaken bug report
1579 % \url{https://github.com/stipub/stixfonts/issues/235},
1580 % the \Lpackage{stix} package is intended to be used \emph{only} for
1581 % `legacy' \TeX\ engines, and \Lpackage{unicode-math} for current ones
1582 % such as Xe\LaTeX\ and Lua\LaTeX.
1583 % I'm fairly confident (as of 2022 July 11) that the following does
1584 % the right thing, but not yet 100% confident.
1585 %
1586 % Note that (as explained in the \Lpackage{unicode-math} manual, we
1587 % should use the STIX Two \emph{Math} font for symbols, and not the
1588 % text font.
1589 % \begin{macrocode}
1590 \or % XeLaTeX
1591 \RequirePackage[bold-style=ISO,math-style=ISO]{unicode-math}
1592 \setmathfont{STIX Two Math}
1593 \setmainfont{STIX Two Text}
1594 \or % LuaLaTeX: like XeLaTeX
1595 \RequirePackage[bold-style=ISO,math-style=ISO]{unicode-math}
1596 \setmathfont{STIX Two Math}
1597 \setmainfont{STIX Two Text}
1598 \fi
1599 % \end{macrocode}
1600 % The no-match case shouldn't happen.
1601 % \begin{macrocode}
1602 \else
1603 \def\ex@fontlabel{ERROR}
1604 \ClassError{exam-n}
1605 {Impossible value of mtselect: \examn@mtselect}
1606 {This shouldn't happen -- this is a class file bug}
1607 \fi
1608 % \end{macrocode}
1609 %
1610 % There are no font complications when using CM fonts. That's nice.
1611 % \begin{macrocode}
1612 \else
1613 \def\ex@fontlabel{CM}
1614 \ClassWarningNoLine{exam-n}{Using CM fonts}
1615 \fi
1616 % \end{macrocode}
1617 %
1618 % Report what engine and font configuration we're using.
1619 % \begin{macrocode}
1620 \typeout{Environment:
1621 engine: \ifcase\examn@engine original/DVI\or pdfTeX\or XeTeX\or LuaTeX\else ???\fi;
1622 fonts: \ex@fontlabel;
1623 options: % show any non-default options
1624 \ifexamn@uprightpi uprightpi, \fi
1625 \ifexamn@siunitx siunitx, \fi
1626 \ifexamn@serif\else noserif, \fi
1627 \if@pageperquestion pageperquestion, \fi
1628 \if@perquestionmarks\else noperquestionmarks, \fi
1629 \if@showmarktotals\else noshowmarktotals, \fi
1630 \if@twosidepages twoside, \fi
1631 \if@fleqn fleqn, \fi
1632 \iffussydescription\else sloppydescription, \fi
1633 \ifbigfont hugefont, \fi
1634 \if@showsolutions showsolutions\else noshowsolutions\fi}
1635 % \end{macrocode}
1636 %
1637 % If we're using a sans serif font, then redefine |\normalfont| appropriately.
1638 % The macro |\examn@bodyfontchange| stores up these font changes until
1639 % they're applied just after |\maketitle|.
1640 % \begin{macrocode}
1641 \def\examn@bodyfontchange{}
1642 \ifexamn@serif \else
1643 \ClassWarningNoLine{exam-n}{Using sans serif fonts}
1644 \DeclareRobustCommand\normalfont
1645 {\usefont\encodingdefault\sfdefault\seriesdefault\shapedefault \relax}
1646 \fi
1647 % \end{macrocode}
1648 % And similarly for the case where we want large fonts.
1649 % This (as it turns out) requires changing only |\normalsize| and not
1650 % |\normalfont|, so the two are in principle compatible; however we
1651 % implement both of them by redefining |\examn@bodyfontchange|, so
1652 % they're not in practice (a future fix, perhaps).
1653 % \begin{macrocode}
1654 \ifcase\examn@fontvariant
1655 % default: do nothing
1656 \def\examn@bodyfontchange{
1657 % ...apart from redefine \small to be more clearly distinct from \normalsize
1658 \renewcommand\small{%
1659 \@setfontsize\normalsize{9}{11}%
1660 \abovedisplayskip 9\p@ \@plus1.5\p@ \@minus5\p@
1661 \abovedisplayshortskip \z@ \@plus2.5\p@
1662 \belowdisplayshortskip 5\p@ \@plus2.5\p@ \@minus2.5\p@
1663 \belowdisplayskip \abovedisplayskip}}
1664 \or
1665 % font variant 1: 18pt
1666 \def\examn@bodyfontchange{
1667 \renewcommand\normalsize{%
1668 \@setfontsize\normalsize{18}{24}%
1669 \abovedisplayskip 18\p@ \@plus3.5\p@ \@minus9\p@
1670 \abovedisplayshortskip \z@ \@plus5\p@
1671 \belowdisplayshortskip 10\p@ \@plus5\p@ \@minus5\p@
1672 \belowdisplayskip \abovedisplayskip
1673 \let\@listi\@listI}
1674 \renewcommand\small{%
1675 \@setfontsize\normalsize{12}{16}%
1676 \abovedisplayskip 12\p@ \@plus2\p@ \@minus6\p@
1677 \abovedisplayshortskip \z@ \@plus4\p@
1678 \belowdisplayshortskip 6.5\p@ \@plus3\p@ \@minus3\p@
1679 \belowdisplayskip \abovedisplayskip}
1680 \parindent=24pt
1681 \parskip=18pt
1682 % Redefine \FormatPartMarks so that it doesn't push the text off the paper
1683 \let\FormatPartMarks\examn@variantFormatPartMarks
1684 }
1685 \or
1686 % font variant 2: 36pt
1687 \def\examn@bodyfontchange{
1688 \renewcommand\normalsize{%
1689 \@setfontsize\normalsize{36}{42}%
1690 \abovedisplayskip 36\p@ \@plus7\p@ \@minus17.5\p@
1691 \abovedisplayshortskip \z@ \@plus10.5\p@
1692 \belowdisplayshortskip 21\p@ \@plus10.5\p@ \@minus10.5\p@
1693 \belowdisplayskip \abovedisplayskip
1694 \let\@listi\@listI}
1695 \renewcommand\small{%
1696 \@setfontsize\normalsize{24}{28}%
1697 \abovedisplayskip 24\p@ \@plus5\p@ \@minus12\p@
1698 \abovedisplayshortskip \z@ \@plus8\p@
1699 \belowdisplayshortskip 14\p@ \@plus8\p@ \@minus8\p@
1700 \belowdisplayskip \abovedisplayskip}
1701 \parindent=48pt
1702 \parskip=36pt
1703 % Redefine \FormatPartMarks so that it doesn't push the text off the paper
1704 \let\FormatPartMarks\examn@variantFormatPartMarks
1705 }
1706 \else
1707 % Bad font variant
1708 \ClassError{exam-n}
1709 {Bad font variant \examn@fontvariant}
1710 {I didn't expect to see that number (broken style file re largefont/hugefont?)}
1711 \fi
1712 % \end{macrocode}
1713 % The above font variants require a |\FormatPartMarks| variant which
1714 % avoids being pushed off the edge of the page.
1715 % \begin{macrocode}
1716 \def\examn@variantFormatPartMarks#1{%
1717 \setbox0=\hbox{\hskip 1em \textbf{[#1]}}%
1718 \@tempdima=0.8\marginsize
1719 \ifdim\wd0>\@tempdima
1720 \advance\@tempdima -\wd0
1721 \hbox to 0pt{\hskip\@tempdima \box0\hss}%
1722 \else
1723 \hbox to 0pt{\box0\hss}%
1724 \fi}
1725 % \end{macrocode}
1726 %
1727 % Adjust maths font sizes for the various cases:
1728 % \begin{macrocode}
1729 \DeclareMathSizes\@xiipt{12}{9}{7}
1730 \DeclareMathSizes\@xipt{10}{8}{6}
1731 % \end{macrocode}
1732 %
1733 % \subsubsection{PDF metadata, and other document identifiers}
1734 %
1735 % Generate an identifier, |\examn@docident| for this paper. This is obtained
1736 % from the university or school course code, followed by the
1737 % day-of-year, and the number of minutes since midnight (the goal here
1738 % is to produce an identifier which automatically increments in time,
1739 % but which isn't obviously a date.
1740 %
1741 % Yes, a big |\ifcase| would be more straightforward;
1742 % no, that wouldn't be any fun at all
1743 % (also it ends up looking messy and even tricksier).
1744 % \begin{macrocode}
1745 \def\examn@setdocident{%
1746 \begingroup
1747 \def\@step##1##2\@nil{\advance\@tempcnta##1 \def\@tempa{##2}}
1748 \def\@tempa{{31}{28}{31}{30}{31}{30}{31}{31}{30}{31}{30}{31}}%
1749 \@tempcnta=\day % day of month
1750 \@tempcntb=\month % month of year (unit-offset)
1751 \loop
1752 \advance\@tempcntb-1
1753 \ifnum \@tempcntb>0
1754 \expandafter\@step\@tempa\@nil
1755 \repeat
1756 \@tempcntb=\year % yes, do calculate leap years
1757 \divide\@tempcntb 4 \multiply\@tempcntb 4
1758 \ifnum\@tempcntb=\year
1759 \ifnum\month>2 % but let's not worry about century years...
1760 \advance\@tempcnta 1
1761 \fi
1762 \fi
1763 % remove any \\ or ~ in the coursecode fields
1764 \let\\\space
1765 \let~\space
1766 \xdef\examn@docident{% first element is based on uni/school course code
1767 \ifx\@coursetitle\@empty
1768 \ifx\@schoolcoursecode\@empty
1769 exam%
1770 \else
1771 \@schoolcoursecode
1772 \fi
1773 \else
1774 \@coursetitle
1775 \fi
1776 /\the\@tempcnta % day-of-year
1777 -\the\time} % minutes since midnight
1778 \endgroup
1779 }
1780 % \end{macrocode}
1781 %
1782 % Add information to the PDF document metadata.
1783 % \begin{macrocode}
1784 \ifcase\examn@engine
1785 \let\@SetDocumentInfo\relax % original TeX
1786 \or % pdfTeX
1787 \def\@SetDocumentInfo{\pdfinfo{/Title (\examn@docident)}}%
1788 % Don't put out an /Author(xxx) info entry -- there may be
1789 % multiple authors, and it isn't obviously useful
1790 \or % XeTeX
1791 % dvipdfm special -- see the dvipdfm manual
1792 \def\@SetDocumentInfo{\special{pdf: docinfo << /Title (\examn@docident) >>}}%
1793 \or % LuaTeX
1794 % from the LuaTeX manual
1795 \def\@SetDocumentInfo{\pdfextension info {/Title (\examn@docident)}}%
1796 \fi
1797 \AtBeginDocument{\examn@setdocident\@SetDocumentInfo}
1798 % \end{macrocode}
1799 %
1800 % \subsubsection{Exam metadata}
1801 %
1802 % \begin{macrocode}
1803 \def\@exambanner{}
1804 \def\exambanner{\def\@exambanner}
1805
1806 \def\@schoolcoursecode{}
1807 \def\schoolcoursecode{\def\@schoolcoursecode}
1808
1809 \def\@universitycoursecode{}
1810 \def\universitycoursecode{\def\@universitycoursecode}
1811
1812 \def\@paperident{}
1813 \def\paperident{\def\@paperident}
1814
1815 \def\@examdate{}
1816 \def\examdate{\def\@examdate}
1817
1818 \def\@examtime{}
1819 \def\examtime{\def\@examtime}
1820
1821 \def\@coursetitle{}
1822 \def\coursetitle{\def\@coursetitle}
1823 % \end{macrocode}
1824 % Display the degree descriptions, which are separated by |\\|. Put
1825 % each one in an |\hbox|, so it doesn't break over the line.
1826 % \begin{macrocode}
1827 \def\@degreedescriptions{}
1828 \def\degreedescriptions{\def\@degreedescriptions}
1829 \def\@displaydegreedescriptions{%
1830 \let\@tempb\leavevmode
1831 \def\dd##1\\{%
1832 \def\@tempa{##1}%
1833 \ifx\@tempa\@empty
1834 \let\next\relax
1835 \else
1836 \@tempb\hbox{##1}\let\next\dd
1837 \fi
1838 \def\@tempb{\discretionary{}{}{\kern0.5em--\kern0.5em}}%
1839 \next}
1840 \expandafter\dd\@degreedescriptions\\}
1841 % \end{macrocode}
1842 %
1843 % We can optionally check the total number of questions. Store this
1844 % if it is present, and add a check to the |\end{document}| to check
1845 % it at the end if it was indeed set at the beginning. Command
1846 % |\CheckTotalQuestions| is added to |\AtEndDocument| below.
1847 % \begin{macrocode}
1848 \def\@numquestions{}
1849 \def\numquestions{\def\@numquestions}
1850 \def\CheckTotalQuestions{%
1851 \ifnum\@draftstatus < 2
1852 \ifx\@numquestions\@empty \else
1853 \ifnum\c@questionnumber=\@numquestions \else
1854 \ClassWarning{exam-n}
1855 {Expected \@numquestions\space questions, got \thequestionnumber!}
1856 \ifnum\@draftstatus > 0 % draft mode
1857 \begin{center}
1858 \textbf{\highlighted{Expected \@numquestions\space questions, got \thequestionnumber}}
1859 \end{center}
1860 \fi
1861 \fi
1862 \fi
1863 \fi
1864 }
1865 % \end{macrocode}
1866 %
1867 %
1868 % \subsection{Geometry and colours}
1869 %
1870 % Adjust the spacing for article and amsmath flush-left equations.
1871 % Amsmath doesn't use |\mathindent| in the same way \LaTeX\ does, and
1872 % this semi-workaround may break with early versions of amsmath. See
1873 % the amsmath FAQ at http://www.ams.org/tex/amsmath-faq.html for
1874 % some discussion.
1875 % \begin{macrocode}
1876 \if@fleqn
1877 \mathindent\parindent
1878 \@mathmargin=\parindent
1879 \fi
1880 % \end{macrocode}
1881 %
1882 % |\marginsize| is the size of the margin all round. Users shouldn't
1883 % change this in normal circumstances, but are free to if they have
1884 % some particular reason. Note that if all you want to do is move the
1885 % text to one side for printing reasons, use |\nudgeleft|.
1886 % \begin{macrocode}
1887 \newdimen\marginsize
1888 \marginsize=35mm
1889
1890 \headheight=15pt
1891 \headsep=15pt
1892 % \end{macrocode}
1893 %
1894 % It's useful to colour-code material that's present in the compose
1895 % and draft modes but which won't appear in the final version; this
1896 % partly reassures question authors that this is `meta' material.
1897 % \begin{macrocode}
1898 \definecolor{meta}{rgb}{0.7,0.2,0.2}
1899 \def\highlighted{\textcolor{meta}}
1900 % \end{macrocode}
1901 % We (currently) want solutions to appear as coloured blocks. The
1902 % colour is this one:
1903 % \begin{macrocode}
1904 \definecolor{solutiontext}{rgb}{0.2,0.2,0.5}
1905 % \end{macrocode}
1906 % And finally a colour for `discreet' information, such as identifier
1907 % numbers.
1908 % \begin{macrocode}
1909 \definecolor{discreettext}{rgb}{0.6,0.6,0.6}
1910 % \end{macrocode}
1911 %
1912 % Set up the textblock in |\@settextblock|.
1913 % The argument is the amount by which the text block is to be nudged
1914 % to the left.
1915 % \begin{macrocode}
1916 \newcommand\@settextblock[1]{
1917 \textwidth=\paperwidth
1918 \advance\textwidth -2\marginsize
1919 \textheight=\paperheight
1920 \advance\textheight -2\marginsize
1921 \oddsidemargin=\marginsize
1922 \advance\oddsidemargin -1in
1923 \advance\oddsidemargin -#1
1924 \evensidemargin=\oddsidemargin
1925 \topmargin=\marginsize
1926 \advance\topmargin -\headheight
1927 \advance\topmargin -\headsep
1928 \advance\topmargin -1in
1929 \marginparwidth=\marginsize
1930 \advance\marginparwidth -1.5cm
1931 \advance\marginparwidth #1
1932 %% \typeout{paperwidth=\the\paperwidth, paperheight=\the\paperheight,
1933 %% textwidth=\the\textwidth, textheight=\the\textheight,
1934 %% oddsidemargin=\the\oddsidemargin,
1935 %% headheight=\the\headheight, headsep=\the\headsep, topmargin=\the\topmargin}
1936 \marginparsep=0.5cm
1937 }
1938 % \end{macrocode}
1939 % In the \Lopt{draft} case, we nudge the text block to the side, to
1940 % give a larger margin.
1941 % \begin{macrocode}
1942 \ifnum\@draftstatus > 0
1943 \@settextblock{2cm}
1944 \else
1945 \@settextblock{0pt}
1946 \fi
1947 % \end{macrocode}
1948 % |\leftnudge| is the amount by which the textblock is shifted
1949 % leftwards. This is usually zero, but is given a non-zero value in
1950 % draft modes, to give space for marginal comments, and may be given a
1951 % non-zero value by users, in the preamble, if that is required for
1952 % some reason by some limitation of the subsequent printing process.
1953 % It may be negative, to nudge the block rightwards.
1954 % \begin{macrocode}
1955 \let\leftnudge\@settextblock
1956 % \end{macrocode}
1957 %
1958 % Format the marginal paragraphs (ie, comments)
1959 % \begin{macrocode}
1960 \renewcommand\@marginparreset{%
1961 \reset@font
1962 \@setminipage
1963 \raggedright
1964 \small
1965 }
1966 % \end{macrocode}
1967 %
1968 % Add a few other formatting parameters.
1969 %
1970 % Note that the (default) layout of |\FormatPartNumber| depends on a
1971 % non-zero |\parindent|, so if the latter is changed, the former must
1972 % be, too. In fact, if |\parindent| is zero or otherwise small,
1973 % \begin{quotation}
1974 % \catcode`\|=0
1975 % |begingroup |ttfamily
1976 % \catcode`\{=12 \catcode`\}=12 \catcode`\\=12
1977 % |noindent \newcommand\FormatPartNumber{|linebreak
1978 % |noindent|null|quad\hbox to 2em{(\StylePartNumber{partnumber})\hss}}
1979 % |endgroup
1980 % \end{quotation}
1981 % works adequately as a part number,
1982 % though this does result in paragraphs being a little hard to make
1983 % out, unless there's a really generous |\parskip|.
1984 % \begin{macrocode}
1985 \setlength{\parindent}{2em}
1986 \setlength{\parskip}{\bigskipamount}
1987 % \end{macrocode}
1988 %
1989 % We must clear out any floats at the end of the paper, without
1990 % forcing a new page (figures and tables don't float, but there are
1991 % other packages which can generate floats, such as the
1992 % \Lenv{sidewaystable} from the \Lpackage{rotating} package).
1993 % This technique is simplified form Donald Arsenau's \Lpackage{placeins} package.
1994 % \begin{macrocode}
1995 \def\examn@flushfloats{\par
1996 \begingroup
1997 \edef\@tempa{\@deferlist\@dbldeferlist}
1998 \ifx\@tempa\@empty \else
1999 \clearpage
2000 \fi
2001 \endgroup
2002 }
2003 % \end{macrocode}
2004 % Text at the end of the paper. Command |\ClosingText| is added to
2005 % |\AtEndDocument|, below.
2006 % \begin{macrocode}
2007 \ifcase\@draftstatus % Final version
2008 \def\ClosingText{
2009 \examn@flushfloats
2010 \begin{center}\textbf{End of Paper}\\\end{center}
2011 \mark{END}}
2012 \or % Draft version
2013 \def\ClosingText{
2014 \examn@flushfloats
2015 \begin{center}\textbf{End of Draft Paper}\\\end{center}
2016 \mark{END}}
2017 \else % Compose version (nothing, because this would be on a page by itself)
2018 \def\ClosingText{
2019 \examn@flushfloats
2020 \mark{END}}
2021 \fi
2022 % \end{macrocode}
2023 %
2024 % \subsection{Headings and marks}
2025 %
2026 % The headers and footers include continuation information.
2027 % \begin{macrocode}
2028 \RequirePackage{fancyhdr}
2029 \pagestyle{fancy}
2030 \setlength{\headwidth}{\textwidth}
2031 \renewcommand{\headrulewidth}{0pt}
2032 \renewcommand{\footrulewidth}{0pt}
2033 \fancyhead{}
2034 \fancyfoot{}
2035 % \end{macrocode}
2036 % Include an identifier in the footer, unless an identifier is present
2037 % in |\@paperident|.
2038 % \begin{macrocode}
2039 \fancyfoot[L]{{\tiny\textcolor{discreettext}{%
2040 \ifx\@paperident\@empty\examn@docident\else\@paperident\fi
2041 }}}
2042 % \end{macrocode}
2043 % We use marks to determine whether, at the top of the page, we're
2044 % continuing a question or starting a new one. Set |\mark{n}| at the
2045 % beginning of a question, and |\mark{}| at the end. In principle, if
2046 % |\topmark| is non-empty, then we're currently in the given question,
2047 % and if it's empty, we're not. Now, the \LaTeX\ floats mechanism
2048 % (which is involved in the handling of marginpars as well as floats)
2049 % interferes with this because it can call the output routine other
2050 % than at the end of a page. Thus |\topmark| is essentially useless
2051 % within \LaTeX, if there's any change of a float appearing.
2052 %
2053 % However, we can work around this by setting |\examn@topmark| in the
2054 % page footer, to be the value of |\botmark| there. I think this has
2055 % exactly the same semantics as |\topmark|, possibly apart from some
2056 % pathological situations.
2057 %
2058 % So, for the footer, we include a continuation mark if and only if
2059 % |\examn@topmark| is non-empty. We additionally store |\botmark| into |\examn@topmark|.
2060 % \begin{macrocode}
2061 \fancyfoot[R]{%
2062 \def\@tempa{END}
2063 \xdef\examn@topmark{\botmark}
2064 \ifx\examn@topmark\@empty
2065 \formatcontinuations{Paper continued over\dots}%
2066 \else\ifx\examn@topmark\@tempa
2067 \formatcontinuations{END}
2068 \else
2069 \formatcontinuations{Q\,\examn@topmark\ continued over\dots}%
2070 \fi\fi
2071 }
2072 \fancyfoot[C]{\thepage/\pageref{lastpage}}
2073 % \end{macrocode}
2074 % In the header, we perform essentially the same test, using the
2075 % |\examn@topmark| we saved in the previous page's footer.
2076 % \begin{macrocode}
2077 \def\examn@topmark{}
2078 \ifnum\@draftstatus=0
2079 \fancyhead[L]{%
2080 \ifx\examn@topmark\@empty \else
2081 \formatcontinuations{Q\,\examn@topmark\ continued}%
2082 \fi
2083 }
2084 \fi
2085 % \end{macrocode}
2086 % We use the header to shout out the status of the paper, in
2087 % particular making it very clear if we're showing the exam answers:
2088 % we don't want this version to be accidentally distributed at the exam\dots.
2089 % The |\examn@bighead| macro sets its contents in a large box, but
2090 % without making the header any larger -- we want the headheight in
2091 % drafts to be the same as in the final version (because otherwise
2092 % we'd get different page breaks).
2093 % \begin{macrocode}
2094 \def\examn@bighead#1{\strut\vbox to 0pt{\vss\hbox{\examn@header@shoutformat{#1}}\vskip 10mm}}
2095 \ifnum\@draftstatus = 1
2096 \if@showsolutions
2097 \fancyhead[C]{\examn@bighead{\highlighted{DRAFT + SOLUTIONS, p\thepage/\pageref{lastpage}}}}
2098 \else
2099 \fancyhead[C]{\examn@bighead{\highlighted{DRAFT, p\thepage/\pageref{lastpage}}}}
2100 \fi
2101 \else
2102 \if@showsolutions
2103 % Add a very prominent banner
2104 \fancyhead[C]{\examn@bighead{\highlighted{SHOWING SOLUTIONS}}}
2105 \fi
2106 \fi
2107 % \end{macrocode}
2108 %
2109 % Allow \texttt{.clo} files to override the formatting of the various
2110 % continuation markers.
2111 % \begin{macrocode}
2112 \def\formatcontinuations#1{\textbf{#1}}
2113 % \end{macrocode}
2114 %
2115 % Now define a command which writes out the page number of the last
2116 % page. This is added to |\AtEndDocument|, in the correct order, below.
2117 % \begin{macrocode}
2118 \def\WriteLastPageLabel{\label{lastpage}}
2119 % \end{macrocode}
2120 %
2121 % \subsubsection{The title page}
2122 %
2123 % Define a special page style for the title page.
2124 %
2125 % There is no header: all of the text on the page is handled by |\maketitle|
2126 % The first-page footer doesn't show anything, but it does have to set
2127 % |\examn@topmark| in case Q1 starts on this page.
2128 % \begin{macrocode}
2129 \def\ps@titlepage{
2130 \def\@oddhead{}
2131 \def\@oddfoot{\xdef\examn@topmark{\botmark}}
2132 }
2133 % \end{macrocode}
2134 %
2135 % Create a custom maketitle.
2136 % Check all required information is present.
2137 % \begin{macrocode}
2138 \def\RequiredMetadata#1#2#3{
2139 \expandafter\ifx\csname @#1\endcsname\@empty
2140 \ClassError{exam-n}{#2}{#3 (command \@backslashchar #1)}
2141 \else
2142 \typeout{#1 check OK}
2143 \fi}
2144 % \end{macrocode}
2145 % Define a |\CheckExamMetadata| test, but only if the macro wasn't defined in a |.clo| file.
2146 % \begin{macrocode}
2147 \@ifundefined{CheckExamMetadata}{
2148 \def\CheckExamMetadata{
2149 % First, data which is always required
2150 \RequiredMetadata{examdate}
2151 {No exam date given}
2152 {Specify an exam date}
2153 \RequiredMetadata{examtime}
2154 {No exam time given}
2155 {Specify an exam time}
2156 \RequiredMetadata{exambanner}
2157 {No exam banner given}
2158 {Specify an exam banner (eg Examination for the degree...)}
2159 \iffussydescription
2160 % The following tests can be skipped by using the option [sloppydescription]
2161 \RequiredMetadata{universitycoursecode}
2162 {No paper title given}
2163 {Specify a university course code (eg PHYS3031)}
2164 \RequiredMetadata{coursetitle}
2165 {No course title given}
2166 {Specify a course title (eg Quantum Mechanics)}
2167 \RequiredMetadata{degreedescriptions}
2168 {No paper subject given}
2169 {Specify a 'degree description' (eg Physics 3)}
2170 \RequiredMetadata{rubric}
2171 {No rubric given}
2172 {Specify a rubric, or declare its absence with \protect\norubric}
2173 \fi
2174 }}{}
2175 % \end{macrocode}
2176 % Start the |\maketitle| command.
2177 % First, handle the 'final' or 'draft' versions.
2178 % \begin{macrocode}
2179 \renewcommand\maketitle{
2180 \ifnum\@draftstatus < 2 % final or draft version
2181 \CheckExamMetadata
2182 % \end{macrocode}
2183 % All OK so far\dots. Now produce the actual text.
2184 % \begin{macrocode}
2185 \thispagestyle{titlepage}
2186 \begin{center}
2187 \null
2188 \vskip -1.5cm
2189 % \end{macrocode}
2190 % Firse produce headers at the top, which highlight things which make
2191 % the paper non-distributable (eg, it includes the answers!).
2192 % Only highlight the number of shouts when we're not showing
2193 % solutions. The highlights above indicate clearly that the
2194 % paper is not in its distributable format; the purpose of
2195 % this output here is to highlight that the paper is still not
2196 % distributable, \emph{even though} it's not showing solutions.
2197 % \begin{macrocode}
2198 \if@showsolutions
2199 \nointerlineskip
2200 \vbox to 0pt{\vss
2201 \examn@header@shoutformat{\shout{SHOWING SOLUTIONS}}
2202 \vskip 1.5\bigskipamount}
2203 \else
2204 \ifnum\examn@shoutcounttotal>0
2205 \typeout{SHOUTS: \the\examn@shoutcounttotal}
2206 \nointerlineskip
2207 \vbox to 0pt{\vss
2208 \examn@header@shoutformat
2209 {\highlighted{SHOUTS: \the\examn@shoutcounttotal\ (see end)}}
2210 \vskip 1.5\bigskipamount}
2211 \fi
2212 \fi
2213 \nointerlineskip
2214 % \end{macrocode}
2215 % The logo, in a zero-size box.
2216 % \begin{macrocode}
2217 \hbox to \textwidth{% date and time
2218 \vbox to 0pt{\vskip-2ex \UniLogo{50mm}\vss}
2219 \hss
2220 % \end{macrocode}
2221 % Make the |\@examtime| box have zero depth, or else fancyhead
2222 % complains that the size of the header isn't big enough, and
2223 % ups it for the whole document. In this position, it's OK that
2224 % it juts out of the bottom of the header line.
2225 % \begin{macrocode}
2226 \setbox0=\hbox{\vtop{% \vtop or \vbox here?
2227 % Opinions differ:
2228 % This week, Norman prefers \vtop because it gives a cleaner top line.
2229 \hsize=0.5\textwidth
2230 \leftskip=0pt plus1fil \rightskip=0pt \parfillskip=0pt
2231 \baselineskip=2.5ex
2232 \parskip=0.25ex
2233 \let\\\par
2234 \ifx\@examdate\@empty
2235 \shout{missing exam date}
2236 \else
2237 \@examdate
2238 \fi
2239 \par
2240 \ifx\@examtime\@empty
2241 \shout{missing exam time}
2242 \else
2243 \@examtime
2244 \fi
2245 \par}}
2246 \dp0=0pt
2247 \box0}
2248 \vskip4\bigskipamount
2249 %\UoGname\\[\medskipamount]
2250 {\uppercase\expandafter{\@exambanner}}\\[\medskipamount]
2251 \vbox{}\hrule
2252 \ifx\@degreedescriptions\@empty\else
2253 \@displaydegreedescriptions\\
2254 \fi
2255 % \end{macrocode}
2256 % Exam identification. The |\@coursetitle| is the most important
2257 % item, so make that biggest.
2258 % Adjust the size of the course title so that it fits on to one line
2259 % (though if |\Large| is still too big, then we give up and go to multiple lines).
2260 % \begin{macrocode}
2261 \vskip 2\baselineskip plus 0.3fil
2262 \def\@tempa{\def\@tempa{\vskip 0.5\baselineskip}}
2263 \ifx\@schoolcoursecode\@empty\else
2264 \@tempa
2265 {\large\textbf{\@schoolcoursecode}}
2266 \fi
2267 \ifx\@universitycoursecode\@empty\else
2268 \@tempa
2269 {\large\textbf{[~\@universitycoursecode~]}}
2270 \fi
2271 \ifx\@coursetitle\@empty\else
2272 \setbox0=\hbox{\Huge\textbf{\@coursetitle}}
2273 \ifdim\wd0>\columnwidth
2274 \setbox0=\hbox{\LARGE\textbf{\@coursetitle}}
2275 \ifdim\wd0>\columnwidth
2276 % we're not going any smaller than this
2277 \setbox0=\vbox{\hsize\columnwidth
2278 \Large\bfseries
2279 \@coursetitle}
2280 \fi
2281 \fi
2282 \vskip 1.2\ht0 % generous vertical skip, size-dependent
2283 \ifhbox0
2284 \hbox to \columnwidth{\hss\box0\hss}
2285 \else
2286 \box0
2287 \fi
2288 \fi
2289 % \end{macrocode}
2290 % Rubric(s). The macros |\@empty| and |\@nnil| both have an empty
2291 % expansion. The difference between them is that |\@rubric| is set to
2292 % |\@nnil| by |\norubric| to indicate that |\@rubric| is deliberately
2293 % empty, whereas if |\@rubric| is |\@empty|, that's trapped in the
2294 % checks above as an error.
2295 % \begin{macrocode}
2296 \vskip 2\baselineskip plus 0.3fil
2297 \parindent=0pt
2298 \parskip=0.5\baselineskip
2299 \ifnum\examn@fontvariant > 0
2300 % Don't put the rubric here (see below)
2301 {\LARGE Rubric: see overleaf}
2302 \else
2303 \ifx\@rubric\@empty\else
2304 \ifx\@rubric\@nnil\else
2305 % If there's a rubric, separate from the base rubric, then
2306 % separate the two with an hrule (the per-exam rubric
2307 % presumably represents special instructions for this exam,
2308 % so should be highlighted)
2309 \vbox{\let\emph\textbf
2310 \@rubric
2311 \par}
2312 \vskip2\baselineskip
2313 \hrule
2314 \vskip1.5\baselineskip
2315 \fi
2316 \fi
2317 % \end{macrocode}
2318 % Let the base rubric be a justified block of text near the bottom.
2319 % \begin{macrocode}
2320 \ifx\@baserubric\@empty \else
2321 \@baserubric \par
2322 \fi
2323 \fi % end \ifbigfont \else ...
2324 \end{center}
2325 % \end{macrocode}
2326 % These various fractions of fil glue don't add up as I'd expect
2327 % them to. No matter: the fractions here produce some spreading
2328 % out of the rubrics below the titles, which is what I'm after.
2329 % \begin{macrocode}
2330 \vskip 2\baselineskip plus 0.6fil % \newpage is {\vfil\penalty-\@M}
2331 \vbox to 0pt{\hbox to \textwidth{%
2332 \tiny
2333 \textcolor{discreettext}
2334 {\hfil\ifx\@paperident\@empty\examn@docident\else\@paperident\fi\hfil}}\vss}
2335 \penalty -\@M
2336 \@displayconstants
2337 % \end{macrocode}
2338 % The compose version is nice and simple, because we don't have to do
2339 % any checks. FIXME: Hmm: this is largely redundant, because we don't
2340 % document, and so don't really support, including the metadata in the
2341 % [compose] mode preamble. However we clearly did include this as one
2342 % point: was that just out of whim, or was there a requirement for that?
2343 % \begin{macrocode}
2344 \else % compose version
2345 \begin{tabular}{rl}
2346 \textbf{Exam}&
2347 {\def\\{ / }\@schoolcoursecode}\\
2348 \textbf{Course codes}&
2349 \@universitycoursecode\\
2350 %% \textbf{Subject}&
2351 %% {\def\and{and}\begin{tabular}
2352 %% {\@degreedescriptionstemplate}\@degreedescriptions
2353 %% \end{tabular}}\\
2354 \textbf{Date \& time}&
2355 {\def\\{, }\@examdate, \@examtime}\\
2356 \end{tabular}
2357 \fi
2358 % \end{macrocode}
2359 % And chatter about what decision we've made.
2360 % \begin{macrocode}
2361 \ifcase\@draftstatus
2362 % Final version
2363 \typeout{Exam \@schoolcoursecode: FINAL VERSION}
2364 \or % Draft version
2365 \typeout{Exam \@schoolcoursecode: DRAFT VERSION}
2366 \else % Compose version
2367 \typeout{Exam \@schoolcoursecode: COMPOSE VERSION}
2368 \fi
2369 %
2370 \examn@bodyfontchange
2371 \normalfont\normalsize
2372 \ifnum\examn@fontvariant>0
2373 % Put the rubric on a second page, in the 'huge' size.
2374 \begin{center}
2375 \parskip=18pt
2376 \let\emph\textbf \@rubric\par
2377 \vskip\baselineskip
2378 \hrule
2379 \vskip\baselineskip
2380 \ifx\@baserubric\@empty \else
2381 \@baserubric \par
2382 \fi
2383 \end{center}
2384 \newpage
2385 \fi
2386 }
2387 % \end{macrocode}
2388 %
2389 % \subsection{Structuring commands}
2390 %
2391 % \subsubsection{Sections}
2392 %
2393 % Define simple sectioning commands. We also check that these aren't
2394 % inside questions.
2395 % \begin{macrocode}
2396 \setcounter{secnumdepth}{0}
2397 % \end{macrocode}
2398 % Redefine |\section|, to include a check that it's not being called
2399 % within a question (|\@currentquestion| is defined only inside the
2400 % \Lenv{question} or \Lenv{mcq} environments).
2401 % \begin{macrocode}
2402 \renewcommand\section{
2403 \@ifundefined{@currentquestion}\@@section
2404 {\ClassError{exam-n}{Misplaced section}
2405 {You can't have a section inside a question;\MessageBreak
2406 move it before the {question} environment starts}}}
2407 \newcommand\@@section{\@startsection{section}{1}{\z@}%
2408 {-3.5ex \@plus -1ex \@minus -.2ex}%
2409 {1ex \@plus.1ex \@minus 0.5ex}%
2410 {\fmt@section}}
2411 \def\fmt@section#1{%
2412 \examn@prequestionspace{}
2413 \hbox to \textwidth{{\hfil\bfseries SECTION #1\hfil}}%
2414 }
2415 % \end{macrocode}
2416 % Redefine |\subsection| similarly.
2417 % \begin{macrocode}
2418 \renewcommand\subsection{
2419 \@ifundefined{@currentquestion}\@@subsection
2420 {\ClassError{exam-n}{Misplaced subsection}
2421 {You can't have a subsection inside a question;\MessageBreak
2422 move it before the {question} environment starts}}}
2423 \newcommand\@@subsection{\@startsection{subsection}{2}{\z@}
2424 {-2ex \@plus -3ex \@minus -0.2ex}
2425 {0.5ex \@plus .1ex \@minus 0.1ex}
2426 {\fmt@subsection}}
2427 \def\fmt@subsection#1{%
2428 \examn@prequestionspace{}
2429 \noindent\textbf{#1}}
2430 % \end{macrocode}
2431 % We must redefine the section and subsection mark commands to gobble
2432 % their arguments. If we don't, then \LaTeX\ gets \emph{terribly}
2433 % confused about what the mark is. I don't quite follow what happens
2434 % in this case, but symptoms include Babel blowing up, and
2435 % \TeX\ running out of stack space. So: bad.
2436 % \begin{macrocode}
2437 \let\sectionmark\@gobble
2438 \let\subsectionmark\@gobble
2439 % \end{macrocode}
2440 %
2441 % Just to be safe, we should also disable the other sectioning
2442 % commands.
2443 % \begin{macrocode}
2444 \def\@badsection#1#2{\ClassError{guexam}{Bad section}
2445 {The exam class goes not support subdivisions like #1{#2}}}
2446 \def\subsubsection{\@badsection{subsubsection}}
2447 \def\paragraph{\@badsection{paragraph}}
2448 \def\subparagraph{\@badsection{subparagraph}}
2449 % \end{macrocode}
2450 %
2451 % The above redefinitions break the |\tableofcontents| macro.
2452 % It's unlikely but \emph{possibly} useful, in some cases, to have a
2453 % table of contents in an exam paper. Whether or not it is, we should
2454 % avoid breaking it, on a principle of least surprise. The following
2455 % makes the macro work again, even though it's not particularly
2456 % pretty.
2457 % \begin{macrocode}
2458 \renewcommand\tableofcontents{\bigskip
2459 \hbox to \textwidth{\hfil\textbf{\Large Contents}\hfil}%
2460 \@starttoc{toc}}
2461 % \end{macrocode}
2462 %
2463 % \subsubsection{Questions and solutions}
2464 % Counters:
2465 % \begin{macrocode}
2466 \newcount\marktotal % number of marks accumulated so far
2467 \newcount\markgoal % number of marks we should have in the end
2468 \newcounter{questionnumber}
2469 \setcounter{questionnumber}0
2470 % \end{macrocode}
2471 %
2472 % Counter partnumber holds the number (i,ii,iii, etc) of the parts
2473 % within a question. It's a \LaTeX\ counter, so we can use |\roman|.
2474 %
2475 % We override the \Lenv{article} |\part| command.
2476 %
2477 % FIXME:
2478 % We would like to use |\StylePartNumber| here, but can't, because
2479 % that's defined as being eg |\alph|, and not |\@alph|. To change
2480 % this, we'll have to retire |\StylePartNumber|, in favour of saying
2481 % that, to change the formatting here, it's merely necessary to
2482 % redefine |\thepartnumber|.
2483 % \begin{macrocode}
2484 \newcounter{partnumber}
2485 \renewcommand\thepartnumber{\thequestionnumber\@alph\c@partnumber}
2486 \renewcommand\part[1][]{%
2487 \if@nobreak \else
2488 \par
2489 \@nobreakfalse
2490 \fi
2491 \ifvmode
2492 \vskip 0pt plus 4\bigskipamount
2493 \penalty-50
2494 \fi
2495 \def\@tempa{#1}%
2496 \ifx\@tempa\@empty
2497 \refstepcounter{partnumber}%
2498 \noindent\FormatPartNumber
2499 \else
2500 \noindent\FormatPartNumber[#1]%
2501 \fi
2502 }
2503 % \end{macrocode}
2504 % The default |\FormatPartNumber| creates a box the same size as a
2505 % parindent. This therefore assumes that it's following a |\noindent|.
2506 % \begin{macrocode}
2507 \newcommand\FormatPartNumber[1][]{%
2508 \def\@tempa{#1}%
2509 \hbox to \parindent{(%
2510 \ifx\@tempa\@empty
2511 \StylePartNumber{partnumber}%
2512 \else
2513 \@tempa
2514 \fi
2515 )\hss}%
2516 }
2517 % \end{macrocode}
2518 % And by default we use alphanumeric counters for parts (we abstract
2519 % this, rather than simply including |\alph| in the definition of
2520 % |\FormatPartNumber|, so that we use the same style for the
2521 % `answerpartnumber' counter.
2522 % \begin{macrocode}
2523 \let\StylePartNumber\alph
2524 % \end{macrocode}
2525 %
2526 % A flag indicating whether we should start a new page before the next
2527 % question. This is manipulated by both |\section| and |\question|.
2528 % \begin{macrocode}
2529 \newif\if@newpagebeforequestion
2530 \if@pageperquestion
2531 \@newpagebeforequestiontrue
2532 \else
2533 \@newpagebeforequestionfalse
2534 \fi
2535 % \end{macrocode}
2536 %
2537 % The command |\examn@prequestionspace| is called just before we start a
2538 % new question, or before we start a header which precedes a
2539 % question. It adds some vertical space, given in the argument,
2540 % unless the |@pageperquestion| settings imply that this should be a
2541 % newpage instead, in which case the vertical space here is ignored.
2542 % \begin{macrocode}
2543 \def\examn@prequestionspace#1{%
2544 \if@pageperquestion
2545 \if@newpagebeforequestion
2546 % Add all the stretchability here, rather than stretching out
2547 % displays and lists above this on the page.
2548 \newpage
2549 % Clear the \@newpagebeforequestion flag, to suppress the action
2550 % of any following calls to \examn@prequestionspace, until the end
2551 % of the next question.
2552 \global\@newpagebeforequestionfalse
2553 \fi
2554 \else
2555 #1%
2556 \fi
2557 }
2558 % \end{macrocode}
2559 %
2560 % Macro |\examn@endquestion| gathers here a couple of checks shared
2561 % between end-of-question macros (see the \Lenv{mcq} environment and
2562 % the |\endquestion| macro).
2563 % The argument to the |\examn@endquestion| macro is material (such as the
2564 % mark-total) which should go at the end of the question,
2565 % and be surrounded by various spacing and resetting actions.
2566 % \begin{macrocode}
2567 \long\def\examn@endquestion#1{%
2568 \mark{} % the position of this call is slightly sensitive (but this works)
2569 \if@pageperquestion
2570 \global\@newpagebeforequestiontrue
2571 \fi
2572 #1
2573 \@nobreakfalse
2574 \everypar{}
2575 }
2576 % \end{macrocode}
2577 %
2578 % \subsubsection{Partmarks}
2579 %
2580 % |\partmarks| is used at the end of a paragraph to indicate the
2581 % number of marks associated with this part. The starred variant
2582 % |\partmarks*| is used only when the end of a part is the end of a display
2583 % maths block which doesn't have an equation number. This moves the
2584 % part note up a bit, which looks nicer.
2585 %
2586 % It's also permissible to use |\partmarks| in the solution, to
2587 % indicate precisely where marks accrue. It's reasonable for this to
2588 % be more fine-grained than in the question. We don't check that the
2589 % partmarks in the solution add up to the mark goal.
2590 %
2591 % Manage the partmarks comments as the contents of a zero-width hbox,
2592 % which is sized to fit reasonably well in the margin. We insert this
2593 % into the output just before formatting the partmarks.
2594 %
2595 % The |\defaultpartmarkscategory| macro creates a default partmarks
2596 % `category'. If this is something like |{category?}|, then this
2597 % should prompt question authors to indicate the category in each call
2598 % to |\partmarks|. This can be declared within a |.clo| option file
2599 % (and is declared above, so that it can be read from there without error).
2600 %
2601 % Below, we must add the footnote text after the end of the paragraph,
2602 % otherwise this inserts vertical mode material, which causes a
2603 % linebreak, at least in the case where the last line is almost full.
2604 % Because we are using the hook mechanism, this package now depends on
2605 % the expl3 modules, and thus on TeXLive versions which aren't too old
2606 % (how old is too old? I'm not sure, but I expect TeXLive 2020 is new enough).
2607 % \begin{macrocode}
2608 \newbox\examn@partmarkscomment
2609 \def\examn@makepartmarkscomment#1{%
2610 \setbox0=\hbox{\small #1}%
2611 \ifdim\wd0 < 3\marginparwidth % let shortish comments wrap here
2612 \setbox\examn@partmarkscomment=\hbox to 0pt{\hbox{%
2613 \vtop to 0pt{%
2614 \hsize=\marginparwidth
2615 \parindent=0pt
2616 \parskip=0pt
2617 \leftskip=1em % 1em matches the hskip in default \FormatPartMarks
2618 \rightskip=0pt plus 0.5\marginsize
2619 \hangindent=2em \hangafter=-1
2620 \small
2621 #1\vss}}\hss
2622 }%
2623 \else
2624 \stepcounter\@mpfn
2625 \protected@xdef\@thefnmark{\thempfn}%
2626 \@footnotetext{#1}%
2627 % 3em matches the \leftskip+\hangindent above
2628 \setbox\examn@partmarkscomment=\hbox to 0pt{%
2629 \hskip3em\highlighted{\small [comment \thempfn]}\hss}%
2630 \fi
2631 }
2632 \def\examn@getpartmarkscomment{%
2633 \ifhbox\examn@partmarkscomment
2634 \box\examn@partmarkscomment
2635 \fi}
2636 % \end{macrocode}
2637 % Now, finally, define the actual |\partmarks| command.
2638 % \begin{macrocode}
2639 \def\partmarks{%
2640 \@ifstar{\@tempswatrue \@partmarks}{\@tempswafalse \@partmarks}}
2641 \newdimen\@partmarksspace
2642 \@partmarksspace=2em % default value
2643 % \end{macrocode}
2644 % Check whether there's an optional (comment/category) argument,
2645 % enclosed in |[...]|.
2646 % \begin{macrocode}
2647 \def\@partmarks{%
2648 \@ifnextchar[%]
2649 \@@partmarks{\@@partmarks[]}}
2650 % \end{macrocode}
2651 % Implement the part marks indicator. First, check that
2652 % `perquestionmarks' is turned on; if it's not, then we shouldn't be
2653 % using |\partmarks|.
2654 % \begin{macrocode}
2655 \def\@@partmarks[#1]#2{%
2656 \if@perquestionmarks
2657 \if@insolution
2658 \@@partmarks@solution{#1}{#2}%
2659 \else
2660 \@@partmarks@question{#1}{#2}%
2661 \fi
2662 \else
2663 \ClassError{exam-n}{\string\partmarks\ is not compatible with
2664 noperquestionmarks}{Either remove \string\partmarks\ or remove
2665 the noperquestionmarks option}
2666 \fi
2667 }
2668 % \end{macrocode}
2669 %
2670 % Finally, implement the two partmarks variants for questions and solutions.
2671 %
2672 % The |\@@partmarks@endenv| command is called when |\partmarks| is
2673 % invoked within an environment, and is used to add a suitable vbox to
2674 % an after-environment hook.
2675 %
2676 % First prepare the vbox that's to be inserted, and then work out how
2677 % to place it. The |\vskip\baselineskip| in the |\@partmarksbox| is
2678 % to better position the box relative to where it ends up in the
2679 % vertical list, and the value has a large heuristic element.
2680 % \begin{macrocode}
2681 \newbox\@partmarksbox
2682 \def\@@partmarks@endenv@display{\@tempswatrue\@@partmarks@endenv@common}
2683 \def\@@partmarks@endenv@nodisplay{\@tempswafalse\@@partmarks@endenv@common}
2684 \def\@@partmarks@endenv@common#1{%
2685 \ifvbox\@partmarksbox % ooops -- been here before: two \partmarks in one env
2686 \ClassError{exam-n}
2687 {Two partmarks commands in one environment! First one IGNORED!}
2688 {You can (currently) have only one partmarks command per environment}
2689 \fi
2690 \global\setbox\@partmarksbox=\vbox to 0pt{\vss
2691 \hbox to \textwidth{%
2692 \strut\hfill
2693 \examn@getpartmarkscomment
2694 \FormatPartMarks{#1}}%
2695 \vskip\baselineskip}%
2696 %\dp\@partmarksbox=0pt
2697 % \end{macrocode}
2698 % Test whether we have the |{question}| environment as our immediate
2699 % container, as opposed to being in an inner environment.
2700 % \begin{macrocode}
2701 \def\@tempa{question}%
2702 \ifx\@tempa\@currenvir
2703 \setbox1=\vbox to 0pt{\vss\box\@partmarksbox}%
2704 \ifvmode
2705 \box1
2706 \else
2707 \vadjust{\box1}%
2708 \fi
2709 \else
2710 % \end{macrocode}
2711 % Generally the \cmd|env/<env>/end| hook seems to
2712 % produce better results, in terms of positioning things at the end of
2713 % environments, but this does not work for environments
2714 % where the command is located inside a display (ie, in \TeX\ terms,
2715 % inside |$$...$$|); in these situations we have to use the
2716 % \texttt{.../after} hook instead. Such displays are most typically amsmath
2717 % alignment environments, but an \cmd|\halign| inside a display will
2718 % also qualify (see the discussion of `alignment displays' in \TeX
2719 % Book ch.19). There isn't a completely straightforward way of
2720 % detecting this situation (though amsmath's \cmd|\start@align| sets
2721 % \cmd|\xatlevel@| to be non-\cmd|\@empty|, which we take to indicate the
2722 % amsmath case), so we have to rely on the caller of this
2723 % command to invoke the \texttt{...@display} or \texttt{...@nodisplay}
2724 % variant appropriately.
2725 % \begin{macrocode}
2726 \if@tempswa % display variant
2727 \AddToHookNext{env/\@currenvir/after}{%
2728 %\typeout{hook:endenv/display #1}%
2729 \ifvmode\box\@partmarksbox
2730 \else\vadjust{\box\@partmarksbox}\fi}%
2731 \else
2732 \AddToHookNext{env/\@currenvir/end}{%
2733 %\typeout{hook:endenv/nodisplay: env/\@currenvir/end #1}%
2734 \ifvmode\box\@partmarksbox
2735 \else\vadjust{\box\@partmarksbox}\fi}%
2736 \fi
2737 \fi
2738 }
2739 % \end{macrocode}
2740 %
2741 % First, define the questions version, for appearing in the version candidates see.
2742 % Here, \cmd|#1| is the possibly empty `classification' text, and \cmd|#2| is the
2743 % number of marks. At this point |\if@tempswa| is true if we got here
2744 % via the \cmd|\partmarks*| variant, and false if it's the unstarred one.
2745 %
2746 % The argument |#2| must be a number: any non-number text will not
2747 % cause an error but will appear in the text.
2748 %
2749 % But first\dots!
2750 %
2751 % The |\partmarks| command increments a global counter, and we
2752 % \emph{don't} want to do this when an \Lpackage{amsmath} alignment is evaluating
2753 % the content in its `measuring' phase. Fortunately,
2754 % \Lpackage{amsmath} has an (internal) flag |\ifmeasuring@| which is
2755 % true in that phase, which it uses for this purpose, so make this macro a no-op in that case.
2756 % \begin{macrocode}
2757 \def\@@partmarks@question{%
2758 \ifmeasuring@
2759 \let\@@partmarksnext\@gobbletwo
2760 \else
2761 \let\@@partmarksnext\@@partmarks@question@do
2762 \fi
2763 \@@partmarksnext
2764 }
2765 % \end{macrocode}
2766 % On with the main business.
2767 % \begin{macrocode}
2768 \def\@@partmarks@question@do#1#2{%
2769 \global\advance\marktotal #2
2770 \let\@@partmarksnext\relax % base case
2771 % \end{macrocode}
2772 % Display the `part category', \emph{visible in the question},
2773 % if \Lopt{showsolutions} is true, either
2774 % explicitly, or implicitly as a consequence of the
2775 % compose/draft/final mode. It's arguable that this should be
2776 % dependent on the mode only, but after some discussion, it ended up
2777 % seeming more reasonable to tie this to \Lopt{showsolutions} directly.
2778 % \begin{macrocode}
2779 \if@showsolutions
2780 \def\@tempa{#1}%
2781 \ifx\@tempa\@empty
2782 \ifx\examn@defaultpartmarkscategory\relax
2783 \let\examn@category\relax
2784 \else
2785 \examn@makepartmarkscomment{\highlighted{\examn@defaultpartmarkscategory}}%
2786 \fi
2787 \else
2788 \examn@makepartmarkscomment{\highlighted{#1}}%
2789 \fi
2790 \fi
2791 % \end{macrocode}
2792 %
2793 % If |\@tempswa|, then this is the starred form of |\partmarks|.
2794 % This is intended to be used only occasionally, after a display or
2795 % list environment, where for some reason the command can't go inside
2796 % the environment.
2797 % \begin{macrocode}
2798 \if@tempswa
2799 \ifdim\displaywidth>0pt
2800 \ClassError{exam-n}
2801 {Don't use \partmarks* inside a display}
2802 {Use \partmarks inside the display, or \partmarks*
2803 after it, if necessary}
2804 % \end{macrocode}
2805 % Else we are most likely just after an equation or just after a list
2806 % environment, or something similar.
2807 % (here and below we include some |{#2:n}| debugging code for when I,
2808 % inevitably, revisit this to worry about the spacing).
2809 % \begin{macrocode}
2810 \else
2811 \@@partmarks@endenv@nodisplay{#2}%{#2:1*}%
2812 \fi
2813 % \end{macrocode}
2814 % We've called the unstarred version of |\partmarks|.
2815 % This is the more usual mode.
2816 % \begin{macrocode}
2817 \else
2818 \ifdim\displaywidth>0pt
2819 % \end{macrocode}
2820 % We're in a display, after |$$|: \TeX\ is probably (but not certainly) in
2821 % maths mode just now; if we're in an amsmath alignment, we're in
2822 % specifically inner maths mode; there are other, rarer, ways of being
2823 % in an `alignment display'. Additionally, and commonly, if we're in
2824 % an \Lenv{equation} environment now -- which we can detect because
2825 % that, amongst other amsmath environments, sets |\eqnsw| to be true
2826 % -- then we're \emph{not} in an alignment, but we \emph{are} in a
2827 % case where the |\eqno| technique will fail (with `You can't use
2828 % `eqno' in math mode.'), so catch that.
2829 %
2830 % CONSIDER: is this |\@eqnsw| test in fact the only one I have to do
2831 % -- is the inner math mode test equivalent? That is, is this, when
2832 % it comes down to it, testing the actual thing I need to test here?
2833 % This will require another dive into the amsmath magic.
2834 % \begin{macrocode}
2835 \@tempswafalse
2836 \ifmmode\ifinner \else \@tempswatrue \fi\fi
2837 \if@tempswa
2838 \if@eqnsw % not so fast... we're in an {equation}
2839 \@tempswafalse
2840 \fi
2841 \fi
2842 \if@tempswa
2843 % \end{macrocode}
2844 % We're in outer maths mode, which we can take to mean a |\[...\]| equation.
2845 % In this case, we can very neatly position the partmarks indicator
2846 % using |\eqno|.
2847 % \begin{macrocode}
2848 \def\@@partmarksnext{\eqno \hbox to 1sp{% the \eqno argument must not be zero size
2849 \examn@getpartmarkscomment
2850 \FormatPartMarks{#2}%{#2:1}
2851 \hss}}%
2852 % \end{macrocode}
2853 % Or we're in one or other type of display.
2854 % \begin{macrocode}
2855 \else
2856 \def\@@partmarksnext{\@@partmarks@endenv@display{#2}}%
2857 %\def\@@partmarksnext{\@@partmarks@endenv@display{#2:2,\@currenvir}}%
2858 \fi
2859 % \end{macrocode}
2860 %
2861 % Otherwise, |\displaywidth=0pt|, and we're not in a display.
2862 % If we are in the |{question}| environment, as opposed to any sub-environment,
2863 % we end the paragraph here and put the partmarks indicator at the end
2864 % of the final line of the paragraph (this technique is filched from the TeXBook, p106).
2865 % Otherwise, we add a suitable box to an end-of-environment hook.
2866 %
2867 % Omitting the |{question}| test below, and handling all cases with
2868 % the end-of-paragraph technique, works in most case, in the sense of
2869 % looking fine. Where it fails is in the case of, eg, |{quote}|,
2870 % where the end-of-line ends up indented from the right.
2871 %
2872 % Using the hook has the additional advantage that |\partmarks| can be anywhere
2873 % within the environment and this locates it at the end.
2874 %
2875 % The dimension |\@partmarksspace| controls how much space the
2876 % partmarks-number takes up, the default is the special case of 0pt,
2877 % which puts it in the margin.
2878 % \begin{macrocode}
2879 \else
2880 \def\@tempa{question}%
2881 \ifx\@tempa\@currenvir
2882 \ifdim\@partmarksspace > 0pt
2883 {\unskip\nobreak\hfil\penalty50 \hskip\@partmarksspace
2884 \hbox{}\nobreak\hfil\examn@getpartmarkscomment\FormatPartMarks{#2}%{#2:3}%
2885 \parfillskip=0pt \finalhyphendemerits=0 \par}
2886 \else
2887 \unskip\nobreak\hfill\examn@getpartmarkscomment\FormatPartMarks{#2}\par%{#2:4}\par
2888 \fi
2889 \let\@@partmarksnext\relax
2890 \else
2891 \def\@@partmarksnext{\@@partmarks@endenv@nodisplay{#2}}%
2892 %\def\@@partmarksnext{\@@partmarks@endenv@nodisplay{#2:5,\@currenvir}}%
2893 \fi
2894 \fi
2895 \fi
2896 % \end{macrocode}
2897 %
2898 % The `question' variant of this macro includes an |\ignorespaces| at the
2899 % end, since that is generally the right thing to do (the command
2900 % almost always appears at the end of paragraphs, or after equations).
2901 % \begin{macrocode}
2902 \@@partmarksnext
2903 \ignorespaces
2904 }
2905 % \end{macrocode}
2906 % Then the solutions version, for the benefit of markers, which is
2907 % typically more finely itemized, and which isn't summed (ie, we don't
2908 % at present confirm that the marks here match the question's marks goal).
2909 % The solutions variant of this macro omits the |\ignorespaces|
2910 % (since in solutions this macro is scattered within the text).
2911 % Setting |\dp0=0pt| is probably unnecessary, but guarantees that box0
2912 % has zero depth, so no extra vertical space appears because of
2913 % this new box.
2914 % \begin{macrocode}
2915 \def\@@partmarks@solution#1#2{%
2916 \setbox0=\vbox to 0pt{\vss
2917 \hbox to \textwidth{\hfil\hbox to 0pt{\quad\small[\dots #2]\hss}}
2918 \vskip0.25ex }%
2919 \dp0=0pt
2920 \ifvmode
2921 \box0
2922 \else
2923 \vadjust{\nointerlineskip\box0}%
2924 \fi
2925 }
2926 % \end{macrocode}
2927 %
2928 % The code above permits page-breaks between lists and |\partmarks|.
2929 % That's because |\@endparenv|, which is called within |\endtrivlist|,
2930 % includes a negative |\@endparpenalty|. Override that here. This
2931 % applies to the whole document, but that's OK, since we want to
2932 % discourage inconvenient page-breaks generally.
2933 % \begin{macrocode}
2934 \@endparpenalty=\@M
2935 % \end{macrocode}
2936 %
2937 % The number of marks is formatted by the command |\FormatPartMarks|, which
2938 % may be overridden, using |\renewcommand| in a |.clo| file.
2939 % In this default case, |\FormatPartMarks| goes into the margin, so we
2940 % don't need to keep space for it, so set |\@partmarksspace| to zero.
2941 % \begin{macrocode}
2942 \newcommand\FormatPartMarks[1]{\hbox to 0pt{\hskip1em \textbf{[#1]}\hss}}
2943 \@partmarksspace=\z@
2944 % \end{macrocode}
2945 %
2946 % \subsubsection{The question environments: normal questions}
2947 %
2948 % The \Lenv{question} environment. Implement
2949 % this using with a |\question| macro, rather than using
2950 % |\newenvironment|, so that we can define an optional argument.
2951 % \begin{macrocode}
2952 \newcommand\question{%
2953 \if@perquestionmarks
2954 \let\ex@next\@questionmarks
2955 \else
2956 \let\ex@next\@questionnomarks
2957 \fi
2958 \@ifnextchar[%]
2959 {\ex@next}{\ex@next[]}}
2960 % \end{macrocode}
2961 % Switch between the perquestionmarks and noperquestionmarks cases.
2962 % \begin{macrocode}
2963 \def\@questionmarks[#1]#2{%
2964 \def\@tempa{#2}% marks available for this question
2965 \ifx\@tempa\@empty
2966 \ClassError{exam-n}
2967 {Missing mark goal for question (using 0 instead)}
2968 {Missing mark goal for question (using 0 instead)}
2969 \def\@tempa{0}
2970 \fi
2971 \ifx\@includequestionoverridenumber\@empty
2972 \do@question{#1}{\@tempa}%
2973 \else
2974 \ClassWarning{exam-n}{Forcing question number
2975 \@includequestionoverridenumber, in included question #2}
2976 \do@question{\@includequestionoverridenumber}{\@tempa}%
2977 \fi
2978 }
2979 \def\@questionnomarks[#1]{%
2980 \do@question{#1}{0}%
2981 }
2982 % \end{macrocode}
2983 %
2984 % \subsubsection{The question environments: multiple-choice questions}
2985 %
2986 % And finally multiple-choice questions. The \Lenv{mcq} environment
2987 % contains a list of possible answers, numbered from one up, including
2988 % precisely one correct answer, indicated by |\answer|. These are
2989 % laid out in a compact itemized list. We do not indicate the number
2990 % of marks, since these are always the same.
2991 %
2992 % First, counters:
2993 % \begin{itemize}
2994 % \item |\ex@nmcq| is the number of answers which MCQs can have. If
2995 % this is less than 1, it's a flag that MCQs haven't been enabled by
2996 % |\multiplechoiceanswers|.
2997 % \item |\ex@mcqi| is the running index of answers.
2998 % \item |\ex@mcqnanswer| is the number of correct answers found
2999 % (which is checked to be one, at the end).
3000 % \end{itemize}
3001 % \begin{macrocode}
3002 \newcount\ex@nmcq
3003 \ex@nmcq=-1
3004 \newcount\ex@mcqnanswer
3005 \def\multiplechoiceanswers#1{\ex@nmcq=#1}
3006 % \end{macrocode}
3007 % The \Lenv{mcq} environment takes a single argument indicating the
3008 % correct answer. The environment starts with the text question,
3009 % followed by a number of |\item| answers.
3010 % \begin{macrocode}
3011 \newenvironment{mcq}
3012 {\parindent=0pt
3013 \ifnum\ex@nmcq<1
3014 \ClassError{exam-n}
3015 {mcq environment without preceding multiplechoiceanswers declaration}
3016 {The mcq environment may only be used if the number of
3017 permitted MCQ answers has been declared with \string\multiplechoiceanswers}
3018 \else
3019 % \end{macrocode}
3020 % Declare |\item| for the individual answers, and |\answer| for the
3021 % single correct answer.
3022 % \begin{macrocode}
3023 \def\item{\@tempswafalse\ex@mcqitem}
3024 \def\answer{\@tempswatrue\ex@mcqitem}
3025 % \end{macrocode}
3026 % Initialise counters, and invoke the common |\do@question| macro.
3027 % \begin{macrocode}
3028 \ex@mcqi=0
3029 \ex@mcqnanswer=0
3030 \do@question{}{1}
3031 \fi}
3032 % \end{macrocode}
3033 % At the end of the \Lenv{mcq} environment, check that we found
3034 % |\ex@nmcq| answers, and that the count of correct answers,
3035 % |\ex@nmcqanswer|, is exactly one.
3036 % \begin{macrocode}
3037 {\par
3038 \ifnum\ex@mcqi<\ex@nmcq
3039 \ClassWarning{exam-n}{Too few potential answers in MCQ \thequestionnumber}
3040 \@shout{Too few potential answers in MCQ \thequestionnumber}
3041 \ifnum\@draftstatus > 0
3042 \highlighted{TOO FEW ANSWERS}\par
3043 \fi
3044 \fi
3045 \ifcase\ex@mcqnanswer
3046 \ClassWarning{exam-n}
3047 {No correct MCQ answer provided in question \thequestionnumber}
3048 \@shout{No correct MCQ answer provided in question \thequestionnumber}
3049 \ifnum\@draftstatus > 0
3050 \highlighted{NO CORRECT ANSWER PROVIDED}\par
3051 \fi
3052 \or
3053 % ex@mcqanswer=1: correct -- do nothing
3054 \else
3055 \ClassWarning{exam-n}
3056 {Too many correct MCQ answers provided in question \thequestionnumber}
3057 \@shout{Too many correct MCQ answers provided in question \thequestionnumber}
3058 \ifnum\@draftstatus > 0
3059 \highlighted{TOO MANY CORRECT ANSWERS}\par
3060 \fi
3061 \fi
3062 % \end{macrocode}
3063 % Other end-question tidyups (compare |\endquestion|).
3064 % \begin{macrocode}
3065 \examn@endquestion{\relax}
3066 }
3067 % \end{macrocode}
3068 % Each |\item| within the environment (implemented by |\ex@mcqitem|)
3069 % creates a new paragraph.
3070 % \begin{macrocode}
3071 \newcount\ex@mcqi
3072 \def\ex@mcqitem{%
3073 \par
3074 \ifnum\ex@mcqi=0
3075 % first one
3076 \smallskip
3077 \parskip=0pt % nothing fancy -- we assume these won't spread
3078 % over more than one line
3079 \advance\leftskip by 2em
3080 \fi
3081 \advance\ex@mcqi by 1
3082 \noindent
3083 \if@tempswa
3084 % the correct answer
3085 \advance\ex@mcqnanswer 1
3086 \if@showsolutions
3087 \hbox to 0pt{\hss \highlighted{$\Longrightarrow$ \@Alph\ex@mcqi . }}%
3088 \else
3089 \hbox to 0pt{\hss \@Alph\ex@mcqi . }%
3090 \fi
3091 \else
3092 \hbox to 0pt{\hss \@Alph\ex@mcqi . }%
3093 \fi
3094 }
3095 % \end{macrocode}
3096 %
3097 % \subsubsection{The question environments: the common handler}
3098 %
3099 % The common question handler. This is the macro which does the work.
3100 % Argument |#1| is the overriding question number (empty indicates the
3101 % next one in sequence); argument |#2| is the mark goal, which must be
3102 % non-zero.
3103 % \begin{macrocode}
3104 \def\do@question#1#2{%
3105 \par % get that out of the way...
3106 \markgoal=#2
3107 \marktotal=0
3108 \ifx\examn@questionpreamble\@empty
3109 \else
3110 \vspace{2\baselineskip}
3111 \hbox to \textwidth{\hfil\textbf{\examn@questionpreamble}\hfil}
3112 \questionpreamble{}
3113 \fi
3114 \setcounter{partnumber}{0}
3115 \setcounter{answerpartnumber}{0}
3116 % \end{macrocode}
3117 % If the argument |#1| is non-empty, then it is a number, forcing the
3118 % question number. This is local, however -- don't use it to change
3119 % the sequence of questions, so don't set the `questionnumber'
3120 % counter, but only the current label.
3121 % \begin{macrocode}
3122 \refstepcounter{questionnumber}
3123 \def\@tempa{#1}
3124 \ifx\@tempa\@empty \else
3125 \edef\@currentlabel{#1}
3126 \fi
3127 % \end{macrocode}
3128 %
3129 % If |pageperquestion| is true, then start a new page here (unless
3130 % this is the first question).
3131 % \begin{macrocode}
3132 \examn@prequestionspace{%
3133 \if@nobreak
3134 % after a heading (or something like that)
3135 \else
3136 % we're not forcing a new page here, but this would be a good point to choose
3137 \vskip 2\baselineskip plus 8\baselineskip
3138 \penalty-200
3139 \fi
3140 }
3141 % \end{macrocode}
3142 %
3143 % The optional argument specifies a question number. In compose mode,
3144 % this unequivocally specifies the question number -- end of story.
3145 % In the two other modes, this is expected to match the question
3146 % number implied by the count of questions so far, and we check this,
3147 % and warn if it is not so.
3148 % \begin{macrocode}
3149 \if@questionnumberchecks
3150 \def\@tempa{#1}% intended question number
3151 % \end{macrocode}
3152 % If there's no optional argument, we've got nothing to do
3153 % \begin{macrocode}
3154 \ifx\@tempa\@empty
3155 % no optional argument -- easy
3156 \def\@currentquestion{\thequestionnumber}
3157 % \end{macrocode}
3158 %
3159 % We have a non-null optional argument in |#1|.
3160 % Check the question number in the argument. If there's a
3161 % mismatch, warn in draft mode, and fail in final mode. First,
3162 % however, check that the argument |#1| is just a number (if it's not,
3163 % the author should have disabled this check in the preamble, and we
3164 % shouldn't be here at all). We do that check by setting a counter
3165 % inside a box. If |#1| is all number, then this will result in a
3166 % zero-width box; if not, then there will be unparsed characters and a
3167 % non-zero-width box (nifty, eh?).
3168 % \begin{macrocode}
3169 \else
3170 \setbox0=\hbox{\@tempcnta=#1}
3171 \ifdim\wd0>0pt
3172 \ClassWarning{exam-n}{Non-numeric question number, #1.
3173 You probably want to put \string\QuestionNumberChecksOff in the preamble}
3174 \par\textbf{Non-numeric question number, #1.
3175 You probably want to put \hbox{$\backslash$\ttfamily QuestionNumberChecksOff} in the preamble}
3176 (the formatting below may be messed up).\par
3177 \fi
3178 % \end{macrocode}
3179 % Switch on the draft status: in the final version, this mismatch is an error
3180 % \begin{macrocode}
3181 \ifcase\@draftstatus
3182 % Final version
3183 \@tempcnta=#1
3184 \ifnum\c@questionnumber=\@tempcnta
3185 \def\@currentquestion{#1}
3186 \else
3187 \ifx\@includequestionoverridenumber\@empty
3188 \ClassError{exam-n}
3189 {\string\question[#1] is actually question \thequestionnumber!}
3190 {The question in {question} environment number
3191 \thequestionnumber\space is specified as
3192 \string\question[#1].\MessageBreak
3193 This is an error in 'final' mode.\MessageBreak
3194 Perhaps you need \string\QuestionNumberChecksOff?}
3195 \def\@currentquestion{???}
3196 \else
3197 \ClassWarning{exam-n}{Forcing question number \@includequestionoverridenumber,
3198 in {question} environment number \thequestionnumber}
3199 \edef\@currentquestion{\@includequestionoverridenumber}% this doesn't seem to expand in fact!
3200 \message{current question=\@currentquestion, override \@includequestionoverridenumber}
3201 \fi
3202 \fi
3203 % \end{macrocode}
3204 % In the other two modes, we simply need a warning.
3205 % \begin{macrocode}
3206 \or
3207 % Draft version -- let the given number override
3208 % \the\questionnumber, but warn if there's a difference.
3209 \@tempcnta=#1
3210 \ifnum\c@questionnumber=\@tempcnta \else
3211 \ClassWarning{exam-n}
3212 {\string\question[#1] is actually question \thequestionnumber!}
3213 \fi
3214 \def\@currentquestion{#1}
3215 \else
3216 % compose mode -- argument overrides without question
3217 \def\@currentquestion{#1}
3218 \fi
3219 \fi
3220 \else
3221 % skip question-number checks
3222 \def\@tempa{#1}% intended question number
3223 \ifx\@tempa\@empty
3224 % no optional argument -- this is possibly an error, so warn
3225 \ClassWarning{exam-n}{\string\QuestionNumberChecksOff\ is in
3226 force, but this question has no [number]}
3227 \def\@currentquestion{\thequestionnumber}
3228 \else
3229 \typeout{Forcing question \thequestionnumber\space to be #1}
3230 \def\@currentquestion{#1}
3231 \fi
3232 \fi
3233 % \end{macrocode}
3234 % Format the question number, first removing and discarding any parindent
3235 % (the reason we don't just start with |\noindent| here is because
3236 % there may be a blank line between the |\begin{question}|, and the
3237 % text, so we'd (inadvertently) start another new paragraph when the
3238 % actual question starts).
3239 % The call to |\mark| should come \emph{after} setting the
3240 % question number: if it happens before, and there is a page-break
3241 % immediately before the new question, we can get a spurious
3242 % `Q?? continued' on the previous page.
3243 %
3244 % If a paragraph starts inside a level of grouping -- for example
3245 % |{\bf 1} text...| or even just |{T}ext| -- then the |\everypar|
3246 % tokens are expanded inside that group, which means that the
3247 % resetting of |\everypar| is local, with the result that the tokens
3248 % are reused for the next paragraph. Make the emptying of |\everypar|
3249 % global for that reason.
3250 % \begin{macrocode}
3251 \everypar{\setbox0=\lastbox % discard \box0
3252 \FormatQuestionNumber
3253 \mark{\@currentquestion}%
3254 \global\everypar{}}
3255 }
3256 % \end{macrocode}
3257 % Format the question number. This command is documented as existing,
3258 % so that it can be potentially overridden in a \texttt{.clo} file.
3259 % \begin{macrocode}
3260 \newcommand\FormatQuestionNumber
3261 {\hbox to 0pt{\hss \textbf{\@currentquestion}\hskip1em}}
3262 % \end{macrocode}
3263 %
3264 % Finish off the question:
3265 % Format the indication of the total number
3266 % of marks, and do a few consistency checks.
3267 % \begin{macrocode}
3268 \def\endquestion{%
3269 \ifnum\marktotal=\markgoal
3270 \typeout{Question \@currentquestion\if@perquestionmarks, \the\marktotal\space marks\fi}
3271 \iffalse % all of this is redundant, and ends up too shouty
3272 \ifcase\@draftstatus
3273 % Final version -- do nothing
3274 \relax
3275 \or % draft version
3276 \relax % no, the above is too much; do nothing
3277 \else % compose version
3278 \par
3279 \hfil\textbf{\highlighted{[Q\,\@currentquestion\if@perquestionmarks, \the\marktotal\space marks\fi]}}%
3280 \break
3281 \fi
3282 \fi
3283 % \end{macrocode}
3284 % In the case where the mark total doesn't match, make a noise about it.
3285 % \begin{macrocode}
3286 \else
3287 \ClassWarning{exam-n}
3288 {Question \@currentquestion\space has a total of \the\marktotal\space marks,
3289 \MessageBreak
3290 when it should have \the\markgoal}
3291 \begin{center}
3292 \edef\@tempa{Question \@currentquestion\space
3293 has a total of \the\marktotal\space marks,
3294 when it should have \the\markgoal}
3295 \expandafter\shout\expandafter{\@tempa}
3296 \end{center}
3297 \fi
3298 % \end{macrocode}
3299 % Make a few tidyups in the end-question wrapper.
3300 % \begin{macrocode}
3301 \examn@endquestion{%
3302 \if@showmarktotals
3303 \par % into vertical mode
3304 \nobreak % keep the marks total with the question
3305 \vbox to 2\baselineskip{
3306 \vss
3307 % this should be very similar to the call to
3308 % \FormatPartMarks in \@partmarks, above
3309 \hbox to \textwidth{\strut\hfill\FormatPartMarks{Total: \the\markgoal
3310 \ifnum\@draftstatus>0
3311 % in draft modes, put a fairly discreet confirmation in the total
3312 \space
3313 \highlighted{\ifnum\marktotal=\markgoal OK\else X\fi}%
3314 \fi}}}
3315 \fi
3316 }
3317 }
3318 % \end{macrocode}
3319 %
3320 % \subsubsection{Other structures}
3321 %
3322 % The \Lenv{questiondata} environment allows the author to provide
3323 % some additional data or equations for the question.
3324 % This environment ends a preceding paragraph.
3325 % \begin{macrocode}
3326 \newenvironment{questiondata}{%
3327 \par
3328 \penalty50 % poor break
3329 \vbox\bgroup
3330 \slshape
3331 \parindent=0pt \parskip=\medskipamount
3332 \smallskip
3333 \hrule
3334 \nobreak
3335 \smallskip
3336 \noindent \ignorespaces
3337 }{%
3338 \par
3339 \nobreak
3340 \medskip
3341 \hrule width \textwidth
3342 \par
3343 \egroup % end of \vbox
3344 }
3345 % \end{macrocode}
3346 %
3347 % If |\questionpreamble| is called some time before the start of a
3348 % \Lenv{question} environment, then its contents will be printed at
3349 % the start of the next question.
3350 % \begin{macrocode}
3351 \newcommand\questionpreamble[1]{\gdef\examn@questionpreamble{#1}}
3352 \let\examn@questionpreamble\@empty
3353 % \end{macrocode}
3354 %
3355 % In those cases where the sequence of question numbers is not
3356 % supposed to match the sequence of question environments, declare
3357 % that we should turn off the corresponding checks within |\question|.
3358 % \begin{macrocode}
3359 \newif\if@questionnumberchecks
3360 \@questionnumbercheckstrue
3361 \newcommand\QuestionNumberChecksOff{\@questionnumberchecksfalse}
3362 % \end{macrocode}
3363 %
3364 % The underlying style (article) has enumerate and itemize
3365 % environments which have a rather generous amount of space. This
3366 % makes sense in an article, but within an exam, which already has a
3367 % lot of white space around, such lists end up looking unattractively
3368 % ragged. So redefine them slightly here, adjusting the spacing
3369 % appropriately. First `enumerate'\dots
3370 % \begin{macrocode}
3371 \def\enumerate{%
3372 \ifnum \@enumdepth >\thr@@\@toodeep\else
3373 \advance\@enumdepth\@ne
3374 \edef\@enumctr{enum\romannumeral\the\@enumdepth}%
3375 \expandafter
3376 \list
3377 \csname label\@enumctr\endcsname
3378 {\usecounter\@enumctr
3379 \topsep0pt
3380 \partopsep0pt
3381 %\parskip=5.0pt \parsep=\parskip
3382 \def\makelabel##1{\hss\llap{##1}}}%
3383 \fi}
3384 % \end{macrocode}
3385 % \dots then `itemize'.
3386 % \begin{macrocode}
3387 \def\itemize{%
3388 \ifnum \@itemdepth >\thr@@\@toodeep\else
3389 \advance\@itemdepth\@ne
3390 \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
3391 \expandafter
3392 \list
3393 \csname\@itemitem\endcsname
3394 {\topsep0pt
3395 \partopsep0pt
3396 \def\makelabel##1{\hss\llap{##1}}}%
3397 \fi}
3398 % \end{macrocode}
3399 % To match the format of the question number above, we have to make
3400 % sure that the enumerate environment's counters are different.
3401 % \begin{macrocode}
3402 \renewcommand\theenumi{\@roman\c@enumi}
3403 % \end{macrocode}
3404 %
3405 % \subsection{Other useful commands}
3406 %
3407 % |\comment| creates a marginal comment in non-final modes. There is an
3408 % interaction with the marks mechanism -- see the discussion about
3409 % |\topmark| above.
3410 % \begin{macrocode}
3411 \newcommand\comment[1]{%
3412 \ifnum\@draftstatus > 0
3413 \marginpar{\highlighted{#1}}%
3414 % should we \@shout this, too?
3415 \fi
3416 \ignorespaces
3417 }
3418 % \end{macrocode}
3419 %
3420 % The |\author| command is a convenience. Used within a
3421 % \Lenv{question} environment, it creates a comment with the author's
3422 % name. I may expand its functionality in future.
3423 % \begin{macrocode}
3424 \renewcommand\author[1]{\comment{Author: #1}}
3425 % \end{macrocode}
3426 %
3427 % The |\@shout| macro is intended for use in all modes: it appends a
3428 % remark to a list of exclamations which are highlighted at the end of
3429 % the document.
3430 % The argument to |\@shout| can have expandable things (such as
3431 % |\thequestionnumber|) in it.
3432 % Shouts appear in all modes and cannot be suppressed.
3433 % \begin{macrocode}
3434 \newtoks\@allshouts \@allshouts={}
3435 \def\@shout#1{\edef\@tempa{#1}\expandafter\@@shout\expandafter{\@tempa}}
3436 \def\@@shout#1{\global\@allshouts=\expandafter{\the\@allshouts\t{#1}}}
3437 \def\showthe@shouts{%
3438 {\def\t##1{{\LARGE\noindent\highlighted{NOTE: ##1}\par}}%
3439 \the\@allshouts}%
3440 % Remark on the number of shouts in the aux file
3441 {\@tempcnta=0 \def\t##1{\advance\@tempcnta1}\the\@allshouts
3442 \protected@write\@auxout{}%
3443 {\string\examn@shoutcount{\the\@tempcnta}}}}
3444 % \end{macrocode}
3445 % Define the user macro |\shout|
3446 % \begin{macrocode}
3447 \def\shout#1{\textbf{\highlighted{#1}}\@shout{#1}}
3448 % \end{macrocode}
3449 % Take note of the number of shouts, and write this information to the
3450 % \texttt{.aux} file, so that it can be read in next time.
3451 % \begin{macrocode}
3452 \newcount\examn@shoutcounttotal
3453 \examn@shoutcounttotal=0
3454 \def\examn@shoutcount#1{\global\examn@shoutcounttotal=#1}
3455 % \end{macrocode}
3456 %
3457 % The |\includequestion| command includes a question from another
3458 % file. For convenience, we disable
3459 %|\documentclass|, |\usepackage|, |\RequirePackage|, and the
3460 % \Lenv{document} environment, so that the included file may be a
3461 % complete \LaTeX\ document.
3462 % We don't try too hard to support including just any old \LaTeX, here:
3463 % any complicated preamble requirements in an included file should
3464 % probably be managed by the exams convener transplanting them into
3465 % the preamble of the main document. This may be an overly
3466 % simple-minded approach, and may change in future versions.
3467 % \begin{macrocode}
3468 \def\dummy@documentclass{%
3469 \@ifnextchar[\dummy@@documentclass{\dummy@@documentclass[]}}
3470 \def\dummy@@documentclass[#1]#2{}
3471 \def\includequestion{
3472 \@ifnextchar[%]
3473 {\@includequestion}{\@includequestion[]}}
3474 \def\@includequestion[#1]#2{%
3475 \begingroup
3476 \let\documentclass\dummy@documentclass
3477 \let\document\@empty % not \relax: makes \begin think {document} is undef'd
3478 \let\enddocument\endinput % stop reading, discarding any junk below \end{document}
3479 \def\@tempa{#1}
3480 \ifx\@tempa\@empty \else
3481 \def\@includequestionoverridenumber{#1}
3482 \message{includequestion override: \@includequestionoverridenumber}
3483 \fi
3484 \def\usepackage##1{\ClassWarning{exam-n}
3485 {Ignoring \string\usepackage{##1} in included question #2}}
3486 \let\RequirePackage\usepackage
3487 \input{#2}
3488 \endgroup
3489 }
3490 \let\@includequestionoverridenumber\@empty
3491 % \end{macrocode}
3492 %
3493 % \subsection{The solution environment}
3494 %
3495 % The solution environment is made somewhat complicated by the way we
3496 % implement it. Rather than using a verbatim-like technique to omit
3497 % the source lines (as done successfully by, for example, the
3498 % \Lpackage{comments} package) we set the contents of the environment
3499 % in a box, which we throw away. This technique is more robust in
3500 % principle, but it does mean we have to disable some things which
3501 % have global side-effects.
3502 %
3503 % Maintain a flag which indicates whether we're in a solution
3504 % environment or not.
3505 % \begin{macrocode}
3506 \newif\if@insolution
3507 \@insolutionfalse
3508 % \end{macrocode}
3509 %
3510 % We want to use |\part| within solutions. If we were to do so naively
3511 % however, we would end up incrementing the |partnumber| counter
3512 % which that macro uses, which either disturbs the numbering of the
3513 % parts in the question (if the solutions are interspersed in the
3514 % question) or starts out of sequence (if the solutions are at the
3515 % end). So we maintain a separate counter. Additionally, we want to
3516 % force the formatting of the solution parts, to be independent of the
3517 % formatting in the main question
3518 % \begin{macrocode}
3519 \newcounter{answerpartnumber}
3520 \newcommand{\examn@solutionpart}{%
3521 \par
3522 \stepcounter{answerpartnumber}
3523 \noindent\hbox to \parindent{(\StylePartNumber{answerpartnumber})\hss}}
3524 % \end{macrocode}
3525 %
3526 % Specify how solutions should be shown. The following makes them
3527 % ragged right, slightly smaller and slanted, with rules fore and aft.
3528 % This doesn't leap out, but the difference should be detectable.
3529 % Putting a box round the solution would be desirable (it keeps it all
3530 % together and would allow a coloured background), but that's rather
3531 % hard to arrange in practice.
3532 %
3533 % Solutions are shown in a slightly smaller size (namely |\small|).
3534 % It's debatable whether this is a good thing or not. Note that if
3535 % this is changed by removing the |\small|, then
3536 % |\examn@dummycaptions| will have to be adjusted, too.
3537 %
3538 % If either of the `enlarged font' options has been given, then we set
3539 % the solutions in the same large font, since these might be
3540 % distributed to students as model answers.
3541 % \begin{macrocode}
3542 \def\@formatsolution{\par
3543 \if@insolution
3544 \ClassError{exam-n}{Misplaced solution}{You can't have a solution within a solution}
3545 \else
3546 \@insolutiontrue % this happens within a group
3547 \fi
3548 \examn@dummycaptions % dummy captions within solutions
3549 \typeout{SHOWING SOLUTIONS}
3550 \let\part\examn@solutionpart
3551 % \end{macrocode}
3552 % Checks done; now get on with the layout
3553 % \begin{macrocode}
3554 \vskip 1ex plus 2\bigskipamount % add stretchable space...
3555 \penalty-\@lowpenalty % ...and encouragement to break here
3556 \parskip 0.5\baselineskip
3557 \raggedright
3558 \color{solutiontext}%\slshape
3559 \normalsize
3560 \hrule
3561 \hbox to \textwidth{\vrule height 1ex \hfil \vrule height 1ex}
3562 \nobreak
3563 \vskip -\parskip % cancel out the following parskip
3564 \textbf{\highlighted{Solution:}}\hskip2em
3565 \ignorespaces
3566 \parindent=2em
3567 }
3568 % \end{macrocode}
3569 % The end of the solution environment is simple, and simply matches
3570 % the box above.
3571 % \begin{macrocode}
3572 \def\end@formatsolution{%
3573 \par
3574 \nobreak
3575 \vskip -0.5ex
3576 \hbox to \textwidth{\vrule height 1ex \hfil \vrule height 1ex}
3577 \hrule
3578 }
3579 % \end{macrocode}
3580 %
3581 % The content of the \Lenv{solution} environment is balanced \LaTeX\
3582 % text, and so does not have to be complicated; in particular, it does
3583 % not have to have the generality, and the consequent restrictions, of
3584 % for example Eijkhout's \Lpackage{comment} package. If we're including the
3585 % solutions, then we simply format them in the usual sort of way,
3586 % inside a group; otherwise we're skipping them, so put the contents in a
3587 % box and throw it away. Note that \Lenv{solution} is an environment,
3588 % so we're inside a group at this point.
3589 % \begin{macrocode}
3590 \if@showsolutions
3591 \let\solution\@formatsolution
3592 \let\endsolution\end@formatsolution
3593 % \end{macrocode}
3594 % In the case where we're not showing solutions, note that we
3595 % \emph{do} format the contents, so any |\global| effects will still
3596 % happen, unless we take action to avoid them.
3597 %
3598 % In particular, |\part|, which is normally redefined in solutions to
3599 % increment \texttt{answerpartnumber} rather than
3600 % \texttt{partnumber}, would increment \texttt{partnumber} in answers
3601 % unless we take action to stop it.
3602 % \begin{macrocode}
3603 \else
3604 \def\solution{% make a vbox...
3605 \par
3606 \if@insolution
3607 \ClassError{exam-n}{Misplaced solution}{You can't have a solution within a solution}
3608 \fi
3609 \let\endfigure\endfloat@skipsolutions
3610 \let\endtable\endfloat@skipsolutions
3611 \examn@dummycaptions % dummy captions avoid counter increments
3612 \let\part\relax % make \part a no-op in discarded {solution}
3613 \@ifundefined{includepdf}{}{\let\includepdf\examn@disabledpdfpages}
3614 \setbox\@tempboxa\vbox\bgroup
3615 \@insolutiontrue
3616 }
3617 \def\endsolution{%...and do nothing with this box
3618 \egroup
3619 }
3620 \fi
3621 % \end{macrocode}
3622 %
3623 % \subsubsection{Floats in solutions}
3624 %
3625 % Figures in solutions must be treated specially, since they mustn't
3626 % move outside the solution. The most straightforward thing seems to
3627 % be to avoid them floating at all. Additionally, this is probably true of
3628 % figures in the question as well (if a question refers to a figure,
3629 % it's probably civil to have the figure on the same page as the
3630 % text), so redefine {figure} so that in all cases figures are placed
3631 % `here', and never float. We also add generous amounts of vertical
3632 % space, to encourage figures to stay on the same page as the text
3633 % before them, if this is at all possible.
3634 %
3635 % \begin{macrocode}
3636 \def\examn@badfloat#1[#2]{
3637 \ClassError{exam-n}
3638 {Bad #1 option #2 ignored}
3639 {In the exam-n class, the 'floating' environments take no argument,\MessageBreak
3640 and are always placed 'here'}
3641 \examn@float{#1}}
3642 \def\examn@float#1{%
3643 % re-using the standard LaTeX parameter means that \caption works
3644 \def\@captype{#1}
3645 \setbox\@tempboxa\vbox\bgroup}
3646 % \end{macrocode}
3647 % End both |{figure}| and |{table}| environments.
3648 % End the |\@tempboxa| and add some space and good breaks before displaying it.
3649 % We're typically in hmode here, but don't depend on it.
3650 % \begin{macrocode}
3651 \def\examn@endfloat{%
3652 \egroup % end \@tempboxa
3653 \ifvmode\else \unskip \fi % bare \unskip would can an error in vmode
3654 \nobreak
3655 % add lots of stretchability, but non-infinite, for the sake of tidiness
3656 \vskip 0pt plus 0.5\textheight
3657 \penalty50 % a pagebreak here discards following vskip
3658 % (cf TeXBook p106; or try \filbreak of p111)
3659 \vskip 2ex plus -0.5\textheight % negative stretch cancels previous vskip
3660 \box\@tempboxa
3661 %\vskip 1ex
3662 \nobreak
3663 }
3664 \def\endfloat@skipsolutions{%
3665 % variant when skipping solutions -- end the \@tempboxa and do nothing
3666 \egroup
3667 }
3668 % \end{macrocode}
3669 % Now, finally, redefine the figure and table environments in terms of
3670 % these new macros.
3671 % \begin{macrocode}
3672 \def\figure{%
3673 \@ifnextchar[{\examn@badfloat{figure}}{\examn@float{figure}}%]
3674 }
3675 \def\table{%
3676 \@ifnextchar[{\examn@badfloat{table}}{\examn@float{table}}%]
3677 }
3678 \let\endfigure\examn@endfloat
3679 \let\endtable\examn@endfloat
3680 % \end{macrocode}
3681 % And disable the \texttt{figure*} and \texttt{table*} environments.
3682 % \begin{macrocode}
3683 \expandafter\def\csname figure*\endcsname{%
3684 \ClassError{exam-n}
3685 {Bad environment figure* -- there is no figure* environment in exam-n}
3686 {Use plain {figure} instead. See the documentation for discussion}}
3687 \expandafter\def\csname table*\endcsname{%
3688 \ClassError{exam-n}
3689 {Bad environment table* -- there is no table* environment in exam-n}
3690 {Use plain {table} instead. See the documentation for discussion}}
3691 % \end{macrocode}
3692 %
3693 % Within these 'floats', we must redefine |\caption|, so that we don't
3694 % increment the float counters. One motivation for this is so that we don't have
3695 % table numbers changing depending on whether solutions are included
3696 % or not; but since we're implementing the solutions by setting the
3697 % content in a discarded box, it turns out that we get the counter
3698 % increments whether we include the solutions or not. The following
3699 % definition of |\caption| is just the standard one, with
3700 % |\refstepcounter| removed and `Table nnn' redefined appropriately.
3701 % \begin{macrocode}
3702 \def\examn@dummycaptions{%
3703 \def\fnum@figure{\figurename} % 'Figure nnn' changed to just 'Figure'
3704 \def\fnum@table{\tablename}
3705 \def\caption{%
3706 \ifx\@captype\@undefined
3707 \@latex@error{\noexpand\caption outside float}\@ehd
3708 \expandafter\@gobble
3709 \else
3710 %\refstepcounter\@captype % omit this line from the standard definition
3711 \expandafter\@firstofone
3712 \fi
3713 {\@dblarg{\@caption\@captype}}%
3714 }
3715 }
3716 % \end{macrocode}
3717 %
3718 % \subsubsection{Solutions and pdfpages}
3719 %
3720 % It appears that the \Lpackage{pdfpages} package is incompatible with
3721 % the way that I implement \Lopt{noshowsolutions}, largely because (I
3722 % think) it bypasses \LaTeX\ and fiddles with the generated PDF
3723 % directly. Therefore, we have to disable the \Lpackage{pdfpages}
3724 % support when we're skipping solutions. We mustn't do this globally,
3725 % since sometimes (for example in a .clo option file's
3726 % constants sheet) we do need pdfpages in the no-show-solutions case.
3727 % \begin{macrocode}
3728 \def\examn@disabledpdfpages{\@ifnextchar[% ]
3729 \examn@disabledpdfpages@
3730 {\examn@disabledpdfpages@[]}}
3731 \def\examn@disabledpdfpages@[#1]#2{\relax}
3732 % \end{macrocode}
3733 %
3734 % \subsection{End-of-document actions}
3735 %
3736 % Add a number of actions to the end-of-document hook. Do them here,
3737 % rather than by calling |\AtEndDocument| multiple times, because the
3738 % order matters (in fact, the order here is the same as the order
3739 % they're defined in, but it's best to be explicit about this).
3740 % \begin{macrocode}
3741 \AtEndDocument{
3742 \CheckTotalQuestions
3743 \ClosingText
3744 \showthe@shouts
3745 \WriteLastPageLabel}
3746 % \end{macrocode}
3747 %
3748 % \iffalse extradefs:start
3749 % This is a magic comment -- see Makefile.
3750 % these definitions are referred to, in order to document
3751 % them, both in this class's documentation, and in the
3752 % notes-for-authors. \fi
3753 %
3754 % \subsection{Other formatting niceties}
3755 %
3756 % Format vectors (the default for |\vec| is a symbol with an arrow
3757 % over it):
3758 %
3759 % Note: the STIX2+(XeLaTeX/LuaLaTeX) support depends on the LaTeX hook
3760 % mechanism released in 2020. It therefore does not work on versions of
3761 % LaTeX older than that. There is a check for this above (see
3762 % Sect~\ref{s:compatibility}).
3763 % \begin{macrocode}
3764 \if@psfonts
3765 \ifcase\examn@mtselect
3766 % mathptm fonts
3767 % This is a very clumsy version, but it appears to be our only option
3768 \def\vec#1{\mathchoice{\mbox{\boldmath $\displaystyle #1$}}
3769 {\mbox{\boldmath $ #1$}}
3770 {\mbox{\boldmath $\scriptstyle #1$}}
3771 {\mbox{\boldmath $\scriptscriptstyle #1$}}}
3772 \ifexamn@uprightpi
3773 \ClassWarning{exam-n}{Can't do uprightpi in [mathptm] -- sorry}
3774 \let\italicpi\pi
3775 \examn@uprightpifalse
3776 \fi
3777 \or % mathtime (should this be the same for mathtime as for mtpro2?
3778 \let\vec\mathbf
3779 \ifexamn@uprightpi
3780 \ClassWarning{exam-n}{Can't do uprightpi in [mathtime] -- sorry}
3781 \let\italicpi\pi
3782 \examn@uprightpifalse
3783 \fi
3784 \or % mtpro2
3785 \let\vec\mathbold
3786 % \uppi is predefined in mtpro2
3787 \ifexamn@uprightpi
3788 \let\italicpi\pi
3789 \let\pi\uppi
3790 \fi
3791 \else
3792 % STIX2: the unicode-math package provides a \symbf for bold math symbols,
3793 \ifnum\examn@engine<2 % pdflatex
3794 \let\vec\mathbf
3795 % pdftex (or original tex)
3796 % The following should, I think, create an upright pi, but doesn't
3797 \def\uppi{\mathrm{\pi}}
3798 \let\italicpi\pi %for consistency
3799 \let\symup\mathrm %not fully the right thing, but avoid errors below
3800 \else % xelatex or lualatex
3801 % This is where the dependence on a recent LaTeX enters.
3802 \let\vec\symbf
3803 \typeout{stix2: upright=\ifexamn@uprightpi true\else false\fi}
3804 \AddToHook{begindocument/end}{\gdef\uppi{\symup{𝜋}}}
3805 \ifexamn@uprightpi
3806 \AddToHook{begindocument/end}{\gdef\italicpi{\symit{𝜋}}\global\let\pi\uppi}
3807 \fi
3808 \fi
3809 \fi
3810 \else
3811 % CM fonts: \mathbf doesn't work with greek in CM
3812 \let\vec\mathbf
3813 \ifexamn@uprightpi
3814 % upright greek is hard to do portably, so give up
3815 % See eg https://tex.stackexchange.com/questions/145926/ for discussion
3816 \ClassWarning{exam-n}{Can't do uprightpi in [cmfonts] -- sorry}
3817 \let\italicpi\pi
3818 \let\uppi\pi %but avoid errors
3819 \examn@uprightpifalse
3820 \fi
3821 \fi
3822 % \end{macrocode}
3823 %
3824 % Abbreviations for various degrees.
3825 % \begin{macrocode}
3826 \newcommand\BSc{B.Sc.{}}
3827 \newcommand\MSci{M.Sci.{}}
3828 \newcommand\MSc{M.Sc.{}}
3829 \newcommand\MA{M.A.{}}
3830 \newcommand\MEng{M.Eng.{}}
3831 \newcommand\BEng{B.Eng.{}}
3832 % \end{macrocode}
3833 %
3834 % Formatting differentials, and the base of natural logs,
3835 % which should be in an upright font.
3836 % See section~\ref{s:othercommands}, or the `notes for authors',
3837 % for a description of these macros.
3838 % The macro |\ddd| is used inside an integral, and includes a leading thinspace
3839 % \begin{macrocode}
3840 \ifnum\examn@mtselect>2
3841 % ie, STIX2, and thus using the unicode-math package (see above)
3842 \def\e{\symup{e}}
3843 \newcommand{\dd}{\symup{d}}
3844 \newcommand{\ddd}{\,\symup{d}}
3845 \else
3846 \def\e{\mathrm{e}}
3847 \newcommand{\dd}{\mathrm{d}}
3848 \newcommand{\ddd}{\,\mathrm{d}}
3849 \fi
3850
3851 \def\Diffl{\@ifstar\@Difflflat\@Diffl}
3852 \def\Partial{\@ifstar\@Partialflat\@Partial}
3853 \def\@Partial{\@ifnextchar[{\@@Diffl\partial}{\@@Diffl\partial[]}}
3854 \def\@Partialflat{\@ifnextchar[{\@@Difflflat\partial}{\@@Difflflat\partial[]}}
3855 \def\@Diffl{\@ifnextchar[{\@@Diffl\dd}{\@@Diffl\dd[]}}
3856 \def\@Difflflat{\@ifnextchar[{\@@Difflflat\dd}{\@@Difflflat\dd[]}}
3857 \def\@@Diffl#1[#2]#3#4{%
3858 \def\@tempa{#2}%
3859 \ifx\@tempa\empty
3860 \frac{#1#3}{#1#4}%
3861 \else
3862 \frac{{#1}^{#2}#3}{#1{#4}^{#2}}%
3863 \fi}
3864 \def\@@Difflflat#1[#2]#3#4{%
3865 \def\@tempa{#2}%
3866 \ifx\@tempa\empty
3867 #1#3\mskip-0.8mu/\mskip-1.2mu #1#4%
3868 \else
3869 {#1}^{#2}#3\mskip-0.8mu /\mskip-1.2mu #1{#4}^{#2}%
3870 \fi}
3871 % \end{macrocode}
3872 %
3873 % Physical units in upright roman. This macro is now deprecated in
3874 % favour of use of the \Lopt{siunitx} option (which uses the
3875 % \Lpackage{siunitx} package, qv), and it will be removed in a
3876 % minor release after v1.4.
3877 %
3878 % The unstarred version includes leading
3879 % |\thinspace|. The starred version doesn't, and is used when referring to
3880 % the unit by itself (eg axis is |$B/\units*T$|), and is not qualifying
3881 % a number.
3882 % Separate units with either \texttt{.} or |~|, as in |\units{m~s^{-1}}| or
3883 % |\units{m.s^{-1}}|.
3884 % Note that although \texttt{.} and |~| are both possible unit separators in
3885 % general, the former won't work if used within a table (due to the timing of
3886 % token-reading).
3887 %
3888 % This is a rather simple-minded approach to unit formatting. For a much more
3889 % comprehensive treatment, see the \texttt{siunitx} package,
3890 % \url{https://ctan.org/pkg/siunitx}, which is now preferred, in place
3891 % of further use of this macro.
3892 %
3893 % Note: there are detailed prescriptions on the formatting of units and symbols in
3894 % ISO-80000-1:2009, Sect. 7.
3895 % \begin{macrocode}
3896 \def\units{\examn@unitswarning
3897 \begingroup
3898 \catcode`\.=\active
3899 \@ifstar{\let\un@tsspace\relax \un@ts}%
3900 {\let\un@tsspace\thinspace\un@ts}}
3901 \begingroup
3902 \catcode`\.=\active
3903 \gdef\un@ts#1{\let~\thinspace\let.\thinspace
3904 \ifmmode
3905 \un@tsspace\mathrm{#1}%
3906 \else
3907 \nobreak$\un@tsspace\mathrm{#1}$%
3908 \fi
3909 \endgroup}
3910 \endgroup
3911 \newif\ifexamn@warnunits \examn@warnunitstrue
3912 \def\examn@unitswarning{\ifexamn@warnunits
3913 \ClassWarning{exam-n}{The units macro will be removed in the next
3914 version; the [siunitx] option is now on by default, so you can use
3915 the macros in the siunits package}%
3916 \global\examn@warnunitsfalse
3917 \fi}
3918 % \end{macrocode}
3919 % \iffalse extradefs:end % magic comment -- see Makefile \fi
3920 %
3921 % All done.
3922 % \begin{macrocode}
3923 %</package>
3924 % \end{macrocode}
3925 % \Finale
3926 %
3927 \endinput