When I'm writing a paper and want to refer to a section, figure or equation in a different part of the document, I end up spending a lot of time scrolling through my source code so that I can see what label I gave it.
Since it's easier to scan through my pdf output than the text source, I had the idea to make this task a lot easier by temporarily overriding the \label
command to display the label in the margin. This would save me a lot of cognitive load when working on the draft, and I could change it back once it's time to submit the final version.
The marginnote
package can put notes in the margin even within math mode, so I tried this:
\usepackage{marginnote}
\let\oldlabel\label
\renewcommand{\label}[1]{\marginnote{\scriptsize #1}\oldlabel{#1}}
This works great for section titles and figures, but for equations I don't see any note in the margin. Moreover, if I do
\renewcommand{\label}[1]{HELLO}
cross-references to equations are still correctly generated, and the "HELLO" doesn't appear in the equation. I tried putting this \renewcommand
after the \begin{document}
, but this doesn't make any difference.
So what's going on here? Why can't I redefine \label
in math mode, and is there a way to get around it?
Addendum
As @Werner points out in a comment, there are packages showkeys
and showlabels
that do what I was trying to do here. However, neither package offers the control over the labels' appearance that I would like, so I'm still interested in a way to roll my own version.
amsmath
redefines\label
inside the equation environment. Have you consideredshowkeys
(see Printing labels along with equation numbers)?\label
doesn't override, I understood @Werner to be saying thatamsmath
redefined the command for the equation environment. So when you write\begin{equation}
or whatever, that triggers the temporary redefinition of\label
. So the only way to override it would be to overrideamsmath
's configuration of that environment or to redefine\label
every time you need to use it in such an environment. That is, the redefining byamsmath
isn't all at once. It is setup to be triggered on use of that environment. [But I've not checked the code.]