I use Emacs + RefTeX + AUCTeX to write .tex files. I use the handy keyboard macro

C-c )

for cross-references. This shows a menu named SELECT A REFERENCE FORMAT and I can choose between a number of options, such as \ref,\pageref and the like. However, among these I am missing the \eqref format. This leads to my question: How can I modify the SELECT A REFERENCE FORMAT menu to add \eqref?


The following works for me, though it may be imperfect as I'm not very comfortable with RefTeX customization:

(defun my-add-to-alist (alist-var key value &optional append)
  "Add an element to an association list.
If ALIST-VAR contains no element whose CAR is `equal' to KEY, then add
(KEY . VALUE) to ALIST-VAR. If APPEND is nil, add it to the beginning of
ALIST-VAR, otherwise add it to the end of ALIST-VAR.

If there is already an element in ALIST-VAR whose CAR is `equal' to KEY,
replace its CDR with VALUE."
  (let ((cons-cell (assoc key (eval alist-var))))
    (if cons-cell
        (setcdr cons-cell value)
      (add-to-list alist-var (cons key value) append))))

(my-add-to-alist 'reftex-ref-style-alist
                 "AMSMath" '("amsmath" (("\\eqref" ?e))) t)

(require 'tex)
(TeX-add-style-hook "amsmath"
   #'(lambda ()
       (when (fboundp 'reftex-add-label-environments)
         (add-to-list 'reftex-ref-style-default-list "AMSMath" t)
         (reftex-ref-style-activate "AMSMath")
         (setq reftex-label-alist '(AMSTeX)))))

Note: I assume you already have something like this before the above code:

;; Use RefTeX in LaTeX buffers
(require 'reftex)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX's LaTeX mode
; (add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs' latex mode
(setq reftex-plug-into-AUCTeX t)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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