TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had a question about setting up a LaTeX document. I'm not sure if it is proper to post such a question here, but I figured that many people here have experience with the system and might be able to help.

I've been asked to write a list of questions with multiple choice answers. The people who will be using it don't know much about TeX, so I need to try to make the code as robust as possible. I've written a command to automatically produce the multiple choice options: the command


roughly outputs

(A) 2  (B) 3  (C) 5  (D) 7  (E) 11

What I'd like to do is add in a sixth argument that will take the answer to the question and then automatically append it to a list at the end of the document, essentially creating an answer key. The problem is that it's not clear to me how to call the sixth argument of every \mc command into an \enumerate environment at the end of the document.

I would greatly appreciate any tips or suggestions anyone may have regarding this project.

share|improve this question

migrated from math.stackexchange.com May 29 '12 at 3:04

This question came from our site for people studying math at any level and professionals in related fields.

Welcome to TeX.SE. – Peter Grill May 29 '12 at 3:29
I'd recommend looking at the exam package. – Caramdir May 29 '12 at 3:29
up vote 9 down vote accepted

You could adapt the solution from How keep a running list of strings and then process them one at a time for this purpose:

enter image description here




    % code to display the multiple choice for #1...#5



The list of answers are:

\foreach \answer in \AnswersList {%
    \item \answer
share|improve this answer

Here's a possible solution using the features provided by the exam document class and the answers package:





One of these things is not like the others; one of these things is not
the same. Which one is different?

\choice John
\choice Paul
\choice George
\choice Ringo
\choice Socrates

One of these numbers is perfect.

\choice $2$
\choice $28$
\choice $5$
\choice $3$
\choice $7$



enter image description here

share|improve this answer
I know the answer for 2 is not 7 (just in case). – Gonzalo Medina May 29 '12 at 4:04
However, it's the successor of one :) – Tom Bombadil May 29 '12 at 13:03

Your Answer


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.