Suppose in my document in section 1 I have a labeled equation, say \label{eq1}
. Then much later, say in section 8, I want to reference this equation and the section it is in. I know \ref{eq1}
will give me the equation number. But is there a command (or a way to write a command) that would let me say something like \refsec{eq1}
and have it return the section number that the equation is in?
I'm trying to avoid having to always look up the section labels. It would be great if this worked across chapters as well.
Best Answer
This following approach based on the idea of
label
defined by the LaTeX-Kernel. First you have to define a new kind of label which write the needed information to theaux
file. Normally the command\label
writes the following in the aux filewhere
\@currentlabel
is the current number (in your case the equation number).Now you need a the current section number instead of the equation number so the information in the
aux
file should be:The prefix
sec@
is used to avoid multiple labels.amsmath
uses his own definition of\label
named\label@in@display
. To make sure that you don't have to type two different labels the definition will expand by the new label command.Now I have to define a new reference command which is able to handle the new label. The idea based on the definition of
\ref
(see latex.ltx).The explanation of the commands
\@bsphack
a.s.o. can be found in the document macros2e.The same with
hyperref