0

Referring to the question below Set counter in exam class to a count based on the first set of questions

I would like to change the answer for this. There are \total{s}\ short questions.

From There are 2 short questions to There are TWO short questions.

Thanks.

4

The package fmtcount defines the command \numberstring{counter}. Adding this to the answer in Set counter in exam class to a count based on the first set of questions, we get

\documentclass{exam}

\usepackage{totcount}
\usepackage{fmtcount}
\makeatletter
\newcommand{\extractcntrvalue}[1]{%
  \value{#1@totc}%
}
\makeatother



\newtotcounter{s}
\setcounter{s}{0}
\newtotcounter{e}
\setcounter{e}{0}
\newcommand{\squestion}[0]{\stepcounter{s}\question}
\newcommand{\equestion}[0]{\stepcounter{e}\question}





\begin{document}
\fullwidth{\Large \textbf{Short questions}}    
There are \total{s}\ short questions. %display the number of short questions.

\begin{questions}
\squestion
This is the first short question.
\squestion
This is the second short question.
\end{questions}


\fullwidth{\Large \textbf{Essay questions}}
There are \total{e}\ essay questions. %display the number of essay questions.

\begin{questions}
  \setcounter{question}{\extractcntrvalue{s}}  % Set the counter to start with 3
  \equestion
This is the first essay question.
\equestion
This is the second essay question.
\equestion
This is the third essay question.
\equestion
This is the fourth essay question.
\end{questions}

For the record there is a total of \numberstring{question} questions.

\end{document}

Note that if you want to extract the information from a "total" counter, this will not work, because totcount counters are not counters in the LaTeX sense.

However, we can use the command \extractcntrvalue defined above together with \numeberstringnum command:

\documentclass{exam}

\usepackage{totcount}
\usepackage{fmtcount}
\makeatletter
\newcommand{\extractcntrvalue}[1]{%
  \value{#1@totc}%
}

\makeatother



\newtotcounter{s}
\setcounter{s}{0}
\newtotcounter{e}
\setcounter{e}{0}
\newcommand{\squestion}[0]{\stepcounter{s}\question}
\newcommand{\equestion}[0]{\stepcounter{e}\question}





\begin{document}
\fullwidth{\Large \textbf{Short questions}}    
There are \numberstringnum{\extractcntrvalue{s}} short questions. %display the number of short questions.

\begin{questions}
\squestion
This is the first short question.
\squestion
This is the second short question.
\end{questions}


\fullwidth{\Large \textbf{Essay questions}}
There are \numberstringnum{\extractcntrvalue{e}} essay questions. %display the number of essay questions.

\begin{questions}
  \setcounter{question}{\extractcntrvalue{s}}  % Set the counter to start with 3
  \equestion
This is the first essay question.
\equestion
This is the second essay question.
\equestion
This is the third essay question.
\equestion
This is the fourth essay question.
\end{questions}

For the record there is a total of \numberstring{question} questions.

\end{document}

enter image description here

2
  • thank you, but why I can't use \value{s} alone with out \extractcntrvalue{s}
    – Statguy
    Mar 20 '17 at 4:12
  • 1
    I think it is discussed in the linked question
    – Boris
    Mar 20 '17 at 4:19

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.