1

I keep all my commonly used latex packages in one custom package, including the referencing package cleveref. However, reftex is configured to only provide insertion of cleveref referencing commands like cref if

\usepackage{cleveref}

is in the document itself. So I wanted to re-configure reftex-ref-style-alist to provide cleveref-commands without depending on the cleveref-package in the used packages in a latex document. I used the Emacs customization buffer to not have Cleveref depend on any package, yielding

'(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" t
      (("\\cref" 99) ("\\Cref" 67) ("\\cpageref" 100)
       ("\\Cpageref" 68)))
     ("AMSmath" "amsmath" (("\\eqref" 101)))))

in my customized variables, but for whatever reason, this still doesn't lead to reftex providing the cleveref commands without cleveref called in a tex file. I also tried to put the following into my (usepackage tex) :config settings:

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

Neither of these worked. Why? And how can I set reftex-cleveref-insertions to be globally available.

Edit: Interestingly, if I have

\usepackage{cleveref}

in one of the .tex files in a buffer in my desktop file when I start Emacs, it seems to provide the corresponding reftex-templates globally, so in particular in files in which it is not included. However, the same isn't true if I have it in a .sty file.

1 Answer 1

1

AUCTeX has a clean interface for hand-written LaTeX package files: You can write a corresponding AUCTeX style file and AUCTeX will load it when you use the package. Say your custom package is called custom-package.sty, then you write a file custom-package.el which looks like this:

(TeX-add-style-hook
 "custom-package" ; <= Adjust
 (lambda ()
   (TeX-run-style-hooks "cleveref"))
 :latex)

and save it under a directory available in TeX-style-private. Make sure you have this in your init file as well:

(setq TeX-parse-self t)

Now restart Emacs and open your .tex file. AUCTeX should load your custom style file as well and cleveref should be available, also with RefTeX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.