Suppose I want to have an enumerate environment, in which I don't want to typeset certain items. I can obtain this in LateX using (let's ignore the problem that the numbers are wrong, this is easy to fix)
\documentclass{article}
\newcounter{excluded}
\newcommand{\exclude}[1]{\setcounter{excluded}{#1}}
\let\Item\item
\renewcommand{\item}[1]{\ifnum\value{enumi}=\value{excluded}%
\stepcounter{enumi}\else\Item #1\fi}
\begin{document}
\begin{enumerate}
\exclude{2}
\item{This is the first item}
\item{This should not be shown}
\item{This should be shown}
% I would like to be able to use
%\item This is an item without \{ and \}. Would make the course look nicer.
\end{enumerate}
\end{document}
The problem with this setup is that the item text now needs to be an argument to \item
, i.e. I need curly brackets around the text. It would be good if I could still use
\item This is the first item
but I can't get it to work.
Any elegant way around this?
Best Answer
Using some ideas from Order items in
enumerate
environment automatically, the following MWE provides amyenumerate
environment where you pass an optional argument as a number, which then excludes that specific item from the list.It could be generalized to process a list of items to be discarded. With a slight modification and the introduction of
etoolbox
's list processing, the following processes a sequence of numbers at every\item
and either sets the item or not.