Website/node_modules/mathjax-node
2015-12-04 02:31:39 -05:00
..
batik Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
bin Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
lib Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
test Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
test-files Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
x-old-stuff Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
.gitmodules Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
.npmignore Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
.travis.yml Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
LICENSE Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
out2.html Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
package.json Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00
README.md Paper rendering works, and news fields get populated correctly now. 2015-12-04 02:31:39 -05:00

MathJax-node Build Status

This repository contains files that provide APIs to call MathJax from node.js programs. There is an API for converting individual math expressions (in any of MathJax's input formats) into SVG images or MathML code, and there is an API for converting HTML snippets containing any of MathJax input formats into HTML snippets containing SVG or MathML.

See the comments in the individual files for more details.

The bin directory contains a collection of command-line programs for converting among MathJax's various formats. These can be used as examples of calling the MathJax API.

Use

npm install MathJax-node

to install MathJax-node and its dependencies.

These API's can produce PNG images, but that requires the Batik library. It should be installed in the batik directory. See the README file in that directory for more details.

Getting started

MahJax-node provides two libraries, lib/mj-single.js and lib/mj-page.js. Below are two very minimal examples -- be sure to check out the examples in ./bin/ for more advanced configurations.

  • lib/mj-single.js is optimized for processing single equations.
// a simple TeX-input example
var mjAPI = require("./lib/mj-single.js");
mjAPI.config({
  MathJax: {
    // traditional MathJax configuration
  }
});
mjAPI.start();

var yourMath = 'E = mc^2';

mjAPI.typeset({
  math: yourMath,
  format: "TeX", // "inline-TeX", "MathML"
  mml:true, //  svg:true,
}, function (data) {
  if (!data.errors) {console.log(data.mml)}
});
  • lib/mj-page.js is optimized for handling full HTML pages.
var mjAPI = require("./lib/mj-page.js");
var jsdom = require("jsdom").jsdom;

var document = jsdom("<!DOCTYPE html><html lang='en'><head><title>Test</title></head><body><h1>Let's test mj-page</h1> <p> \\[f: X \\to Y\\], where \\( X = 2^{\mathbb{N}}\\) </p></body></html>");

mjAPI.start();

mjAPI.typeset({
  html: document.body.innerHTML,
  renderer: "NativeMML",
  inputs: ["TeX"],
  xmlns: "mml"
}, function(result) {
  "use strict";
  document.body.innerHTML = result.html;
  var HTML = "<!DOCTYPE html>\n" + document.documentElement.outerHTML.replace(/^(\n|\s)*/, "");
  console.log(HTML);
});