Hi Gabriele,
>>>>> Gabriele Nicolardi via bug-auctex via Bug reporting list for AUCTeX
>>>>> <[email protected]> writes:
> texmathp misreports math mode when a math-opening "$" is immediately
> preceded by "\\" (a TeX line break). This is valid LaTeX and common in
> tabular/array cells and multi-line TikZ node labels.
> Tested against current git master (texmathp.el, copyright 1998-2024).
> How to reproduce (emacs -Q, AUCTeX loaded):
> Put point on the "b" of the second math group and run M-x texmathp.
> \begin{tabular}{c}$a$\\$b$\end{tabular}
> ^ point here
> Expected: math-mode is on (point is inside $...$).
> Actual: texmathp returns nil ("math-mode is off").
> Minimal trigger: in a buffer containing $a$\\$b$ , point on "b"
> returns nil. The first group $a$ is detected correctly; everything
> after the "\\$" has inverted parity.
> Root cause:
> texmathp counts unescaped "$" toggles via `texmathp-toggle-regexp',
> built in `texmathp-compile' as
> (concat "\\([^\\$]\\|\\`\\)" (regexp-opt togglers t))
> The "[^\\$]" prefix is meant to skip an escaped dollar "\$", by
> requiring the char before a counted "$" to be neither "\" nor "$".
> But it also rejects a *genuine* math "$" that follows "\\": in
> "$a$\\$b$" the opening "$" of the second group is preceded by the
> second backslash of "\\", so it is never counted. The dollar parity
> is then wrong for the rest of the paragraph, and texmathp returns the
> inverted result on alternating math groups.
I agree with your analysis.
> The correct rule is backslash *parity*: a "$" is a real toggle iff it
> is preceded by an even number of backslashes ("\$" = literal, skip;
> "\\$" = line break + math open, count).
I basically agree with this analysis as well.
> Proposed fix (texmathp-compile):
> - (concat "\\([^\\$]\\|\\`\\)"
> + (concat
> "\\(\\(?:\\(?:[^\\$]\\|\\`\\)\\(?:\\\\\\\\\\)*\\)\\|\\(?:\\\\\\\\\\)+\\)"
> (regexp-opt togglers t))
However, this proposal leads to false positive for a dollar sign
following 3 (or more) consecutive backslashes; M-x texmathp says
"math-mode is on" at the end the following line:
\\\$
Could you further tune the regexp?
In addition, we have to take another perspetive into consideration;
`texmathp` is used in font-lock machinery in AUCTeX, thus every
non-trivial edition in the buffer calls `texmathp` to compute correct
syntax hilighting. For this reason, `texmathp` must be lightweight
enough not to interrupt the user editing process. If the regular
expression is too complex and it slows down `texmathp` siginificantly,
it wouldn't be a good idea to implement it into `texmathp-compile`.
(However, I'm optimistic about this aspect. I suppose we can find regexp
simple enough.)
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopGenocide #CeasefireNOW
#IProtestAgainstTrumpAndNetanyahu'sAttackOnIran,WhichViolatesInternationalLaw
_______________________________________________
bug-auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-auctex