I use the cleveref package, which allows annotating \label
commands with
an optional argument. Unfortunately, this prevents the various functions in
latex.el
from detecting those labels. My guess is that it is because they do not match the built-in regexp for labels.
Some example LaTeX code to illustrate the situation:
\usepackage{cleveref}
\crefname{diagram}{diagram}{diagrams}
% ...
\begin{equation}
\label[diagram]{eq:23}
1 = 1
\end{equation}
AUCTeX will not notice that I have used eq:23
, and then if I try to
automatically generate labels, it will again propose eq:23
.
Digging around in the AUCTeX sources, I found the following in latex.el
:
(defvar LaTeX-auto-label-regexp-list
'(("\\\\label{\\([^^M\n\r%\\{}]+\\)}" 1 LaTeX-auto-label))
"List of regular expression matching LaTeX labels only.")
This seems to be the appropriate variable to extend. However, I can't seem to get the regexp right. I have tried adding the following to my emacs config before AUCTeX gets loaded (and it appears in the output of describe-variable
for LaTeX-auto-label-regexp-list
), but AUCTeX is still not recognizing the above as labels.
(setq LaTeX-auto-label-regexp-list
'(("\\\\label{\\([^^M%\\{}]+\\)}" 1 LaTeX-auto-label)
("\\\\label\\[[^^M[\\{}]+\\]{\\([^^M%\\{}]+\\)}" 1 LaTeX-auto-label)))
What am I missing?
^M
right after the following[
(in the regexp you added).re-builder
, and it correctly matches\label[abc]{eq:3}
for example.LaTeX-auto-label-regexp-list
is used for something else in AUCTeX, such as fontification.reftex-label
function is what seems to actually generate the labels, and I think it usesreftex-parse-from-file
to figure out existing labels. Unfortunately, it hard-codes the\label{
prefix. I've filed a wishlist bug report. I'll update the question with an answer if ever it gets fixed.