emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Leo Butler <Leo.Butler@umanitoba.ca>
To: Org Mode List <emacs-orgmode@gnu.org>
Subject: Re: MathML and ODT export: inline possible?
Date: Thu, 18 Apr 2024 15:38:18 +0000	[thread overview]
Message-ID: <875xweof4n.fsf@t14.reltub.ca> (raw)
In-Reply-To: <871q727tqp.fsf@ucl.ac.uk> (Eric Fraga's message of "Thu, 18 Apr 2024 12:14:39 +0000")

[-- 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 --]

  parent reply	other threads:[~2024-04-18 15:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2024-04-18 16:01   ` Fraga, Eric

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875xweof4n.fsf@t14.reltub.ca \
    --to=leo.butler@umanitoba.ca \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).