emacs-pretest-bug
[Top][All Lists]
Advanced

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

Re: [tex-mode.el] Subscript in math not fully matched


From: Stefan Monnier
Subject: Re: [tex-mode.el] Subscript in math not fully matched
Date: Mon, 17 Apr 2006 00:10:09 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

>>>>> "Ralf" == Ralf Angeli <address@hidden> writes:

> An AUCTeX user reported that the last brace in the following
> expression is not being displayed as subscript by font-lock:

> $x_{\sqrt{\sqrt{2}}}$

> AUCTeX uses the same regular expression as tex-mode.el for matching
> these things, so this bug is present in Emacs as well.

> I am intending to fix this in AUCTeX by finding the end of the
> expression in braces by means of a function instead of a regexp, like
> this:

> (defun font-latex-match-script (limit)
>   "Match subscript and superscript patterns up to LIMIT."
>   (when (and font-latex-fontify-script
>            (re-search-forward
>             "[_^] *\\([^\n\\{}]\\|\\\\\\(address@hidden|[^ \t\n]\\)\\|{\\)"
>             limit t))
>     (when (string= (match-string 1) "{")

Better do (eq (char-after (match-beginning 1)) ?\{) so as to avoid consing
a string.  Alternatively, wrpa the "{" in the regexp inside "\\(...\\)" and
then just check if (match-end 2) is non-nil.
You could even make it more efficient by handling the "no-nesting" case
directly in the regexp (as is the case now) and only revert to the elisp
code for the more complex case.

>       (let ((beg1 (match-beginning 1))
>           (end (TeX-find-closing-brace)))
>       (if end
>           (store-match-data (list (match-beginning 0) end beg1 end))
>         (store-match-data (list beg1 beg1 beg1 beg1)))))
>     t))

Why not merge the two branches of the if:

        (store-match-data (if end
                              (list (match-beginning 0) end beg1 end))
                            (store-match-data (list beg1 beg1 beg1 beg1)))

> I guess I could come up with a similar fix for tex-mode.el if somebody
> is interested.

Please do,


        Stefan




reply via email to

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