# ams math + AUCTeX + refTeX causing label references to always be \eqref not the desired \vref

As stated on the reftex documentation “Note that this is automatically done by the ‘amsmath.el’ style file of AUCTEX, see Section 7.8.2, page 38 – so if you use AUCTEX, this configuration will not be necessary.” but my problem is that C-c ) which inserts a reference gives me the style dialogue, and I select \vref, but then it inserts a \eqref. It’s making me crazy. I have no idea how to debug and fix this, my lisp-fu is very poor.

My document uses the amsmath, varioref, and cleveref packages.

• Welcome to TeX.SE! Have you tried to change the code line (setq reftex-label-alist ’((nil ?e nil "~\\eqref{%s}" nil nil))) in amsmath.el to, say, (setq reftex-label-alist ’((nil ?e nil "~\\vref{%s}" nil nil)))? – Mico Nov 10 '14 at 19:39
• Possible duplicate of Cross-ref an equation using RefTeX, AUCTeX and cleveref – giordano Nov 11 '14 at 0:33
• @Mico: Why is amsmath.el overriding a custom set variable?! grrr – zbeekman Nov 11 '14 at 14:31
• You're asking the wrong person... – Mico Nov 11 '14 at 14:34
• OK, I have little idea how I fixed this, because I was mucking around in the customization menus of AUCTeX and refTeX, but now when I select varioref style in the interactive reftex menu, it actually works and inserts \vref instead of \eqref. Also, I had some \newtheorem declarations before \usepackage{cleveref} but I think that was an unrelated issue. I may try to dig deeper to see what I changed that fixed it, but I’m pretty swamped at the moment so I’m not sure if I’ll ever get to this. Thanks for your help. – zbeekman Nov 11 '14 at 14:54

So @giordano was at least partially correct, this is closely related to Cross-ref an equation using RefTeX, AUCTeX and cleveref and more specifically the bug fixed by this patch

On Mac OS X, in order to fix it, using Emacs 24.3 (9.0) I did the following:

Sudo Emacs /Applications/Emacs.app//Contents/Resources/lisp/textmodes/reftex-ref.el.gz

Then within emacs I manually edited lines 836-837, deleting what had been there,

(while (string-match "\$$\\\\ref\$$[ \t]*{" fmt) (setq fmt (replace-match refstyle t t fmt 1)))

with:

(cond ((while (string-match "\$$\\\\ref\$$[ \t]*{" fmt) (setq fmt (replace-match refstyle t t fmt 1)))) ((string-match "\$$\\\\[[:alpha:]]+\$$[ \t]*{" fmt) (setq fmt (replace-match refstyle t t fmt 1))))

Next, I saved it and ran

M-x byte-compile

then closed and reopened my other Emacs session.

I hope others find this useful.