plurimath 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +13 -0
- data/.github/workflows/release.yml +22 -0
- data/.gitignore +1 -0
- data/.hound.yml +5 -0
- data/.rubocop.yml +8 -0
- data/AsciiMath-Supported-Data.adoc +2000 -0
- data/Gemfile +3 -0
- data/Latex-Supported-Data.adoc +1879 -0
- data/MathML-Supported-Data.adoc +287 -0
- data/README.adoc +96 -0
- data/lib/plurimath/asciimath/constants.rb +267 -229
- data/lib/plurimath/asciimath/parse.rb +125 -26
- data/lib/plurimath/asciimath/parser.rb +6 -3
- data/lib/plurimath/asciimath/transform.rb +1135 -208
- data/lib/plurimath/asciimath.rb +1 -1
- data/lib/plurimath/html/constants.rb +50 -0
- data/lib/plurimath/html/parse.rb +149 -0
- data/lib/plurimath/html/parser.rb +26 -0
- data/lib/plurimath/html/transform.rb +363 -0
- data/lib/plurimath/html.rb +1 -1
- data/lib/plurimath/latex/constants.rb +3729 -1906
- data/lib/plurimath/latex/parse.rb +167 -51
- data/lib/plurimath/latex/parser.rb +12 -4
- data/lib/plurimath/latex/transform.rb +598 -183
- data/lib/plurimath/math/base.rb +15 -0
- data/lib/plurimath/math/formula.rb +96 -11
- data/lib/plurimath/math/function/bar.rb +34 -0
- data/lib/plurimath/math/function/base.rb +32 -5
- data/lib/plurimath/math/function/binary_function.rb +104 -17
- data/lib/plurimath/math/function/cancel.rb +8 -0
- data/lib/plurimath/math/function/ceil.rb +3 -0
- data/lib/plurimath/math/function/color.rb +16 -6
- data/lib/plurimath/math/function/f.rb +8 -0
- data/lib/plurimath/math/function/fenced.rb +95 -3
- data/lib/plurimath/math/function/floor.rb +15 -0
- data/lib/plurimath/math/function/font_style/bold.rb +37 -0
- data/lib/plurimath/math/function/font_style/double_struck.rb +37 -0
- data/lib/plurimath/math/function/font_style/fraktur.rb +37 -0
- data/lib/plurimath/math/function/font_style/italic.rb +37 -0
- data/lib/plurimath/math/function/font_style/monospace.rb +37 -0
- data/lib/plurimath/math/function/font_style/normal.rb +37 -0
- data/lib/plurimath/math/function/font_style/sans-serif.rb +37 -0
- data/lib/plurimath/math/function/font_style/script.rb +37 -0
- data/lib/plurimath/math/function/font_style.rb +18 -25
- data/lib/plurimath/math/function/frac.rb +35 -5
- data/lib/plurimath/math/function/g.rb +7 -0
- data/lib/plurimath/math/function/hat.rb +12 -0
- data/lib/plurimath/math/function/inf.rb +21 -1
- data/lib/plurimath/math/function/int.rb +23 -2
- data/lib/plurimath/math/function/left.rb +25 -4
- data/lib/plurimath/math/function/lim.rb +40 -2
- data/lib/plurimath/math/function/limits.rb +8 -0
- data/lib/plurimath/math/function/log.rb +61 -4
- data/lib/plurimath/math/function/longdiv.rb +12 -0
- data/lib/plurimath/math/function/mbox.rb +31 -0
- data/lib/plurimath/math/function/menclose.rb +46 -0
- data/lib/plurimath/math/function/merror.rb +12 -0
- data/lib/plurimath/math/function/mod.rb +25 -4
- data/lib/plurimath/math/function/msgroup.rb +37 -0
- data/lib/plurimath/math/function/msline.rb +12 -0
- data/lib/plurimath/math/function/multiscript.rb +30 -0
- data/lib/plurimath/math/function/norm.rb +18 -1
- data/lib/plurimath/math/function/obrace.rb +17 -0
- data/lib/plurimath/math/function/oint.rb +2 -2
- data/lib/plurimath/math/function/over.rb +36 -0
- data/lib/plurimath/math/function/overset.rb +36 -7
- data/lib/plurimath/math/function/phantom.rb +28 -0
- data/lib/plurimath/math/function/power.rb +33 -9
- data/lib/plurimath/math/function/power_base.rb +110 -5
- data/lib/plurimath/math/function/prod.rb +29 -2
- data/lib/plurimath/math/function/right.rb +44 -0
- data/lib/plurimath/math/function/root.rb +27 -4
- data/lib/plurimath/math/function/rule.rb +33 -0
- data/lib/plurimath/math/function/scarries.rb +12 -0
- data/lib/plurimath/math/function/scarry.rb +12 -0
- data/lib/plurimath/math/function/sqrt.rb +24 -2
- data/lib/plurimath/math/function/stackrel.rb +27 -0
- data/lib/plurimath/math/function/substack.rb +7 -1
- data/lib/plurimath/math/function/sum.rb +56 -2
- data/lib/plurimath/math/function/sup.rb +3 -0
- data/lib/plurimath/math/function/table/align.rb +24 -0
- data/lib/plurimath/math/function/table/array.rb +44 -0
- data/lib/plurimath/math/function/table/bmatrix.rb +37 -0
- data/lib/plurimath/math/function/table/matrix.rb +32 -0
- data/lib/plurimath/math/function/table/multline.rb +24 -0
- data/lib/plurimath/math/function/table/pmatrix.rb +24 -0
- data/lib/plurimath/math/function/table/split.rb +24 -0
- data/lib/plurimath/math/function/table/vmatrix.rb +24 -0
- data/lib/plurimath/math/function/table.rb +190 -20
- data/lib/plurimath/math/function/td.rb +27 -9
- data/lib/plurimath/math/function/ternary_function.rb +83 -8
- data/lib/plurimath/math/function/text.rb +45 -8
- data/lib/plurimath/math/function/tr.rb +28 -4
- data/lib/plurimath/math/function/ubrace.rb +17 -0
- data/lib/plurimath/math/function/ul.rb +29 -0
- data/lib/plurimath/math/function/unary_function.rb +85 -7
- data/lib/plurimath/math/function/underline.rb +12 -0
- data/lib/plurimath/math/function/underover.rb +107 -0
- data/lib/plurimath/math/function/underset.rb +39 -0
- data/lib/plurimath/math/function/vec.rb +10 -0
- data/lib/plurimath/math/function.rb +13 -2
- data/lib/plurimath/math/number.rb +11 -3
- data/lib/plurimath/math/symbol.rb +57 -9
- data/lib/plurimath/math/unicode.rb +11 -0
- data/lib/plurimath/math.rb +15 -6
- data/lib/plurimath/mathml/constants.rb +224 -179
- data/lib/plurimath/mathml/parser.rb +24 -7
- data/lib/plurimath/mathml/transform.rb +249 -148
- data/lib/plurimath/mathml.rb +1 -1
- data/lib/plurimath/omml/parser.rb +42 -0
- data/lib/plurimath/omml/transform.rb +278 -0
- data/lib/plurimath/omml.rb +1 -1
- data/lib/plurimath/unitsml.rb +4 -0
- data/lib/plurimath/utility.rb +395 -0
- data/lib/plurimath/version.rb +1 -1
- data/plurimath.gemspec +1 -0
- metadata +66 -9
- data/.github/workflows/test.yml +0 -36
- data/README.md +0 -40
- data/lib/plurimath/mathml/parse.rb +0 -63
@@ -3,176 +3,537 @@
|
|
3
3
|
module Plurimath
|
4
4
|
class Latex
|
5
5
|
class Transform < Parslet::Transform
|
6
|
-
rule(base: simple(:base))
|
7
|
-
rule(
|
8
|
-
rule(number: simple(:num))
|
9
|
-
rule(power: simple(:power))
|
10
|
-
rule(
|
11
|
-
rule(
|
12
|
-
rule(
|
13
|
-
rule(
|
6
|
+
rule(base: simple(:base)) { base }
|
7
|
+
rule(over: simple(:over)) { over }
|
8
|
+
rule(number: simple(:num)) { Math::Number.new(num) }
|
9
|
+
rule(power: simple(:power)) { power }
|
10
|
+
rule(unary: simple(:unary)) { Utility.get_class(unary).new }
|
11
|
+
rule(space: simple(:space)) { Math::Function::Text.new(" ") }
|
12
|
+
rule(operant: simple(:oper)) { Math::Symbol.new(oper) }
|
13
|
+
rule(symbol: simple(:symbol)) { Math::Symbol.new(symbol) }
|
14
|
+
rule(lparen: simple(:lparen)) { Math::Symbol.new(lparen) }
|
15
|
+
rule(rparen: simple(:rparen)) { Math::Symbol.new(rparen) }
|
16
|
+
rule(limits: simple(:limits)) { limits }
|
17
|
+
rule("\\\\" => simple(:slash)) { Math::Symbol.new(slash) }
|
18
|
+
rule(expression: simple(:expr)) { expr }
|
19
|
+
rule(environment: simple(:env)) { env }
|
20
|
+
|
21
|
+
rule(unary_functions: simple(:unary)) { unary }
|
22
|
+
rule(left_right: simple(:left_right)) { left_right }
|
23
|
+
rule(under_over: simple(:under_over)) { under_over }
|
24
|
+
rule(power_base: simple(:power_base)) { power_base }
|
25
|
+
rule(table_data: simple(:table_data)) { table_data }
|
26
|
+
|
27
|
+
rule(numeric_values: simple(:value)) do
|
28
|
+
Math::Symbol.new(value)
|
29
|
+
end
|
30
|
+
|
31
|
+
rule(text: simple(:text)) do
|
32
|
+
Math::Function::Text.new(text)
|
33
|
+
end
|
34
|
+
|
35
|
+
rule(unicode_symbols: simple(:unicode)) do
|
36
|
+
Math::Unicode.new(unicode)
|
37
|
+
end
|
38
|
+
|
14
39
|
rule(binary: simple(:binary)) do
|
15
|
-
binary.is_a?(Slice) ?
|
40
|
+
binary.is_a?(Parslet::Slice) ? Utility.get_class(binary).new : binary
|
16
41
|
end
|
17
|
-
rule("\\\\" => simple(:slash)) { Math::Symbol.new(slash.to_s) }
|
18
42
|
|
19
|
-
rule(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
43
|
+
rule(symbols: simple(:sym)) do
|
44
|
+
if sym.is_a?(Parslet::Slice)
|
45
|
+
Math::Symbol.new(
|
46
|
+
Constants::UNICODE_SYMBOLS[sym.to_sym] || sym,
|
47
|
+
)
|
48
|
+
else
|
49
|
+
sym
|
50
|
+
end
|
51
|
+
end
|
26
52
|
|
27
|
-
rule(
|
28
|
-
|
53
|
+
rule(lparen: simple(:lparen),
|
54
|
+
rparen: simple(:rparen)) do
|
55
|
+
[]
|
29
56
|
end
|
30
57
|
|
31
|
-
rule(
|
32
|
-
|
58
|
+
rule(left_right: simple(:left_right),
|
59
|
+
subscript: simple(:subscript)) do
|
60
|
+
Math::Function::Base.new(
|
61
|
+
left_right,
|
62
|
+
subscript,
|
63
|
+
)
|
33
64
|
end
|
34
65
|
|
35
|
-
rule(
|
36
|
-
|
37
|
-
Math::Function::
|
66
|
+
rule(left_right: simple(:left_right),
|
67
|
+
supscript: simple(:supscript)) do
|
68
|
+
Math::Function::Power.new(
|
69
|
+
left_right,
|
70
|
+
supscript,
|
71
|
+
)
|
38
72
|
end
|
39
73
|
|
40
|
-
rule(
|
41
|
-
|
42
|
-
|
74
|
+
rule(left: simple(:left),
|
75
|
+
lparen: simple(:lparen),
|
76
|
+
expression: sequence(:expr),
|
77
|
+
right: simple(:right),
|
78
|
+
rparen: simple(:rparen)) do
|
79
|
+
Math::Formula.new(
|
80
|
+
[
|
81
|
+
Math::Function::Left.new(lparen),
|
82
|
+
Math::Formula.new(expr),
|
83
|
+
Math::Function::Right.new(rparen),
|
84
|
+
],
|
85
|
+
)
|
43
86
|
end
|
44
87
|
|
45
|
-
rule(
|
46
|
-
|
47
|
-
|
88
|
+
rule(left: simple(:left),
|
89
|
+
lparen: simple(:lparen),
|
90
|
+
right: simple(:right)) do
|
91
|
+
Math::Formula.new(
|
92
|
+
[
|
93
|
+
Math::Function::Left.new(lparen),
|
94
|
+
Math::Function::Right.new,
|
95
|
+
],
|
96
|
+
)
|
48
97
|
end
|
49
98
|
|
50
|
-
rule(
|
51
|
-
|
52
|
-
|
99
|
+
rule(left: simple(:left),
|
100
|
+
lparen: simple(:lparen),
|
101
|
+
right: simple(:right),
|
102
|
+
rparen: simple(:rparen)) do
|
103
|
+
Math::Formula.new(
|
104
|
+
[
|
105
|
+
Math::Function::Left.new(lparen),
|
106
|
+
Math::Function::Right.new(rparen),
|
107
|
+
],
|
108
|
+
)
|
53
109
|
end
|
54
110
|
|
55
|
-
rule(
|
56
|
-
|
57
|
-
|
111
|
+
rule(left: simple(:left),
|
112
|
+
lparen: simple(:lparen)) do
|
113
|
+
Math::Function::Left.new(lparen)
|
58
114
|
end
|
59
115
|
|
60
|
-
rule(
|
61
|
-
|
116
|
+
rule(left: simple(:left),
|
117
|
+
lparen: simple(:lparen),
|
118
|
+
expression: simple(:expr),
|
119
|
+
right: simple(:right),
|
120
|
+
rparen: simple(:rparen)) do
|
121
|
+
Math::Formula.new(
|
122
|
+
[
|
123
|
+
Math::Function::Left.new(lparen),
|
124
|
+
expr,
|
125
|
+
Math::Function::Right.new(rparen),
|
126
|
+
],
|
127
|
+
)
|
62
128
|
end
|
63
129
|
|
64
|
-
rule(
|
65
|
-
|
66
|
-
|
67
|
-
|
130
|
+
rule(power: simple(:power),
|
131
|
+
number: simple(:number)) do
|
132
|
+
Math::Function::Power.new(
|
133
|
+
power,
|
134
|
+
Math::Number.new(number),
|
135
|
+
)
|
68
136
|
end
|
69
137
|
|
70
|
-
rule(
|
71
|
-
|
138
|
+
rule(power: simple(:power),
|
139
|
+
expression: simple(:expr)) do
|
140
|
+
Math::Function::Power.new(
|
141
|
+
power,
|
142
|
+
expr,
|
143
|
+
)
|
72
144
|
end
|
73
145
|
|
74
|
-
rule(
|
75
|
-
|
146
|
+
rule(base: simple(:base),
|
147
|
+
expression: simple(:expr)) do
|
148
|
+
Math::Function::Base.new(
|
149
|
+
base,
|
150
|
+
expr,
|
151
|
+
)
|
76
152
|
end
|
77
153
|
|
78
|
-
rule(
|
79
|
-
|
80
|
-
|
81
|
-
Plurimath::Math::Function::Limits.new(
|
82
|
-
Transform.get_class(unary).new,
|
154
|
+
rule(base: simple(:base),
|
155
|
+
expression: sequence(:expr)) do
|
156
|
+
Math::Function::Base.new(
|
83
157
|
base,
|
158
|
+
Utility.filter_values(expr),
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
rule(power: simple(:power),
|
163
|
+
expression: sequence(:expr)) do
|
164
|
+
Math::Function::Power.new(
|
84
165
|
power,
|
166
|
+
Utility.filter_values(expr),
|
85
167
|
)
|
86
168
|
end
|
87
169
|
|
88
|
-
rule(
|
89
|
-
|
170
|
+
rule(left: simple(:left),
|
171
|
+
lparen: simple(:lparen),
|
172
|
+
dividend: subtree(:dividend),
|
173
|
+
divisor: subtree(:divisor),
|
174
|
+
right: simple(:right),
|
90
175
|
rparen: simple(:rparen)) do
|
91
|
-
Math::
|
176
|
+
Math::Formula.new(
|
177
|
+
[
|
178
|
+
Math::Function::Left.new(lparen),
|
179
|
+
Math::Function::Over.new(
|
180
|
+
Math::Formula.new(
|
181
|
+
Array(dividend).flatten,
|
182
|
+
),
|
183
|
+
Math::Formula.new(
|
184
|
+
Array(divisor).flatten,
|
185
|
+
),
|
186
|
+
),
|
187
|
+
Math::Function::Right.new(rparen),
|
188
|
+
],
|
189
|
+
)
|
92
190
|
end
|
93
191
|
|
94
|
-
rule(
|
95
|
-
|
96
|
-
|
97
|
-
|
192
|
+
rule(dividend: subtree(:dividend),
|
193
|
+
divisor: subtree(:divisor)) do
|
194
|
+
Math::Function::Over.new(
|
195
|
+
Math::Formula.new(
|
196
|
+
Array(dividend).flatten,
|
197
|
+
),
|
198
|
+
Math::Formula.new(
|
199
|
+
Array(divisor).flatten,
|
200
|
+
),
|
201
|
+
)
|
98
202
|
end
|
99
203
|
|
100
|
-
rule(
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
until value.nil?
|
106
|
-
if value.first.is_a?(Plurimath::Math::Symbol) &&
|
107
|
-
value.first.value == "\\\\"
|
108
|
-
value.delete_at(0)
|
109
|
-
break;
|
110
|
-
else
|
111
|
-
first_value << value.delete_at(0)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
Transform.get_class(substack).new(
|
115
|
-
Math::Formula.new(first_value),
|
116
|
-
Math::Formula.new(value)
|
204
|
+
rule(over: simple(:over),
|
205
|
+
subscript: simple(:subscript)) do
|
206
|
+
Math::Function::Base.new(
|
207
|
+
over,
|
208
|
+
subscript,
|
117
209
|
)
|
118
210
|
end
|
119
211
|
|
120
|
-
rule(
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
212
|
+
rule(over: simple(:over),
|
213
|
+
supscript: simple(:supscript)) do
|
214
|
+
Math::Function::Power.new(
|
215
|
+
over,
|
216
|
+
supscript,
|
217
|
+
)
|
125
218
|
end
|
126
219
|
|
127
|
-
rule(
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
220
|
+
rule(operant: simple(:operant),
|
221
|
+
subscript: simple(:subscript)) do
|
222
|
+
Math::Function::Base.new(
|
223
|
+
Math::Symbol.new(operant),
|
224
|
+
subscript,
|
225
|
+
)
|
132
226
|
end
|
133
227
|
|
134
|
-
rule(
|
135
|
-
expression: simple(:expr)
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
228
|
+
rule(sequence: simple(:sequence),
|
229
|
+
expression: simple(:expr)) do
|
230
|
+
[sequence, expr].compact
|
231
|
+
end
|
232
|
+
|
233
|
+
rule(sequence: simple(:sequence),
|
234
|
+
expression: sequence(:expr)) do
|
235
|
+
[sequence] + expr
|
236
|
+
end
|
237
|
+
|
238
|
+
rule(unary_functions: simple(:unary),
|
239
|
+
subscript: simple(:subscript)) do
|
240
|
+
unary_function = if unary.is_a?(Parslet::Slice)
|
241
|
+
Utility.get_class(unary).new
|
242
|
+
else
|
243
|
+
unary
|
244
|
+
end
|
245
|
+
Math::Function::Base.new(
|
246
|
+
unary_function,
|
247
|
+
subscript,
|
248
|
+
)
|
249
|
+
end
|
250
|
+
|
251
|
+
rule(binary_functions: simple(:binary),
|
252
|
+
supscript: simple(:supscript)) do
|
253
|
+
Math::Function::Power.new(
|
254
|
+
binary,
|
255
|
+
supscript,
|
256
|
+
)
|
257
|
+
end
|
258
|
+
|
259
|
+
rule(unary_functions: simple(:unary),
|
260
|
+
supscript: simple(:supscript)) do
|
261
|
+
Math::Function::Power.new(
|
262
|
+
unary,
|
263
|
+
supscript,
|
264
|
+
)
|
265
|
+
end
|
266
|
+
|
267
|
+
rule(unary_functions: simple(:unary),
|
268
|
+
subscript: simple(:subscript),
|
269
|
+
supscript: simple(:supscript)) do
|
270
|
+
Math::Function::PowerBase.new(
|
271
|
+
unary,
|
272
|
+
subscript,
|
273
|
+
supscript,
|
274
|
+
)
|
275
|
+
end
|
276
|
+
|
277
|
+
rule(fonts: simple(:fonts),
|
278
|
+
intermediate_exp: simple(:int_exp)) do
|
279
|
+
if Utility::FONT_STYLES[fonts.to_sym]
|
280
|
+
Utility::FONT_STYLES[fonts.to_sym].new(
|
281
|
+
int_exp,
|
282
|
+
fonts.to_s,
|
148
283
|
)
|
149
284
|
else
|
150
|
-
|
285
|
+
Math::Function::FontStyle.new(
|
286
|
+
int_exp,
|
287
|
+
fonts.to_s,
|
288
|
+
)
|
151
289
|
end
|
152
290
|
end
|
153
291
|
|
292
|
+
rule(number: simple(:number),
|
293
|
+
subscript: simple(:subscript)) do
|
294
|
+
Math::Function::Base.new(
|
295
|
+
Math::Number.new(number),
|
296
|
+
subscript,
|
297
|
+
)
|
298
|
+
end
|
299
|
+
|
300
|
+
rule(number: simple(:number),
|
301
|
+
supscript: simple(:supscript)) do
|
302
|
+
Math::Function::Power.new(
|
303
|
+
Math::Number.new(number),
|
304
|
+
supscript,
|
305
|
+
)
|
306
|
+
end
|
307
|
+
|
308
|
+
rule(symbols: simple(:sym),
|
309
|
+
subscript: simple(:subscript)) do
|
310
|
+
Math::Function::Base.new(
|
311
|
+
Math::Symbol.new(
|
312
|
+
Constants::UNICODE_SYMBOLS[sym.to_sym] || sym,
|
313
|
+
),
|
314
|
+
subscript,
|
315
|
+
)
|
316
|
+
end
|
317
|
+
|
318
|
+
rule(numeric_values: simple(:value),
|
319
|
+
subscript: simple(:subscript)) do
|
320
|
+
Math::Function::Base.new(
|
321
|
+
Math::Symbol.new(value),
|
322
|
+
subscript,
|
323
|
+
)
|
324
|
+
end
|
325
|
+
|
326
|
+
rule(symbols: simple(:sym),
|
327
|
+
supscript: simple(:supscript)) do
|
328
|
+
Math::Function::Power.new(
|
329
|
+
Math::Symbol.new(
|
330
|
+
Constants::UNICODE_SYMBOLS[sym.to_sym] || sym,
|
331
|
+
),
|
332
|
+
supscript,
|
333
|
+
)
|
334
|
+
end
|
335
|
+
|
336
|
+
rule(unicode_symbols: simple(:sym),
|
337
|
+
subscript: simple(:subscript)) do
|
338
|
+
Math::Function::Base.new(
|
339
|
+
Math::Unicode.new(sym),
|
340
|
+
subscript,
|
341
|
+
)
|
342
|
+
end
|
343
|
+
|
344
|
+
rule(unicode_symbols: simple(:sym),
|
345
|
+
supscript: simple(:supscript)) do
|
346
|
+
Math::Function::Power.new(
|
347
|
+
Math::Unicode.new(sym),
|
348
|
+
supscript,
|
349
|
+
)
|
350
|
+
end
|
351
|
+
|
352
|
+
rule(numeric_values: simple(:value),
|
353
|
+
supscript: simple(:supscript)) do
|
354
|
+
Math::Function::Power.new(
|
355
|
+
Math::Symbol.new(value),
|
356
|
+
supscript,
|
357
|
+
)
|
358
|
+
end
|
359
|
+
|
360
|
+
rule(unary: simple(:unary),
|
361
|
+
first_value: simple(:first_value)) do
|
362
|
+
Utility.get_class(
|
363
|
+
unary == "overline" ? "bar" : unary,
|
364
|
+
).new(first_value)
|
365
|
+
end
|
366
|
+
|
367
|
+
rule(sqrt: simple(:sqrt),
|
368
|
+
intermediate_exp: simple(:int_exp)) do
|
369
|
+
Math::Function::Sqrt.new(int_exp)
|
370
|
+
end
|
371
|
+
|
372
|
+
rule(fonts: simple(:fonts),
|
373
|
+
intermediate_exp: simple(:int_exp),
|
374
|
+
supscript: simple(:supscript)) do
|
375
|
+
font_style = if Utility::FONT_STYLES[fonts.to_sym].nil?
|
376
|
+
Math::Function::FontStyle.new(
|
377
|
+
int_exp,
|
378
|
+
fonts.to_s,
|
379
|
+
)
|
380
|
+
else
|
381
|
+
Utility::FONT_STYLES[fonts.to_sym].new(
|
382
|
+
int_exp,
|
383
|
+
fonts.to_s,
|
384
|
+
)
|
385
|
+
end
|
386
|
+
Math::Function::Power.new(
|
387
|
+
font_style,
|
388
|
+
supscript,
|
389
|
+
)
|
390
|
+
end
|
391
|
+
|
392
|
+
rule(fonts: simple(:fonts),
|
393
|
+
intermediate_exp: simple(:int_exp),
|
394
|
+
subscript: simple(:subscript)) do
|
395
|
+
font_style = if Utility::FONT_STYLES[fonts.to_sym].nil?
|
396
|
+
Math::Function::FontStyle.new(
|
397
|
+
int_exp,
|
398
|
+
fonts.to_s,
|
399
|
+
)
|
400
|
+
else
|
401
|
+
Utility::FONT_STYLES[fonts.to_sym].new(
|
402
|
+
int_exp,
|
403
|
+
fonts.to_s,
|
404
|
+
)
|
405
|
+
end
|
406
|
+
Math::Function::Base.new(
|
407
|
+
font_style,
|
408
|
+
subscript,
|
409
|
+
)
|
410
|
+
end
|
411
|
+
|
412
|
+
rule(root: simple(:root),
|
413
|
+
first_value: simple(:first_value),
|
414
|
+
second_value: simple(:second_value)) do
|
415
|
+
second = second_value.nil? ? Math::Formula.new : second_value
|
416
|
+
Math::Function::Root.new(
|
417
|
+
first_value,
|
418
|
+
second,
|
419
|
+
)
|
420
|
+
end
|
421
|
+
|
422
|
+
rule(root: simple(:root),
|
423
|
+
first_value: sequence(:first_value),
|
424
|
+
second_value: simple(:second_value)) do
|
425
|
+
first = Utility.filter_values(first_value)
|
426
|
+
first = first.nil? ? Math::Formula.new : first
|
427
|
+
Math::Function::Root.new(
|
428
|
+
first,
|
429
|
+
second_value,
|
430
|
+
)
|
431
|
+
end
|
432
|
+
|
433
|
+
rule(first_value: simple(:first_value),
|
434
|
+
base: simple(:base),
|
435
|
+
power: simple(:power)) do
|
436
|
+
Math::Function::Limits.new(
|
437
|
+
first_value,
|
438
|
+
base,
|
439
|
+
power,
|
440
|
+
)
|
441
|
+
end
|
442
|
+
|
154
443
|
rule(lparen: simple(:lparen),
|
155
444
|
expression: sequence(:expr),
|
156
445
|
rparen: simple(:rparen)) do
|
157
446
|
Math::Formula.new(expr)
|
158
447
|
end
|
159
448
|
|
449
|
+
rule(expression: sequence(:expr)) do
|
450
|
+
Math::Formula.new(expr)
|
451
|
+
end
|
452
|
+
|
453
|
+
rule(rule: simple(:rule),
|
454
|
+
first_value: simple(:first_value),
|
455
|
+
second_value: simple(:second_value),
|
456
|
+
third_value: simple(:third_value)) do
|
457
|
+
Math::Function::Rule.new(
|
458
|
+
first_value,
|
459
|
+
second_value,
|
460
|
+
third_value,
|
461
|
+
)
|
462
|
+
end
|
463
|
+
|
464
|
+
rule(expression: simple(:expression),
|
465
|
+
subscript: simple(:subscript)) do
|
466
|
+
Math::Function::Base.new(
|
467
|
+
expression,
|
468
|
+
subscript,
|
469
|
+
)
|
470
|
+
end
|
471
|
+
|
472
|
+
rule(rparen: simple(:rparen),
|
473
|
+
supscript: simple(:supscript)) do
|
474
|
+
Math::Function::Power.new(
|
475
|
+
Math::Symbol.new(rparen),
|
476
|
+
supscript,
|
477
|
+
)
|
478
|
+
end
|
479
|
+
|
480
|
+
rule(expression: simple(:expr),
|
481
|
+
supscript: simple(:supscript)) do
|
482
|
+
Math::Function::Power.new(
|
483
|
+
expr,
|
484
|
+
supscript,
|
485
|
+
)
|
486
|
+
end
|
487
|
+
|
488
|
+
rule(expression: sequence(:expr),
|
489
|
+
supscript: simple(:supscript)) do
|
490
|
+
Math::Function::Power.new(
|
491
|
+
Utility.filter_values(expr),
|
492
|
+
supscript,
|
493
|
+
)
|
494
|
+
end
|
495
|
+
|
160
496
|
rule(binary: simple(:binary),
|
161
497
|
subscript: simple(:subscript),
|
162
498
|
supscript: simple(:supscript)) do
|
163
|
-
|
499
|
+
Utility.get_class(binary).new(
|
500
|
+
subscript,
|
501
|
+
supscript,
|
502
|
+
)
|
164
503
|
end
|
165
504
|
|
166
505
|
rule(binary: simple(:binary),
|
167
506
|
subscript: simple(:subscript)) do
|
168
|
-
|
507
|
+
if binary.is_a?(Parslet::Slice)
|
508
|
+
Utility.get_class(binary).new(subscript)
|
509
|
+
else
|
510
|
+
Math::Function::Base.new(
|
511
|
+
binary,
|
512
|
+
subscript,
|
513
|
+
)
|
514
|
+
end
|
169
515
|
end
|
170
516
|
|
171
|
-
rule(
|
517
|
+
rule(symbols: simple(:sym),
|
172
518
|
subscript: simple(:subscript),
|
173
519
|
supscript: simple(:supscript)) do
|
174
|
-
|
175
|
-
|
520
|
+
Math::Function::PowerBase.new(
|
521
|
+
Math::Symbol.new(
|
522
|
+
Constants::UNICODE_SYMBOLS[sym.to_sym] || sym,
|
523
|
+
),
|
524
|
+
subscript,
|
525
|
+
supscript,
|
526
|
+
)
|
527
|
+
end
|
528
|
+
|
529
|
+
rule(unicode_symbols: simple(:sym),
|
530
|
+
subscript: simple(:subscript),
|
531
|
+
supscript: simple(:supscript)) do
|
532
|
+
Math::Function::PowerBase.new(
|
533
|
+
Math::Unicode.new(sym),
|
534
|
+
subscript,
|
535
|
+
supscript,
|
536
|
+
)
|
176
537
|
end
|
177
538
|
|
178
539
|
rule(binary: simple(:binary),
|
@@ -180,118 +541,172 @@ module Plurimath
|
|
180
541
|
second_value: simple(:second_value)) do
|
181
542
|
if binary == "binom"
|
182
543
|
Math::Function::Table.new(
|
183
|
-
[
|
184
|
-
|
544
|
+
[
|
545
|
+
Math::Function::Tr.new(
|
546
|
+
Utility.table_td(first_value),
|
547
|
+
),
|
548
|
+
Math::Function::Tr.new(
|
549
|
+
Utility.table_td(second_value),
|
550
|
+
),
|
551
|
+
],
|
185
552
|
"(",
|
186
553
|
")",
|
187
554
|
)
|
188
555
|
else
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
end
|
196
|
-
Transform.get_class(binary_class).new(first_value, second_value)
|
556
|
+
Utility.get_class(
|
557
|
+
binary.to_s.include?("mod") ? "mod" : binary,
|
558
|
+
).new(
|
559
|
+
first_value,
|
560
|
+
second_value,
|
561
|
+
)
|
197
562
|
end
|
198
563
|
end
|
199
564
|
|
200
|
-
rule(
|
565
|
+
rule(underover: simple(:function),
|
566
|
+
first_value: simple(:first),
|
567
|
+
subscript: simple(:subscript),
|
568
|
+
supscript: simple(:supscript)) do
|
569
|
+
Math::Function::PowerBase.new(
|
570
|
+
Utility.get_class(function).new(first),
|
571
|
+
subscript,
|
572
|
+
supscript,
|
573
|
+
)
|
574
|
+
end
|
575
|
+
|
576
|
+
rule(environment: simple(:environment),
|
201
577
|
table_data: sequence(:table_data),
|
202
578
|
ending: simple(:ending)) do
|
203
|
-
|
204
|
-
|
579
|
+
open_paren = Constants::MATRICES[environment.to_sym]
|
580
|
+
Utility.get_table_class(environment).new(
|
581
|
+
Utility.organize_table(table_data),
|
582
|
+
open_paren,
|
583
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
584
|
+
{},
|
585
|
+
)
|
205
586
|
end
|
206
587
|
|
207
|
-
rule(
|
208
|
-
|
209
|
-
|
210
|
-
|
588
|
+
rule(environment: simple(:environment),
|
589
|
+
args: simple(:args),
|
590
|
+
table_data: simple(:table_data),
|
591
|
+
ending: simple(:ending)) do
|
592
|
+
third_value = args ? [args] : []
|
593
|
+
open_paren = Constants::MATRICES[environment.to_sym]
|
594
|
+
table = Utility.organize_table(
|
595
|
+
[table_data],
|
596
|
+
column_align: third_value,
|
597
|
+
)
|
598
|
+
Utility.get_table_class(environment).new(
|
599
|
+
table,
|
600
|
+
open_paren,
|
601
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
602
|
+
Utility.table_options(table),
|
603
|
+
)
|
211
604
|
end
|
212
605
|
|
213
|
-
rule(
|
214
|
-
args: simple(:args),
|
606
|
+
rule(environment: simple(:environment),
|
215
607
|
table_data: simple(:table_data),
|
216
608
|
ending: simple(:ending)) do
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
609
|
+
open_paren = Constants::MATRICES[environment.to_sym]
|
610
|
+
Utility.get_table_class(environment).new(
|
611
|
+
Utility.organize_table([table_data]),
|
612
|
+
open_paren,
|
613
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
614
|
+
)
|
221
615
|
end
|
222
616
|
|
223
|
-
rule(
|
617
|
+
rule(environment: simple(:environment),
|
224
618
|
args: sequence(:args),
|
225
619
|
table_data: sequence(:table_data),
|
226
620
|
ending: simple(:ending)) do
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
621
|
+
open_paren = Constants::MATRICES[environment.to_sym]
|
622
|
+
table = Utility.organize_table(table_data, column_align: args)
|
623
|
+
Utility.get_table_class(environment).new(
|
624
|
+
table,
|
625
|
+
open_paren,
|
626
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
627
|
+
Utility.table_options(table),
|
628
|
+
)
|
231
629
|
end
|
232
630
|
|
233
|
-
rule(
|
631
|
+
rule(environment: simple(:environment),
|
234
632
|
args: simple(:args),
|
235
633
|
table_data: sequence(:table_data),
|
236
634
|
ending: simple(:ending)) do
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
635
|
+
third_value = args ? [args] : []
|
636
|
+
open_paren = Constants::MATRICES[environment.to_sym]
|
637
|
+
table = Utility.organize_table(table_data, column_align: third_value)
|
638
|
+
Utility.get_table_class(environment).new(
|
639
|
+
table,
|
640
|
+
open_paren,
|
641
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
642
|
+
Utility.table_options(table),
|
643
|
+
)
|
644
|
+
end
|
645
|
+
|
646
|
+
rule(environment: simple(:environment),
|
647
|
+
asterisk: simple(:asterisk),
|
648
|
+
options: simple(:options),
|
649
|
+
table_data: sequence(:table_data),
|
650
|
+
ending: simple(:ending)) do
|
651
|
+
third_value = options ? [options] : []
|
652
|
+
open_paren = Constants::MATRICES[environment.to_sym]
|
653
|
+
table = Utility.organize_table(
|
654
|
+
table_data,
|
655
|
+
column_align: third_value,
|
656
|
+
options: true,
|
657
|
+
)
|
658
|
+
Utility.get_table_class(environment).new(
|
659
|
+
table,
|
660
|
+
open_paren,
|
661
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
662
|
+
{ asterisk: true },
|
663
|
+
)
|
664
|
+
end
|
665
|
+
|
666
|
+
rule(environment: simple(:environment),
|
667
|
+
asterisk: simple(:asterisk),
|
668
|
+
table_data: sequence(:table_data),
|
669
|
+
ending: simple(:ending)) do
|
670
|
+
open_paren = Constants::MATRICES[environment.to_sym]
|
671
|
+
Utility.get_table_class(environment).new(
|
672
|
+
Utility.organize_table(table_data),
|
673
|
+
open_paren,
|
674
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
675
|
+
{ asterisk: true },
|
676
|
+
)
|
241
677
|
end
|
242
678
|
|
243
679
|
rule(environment: simple(:env),
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
left_paren,
|
252
|
-
Constants::PARENTHESIS[left_paren],
|
680
|
+
expression: simple(:expr)) do
|
681
|
+
open_paren = Constants::MATRICES[env.to_sym]
|
682
|
+
Utility.get_table_class(env).new(
|
683
|
+
Utility.organize_table(expr.nil? ? [] : [expr]),
|
684
|
+
open_paren,
|
685
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
686
|
+
{},
|
253
687
|
)
|
254
688
|
end
|
255
689
|
|
256
|
-
rule(
|
257
|
-
expression: sequence(:expr)
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
690
|
+
rule(environment: simple(:env),
|
691
|
+
expression: sequence(:expr)) do
|
692
|
+
open_paren = Constants::MATRICES[env.to_sym]
|
693
|
+
Utility.get_table_class(env).new(
|
694
|
+
Utility.organize_table(expr.compact),
|
695
|
+
open_paren,
|
696
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
697
|
+
{},
|
698
|
+
)
|
262
699
|
end
|
263
700
|
|
264
|
-
rule(
|
265
|
-
expression:
|
266
|
-
|
267
|
-
subscript: simple(:subscript)) do
|
268
|
-
formula = Math::Formula.new(expr)
|
269
|
-
Math::Function::Base.new(formula, subscript)
|
270
|
-
end
|
271
|
-
|
272
|
-
class << self
|
273
|
-
def organize_table(array, table = [], table_data = [], table_row = [])
|
274
|
-
array.each do |data|
|
275
|
-
if data.is_a?(Math::Symbol) && data.value == "&"
|
276
|
-
table_row << Math::Function::Td.new(table_data)
|
277
|
-
table_data = []
|
278
|
-
elsif data.is_a?(Math::Symbol) && data.value == "\\\\"
|
279
|
-
table_row << Math::Function::Td.new(table_data)
|
280
|
-
table << Math::Function::Tr.new(table_row.flatten)
|
281
|
-
table_row = []
|
282
|
-
table_data = []
|
283
|
-
else
|
284
|
-
table_data << data
|
285
|
-
end
|
286
|
-
end
|
287
|
-
table_row << Math::Function::Td.new(table_data) if table_data
|
288
|
-
table << Math::Function::Tr.new(table_row) unless table_row.empty?
|
289
|
-
table
|
290
|
-
end
|
701
|
+
rule(substack: simple(:substack),
|
702
|
+
expression: sequence(:value)) do
|
703
|
+
tds = Utility.td_values(value, "\\\\")
|
291
704
|
|
292
|
-
|
293
|
-
|
294
|
-
|
705
|
+
substack_values = tds.map { |td| Math::Function::Tr.new([td]) }
|
706
|
+
Math::Function::Substack.new(
|
707
|
+
substack_values.shift,
|
708
|
+
substack_values.shift,
|
709
|
+
)
|
295
710
|
end
|
296
711
|
end
|
297
712
|
end
|