# How to skip an \item entirely, with no side-effects?

In Ryan Reich's great answer to my question on onlyitems, he had LaTeX ignore an \item by setting it into a box and then not using the box, effectively discarding it:

...SNIP...
\renewcommand\item[1][]{%
% The \egroup closes off any \vbox'es from the previously ignored \item.
% The conditional \bgroup cancels it out when there aren't any.
\itemIf\bgroup\fi\egroup
\let\itemIf=\iffalse%\fi
\onlyitemsset{utility/store tag = {}, utility/verdict/.style = {}, select/\the\itemsSoFar, #1, utility/verdict}%
\itemIf
\def\next{\expandafter\itemLaTeX\itemOptions}%
\else
% The vbox is set and then discarded, effectively ignoring an entire \item.
% This inner \itemLaTeX is necessary to avoid a glitch when we ignore the first \item of an itemize that itself contains a nested \itemize.  Don't ask, I don't know.
\def\next{\setbox0=\vbox\bgroup\itemLaTeX}%
\fi
\next
}

...SNIP...


This works, but has the unfortunate side-effect of advancing the appropriate LaTeX counter, which is either good or bad, depending on how one wants to use onlyitems.

In my case, I want onlyitems to literally behave as if only the included \items are there, so that means that the counters must not be advanced. Since the implementation is list-agnostic (it should work for enumerate, revnum or any other list of \items you like to define), I cannot manually set back counters (I cannot know which are the important ones), rather I need to skip the \item entirely, without side-effects.

Thus, to repeat the title, the question is:

How can I skip an \item without any side-effect?

-
With sufficient industry I'll bet a form of verbatim (well, ignored) parsing would work. Two things are necessary: first, make \item the termination string, and second, count \begin...\end pairs so that you don't comment out half of a nested itemize. I am not feeling up to it now, though. – Ryan Reich Nov 14 '11 at 17:03
@RyanReich: you did a lot already! thanks! – Yossi Farjoun Nov 14 '11 at 17:11
You're welcome, but I have always wanted to see if that would work. – Ryan Reich Nov 14 '11 at 17:45
@RyanReich: if by "it" you mean \onlyitems, the answer is yes. I would publish it if I thought that others might be interested. maybe I'll just keep the current version of it on that question's page.... – Yossi Farjoun Nov 14 '11 at 17:55
I actually meant the "ignore \items by verbatim methods", but until I answered your question, I had also always wanted to get the onlyitems thing to work in general. If you think it's good, I'll put together a package (perhaps in December). – Ryan Reich Nov 14 '11 at 18:02

\let\stepcounter\@gobble


just between \setbox0=\vbox\bgroup and \itemLaTeX. This will avoid that the counter is stepped when the item is ignored (\item uses \refstepcounter internally, which in turn does \stepcounter).

You'll have to enclose the \renewcommand\item[1][]{...} between \makeatletter and \makeatother.

-
what if someone implements a different sort of list in which internally they use \addtocounter? – Yossi Farjoun Nov 14 '11 at 17:13
revnumerate.sty uses both \stepcounter and \addtocounter inorder to both count how many items there are and to count-down from that number (saved in aux) to 1. your solution seems to stop the count of total items, while the count of current item continues unscathed...resulting in a correct starting number, but a jump, and then negative item numbers... – Yossi Farjoun Nov 14 '11 at 17:21
@YossiFarjoun Do also \let\addtocounter\@gobbletwo. – egreg Nov 14 '11 at 17:28
did you read the relevant part in revnum? there's a whole section, with if's setcounters etc. won't the behavior of this part will be quite unpredictable if I simply gobble these commands? – Yossi Farjoun Nov 14 '11 at 17:35
BTW: It does work...:-) – Yossi Farjoun Nov 14 '11 at 17:37