auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: \documentclass does not activate latex-mode


From: jfbu
Subject: Re: \documentclass does not activate latex-mode
Date: Wed, 17 Aug 2022 09:25:14 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:91.0) Gecko/20100101 Thunderbird/91.12.0


Hi

Le 15/08/2022 à 14:41, Mandar Mitra a écrit :
jfbu wrote (Sun, Aug 14, 2022 at 06:14:12PM +0200):
I can not add any file local variable, the file is output
by some build.

You can't modify the build file that generates your .tex file? Something as 
simple as renaming haru.tex to haru.ltx might fix things for you.


I could modify some scripts which are put into the source directory of test 
projects and invoked to build, but I would have to repeat at each new feature 
testing directory
I would not modify my git clone of the upstream Makefile templates else I would 
risk committing and pushing accidentally

Some more questionable suggestions, while you wait for the experts to weigh in.

C-h v shows that I have the following entries in auto-mode-alist:

("\\.[tT]e[xX]\\'" . tex-mode)

("\\.ltx\\'" . latex-mode)


same here

Do you ever use plain-tex-mode at all?

yes I do routinely...

If not, or only very infrequently, you could see if

(add-to-list 'auto-mode-alist '("\\[tT]e[xX]\\'" . latex-mode))

in your .emacs or init.el helps.


not an option...


But IMHO, should'nt \documentclass by itself trigger latex-mode?
It is relatively frequent to have to put code before the
\documentclass.

According to the variable TeX-format-list at tex.el:3640, a file will have to start with 
\documentclass, or \begin, \section, \subsection, etc. for auctex to go into latex-mode. 
The last entry in the list is a catchall regexp "." that invokes plain-tex-mode.


I am not sure from "3. A regexp typically matched in the beginning of the file." of the 
docstring what "in the beginning of the file means".  But anyhow, what I could see with 
my  sample file

----
\def\foo{bar}
\documentclass{foobar}
\begin{document}
hello
\end{document}
----

is that it would trigger latex-mode if the first line was commented.

So I now tried with \newcommand\foo{bar} in place of \def\foo{bar} and then yes 
latex-mode is triggered which is good as some LaTeX constructs require 
macro-code before \documentclass.  Notice that \newcommand is the same apart 
from existence check (and construction of macro with one optional argument) as 
\long\def and one could imagine (convoluted) situations where you really want 
\def and not \long\def here.

I even remember that there might

Now, indeed this is problematic as the \def in first line could indicate the 
author is a TeX fanatic and the presence of \documentclass could simply be a 
mirage.

But, sincerely, if you have \documentclass at start of one the first 5 lines of 
your document, reasonable bets at 99,9% is that this a LaTeX2e document.

Now the \def in my use case is inserted there by the LaTeX templates of the 
build system I am using.  I could possible make a PR there to ask them (aka me 
for latex) to use \newcommand...

On further investigation already

\foo{bar}
\documentclass{foobar}

triggers tex-mode not latex-mode
it is not especially the \def token

Now if \foo is replaced by \RequirePackage or something latexian auctex 
accurately chooses latex mode.

with

----
\input{bar}
\documentclass{article}
\begin{document}
hello
\end{document}
----

latex-mode is **not** triggered.  But this is quite LaTeXian in spirit.

I would argue that \documentclass at start of anyone of the first 5 lines of a 
document should trigger latex-mode.

Jean-François

-mandar







reply via email to

[Prev in Thread] Current Thread [Next in Thread]