# Cleveref: AUCTeX and RefTeX set-up

How can I set up cleveref to work with AUCTeX and RefTeX? I have tried the advice on Emacs, RefTeX and Cleveref – can they work together? but it didn't work.

Additionally, when I hit enter, \ref{} portion is always enclosed in ( ). How can I get rid of ( ) enclosing the ref{}?

I also checked out:

AUCTeX – new commands recognized as such

this post but all the information is relatively old so maybe there is a newer answer?

-

(eval-after-load
"latex"
"cleveref"
(lambda ()
(if (boundp 'reftex-ref-style-alist)
'reftex-ref-style-alist
'("Cleveref" "cleveref"
(("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
'("cref" TeX-arg-ref)
'("Cref" TeX-arg-ref)
'("cpageref" TeX-arg-ref)
'("Cpageref" TeX-arg-ref)))))


I've taken the value for reftex-ref-style-alist from this revision: http://bzr.savannah.gnu.org/lh/emacs/trunk/revision/112689

I don't know why you have \ref enclosed in ( ), this isn't the default behavior of RefTeX, perhaps you put a dirty hack in your init file.

-
The code I posted works for me: if I press C-c C-m cref RET, I get \cref, not \ref, it's impossible you get a \ref. Please explain better what's your problem and, if you can, post all AUCTeX/RefTeX related customizations in your .emacs. –  giordano Jun 15 '13 at 15:12
@dustin I updated my answer, but you didn't specify that. –  giordano Jun 15 '13 at 15:38
@dustin which version of AUCTeX and RefTeX are you using? Here: AUCTeX 11.87 and RefTeX shipped with Emacs 24.3. Do you set AUCTeX TeX-parse-self and TeX-auto-save variables to t? –  giordano Jun 19 '13 at 23:38
See the first lines of AUCTeX manual: gnu.org/software/auctex/manual/auctex.html If you want to exploit all AUCTeX features (in particular its ability to parse TeX documents) you have to set those variables to non-nil. My code works in that case, that's the most common case among AUCTeX users. –  giordano Jun 19 '13 at 23:41
If TeX-parse-self and TeX-auto-save are non nil, it must work. When you have a \usepackage{cleveref} in your document cleveref appears in TeX-style-list variable (check its value in your buffer) and the hook associated to cleveref is run, that is the hook I wrote in the answer. –  giordano Jun 19 '13 at 23:57