ratex 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cf8c5a19dbb684f84eb18facbee64857f0423a9
4
- data.tar.gz: 6d5fc9f99fcf9a5a2098f05769474747ae136216
3
+ metadata.gz: 7f95dd94612880110256b762bb42dbf5a51b3f45
4
+ data.tar.gz: 6aadb8e921f6775fd557c0312b8c97573708e547
5
5
  SHA512:
6
- metadata.gz: aa286d4435997b9fedcaa66b85bcacd0ee0a53ca638940fcbbb4603b1343ed208c30234400d4d769eefec366c4c26ce59bbe618f55c80265d78ef1ae48fb882e
7
- data.tar.gz: aa77607ca6bab9491d25243e9bc913e118ebf34910a8d875bdb4a3be56e8cbf4100f22a11191c42148d7ff8530fff1a1d1ff1bd7fbfc130f72b7ef5c9b23a611
6
+ metadata.gz: 02d5d3776f78729ce8a7cb205ce8459fa66c1ccbf0ece13666876d1018cae591e11f9adf2226e5dde4b10b5850c93c5db9b9fbf35b355181a161a2e4d7568240
7
+ data.tar.gz: 47f82ee3af14db551d28990defd11a242b6e038ee6552c09bf35f419ca0ddfc7459c3554cfb8885472c15b9b1163e362fe740e10e0d582ea05c854fcbdee7c8b
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ratex
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
- ## Contributing
25
+ ![enter image description here][1]
24
26
 
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
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 calc{ f(x, y) == x * y }
5
- puts calc{ f(x, y, t) == 2 * sin(pi / 4 * sqrt(x ** 2 + y ** 2) - pi / 2 * t) }
6
- puts calc{ n! == n * fact(n - 1) }
7
- puts calc{ f[n] == f[n - 2] + f[n - 1] }
8
- puts calc{ e ** (i * theta) == cos(theta) + i * sin(theta) }
9
- puts calc{ f(x, y) == sum(i == -1, h, a_i(x, y) * g_i(x, y)) }
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
@@ -1,3 +1,3 @@
1
1
  module Ratex
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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
- def begin_calc
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 end_calc
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
- end_calc
71
+ end_generate
67
72
  ret = yield
68
- begin_calc
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 b(expr)
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 calc(&block)
126
- begin_calc
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
- end_calc
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.1
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-14 00:00:00.000000000 Z
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