I defined a new tcolorbox based floating environment named riquadro, and I want RefTeX to find the label I insert using label={name} option.

From the documentation of reftex-label-regexps it seems the keyval style format should be recognised by default, but no label of this type appears when I try to run reftex-reference (with C-c )).

I also set up

   '(("riquadro" ?a "riq:" nil caption ("riquadro")))

but this seems to have no effect.

Maybe I have to declare the new environment and tell RefTeX to look for its label, but I don't know how to do it.

  • Which Emacs version are you using? Feb 23, 2021 at 7:46
  • GNU Emacs 28.0.50. AUCTeX 12.3.1
    – Massimo
    Feb 24, 2021 at 9:25
  • I realised the problem is that reftex-label-regexps looks for keyval labels only within specific environments
    – Massimo
    Feb 24, 2021 at 9:27

1 Answer 1


The behavior of reftex-label-regexps was changed with Emacs version 27: RefTeX now looks for the label key in the optional argument of given environments; others are ignored. The docstring says:

reftex-label-regexps is a variable defined in ‘reftex-vars.el’. Its value is [...]

List of regexps matching \label definitions. The default value matches usual \label{...} definitions and keyval style [..., label = {...}, ...] label definitions. The regexp for keyval style explicitly looks for environments provided by the packages "listings" ("lstlisting"), "beamer" ("frame"), "breqn" ("dmath", "dseries", "dgroup", "darray") and the macro "\ctable" provided by the package of the same name.

It is assumed that the regexp group 1 matches the label text, so you have to define it using \(?1:...\) when adding new regexps.

For your custom environment, you can use the customize interface to add an entry or put something like this in your init file:

(with-eval-after-load "reftex-vars"
  (add-to-list 'reftex-label-regexps
                ;; Match the opening [ and the following chars
                ;; Allow nested levels of chars enclosed in braces
                ;; Match the label key
                ;; Match the label value; braces around the value are
                ;; optional.
                "{?\\(?1:[^] ,}\r\n\t%]+\\)"
                ;; We are done.  Just search until the next closing bracket

OTOH, AUCTeX has a style file for tcolorbox which is able to parse and process user defined environments. It should contain some code to make this addition automatically.

You must log in to answer this question.

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