Project

plurimath

0.0
The project is in a healthy, maintained state
Converts LaTeX math into MathML.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

Plurimath

This gem implements a mechanism of conversion between Math languages mentioned below.

  1. AsciiMath

  2. MathML

  3. 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
  asciimath = "sin(1)"
  formula = Plurimath::Math.parse(asciimath, :asciimath)
MathML Formula Example
  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")
Latex Formula Example
  latex = "\\sin{1}"
  formula = Plurimath::Math.parse(latex, "latex")

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>