29

Mathup – A simple MathML authoring tool

 4 years ago
source link: https://runarberg.github.io/mathup/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Installation

npm

npm install mathup
import mathup from "mathup";

Client

Download one of the following:

…and include the module :

<script type="module" src="mathup.mjs"></script>

…the custom element :

<script type="module" src="math-up-element.mjs"></script>

…or the script :

<script src="mathup.iife.js"></script>

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: ",",

};

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK