Skip to content

Feature Request: MathJax-node in Pandoc #3153

@ickc

Description

@ickc

The suggestion is made as a sidetrack in a few issues: #2758 and jgm/pandoc-templates#219. I think may be a dedicated issue should be made.

What Does It Do?

It is similar to what MathJax does, but on the "server-side". i.e. rather than render it every time it is viewed, it pre-renders it.

What Problems Can It Solve?

Alternative Rendering Engine for MathML Output

At the very least, it provides another choice to output MathML. If features unique to MathJax is needed, mathjax-node will be a better alternatives to the existing choices of MathML output options.

Static, Non-Rasterized and HTML Rendering Engine Independent

There were already a few other choices in pandoc that provide a truly static (does not depends on javascript) output: MathML, PNG. PNG are rasterized, MathML support is broken. MathJax-node have CHTML/SVG options that are superior to both (MathJax also has MathML and PNG output; and CHTML is the newest and fastest option).

Self-contained MathJax

It is difficult to self-contained MathJax since mathjax.js will requests additional .js files. To self-contain Maths, either you sacrifies MathJax (and use some other options which might lacks some of the features of the MathJax you relies on), or you need to embed MathJax in your package (see mathjax/MathJax-grunt-cleaner to make the MathJax footprint smaller for embedding).

In this sense, MathJax-node provides a self-contained way of using MathJax, and would be useful in, say, ePub(3) output.

How to implement it in pandoc?

No idea, but the following are my observations:

MathJax-node/bin/tex2html could be used to create a filter to process each math elements and turn it into raw HTML.

It will then has an external dependancy of npm install mathjax-node -g. The size is big (63.8 MB) since it includes the whole MathJax (54.5MB) in it. However if pandoc only use some particular features, the MathJax can be MathJax-grunt-cleaner cleansed to about 2MB (say for the CHTML option only). May be the MathJax and MathJax-node can be forked and created a small foot-print version for pandoc specifically?

In terms of command line option, one way is that whenever pandoc ... --self-contained ... --mathjax ... is used, then it actually uses MathJax-node to provide a "self-contained MathJax". Or else may be --mathjax-node option can be provided.

"I want to do it now"

Install MathJax-node by npm install mathjax-node -g.

page2html as a post-processor

If the output is HTML5, MathJax-node/bin/page2html can be used as a post-processor after pandoc. page2html is specifically said to

Reads an HTML5 file…

page2html as a pre-processor

I tried to process the markdown file directly with page2html and it seems ok. Basically page2html is used here beyond what it is designed for, but any markdown syntaxes probably will be ignored because it would treat it as texts. I'm not sure if raw HTML, div, span used in the pandoc markdown source might confuses page2html though.

In this case, page2html is used as a pre-processor to process the markdown first. The Math becomes raw HTML, and should be ok when parsed by pandoc, and then output to any HTML-related output including ePub(3).

Caveat

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions