plurimath 0.11.6 → 0.11.7
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/utility.rb +50 -0
- data/lib/plurimath/asciimath.rb +1 -0
- data/lib/plurimath/formatter/numbers/mathml_renderer.rb +15 -15
- data/lib/plurimath/formatter/numbers/omml_renderer.rb +19 -19
- data/lib/plurimath/html/utility.rb +18 -0
- data/lib/plurimath/html.rb +1 -0
- data/lib/plurimath/latex/utility.rb +118 -0
- data/lib/plurimath/latex.rb +1 -0
- data/lib/plurimath/math/core.rb +12 -12
- data/lib/plurimath/math/formula.rb +10 -10
- data/lib/plurimath/math/function/abs.rb +3 -3
- data/lib/plurimath/math/function/bar.rb +14 -14
- data/lib/plurimath/math/function/base.rb +15 -7
- data/lib/plurimath/math/function/binary_function.rb +7 -7
- data/lib/plurimath/math/function/cancel.rb +2 -2
- data/lib/plurimath/math/function/ceil.rb +1 -1
- data/lib/plurimath/math/function/color.rb +2 -2
- data/lib/plurimath/math/function/ddot.rb +3 -3
- data/lib/plurimath/math/function/dot.rb +8 -8
- data/lib/plurimath/math/function/fenced.rb +8 -8
- data/lib/plurimath/math/function/floor.rb +1 -1
- data/lib/plurimath/math/function/font_style/bold.rb +2 -2
- data/lib/plurimath/math/function/font_style/double_struck.rb +2 -2
- data/lib/plurimath/math/function/font_style/fraktur.rb +2 -2
- data/lib/plurimath/math/function/font_style/italic.rb +2 -2
- data/lib/plurimath/math/function/font_style/monospace.rb +2 -2
- data/lib/plurimath/math/function/font_style/normal.rb +2 -2
- data/lib/plurimath/math/function/font_style/sans-serif.rb +2 -2
- data/lib/plurimath/math/function/font_style/script.rb +2 -2
- data/lib/plurimath/math/function/font_style.rb +16 -15
- data/lib/plurimath/math/function/frac.rb +7 -7
- data/lib/plurimath/math/function/hat.rb +8 -8
- data/lib/plurimath/math/function/inf.rb +2 -2
- data/lib/plurimath/math/function/int.rb +8 -8
- data/lib/plurimath/math/function/left.rb +5 -5
- data/lib/plurimath/math/function/lim.rb +3 -3
- data/lib/plurimath/math/function/limits.rb +2 -2
- data/lib/plurimath/math/function/linebreak.rb +2 -2
- data/lib/plurimath/math/function/log.rb +10 -10
- data/lib/plurimath/math/function/longdiv.rb +1 -1
- data/lib/plurimath/math/function/menclose.rb +2 -2
- data/lib/plurimath/math/function/merror.rb +2 -2
- data/lib/plurimath/math/function/mod.rb +1 -1
- data/lib/plurimath/math/function/mpadded.rb +2 -2
- data/lib/plurimath/math/function/ms.rb +2 -2
- data/lib/plurimath/math/function/msgroup.rb +2 -2
- data/lib/plurimath/math/function/multiscript.rb +2 -2
- data/lib/plurimath/math/function/nary.rb +15 -15
- data/lib/plurimath/math/function/none.rb +1 -1
- data/lib/plurimath/math/function/norm.rb +1 -1
- data/lib/plurimath/math/function/obrace.rb +8 -8
- data/lib/plurimath/math/function/oint.rb +6 -6
- data/lib/plurimath/math/function/over.rb +5 -5
- data/lib/plurimath/math/function/overleftrightarrow.rb +7 -7
- data/lib/plurimath/math/function/overset.rb +5 -5
- data/lib/plurimath/math/function/phantom.rb +9 -9
- data/lib/plurimath/math/function/power.rb +5 -5
- data/lib/plurimath/math/function/power_base.rb +5 -5
- data/lib/plurimath/math/function/prod.rb +4 -4
- data/lib/plurimath/math/function/right.rb +5 -5
- data/lib/plurimath/math/function/root.rb +7 -7
- data/lib/plurimath/math/function/rule.rb +2 -2
- data/lib/plurimath/math/function/scarries.rb +1 -1
- data/lib/plurimath/math/function/semantics.rb +4 -4
- data/lib/plurimath/math/function/sqrt.rb +7 -7
- data/lib/plurimath/math/function/stackrel.rb +5 -5
- data/lib/plurimath/math/function/substack.rb +1 -1
- data/lib/plurimath/math/function/sum.rb +4 -4
- data/lib/plurimath/math/function/sup.rb +1 -1
- data/lib/plurimath/math/function/table/array.rb +1 -1
- data/lib/plurimath/math/function/table/bmatrix.rb +2 -2
- data/lib/plurimath/math/function/table/matrix.rb +2 -2
- data/lib/plurimath/math/function/table.rb +29 -29
- data/lib/plurimath/math/function/td.rb +3 -3
- data/lib/plurimath/math/function/ternary_function.rb +13 -13
- data/lib/plurimath/math/function/text.rb +4 -4
- data/lib/plurimath/math/function/tilde.rb +6 -6
- data/lib/plurimath/math/function/tr.rb +4 -4
- data/lib/plurimath/math/function/ubrace.rb +1 -1
- data/lib/plurimath/math/function/ul.rb +9 -9
- data/lib/plurimath/math/function/unary_function.rb +14 -14
- data/lib/plurimath/math/function/underover.rb +1 -1
- data/lib/plurimath/math/function/underset.rb +12 -12
- data/lib/plurimath/math/function/unitsml.rb +1 -1
- data/lib/plurimath/math/function/vec.rb +7 -7
- data/lib/plurimath/math/model_helper.rb +103 -0
- data/lib/plurimath/math/number.rb +2 -2
- data/lib/plurimath/math/symbols/symbol.rb +2 -2
- data/lib/plurimath/math/symbols/tilde.rb +1 -1
- data/lib/plurimath/math.rb +1 -0
- data/lib/plurimath/mathml/constants.rb +29 -155
- data/lib/plurimath/mathml/formula_transformation.rb +2 -5
- data/lib/plurimath/mathml/translator.rb +6 -0
- data/lib/plurimath/mathml/utility.rb +53 -0
- data/lib/plurimath/mathml.rb +1 -0
- data/lib/plurimath/omml/formula_transformation.rb +5 -5
- data/lib/plurimath/omml/translator.rb +8 -5
- data/lib/plurimath/omml/utility.rb +109 -0
- data/lib/plurimath/omml.rb +1 -0
- data/lib/plurimath/unicode_math/transform.rb +5 -1
- data/lib/plurimath/unicode_math/utility.rb +256 -0
- data/lib/plurimath/unicode_math.rb +1 -0
- data/lib/plurimath/utility/intent_encoding.rb +4 -4
- data/lib/plurimath/utility.rb +6 -815
- data/lib/plurimath/version.rb +1 -1
- data/lib/plurimath/xml_engine/oga/dumper.rb +8 -1
- data/lib/plurimath/xml_engine/ox_engine.rb +4 -1
- data/lib/plurimath/xml_helper.rb +47 -0
- data/lib/plurimath.rb +1 -0
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 950039d5d3676703fbcd630f86ba5331ff73c07775564b72f54e533e41052661
|
|
4
|
+
data.tar.gz: c716654e4fc2c2fde3d3148312a87a772c2137b31a4f160ade66a21c0dc18da3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e7ba8db57e105ce7c1792128b621dba6dc4519f75bdb43185edf4b3b38bc7a21a214686896ed8fa8728dd037a5f7090dd9b4efa572aba62f480d7efb9dc3dc87
|
|
7
|
+
data.tar.gz: a313a02c3e4ab7d05a7d08129b07e98ba513b4953fd703ea88491fca5a1433fe282babce59e16aeb4032597e0165d65869b1180594a88f41d99fc3fbf4442346
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Plurimath
|
|
4
|
+
class Asciimath
|
|
5
|
+
# AsciiMath-specific helpers extracted from Plurimath::Utility (code-quality
|
|
6
|
+
# refactor). Subclasses Utility so bareword `Utility.<generic>` calls inside
|
|
7
|
+
# AsciiMath files keep resolving here and inherit the generic helpers.
|
|
8
|
+
class Utility < Plurimath::Utility
|
|
9
|
+
class << self
|
|
10
|
+
def td_values(objects, slicer)
|
|
11
|
+
sliced = objects.slice_when { |object, _| symbol_value(object, slicer) }
|
|
12
|
+
tds = sliced.map do |slice|
|
|
13
|
+
Math::Function::Td.new(
|
|
14
|
+
slice.delete_if { |d| symbol_value(d, slicer) }.compact,
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
tds << Math::Function::Td.new([]) if symbol_value(objects.last, slicer)
|
|
18
|
+
tds
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def td_value(td_object)
|
|
22
|
+
str_classes = [String, Parslet::Slice]
|
|
23
|
+
if str_classes.include?(td_object.class) && td_object.to_s.empty?
|
|
24
|
+
return Math::Function::Text.new(nil)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
td_object
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def frac_values(object)
|
|
31
|
+
case object
|
|
32
|
+
when Math::Formula
|
|
33
|
+
object.value.any? { |d| symbol_value(d, ",") }
|
|
34
|
+
when Array
|
|
35
|
+
object.any? { |d| symbol_value(d, ",") }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def asciimath_symbol_object(value, lang: :asciimath)
|
|
40
|
+
return if value.nil?
|
|
41
|
+
|
|
42
|
+
symbols = symbols_hash(lang)
|
|
43
|
+
return symbols[value&.to_s].new if symbols.key?(value&.to_s)
|
|
44
|
+
|
|
45
|
+
symbol_object(value&.to_s, lang: lang)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
data/lib/plurimath/asciimath.rb
CHANGED
|
@@ -23,32 +23,32 @@ module Plurimath
|
|
|
23
23
|
return plain_element(notation) if notation.notation_style == :e
|
|
24
24
|
|
|
25
25
|
coeff = plain_element(notation.coefficient)
|
|
26
|
-
times =
|
|
27
|
-
base_el =
|
|
28
|
-
exp_el =
|
|
29
|
-
sup =
|
|
30
|
-
|
|
31
|
-
row =
|
|
32
|
-
|
|
26
|
+
times = XmlHelper.ox_element("mo") << notation.times_symbol.to_s
|
|
27
|
+
base_el = XmlHelper.ox_element("mn") << "10"
|
|
28
|
+
exp_el = XmlHelper.ox_element("mn") << notation.formatted_exponent
|
|
29
|
+
sup = XmlHelper.ox_element("msup")
|
|
30
|
+
XmlHelper.update_nodes(sup, [base_el, exp_el])
|
|
31
|
+
row = XmlHelper.ox_element("mrow")
|
|
32
|
+
XmlHelper.update_nodes(row, [coeff, times, sup])
|
|
33
33
|
row
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def render_semantic_base(formatted)
|
|
37
|
-
digits =
|
|
38
|
-
base_el =
|
|
39
|
-
sub =
|
|
40
|
-
|
|
37
|
+
digits = XmlHelper.ox_element("mn") << formatted.digits_string
|
|
38
|
+
base_el = XmlHelper.ox_element("mn") << formatted.base_notation.base.to_s
|
|
39
|
+
sub = XmlHelper.ox_element("msub")
|
|
40
|
+
XmlHelper.update_nodes(sub, [digits, base_el])
|
|
41
41
|
|
|
42
42
|
return sub unless formatted.sign_text
|
|
43
43
|
|
|
44
|
-
sign_el =
|
|
45
|
-
row =
|
|
46
|
-
|
|
44
|
+
sign_el = XmlHelper.ox_element("mo") << formatted.sign_text
|
|
45
|
+
row = XmlHelper.ox_element("mrow")
|
|
46
|
+
XmlHelper.update_nodes(row, [sign_el, sub])
|
|
47
47
|
row
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def plain_element(result)
|
|
51
|
-
|
|
51
|
+
XmlHelper.ox_element("mn") << result.to_s
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
end
|
|
@@ -22,51 +22,51 @@ module Plurimath
|
|
|
22
22
|
def render_notation(notation)
|
|
23
23
|
return plain_element(notation) if notation.notation_style == :e
|
|
24
24
|
|
|
25
|
-
sup_struct =
|
|
26
|
-
subpr =
|
|
27
|
-
subpr <<
|
|
25
|
+
sup_struct = XmlHelper.ox_element("sSup", namespace: "m")
|
|
26
|
+
subpr = XmlHelper.ox_element("sSupPr", namespace: "m")
|
|
27
|
+
subpr << XmlHelper.pr_element("ctrl", true, namespace: "m")
|
|
28
28
|
|
|
29
29
|
coeff_run = text_run(notation.coefficient.to_s)
|
|
30
30
|
times_run = text_run(" #{notation.times_symbol} ")
|
|
31
31
|
base_run = text_run("10")
|
|
32
32
|
exp_run = text_run(notation.formatted_exponent)
|
|
33
33
|
|
|
34
|
-
e_el =
|
|
35
|
-
|
|
34
|
+
e_el = XmlHelper.ox_element("e", namespace: "m")
|
|
35
|
+
XmlHelper.update_nodes(e_el, [coeff_run, times_run, base_run])
|
|
36
36
|
|
|
37
|
-
sup_el =
|
|
38
|
-
|
|
37
|
+
sup_el = XmlHelper.ox_element("sup", namespace: "m")
|
|
38
|
+
XmlHelper.update_nodes(sup_el, [exp_run])
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
XmlHelper.update_nodes(sup_struct, [subpr, e_el, sup_el])
|
|
41
41
|
sup_struct
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def render_semantic_base(formatted)
|
|
45
|
-
sub_struct =
|
|
46
|
-
subpr =
|
|
47
|
-
subpr <<
|
|
45
|
+
sub_struct = XmlHelper.ox_element("sSub", namespace: "m")
|
|
46
|
+
subpr = XmlHelper.ox_element("sSubPr", namespace: "m")
|
|
47
|
+
subpr << XmlHelper.pr_element("ctrl", true, namespace: "m")
|
|
48
48
|
|
|
49
49
|
digits_with_sign = "#{formatted.sign_text}#{formatted.digits_string}"
|
|
50
50
|
base_run = text_run(digits_with_sign)
|
|
51
51
|
sub_run = text_run(formatted.base_notation.base.to_s)
|
|
52
52
|
|
|
53
|
-
e_el =
|
|
54
|
-
|
|
53
|
+
e_el = XmlHelper.ox_element("e", namespace: "m")
|
|
54
|
+
XmlHelper.update_nodes(e_el, [base_run])
|
|
55
55
|
|
|
56
|
-
sub_el =
|
|
57
|
-
|
|
56
|
+
sub_el = XmlHelper.ox_element("sub", namespace: "m")
|
|
57
|
+
XmlHelper.update_nodes(sub_el, [sub_run])
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
XmlHelper.update_nodes(sub_struct, [subpr, e_el, sub_el])
|
|
60
60
|
sub_struct
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def plain_element(result)
|
|
64
|
-
|
|
64
|
+
XmlHelper.ox_element("t", namespace: "m") << result.to_s
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
def text_run(text)
|
|
68
|
-
run =
|
|
69
|
-
run << (
|
|
68
|
+
run = XmlHelper.ox_element("r", namespace: "m")
|
|
69
|
+
run << (XmlHelper.ox_element("t", namespace: "m") << text)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Plurimath
|
|
4
|
+
class Html
|
|
5
|
+
# Html-specific helper extracted from Plurimath::Utility (code-quality
|
|
6
|
+
# refactor). Subclasses Utility so bareword `Utility.<generic>` calls inside
|
|
7
|
+
# Html files keep resolving here and inherit the generic helpers.
|
|
8
|
+
class Utility < Plurimath::Utility
|
|
9
|
+
class << self
|
|
10
|
+
def sub_sup_method?(sub_sup)
|
|
11
|
+
if sub_sup.methods.include?(:class_name)
|
|
12
|
+
Html::Constants::SUB_SUP_CLASSES.value?(sub_sup.class_name.to_sym)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/plurimath/html.rb
CHANGED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Plurimath
|
|
4
|
+
class Latex
|
|
5
|
+
# LaTeX-specific helpers extracted from Plurimath::Utility (code-quality
|
|
6
|
+
# refactor). Subclasses Utility so bareword `Utility.<generic>` calls inside
|
|
7
|
+
# LaTeX files keep resolving here and inherit the generic helpers.
|
|
8
|
+
class Utility < Plurimath::Utility
|
|
9
|
+
class << self
|
|
10
|
+
def organize_table(array, column_align: nil, options: nil)
|
|
11
|
+
table = []
|
|
12
|
+
table_data = []
|
|
13
|
+
table_row = []
|
|
14
|
+
organize_options(array, column_align) if options
|
|
15
|
+
string_columns = column_align&.map { |column| column.is_a?(Math::Symbols::Paren) ? "|" : column.value }
|
|
16
|
+
array.each do |data|
|
|
17
|
+
if data&.separate_table
|
|
18
|
+
table_row << Math::Function::Td.new(filter_table_data(table_data).compact)
|
|
19
|
+
table_data = []
|
|
20
|
+
if data.linebreak?
|
|
21
|
+
organize_tds(table_row.flatten, string_columns.dup, options)
|
|
22
|
+
table << Math::Function::Tr.new(table_row)
|
|
23
|
+
table_row = []
|
|
24
|
+
end
|
|
25
|
+
next
|
|
26
|
+
end
|
|
27
|
+
table_data << data
|
|
28
|
+
end
|
|
29
|
+
# A trailing linebreak has already flushed its row and nothing follows
|
|
30
|
+
# it, so there is no final cell to add. An empty input has flushed
|
|
31
|
+
# nothing, and still yields its one placeholder cell.
|
|
32
|
+
flushed_by_trailing_linebreak =
|
|
33
|
+
table_data.empty? && table_row.empty? && !table.empty?
|
|
34
|
+
unless flushed_by_trailing_linebreak
|
|
35
|
+
table_row << Math::Function::Td.new(table_data.compact)
|
|
36
|
+
end
|
|
37
|
+
unless table_row.nil? || table_row.empty?
|
|
38
|
+
organize_tds(table_row.flatten, string_columns.dup, options)
|
|
39
|
+
table << Math::Function::Tr.new(table_row)
|
|
40
|
+
end
|
|
41
|
+
unless column_align.nil? || column_align.empty?
|
|
42
|
+
table_separator(string_columns, table,
|
|
43
|
+
symbol: "|")
|
|
44
|
+
end
|
|
45
|
+
table
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def organize_options(table_data, column_align)
|
|
49
|
+
return column_align if column_align.length <= 1
|
|
50
|
+
|
|
51
|
+
align = [column_align&.shift]
|
|
52
|
+
table_data.insert(0, *column_align)
|
|
53
|
+
align
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def table_options(table_data)
|
|
57
|
+
rowline = ""
|
|
58
|
+
table_data.each do |tr|
|
|
59
|
+
rowline += hline_row?(tr) ? "solid " : "none "
|
|
60
|
+
end
|
|
61
|
+
options = { rowline: rowline.strip } if rowline.include?("solid")
|
|
62
|
+
options || {}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def organize_tds(tr_array, column_align, options)
|
|
66
|
+
return tr_array if column_align.nil? || column_align.empty?
|
|
67
|
+
|
|
68
|
+
column_align.reject! { |string| string == "|" }
|
|
69
|
+
column_align = column_align * tr_array.length if options
|
|
70
|
+
tr_array.map.with_index do |td, ind|
|
|
71
|
+
columnalign = Plurimath::Utility::ALIGNMENT_LETTERS[column_align[ind]&.to_sym]
|
|
72
|
+
td.parameter_two = { columnalign: columnalign } if columnalign
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def filter_table_data(table_data)
|
|
77
|
+
table_data.each_with_index do |object, ind|
|
|
78
|
+
if object.is_a?(Math::Symbols::Minus)
|
|
79
|
+
table_data[ind] = Math::Formula.new(
|
|
80
|
+
[object, table_data.delete_at(ind.next)],
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
table_data
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def table_td(object)
|
|
88
|
+
new_object = case object
|
|
89
|
+
when Math::Function::Td
|
|
90
|
+
object
|
|
91
|
+
else
|
|
92
|
+
Math::Function::Td.new([object].compact)
|
|
93
|
+
end
|
|
94
|
+
Array(new_object)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def left_right_objects(paren, function)
|
|
98
|
+
paren = if paren.to_s.match?(/\\\{|\\\}/)
|
|
99
|
+
paren.to_s.gsub("\\", "")
|
|
100
|
+
else
|
|
101
|
+
Latex::Constants::LEFT_RIGHT_PARENTHESIS[paren.to_sym]
|
|
102
|
+
end
|
|
103
|
+
get_class(function).new(paren)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
private
|
|
107
|
+
|
|
108
|
+
# True when the row's first cell holds an Hline marker (a horizontal
|
|
109
|
+
# rule), reached through the tr -> first cell -> first content nesting.
|
|
110
|
+
def hline_row?(row)
|
|
111
|
+
first_cell = row&.parameter_one&.first
|
|
112
|
+
first_content = first_cell&.parameter_one&.first
|
|
113
|
+
first_content.is_a?(Math::Symbols::Hline)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
data/lib/plurimath/latex.rb
CHANGED
data/lib/plurimath/math/core.rb
CHANGED
|
@@ -65,7 +65,7 @@ namespace: "m")
|
|
|
65
65
|
else
|
|
66
66
|
field.insert_t_tag(display_style, options: options)
|
|
67
67
|
end
|
|
68
|
-
|
|
68
|
+
XmlHelper.update_nodes(tag, field_value)
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def validate_function_formula
|
|
@@ -103,7 +103,7 @@ namespace: "m")
|
|
|
103
103
|
|
|
104
104
|
hashed = common_math_zone_conversion(field, options)
|
|
105
105
|
options[:array] << "#{hashed[:spacing]}|_ \"#{field&.to_asciimath(options: options[:options])}\"#{hashed[:field_name]}\n"
|
|
106
|
-
return unless
|
|
106
|
+
return unless ModelHelper.validate_math_zone(field, lang: :asciimath)
|
|
107
107
|
|
|
108
108
|
options[:array] << field&.to_asciimath_math_zone(
|
|
109
109
|
hashed[:function_spacing], hashed[:last], hashed[:indent], options: options[:options]
|
|
@@ -115,7 +115,7 @@ namespace: "m")
|
|
|
115
115
|
|
|
116
116
|
hashed = common_math_zone_conversion(field, options)
|
|
117
117
|
options[:array] << "#{hashed[:spacing]}|_ \"#{field&.to_latex(options: options[:options])}\"#{hashed[:field_name]}\n"
|
|
118
|
-
return unless
|
|
118
|
+
return unless ModelHelper.validate_math_zone(field, lang: :latex)
|
|
119
119
|
|
|
120
120
|
options[:array] << field&.to_latex_math_zone(hashed[:function_spacing],
|
|
121
121
|
hashed[:last], hashed[:indent], options: options[:options])
|
|
@@ -127,8 +127,8 @@ namespace: "m")
|
|
|
127
127
|
hashed = common_math_zone_conversion(field, options)
|
|
128
128
|
options[:array] << "#{hashed[:spacing]}|_ \"#{dump_mathml(field,
|
|
129
129
|
options: options[:options])}\"#{hashed[:field_name]}\n"
|
|
130
|
-
return unless
|
|
131
|
-
|
|
130
|
+
return unless ModelHelper.validate_math_zone(field, lang: :mathml,
|
|
131
|
+
intent: options[:intent], options: options[:options])
|
|
132
132
|
|
|
133
133
|
options[:array] << field&.to_mathml_math_zone(
|
|
134
134
|
hashed[:function_spacing], hashed[:last], hashed[:indent], options: options[:options]
|
|
@@ -142,7 +142,7 @@ namespace: "m")
|
|
|
142
142
|
display_style = options[:display_style]
|
|
143
143
|
options[:array] << "#{hashed[:spacing]}|_ \"#{dump_omml(field,
|
|
144
144
|
display_style, options: options[:options])}\"#{hashed[:field_name]}\n"
|
|
145
|
-
return unless
|
|
145
|
+
return unless ModelHelper.validate_math_zone(field, lang: :omml)
|
|
146
146
|
|
|
147
147
|
options[:array] << field&.to_omml_math_zone(hashed[:function_spacing],
|
|
148
148
|
hashed[:last], hashed[:indent], display_style: display_style, options: options[:options])
|
|
@@ -153,7 +153,7 @@ namespace: "m")
|
|
|
153
153
|
|
|
154
154
|
hashed = common_math_zone_conversion(field, options)
|
|
155
155
|
options[:array] << "#{hashed[:spacing]}|_ \"#{field&.to_unicodemath(options: options[:options])}\"#{hashed[:field_name]}\n"
|
|
156
|
-
return unless
|
|
156
|
+
return unless ModelHelper.validate_math_zone(field, lang: :unicodemath)
|
|
157
157
|
|
|
158
158
|
options[:array] << field&.to_unicodemath_math_zone(
|
|
159
159
|
hashed[:function_spacing], hashed[:last], hashed[:indent], options: options[:options]
|
|
@@ -201,8 +201,8 @@ namespace: "m")
|
|
|
201
201
|
end
|
|
202
202
|
|
|
203
203
|
def filtered_values(value, lang:, options: {})
|
|
204
|
-
@values =
|
|
205
|
-
|
|
204
|
+
@values = ModelHelper.filter_math_zone_values(value, lang: lang,
|
|
205
|
+
options: options)
|
|
206
206
|
end
|
|
207
207
|
|
|
208
208
|
def dump_ox_nodes(nodes)
|
|
@@ -315,7 +315,7 @@ namespace: "m")
|
|
|
315
315
|
end
|
|
316
316
|
|
|
317
317
|
def ox_element(node, attributes: [], namespace: "")
|
|
318
|
-
|
|
318
|
+
XmlHelper.ox_element(
|
|
319
319
|
node,
|
|
320
320
|
attributes: attributes,
|
|
321
321
|
namespace: namespace,
|
|
@@ -523,10 +523,10 @@ namespace: "m")
|
|
|
523
523
|
when "mover" then tag.name = "msup"
|
|
524
524
|
end
|
|
525
525
|
elsif options_array.include?("upper_limit_as_super_script") && tag.nodes[1].name == "mrow"
|
|
526
|
-
tag =
|
|
526
|
+
tag = XmlHelper.update_nodes(
|
|
527
527
|
ox_element("munder"),
|
|
528
528
|
[
|
|
529
|
-
|
|
529
|
+
XmlHelper.update_nodes(
|
|
530
530
|
ox_element("msup"),
|
|
531
531
|
[
|
|
532
532
|
tag.nodes[0],
|
|
@@ -100,8 +100,8 @@ module Plurimath
|
|
|
100
100
|
style_attrs = { displaystyle: boolean_display_style(display_style) }
|
|
101
101
|
math = ox_element("math", attributes: math_attrs)
|
|
102
102
|
style = ox_element("mstyle", attributes: style_attrs)
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
XmlHelper.update_nodes(style, mathml_content(intent, options: options))
|
|
104
|
+
XmlHelper.update_nodes(math, [style])
|
|
105
105
|
unitsml_post_processing(math, style)
|
|
106
106
|
dump_nodes(math, indent: 2)
|
|
107
107
|
end
|
|
@@ -127,7 +127,7 @@ module Plurimath
|
|
|
127
127
|
mathml_value = mathml_content(intent, options: options)
|
|
128
128
|
attributes = intent_attribute(mathml_value) if intent
|
|
129
129
|
mrow = ox_element("mrow", attributes: attributes)
|
|
130
|
-
|
|
130
|
+
XmlHelper.update_nodes(mrow, mathml_value)
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
def mathml_content(intent, options:)
|
|
@@ -160,11 +160,11 @@ formatter: nil, unitsml: {})
|
|
|
160
160
|
objects = split_on_linebreak ? new_line_support : [self]
|
|
161
161
|
options = { formatter: formatter, unitsml: unitsml }.compact
|
|
162
162
|
options[:formula] ||= self
|
|
163
|
-
para_element =
|
|
163
|
+
para_element = XmlHelper.ox_element("oMathPara",
|
|
164
164
|
attributes: OMML_NAMESPACES, namespace: "m")
|
|
165
165
|
objects.each.with_index(1) do |object, index|
|
|
166
|
-
para_element <<
|
|
167
|
-
|
|
166
|
+
para_element << XmlHelper.update_nodes(
|
|
167
|
+
XmlHelper.ox_element("oMath", namespace: "m"),
|
|
168
168
|
object.omml_content(boolean_display_style(display_style),
|
|
169
169
|
options: options),
|
|
170
170
|
)
|
|
@@ -505,7 +505,7 @@ options:)
|
|
|
505
505
|
end
|
|
506
506
|
|
|
507
507
|
def intent_post_processing(nodes, _intent)
|
|
508
|
-
mrow =
|
|
508
|
+
mrow = XmlHelper.update_nodes(ox_element("mrow"), nodes)
|
|
509
509
|
upcase_dd_derivative(nodes) if validate_upcase_dd_derivatives?(nodes)
|
|
510
510
|
subsup_dd_derivative(nodes) if validate_subsup_dd_derivatives?(nodes)
|
|
511
511
|
partial_derivative(nodes) if valid_partial_derivative?(nodes)
|
|
@@ -624,7 +624,7 @@ options:)
|
|
|
624
624
|
node["arg"] = "f"
|
|
625
625
|
node
|
|
626
626
|
else
|
|
627
|
-
|
|
627
|
+
XmlHelper.update_nodes(
|
|
628
628
|
ox_element("mrow", attributes: { arg: "f" }),
|
|
629
629
|
nodes,
|
|
630
630
|
)
|
|
@@ -671,7 +671,7 @@ options:)
|
|
|
671
671
|
end
|
|
672
672
|
intent_name = "#{intent_names[:derivative]}(1,#{second_arg},#{third_arg})"
|
|
673
673
|
mrow = ox_element("mrow", attributes: { intent: intent_name })
|
|
674
|
-
nodes.insert(0,
|
|
674
|
+
nodes.insert(0, XmlHelper.update_nodes(mrow, mrow_nodes))
|
|
675
675
|
end
|
|
676
676
|
|
|
677
677
|
def subsup_dd_derivative(nodes)
|
|
@@ -766,7 +766,7 @@ options:)
|
|
|
766
766
|
next if node.name == "mi"
|
|
767
767
|
break if node.name == "mrow"
|
|
768
768
|
end
|
|
769
|
-
|
|
769
|
+
XmlHelper.update_nodes(mrow, row_nodes)
|
|
770
770
|
end
|
|
771
771
|
|
|
772
772
|
def numeric_encoding(node)
|
|
@@ -7,11 +7,11 @@ module Plurimath
|
|
|
7
7
|
attr_accessor :open_paren, :close_paren
|
|
8
8
|
|
|
9
9
|
def to_mathml_without_math_tag(intent, options:)
|
|
10
|
-
symbol =
|
|
10
|
+
symbol = XmlHelper.ox_element("mo") << "|"
|
|
11
11
|
first_value = mathml_value(intent, options: options)
|
|
12
12
|
first_value&.insert(0, symbol) unless open_paren
|
|
13
13
|
first_value << symbol unless close_paren
|
|
14
|
-
mrow =
|
|
14
|
+
mrow = XmlHelper.update_nodes(ox_element("mrow"), first_value)
|
|
15
15
|
intentify(mrow, intent, func_name: :abs,
|
|
16
16
|
intent_name: intent_names[:name])
|
|
17
17
|
end
|
|
@@ -52,7 +52,7 @@ module Plurimath
|
|
|
52
52
|
def md_tag
|
|
53
53
|
attribute = { "m:val": "|" }
|
|
54
54
|
sepchr_attr = { "m:val": "" }
|
|
55
|
-
mdpr =
|
|
55
|
+
mdpr = XmlHelper.pr_element("d", namespace: "m")
|
|
56
56
|
unless open_paren
|
|
57
57
|
mdpr << ox_element("begChr", namespace: "m",
|
|
58
58
|
attributes: attribute)
|
|
@@ -22,12 +22,12 @@ module Plurimath
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def to_mathml_without_math_tag(intent, options:)
|
|
25
|
-
mo_tag =
|
|
25
|
+
mo_tag = XmlHelper.ox_element("mo") << "¯"
|
|
26
26
|
return mo_tag unless parameter_one
|
|
27
27
|
|
|
28
|
-
mover_tag =
|
|
28
|
+
mover_tag = XmlHelper.ox_element("mover")
|
|
29
29
|
mover_tag.set_attr(attributes) if attributes && !attributes.empty?
|
|
30
|
-
|
|
30
|
+
XmlHelper.update_nodes(
|
|
31
31
|
mover_tag,
|
|
32
32
|
[
|
|
33
33
|
parameter_one&.to_mathml_without_math_tag(intent,
|
|
@@ -66,11 +66,11 @@ module Plurimath
|
|
|
66
66
|
protected
|
|
67
67
|
|
|
68
68
|
def acc_tag(display_style, options:)
|
|
69
|
-
acc =
|
|
70
|
-
chr =
|
|
71
|
-
|
|
72
|
-
acc_pr = (
|
|
73
|
-
|
|
69
|
+
acc = XmlHelper.ox_element("acc", namespace: "m")
|
|
70
|
+
chr = XmlHelper.ox_element("chr", namespace: "m",
|
|
71
|
+
attributes: { "m:val": "‾" })
|
|
72
|
+
acc_pr = (XmlHelper.ox_element("accPr", namespace: "m") << chr)
|
|
73
|
+
XmlHelper.update_nodes(
|
|
74
74
|
acc,
|
|
75
75
|
[
|
|
76
76
|
acc_pr,
|
|
@@ -82,8 +82,8 @@ module Plurimath
|
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
def bar_tag(display_style, options:)
|
|
85
|
-
bar =
|
|
86
|
-
|
|
85
|
+
bar = XmlHelper.ox_element("bar", namespace: "m")
|
|
86
|
+
XmlHelper.update_nodes(
|
|
87
87
|
bar,
|
|
88
88
|
[
|
|
89
89
|
bar_pr,
|
|
@@ -96,10 +96,10 @@ module Plurimath
|
|
|
96
96
|
|
|
97
97
|
def bar_pr
|
|
98
98
|
attrs = { "m:val": "top" }
|
|
99
|
-
barpr =
|
|
100
|
-
pos =
|
|
101
|
-
ctrlp =
|
|
102
|
-
|
|
99
|
+
barpr = XmlHelper.ox_element("barPr", namespace: "m")
|
|
100
|
+
pos = XmlHelper.ox_element("pos", namespace: "m", attributes: attrs)
|
|
101
|
+
ctrlp = XmlHelper.pr_element("ctrl", true, namespace: "m")
|
|
102
|
+
XmlHelper.update_nodes(barpr, [pos, ctrlp])
|
|
103
103
|
end
|
|
104
104
|
end
|
|
105
105
|
|
|
@@ -11,6 +11,14 @@ module Plurimath
|
|
|
11
11
|
first_value: "base",
|
|
12
12
|
second_value: "script",
|
|
13
13
|
}.freeze
|
|
14
|
+
# Base values whose MathML script renders as <munder> instead of <msub>.
|
|
15
|
+
MUNDER_CLASSES = %w[
|
|
16
|
+
ubrace
|
|
17
|
+
obrace
|
|
18
|
+
right
|
|
19
|
+
max
|
|
20
|
+
min
|
|
21
|
+
].freeze
|
|
14
22
|
|
|
15
23
|
def initialize(parameter_one = nil,
|
|
16
24
|
parameter_two = nil,
|
|
@@ -34,14 +42,14 @@ module Plurimath
|
|
|
34
42
|
end
|
|
35
43
|
|
|
36
44
|
def to_mathml_without_math_tag(intent, options:)
|
|
37
|
-
tag_name =
|
|
38
|
-
sub_tag =
|
|
45
|
+
tag_name = MUNDER_CLASSES.include?(parameter_one&.class_name) ? "under" : "sub"
|
|
46
|
+
sub_tag = XmlHelper.ox_element("m#{tag_name}")
|
|
39
47
|
mathml_value = []
|
|
40
48
|
mathml_value << validate_mathml_fields(parameter_one, intent,
|
|
41
49
|
options: options)
|
|
42
50
|
mathml_value << validate_mathml_fields(parameter_two, intent,
|
|
43
51
|
options: options)
|
|
44
|
-
|
|
52
|
+
XmlHelper.update_nodes(sub_tag, mathml_value)
|
|
45
53
|
end
|
|
46
54
|
|
|
47
55
|
def to_latex(options:)
|
|
@@ -58,10 +66,10 @@ module Plurimath
|
|
|
58
66
|
end
|
|
59
67
|
|
|
60
68
|
def to_omml_without_math_tag(display_style, options:)
|
|
61
|
-
ssub_element =
|
|
62
|
-
subpr_element =
|
|
63
|
-
subpr_element <<
|
|
64
|
-
|
|
69
|
+
ssub_element = XmlHelper.ox_element("sSub", namespace: "m")
|
|
70
|
+
subpr_element = XmlHelper.ox_element("sSubPr", namespace: "m")
|
|
71
|
+
subpr_element << XmlHelper.pr_element("ctrl", true, namespace: "m")
|
|
72
|
+
XmlHelper.update_nodes(
|
|
65
73
|
ssub_element,
|
|
66
74
|
[
|
|
67
75
|
subpr_element,
|