I wonder whether I can change displayed text in \ref globally for a \label referencing a numbered environment. Concretely:

Let's suppose I have a theorem called "Important Proof".

\begin{theorem}[Important Proof]\label{IP}

Then \ref{IP} would display something like 1.1.1. I however want to change that text only sporadically, so that this specific proof gets displayed e.g. with Important Proof, but all other proofs stay unaffected.

What did I mean with globally? I saw some workarounds using \hyperref every single time, but this does not seem really convincing; I would like to have some kind of redefinition, so that I can just use something like \ref s.t. I don't have to insert the text every single time manually.

  • 1
    The nameref package provides \nameref that works like that. Redefining \ref globally to be \nameref won't be a good idea though.
    – Werner
    Dec 24, 2019 at 16:30

2 Answers 2

\begin{theorem}[Important Proof]%
\makeatletter\def\@currentlabel{Important Proof}\makeatother


enter image description here

  • Great, thanks! How did you infer that one must redefine \@currentlabel? Just by reading the hyperref documentation?
    – J.N.
    Dec 26, 2019 at 16:18
  • I know a bit about the LaTeX and hyperref code. Dec 26, 2019 at 16:48
  • Sure, I just wonder how to get to the solution as a mere mortal :D
    – J.N.
    Dec 26, 2019 at 17:47
  • I'm a mere mortal and I learned it because it is not a secret. You can find over 600 hits with \@currentlabel and more if you google. At some time in the past I probably read one answer about it. Dec 26, 2019 at 20:20

I don't think this would be possible simply without redefining \ref, which is probably considerably more work than you're interested in (or than the problem is really worth). However, you could define a wrapper macro that would take care of what you want. Make sure you use \usepackage{ifthen} (this is a standard LaTeX package), and define a macro \nref like so:

        ``Important Proof''%

Then, anytime you'd use \ref, use \nref instead. This resulted in the following references, when I defined two figures:


I hope that answers your difficulty.

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.