plurimath 0.8.17 → 0.8.18
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/Gemfile +1 -1
- data/lib/plurimath/asciimath/parse.rb +1 -0
- data/lib/plurimath/asciimath/transform.rb +12 -0
- data/lib/plurimath/math/core.rb +63 -4
- data/lib/plurimath/math/formula/mrow.rb +193 -0
- data/lib/plurimath/math/formula/mstyle.rb +17 -0
- data/lib/plurimath/math/formula.rb +307 -4
- data/lib/plurimath/math/function/base.rb +4 -0
- data/lib/plurimath/math/function/color.rb +17 -4
- data/lib/plurimath/math/function/fenced.rb +219 -0
- data/lib/plurimath/math/function/frac.rb +4 -0
- data/lib/plurimath/math/function/linebreak.rb +2 -2
- data/lib/plurimath/math/function/longdiv.rb +3 -0
- data/lib/plurimath/math/function/menclose.rb +3 -0
- data/lib/plurimath/math/function/merror.rb +5 -2
- data/lib/plurimath/math/function/mglyph.rb +27 -0
- data/lib/plurimath/math/function/mlabeledtr.rb +19 -0
- data/lib/plurimath/math/function/mpadded.rb +28 -1
- data/lib/plurimath/math/function/ms.rb +80 -0
- data/lib/plurimath/math/function/msgroup.rb +15 -0
- data/lib/plurimath/math/function/msline.rb +5 -2
- data/lib/plurimath/math/function/multiscript.rb +14 -0
- data/lib/plurimath/math/function/over.rb +3 -0
- data/lib/plurimath/math/function/overset.rb +11 -0
- data/lib/plurimath/math/function/phantom.rb +3 -0
- data/lib/plurimath/math/function/power.rb +3 -0
- data/lib/plurimath/math/function/power_base.rb +3 -0
- data/lib/plurimath/math/function/root.rb +3 -0
- data/lib/plurimath/math/function/scarries.rb +3 -0
- data/lib/plurimath/math/function/semantics.rb +14 -0
- data/lib/plurimath/math/function/sqrt.rb +3 -0
- data/lib/plurimath/math/function/stackrel.rb +3 -0
- data/lib/plurimath/math/function/table.rb +53 -0
- data/lib/plurimath/math/function/td.rb +4 -1
- data/lib/plurimath/math/function/text.rb +22 -2
- data/lib/plurimath/math/function/tr.rb +13 -0
- data/lib/plurimath/math/function/underover.rb +3 -0
- data/lib/plurimath/math/function/underset.rb +44 -0
- data/lib/plurimath/math/number.rb +10 -1
- data/lib/plurimath/math/symbols/gg.rb +4 -4
- data/lib/plurimath/math/symbols/ll.rb +4 -4
- data/lib/plurimath/math/symbols/minus.rb +1 -1
- data/lib/plurimath/math/symbols/symbol.rb +12 -4
- data/lib/plurimath/math.rb +2 -0
- data/lib/plurimath/mathml/parser.rb +45 -86
- data/lib/plurimath/mathml/utility/empty_defined_methods.rb +477 -0
- data/lib/plurimath/mathml/utility/formula_transformation.rb +472 -0
- data/lib/plurimath/mathml/utility.rb +363 -0
- data/lib/plurimath/mathml.rb +1 -0
- data/lib/plurimath/unicode_math/transform.rb +2 -2
- data/lib/plurimath/utility.rb +5 -23
- data/lib/plurimath/version.rb +1 -1
- data/lib/plurimath.rb +9 -0
- data/plurimath.gemspec +4 -2
- metadata +37 -5
- data/lib/plurimath/mathml/transform.rb +0 -413
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 766097c1faa26dc82f8664fca18a302b52920df2fce4ec8395cf2f65d8a7d687
|
4
|
+
data.tar.gz: 35cf1a6b6a0e87fa5404b3eea87927cd69da535deeebfcd49f8db5ce1aaba8e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7307ab95dc0d60e6fe65c939665e08ec59902527a454427956ee17e6d2c7bc207921e529ae107d51ec0f2a2a0909cd7da260943d277a03755efc34aa01edd2d0
|
7
|
+
data.tar.gz: 6f050eb9cae6730e911ccae66afe0a4384ab0fade68810fa4fa176e15d5f37eef225f0b11c1409fcd10ed05e75cbf7aa6fdd10a4e18d85ab335dbb947c22d350
|
data/Gemfile
CHANGED
@@ -158,6 +158,7 @@ module Plurimath
|
|
158
158
|
str("") |
|
159
159
|
(rparen.as(:rparen) >> space? >> controversial_symbols >> comma.as(:comma).maybe >> expression).repeat(1).as(:expr) |
|
160
160
|
(power.as(:symbol) >> space? >> expression).as(:expr) |
|
161
|
+
table.as(:table) >> space? >> rparen.as(:rparen) >> space? >> expression.as(:expr).maybe |
|
161
162
|
comma.as(:comma).maybe
|
162
163
|
end
|
163
164
|
|
@@ -900,6 +900,18 @@ module Plurimath
|
|
900
900
|
Math::Formula.new(formula_array)
|
901
901
|
end
|
902
902
|
|
903
|
+
rule(table: simple(:table),
|
904
|
+
rparen: simple(:rparen),
|
905
|
+
expr: sequence(:expr)) do
|
906
|
+
[
|
907
|
+
Math::Function::Fenced.new(
|
908
|
+
Math::Symbols::Paren::OpenParen.new,
|
909
|
+
[table],
|
910
|
+
Utility.asciimath_symbol_object(rparen),
|
911
|
+
),
|
912
|
+
] + expr.flatten.compact
|
913
|
+
end
|
914
|
+
|
903
915
|
rule(left: simple(:left),
|
904
916
|
left_right_value: simple(:left_right),
|
905
917
|
right: simple(:right)) do
|
data/lib/plurimath/math/core.rb
CHANGED
@@ -8,6 +8,13 @@ module Plurimath
|
|
8
8
|
/^\n/ => "",
|
9
9
|
}.freeze
|
10
10
|
|
11
|
+
ALL_PARAMETERS = %i[
|
12
|
+
parameter_one
|
13
|
+
parameter_two
|
14
|
+
parameter_three
|
15
|
+
parameter_four
|
16
|
+
].freeze
|
17
|
+
|
11
18
|
def self.inherited(subclass)
|
12
19
|
@descendants ||= []
|
13
20
|
@descendants << subclass
|
@@ -201,7 +208,7 @@ module Plurimath
|
|
201
208
|
false
|
202
209
|
end
|
203
210
|
|
204
|
-
def linebreak
|
211
|
+
def linebreak?
|
205
212
|
false
|
206
213
|
end
|
207
214
|
|
@@ -291,11 +298,15 @@ module Plurimath
|
|
291
298
|
is_a?(Math::Function::UnaryFunction)
|
292
299
|
end
|
293
300
|
|
294
|
-
def is_nary_function?;end
|
301
|
+
def is_nary_function?; end
|
302
|
+
|
303
|
+
def is_nary_symbol?; end
|
295
304
|
|
296
|
-
def
|
305
|
+
def nary_intent_name; end
|
297
306
|
|
298
|
-
def
|
307
|
+
def symbol?
|
308
|
+
is_a?(Math::Symbols::Symbol)
|
309
|
+
end
|
299
310
|
|
300
311
|
def is_binary_function?
|
301
312
|
is_a?(Function::BinaryFunction)
|
@@ -323,8 +334,56 @@ module Plurimath
|
|
323
334
|
Utility.primes_constants.any? { |prefix, prime| unicodemath_field_value(field).include?(prime) }
|
324
335
|
end
|
325
336
|
|
337
|
+
def paren?
|
338
|
+
false
|
339
|
+
end
|
340
|
+
|
341
|
+
def pretty_print_instance_variables
|
342
|
+
excluded_vars = [
|
343
|
+
:@left_right_wrapper,
|
344
|
+
:@temp_mathml_order,
|
345
|
+
:@using_default,
|
346
|
+
:@displaystyle,
|
347
|
+
:@__ordered,
|
348
|
+
:@__mixed,
|
349
|
+
:@is_mrow,
|
350
|
+
:@values,
|
351
|
+
]
|
352
|
+
instance_variables.sort - excluded_vars
|
353
|
+
end
|
354
|
+
|
355
|
+
def to_ms_value
|
356
|
+
new_arr = []
|
357
|
+
case self
|
358
|
+
when Math::Symbols::Symbol
|
359
|
+
new_arr << (value ? value.to_s : to_unicodemath(options: {}))
|
360
|
+
when Math::Number, Math::Function::Text
|
361
|
+
new_arr << value
|
362
|
+
else
|
363
|
+
parameters_to_ms_value(new_arr)
|
364
|
+
if respond_to?(:value) && value.is_a?(Array)
|
365
|
+
new_arr << value&.map { |element| element.to_ms_value }.join(" ")
|
366
|
+
end
|
367
|
+
end
|
368
|
+
new_arr
|
369
|
+
end
|
370
|
+
|
371
|
+
def is_mstyle?
|
372
|
+
false
|
373
|
+
end
|
374
|
+
|
375
|
+
def is_mrow?
|
376
|
+
false
|
377
|
+
end
|
378
|
+
|
326
379
|
private
|
327
380
|
|
381
|
+
def parameters_to_ms_value(array)
|
382
|
+
ALL_PARAMETERS.each do |field|
|
383
|
+
array << get("@#{field}")&.to_ms_value if respond_to?(field)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
328
387
|
def array_line_break_field(field, variable, obj)
|
329
388
|
if result(field).length > 1
|
330
389
|
updated_object_values(variable, obj: obj)
|
@@ -0,0 +1,193 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Plurimath
|
4
|
+
module Math
|
5
|
+
class Formula
|
6
|
+
class Mrow < Formula
|
7
|
+
attr_accessor :is_mrow
|
8
|
+
|
9
|
+
def initialize(
|
10
|
+
value = [],
|
11
|
+
left_right_wrapper = true,
|
12
|
+
display_style: true,
|
13
|
+
input_string: nil,
|
14
|
+
unitsml: false
|
15
|
+
)
|
16
|
+
super
|
17
|
+
@is_mrow = true
|
18
|
+
end
|
19
|
+
|
20
|
+
def element_order=(value)
|
21
|
+
@value = validated_order(value, rejectable_array: ["comment"])
|
22
|
+
end
|
23
|
+
|
24
|
+
def content; end
|
25
|
+
|
26
|
+
def content=(value)
|
27
|
+
arr_value = Array(value)
|
28
|
+
if no_content_in?(arr_value)
|
29
|
+
delete_all_text
|
30
|
+
else
|
31
|
+
validate_text_order(
|
32
|
+
arr_value.map { |val| validate_symbols(val) unless val.strip.empty? }
|
33
|
+
)
|
34
|
+
end
|
35
|
+
organize_value
|
36
|
+
end
|
37
|
+
|
38
|
+
def is_mrow?
|
39
|
+
@is_mrow
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def organize_value
|
45
|
+
return if value.any?(String)
|
46
|
+
return unless is_mrow
|
47
|
+
|
48
|
+
value.each_with_index do |element, index|
|
49
|
+
update_current_element(element, value, index)
|
50
|
+
if value[index + 1].is_a?(Math::Function::Mod)
|
51
|
+
update_mod_function(value, index)
|
52
|
+
elsif unary_function_updatable?(value, element, index)
|
53
|
+
unary_function_update(value, index)
|
54
|
+
elsif value.first.paren? && value.last.paren?
|
55
|
+
organize_fencing(value)
|
56
|
+
elsif valid_underset_function?(element)
|
57
|
+
value[index] = new_nary_element(element, value)
|
58
|
+
elsif valid_underover_function?(element)
|
59
|
+
replace_with_nary_function(element, value, index)
|
60
|
+
elsif ternary_function_third_value_present?(element)
|
61
|
+
element.parameter_three = value.delete_at(index + 1)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def update_current_element(element, value, index)
|
67
|
+
if first_and_last_values_nil?(value)
|
68
|
+
replace_symbols_with_parens(value)
|
69
|
+
elsif element.class_name == "symbol" && element.value.nil?
|
70
|
+
element.value = ""
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def validate_text_order(value)
|
75
|
+
@value.each_with_index do |item, index|
|
76
|
+
next unless item == "text"
|
77
|
+
|
78
|
+
if value.first
|
79
|
+
@value[index] = value.shift
|
80
|
+
else
|
81
|
+
value.shift
|
82
|
+
@value.delete_at(index)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def delete_all_text
|
88
|
+
@value.delete("text")
|
89
|
+
end
|
90
|
+
|
91
|
+
def no_content_in?(value)
|
92
|
+
value.nil? || value.empty? || value&.all? { |val| val.strip.empty? }
|
93
|
+
end
|
94
|
+
|
95
|
+
def first_and_last_values_nil?(value)
|
96
|
+
value.first.class_name == "symbol" &&
|
97
|
+
value.first.value.nil? &&
|
98
|
+
value.last.class_name == "symbol" &&
|
99
|
+
value.last.value.nil?
|
100
|
+
end
|
101
|
+
|
102
|
+
def replace_symbols_with_parens(value)
|
103
|
+
value[0] = Math::Symbols::Paren::OpenParen.new
|
104
|
+
value[-1] = Math::Symbols::Paren::CloseParen.new
|
105
|
+
end
|
106
|
+
|
107
|
+
def nary_function_or_symbol?(element)
|
108
|
+
element.is_nary_function? || element.is_nary_symbol?
|
109
|
+
end
|
110
|
+
|
111
|
+
def valid_underover_function?(element)
|
112
|
+
element.is_a?(Math::Function::Underover) &&
|
113
|
+
nary_function_or_symbol?(element.parameter_one)
|
114
|
+
end
|
115
|
+
|
116
|
+
def valid_underset_function?(element)
|
117
|
+
element.is_a?(Math::Function::Underset) &&
|
118
|
+
nary_function_or_symbol?(element.parameter_two)
|
119
|
+
end
|
120
|
+
|
121
|
+
def unary_function_updatable?(value, element, index)
|
122
|
+
value.length > 1 &&
|
123
|
+
element.is_unary? &&
|
124
|
+
value[index + 1] &&
|
125
|
+
Plurimath::Utility::UNARY_CLASSES.include?(element.class_name)
|
126
|
+
end
|
127
|
+
|
128
|
+
def ternary_function_third_value_present?(element)
|
129
|
+
element.is_ternary_function? &&
|
130
|
+
element.any_value_exist? &&
|
131
|
+
element.parameter_three.nil?
|
132
|
+
end
|
133
|
+
|
134
|
+
def update_mod_function(value, index)
|
135
|
+
mod_obj = value[index + 1]
|
136
|
+
mod_obj.parameter_one = filter_values(
|
137
|
+
value.delete_at(index),
|
138
|
+
array_to_instance: true
|
139
|
+
)
|
140
|
+
mod_obj.parameter_two = filter_values(
|
141
|
+
value.delete_at(index + 1),
|
142
|
+
array_to_instance: true
|
143
|
+
)
|
144
|
+
end
|
145
|
+
|
146
|
+
def unary_function_update(value, index)
|
147
|
+
element = value.delete_at(index)
|
148
|
+
element.parameter_one = filter_values(
|
149
|
+
value.delete_at(index),
|
150
|
+
array_to_instance: true
|
151
|
+
)
|
152
|
+
value.insert(index, element)
|
153
|
+
end
|
154
|
+
|
155
|
+
def organize_fencing(value)
|
156
|
+
if value[1].is_a?(Math::Function::Table) && value.length == 3
|
157
|
+
table = value[1]
|
158
|
+
table.open_paren = value.shift
|
159
|
+
table.close_paren = value.pop
|
160
|
+
else
|
161
|
+
@value = [
|
162
|
+
Function::Fenced.new(value.shift, value, value.pop)
|
163
|
+
]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def new_nary_element(element, value)
|
168
|
+
value.shift
|
169
|
+
nary = Plurimath::Math::Function::Nary.new(
|
170
|
+
element.parameter_two,
|
171
|
+
element.parameter_one,
|
172
|
+
nil,
|
173
|
+
filter_values(value.shift(value.length), array_to_instance: true),
|
174
|
+
{ type: "undOvr" }
|
175
|
+
)
|
176
|
+
nary
|
177
|
+
end
|
178
|
+
|
179
|
+
def replace_with_nary_function(element, value, index)
|
180
|
+
fourth_value = value.delete_at(index + 1)
|
181
|
+
organize_value(fourth_value) if fourth_value.is_mrow?
|
182
|
+
value[index] = Math::Function::Nary.new(
|
183
|
+
element.parameter_one,
|
184
|
+
element.parameter_two,
|
185
|
+
element.parameter_three,
|
186
|
+
filter_values(fourth_value, array_to_instance: true),
|
187
|
+
{ type: "undOvr" }
|
188
|
+
)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Plurimath
|
4
|
+
module Math
|
5
|
+
class Formula
|
6
|
+
class Mstyle < Formula
|
7
|
+
def displaystyle=(value)
|
8
|
+
@displaystyle = boolean_display_style(value)
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_mstyle?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|