简体   繁体   English

配置emacs for latex - void-variable LaTeX-mode-hook

[英]Configuring emacs for latex - void-variable LaTeX-mode-hook

Following this pdf document I added the following to my ~/.emacs file: 这个pdf文档之后,我将以下内容添加到~/.emacs文件中:

(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 不幸的是,emacs现在无法启动,而是出现错误

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 --debug-init开始时,它提供以下信息

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. 我尝试使用latex-mode-hook代替。 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. 我正在使用Ubuntu 12.04和最新的Emacs和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? 如何让emacs使用该配置?

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). (同样适用于该角色的所有其他事件)。

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. 但是,一般来说,如果你得到“符号的值作为变量是无效的”错误,它意味着与其他语言中的NPE(空指针异常)相同。 The way to check what went wrong is like so: 检查出错的方法是这样的:

Move point to the variable that gives the problem and Ch v (or Mx describe-variable [name of the variable without quote]). 将点移动到给出问题的变量和Ch v (或Mx describe-variable [ Mx describe-variable名称不带引号])。 You can use TAB to complete the variable name as you type to see if you by chance didn't mistype it. 您可以在键入时使用TAB完成变量名称,以查看您是否偶然输错了它。 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. 现在,如果您通过auctex.el设置了LaTeX模式,那么必须存在latex-mode-hook However, you need to make sure that auctex.el actually loads and requires latex-mode . 但是,您需要确保auctex.el实际加载并需要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? 它这样做的方式并不是Emacs这样做的惯用方法,大多数时候你将模式的源文件添加到load-path变量然后(require 'mode-name)或者有条件地加载模式一次Emacs通过autoload打开与之关联的文件类型(使Emacs的启动时间缩短),如下所述: Emacs:.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. 但是,每当您看到名为[something]-mode-hook的变量时,就意味着这是在[something]模式加载时要调用的函数列表。 If the [something] mode at all exists, there's a 99.99% chance that variable exists too (can't be void). 如果[something]模式完全存在,那么变量存在的可能性为99.99%(不能为空)。 So, if it is void - you need to make sure that the mode it belongs to at all loads. 因此,如果它无效的 - 您需要确保它在所有负载下属于它的模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM