[Tex/LaTex] Slave duplicate counter

counters

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

Best Answer

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.

\newcommand*{\dupcntr}[2]{%
    \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.

Related Question