Giter VIP home page Giter VIP logo

math-to-itex's Introduction

Math to Itex

Convert strings into a proper itex format.

Build Status

Installation

Add this line to your application's Gemfile:

gem 'math-to-itex'

And then execute:

$ bundle

Or install it yourself as:

$ gem install math-to-itex

Usage

Due to fancy regexes, this gem only works with Ruby 2.0+.

To use this gem, pass a string to the MathToItex module, and an optional block:

require 'math-to-itex'

result = MathToItex('\[a \ne 0\]').convert
# result is now `$$a \ne 0$$`

result = MathToItex('\[a \ne 0\]').convert { |string| "<span>#{string}</span>" }
# result is now `<span>$$a \ne 0$$</span>`

Basically, by not passing a block, you do a simple convert. By passing a block, you can modify the resulting math equation.

Behind the scenes, MathToItex uses gsub, so all equations in a string are modified.

If you want, you can determine the type (inline or display), too:

result = MathToItex('$0$ is not equal to $$1 = 0$$').convert do |string, type|
  %|<span class="#{type}">#{string}</span>|
end

# result is `<span class="inline">$0$</span> is not equal to <span class="display">$$1 = 0$$</span>`

Matched math notations

Currently, the following formats are supported:

inline formulas display formulas
$...$ $$...$$
\(...\) \[...\]
ย  \begin{equation}...\end{equation}

More math stuff

Check out Mathematical, which quickly converts itex notation equations into beautiful SVGs.

math-to-itex's People

Contributors

gjtorikian avatar skalnik avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.