RefTeX:如何修改“选择参考格式”菜单?

RefTeX:如何修改“选择参考格式”菜单?

我使用 Emacs + RefTeX + AUCTeX 来编写.tex文件。我使用方便的键盘宏

C-c )

用于交叉引用。这显示了一个名为的菜单SELECT A REFERENCE FORMAT,我可以在多个选项之间进行选择,例如\ref\pageref等等。然而,在这些选项中,我缺少格式\eqref。这导致我的问题:我怎样才能修改SELECT A REFERENCE FORMAT要添加的菜单\eqref

答案1

以下方法对我有用,尽管它可能不完美,因为我对 RefTeX 定制不太满意:

(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."
  (interactive)
  (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)))))

注意:我假设你已经有类似的东西上面的代码:

;; 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)

相关内容