1

I write somes exams using the examdesign class and others using the exam class. Each has its benefits.

One feature about exam that I really like is the macro \numquestions which counts the numbers of questions (defined by \question) in the exam. I wish this feature existed for examdesign. So I am trying to add it myself. However, I am new to counters.

In examdesign questions are defined by an environment:

\begin{question}
\end{question}

and from my initial reading of counters it should be possible to define a counter that simply counts the number of times this environment is used.

Does one need redefine an environment so that it can be counted? Or can one define a counter that follows a pre-existing environment?

MWE:

\documentclass[10pt]{examdesign}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\SectionFont{\large\bfseries\ttfamily}
\ContinuousNumbering
\Fullpages
\NoKey
\NumberOfVersions{1}

\let\namedata\relax

\begin{document}

\begin{examtop}
This exam is worth all the marbles. It contains \thequestion\ questions.
\end{examtop}

\begin{multiplechoice}[]
\begin{question}
  True?
    \choice[!]{True.}
    \choice{False.}
    \choice{Maybe.}
    \choice{Dunno.}
\end{question}
\end{multiplechoice}

\begin{shortanswer}[]
\begin{question}
What is love?
\begin{answer}
Baby don't hurt me. 
\end{answer}
\end{question}
\end{shortanswer}


\begin{examclosing}
This exam contained \thequestion\ questions. 
\end{examclosing}

\end{document}
  • It seems I cannot compile the examdesign class with texlive 2017, but from its source code, it has a counter question that counts the questions. You should be able to access the value with \thequestion. In case you need this number before the last question, the totcount can help with that. – user36296 Sep 25 '17 at 21:12
  • \thequestion will just print "1". Not sure what it is counting - but it is not counting the total number of questions. – invictus Sep 25 '17 at 21:29
  • Where did you put it the code? (please use @ in front of my name to ping me) – user36296 Sep 25 '17 at 22:36
  • @samcarter see the updated MWE. \thequestion is put at the beginning and the end of the exam but it makes no difference. – invictus Sep 26 '17 at 0:40
1

If the total number of questions is enough, you could simply define a new counter and use the etoolbox package to increase this counter for every question.

\documentclass[10pt]{examdesign}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\SectionFont{\large\bfseries\ttfamily}
\ContinuousNumbering
\Fullpages
\NoKey
\NumberOfVersions{1}

\let\namedata\relax

\newcounter{qcount}
\setcounter{qcount}{0}

\usepackage{etoolbox}
\AtBeginEnvironment{question}{\addtocounter{qcount}{1}}

\begin{document}

\begin{examtop}
This exam is worth all the marbles. It contains \theqcount\ questions.
\end{examtop}

\begin{multiplechoice}[]
\begin{question}
  True?
    \choice[!]{True.}
    \choice{False.}
    \choice{Maybe.}
    \choice{Dunno.}
\end{question}
\end{multiplechoice}

\begin{shortanswer}[]
\begin{question}
What is love?
\begin{answer}
Baby don't hurt me. 
\end{answer}
\end{question}
\end{shortanswer}


\begin{examclosing}
This exam contained \theqcount\ questions. 
\end{examclosing}


\end{document}

enter image description here

  • Awesome! Short follow-up: can the counter distinguish between question environments? Say, count MC questions and count short-answer questions. – invictus Sep 26 '17 at 15:57
  • @invictus Yes, if you want this don't increment the counter for the question environment, but for multiplechoice – user36296 Sep 26 '17 at 16:03
  • the trouble is I want to count both MC and short answer questions. I'll open a new question. – invictus Sep 26 '17 at 16:43

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.