# Exam class: write details of points with \totalpoints

I use the exam class to produce exams for students, and I want to make a kind of questions, which puts in front the total points, but given detailed. I give an example:

\documentclass[addpoints]{exam}

\pointformat{}
\qformat{\textbf{Question \thequestion}. [Points of question \thequestion: \totalpoints]\hfill}

\begin{document}
\begin{questions}
\question
\begin{parts}
\part[3]
\part[2]
\end{parts}
\end{questions}
\end{document}


which gives this output:

I want to obtain, as output, the detailed points of the question, so precisely something like:

[Points of question 1: 3+2=5 points]


How can I obtain this ?

• The information is stored on the aux files as \gdef\pointsofq@i{5}. Alas, no points per part are so saved. – John Kormylo Nov 24 '17 at 18:00
• So we must install a similar command storing the information on the aux file for parts... something like \gdef\pointsofpartofq{.}.. I'm not a programmer but I think that it's not very difficult.. It's surprising that this macro does not exist because it's useful, I think ! – Faouzi Bellalouna Nov 24 '17 at 18:38
• For idea ! I found in exam.cls the command \def\do@cvloop{...} which seems to do the loops for computing \totalpoints – Faouzi Bellalouna Nov 24 '17 at 18:49
• I haven't found exercise@parts in exam.cls. where is it ? – Faouzi Bellalouna Nov 25 '17 at 6:33
• The macro \def\begingradingrange seems to do something like my purpose – Faouzi Bellalouna Nov 25 '17 at 7:16

The key was figuring out the \@doitem was actually processing the argument. While it is defined globally, I only want to modify/replace it for parts.

The \expandafters are to expand \else and \fi first.

\documentclass[addpoints]{exam}

\pointformat{}
\qformat{\textbf{Question \thequestion}. [Points of question \thequestion: \details\totalpoints]\hfill}

\makeatletter
\newcommand{\details}{\@ifundefined{details@\roman{question}}{}{\csname details@\roman{question}\endcsname =}}

\newcommand{\@details}{}% reserve global name

\let\normal@parts=\parts
\let\endnormal@parts=\endparts
\renewenvironment{parts}% no arguments?
{\xdef\@details{\@empty}% initialize
\normal@parts
\let\normal@part=\@doitem
\let\@doitem=\my@part
}{%
\endnormal@parts
\ifx\@empty\@details
\else
\immediate\write\@auxout{\string\gdef\string\details@\roman{question}{\@details}}
\fi
}

\newcommand{\my@part}[1][\@empty]{%
\ifx\@empty#1\relax
\expandafter\normal@part
\else
\ifx\@empty\@details
\xdef\@details{#1}%
\else
\xdef\@details{\@details +#1}%
\fi
\expandafter\normal@part\expandafter[\expandafter#1\expandafter]%
\fi
}%
\makeatother

\begin{document}

\begin{questions}
\question[5]
\question
\begin{parts}
\part[3]
\part[2]
\end{parts}
\end{questions}
\end{document}