texmath-ruby
A wrapper for TeXMath, a Haskell library for converting between formats used to represent mathematics.
TeXMath can convert between LaTeX, presentation MathML, and OMML (Office Math Markup Language). This wrapper uses the command line program for texmath for all operations (rather than interface directly with the Haskell library) and is heavily based on William Melody's wrapper for Pandoc.
Installation
First, make sure texmath is installed. If you already have The Haskell Platform, you can install texmath with Cabal:
$ cabal install texmath
If you use Bundler, then add this line to your application's Gemfile:
gem 'texmath-ruby', require: 'texmath'
And then execute:
$ bundle
Or install it yourself as:
$ gem install texmath-ruby
Usage
Once everything is installed correctly, using TeXMath is incredibly easy.
For example, converting from LaTeX to MathML looks like this:
TeXMath.convert('\sqrt{x^3}', from: :tex, to: :mathml)
# => '<math display="block" xmlns=...'
TeXMath can convert between LaTeX, MathML, and OMML, in any direction. By default (if either the source or destination format isn't explicitly specified), TeXMath will try to convert from LaTeX to MathML. So to convert from LaTeX (the default source format) to OMML:
TeXMath.convert('\sqrt{x^3}', to: :omml)
# => '<m:oMathPara>...'
Or from OMML to MathML (the default destination format):
TeXMath.convert('<m:oMathPara>...', from: :omml)
# => '<math display="block" xmlns=...'
TeXMath also comes with writers for XHTML and Pandoc's native format.
Supported formats
Format | Symbol | Reader | Writer |
---|---|---|---|
LaTeX | :tex |
✔ | ✔ |
MathML | :mathml |
✔ | ✔ |
Office Math Markup Language | :omml |
✔ | ✔ |
TeXMath native | :native |
✔ | ✔ |
XHTML | :xhtml |
✔ | |
Pandoc native | :pandoc |
✔ |
Contributing
- Fork it ( https://github.com/hollingberry/texmath-ruby/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request