问题
I am trying to add the following code to my .emacs
init file:
(TeX-add-symbols '("eqref" TeX-arg-ref))
But I cannot get it to work. I get the following error when running emacs t.tex
(t.tex
is here a sample text file) from the command line:
Warning (initialization): An error occurred while loading `.emacs':
Symbol's function definition is void: TeX-add-symbols
I am using GNU Emacs version 23.3.1 on Ubuntu 12.04. My .emacs
init file looks like
(setq TeX-auto-parse t)
(setq TeX-electric-escape t)
(setq reftex-label-alist '((nil ?e nil "~\\eqref{%s}" nil nil)))
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
(TeX-add-symbols '("eqref" TeX-arg-ref))
If I enter ESC-:
(i.e. running the command eval-expression
) and enter
(TeX-add-symbols '("eqref" TeX-arg-ref))
at the prompt it works fine. (That is after running this, I can enter \eqref
in the buffer and it works as expected.. But this is not a good solution, having to enter this code manually each time I edit a file.. That is the reason why I try to set it up in the .emacs
file..)
Background information for this question:
I have a problem with using the AucTeX style amsmath.el
.. it seems that it is not loaded properly on my machine.. For more information, see Using \eqref with RefTeX.
回答1:
You have to evaluate the code after LaTeX-mode
is activated, otherwise you get the error Symbol's function definition is void: TeX-add-symbols
. You can add that function to the hook of LaTeX-mode
. In order to override possible other eqref
macro definitions, you should add a dummy (ignore)
to the definition of the macro. This code, in your .emacs
, does the trick:
(add-hook 'LaTeX-mode-hook
'(lambda ()
(TeX-add-symbols '("eqref" TeX-arg-ref (ignore)))))
来源:https://stackoverflow.com/questions/17244255/add-a-tex-symbol-in-the-emacs-init-file