plurimath 0.9.5 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/plurimath/formatter/numbers/significant.rb +4 -5
- data/lib/plurimath/math/core.rb +15 -8
- data/lib/plurimath/math/formula.rb +45 -45
- data/lib/plurimath/math/function/log.rb +1 -3
- data/lib/plurimath/math/function/text.rb +16 -2
- data/lib/plurimath/math/function/unary_function.rb +23 -7
- data/lib/plurimath/omml/transform.rb +2 -1
- data/lib/plurimath/utility.rb +4 -4
- 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: 25137b188abdff732f47c221a2b04e8a5861cd2d642e8496176ff77c6d991f72
|
4
|
+
data.tar.gz: b1a9c2180b99f077a0c77293785b5b11a5ea76a6b5b1dc35328b6456e1c7664d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1ecd1523941d106ab5f5903e874a689ae2ee3a74f0cc002fe0e346451f45d339ed83c7bb330af8897770280a3859047809cf6e55b05d738f1953fb1e1ab2ccb
|
7
|
+
data.tar.gz: 22b67912e8b99d1ceab2e09b50da7638cfca8d329279ddbcc97174cd5beba8315c23802cc99701b80f41cc64b42bd428fff3bed8f081c3900ec6b489061f5c60
|
@@ -33,9 +33,9 @@ module Plurimath
|
|
33
33
|
frac_part = false
|
34
34
|
new_chars = []
|
35
35
|
sig_count = significant
|
36
|
-
chars.
|
37
|
-
frac_part
|
38
|
-
sig_num
|
36
|
+
chars.each_with_index do |char, ind|
|
37
|
+
frac_part ||= char == decimal
|
38
|
+
sig_num ||= char.match?(/[1-9]/)
|
39
39
|
break if sig_count.zero?
|
40
40
|
|
41
41
|
new_chars << char
|
@@ -47,7 +47,6 @@ module Plurimath
|
|
47
47
|
|
48
48
|
if sig_count > 0
|
49
49
|
new_chars << decimal unless frac_part
|
50
|
-
new_chars << ("0" * sig_count)
|
51
50
|
else
|
52
51
|
remain_chars = count_chars(chars, frac_part) - significant
|
53
52
|
if remain_chars > 0
|
@@ -66,7 +65,7 @@ module Plurimath
|
|
66
65
|
|
67
66
|
frac_part = false if chars[arr_len] == decimal
|
68
67
|
prev_ten = false
|
69
|
-
array.reverse!.
|
68
|
+
array.reverse!.each_with_index do |char, ind|
|
70
69
|
if char == decimal
|
71
70
|
array[ind] = ""
|
72
71
|
frac_part = false
|
data/lib/plurimath/math/core.rb
CHANGED
@@ -30,7 +30,7 @@ module Plurimath
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def insert_t_tag(display_style, options:)
|
33
|
-
Array(
|
33
|
+
Array(omml_nodes(display_style, options: options))
|
34
34
|
end
|
35
35
|
|
36
36
|
def tag_name
|
@@ -72,14 +72,17 @@ module Plurimath
|
|
72
72
|
def r_element(string, rpr_tag: true)
|
73
73
|
r_tag = ox_element("r", namespace: "m")
|
74
74
|
if rpr_tag
|
75
|
-
|
76
|
-
sty_tag = ox_element("sty", namespace: "m", attributes: attrs)
|
77
|
-
r_tag << (ox_element("rPr", namespace: "m") << sty_tag)
|
75
|
+
r_tag << (ox_element("rPr", namespace: "m") << msty_tag_with_attrs)
|
78
76
|
end
|
79
77
|
r_tag << (ox_element("t", namespace: "m") << string)
|
80
78
|
Array(r_tag)
|
81
79
|
end
|
82
80
|
|
81
|
+
def msty_tag_with_attrs
|
82
|
+
attrs = { "m:val": "p" }
|
83
|
+
ox_element("sty", namespace: "m", attributes: attrs)
|
84
|
+
end
|
85
|
+
|
83
86
|
def extractable?
|
84
87
|
false
|
85
88
|
end
|
@@ -89,7 +92,7 @@ module Plurimath
|
|
89
92
|
end
|
90
93
|
|
91
94
|
def font_style_t_tag(display_style, options:)
|
92
|
-
|
95
|
+
omml_nodes(display_style, options: options)
|
93
96
|
end
|
94
97
|
|
95
98
|
def ascii_fields_to_print(field, options = {})
|
@@ -144,7 +147,7 @@ module Plurimath
|
|
144
147
|
end
|
145
148
|
|
146
149
|
def dump_mathml(field, intent = false, options:)
|
147
|
-
dump_ox_nodes(field.
|
150
|
+
dump_ox_nodes(field.mathml_nodes(intent, options: options)).gsub(/\n\s*/, "")
|
148
151
|
end
|
149
152
|
|
150
153
|
def dump_omml(field, display_style, options:)
|
@@ -153,15 +156,19 @@ module Plurimath
|
|
153
156
|
dump_ox_nodes(field.omml_nodes(display_style, options: options)).gsub(/\n\s*/, "")
|
154
157
|
end
|
155
158
|
|
159
|
+
def mathml_nodes(intent, options:)
|
160
|
+
to_mathml_without_math_tag(intent, options: options)
|
161
|
+
end
|
162
|
+
|
156
163
|
def omml_nodes(display_style, options:)
|
157
164
|
to_omml_without_math_tag(display_style, options: options)
|
158
165
|
end
|
159
166
|
|
160
167
|
def validate_mathml_fields(field, intent, options:)
|
161
168
|
if field.is_a?(Array)
|
162
|
-
field&.map { |object| object.
|
169
|
+
field&.map { |object| object.mathml_nodes(intent, options: options) }
|
163
170
|
else
|
164
|
-
field&.
|
171
|
+
field&.mathml_nodes(intent, options: options)
|
165
172
|
end
|
166
173
|
end
|
167
174
|
|
@@ -9,20 +9,29 @@ module Plurimath
|
|
9
9
|
|
10
10
|
attr_accessor :value, :left_right_wrapper, :displaystyle, :input_string, :display
|
11
11
|
|
12
|
-
MATH_ZONE_TYPES = %i[
|
13
|
-
omml
|
14
|
-
latex
|
15
|
-
mathml
|
16
|
-
asciimath
|
17
|
-
unicodemath
|
18
|
-
].freeze
|
19
12
|
POWER_BASE_CLASSES = %w[powerbase power base].freeze
|
20
|
-
DERIVATIVE_CONSTS
|
21
|
-
|
22
|
-
|
23
|
-
"
|
24
|
-
"
|
25
|
-
|
13
|
+
DERIVATIVE_CONSTS = ["𝑑", "ⅅ", "ⅆ", "d"].freeze
|
14
|
+
MATH_ZONE_TYPES = %i[omml latex mathml asciimath unicodemath].freeze
|
15
|
+
OMML_NAMESPACES = {
|
16
|
+
"xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math",
|
17
|
+
"xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
18
|
+
"xmlns:mo": "http://schemas.microsoft.com/office/mac/office/2008/main",
|
19
|
+
"xmlns:mv": "urn:schemas-microsoft-com:mac:vml",
|
20
|
+
"xmlns:o": "urn:schemas-microsoft-com:office:office",
|
21
|
+
"xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
22
|
+
"xmlns:v": "urn:schemas-microsoft-com:vml",
|
23
|
+
"xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
24
|
+
"xmlns:w10": "urn:schemas-microsoft-com:office:word",
|
25
|
+
"xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
|
26
|
+
"xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml",
|
27
|
+
"xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml",
|
28
|
+
"xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
|
29
|
+
"xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",
|
30
|
+
"xmlns:wpc": "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
|
31
|
+
"xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
|
32
|
+
"xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
|
33
|
+
"xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
|
34
|
+
}.freeze
|
26
35
|
|
27
36
|
def initialize(
|
28
37
|
value = [],
|
@@ -55,9 +64,14 @@ module Plurimath
|
|
55
64
|
formatter: nil,
|
56
65
|
unitsml: {},
|
57
66
|
split_on_linebreak: false,
|
58
|
-
display_style: displaystyle
|
67
|
+
display_style: displaystyle,
|
68
|
+
unary_function_spacing: true
|
59
69
|
)
|
60
|
-
options = {
|
70
|
+
options = {
|
71
|
+
formatter: formatter,
|
72
|
+
unitsml: unitsml,
|
73
|
+
unary_function_spacing: unary_function_spacing
|
74
|
+
}.compact
|
61
75
|
return line_breaked_mathml(display_style, intent, options: options) if split_on_linebreak
|
62
76
|
|
63
77
|
math_attrs = {
|
@@ -77,7 +91,12 @@ module Plurimath
|
|
77
91
|
|
78
92
|
def line_breaked_mathml(display_style, intent, options:)
|
79
93
|
new_line_support.map do |formula|
|
80
|
-
formula.to_mathml(
|
94
|
+
formula.to_mathml(
|
95
|
+
display_style: display_style,
|
96
|
+
intent: intent,
|
97
|
+
formatter: options[:formatter],
|
98
|
+
unary_function_spacing: options[:unary_function_spacing],
|
99
|
+
)
|
81
100
|
end.join
|
82
101
|
end
|
83
102
|
|
@@ -110,33 +129,10 @@ module Plurimath
|
|
110
129
|
parse_error!(:html)
|
111
130
|
end
|
112
131
|
|
113
|
-
def omml_attrs
|
114
|
-
{
|
115
|
-
"xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math",
|
116
|
-
"xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
117
|
-
"xmlns:mo": "http://schemas.microsoft.com/office/mac/office/2008/main",
|
118
|
-
"xmlns:mv": "urn:schemas-microsoft-com:mac:vml",
|
119
|
-
"xmlns:o": "urn:schemas-microsoft-com:office:office",
|
120
|
-
"xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
121
|
-
"xmlns:v": "urn:schemas-microsoft-com:vml",
|
122
|
-
"xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
123
|
-
"xmlns:w10": "urn:schemas-microsoft-com:office:word",
|
124
|
-
"xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
|
125
|
-
"xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml",
|
126
|
-
"xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml",
|
127
|
-
"xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
|
128
|
-
"xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",
|
129
|
-
"xmlns:wpc": "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
|
130
|
-
"xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
|
131
|
-
"xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
|
132
|
-
"xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
|
133
|
-
}
|
134
|
-
end
|
135
|
-
|
136
132
|
def to_omml(display_style: displaystyle, split_on_linebreak: false, formatter: nil, unitsml: {})
|
137
133
|
objects = split_on_linebreak ? new_line_support : [self]
|
138
134
|
options = { formatter: formatter, unitsml: unitsml }.compact
|
139
|
-
para_element = Utility.ox_element("oMathPara", attributes:
|
135
|
+
para_element = Utility.ox_element("oMathPara", attributes: OMML_NAMESPACES, namespace: "m")
|
140
136
|
objects.each.with_index(1) do |object, index|
|
141
137
|
para_element << Utility.update_nodes(
|
142
138
|
Utility.ox_element("oMath", namespace: "m"),
|
@@ -166,8 +162,12 @@ module Plurimath
|
|
166
162
|
parse_error!(:unicodemath)
|
167
163
|
end
|
168
164
|
|
169
|
-
def to_display(type = nil, formatter: nil, unitsml: {})
|
170
|
-
options = {
|
165
|
+
def to_display(type = nil, formatter: nil, unitsml: {}, unary_function_spacing: true)
|
166
|
+
options = {
|
167
|
+
formatter: formatter,
|
168
|
+
unitsml: unitsml,
|
169
|
+
unary_function_spacing: unary_function_spacing
|
170
|
+
}
|
171
171
|
return type_error!(type) unless MATH_ZONE_TYPES.include?(type.downcase.to_sym)
|
172
172
|
|
173
173
|
math_zone = case type
|
@@ -176,7 +176,7 @@ module Plurimath
|
|
176
176
|
when :latex
|
177
177
|
" |_ \"#{to_latex(options: options)}\"\n#{to_latex_math_zone(" ", options: options).join}"
|
178
178
|
when :mathml
|
179
|
-
mathml = to_mathml(formatter: formatter).gsub(/\n\s*/, "")
|
179
|
+
mathml = to_mathml(formatter: formatter, unary_function_spacing: options[:unary_function_spacing]).gsub(/\n\s*/, "")
|
180
180
|
math_display = to_mathml_math_zone(" ", options: options).join
|
181
181
|
" |_ \"#{mathml}\"\n#{math_display}"
|
182
182
|
when :omml
|
@@ -628,7 +628,7 @@ module Plurimath
|
|
628
628
|
insert_index = 0
|
629
629
|
nodes.each.with_index do |node, index|
|
630
630
|
if node[:unitsml]
|
631
|
-
prev_node.insert_in_nodes(index + insert_index, space_element
|
631
|
+
prev_node.insert_in_nodes(index + insert_index, space_element)
|
632
632
|
insert_index += 1
|
633
633
|
node.remove_attr("unitsml")
|
634
634
|
end
|
@@ -636,7 +636,7 @@ module Plurimath
|
|
636
636
|
end
|
637
637
|
end
|
638
638
|
|
639
|
-
def space_element
|
639
|
+
def space_element
|
640
640
|
element = (ox_element("mo") << "⁢")
|
641
641
|
element[:rspace] = "thickmathspace"
|
642
642
|
element
|
@@ -92,9 +92,7 @@ module Plurimath
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def rpr_tag
|
95
|
-
|
96
|
-
sty_tag = Utility.ox_element("sty", attributes: sty_atrs, namespace: "m")
|
97
|
-
rpr_tag = (Utility.ox_element("rPr", namespace: "m") << sty_tag)
|
95
|
+
rpr_tag = (Utility.ox_element("rPr", namespace: "m") << msty_tag_with_attrs)
|
98
96
|
r_tag = Utility.ox_element("r", namespace: "m")
|
99
97
|
t_tag = (Utility.ox_element("t", namespace: "m") << "log")
|
100
98
|
Utility.update_nodes(r_tag, [rpr_tag, t_tag])
|
@@ -12,8 +12,14 @@ module Plurimath
|
|
12
12
|
|
13
13
|
PARSER_REGEX = %r{unicode\[:(?<unicode>\w{1,})\]}.freeze
|
14
14
|
|
15
|
-
def initialize(parameter_one = "")
|
15
|
+
def initialize(parameter_one = "", lang: nil)
|
16
16
|
super(parameter_one)
|
17
|
+
@lang = lang
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==(object)
|
21
|
+
object.class == self.class &&
|
22
|
+
object.parameter_one == self.parameter_one
|
17
23
|
end
|
18
24
|
|
19
25
|
def to_asciimath(**)
|
@@ -50,7 +56,15 @@ module Plurimath
|
|
50
56
|
|
51
57
|
def insert_t_tag(display_style, options:)
|
52
58
|
r_tag = Utility.ox_element("r", namespace: "m")
|
53
|
-
|
59
|
+
if @lang&.to_s != "omml"
|
60
|
+
rpr_tag = Utility.ox_element("rPr", namespace: "m")
|
61
|
+
rpr_tag << msty_tag_with_attrs
|
62
|
+
r_tag << rpr_tag
|
63
|
+
end
|
64
|
+
Utility.update_nodes(
|
65
|
+
r_tag,
|
66
|
+
[omml_nodes(display_style, options: options)],
|
67
|
+
)
|
54
68
|
[r_tag]
|
55
69
|
end
|
56
70
|
|
@@ -28,16 +28,32 @@ module Plurimath
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def to_mathml_without_math_tag(intent, options:)
|
31
|
-
tag_name = Utility::UNARY_CLASSES.include?(class_name)
|
31
|
+
tag_name = if Utility::UNARY_CLASSES.include?(class_name)
|
32
|
+
insert_space_tags = true
|
33
|
+
"mi"
|
34
|
+
else
|
35
|
+
"mo"
|
36
|
+
end
|
32
37
|
new_arr = []
|
33
38
|
new_arr << (ox_element(tag_name) << class_name) unless hide_function_name
|
34
|
-
if parameter_one
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
unary_element = if parameter_one
|
40
|
+
new_arr += mathml_value(intent, options: options)
|
41
|
+
mrow = ox_element("mrow")
|
42
|
+
Utility.update_nodes(mrow, new_arr)
|
43
|
+
intentify(mrow, intent, func_name: :function, intent_name: intent_names[:name])
|
44
|
+
else
|
45
|
+
new_arr.first
|
46
|
+
end
|
47
|
+
if insert_space_tags && options[:unary_function_spacing]
|
48
|
+
Utility.update_nodes(
|
49
|
+
ox_element("mrow"),
|
50
|
+
[
|
51
|
+
ox_element("mo", attributes: { rspace: "thickmathspace" }),
|
52
|
+
unary_element,
|
53
|
+
],
|
54
|
+
)
|
39
55
|
else
|
40
|
-
|
56
|
+
unary_element
|
41
57
|
end
|
42
58
|
end
|
43
59
|
|
@@ -15,6 +15,7 @@ module Plurimath
|
|
15
15
|
rule(sty: simple(:sty)) { sty }
|
16
16
|
rule(num: subtree(:num)) { num }
|
17
17
|
rule(den: subtree(:den)) { den }
|
18
|
+
rule(nor: subtree(:nor)) { nil }
|
18
19
|
rule(fPr: subtree(:fPr)) { nil }
|
19
20
|
rule(mpr: subtree(:mpr)) { nil }
|
20
21
|
rule(mPr: subtree(:mPr)) { nil }
|
@@ -88,7 +89,7 @@ module Plurimath
|
|
88
89
|
|
89
90
|
rule(t: sequence(:t)) do
|
90
91
|
if t.empty?
|
91
|
-
Math::Function::Text.new
|
92
|
+
Math::Function::Text.new("", lang: :omml)
|
92
93
|
else
|
93
94
|
t&.compact&.empty? ? [nil] : Utility.mathml_unary_classes(t, omml: true, lang: :omml)
|
94
95
|
end
|
data/lib/plurimath/utility.rb
CHANGED
@@ -361,7 +361,7 @@ module Plurimath
|
|
361
361
|
if text&.scan(/[[:digit:]]/)&.length == text&.length
|
362
362
|
Math::Number.new(text)
|
363
363
|
elsif text&.match?(/[a-zA-Z]/)
|
364
|
-
Math::Function::Text.new(text)
|
364
|
+
Math::Function::Text.new(text, lang: lang)
|
365
365
|
else
|
366
366
|
text = string_to_html_entity(text)
|
367
367
|
.gsub("&", "&")
|
@@ -481,7 +481,7 @@ module Plurimath
|
|
481
481
|
[
|
482
482
|
Math::Function::Intent.new(
|
483
483
|
filter_values(join_attr_value(nil, value, unicode_only: unicode_only, lang: lang)),
|
484
|
-
Math::Function::Text.new(attrs[:intent]),
|
484
|
+
Math::Function::Text.new(attrs[:intent], lang: lang),
|
485
485
|
)
|
486
486
|
]
|
487
487
|
elsif value.any?(String)
|
@@ -767,11 +767,11 @@ module Plurimath
|
|
767
767
|
next temp_array << (object.is_a?(Math::Symbols::Symbol) ? symbol_to_text(object, lang: lang, intent: intent, options: options) : object.value)
|
768
768
|
end
|
769
769
|
|
770
|
-
new_arr << Math::Function::Text.new(temp_array.join(" ")) if temp_array.any?
|
770
|
+
new_arr << Math::Function::Text.new(temp_array.join(" "), lang: lang) if temp_array.any?
|
771
771
|
temp_array = []
|
772
772
|
new_arr << object
|
773
773
|
end
|
774
|
-
new_arr << Math::Function::Text.new(temp_array.join(" ")) if temp_array.any?
|
774
|
+
new_arr << Math::Function::Text.new(temp_array.join(" "), lang: lang) if temp_array.any?
|
775
775
|
new_arr
|
776
776
|
end
|
777
777
|
|
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.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ox
|