[comp.text.tex] Counters in List Environment

woo@WOONEXT.DSRD.ORNL.GOV ("John W. Wooten") (05/03/91)

Gentlemen:
        When trying to implement a distribution list, that is a
method for stating the number of copies to be sent to each recipient,
several problems occurred with the list environment.  While they may
have been pilot error, I still thought it worth sharing.  The
following does work.  It creates a list viz:
 
        1.      G. A. Dailey
        2.      G. S. Danford
        3-5.    M. F. Theofanos
        6.      R. G. Tudor
 
which is what I wanted.  However, in the LaTeX definition of list a
statement occurs such that if a counter is incremented in the
makelabel section shown below, AND the \hbox statements are not set
to make their width greater than the \labelwidth, then the counter is
incremented twice each time the label is used.  I'm not sure why this
is set in this fashion, but it causes problems with incrementing
counters in the makelabel statement.  The relevant section from the
LaTeX macros are:
 
\def\@item[#1]{ .....
...
\everypar{ ...
...
\setbox\@temboxa\hbox{\makelabel{#1}}%
...
        \ifdim \wd\@tempboxa > \labelwidth
                \hbox\@tempboxa
        \else \hbox to \labelwidth {\makelabel{#1}}\fi
        ...
 
this cause the double counting, i.e. the labels become 2 4 6 etc.
 
I fixed it in this case by setting \labelwidth to 40pt and then
putting an hbox to 41 pt so that the condition would be false, BUT
this doesn't seem very elegant!
 
-----Begin distribution list
\newcounter{copynum}
\begin{list}{\label{\stop}}%
        {\usecounter{copynum}\labelwidth 40pt \itemsep 0pt \parsep
0pt%
        \partopsep 0pt \topsep 0pt
        \def\makelabel#1{\stepcounter{copynum}\ifthenelse{\equal{#1}{
1}}%
     {\hbox to 41pt{\thecopynum.\hss}}
         {\hbox to 41pt{\thecopynum--\addtocounter{copynum}{#1}%
         \addtocounter{copynum}{-1}\thecopynum.\hss}}}}
\item[1] G. A. Dailey
\item[1] G. S. Danford
\item[3] M. F. Theofanos
\item[1] R. G. Tudor
\end{list}
-----end distribution list
 
Your suggestions or comments appreciated.
 
Thanks,
Dr. John W. Wooten, Oak Ridge National Laboratory

ASND@TRIUMFRG.BITNET (Donald Arseneau) (05/04/91)

Yes, LaTeX does process the label in a list environment twice, which
can lead to double increments of counters.
 
The relevant definitions are:
 
\def\@item[#1]{ ...
...
\everypar{...
...
\setbox\@tempboxa\hbox{\makelabel{#1}}%
\global\setbox\@labels
 \hbox{\unhbox\@labels \hskip \itemindent
       \hskip -\labelwidth \hskip -\labelsep
       \ifdim \wd\@tempboxa >\labelwidth
                \box\@tempboxa
          \else \hbox to\labelwidth {\makelabel{#1}}\fi
       \hskip \labelsep}\ignorespaces}
 
It is clear that "#1" can be performed twice.
 
There is a safer way to handle the labels, and it is even more efficient!
I am surprised that it isn't what LaTeX does.
 
Replace the second-last line quoted above with:
 
          \else \hbox to\labelwidth {\unhbox\@tempboxa}\fi
 
Note: This is from an old version of LaTeX, so this MIGHT have been fixed!
 
Donald Arseneau
asnd@reg.triumf.ca
asnd@triumfcl