asciidoctor / asciidoctor-mathematical

An extension for Asciidoctor that converts the content of STEM blocks and inline macros using Mathematical.
MIT License
50 stars 45 forks source link

Add support for mathml output, closes #110, #118 #117

Open infinity0 opened 1 year ago

infinity0 commented 1 year ago

Enable by setting mathematical-format = mathml, mathematical-inline = true

infinity0 commented 1 year ago

The second commit is optional; I mentioned some details in #110. It would also be easy to tweak this PR to instead use plurimath over latexmath. That is, we have 3 options:

infinity0 commented 1 year ago

One downside of docutil's latex2mathml is that "supports only a subset of LaTeX math syntax". For example, it doesn't support {align}. (To its credit, latexmath does appear to support this.)

After some experimentation, my impression is that pandoc(1) supports converting the most wide-ranging set of LaTeX math features to MathML. I've therefore added a 3rd commit to switch to using pandoc(1). So we have a total of 4 options to choose from; I've updated the above comment to reflect that.

infinity0 commented 1 year ago

MathML is due to be released and enabled by default in Chrome 109, so nudging again on this.

infinity0 commented 1 year ago

More info:

Note, MathML already works on Firefox and Opera.

mateibarbu19 commented 1 year ago

Hello, I tried using your patch, but could not get it to work with AsciiDoctor PDF. Ended up with inline HTML in PDF.

<div class="stemblock"> <span class="math display">$$\lim_{n \to
\infty}\frac{n}{\sqrt[n]{n!}} = {\large e}$$</span> </div>

Could you please provide a example?

infinity0 commented 1 year ago

I've not tested PDF. I'm just using asciidoctor -a stem -r asciidoctor-mathematical -a mathematical-format=mathml -a mathematical-inline=true.

Example source here: https://github.com/infinity0/mkwww/blob/master/example/src/test%20with%20spaces.adoc (raw) Example output here: https://infinity0.github.io/mkwww/test%20with%20spaces.html

infinity0 commented 1 year ago

This PR is about MathML support. How do you expect MathML support to work inside a PDF, @mateibarbu19 ?

mateibarbu19 commented 1 year ago

This PR is about MathML support. How do you expect MathML support to work inside a PDF, @mateibarbu19 ?

Hey, thanks for your helpful example! I was thinking that there may be a way of rendering it with an external call (e.g., to Chromium to then print it), and then including those graphics inside the PDF should be no problem.

I see now that my assumption was foolish, and I understand now how to use your fork for an HTML output.

Thank you!