Writing MCQs in LaTeX: the qanda class

I was writing a series of practice multi-choice questions for the class I teach when I decided I wanted to write a LaTeX function to automate the formatting. I wanted to include the answer as an argument of that function (possibly with room for an explanation) but not to display the answer until the end of the document. (This is a reasonably simple process. For a more hardcore setup, see the eqexam package.)

I hacked away at the endnotes package until I got what I wanted. Editing packages is a pain though, so I summarized the changes into a Questions and Answers class: qanda.cls.

This does the dirty work in the background and defines two new commands: \q and \qtf. The former takes six arguments: the question, four multi-choice options, and the answer. The latter takes four arguments: the question, two multi-choice options (e.g. true and false, thus the tf in command name), and the answer.

This makes writing multi-choice questions very easy. Here is some sample code.
[sourcecode]
\documentclass{qanda}
\title{An Example of the qanda Class}
\author{Enda Hargaden}
\begin{document}
\maketitle
This document is an example of the output of the qanda (“q and a”) class.

\q{Who wrote \textit{Animal Farm}?}{Hargaden}{Orwell}{Marx}{Huxley}{Orwell}
\qtf{There are subtle historical parallels in \textit{Animal Farm}.}{True}{False}{True; it is an allegory for the unfortunate route Communism took.}
\q{Who wrote \textit{Capital}?}{Hargaden}{Orwell}{Marx}{Huxley}{Marx}

\newpage
\theendnotes

\end{document}
[/sourcecode]
This produces this nifty document.

To use the qanda class:

  1. Download qanda.cls
  2. Place it in the folder your .tex is in
  3. Start your document with \documentclass{qanda}

To produce the answers to your questions, simply include the \theendnotes command where you want them in your document. Preface this with \newpage if you want them on a new page.

Note that the qanda class is based on the scrartcl class, so you need that on your computer. You also will need to have installed the enumerate and setspace packages.

Enjoy!

2 thoughts on “Writing MCQs in LaTeX: the qanda class”

  1. Sure, Saadia. Add the following code to your document. (You may edit the qanda.cls file to include this, or you may manually add this to any exam you are writing.)

    \newcommand{\qfive}[7]{\vspace{\baselineskip} \textbf{\endnotemark . #1} %
    \begin{enumerate}[(a)]\setlength{\itemsep}{0.5pt}
    {\setlength\itemindent{0.75cm} \item #2}
    {\setlength\itemindent{0.75cm} \item #3}
    {\setlength\itemindent{0.75cm} \item #4}
    {\setlength\itemindent{0.75cm} \item #5}
    {\setlength\itemindent{0.75cm} \item #6}
    \end{enumerate}
    \endnotetext{ #7}%
    }

    This makes a new command named \qfive that lets you include five potential answers. For example

    \qfive{What is 2 times 2?}{2.718}{0}{2}{4}{3.14}{The correct answer is 4}

    will create a simple question with five choices. Don’t forget to include the \theendnotes command to print your answers.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top