[Tex/LaTex] How to use \titledquestion in the exam class with or without points

exam

When using the exam class, it is possible to have commands like \question[5] or simply \question (i.e. with no points). The former includes the points within parentheses by default, and the latter omits the points and the surrounding parentheses.

To use titled questions within the exam, where the points are surrounded by parentheses, I have used the following command:

\qformat{\bf \thequestiontitle ~(\thepoints) \hfill}

Now, when I use the \titledquestion{my title}[5] and \titledquestion{my title} commands, they do not behave in the same way that the \question[5] and \question commands do. The difference is that the titled versions always end up including parentheses, whether or not points have been specified.

What I want to know is: what is a proper way to modify the argument of \qformat so that the parentheses are only present when a point value has been specified? I was unable to find this in the manual for exam.cls (I assumed it would be somewhere in the section dealing with titled questions).

Best Answer

You can use \if@placepoints to conditionally include the parentheses and the value:

\documentclass{exam}

\makeatletter
\qformat{\bfseries\thequestiontitle\if@placepoints~(\thepoints)\else\fi\hfill}
\makeatother

\begin{document}

\begin{questions}
\titledquestion{my title}[5]
\titledquestion{my title}
\end{questions}

\end{document}

enter image description here