texsvg
TypeScript icon, indicating that this package has built-in type declarations

2.2.1 • Public • Published

texsvg

NPM

NPM version build codecov

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 with ES Modules:

import * as texsvg from 'texsvg';

Or require with CommonJS:

const texsvg = require('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

Package Sidebar

Install

npm i texsvg

Weekly Downloads

63

Version

2.2.1

License

MIT

Unpacked Size

12.1 kB

Total Files

9

Last publish

Collaborators

  • remarkablemark