9

Is there a way to access the key of the most-recently-declared label?

for instance:

    \begin{equation}\label{equ:1}
    ...
    \end{equation}

    bla bla bla \ref{\getlastlabelkey} bla bla bla ...

instead of:

    bla bla bla \ref{equ:1} bla bla bla ...
Mico
  • 506,678
Pedro
  • 267
  • 2
    +1 for an interesting question- however it does sound an incredibly dangerous thing to use. What happens if you insert a labelled equation in between what is now your equ:1 and the reference? – cmhughes May 23 '12 at 16:57
  • In that case that would obviously be a problem :)! However this was just a simple question to try and achieve a solution to this problem http://tex.stackexchange.com/questions/57093/automatically-position-detailed-information-about-an-equation-into-appendix – Pedro May 23 '12 at 18:32
  • 1
    Note that the current potential label is located in \@currentlabel. This macro is set by all labelable macros like \section, \caption, equation etc. and written by \label under the given label name in the .aux file. If you need to do some internal stuff using \@currentlabel directly might be easier because it doesn't need an explicit \label added by the user. – Martin Scharrer May 24 '12 at 09:11

1 Answers1

6

A simple solution would be to redefine \label to save its argument in a global macro:

\let\origlabel\label% Save old definition
\def\label#1{\origlabel{#1}\gdef\lastlabel{#1}}

Then use:

\ref{\lastlabel} or \ref\lastlabel
Martin Scharrer
  • 262,582