Pangram verdict · v3.3
We believe that this document is fully human-written
AI likelihood · overall
HumanArticle text · 1,027 words · 5 segments analyzed
Use
Installation Usage Options
Philosophy
Quick to write / Easy to read Why not just use MathJax Why AsciiMath / Why not TeΧ
Reference
Reference Basics Numbers Operators Identifiers Text Spaces Fractions Sub and superscripts Fenced groups Matrices Tensors Roots Accents Font commands Colors
Open Source
GitHub
Bug Reports
License (MIT)
Installation
npm
npm install mathup
import mathup from "mathup";
Client
Download one of the following:
Module (full, min)
Script (full, min)
Custom element as module (full, min)
Custom element as script (full, min)
Stylesheet (full; not needed for custom element)
…and include the module:
<script type="module" src="mathup.js"></script> <link rel="stylesheet" href="mathup.css" />
…the custom element:
<script type="module" src="math-up-element.js"></script>
…or the script:
<script src="mathup.iife.js"></script> <link rel="stylesheet" href="mathup.css" />
Usage
const
expression = "1+1 = 2"; const options = {}; // optional const mathml = mathup(expression, options);
mathml.toString(); // => "<math><mrow><mn>1</mn><mo>+</mo><mn>1</mn></mrow><mo>=</mo><mn>2</mn></math>"
const mathNode = mathml.toDOM(); // => [object MathMLElement]
// Update existing <math> node in place mathup("3-2 = 1", { bare: true }).updateDOM(mathNode);
Custom Element
<math-up display="inline" dir="ltr" decimal-mark="," col-sep=";" row-sep=";;" > 1+1 = 2 </math-up>
Command line
npm install -g mathup mathup [options] -- <expression>
# or from stdin echo <expression> | mathup [options]
Options (with defaults)
const options = { decimalMark: ".", // -m --decimal-mark="." colSep: ",", // -c --col-sep="," rowSep: ";", // -r --row-sep=";" display: "inline", // -d --display="inline" dir: "ltr", // --rtl bare: false, // -b --bare };
Note: If you pick , as your decimal mark then ; becomes the new default column separator. And if ; is your column separator then the new default row separator becomes ;;. You can use , as both a decimal mark and a row separator if you take care to add a space between the row separator and the following digit. However then you must set both explicitly.
const options = { decimalMark: ",", colSep: ",", };
Quick to write / Easy to read
This package exposes a single function mathup that intuitively takes simple mathematical expressions—written in a markup language inspired by AsciiMath—and outputs structured MathML.
You can use it on the command line or on the server as a node 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 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 lets 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 for example.
Reference
Basics
Mathup uses four of MathML’s token elements (identifiers <mi>, operators <mo>, numbers <mn> and text <mtext>). Mathup recognizes which of these you mean when you write simple expressions.
For example: 1+1 = 2 ⇒
<mrow> <mn>1</mn> <mo>+</mo> <mn>1</mn> </mrow> <mo>=</mo> <mn>2</mn>
And sin theta ⇒
<mi>sin</mi><mi>θ</mi>
Mathup will also recognize most of the unicode characters you’ll write. If a character comes from one of the mathematical operator code blocks it will wrap it in an <mo> tag, otherwise it will be wrapped in an <mi> tag. Additionally d will be wrapped in an <mo> tag if it obviously a part of a differential.
Numbers
Numbers are usually what you think they are (including unicode numerals like Ⅻ or ↋). However if you want to write a number in an odd way (like spelling it out, as a hex string, or as a roman numeral) you can prepend a string with #, (e.g. #0x2A) or—if your number includes a non alphanumeric character—prepend a backticked fence (like in markdown) #`…`like so: #`forty two` or #`` `42 `` to make `42 a number.
Operators
Anything in the Pc, Pd, Pe, Pf, Pi, Po, Ps, Sm, or So unicode categories is considered an operator. Additionally the symbol character or alphanumeric string immediately following a backslash \ will become an operator (<mo>).
If you need more then one symbol character, or more then one word, as a single operator in the operator (e.g. <mo>for each</mo>), you can fence it following markdown semantics; (e.g. \`for each` or \`` ` `` for <mo>`</mo>).
The following will also map to the respective operator.
Operational
.$ FUNCTION APPLICATION (zero width)
.* INVISIBLE TIMES (zero width)
.+ INVISIBLE PLUS (zero width)
lim lim
mod mod
- −
+- ±
-+ ∓
* ·
xx ×
-: ÷
// ⁄
prod ∏
sum ∑
** ∗
@ ∘
^^ ∧
vv ∨
nn ∩
uu ∪
int ∫
dint ∬
oint ∮
!= ≠
!== ≢
o+ ⊕
ox ⊗
o. ⊙
^^^ ⋀
vvv ⋁
nnn ⋂
uuu ⋃
*** ⋆
|><|