0

MWE

\documentclass[11pt,paper=a4,answers]{exam}
\usepackage{environ}

\newtoks\allanswers

\NewEnviron{answer}
{%
 \edef\temp{%
   \the\allanswers % the previous ones
   \thequestion) \thechoice
   \noexpand\par % maybe \par has been redefined
   \unexpanded\expandafter{\BODY}%
 }
 \global\allanswers=\expandafter{\temp}
}

    \newcommand{\Cchoice}{\CorrectChoice\begin{answer}\end{answer}}
\newcommand{\showallanswers}{%
\ifprintanswers {\centering ANSWER KEYS \par} \textbf{\the\allanswers} \fi}

\begin{document}

\begin{questions}
\question One
\begin{choices}
\Cchoice True
\choice False
\choice False
\choice False
\choice False
\end{choices}

\question Two
\begin{choices}
\choice False
\choice False
\Cchoice True
\choice False
\choice False
\end{choices}
\end{questions}
\showallanswers
\end{document}

That I want output,

enter image description here

That is, I want all true choices counting.

Number of choice A's

Number of choice B's

Number of choice C's

Number of choice D's

Number of choice E's

Is it possible?

5
  • I don't understand this question! Do you want to count the total numbers of choice questions?
    – user31729
    Jul 21, 2016 at 14:08
  • This means the result should be 10 in your given example?
    – user31729
    Jul 21, 2016 at 14:11
  • 1
    @Özgür Your new edit is not what Christian was talking about though.
    – Alenanno
    Jul 21, 2016 at 14:31
  • 1
    @Özgür: This is really annoying -- I asked you about that the output should be 10 -- you said 'yes', now you're changing the question completely! :-((((
    – user31729
    Jul 21, 2016 at 14:34
  • @Özgür: All work useless :-(
    – user31729
    Jul 21, 2016 at 14:36

1 Answer 1

2

Using etoolbox's arithmetic with macro commands:

\documentclass[11pt,paper=a4,answers]{exam}
\usepackage{ifthen}
\usepackage{etoolbox}
\usepackage{environ}

\newtoks\allanswers

\NewEnviron{answer}
{%
 \edef\temp{%
   \the\allanswers % the previous ones
   \thequestion) \thechoice
   \noexpand\par % maybe \par has been redefined
   \unexpanded\expandafter{\BODY}%
 }
 \global\allanswers=\expandafter{\temp}
 \csnumgdef{ctrchoice\thechoice}{\csname ctrchoice\thechoice\endcsname + 1} % Increments ctrchoice\thechoice if it is defined; sets it to one otherwise.
}

    \newcommand{\Cchoice}{\CorrectChoice\begin{answer}\end{answer}}
\newcommand{\showallanswers}{%
\ifprintanswers {\centering ANSWER KEYS \par} \textbf{\the\allanswers} \fi}


\newcommand{\showchoicecounts}[1]{% The argument is the number of choices
    \setcounter{choice}{0}
    \whiledo{\value{choice} < #1}{%
        \stepcounter{choice}%
        \csnumgdef{ctrchoice\thechoice}{\csname ctrchoice\thechoice\endcsname}% Set ctrchoice\thechoice to 0 if undefined
        % Edit the following line to do formatting
        \thechoice: \csname ctrchoice\thechoice\endcsname \newline}}

\begin{document}

\begin{questions}
\question One
\begin{choices}
\Cchoice True
\choice False
\choice False
\choice False
\choice False
\end{choices}

\question Two
\begin{choices}
\choice False
\choice False
\Cchoice True
\choice False
\choice False
\end{choices}
\end{questions}
\showallanswers


\showchoicecounts{5}
\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.