# Creating a new environment for multiple choice questions

I am trying to create a new environment for multiple choice test questions. I want to make sure that every question has a number and has a constant indentation:

1.  Lorem ipsum
dolor sit amet.
Lorem ipsum
dolor sit amet.

2.  Lorem ipsum
dolor sit amet.
Lorem ipsum
dolor sit amet.


I think I should use a minipage for each question in the environment definition. But I don't know how to adjust the spacing so that each question body is aligned. What should I use for the numbers?

Edit: I'm attaching my working example. Down below is a portion of the latex.ltx file, with enumerate modified to cnumerate to prevent name clashes. I basically want to create an independent environment like the equation or tabular. Just assume that \begin{question} \item Lorem. \end{question} is to create a single indented item with a number.

Why does cnumerate not print numbers? The indentation is fine, but there is no numbers. I print \thecnumi for each item, and it works, but the numbers do not show up in the labels.

cnumerate.sty:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{cnumerate}
[1999/03/05 v3.00 cnumerate extcnsions (DPC)]

% latex.ltx

\newcount\@cnumdepth \@cnumdepth = 0
\@definecounter{cnumi}
\@definecounter{cnumii}
\@definecounter{cnumiii}
\@definecounter{cnumiv}
\def\cnumerate{%
\ifnum \@cnumdepth >\thr@@\@toodeep\else
\edef\@cnumctr{cnum\romannumeral\the\@cnumdepth}%
\expandafter
\list
\csname label\@cnumctr\endcsname
{\usecounter\@cnumctr\def\makelabel##1{\hss\llap{##1}}}%
\fi}
\let\endcnumerate =\endlist
\endinput


the main file, doc.tex

\documentclass{article}
\usepackage{cnumerate}
\begin{document}
\begin{cnumerate}
\item Lorem ipsum.
\end{cnumerate}
end{document}

-
– Peter Grill Oct 25 '12 at 18:54
As an aside, might I recommend the exam document class? It's a lot easier for things like this. If you need custom question numbers (not automagic), I've written a few macros for that. – Sean Allred Oct 25 '12 at 23:24
@vermiculus The exam class does exactly what I want, especially the multiple choice questions. I'm surprised I didn't come across that before. I am going to delve into the source code to make it suit my needs. Perhaps you could post your comment as an answer so I could mark it? – hos Oct 26 '12 at 8:19

Might I suggest the exam document class?

Sample document:

\documentclass{exam}

\usepackage{lipsum}

\firstpagefootrule % Use a footer rule on the first page
\runningfootrule   % and so on (note that this does not cancel out \firstpagefootrule

% define the header for the first page (left, center, right), and so on
\firstpageheader{MATH 351 -- Analysis}{\large \sc Fall 2012 Midterm}{\today}
\firstpagefooter{}{\thepage\ of \numpages}{}
\runningheader{MATH 351 -- Analysis}{Fall 2012 Midterm}{\today}
\runningfooter{}{\thepage\ of \numpages}{}

\begin{document}
Read each question carefully. % Preliminary instructions
\begin{questions}
\question[50] How long should a man's legs be? % This question is worth 50 points
\begin{solutionorlines}[1in] % If \printanswers is specified,
% the solution will be printed.
% Otherwise, a box 1 inch tall
Long enough to reach the ground!
\end{solutionorlines}
\question[$\infty$] \lipsum[1]   % arbitrary symbolic point values
$$\int_0^{2\pi} \sin x\ \mathbf{d}x$$
\begin{solutionorbox}[2in]
\lipsum[2]
$$\int_0^{2\pi} \sin x\ \mathbf{d}x = 0$$
\end{solutionorbox}
\uplevel{\lipsum[1-2]} % Perhaps a different part of the exam? More instructions?
\newpage
\question \lipsum[4]
\begin{parts}
\part[10] \lipsum[5]
\begin{solutionorbox}[2in]
\lipsum[10]
\end{solutionorbox}
\part[15] \lipsum[6]
\begin{solutionorbox}[2in]
\lipsum[12]
\end{solutionorbox}
\end{parts}
\end{questions}
\end{document}


produces , while adding \printanswers to the preamble will produce If you would like custom question labels (instead of simply incremental), I've written a few new commands for that:

% for the exam class
\newcommand{\xquestion}[1]{
% Set the questionlabel to the user's choice
\renewcommand{\questionlabel}{#1}
\question % do the question thing
% and reset it back to default
\renewcommand{\questionlabel}{\thequestion.}
}
\newcommand{\xpart}[1]{
% Set the partlabel to the user's choice
\renewcommand{\partlabel}{#1}
\part % do the part thing
% and reset it back to default
\renewcommand{\partlabel}{(\thepartno)}
}


As always, complete documentation for the document class lives on CTAN.

Hope this helps!

-

I think in this instance (considering your output) it is easiest to use a standard enumerate environment. Possible alignment or counter formatting/cross-referencing could be manipulated/changed using enumitem, if/as needed:

\documentclass{article}
\usepackage{enumitem}% http://ctan.org/pkg/enumitem
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\begin{enumerate}[label=\arabic*.]
\item \lipsum[1-2]
\item \lipsum[3-4]
\item \lipsum[5-6]
\end{enumerate}
\end{document}


lipsum provided some dummy text in paragraph form, Lorem ipsum style.

1. Easily modifiable via enumitem;
2. Breaks across page boundaries; and
3. Standard interface/usage.

For a global take an a specially-created environment question that emulates/clones enumerate, enumitem's interface provides:

\newlist{question}{enumerate}{3}% Clone enumerate as question environment (depth of 3)
\setlist[question]{label=\arabic*.}% All labels are "\arabic."


Now you can use

\begin{question}
\item \lipsum[1-2]
\item \lipsum[3-4]
\item \lipsum[5-6]
\end{question}


For more detail, see the enumitem documentation (section 7 Cloning the basic lists, p 10).

-
I've considered using enumerate, but what I want is more complicated: Create a new environment question which has its own contextual syntax, like a tabular environment. You know, like {c c c}. I wanted to borrow from the enumerate package and located enumerate.sty, but it was just recently and I didn't have time to understand any of that TeX code. Enumerate has a TeX definition instead of a LaTeX one. Do you have any suggestions on how to clone the definition of enumerate to provide for my needs? – hos Oct 25 '12 at 18:38
@cgnieder I am aiming at writing a standalone class with many features. I need to build from the lowest level, so I tried copying and reverse-engineering enumerate.sty. I now need to find where enumdepth and enumi are defined, because they are not in the sty file. Do you have any suggestions? – hos Oct 25 '12 at 18:54
@OnurSolmaz: It is difficult to provide a more appropriate answer without having details as to what you want to do. Best way to do that would be to It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. At least as far as you can take it. Then you can ask specific questions about it which could be more directly addressed. – Peter Grill Oct 25 '12 at 19:20
@PeterGrill I isolated the enumerate environment from the files base/latex.ltx and tools/enumerate.sty. However, when I use the environment, it compiles but does not show the numbers. How and where can I attach the code, as a MWE? – hos Oct 25 '12 at 19:57
@OnurSolmaz: You should edit your original post and append/insert the code. Why does the enumitem solution not seem satisfactory? I don't understand. Is it because you want it to be "stand alone" and not depend on anything else? – Werner Oct 25 '12 at 20:02

I've found out that each class defines its own style enumeration labels. So I borrowed from article and modified for cnumerate. Adding the following to cnumerate.sty solves the problem. Also, the choices environment from the exam does something similar to what I need, and can be modified accordingly.

\newtoks\@cnLab\renewcommand\thecnumi{\@arabic\c@cnumi}
\renewcommand\thecnumii{\@alph\c@cnumii}
\renewcommand\thecnumiii{\@roman\c@cnumiii}
\renewcommand\thecnumiv{\@Alph\c@cnumiv}
\newcommand\labelcnumi{\thecnumi.}
\newcommand\labelcnumii{(\thecnumii)}
\newcommand\labelcnumiii{\thecnumiii.}
\newcommand\labelcnumiv{\thecnumiv.}
\renewcommand\p@cnumii{\thecnumi}
\renewcommand\p@cnumiii{\thecnumi(\thecnumii)}
\renewcommand\p@cnumiv{\p@cnumiii\thecnumiii}

-