[Tugindia] help required with numbered lists

E. Krishnan ekmath at asianetindia.com
Sat Jul 2 03:33:16 CEST 2005


On Fri, 1 Jul 2005, Dr. Anoop Sinha wrote:

> I need some help to typeset question papers, especially multiple choice 
> questions.

I've tweaked the shortlst.sty to produce a mctest.sty which may meet yur
requirements, which I'm attaching.  There are two options, "four" or
"five" to control the number of choices and two other options "letters" or
"numbers" to cotrol the labeling of the choices. The sample file attached 
shows the usage. Among the choces, the right answer is marked with the 
"\answer' command and the answer key is printed (in five columns) in a 
separate page with the "\printanswers" command.


-- 
Krishnan
-------------- next part --------------
\RequirePackage{ifthen}
\RequirePackage{multicol}
 

%% This piece is shameleely stolen from "shortlst.sty"

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newlength{\shortitemwidth}

\newenvironment{choice}[1][\hbox to \shortitemwidth{\hfil}]{%
   \ifnum \@enumdepth >\thr@@\@toodeep\let\endsh at rtitem\relax\else
   \ifx\item\sh at rtitem\sh at rtnesterr\let\endsh at rtitem\relax\else
   \advance\@enumdepth\@ne
   \edef\@enumctr{enum\romannumeral\the\@enumdepth}%
   \settowidth\shortitemwidth{#1}%
   \list{}{\addtolength\leftmargin\itemindent
           \addtolength\leftmargin{-\labelwidth}%
           \addtolength\leftmargin{-\labelsep}%
           \setlength\itemindent\z@}%
   \item\relax
   \@rightskip\@flushglue \rightskip\@rightskip
   \let\endsh at rtitem\noindent
   \let\item\sh at rtitem
   \usecounter{\@enumctr}%
   \def\@itemlabel{\csname label\@enumctr \endcsname}%
   \fi\fi\ignorespaces}%
   {\endsh at rtitem\endlist}

 \ifx\TX at ftn\undefined
    \newtoks\TX at ftn
    \long\def\TX at ftntext#1{%
      \edef\@tempa{\the\TX at ftn\noexpand\footnotetext
                        [\the\csname c@\@mpfn\endcsname]}%
      \global\TX at ftn\expandafter{\@tempa{#1}}}%
    \long\def\TX at xftntext[#1]#2{%
      \global\TX at ftn\expandafter{\the\TX at ftn\footnotetext[#1]{#2}}}
 \fi

 \def\sh at rtitem{%
   \endsh at rtitem
   \@inmatherr\item
   \@ifnextchar [\sh at rt@item{\@noitemargtrue \sh at rt@item[\@itemlabel]}}
 \def\sh at rt@item[#1]{%
    \def\endsh at rtitem{\endlrbox\endgroup%
       \setlength\@tempdima{\wd\@tempboxa}%
       \addtolength\@tempdima\labelsep
       \setlength\@tempdimb\shortitemwidth
       \addtolength\@tempdimb{2\labelsep}%
       \addtolength\@tempdimb{\labelwidth}%
       \addtolength\@tempdima{-1sp}% subtract a Very Small Length
       \divide\@tempdima by \@tempdimb%
       \addtolength\@tempdima{1sp}%  add one
       \multiply\@tempdimb by \@tempdima%
       \addtolength\@tempdimb{-\wd\@tempboxa}%
       \usebox\@tempboxa
       \global\TX at ftn\expandafter{\expandafter}\the\TX at ftn
       \hspace\@tempdimb}%
    \if at noitemarg
       \@noitemargfalse
       \if at nmbrlist\refstepcounter{\@listctr}\fi
    \fi
    \settowidth\@tempdima{#1}%
    \ifdim\@tempdima>\labelwidth\PackageWarning{shortlst}%
       {label too wide
        (set \string\labelwidth\space to at least \the\@tempdima)}%
    \fi
    \begingroup\lrbox{\@tempboxa}%
       \let\@footnotetext\TX at ftntext\let\@xfootnotenext\TX at xftntext
       \makebox[\labelwidth][r]{#1}%
       \hspace{\labelsep}\ignorespaces}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setlength{\shortitemwidth}{2pt}

\DeclareOption{five}{%
  \DeclareOption{letters}{%
  \renewcommand{\theenumii}{\Alph{enumii}}
  \newcommand{\choices}[5]{%
    \begin{choice}
     \item #1 \item #2 \item #3 \item #4 \item #5
   \end{choice}}}
  \DeclareOption{numbers}{%
    \renewcommand{\theenumii}{\arabic{enumii}}
    \newcommand{\choices}[5]{%
    \begin{choice}
     \item #1 \item #2 \item #3 \item #4 \item #5
   \end{choice}}}}


\DeclareOption{four}{%
  \DeclareOption{letters}{%
    \renewcommand{\theenumii}{\Alph{enumii}}
    \newcommand{\choices}[4]{%
      \begin{choice}
      \item #1 \item #2 \item #3 \item #4 
      \end{choice}}}
  \DeclareOption{numbers}{%
    \renewcommand{\theenumii}{\arabic{enumii}}
    \newcommand{\choices}[4]{%
    \begin{choice}
     \item #1 \item #2 \item #3 \item #4 
   \end{choice}}}}




\ProcessOptions


\newenvironment{mctest}{\begin{enumerate}}{\end{enumerate}}
\newcommand{\question}{\item}



\newwrite\key

\immediate\openout\key=answers


\def\Answers{\centering{\large\bfseries Answers}}

\immediate\write\key{\string\thispagestyle{empty}}

%\immediate\write\key{\string\Answers\string\par\string\medskip}

\immediate\write\key{\string\begin{multicols}{5}[\string\Answers]}

%\immediate\write\key{\string\begin{flushright}}

%\def\answer{\immediate\write\key{\theenumi.\,\,\theenumii\string\par}}

\def\answer{\immediate\write\key{%
  \string\noindent\theenumi.\,\,(\theenumii)\string\par\string\medskip}} 

% \def\printanswers{\immediate\write\key{\string\end{multicols}}
% \immediate\closeout\key \include{answers}}


 \def\printanswers{%\immediate\write\key{\string\end{flushright}}
     \immediate\write\key{\string\end{multicols}}
 \immediate\closeout\key \include{answers}}


More information about the tugindia mailing list