3

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.

Community
  • 1
  • 1
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
  • 2
    `(eval-after-load "latex" '(TeX-add-symbols '("eqref" TeX-arg-ref)))` – giordano Jun 21 '13 at 21:06
  • Thanks, but it seems that it does not work .. – Håkon Hægland Jun 21 '13 at 21:12
  • The error you reported (`Symbol's function definition is void: TeX-add-symbols`) should be fixed, right? To make `eqref` work you have to delete the file in `/var/lib`, as I suggested on TeX.SE. – giordano Jun 21 '13 at 21:13
  • yes :) But when I enter `C-h v TeX-symbol-list` `eqref` is not defined... – Håkon Hægland Jun 21 '13 at 21:14
  • I hoped I could fix this it without deleting the file :) – Håkon Hægland Jun 21 '13 at 21:15
  • Why doesn't `eval-after-load "latex"` work here? – Håkon Hægland Jun 21 '13 at 21:19
  • The following question: http://stackoverflow.com/questions/2736087/eval-after-load-vs-mode-hook indicates that mode hooks are run later than `eval-after-load` code.. Is it possible to use a mode hook here? – Håkon Hægland Jun 21 '13 at 21:33
  • 1
    Try `(add-hook 'LaTeX-mode-hook '(lambda () (TeX-add-symbols '("eqref" TeX-arg-ref))))` or `(add-hook 'LaTeX-mode-hook '(lambda () (TeX-add-symbols '("eqref" TeX-arg-ref (ignore)))))` – giordano Jun 21 '13 at 21:55
  • Thanks again.. But it does not work. It seem that it the mode hook is run just *before* (not *after* as I was hoping for) emacs loads the file `/var/lib/auctex/emacs23/amsmath.elc`.. – Håkon Hægland Jun 21 '13 at 22:04
  • Yes, `LaTeX-mode-hook` is run as soon as LaTeX mode is activated, `/var/lib/.../amsmath.elc` is loaded when the file is parsed and AUCTeX sees that your LaTeX source contains a `\usepackage{amsmath}`. But `TeX-symbol-list` should contain a `("eqref" 1)` and a `("eqref" TeX-arg-ref (ignore))` and AUCTeX should prefer the one with the longest definition, the latter in this case. This is AUCTeX works, see the [AUCTeX manual](http://www.gnu.org/software/auctex/manual/auctex.html#Adding-Macros). – giordano Jun 21 '13 at 22:09
  • @giordano Yes! Very nice, I missed your point.. After adding the `ignore` argument in `(add-hook 'LaTeX-mode-hook '(lambda () (TeX-add-symbols '("eqref" TeX-arg-ref (ignore)))))` it seems to work :-) But my `TeX-symbol-list` looks strange now. It contains one `"eqref"`, one instance of `("eqref 1)`, two instances of `("eqref" TeX-arg-ref)`, and one instance of `("eqref" TeX-arg-ref (ignore))`.. :-) – Håkon Hægland Jun 22 '13 at 08:05
  • @giordano You may also add the solution now as an answer here (and also at tex.stackexchange.com, if you want) and I will accept them.. Thanks a lot for all the help! – Håkon Hægland Jun 22 '13 at 08:08

1 Answers1

3

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)))))
giordano
  • 8,087
  • 3
  • 23
  • 48