JavaScript library to convert AsciiMath to TeX.
I wrote this so I could use KaTeX to render AsciiMath.
The library is written as an ECMAScript module but is also distributed as CommonJS and UMD modules.
The file asciimath2tex.js
is an ES6 module which can be used in browsers that support it.
If you can use ES6 modules, use asciimath2tex.js
as-is:
import AsciiMathParser from 'asciimath2tex';
const parser = new AsciiMathParser();
const tex = parser.parse("int_(i=1)^10 x^2/2 dx");
parser.parse
returns a string of TeX.
If you can't use ES6 modules, there is a UMD version. You can load it from unpkg.com, or create it yourself.
<script src="https://unpkg.com/[email protected]/dist/asciimath2tex.umd.js"></script>
Clone this repository, and run:
npm install
npm run-script build
Copy the file dist/asciimath2tex.umd.js
into your project.
Install the package using npm:
npm install asciimath2tex
You can then load the package in your script:
const AsciiMathParser = require('asciimath2tex');
const parser = new AsciiMathParser();
const tex = parser.parse("int_(i=1)^10 x^2/2 dx");
There are some unit tests in test.html
, copied from the asciimath repository.
All of the tests are rendered correctly by KaTeX, apart from \twoheadrightarrowtail
, which it apparently doesn't support.