reddit / emacs

How to make AuCTeX and RefTeX work with Cleveref?

FranekW · 2022-12-10 10:34
I cross-reference with RefTeX using `reftex-reference` (`C-c )`). It's very convenient as it opens a list of available macros, followed by a type of references, followed by a list of labels to insert. On the other hand, `cleveref` extends cross-referencing, which add very useful macros and does other things as well. Currently, my routine is to press `C-c )`, insert a standard `\ref{}`, and then change it to `\cref{}`. I tried to find solutions, which implement Cleveref in RefTeX but there is not many sources; the one I found [here on TeX](https://tex.stackexchange.com/questions/119253/cleveref-auctex-and-reftex-set-up) does not seem to work; It does not add anything new to the list. I found somewhere else this line: `(setq reftex-refstyle "\\cref")`. This is OK. RefTeX no longer asks for a macro but go straight to a list of types followed by a list of labels. Then it inserts `\cref{...}` with a proper string. This works but ideally though I would have a proper list of macros available from Cleveref: `\cref{}`, `\Cref{}`, `\namecref{}`, `\pagecref{}` etc. on top of regular macros. Does anyone have or know about a working solution?
FranekW · 2022-12-10 13:58
So I was digging in a reference manual and found this variable: `reftex-ref-style-default-list`. It turns out the only thing I have to do is to set it to one of the templates; the default value is `("Default")`. It must match one of the strings available in another variable `reftex-ref-style-alist`: (("Default" t (("\\ref" 13) ("\\Ref" 82) ("\\footref" 110) ("\\pageref" 112))) ("Varioref" "varioref" (("\\vref" 118) ("\\Vref" 86) ("\\vpageref" 103))) ("Fancyref" "fancyref" (("\\fref" 102) ("\\Fref" 70))) ("Hyperref" "hyperref" (("\\autoref" 97) ("\\autopageref" 117))) ("Cleveref" "cleveref" (("\\cref" 99) ("\\Cref" 67) ("\\cpageref" 100) ("\\Cpageref" 68))) ("AMSmath" "amsmath" (("\\eqref" 101)))) So I added this to my `.emacs` init file ;; Setup AUCTeX on load (add-hook 'LaTeX-mode-hook (lambda () (setq reftex-ref-style-default-list '("Default" "Cleveref"))) and now I am a happy user of Cleveref :)