Re: MathML and ODT export: inline possible?

2024-04-22 Thread Max Nikulin

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  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.





Re: MathML and ODT export: inline possible?

2024-04-22 Thread Fraga, Eric
On Friday, 19 Apr 2024 at 23:19, Max Nikulin wrote:
> MathJax may be your friend. LaTeXML and katex do not add  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


Re: MathML and ODT export: inline possible?

2024-04-19 Thread Max Nikulin

On 18/04/2024 22:51, Fraga, Eric wrote:

In LaTeX, something like $a_{b_c}$.  Pandoc generates

 a  b c 

(where the a, b, and c are ...) whereas, by hand, I use

 a  b c 


MathJax may be your friend. LaTeXML and katex do not add  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/cadojovjhoc5zzatf1y7uw2deqndhmdp5ka8mgzujhufkgte...@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 ... block in
.  I do not know what that does as I've only just started
learning mathml.


I have seen  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@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.









Re: MathML and ODT export: inline possible?

2024-04-18 Thread Fraga, Eric
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  block within the following
ODT to get anything to display:

--8<---cut here---start->8---




MathML goes here




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


Re: MathML and ODT export: inline possible?

2024-04-18 Thread Fraga, Eric
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

 a  b c 

(where the a, b, and c are ...) whereas, by hand, I use

 a  b c 

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 ... block in
.  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


Re: MathML and ODT export: inline possible?

2024-04-18 Thread Leo Butler
On Thu, Apr 18 2024, "Fraga, Eric"  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

#+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
  #$
  <>
  #$
#+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
http://www.w3.org/1998/Math/MathML;> mlabel 
 %o 1 ,
 6 
 2  5  
 4  91  
 29  85 
   98 
  3  7 
  13  
 20  13  
 39  20  
  19  4 
  97  6 
  1 43 
  39   
 23  13  
 36  53 
  60  
 71  4  
 3 
#+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]]





mathml.odt
Description: mathml.odt


Re: MathML and ODT export: inline possible?

2024-04-18 Thread Max Nikulin

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.




Re: MathML and ODT export: inline possible?

2024-04-18 Thread Fraga, Eric
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
... within a .

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


Re: MathML and ODT export: inline possible?

2024-04-18 Thread Max Nikulin

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-8593af357...@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+xntrpximp...@mail.gmail.com




MathML and ODT export: inline possible?

2024-04-18 Thread Fraga, Eric
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