I am trying to iterate over a list, the delimiter of which is not a comma. The reason for not using commas as delimiters is that they are part of the payload. Is there a way to iterate over a list in which the delimiter is a semicolon (or any other delimiter)?

So far, I have tried


\newcommand{\ls}[1]{\@for\tmp:=#1 \do{\tmp}}




Hence, I'd like to loop over the tuples separated by the semicolon, i.e. (a,b) and (c,d).

Edit: I was also trying to find some documentation on \@for, but I was not able to find any.

  • 1
    See the loop macros in etoolbox – daleif Feb 20 '15 at 13:07
  • 1
    @daleif would you like to turn your comment into a proper answer? I was writing one, when I saw your comment, so I decided to ask first :) – Gonzalo Medina Feb 20 '15 at 13:15
  • \@for is part of the latex format so texdoc source2e If you want to use \@for and a comma you can hide inner commas in {} so \ls{{a,b},{c,d}} would iterate over the two pairs – David Carlisle Feb 20 '15 at 13:35

The etoolbox has many interesting features, including making list parsers. See also the unstarred version.

\newcommand\handler[1]{item: #1\par}

For example, you can use this code:

\def\lsA#1;{\ifx;#1;\else \dosomething{#1}\expandafter\lsA\fi}
\def\dosomething#1{\message{I am doing something with #1}}


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.