calculus 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,33 +4,33 @@ Calculus is utility library which allow to parse some subset of latex equations
4
4
 
5
5
  == Installation
6
6
 
7
- gem install calculus
7
+ gem install calculus
8
8
 
9
9
  == Examples
10
10
 
11
- 001:0> require 'calculus'
12
- true
13
- 002:0> exp = Calculus::Expression.new("2 + 3 * x")
14
- #<Expression:f46e77a9377ed2d5a9da768496a7e1c20be51bfe postfix_notation=[2, 3, "x", :mul, :plus] variables={"x"=>nil}>
15
- 003:0> exp.postfix_notation
16
- [2, 3, "x", :mul, :plus]
17
- 004:0> exp.abstract_syntax_tree
18
- [:plus, 2, [:mul, 3, "x"]]
19
- 005:0> exp.variables
20
- ["x"]
21
- 006:0> exp.unbound_variables
22
- ["x"]
23
- 007:0> exp["x"] = 5
24
- 5
25
- 008:0> exp.unbound_variables
26
- []
27
- 009:0> exp.calculate
28
- 17
11
+ 001:0> require 'calculus'
12
+ true
13
+ 002:0> exp = Calculus::Expression.new("2 + 3 * x")
14
+ #<Expression:f46e77a9377ed2d5a9da768496a7e1c20be51bfe postfix_notation=[2, 3, "x", :mul, :plus] variables={"x"=>nil}>
15
+ 003:0> exp.postfix_notation
16
+ [2, 3, "x", :mul, :plus]
17
+ 004:0> exp.abstract_syntax_tree
18
+ [:plus, 2, [:mul, 3, "x"]]
19
+ 005:0> exp.variables
20
+ ["x"]
21
+ 006:0> exp.unbound_variables
22
+ ["x"]
23
+ 007:0> exp["x"] = 5
24
+ 5
25
+ 008:0> exp.unbound_variables
26
+ []
27
+ 009:0> exp.calculate
28
+ 17
29
29
 
30
30
  You can also render expression to PNG image if you have <tt>latex</tt> and <tt>dvipng</tt> installed.
31
31
 
32
- 010:0> Calculus::Expression.new("2 + 3 \\cdot x").to_png
33
- "/tmp/d20110512-16457-dhxt71/f46e77a9377ed2d5a9da768496a7e1c20be51bfe.png"
32
+ 010:0> Calculus::Expression.new("2 + 3 \\cdot x").to_png
33
+ "/tmp/d20110512-16457-dhxt71/f46e77a9377ed2d5a9da768496a7e1c20be51bfe.png"
34
34
 
35
35
  {2 + 3 \cdot x}[http://files.avsej.net/expression.png]
36
36
 
@@ -13,7 +13,7 @@ module Calculus
13
13
  \\end{document}
14
14
  EOT
15
15
 
16
- def to_png(density = 700)
16
+ def to_png(background = 'White', density = 700)
17
17
  raise CommandNotFoundError, "Required commands missing: #{missing_commands.join(', ')} in PATH. (#{ENV['PATH']})" unless missing_commands.empty?
18
18
 
19
19
  temp_path = Dir.mktmpdir
@@ -21,7 +21,7 @@ module Calculus
21
21
  File.open("#{sha1}.tex", 'w') do |f|
22
22
  f.write(TEMPLATE.sub('#', self.to_s))
23
23
  end
24
- `latex -interaction=nonstopmode #{sha1}.tex && dvipng -q -T tight -bg White -D #{density.to_i} -o #{sha1}.png #{sha1}.dvi`
24
+ `latex -interaction=nonstopmode #{sha1}.tex && dvipng -q -T tight -bg #{background} -D #{density.to_i} -o #{sha1}.png #{sha1}.dvi`
25
25
  end
26
26
  return File.join(temp_path, "#{sha1}.png") if $?.exitstatus.zero?
27
27
  ensure
@@ -1,3 +1,3 @@
1
1
  module Calculus
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: calculus
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sergey Avseyev