plurimath 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/plurimath/asciimath/transform.rb +17 -0
- data/lib/plurimath/math/core.rb +4 -0
- data/lib/plurimath/math/formula.rb +19 -6
- data/lib/plurimath/math/function/binary_function.rb +11 -1
- data/lib/plurimath/math/function/inf.rb +2 -8
- data/lib/plurimath/math/function/lim.rb +1 -7
- data/lib/plurimath/math/function/oint.rb +11 -12
- data/lib/plurimath/math/function/power_base.rb +3 -1
- data/lib/plurimath/math/function/prod.rb +4 -0
- data/lib/plurimath/math/function/sum.rb +8 -0
- data/lib/plurimath/math/function/table.rb +0 -4
- data/lib/plurimath/math/function/ternary_function.rb +7 -0
- data/lib/plurimath/math/function/ubrace.rb +4 -0
- data/lib/plurimath/math/function/underover.rb +2 -5
- data/lib/plurimath/math/symbol.rb +8 -0
- data/lib/plurimath/math.rb +3 -1
- data/lib/plurimath/mathml/parser.rb +2 -2
- data/lib/plurimath/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d50026941bd556b94051c14a61a081ad96dbf839ed1aa324a9451382ef512e8
|
4
|
+
data.tar.gz: 40bf633bf5c0286daa011bf80d90baa2d522b18b9e545035d5dd6c32593792db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cf6f394801e567d2a7b482a14fc4da5e3b4c19515ce549a00fc9c247ce4d26c565dc5ff72586648cd30c51c0361f40808fb1117ed408bd9c319156622b34640
|
7
|
+
data.tar.gz: 65d1590db64f33f620ad438ae2d328eb1fe9a6bffeee9a427dba9f782bdc9b429ed5c54e9892ade8c59894ddd57d2bcc6680a4b7cb1b9cee26c67c0cab1b05d2
|
@@ -766,6 +766,18 @@ module Plurimath
|
|
766
766
|
)
|
767
767
|
end
|
768
768
|
|
769
|
+
rule(ternary_class: simple(:function),
|
770
|
+
base_value: simple(:base),
|
771
|
+
power_value: simple(:power),
|
772
|
+
third_value: sequence(:third)) do
|
773
|
+
third_value = third.is_a?(Slice) ? nil : third
|
774
|
+
Utility.get_class(function).new(
|
775
|
+
Utility.unfenced_value(base),
|
776
|
+
Utility.unfenced_value(power),
|
777
|
+
Utility.filter_values(third_value),
|
778
|
+
)
|
779
|
+
end
|
780
|
+
|
769
781
|
rule(unary_class: simple(:function),
|
770
782
|
intermediate_exp: simple(:int_exp)) do
|
771
783
|
first_value = if Utility::UNARY_CLASSES.include?(function)
|
@@ -821,6 +833,11 @@ module Plurimath
|
|
821
833
|
expr.insert(0, ternary)
|
822
834
|
end
|
823
835
|
|
836
|
+
rule(ternary: simple(:ternary),
|
837
|
+
left_right: simple(:left_right)) do
|
838
|
+
[ternary, left_right]
|
839
|
+
end
|
840
|
+
|
824
841
|
rule(unary_class: simple(:function),
|
825
842
|
text: simple(:text)) do
|
826
843
|
Utility.get_class(function).new(
|
data/lib/plurimath/math/core.rb
CHANGED
@@ -3,12 +3,13 @@
|
|
3
3
|
module Plurimath
|
4
4
|
module Math
|
5
5
|
class Formula < Core
|
6
|
-
attr_accessor :value, :left_right_wrapper, :displaystyle
|
6
|
+
attr_accessor :value, :left_right_wrapper, :displaystyle, :input_string
|
7
7
|
|
8
8
|
def initialize(
|
9
9
|
value = [],
|
10
10
|
left_right_wrapper = true,
|
11
|
-
displaystyle: true
|
11
|
+
displaystyle: true,
|
12
|
+
input_string: nil
|
12
13
|
)
|
13
14
|
@value = value.is_a?(Array) ? value : [value]
|
14
15
|
left_right_wrapper = false if @value.first.is_a?(Function::Left)
|
@@ -23,6 +24,8 @@ module Plurimath
|
|
23
24
|
|
24
25
|
def to_asciimath
|
25
26
|
value.map(&:to_asciimath).join(" ")
|
27
|
+
rescue
|
28
|
+
parse_error!(:asciimath)
|
26
29
|
end
|
27
30
|
|
28
31
|
def to_mathml(display_style: displaystyle)
|
@@ -36,6 +39,8 @@ module Plurimath
|
|
36
39
|
Utility.update_nodes(style, mathml_content)
|
37
40
|
Utility.update_nodes(math, [style])
|
38
41
|
Ox.dump(math, indent: 2).gsub("&", "&")
|
42
|
+
rescue
|
43
|
+
parse_error!(:mathml)
|
39
44
|
end
|
40
45
|
|
41
46
|
def to_mathml_without_math_tag
|
@@ -53,10 +58,14 @@ module Plurimath
|
|
53
58
|
|
54
59
|
def to_latex
|
55
60
|
value&.map(&:to_latex)&.join(" ")
|
61
|
+
rescue
|
62
|
+
parse_error!(:latex)
|
56
63
|
end
|
57
64
|
|
58
65
|
def to_html
|
59
66
|
value&.map(&:to_html)&.join(" ")
|
67
|
+
rescue
|
68
|
+
parse_error!(:html)
|
60
69
|
end
|
61
70
|
|
62
71
|
def omml_math_attrs
|
@@ -92,6 +101,8 @@ module Plurimath
|
|
92
101
|
Utility.update_nodes(math_element, omml_content)
|
93
102
|
Utility.update_nodes(para_element, Array(math_element))
|
94
103
|
Ox.dump(para_element, indent: 2).gsub("&", "&").lstrip
|
104
|
+
rescue
|
105
|
+
parse_error!(:omml)
|
95
106
|
end
|
96
107
|
|
97
108
|
def omml_content
|
@@ -115,10 +126,6 @@ module Plurimath
|
|
115
126
|
[nary_tag]
|
116
127
|
end
|
117
128
|
|
118
|
-
def class_name
|
119
|
-
self.class.name.split("::").last.downcase
|
120
|
-
end
|
121
|
-
|
122
129
|
def extract_class_from_text
|
123
130
|
return false unless (value.length < 2 && value&.first&.is_a?(Function::Text))
|
124
131
|
|
@@ -141,6 +148,12 @@ module Plurimath
|
|
141
148
|
def validate_function_formula
|
142
149
|
(value.none?(Function::Left) || value.none?(Function::Right))
|
143
150
|
end
|
151
|
+
|
152
|
+
protected
|
153
|
+
|
154
|
+
def parse_error!(type)
|
155
|
+
Math.parse_error!(input_string, type)
|
156
|
+
end
|
144
157
|
end
|
145
158
|
end
|
146
159
|
end
|
@@ -83,7 +83,17 @@ module Plurimath
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def all_values_exist?
|
86
|
-
!parameter_one.nil? &&
|
86
|
+
!(parameter_one.nil? && parameter_two.nil?)
|
87
|
+
end
|
88
|
+
|
89
|
+
def underover
|
90
|
+
return r_element(class_name, rpr_tag: false) unless all_values_exist?
|
91
|
+
|
92
|
+
first_value = Symbol.new(class_name)
|
93
|
+
overset = Overset.new(first_value, parameter_two)
|
94
|
+
return Array(overset.to_omml_without_math_tag) unless parameter_one
|
95
|
+
|
96
|
+
Array(Underset.new(overset, parameter_one)&.to_omml_without_math_tag)
|
87
97
|
end
|
88
98
|
end
|
89
99
|
end
|
@@ -14,7 +14,7 @@ module Plurimath
|
|
14
14
|
|
15
15
|
def to_mathml_without_math_tag
|
16
16
|
first_value = Utility.ox_element("mo") << class_name
|
17
|
-
return first_value
|
17
|
+
return first_value unless all_values_exist?
|
18
18
|
|
19
19
|
value_array = [first_value]
|
20
20
|
value_array << parameter_one&.to_mathml_without_math_tag
|
@@ -31,13 +31,7 @@ module Plurimath
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def to_omml_without_math_tag
|
34
|
-
|
35
|
-
|
36
|
-
inf = Symbol.new("inf")
|
37
|
-
overset = Overset.new(inf, parameter_two)
|
38
|
-
return Array(overset.to_omml_without_math_tag) unless parameter_one
|
39
|
-
|
40
|
-
Array(Underset.new(overset, parameter_one)&.to_omml_without_math_tag)
|
34
|
+
underover
|
41
35
|
end
|
42
36
|
end
|
43
37
|
end
|
@@ -40,13 +40,7 @@ module Plurimath
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def to_omml_without_math_tag
|
43
|
-
|
44
|
-
|
45
|
-
lim = Symbol.new("lim")
|
46
|
-
overset = Overset.new(lim, parameter_two)
|
47
|
-
return overset.to_omml_without_math_tag unless parameter_one
|
48
|
-
|
49
|
-
Underset.new(overset, parameter_one)&.to_omml_without_math_tag
|
43
|
+
underover
|
50
44
|
end
|
51
45
|
end
|
52
46
|
end
|
@@ -22,17 +22,16 @@ module Plurimath
|
|
22
22
|
mo_tag = Utility.ox_element("mo") << invert_unicode_symbols.to_s
|
23
23
|
return mo_tag unless all_values_exist?
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
)
|
25
|
+
value_array = [mo_tag]
|
26
|
+
value_array << parameter_one&.to_mathml_without_math_tag
|
27
|
+
value_array << parameter_two&.to_mathml_without_math_tag
|
28
|
+
tag_name = if parameter_one && parameter_two
|
29
|
+
"subsup"
|
30
|
+
else
|
31
|
+
parameter_one ? "sub" : "sup"
|
32
|
+
end
|
33
|
+
msubsup_tag = Utility.ox_element("m#{tag_name}")
|
34
|
+
Utility.update_nodes(msubsup_tag, value_array)
|
36
35
|
return msubsup_tag if parameter_three.nil?
|
37
36
|
|
38
37
|
Utility.update_nodes(
|
@@ -40,7 +39,7 @@ module Plurimath
|
|
40
39
|
[
|
41
40
|
msubsup_tag,
|
42
41
|
parameter_three&.to_mathml_without_math_tag,
|
43
|
-
].
|
42
|
+
].compact,
|
44
43
|
)
|
45
44
|
end
|
46
45
|
|
@@ -35,7 +35,7 @@ module Plurimath
|
|
35
35
|
narypr << Utility.ox_element(
|
36
36
|
"limLoc",
|
37
37
|
namespace: "m",
|
38
|
-
attributes: { "m:val":
|
38
|
+
attributes: { "m:val": parameter_one.omml_tag_name },
|
39
39
|
)
|
40
40
|
hide_tags(narypr)
|
41
41
|
narypr << Utility.pr_element("ctrl", true, namespace: "m")
|
@@ -47,6 +47,8 @@ module Plurimath
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def to_omml_without_math_tag
|
50
|
+
return underover if parameter_one.omml_tag_name == "undOvr"
|
51
|
+
|
50
52
|
ssubsup = Utility.ox_element("sSubSup", namespace: "m")
|
51
53
|
ssubsuppr = Utility.ox_element("sSubSupPr", namespace: "m")
|
52
54
|
ssubsuppr << hide_tags(
|
@@ -131,6 +131,13 @@ module Plurimath
|
|
131
131
|
|
132
132
|
Array(parameter.to_mathml_without_math_tag)
|
133
133
|
end
|
134
|
+
|
135
|
+
def underover
|
136
|
+
overset = Overset.new(parameter_one, parameter_three)
|
137
|
+
return overset unless parameter_two
|
138
|
+
|
139
|
+
Underset.new(overset, parameter_two)&.to_omml_without_math_tag
|
140
|
+
end
|
134
141
|
end
|
135
142
|
end
|
136
143
|
end
|
@@ -36,10 +36,7 @@ module Plurimath
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def to_omml_without_math_tag
|
39
|
-
|
40
|
-
return overset unless parameter_two
|
41
|
-
|
42
|
-
Underset.new(overset, parameter_two)&.to_omml_without_math_tag
|
39
|
+
underover
|
43
40
|
end
|
44
41
|
|
45
42
|
def omml_nary_tag
|
@@ -86,7 +83,7 @@ module Plurimath
|
|
86
83
|
end
|
87
84
|
|
88
85
|
def first_value(pr_element)
|
89
|
-
first_value = parameter_one.
|
86
|
+
first_value = parameter_one.nary_attr_value
|
90
87
|
first_value = Utility.html_entity_to_unicode(first_value)
|
91
88
|
unless first_value == "∫"
|
92
89
|
pr_element << Utility.ox_element(
|
@@ -72,6 +72,14 @@ module Plurimath
|
|
72
72
|
["⋀", "⋁", "⋂", "⋃"].include?(value) ? "underover" : "subsup"
|
73
73
|
end
|
74
74
|
|
75
|
+
def omml_tag_name
|
76
|
+
if ["⋀", "⋁", "⋂", "⋃", "⋃", "∑", "∏"].include?(value)
|
77
|
+
return "undOvr"
|
78
|
+
end
|
79
|
+
|
80
|
+
"subSup"
|
81
|
+
end
|
82
|
+
|
75
83
|
def nary_attr_value
|
76
84
|
value
|
77
85
|
end
|
data/lib/plurimath/math.rb
CHANGED
@@ -22,11 +22,11 @@ module Plurimath
|
|
22
22
|
|
23
23
|
def parse
|
24
24
|
ox_nodes = Ox.load(text, strip_namespace: true)
|
25
|
-
display_style = ox_nodes&.locate("*/mstyle/@displaystyle")&.first
|
25
|
+
display_style = ox_nodes&.locate("*/mstyle/@displaystyle")&.first || true
|
26
26
|
nodes = parse_nodes(ox_nodes.nodes)
|
27
27
|
Math::Formula.new(
|
28
28
|
Transform.new.apply(nodes).flatten.compact,
|
29
|
-
displaystyle: display_style
|
29
|
+
displaystyle: display_style,
|
30
30
|
)
|
31
31
|
end
|
32
32
|
|
data/lib/plurimath/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plurimath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|