auctex
[Top][All Lists]

## [AUCTeX] Problem with latex2e style hook --- LaTeX/Texinfo collision

 From: Vincent Belaïche Subject: [AUCTeX] Problem with latex2e style hook --- LaTeX/Texinfo collision Date: Thu, 14 Aug 2014 11:42:42 +0200

```Dear all,

I have found a problem with AUCTeX. Here is the observed problem: when I
edit a Texinfo file named latex2e.texi 'C-c C-f' does not provide
Texinfo-font-list but LaTeX-font-list. The problem happens only if
latex2e.texi is not the first file I am editing, but I have edited some
LaTeX file --- say foo.tex --- before that.

Note: latex2e.texi is the english version of unofficial LaTeX manual
maintained by Karl Berry and myself on GNA!  latexrefman project. I
don't think that we are going to change the filename --- everybody
should be free to name their files in the way they like!

The root of the problem is in AUCTeX latex.el as follows

-----------------------------------------------------------------------
;; Use new fonts for `\documentclass' documents.
(lambda ()
(setq TeX-font-list LaTeX-font-list)
(setq TeX-font-replace-function 'TeX-font-replace-macro)
(run-hooks 'LaTeX2e-hook)))
-----------------------------------------------------------------------

After editing foo.tex the LaTeX mode is invoked, which in turns evaluate
(LaTeX-common-initialization), which in turn adds the "latex2e" style
hook as above.

Now, after texinfo-mode invocation on latex2e.texi, TeX-font-list is
correctly pointing to Texinfo-font-list. But then, when 'C-c C-f' is
called, then (TeX-update-style) is evaluated, and then the The latex2e
style hook pushed to TeX-style-hook-list by prior editing of foo.tex is
run, which has the effect of evaluating (setq TeX-font-list
LaTeX-font-list): that is the problem.

A simple fix would be to do anything in the style hook conditionally to
some prior checks --- e.g. checking some (derived-mode-p 'LaTeX-mode)
sort of condition.

Well, I think that this would *NOT* be a good fix, because there may be
the same sort of issue popping up again and again with other style hooks
--- imagine some LaTeX package myfont.sty adding some font, with some
style hook pushing some shortcut to LaTeX-font-list and doing (setq
TeX-font-list LaTeX-font-list), and some Texinfo file named myfont.texi
with the same basename as the LaTeX package myfont.sty ...

There could be some radical solution like not using any longer
TeX-font-list, and XXXX-font-list for each TeX dialect, but having some
TeX-dialect buffer-local variable pointing as some eieio object with
some slot being the font list, and some other slots for each of other
dialect specific things --- e.g. style hook list ... So TeX-font
function (aka 'C-c C-f') would now evaluate (oref TeX-dialect
:font-list) rather than TeX-font-list. In a same way one would use (oref
TeX-dialect :style-hook-list) instead of TeX-style-hook-list. So in each
XXXX-mode, where XXXX is a dialect (like LaTeX, Texinfo, etc...) you
would just set locally to buffer TeX-dialect to some XXX-dialect eieo
object with the dialect specific data.

That would be clean and futureproof, there would be a unique switch
point (the TeX-dialect variable) but I am not sure that people will like
it for all the impact on what we already have.

I think however that the above solution is sort of similar to what
c-mode does to accomodate all c dialects (c++, awk, ...), but I am not
sure of that, anyway it has some value in my view.

So, I thought a little bit, and I am coming with another solution
attached to this email as file <auctex-texinfo-style-hooks.diff>. That
amounts to marking each hook with a context symbol and runing the hook
function only conditionally to the context being active. It is
implemented in a way that all LaTeX specific existing code (notably
style hooks and user init files I think) can remain unchanged, only
Texinfo specific stuff may need some context-marking.

Sorry for that, but I could not retain myself for doing other changes
--- beautifying and optimizing a few things --- attached to this email
as <auctex-optimizations.diff>.

auctex-optimizations.diff patch isn't related with the latex2e style hook
problem, so I did it as a first change as I naively think that it should
not be contentious, and then auctex-texinfo-style-hooks.diff is a second
patch over that first one.

Thank you for your attention to this lengthy email.

Vincent.

```

auctex-optimizations.diff
Description: Binary data

auctex-texinfo-style-hooks.diff
Description: Binary data