I recently upgraded to Emacs 29.1 (from Emacs 26).

While using latex-mode, I encountered a fontification issue for which I found a patch (Latex mode: tex-verbatim face has priority on font-lock-comment-face). I also observed that this issue does not occur with AUCTeX.

My setup includes having AUCTeX installed but not activated by default when editing .tex files. I prefer the default latex-mode (AUCTeX does not provide its own major mode but overrides it How to install AUCTeX on Emacs without automatic activation for LaTeX (.tex) files?).

My question is: unable to use the major-mode variable, which has the same value for both the standard latex-mode and AUCTeX, and assuming that AUCTeX is installed on my machine anyway, how do I test whether AUCTeX (potentially activated by the TeX-latex-mode function) is active in the buffer?

The only clue I have is that on my machine, I see "LaTeX" on the mode-line when the default latex-mode is active, while if I activate AUCTeX (M-x TeX-latex-mode), the lighter is "LaTeX/P".

My goal is to apply the patch only when the default latex-mode is active in the buffer and NOT AUCTeX.

2 Answers 2


From mode-line-format we find that the "LaTeX/P" in the mode-line is configured via mode-line-modes. From there we find that "LaTeX/P" is simply the value of mode-name so you could check if AUCTeX is active by checking the mode-name:

(string= mode-name "LaTeX/P")

Furthermore, from looking at the code of TeX-set-mode-name we find that the "P" is due to TeX-PDF-mode, but other modes are possible. Therefore I guess a more universal check is to check that the mode-name is not "LaTeX"

(not (string= mode-name "LaTeX"))
  • I often find myself wishing that AUCTeX had done things differently and not done a land grab on latex-mode etc. But I guess it's too late now.
    – NickD
    Feb 4 at 5:23
  • 3
    @NickD - It is never too late, and wishes do come true :-) Next AUCTeX release changes the mode names and leaves latex-mode alone. Check this announcement for details Feb 4 at 9:40
  • @NickD I am not sure in what way. It seems quite natural to me that it 'extends/hijacks' latex-mode. It does it cleanly by (:override) advising latex-mode. I'm no heavy latex user (at least not at the moment), but I guess AUCTeX design is 99% of the cases not a 'big deal'. It might be too late to 'fix' the design with the advice, but it should not be too much work to add a (better) AUCTeX indicator, and update its documentation about its 'relation' to latex-mode. Feb 4 at 9:41
  • The second part of the answer leaves me with some doubt. What happens if no additional modes are activated? In that case, mode-name would simply be "LaTeX". I also think that AUCTeX should be structured as a standalone major mode even though it is derived from latex-mode. In the latex.el code, I see the comment: "FIXME: Use `define-derived-mode'." so I believe the developers are aware of it."
    – Gabriele
    Feb 4 at 10:06
  • Not sure, but I guess that when using AUCTeX, probably always one of those modes is active. I have quickly tried to confirm it from looking at the code of TeX-set-mode-name, and although it looks like it's the case, I am not sure. What I do find, is that AUCTeX uses the variable TeX-mode-p. So I guess that variable is non-nil when AUCTeX is active, and nil when it is not (but, I'm not sure about it). Despite their comment, I don't see, if things work fine, why AUCTeX should be a different mode, as one can use only a single major-mode at a time. Good documentation is important though. Feb 4 at 22:43

You can try to run advice-member-p and test for the advice on latex-mode:

advice-member-p is a native-compiled Lisp function in ‘nadvice.el’.

(advice-member-p ADVICE SYMBOL)

Return non-nil if ADVICE has been added to SYMBOL. Instead of ADVICE being the actual function, it can also be the ‘name’ of the piece of advice.

So something like this should return non-nil when AUCTeX is activated:

(advice-member-p #'TeX-latex-mode #'latex-mode)
  • I tried your code but I get nil in both cases,
    – Gabriele
    Feb 8 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.