3

Following-up this answer, I would like to know to make \NAMEquestions print the word "questions" in case of multiple questions exam and "question" in case of a single question exam?

For example, in a two-question exam, \NAMEquestions prints TWO questions, while in a single question exam, it prints ONE question. The same applies to \NAMEpages and \NAMEpoints.

So, in the MWE below, the desired output is:

This exam contains ONE question in ONE page (including the cover) for a total of TEN marks.

\documentclass[addpoints]{exam}

\usepackage{fmtcount,etoolbox}

\makeatletter
\let\NAMEquestions\numquestions
\patchcmd{\NAMEquestions}{\exam@numquestions}{{\NUMBERstringnum\exam@numquestions}}{}{}
\let\NAMEpages\numpages
\patchcmd{\NAMEpages}{\exam@lastpage}{{\NUMBERstringnum\exam@lastpage}}{}{}
\let\NAMEpoints\numpoints
\patchcmd{\NAMEpoints}{\exam@numpoints}{{\NUMBERstringnum\exam@numpoints}}{}{}
\makeatother

\begin{document}

This exam contains \textbf{\NAMEquestions} in \textbf{\NAMEpages} (including the cover) for a total of \textbf{\NAMEpoints}.

\begin{questions}
  \question[10] single question
\end{questions}

\end{document}
3

You can condition on the value of the respective macros used to print the named numbers:

enter image description here

\documentclass[addpoints]{exam}

\usepackage{fmtcount,etoolbox}

\makeatletter
\let\NAMEquestions\numquestions
\patchcmd{\NAMEquestions}{\exam@numquestions}{{\NUMBERstringnum\exam@numquestions} question\ifnum\exam@numquestions>1 s\fi}{}{}
\let\NAMEpages\numpages
\patchcmd{\NAMEpages}{\exam@lastpage}{{\NUMBERstringnum\exam@lastpage} page\ifnum\exam@lastpage>1 s\fi}{}{}
\let\NAMEpoints\numpoints
\patchcmd{\NAMEpoints}{\exam@numpoints}{{\NUMBERstringnum\exam@numpoints} mark\ifnum\exam@numpoints>1 s\fi}{}{}
\makeatother

\begin{document}

This exam contains \textbf{\NAMEquestions} in \textbf{\NAMEpages} (including the cover) for a total of \textbf{\NAMEpoints}.

\begin{questions}
  \question[10] single question
\end{questions}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.