plurimath 0.8.16 → 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/.github/workflows/gen_docs.yml +10 -8
- data/Gemfile +1 -1
- data/README.adoc +4 -0
- data/Rakefile +55 -8
- data/intent_supported_classes.adoc +82 -0
- data/lib/plurimath/asciimath/parse.rb +1 -0
- data/lib/plurimath/asciimath/transform.rb +12 -0
- data/lib/plurimath/formatter/number_formatter.rb +6 -6
- data/lib/plurimath/formatter/numeric_formatter.rb +5 -2
- data/lib/plurimath/formatter/standard.rb +2 -0
- data/lib/plurimath/math/core.rb +65 -6
- data/lib/plurimath/math/formula/mrow.rb +193 -0
- data/lib/plurimath/math/formula/mstyle.rb +17 -0
- data/lib/plurimath/math/formula.rb +317 -7
- data/lib/plurimath/math/function/abs.rb +5 -1
- 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 +238 -7
- data/lib/plurimath/math/function/frac.rb +12 -1
- data/lib/plurimath/math/function/inf.rb +5 -1
- data/lib/plurimath/math/function/int.rb +5 -1
- data/lib/plurimath/math/function/intent.rb +6 -2
- data/lib/plurimath/math/function/lim.rb +5 -1
- 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/nary.rb +13 -1
- data/lib/plurimath/math/function/oint.rb +5 -1
- 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/prod.rb +5 -1
- 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/sum.rb +5 -1
- data/lib/plurimath/math/function/table/array.rb +1 -1
- data/lib/plurimath/math/function/table/bmatrix.rb +1 -1
- data/lib/plurimath/math/function/table/cases.rb +2 -2
- data/lib/plurimath/math/function/table/eqarray.rb +2 -2
- data/lib/plurimath/math/function/table/pmatrix.rb +1 -1
- data/lib/plurimath/math/function/table/vmatrix.rb +1 -1
- data/lib/plurimath/math/function/table.rb +65 -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/unary_function.rb +5 -1
- 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/bigwedge.rb +4 -0
- data/lib/plurimath/math/symbols/cap.rb +0 -4
- data/lib/plurimath/math/symbols/clockoint.rb +1 -1
- data/lib/plurimath/math/symbols/cntclockoint.rb +1 -1
- data/lib/plurimath/math/symbols/coprod.rb +1 -1
- data/lib/plurimath/math/symbols/dd.rb +4 -0
- data/lib/plurimath/math/symbols/dint.rb +4 -0
- data/lib/plurimath/math/symbols/duni.rb +4 -0
- data/lib/plurimath/math/symbols/gg.rb +4 -4
- data/lib/plurimath/math/symbols/ii.rb +4 -0
- data/lib/plurimath/math/symbols/iiiint.rb +1 -1
- data/lib/plurimath/math/symbols/iiint.rb +4 -0
- data/lib/plurimath/math/symbols/iint.rb +1 -1
- data/lib/plurimath/math/symbols/intclockwise.rb +1 -1
- data/lib/plurimath/math/symbols/intercal.rb +4 -0
- data/lib/plurimath/math/symbols/jj.rb +4 -0
- data/lib/plurimath/math/symbols/ll.rb +4 -4
- data/lib/plurimath/math/symbols/minus.rb +1 -1
- data/lib/plurimath/math/symbols/oiiint.rb +1 -1
- data/lib/plurimath/math/symbols/oiint.rb +1 -1
- data/lib/plurimath/math/symbols/oint.rb +1 -1
- data/lib/plurimath/math/symbols/symbol.rb +12 -4
- data/lib/plurimath/math/symbols/upcase_dd.rb +4 -0
- 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/intent_encoding.rb +21 -21
- 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 +38 -5
- data/lib/plurimath/mathml/transform.rb +0 -411
@@ -2,13 +2,20 @@
|
|
2
2
|
|
3
3
|
require "htmlentities"
|
4
4
|
require_relative "unary_function"
|
5
|
+
require_relative "../../mathml/utility"
|
5
6
|
|
6
7
|
module Plurimath
|
7
8
|
module Math
|
8
9
|
module Function
|
9
10
|
class Text < UnaryFunction
|
11
|
+
include Mathml::Utility
|
12
|
+
|
10
13
|
PARSER_REGEX = %r{unicode\[:(?<unicode>\w{1,})\]}.freeze
|
11
14
|
|
15
|
+
def initialize(parameter_one = "")
|
16
|
+
super(parameter_one)
|
17
|
+
end
|
18
|
+
|
12
19
|
def to_asciimath(**)
|
13
20
|
"\"#{parse_text('asciimath') || parameter_one}\""
|
14
21
|
end
|
@@ -67,12 +74,25 @@ module Plurimath
|
|
67
74
|
"#{spacing}\"#{dump_omml(self, display_style, options: options)}\" text\n"
|
68
75
|
end
|
69
76
|
|
77
|
+
def to_unicodemath_math_zone(spacing, _, _, options:)
|
78
|
+
"#{spacing}#{to_unicodemath(options: options)} text\n"
|
79
|
+
end
|
80
|
+
|
70
81
|
def value
|
71
82
|
parameter_one
|
72
83
|
end
|
73
84
|
|
74
|
-
def
|
75
|
-
|
85
|
+
def element_order=(*); end
|
86
|
+
|
87
|
+
def value=(text)
|
88
|
+
text = text.join if text.is_a?(Array)
|
89
|
+
entities = HTMLEntities.new
|
90
|
+
symbols = Mathml::Constants::UNICODE_SYMBOLS.transform_keys(&:to_s)
|
91
|
+
text = entities.encode(text, :hexadecimal)
|
92
|
+
symbols.each do |code, string|
|
93
|
+
text = text.gsub(code.downcase, "unicode[:#{string}]")
|
94
|
+
end
|
95
|
+
self.parameter_one = text
|
76
96
|
end
|
77
97
|
|
78
98
|
protected
|
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "unary_function"
|
4
|
+
require_relative "../../mathml/utility"
|
4
5
|
|
5
6
|
module Plurimath
|
6
7
|
module Math
|
7
8
|
module Function
|
8
9
|
class Tr < UnaryFunction
|
10
|
+
include Mathml::Utility
|
11
|
+
|
9
12
|
def initialize(parameter_one = [])
|
10
13
|
parameter_one.map!.with_index { |_, index| Td.new([]) } if parameter_one&.all?("@")
|
11
14
|
super(parameter_one)
|
@@ -93,6 +96,16 @@ module Plurimath
|
|
93
96
|
row_lines.shift if row_lines.first.is_a?(Math::Symbols::Hline)
|
94
97
|
first_value
|
95
98
|
end
|
99
|
+
|
100
|
+
def mtd_value=(value)
|
101
|
+
return if value.nil? || value.empty?
|
102
|
+
|
103
|
+
self.parameter_one = replace_order_with_value(
|
104
|
+
clear_temp_order,
|
105
|
+
update_temp_mathml_values(value),
|
106
|
+
"mtd"
|
107
|
+
)
|
108
|
+
end
|
96
109
|
end
|
97
110
|
end
|
98
111
|
end
|
@@ -35,7 +35,7 @@ module Plurimath
|
|
35
35
|
new_arr += mathml_value(intent, options: options)
|
36
36
|
mrow = ox_element("mrow")
|
37
37
|
Utility.update_nodes(mrow, new_arr)
|
38
|
-
intentify(mrow, intent, func_name: :function, intent_name: :
|
38
|
+
intentify(mrow, intent, func_name: :function, intent_name: intent_names[:name])
|
39
39
|
else
|
40
40
|
new_arr.first
|
41
41
|
end
|
@@ -153,6 +153,10 @@ module Plurimath
|
|
153
153
|
!parameter_one
|
154
154
|
end
|
155
155
|
|
156
|
+
def intent_names
|
157
|
+
{ name: ":function" }
|
158
|
+
end
|
159
|
+
|
156
160
|
protected
|
157
161
|
|
158
162
|
def asciimath_value(options:)
|
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "../../mathml/utility"
|
3
4
|
require_relative "ternary_function"
|
4
5
|
|
5
6
|
module Plurimath
|
6
7
|
module Math
|
7
8
|
module Function
|
8
9
|
class Underover < TernaryFunction
|
10
|
+
include Mathml::Utility
|
11
|
+
|
9
12
|
FUNCTION = {
|
10
13
|
name: "UnderOver",
|
11
14
|
first_value: "base",
|
@@ -1,12 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "binary_function"
|
4
|
+
require_relative "../../mathml/utility"
|
4
5
|
|
5
6
|
module Plurimath
|
6
7
|
module Math
|
7
8
|
module Function
|
8
9
|
class Underset < BinaryFunction
|
10
|
+
include Mathml::Utility
|
11
|
+
|
9
12
|
attr_accessor :options
|
13
|
+
|
10
14
|
FUNCTION = {
|
11
15
|
name: "underscript",
|
12
16
|
first_value: "underscript value",
|
@@ -21,6 +25,13 @@ module Plurimath
|
|
21
25
|
@options = options unless options.empty?
|
22
26
|
end
|
23
27
|
|
28
|
+
def element_order=(value)
|
29
|
+
@temp_mathml_order = validated_order(
|
30
|
+
value,
|
31
|
+
rejectable_array: ["comment"]
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
24
35
|
def to_mathml_without_math_tag(intent, options:)
|
25
36
|
value_array = [
|
26
37
|
validate_mathml_fields(parameter_two, intent, options: options),
|
@@ -79,8 +90,41 @@ module Plurimath
|
|
79
90
|
parameter_two.is_nary_function? || parameter_two.is_nary_symbol?
|
80
91
|
end
|
81
92
|
|
93
|
+
def content=(value)
|
94
|
+
if no_content_in?(Array(value))
|
95
|
+
delete_all_text
|
96
|
+
else
|
97
|
+
new_val = Array(value).map do |val|
|
98
|
+
validate_symbols(val) unless val.strip.empty?
|
99
|
+
end
|
100
|
+
validate_text_order(new_val)
|
101
|
+
end
|
102
|
+
update_temp_mathml_values(@temp_mathml_order)
|
103
|
+
end
|
104
|
+
|
82
105
|
protected
|
83
106
|
|
107
|
+
def validate_text_order(value)
|
108
|
+
@temp_mathml_order.each_with_index do |item, index|
|
109
|
+
next unless item == "text"
|
110
|
+
|
111
|
+
shifted_value = value.shift
|
112
|
+
next @temp_mathml_order[index] = shifted_value if shifted_value
|
113
|
+
|
114
|
+
@temp_mathml_order.delete_at(index)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def delete_all_text
|
119
|
+
@temp_mathml_order.delete("text")
|
120
|
+
end
|
121
|
+
|
122
|
+
def no_content_in?(value)
|
123
|
+
value.nil? ||
|
124
|
+
value.empty? ||
|
125
|
+
value&.all? { |val| val.strip.empty? }
|
126
|
+
end
|
127
|
+
|
84
128
|
def unicode_accent?(field)
|
85
129
|
return unless field.is_a?(Math::Symbols::Symbol)
|
86
130
|
|
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "../mathml/utility"
|
4
|
+
|
3
5
|
module Plurimath
|
4
6
|
module Math
|
5
7
|
class Number < Core
|
6
8
|
attr_accessor :value, :mini_sub_sized, :mini_sup_sized
|
9
|
+
include Mathml::Utility
|
7
10
|
|
8
|
-
def initialize(value, mini_sub_sized: false, mini_sup_sized: false)
|
11
|
+
def initialize(value = nil, mini_sub_sized: false, mini_sup_sized: false)
|
9
12
|
@value = value.is_a?(Parslet::Slice) ? value.to_s : value
|
10
13
|
@mini_sub_sized = mini_sub_sized if mini_sub_sized
|
11
14
|
@mini_sup_sized = mini_sup_sized if mini_sup_sized
|
@@ -18,6 +21,8 @@ module Plurimath
|
|
18
21
|
object.mini_sup_sized == mini_sup_sized
|
19
22
|
end
|
20
23
|
|
24
|
+
def element_order=(*); end
|
25
|
+
|
21
26
|
def to_asciimath(options:)
|
22
27
|
format_value_with_options(options)
|
23
28
|
end
|
@@ -71,6 +76,10 @@ module Plurimath
|
|
71
76
|
mini_sub_sized || mini_sup_sized
|
72
77
|
end
|
73
78
|
|
79
|
+
def value=(value)
|
80
|
+
@value = value.is_a?(Array) ? value.join : value
|
81
|
+
end
|
82
|
+
|
74
83
|
protected
|
75
84
|
|
76
85
|
def mini_sub
|
@@ -3,10 +3,10 @@ module Plurimath
|
|
3
3
|
module Symbols
|
4
4
|
class Gg < Symbol
|
5
5
|
INPUT = {
|
6
|
-
unicodemath: [
|
7
|
-
asciimath: [
|
6
|
+
unicodemath: ["gg", "≫", parsing_wrapper(["mgt"], lang: :unicode)],
|
7
|
+
asciimath: ["≫", "gg", "mgt"],
|
8
8
|
mathml: ["≫"],
|
9
|
-
latex: [
|
9
|
+
latex: ["gg", "≫", parsing_wrapper(["mgt"], lang: :latex)],
|
10
10
|
omml: ["≫"],
|
11
11
|
html: ["≫"],
|
12
12
|
}.freeze
|
@@ -17,7 +17,7 @@ module Plurimath
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_asciimath(**)
|
20
|
-
|
20
|
+
"gg"
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_unicodemath(**)
|
@@ -3,10 +3,10 @@ module Plurimath
|
|
3
3
|
module Symbols
|
4
4
|
class Ll < Symbol
|
5
5
|
INPUT = {
|
6
|
-
unicodemath: [
|
7
|
-
asciimath: [
|
6
|
+
unicodemath: ["ll", "≪", parsing_wrapper(["mlt"], lang: :unicode)],
|
7
|
+
asciimath: ["≪", "ll", "mlt"],
|
8
8
|
mathml: ["≪"],
|
9
|
-
latex: [
|
9
|
+
latex: ["ll", "≪", parsing_wrapper(["mlt"], lang: :latex)],
|
10
10
|
omml: ["≪"],
|
11
11
|
html: ["≪"],
|
12
12
|
}.freeze
|
@@ -17,7 +17,7 @@ module Plurimath
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_asciimath(**)
|
20
|
-
|
20
|
+
"ll"
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_unicodemath(**)
|
@@ -5,7 +5,7 @@ module Plurimath
|
|
5
5
|
INPUT = {
|
6
6
|
unicodemath: [["−", "-"], parsing_wrapper(["minus"], lang: :unicode)],
|
7
7
|
asciimath: [["-", "−"], parsing_wrapper(["minus"], lang: :asciimath)],
|
8
|
-
mathml: ["−"],
|
8
|
+
mathml: ["−", "-"],
|
9
9
|
latex: [["minus", "-", "−"]],
|
10
10
|
omml: ["−"],
|
11
11
|
html: ["−"],
|
@@ -1,9 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "../../mathml/utility"
|
4
|
+
|
3
5
|
module Plurimath
|
4
6
|
module Math
|
5
7
|
module Symbols
|
6
8
|
class Symbol < Core
|
9
|
+
include Mathml::Utility
|
10
|
+
|
7
11
|
attr_accessor :value, :slashed, :mini_sub_sized, :mini_sup_sized, :options
|
8
12
|
|
9
13
|
INPUT = {}.freeze
|
@@ -13,7 +17,7 @@ module Plurimath
|
|
13
17
|
mini_sub_sized: false,
|
14
18
|
mini_sup_sized: false,
|
15
19
|
options: {})
|
16
|
-
@value = sym.is_a?(
|
20
|
+
@value = sym.is_a?(Array) ? sym.join : sym&.to_s
|
17
21
|
@slashed = slashed if slashed
|
18
22
|
@mini_sub_sized = mini_sub_sized if mini_sub_sized
|
19
23
|
@mini_sup_sized = mini_sup_sized if mini_sup_sized
|
@@ -22,7 +26,7 @@ module Plurimath
|
|
22
26
|
|
23
27
|
def ==(object)
|
24
28
|
object.respond_to?(:value) &&
|
25
|
-
object.class ==
|
29
|
+
object.class == self.class &&
|
26
30
|
object.value == value &&
|
27
31
|
object.slashed == slashed &&
|
28
32
|
object.mini_sub_sized == mini_sub_sized &&
|
@@ -36,6 +40,10 @@ module Plurimath
|
|
36
40
|
value
|
37
41
|
end
|
38
42
|
|
43
|
+
def value=(value)
|
44
|
+
@value = value.is_a?(Array) ? value.join : value.to_s
|
45
|
+
end
|
46
|
+
|
39
47
|
def to_mathml_without_math_tag(intent, **)
|
40
48
|
if value&.include?("ⅇ")
|
41
49
|
attributes = {
|
@@ -45,7 +53,7 @@ module Plurimath
|
|
45
53
|
mi_tag = ox_element("mi", attributes: attributes)
|
46
54
|
return mi_tag if ["{:", ":}"].include?(value)
|
47
55
|
|
48
|
-
mi_tag << value
|
56
|
+
value ? mi_tag << value : mi_tag
|
49
57
|
end
|
50
58
|
|
51
59
|
def to_latex(**)
|
@@ -108,7 +116,7 @@ module Plurimath
|
|
108
116
|
self.is_a?(Math::Symbols::Ampersand)
|
109
117
|
end
|
110
118
|
|
111
|
-
def linebreak
|
119
|
+
def linebreak?
|
112
120
|
value == "\\\\"
|
113
121
|
end
|
114
122
|
|
data/lib/plurimath/math.rb
CHANGED
@@ -13,6 +13,8 @@ require_relative "math/core"
|
|
13
13
|
require_relative "math/number"
|
14
14
|
require_relative "math/symbols"
|
15
15
|
require_relative "math/formula"
|
16
|
+
require_relative "math/formula/mrow"
|
17
|
+
require_relative "math/formula/mstyle"
|
16
18
|
require_relative "math/function"
|
17
19
|
require_relative "asciimath/parser"
|
18
20
|
require_relative "unicode_math/parser"
|