plurimath 0.2.1 → 0.2.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.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +13 -0
  3. data/.github/workflows/release.yml +22 -0
  4. data/.hound.yml +5 -0
  5. data/.rubocop.yml +8 -0
  6. data/AsciiMath-Supported-Data.adoc +1994 -274
  7. data/Gemfile +2 -0
  8. data/Latex-Supported-Data.adoc +1875 -1868
  9. data/MathML-Supported-Data.adoc +280 -263
  10. data/README.adoc +22 -20
  11. data/lib/plurimath/asciimath/constants.rb +186 -141
  12. data/lib/plurimath/asciimath/parse.rb +104 -39
  13. data/lib/plurimath/asciimath/parser.rb +3 -1
  14. data/lib/plurimath/asciimath/transform.rb +1074 -238
  15. data/lib/plurimath/html/parse.rb +1 -1
  16. data/lib/plurimath/latex/constants.rb +3228 -1432
  17. data/lib/plurimath/latex/parse.rb +106 -83
  18. data/lib/plurimath/latex/parser.rb +11 -4
  19. data/lib/plurimath/latex/transform.rb +354 -99
  20. data/lib/plurimath/math/base.rb +15 -0
  21. data/lib/plurimath/math/formula.rb +90 -13
  22. data/lib/plurimath/math/function/bar.rb +35 -1
  23. data/lib/plurimath/math/function/base.rb +25 -4
  24. data/lib/plurimath/math/function/binary_function.rb +101 -19
  25. data/lib/plurimath/math/function/cancel.rb +8 -0
  26. data/lib/plurimath/math/function/ceil.rb +3 -0
  27. data/lib/plurimath/math/function/color.rb +15 -5
  28. data/lib/plurimath/math/function/f.rb +8 -0
  29. data/lib/plurimath/math/function/fenced.rb +95 -8
  30. data/lib/plurimath/math/function/floor.rb +15 -0
  31. data/lib/plurimath/math/function/font_style/bold.rb +19 -0
  32. data/lib/plurimath/math/function/font_style/double_struck.rb +19 -0
  33. data/lib/plurimath/math/function/font_style/fraktur.rb +19 -0
  34. data/lib/plurimath/math/function/font_style/italic.rb +37 -0
  35. data/lib/plurimath/math/function/font_style/monospace.rb +19 -0
  36. data/lib/plurimath/math/function/font_style/normal.rb +37 -0
  37. data/lib/plurimath/math/function/font_style/sans-serif.rb +19 -0
  38. data/lib/plurimath/math/function/font_style/script.rb +19 -0
  39. data/lib/plurimath/math/function/font_style.rb +18 -5
  40. data/lib/plurimath/math/function/frac.rb +33 -3
  41. data/lib/plurimath/math/function/g.rb +7 -0
  42. data/lib/plurimath/math/function/hat.rb +12 -0
  43. data/lib/plurimath/math/function/inf.rb +21 -0
  44. data/lib/plurimath/math/function/int.rb +23 -2
  45. data/lib/plurimath/math/function/left.rb +25 -1
  46. data/lib/plurimath/math/function/lim.rb +40 -2
  47. data/lib/plurimath/math/function/limits.rb +9 -0
  48. data/lib/plurimath/math/function/log.rb +55 -4
  49. data/lib/plurimath/math/function/longdiv.rb +12 -0
  50. data/lib/plurimath/math/function/mbox.rb +31 -0
  51. data/lib/plurimath/math/function/menclose.rb +46 -0
  52. data/lib/plurimath/math/function/merror.rb +12 -0
  53. data/lib/plurimath/math/function/mod.rb +19 -4
  54. data/lib/plurimath/math/function/msgroup.rb +37 -0
  55. data/lib/plurimath/math/function/msline.rb +12 -0
  56. data/lib/plurimath/math/function/multiscript.rb +19 -0
  57. data/lib/plurimath/math/function/norm.rb +17 -1
  58. data/lib/plurimath/math/function/obrace.rb +17 -0
  59. data/lib/plurimath/math/function/oint.rb +2 -2
  60. data/lib/plurimath/math/function/over.rb +12 -5
  61. data/lib/plurimath/math/function/overset.rb +34 -5
  62. data/lib/plurimath/math/function/phantom.rb +28 -0
  63. data/lib/plurimath/math/function/power.rb +27 -9
  64. data/lib/plurimath/math/function/power_base.rb +109 -11
  65. data/lib/plurimath/math/function/prod.rb +25 -4
  66. data/lib/plurimath/math/function/right.rb +22 -2
  67. data/lib/plurimath/math/function/root.rb +23 -1
  68. data/lib/plurimath/math/function/rule.rb +33 -0
  69. data/lib/plurimath/math/function/scarries.rb +12 -0
  70. data/lib/plurimath/math/function/scarry.rb +12 -0
  71. data/lib/plurimath/math/function/sqrt.rb +23 -1
  72. data/lib/plurimath/math/function/stackrel.rb +27 -0
  73. data/lib/plurimath/math/function/substack.rb +7 -0
  74. data/lib/plurimath/math/function/sum.rb +50 -2
  75. data/lib/plurimath/math/function/sup.rb +3 -0
  76. data/lib/plurimath/math/function/table/align.rb +5 -5
  77. data/lib/plurimath/math/function/table/array.rb +25 -6
  78. data/lib/plurimath/math/function/table/bmatrix.rb +18 -7
  79. data/lib/plurimath/math/function/table/matrix.rb +13 -5
  80. data/lib/plurimath/math/function/table/multline.rb +5 -5
  81. data/lib/plurimath/math/function/table/pmatrix.rb +5 -5
  82. data/lib/plurimath/math/function/table/split.rb +5 -5
  83. data/lib/plurimath/math/function/table/vmatrix.rb +5 -6
  84. data/lib/plurimath/math/function/table.rb +185 -27
  85. data/lib/plurimath/math/function/td.rb +22 -9
  86. data/lib/plurimath/math/function/ternary_function.rb +74 -9
  87. data/lib/plurimath/math/function/text.rb +36 -11
  88. data/lib/plurimath/math/function/tr.rb +23 -4
  89. data/lib/plurimath/math/function/ubrace.rb +17 -0
  90. data/lib/plurimath/math/function/ul.rb +29 -0
  91. data/lib/plurimath/math/function/unary_function.rb +81 -8
  92. data/lib/plurimath/math/function/underline.rb +12 -0
  93. data/lib/plurimath/math/function/underover.rb +107 -0
  94. data/lib/plurimath/math/function/underset.rb +39 -0
  95. data/lib/plurimath/math/function/vec.rb +7 -1
  96. data/lib/plurimath/math/number.rb +5 -5
  97. data/lib/plurimath/math/symbol.rb +51 -12
  98. data/lib/plurimath/math/unicode.rb +11 -0
  99. data/lib/plurimath/math.rb +7 -3
  100. data/lib/plurimath/mathml/constants.rb +224 -147
  101. data/lib/plurimath/mathml/parser.rb +24 -8
  102. data/lib/plurimath/mathml/transform.rb +249 -153
  103. data/lib/plurimath/omml/parser.rb +24 -4
  104. data/lib/plurimath/omml/transform.rb +219 -157
  105. data/lib/plurimath/utility.rb +342 -20
  106. data/lib/plurimath/version.rb +1 -1
  107. metadata +21 -6
  108. data/.github/workflows/test.yml +0 -33
  109. data/lib/plurimath/mathml/parse.rb +0 -68
  110. 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 = sym
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
- symbol = Asciimath::Constants::SYMBOLS.invert[value.to_sym].to_s
18
- symbol.empty? ? value : symbol
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
- "<mo>#{mathml_symbol_value}</mo>"
23
- end
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
- def mathml_symbol_value
26
- Mathml::Constants::UNICODE_SYMBOLS.invert[value] || value
39
+ mi_tag << value
27
40
  end
28
41
 
29
42
  def to_latex
30
- symbols = Latex::Constants::SYMBOLS.invert
31
- symbols.key?(value) ? "\\#{symbols[value]}" : value
43
+ returned = specific_values
44
+ return returned if returned
45
+
46
+ special_char = %w[&#x26; &#x23;]
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 class_name
39
- self.class.name.split("::").last.downcase
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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ module Math
5
+ class Unicode < Symbol
6
+ def to_mathml_without_math_tag
7
+ Utility.ox_element("mo") << value
8
+ end
9
+ end
10
+ end
11
+ end
@@ -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/formula"
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
- "&#x3B1;": "alpha",
8
- "&#x3B2;": "beta",
9
- "&#x3B3;": "gamma",
7
+ "&#x3b1;": "alpha",
8
+ "&#x3b2;": "beta",
9
+ "&#x3b3;": "gamma",
10
10
  "&#x393;": "Gamma",
11
- "&#x3B4;": "delta",
11
+ "&#x3b4;": "delta",
12
12
  "&#x394;": "Delta",
13
13
  "&#x2206;": "Delta",
14
- "&#x3B5;": "epsilon",
14
+ "&#x3b5;": "epsilon",
15
15
  "&#x25b;": "varepsilon",
16
- "&#x3B6;": "zeta",
17
- "&#x3B7;": "eta",
18
- "&#x3B8;": "theta",
16
+ "&#x3b6;": "zeta",
17
+ "&#x3b7;": "eta",
18
+ "&#x3b8;": "theta",
19
19
  "&#x398;": "Theta",
20
- "&#x3D1;": "vartheta",
21
- "&#x3B9;": "iota",
22
- "&#x3BA;": "kappa",
23
- "&#x3BB;": "lambda",
24
- "&#x39B;": "Lambda",
25
- "&#x3BC;": "mu",
26
- "&#x3BD;": "nu",
27
- "&#x3BE;": "xi",
28
- "&#x39E;": "Xi",
20
+ "&#x3d1;": "vartheta",
21
+ "&#x3b9;": "iota",
22
+ "&#x3ba;": "kappa",
23
+ "&#x3bb;": "lambda",
24
+ "&#x39b;": "Lambda",
25
+ "&#x3bc;": "mu",
26
+ "&#x3bd;": "nu",
27
+ "&#x3be;": "xi",
28
+ "&#x39e;": "Xi",
29
29
  "&#x3C0;": "pi",
30
- "&#x3A0;": "Pi",
31
- "&#x3C1;": "rho",
32
- "&#x3C2;": "beta",
33
- "&#x3C3;": "sigma",
34
- "&#x3A3;": "Sigma",
35
- "&#x3C4;": "tau",
36
- "&#x3C5;": "upsilon",
37
- "&#x3C6;": "phi",
38
- "&#x3A6;": "Phi",
39
- "&#x3D5;": "varphi",
40
- "&#x3C7;": "chi",
41
- "&#x3C8;": "psi",
42
- "&#x3A8;": "Psi",
43
- "&#x3C9;": "omega",
44
- "&#x3A9;": "omega",
45
- "&#x22C5;": "dot",
30
+ "&#x3a0;": "Pi",
31
+ "&#x3c1;": "rho",
32
+ "&#x3c2;": "beta",
33
+ "&#x3c3;": "sigma",
34
+ "&#x3a3;": "Sigma",
35
+ "&#x3c4;": "tau",
36
+ "&#x3c5;": "upsilon",
37
+ "&#x3c6;": "phi",
38
+ "&#x3a6;": "Phi",
39
+ "&#x3d5;": "varphi",
40
+ "&#x3c7;": "chi",
41
+ "&#x3c8;": "psi",
42
+ "&#x3a8;": "Psi",
43
+ "&#x3c9;": "omega",
44
+ "&#x3a9;": "omega",
45
+ "&#x22c5;": "dot",
46
46
  "&#x2219;": "*",
47
- "&#xB7;": ".",
47
+ "&#xb7;": ".",
48
48
  "&#x2217;": "**",
49
- "&#x22C6;": "***",
50
- "&#xD7;": "xx",
51
- "&#x22C9;": "|><",
52
- "&#x22CA;": "><|",
53
- "&#x22C8;": "|><|",
54
- "&#xF7;": "-:",
49
+ "&#x22c6;": "***",
50
+ "&#xd7;": "xx",
51
+ "&#x22c9;": "|><",
52
+ "&#x22ca;": "><|",
53
+ "&#x22c8;": "|><|",
54
+ "&#xf7;": "-:",
55
55
  "&#x2218;": "@",
56
56
  "&#x2295;": "o+",
57
- "&#x2A01;": "o+",
57
+ "&#x2a01;": "o+",
58
58
  "&#x2297;": "ox",
59
59
  "&#x2299;": " ",
60
60
  "&#x2211;": "sum",
61
- "&#x220F;": "prod",
62
61
  "&#x220f;": "prod",
63
62
  "&#x2227;": "^^",
64
- "&#x22C0;": "^^^",
63
+ "&#x22c0;": "^^^",
65
64
  "&#x2228;": "vv",
66
65
  "&#x22c1;": "vvv",
67
66
  "&#x2229;": "nn",
68
- "&#x22C2;": "nnn",
69
- "&#x222A;": "cup",
70
- "&#x22C3;": "uuu",
67
+ "&#x22c2;": "nnn",
68
+ "&#x222a;": "cup",
69
+ "&#x22c3;": "uuu",
71
70
  "&#x2260;": "!=",
72
71
  "&#x2264;": "<=",
73
72
  "&#x2265;": ">=",
74
- "&#x227A;": "-<",
75
- "&#x227B;": ">-",
76
- "&#x2AAF;": "-<=",
77
- "&#x2AB0;": " >-=",
73
+ "&#x227a;": "-<",
74
+ "&#x227b;": ">-",
75
+ "&#x2aaf;": "-<=",
76
+ "&#x2ab0;": " >-=",
78
77
  "&#x2208;": "in",
79
78
  "&#x2209;": "!in",
80
79
  "&#x2282;": "sub",
@@ -84,65 +83,68 @@ module Plurimath
84
83
  "&#x2261;": "-=",
85
84
  "&#x2245;": "~=",
86
85
  "&#x2248;": "~~",
87
- "&#x221D;": "prop",
88
- "&#xAC;": "not",
86
+ "&#x221d;": "prop",
87
+ "&#xac;": "not",
89
88
  "&#x2200;": "AA",
90
89
  "&#x2203;": "EE",
91
- "&#x22A5;": "_|_",
92
- "&#x22A4;": "TT",
93
- "&#x22A2;": "|--",
94
- "&#x22A8;": "|==",
90
+ "&#x22a5;": "_|_",
91
+ "&#x22a4;": "TT",
92
+ "&#x22a2;": "|--",
93
+ "&#x22a8;": "|==",
95
94
  "&#x2329;": "(:",
96
- "&#x232A;": ":)",
97
- "&#x27E8;": "<<",
98
- "&#x27E9;": ">>",
99
- "&#x222B;": "int",
100
- "&#x222E;": "oint",
95
+ "&#x232a;": ":)",
96
+ "&#x27e8;": "<<",
97
+ "&#x27e9;": ">>",
98
+ "&#x222b;": "int",
99
+ "&#x222e;": "oint",
101
100
  "&#x2202;": "del",
102
101
  "&#x2207;": "grad",
103
- "&#xB1;": "+-",
102
+ "&#xb1;": "+-",
104
103
  "&#x2205;": "O/",
105
- "&#x221E;": "oo",
104
+ "&#x221e;": "oo",
106
105
  "&#x2135;": "aleph",
107
106
  "&#x2234;": ":.",
108
107
  "&#x2235;": ":'",
109
108
  "&#x2220;": "/_",
110
- "&#x25B3;": "/_\\",
109
+ "&#x25b3;": "/_\\",
111
110
  "&#x2032;": "'",
112
- "&#xA0;&#xA0;": "quad",
113
- "&#xA0;&#xA0;&#xA0;&#xA0;": "qquad",
111
+ "&#xa0;&#xa0;": "quad",
112
+ "&#xa0;&#xa0;&#xa0;&#xa0;": "qquad",
114
113
  "&#x2322;": "frown",
115
- "&#x22EF;": "cdots",
116
- "&#x22EE;": "vdots",
117
- "&#x22F1;": "ddots",
118
- "&#x22C4;": "diamond",
119
- "&#x25A1;": "square",
120
- "&#x230A;": "|__",
121
- "&#x230B;": "__|",
114
+ "&#x22ef;": "cdots",
115
+ "&#x22ee;": "vdots",
116
+ "&#x22f1;": "ddots",
117
+ "&#x22c4;": "diamond",
118
+ "&#x25a1;": "square",
119
+ "&#x230a;": "|__",
120
+ "&#x230b;": "__|",
122
121
  "&#x2308;": "|~",
123
122
  "&#x2309;": "~|",
124
123
  "&#x2102;": "CC",
125
124
  "&#x2115;": "NN",
126
- "&#x211A;": "QQ",
127
- "&#x211D;": "RR",
125
+ "&#x211a;": "QQ",
126
+ "&#x211d;": "RR",
128
127
  "&#x2124;": "ZZ",
129
128
  "&#x2191;": "uarr",
130
129
  "&#x2193;": "darr",
131
130
  "&#x2190;": "larr",
132
131
  "&#x2194;": "harr",
133
- "&#x21D2;": "rArr",
134
- "&#x21D0;": "lArr",
135
- "&#x21D4;": "hArr",
132
+ "&#x21d2;": "rArr",
133
+ "&#x21d0;": "lArr",
134
+ "&#x21d4;": "hArr",
136
135
  "&#x2192;": "->",
137
- "&#x21A3;": ">->",
138
- "&#x21A0;": "->>",
136
+ "&#x21a3;": ">->",
137
+ "&#x21a0;": "->>",
139
138
  "&#x2916;": ">->>",
140
- "&#x21A6;": "|->",
139
+ "&#x21a6;": "|->",
141
140
  "&#x2026;": "...",
142
141
  "&#x2212;": "-",
143
- "&#x2061;": "",
144
- "&#x23DE;": "obrace",
145
- "&#x23DF;": "ubrace",
142
+ "&#x23de;": "obrace",
143
+ "&#x23df;": "ubrace",
144
+ "&#x26;": "&",
145
+ "&#x3e;": ">",
146
+ "&#x3c;": "<",
147
+ "&amp;": "&",
146
148
  }.freeze
147
149
  SYMBOLS = {
148
150
  "|": "|",
@@ -226,69 +228,144 @@ module Plurimath
226
228
  f
227
229
  g
228
230
  ].freeze
229
- TAGS = %i[
230
- annotation-xml
231
- annotation_xml
232
- mmultiscripts
233
- maligngroup
234
- malignmark
235
- annotation
236
- munderover
237
- mscarries
238
- semantics
239
- mphantom
240
- mlongdiv
241
- menclose
242
- mscarry
243
- msubsup
244
- mpadded
245
- maction
246
- msgroup
247
- mfenced
248
- merror
249
- munder
250
- mtable
251
- mstyle
252
- mstack
253
- mspace
254
- msline
255
- mfrac
256
- mover
257
- msrow
258
- mroot
259
- msqrt
260
- msup
261
- msub
262
- mrow
263
- math
264
- mtr
265
- mtd
266
- ms
267
- mi
268
- mo
269
- mn
270
- ].freeze
271
- BINARY_CLASSES = %i[
272
- underset
273
- stackrel
274
- overset
275
- color
276
- prod
277
- frac
278
- root
279
- oint
280
- int
281
- sum
282
- mod
283
- log
284
- ].freeze
285
- FONT_CLASSES = %i[
286
- double-struck
287
- sans-serif
288
- monospace
289
- fraktur
290
- script
291
- bold
231
+ OPERATORS = [
232
+ "&#x00a0;&#x00a0;&#x00a0;&#x00a0;",
233
+ "&#x00a0;&#x00a0;",
234
+ "&#x002a;",
235
+ "&#x003c;",
236
+ "&#x003e;",
237
+ "&#x00a0;",
238
+ "&#x00ac;",
239
+ "&#x00b1;",
240
+ "&#x00d7;",
241
+ "&#x00f7;",
242
+ "&#x0393;",
243
+ "&#x0394;",
244
+ "&#x0398;",
245
+ "&#x039b;",
246
+ "&#x039e;",
247
+ "&#x03a0;",
248
+ "&#x03a3;",
249
+ "&#x03a9;",
250
+ "&#x2026;",
251
+ "&#x2032;",
252
+ "&#x2102;",
253
+ "&#x2115;",
254
+ "&#x211a;",
255
+ "&#x211d;",
256
+ "&#x2124;",
257
+ "&#x2135;",
258
+ "&#x2190;",
259
+ "&#x2191;",
260
+ "&#x2192;",
261
+ "&#x2192;",
262
+ "&#x2193;",
263
+ "&#x2194;",
264
+ "&#x21a0;",
265
+ "&#x21a3;",
266
+ "&#x21a6;",
267
+ "&#x21d0;",
268
+ "&#x21d2;",
269
+ "&#x21d2;",
270
+ "&#x21d4;",
271
+ "&#x21d4;",
272
+ "&#x2200;",
273
+ "&#x2202;",
274
+ "&#x2203;",
275
+ "&#x2205;",
276
+ "&#x2207;",
277
+ "&#x2208;",
278
+ "&#x2209;",
279
+ "&#x220f;",
280
+ "&#x2211;",
281
+ "&#x2212;",
282
+ "&#x2213;",
283
+ "&#x221d;",
284
+ "&#x221e;",
285
+ "&#x2220;",
286
+ "&#x2227;",
287
+ "&#x2228;",
288
+ "&#x2229;",
289
+ "&#x222a;",
290
+ "&#x222b;",
291
+ "&#x222e;",
292
+ "&#x2234;",
293
+ "&#x2235;",
294
+ "&#x223c;",
295
+ "&#x2245;",
296
+ "&#x2248;",
297
+ "&#x2254;",
298
+ "&#x2260;",
299
+ "&#x2261;",
300
+ "&#x2264;",
301
+ "&#x2265;",
302
+ "&#x226a;",
303
+ "&#x226b;",
304
+ "&#x227a;",
305
+ "&#x227b;",
306
+ "&#x2282;",
307
+ "&#x2283;",
308
+ "&#x2286;",
309
+ "&#x2287;",
310
+ "&#x2295;",
311
+ "&#x2297;",
312
+ "&#x2299;",
313
+ "&#x22a2;",
314
+ "&#x22a4;",
315
+ "&#x22a5;",
316
+ "&#x22a8;",
317
+ "&#x22c0;",
318
+ "&#x22c1;",
319
+ "&#x22c2;",
320
+ "&#x22c3;",
321
+ "&#x22c4;",
322
+ "&#x22c5;",
323
+ "&#x22c6;",
324
+ "&#x22c8;",
325
+ "&#x22c9;",
326
+ "&#x22ca;",
327
+ "&#x22ee;",
328
+ "&#x22ef;",
329
+ "&#x22f1;",
330
+ "&#x2308;",
331
+ "&#x2309;",
332
+ "&#x230a;",
333
+ "&#x230b;",
334
+ "&#x2322;",
335
+ "&#x25a1;",
336
+ "&#x25b3;",
337
+ "&#x26ac;",
338
+ "&#x2916;",
339
+ "&#x2aaf;",
340
+ "&#x2ab0;",
341
+ "&#x2b;",
342
+ "&#x3d;",
343
+ "&#x3a;",
344
+ "&#x3c;",
345
+ "&#xd7;",
346
+ "&#xb1;",
347
+ "&#x26;",
348
+ "&#x3b;",
349
+ "&#x3e;",
350
+ "&#x7c;",
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.gsub(/\s/, "")
11
+ @text = text
13
12
  end
14
13
 
15
14
  def parse
16
- tree_t = Plurimath::Mathml::Parse.new.parse(text)
17
- tree_t = JSON.parse(tree_t.to_json, symbolize_names: true)
18
- formula = Plurimath::Mathml::Transform.new.apply(tree_t)
19
- formula = [formula] unless formula.is_a?(Array) || formula.nil?
20
- return if formula.nil?
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
- Plurimath::Math::Formula.new(formula)
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