Awesome Open Source
Awesome Open Source

texsvg

NPM

NPM version build Coverage Status

Converts TeX to SVG using MathJax and SVGO:

texsvg(string)

Examples

Module:

const texsvg = require('texsvg');

texsvg('\\frac{a}{b}').then((svg) => console.log(svg));

CLI:

texsvg '\frac{a}{b}' fraction.svg

Other:

Installation

Module

NPM:

npm install texsvg

Yarn:

yarn add texsvg

CLI

NPM:

npm install --global texsvg

Yarn:

yarn global add texsvg

NPX:

npx texsvg

Usage

Module

Import module:

// CommonJS
const texsvg = require('texsvg');

// ES Modules
import * as texsvg from 'texsvg';

Convert TeX to SVG using async-await:

const quadraticFormula = 'x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}';

(async () => {
  try {
    const svg = await texsvg(quadraticFormula);
    console.log(svg);
  } catch (err) {
    console.error(err);
  }
})();

Convert TeX to SVG using Promise:

const quadraticFormula = 'x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}';

texsvg(quadraticFormula)
  .then((svg) => console.log(svg))
  .catch((err) => console.error(err));

CLI

Usage:

texsvg <tex> <file>

Convert TeX to SVG and log result to console:

texsvg '\frac{a}{b}'

Convert TeX to SVG and save result to file:

texsvg '\frac{a}{b}' fraction.svg

Testing

Run tests with coverage:

npm test

Run tests in watch mode:

npm run test:watch

Run integration tests:

npm run test:integration

Lint files:

npm run lint
npm run lint:tsc

Fix lint errors:

npm run lint:fix

Release

Release is automated with Release Please.

License

MIT

Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,058,025
Typescript (245,128
Cli (131,505
Tex (19,588
Latex (10,120
Math (9,858
Lint (9,086
Mathjax (780
Svgo (247