Giter Site home page Giter Site logo

mathjax-node's Introduction

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

mathjax-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);
});

mathjax-node's People

Contributors

dpvc avatar geyang avatar gjtorikian avatar jcayzac avatar onomojo avatar pauldraper avatar peterldowns avatar physikerwelt avatar pkra avatar sammarshallou avatar zorkow avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.