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 create counters with names like mycounter1, mycounter2,... Basically this should be a counter-valued data array. The code like

\newcounter{\csname mycounter\the\value{index}\endcsname}

does not work. It seems that it is impossible to use \csname...\endcsname for counter names. Using \expandafter with different variants also does not help. Is there a way to resolve this problem?

share|improve this question
Could you give an example application? Perhaps there are more efficient ways to cope with the problem. – egreg Sep 24 '12 at 17:15
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). – Martin Schröder Oct 5 '12 at 16:32
up vote 7 down vote accepted

Counters do not have a leading backslash which is what the \csname would put in it. So


does the job. With counters it appears that numbers also work:


The MWE below yields:

enter image description here






Counter\arabic{index} = \arabic{mycounter\arabic{index}}

Counter\Alph{index} = \arabic{mycounter\arabic{index}}
share|improve this answer
Thank you very much. It is easy and elegant! – Andrew Sep 24 '12 at 16:44
Yes, also numbers work, because \newcounter{<string>} does \expandafter\newcount\csname c@<string>\endcsname. So even \newcounter{@#^&*({})} would work. :-) For renewing the \the... command associated to it, do \expandafter\renewcommand\csname @#^&*({})\endcsname{\alph{@#^&*({})}}. ;-) – egreg Sep 24 '12 at 17:19
@egreg those are the names that LaTeX counters should have; I don't know why Lamport et al. chose such exotic names like page or chapter for counters ;-) – Gonzalo Medina Sep 24 '12 at 20:10

There are the forarray and the arrayjobx packages for handling arrays with LaTeX.

And of course LuaLaTeX offers arrays natively in Lua.

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.