I'm trying to produce an answer key for an exam. What I'd like to do is to produce a list of only the answers. (Technically I'm planning on putting a grading checklist into the solutions - I want to see as many questions' checklists on one page as possible while grading)
I was hoping to use \ifprintanswers
but when I use \thequestion in the \solutiontitle
it always shows up as zero.
Also, when I use this approach (which is based on the endnotes approach I found on StackExchange) I need to first compile the document (using XeLaTeX) WITHOUT \printanswers
, then go back and run it a second time with \printanswers
turned on. If I don't it complains about a missing .ent
file, which I assume is where the endnotes are being stored.
I was hoping there's some way to capture the value of \thequestion
when I run it without the \printanswers
so that it'll still be there on the second run.
MWE:
\documentclass[addpoints, 12pt]{exam}
%TODO: Turn this on/off based on need for answer key
\printanswers
\unframedsolutions
% This will number the answers
% from https://tex.stackexchange.com/questions/284672/numbering-solutions-in-exam-environment#comment686934_284672
\renewcommand{\solutiontitle}{\noindent\textbf{Solution \thequestion:}}
% this exists to collect up the solutions/answers in one place:
% from https://tex.stackexchange.com/a/237849/131222
\usepackage{endnotes}
\def\enotesize{\normalsize}
\def\makeenmark{\relax}
\def\notesname{Answers}
\def\answer#1{\endnotetext{\vspace*{-3.5ex}\begin{solution}#1\end{solution}\unskip}}
\def\theanswers{\theendnotes \medskip}
\begin{document}
\ifprintanswers % prints out the answer key, based on \printanswers in the preamble
\newpage
\theanswers
\else % prints out the exam itself
\begin{questions}
\qformat{\large \textbf{Question:} \thequestion: \thequestiontitle\hfill(\thepoints)}
\titledquestion{Syntax and Semantics}[30]
\answer{Answer for Syntax and Semantics \thequestion DONE}
\titledquestion{Second Question}[30]
\answer{Answer for Second Question \protect \thequestion DONE}
\titledquestion{Third Question}[30]
\answer{Answer for Third Question \protect \thequestion DONE}
\end{questions}
\fi
\end{document}
For what it's worth, I wasn't able to get solution numbers to appear when I followed this post, either