Skip to content

Instantly share code, notes, and snippets.

Last active August 9, 2017 21:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save parsd/40209f5822ebd394891b03893c7f8acf to your computer and use it in GitHub Desktop.
Convert TeX math expressions into svg via MathJax and Node.js

SVG from TeX Math Expression

Install Node.js

Install Node.js from or via your distrubution's package manager. So e.g. for Debian based distros like Ubuntu:

sudo apt install npm

and for Ubuntu to properly install some packages also

sudo apt install nodejs-legacy

Create a Simple MathJax Converter

Create a folder Tex2Svg and open a command prompt here to install mathjax-node:

npm install mathjax-node

And then create tex2svg.js:

#!/usr/bin/env node
var mjAPI = require("mathjax-node");

if (process.argv.length != 3) {
  console.log("No expression given!\n");
  console.log("Usage: " + process.argv[0] + " " + process.argv[1] + " <TeX expression>");

var yourMath = process.argv[2];

  math: yourMath,
  format: "TeX",
}, function (data) {
  if (!data.errors)


node ./tex2svg.js "f(x) = x^2" > parabola.svg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment