https://github.com/runarberg/mathup
Easy MathML authoring tool with a quick to write syntax
https://github.com/runarberg/mathup
asciimath javascript markup-language mathematical-expressions mathml
Last synced: 6 months ago
JSON representation
Easy MathML authoring tool with a quick to write syntax
- Host: GitHub
- URL: https://github.com/runarberg/mathup
- Owner: runarberg
- License: mit
- Created: 2015-03-11T20:09:46.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2023-12-02T03:52:29.000Z (over 1 year ago)
- Last Synced: 2024-04-14T02:07:15.709Z (about 1 year ago)
- Topics: asciimath, javascript, markup-language, mathematical-expressions, mathml
- Language: JavaScript
- Homepage: https://runarberg.github.io/mathup
- Size: 5.54 MB
- Stars: 61
- Watchers: 4
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mathup
[](https://www.npmjs.com/package/mathup)
[](LICENSE)
[](https://github.com/runarberg/mathup/actions/workflows/ci.yml?query=branch%3Amain)
[](https://coveralls.io/github/runarberg/mathup)
[](https://npm-stat.com/charts.html?package=mathup)
[](https://api.npms.io/v2/package/mathup)#### Installation
##### npm
```bash
npm install mathup
``````js
import mathup from "mathup";
```##### Client
Download or link one or more of the [released assets](https://www.jsdelivr.com/package/npm/mathup?tab=files&path=dist)
and include the **module**:```html
```
…the **custom element**:
```html
```
…or the **script**:
```html
```
#### Usage
```js
const expression = "1+1 = 2";
const options = {}; // optional
const mathml = mathup(expression, options);mathml.toString();
// => "1+1=2"const mathNode = mathml.toDOM();
// => [object MathMLElement]// Update existing node in place
mathup("3-2 = 1", { bare: true }).updateDOM(mathNode);
```##### Custom Element
```html
1+1 = 2
```
##### Command Line
```bash
npm install -g mathupmathup [options] --
# or from stdin
echo | mathup [options]
```#### Options (with defaults)
```js
const options = {
decimalMark: ".", // -m, --decimalmark="."
colSep: ",", // -c, --colsep=","
rowSep: ";", // -r, --rowsep=";"
display: "inline", // -d, --display
dir: "ltr", // --rtl
bare: false, // -b, --bare
}
```## Reference
[See here](http://runarberg.github.io/mathup/#reference)
## Easy MathML authoring tool with a quick to write syntax
This package exposes a single function `mathup` that intuitively takes
simple mathematical expressions—written in a markup language inspired
by [_AsciiMath_](http://asciimath.org/)—and outputs structured
[_MathML_](http://www.w3.org/Math/).You can use it on the command line or on the server as an
[npm](https://npmjs.com) package, or in the browser by including the
script source. In the browser, you choose how to parse the math in
your document—by looking hard for any math-y substrings, parsing all
expressions wrapped in `$`…`$`, or using some other excellent tools out
there that does it for you. And you can choose what to do with the
output as well—piping it to another program, inject it streight to the
DOM, or just logging it to the console.## Why not just use _MathJax_?
[_MathJax_](http://www.mathjax.org/) is an excellent tool that you can
safely use if all you want to do is include complex mathematical
expressions in a document. However, MathJax is a complex piece of
software that does a great deal more than just translate simple
expression into structured form, and if that is all you want to do,
then MathJax is definitely overkill. Mathup promises to be a lot
faster (by doing less) then MathJax. While MathJax will search for
expressions, parse them, translate and render them. Mathup only parses
and translates them, and let the browser do the rendering.## Why AsciiMath / Why not TeΧ?
I wrote this tool, because I wanted to be able to author mathematical
expressions quickly, with no overhead (imagine `1/2` instead of
`\frac{1}{2}`). TeΧ expressions can easily become verbose and annoying
to write (especially on keyboards with complex access to the
\ , {, and } keys). However, the
purpose of this package is _not_ to give people complete control over
MathML in a non-verbose way, the purpose is to make it simple for
people to write simple expression. Of course I’ll try to give as much
expressive power as possible in the way, but I won’t promise to make
all complex things possible.If you want full support of MathML, and don’t want to write all those
tags perhaps you should look for another tool. There are other great
efforts to enable people to author MathML in TeX format, take a look
at [TeXZilla](https://github.com/fred-wang/TeXZilla) for example.## Testing
Run the test suites with:
```bash
npm test
```As for manual and visual tests, if you are running node 13 or newer,
you don’t need to compile between edit and run as the code is written
without transpilation in mind. The code works in both browsers and
node without any transcompilation.For a simple test do:
```bash
./bin/mathup.js -- 'my expression'
```You can open a
[playground](http://localhost:8000/demo/playground.html) and [test
cases](http://localhost:8000/demo/test-cases.html) on
by running:```bash
npm run server
```