3

I'm using RefTeX along with enumitem, and I find that RefTeX seems to interpret a block like

\begin{enumerate}[label=\Alph*.]
\end{enumerate}

as defining a label named \Alph*. That's fine, but then if I later have another block like this, the TOC thinks I'm at the location of the first such block.

Any ideas on how I might work around this? (Can I define some strings that RefTeX should never consider to be labels?)

2
  • Just to make sure: You use Emacs as editor, yes? I understand that Emacs can think for itself, if you don't believe me, type M-x doctor RET. That said, what do you mean by »the TOC thinks« you were somewhere? Please explain!
    – Keks Dose
    Commented Sep 15, 2018 at 20:17
  • Sorry, what I meant was that if I run reftex-toc, it shows my current location as the first occurrence of \begin{enumerate}[label=\Alph*.] rather than where I actually am in the file. However, after some more reading, I've figured out how to fix this, so I'll post that below.
    – Janet
    Commented Sep 16, 2018 at 15:03

2 Answers 2

3

RefTeX comes with a variable called reftex-label-ignored-macros-and-environments. The documentation string says:

reftex-label-ignored-macros-and-environments is a variable defined in reftex-vars.el.

List of macros and environments to be ignored when searching for labels. The purpose is to ignore environments and macros that use keyval style label=foo arguments, but the label has a different meaning than a \label{foo}. Standard \label{...} definitions are never ignored.

E.g., TikZ defines several macros/environments where [label=foo] defines the label to be printed at some node or edge, but it’s not a label used for referencing.

Note that this feature is only supported if you are using AUCTeX and the functions TeX-current-macro and LaTeX-current-environment are bound. Also note that this feature might slow down the reftex parsing process for large TeX files.

In your case, don't touch reftex-label-regexps and add enumerate to the variable mentioned above.

E.g., do M-x customize-variable RET reftex-label-ignored-macros-and-environments RET, make the addition and hit Apply and Save.

5
  • Arash, thank you for this. I was trying to figure out how to deal with this case and, as usual, you guys are always some steps ahead. If I may ask, is there a reason why this variable defaults to nil, instead of including some common known cases? (either globally or in the style files).
    – gusbrs
    Commented Jul 2, 2019 at 22:38
  • 1
    @gusbrs - I think the reason is the slowdown it can produce. At any rate, I wasn't happy with this either and made some changes reftex-label-regexps. With Emacs 27, RefTeX will look in opt. arguments of predefined environments for label. Until then, you can customize reftex-label-regexps and append this regexp to it: "\\\\\\(?:begin[[:space:]]*{\\(?:d\\(?:array\\|group\\|math\\|series\\)\\|lstlisting\\)}[[:space:]]*\\|ctable\\)\\[[^][]*\\(?:{[^}{]*\\(?:{[^}{]*\\(?:{[^}{]*}[^}{]*\\)*}[^}{]*\\)*}[^][]*\\)*\\<label[[:space:]]*=[[:space:]]*{?\\(?1:[^] ,}\r\n\t%]+\\)}?[^]]*\\]" Commented Jul 3, 2019 at 15:58
  • 1
    Arash, thank you once again! If I understand correctly, the new regexp will only match keyval style labels in predefined environments. Instead of matching all, and excluding some. That sounds better indeed. All in all, alongside with the support for biblatex multicite commands, this leaves me anxiously waiting for Emacs 27. But your suggestion does work perfectly in the meantime. Thanks!
    – gusbrs
    Commented Jul 3, 2019 at 19:42
  • @gusbrs - You're welcome. Yes, your understanding is correct, the regexp now matches keyval labels in environments provided by breqn and listings package and the macro \ctable. As a note, if you've used the customize interface, you don't need to quote the \, i.e., use "\\\(?:begin[[:space:]]*{\(?:d\( ... Sorry for the inconvenience. Commented Jul 3, 2019 at 19:50
  • No inconvenience at all, on the contrary, thanks for the warning! Anyway, I just took the full new definition from the Git repo and placed it in my init file. ;-)
    – gusbrs
    Commented Jul 3, 2019 at 20:02
2

It turns out that the variable I needed was reftex-label-regexps, which specifies the regexps that RefTeX considers labeling commands. I've now set it to only look for labeling commands of the form \label{name} rather than also including label=name.

1
  • Then accept your own answer, if possible. This will move the question off the list of unanswered questions. We already got enough of them.
    – Keks Dose
    Commented Sep 17, 2018 at 7:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .