Project

calculus

0.01
No commit activity in last 3 years
No release in over 3 years
A ruby parser for TeX equations. It parses equations to postfix (reverse polish) notation and can build abstract syntax tree (AST). Also it can render images via latex. Requres modern ruby 1.9.x because of using advanced oniguruma regex engine
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

Calculus¶ ↑

Calculus is utility library which allow to parse some subset of latex equations and store them in Postfix notation It also allows translate it to Abstract syntax tree and calculate (implemented for simple expressions).

Build status: <img src=“http://travis-ci.org/avsej/calculus.png” />

Installation¶ ↑

gem install calculus

Examples¶ ↑

001:0> require 'calculus'
true
002:0> exp = Calculus::Expression.new("2 + 3 * x")
#<Expression:f46e77a9377ed2d5a9da768496a7e1c20be51bfe postfix_notation=[2, 3, "x", :mul, :plus] variables={"x"=>nil}>
003:0> exp.postfix_notation
[2, 3, "x", :mul, :plus]
004:0> exp.abstract_syntax_tree
[:plus, 2, [:mul, 3, "x"]]
005:0> exp.variables
["x"]
006:0> exp.unbound_variables
["x"]
007:0> exp["x"] = 5
5
008:0> exp.unbound_variables
[]
009:0> exp.calculate
17

You can also render expression to PNG image if you have latex and dvipng installed.

010:0> Calculus::Expression.new("2 + 3 \\cdot x").to_png
"/tmp/d20110512-16457-dhxt71/f46e77a9377ed2d5a9da768496a7e1c20be51bfe.png"

Also you can skip parser if you need only png generation

011:0> Calculus::Expression.new("\\hat{f}(\\xi) = \\int_{-\\infty}^{\\infty} f(x)\\ e^{- 2\\pi i x \\xi}\\,dx", :parse => false).to_png

{hat{f}(xi) = int_{-infty}^{infty} f(x)\ e^{- 2pi i x xi},dx}[]

Don’t forget to cleanup file after using.

Hacking¶ ↑

Just fork and pull request.