-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert mathematical formulae to MathML #108
Comments
You can do this, and if it works, it will be useful in Metanorma as well. Metanorma uses the LaTeXML installation separately via package managers. In the docker image it uses CPAN, in other situations the Snap package and the Chocolatey package. |
@skalee for LaTeX math, ONLY LaTeXML is deterministically accurate and correct (i.e. it always arrives at the correct structure), even though it is slower than others. It is also necessary to use the same processor being used in Metanorma because the terminology site software is part of our standardization suite. |
Okay, these are strong arguments. I'll experiment with LaTeXML then. Regarding bridging LaTeXML as native extension: Initially I thought that LaTeXML is written in C, but now I see it's in Perl. This makes everything difficult. Resources on the topic are scarce, if any. We're literally entering uncharted waters and I doubt we'll succeed, especially that I don't know Perl at all. Nevertheless, I'll be happy to try. (update: this is very old, but looks promising: ruby-perl) However, we can still call LaTeXML from a subshell, and we can avoid repetitive calls by caching the results. This should improve performance greatly, especially if we use a disk case in order to persist it between builds. At the moment I'm pretty convinced we'll end up with subshell calls. Having said that, I still don't know what to do with missing entities like
On my computer, it ends up with one error (Error:undefined:\backepsilon The token T_CS[\backepsilon] is not defined) and one warning (Warning:not_parsed:UNKNOWN.ATOM.CLOSE>METARELOP MathParser failed to match rule 'Anything'). Produced MathML is as follows (note
You can copy-paste it to MathJax demo. |
@ronaldtse I still have troubles with LaTeXML. Does anyone know how to fix error produced by following command (
|
@skalee Please check usage of latexmlmath in the metanorma gem. Backepsilon is recognized there. |
We now have the plurimath gem that can do all of the above conversions. Thanks @suleman-uzair! |
Some concepts may contain mathematical symbols and formulas in their designations, descriptions, or notes. Formulas can be expressed either in LaTeX math, AsciiMath, or MathML. It is also preferred that concepts follow AsciiDoc stemming syntax with
stem
,asciimath
, andlatexmath
macros.Available converters
There are some programs which come handy:
AsciiMath gem
A handy gem which converts AsciiMath to MathML. AsciiDoctor relies on it when processing stem macros (optional dependency). Does job pretty well, however does not convert LaTeX math strings. There is no corresponding gem for LaTeX math.
LaTeXML
A toolset for processing LaTeX documents. Most importantly, it contains
latexmlmath
program, which converts LaTeX math formulas to MathML. Sadly, this program fails to recognize some symbols, e.g.\backepsilon
. Perhaps this can be fixed with proper configuration.Example:
latexmlmath '\sqrt{b^2-4ac}'
Pandoc
Pandoc is capable of converting LaTeX math to MathML, though it must be wrapped in a Markdown document. We can craft a minimalistic Markdown document and then extract MathML formula from generated HTML.
Example:
echo '$$\sqrt{b^2-4ac}$$' | pandoc --mathml -f markdown -t html
MathJax
MathJax converts both AsciiMath and LaTeX math to MathML. It is designed to be run in browser primarily, but works in NodeJS too. The problem is that it is poorly documented, and API docs are non-existent. There are some usage examples in https://github.com/mathjax/MathJax-demos-node which present working solutions. Following two snippets use programs from that repository:
Example:
node -r esm component/tex2mml \\sqrt{b^2-4ac}
(LaTeX math -> MathML)Example:
node -r esm component/am2mml 'sqrt(b^2-4ac)'
(AsciiMath -> MathML)Performance considerations
Executing a program per each formula on site may hamper site generation time. LaTeXML, Pandoc and MathJax have been benchmarked with hyperfine:
Integration considerations
We can call any of these programs from Ruby by creating a subshell. However, it will be very time-consuming for MathJax, and especially for LaTeXML.
Final considerations
We would love to integrate LaTeXML as we have our part in its development, however this seems to be the most difficult of all above. We need to turn it into a gem, and resolve issues with unrecognized symbols. Perhaps in a longer run… unless we have a gem already?
The text was updated successfully, but these errors were encountered: