plurimath 0.2.1 → 0.2.3
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/.hound.yml +5 -0
- data/.rubocop.yml +8 -0
- data/AsciiMath-Supported-Data.adoc +1994 -274
- data/Gemfile +2 -0
- data/Latex-Supported-Data.adoc +1875 -1868
- data/MathML-Supported-Data.adoc +280 -263
- data/README.adoc +22 -20
- data/lib/plurimath/asciimath/constants.rb +187 -141
- data/lib/plurimath/asciimath/parse.rb +104 -39
- data/lib/plurimath/asciimath/parser.rb +3 -1
- data/lib/plurimath/asciimath/transform.rb +1074 -238
- data/lib/plurimath/html/parse.rb +1 -1
- data/lib/plurimath/latex/constants.rb +3229 -1432
- data/lib/plurimath/latex/parse.rb +108 -85
- data/lib/plurimath/latex/parser.rb +11 -4
- data/lib/plurimath/latex/transform.rb +354 -99
- data/lib/plurimath/math/base.rb +15 -0
- data/lib/plurimath/math/formula.rb +90 -13
- data/lib/plurimath/math/function/bar.rb +35 -1
- data/lib/plurimath/math/function/base.rb +25 -4
- data/lib/plurimath/math/function/binary_function.rb +101 -19
- 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 +15 -5
- data/lib/plurimath/math/function/f.rb +8 -0
- data/lib/plurimath/math/function/fenced.rb +95 -8
- data/lib/plurimath/math/function/floor.rb +15 -0
- data/lib/plurimath/math/function/font_style/bold.rb +19 -0
- data/lib/plurimath/math/function/font_style/double_struck.rb +19 -0
- data/lib/plurimath/math/function/font_style/fraktur.rb +19 -0
- data/lib/plurimath/math/function/font_style/italic.rb +37 -0
- data/lib/plurimath/math/function/font_style/monospace.rb +19 -0
- data/lib/plurimath/math/function/font_style/normal.rb +37 -0
- data/lib/plurimath/math/function/font_style/sans-serif.rb +19 -0
- data/lib/plurimath/math/function/font_style/script.rb +19 -0
- data/lib/plurimath/math/function/font_style.rb +18 -5
- data/lib/plurimath/math/function/frac.rb +33 -3
- 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 -0
- data/lib/plurimath/math/function/int.rb +23 -2
- data/lib/plurimath/math/function/left.rb +25 -1
- data/lib/plurimath/math/function/lim.rb +40 -2
- data/lib/plurimath/math/function/limits.rb +9 -0
- data/lib/plurimath/math/function/log.rb +55 -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 +19 -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 +19 -0
- data/lib/plurimath/math/function/norm.rb +17 -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 +12 -5
- data/lib/plurimath/math/function/overset.rb +34 -5
- data/lib/plurimath/math/function/phantom.rb +28 -0
- data/lib/plurimath/math/function/power.rb +27 -9
- data/lib/plurimath/math/function/power_base.rb +109 -11
- data/lib/plurimath/math/function/prod.rb +25 -4
- data/lib/plurimath/math/function/right.rb +22 -2
- data/lib/plurimath/math/function/root.rb +23 -1
- 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 +23 -1
- data/lib/plurimath/math/function/stackrel.rb +27 -0
- data/lib/plurimath/math/function/substack.rb +7 -0
- data/lib/plurimath/math/function/sum.rb +50 -2
- data/lib/plurimath/math/function/sup.rb +3 -0
- data/lib/plurimath/math/function/table/align.rb +5 -5
- data/lib/plurimath/math/function/table/array.rb +25 -6
- data/lib/plurimath/math/function/table/bmatrix.rb +18 -7
- data/lib/plurimath/math/function/table/matrix.rb +13 -5
- data/lib/plurimath/math/function/table/multline.rb +5 -5
- data/lib/plurimath/math/function/table/pmatrix.rb +5 -5
- data/lib/plurimath/math/function/table/split.rb +5 -5
- data/lib/plurimath/math/function/table/vmatrix.rb +5 -6
- data/lib/plurimath/math/function/table.rb +185 -27
- data/lib/plurimath/math/function/td.rb +22 -9
- data/lib/plurimath/math/function/ternary_function.rb +74 -9
- data/lib/plurimath/math/function/text.rb +36 -11
- data/lib/plurimath/math/function/tr.rb +23 -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 +81 -8
- 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 +7 -1
- data/lib/plurimath/math/number.rb +5 -5
- data/lib/plurimath/math/symbol.rb +51 -12
- data/lib/plurimath/math/unicode.rb +11 -0
- data/lib/plurimath/math.rb +7 -3
- data/lib/plurimath/mathml/constants.rb +224 -147
- data/lib/plurimath/mathml/parser.rb +24 -8
- data/lib/plurimath/mathml/transform.rb +249 -153
- data/lib/plurimath/omml/parser.rb +24 -4
- data/lib/plurimath/omml/transform.rb +219 -157
- data/lib/plurimath/utility.rb +342 -20
- data/lib/plurimath/version.rb +1 -1
- metadata +21 -6
- data/.github/workflows/test.yml +0 -33
- data/lib/plurimath/mathml/parse.rb +0 -68
- data/lib/plurimath/omml/constants.rb +0 -154
@@ -3,14 +3,20 @@
|
|
3
3
|
module Plurimath
|
4
4
|
class Latex
|
5
5
|
class Transform < Parslet::Transform
|
6
|
-
rule(base: simple(:base))
|
7
|
-
rule(over: simple(:over))
|
8
|
-
rule(number: simple(:num))
|
9
|
-
rule(power: simple(:power))
|
10
|
-
rule(unary: simple(:unary))
|
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 }
|
14
20
|
|
15
21
|
rule(unary_functions: simple(:unary)) { unary }
|
16
22
|
rule(left_right: simple(:left_right)) { left_right }
|
@@ -18,25 +24,35 @@ module Plurimath
|
|
18
24
|
rule(power_base: simple(:power_base)) { power_base }
|
19
25
|
rule(table_data: simple(:table_data)) { table_data }
|
20
26
|
|
21
|
-
rule(
|
27
|
+
rule(numeric_values: simple(:value)) do
|
28
|
+
Math::Symbol.new(value)
|
29
|
+
end
|
22
30
|
|
23
31
|
rule(text: simple(:text)) do
|
24
32
|
Math::Function::Text.new(text)
|
25
33
|
end
|
26
34
|
|
35
|
+
rule(unicode_symbols: simple(:unicode)) do
|
36
|
+
Math::Unicode.new(unicode)
|
37
|
+
end
|
38
|
+
|
27
39
|
rule(binary: simple(:binary)) do
|
28
|
-
binary.is_a?(
|
40
|
+
binary.is_a?(Parslet::Slice) ? Utility.get_class(binary).new : binary
|
29
41
|
end
|
30
42
|
|
31
43
|
rule(symbols: simple(:sym)) do
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
35
51
|
end
|
36
52
|
|
37
53
|
rule(lparen: simple(:lparen),
|
38
54
|
rparen: simple(:rparen)) do
|
39
|
-
|
55
|
+
[]
|
40
56
|
end
|
41
57
|
|
42
58
|
rule(left_right: simple(:left_right),
|
@@ -69,6 +85,34 @@ module Plurimath
|
|
69
85
|
)
|
70
86
|
end
|
71
87
|
|
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
|
+
)
|
97
|
+
end
|
98
|
+
|
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
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
rule(left: simple(:left),
|
112
|
+
lparen: simple(:lparen)) do
|
113
|
+
Math::Function::Left.new(lparen)
|
114
|
+
end
|
115
|
+
|
72
116
|
rule(left: simple(:left),
|
73
117
|
lparen: simple(:lparen),
|
74
118
|
expression: simple(:expr),
|
@@ -91,18 +135,54 @@ module Plurimath
|
|
91
135
|
)
|
92
136
|
end
|
93
137
|
|
138
|
+
rule(power: simple(:power),
|
139
|
+
expression: simple(:expr)) do
|
140
|
+
Math::Function::Power.new(
|
141
|
+
power,
|
142
|
+
expr,
|
143
|
+
)
|
144
|
+
end
|
145
|
+
|
146
|
+
rule(base: simple(:base),
|
147
|
+
expression: simple(:expr)) do
|
148
|
+
Math::Function::Base.new(
|
149
|
+
base,
|
150
|
+
expr,
|
151
|
+
)
|
152
|
+
end
|
153
|
+
|
154
|
+
rule(base: simple(:base),
|
155
|
+
expression: sequence(:expr)) do
|
156
|
+
Math::Function::Base.new(
|
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(
|
165
|
+
power,
|
166
|
+
Utility.filter_values(expr),
|
167
|
+
)
|
168
|
+
end
|
169
|
+
|
94
170
|
rule(left: simple(:left),
|
95
171
|
lparen: simple(:lparen),
|
96
172
|
dividend: subtree(:dividend),
|
97
|
-
divisor:
|
173
|
+
divisor: subtree(:divisor),
|
98
174
|
right: simple(:right),
|
99
175
|
rparen: simple(:rparen)) do
|
100
176
|
Math::Formula.new(
|
101
177
|
[
|
102
178
|
Math::Function::Left.new(lparen),
|
103
179
|
Math::Function::Over.new(
|
104
|
-
Math::Formula.new(
|
105
|
-
|
180
|
+
Math::Formula.new(
|
181
|
+
Array(dividend).flatten,
|
182
|
+
),
|
183
|
+
Math::Formula.new(
|
184
|
+
Array(divisor).flatten,
|
185
|
+
),
|
106
186
|
),
|
107
187
|
Math::Function::Right.new(rparen),
|
108
188
|
],
|
@@ -112,8 +192,12 @@ module Plurimath
|
|
112
192
|
rule(dividend: subtree(:dividend),
|
113
193
|
divisor: subtree(:divisor)) do
|
114
194
|
Math::Function::Over.new(
|
115
|
-
Math::Formula.new(
|
116
|
-
|
195
|
+
Math::Formula.new(
|
196
|
+
Array(dividend).flatten,
|
197
|
+
),
|
198
|
+
Math::Formula.new(
|
199
|
+
Array(divisor).flatten,
|
200
|
+
),
|
117
201
|
)
|
118
202
|
end
|
119
203
|
|
@@ -143,7 +227,7 @@ module Plurimath
|
|
143
227
|
|
144
228
|
rule(sequence: simple(:sequence),
|
145
229
|
expression: simple(:expr)) do
|
146
|
-
[sequence, expr]
|
230
|
+
[sequence, expr].compact
|
147
231
|
end
|
148
232
|
|
149
233
|
rule(sequence: simple(:sequence),
|
@@ -153,9 +237,40 @@ module Plurimath
|
|
153
237
|
|
154
238
|
rule(unary_functions: simple(:unary),
|
155
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
|
156
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(
|
157
271
|
unary,
|
158
272
|
subscript,
|
273
|
+
supscript,
|
159
274
|
)
|
160
275
|
end
|
161
276
|
|
@@ -164,12 +279,12 @@ module Plurimath
|
|
164
279
|
if Utility::FONT_STYLES[fonts.to_sym]
|
165
280
|
Utility::FONT_STYLES[fonts.to_sym].new(
|
166
281
|
int_exp,
|
167
|
-
fonts,
|
282
|
+
fonts.to_s,
|
168
283
|
)
|
169
284
|
else
|
170
285
|
Math::Function::FontStyle.new(
|
171
286
|
int_exp,
|
172
|
-
fonts,
|
287
|
+
fonts.to_s,
|
173
288
|
)
|
174
289
|
end
|
175
290
|
end
|
@@ -182,38 +297,62 @@ module Plurimath
|
|
182
297
|
)
|
183
298
|
end
|
184
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
|
+
|
185
308
|
rule(symbols: simple(:sym),
|
186
309
|
subscript: simple(:subscript)) do
|
187
310
|
Math::Function::Base.new(
|
188
311
|
Math::Symbol.new(
|
189
|
-
Constants::
|
312
|
+
Constants::UNICODE_SYMBOLS[sym.to_sym] || sym,
|
190
313
|
),
|
191
314
|
subscript,
|
192
315
|
)
|
193
316
|
end
|
194
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
|
+
|
195
326
|
rule(symbols: simple(:sym),
|
196
327
|
supscript: simple(:supscript)) do
|
197
328
|
Math::Function::Power.new(
|
198
329
|
Math::Symbol.new(
|
199
|
-
Constants::
|
330
|
+
Constants::UNICODE_SYMBOLS[sym.to_sym] || sym,
|
200
331
|
),
|
201
332
|
supscript,
|
202
333
|
)
|
203
334
|
end
|
204
335
|
|
205
|
-
rule(
|
336
|
+
rule(unicode_symbols: simple(:sym),
|
206
337
|
subscript: simple(:subscript)) do
|
207
338
|
Math::Function::Base.new(
|
208
|
-
Math::
|
339
|
+
Math::Unicode.new(sym),
|
209
340
|
subscript,
|
210
341
|
)
|
211
342
|
end
|
212
343
|
|
213
|
-
rule(
|
344
|
+
rule(unicode_symbols: simple(:sym),
|
214
345
|
supscript: simple(:supscript)) do
|
215
346
|
Math::Function::Power.new(
|
216
|
-
Math::
|
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),
|
217
356
|
supscript,
|
218
357
|
)
|
219
358
|
end
|
@@ -236,12 +375,12 @@ module Plurimath
|
|
236
375
|
font_style = if Utility::FONT_STYLES[fonts.to_sym].nil?
|
237
376
|
Math::Function::FontStyle.new(
|
238
377
|
int_exp,
|
239
|
-
fonts,
|
378
|
+
fonts.to_s,
|
240
379
|
)
|
241
380
|
else
|
242
381
|
Utility::FONT_STYLES[fonts.to_sym].new(
|
243
382
|
int_exp,
|
244
|
-
fonts,
|
383
|
+
fonts.to_s,
|
245
384
|
)
|
246
385
|
end
|
247
386
|
Math::Function::Power.new(
|
@@ -256,12 +395,12 @@ module Plurimath
|
|
256
395
|
font_style = if Utility::FONT_STYLES[fonts.to_sym].nil?
|
257
396
|
Math::Function::FontStyle.new(
|
258
397
|
int_exp,
|
259
|
-
fonts,
|
398
|
+
fonts.to_s,
|
260
399
|
)
|
261
400
|
else
|
262
401
|
Utility::FONT_STYLES[fonts.to_sym].new(
|
263
402
|
int_exp,
|
264
|
-
fonts,
|
403
|
+
fonts.to_s,
|
265
404
|
)
|
266
405
|
end
|
267
406
|
Math::Function::Base.new(
|
@@ -273,65 +412,84 @@ module Plurimath
|
|
273
412
|
rule(root: simple(:root),
|
274
413
|
first_value: simple(:first_value),
|
275
414
|
second_value: simple(:second_value)) do
|
415
|
+
second = second_value.nil? ? Math::Formula.new : second_value
|
276
416
|
Math::Function::Root.new(
|
277
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,
|
278
429
|
second_value,
|
279
430
|
)
|
280
431
|
end
|
281
432
|
|
282
|
-
rule(
|
433
|
+
rule(first_value: simple(:first_value),
|
283
434
|
base: simple(:base),
|
284
435
|
power: simple(:power)) do
|
285
436
|
Math::Function::Limits.new(
|
286
|
-
|
437
|
+
first_value,
|
287
438
|
base,
|
288
439
|
power,
|
289
440
|
)
|
290
441
|
end
|
291
442
|
|
292
443
|
rule(lparen: simple(:lparen),
|
293
|
-
|
444
|
+
expression: sequence(:expr),
|
294
445
|
rparen: simple(:rparen)) do
|
295
|
-
Math::
|
446
|
+
Math::Formula.new(expr)
|
296
447
|
end
|
297
448
|
|
298
|
-
rule(
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
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,
|
303
461
|
)
|
304
462
|
end
|
305
463
|
|
306
|
-
rule(
|
307
|
-
|
308
|
-
|
309
|
-
|
464
|
+
rule(expression: simple(:expression),
|
465
|
+
subscript: simple(:subscript)) do
|
466
|
+
Math::Function::Base.new(
|
467
|
+
expression,
|
468
|
+
subscript,
|
469
|
+
)
|
310
470
|
end
|
311
471
|
|
312
|
-
rule(
|
313
|
-
|
314
|
-
|
315
|
-
|
472
|
+
rule(rparen: simple(:rparen),
|
473
|
+
supscript: simple(:supscript)) do
|
474
|
+
Math::Function::Power.new(
|
475
|
+
Math::Symbol.new(rparen),
|
476
|
+
supscript,
|
477
|
+
)
|
316
478
|
end
|
317
479
|
|
318
|
-
rule(
|
319
|
-
expression: simple(:expr),
|
320
|
-
rparen: simple(:rparen),
|
480
|
+
rule(expression: simple(:expr),
|
321
481
|
supscript: simple(:supscript)) do
|
322
482
|
Math::Function::Power.new(
|
323
|
-
|
483
|
+
expr,
|
324
484
|
supscript,
|
325
485
|
)
|
326
486
|
end
|
327
487
|
|
328
|
-
rule(
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
Math::Formula.new(expr),
|
334
|
-
subscript,
|
488
|
+
rule(expression: sequence(:expr),
|
489
|
+
supscript: simple(:supscript)) do
|
490
|
+
Math::Function::Power.new(
|
491
|
+
Utility.filter_values(expr),
|
492
|
+
supscript,
|
335
493
|
)
|
336
494
|
end
|
337
495
|
|
@@ -346,26 +504,33 @@ module Plurimath
|
|
346
504
|
|
347
505
|
rule(binary: simple(:binary),
|
348
506
|
subscript: simple(:subscript)) do
|
349
|
-
|
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
|
350
515
|
end
|
351
516
|
|
352
|
-
rule(
|
517
|
+
rule(symbols: simple(:sym),
|
353
518
|
subscript: simple(:subscript),
|
354
519
|
supscript: simple(:supscript)) do
|
355
520
|
Math::Function::PowerBase.new(
|
356
|
-
Math::
|
521
|
+
Math::Symbol.new(
|
522
|
+
Constants::UNICODE_SYMBOLS[sym.to_sym] || sym,
|
523
|
+
),
|
357
524
|
subscript,
|
358
525
|
supscript,
|
359
526
|
)
|
360
527
|
end
|
361
528
|
|
362
|
-
rule(
|
529
|
+
rule(unicode_symbols: simple(:sym),
|
363
530
|
subscript: simple(:subscript),
|
364
531
|
supscript: simple(:supscript)) do
|
365
532
|
Math::Function::PowerBase.new(
|
366
|
-
Math::
|
367
|
-
Constants::SYMBOLS[sym.to_sym] || sym,
|
368
|
-
),
|
533
|
+
Math::Unicode.new(sym),
|
369
534
|
subscript,
|
370
535
|
supscript,
|
371
536
|
)
|
@@ -377,15 +542,19 @@ module Plurimath
|
|
377
542
|
if binary == "binom"
|
378
543
|
Math::Function::Table.new(
|
379
544
|
[
|
380
|
-
Math::Function::Tr.new(
|
381
|
-
|
545
|
+
Math::Function::Tr.new(
|
546
|
+
Utility.table_td(first_value),
|
547
|
+
),
|
548
|
+
Math::Function::Tr.new(
|
549
|
+
Utility.table_td(second_value),
|
550
|
+
),
|
382
551
|
],
|
383
552
|
"(",
|
384
553
|
")",
|
385
554
|
)
|
386
555
|
else
|
387
556
|
Utility.get_class(
|
388
|
-
binary.include?("mod") ? "mod" : binary,
|
557
|
+
binary.to_s.include?("mod") ? "mod" : binary,
|
389
558
|
).new(
|
390
559
|
first_value,
|
391
560
|
second_value,
|
@@ -393,65 +562,151 @@ module Plurimath
|
|
393
562
|
end
|
394
563
|
end
|
395
564
|
|
396
|
-
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),
|
397
577
|
table_data: sequence(:table_data),
|
398
578
|
ending: simple(:ending)) do
|
399
|
-
|
579
|
+
open_paren = Constants::MATRICES[environment.to_sym]
|
580
|
+
Utility.get_table_class(environment).new(
|
400
581
|
Utility.organize_table(table_data),
|
582
|
+
open_paren,
|
583
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
584
|
+
{},
|
401
585
|
)
|
402
586
|
end
|
403
587
|
|
404
|
-
rule(
|
588
|
+
rule(environment: simple(:environment),
|
405
589
|
args: simple(:args),
|
406
590
|
table_data: simple(:table_data),
|
407
591
|
ending: simple(:ending)) do
|
408
|
-
|
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
|
+
)
|
604
|
+
end
|
605
|
+
|
606
|
+
rule(environment: simple(:environment),
|
607
|
+
table_data: simple(:table_data),
|
608
|
+
ending: simple(:ending)) do
|
609
|
+
open_paren = Constants::MATRICES[environment.to_sym]
|
610
|
+
Utility.get_table_class(environment).new(
|
409
611
|
Utility.organize_table([table_data]),
|
410
|
-
|
411
|
-
[
|
612
|
+
open_paren,
|
613
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
412
614
|
)
|
413
615
|
end
|
414
616
|
|
415
|
-
rule(
|
617
|
+
rule(environment: simple(:environment),
|
416
618
|
args: sequence(:args),
|
417
619
|
table_data: sequence(:table_data),
|
418
620
|
ending: simple(:ending)) do
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
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),
|
423
628
|
)
|
424
629
|
end
|
425
630
|
|
426
|
-
rule(
|
631
|
+
rule(environment: simple(:environment),
|
427
632
|
args: simple(:args),
|
428
633
|
table_data: sequence(:table_data),
|
429
634
|
ending: simple(:ending)) do
|
430
|
-
|
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(
|
431
672
|
Utility.organize_table(table_data),
|
432
|
-
|
433
|
-
[
|
673
|
+
open_paren,
|
674
|
+
Constants::MATRICES_PARENTHESIS[open_paren&.to_sym]&.to_s,
|
675
|
+
{ asterisk: true },
|
434
676
|
)
|
435
677
|
end
|
436
678
|
|
437
679
|
rule(environment: simple(:env),
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
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
|
+
{},
|
446
687
|
)
|
447
688
|
end
|
448
689
|
|
449
|
-
rule(
|
450
|
-
expression: sequence(:expr)
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
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
|
+
)
|
699
|
+
end
|
700
|
+
|
701
|
+
rule(substack: simple(:substack),
|
702
|
+
expression: sequence(:value)) do
|
703
|
+
tds = Utility.td_values(value, "\\\\")
|
704
|
+
|
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
|
+
)
|
455
710
|
end
|
456
711
|
end
|
457
712
|
end
|