繁体   English   中英

emacs中tex-mode和latex-mode和LaTeX-mode有什么区别

[英]What is the difference of tex-mode and latex-mode and LaTeX-mode in emacs

我正在 emacs 中配置 AUCTeX。

大多数配置都放在 LaTeX 模式挂钩中。 当我打开一个 main.tex 文件时,我注意到主要模式是 latex-mode 并且我的挂钩配置没有被激活。 我必须使用 Mx Tex-latex-mode 来激活它们。 但是主要模式仍然是乳胶模式。

(add-hook 'LaTeX-mode-hook
      (lambda ()

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;; auctex

        (setq TeX-auto-save t)
        (setq TeX-parse-self t)
       ))

所以我想知道这些模式有什么区别,以及如何在打开 *.tex 文件时自动打开 AUCTeX。

AUCTeX提供的模式列于https://www.gnu.org/software/auctex/manual/auctex.html#Modes-and-Hooks ,它们是

  • plain-TeX-mode
  • LaTeX-mode
  • ams-TeX-mode
  • ConTeXt-mode
  • Texinfo-mode
  • docTeX-mode

代替,

  • tex-mode
  • plain-tex-mode
  • latex-mode
  • slitex-mode
  • doctex-mode

(注意不同的大小写)是Emacs附带的TeX模式包提供的主要模式。

如果要使用AUCTeX LaTeX模式打开所有*.tex文件,请将其添加到.emacs

(add-to-list 'auto-mode-alist '("\\.tex$" . LaTeX-mode))

实际上,这不是必需的,因为AUCTeX将tex-mode.el模式名称定义为其自身模式的别名。

TLDR:使用latex-modeLaTeX-mode (它们的意思相同),无需更改auto-mode-alist ,并使用LaTeX-mode-hook挂钩到 AucTeX。

设置 AucTeX 可能会非常令人困惑,因为它使用建议来覆盖 Emacs 对 TeX 和朋友的内置支持。

因此,从 ELPA 安装 AucTeX 后,您应该在Ch f latex-mode看到以下内容:

This function has :override advice: ‘TeX-latex-mode’.

所有其他 tex 模式相同,尽管 AucTeX 覆盖的模式列表取决于TeX-modes变量的值。

函数LaTeX-mode没有在 AucTeX 中定义(还有吗?):它是在核心 Emacs 中定义的,有一个关于兼容性的神秘评论:

;; The following three autoloaded aliases appear to conflict with
;; AUCTeX.  However, even though AUCTeX uses the mixed case variants
;; for all mode relevant variables and hooks, the invocation function
;; and setting of `major-mode' themselves need to be lowercase for
;; AUCTeX to provide a fully functional user-level replacement.  So
;; these aliases should remain as they are, in particular since AUCTeX
;; users are likely to use them.
;; Note from Stef: I don't understand the above explanation, the only
;; justification I can find to keep those confusing aliases is for those
;; users who may have files annotated with -*- LaTeX -*- (e.g. because they
;; received them from someone using AUCTeX).

;;;###autoload
(defalias 'TeX-mode #'tex-mode)
;;;###autoload
(defalias 'plain-TeX-mode #'plain-tex-mode)
;;;###autoload
(defalias 'LaTeX-mode #'latex-mode)

这一切都意味着,至少在2021年,你不需要改变auto-mode-alist在使用AucTeX; 只需安装它就足以覆盖 Emacs 的内置功能。

不幸的是,还有最后一个混乱来源。 尽管LaTeX-mode现在大多只是latex-mode的无用别名,但事实证明,AucTeX 中覆盖latex-mode代码不会调用latex-mode-hook (它调用LaTeX-mode-hook ,这是不同的。因此, LaTeX-变量,即LaTeX-变量(与 Emacs 内置的小写变量相反)仍然有用。

暂无
暂无

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

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