nstanger / ouexam

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

Crash: Verbatim environments followed by blank line at end of question #28

Closed nstanger closed 8 years ago

nstanger commented 10 years ago

Discovered by Mark George. If the very last thing in a question is some sort of verbatim environment (verbatim, lstlisting, etc.) following by a blank line, then ouexam crashes when attempting to insert the number of marks:

! You can't use `\unskip' in vertical mode.
\endquestion ...nning}{\value {qexpected}}\unskip 
                                                  \nobreak \hfil \penalty 50...
l.64 \end{question}

I’m guessing the verbatim environment is putting TeX into vertical mode (they do tend to screw around with things quite a lot).

Things to note:

Minimal (not) working example:

\documentclass{ouexam}

\examyear{2014}
\department{department}
\papernumber{paper}
\papertitle{title}

\begin{document}
\begin{question}{100}
    bla bla

    \begin{verbatim}
        bla bla bla
    \end{verbatim}

\end{question}
\end{document}

Remove the blank line after \end{verbatim} and it’s fine.

nstanger commented 10 years ago

Relevant things from The TeXbook:

nstanger commented 10 years ago

The \vskip-\lastskip approach seems to work fine.

nstanger commented 10 years ago

Ah, an interesting wrinkle: it only fails if there is a blank line following the verbatim environment and there is text before the verbatim. No text or whitespace before the verbatim doesn’t trigger the problem, regardless of following whitespace. The solution is still the same regardless.

nstanger commented 9 years ago

After upgrading to TeX Live 2015, the \vskip-\lastskip solution has stopped working. The document builds fine, but the marks are no longer pulled back to the previous line if there’s space. The breakage with \unskip and verbatims still holds.

nstanger commented 9 years ago

It looks like \lastskip is now always zero for some reason. Switching back to \unskip with a \leavevmode in front of it seems to work OK, except perhaps for too much vertical space after an itemize.