Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How to define an enumerate environment in which the label is omitted when item number is just one and displayed as usual when item number is more than one?

share|improve this question
1  
You must write the contents in a file (or a macro), and then test the number, and then typeset it. –  Leo Liu Nov 28 '11 at 14:42
    
@Leo Thanks. I have seen the manual of thmtools in which (page 3) a package unique is mentioned. But I cannot find it in CTAN. The package might give any help? –  Tau spit Nov 28 '11 at 15:02
    
Instead of "item number" did you mean "the number of items", as it has a different meaning. The solution by @egreg below solves the problem with this rephrasing, not your original wording. –  Peter Grill Nov 28 '11 at 16:57
add comment

1 Answer 1

up vote 8 down vote accepted

You can typeset the environment inside a box just to get the number of items and then retypeset it:

\usepackage{environ}
\makeatletter
\NewEnviron{fenumerate}
  {\setbox0=\vbox{\enumerate\BODY\endenumerate\expandafter}%
   \expandafter\def\expandafter\@tempfenum\expandafter{\the\value{\@enumctr}}%
   \begin{enumerate}
     \ifnum\@tempfenum=\@ne\expandafter\def\csname label\@enumctr\endcsname{}\fi
     \BODY
   \end{enumerate}}
\makeatother

First of all, the infrastructure set up by environ gathers the environment's text; then it typesets it in a temporary box and at the end the value of the relevant counter (enumi, enumii, enumiii or enumiv) is stored in \@tempfenum, which is used for the "real" typesetting.

Usage:

\begin{fenumerate}
\item this won't get a number
\end{fenumerate}

\begin{fenumerate}
\item this will have a number
\item since it's followed by another item
\end{fenumerate}
share|improve this answer
    
@GonzaloMedina Yes, of course! –  egreg Nov 28 '11 at 17:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.