1

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 \printanswersso 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

1 Answer 1

1

If you examine the .ent file, you will see that none of the macros inside the \endnotetext are expanded. This means that in the second run you have a bunch of solutions with no questions. At the least, you need to increment the question counter.

\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}\stepcounter{question}\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 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}
2
  • That worked great! Thanks a ton! Sep 3, 2019 at 5:30
  • Also, it's fascinating to look through the .ent file - thanks for pointing out that one can do that (it totally hadn't occurred to me before, but now seems like a really obvious think to try in the future - thanks! :) ) Sep 3, 2019 at 5:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .