What is the difference of tex-mode and latex-mode and LaTeX-mode in emacs
Asked Answered
A

2

11

I am configuring AUCTeX in emacs.

Most of the configurations are put in a LaTeX-mode-hook. When I open a main.tex file, I notice that the major mode is latex-mode and my hooked configurations are not activated. I have to M-x Tex-latex-mode to activate them. 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.

Airman answered 21/7, 2013 at 21:37 Comment(0)
K
11

The modes provided by AUCTeX are listed at https://www.gnu.org/software/auctex/manual/auctex.html#Modes-and-Hooks and they are

  • 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.

If you want to open all *.tex files with AUCTeX LaTeX mode add this to your .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.

Koslo answered 21/7, 2013 at 23:35 Comment(4)
I think this information is outdated. LaTeX-mode seems to be an alias of latex-mode, and TeX-latex-mode is a mode defined by AUCTeX (version 12.3). Anyways, I am completely confused. If i want to set keybindings, which map do I use: latex-mode-map or LaTeX-mode-map or both?Brevity
After digging a bit deeper, it seems that AUCTeX is overriding the alias of LaTeX-mode, but I can't see where ... I wonder why this is so complicated.Brevity
For your keybindings you should use only LaTeX-mode-map, which is the official AUCTeX name.Koslo
This answer is missing an explanation of TeX-latex-mode, which seems to be what the OP originally asked about. LaTeX-mode does not have a docstring, whereas TeX-latex-mode is documented as being the Major mode in AUCTeX for editing LaTeX files.Lessielessing
C
1

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.

Setting up AucTeX can be quite confusing, because it uses advice to override Emacs' built-in support for TeX and friends.

So, after installing AucTeX from ELPA, you should see the following in C-h 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.

The function LaTeX-mode is not defined in AucTeX (any more?): it's defined in core Emacs, with a cryptic comment about compatibility:

;; 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; just installing it is enough for it to override Emacs' builtin functionality.

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.

Counterattraction answered 1/12, 2021 at 3:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.