help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Fontifying latex.ltx


From: Stefan Monnier
Subject: Re: Fontifying latex.ltx
Date: Mon, 17 Jan 2011 23:12:00 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

> Whenever I visit latex.ltx, I encounter two rather annoying problems
> with the resulting fontification via font-lock-mode:

> 1. In the definition \def\verb{...,

Indeed, the \verbC...C fontification gets triggered incorrectly there.
Hmm...kind of a pain to try and detect such corner cases.
In the mean time you can circumvent the problem with %{

>    everything from there to the end of the buffer is fontified as if it
>    were the argument of \verb. (Sometimes only up to the next left curly
>    brace.)

Indeed, we have a plain bug here, it should *always* go only up to the
next opening {, but I see we don't refresh the data correctly.
I've just fixed the code in Emacs's trunk so we only highlight \verb+..+
if it spans a single line.

> 2. A bit later, a macro definition includes a single dollar sign:

>    \def\@argarraycr[#1]{%
>      \ifnum0=`{\fi}${}\ifdim #1>\z@ \@xargarraycr{#1}\else
>       \@yargarraycr{#1}\fi}

>    and so the rest of the file is fontified as math (in those cases
>    where #1 does not affect the rest of the file, or when I have
>    cured #1 by the method below).

Right, the $...$ highlighting is problematic.  You can work around it by
adding a %$, but it's not very satisfactory.

Overall handling LaTeX is a real nightmare, because there is no actual
structure: \begin and \end don't have to match up, and neither do
$...$.  They're just usually used in pairs.  Of course, you can mess up
c-mode similarly by playing around with macros like

#define LOTSOFFUN }

but luckily this is not done in practice, whereas "odd" LaTeX structures
are used even by normal LaTeX users (tho \def\verb arguably is not).

> To cure #2, I thought I would disable the fontification of math
> altogether in latex.ltx. But neither changing the character syntax of
> the dollar nor removing the pair

The char-syntax of $ used for normal LaTeX editing is different from the
syntax used internally by font-lock when highlighting LaTeX (see the
value of font-lock-defaults when in latex-mode), which is why your
change had no effect.  Instead, you'll want to replace ((?$ . "\""))
with nil.


        Stefan


reply via email to

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