Project

katex2html

0.0
No commit activity in last 3 years
No release in over 3 years
Now you can parse your LaTeX formules with Katex and let the client-side worry only with stylesheets.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 0.10
~> 10.0
~> 3.4

Runtime

>= 1.4.0
 Project Readme

Katex2HTML

Gem Version Build Status Code Climate Test Coverage

An easy way to convert LaTeX formules into Katex HTML using Ruby.

Installation

Add this line to your application's Gemfile:

gem 'katex2html'

And then execute:

$ bundle

Or install it yourself as:

$ gem install katex2html

Usage

To render strings into Katex HTML rendered maths, just use the method below:

Katex2HTML.render(string, options)

Options

You can provide options as the last argument to Katex2HTML.render. Available options are:

  • renderer : symbol. If :html parse an HTML file looking for matching patterns, convert the math and return a HTML with Katex rendered string. If :single render a single formule and returns an Katex rendered HTML string. (default :single)
  • delimiters : array. You can send an array with custom delimiters to customize the parser patterns. (default: [ ['$', '$'], ['\\[', '\\]'] ])

Renderer

Single

To render a specific math formule, you can use:

# Single formule
formule = "log_c (a.c) + 3log_c b - 2log_c \\left(\\dfrac{a}{b}\\right)"

Katex2HTML.render(formule, renderer: :single) # Returns Katex HTML rendered
HTML

To parse all latex from an HTML string, you can just:

# HTML with formules between `$`
mathHtml = "<p>Math below:</p><p>$log_c (a.c) + 3log_c b - 2log_c \\left(\\dfrac{a}{b}\\right)$</p>"

Katex2HTML.render(latex_html, renderer: :html) # Returns HTML with Katex HTML rendered

Delimiters

You can send an array with custom delimiters

# HTML with formules between `BOF` and `EOF`
mathHtml = "<p>Math below:</p><p>BOFlog_c (a.c) + 3log_c b - 2log_c \\left(\\dfrac{a}{b}\\right)EOF</p>"

Katex2HTML.render(latex_html, delimiters: ['BOF', 'EOF'], renderer: :html) # Returns HTML with Katex HTML rendered

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/appprova/katex2html. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.