Try to render MathJax in pure HTML/CSS for use in environments without JS.
This experiment is part of my project at NTUOSC, trying to write and publish documents of simple structure in Markdown and PDF formats. One of the features is the support of LaTeX math expressions, especially for people (including myself) who are going to use this tool to write some technical reports.
I decided to use MathJax for LaTeX support. (No, no, MathML cannot satisfy me!) Since MathJax tends to be typeset by heavy JS at client-side, I wondered if there is an option to render it within Node.js, piping out the HTML/CSS structure to PrinceXML. To my suprise, there is an undocumented hiding here.
Sample document used in this experiment, which was written half a year ago, containing LaTeX markers for both display style and inline math, can be accessed at https://gist.github.com/andy0130tw/361531904c6909da8b86.
The document doc.md
is converted to HTML by Markdown-it using a plugin to escape math expressions.
npm install # install dependencies
node index.js # produce output.html
prince output.html test.pdf # produce test.pdf
# alternatively you can add the stylesheet for "Paged Media"
prince output.html test.pdf -s res/css/paged-media.css
- Super-slow in both convertions, MathJax and PrinceXML.
Output format: HTML-CSS is preferable, but failed with a timeout. Use CommonHTML instead.HTML-CSS is infeasible without a real browser, or to fake the creation of web fonts in jsdom.- Should provide customizable font paths.
- Make some adjustments to CSS stylesheets for printing.
- More verbose on progress. (debug messages for MathJax can be turned on manually.)
- Some typesetting issues in MathJax like the fraction bar (?). MathJax is intended to be run in browser because it needs context to apply workarounds.
Will try to adjust or patch settings accordingly to the result of Prince.(There might be some bugs in Prince!)