ratex 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -8
- data/examples/example.rb +7 -6
- data/images/fig1.png +0 -0
- data/images/fig2.png +0 -0
- data/images/fig3.png +0 -0
- data/lib/ratex/version.rb +1 -1
- data/lib/ratex.rb +26 -9
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f95dd94612880110256b762bb42dbf5a51b3f45
|
4
|
+
data.tar.gz: 6aadb8e921f6775fd557c0312b8c97573708e547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02d5d3776f78729ce8a7cb205ce8459fa66c1ccbf0ece13666876d1018cae591e11f9adf2226e5dde4b10b5850c93c5db9b9fbf35b355181a161a2e4d7568240
|
7
|
+
data.tar.gz: 47f82ee3af14db551d28990defd11a242b6e038ee6552c09bf35f419ca0ddfc7459c3554cfb8885472c15b9b1163e362fe740e10e0d582ea05c854fcbdee7c8b
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Ratex
|
2
2
|
|
3
|
-
|
3
|
+
You can write TeX in Ruby!
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,12 +18,25 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
```ruby
|
22
|
+
puts Ratex.generate{ f(x, y, t) == 2 * sin(pi / 4 * sqrt(x ** 2 + y ** 2) - pi / 2 * t) }
|
23
|
+
```
|
22
24
|
|
23
|
-
|
25
|
+
![enter image description here][1]
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
```ruby
|
28
|
+
puts Ratex.generate{ f[n] == f[n - 2] + f[n - 1] }
|
29
|
+
```
|
30
|
+
|
31
|
+
![enter image description here][2]
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
puts Ratex.generate{ f(x, y) == sum(i == -1, h, a_i(x, y) * g_i(x, y)) }
|
35
|
+
```
|
36
|
+
|
37
|
+
![enter image description here][3]
|
38
|
+
|
39
|
+
|
40
|
+
[1]: images/fig1.png
|
41
|
+
[2]: images/fig2.png
|
42
|
+
[3]: images/fig3.png
|
data/examples/example.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'ratex'
|
2
2
|
include Ratex
|
3
3
|
|
4
|
-
puts
|
5
|
-
puts
|
6
|
-
puts
|
7
|
-
puts
|
8
|
-
puts
|
9
|
-
puts
|
4
|
+
puts generate{ V == R * I }
|
5
|
+
puts generate{ f(x, y) == x * y }
|
6
|
+
puts generate{ f(x, y, t) == 2 * sin(pi / 4 * sqrt(x ** 2 + y ** 2) - pi / 2 * t) }
|
7
|
+
puts generate{ n! == n * fact(n - 1) }
|
8
|
+
puts generate{ f[n] == f[n - 2] + f[n - 1] }
|
9
|
+
puts generate{ e ** (i * theta) == cos(theta) + i * sin(theta) }
|
10
|
+
puts generate{ F(x, y) == sum(i == -1, h, A_i(x, y) * G_i(x, y)) }
|
data/images/fig1.png
ADDED
Binary file
|
data/images/fig2.png
ADDED
Binary file
|
data/images/fig3.png
ADDED
Binary file
|
data/lib/ratex/version.rb
CHANGED
data/lib/ratex.rb
CHANGED
@@ -3,10 +3,14 @@ require "ratex/version"
|
|
3
3
|
module Ratex
|
4
4
|
extend self
|
5
5
|
|
6
|
-
OPERATORS = [:+, :-, :*, :/, :==, :+@,
|
6
|
+
OPERATORS = [:+, :-, :*, :/, :**, :==, :+@, :-@, :<, :>]
|
7
7
|
KLASSES = [Fixnum, String, Symbol]
|
8
8
|
|
9
|
-
|
9
|
+
('A'..'Z').each do |c|
|
10
|
+
const_set(c, c)
|
11
|
+
end
|
12
|
+
|
13
|
+
def begin_generate
|
10
14
|
KLASSES.each do |klass|
|
11
15
|
klass.class_eval do
|
12
16
|
OPERATORS.each do |ope|
|
@@ -20,6 +24,7 @@ module Ratex
|
|
20
24
|
"#{self} #{ope} #{other}"
|
21
25
|
end
|
22
26
|
end
|
27
|
+
|
23
28
|
def **(other)
|
24
29
|
"#{self} ^{#{other}}"
|
25
30
|
end
|
@@ -47,7 +52,7 @@ module Ratex
|
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
50
|
-
def
|
55
|
+
def end_generate
|
51
56
|
KLASSES.each do |klass|
|
52
57
|
klass.class_eval do
|
53
58
|
OPERATORS.each do |ope|
|
@@ -63,9 +68,9 @@ module Ratex
|
|
63
68
|
class Context
|
64
69
|
|
65
70
|
def out_of_calc
|
66
|
-
|
71
|
+
end_generate
|
67
72
|
ret = yield
|
68
|
-
|
73
|
+
begin_generate
|
69
74
|
ret
|
70
75
|
end
|
71
76
|
|
@@ -91,10 +96,18 @@ module Ratex
|
|
91
96
|
"(#{expr})!"
|
92
97
|
end
|
93
98
|
|
94
|
-
def
|
99
|
+
def b1(expr)
|
95
100
|
"(#{expr})"
|
96
101
|
end
|
97
102
|
|
103
|
+
def b2(expr)
|
104
|
+
"{#{expr}}"
|
105
|
+
end
|
106
|
+
|
107
|
+
def b3(expr)
|
108
|
+
"[#{expr}]"
|
109
|
+
end
|
110
|
+
|
98
111
|
[:sin, :cos, :tan].each do |func|
|
99
112
|
define_method(func) do |expr|
|
100
113
|
out_of_calc do
|
@@ -103,6 +116,10 @@ module Ratex
|
|
103
116
|
end
|
104
117
|
end
|
105
118
|
|
119
|
+
def [](expr)
|
120
|
+
"aaa[#{expr}]"
|
121
|
+
end
|
122
|
+
|
106
123
|
def method_missing(name, *args)
|
107
124
|
out_of_calc do
|
108
125
|
ret = name.to_s
|
@@ -122,13 +139,13 @@ module Ratex
|
|
122
139
|
end
|
123
140
|
end
|
124
141
|
|
125
|
-
def
|
126
|
-
|
142
|
+
def generate(&block)
|
143
|
+
begin_generate
|
127
144
|
|
128
145
|
context = Context.new
|
129
146
|
ret = context.instance_eval(&block).to_s
|
130
147
|
|
131
|
-
|
148
|
+
end_generate
|
132
149
|
|
133
150
|
"$$" + ret + "$$"
|
134
151
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ratex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- long-long-float
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,6 +51,9 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- examples/example.rb
|
54
|
+
- images/fig1.png
|
55
|
+
- images/fig2.png
|
56
|
+
- images/fig3.png
|
54
57
|
- lib/ratex.rb
|
55
58
|
- lib/ratex/version.rb
|
56
59
|
- ratex.gemspec
|