nstanger / ouexam

University of Otago LaTeX exam template
0 stars 1 forks source link

hyperref crashes with \ref to a manually-defined label #47

Closed nstanger closed 4 years ago

nstanger commented 4 years ago

e.g., \otherinstructions{Please read and abide by the Academic Integrity Notice on page~\pageref{page.integrity}. …} causes a crash:

Runaway argument?
{\@secondoffive }\fi . You should upload a \textbf {single} PDF or Mi\ETC.
! Paragraph ended before \Hy@setref@link was complete.
<to be read again> 
                   \par 
l.85 \maketitlepage

page.integrity is manually created on page 2:

\makeatletter
\immediate\write\@auxout{\string\newlabel{page.integrity}{{}{\thepage}}}
\makeatother

Could it be crashing because the label hasn’t been defined yet?

nstanger commented 4 years ago

The solution is to use \phantomsection from hyperref instead of manually writing the auxiliary file:

\phantomsection\label{page.integrity}

Note: not useful for num.pages as it requires hyperref.

nstanger commented 4 years ago

Probably not worth officially documenting other than here, as it’s rather an extreme edge case.