Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/asnunes/mathml-to-latex

A JavaScript tool to convert mathml string to LaTeX equation string.
https://github.com/asnunes/mathml-to-latex

Last synced: 4 days ago
JSON representation

A JavaScript tool to convert mathml string to LaTeX equation string.

Awesome Lists containing this project

README

        

# mathml-to-latex

It converts [MathML](https://en.wikipedia.org/wiki/MathML) to [LaTeX](https://pt.wikipedia.org/wiki/LaTeX).

## Installation

If you use NPM

```
npm install mathml-to-latex --save
```

If you use Yarn

```
yarn add mathml-to-latex
```

## Usage

```javascript
import { MathMLToLaTeX } from 'mathml-to-latex';
// const { MathMLToLaTeX } = require('mathml-to-latex');

const mathml = `


a
+
b


`;

MathMLToLaTeX.convert(mathml);
// => a + b
```

```javascript
import { MathMLToLaTeX } from 'mathml-to-latex';
// const { MathMLToLaTeX } = require('mathml-to-latex');

const mathml = `


A
=



x
y


z
w





`;

MathMLToLaTeX.convert(mathml);
// => A = \begin{bmatrix} x & y \\ z & w \end{bmatrix}
```

## Browser

Package is also available directly in the browser through CDN:

```html




MathML to LaTeX Converter






MathML to LaTeX Converter






Convert to LaTeX






const mathmlInput = document.getElementById('mathmlInput');
const latexOutput = document.getElementById('latexOutput');
const convertButton = document.getElementById('convertButton');

mathmlInput.value = `\
<math>
<mrow>
<mn>2</mn>
<mo>+</mo>
<mn>2</mn>
<mo>=</mo>
<mn>4</mn>
</mrow>
</math>`;

convertButton.addEventListener('click', function () {
const latex = MathMLToLaTeX.MathMLToLaTeX.convert(mathmlInput.value);
latexOutput.textContent = latex;
});

```

Output:

![Browser DEMO](./docs/browser-demo.gif)