Using Plurimath (Ruby or Javascript)
Ruby
General
Add this line to your application’s Gemfile:
gem "plurimath"
Then execute:
$ bundle install
Or install it:
$ gem install plurimath
Usage
General
The Plurimath::Math.parse(string, type) method parses a math formula of a
type identifying the math language type and returns a
Plurimath::Math::Formula representation of the string provided as output.
The Plurimath::Math::Formula object allows generating any supported math
language string from the formula object through conversion methods.
AsciiMath
For guidance on grouping, visible parentheses, matrices, text, and decimal commas, see the AsciiMath author guide.
From AsciiMath:
> asciimath = "sin(1)"
> formula = Plurimath::Math.parse(asciimath, :asciimath)
To AsciiMath:
> formula.to_asciimath
=> sin(1)
|
Note
|
Plurimath’s AsciiMath provides extended support for additional symbols not included in AsciiMath but allowed in LaTeX. The full list of these symbols are listed here. |
LaTeX math
From LaTeX math:
> latex = "\\sin{1}"
> formula = Plurimath::Math.parse(latex, :latex)
To LaTeX math:
> formula.to_latex
=> \\sin1
MathML
From MathML:
> mathml = <<~MATHML
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mstyle displaystyle='true'>
<mi>sin</mi>
<mn>1</mn>
</mstyle>
</math>
MATHML
> formula = Plurimath::Math.parse(mathml, :mathml)
To MathML:
> formula.to_mathml
=> <math xmlns='http://www.w3.org/1998/Math/MathML'>
<mstyle displaystyle='true'>
<mi>sin</mi>
<mn>1</mn>
</mstyle>
</math>
Javascript
General
The website’s native TypeScript converter is available as a browser module:
-
Javascript:
plurimath.js
The website builds a pinned source revision from
plurimath-ts.
Web applications
<script type="module">
import Plurimath from "https://www.plurimath.org/javascript/plurimath.js";
const formula = new Plurimath('ubrace(1+2+3+4)_("4 terms")', "asciimath");
console.log(formula.toLatex());
</script>
Node.js (legacy Opal package)
The published @plurimath/plurimath
package uses Opal. The instructions below apply to that package.
Install
$ npm install -S @plurimath/plurimath
ES Modules (recommended)
import Plurimath from "@plurimath/plurimath"
const formula = new Plurimath('ubrace(1+2+3+4)_("4 terms")', "asciimath");
console.log(formula.toLatex());
CommonJS
const Plurimath = require("@plurimath/plurimath/index.cjs").default;
const formula = new Plurimath('ubrace(1+2+3+4)_("4 terms")', "asciimath");
console.log(formula.toLatex());