README
prerender-mathjax
Use MathJax to prerender math in HTML documents on the server side.
Installation
npm install --save prerender-mathjax
Usage
As a Node server:
var prerenderServer = require('prerender-mathjax/server');
prerenderServer(ROOT, options).listen(3000);
Where ROOT
is the path from which to serve files and options
is the config
object expected by the config
method of the MathJax-node API. Example config:
var options = {
MathJax: {
menuSettings: {semantics: true},
SVG: {font: "TeX"}
}
}
Server will serve files from ROOT
and respect the following query params:
prerender={MML|SVG}
- prerender math using the given output format.stripmj
- strip out MathJax-related <script> tags.
As Koa middleware:
var prerender = require('prerender-mathjax')(options);
// Upstream middleware that populates `this.body` with HTML (can be a String,
// Buffer, or Stream).
app.use(function*(next) {
yield prerender(this, options);
yield* next;
})
Where options
is the config object expected by the config
method of the
MathJax-node API. (See above for example.)
This is just the prerendering logic. To make it contingent on query parameters and to strip out MathJax <script> elements, see the server code.
From the command line:
node --harmony server.js test/fixtures/
Point to http://localhost:3000/simple.html. Result:
<html>
<head>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/javascript">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [
['