Subject: bug#41559: texmathp reports false negatives

From: TEC <[email-masked]>
Date: Wed, 27 May 2020 13:25:09 +0800

Hello!

Org-mode recently added support for editing LaTeX fragments in the 
minibuffer (https://code.orgmode.org/bzg/org-mode/commit/f5c47d8). 
While I have previously noticed occasions where (texmathp) has 
failed to pick up math mode from LaTeX inline deliminators (by 
which I mean \(\) and \[\]), with this it's become increacingly 
apparent to me. Perhaps there are issues caused by not having a 
full LaTeX file with \begin{document} etc., but this doesn't seem 
to be an issue with 'old' TeX deliminators ($…$ and $$…$$).

Consider the following examples

#+BEGIN_EXPORT latex \(a\) #+END_EXPORT

and

#+BEGIN_EXPORT latex \[
    a
\] #+END_EXPORT

In both cases (texmathp) returns nil. However if I replace these 
LaTeX deliminators with their TeX counterparts, (texmathp) rteurns 
t, correctly.

When using say CDLaTeX it automatically inserts deliminators if 
(texmathp) returns nil, this is obviously problematic, as it 
causes 'nesting' of deliminators, I.e. \(\(\alpha\)\).

Interestingly, once a level of nesting has been performed, 
(texmathp) returns t.

I hope that someone may be willing to tweak texmathp and have it 
produce correct results in these cases.

Regards,

Timothy.