[英]What is the difference of tex-mode and latex-mode and LaTeX-mode in emacs
I am configuring AUCTeX in emacs.我正在 emacs 中配置 AUCTeX。
Most of the configurations are put in a LaTeX-mode-hook.大多数配置都放在 LaTeX 模式挂钩中。 When I open a main.tex file, I notice that the major mode is latex-mode and my hooked configurations are not activated.
当我打开一个 main.tex 文件时,我注意到主要模式是 latex-mode 并且我的挂钩配置没有被激活。 I have to Mx Tex-latex-mode to activate them.
我必须使用 Mx Tex-latex-mode 来激活它们。 But the major-mode is still latex-mode.
但是主要模式仍然是乳胶模式。
(add-hook 'LaTeX-mode-hook
(lambda ()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; auctex
(setq TeX-auto-save t)
(setq TeX-parse-self t)
))
So I would like to know what is the difference of these modes and how can I turn on AUCTeX automatically when I open a *.tex file.所以我想知道这些模式有什么区别,以及如何在打开 *.tex 文件时自动打开 AUCTeX。
The modes provided by AUCTeX are listed at https://www.gnu.org/software/auctex/manual/auctex.html#Modes-and-Hooks and they are 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
Instead, 代替,
tex-mode
plain-tex-mode
latex-mode
slitex-mode
doctex-mode
(note the different capitalization) are the major modes provided by the TeX mode package shipped with Emacs. (注意不同的大小写)是Emacs附带的TeX模式包提供的主要模式。
If you want to open all *.tex
files with AUCTeX LaTeX mode add this to your .emacs
: 如果要使用AUCTeX LaTeX模式打开所有
*.tex
文件,请将其添加到.emacs
:
(add-to-list 'auto-mode-alist '("\\.tex$" . LaTeX-mode))
Actually, this shouldn't be necessary, because AUCTeX defines the tex-mode.el
mode names as alias of its own modes. 实际上,这不是必需的,因为AUCTeX将
tex-mode.el
模式名称定义为其自身模式的别名。
TLDR: Use latex-mode
or LaTeX-mode
(they mean the same thing), no need to change auto-mode-alist
, and use LaTeX-mode-hook
for hooking into AucTeX. TLDR:使用
latex-mode
或LaTeX-mode
(它们的意思相同),无需更改auto-mode-alist
,并使用LaTeX-mode-hook
挂钩到 AucTeX。
Setting up AucTeX can be quite confusing, because it uses advice to override Emacs' built-in support for TeX and friends.设置 AucTeX 可能会非常令人困惑,因为它使用建议来覆盖 Emacs 对 TeX 和朋友的内置支持。
So, after installing AucTeX from ELPA, you should see the following in Ch f latex-mode
:因此,从 ELPA 安装 AucTeX 后,您应该在
Ch f latex-mode
看到以下内容:
This function has :override advice: ‘TeX-latex-mode’.
Same for all the other tex modes, though the list of modes that AucTeX overrides depends on the value of the TeX-modes
variable.所有其他 tex 模式相同,尽管 AucTeX 覆盖的模式列表取决于
TeX-modes
变量的值。
The function LaTeX-mode
is not defined in AucTeX (any more?): it's defined in core Emacs, with a cryptic comment about compatibility:函数
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)
What this all means is that, at least in 2021, you do not need to change auto-mode-alist
to use AucTeX;这一切都意味着,至少在2021年,你不需要改变
auto-mode-alist
在使用AucTeX; just installing it is enough for it to override Emacs' builtin functionality.只需安装它就足以覆盖 Emacs 的内置功能。
Unfortunately, there's one last source of confusion.不幸的是,还有最后一个混乱来源。 Even though
LaTeX-mode
is now mostly just a useless alias for latex-mode
, it turns out that code in AucTeX that overrides latex-mode
does not call latex-mode-hook
(it calls LaTeX-mode-hook
, which is different. So the LaTeX-
variables, which are the AucTeX ones (as opposed to the lowercase ones that are builtin with Emacs), are still useful.尽管
LaTeX-mode
现在大多只是latex-mode
的无用别名,但事实证明,AucTeX 中覆盖latex-mode
代码不会调用latex-mode-hook
(它调用LaTeX-mode-hook
,这是不同的。因此, LaTeX-
变量,即LaTeX-
变量(与 Emacs 内置的小写变量相反)仍然有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.