plurimath 0.9.2 → 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/asciimath/parse.rb +2 -2
- data/lib/plurimath/asciimath/transform.rb +81 -0
- data/lib/plurimath/formatter/numbers/fraction.rb +11 -8
- data/lib/plurimath/formatter/numbers/significant.rb +4 -5
- data/lib/plurimath/latex/transform.rb +8 -0
- 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
- data/lib/plurimath.rb +1 -2
- 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
|
|
@@ -65,7 +65,7 @@ module Plurimath
|
|
|
65
65
|
rule(:left_right) do
|
|
66
66
|
(str("left") >> space? >> left_right_open_paren.as(:left) >> space? >> (iteration.maybe >> sequence.maybe).as(:left_right_value) >> space? >> str("right") >> space? >> left_right_close_paren.as(:right)) |
|
|
67
67
|
((table.as(:numerator) >> space? >> match(/(?<!\/)\/(?!\/)/) >> space? >> iteration.as(:denominator)).as(:frac) >> expression) |
|
|
68
|
-
(table.as(:table) >> expression.maybe)
|
|
68
|
+
(table.as(:table) >> power_base.maybe >> expression.maybe)
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
rule(:quoted_text) do
|
|
@@ -138,7 +138,7 @@ module Plurimath
|
|
|
138
138
|
|
|
139
139
|
rule(:iteration) do
|
|
140
140
|
ternary_classes_rules |
|
|
141
|
-
table.as(:table) |
|
|
141
|
+
table.as(:table) >> power_base.maybe |
|
|
142
142
|
comma.as(:comma) |
|
|
143
143
|
mod |
|
|
144
144
|
(sequence.as(:sequence) >> space? >> str("//").as(:symbol)) |
|
|
@@ -900,6 +900,64 @@ module Plurimath
|
|
|
900
900
|
Math::Formula.new(formula_array)
|
|
901
901
|
end
|
|
902
902
|
|
|
903
|
+
rule(table: simple(:table),
|
|
904
|
+
base: simple(:base)) do
|
|
905
|
+
Math::Function::Base.new(table, base)
|
|
906
|
+
end
|
|
907
|
+
|
|
908
|
+
rule(table: simple(:table),
|
|
909
|
+
power: simple(:power)) do
|
|
910
|
+
Math::Function::Power.new(table, power)
|
|
911
|
+
end
|
|
912
|
+
|
|
913
|
+
rule(table: simple(:table),
|
|
914
|
+
power_value: simple(:power),
|
|
915
|
+
base_value: simple(:base)) do
|
|
916
|
+
Math::Function::PowerBase.new(table, power, base)
|
|
917
|
+
end
|
|
918
|
+
|
|
919
|
+
rule(table: simple(:table),
|
|
920
|
+
power: simple(:power),
|
|
921
|
+
expr: sequence(:expr)) do
|
|
922
|
+
Math::Formula.new(
|
|
923
|
+
[
|
|
924
|
+
Math::Function::Power.new(table, power),
|
|
925
|
+
] + expr.flatten.compact,
|
|
926
|
+
)
|
|
927
|
+
end
|
|
928
|
+
|
|
929
|
+
rule(table: simple(:table),
|
|
930
|
+
power: simple(:power),
|
|
931
|
+
expr: simple(:expr)) do
|
|
932
|
+
Math::Formula.new(
|
|
933
|
+
[
|
|
934
|
+
Math::Function::Power.new(table, power),
|
|
935
|
+
expr,
|
|
936
|
+
],
|
|
937
|
+
)
|
|
938
|
+
end
|
|
939
|
+
|
|
940
|
+
rule(table: simple(:table),
|
|
941
|
+
base: simple(:base),
|
|
942
|
+
expr: sequence(:expr)) do
|
|
943
|
+
Math::Formula.new(
|
|
944
|
+
[
|
|
945
|
+
Math::Function::Base.new(table, base),
|
|
946
|
+
] + expr.flatten.compact,
|
|
947
|
+
)
|
|
948
|
+
end
|
|
949
|
+
|
|
950
|
+
rule(table: simple(:table),
|
|
951
|
+
base: simple(:base),
|
|
952
|
+
expr: simple(:expr)) do
|
|
953
|
+
Math::Formula.new(
|
|
954
|
+
[
|
|
955
|
+
Math::Function::Base.new(table, base),
|
|
956
|
+
expr,
|
|
957
|
+
],
|
|
958
|
+
)
|
|
959
|
+
end
|
|
960
|
+
|
|
903
961
|
rule(table: simple(:table),
|
|
904
962
|
rparen: simple(:rparen),
|
|
905
963
|
expr: sequence(:expr)) do
|
|
@@ -1032,6 +1090,29 @@ module Plurimath
|
|
|
1032
1090
|
)
|
|
1033
1091
|
end
|
|
1034
1092
|
|
|
1093
|
+
rule(table: simple(:table),
|
|
1094
|
+
power_value: simple(:power),
|
|
1095
|
+
base_value: simple(:base),
|
|
1096
|
+
expr: simple(:expr)) do
|
|
1097
|
+
Math::Formula.new(
|
|
1098
|
+
[
|
|
1099
|
+
Math::Function::PowerBase.new(table, power, base),
|
|
1100
|
+
expr,
|
|
1101
|
+
],
|
|
1102
|
+
)
|
|
1103
|
+
end
|
|
1104
|
+
|
|
1105
|
+
rule(table: simple(:table),
|
|
1106
|
+
power_value: simple(:power),
|
|
1107
|
+
base_value: simple(:base),
|
|
1108
|
+
expr: sequence(:expr)) do
|
|
1109
|
+
Math::Formula.new(
|
|
1110
|
+
[
|
|
1111
|
+
Math::Function::PowerBase.new(table, power, base),
|
|
1112
|
+
] + expr.flatten.compact,
|
|
1113
|
+
)
|
|
1114
|
+
end
|
|
1115
|
+
|
|
1035
1116
|
rule(table_left: simple(:table_left),
|
|
1036
1117
|
table_row: simple(:table_row),
|
|
1037
1118
|
expr: simple(:expr),
|
|
@@ -18,8 +18,12 @@ module Plurimath
|
|
|
18
18
|
precision = options[:precision] || @precision
|
|
19
19
|
return "" unless precision > 0
|
|
20
20
|
|
|
21
|
-
number =
|
|
22
|
-
|
|
21
|
+
number = if @digit_count
|
|
22
|
+
digit_count_format(int, fraction)
|
|
23
|
+
else
|
|
24
|
+
format(fraction, precision)
|
|
25
|
+
end
|
|
26
|
+
|
|
23
27
|
formatted_number = change_format(number) if number
|
|
24
28
|
formatted_number ? decimal + formatted_number : ""
|
|
25
29
|
end
|
|
@@ -40,18 +44,17 @@ module Plurimath
|
|
|
40
44
|
tokens.compact.join(separator)
|
|
41
45
|
end
|
|
42
46
|
|
|
43
|
-
def digit_count_format(int, fraction
|
|
47
|
+
def digit_count_format(int, fraction)
|
|
44
48
|
integer = int + "." + fraction
|
|
45
|
-
|
|
46
|
-
int_length = integer.length - 1
|
|
49
|
+
int_length = integer.length - 1 # integer length; excluding the decimal point
|
|
47
50
|
@digit_count ||= int_length
|
|
48
51
|
if int_length > @digit_count
|
|
49
|
-
number_string =
|
|
52
|
+
number_string = BigDecimal(integer).round(@digit_count - int.length)
|
|
50
53
|
numeric_digits(number_string) if @digit_count > int.length
|
|
51
54
|
elsif int_length < @digit_count
|
|
52
|
-
|
|
55
|
+
fraction + ("0" * (update_digit_count(fraction) - int_length))
|
|
53
56
|
else
|
|
54
|
-
|
|
57
|
+
fraction
|
|
55
58
|
end
|
|
56
59
|
end
|
|
57
60
|
|
|
@@ -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
|
|
@@ -183,6 +183,14 @@ module Plurimath
|
|
|
183
183
|
)
|
|
184
184
|
end
|
|
185
185
|
|
|
186
|
+
rule(power: simple(:power),
|
|
187
|
+
symbols: simple(:sym)) do
|
|
188
|
+
Math::Function::Power.new(
|
|
189
|
+
power,
|
|
190
|
+
Utility.symbols_class(sym, lang: :latex),
|
|
191
|
+
)
|
|
192
|
+
end
|
|
193
|
+
|
|
186
194
|
rule(power: simple(:power),
|
|
187
195
|
expression: simple(:expr)) do
|
|
188
196
|
Math::Function::Power.new(
|
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
data/lib/plurimath.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-
|
|
11
|
+
date: 2025-04-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ox
|