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:

 % The \egroup closes off any \vbox'es from the previously ignored \item.
 % The conditional \bgroup cancels it out when there aren't any.
 \advance\itemsSoFar by 1 %
 \onlyitemsset{utility/store tag = {}, utility/verdict/.style = {}, select/\the\itemsSoFar, #1, utility/verdict}%
  % 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.


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
  • 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
  • @RyanReich: it made writing multiple resumes/publication list/list of references/list of select publications/list of etc much easier: I have one file of definitions: Resume_data.tex and many files that call up whatever sublist they happen to need. I can dice and slice however I like, but I only need to keep one list of items...it's great! – Yossi Farjoun Nov 14 '11 at 19:27



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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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