TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

I need to store a csv list for later use in the end code part of an environment. Can somebody explain me what's going wrong in the following example?

  \ifthenelse{\equal{#1}{1}}{one, }{}
  \ifthenelse{\equal{#1}{2}}{two, }{}
  \ifthenelse{\equal{#1}{3}}{three, }{}
\doprint{1,2,3} % does work

\doprint{\mycsv} % does not work

If the list is stored in the macro, it seems to be no longer a list for \forcsvlist but a single token. Any other solution which solves my problem?

share|improve this question
Related/duplicate tex.stackexchange.com/questions/22393/forcsvlist-and-expansion – egreg Feb 5 '13 at 14:59
@egreg Yep '\newcommand*\doprint[1]{\expandafter\forcsvlist\expandafter\printnumbers\expand‌​after{#1}}' does the trick. Thank you! Oh, i hate TeX ;-) – Josef Feb 5 '13 at 15:11
You can hide that in a \xforcsvlist macro: \newcommand{\xforcsvlist}[2]{\expandafter\forcsvlist\expandafter#1\expandafter{‌​#2}} and then \newcommand{\doprint}[1]{\xforcsvlist\printnumbers{#1}} – egreg Feb 5 '13 at 15:26
up vote 2 down vote accepted

Since #1 can't be all of 1, 2, 3 at the same time, there is an inefficiency in OP's \printnumbers. Here is an alternative solution.

\newcommand*\comma{\ifforeachlastitem.\else, \fi}
  \newforeach [expand list once] \x in {#1} {%
      \@latex@error{\string\doprint: no match}\@ehd
\doprint{} % empty list

This solution can be generalized to other list types beyond {1,2,3}.

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.