* The org--math-p advice around texmathp
@ 2024-03-09 19:41 Tony Zorman
2024-03-13 12:58 ` Ihor Radchenko
0 siblings, 1 reply; 7+ messages in thread
From: Tony Zorman @ 2024-03-09 19:41 UTC (permalink / raw)
To: emacs-orgmode
Hi,
I recently stumbled upon the fact that Org has some around advice for
texmathp: org--math-p. For reasons that aren't entirely clear to me,
this has some special handling for cdlatex-math-symbol, and recognises
display and inline maths environments on its own, only calling out to
texmathp if it could not find anything. In the former cases, it also
populates the texmathp-why variable, although the position is just
filled in with 0.
I suppose my succinct question is: why? Is there any advantage in
handling inline and display maths in this way, only deferring to
texmathp as a last resort? I'm asking because I wrote a small package to
switch between environments, and the position information that
texmathp-why provides is very useful in choosing the closest
environment.
Thanks!
Tony
--
Tony Zorman | https://tony-zorman.com/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: The org--math-p advice around texmathp
2024-03-09 19:41 The org--math-p advice around texmathp Tony Zorman
@ 2024-03-13 12:58 ` Ihor Radchenko
2024-03-14 16:15 ` Tony Zorman
0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2024-03-13 12:58 UTC (permalink / raw)
To: Tony Zorman; +Cc: emacs-orgmode
Tony Zorman <tony.zorman@tu-dresden.de> writes:
> I recently stumbled upon the fact that Org has some around advice for
> texmathp: org--math-p. For reasons that aren't entirely clear to me,
> this has some special handling for cdlatex-math-symbol, and recognises
> display and inline maths environments on its own, only calling out to
> texmathp if it could not find anything. In the former cases, it also
> populates the texmathp-why variable, although the position is just
> filled in with 0.
>
> I suppose my succinct question is: why? Is there any advantage in
> handling inline and display maths in this way, only deferring to
> texmathp as a last resort? I'm asking because I wrote a small package to
> switch between environments, and the position information that
> texmathp-why provides is very useful in choosing the closest
> environment.
Because Org mode syntax is not LaTeX and `texmathp' assumes that we are inside
LaTeX buffer. So, we first check using Org syntax whether the point is
inside latex fragment in Org sense.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: The org--math-p advice around texmathp
2024-03-13 12:58 ` Ihor Radchenko
@ 2024-03-14 16:15 ` Tony Zorman
2024-03-15 14:14 ` Ihor Radchenko
0 siblings, 1 reply; 7+ messages in thread
From: Tony Zorman @ 2024-03-14 16:15 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
On Wed, Mar 13 2024 12:58, Ihor Radchenko wrote:
> Tony Zorman <tony.zorman@tu-dresden.de> writes:
>
>> I recently stumbled upon the fact that Org has some around advice for
>> texmathp: org--math-p. For reasons that aren't entirely clear to me,
>> this has some special handling for cdlatex-math-symbol, and recognises
>> display and inline maths environments on its own, only calling out to
>> texmathp if it could not find anything. In the former cases, it also
>> populates the texmathp-why variable, although the position is just
>> filled in with 0.
>>
>> I suppose my succinct question is: why? Is there any advantage in
>> handling inline and display maths in this way, only deferring to
>> texmathp as a last resort? I'm asking because I wrote a small package to
>> switch between environments, and the position information that
>> texmathp-why provides is very useful in choosing the closest
>> environment.
>
> Because Org mode syntax is not LaTeX and `texmathp' assumes that we are inside
> LaTeX buffer. So, we first check using Org syntax whether the point is
> inside latex fragment in Org sense.
But isn't what Org calls LaTeX math pretty equivalent to what would
count as the same in a LaTeX buffer? From a quick scan of texmathp.el, I
couldn't actually see a hard-dependency on a TeX-derived mode at all. I
wouldn't really care about this so much, but the fact that the Org
variant just misreports the position is a bit unfortunate, in my
opinion.
Tony
--
Tony Zorman | https://tony-zorman.com/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: The org--math-p advice around texmathp
2024-03-14 16:15 ` Tony Zorman
@ 2024-03-15 14:14 ` Ihor Radchenko
2024-03-15 20:41 ` Tony Zorman
0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2024-03-15 14:14 UTC (permalink / raw)
To: Tony Zorman; +Cc: emacs-orgmode
Tony Zorman <tony.zorman@tu-dresden.de> writes:
>> Because Org mode syntax is not LaTeX and `texmathp' assumes that we are inside
>> LaTeX buffer. So, we first check using Org syntax whether the point is
>> inside latex fragment in Org sense.
>
> But isn't what Org calls LaTeX math pretty equivalent to what would
> count as the same in a LaTeX buffer? From a quick scan of texmathp.el, I
> couldn't actually see a hard-dependency on a TeX-derived mode at all. I
> wouldn't really care about this so much, but the fact that the Org
> variant just misreports the position is a bit unfortunate, in my
> opinion.
No, there is a difference.
For example, something like \alpha is a valid Org mode entity.
Without `org--math-p' advice, if you do "`a" in Org buffer with
org-cdlatex-mode, you will see $\alpha$ inserted. With the advice, just
\alpha will be inserted.
There are likely other similar edge cases.
We would not choose to advice third-party function without a strong
reason.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: The org--math-p advice around texmathp
2024-03-15 14:14 ` Ihor Radchenko
@ 2024-03-15 20:41 ` Tony Zorman
2024-03-16 10:07 ` Ihor Radchenko
0 siblings, 1 reply; 7+ messages in thread
From: Tony Zorman @ 2024-03-15 20:41 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
On Fri, Mar 15 2024 14:14, Ihor Radchenko wrote:
> Tony Zorman <tony.zorman@tu-dresden.de> writes:
>
>>> Because Org mode syntax is not LaTeX and `texmathp' assumes that we are inside
>>> LaTeX buffer. So, we first check using Org syntax whether the point is
>>> inside latex fragment in Org sense.
>>
>> But isn't what Org calls LaTeX math pretty equivalent to what would
>> count as the same in a LaTeX buffer? From a quick scan of texmathp.el, I
>> couldn't actually see a hard-dependency on a TeX-derived mode at all. I
>> wouldn't really care about this so much, but the fact that the Org
>> variant just misreports the position is a bit unfortunate, in my
>> opinion.
>
> No, there is a difference.
>
> For example, something like \alpha is a valid Org mode entity.
> Without `org--math-p' advice, if you do "`a" in Org buffer with
> org-cdlatex-mode, you will see $\alpha$ inserted. With the advice, just
> \alpha will be inserted.
>
> There are likely other similar edge cases.
>
> We would not choose to advice third-party function without a strong
> reason.
I believe you, but apparently I still haven't really understood the
point of the advice.
For example, I would think it's expected behaviour that "`a" in a string
produces "\(\alpha\)" with CDLaTeX; indeed, so far I thought it was just
a bug that it didn't! Likewise, that a standalone `a produces \alpha
instead of \(\alpha\). Why is this not expected behaviour in Org?
Tony
--
Tony Zorman | https://tony-zorman.com/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: The org--math-p advice around texmathp
2024-03-15 20:41 ` Tony Zorman
@ 2024-03-16 10:07 ` Ihor Radchenko
2024-03-16 12:23 ` Tony Zorman
0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2024-03-16 10:07 UTC (permalink / raw)
To: Tony Zorman; +Cc: emacs-orgmode
Tony Zorman <tony.zorman@tu-dresden.de> writes:
>> For example, something like \alpha is a valid Org mode entity.
>> Without `org--math-p' advice, if you do "`a" in Org buffer with
>> org-cdlatex-mode, you will see $\alpha$ inserted. With the advice, just
>> \alpha will be inserted.
> ...
>
> For example, I would think it's expected behaviour that "`a" in a string
> produces "\(\alpha\)" with CDLaTeX; indeed, so far I thought it was just
> a bug that it didn't! Likewise, that a standalone `a produces \alpha
> instead of \(\alpha\). Why is this not expected behaviour in Org?
In Org mode, there is a significant difference between \alpha and
\(\alpha\). The former is natively fontified (with `org-pretty-entities'
set to t) and natively exported to HTML/ASCII/ODT/etc. In contrast,
\(\alpha\) is very generic and Org mode has to invoke LaTeX, and
transform the contents into an image to render it. This includes export.
So, plain \alpha entity is generally more universal when in Org mode.
Further on the topic of the advice, the original texmathp has no idea
about Org-mode's syntax. If you have something like
Verbatim text: =\(= followed by \alpha \)
Then, (texmathp) will return non-nil on "\alpha" disregarding Org mode's
syntax.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: The org--math-p advice around texmathp
2024-03-16 10:07 ` Ihor Radchenko
@ 2024-03-16 12:23 ` Tony Zorman
0 siblings, 0 replies; 7+ messages in thread
From: Tony Zorman @ 2024-03-16 12:23 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
On Sat, Mar 16 2024 10:07, Ihor Radchenko wrote:
> In Org mode, there is a significant difference between \alpha and
> \(\alpha\). The former is natively fontified (with `org-pretty-entities'
> set to t) and natively exported to HTML/ASCII/ODT/etc. In contrast,
> \(\alpha\) is very generic and Org mode has to invoke LaTeX, and
> transform the contents into an image to render it. This includes export.
>
> So, plain \alpha entity is generally more universal when in Org mode.
That's fair enough, I didn't know about org-pretty-entities! I guess
for me org-cdlatex-mode was always something to insert *LaTeX* in Org,
and not arbitrary Unicode (especially since there's currently no check
in place that verifies whether the entered symbol can actually be
rendered correctly via org-pretty-entities and cdlatex-math-symbol can
insert arbitrary LaTeX code)
> Further on the topic of the advice, the original texmathp has no idea
> about Org-mode's syntax. If you have something like
>
> Verbatim text: =\(= followed by \alpha \)
>
> Then, (texmathp) will return non-nil on "\alpha" disregarding Org mode's
> syntax.
Ah indeed, this is a good point. I guess I would wish for more granular
advice, but I recognise the difficulty in getting this exactly right.
Thanks for your patience!
Tony
--
Tony Zorman | https://tony-zorman.com/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-03-16 12:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-09 19:41 The org--math-p advice around texmathp Tony Zorman
2024-03-13 12:58 ` Ihor Radchenko
2024-03-14 16:15 ` Tony Zorman
2024-03-15 14:14 ` Ihor Radchenko
2024-03-15 20:41 ` Tony Zorman
2024-03-16 10:07 ` Ihor Radchenko
2024-03-16 12:23 ` Tony Zorman
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).