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, ...).


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.

  • 2
    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

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.


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.


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


The package assoccnt and its successor xassoccnt provides exactly this feature, "a way of associating counters to an existing driver counter so that incrementing the driver counter will increase its associated counters as well."

Here is a small example:

enter image description here




\thesection\ \themysection

\section{A section} \thesection\ \themysection

  • 1
    (+1) for mentioning xassoccnt, but please don't use assoccnt any longer. It had some issues which are hopefully extinguished in xassoccnt. I will soon declare assoccnt as obsolete – user31729 Jun 5 '16 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.