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

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

for instance:


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

instead of:

    bla bla bla \ref{equ:1} bla bla bla ...
share|improve this question
+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 tex.stackexchange.com/questions/57093/… – Pedro May 23 '12 at 18:32
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 9:11
up vote 6 down vote accepted

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

\let\origlabel\label% Save old definition

Then use:

\ref{\lastlabel} or \ref\lastlabel
share|improve this answer

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.