3

I'm trying to have a number of lists using etoolbox that I process near the end of a document. There may be a large number of these lists, and I do not know how many I will have beforehand, so I have been trying to use a number in the list name to keep track of everything.

With the code below, I am probably doing something horribly wrong, it is just not obvious to me what that is.

\documentclass{article}
\usepackage{etoolbox}

\begin{document}
\csdef{foo1}{}
\csdef{foo2}{}

\listcsadd{\csname foo1\endcsname}{first}
\listcsadd{\csname foo2\endcsname}{second}

\dolistcsloop{\csname foo1\endcsname}

\end{document}

This print "firstsecond", but I only expected it to print "first". The same thing happens if I only try to print the second list. What do I need to change to make it behave as I would expect?

1 Answer 1

6

the ...cs... variants of the commands take the name of a macro not the macro itself, so you don't want those \csname (they are added internally)

\documentclass{article}
\usepackage{etoolbox}

\begin{document}
\csdef{foo1}{}
\csdef{foo2}{}

\listcsadd{foo1}{first}
\listcsadd{foo2}{second}

\dolistcsloop{foo1}

\end{document}
2
  • And the two \csdef seem unnecessary.
    – egreg
    Jun 13, 2012 at 22:21
  • yeah they are, they were left over from when i was making a MWE. thanks for pointing it out though, they are gone now. Jun 13, 2012 at 22:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .