Configuring emacs for latex - void-variable LaTeX-mode-hook
Asked Answered
M

2

5

Following this pdf document I added the following to my ~/.emacs file:

(load "auctex.el" nil t t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-PDF-mode t) ;; .pdf statt .dvi per default:
;;Zeilenumbruch
;;(add-hook ’LaTeX-mode-hook ’turn-on-auto-fill)
;;Syntax Higlight
(add-hook ’LaTeX-mode-hook ’turn-on-font-lock)
;; Mathe Modus
(add-hook ’LaTeX-mode-hook ’LaTeX-math-mode)
;; Reftex einflechten und laden
(setq reftex-plug-into-AUCTeX t)
(add-hook ’LaTeX-mode-hook ’turn-on-reftex)
;; Satzende ". " statt ". ". " fuer M-k: loeschen bis Satzende usw.
;;(setq sentence-end "[.?!][]\"’)}]*\\($\\| \\| \\)[
;;]*") ;; Da ist ein "Newline in der Zeile!"
;;(setq sentence-end-double-space nil)
;;direkte Rechtschreib Korrektur:
;;(add-hook ’LaTeX-mode-hook ’flyspell-mode)
;; Nur benutzen falls Auctex > 11.81 mit preview-latex:
(load "preview-latex.el" nil t t)
;; aspell ist besser als ispell.
;; Zeile kommentieren, falls nicht installiert:
(setq-default ispell-program-name "aspell")
;; Deutsche Rechtschreibung falls \usepackage{ngerman}
;; oder german benutzt wird
(add-hook ’TeX-language-de-hook
(function (lambda () (ispell-change-dictionary "german8"))))

Unfortunately emacs doesn't start now, instead it gives the error

Warning (initialization): An error occurred while loading `/home/../.emacs':

Symbol's value as variable is void: ’LaTeX-mode-hook

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.

When starting with --debug-init it gives the following information

Debugger entered--Lisp error: (void-variable ’LaTeX-mode-hook)
  (add-hook ’LaTeX-mode-hook ’turn-on-font-lock)
  eval-buffer(#<buffer  *load*> nil "/home/../.emacs" nil t)  ; Reading at buffer position 812
  load-with-code-conversion("/home/../.emacs" "/home/../.emacs" t t)
  load("~/.emacs" t t)
...

I tried using latex-mode-hook instead. I searched for a solution, but I seem to be the only one having exactly this problem.

I'm using Ubuntu 12.04 with the latest Emacs and Auctex. If required I'll post version information, but I rather think that something has to be added into the configuration or any package has to be installed instead.

How can I get emacs work with that configuration?

Montserrat answered 6/6, 2012 at 17:47 Comment(4)
What happens if you include only (load "auctex.el" nil t t) in your .emacs? It seems that for some reason AucTeX is not being loaded. If you don't get an entry in the Emacs menu for LaTeX, then AucTeX is not being loaded.Minutely
@Minutely I can see the LaTeX menu in Emacs, if I don't include (load "auctex.el" nil t t). Also Emacs starts without any error, when including that line in my .emacs. If I include that line, the LaTeX menu disappears.Montserrat
OK, then probably the auctex package adds the lines needed to initialize AucTeX to some global (or Debian-specific) Emacs initialization files. What happens if you add only (add-hook ’LaTeX-mode-hook ’LaTeX-math-mode) to your .emacs? Can you work with AucTeX? (that is does C-c C-c in a LaTeX file offers to compile the file?)Minutely
I tried adding (add-hook ’LaTeX-mode-hook ’LaTeX-math-mode) which gave the same error. Then as mentioned in the answers I tried adding (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode) and it gave no error.Montserrat
R
9

Are you using the wrong single quote character? it seems to be some kind of a backward quote instead of a plain single quote. Try

'LaTeX-mode-hook

instead of

’LaTeX-mode-hook

(and likewise for all other occurrences of that character).

Remora answered 7/6, 2012 at 5:1 Comment(1)
Oh dear! Thanks for that answer, it solved the problem - at least Emacs starts without error. Now I can use the weekend to play with the features.Montserrat
H
2

As Thomas also said, the back quote is not the character you want to use there, it should be the single straight quote. But, in general, if you get "symbol's value as variable is void" error, it means the same as NPE (null pointer exception) in other languages. The way to check what went wrong is like so:

Move point to the variable that gives the problem and C-h v (or M-x describe-variable [name of the variable without quote]). You can use TAB to complete the variable name as you type to see if you by chance didn't mistype it. Once you see the buffer that describes the variable - you know you've fixed the error.

Now, if you have LaTeX mode set through auctex.el, then latex-mode-hook must exist. However, you need to make sure that auctex.el actually loads and requires latex-mode. The way it does so isn't an idiomatic way for Emacs to do it, most of the time you add the source files for the mode to the load-path variable and then (require 'mode-name) or load the mode conditionally once Emacs opens the type of the file associated with it (makes startup time for Emacs shorter) through autoload as described here: Emacs: Best-practice for lazy loading modes in .emacs? .

However, whenever you see a variable called [something]-mode-hook it means that this is a list of functions you want to call when [something] mode loads up. If the [something] mode at all exists, there's a 99.99% chance that variable exists too (can't be void). So, if it is void - you need to make sure that the mode it belongs to at all loads.

Helpless answered 7/6, 2012 at 7:56 Comment(1)
Thanks for that further explanation. I think that'll help me in future when seeing such an error again :)Montserrat

© 2022 - 2024 — McMap. All rights reserved.