%%% ====================================================================
%%%  @LaTeX-style-file{
%%%     filename        = "enumerate.sty",
%%%     version         = "2.01",
%%%     date            = "26 June 1992",
%%%     time            = "17:08:06 BST",
%%%     author          = "David Carlisle",
%%%     address         = "Computer Science Department
%%%                        Manchester University
%%%                        Oxford Road
%%%                        Manchester
%%%                        England
%%%                        M13 9PL",
%%%     telephone       = "+44 61 275 6139",
%%%     FAX             = "+44 61 275 6236",
%%%     checksum        = "44426 311 1335 10647",
%%%     email           = "carlisle@cs.man.ac.uk (Internet)",
%%%     codetable       = "ISO/ASCII",
%%%     keywords        = "LaTeX, enumerate",
%%%     supported       = "yes",
%%%     docstring       = "
%%%
%%%     enumerate.sty
%%%
%%%     A LaTeX style option giving the enumerate environment an
%%%     optional argument controlling the printing of the counter.
%%%
%%%     The checksum field above was produced by
%%%     Robert Solovay's checksum utility.",
%%%  }
%%% ====================================================================
%
% Version 1.00 1990 ?
% Version 2.00 25 July 1991
% Version 2.01 26 June 1992 Re-issue for the new doc and docstrip.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%<*x>
% This file may be used without modification as a style (.sty) file.
%
% If you have Mittelbach's doc.sty, this file may be formatted with a
% command like:
%                latex enumerate.sty
%
% If you have the Mittelbach/Duchier/Braams docstrip utility, you may
% produce a faster loading .sty file. Rename this file to: enumerate.doc
% Then run this file through *plain* TeX:
%                tex enumerate.doc
% This should produce the file enumerate.sty.
% If you do not have plain TeX on your system, you can trick LaTeX into
% doing the work as follows:
%                latex \def\fmtname{plain} \input enumerate.doc
% Note that you may need to quote the arguments here to stop your
% operating system treating the \ characters incorrectly.
%
%                latex enumerate.doc
% Will produce a typeset version of the documentation, as above.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\plain{plain}\ifx\fmtname\plain\csname fi\endcsname
     \def\batchfile{enumerate.doc}
     \input docstrip
     \preamble

     Do not distribute the stripped version of this file.
     The checksum in the header refers to the documented version.

     \endpreamble
     \generateFile{enumerate.sty}{t}{\from{enumerate.doc}{}}
     \endinput
\fi
%
\ifcat a\noexpand @\let\next\relax\else\def\next{%
    \documentstyle[enumerate,doc]{article}\MakePercentIgnore}\fi\next
%
%\def\eatmodule<#1>{}\eatmodule
%</x>
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \textwidth=355pt   ^^A Allow macrocode text with 72 columns.
% \CodelineIndex     ^^A Code lines numbered.
% \DisableCrossrefs  ^^A No Cross references.
% \MakeShortVerb{\|} ^^A |\foo| works like \verb+\foo+
%
% \title{enumerate.sty}
% \author{D. P. Carlisle}
% \date{26 June 1992}
% \begin{document}
% \maketitle
% \begin{abstract}
% This style option gives the enumerate environment an optional argument
% which determines the style in which the counter is printed.

% An occurence of one of the tokens |A a I i| or |1| produces the value
% of the counter printed with (respectively) |\Alph \alph \Roman \roman|
% or |\arabic|.

% These letters may be surrounded by any strings involving any other
% \TeX\ expressions, however the tokens |A a I i 1| must be inside a
% |{ }| group if they are not to be taken as special.
% \end{abstract}
%
% \section{Examples}
%\showboxdepth=10
% \showboxbreadth=10
% \[
% \parbox{2.2in}{\hbadness2000
% \begin{enumerate}[EX i.]
% \item one one one one one one one
%        one one one one one\label{LA}
% \item two
%     \begin{enumerate}[{example} a)]
%     \item one of two  one of two  one of two\label{LB}
%     \item two of two
%     \end{enumerate}
% \end{enumerate}
% \begin{enumerate}[{A}-1]
% \item one\label{LC}
% \item two
% \end{enumerate}}
% \hspace{20pt}
% \vcenter{\hsize=2.4in
% \begin{verbatim}
% \begin{enumerate}[EX i.]
% \item one one one one one one one
%        one one one one\label{LA}
% \item two
%     \begin{enumerate}[{example} a)]
%     \item one of two  one of two
%           one of two\label{LB}
%     \item two of two
%     \end{enumerate}
%     \item two of two
%     \end{enumerate}
% \end{enumerate}
%
% \begin{enumerate}[{A}-1]
% \item one\label{LC}
% \item two
% \end{enumerate}
% \end{verbatim}
% }\]
%
% |\label| and |\ref| may be used as with the standard {\tt
% enumerate} environment. |\ref| only produces the counter value,
% not the whole label. |\ref| prints the value in the same style
% as |\item|, as determined by the presence of one of the tokens
% |A a I i 1| in the optional argument. In the above example
% |\ref{LA}|, |\ref{LB}| and |\ref{LC}| produce
% `\ref{LA}',  `\ref{LB}' and `\ref{LC}' respectively.
%
% \typeout{End of the Introduction and Examples.}
% \typein[\answer]%
%   {Do you want an annotated listing of the macro definitions (y/n) ?}
% \def\next{y}\ifx\answer\next\else\expandafter\stop\fi
%
%\section{Macros}
%
% \begin{macro}{\@enlab}
% Internal token register used to build up the label command from the
% optional argument.
%    \begin{macrocode}
\newtoks\@enLab
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@enQmark}
% This just expands to a `?'. |\ref| will produce this, if no counter
% is printed.
%    \begin{macrocode}
\def\@enQmark{?}
%    \end{macrocode}
% \end{macro}
%
% The next four macros build up the command that will print the item
% label. They each gobble one token or group from the optional argument,
% and add corresponding tokens to the register |\@enLab|. They each end
% with a call to |\@enloop|, which starts the processing of the next
% token.
% \begin{macro}{\@enLabel}
% Add the counter to the label. |#2| will be one of the `special'
% tokens |A a I i 1|, and is thrown away. |#1| will be a command
% like |\Roman|.
%    \begin{macrocode}
\def\@enLabel#1#2{%
  \edef\@enThe{\noexpand#1{\@enumctr}}%
  \@enLab\expandafter{\the\@enLab\csname the\@enumctr\endcsname}%
  \@enloop}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@enSpace}
% \begin{macro}{\@enSp@ce}
% Add a space to the label. The tricky bit is to gobble the space token,
% as you can not do this with a macro argument.
%    \begin{macrocode}
\def\@enSpace{\afterassignment\@enSp@ce\let\@tempa= }
\def\@enSp@ce{\@enLab\expandafter{\the\@enLab\space}\@enloop}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@enGroup}
% Add a |{ }| group to the label.
%    \begin{macrocode}
\def\@enGroup#1{\@enLab\expandafter{\the\@enLab{#1}}\@enloop}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@enOther}
% Add anything else to the label
%    \begin{macrocode}
\def\@enOther#1{\@enLab\expandafter{\the\@enLab#1}\@enloop}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@enloop}
% \begin{macro}{\@enloop@}
% The body of the main loop.
% Eating tokens this way instead of using |\@tfor| lets you see
% spaces and {\bf all} braces. |\@tfor| would treat {\tt a} and
% |{a}| as  special, but not |{{a}}|.
%    \begin{macrocode}
\def\@enloop{\futurelet\@entemp\@enloop@}
%    \end{macrocode}
%    \begin{macrocode}
\def\@enloop@{%
  \ifx A\@entemp         \def\next{\@enLabel\Alph  }\else
  \ifx a\@entemp         \def\next{\@enLabel\alph  }\else
  \ifx i\@entemp         \def\next{\@enLabel\roman }\else
  \ifx I\@entemp         \def\next{\@enLabel\Roman }\else
  \ifx 1\@entemp         \def\next{\@enLabel\arabic}\else
  \ifx \@sptoken\@entemp \let\next\@enSpace         \else
  \ifx \bgroup\@entemp   \let\next\@enGroup         \else
  \ifx \@enum@\@entemp   \let\next\@gobble          \else
                         \let\next\@enOther
             \fi\fi\fi\fi\fi\fi\fi\fi
%    \end{macrocode}
% \end{macro}
% Process the current token, then look at the next.
%    \begin{macrocode}
  \next}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\enumerate}
% The new {\tt enumerate} environment. This is the first half of the
% original enumerate environment. If there is an optional argument, call
% |\@@enum@| to define the label commands, otherwise call
% |\@enum@| which is the second half of the original definition.
%    \begin{macrocode}
\def\enumerate{%
  \ifnum \@enumdepth >3 \@toodeep\else
      \advance\@enumdepth \@ne
      \edef\@enumctr{enum\romannumeral\the\@enumdepth}\fi
  \@ifnextchar[{\@@enum@}{\@enum@}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@enum@}
% Handle the optional argument..
%    \begin{macrocode}
\def\@@enum@[#1]{%
%    \end{macrocode}
% Initialise the loop which will break apart the optional argument.
% The command to print the label is built up in |\@enlab|.
% |\@enThe| will be used to define |\theenum|\,$n$.
%    \begin{macrocode}
  \@enLab{}\let\@enThe\@enQmark
%    \end{macrocode}
% The |\@enum@| below is never expanded, it is used to detect the end
% of the token list.
%    \begin{macrocode}
  \@enloop#1\@enum@
%    \end{macrocode}
% Issue a warning if we did not find one of the `special' tokens.
%    \begin{macrocode}
  \ifx\@enThe\@enQmark\@warning{The counter will not be printed.%
   ^^J\space\@spaces\@spaces\@spaces The label is: \the\@enLab}\fi
%    \end{macrocode}
% Define |\labelenum|$\,n$ and |\theenum|$\,n$.
%    \begin{macrocode}
  \expandafter\edef\csname label\@enumctr\endcsname{\the\@enLab}%
  \expandafter\let\csname the\@enumctr\endcsname\@enThe
%    \end{macrocode}
% Set the counter to 7 so that we get the width of `vii' if roman
% numbering is in force then set |\leftmargin|$\,n$. to the width of the
% label plus |\labelsep|.
%    \begin{macrocode}
  \csname c@\@enumctr\endcsname7
  \expandafter\settowidth
            \csname leftmargin\romannumeral\@enumdepth\endcsname
            {\the\@enLab\hspace{\labelsep}}%
%    \end{macrocode}
% Finally call |\@enum@| which is the second half of the original
% definition.
%    \begin{macrocode}
  \@enum@}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@enum@}
% All the list parameters have now been defined, so call |\list|. This
% is taken straight from the original definition of |\enumerate|.
%    \begin{macrocode}
\def\@enum@{\list{\csname label\@enumctr\endcsname}%
           {\usecounter{\@enumctr}\def\makelabel##1{\hss\llap{##1}}}}
%    \end{macrocode}
% \end{macro}
%
% \end{document}
