unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Fontifying latex.ltx
@ 2011-01-17  0:06 Harald Hanche-Olsen
  2011-01-18  4:12 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Harald Hanche-Olsen @ 2011-01-17  0:06 UTC (permalink / raw)
  To: help-gnu-emacs

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{...,
   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.)
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).

After a bit of experimentation I managed to cure #1 by doing this:

(defadvice tex-common-initialization (after nopropertize activate)
  (when (string= (file-name-nondirectory (buffer-file-name)) "latex.ltx")
    (setq syntax-propertize-function nil)))

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

(font-lock-syntactic-face-function . tex-font-lock-syntactic-face-function)

from font-lock-defaults has the slightest effect.

Maybe my approach to this is wrong. Any suggestions?

Followups set to gnu.emacs.help.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Fontifying latex.ltx
  2011-01-17  0:06 Fontifying latex.ltx Harald Hanche-Olsen
@ 2011-01-18  4:12 ` Stefan Monnier
  2011-01-18  7:33   ` Ilya Zakharevich
  2011-01-18 19:38   ` Harald Hanche-Olsen
  0 siblings, 2 replies; 4+ messages in thread
From: Stefan Monnier @ 2011-01-18  4:12 UTC (permalink / raw)
  To: help-gnu-emacs

> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Fontifying latex.ltx
  2011-01-18  4:12 ` Stefan Monnier
@ 2011-01-18  7:33   ` Ilya Zakharevich
  2011-01-18 19:38   ` Harald Hanche-Olsen
  1 sibling, 0 replies; 4+ messages in thread
From: Ilya Zakharevich @ 2011-01-18  7:33 UTC (permalink / raw)
  To: help-gnu-emacs

On 2011-01-18, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> 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.

The user was using defadvice anyway.  Could one allow EASIER modification of
LaTeX font-lock structures on the fly, like disabling \verbC...C in
certain files?

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

Since latex.ltx is NOT written in LaTeX... ;-)

Ilya


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Fontifying latex.ltx
  2011-01-18  4:12 ` Stefan Monnier
  2011-01-18  7:33   ` Ilya Zakharevich
@ 2011-01-18 19:38   ` Harald Hanche-Olsen
  1 sibling, 0 replies; 4+ messages in thread
From: Harald Hanche-Olsen @ 2011-01-18 19:38 UTC (permalink / raw)
  To: help-gnu-emacs

[Stefan Monnier <monnier@iro.umontreal.ca>]

>> 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 %{

Except for the pain of modifying code that isn't mine and that will
change back on the next software update, I could.

> I've just fixed the code in Emacs's trunk so we only highlight \verb+..+
> if it spans a single line.

Great. Since I do track the trunk, I'll soon have it.

> [...] whereas "odd" LaTeX structures
> are used even by normal LaTeX users (tho \def\verb arguably is not).

Yeah, it doesn't happen to me very often in my everyday LaTeX usage,
and when it does, I can usually work around it using a well placed
comment. I am used to that. But still, it might be nice perhaps to have
a pair of special comments I could put in LaTeX code, that would have
the side effect of turning off fontification in between.

> [...] (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.

That did it. Thanks!

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-01-18 19:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-17  0:06 Fontifying latex.ltx Harald Hanche-Olsen
2011-01-18  4:12 ` Stefan Monnier
2011-01-18  7:33   ` Ilya Zakharevich
2011-01-18 19:38   ` Harald Hanche-Olsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).