I am trying to use the exam class to create a study guide for my students that has all of the answers at the end of the document.
I would like to have the answers automatically labeled by question number and part, but I'm hung up on how to pass the question and part counters to the command I'm using to construct the end notes.
All of my attempts to do this end up labeling all answers with the most recent question and part counter values. My problem seems very related to this question, but I'm unable to bridge the gap between them. I've tried reading through a few posts on expanding arguments, but I don't know enough of the deeper aspects of TeX to understand what's going on.
Here's a (relatively minimal) working example. Again, I would like to have output that numbers answers like "1: 5, 2(a): 9, 2(b): 30, 3: 2 apples".
\documentclass{exam}
\usepackage[utf8]{inputenc}
\usepackage{endnotes}
\def\enotesize{\normalsize}
\def\makeenmark{\relax}
\def\notesname{\normalsize Answers}
\def\answer#1{\endnotetext{#1\\}}
\def\theanswers{\theendnotes}
\begin{document}
\noindent\textbf{Practice Problems}
\begin{questions}
\question How many sides does a pentagon have?
\answer{\thequestion: $5$}
\question Calculate the following:
\begin{parts}
\part $2+7$
\answer{\thequestion(\thepartno): $9$}
\part $5\cdot 6$
\answer{\thequestion(\thepartno): $30$}
\end{parts}
\question If I have four apples and I eat two, how many are left?
\answer{\thequestion: $2$ apples}
\end{questions}
\theanswers
\end{document}