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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

\ForEach and related commands of forarray package aren't robust. They can't deal with lists whose separators are active (e.g., active comma). Also any trailing space after the list item is retained throughout processing. For example, with

\gdef\x{ {a} , \if , {b} , \fi }

I get

\fe@item@check@next ->\fe@getitem@i {a}
\fe@getitem@i #1,->\fe@setitem@i {#1}
#1<-{a} , \if , {b} , \fi
{changing \thislevelitem=\relax}
{into \thislevelitem=\long macro:->{a} , \if , {b} , \fi }

This means that on first grabbing of list item, \thislevelitem is the entire list: ->{a} , \if , {b} , \fi.

Please how do I solve these problems?

Also, it will be less confusing if the following forarray syntax

  \item This is item No.\ \the\thislevelcount.
  \ForEachSublevel{,}{\item \thislevelitem.}
  This is a nested item, Another nested item ;
  {This item is, well, nested}, A final item

is made like this

  \item This is item No.\ \the\thislevelcount.
  \ForEach{,}{\item \thislevelitem.}{<level 2 list>}
{<level 1 list>}
share|improve this question
This seems more a feature request than a real question. \ForEachX asks for the delimiter and doesn't do any sanitization: it's a simple package that does simple loops. – egreg Jun 22 '12 at 23:15
This may qualify as an answer. – Ahmed Musa Jun 24 '12 at 5:01
up vote 4 down vote accepted

\ForEach doesn't perform any sanitization of its input, which makes it unsuitable for usage in a generic package that may be employed in situations where the delimiter has a different category code (this is a common problem for packages dealing with option lists, as you know well).

The \ForEachX version does a one level expansion of its third argument. There are more robust ways to process lists with arbitrary delimiters.

share|improve this answer

Your Answer


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.