4

We have the \stepcounter command in LaTeX where \stepcounter{counter} adds one to the counter and resets all subsidiary counters.

We also have the \refstepcounter command where \refstepcounter{counter} works like \stepcounter, except it also defines the current \ref value to be the result of \thecounter.

Now, sometimes, specially when building some home grown macro, we face a situation (believe me, I have been in that situation more than once in my life) where we need to \ref to a custom counter without actually incrementing the value.

If we check the definition of \refstepcounter, we see something like this:

\stepcounter {#1}\protected@edef \@currentlabel {\csname p@#1\endcsname \cs
name the#1\endcsname}

So, defining the command \refcounter would mean a simple deletion of the first incrementing part, namely, removing \stepcounter {#1}.

Why is not the \refcounter command part of base LaTeX?

Is the reason a plain and simple omission or there is a specific reason behind this?

  • 3
    If hyperref is loaded the definition is different. – Ulrike Fischer Aug 30 '17 at 16:40
  • 4
    it is so rarely needed, and you can always do \addtocounter{foo}{-1}\refstepcounter{foo} if you need it and don't want to look at the internals. – David Carlisle Aug 30 '17 at 16:46
  • 5
    @DavidCarlisle but not together with hyperref, you would get a " destination with the same identifier (name{section.1})" warning. – Ulrike Fischer Aug 30 '17 at 16:51
  • 1
    @DavidCarlisle not "probably", I tried ;-) – Ulrike Fischer Aug 30 '17 at 16:52
  • 1
    @DavidCarlisle Yes, the problem are two \refstepcounters to the same value. – Ulrike Fischer Aug 30 '17 at 17:01

Your Answer

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

Browse other questions tagged or ask your own question.