\documentclass[12,lettersize]{article}
%%%% PACKAGE FOR MARGINS %%%% \usepackage[letterpaper,left=1in,right=1in,top=1in,bottom=1in]{geometry}
%%%% PACKAGE FOR SETTING LINE SPACING %%%% \usepackage{setspace}
%%%% IFTHEN PACKAGE FOR FIGURING WHETHER CORRECT ANSWERS LOOK DIFFERENT %%%% \usepackage{ifthen}
%%%% SHOW CORRECT ANSWER??? %%%% \def\showcorrect{true} %\def\showcorrect{false}
%%%% QUESTION COUNTER %%%% \newcounter{qcounter}
%%%% ANSWER COUNTER RESETS ON CHANGE OF QUESTION COUNTER %%%% \newcounter{acounter}[qcounter]
%%%% MARKER (DOUBLE ASTERISK) FOR FRONT OF CORRECT ANSWER %%%% \def\correctmarker{init}
%%%% ENVIRONMENT FOR LIST FOR QUESTIONS LIST %%%% \newenvironment{questions}{ % %%%% Begin preliminary environment code \begin{list}{ % %%%% Begin list item label code \bfseries\upshape\arabic{qcounter}: }{ % %%%% Begin list item body code \usecounter{qcounter} \setlength{\labelwidth}{1in} \setlength{\leftmargin}{0.25in} \setlength{\labelsep}{0.5ex} \setlength{\itemsep}{2em} } %%%%% End list item body code }{ %%%%% Begin wrapup environment code \end{list} } %%%%% End wrapup environment code
%%%% ENVIRONMENT FOR A SINGLE QUESTION %%%% \newenvironment{question}{\item{}}{}
%%%% ENVIRONMENT FOR THE LIST OF CHOICES FOR A QUESTION %%%% \newenvironment{choices}{ %%%%% begin preliminary environment code \begin{list}{ %%%%% Begin list item label code \bfseries\upshape \correctmarker\alph{acounter}: }{ %%%%% begin list item body code \usecounter{acounter} \setlength{\topsep}{-0.3ex} \setlength{\labelwidth}{1in} \setlength{\leftmargin}{0.7in} \setlength{\labelsep}{0.5ex} \setlength{\rightmargin}{0.5in} \setlength{\itemsep}{1ex} \setlength{\parsep}{0ex} \setstretch{0.8} \setlength{\listparindent}{0.5in} } %%%%% end list item body code }{ \end{list} }
%%%% ENVIRONMENTS FOR A SINGLE WRONG OR A SINGLE CORRECT CHOICE %%%% \newenvironment{choice}{\def\correctmarker{~~~~}\item{}}{} \newenvironment{correctchoice}{ \ifthenelse{\equal{\showcorrect}{true}}{ \def\correctmarker{** ~} \item\bfseries\slshape }{ \def\correctmarker{~~~~} \item{} } }{ \ifthenelse{\equal{\showcorrect}{true}}{% ~~** }{% } }
%%%% THE DOCUMENT ITSELF %%%% \begin{document} Hello world ~\\[0.2in] \begin{questions}
\begin{question}What is LyX?\end{question} \begin{choices} \begin{choice}A wordprocessor.\end{choice} \begin{choice}A text editor.\end{choice} \begin{choice}Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
Now we are engaged in a great civil war, testing whether that nation, or any nation, so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. .\end{choice} \begin{correctchoice}A layout and typesetting program.\end{correctchoice} \begin{choice}A seamless, business rule aware middleware product.\end{choice} \end{choices}
\begin{question}Why is LyX better?\end{question} \begin{choices} \begin{choice}It's a Microsoft program.\end{choice} \begin{correctchoice}It uses LaTeX to create superior layout.\end{correctchoice} \begin{choice}Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.\end{choice} \begin{choice}It's a fixed sequence, rapid authoring environment.\end{choice} \begin{choice}You needn't use styles with LyX.\end{choice} \end{choices}
\begin{question}What is LyX's relationship to LaTeX\end{question} \begin{choices} \begin{correctchoice}LyX is a front end to LaTeX.\end{correctchoice} \begin{choice}LaTeX is a front end to LyX.\end{choice} \begin{choice}Now we are engaged in a great civil war, testing whether that nation, or any nation, so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. \end{choice} \begin{choice}They're dedicated life partners.\end{choice} \begin{choice}LaTeX is a wordprocessor with Visual Basic for Applications, Object Embedding and Linking, and TrueType fonts.\end{choice} \begin{choice}LyX is a corporation.\end{choice} \end{choices}
\end{questions}
\end{document}
|
To the left is the LaTeX producing the preceding output. This LaTeX uses three external packages: geometry to specify margins, setspace to shrink line spacing, and ifthen to facilitate if/then logic in order to turn on or turn off identification of the correct choice.
The flag this file uses to determine whether or not to identify the correct answer (with asterisks, italics and bold) is \showcorrect.
Two counters are used: qcounter for questions, and acounter for answers. The \newcounter statement for acounter relates it to qcounter in such a fashion that when qcounter changes, acounter is reset back to 1 (or its letter equivalent, a).
The \correctmarker
command, which is used as a string, is declared. This will later be
used to put the double asterisk within the correct choice's label.
The questions list environment uses bold labels with arabic representations of counter qcounter. It uses counter qcounter, and within the body portion sets various measurements. At 2em, the \itemsep length is quite long, so as to put plenty of space above a question and make it clear what question owns what choices.
The question environment prints a list item.
The choices list environment lists choices for a question, using a lower case alphabetic representation of the acounter counter. These choices are indented a half inch to the right of their questions (\setlength{\rightmargin}{0.5in}). Also, \topsep is set to -0.3ex to move the choices right up below their question.
The choices list must be vertically compact, so line spacing is shrunk to 80% (\setstretch{0.8}), paragraph spacing is set to 0 (\setlength{parsep}{0ex}) and to replace spacing as paragraph identification, paragraphs are indented (\setlength{\listparindent}{0.5in}). The \itemsep length is set to the tiny value of 1ex, whihc is the height of a lower case s, to reduce spacing between items.
The choice environment sets \correctmarker to four nonbreaking spaces and then prints the item. The correctchoice environment checks the \showcorrect flag and if it's set to true, sets \correctmarker to two asterisks, a space and a nonbreaking space. The finalization part of correctchoice also prints two nonbreaking spaces and two asterisks at the end. If \showcorrect is not true, it prints the item just like the choice environment would.
The actual document nests everything within the questions environment, with a series of question items, each of which is followed by a choice list implemented by the choices environment, which wraps around a bunch of items implemented with choice environment. |