I am trying to use the etoolbox with the document class exam
. I have had good luck using etoolbox with the article
class, but I can't get it to work inside of the question
environment. Here's a minimal example:
\documentclass[12pt]{exam}
\usepackage{etoolbox}
\def\QuizKey{\newpage }
\newcommand{\answer}[2][0 pt]{
\eappto{\QuizKey}{\noexpand\par\arabic{question}.\ \unexpanded{#2}}
\vspace{#1}
}
\begin{document}
\appto{\QuizKey}{Opening Code}
\begin{questions}
\question When did the Internet first begin?\answer{1985}
\appto{\QuizKey}{Something else to test}
\end{questions}
\appto{\QuizKey}{Ending Code}
\QuizKey
\end{document}
My end result is that the \QuizKey
printout does everything it was told to in the document, except the parts in the questions environment. I'm guessing the \eappto
and \appto
commands aren't able to reach the hook, or perhaps they are not allowed to be used inside of the environment, but it doesn't seem to cause any errors, either. Is there a way I can fix this?