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.

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

Is it possible to create a counter that is a "slave" to another (master) counter, but also an exact duplicate?

The \@addtoreset{<slave>}{<master>} resets <slave> whenever <master> is incremented (similar functionality is offered by chngcntr), but I don't know about anything incrementing one counter (<slave>) automatically whenever another counter (<master>) is incremented.

The idea is to have a macro (say) \dupcntr{<slave>}{<master>} as an analogue to \@addtoreset. The application for this might be where one is interested in renaming a counter used/provided by a package into something more meaningful for the user (say, <slave>), without having to reference <master>. Or, if the original counter contains @ that needs to be escaped every time it's used, it is sometimes more convenient to have a "more user friendly" counter.

I know one way around is to use a macro that returns the value of <master>, but is it possible to perform the same manipulation with a macro than one could with the counter? Manipulation here refers to the printing of the counter (via \the<slave>) and perhaps it's representation (like \arabic, \alph, ...).

share|improve this question
up vote 8 down vote accepted

If both should have always the same value, why not simply \let the slave to the master? This copies the internal reference to the \count register.

    \expandafter\let\csname c@#1\expandafter\endcsname\csname c@#2\endcsname

This is for LaTeX counters. For TeX count's simply remove the c@ (if given by cs name) or use \let#1#2 if given by control sequence.

share|improve this answer
You have to copy also \themaster into \theslave; of course, redefining \themaster wouldn't redefine \theslave, nor conversely. – egreg Nov 7 '11 at 0:23
@egreg: True. I would say \newcommand\theslave{\themaster} should do it. – Martin Scharrer Nov 7 '11 at 8:04
Thanks Martin, this was a straight-forward solution. – Werner Dec 13 '11 at 17:08

Check out my "amsthm tweaks": posted here. I did just this, because the amsthm package is lazy about making subordinate theorem numbers, and this breaks the fncylab package's way of customizing \ref's output. The code is thus:

  \@xp\xdef\csname c@#1\endcsname{\@xp\@nx\csname c@#2\endcsname}
  \@xp\xdef\csname the#1\endcsname{\@xp\@nx\csname the#2\endcsname}
  % This is for hyperref compatibility
  \@xp\xdef\csname theH#1\endcsname{\@xp\@nx\csname theH#2\endcsname}
  % Don't copy p@#2 or cl@#2!
  \global\@xp\let\csname p@#1\endcsname = \@empty
  \global\@xp\let\csname cl@#1\endcsname = \@empty
  % This is wrong, for some reason.  So it's commented out.

This makes a new counter #1 which, at its birth, is a complete slave to #2: same count register, same manner of printing. It sets up all the internal quantities that LaTeX considers to constitute a "counter", so you can \addtocounter and \refstepcounter and \@addtoreset correctly.

share|improve this answer

Heiko Oberdiek's aliascnt package provides this functionality. It provides \newaliascnt{<slave>}{<master>} and can be used in instances where theorems share base counters:

enter image description here

\usepackage{aliascnt}% http://ctan.org/pkg/aliascnt
\newtheorem{foo}{Foo}% counter "foo"
\newaliascnt{bar}{foo}% alias counter "bar"
\setlength{\parindent}{0pt}% Just for this example
\verb|foo:|\ \thefoo \par
\verb|bar:|\ \thebar

As expected, it integrates well with hyperref.

share|improve this answer

ConTeXt presents a key-value interface to couple two counters. For example:


  [number=first, numberconversion=numbers]



\convertedcounter[first] % Prints "B"
\convertedcounter[second]% Prints "2"


If you want the second counter to inherit all the settings of the first counter, (conversion, color, style, etc), just use

share|improve this answer

The package assoccnt and its successor xassoccnt provides exactly this feature, "a way of as­so­ci­at­ing coun­ters to an ex­ist­ing driver counter so that in­cre­ment­ing the driver counter will in­crease its as­so­ci­ated coun­ters as well."

Here is a small example:

enter image description here




\thesection\ \themysection

\section{A section} \thesection\ \themysection

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.