Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/remarkablemark/texsvg
📐 TeX to SVG
https://github.com/remarkablemark/texsvg
equation formula javascript latex math mathjax nodejs npm npm-package package svg tex
Last synced: about 1 month ago
JSON representation
📐 TeX to SVG
- Host: GitHub
- URL: https://github.com/remarkablemark/texsvg
- Owner: remarkablemark
- License: mit
- Created: 2020-04-30T02:22:39.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-27T23:14:58.000Z (6 months ago)
- Last Synced: 2024-05-28T08:37:48.477Z (6 months ago)
- Topics: equation, formula, javascript, latex, math, mathjax, nodejs, npm, npm-package, package, svg, tex
- Language: TypeScript
- Homepage: https://npmjs.com/package/texsvg
- Size: 1.15 MB
- Stars: 17
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# texsvg
[![NPM](https://nodei.co/npm/texsvg.png)](https://nodei.co/npm/texsvg/)
[![NPM version](https://img.shields.io/npm/v/texsvg.svg)](https://www.npmjs.com/package/texsvg)
[![build](https://github.com/remarkablemark/texsvg/actions/workflows/build.yml/badge.svg)](https://github.com/remarkablemark/texsvg/actions/workflows/build.yml)
[![codecov](https://codecov.io/gh/remarkablemark/texsvg/branch/master/graph/badge.svg?token=BC34P2RTJB)](https://codecov.io/gh/remarkablemark/texsvg)Converts [TeX](https://wikipedia.org/wiki/TeX) to [SVG](https://wikipedia.org/wiki/Scalable_Vector_Graphics) using [MathJax](https://www.mathjax.org/) and [SVGO](https://github.com/svg/svgo):
```
texsvg(string)
```### Examples
Module:
```js
const texsvg = require('texsvg');texsvg('\\frac{a}{b}').then((svg) => console.log(svg));
```CLI:
```sh
texsvg '\frac{a}{b}' fraction.svg
```Other:
- [Replit (Node.js)](https://replit.com/@remarkablemark/texsvg)
- [Replit (Server)](https://replit.com/@remarkablemark/texsvg-server)
- [texsvg-server](https://github.com/remarkablemark/texsvg-server)
- [JSFiddle](https://jsfiddle.net/remarkablemark/1k7t6s9o/)## Installation
### Module
[NPM](https://www.npmjs.com/package/texsvg):
```sh
npm install texsvg
```[Yarn](https://yarnpkg.com/package/texsvg):
```sh
yarn add texsvg
```### CLI
NPM:
```sh
npm install --global texsvg
```Yarn:
```sh
yarn global add texsvg
```NPX:
```sh
npx texsvg
```## Usage
### Module
Import with ES Modules:
```js
import * as texsvg from 'texsvg';
```Or require with CommonJS:
```js
const texsvg = require('texsvg');
```Convert TeX to SVG using [async-await](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/async_function):
```js
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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise):
```js
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:
```sh
texsvg
```Convert TeX to SVG and log result to console:
```sh
texsvg '\frac{a}{b}'
```Convert TeX to SVG and save result to file:
```sh
texsvg '\frac{a}{b}' fraction.svg
```## Testing
Run tests with coverage:
```sh
npm test
```Run tests in watch mode:
```sh
npm run test:watch
```Run integration tests:
```sh
npm run test:integration
```Lint files:
```sh
npm run lint
npm run lint:tsc
```Fix lint errors:
```sh
npm run lint:fix
```## Release
Release is automated with [Release Please](https://github.com/googleapis/release-please).
## License
[MIT](https://github.com/remarkablemark/texsvg/blob/master/LICENSE)