plurimath 0.6.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/plurimath/asciimath/parse.rb +3 -2
- data/lib/plurimath/asciimath/transform.rb +32 -5
- data/lib/plurimath/latex/constants.rb +2 -1
- data/lib/plurimath/latex/transform.rb +9 -13
- data/lib/plurimath/math/core.rb +134 -20
- data/lib/plurimath/math/formula.rb +88 -18
- data/lib/plurimath/math/function/abs.rb +28 -15
- data/lib/plurimath/math/function/bar.rb +5 -0
- data/lib/plurimath/math/function/base.rb +14 -0
- data/lib/plurimath/math/function/binary_function.rb +2 -8
- data/lib/plurimath/math/function/ceil.rb +24 -9
- data/lib/plurimath/math/function/ddot.rb +6 -1
- data/lib/plurimath/math/function/deg.rb +4 -1
- data/lib/plurimath/math/function/det.rb +4 -1
- data/lib/plurimath/math/function/dim.rb +4 -1
- data/lib/plurimath/math/function/dot.rb +5 -0
- data/lib/plurimath/math/function/exp.rb +4 -1
- data/lib/plurimath/math/function/fenced.rb +25 -16
- data/lib/plurimath/math/function/floor.rb +23 -13
- data/lib/plurimath/math/function/font_style.rb +18 -8
- data/lib/plurimath/math/function/frac.rb +32 -18
- data/lib/plurimath/math/function/gcd.rb +4 -1
- data/lib/plurimath/math/function/glb.rb +8 -1
- data/lib/plurimath/math/function/hat.rb +16 -5
- data/lib/plurimath/math/function/hom.rb +4 -1
- data/lib/plurimath/math/function/inf.rb +16 -0
- data/lib/plurimath/math/function/int.rb +28 -9
- data/lib/plurimath/math/function/ker.rb +4 -1
- data/lib/plurimath/math/function/lcm.rb +17 -1
- data/lib/plurimath/math/function/left.rb +1 -1
- data/lib/plurimath/math/function/lg.rb +4 -1
- data/lib/plurimath/math/function/lim.rb +10 -0
- data/lib/plurimath/math/function/liminf.rb +4 -1
- data/lib/plurimath/math/function/limits.rb +22 -9
- data/lib/plurimath/math/function/limsup.rb +4 -1
- data/lib/plurimath/math/function/linebreak.rb +95 -0
- data/lib/plurimath/math/function/ln.rb +4 -1
- data/lib/plurimath/math/function/log.rb +21 -12
- data/lib/plurimath/math/function/longdiv.rb +19 -0
- data/lib/plurimath/math/function/lub.rb +4 -1
- data/lib/plurimath/math/function/max.rb +4 -1
- data/lib/plurimath/math/function/mbox.rb +8 -7
- data/lib/plurimath/math/function/merror.rb +12 -3
- data/lib/plurimath/math/function/min.rb +4 -1
- data/lib/plurimath/math/function/mod.rb +42 -15
- data/lib/plurimath/math/function/msgroup.rb +4 -0
- data/lib/plurimath/math/function/msline.rb +10 -0
- data/lib/plurimath/math/function/multiscript.rb +20 -0
- data/lib/plurimath/math/function/nary.rb +39 -5
- data/lib/plurimath/math/function/norm.rb +24 -15
- data/lib/plurimath/math/function/obrace.rb +5 -0
- data/lib/plurimath/math/function/oint.rb +42 -20
- data/lib/plurimath/math/function/over.rb +23 -10
- data/lib/plurimath/math/function/overset.rb +13 -10
- data/lib/plurimath/math/function/phantom.rb +24 -6
- data/lib/plurimath/math/function/power.rb +13 -4
- data/lib/plurimath/math/function/power_base.rb +28 -6
- data/lib/plurimath/math/function/prod.rb +33 -14
- data/lib/plurimath/math/function/right.rb +1 -1
- data/lib/plurimath/math/function/rule.rb +1 -1
- data/lib/plurimath/math/function/scarries.rb +14 -0
- data/lib/plurimath/math/function/semantics.rb +9 -0
- data/lib/plurimath/math/function/sqrt.rb +5 -0
- data/lib/plurimath/math/function/stackrel.rb +8 -0
- data/lib/plurimath/math/function/substack.rb +12 -51
- data/lib/plurimath/math/function/sum.rb +43 -20
- data/lib/plurimath/math/function/sup.rb +11 -2
- data/lib/plurimath/math/function/table/array.rb +1 -1
- data/lib/plurimath/math/function/table/matrix.rb +4 -0
- data/lib/plurimath/math/function/table.rb +11 -3
- data/lib/plurimath/math/function/td.rb +14 -4
- data/lib/plurimath/math/function/ternary_function.rb +8 -10
- data/lib/plurimath/math/function/text.rb +1 -1
- data/lib/plurimath/math/function/tilde.rb +5 -0
- data/lib/plurimath/math/function/tr.rb +1 -1
- data/lib/plurimath/math/function/ubrace.rb +5 -0
- data/lib/plurimath/math/function/unary_function.rb +72 -26
- data/lib/plurimath/math/function/underover.rb +25 -8
- data/lib/plurimath/math/function/underset.rb +19 -9
- data/lib/plurimath/math/function/vec.rb +5 -0
- data/lib/plurimath/math/number.rb +3 -3
- data/lib/plurimath/math/symbol.rb +13 -5
- data/lib/plurimath/mathml/parser.rb +2 -0
- data/lib/plurimath/mathml/transform.rb +23 -15
- data/lib/plurimath/omml/transform.rb +22 -10
- data/lib/plurimath/unitsml.rb +2 -1
- data/lib/plurimath/utility.rb +29 -28
- data/lib/plurimath/version.rb +1 -1
- metadata +3 -3
- data/lib/plurimath/math/function/scarry.rb +0 -12
@@ -6,6 +6,8 @@ module Plurimath
|
|
6
6
|
class Table < Core
|
7
7
|
attr_accessor :value, :open_paren, :close_paren, :options
|
8
8
|
|
9
|
+
SIMPLE_TABLES = %w[array align split].freeze
|
10
|
+
|
9
11
|
def initialize(value = nil,
|
10
12
|
open_paren = nil,
|
11
13
|
close_paren = nil,
|
@@ -25,6 +27,8 @@ module Plurimath
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def to_asciimath
|
30
|
+
return parentheless_table if SIMPLE_TABLES.include?(class_name)
|
31
|
+
|
28
32
|
parenthesis = Asciimath::Constants::TABLE_PARENTHESIS
|
29
33
|
first_value = value.map(&:to_asciimath).join(", ")
|
30
34
|
third_value = close_paren.is_a?(::Array) || close_paren.nil?
|
@@ -193,7 +197,7 @@ module Plurimath
|
|
193
197
|
eqarrpr = Utility.ox_element("eqArrPr", namespace: "m")
|
194
198
|
eqarrpr << Utility.pr_element("ctrl", true, namespace: "m")
|
195
199
|
eqarr << eqarrpr
|
196
|
-
tr_value = value.map { |
|
200
|
+
tr_value = value.map { |object| object.to_omml_without_math_tag(display_style) }.flatten
|
197
201
|
Utility.update_nodes(eqarr, tr_value.compact)
|
198
202
|
[eqarr]
|
199
203
|
end
|
@@ -202,7 +206,7 @@ module Plurimath
|
|
202
206
|
count = { "m:val": value&.first&.parameter_one&.count }
|
203
207
|
mcjc = { "m:val": "center" }
|
204
208
|
mm = Utility.ox_element("m", namespace: "m")
|
205
|
-
mpr = Utility.ox_element("
|
209
|
+
mpr = Utility.ox_element("mPr", namespace: "m")
|
206
210
|
mcs = Utility.ox_element("mcs", namespace: "m")
|
207
211
|
mc = Utility.ox_element("mc", namespace: "m")
|
208
212
|
mcpr = Utility.ox_element("mcPr", namespace: "m")
|
@@ -222,7 +226,7 @@ module Plurimath
|
|
222
226
|
mcs << mc
|
223
227
|
mpr << mcs
|
224
228
|
mpr << ctrlpr
|
225
|
-
mm_value = value&.map { |
|
229
|
+
mm_value = value&.map { |object| object.to_omml_without_math_tag(display_style) }
|
226
230
|
Utility.update_nodes(
|
227
231
|
mm,
|
228
232
|
mm_value.insert(0, mpr).flatten,
|
@@ -276,6 +280,10 @@ module Plurimath
|
|
276
280
|
|
277
281
|
parenthesis
|
278
282
|
end
|
283
|
+
|
284
|
+
def parentheless_table
|
285
|
+
"{:#{value.map(&:to_asciimath).join(", ")}:}"
|
286
|
+
end
|
279
287
|
end
|
280
288
|
end
|
281
289
|
end
|
@@ -36,10 +36,7 @@ module Plurimath
|
|
36
36
|
me = Utility.ox_element("e", namespace: "m")
|
37
37
|
return [me] if parameter_one&.empty?
|
38
38
|
|
39
|
-
Utility.update_nodes(
|
40
|
-
me,
|
41
|
-
Formula.new(parameter_one).omml_content(display_style),
|
42
|
-
)
|
39
|
+
Utility.update_nodes(me, omml_content(display_style))
|
43
40
|
[me]
|
44
41
|
end
|
45
42
|
|
@@ -70,6 +67,19 @@ module Plurimath
|
|
70
67
|
Formula.new(parameter_one).to_omml_math_zone(gsub_spacing(spacing, last), last, indent, display_style: display_style),
|
71
68
|
]
|
72
69
|
end
|
70
|
+
|
71
|
+
def omml_content(display_style)
|
72
|
+
parameter_one&.map { |val| val.insert_t_tag(display_style) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def line_breaking(obj)
|
76
|
+
sliced_value = result(Array(parameter_one))
|
77
|
+
return unless sliced_value.length > 1
|
78
|
+
|
79
|
+
sliced_result = sliced_value.first.last.omml_line_break(sliced_value)
|
80
|
+
table = Table.new(sliced_result.map { |res| Tr.new(Array(Td.new(Array(res)))) })
|
81
|
+
self.parameter_one = [table]
|
82
|
+
end
|
73
83
|
end
|
74
84
|
end
|
75
85
|
end
|
@@ -4,7 +4,7 @@ module Plurimath
|
|
4
4
|
module Math
|
5
5
|
module Function
|
6
6
|
class TernaryFunction < Core
|
7
|
-
attr_accessor :parameter_one, :parameter_two, :parameter_three
|
7
|
+
attr_accessor :parameter_one, :parameter_two, :parameter_three, :hide_function_name
|
8
8
|
|
9
9
|
def initialize(parameter_one = nil,
|
10
10
|
parameter_two = nil,
|
@@ -12,7 +12,7 @@ module Plurimath
|
|
12
12
|
@parameter_one = parameter_one
|
13
13
|
@parameter_two = parameter_two
|
14
14
|
@parameter_three = parameter_three
|
15
|
-
Utility.validate_left_right(
|
15
|
+
Utility.validate_left_right(variables.map { |var| get(var) })
|
16
16
|
end
|
17
17
|
|
18
18
|
def to_asciimath
|
@@ -30,10 +30,12 @@ module Plurimath
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def to_mathml_without_math_tag
|
33
|
-
value_arr = [
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
value_arr = [
|
34
|
+
validate_mathml_fields(parameter_one),
|
35
|
+
validate_mathml_fields(parameter_two),
|
36
|
+
validate_mathml_fields(parameter_three),
|
37
|
+
]
|
38
|
+
class_tag = ox_element("m#{class_name}")
|
37
39
|
Utility.update_nodes(class_tag, value_arr)
|
38
40
|
end
|
39
41
|
|
@@ -99,10 +101,6 @@ module Plurimath
|
|
99
101
|
new_arr
|
100
102
|
end
|
101
103
|
|
102
|
-
def any_value_exist?
|
103
|
-
!(parameter_one.nil? || parameter_two.nil? || parameter_three.nil?)
|
104
|
-
end
|
105
|
-
|
106
104
|
protected
|
107
105
|
|
108
106
|
def latex_wrapped(field)
|
@@ -32,7 +32,7 @@ module Plurimath
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def to_omml_without_math_tag(display_style)
|
35
|
-
omml_content = parameter_one&.map { |
|
35
|
+
omml_content = parameter_one&.map { |object| object.to_omml_without_math_tag(display_style) }
|
36
36
|
if parameter_one.count.eql?(1)
|
37
37
|
omml_content
|
38
38
|
else
|
@@ -56,6 +56,11 @@ module Plurimath
|
|
56
56
|
symbol = Symbol.new("⏟")
|
57
57
|
Underset.new(parameter_one, symbol).to_omml_without_math_tag(true)
|
58
58
|
end
|
59
|
+
|
60
|
+
def line_breaking(obj)
|
61
|
+
parameter_one&.line_breaking(obj)
|
62
|
+
obj.update(Utility.filter_values(obj.value)) if obj.value_exist?
|
63
|
+
end
|
59
64
|
end
|
60
65
|
|
61
66
|
Underbrace = Ubrace
|
@@ -4,12 +4,13 @@ module Plurimath
|
|
4
4
|
module Math
|
5
5
|
module Function
|
6
6
|
class UnaryFunction < Core
|
7
|
-
attr_accessor :parameter_one
|
7
|
+
attr_accessor :parameter_one, :hide_function_name
|
8
8
|
|
9
9
|
def initialize(parameter_one = nil)
|
10
10
|
parameter_one = parameter_one.to_s if parameter_one.is_a?(Parslet::Slice)
|
11
11
|
@parameter_one = parameter_one
|
12
|
-
|
12
|
+
method(:post_initialize).call if methods.include?(:post_initialize)
|
13
|
+
Utility.validate_left_right(variables.map { |var| get(var) })
|
13
14
|
end
|
14
15
|
|
15
16
|
def ==(object)
|
@@ -27,12 +28,12 @@ module Plurimath
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def to_mathml_without_math_tag
|
30
|
-
row_tag = Utility.ox_element("mrow")
|
31
31
|
tag_name = Utility::UNARY_CLASSES.include?(class_name) ? "mi" : "mo"
|
32
|
-
new_arr = [
|
32
|
+
new_arr = []
|
33
|
+
new_arr << (ox_element(tag_name) << class_name) unless hide_function_name
|
33
34
|
if parameter_one
|
34
35
|
new_arr += mathml_value
|
35
|
-
Utility.update_nodes(
|
36
|
+
Utility.update_nodes(ox_element("mrow"), new_arr)
|
36
37
|
else
|
37
38
|
new_arr.first
|
38
39
|
end
|
@@ -54,25 +55,13 @@ module Plurimath
|
|
54
55
|
def to_omml_without_math_tag(display_style)
|
55
56
|
return r_element(class_name, rpr_tag: false) unless parameter_one
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
fname << Utility.update_nodes(mr, [rpr, mt])
|
65
|
-
me = Utility.ox_element("e", namespace: "m")
|
66
|
-
Utility.update_nodes(me, omml_value(display_style)) if parameter_one
|
67
|
-
Utility.update_nodes(
|
68
|
-
func,
|
69
|
-
[
|
70
|
-
funcpr,
|
71
|
-
fname,
|
72
|
-
me,
|
73
|
-
],
|
74
|
-
)
|
75
|
-
[func]
|
58
|
+
if @hide_function_name
|
59
|
+
value = omml_value(display_style)
|
60
|
+
else
|
61
|
+
func = Utility.ox_element("func", namespace: "m")
|
62
|
+
value = Utility.update_nodes(func, function_values(display_style))
|
63
|
+
end
|
64
|
+
Array(value)
|
76
65
|
end
|
77
66
|
|
78
67
|
def to_asciimath_math_zone(spacing, last = false, _)
|
@@ -115,6 +104,39 @@ module Plurimath
|
|
115
104
|
new_arr
|
116
105
|
end
|
117
106
|
|
107
|
+
def custom_array_line_breaking(obj)
|
108
|
+
parameter_value = result(parameter_one)
|
109
|
+
if parameter_value.size > 1
|
110
|
+
breaked_result = parameter_value.first.last.omml_line_break(parameter_value)
|
111
|
+
update(Array(breaked_result.shift))
|
112
|
+
obj.update(self.class.new(breaked_result.flatten))
|
113
|
+
reprocess_parameter_one(obj)
|
114
|
+
return
|
115
|
+
end
|
116
|
+
|
117
|
+
parameter_one.each.with_index(1) do |object, index|
|
118
|
+
object.line_breaking(obj)
|
119
|
+
break obj.insert(parameter_one.slice!(index..parameter_one.size)) if obj.value_exist?
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def update(value)
|
124
|
+
self.parameter_one = value
|
125
|
+
end
|
126
|
+
|
127
|
+
def reprocess_parameter_one(obj)
|
128
|
+
new_obj = Formula.new([])
|
129
|
+
self.line_breaking(new_obj)
|
130
|
+
if new_obj.value_exist?
|
131
|
+
obj.value.insert(0, Linebreak.new)
|
132
|
+
obj.value.insert(0, self.class.new(new_obj.value))
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def value_nil?
|
137
|
+
!parameter_one
|
138
|
+
end
|
139
|
+
|
118
140
|
protected
|
119
141
|
|
120
142
|
def asciimath_value
|
@@ -147,15 +169,39 @@ module Plurimath
|
|
147
169
|
|
148
170
|
def omml_value(display_style)
|
149
171
|
if parameter_one.is_a?(Array)
|
150
|
-
return parameter_one&.compact&.map { |
|
172
|
+
return parameter_one&.compact&.map { |object| formula_to_nodes(object, display_style) }
|
151
173
|
end
|
152
174
|
|
153
|
-
Array(parameter_one
|
175
|
+
Array(formula_to_nodes(parameter_one, display_style))
|
176
|
+
end
|
177
|
+
|
178
|
+
def formula_to_nodes(object, display_style)
|
179
|
+
object&.insert_t_tag(display_style)
|
154
180
|
end
|
155
181
|
|
156
182
|
def latex_paren
|
157
183
|
Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || '.'
|
158
184
|
end
|
185
|
+
|
186
|
+
def exist?
|
187
|
+
!(parameter_one.is_a?(Array) ? parameter_one.empty? : parameter_one.nil?)
|
188
|
+
end
|
189
|
+
|
190
|
+
def function_values(display_style)
|
191
|
+
funcpr = Utility.ox_element("funcPr", namespace: "m")
|
192
|
+
funcpr << Utility.pr_element("ctrl", true, namespace: "m")
|
193
|
+
fname = Utility.ox_element("fName", namespace: "m")
|
194
|
+
fname << Utility.update_nodes(
|
195
|
+
Utility.ox_element("r", namespace: "m"),
|
196
|
+
[
|
197
|
+
Utility.rpr_element,
|
198
|
+
(Utility.ox_element("t", namespace: "m") << class_name),
|
199
|
+
],
|
200
|
+
)
|
201
|
+
me = Utility.ox_element("e", namespace: "m")
|
202
|
+
Utility.update_nodes(me, omml_value(display_style)) if parameter_one
|
203
|
+
[funcpr, fname, me]
|
204
|
+
end
|
159
205
|
end
|
160
206
|
end
|
161
207
|
end
|
@@ -28,16 +28,12 @@ module Plurimath
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def to_mathml_without_math_tag
|
31
|
-
first_value = parameter_one&.to_mathml_without_math_tag
|
32
|
-
second_value = parameter_two&.to_mathml_without_math_tag
|
33
|
-
third_value = parameter_three&.to_mathml_without_math_tag
|
34
|
-
class_tag = Utility.ox_element("m#{class_name}")
|
35
31
|
Utility.update_nodes(
|
36
|
-
|
32
|
+
ox_element("m#{class_name}"),
|
37
33
|
[
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
validate_mathml_fields(parameter_one),
|
35
|
+
validate_mathml_fields(parameter_two),
|
36
|
+
validate_mathml_fields(parameter_three),
|
41
37
|
],
|
42
38
|
)
|
43
39
|
end
|
@@ -50,6 +46,27 @@ module Plurimath
|
|
50
46
|
|
51
47
|
underover(display_style)
|
52
48
|
end
|
49
|
+
|
50
|
+
def line_breaking(obj)
|
51
|
+
parameter_one&.line_breaking(obj)
|
52
|
+
if obj.value_exist?
|
53
|
+
obj.update(
|
54
|
+
Underover.new(Utility.filter_values(obj.value), parameter_two, parameter_three)
|
55
|
+
)
|
56
|
+
self.parameter_two = nil
|
57
|
+
self.parameter_three = nil
|
58
|
+
return
|
59
|
+
end
|
60
|
+
|
61
|
+
parameter_two.line_breaking(obj)
|
62
|
+
if obj.value_exist?
|
63
|
+
obj.update(
|
64
|
+
Underover.new(nil, Utility.filter_values(obj.value), parameter_three)
|
65
|
+
)
|
66
|
+
self.parameter_two = nil
|
67
|
+
self.parameter_three = nil
|
68
|
+
end
|
69
|
+
end
|
53
70
|
end
|
54
71
|
end
|
55
72
|
end
|
@@ -13,15 +13,11 @@ module Plurimath
|
|
13
13
|
}.freeze
|
14
14
|
|
15
15
|
def to_mathml_without_math_tag
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
second_value,
|
22
|
-
first_value,
|
23
|
-
],
|
24
|
-
)
|
16
|
+
value_array = [
|
17
|
+
validate_mathml_fields(parameter_two),
|
18
|
+
validate_mathml_fields(parameter_one),
|
19
|
+
]
|
20
|
+
Utility.update_nodes(ox_element("munder"), value_array)
|
25
21
|
end
|
26
22
|
|
27
23
|
def to_omml_without_math_tag(display_style)
|
@@ -43,6 +39,20 @@ module Plurimath
|
|
43
39
|
)
|
44
40
|
[limlow]
|
45
41
|
end
|
42
|
+
|
43
|
+
def line_breaking(obj)
|
44
|
+
parameter_one&.line_breaking(obj)
|
45
|
+
if obj.value_exist?
|
46
|
+
obj.update(self.class.new(Utility.filter_values(obj.value), parameter_two))
|
47
|
+
self.parameter_two = nil
|
48
|
+
return
|
49
|
+
end
|
50
|
+
|
51
|
+
parameter_two&.line_breaking(obj)
|
52
|
+
if obj.value_exist?
|
53
|
+
obj.update(self.class.new(nil, Utility.filter_values(obj.value)))
|
54
|
+
end
|
55
|
+
end
|
46
56
|
end
|
47
57
|
end
|
48
58
|
end
|
@@ -29,17 +29,17 @@ module Plurimath
|
|
29
29
|
value
|
30
30
|
end
|
31
31
|
|
32
|
-
def to_omml_without_math_tag(
|
32
|
+
def to_omml_without_math_tag(_)
|
33
33
|
[t_tag]
|
34
34
|
end
|
35
35
|
|
36
|
-
def insert_t_tag(
|
36
|
+
def insert_t_tag(_)
|
37
37
|
[
|
38
38
|
(Utility.ox_element("r", namespace: "m") << t_tag),
|
39
39
|
]
|
40
40
|
end
|
41
41
|
|
42
|
-
def font_style_t_tag(
|
42
|
+
def font_style_t_tag(_)
|
43
43
|
t_tag
|
44
44
|
end
|
45
45
|
|
@@ -5,7 +5,7 @@ module Plurimath
|
|
5
5
|
class Symbol < Core
|
6
6
|
attr_accessor :value
|
7
7
|
|
8
|
-
def initialize(sym)
|
8
|
+
def initialize(sym = nil)
|
9
9
|
@value = sym.is_a?(Parslet::Slice) ? sym.to_s : sym
|
10
10
|
end
|
11
11
|
|
@@ -56,11 +56,11 @@ module Plurimath
|
|
56
56
|
value
|
57
57
|
end
|
58
58
|
|
59
|
-
def to_omml_without_math_tag(
|
59
|
+
def to_omml_without_math_tag(_, _)
|
60
60
|
value
|
61
61
|
end
|
62
62
|
|
63
|
-
def insert_t_tag(
|
63
|
+
def insert_t_tag(_)
|
64
64
|
[(Utility.ox_element("r", namespace: "m") << t_tag)]
|
65
65
|
end
|
66
66
|
|
@@ -76,7 +76,7 @@ module Plurimath
|
|
76
76
|
"subSup"
|
77
77
|
end
|
78
78
|
|
79
|
-
def font_style_t_tag(
|
79
|
+
def font_style_t_tag(_)
|
80
80
|
t_tag
|
81
81
|
end
|
82
82
|
|
@@ -88,7 +88,7 @@ module Plurimath
|
|
88
88
|
false
|
89
89
|
end
|
90
90
|
|
91
|
-
def omml_nodes(
|
91
|
+
def omml_nodes(_)
|
92
92
|
Array(t_tag)
|
93
93
|
end
|
94
94
|
|
@@ -96,6 +96,14 @@ module Plurimath
|
|
96
96
|
Utility.ox_element("t", namespace: "m") << value
|
97
97
|
end
|
98
98
|
|
99
|
+
def separate_table
|
100
|
+
["&", "\\\\"].include?(value)
|
101
|
+
end
|
102
|
+
|
103
|
+
def linebreak
|
104
|
+
value == "\\\\"
|
105
|
+
end
|
106
|
+
|
99
107
|
private
|
100
108
|
|
101
109
|
def operator?(unicode)
|
@@ -9,6 +9,7 @@ module Plurimath
|
|
9
9
|
rule(mtd: sequence(:mtd)) { Math::Function::Td.new(mtd) }
|
10
10
|
rule(mtr: sequence(:mtr)) { Math::Function::Tr.new(mtr) }
|
11
11
|
rule(none: sequence(:none)) { nil }
|
12
|
+
rule(mspace: simple(:space)) { nil }
|
12
13
|
rule(notation: simple(:att)) { Math::Function::Menclose.new(att) }
|
13
14
|
rule(mtable: simple(:table)) { table }
|
14
15
|
rule(msqrt: sequence(:sqrt)) { Math::Function::Sqrt.new(sqrt.first) }
|
@@ -36,7 +37,9 @@ module Plurimath
|
|
36
37
|
end
|
37
38
|
|
38
39
|
rule(mphantom: sequence(:phantom)) do
|
39
|
-
Math::Function::Phantom.new(
|
40
|
+
Math::Function::Phantom.new(
|
41
|
+
Utility.filter_values(phantom),
|
42
|
+
)
|
40
43
|
end
|
41
44
|
|
42
45
|
rule(mn: sequence(:mn)) do
|
@@ -316,11 +319,6 @@ module Plurimath
|
|
316
319
|
end
|
317
320
|
end
|
318
321
|
|
319
|
-
rule(attributes: simple(:attrs),
|
320
|
-
value: subtree(:value)) do
|
321
|
-
Utility.join_attr_value(attrs, value&.flatten&.compact)
|
322
|
-
end
|
323
|
-
|
324
322
|
rule(semantics: subtree(:value)) do
|
325
323
|
Math::Function::Semantics.new(
|
326
324
|
value.shift,
|
@@ -328,17 +326,27 @@ module Plurimath
|
|
328
326
|
)
|
329
327
|
end
|
330
328
|
|
329
|
+
rule(attributes: simple(:attrs),
|
330
|
+
value: subtree(:value)) do
|
331
|
+
Utility.join_attr_value(attrs, value&.flatten&.compact)
|
332
|
+
end
|
333
|
+
|
331
334
|
rule(attributes: subtree(:attrs),
|
332
335
|
value: sequence(:value)) do
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
336
|
+
approved = if attrs.is_a?(Hash)
|
337
|
+
supported = %w[accentunder accent linebreak]
|
338
|
+
if attrs.keys.any? { |k| supported.include?(k.to_s) }
|
339
|
+
unicode_only = true if attrs.key?(:linebreak)
|
340
|
+
attrs
|
341
|
+
end
|
342
|
+
else
|
343
|
+
attrs
|
344
|
+
end
|
345
|
+
Utility.join_attr_value(
|
346
|
+
approved,
|
347
|
+
value&.flatten&.compact,
|
348
|
+
unicode_only: unicode_only,
|
349
|
+
)
|
342
350
|
end
|
343
351
|
end
|
344
352
|
end
|
@@ -9,6 +9,7 @@ module Plurimath
|
|
9
9
|
rule(i: sequence(:i)) { i }
|
10
10
|
rule(e: sequence(:e)) { e.flatten.compact }
|
11
11
|
|
12
|
+
rule(br: sequence(:br)) { Math::Function::Linebreak.new }
|
12
13
|
rule(val: simple(:val)) { val }
|
13
14
|
rule(scr: simple(:scr)) { scr }
|
14
15
|
rule(sty: simple(:sty)) { sty }
|
@@ -210,7 +211,7 @@ module Plurimath
|
|
210
211
|
end
|
211
212
|
if Utility.valid_class(subsup[0])
|
212
213
|
Utility.get_class(
|
213
|
-
subsup[0].
|
214
|
+
subsup[0].extract_class_name_from_text,
|
214
215
|
).new(
|
215
216
|
subsup[1],
|
216
217
|
subsup[2],
|
@@ -256,20 +257,31 @@ module Plurimath
|
|
256
257
|
rule(limUpp: subtree(:lim)) do
|
257
258
|
lim_values = lim.flatten.compact
|
258
259
|
first_value = lim_values[0]
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
260
|
+
if lim.last.is_unary? && lim.last.value_nil?
|
261
|
+
function_class = lim.pop
|
262
|
+
function_class.parameter_one = Utility.filter_values(lim.flatten.compact)
|
263
|
+
function_class
|
264
|
+
else
|
265
|
+
Math::Function::Overset.new(
|
266
|
+
first_value,
|
267
|
+
lim_values[1],
|
268
|
+
)
|
269
|
+
end
|
263
270
|
end
|
264
271
|
|
265
272
|
rule(limLow: subtree(:lim)) do
|
266
273
|
second_value = Utility.filter_values(lim[2])
|
267
|
-
unicode = Mathml::Constants::UNICODE_SYMBOLS.invert[second_value
|
274
|
+
unicode = Mathml::Constants::UNICODE_SYMBOLS.invert[second_value&.class_name]
|
268
275
|
second_value = unicode ? Math::Symbol.new(unicode.to_s) : second_value
|
269
|
-
|
270
|
-
Utility.filter_values(lim[1])
|
271
|
-
second_value
|
272
|
-
|
276
|
+
if second_value.is_unary? && second_value.value_nil?
|
277
|
+
second_value.parameter_one = Utility.filter_values(lim[1])
|
278
|
+
second_value
|
279
|
+
else
|
280
|
+
Math::Function::Underset.new(
|
281
|
+
Utility.filter_values(lim[1]),
|
282
|
+
second_value,
|
283
|
+
)
|
284
|
+
end
|
273
285
|
end
|
274
286
|
|
275
287
|
rule(borderBox: subtree(:box)) do
|
data/lib/plurimath/unitsml.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "unitsml"
|
3
4
|
module Plurimath
|
4
5
|
class Unitsml
|
5
6
|
attr_accessor :text
|
@@ -9,7 +10,7 @@ module Plurimath
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def to_formula
|
12
|
-
|
13
|
+
::Unitsml.parse(text).to_plurimath
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|