plurimath 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +33 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +2 -0
  5. data/AsciiMath-Supported-Data.adoc +280 -0
  6. data/Gemfile +1 -0
  7. data/Latex-Supported-Data.adoc +1872 -0
  8. data/MathML-Supported-Data.adoc +270 -0
  9. data/README.adoc +94 -0
  10. data/lib/plurimath/asciimath/constants.rb +301 -0
  11. data/lib/plurimath/asciimath/parse.rb +121 -0
  12. data/lib/plurimath/asciimath/parser.rb +25 -0
  13. data/lib/plurimath/asciimath/transform.rb +395 -0
  14. data/lib/plurimath/asciimath.rb +16 -0
  15. data/lib/plurimath/html/constants.rb +50 -0
  16. data/lib/plurimath/html/parse.rb +149 -0
  17. data/lib/plurimath/html/parser.rb +26 -0
  18. data/lib/plurimath/html/transform.rb +363 -0
  19. data/lib/plurimath/html.rb +15 -0
  20. data/lib/plurimath/latex/constants.rb +1990 -0
  21. data/lib/plurimath/latex/parse.rb +198 -0
  22. data/lib/plurimath/latex/parser.rb +25 -0
  23. data/lib/plurimath/latex/transform.rb +458 -0
  24. data/lib/plurimath/latex.rb +15 -0
  25. data/lib/plurimath/math/formula.rb +51 -0
  26. data/lib/plurimath/math/function/abs.rb +12 -0
  27. data/lib/plurimath/math/function/arccos.rb +12 -0
  28. data/lib/plurimath/math/function/arcsin.rb +12 -0
  29. data/lib/plurimath/math/function/arctan.rb +12 -0
  30. data/lib/plurimath/math/function/bar.rb +16 -0
  31. data/lib/plurimath/math/function/base.rb +36 -0
  32. data/lib/plurimath/math/function/binary_function.rb +58 -0
  33. data/lib/plurimath/math/function/cancel.rb +12 -0
  34. data/lib/plurimath/math/function/ceil.rb +12 -0
  35. data/lib/plurimath/math/function/color.rb +23 -0
  36. data/lib/plurimath/math/function/cos.rb +12 -0
  37. data/lib/plurimath/math/function/cosh.rb +12 -0
  38. data/lib/plurimath/math/function/cot.rb +12 -0
  39. data/lib/plurimath/math/function/coth.rb +12 -0
  40. data/lib/plurimath/math/function/csc.rb +12 -0
  41. data/lib/plurimath/math/function/csch.rb +12 -0
  42. data/lib/plurimath/math/function/ddot.rb +12 -0
  43. data/lib/plurimath/math/function/deg.rb +12 -0
  44. data/lib/plurimath/math/function/det.rb +12 -0
  45. data/lib/plurimath/math/function/dim.rb +12 -0
  46. data/lib/plurimath/math/function/dot.rb +12 -0
  47. data/lib/plurimath/math/function/exp.rb +12 -0
  48. data/lib/plurimath/math/function/f.rb +12 -0
  49. data/lib/plurimath/math/function/fenced.rb +27 -0
  50. data/lib/plurimath/math/function/floor.rb +12 -0
  51. data/lib/plurimath/math/function/font_style/bold.rb +18 -0
  52. data/lib/plurimath/math/function/font_style/double_struck.rb +18 -0
  53. data/lib/plurimath/math/function/font_style/fraktur.rb +18 -0
  54. data/lib/plurimath/math/function/font_style/monospace.rb +18 -0
  55. data/lib/plurimath/math/function/font_style/sans-serif.rb +18 -0
  56. data/lib/plurimath/math/function/font_style/script.rb +18 -0
  57. data/lib/plurimath/math/function/font_style.rb +25 -0
  58. data/lib/plurimath/math/function/frac.rb +23 -0
  59. data/lib/plurimath/math/function/g.rb +12 -0
  60. data/lib/plurimath/math/function/gcd.rb +12 -0
  61. data/lib/plurimath/math/function/glb.rb +12 -0
  62. data/lib/plurimath/math/function/hat.rb +12 -0
  63. data/lib/plurimath/math/function/hom.rb +12 -0
  64. data/lib/plurimath/math/function/inf.rb +17 -0
  65. data/lib/plurimath/math/function/int.rb +17 -0
  66. data/lib/plurimath/math/function/ker.rb +12 -0
  67. data/lib/plurimath/math/function/lcm.rb +12 -0
  68. data/lib/plurimath/math/function/left.rb +20 -0
  69. data/lib/plurimath/math/function/lg.rb +12 -0
  70. data/lib/plurimath/math/function/lim.rb +23 -0
  71. data/lib/plurimath/math/function/liminf.rb +12 -0
  72. data/lib/plurimath/math/function/limits.rb +18 -0
  73. data/lib/plurimath/math/function/limsup.rb +12 -0
  74. data/lib/plurimath/math/function/ln.rb +12 -0
  75. data/lib/plurimath/math/function/log.rb +29 -0
  76. data/lib/plurimath/math/function/lub.rb +12 -0
  77. data/lib/plurimath/math/function/max.rb +12 -0
  78. data/lib/plurimath/math/function/min.rb +12 -0
  79. data/lib/plurimath/math/function/mod.rb +29 -0
  80. data/lib/plurimath/math/function/multiscript.rb +11 -0
  81. data/lib/plurimath/math/function/norm.rb +16 -0
  82. data/lib/plurimath/math/function/obrace.rb +12 -0
  83. data/lib/plurimath/math/function/oint.rb +17 -0
  84. data/lib/plurimath/math/function/over.rb +29 -0
  85. data/lib/plurimath/math/function/overset.rb +23 -0
  86. data/lib/plurimath/math/function/power.rb +36 -0
  87. data/lib/plurimath/math/function/power_base.rb +33 -0
  88. data/lib/plurimath/math/function/prod.rb +29 -0
  89. data/lib/plurimath/math/function/right.rb +24 -0
  90. data/lib/plurimath/math/function/root.rb +23 -0
  91. data/lib/plurimath/math/function/sec.rb +12 -0
  92. data/lib/plurimath/math/function/sech.rb +12 -0
  93. data/lib/plurimath/math/function/sin.rb +12 -0
  94. data/lib/plurimath/math/function/sinh.rb +12 -0
  95. data/lib/plurimath/math/function/sqrt.rb +16 -0
  96. data/lib/plurimath/math/function/stackrel.rb +12 -0
  97. data/lib/plurimath/math/function/substack.rb +17 -0
  98. data/lib/plurimath/math/function/sum.rb +29 -0
  99. data/lib/plurimath/math/function/sup.rb +12 -0
  100. data/lib/plurimath/math/function/table/align.rb +24 -0
  101. data/lib/plurimath/math/function/table/array.rb +25 -0
  102. data/lib/plurimath/math/function/table/bmatrix.rb +26 -0
  103. data/lib/plurimath/math/function/table/matrix.rb +24 -0
  104. data/lib/plurimath/math/function/table/multline.rb +24 -0
  105. data/lib/plurimath/math/function/table/pmatrix.rb +24 -0
  106. data/lib/plurimath/math/function/table/split.rb +24 -0
  107. data/lib/plurimath/math/function/table/vmatrix.rb +25 -0
  108. data/lib/plurimath/math/function/table.rb +54 -0
  109. data/lib/plurimath/math/function/tan.rb +12 -0
  110. data/lib/plurimath/math/function/tanh.rb +12 -0
  111. data/lib/plurimath/math/function/td.rb +32 -0
  112. data/lib/plurimath/math/function/ternary_function.rb +52 -0
  113. data/lib/plurimath/math/function/text.rb +44 -0
  114. data/lib/plurimath/math/function/tilde.rb +12 -0
  115. data/lib/plurimath/math/function/tr.rb +30 -0
  116. data/lib/plurimath/math/function/ubrace.rb +12 -0
  117. data/lib/plurimath/math/function/ul.rb +12 -0
  118. data/lib/plurimath/math/function/unary_function.rb +46 -0
  119. data/lib/plurimath/math/function/underover.rb +12 -0
  120. data/lib/plurimath/math/function/underset.rb +12 -0
  121. data/lib/plurimath/math/function/vec.rb +16 -0
  122. data/lib/plurimath/math/function.rb +14 -0
  123. data/lib/plurimath/math/number.rb +37 -0
  124. data/lib/plurimath/math/symbol.rb +43 -0
  125. data/lib/plurimath/math.rb +56 -0
  126. data/lib/plurimath/mathml/constants.rb +295 -0
  127. data/lib/plurimath/mathml/parse.rb +68 -0
  128. data/lib/plurimath/mathml/parser.rb +26 -0
  129. data/lib/plurimath/mathml/transform.rb +200 -0
  130. data/lib/plurimath/mathml.rb +16 -0
  131. data/lib/plurimath/omml/constants.rb +154 -0
  132. data/lib/plurimath/omml/parser.rb +22 -0
  133. data/lib/plurimath/omml/transform.rb +216 -0
  134. data/lib/plurimath/omml.rb +15 -0
  135. data/lib/plurimath/unicode.rb +15 -0
  136. data/lib/plurimath/unitsml.rb +15 -0
  137. data/lib/plurimath/utility.rb +73 -0
  138. data/lib/plurimath/version.rb +3 -1
  139. data/lib/plurimath.rb +3 -5
  140. data/plurimath.gemspec +4 -3
  141. metadata +169 -9
  142. data/README.md +0 -40
@@ -0,0 +1,200 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class Mathml
5
+ class Transform < Parslet::Transform
6
+ rule(tag: simple(:tag)) { tag }
7
+ rule(tag: sequence(:tag)) { tag }
8
+ rule(text: simple(:text)) { Math::Symbol.new(text) }
9
+ rule(class: simple(:string)) { Utility.get_class(string).new }
10
+ rule(number: simple(:number)) { Math::Number.new(number) }
11
+
12
+ rule(tag: sequence(:tag), sequence: simple(:sequence)) do
13
+ tag + [sequence]
14
+ end
15
+
16
+ rule(tag: simple(:tag), sequence: sequence(:sequence)) do
17
+ [tag] + sequence
18
+ end
19
+
20
+ rule(tag: sequence(:tag), sequence: sequence(:sequence)) do
21
+ tag + sequence
22
+ end
23
+
24
+ rule(quoted_text: simple(:quoted_text)) do
25
+ text = quoted_text
26
+ symbols = Constants::UNICODE_SYMBOLS.transform_keys(&:to_s)
27
+ symbols.each do |code, string|
28
+ text.gsub!(code, "unicode[:#{string}]")
29
+ end
30
+ Math::Function::Text.new(text)
31
+ end
32
+
33
+ rule(
34
+ tag: sequence(:tag),
35
+ sequence: sequence(:sequence),
36
+ iteration: simple(:iteration),
37
+ ) do
38
+ new_arr = []
39
+ new_arr = new_arr + tag unless tag.compact.empty?
40
+ new_arr = new_arr + sequence unless sequence.compact.empty?
41
+ new_arr << iteration unless iteration.to_s.empty?
42
+ new_arr
43
+ end
44
+
45
+ rule(
46
+ tag: sequence(:tag),
47
+ sequence: simple(:sequence),
48
+ iteration: simple(:iteration),
49
+ ) do
50
+ Math::Formula.new(tag + [sequence, iteration])
51
+ end
52
+
53
+ rule(
54
+ tag: simple(:tag),
55
+ sequence: simple(:sequence),
56
+ iteration: simple(:iteration),
57
+ ) do
58
+ iteration.size.zero? ? [tag, sequence] : [tag, sequence, iteration]
59
+ end
60
+
61
+ rule(tag: sequence(:tag), iteration: simple(:iteration)) do
62
+ new_arr = []
63
+ new_arr = tag unless tag.compact.empty?
64
+ new_arr << iteration unless iteration.to_s.empty?
65
+ new_arr
66
+ end
67
+
68
+ rule(tag: simple(:tag), sequence: simple(:sequence)) do
69
+ new_arr = []
70
+ new_arr << tag unless tag.nil?
71
+ new_arr << sequence unless sequence.nil?
72
+ new_arr
73
+ end
74
+
75
+ rule(tag: simple(:tag), iteration: simple(:iteration)) do
76
+ new_arr = []
77
+ new_arr << tag unless tag.to_s.empty?
78
+ new_arr << iteration unless iteration.to_s.empty?
79
+ new_arr
80
+ end
81
+
82
+ rule(symbol: simple(:symbol)) do
83
+ decoded_symbol = Constants::UNICODE_SYMBOLS[symbol.to_sym]
84
+ if Constants::CLASSES.include?(decoded_symbol)
85
+ [Utility.get_class(decoded_symbol).new]
86
+ elsif decoded_symbol.nil? && Constants::SYMBOLS[symbol.to_sym]
87
+ Math::Symbol.new(Constants::SYMBOLS[symbol.to_sym])
88
+ else
89
+ Math::Symbol.new(decoded_symbol)
90
+ end
91
+ end
92
+
93
+ rule(name: simple(:name), value: simple(:value)) do
94
+ if ["open", "close"].include?(name)
95
+ Math::Symbol.new(value)
96
+ elsif name == "mathcolor"
97
+ Math::Function::Color.new(value)
98
+ elsif name == "mathvariant"
99
+ value
100
+ end
101
+ end
102
+
103
+ rule(
104
+ tag: simple(:tag),
105
+ sequence: sequence(:sequence),
106
+ iteration: simple(:iteration),
107
+ ) do
108
+ new_arr = sequence.compact
109
+ new_arr = [tag] + new_arr unless tag.nil?
110
+ new_arr << iteration unless iteration.to_s.empty?
111
+ new_arr
112
+ end
113
+
114
+ rule(
115
+ open: simple(:open_tag),
116
+ attributes: sequence(:attributes),
117
+ iteration: sequence(:iteration),
118
+ close: simple(:close_tag),
119
+ ) do
120
+ Utility.raise_error!(open_tag, close_tag) unless open_tag == close_tag
121
+
122
+ if open_tag == "mrow"
123
+ Math::Formula.new(iteration)
124
+ elsif open_tag == "munder"
125
+ if iteration.last.class_name == "obrace"
126
+ iteration.last.parameter_one = iteration.first
127
+ iteration.last
128
+ else
129
+ Math::Function::Underset.new(iteration[1], iteration[0])
130
+ end
131
+ elsif open_tag == "munderover"
132
+ Utility.get_class(open_tag.delete_prefix("m")).new(
133
+ iteration[0],
134
+ iteration[1],
135
+ iteration[2],
136
+ )
137
+ elsif open_tag == "mover"
138
+ if iteration.last.class_name == "ubrace"
139
+ iteration.last.parameter_one = iteration.first
140
+ iteration.last
141
+ else
142
+ Math::Function::Overset.new(iteration[1], iteration[0])
143
+ end
144
+ elsif ["msub", "msup"].include?(open_tag)
145
+ tag = (open_tag == "msup" ? "power" : "base")
146
+ Utility.get_class(tag).new(iteration[0], iteration[1])
147
+ elsif open_tag == "msubsup"
148
+ Math::Function::PowerBase.new(iteration[0],
149
+ iteration[1],
150
+ iteration[2])
151
+ elsif open_tag == "mfrac"
152
+ Math::Function::Frac.new(iteration.first, iteration.last)
153
+ elsif open_tag == "msqrt"
154
+ Math::Function::Sqrt.new(iteration.first)
155
+ elsif open_tag == "mroot"
156
+ Math::Function::Root.new(iteration[0], iteration[1])
157
+ elsif open_tag == "mfenced"
158
+ Math::Function::Fenced.new(
159
+ attributes[0],
160
+ iteration,
161
+ attributes[1],
162
+ )
163
+ elsif ["mtr", "mtd", "mtable"].include?(open_tag)
164
+ tag = open_tag.delete_prefix("m")
165
+ Utility.get_class(tag).new(iteration)
166
+ elsif attributes.first.is_a?(Math::Function::Color)
167
+ attributes.first.parameter_two = iteration.first
168
+ attributes.first
169
+ elsif open_tag == "mstyle" && !attributes.compact.empty?
170
+ font_type = attributes.compact.last
171
+ if Utility::FONT_STYLES.key?(font_type.to_sym)
172
+ Utility::FONT_STYLES[font_type.to_sym].new(
173
+ iteration.last,
174
+ font_type,
175
+ )
176
+ else
177
+ Math::Function::FontStyle.new(iteration.last, font_type)
178
+ end
179
+ else
180
+ iteration
181
+ end
182
+ end
183
+
184
+ rule(
185
+ open: simple(:open_tag),
186
+ attributes: sequence(:attributes),
187
+ iteration: simple(:iteration),
188
+ close: simple(:close_tag),
189
+ ) do
190
+ Utility.raise_error!(open_tag, close_tag) unless open_tag == close_tag
191
+
192
+ if iteration.to_s.include?("Function")
193
+ iteration
194
+ else
195
+ [iteration.to_s.empty? ? nil : iteration]
196
+ end
197
+ end
198
+ end
199
+ end
200
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "math"
4
+ module Plurimath
5
+ class Mathml
6
+ attr_accessor :text
7
+
8
+ def initialize(text)
9
+ @text = text
10
+ end
11
+
12
+ def to_formula
13
+ Parser.new(text).parse
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,154 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class Omml
5
+ class Constants
6
+ TAGS = %w[
7
+ lastRenderedPageBreak
8
+ oMathParaPr
9
+ borderBoxPr
10
+ wrapIndent
11
+ strikeTLBR
12
+ strikeBLTR
13
+ groupChrPr
14
+ wrapRight
15
+ smallFrac
16
+ oMathPara
17
+ hideRight
18
+ brkBinSub
19
+ borderBox
20
+ sSubSupPr
21
+ zeroDesc
22
+ mathFont
23
+ limUppPr
24
+ limLowPr
25
+ hideLeft
26
+ groupChr
27
+ zeroWid
28
+ zeroAsc
29
+ strikeV
30
+ strikeH
31
+ rSpRule
32
+ rMargin
33
+ plcHide
34
+ phantPr
35
+ objDist
36
+ noBreak
37
+ naryLim
38
+ maxDist
39
+ lMargin
40
+ intraSp
41
+ interSp
42
+ hideTop
43
+ hideBot
44
+ eqArrPr
45
+ dispDef
46
+ degHide
47
+ cGpRule
48
+ supHide
49
+ subHide
50
+ vertJc
51
+ transp
52
+ sSupPr
53
+ sSubPr
54
+ sepChr
55
+ postSp
56
+ naryPr
57
+ mathPr
58
+ limUpp
59
+ limLow
60
+ rFonts
61
+ limLoc
62
+ intLim
63
+ funcPr
64
+ endChr
65
+ ctrlPr
66
+ brkBin
67
+ begChr
68
+ baseJc
69
+ alnScr
70
+ sPrePr
71
+ radPr
72
+ preSp
73
+ phant
74
+ opEmu
75
+ oMath
76
+ fName
77
+ eqArr
78
+ defJc
79
+ count
80
+ boxPr
81
+ barPr
82
+ argSz
83
+ argPr
84
+ accPr
85
+ type
86
+ show
87
+ mcPr
88
+ mcJc
89
+ grow
90
+ diff
91
+ sty
92
+ shp
93
+ scr
94
+ rSp
95
+ rPr
96
+ sup
97
+ sub
98
+ pos
99
+ num
100
+ nor
101
+ mPr
102
+ mcs
103
+ lit
104
+ lim
105
+ fPr
106
+ dPr
107
+ den
108
+ deg
109
+ cSp
110
+ chr
111
+ cGp
112
+ brk
113
+ box
114
+ bar
115
+ aln
116
+ mr
117
+ mc
118
+ jc
119
+ t
120
+ r
121
+ i
122
+ m
123
+ e
124
+ ].freeze
125
+ SUB_SUP_TAG = %w[
126
+ sSubSup
127
+ func
128
+ sPre
129
+ sSup
130
+ sSub
131
+ nary
132
+ acc
133
+ rad
134
+ f
135
+ d
136
+ ].freeze
137
+ UNARY_FUNCTIONS = %w[
138
+ arcsin
139
+ arctan
140
+ arccos
141
+ coth
142
+ tanh
143
+ sinh
144
+ cosh
145
+ tan
146
+ cos
147
+ cot
148
+ csc
149
+ sin
150
+ sec
151
+ ].freeze
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "constants"
4
+ require_relative "transform"
5
+ module Plurimath
6
+ class Omml
7
+ class Parser
8
+ attr_accessor :text
9
+
10
+ def initialize(text)
11
+ @text = CGI.unescape(text)
12
+ end
13
+
14
+ def parse
15
+ nodes = Ox.load(text, mode: :hash, strip_namespace: true)
16
+ Math::Formula.new(
17
+ Transform.new.apply(nodes),
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,216 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parslet"
4
+ module Plurimath
5
+ class Omml
6
+ class Transform < Parslet::Transform
7
+ rule(r: simple(:r)) { r }
8
+ rule(f: simple(:f)) { f }
9
+ rule(d: simple(:d)) { Math::Function::Fenced.new(nil, [d], nil) }
10
+ rule(val: simple(:val)) { val }
11
+ rule(box: simple(:box)) { box }
12
+ rule(rPr: simple(:rpr)) { nil }
13
+ rule(rad: simple(:rad)) { rad }
14
+ rule(sSub: simple(:sub)) { sub }
15
+ rule(eqArr: simple(:arr)) { arr }
16
+ rule(nary: simple(:nary)) { nary }
17
+ rule(sSup: simple(:sSup)) { sSup }
18
+ rule(sPre: simple(:sPre)) { sPre }
19
+ rule(ctrlPr: simple(:ctrlPr)) { nil }
20
+ rule(argSz: sequence(:argsz)) { nil }
21
+ rule(rFonts: sequence(:fonts)) { nil }
22
+ rule(sSubSup: simple(:sSubSup)) { sSubSup }
23
+ rule(oMathPara: subtree(:omath)) { omath.drop(1) }
24
+ rule(rPr: simple(:rpr), i: simple(:i)) { nil }
25
+ rule(dPr: simple(:dpr), e: simple(:e)) { e }
26
+ rule(dPr: simple(:dpr), e: sequence(:e)) { e }
27
+ rule(boxPr: simple(:boxpr), e: simple(:e)) { e }
28
+ rule(argPr: simple(:argPr), f: simple(:f)) { f }
29
+ rule(rFonts: sequence(:fonts), i: simple(:i)) { nil }
30
+ rule(type: sequence(:type), ctrlPr: simple(:ctrl)) { nil }
31
+ rule(ascii: simple(:ascii), hAnsi: simple(:hansi)) { nil }
32
+ rule(diff: sequence(:diff), ctrlPr: simple(:ctrl)) { nil }
33
+ rule(limLoc: sequence(:limloc), ctrlPr: simple(:ctrl)) { limloc }
34
+ rule(degHide: sequence(:degHide), ctrlPr: simple(:ctrl)) { nil }
35
+
36
+ rule(oMath: subtree(:omath)) do
37
+ omath.is_a?(Array) ? omath.drop(1) : omath
38
+ end
39
+
40
+ rule(d: sequence(:d)) do
41
+ open_paren = d.shift if d.first.class_name == "symbol"
42
+ close_paren = d.pop if d.last.class_name == "symbol"
43
+ Math::Function::Fenced.new(
44
+ open_paren,
45
+ d,
46
+ close_paren,
47
+ )
48
+ end
49
+
50
+ rule(dPr: sequence(:dpr),
51
+ e: simple(:e)) do
52
+ [
53
+ dpr[0],
54
+ e,
55
+ dpr[1],
56
+ ]
57
+ end
58
+
59
+ rule(sSub: sequence(:sub), r: simple(:r)) do
60
+ [
61
+ Math::Formula.new(
62
+ sub.insert(1, r),
63
+ ),
64
+ ]
65
+ end
66
+
67
+ rule(rPr: simple(:rpr), t: subtree(:t)) do
68
+ Math::Function::Text.new(t.last)
69
+ end
70
+
71
+ rule(r: simple(:r), d: simple(:d)) do
72
+ Math::Formula.new(
73
+ [
74
+ r,
75
+ d,
76
+ ],
77
+ )
78
+ end
79
+
80
+ rule(eqArrPr: simple(:aqArrPr), e: sequence(:e)) do
81
+ table_value = []
82
+ e.each do |value|
83
+ table_value << Math::Function::Tr.new(
84
+ [
85
+ Math::Function::Td.new(
86
+ [
87
+ value,
88
+ ],
89
+ ),
90
+ ],
91
+ )
92
+ end
93
+ Math::Function::Table.new(table_value)
94
+ end
95
+
96
+ rule(rPr: simple(:rpr),
97
+ t: simple(:text)) do
98
+ if text.scan(/[[:digit:]]/).length == text.length
99
+ Math::Number.new(text)
100
+ elsif text.match?(/[[:alpha:]]/)
101
+ Math::Function::Text.new(text)
102
+ else
103
+ Math::Symbol.new(text)
104
+ end
105
+ end
106
+
107
+ rule(radPr: simple(:rad),
108
+ deg: simple(:deg),
109
+ e: simple(:e)) do
110
+ if deg.nil?
111
+ Math::Function::Sqrt.new(e)
112
+ else
113
+ Math::Function::Root.new(deg, e)
114
+ end
115
+ end
116
+
117
+ rule(fPr: simple(:fpr), num: simple(:num), den: simple(:den)) do
118
+ Math::Function::Frac.new(num, den)
119
+ end
120
+
121
+ rule(sSupPr: simple(:sSuppr), e: simple(:e), sup: simple(:power)) do
122
+ Math::Function::Power.new(e, power)
123
+ end
124
+
125
+ rule(sSubPr: simple(:sSubpr), e: simple(:e), sub: simple(:base)) do
126
+ Math::Function::Base.new(e, base)
127
+ end
128
+
129
+ rule(chr: sequence(:chr),
130
+ ctrlPr: simple(:ctrl)) do
131
+ [nil] + chr
132
+ end
133
+
134
+ rule(chr: sequence(:chr),
135
+ limLoc: sequence(:limloc),
136
+ ctrlPr: simple(:ctrl)) do
137
+ limloc + chr
138
+ end
139
+
140
+ rule(begChr: sequence(:begChr),
141
+ endChr: sequence(:endChr),
142
+ ctrlPr: simple(:ctrl)) do
143
+ [
144
+ Math::Symbol.new(begChr.first),
145
+ Math::Symbol.new(endChr.first),
146
+ ]
147
+ end
148
+
149
+ rule(chr: sequence(:chr),
150
+ supHide: sequence(:supHide),
151
+ ctrlPr: simple(:ctrl)) do
152
+ [nil] + chr
153
+ end
154
+
155
+ rule(chr: sequence(:chr),
156
+ limLoc: sequence(:limloc),
157
+ supHide: sequence(:sup),
158
+ ctrlPr: simple(:ctrl)) do
159
+ limloc + chr
160
+ end
161
+
162
+ rule(limLoc: sequence(:limloc),
163
+ subHide: sequence(:sub),
164
+ supHide: sequence(:sup),
165
+ ctrlPr: simple(:ctrl)) do
166
+ limloc
167
+ end
168
+
169
+ rule(chr: sequence(:chr),
170
+ limLoc: sequence(:limloc),
171
+ subHide: sequence(:sub),
172
+ supHide: sequence(:sup),
173
+ ctrlPr: simple(:ctrl)) do
174
+ limloc + chr
175
+ end
176
+
177
+ rule(naryPr: sequence(:naryPr),
178
+ sub: simple(:base),
179
+ sup: simple(:power),
180
+ e: simple(:e)) do
181
+ fonts = Plurimath::Math::Symbol.new(naryPr[1] || "∫")
182
+ first_value = if base.nil? && power.nil?
183
+ fonts
184
+ elsif naryPr.first == "undOvr"
185
+ Math::Function::Underover.new(fonts, base, power)
186
+ else
187
+ Math::Function::PowerBase.new(fonts, base, power)
188
+ end
189
+ Math::Formula.new(
190
+ [
191
+ first_value,
192
+ Math::Formula.new(
193
+ [
194
+ e,
195
+ ],
196
+ ),
197
+ ],
198
+ )
199
+ end
200
+
201
+ rule(sSubSupPr: simple(:sSubSuppr),
202
+ e: simple(:e),
203
+ sub: simple(:base),
204
+ sup: simple(:power)) do
205
+ Math::Function::PowerBase.new(e, base, power)
206
+ end
207
+
208
+ rule(sPrePr: simple(:sPrePr),
209
+ e: simple(:e),
210
+ sub: simple(:base),
211
+ sup: simple(:power)) do
212
+ Math::Function::Multiscript.new(e, base, power)
213
+ end
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class Omml
5
+ attr_accessor :text
6
+
7
+ def initialize(text)
8
+ @text = text
9
+ end
10
+
11
+ def to_formula
12
+ Parser.new(text).parse
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class Unicode
5
+ attr_accessor :text
6
+
7
+ def initialize(text)
8
+ @text = text
9
+ end
10
+
11
+ def to_formula
12
+ # TODO: Will be implemented soon
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class Unitsml
5
+ attr_accessor :text
6
+
7
+ def initialize(text)
8
+ @text = text
9
+ end
10
+
11
+ def to_formula
12
+ # TODO: Will be implemented soon
13
+ end
14
+ end
15
+ end