* MathML and ODT export: inline possible?
@ 2024-04-18 12:14 Fraga, Eric
2024-04-18 14:44 ` Max Nikulin
2024-04-18 15:38 ` Leo Butler
0 siblings, 2 replies; 10+ messages in thread
From: Fraga, Eric @ 2024-04-18 12:14 UTC (permalink / raw)
To: Emacs Org mode mailing list
Hello all,
I am having (for my sins) to write some Word documents. I don't even
have Word on my system but that's by the by. The documents have some
mathematical expressions. In the past, I have used LaTeX to create
images of these expressions (and hence my earlier post today). But I'm
told this is no longer good enough. Sigh.
So I've started playing with MathML and ODT export. This is actually
working quite nicely although writing equations in MathML is ponderous
[1].
The question I have is: can I replace the link to a Math ML file (which
does work, as noted in the org info manual) with the actual Math ML code
inline within the org file? If so, how? I would rather not have
separate files lying around.
Thank you,
eric
Footnotes:
[1] exporting LaTeX fragments directly, via latexmlmath, does not
actually work very well at all. The text passed by org is wrong
basically. And latexmlmath gets easily confused, it seems. I'd
rather work with the MathML directly in the end.
--
: Eric S Fraga, with org release_9.6.23-1320-g1be2f9 in Emacs 30.0.50
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MathML and ODT export: inline possible?
2024-04-18 12:14 MathML and ODT export: inline possible? Fraga, Eric
@ 2024-04-18 14:44 ` Max Nikulin
2024-04-18 15:03 ` Fraga, Eric
2024-04-18 15:38 ` Leo Butler
1 sibling, 1 reply; 10+ messages in thread
From: Max Nikulin @ 2024-04-18 14:44 UTC (permalink / raw)
To: emacs-orgmode
On 18/04/2024 19:14, Fraga, Eric wrote:
>
> The question I have is: can I replace the link to a Math ML file (which
> does work, as noted in the org info manual) with the actual Math ML code
> inline within the org file?
#+begin_export odt
...
#+end_export
> [1] exporting LaTeX fragments directly, via latexmlmath, does not
> actually work very well at all. The text passed by org is wrong
> basically. And latexmlmath gets easily confused, it seems. I'd
> rather work with the MathML directly in the end.
Manual on the web site is incorrect. Do not use single or double quotes
around %i if you are on the main branch. On bugfix it is necessary to
use an alternative command with %I.
However LaTeXML has issues with latex3
Max Nikulin… Re: Warn about shell-expansion in the docstring of
org-latex-to-html-convert-command. Tue, 5 Mar 2024 19:01:16 +0700.
https://list.orgmode.org/dfdb0777-2741-410a-ac8a-8593af357abc@gmail.com
Have you tried pandoc?
(setq org-latex-to-mathml-convert-command
"pandoc -f latex -t html5 --mathml %I -o %o")
David Lukeš. Using pandoc to convert LaTeX math to MathML. Tue, 1 Mar
2022 15:59:36 +0100.
https://list.orgmode.org/CAEPTPEzvx5ZhY5qrCJnFtAC_NpPC9d1a-Q=yE+XNTrPXiMpTag@mail.gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MathML and ODT export: inline possible?
2024-04-18 14:44 ` Max Nikulin
@ 2024-04-18 15:03 ` Fraga, Eric
2024-04-18 15:05 ` Max Nikulin
0 siblings, 1 reply; 10+ messages in thread
From: Fraga, Eric @ 2024-04-18 15:03 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode@gnu.org
Hi Max,
On Thursday, 18 Apr 2024 at 21:44, Max Nikulin wrote:
> #+begin_export odt
> ...
> #+end_export
I thought I had tried that but must have done something different/wrong.
This works beautifully, once I figured out I had to wrap the
<math>...</math> within a <draw:object>.
Many thanks,
eric
PS - also thanks for details on latexmlmath.
--
: Eric S Fraga, with org release_9.6.23-1320-g1be2f9 in Emacs 30.0.50
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MathML and ODT export: inline possible?
2024-04-18 15:03 ` Fraga, Eric
@ 2024-04-18 15:05 ` Max Nikulin
2024-04-18 15:51 ` Fraga, Eric
0 siblings, 1 reply; 10+ messages in thread
From: Max Nikulin @ 2024-04-18 15:05 UTC (permalink / raw)
To: emacs-orgmode
On 18/04/2024 22:03, Fraga, Eric wrote:
> PS - also thanks for details on latexmlmath.
I am still curious if pandoc can handle your math expressions.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MathML and ODT export: inline possible?
2024-04-18 12:14 MathML and ODT export: inline possible? Fraga, Eric
2024-04-18 14:44 ` Max Nikulin
@ 2024-04-18 15:38 ` Leo Butler
2024-04-18 16:01 ` Fraga, Eric
1 sibling, 1 reply; 10+ messages in thread
From: Leo Butler @ 2024-04-18 15:38 UTC (permalink / raw)
To: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 1794 bytes --]
On Thu, Apr 18 2024, "Fraga, Eric" <e.fraga@ucl.ac.uk> wrote:
> Hello all,
>
> I am having (for my sins) to write some Word documents. I don't even
> have Word on my system but that's by the by. The documents have some
> mathematical expressions. In the past, I have used LaTeX to create
> images of these expressions (and hence my earlier post today). But I'm
> told this is no longer good enough. Sigh.
>
> So I've started playing with MathML and ODT export. This is actually
> working quite nicely although writing equations in MathML is ponderous
> [1].
>
> The question I have is: can I replace the link to a Math ML file (which
> does work, as noted in the org info manual) with the actual Math ML code
> inline within the org file? If so, how? I would rather not have
> separate files lying around.
>
> Thank you,
> eric
>
> Footnotes:
> [1] exporting LaTeX fragments directly, via latexmlmath, does not
> actually work very well at all. The text passed by org is wrong
> basically. And latexmlmath gets easily confused, it seems. I'd
> rather work with the MathML directly in the end.
Eric,
I think there is a bug in the way the exporter handles odt fragments.
Explanation: Maxima can print output in mathml. Your question inspired
me to try to craft an example. I came up with the attached org file.
The first two subsections of it exports fine to html (replace "export
odt" with "export html"). But when I export to odt, something weird
happens: contents.xml contains the fragment of mathml, but it is not
displayed in libreoffice. On the other hand, the snippet in the third
sub-section, that is saved to file, is handled correctly (the somewhat
mangled formatting is a bug in Maxima's mathml printer).
Leo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mathml.org --]
[-- Type: text/org; name="mathml.org", Size: 4080 bytes --]
#+TITLE: Demo of mathml and maxima
* An example
** Set up of the printer
If you have version =5.46+= of Maxima, this Maxima code can be used.
#+name: startup
#+begin_src maxima :tangle ./startup.mac :exports code :results none
(load("alt-display"),
set_alt_display(1,lambda([x],false)),
set_alt_display(2,mathml_display),
display2d:true, linenum:0);
#+end_src
Otherwise, for older versions, this Lisp-ified Maxima code can be used.
#+begin_src maxima :tangle ./startup.lisp :exports code :results none :noweb yes
#$
<<startup>>
#$
#+end_src
The code loads the =alt-display= package.
It sets the 1d printer to print nothing, so input is not echoed; it sets the 2d printer to use the =mathml_display= function, which is provided by =alt-display=.
** A simple example
The code block
#+name: example.org
#+begin_src org :exports code :results replace
,#+name: example.mac
,#+header: :exports both
,#+header: :results raw
,#+header: :wrap "export odt"
,#+header: :batch batch
,#+header: :cmdline --no-init --very-quiet --preload ./startup.lisp
,#+begin_src maxima
genmatrix(lambda([i,j], random(100)/random(100)), 4,4);
,#+end_src
#+end_src
#+RESULTS: example.org
#+name: example.mac
#+header: :exports both
#+header: :results raw
#+header: :wrap "export odt"
#+header: :batch batch
#+header: :cmdline --no-init --very-quiet --preload ./startup.lisp
#+begin_src maxima
genmatrix(lambda([i,j], random(100)/random(100)), 4,4);
#+end_src
produces the following output:
#+RESULTS: example.mac
#+begin_export odt
<math xmlns="http://www.w3.org/1998/Math/MathML"> <mi>mlabel</mi>
<mfenced separators=""><msub><mi>%o</mi> <mn>1</mn></msub> <mo>,</mo>
<mfenced separators="" open="(" close=")"><mtable><mtr><mtd><mn>6</mn>
</mtd><mtd><mfrac><mrow><mn>2</mn> </mrow> <mrow><mn>5</mn> </mrow></mfrac>
</mtd><mtd><mfrac><mrow><mn>4</mn> </mrow> <mrow><mn>91</mn> </mrow></mfrac>
</mtd><mtd><mfrac><mrow><mn>29</mn> </mrow> <mrow><mn>85</mn>
</mrow></mfrac> </mtd></mtr> <mtr><mtd><mfrac><mrow><mn>98</mn>
</mrow> <mrow><mn>3</mn> </mrow></mfrac> </mtd><mtd><mfrac><mrow><mn>7</mn>
</mrow> <mrow><mn>13</mn> </mrow></mfrac> </mtd><mtd><mfrac><mrow>
<mn>20</mn> </mrow> <mrow><mn>13</mn> </mrow></mfrac> </mtd><mtd>
<mfrac><mrow><mn>39</mn> </mrow> <mrow><mn>20</mn> </mrow></mfrac>
</mtd></mtr> <mtr><mtd><mfrac><mrow><mn>19</mn> </mrow> <mrow><mn>4</mn>
</mrow></mfrac> </mtd><mtd><mfrac><mrow><mn>97</mn> </mrow> <mrow><mn>6</mn>
</mrow></mfrac> </mtd><mtd><mn>1</mn> </mtd><mtd><mfrac><mrow><mn>43</mn>
</mrow> <mrow><mn>39</mn> </mrow></mfrac> </mtd></mtr> <mtr><mtd>
<mfrac><mrow><mn>23</mn> </mrow> <mrow><mn>13</mn> </mrow></mfrac>
</mtd><mtd><mfrac><mrow><mn>36</mn> </mrow> <mrow><mn>53</mn>
</mrow></mfrac> </mtd><mtd><mfrac><mrow><mn>60</mn> </mrow> <mrow>
<mn>71</mn> </mrow></mfrac> </mtd><mtd><mfrac><mrow><mn>4</mn> </mrow> <mrow>
<mn>3</mn> </mrow></mfrac> </mtd></mtr> </mtable></mfenced> </mfenced> </math>
#+end_export
A small amount of hand-editing will give something better.
** A re-think
The code seems correct, so let's save the results of the code block to file and use the exporter to correctly handle it.
#+name: rethink.org
#+begin_src org :exports code :results replace
,#+name: rethink.mac
,#+header: :exports both
,#+header: :results file
,#+header: :file ./snippet.mml
,#+header: :batch batch
,#+header: :cmdline --no-init --very-quiet --preload ./startup.lisp
,#+begin_src maxima
genmatrix(lambda([i,j], random(100)/random(100)), 4,4);
,#+end_src
#+end_src
#+RESULTS: rethink.org
#+name: rethink.mac
#+header: :exports both
#+header: :results file
#+header: :file ./snippet.mml
#+header: :batch batch
#+header: :cmdline --no-init --very-quiet --preload ./startup.lisp
#+begin_src maxima
genmatrix(lambda([i,j], random(100)/random(100)), 4,4);
#+end_src
produces the following output:
#+RESULTS: rethink.mac
[[file:./snippet.mml]]
[-- Attachment #3: mathml.odt --]
[-- Type: application/vnd.oasis.opendocument.text, Size: 12708 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MathML and ODT export: inline possible?
2024-04-18 15:05 ` Max Nikulin
@ 2024-04-18 15:51 ` Fraga, Eric
2024-04-19 16:19 ` Max Nikulin
0 siblings, 1 reply; 10+ messages in thread
From: Fraga, Eric @ 2024-04-18 15:51 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode@gnu.org
Hi Max,
On Thursday, 18 Apr 2024 at 22:05, Max Nikulin wrote:
> I am still curious if pandoc can handle your math expressions.
The short answer: not quite but definitely much better than latexmlmath.
The longer answer: my equation has a number of terms with subscripts
where the subscripts themselves have subscripts. In LaTeX, something
like $a_{b_c}$. Pandoc generates
<msub> a <msub> b c </msub></msub>
(where the a, b, and c are <mi>...</mi>) whereas, by hand, I use
<msub> a <mrow><msub> b c </msub></mrow></msub>
which has a more "LaTeX" protected feel.
The latter works but the former (pandoc) does show properly for most of
the terms but not all of them (showing a red upside down question mark
instead of the subscripted subscript). Yet all these terms have the
same structure in MML.
Pandoc also wraps the inner contents of the <math>...</math> block in
<semantics>. I do not know what that does as I've only just started
learning mathml.
Thanks again for all the help today. I may actually meet my deadline...
eric
PS. my remaining task, were I to use EXPORT ODT blocks, is figuring out
how to style (typeface, size, etc.) the equation properly, something
which the link approach does magically (well, seems like magic to me at
the moment ;-)). But that can wait for after my deadline!
--
: Eric S Fraga, with org release_9.6.23-1320-g1be2f9 in Emacs 30.0.50
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MathML and ODT export: inline possible?
2024-04-18 15:38 ` Leo Butler
@ 2024-04-18 16:01 ` Fraga, Eric
0 siblings, 0 replies; 10+ messages in thread
From: Fraga, Eric @ 2024-04-18 16:01 UTC (permalink / raw)
To: Leo Butler; +Cc: Org Mode List
On Thursday, 18 Apr 2024 at 15:38, Leo Butler wrote:
> Eric,
> I think there is a bug in the way the exporter handles odt fragments.
>
> Explanation: Maxima can print output in mathml.
Oh, this is actually excellent news! I use maxima all the time...
> But when I export to odt, something weird happens: contents.xml
> contains the fragment of mathml, but it is not displayed in
> libreoffice.
Yes, I found this. I had to wrap the <math> block within the following
ODT to get anything to display:
--8<---------------cut here---------------start------------->8---
<text:p text:style-name="Text_20_body">
<draw:frame draw:style-name="OrgCaptionedFormula" text:anchor-type="paragraph" draw:name="Frame1">
<draw:object>
MathML goes here
</draw:object>
</draw:frame>
</text:p>
--8<---------------cut here---------------end--------------->8---
although the styling is weird currently. I've not yet played with the
style name etc. but I needed all three aspects: paragraph, frame, and
object to get the equation to appear.
> On the other hand, the snippet in the third sub-section, that is saved
> to file,
Yes, the exporter seems to wrap the MML with the types of lines I've
shown above.
I will play with maxima (tomorrow, I think).
Thank you,
eric
--
: Eric S Fraga, with org release_9.6.23-1320-g1be2f9 in Emacs 30.0.50
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MathML and ODT export: inline possible?
2024-04-18 15:51 ` Fraga, Eric
@ 2024-04-19 16:19 ` Max Nikulin
2024-04-22 9:05 ` Fraga, Eric
0 siblings, 1 reply; 10+ messages in thread
From: Max Nikulin @ 2024-04-19 16:19 UTC (permalink / raw)
To: emacs-orgmode
On 18/04/2024 22:51, Fraga, Eric wrote:
> In LaTeX, something like $a_{b_c}$. Pandoc generates
>
> <msub> a <msub> b c </msub></msub>
>
> (where the a, b, and c are <mi>...</mi>) whereas, by hand, I use
>
> <msub> a <mrow><msub> b c </msub></mrow></msub>
MathJax may be your friend. LaTeXML and katex do not add <mrow> as well.
Actually I asked to confirm that your troubles are not with proper
escaping of input to a converter.
I have not used katex before, I just noticed it in
Martin Edström. Re: Warn about shell-expansion in the docstring of
org-latex-to-html-convert-command. Wed, 21 Feb 2024 15:57:47 +0100.
https://list.orgmode.org/CADojovJHoC5ZZATF1y7Uw2dEqNdhMDp5Ka8mgzujHUfkgTeE4Q@mail.gmail.com
During my quick try of LaTeXML I learned that "--preload=siunitx.sty"
should not be used with fresh TeXLive despite it is recommended in the
`org-latex-to-html-convert-command' docstring.
> Pandoc also wraps the inner contents of the <math>...</math> block in
> <semantics>. I do not know what that does as I've only just started
> learning mathml.
I have seen <semantics> as well, but I did not go deeper. I recall the
following in the context of screen readers:
T.V Raman. Re: Org mode export accessibility. Sat, 09 Jul 2022 06:20:27
-0700.
https:list.orgmode.org/p91czeeo21w.fsf@google.com
> MathJax is a wonderful thing and the LaTeX expression embedded in the
> HTML is the best one can do -- MathML loses semantics -- which is why I
> always recommend preserving the LaTeX when going to HTML.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MathML and ODT export: inline possible?
2024-04-19 16:19 ` Max Nikulin
@ 2024-04-22 9:05 ` Fraga, Eric
2024-04-22 10:57 ` Max Nikulin
0 siblings, 1 reply; 10+ messages in thread
From: Fraga, Eric @ 2024-04-22 9:05 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode@gnu.org
On Friday, 19 Apr 2024 at 23:19, Max Nikulin wrote:
> MathJax may be your friend. LaTeXML and katex do not add <mrow> as well.
MathJax works well but for websites; my context is that I need to
prepare a Word document to share with others.
> Actually I asked to confirm that your troubles are not with proper
> escaping of input to a converter.
I don't think so but cannot be sure.
Anyway, with the explicit .mml file, everything is good. Thanks for
your help.
eric
--
: Eric S Fraga, with org release_9.6.19-1230-g407a55 in Emacs 30.0.50
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MathML and ODT export: inline possible?
2024-04-22 9:05 ` Fraga, Eric
@ 2024-04-22 10:57 ` Max Nikulin
0 siblings, 0 replies; 10+ messages in thread
From: Max Nikulin @ 2024-04-22 10:57 UTC (permalink / raw)
To: emacs-orgmode
On 22/04/2024 16:05, Fraga, Eric wrote:
> On Friday, 19 Apr 2024 at 23:19, Max Nikulin wrote:
>> MathJax may be your friend. LaTeXML and katex do not add <mrow> as well.
>
> MathJax works well but for websites; my context is that I need to
> prepare a Word document to share with others.
I have not tried it, but I suggested MathJax expecting that the
following features may be combined in a small custom CLI tool:
- MathML,
- Server-side rendering.
Concerning pandoc, perhaps it is possible to create a Lua filter to
handle some specific cases. Again, I have seen some buzzwords in docs
and discussions, but I have not tried it myself.
Certainly my expectations in respect to LaTeXML failed. I believed that
a tool used for https://dlmf.nist.gov/ should be close to perfect. The
reason might be that it is tested with browsers, but not with office
software. LaTeX3 code appeared to be a severe performance test for engines.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-04-22 10:58 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-18 12:14 MathML and ODT export: inline possible? Fraga, Eric
2024-04-18 14:44 ` Max Nikulin
2024-04-18 15:03 ` Fraga, Eric
2024-04-18 15:05 ` Max Nikulin
2024-04-18 15:51 ` Fraga, Eric
2024-04-19 16:19 ` Max Nikulin
2024-04-22 9:05 ` Fraga, Eric
2024-04-22 10:57 ` Max Nikulin
2024-04-18 15:38 ` Leo Butler
2024-04-18 16:01 ` Fraga, Eric
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).