rubtex 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ec058f385399e5e88edfdec55d423936664e3d3
4
+ data.tar.gz: fdc16912921dd669684a9751a7659fba59183ec5
5
+ SHA512:
6
+ metadata.gz: 91afe7c194403b0e563b65685177d75c3fb36ab15fbbd90ae0665b03f87a64b100c01d4da6743fc6ef38aba47f9c579d358d33e8bd62c0fb234c3b26db1aa248
7
+ data.tar.gz: a239240ee0a17fff9ddc64679f40a8271b15ee7abc3f95ec3a73b675536c4d849295e51455681fdb2cbb0242c157d811e6f2e6315c7ee49b2c9c3da4989f35e8
data/bin/rubtex ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'rubtex'
4
+
5
+
6
+ def get_binding()
7
+ return binding
8
+ end
9
+
10
+ b = get_binding()
11
+
12
+ ('a'..'z').each {|i|
13
+ b.eval("#{i} = Variable.new(\'#{i}\')")}
14
+
15
+ loop do
16
+ begin
17
+ data = gets()
18
+ rst = (b.eval(data).to_latex())
19
+ rescue SignalException => e
20
+ raise e
21
+ rescue Exception => e
22
+ puts e.message
23
+ else
24
+ puts "-> #{rst}\n\n"
25
+ end
26
+ end
27
+
28
+
29
+
30
+
31
+
32
+
data/lib/rubtex.rb ADDED
@@ -0,0 +1,19 @@
1
+ require_relative 'rubtex/op.rb'
2
+ require_relative 'rubtex/integer.rb'
3
+ require_relative 'rubtex/variable.rb'
4
+ require_relative 'rubtex/mul.rb'
5
+ require_relative 'rubtex/sum.rb'
6
+ require_relative 'rubtex/div.rb'
7
+ require_relative 'rubtex/sub.rb'
8
+ require_relative 'rubtex/pow.rb'
9
+ require_relative 'rubtex/sqrt.rb'
10
+ require_relative 'rubtex/utils.rb'
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
data/lib/rubtex/div.rb ADDED
@@ -0,0 +1,22 @@
1
+
2
+ class Div < Op
3
+ def to_latex op=Op.new()
4
+ lhs = @lhs.to_latex(self)
5
+ rhs = @rhs.to_latex(self)
6
+
7
+ return case_parens lhs, rhs if
8
+ op.is_op?([Mul, Pow, Sqrt])
9
+
10
+ case_noparens lhs, rhs
11
+ end
12
+
13
+ def case_parens lhs, rhs
14
+ "\\left(\\frac{#{lhs}}{#{rhs}}\\right)"
15
+ end
16
+
17
+ def case_noparens lhs, rhs
18
+ "\\frac{#{lhs}}{#{rhs}}"
19
+ end
20
+ end
21
+
22
+
@@ -0,0 +1,29 @@
1
+
2
+ class Integer
3
+ def ** other
4
+ Pow.new self, other
5
+ end
6
+
7
+ def + other
8
+ Sum.new self, other
9
+ end
10
+
11
+ def - other
12
+ Sub.new self, other
13
+ end
14
+
15
+ def * other
16
+ Mul.new self, other
17
+ end
18
+
19
+ def / other
20
+ Div.new self, other
21
+ end
22
+
23
+ def to_latex op=nil
24
+ to_s()
25
+ end
26
+ end
27
+
28
+
29
+
data/lib/rubtex/mul.rb ADDED
@@ -0,0 +1,22 @@
1
+
2
+ class Mul < Op
3
+ def to_latex op=Op.new()
4
+ lhs = @lhs.to_latex(self)
5
+ rhs = @rhs.to_latex(self)
6
+
7
+ return case_parens lhs, rhs if
8
+ op.is_op?([Pow])
9
+
10
+ case_noparens lhs, rhs
11
+ end
12
+
13
+ def case_parens lhs, rhs
14
+ "\\left(#{lhs} \\cdot #{rhs}\\right)"
15
+ end
16
+
17
+ def case_noparens lhs, rhs
18
+ "#{lhs} \\cdot #{rhs}"
19
+ end
20
+ end
21
+
22
+
data/lib/rubtex/op.rb ADDED
@@ -0,0 +1,35 @@
1
+
2
+ class Op
3
+ def initialize lhs=nil, rhs=nil
4
+ @lhs = lhs
5
+ @rhs = rhs
6
+ end
7
+
8
+ def ** other
9
+ Pow.new self, other
10
+ end
11
+
12
+ def - other
13
+ Sub.new self, other
14
+ end
15
+
16
+ def + other
17
+ Sum.new self, other
18
+ end
19
+
20
+ def * other
21
+ Mul.new self, other
22
+ end
23
+
24
+ def / other
25
+ Div.new self, other
26
+ end
27
+
28
+ def is_op? args
29
+ args.any? { |ind|
30
+ self.instance_of?(ind)}
31
+ end
32
+ end
33
+
34
+
35
+
data/lib/rubtex/pow.rb ADDED
@@ -0,0 +1,24 @@
1
+
2
+ class Pow < Op
3
+ def to_latex op=Op.new()
4
+ lhs = @lhs.to_latex(self)
5
+ rhs = @rhs.to_latex(self)
6
+
7
+ return case_parens lhs, rhs if
8
+ op.is_op?([Mul, Pow, Sqrt])
9
+
10
+ case_noparens lhs, rhs
11
+ end
12
+
13
+ def case_parens lhs, rhs
14
+ "\\left({#{lhs}}^{#{rhs}}\\right)"
15
+ end
16
+
17
+ def case_noparens lhs, rhs
18
+ "{#{lhs}}^{#{rhs}}"
19
+ end
20
+ end
21
+
22
+
23
+
24
+
@@ -0,0 +1,12 @@
1
+
2
+ class Sqrt < Op
3
+ def to_latex op=Op.new()
4
+ lhs = @lhs.to_latex(self)
5
+ rhs = @rhs.to_latex(self)
6
+
7
+ "\\sqrt[#{lhs}]{#{rhs}}"
8
+ end
9
+ end
10
+
11
+
12
+
data/lib/rubtex/sub.rb ADDED
@@ -0,0 +1,23 @@
1
+
2
+ class Sub < Op
3
+ def to_latex op=Op.new()
4
+ lhs = @lhs.to_latex(self)
5
+ rhs = @rhs.to_latex(self)
6
+
7
+ return case_parens lhs, rhs if
8
+ op.is_op?([Mul, Pow])
9
+
10
+ case_noparens lhs, rhs
11
+ end
12
+
13
+ def case_parens lhs, rhs
14
+ "\\left(#{lhs} - #{rhs}\\right)"
15
+ end
16
+
17
+ def case_noparens lhs, rhs
18
+ "#{lhs} - #{rhs}"
19
+ end
20
+ end
21
+
22
+
23
+
data/lib/rubtex/sum.rb ADDED
@@ -0,0 +1,22 @@
1
+
2
+ class Sum < Op
3
+ def to_latex op=Op.new()
4
+ lhs = @lhs.to_latex(self)
5
+ rhs = @rhs.to_latex(self)
6
+
7
+ return case_parens lhs, rhs if
8
+ op.is_op?([Mul, Pow])
9
+
10
+ case_noparens lhs, rhs
11
+ end
12
+
13
+ def case_parens lhs, rhs
14
+ "\\left(#{lhs} + #{rhs}\\right)"
15
+ end
16
+
17
+ def case_noparens lhs, rhs
18
+ "#{lhs} + #{rhs}"
19
+ end
20
+ end
21
+
22
+
@@ -0,0 +1,4 @@
1
+ def sqrt lhs, rhs
2
+ Sqrt.new lhs, rhs
3
+ end
4
+
@@ -0,0 +1,35 @@
1
+
2
+ class Variable
3
+ def initialize value
4
+ @value = value
5
+ end
6
+
7
+ def ** other
8
+ Pow.new self, other
9
+ end
10
+
11
+ def - other
12
+ Sub.new self, other
13
+ end
14
+
15
+ def + other
16
+ Sum.new self, other
17
+ end
18
+
19
+ def * other
20
+ Mul.new self, other
21
+ end
22
+
23
+ def / other
24
+ Div.new self, other
25
+ end
26
+
27
+ def to_latex op=nil
28
+ @value
29
+ end
30
+ end
31
+
32
+
33
+
34
+
35
+
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubtex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Iury O. G. Figueiredo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Compile ruby into latex.
14
+ email: ioliveira@id.uff.br
15
+ executables:
16
+ - rubtex
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/rubtex
21
+ - lib/rubtex.rb
22
+ - lib/rubtex/div.rb
23
+ - lib/rubtex/integer.rb
24
+ - lib/rubtex/mul.rb
25
+ - lib/rubtex/op.rb
26
+ - lib/rubtex/pow.rb
27
+ - lib/rubtex/sqrt.rb
28
+ - lib/rubtex/sub.rb
29
+ - lib/rubtex/sum.rb
30
+ - lib/rubtex/utils.rb
31
+ - lib/rubtex/variable.rb
32
+ homepage:
33
+ licenses: []
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.6.11
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Write latex in ruby.
55
+ test_files: []