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? Commented Jul 21, 2016 at 14:08
  • This means the result should be 10 in your given example? Commented Jul 21, 2016 at 14:11
  • 1
    @Özgür Your new edit is not what Christian was talking about though. Commented 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! :-(((( Commented Jul 21, 2016 at 14:34
  • @Özgür: All work useless :-( Commented 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} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.