[Tex/LaTex] Customized bonus questions in exam class

exam

I'm using the exam class (with the addpoints option) to create assignments, and I want to create some bonus questions. I have a customized question format that looks like this:

\qformat{Question \thequestion: [\totalpoints]}

which works fine for regular questions.

However, the \totalpoints command doesn't return a value for bonus questions, and so those questions are incorrectly marked as having 0 points.

I hacked this by redefining \qformat (before the bonus questions) to be

\qformat{Question \thequestion: [\totalbonuspoints]}

which works fine. But I'd rather have a single designation that works for all question (bonus or not). How might I do that ?

note: I could have used \thepoints in the definition, but some of my questions have parts, and so \totalpoints is needed to add up the points.

Best Answer

Looking at the source of exam.cls there is a if@bonus that you can use to test if you are typesetting a bonus or a regular question. Hacking a bit you can do something like

\makeatletter
\newcommand\thetotalpoints{%
  \if@bonus
    [\totalbonuspoints\ bonus points]
  \else
    [\totalpoints\ points]
  \fi
}
\makeatother

\qformat{Question \thequestion: \thetotalpoints \hfill}