plurimath 0.3.9 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/plurimath/latex/constants.rb +1 -0
- data/lib/plurimath/latex/parse.rb +11 -3
- data/lib/plurimath/latex/transform.rb +93 -7
- data/lib/plurimath/math/core.rb +16 -4
- data/lib/plurimath/math/formula.rb +24 -20
- data/lib/plurimath/math/function/abs.rb +2 -2
- data/lib/plurimath/math/function/bar.rb +48 -10
- data/lib/plurimath/math/function/base.rb +3 -3
- data/lib/plurimath/math/function/binary_function.rb +20 -10
- data/lib/plurimath/math/function/cancel.rb +2 -2
- data/lib/plurimath/math/function/ceil.rb +7 -2
- data/lib/plurimath/math/function/color.rb +2 -2
- data/lib/plurimath/math/function/ddot.rb +17 -12
- data/lib/plurimath/math/function/deg.rb +2 -2
- data/lib/plurimath/math/function/det.rb +2 -2
- data/lib/plurimath/math/function/dim.rb +2 -2
- data/lib/plurimath/math/function/dot.rb +26 -2
- data/lib/plurimath/math/function/exp.rb +2 -2
- data/lib/plurimath/math/function/fenced.rb +6 -7
- data/lib/plurimath/math/function/floor.rb +2 -2
- data/lib/plurimath/math/function/font_style/bold-fraktur.rb +17 -0
- data/lib/plurimath/math/function/font_style/bold-italic.rb +17 -0
- data/lib/plurimath/math/function/font_style/bold-sans-serif.rb +17 -0
- data/lib/plurimath/math/function/font_style/bold-script.rb +17 -0
- data/lib/plurimath/math/function/font_style/bold.rb +4 -0
- data/lib/plurimath/math/function/font_style/double_struck.rb +4 -0
- data/lib/plurimath/math/function/font_style/fraktur.rb +4 -0
- data/lib/plurimath/math/function/font_style/italic.rb +4 -0
- data/lib/plurimath/math/function/font_style/monospace.rb +4 -0
- data/lib/plurimath/math/function/font_style/normal.rb +4 -0
- data/lib/plurimath/math/function/font_style/sans-serif-bold-italic.rb +17 -0
- data/lib/plurimath/math/function/font_style/sans-serif-italic.rb +17 -0
- data/lib/plurimath/math/function/font_style/sans-serif.rb +4 -0
- data/lib/plurimath/math/function/font_style/script.rb +4 -0
- data/lib/plurimath/math/function/font_style.rb +24 -2
- data/lib/plurimath/math/function/frac.rb +3 -3
- data/lib/plurimath/math/function/gcd.rb +2 -2
- data/lib/plurimath/math/function/glb.rb +2 -2
- data/lib/plurimath/math/function/hat.rb +42 -9
- data/lib/plurimath/math/function/hom.rb +2 -2
- data/lib/plurimath/math/function/inf.rb +2 -2
- data/lib/plurimath/math/function/int.rb +4 -4
- data/lib/plurimath/math/function/ker.rb +2 -2
- data/lib/plurimath/math/function/lcm.rb +2 -2
- data/lib/plurimath/math/function/left.rb +1 -1
- data/lib/plurimath/math/function/lg.rb +2 -2
- data/lib/plurimath/math/function/lim.rb +2 -2
- data/lib/plurimath/math/function/liminf.rb +2 -2
- data/lib/plurimath/math/function/limits.rb +4 -4
- data/lib/plurimath/math/function/limsup.rb +2 -2
- data/lib/plurimath/math/function/ln.rb +2 -2
- data/lib/plurimath/math/function/log.rb +5 -3
- data/lib/plurimath/math/function/longdiv.rb +2 -2
- data/lib/plurimath/math/function/lub.rb +2 -2
- data/lib/plurimath/math/function/max.rb +2 -2
- data/lib/plurimath/math/function/mbox.rb +2 -2
- data/lib/plurimath/math/function/menclose.rb +2 -2
- data/lib/plurimath/math/function/merror.rb +1 -1
- data/lib/plurimath/math/function/min.rb +2 -2
- data/lib/plurimath/math/function/mod.rb +3 -3
- data/lib/plurimath/math/function/msgroup.rb +2 -2
- data/lib/plurimath/math/function/msline.rb +2 -2
- data/lib/plurimath/math/function/multiscript.rb +4 -4
- data/lib/plurimath/math/function/norm.rb +2 -2
- data/lib/plurimath/math/function/obrace.rb +40 -26
- data/lib/plurimath/math/function/oint.rb +4 -4
- data/lib/plurimath/math/function/over.rb +3 -3
- data/lib/plurimath/math/function/overset.rb +8 -3
- data/lib/plurimath/math/function/power.rb +3 -3
- data/lib/plurimath/math/function/power_base.rb +8 -8
- data/lib/plurimath/math/function/prod.rb +4 -4
- data/lib/plurimath/math/function/right.rb +1 -1
- data/lib/plurimath/math/function/root.rb +3 -3
- data/lib/plurimath/math/function/rule.rb +1 -1
- data/lib/plurimath/math/function/scarries.rb +2 -2
- data/lib/plurimath/math/function/semantics.rb +2 -2
- data/lib/plurimath/math/function/sqrt.rb +2 -2
- data/lib/plurimath/math/function/stackrel.rb +3 -3
- data/lib/plurimath/math/function/substack.rb +3 -3
- data/lib/plurimath/math/function/sum.rb +14 -19
- data/lib/plurimath/math/function/sup.rb +2 -2
- data/lib/plurimath/math/function/table.rb +7 -7
- data/lib/plurimath/math/function/td.rb +2 -2
- data/lib/plurimath/math/function/ternary_function.rb +13 -9
- data/lib/plurimath/math/function/text.rb +6 -5
- data/lib/plurimath/math/function/tilde.rb +27 -2
- data/lib/plurimath/math/function/tr.rb +2 -2
- data/lib/plurimath/math/function/ubrace.rb +28 -21
- data/lib/plurimath/math/function/ul.rb +55 -18
- data/lib/plurimath/math/function/unary_function.rb +13 -8
- data/lib/plurimath/math/function/underover.rb +10 -5
- data/lib/plurimath/math/function/underset.rb +8 -3
- data/lib/plurimath/math/function/vec.rb +25 -3
- data/lib/plurimath/math/number.rb +6 -2
- data/lib/plurimath/math/symbol.rb +6 -2
- data/lib/plurimath/math.rb +1 -0
- data/lib/plurimath/mathml/constants.rb +9 -1
- data/lib/plurimath/mathml/parser.rb +16 -10
- data/lib/plurimath/mathml/transform.rb +59 -31
- data/lib/plurimath/omml/parser.rb +24 -1
- data/lib/plurimath/omml/transform.rb +56 -41
- data/lib/plurimath/utility.rb +154 -9
- data/lib/plurimath/version.rb +1 -1
- metadata +8 -2
@@ -51,6 +51,14 @@ module Plurimath
|
|
51
51
|
"#{first_value}#{second_value}#{third_value}"
|
52
52
|
end
|
53
53
|
|
54
|
+
def any_value_exist?
|
55
|
+
!(parameter_one.nil? || parameter_two.nil? || parameter_three.nil?)
|
56
|
+
end
|
57
|
+
|
58
|
+
def all_values_exist?
|
59
|
+
!(parameter_one.nil? && parameter_two.nil? && parameter_three.nil?)
|
60
|
+
end
|
61
|
+
|
54
62
|
protected
|
55
63
|
|
56
64
|
def latex_wrapped(field)
|
@@ -104,8 +112,8 @@ module Plurimath
|
|
104
112
|
def narypr(function_symbol, function_type: "undOvr")
|
105
113
|
chr_arg = { "m:val": function_symbol }
|
106
114
|
limloc_arg = { "m:val": function_type }
|
107
|
-
subhide_arg = { "m:val": "0" }
|
108
|
-
suphide_arg = { "m:val": "0" }
|
115
|
+
subhide_arg = { "m:val": parameter_one ? "0" : "1" }
|
116
|
+
suphide_arg = { "m:val": parameter_two ? "0" : "1" }
|
109
117
|
chr_tag = Utility.ox_element("chr", attributes: chr_arg, namespace: "m")
|
110
118
|
limloc_tag = Utility.ox_element("limLoc", attributes: limloc_arg, namespace: "m")
|
111
119
|
subhide_tag = Utility.ox_element("subHide", attributes: subhide_arg, namespace: "m")
|
@@ -122,21 +130,17 @@ module Plurimath
|
|
122
130
|
)
|
123
131
|
end
|
124
132
|
|
125
|
-
def all_values_exist?
|
126
|
-
!(parameter_one.nil? && parameter_two.nil? && parameter_three.nil?)
|
127
|
-
end
|
128
|
-
|
129
133
|
def validate_mathml_tag(parameter)
|
130
134
|
return Array(Utility.ox_element("mrow")) unless parameter
|
131
135
|
|
132
136
|
Array(parameter.to_mathml_without_math_tag)
|
133
137
|
end
|
134
138
|
|
135
|
-
def underover
|
139
|
+
def underover(display_style)
|
136
140
|
overset = Overset.new(parameter_one, parameter_three)
|
137
|
-
return overset unless parameter_two
|
141
|
+
return overset.to_omml_without_math_tag(display_style) unless parameter_two
|
138
142
|
|
139
|
-
Underset.new(overset, parameter_two)&.to_omml_without_math_tag
|
143
|
+
Underset.new(overset, parameter_two)&.to_omml_without_math_tag(display_style)
|
140
144
|
end
|
141
145
|
end
|
142
146
|
end
|
@@ -27,15 +27,15 @@ module Plurimath
|
|
27
27
|
parse_text("html") || parameter_one
|
28
28
|
end
|
29
29
|
|
30
|
-
def to_omml_without_math_tag
|
30
|
+
def to_omml_without_math_tag(_display_style)
|
31
31
|
text = Utility.ox_element("t", namespace: "m")
|
32
32
|
text << (parse_text("omml") || parameter_one)
|
33
33
|
[text]
|
34
34
|
end
|
35
35
|
|
36
|
-
def insert_t_tag
|
36
|
+
def insert_t_tag(display_style)
|
37
37
|
r_tag = Utility.ox_element("r", namespace: "m")
|
38
|
-
Utility.update_nodes(r_tag, to_omml_without_math_tag)
|
38
|
+
Utility.update_nodes(r_tag, to_omml_without_math_tag(display_style))
|
39
39
|
[r_tag]
|
40
40
|
end
|
41
41
|
|
@@ -54,7 +54,8 @@ module Plurimath
|
|
54
54
|
html_value = first_value(lang).dup
|
55
55
|
html_value&.gsub!(PARSER_REGEX) do |_text|
|
56
56
|
last_match = Regexp.last_match
|
57
|
-
|
57
|
+
case lang
|
58
|
+
when "mathml", "html"
|
58
59
|
symbol_value(last_match[:unicode])
|
59
60
|
else
|
60
61
|
last_match[:unicode]
|
@@ -67,7 +68,7 @@ module Plurimath
|
|
67
68
|
if lang == "omml"
|
68
69
|
entities = HTMLEntities.new
|
69
70
|
entities.encode(
|
70
|
-
entities.decode(parameter_one),
|
71
|
+
entities.decode(parameter_one&.gsub(/ /, " ")),
|
71
72
|
:named,
|
72
73
|
)
|
73
74
|
else
|
@@ -6,14 +6,39 @@ module Plurimath
|
|
6
6
|
module Math
|
7
7
|
module Function
|
8
8
|
class Tilde < UnaryFunction
|
9
|
+
attr_accessor :attributes
|
10
|
+
|
11
|
+
def initialize(parameter_one = nil, attributes = {})
|
12
|
+
super(parameter_one)
|
13
|
+
@attributes = attributes
|
14
|
+
end
|
15
|
+
|
9
16
|
def to_mathml_without_math_tag
|
10
17
|
mover = Utility.ox_element("mover")
|
18
|
+
mover.attributes.merge!({ accent: attributes[:accent]}) if attributes && attributes[:accent]
|
11
19
|
first_value = (Utility.ox_element("mo") << "~")
|
12
20
|
second_value = parameter_one.to_mathml_without_math_tag if parameter_one
|
13
21
|
Utility.update_nodes(mover, [second_value, first_value])
|
14
22
|
end
|
15
23
|
|
16
|
-
def to_omml_without_math_tag
|
24
|
+
def to_omml_without_math_tag(display_style)
|
25
|
+
return r_element("~", rpr_tag: false) unless parameter_one
|
26
|
+
|
27
|
+
if attributes && attributes[:accent]
|
28
|
+
acc_tag(display_style)
|
29
|
+
else
|
30
|
+
symbol = Symbol.new("~")
|
31
|
+
Overset.new(parameter_one, symbol).to_omml_without_math_tag(true)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate_function_formula
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def acc_tag(display_style)
|
17
42
|
acc_tag = Utility.ox_element("acc", namespace: "m")
|
18
43
|
acc_pr_tag = Utility.ox_element("accPr", namespace: "m")
|
19
44
|
acc_pr_tag << (Utility.ox_element("chr", namespace: "m", attributes: { "m:val": "˜" }))
|
@@ -21,7 +46,7 @@ module Plurimath
|
|
21
46
|
acc_tag,
|
22
47
|
[
|
23
48
|
acc_pr_tag,
|
24
|
-
omml_parameter(parameter_one, tag_name: "e"),
|
49
|
+
omml_parameter(parameter_one, display_style, tag_name: "e"),
|
25
50
|
],
|
26
51
|
)
|
27
52
|
[acc_tag]
|
@@ -31,8 +31,8 @@ module Plurimath
|
|
31
31
|
"<tr>#{first_value}</tr>"
|
32
32
|
end
|
33
33
|
|
34
|
-
def to_omml_without_math_tag
|
35
|
-
omml_content = parameter_one&.map(
|
34
|
+
def to_omml_without_math_tag(display_style)
|
35
|
+
omml_content = parameter_one&.map { |obj| obj.to_omml_without_math_tag(display_style) }
|
36
36
|
if parameter_one.count.eql?(1)
|
37
37
|
omml_content
|
38
38
|
else
|
@@ -6,6 +6,18 @@ module Plurimath
|
|
6
6
|
module Math
|
7
7
|
module Function
|
8
8
|
class Ubrace < UnaryFunction
|
9
|
+
attr_accessor :attributes
|
10
|
+
|
11
|
+
def initialize(parameter_one = nil, attributes = {})
|
12
|
+
super(parameter_one)
|
13
|
+
@attributes = attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_asciimath
|
17
|
+
first_value = "(#{parameter_one.to_asciimath})" if parameter_one
|
18
|
+
"ubrace#{first_value}"
|
19
|
+
end
|
20
|
+
|
9
21
|
def to_latex
|
10
22
|
first_value = "{#{parameter_one.to_latex}}" if parameter_one
|
11
23
|
"\\underbrace#{first_value}"
|
@@ -13,13 +25,17 @@ module Plurimath
|
|
13
25
|
|
14
26
|
def to_mathml_without_math_tag
|
15
27
|
mo_tag = (Utility.ox_element("mo") << "⏟")
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
28
|
+
return mo_tag unless parameter_one
|
29
|
+
|
30
|
+
over_tag = Utility.ox_element("munder")
|
31
|
+
over_tag.attributes.merge!(attributes) if attributes && !attributes.empty?
|
32
|
+
Utility.update_nodes(
|
33
|
+
over_tag,
|
34
|
+
[
|
35
|
+
parameter_one.to_mathml_without_math_tag,
|
36
|
+
mo_tag,
|
37
|
+
],
|
38
|
+
)
|
23
39
|
end
|
24
40
|
|
25
41
|
def tag_name
|
@@ -34,20 +50,11 @@ module Plurimath
|
|
34
50
|
false
|
35
51
|
end
|
36
52
|
|
37
|
-
def to_omml_without_math_tag
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
Utility.update_nodes(
|
43
|
-
limlow,
|
44
|
-
[
|
45
|
-
limlowpr,
|
46
|
-
omml_parameter(parameter_one, tag_name: "e"),
|
47
|
-
Utility.update_nodes(lim, r_element("⏟")),
|
48
|
-
],
|
49
|
-
)
|
50
|
-
[limlow]
|
53
|
+
def to_omml_without_math_tag(display_style)
|
54
|
+
return r_element("⏟", rpr_tag: false) unless parameter_one
|
55
|
+
|
56
|
+
symbol = Symbol.new("⏟")
|
57
|
+
Underset.new(parameter_one, symbol).to_omml_without_math_tag(true)
|
51
58
|
end
|
52
59
|
end
|
53
60
|
|
@@ -6,36 +6,73 @@ module Plurimath
|
|
6
6
|
module Math
|
7
7
|
module Function
|
8
8
|
class Ul < UnaryFunction
|
9
|
+
attr_accessor :attributes
|
10
|
+
|
11
|
+
def initialize(parameter_one = nil, attributes = {})
|
12
|
+
super(parameter_one)
|
13
|
+
@attributes = attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_asciimath
|
17
|
+
first_value = "(#{parameter_one.to_asciimath})" if parameter_one
|
18
|
+
"underline#{first_value}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_latex
|
22
|
+
first_value = "{#{parameter_one.to_latex}}" if parameter_one
|
23
|
+
"\\underline#{first_value}"
|
24
|
+
end
|
25
|
+
|
9
26
|
def to_mathml_without_math_tag
|
10
|
-
|
27
|
+
mo_tag = Utility.ox_element("mo") << "̲"
|
28
|
+
return mo_tag unless parameter_one
|
29
|
+
|
30
|
+
munder_tag = Utility.ox_element("munder")
|
31
|
+
munder_tag.attributes.merge!(attributes) if attributes && !attributes.empty?
|
11
32
|
Utility.update_nodes(
|
12
|
-
|
33
|
+
munder_tag,
|
13
34
|
[
|
14
|
-
|
15
|
-
|
35
|
+
parameter_one&.to_mathml_without_math_tag,
|
36
|
+
mo_tag,
|
16
37
|
],
|
17
38
|
)
|
18
39
|
end
|
19
40
|
|
20
|
-
def to_omml_without_math_tag
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
barpr,
|
30
|
-
me,
|
31
|
-
],
|
32
|
-
)
|
33
|
-
[bar]
|
41
|
+
def to_omml_without_math_tag(display_style)
|
42
|
+
return r_element("̲", rpr_tag: false) unless parameter_one
|
43
|
+
|
44
|
+
if attributes && attributes[:accentunder]
|
45
|
+
groupchr_tag(display_style)
|
46
|
+
else
|
47
|
+
symbol = Symbol.new("̲")
|
48
|
+
Underset.new(parameter_one, symbol).to_omml_without_math_tag(true)
|
49
|
+
end
|
34
50
|
end
|
35
51
|
|
36
52
|
def class_name
|
37
53
|
"underline"
|
38
54
|
end
|
55
|
+
|
56
|
+
def swap_class
|
57
|
+
Bar.new(parameter_one, attributes)
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
|
62
|
+
def groupchr_tag(display_style)
|
63
|
+
groupchr = Utility.ox_element("groupChr", namespace: "m")
|
64
|
+
groupchrpr = Utility.ox_element("groupChrPR", namespace: "m")
|
65
|
+
chr = Utility.ox_element("chr", namespace: "m", attributes: { "m:val": "_" })
|
66
|
+
pos = Utility.ox_element("pos", namespace: "m", attributes: { "m:val": "bot" })
|
67
|
+
Utility.update_nodes(groupchrpr, [chr, pos])
|
68
|
+
Utility.update_nodes(
|
69
|
+
groupchr,
|
70
|
+
[
|
71
|
+
groupchrpr,
|
72
|
+
omml_parameter(parameter_one, display_style, tag_name: "e", namespace: "m"),
|
73
|
+
],
|
74
|
+
)
|
75
|
+
end
|
39
76
|
end
|
40
77
|
|
41
78
|
Underline = Ul
|
@@ -39,8 +39,7 @@ module Plurimath
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def to_latex
|
42
|
-
|
43
|
-
"\\#{class_name}#{first_value}"
|
42
|
+
"\\#{class_name}{#{latex_value}}"
|
44
43
|
end
|
45
44
|
|
46
45
|
def to_html
|
@@ -49,10 +48,12 @@ module Plurimath
|
|
49
48
|
elsif parameter_one
|
50
49
|
"<i>#{parameter_one.to_html}</i>"
|
51
50
|
end
|
52
|
-
|
51
|
+
"<i>#{invert_unicode_symbols}</i>#{first_value}"
|
53
52
|
end
|
54
53
|
|
55
|
-
def to_omml_without_math_tag
|
54
|
+
def to_omml_without_math_tag(display_style)
|
55
|
+
return r_element(class_name, rpr_tag: false) unless parameter_one
|
56
|
+
|
56
57
|
func = Utility.ox_element("func", namespace: "m")
|
57
58
|
funcpr = Utility.ox_element("funcPr", namespace: "m")
|
58
59
|
funcpr << Utility.pr_element("ctrl", true, namespace: "m")
|
@@ -62,7 +63,7 @@ module Plurimath
|
|
62
63
|
mt = Utility.ox_element("t", namespace: "m") << class_name
|
63
64
|
fname << Utility.update_nodes(mr, [rpr, mt])
|
64
65
|
me = Utility.ox_element("e", namespace: "m")
|
65
|
-
Utility.update_nodes(me, omml_value) if parameter_one
|
66
|
+
Utility.update_nodes(me, omml_value(display_style)) if parameter_one
|
66
67
|
Utility.update_nodes(
|
67
68
|
func,
|
68
69
|
[
|
@@ -76,6 +77,10 @@ module Plurimath
|
|
76
77
|
|
77
78
|
protected
|
78
79
|
|
80
|
+
def invert_unicode_symbols
|
81
|
+
Mathml::Constants::UNICODE_SYMBOLS.invert[class_name] || class_name
|
82
|
+
end
|
83
|
+
|
79
84
|
def asciimath_value
|
80
85
|
return "" unless parameter_one
|
81
86
|
|
@@ -104,12 +109,12 @@ module Plurimath
|
|
104
109
|
parameter_one&.to_latex
|
105
110
|
end
|
106
111
|
|
107
|
-
def omml_value
|
112
|
+
def omml_value(display_style)
|
108
113
|
if parameter_one.is_a?(Array)
|
109
|
-
return parameter_one&.compact&.map(
|
114
|
+
return parameter_one&.compact&.map { |obj| obj.insert_t_tag(display_style) }
|
110
115
|
end
|
111
116
|
|
112
|
-
Array(parameter_one&.insert_t_tag)
|
117
|
+
Array(parameter_one&.insert_t_tag(display_style))
|
113
118
|
end
|
114
119
|
end
|
115
120
|
end
|
@@ -35,16 +35,21 @@ module Plurimath
|
|
35
35
|
)
|
36
36
|
end
|
37
37
|
|
38
|
-
def to_omml_without_math_tag
|
39
|
-
|
38
|
+
def to_omml_without_math_tag(display_style)
|
39
|
+
if !display_style
|
40
|
+
power_base = PowerBase.new(parameter_one, parameter_two, parameter_three)
|
41
|
+
return power_base.to_omml_without_math_tag(display_style)
|
42
|
+
end
|
43
|
+
|
44
|
+
underover(display_style)
|
40
45
|
end
|
41
46
|
|
42
|
-
def omml_nary_tag
|
47
|
+
def omml_nary_tag(display_style)
|
43
48
|
pr = Utility.ox_element("naryPr", namespace: "m")
|
44
49
|
[
|
45
50
|
pr_element_value(pr),
|
46
|
-
omml_parameter(parameter_two, tag_name: "sub"),
|
47
|
-
omml_parameter(parameter_three, tag_name: "sup"),
|
51
|
+
omml_parameter(parameter_two, display_style, tag_name: "sub"),
|
52
|
+
omml_parameter(parameter_three, display_style, tag_name: "sup"),
|
48
53
|
]
|
49
54
|
end
|
50
55
|
|
@@ -18,7 +18,12 @@ module Plurimath
|
|
18
18
|
)
|
19
19
|
end
|
20
20
|
|
21
|
-
def to_omml_without_math_tag
|
21
|
+
def to_omml_without_math_tag(display_style)
|
22
|
+
if !display_style
|
23
|
+
base = Base.new(parameter_one, parameter_two)
|
24
|
+
return base.to_omml_without_math_tag(display_style)
|
25
|
+
end
|
26
|
+
|
22
27
|
limlow = Utility.ox_element("limLow", namespace: "m")
|
23
28
|
limlowpr = Utility.ox_element("limLowPr", namespace: "m")
|
24
29
|
limlowpr << Utility.pr_element("ctrl", true, namespace: "m")
|
@@ -26,8 +31,8 @@ module Plurimath
|
|
26
31
|
limlow,
|
27
32
|
[
|
28
33
|
limlowpr,
|
29
|
-
omml_parameter(parameter_one, tag_name: "e"),
|
30
|
-
omml_parameter(parameter_two, tag_name: "lim"),
|
34
|
+
omml_parameter(parameter_one, display_style, tag_name: "e"),
|
35
|
+
omml_parameter(parameter_two, display_style, tag_name: "lim"),
|
31
36
|
],
|
32
37
|
)
|
33
38
|
[limlow]
|
@@ -6,10 +6,19 @@ module Plurimath
|
|
6
6
|
module Math
|
7
7
|
module Function
|
8
8
|
class Vec < UnaryFunction
|
9
|
+
attr_accessor :attributes
|
10
|
+
|
11
|
+
def initialize(parameter_one = nil, attributes = {})
|
12
|
+
super(parameter_one)
|
13
|
+
@attributes = attributes
|
14
|
+
end
|
15
|
+
|
9
16
|
def to_mathml_without_math_tag
|
17
|
+
mover = Utility.ox_element("mover")
|
10
18
|
first_value = parameter_one&.to_mathml_without_math_tag
|
19
|
+
mover.attributes.merge!({ accent: attributes[:accent] }) if attributes && attributes[:accent]
|
11
20
|
Utility.update_nodes(
|
12
|
-
|
21
|
+
mover,
|
13
22
|
[
|
14
23
|
first_value,
|
15
24
|
Utility.ox_element("mo") << "→",
|
@@ -17,7 +26,20 @@ module Plurimath
|
|
17
26
|
)
|
18
27
|
end
|
19
28
|
|
20
|
-
def to_omml_without_math_tag
|
29
|
+
def to_omml_without_math_tag(display_style)
|
30
|
+
return r_element("→", rpr_tag: false) unless parameter_one
|
31
|
+
|
32
|
+
if attributes && attributes[:accent]
|
33
|
+
acc_tag(display_style)
|
34
|
+
else
|
35
|
+
symbol = Symbol.new("→")
|
36
|
+
Overset.new(parameter_one, symbol).to_omml_without_math_tag(true)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def acc_tag(display_style)
|
21
43
|
acc_tag = Utility.ox_element("acc", namespace: "m")
|
22
44
|
acc_pr_tag = Utility.ox_element("accPr", namespace: "m")
|
23
45
|
acc_pr_tag << (Utility.ox_element("chr", namespace: "m", attributes: { "m:val": "→" }))
|
@@ -25,7 +47,7 @@ module Plurimath
|
|
25
47
|
acc_tag,
|
26
48
|
[
|
27
49
|
acc_pr_tag,
|
28
|
-
omml_parameter(parameter_one, tag_name: "e"),
|
50
|
+
omml_parameter(parameter_one, display_style, tag_name: "e"),
|
29
51
|
],
|
30
52
|
)
|
31
53
|
[acc_tag]
|
@@ -29,16 +29,20 @@ module Plurimath
|
|
29
29
|
value
|
30
30
|
end
|
31
31
|
|
32
|
-
def to_omml_without_math_tag
|
32
|
+
def to_omml_without_math_tag(_display_style)
|
33
33
|
[(Utility.ox_element("t", namespace: "m") << value)]
|
34
34
|
end
|
35
35
|
|
36
|
-
def insert_t_tag
|
36
|
+
def insert_t_tag(_display_style)
|
37
37
|
r_tag = Utility.ox_element("r", namespace: "m")
|
38
38
|
r_tag << (Utility.ox_element("t", namespace: "m") << value)
|
39
39
|
[r_tag]
|
40
40
|
end
|
41
41
|
|
42
|
+
def font_style_t_tag(_display_style)
|
43
|
+
Utility.ox_element("t", namespace: "m") << value
|
44
|
+
end
|
45
|
+
|
42
46
|
def nary_attr_value
|
43
47
|
value
|
44
48
|
end
|
@@ -58,11 +58,11 @@ module Plurimath
|
|
58
58
|
value
|
59
59
|
end
|
60
60
|
|
61
|
-
def to_omml_without_math_tag
|
61
|
+
def to_omml_without_math_tag(_display_style)
|
62
62
|
value
|
63
63
|
end
|
64
64
|
|
65
|
-
def insert_t_tag
|
65
|
+
def insert_t_tag(_display_style)
|
66
66
|
r_tag = Utility.ox_element("r", namespace: "m")
|
67
67
|
r_tag << (Utility.ox_element("t", namespace: "m") << value)
|
68
68
|
[r_tag]
|
@@ -80,6 +80,10 @@ module Plurimath
|
|
80
80
|
"subSup"
|
81
81
|
end
|
82
82
|
|
83
|
+
def font_style_t_tag(_display_style)
|
84
|
+
Utility.ox_element("t", namespace: "m") << value
|
85
|
+
end
|
86
|
+
|
83
87
|
def nary_attr_value
|
84
88
|
value
|
85
89
|
end
|
data/lib/plurimath/math.rb
CHANGED
@@ -130,7 +130,6 @@ module Plurimath
|
|
130
130
|
"⇒": "rArr",
|
131
131
|
"⇐": "lArr",
|
132
132
|
"⇔": "hArr",
|
133
|
-
"→": "->",
|
134
133
|
"↣": ">->",
|
135
134
|
"↠": "->>",
|
136
135
|
"⤖": ">->>",
|
@@ -139,10 +138,19 @@ module Plurimath
|
|
139
138
|
"−": "-",
|
140
139
|
"⏞": "obrace",
|
141
140
|
"⏟": "ubrace",
|
141
|
+
"→": "vec",
|
142
|
+
"̂": "hat",
|
143
|
+
"̲": "ul",
|
144
|
+
"¯": "bar",
|
142
145
|
"&": "&",
|
143
146
|
">": ">",
|
144
147
|
"<": "<",
|
145
148
|
"&": "&",
|
149
|
+
"~": "tilde",
|
150
|
+
"..": "ddot",
|
151
|
+
"^": "hat",
|
152
|
+
"¯": "bar",
|
153
|
+
"_": "ul",
|
146
154
|
}.freeze
|
147
155
|
SYMBOLS = {
|
148
156
|
"|": "|",
|
@@ -7,11 +7,13 @@ module Plurimath
|
|
7
7
|
class Parser
|
8
8
|
attr_accessor :text
|
9
9
|
|
10
|
-
|
10
|
+
SUPPORTED_ATTRS = %w[
|
11
11
|
columnlines
|
12
12
|
mathvariant
|
13
|
+
accentunder
|
13
14
|
mathcolor
|
14
15
|
notation
|
16
|
+
accent
|
15
17
|
close
|
16
18
|
open
|
17
19
|
].freeze
|
@@ -22,11 +24,11 @@ module Plurimath
|
|
22
24
|
|
23
25
|
def parse
|
24
26
|
ox_nodes = Ox.load(text, strip_namespace: true)
|
25
|
-
display_style = ox_nodes&.locate("*/mstyle/@displaystyle")&.first
|
27
|
+
display_style = ox_nodes&.locate("*/mstyle/@displaystyle")&.first
|
26
28
|
nodes = parse_nodes(ox_nodes.nodes)
|
27
29
|
Math::Formula.new(
|
28
30
|
Transform.new.apply(nodes).flatten.compact,
|
29
|
-
|
31
|
+
display_style: (display_style || true),
|
30
32
|
)
|
31
33
|
end
|
32
34
|
|
@@ -37,12 +39,7 @@ module Plurimath
|
|
37
39
|
if node.is_a?(String)
|
38
40
|
node
|
39
41
|
elsif !node.attributes.empty?
|
40
|
-
|
41
|
-
node.name.to_sym => {
|
42
|
-
attributes: validate_attributes(node.attributes),
|
43
|
-
value: parse_nodes(node.nodes),
|
44
|
-
},
|
45
|
-
}
|
42
|
+
attrs_hash(node)
|
46
43
|
else
|
47
44
|
{ node.name.to_sym => parse_nodes(node.nodes) }
|
48
45
|
end
|
@@ -50,9 +47,18 @@ module Plurimath
|
|
50
47
|
end
|
51
48
|
|
52
49
|
def validate_attributes(attributes)
|
53
|
-
attributes&.select! { |key, _|
|
50
|
+
attributes&.select! { |key, _| SUPPORTED_ATTRS.include?(key&.to_s) }
|
54
51
|
attributes&.transform_keys(&:to_sym) if attributes&.any?
|
55
52
|
end
|
53
|
+
|
54
|
+
def attrs_hash(node)
|
55
|
+
{
|
56
|
+
node.name.to_sym => {
|
57
|
+
attributes: validate_attributes(node.attributes),
|
58
|
+
value: parse_nodes(node.nodes),
|
59
|
+
},
|
60
|
+
}
|
61
|
+
end
|
56
62
|
end
|
57
63
|
end
|
58
64
|
end
|