[Tex/LaTex] the best way to scan over a list of somethings

comma-separated listmacrosprogramming

It seems that a common operation needed when defining new commands is to scan over a list of arguments (separated e.g. by a comma, but maybe by something else) and do something with each argument in the list, find the last one, or whatever.

For example to write commands that look like \Command{a,b,c} or \Command{c.d.e} and
do something with each a, b, and c. See e.g. questions on defining a list of operators and ignoring even numbered inputs.

Some solutions have been posted there, but what would be the best idiom to perform such kind of operations? LaTeX's \@for looks very nice, but is it possible to use it to scan anything other than comma-separated lists?

Best Answer

I have not progressed to the level of processing a list myself but I have been using etoolbox by Philipp Lehman for some other TeX programming tasks I am doing. I believe 3.7 List processing should give you a good solution.

For example (on a recent version of etoolbox) you can write:

\DeclareListParser*{\myfor}{;}
\myfor{\fbox}{item1; item2; item3}
Related Question