Sign up ×
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 have a counterA and a counterB. I want to define a command \PrintCounter, which gets either A or B as argument, and then prints the value of the corresponding counter.

I wrote the following code:


which results in an error. I need a way to tell LaTeX to evaluate counter#1 before evaluating \the. Unfortunately, I couldn't make it work using \expandafter.

share|improve this question

1 Answer 1

up vote 8 down vote accepted

If \counterA and \counterB are \count registers, i.e. TeX counters, then you can use \csname ..\endcsname together with \expandafter:

    \expandafter\the\csname counter#1\endcsname

If they are however defined using \newcounter, i.e. LaTeX counters, then simply use \arabic{counter#1}.

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.