This gem implements a mechanism of conversion between Math languages mentioned below.
-
AsciiMath
-
MathML
-
Latex
Installation
Add this line to your application’s Gemfile:
gem "plurimath"
And then execute:
$ bundle install
Or install it yourself as:
$ gem install plurimath
Usage
Pass the string you want to convert and Math type of the string provided, which will give you Plurimath::Math::Formula object as output, Let’s see some examples below.
Conversion Examples
Asciimath Formula Example
MathML Formula Example
Latex Formula Example
Since we have the object of Plurimath::Formula,We can generate AsciiMath, MathMl or Latex string from the formula object,All we have to do is call conversion function on formula object, see examples below.
AsciiMath Output conversion
formula.to_asciimath
> sin(1)
Note: Asciimath doesn’t support following symbols but Latex does.So from Latex to Asciimath conversion we are returning latex’s supported symbols if it’s not supported in Asciimath.
Latex Output conversion
formula.to_latex
> \\sin1
MathML Output conversion
formula.to_mathml
> <math xmlns='http://www.w3.org/1998/Math/MathML'>
> <mstyle displaystyle='true'>
> <mi>sin</mi>
> <mn>1</mn>
> </mstyle>
> </math>
XML Engines
Plurimath supports two XML engines.
-
Oga
-
Ox
By default, Ox is used which can be easily changed using the following syntax.
require "plurimath/xml_engines/oga" # load files related to oga
Plurimath.xml_engine = Plurimath::XmlEngine::Oga # set Oga as Plurimath xml engine
Using the same syntax you can change from Oga to Ox.
Supported Content
Take a look into the Symbols and Parenthesis tables for parenthesis and symbols support.