plurimath 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +8 -11
- data/.gitignore +1 -0
- data/AsciiMath-Supported-Data.adoc +280 -0
- data/Gemfile +1 -0
- data/Latex-Supported-Data.adoc +1872 -0
- data/MathML-Supported-Data.adoc +270 -0
- data/README.adoc +94 -0
- data/lib/plurimath/asciimath/constants.rb +215 -222
- data/lib/plurimath/asciimath/parse.rb +45 -11
- data/lib/plurimath/asciimath/parser.rb +4 -3
- data/lib/plurimath/asciimath/transform.rb +222 -131
- 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 +1885 -1858
- data/lib/plurimath/latex/parse.rb +127 -34
- data/lib/plurimath/latex/parser.rb +5 -4
- data/lib/plurimath/latex/transform.rb +324 -164
- data/lib/plurimath/math/formula.rb +9 -1
- data/lib/plurimath/math/function/bar.rb +1 -1
- data/lib/plurimath/math/function/base.rb +7 -1
- data/lib/plurimath/math/function/binary_function.rb +10 -5
- data/lib/plurimath/math/function/color.rb +4 -4
- data/lib/plurimath/math/function/fenced.rb +7 -2
- data/lib/plurimath/math/function/font_style/bold.rb +18 -0
- data/lib/plurimath/math/function/font_style/double_struck.rb +18 -0
- data/lib/plurimath/math/function/font_style/fraktur.rb +18 -0
- data/lib/plurimath/math/function/font_style/monospace.rb +18 -0
- data/lib/plurimath/math/function/font_style/sans-serif.rb +18 -0
- data/lib/plurimath/math/function/font_style/script.rb +18 -0
- data/lib/plurimath/math/function/font_style.rb +2 -22
- data/lib/plurimath/math/function/frac.rb +4 -4
- data/lib/plurimath/math/function/inf.rb +0 -1
- data/lib/plurimath/math/function/left.rb +3 -6
- data/lib/plurimath/math/function/limits.rb +0 -1
- data/lib/plurimath/math/function/log.rb +6 -0
- data/lib/plurimath/math/function/mod.rb +6 -0
- data/lib/plurimath/math/function/multiscript.rb +11 -0
- data/lib/plurimath/math/function/norm.rb +2 -1
- data/lib/plurimath/math/function/over.rb +29 -0
- data/lib/plurimath/math/function/overset.rb +2 -2
- data/lib/plurimath/math/function/power.rb +7 -1
- data/lib/plurimath/math/function/power_base.rb +14 -7
- data/lib/plurimath/math/function/prod.rb +6 -0
- data/lib/plurimath/math/function/right.rb +24 -0
- data/lib/plurimath/math/function/root.rb +5 -4
- data/lib/plurimath/math/function/sqrt.rb +1 -1
- data/lib/plurimath/math/function/substack.rb +0 -1
- data/lib/plurimath/math/function/sum.rb +6 -0
- data/lib/plurimath/math/function/table/align.rb +24 -0
- data/lib/plurimath/math/function/table/array.rb +25 -0
- data/lib/plurimath/math/function/table/bmatrix.rb +26 -0
- data/lib/plurimath/math/function/table/matrix.rb +24 -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 +25 -0
- data/lib/plurimath/math/function/table.rb +17 -5
- data/lib/plurimath/math/function/td.rb +6 -1
- data/lib/plurimath/math/function/ternary_function.rb +16 -6
- data/lib/plurimath/math/function/text.rb +19 -7
- data/lib/plurimath/math/function/tr.rb +6 -1
- data/lib/plurimath/math/function/unary_function.rb +5 -0
- data/lib/plurimath/math/function/vec.rb +4 -0
- data/lib/plurimath/math/function.rb +13 -2
- data/lib/plurimath/math/number.rb +8 -0
- data/lib/plurimath/math/symbol.rb +12 -3
- data/lib/plurimath/math.rb +9 -4
- data/lib/plurimath/mathml/constants.rb +2 -34
- data/lib/plurimath/mathml/parse.rb +7 -2
- data/lib/plurimath/mathml/parser.rb +2 -1
- data/lib/plurimath/mathml/transform.rb +73 -68
- data/lib/plurimath/mathml.rb +1 -1
- data/lib/plurimath/omml/constants.rb +154 -0
- data/lib/plurimath/omml/parser.rb +22 -0
- data/lib/plurimath/omml/transform.rb +216 -0
- data/lib/plurimath/omml.rb +1 -1
- data/lib/plurimath/unitsml.rb +4 -0
- data/lib/plurimath/utility.rb +73 -0
- data/lib/plurimath/version.rb +1 -1
- data/plurimath.gemspec +1 -0
- metadata +49 -7
- data/README.md +0 -40
@@ -5,19 +5,29 @@ module Plurimath
|
|
5
5
|
class Transform < Parslet::Transform
|
6
6
|
rule(tag: simple(:tag)) { tag }
|
7
7
|
rule(tag: sequence(:tag)) { tag }
|
8
|
-
rule(text: simple(:text)) {
|
9
|
-
rule(class: simple(:string)) {
|
10
|
-
rule(number: simple(:number)) {
|
11
|
-
|
12
|
-
rule(tag:
|
13
|
-
|
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
|
14
23
|
|
15
24
|
rule(quoted_text: simple(:quoted_text)) do
|
16
|
-
text = quoted_text
|
17
|
-
Constants::UNICODE_SYMBOLS.
|
18
|
-
|
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}]")
|
19
29
|
end
|
20
|
-
|
30
|
+
Math::Function::Text.new(text)
|
21
31
|
end
|
22
32
|
|
23
33
|
rule(
|
@@ -37,7 +47,7 @@ module Plurimath
|
|
37
47
|
sequence: simple(:sequence),
|
38
48
|
iteration: simple(:iteration),
|
39
49
|
) do
|
40
|
-
|
50
|
+
Math::Formula.new(tag + [sequence, iteration])
|
41
51
|
end
|
42
52
|
|
43
53
|
rule(
|
@@ -45,7 +55,7 @@ module Plurimath
|
|
45
55
|
sequence: simple(:sequence),
|
46
56
|
iteration: simple(:iteration),
|
47
57
|
) do
|
48
|
-
[tag, sequence]
|
58
|
+
iteration.size.zero? ? [tag, sequence] : [tag, sequence, iteration]
|
49
59
|
end
|
50
60
|
|
51
61
|
rule(tag: sequence(:tag), iteration: simple(:iteration)) do
|
@@ -72,21 +82,21 @@ module Plurimath
|
|
72
82
|
rule(symbol: simple(:symbol)) do
|
73
83
|
decoded_symbol = Constants::UNICODE_SYMBOLS[symbol.to_sym]
|
74
84
|
if Constants::CLASSES.include?(decoded_symbol)
|
75
|
-
[
|
85
|
+
[Utility.get_class(decoded_symbol).new]
|
76
86
|
elsif decoded_symbol.nil? && Constants::SYMBOLS[symbol.to_sym]
|
77
|
-
|
87
|
+
Math::Symbol.new(Constants::SYMBOLS[symbol.to_sym])
|
78
88
|
else
|
79
|
-
|
89
|
+
Math::Symbol.new(decoded_symbol)
|
80
90
|
end
|
81
91
|
end
|
82
92
|
|
83
93
|
rule(name: simple(:name), value: simple(:value)) do
|
84
|
-
if ["open", "close"].include?(name
|
85
|
-
|
86
|
-
elsif name
|
87
|
-
|
88
|
-
elsif name
|
89
|
-
value
|
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
|
90
100
|
end
|
91
101
|
end
|
92
102
|
|
@@ -95,15 +105,10 @@ module Plurimath
|
|
95
105
|
sequence: sequence(:sequence),
|
96
106
|
iteration: simple(:iteration),
|
97
107
|
) do
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
new_arr = sequence.compact
|
103
|
-
new_arr = [tag] + new_arr unless tag.nil?
|
104
|
-
new_arr << iteration unless iteration.to_s.empty?
|
105
|
-
new_arr
|
106
|
-
end
|
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
|
107
112
|
end
|
108
113
|
|
109
114
|
rule(
|
@@ -112,53 +117,64 @@ module Plurimath
|
|
112
117
|
iteration: sequence(:iteration),
|
113
118
|
close: simple(:close_tag),
|
114
119
|
) do
|
115
|
-
|
120
|
+
Utility.raise_error!(open_tag, close_tag) unless open_tag == close_tag
|
116
121
|
|
117
122
|
if open_tag == "mrow"
|
118
|
-
|
123
|
+
Math::Formula.new(iteration)
|
119
124
|
elsif open_tag == "munder"
|
120
|
-
if
|
125
|
+
if iteration.last.class_name == "obrace"
|
121
126
|
iteration.last.parameter_one = iteration.first
|
122
127
|
iteration.last
|
123
128
|
else
|
124
|
-
|
129
|
+
Math::Function::Underset.new(iteration[1], iteration[0])
|
125
130
|
end
|
126
131
|
elsif open_tag == "munderover"
|
127
|
-
|
132
|
+
Utility.get_class(open_tag.delete_prefix("m")).new(
|
133
|
+
iteration[0],
|
134
|
+
iteration[1],
|
135
|
+
iteration[2],
|
136
|
+
)
|
128
137
|
elsif open_tag == "mover"
|
129
|
-
if
|
138
|
+
if iteration.last.class_name == "ubrace"
|
130
139
|
iteration.last.parameter_one = iteration.first
|
131
140
|
iteration.last
|
132
141
|
else
|
133
|
-
|
142
|
+
Math::Function::Overset.new(iteration[1], iteration[0])
|
134
143
|
end
|
135
|
-
elsif
|
136
|
-
|
137
|
-
|
138
|
-
Plurimath::Math::Function::Base.new(iteration[0], iteration[1])
|
144
|
+
elsif ["msub", "msup"].include?(open_tag)
|
145
|
+
tag = (open_tag == "msup" ? "power" : "base")
|
146
|
+
Utility.get_class(tag).new(iteration[0], iteration[1])
|
139
147
|
elsif open_tag == "msubsup"
|
140
|
-
|
148
|
+
Math::Function::PowerBase.new(iteration[0],
|
149
|
+
iteration[1],
|
150
|
+
iteration[2])
|
141
151
|
elsif open_tag == "mfrac"
|
142
|
-
|
152
|
+
Math::Function::Frac.new(iteration.first, iteration.last)
|
143
153
|
elsif open_tag == "msqrt"
|
144
|
-
|
154
|
+
Math::Function::Sqrt.new(iteration.first)
|
145
155
|
elsif open_tag == "mroot"
|
146
|
-
|
156
|
+
Math::Function::Root.new(iteration[0], iteration[1])
|
147
157
|
elsif open_tag == "mfenced"
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
elsif
|
154
|
-
|
155
|
-
|
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)
|
156
167
|
attributes.first.parameter_two = iteration.first
|
157
168
|
attributes.first
|
158
169
|
elsif open_tag == "mstyle" && !attributes.compact.empty?
|
159
|
-
font_type = attributes.compact.last
|
160
|
-
if
|
161
|
-
|
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)
|
162
178
|
end
|
163
179
|
else
|
164
180
|
iteration
|
@@ -171,7 +187,7 @@ module Plurimath
|
|
171
187
|
iteration: simple(:iteration),
|
172
188
|
close: simple(:close_tag),
|
173
189
|
) do
|
174
|
-
|
190
|
+
Utility.raise_error!(open_tag, close_tag) unless open_tag == close_tag
|
175
191
|
|
176
192
|
if iteration.to_s.include?("Function")
|
177
193
|
iteration
|
@@ -179,17 +195,6 @@ module Plurimath
|
|
179
195
|
[iteration.to_s.empty? ? nil : iteration]
|
180
196
|
end
|
181
197
|
end
|
182
|
-
|
183
|
-
def self.get_class(text)
|
184
|
-
Object.const_get("Plurimath::Math::Function::#{text.to_s.capitalize}")
|
185
|
-
end
|
186
|
-
|
187
|
-
def self.raise_error!(open_tag, close_tag)
|
188
|
-
message = "Please check your input."\
|
189
|
-
" Opening tag is \"#{open_tag}\""\
|
190
|
-
" and closing tag is \"#{close_tag}\""
|
191
|
-
raise Plurimath::Math::Error.new(message)
|
192
|
-
end
|
193
198
|
end
|
194
199
|
end
|
195
200
|
end
|
data/lib/plurimath/mathml.rb
CHANGED
@@ -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
|
data/lib/plurimath/omml.rb
CHANGED