\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
\begingroup
\catcode`\,=13
\gdef\x{ {a} , \if , {b} , \fi }
\endgroup
\ForEachX{,}{\typeout{X\unexpanded\expandafter{\thislevelitem}X}}\x
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
\begin{enumerate}
\ForEach{;}{
\item This is item No.\ \the\thislevelcount.
\begin{enumerate}
\ForEachSublevel{,}{\item \thislevelitem.}
\end{enumerate}
}{%
This is a nested item, Another nested item ;
{This item is, well, nested}, A final item
}
\end{enumerate}
is made like this
\begin{enumerate}
\ForEach{;}{
\item This is item No.\ \the\thislevelcount.
\begin{enumerate}
\ForEach{,}{\item \thislevelitem.}{<level 2 list>}
\end{enumerate}
}
{<level 1 list>}
\end{enumerate}
\ForEachXasks 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