Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kgryte/tex-equation-to-svg
Convert a TeX or LaTeX string to an SVG.
https://github.com/kgryte/tex-equation-to-svg
convert converter equation latex svg tex
Last synced: 3 months ago
JSON representation
Convert a TeX or LaTeX string to an SVG.
- Host: GitHub
- URL: https://github.com/kgryte/tex-equation-to-svg
- Owner: kgryte
- License: mit
- Created: 2016-02-23T02:19:40.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-07T18:10:00.000Z (over 7 years ago)
- Last Synced: 2024-05-02T06:17:09.065Z (8 months ago)
- Topics: convert, converter, equation, latex, svg, tex
- Language: JavaScript
- Homepage:
- Size: 25.4 KB
- Stars: 36
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
tex2svg
===
[![NPM version][npm-image]][npm-url] [![Build Status][build-image]][build-url] [![Coverage Status][coverage-image]][coverage-url] [![Dependencies][dependencies-image]][dependencies-url]> Convert a [TeX][tex] or [LaTeX][latex] `string` to an SVG.
## Installation
``` bash
$ npm install tex-equation-to-svg
```## Usage
``` javascript
var tex2svg = require( 'tex-equation-to-svg' );
```
#### tex2svg( str[, options], clbk )Converts a [TeX][tex] or [LaTeX][latex] `string` to an SVG.
``` javascript
var eqn = 'y = mx + b';tex2svg( eqn, clbk );
function clbk( error, svg ) {
if ( error ) {
throw error;
}
console.log( svg );
/*
'
Equation
y equals m x plus b
'
*/
}
```The `function` accepts the following `options`:
* __width__: container width in `ex` (used for linebreaking and tags). Default: `100`.
* __ex__: `ex` size in pixels. Default: `6`.
* __inline__: `boolean` indicating whether to format an input `string` as an inline equation. Default: `false`.
* __linebreaks__: `boolean` indicating whether to perform linebreaking. Default: `true`.By default, the `function` formats an input `string` as a displayed equation. To format the `string` as a text (inline) equation, set the `inline` option to `true`.
``` javascript
var eqn = 'y = mx + b';var opts = {
'inline': true
};tex2svg( eqn, opts, clbk );
```#### tex2svg.factory( options, clbk )
Creates a reusable `function`.
``` javascript
var opts = {
'inline': true
};var convert = tex2svg.factory( opts, clbk );
convert( 'y = mx + b' );
convert( 'z = \\frac{1}{2}' );
convert( 'w = \\sum_{i=0}^{n} x_i' );
// ...
```The factory method accepts the same `options` as [`tex2svg()`](#tex2svg).
## Notes
* All [TeX][tex] and [LaTeX][latex] commands should be escaped.
``` javascript
// Not escaped:
var eqn = 'x = \frac{1}{2}';// Escaped:
eqn = 'x = \\frac{1}{2}';
```## Examples
``` javascript
var tex2svg = require( 'tex-equation-to-svg' );var eqn = '\\operatorname{erf}(x) = \\frac{2}{\\sqrt\\pi}\\int_0^x e^{-t^2}\\,\\mathrm dt.';
tex2svg( eqn, done );
function done( error, svg ) {
if ( error ) {
throw error;
}
console.log( svg );
// returns ''
}
```To run the example code from the top-level application directory,
``` bash
$ node ./examples/index.js
```---
## CLI### Installation
To use the module as a general utility, install the module globally
``` bash
$ npm install -g tex-equation-to-svg
```### Usage
``` bash
Usage: tex2svg [options] equationOptions:
-h, --help Print this message.
-V, --version Print the package version.
--width width Container width in ex. Default: 100.
--ex ex ex size in pixels. Default: 6.
--inline Format input equation as inline TeX.
--no-linebreaks Disable linebreaking.
```### Examples
``` bash
$ tex2svg '\operatorname{erf}(x) = \frac{2}{\sqrt\pi}\int_0^x e^{-t^2}\,\mathrm dt.'
# =>