Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to set up an environment for multiple choice questions, such that the list of the correct answers, and some lines of comments, will be typeset at the end of the chapter.

Something like this:

\question
This is the question
\choice First guess
\truechoice Second guess {This is a comment that goes at the end of the chapter}
\choice Third guess

At the end of the chapter, I would like to have a list of question numbers (automatically written), the correct answer (correctly numbered), and the comment.

How could i do?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Here's a bit of a hack using the endnotes package. I tried to inline some comments.

\documentclass{article}
\usepackage{endnotes}

% Define two new counters for ease of using.
\newcounter{questionnumber}
\newcounter{choicenumber}[questionnumber]
% Formatting the counters, this is where you change how the counters appear.
\renewcommand*\thequestionnumber{\arabic{questionnumber}.}
\renewcommand*\thechoicenumber{\alph{choicenumber})}

% Define the \question and \choice commands to be similar to what is 
% given in the OP
\newcommand*\question{\item}
\newcommand*\choice{\item}
% Here's a bit of a hack: \endnotetext stores the \meaning of the its argument
% in the endnotetext file, so the macros aren't expanded. I use \edef to fully
% expand the current \thechoicenumber, and use \expandafter to stuff it into
% the argument for \endnotetext. Suggestions for improvements are welcome!
\newcommand*\entreplace[1]{\endnotetext[\value{questionnumber}]{#1}}
\makeatletter
\newcommand\truechoice[1]{\item \protected@edef\currentcount{\thechoicenumber~~#1} \expandafter\entreplace\expandafter{\currentcount}}
\makeatother
% Define a choices environment, just a list basically. 
\newenvironment{choices}{\begin{list}{\thechoicenumber}{\usecounter{choicenumber}}}{\end{list}}

% These are to set up the endnotes. The first makes the endnote marks look 
% like the question numbering (as opposed to being in superscript). The second
% sets the endnotes heading to read "Answers". 
\renewcommand*\makeenmark{\theenmark.~~}
\renewcommand*\notesname{Answers:}

\begin{document}
\begin{list}{\thequestionnumber}{\usecounter{questionnumber}}
\question Some question
\begin{choices}
\choice False choice
\choice Bad choice
\truechoice{This is true for no good reason} True choice.
\end{choices}

\question Who won the 2012 Presidential Election in US?
\begin{choices}
\choice Mitt Romney
\truechoice{Without even counting Florida} Barack Obama
\end{choices}
\end{list}

% Print the "answers"
\theendnotes
\end{document}

And here's the output:

enter image description here


Edit:

In response to zar's comment below, if we want the input syntax to be

\truechoice{Choice text}{Justification/commentary}

instead of

\truechoice{Justification/commentary} Choice text

one can change the definition to

\newcommand\truechoice[2]{\item #1 \protected@edef\currentcount{\thechoicenumber~~#2} \expandafter\entreplace\expandafter{\currentcount}}

But this way you have to put the choice text in braces, for example, you must write

\truechoice{True Choice!}{That choice was true for no good reason} 

Edit 2: S.G. and zar noticed some problems with my abuse of the \edef function. A more complicated, but functionally better hack is the following (I'm including the full file below for easy of copy-pasting)

\documentclass{article}
\usepackage{endnotes}

% Define two new counters for ease of using.
\newcounter{questionnumber}
\newcounter{choicenumber}[questionnumber]
% Formatting the counters, this is where you change how the counters
% appear.
\renewcommand*\thequestionnumber{\arabic{questionnumber}.}
\renewcommand*\thechoicenumber{\alph{choicenumber})}

% Define the \question and \choice commands to be similar to what is 
% given in the OP
\newcommand*\question{\item}
\newcommand*\choice{\item}
% Here's a bit of a hack: \endnotetext stores the \meaning of the its argument
% in the endnotetext file, so the macros aren't expanded. I use \edef to fully
% expand the current \thechoicenumber, and use \expandafter to stuff it into
% the argument for \endnotetext. Suggestions for improvements are welcome!
\newcommand*\entreplace[1]{\endnotetext[\value{questionnumber}]{#1}}
\newcommand\truechoice[2]{\item #1 \edef\tempchoice{\thechoicenumber} \expandafter\def\expandafter\currentcount\expandafter{\tempchoice \ \ #2} \expandafter\entreplace\expandafter{\currentcount}}

% Define a choices environment, just a list basically. 
\newenvironment{choices}{\begin{list}{\thechoicenumber}{\usecounter{choicenumber}}}{\end{list}}

% These are to set up the endnotes. The first makes the endnote marks look 
% like the question numbering (as opposed to being in superscript). The second
% sets the endnotes heading to read "Answers". 
\renewcommand*\makeenmark{\theenmark.~~}
\renewcommand*\notesname{Answers:}

\begin{document}
\begin{list}{\thequestionnumber}{\usecounter{questionnumber}}
\question Some question
\begin{choices}
\choice False choice
\choice Bad choice
\truechoice{True choice}{This is true for no good reason $1+1$. Let me
add more text. There should be four or five lines. Can I put displayed
math in here? \emph{test} \[ E = mc^2\] Some more text.}
\end{choices}
\end{list}

% Print the "answers"
\theendnotes
\end{document}

and this is what it outputs

enter image description here

which as one can see correctly handles the \emph command and math (both displayed and inline) environments.

share|improve this answer
    
how could I modify the \truechoice statement in order to have the answer after the question? –  zar Nov 9 '12 at 20:23
1  
@Zar: I don't understand what it is you want, do you mean you want the input order to be \truechoice{Choice text}{Justification} instead of \truechoice{Justification} Choice text? In that case see edit. –  Willie Wong Nov 12 '12 at 9:45
    
yes, thank you. –  zar Nov 13 '12 at 23:18
    
@Willie Wong: I feel the endnotes must be text. How can I use lengthy mathematical equations in the justification part as \truechoice{text includes mathematical equations 4 or 5 lines}True choice –  S.G. Sekaran Dec 8 '12 at 17:44
    
I have another problem: if the \truechoice second parameter contains something like "\emph{some text}", LaTeX stops compiling and exits with an error: ! Use of \@item doesn't match its definition. \text@command #1->\def \reserved@a { #1}\ifx \reserved@a \@empty \let \check@... –  zar Dec 8 '12 at 22:21
show 10 more comments

You could use the exsheets package for this. It's purpose is to print the solutions of exercises in another part of the document. However, it was not designed with multiple choice tests in mind which means you'd have to type them twice:

\documentclass{book}

\usepackage[load-tasks]{exsheets}

% we could use `enumitem' for this (or...)
% but exsheets v0.4 provides a command to generate list-like
% environments
% this defines an environment {choices} that uses a square box as
% item symbol, \choice as command to start an item and uses 2 columns:
\NewTasks[style=multiplechoice]{choices}[\choice](2)

\newcommand*\correct{\PrintSolutionsTF{\checkedchoicebox}{\choicebox}}

\begin{document}

\chapter{Some chapter}
\section{Exercises}
\begin{question}
 \begin{choices}
  \choice First choice
  \choice Second choice
  \choice[\correct] Third choice
  \choice Fourth choice
 \end{choices}
\end{question}
\begin{solution}
 \begin{choices}
  \choice First choice
  \choice Second choice
  \choice[\correct] Third choice\\
    This is the right choice because...
  \choice Fourth choice
 \end{choices}
\end{solution}

\begin{question}
 \begin{choices}
  \choice First choice
  \choice[\correct] Second choice
  \choice Third choice
  \choice Fourth choice
 \end{choices}
\end{question}
\begin{solution}
 \begin{choices}
  \choice First choice
  \choice[\correct] Second choice\\
    This is the right choice because...
  \choice Third choice
  \choice Fourth choice
 \end{choices}
\end{solution}

\section{Solutions}
\printsolutions[chapter]

% similar for other chapters

\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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