Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

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}
share|improve this answer
    
thanks, i have no idea how i forgot that. –  grizzilus Jun 13 '12 at 22:16
    
And the two \csdef seem unnecessary. –  egreg Jun 13 '12 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. –  grizzilus Jun 13 '12 at 22:27
add comment

Your Answer

 
discard

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.