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've been trying to change the numbering behavior of subsection to use a global counter. I first did:


and got:

! Missing \endcsname inserted.
<to be read again> 
l.64 \subsection{Orientation}

I then did it by defining \mysubsection:


And that works fine but requires me to change every instance of \subsection with \mysubsection in the document. Is there any way to decorate a LaTeX command? As in redefining \subsection in a way that is able to call the previous implementation of it. This generates an infinite loop:

share|improve this question
What do you mean with "to decorate a LaTeX command"? It doesn't make much sense to me. – Martin Scharrer May 27 '11 at 21:00
I meant in in the sense of the OO pattern: en.wikipedia.org/wiki/Decorator_pattern – Pedro Côrte-Real Jan 1 '14 at 3:41
up vote 3 down vote accepted

You can copy the meaning of a macro (aka command sequence) to another using \let\newmacro=\oldmacro (the = is optional):


You shoudln't put \stepcounter into a \the... macro. This makes it fragile and will might break certain \label or similar code.

share|improve this answer
My answer shows the general way to redefine a macro which uses its old definition. If you only want to make the subsection counter independent of the section counter then @locksteps answer is the way to go. I think I misunderstood the question because I thought maincount is also used and incremented elsewhere. The main part makes it look like it. – Martin Scharrer May 27 '11 at 21:09
@Martin: Wouldn’t it be better to use \refstepcounter to make the count work with \label-\ref-combinations? – Tobi May 27 '11 at 21:36
@Tobi: That's correct, however the \refstepcounter{subsection} will overwrite the label again. I didn't changed the OP original code in this point but merely wanted to show the redefinition technique. He doesn't state what exactly he is doing with it, so I kept it general – Martin Scharrer May 27 '11 at 21:42
This works perfectly. As others have mentioned the way I went about this is probably not the best way to "change the count for subsections" but your solution is the correct one for "how to decorate a tex macro". Thanks – Pedro Côrte-Real May 28 '11 at 0:31
And maincount is indeed incremented elsewhere but I just incremented subsection instead and that works. – Pedro Côrte-Real May 28 '11 at 0:42

I suggest to simply use the chngcntr package.








share|improve this answer
This is a much better solution for the numbering problem than the hack I was going for. Thanks. – Pedro Côrte-Real May 28 '11 at 0:40

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.