plurimath 0.2.1 → 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/.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 +186 -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 +3228 -1432
- data/lib/plurimath/latex/parse.rb +106 -83
- 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
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
module Plurimath
|
4
4
|
module Math
|
5
|
-
class Symbol
|
5
|
+
class Symbol < Base
|
6
6
|
attr_accessor :value
|
7
7
|
|
8
8
|
def initialize(sym)
|
9
|
-
@value =
|
9
|
+
@value = super
|
10
10
|
end
|
11
11
|
|
12
12
|
def ==(object)
|
@@ -14,29 +14,68 @@ module Plurimath
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_asciimath
|
17
|
-
|
18
|
-
|
17
|
+
return "" if value.nil?
|
18
|
+
|
19
|
+
symbol = Asciimath::Constants::SYMBOLS.invert[value.strip.to_sym]
|
20
|
+
unicodes = Latex::Constants::UNICODE_SYMBOLS.invert
|
21
|
+
if value.match?(/&#x[0-9\w]+;/) && symbol.nil? && unicodes[value]
|
22
|
+
return unicodes[value].to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
symbol ? symbol.to_s : value
|
19
26
|
end
|
20
27
|
|
21
28
|
def to_mathml_without_math_tag
|
22
|
-
"
|
23
|
-
|
29
|
+
mi_tag = Utility.ox_element("mi")
|
30
|
+
return mi_tag if ["{:", ":}"].include?(value)
|
31
|
+
|
32
|
+
unicodes = Mathml::Constants::UNICODE_SYMBOLS
|
33
|
+
unicode = unicodes.invert[value]
|
34
|
+
if operator?(unicode) || unicode
|
35
|
+
mo_value = (unicodes[value] || unicode || value).to_s
|
36
|
+
return Utility.ox_element("mo") << mo_value
|
37
|
+
end
|
24
38
|
|
25
|
-
|
26
|
-
Mathml::Constants::UNICODE_SYMBOLS.invert[value] || value
|
39
|
+
mi_tag << value
|
27
40
|
end
|
28
41
|
|
29
42
|
def to_latex
|
30
|
-
|
31
|
-
|
43
|
+
returned = specific_values
|
44
|
+
return returned if returned
|
45
|
+
|
46
|
+
special_char = %w[& #]
|
47
|
+
symbols = Latex::Constants::UNICODE_SYMBOLS.invert
|
48
|
+
|
49
|
+
symbol = symbols[value]
|
50
|
+
if Latex::Constants::SYMBOLS[symbol] == :operant
|
51
|
+
special_char.include?(value) ? "\\#{symbol}" : symbol
|
52
|
+
else
|
53
|
+
symbols.key?(value) ? "\\#{symbol}" : value
|
54
|
+
end
|
32
55
|
end
|
33
56
|
|
34
57
|
def to_html
|
35
58
|
value
|
36
59
|
end
|
37
60
|
|
38
|
-
def
|
39
|
-
|
61
|
+
def to_omml_without_math_tag
|
62
|
+
value
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def operator?(unicode)
|
68
|
+
Mathml::Constants::OPERATORS.any? do |d|
|
69
|
+
[unicode.to_s, value.strip].include?(d)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def specific_values
|
74
|
+
return "" if ["{:", ":}"].include?(value)
|
75
|
+
|
76
|
+
return "\\#{value}" if ["{", "}"].include?(value) || value == "_"
|
77
|
+
|
78
|
+
return "\\operatorname{if}" if value == "if"
|
40
79
|
end
|
41
80
|
end
|
42
81
|
end
|
data/lib/plurimath/math.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "ox"
|
4
3
|
require_relative "unicode"
|
5
4
|
require_relative "asciimath"
|
6
5
|
require_relative "omml"
|
@@ -8,16 +7,21 @@ require_relative "mathml"
|
|
8
7
|
require_relative "html"
|
9
8
|
require_relative "latex"
|
10
9
|
require_relative "unitsml"
|
11
|
-
require_relative "math/
|
12
|
-
require_relative "math/function"
|
10
|
+
require_relative "math/base"
|
13
11
|
require_relative "math/number"
|
14
12
|
require_relative "math/symbol"
|
13
|
+
require_relative "math/unicode"
|
14
|
+
require_relative "math/formula"
|
15
|
+
require_relative "math/function"
|
15
16
|
require_relative "asciimath/parser"
|
16
17
|
require_relative "mathml/parser"
|
17
18
|
require_relative "latex/parser"
|
18
19
|
require_relative "html/parser"
|
19
20
|
require_relative "omml/parser"
|
20
21
|
require_relative "utility"
|
22
|
+
require "ox"
|
23
|
+
Ox.default_options = { encoding: "UTF-8" }
|
24
|
+
|
21
25
|
module Plurimath
|
22
26
|
module Math
|
23
27
|
class Error < StandardError; end
|
@@ -4,77 +4,76 @@ module Plurimath
|
|
4
4
|
class Mathml
|
5
5
|
class Constants
|
6
6
|
UNICODE_SYMBOLS = {
|
7
|
-
"&#
|
8
|
-
"&#
|
9
|
-
"&#
|
7
|
+
"α": "alpha",
|
8
|
+
"β": "beta",
|
9
|
+
"γ": "gamma",
|
10
10
|
"Γ": "Gamma",
|
11
|
-
"&#
|
11
|
+
"δ": "delta",
|
12
12
|
"Δ": "Delta",
|
13
13
|
"∆": "Delta",
|
14
|
-
"&#
|
14
|
+
"ε": "epsilon",
|
15
15
|
"ɛ": "varepsilon",
|
16
|
-
"&#
|
17
|
-
"&#
|
18
|
-
"&#
|
16
|
+
"ζ": "zeta",
|
17
|
+
"η": "eta",
|
18
|
+
"θ": "theta",
|
19
19
|
"Θ": "Theta",
|
20
|
-
"&#
|
21
|
-
"&#
|
22
|
-
"&#
|
23
|
-
"&#
|
24
|
-
"&#
|
25
|
-
"&#
|
26
|
-
"&#
|
27
|
-
"&#
|
28
|
-
"&#
|
20
|
+
"ϑ": "vartheta",
|
21
|
+
"ι": "iota",
|
22
|
+
"κ": "kappa",
|
23
|
+
"λ": "lambda",
|
24
|
+
"Λ": "Lambda",
|
25
|
+
"μ": "mu",
|
26
|
+
"ν": "nu",
|
27
|
+
"ξ": "xi",
|
28
|
+
"Ξ": "Xi",
|
29
29
|
"π": "pi",
|
30
|
-
"&#
|
31
|
-
"&#
|
32
|
-
"&#
|
33
|
-
"&#
|
34
|
-
"&#
|
35
|
-
"&#
|
36
|
-
"&#
|
37
|
-
"&#
|
38
|
-
"&#
|
39
|
-
"&#
|
40
|
-
"&#
|
41
|
-
"&#
|
42
|
-
"&#
|
43
|
-
"&#
|
44
|
-
"&#
|
45
|
-
"&#
|
30
|
+
"Π": "Pi",
|
31
|
+
"ρ": "rho",
|
32
|
+
"ς": "beta",
|
33
|
+
"σ": "sigma",
|
34
|
+
"Σ": "Sigma",
|
35
|
+
"τ": "tau",
|
36
|
+
"υ": "upsilon",
|
37
|
+
"φ": "phi",
|
38
|
+
"Φ": "Phi",
|
39
|
+
"ϕ": "varphi",
|
40
|
+
"χ": "chi",
|
41
|
+
"ψ": "psi",
|
42
|
+
"Ψ": "Psi",
|
43
|
+
"ω": "omega",
|
44
|
+
"Ω": "omega",
|
45
|
+
"⋅": "dot",
|
46
46
|
"∙": "*",
|
47
|
-
"&#
|
47
|
+
"·": ".",
|
48
48
|
"∗": "**",
|
49
|
-
"&#
|
50
|
-
"&#
|
51
|
-
"&#
|
52
|
-
"&#
|
53
|
-
"&#
|
54
|
-
"&#
|
49
|
+
"⋆": "***",
|
50
|
+
"×": "xx",
|
51
|
+
"⋉": "|><",
|
52
|
+
"⋊": "><|",
|
53
|
+
"⋈": "|><|",
|
54
|
+
"÷": "-:",
|
55
55
|
"∘": "@",
|
56
56
|
"⊕": "o+",
|
57
|
-
"&#
|
57
|
+
"⨁": "o+",
|
58
58
|
"⊗": "ox",
|
59
59
|
"⊙": " ",
|
60
60
|
"∑": "sum",
|
61
|
-
"∏": "prod",
|
62
61
|
"∏": "prod",
|
63
62
|
"∧": "^^",
|
64
|
-
"&#
|
63
|
+
"⋀": "^^^",
|
65
64
|
"∨": "vv",
|
66
65
|
"⋁": "vvv",
|
67
66
|
"∩": "nn",
|
68
|
-
"&#
|
69
|
-
"&#
|
70
|
-
"&#
|
67
|
+
"⋂": "nnn",
|
68
|
+
"∪": "cup",
|
69
|
+
"⋃": "uuu",
|
71
70
|
"≠": "!=",
|
72
71
|
"≤": "<=",
|
73
72
|
"≥": ">=",
|
74
|
-
"&#
|
75
|
-
"&#
|
76
|
-
"&#
|
77
|
-
"&#
|
73
|
+
"≺": "-<",
|
74
|
+
"≻": ">-",
|
75
|
+
"⪯": "-<=",
|
76
|
+
"⪰": " >-=",
|
78
77
|
"∈": "in",
|
79
78
|
"∉": "!in",
|
80
79
|
"⊂": "sub",
|
@@ -84,65 +83,68 @@ module Plurimath
|
|
84
83
|
"≡": "-=",
|
85
84
|
"≅": "~=",
|
86
85
|
"≈": "~~",
|
87
|
-
"&#
|
88
|
-
"&#
|
86
|
+
"∝": "prop",
|
87
|
+
"¬": "not",
|
89
88
|
"∀": "AA",
|
90
89
|
"∃": "EE",
|
91
|
-
"&#
|
92
|
-
"&#
|
93
|
-
"&#
|
94
|
-
"&#
|
90
|
+
"⊥": "_|_",
|
91
|
+
"⊤": "TT",
|
92
|
+
"⊢": "|--",
|
93
|
+
"⊨": "|==",
|
95
94
|
"〈": "(:",
|
96
|
-
"&#
|
97
|
-
"&#
|
98
|
-
"&#
|
99
|
-
"&#
|
100
|
-
"&#
|
95
|
+
"〉": ":)",
|
96
|
+
"⟨": "<<",
|
97
|
+
"⟩": ">>",
|
98
|
+
"∫": "int",
|
99
|
+
"∮": "oint",
|
101
100
|
"∂": "del",
|
102
101
|
"∇": "grad",
|
103
|
-
"&#
|
102
|
+
"±": "+-",
|
104
103
|
"∅": "O/",
|
105
|
-
"&#
|
104
|
+
"∞": "oo",
|
106
105
|
"ℵ": "aleph",
|
107
106
|
"∴": ":.",
|
108
107
|
"∵": ":'",
|
109
108
|
"∠": "/_",
|
110
|
-
"&#
|
109
|
+
"△": "/_\\",
|
111
110
|
"′": "'",
|
112
|
-
"&#
|
113
|
-
"&#
|
111
|
+
"  ": "quad",
|
112
|
+
"    ": "qquad",
|
114
113
|
"⌢": "frown",
|
115
|
-
"&#
|
116
|
-
"&#
|
117
|
-
"&#
|
118
|
-
"&#
|
119
|
-
"&#
|
120
|
-
"&#
|
121
|
-
"&#
|
114
|
+
"⋯": "cdots",
|
115
|
+
"⋮": "vdots",
|
116
|
+
"⋱": "ddots",
|
117
|
+
"⋄": "diamond",
|
118
|
+
"□": "square",
|
119
|
+
"⌊": "|__",
|
120
|
+
"⌋": "__|",
|
122
121
|
"⌈": "|~",
|
123
122
|
"⌉": "~|",
|
124
123
|
"ℂ": "CC",
|
125
124
|
"ℕ": "NN",
|
126
|
-
"&#
|
127
|
-
"&#
|
125
|
+
"ℚ": "QQ",
|
126
|
+
"ℝ": "RR",
|
128
127
|
"ℤ": "ZZ",
|
129
128
|
"↑": "uarr",
|
130
129
|
"↓": "darr",
|
131
130
|
"←": "larr",
|
132
131
|
"↔": "harr",
|
133
|
-
"&#
|
134
|
-
"&#
|
135
|
-
"&#
|
132
|
+
"⇒": "rArr",
|
133
|
+
"⇐": "lArr",
|
134
|
+
"⇔": "hArr",
|
136
135
|
"→": "->",
|
137
|
-
"&#
|
138
|
-
"&#
|
136
|
+
"↣": ">->",
|
137
|
+
"↠": "->>",
|
139
138
|
"⤖": ">->>",
|
140
|
-
"&#
|
139
|
+
"↦": "|->",
|
141
140
|
"…": "...",
|
142
141
|
"−": "-",
|
143
|
-
"&#
|
144
|
-
"&#
|
145
|
-
"&#
|
142
|
+
"⏞": "obrace",
|
143
|
+
"⏟": "ubrace",
|
144
|
+
"&": "&",
|
145
|
+
">": ">",
|
146
|
+
"<": "<",
|
147
|
+
"&": "&",
|
146
148
|
}.freeze
|
147
149
|
SYMBOLS = {
|
148
150
|
"|": "|",
|
@@ -226,69 +228,144 @@ module Plurimath
|
|
226
228
|
f
|
227
229
|
g
|
228
230
|
].freeze
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
231
|
+
OPERATORS = [
|
232
|
+
"    ",
|
233
|
+
"  ",
|
234
|
+
"*",
|
235
|
+
"<",
|
236
|
+
">",
|
237
|
+
" ",
|
238
|
+
"¬",
|
239
|
+
"±",
|
240
|
+
"×",
|
241
|
+
"÷",
|
242
|
+
"Γ",
|
243
|
+
"Δ",
|
244
|
+
"Θ",
|
245
|
+
"Λ",
|
246
|
+
"Ξ",
|
247
|
+
"Π",
|
248
|
+
"Σ",
|
249
|
+
"Ω",
|
250
|
+
"…",
|
251
|
+
"′",
|
252
|
+
"ℂ",
|
253
|
+
"ℕ",
|
254
|
+
"ℚ",
|
255
|
+
"ℝ",
|
256
|
+
"ℤ",
|
257
|
+
"ℵ",
|
258
|
+
"←",
|
259
|
+
"↑",
|
260
|
+
"→",
|
261
|
+
"→",
|
262
|
+
"↓",
|
263
|
+
"↔",
|
264
|
+
"↠",
|
265
|
+
"↣",
|
266
|
+
"↦",
|
267
|
+
"⇐",
|
268
|
+
"⇒",
|
269
|
+
"⇒",
|
270
|
+
"⇔",
|
271
|
+
"⇔",
|
272
|
+
"∀",
|
273
|
+
"∂",
|
274
|
+
"∃",
|
275
|
+
"∅",
|
276
|
+
"∇",
|
277
|
+
"∈",
|
278
|
+
"∉",
|
279
|
+
"∏",
|
280
|
+
"∑",
|
281
|
+
"−",
|
282
|
+
"∓",
|
283
|
+
"∝",
|
284
|
+
"∞",
|
285
|
+
"∠",
|
286
|
+
"∧",
|
287
|
+
"∨",
|
288
|
+
"∩",
|
289
|
+
"∪",
|
290
|
+
"∫",
|
291
|
+
"∮",
|
292
|
+
"∴",
|
293
|
+
"∵",
|
294
|
+
"∼",
|
295
|
+
"≅",
|
296
|
+
"≈",
|
297
|
+
"≔",
|
298
|
+
"≠",
|
299
|
+
"≡",
|
300
|
+
"≤",
|
301
|
+
"≥",
|
302
|
+
"≪",
|
303
|
+
"≫",
|
304
|
+
"≺",
|
305
|
+
"≻",
|
306
|
+
"⊂",
|
307
|
+
"⊃",
|
308
|
+
"⊆",
|
309
|
+
"⊇",
|
310
|
+
"⊕",
|
311
|
+
"⊗",
|
312
|
+
"⊙",
|
313
|
+
"⊢",
|
314
|
+
"⊤",
|
315
|
+
"⊥",
|
316
|
+
"⊨",
|
317
|
+
"⋀",
|
318
|
+
"⋁",
|
319
|
+
"⋂",
|
320
|
+
"⋃",
|
321
|
+
"⋄",
|
322
|
+
"⋅",
|
323
|
+
"⋆",
|
324
|
+
"⋈",
|
325
|
+
"⋉",
|
326
|
+
"⋊",
|
327
|
+
"⋮",
|
328
|
+
"⋯",
|
329
|
+
"⋱",
|
330
|
+
"⌈",
|
331
|
+
"⌉",
|
332
|
+
"⌊",
|
333
|
+
"⌋",
|
334
|
+
"⌢",
|
335
|
+
"□",
|
336
|
+
"△",
|
337
|
+
"⚬",
|
338
|
+
"⤖",
|
339
|
+
"⪯",
|
340
|
+
"⪰",
|
341
|
+
"+",
|
342
|
+
"=",
|
343
|
+
":",
|
344
|
+
"<",
|
345
|
+
"×",
|
346
|
+
"±",
|
347
|
+
"&",
|
348
|
+
";",
|
349
|
+
">",
|
350
|
+
"|",
|
351
|
+
"lim",
|
352
|
+
"max",
|
353
|
+
"min",
|
354
|
+
"\\",
|
355
|
+
"//",
|
356
|
+
"/",
|
357
|
+
"if",
|
358
|
+
"^",
|
359
|
+
"_",
|
360
|
+
"+",
|
361
|
+
"/",
|
362
|
+
"=",
|
363
|
+
":",
|
364
|
+
",",
|
365
|
+
")",
|
366
|
+
"(",
|
367
|
+
"[",
|
368
|
+
"]",
|
292
369
|
].freeze
|
293
370
|
end
|
294
371
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "parse"
|
4
3
|
require_relative "constants"
|
5
4
|
require_relative "transform"
|
6
5
|
module Plurimath
|
@@ -9,17 +8,34 @@ module Plurimath
|
|
9
8
|
attr_accessor :text
|
10
9
|
|
11
10
|
def initialize(text)
|
12
|
-
@text = text
|
11
|
+
@text = text
|
13
12
|
end
|
14
13
|
|
15
14
|
def parse
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
ox_nodes = Ox.load(text, strip_namespace: true).nodes
|
16
|
+
nodes = parse_nodes(ox_nodes)
|
17
|
+
Math::Formula.new(
|
18
|
+
Transform.new.apply(nodes).flatten.compact,
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_nodes(nodes)
|
23
|
+
nodes.map do |node|
|
24
|
+
next if node.is_a?(Ox::Comment)
|
21
25
|
|
22
|
-
|
26
|
+
if node.is_a?(String)
|
27
|
+
node
|
28
|
+
elsif !node.attributes.empty?
|
29
|
+
{
|
30
|
+
node.name.to_sym => {
|
31
|
+
attributes: node.attributes.transform_keys(&:to_sym),
|
32
|
+
value: parse_nodes(node.nodes),
|
33
|
+
},
|
34
|
+
}
|
35
|
+
else
|
36
|
+
{ node.name.to_sym => parse_nodes(node.nodes) }
|
37
|
+
end
|
38
|
+
end
|
23
39
|
end
|
24
40
|
end
|
25
41
|
end
|