diff --git a/ouexam.dtx b/ouexam.dtx index 15ff872..d69041b 100644 --- a/ouexam.dtx +++ b/ouexam.dtx @@ -1930,28 +1930,31 @@ % \end{macro} % % \begin{macro}{num.pages} -% \changes{1.1}{1999/04/20}{NJS Renamed label from \cs{page.last}.} -% There is no macro to specify the number of pages in the examination because -% it is done automatically by inserting a \cs{newlabel} that refers to the last -% page directly into the |.aux| file: +% \changes{1.1}{1999/04/20}{NJS Renamed \textt{page.last} label to \texttt{num.pages}.} +% \changes{2.4}{2013/06/05}{NJS Added check for \textsf{hyperref} being loaded.} +% There is no macro to specify the number of pages in the examination because it is done automatically by inserting a \cs{newlabel} that refers to the last page directly into the |.aux| file. The \textsf{hyperref} package redefines the \cs{newlabel} macro (in particular it increases the number of arguments), so we need to test whether \textsf{hyperref} is loaded and write the appropriate string to the |.aux| file. We borrow a technique from the \textsf{pageslts} package of checking for the existence of \cs{Hy@Warning}. (Ideally we would use \cs{if@packageloaded}, but this can't be used after \cs{AtBeginDocument}, and can be foiled by a package loading \textsf{hyperref} \cs{\AtBeginDocument}.) % \begin{macrocode} \AtEndDocument{% - \immediate\write\@auxout{\string\newlabel{num.pages}{{}{\thepage}}}% + \@ifundefined{Hy@Warning}{% hyperref not loaded + \immediate\write\@auxout{\string\newlabel{num.pages}{{}{\thepage}}}% + }{% hyperref loaded + \immediate\write\@auxout{\string\newlabel{num.pages}{{}{\thepage}{}{}{}}}% + }% } % \end{macrocode} % This label is then referenced in \cs{@maketitlepage}. % \end{macro} % % \begin{macro}{num.questions} -% \changes{1.1}{1999/04/20}{NJS New \cs{num.questions} label representing the -% number of questions.} -% Similarly, there is no macro to specify the number of questions in the -% examination. This is calculated using the same method as for the number of -% pages: +% \changes{1.1}{1999/04/20}{NJS Added \cs{num.questions} label representing the number of questions.} +% \changes{2.4}{2013/06/05}{NJS Added check for \textsf{hyperref} being loaded.} +% Similarly, there is no macro to specify the number of questions in the examination. This is calculated using the same method as for the number of pages. % \begin{macrocode} \AtEndDocument{% - \immediate\write\@auxout{% - \string\newlabel{num.questions}{{}{\thequestion}}% + \@ifundefined{Hy@Warning}{% + \immediate\write\@auxout{\string\newlabel{num.questions}{{}{\thequestion}}}% + }{% + \immediate\write\@auxout{\string\newlabel{num.questions}{{}{\thequestion}{}{}{}}}% }% } % \end{macrocode} @@ -2093,10 +2096,8 @@ % % \begin{macro}{\@maketitlepage} % \changes{1.1}{1999/04/20}{NJS Renamed macro from \cs{maketitlepage}.} -% The \cs{@maketitlepage} macro generates an examination title page that -% meets the Otago University requirements for final examination papers. You -% can redefine this if you want to change the format, but normally you would -% not do this. +% \changes{2.4}{2013/06/05}{NJS Added check for \textsf{hyperref} being loaded.} +% The \cs{@maketitlepage} macro generates an examination title page that meets the Otago University requirements for final examination papers. You can redefine this if you want to change the format, but normally you would not do this. % \begin{macrocode} \def\@maketitlepage{% \thispagestyle{titlepage}% @@ -2128,11 +2129,11 @@ \\[\baselineskip]% \end{center}% % \end{macrocode} -% The number of pages is automatically calculated, as described earlier. All we -% need to do is reference the |num.pages| label that we put into the |.aux| -% file: +% The number of pages is automatically calculated, as described earlier. All we need to do is \cs{pageref} the |num.pages| label that we wrote into the |.aux| file, or \cs{pageref*} if \textsf{hyperref} is loaded to inhibit hyperlink generation. % \begin{macrocode} - \underline{This examination paper comprises \pageref{num.pages} pages.}% + \underline{This examination paper comprises % + \@ifundefined{Hy@Warning}{\pageref{num.pages}}{\pageref*{num.pages}} pages.% + }% \\[\baselineskip]% % \end{macrocode} % Print out the instructions for answering questions: