plurimath 0.2.1 → 0.2.3

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.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +13 -0
  3. data/.github/workflows/release.yml +22 -0
  4. data/.hound.yml +5 -0
  5. data/.rubocop.yml +8 -0
  6. data/AsciiMath-Supported-Data.adoc +1994 -274
  7. data/Gemfile +2 -0
  8. data/Latex-Supported-Data.adoc +1875 -1868
  9. data/MathML-Supported-Data.adoc +280 -263
  10. data/README.adoc +22 -20
  11. data/lib/plurimath/asciimath/constants.rb +187 -141
  12. data/lib/plurimath/asciimath/parse.rb +104 -39
  13. data/lib/plurimath/asciimath/parser.rb +3 -1
  14. data/lib/plurimath/asciimath/transform.rb +1074 -238
  15. data/lib/plurimath/html/parse.rb +1 -1
  16. data/lib/plurimath/latex/constants.rb +3229 -1432
  17. data/lib/plurimath/latex/parse.rb +108 -85
  18. data/lib/plurimath/latex/parser.rb +11 -4
  19. data/lib/plurimath/latex/transform.rb +354 -99
  20. data/lib/plurimath/math/base.rb +15 -0
  21. data/lib/plurimath/math/formula.rb +90 -13
  22. data/lib/plurimath/math/function/bar.rb +35 -1
  23. data/lib/plurimath/math/function/base.rb +25 -4
  24. data/lib/plurimath/math/function/binary_function.rb +101 -19
  25. data/lib/plurimath/math/function/cancel.rb +8 -0
  26. data/lib/plurimath/math/function/ceil.rb +3 -0
  27. data/lib/plurimath/math/function/color.rb +15 -5
  28. data/lib/plurimath/math/function/f.rb +8 -0
  29. data/lib/plurimath/math/function/fenced.rb +95 -8
  30. data/lib/plurimath/math/function/floor.rb +15 -0
  31. data/lib/plurimath/math/function/font_style/bold.rb +19 -0
  32. data/lib/plurimath/math/function/font_style/double_struck.rb +19 -0
  33. data/lib/plurimath/math/function/font_style/fraktur.rb +19 -0
  34. data/lib/plurimath/math/function/font_style/italic.rb +37 -0
  35. data/lib/plurimath/math/function/font_style/monospace.rb +19 -0
  36. data/lib/plurimath/math/function/font_style/normal.rb +37 -0
  37. data/lib/plurimath/math/function/font_style/sans-serif.rb +19 -0
  38. data/lib/plurimath/math/function/font_style/script.rb +19 -0
  39. data/lib/plurimath/math/function/font_style.rb +18 -5
  40. data/lib/plurimath/math/function/frac.rb +33 -3
  41. data/lib/plurimath/math/function/g.rb +7 -0
  42. data/lib/plurimath/math/function/hat.rb +12 -0
  43. data/lib/plurimath/math/function/inf.rb +21 -0
  44. data/lib/plurimath/math/function/int.rb +23 -2
  45. data/lib/plurimath/math/function/left.rb +25 -1
  46. data/lib/plurimath/math/function/lim.rb +40 -2
  47. data/lib/plurimath/math/function/limits.rb +9 -0
  48. data/lib/plurimath/math/function/log.rb +55 -4
  49. data/lib/plurimath/math/function/longdiv.rb +12 -0
  50. data/lib/plurimath/math/function/mbox.rb +31 -0
  51. data/lib/plurimath/math/function/menclose.rb +46 -0
  52. data/lib/plurimath/math/function/merror.rb +12 -0
  53. data/lib/plurimath/math/function/mod.rb +19 -4
  54. data/lib/plurimath/math/function/msgroup.rb +37 -0
  55. data/lib/plurimath/math/function/msline.rb +12 -0
  56. data/lib/plurimath/math/function/multiscript.rb +19 -0
  57. data/lib/plurimath/math/function/norm.rb +17 -1
  58. data/lib/plurimath/math/function/obrace.rb +17 -0
  59. data/lib/plurimath/math/function/oint.rb +2 -2
  60. data/lib/plurimath/math/function/over.rb +12 -5
  61. data/lib/plurimath/math/function/overset.rb +34 -5
  62. data/lib/plurimath/math/function/phantom.rb +28 -0
  63. data/lib/plurimath/math/function/power.rb +27 -9
  64. data/lib/plurimath/math/function/power_base.rb +109 -11
  65. data/lib/plurimath/math/function/prod.rb +25 -4
  66. data/lib/plurimath/math/function/right.rb +22 -2
  67. data/lib/plurimath/math/function/root.rb +23 -1
  68. data/lib/plurimath/math/function/rule.rb +33 -0
  69. data/lib/plurimath/math/function/scarries.rb +12 -0
  70. data/lib/plurimath/math/function/scarry.rb +12 -0
  71. data/lib/plurimath/math/function/sqrt.rb +23 -1
  72. data/lib/plurimath/math/function/stackrel.rb +27 -0
  73. data/lib/plurimath/math/function/substack.rb +7 -0
  74. data/lib/plurimath/math/function/sum.rb +50 -2
  75. data/lib/plurimath/math/function/sup.rb +3 -0
  76. data/lib/plurimath/math/function/table/align.rb +5 -5
  77. data/lib/plurimath/math/function/table/array.rb +25 -6
  78. data/lib/plurimath/math/function/table/bmatrix.rb +18 -7
  79. data/lib/plurimath/math/function/table/matrix.rb +13 -5
  80. data/lib/plurimath/math/function/table/multline.rb +5 -5
  81. data/lib/plurimath/math/function/table/pmatrix.rb +5 -5
  82. data/lib/plurimath/math/function/table/split.rb +5 -5
  83. data/lib/plurimath/math/function/table/vmatrix.rb +5 -6
  84. data/lib/plurimath/math/function/table.rb +185 -27
  85. data/lib/plurimath/math/function/td.rb +22 -9
  86. data/lib/plurimath/math/function/ternary_function.rb +74 -9
  87. data/lib/plurimath/math/function/text.rb +36 -11
  88. data/lib/plurimath/math/function/tr.rb +23 -4
  89. data/lib/plurimath/math/function/ubrace.rb +17 -0
  90. data/lib/plurimath/math/function/ul.rb +29 -0
  91. data/lib/plurimath/math/function/unary_function.rb +81 -8
  92. data/lib/plurimath/math/function/underline.rb +12 -0
  93. data/lib/plurimath/math/function/underover.rb +107 -0
  94. data/lib/plurimath/math/function/underset.rb +39 -0
  95. data/lib/plurimath/math/function/vec.rb +7 -1
  96. data/lib/plurimath/math/number.rb +5 -5
  97. data/lib/plurimath/math/symbol.rb +51 -12
  98. data/lib/plurimath/math/unicode.rb +11 -0
  99. data/lib/plurimath/math.rb +7 -3
  100. data/lib/plurimath/mathml/constants.rb +224 -147
  101. data/lib/plurimath/mathml/parser.rb +24 -8
  102. data/lib/plurimath/mathml/transform.rb +249 -153
  103. data/lib/plurimath/omml/parser.rb +24 -4
  104. data/lib/plurimath/omml/transform.rb +219 -157
  105. data/lib/plurimath/utility.rb +342 -20
  106. data/lib/plurimath/version.rb +1 -1
  107. metadata +21 -6
  108. data/.github/workflows/test.yml +0 -33
  109. data/lib/plurimath/mathml/parse.rb +0 -68
  110. data/lib/plurimath/omml/constants.rb +0 -154
@@ -6,6 +6,33 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Stackrel < BinaryFunction
9
+ def to_asciimath
10
+ first_value = wrapped(parameter_one)
11
+ second_value = wrapped(parameter_two)
12
+ "#{class_name}#{first_value}#{second_value}"
13
+ end
14
+
15
+ def to_mathml_without_math_tag
16
+ mover = Utility.ox_element("mover")
17
+ first_value = Utility.ox_element("mrow")
18
+ first_value << parameter_one.to_mathml_without_math_tag if parameter_one
19
+ second_value = Utility.ox_element("mrow")
20
+ second_value << parameter_two.to_mathml_without_math_tag if parameter_two
21
+ Utility.update_nodes(mover, [second_value, first_value])
22
+ end
23
+
24
+ def to_html
25
+ first_value = parameter_one&.to_html
26
+ second_value = parameter_two&.to_html
27
+ "#{first_value}#{second_value}"
28
+ end
29
+
30
+ protected
31
+
32
+ def wrapped(field)
33
+ string = field&.to_asciimath || ""
34
+ string.start_with?("(") ? string : "(#{string})"
35
+ end
9
36
  end
10
37
  end
11
38
  end
@@ -11,6 +11,13 @@ module Plurimath
11
11
  second_value = "\\\\#{parameter_two.to_latex}" if parameter_two
12
12
  "\\#{class_name}{#{first_value}#{second_value}}"
13
13
  end
14
+
15
+ def to_mathml_without_math_tag
16
+ value_array = []
17
+ value_array << parameter_one.to_mathml_without_math_tag if parameter_one
18
+ value_array << parameter_two.to_mathml_without_math_tag if parameter_two
19
+ Utility.update_nodes(Utility.ox_element("mtable"), value_array)
20
+ end
14
21
  end
15
22
  end
16
23
  end
@@ -7,8 +7,8 @@ module Plurimath
7
7
  module Function
8
8
  class Sum < BinaryFunction
9
9
  def to_asciimath
10
- first_value = "_(#{parameter_one.to_asciimath})" if parameter_one
11
- second_value = "^(#{parameter_two.to_asciimath})" if parameter_two
10
+ first_value = "_#{wrapped(parameter_one)}" if parameter_one
11
+ second_value = "^#{wrapped(parameter_two)}" if parameter_two
12
12
  "sum#{first_value}#{second_value}"
13
13
  end
14
14
 
@@ -18,11 +18,59 @@ module Plurimath
18
18
  "\\sum#{first_value}#{second_value}"
19
19
  end
20
20
 
21
+ def to_mathml_without_math_tag
22
+ first_value = Utility.ox_element("mo") << invert_unicode_symbols.to_s
23
+ if parameter_one || parameter_two
24
+ value_array = []
25
+ value_array << parameter_one&.to_mathml_without_math_tag
26
+ value_array << parameter_two&.to_mathml_without_math_tag
27
+ tag_name = if parameter_two && parameter_one
28
+ "underover"
29
+ else
30
+ parameter_one ? "under" : "over"
31
+ end
32
+ munderover_tag = Utility.ox_element("m#{tag_name}")
33
+ Utility.update_nodes(
34
+ munderover_tag,
35
+ value_array.insert(0, first_value),
36
+ )
37
+ else
38
+ first_value
39
+ end
40
+ end
41
+
21
42
  def to_html
22
43
  first_value = "<sub>#{parameter_one.to_html}</sub>" if parameter_one
23
44
  second_value = "<sup>#{parameter_two.to_html}</sup>" if parameter_two
24
45
  "<i>&sum;</i>#{first_value}#{second_value}"
25
46
  end
47
+
48
+ def to_omml_without_math_tag
49
+ limupp = Utility.ox_element("limLow", namespace: "m")
50
+ limupppr = Utility.ox_element("limUppPr", namespace: "m")
51
+ sum << Utility.pr_element("e", true, namespace: "m")
52
+ me = (Utility.ox_element("e", namespace: "m") << omml_first_value)
53
+ lim = (Utility.ox_element("lim", namespace: "m") << omml_second_value)
54
+ Utility.update_nodes(limupp, [limupppr, me, lim])
55
+ end
56
+
57
+ protected
58
+
59
+ def omml_first_value
60
+ return parameter_one.to_omml_without_math_tag unless parameter_one.is_a?(Math::Symbol)
61
+
62
+ mt = Utility.ox_element("t", namespace: "m")
63
+ mt << parameter_one.to_omml_without_math_tag if parameter_one
64
+ mt
65
+ end
66
+
67
+ def omml_second_value
68
+ return parameter_two.to_omml_without_math_tag unless parameter_two.is_a?(Math::Symbol)
69
+
70
+ mt = Utility.ox_element("t", namespace: "m")
71
+ mt << parameter_two.to_omml_without_math_tag if parameter_two
72
+ mt
73
+ end
26
74
  end
27
75
  end
28
76
  end
@@ -6,6 +6,9 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Sup < UnaryFunction
9
+ def to_mathml_without_math_tag
10
+ Utility.ox_element("mo") << "sup"
11
+ end
9
12
  end
10
13
  end
11
14
  end
@@ -7,15 +7,15 @@ module Plurimath
7
7
  module Function
8
8
  class Table
9
9
  class Align < Table
10
- def initialize(parameter_one,
11
- parameter_two = "[",
12
- parameter_three = "]")
10
+ def initialize(value,
11
+ open_paren = "[",
12
+ close_paren = "]",
13
+ options = {})
13
14
  super
14
15
  end
15
16
 
16
17
  def to_latex
17
- first_value = parameter_one&.map(&:to_latex)&.join("\\\\")
18
- "\\begin{align}#{first_value}\\end{align}"
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
19
  end
20
20
  end
21
21
  end
@@ -7,16 +7,35 @@ module Plurimath
7
7
  module Function
8
8
  class Table
9
9
  class Array < Table
10
- def initialize(parameter_one = [],
11
- parameter_two = "[",
12
- parameter_three = "]")
10
+ def initialize(value = [],
11
+ open_paren = "[",
12
+ close_paren = "]",
13
+ options = {})
13
14
  super
14
15
  end
15
16
 
16
17
  def to_latex
17
- divider = "{#{parameter_three.map(&:to_latex).join}}"
18
- first_value = parameter_one&.map(&:to_latex)&.join("\\\\")
19
- "\\begin{array}#{divider}#{first_value}\\end{array}"
18
+ "\\begin{array}#{array_args}#{latex_content}\\end{array}"
19
+ end
20
+
21
+ def array_args
22
+ args = []
23
+ value.first.parameter_one.each do |td|
24
+ args << if Utility.symbol_value(td.parameter_one.first, "|")
25
+ "|"
26
+ else
27
+ Utility::ALIGNMENT_LETTERS.invert[Hash(td.parameter_two)[:columnalign]]&.to_s
28
+ end
29
+ end
30
+ "{#{args.join}}" unless args.compact.empty?
31
+ end
32
+
33
+ def to_mathml_without_math_tag
34
+ table_tag = Utility.ox_element("mtable", attributes: table_attribute)
35
+ Utility.update_nodes(
36
+ table_tag,
37
+ value&.map(&:to_mathml_without_math_tag),
38
+ )
20
39
  end
21
40
  end
22
41
  end
@@ -7,17 +7,28 @@ module Plurimath
7
7
  module Function
8
8
  class Table
9
9
  class Bmatrix < Table
10
- def initialize(parameter_one,
11
- parameter_two = "[",
12
- parameter_three = "]")
10
+ def initialize(value,
11
+ open_paren = "[",
12
+ close_paren = "]",
13
+ options = {})
13
14
  super
14
15
  end
15
16
 
16
17
  def to_latex
17
- first_value = parameter_one&.map(&:to_latex)&.join("\\\\")
18
- matrices = Latex::Constants::MATRICES.invert
19
- environment = matrices[parameter_two].to_s
20
- "\\begin{#{environment}}#{first_value}\\end{#{environment}}"
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
+ end
20
+
21
+ def to_mathml_without_math_tag
22
+ table_tag = Utility.ox_element("mtable", attributes: table_attribute)
23
+ Utility.update_nodes(
24
+ table_tag,
25
+ value&.map(&:to_mathml_without_math_tag),
26
+ )
27
+ attributes = {
28
+ open: mathml_parenthesis(open_paren),
29
+ close: mathml_parenthesis(close_paren),
30
+ }
31
+ Utility.ox_element("mfenced", attributes: attributes) << table_tag
21
32
  end
22
33
  end
23
34
  end
@@ -7,15 +7,23 @@ module Plurimath
7
7
  module Function
8
8
  class Table
9
9
  class Matrix < Table
10
- def initialize(parameter_one = [],
11
- parameter_two = "(",
12
- parameter_three = ")")
10
+ def initialize(value = [],
11
+ open_paren = "(",
12
+ close_paren = ")",
13
+ options = {})
13
14
  super
14
15
  end
15
16
 
16
17
  def to_latex
17
- first_value = parameter_one&.map(&:to_latex)&.join("\\\\")
18
- "\\begin{matrix}#{first_value}\\end{matrix}"
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
+ end
20
+
21
+ def to_mathml_without_math_tag
22
+ table_tag = Utility.ox_element("mtable", attributes: table_attribute)
23
+ Utility.update_nodes(
24
+ table_tag,
25
+ value&.map(&:to_mathml_without_math_tag),
26
+ )
19
27
  end
20
28
  end
21
29
  end
@@ -7,15 +7,15 @@ module Plurimath
7
7
  module Function
8
8
  class Table
9
9
  class Multline < Table
10
- def initialize(parameter_one,
11
- parameter_two = "[",
12
- parameter_three = "]")
10
+ def initialize(value,
11
+ open_paren = "[",
12
+ close_paren = "]",
13
+ options = {})
13
14
  super
14
15
  end
15
16
 
16
17
  def to_latex
17
- first_value = parameter_one&.map(&:to_latex)&.join("\\\\")
18
- "\\begin{multline}#{first_value}\\end{multline}"
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
19
  end
20
20
  end
21
21
  end
@@ -7,15 +7,15 @@ module Plurimath
7
7
  module Function
8
8
  class Table
9
9
  class Pmatrix < Table
10
- def initialize(parameter_one,
11
- parameter_two = "(",
12
- parameter_three = ")")
10
+ def initialize(value,
11
+ open_paren = "(",
12
+ close_paren = ")",
13
+ options = {})
13
14
  super
14
15
  end
15
16
 
16
17
  def to_latex
17
- first_value = parameter_one&.map(&:to_latex)&.join("\\\\")
18
- "\\begin{pmatrix}#{first_value}\\end{pmatrix}"
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
19
  end
20
20
  end
21
21
  end
@@ -7,15 +7,15 @@ module Plurimath
7
7
  module Function
8
8
  class Table
9
9
  class Split < Table
10
- def initialize(parameter_one,
11
- parameter_two = "[",
12
- parameter_three = "]")
10
+ def initialize(value,
11
+ open_paren = "[",
12
+ close_paren = "]",
13
+ options = {})
13
14
  super
14
15
  end
15
16
 
16
17
  def to_latex
17
- first_value = parameter_one&.map(&:to_latex)&.join("\\\\")
18
- "\\begin{split}#{first_value}\\end{split}"
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
19
19
  end
20
20
  end
21
21
  end
@@ -7,16 +7,15 @@ module Plurimath
7
7
  module Function
8
8
  class Table
9
9
  class Vmatrix < Table
10
- def initialize(parameter_one,
11
- parameter_two = "|",
12
- parameter_three = "|")
13
- parameter_three = nil if parameter_two == "norm["
10
+ def initialize(value,
11
+ open_paren = "|",
12
+ close_paren = "|",
13
+ options = {})
14
14
  super
15
15
  end
16
16
 
17
17
  def to_latex
18
- first_value = parameter_one&.map(&:to_latex)&.join("\\\\")
19
- "\\begin{vmatrix}#{first_value}\\end{vmatrix}"
18
+ "\\begin#{opening}#{latex_content}\\end#{matrix_class}"
20
19
  end
21
20
  end
22
21
  end
@@ -5,49 +5,207 @@ require_relative "ternary_function"
5
5
  module Plurimath
6
6
  module Math
7
7
  module Function
8
- class Table < TernaryFunction
9
- def initialize(parameter_one = nil,
10
- parameter_two = nil,
11
- parameter_three = nil)
12
- super
8
+ class Table
9
+ attr_accessor :value, :open_paren, :close_paren, :options
10
+
11
+ def initialize(value = nil,
12
+ open_paren = nil,
13
+ close_paren = nil,
14
+ options = {})
15
+ @value = value
16
+ @open_paren = open_paren
17
+ @close_paren = close_paren
18
+ @options = options
19
+ end
20
+
21
+ def ==(object)
22
+ object.class == self.class &&
23
+ object.value == value &&
24
+ object.options == options &&
25
+ object.open_paren == open_paren &&
26
+ object.close_paren == close_paren
13
27
  end
14
28
 
15
29
  def to_asciimath
16
- first_value = parameter_one.map(&:to_asciimath).join(",")
17
- second_value = parameter_two.nil? ? "[" : parameter_two
18
- third_value = parameter_three.nil? ? "]" : parameter_three
19
- "#{second_value}#{first_value}#{third_value}"
30
+ parenthesis = Asciimath::Constants::TABLE_PARENTHESIS
31
+ first_value = value.map(&:to_asciimath).join(", ")
32
+ third_value = close_paren.is_a?(::Array) || close_paren.nil?
33
+ lparen = open_paren.nil? ? "[" : open_paren
34
+ rparen = third_value ? parenthesis[lparen.to_sym] : close_paren
35
+ "#{lparen}#{first_value}#{rparen}"
20
36
  end
21
37
 
22
38
  def to_mathml_without_math_tag
23
- table_value = parameter_one.map(&:to_mathml_without_math_tag).join
24
- parenthesis = Latex::Constants::PARENTHESIS
25
- if parenthesis.key?(parameter_two) || parameter_two == "|"
26
- "<mfenced open='#{parameter_two}' close='#{parameter_three}'>"\
27
- "<mtable>#{table_value}</mtable></mfenced>"
28
- elsif parameter_two == "norm["
29
- "<mo>&#x2225;</mo>#{table_value}<mo>&#x2225;</mo>"
30
- else
31
- "<mtable>#{table_value}</mtable>"
39
+ table_tag = Utility.ox_element("mtable", attributes: table_attribute)
40
+ Utility.update_nodes(
41
+ table_tag,
42
+ value&.map(&:to_mathml_without_math_tag),
43
+ )
44
+ return norm_table(table_tag) if open_paren == "norm["
45
+
46
+ if present?(open_paren) || present?(close_paren)
47
+ first_paren = Utility.ox_element("mo") << mathml_parenthesis(open_paren)
48
+ second_paren = Utility.ox_element("mo") << mathml_parenthesis(close_paren)
49
+ mrow_tag = Utility.ox_element("mrow")
50
+ return Utility.update_nodes(mrow_tag, [first_paren, table_tag, second_paren])
32
51
  end
52
+
53
+ table_tag
33
54
  end
34
55
 
35
56
  def to_latex
36
- first_value = parameter_one&.map(&:to_latex)&.join("\\\\")
37
- environment = latex_environment
38
- "\\begin{#{environment}}#{first_value}\\end{#{environment}}"
39
- end
57
+ if open_paren == "norm["
58
+ return "\\begin{Vmatrix}#{latex_content}\\end{Vmatrix}"
59
+ end
40
60
 
41
- def latex_environment
42
- matrices_hash = Latex::Constants::MATRICES
43
- matric_value = matrices_hash.value?(parameter_two)
44
- matrices_hash.invert[parameter_two] if matric_value
61
+ separator = "{#{table_attribute(:latex)}}" if environment&.include?("array")
62
+ left_paren = latex_parenthesis(open_paren) || "."
63
+ right_paren = latex_parenthesis(close_paren) || "."
64
+ left = "\\left #{left_paren}\\begin{matrix}"
65
+ right = "\\end{matrix}\\right #{right_paren}"
66
+ "#{left}#{separator}#{latex_content}#{right}"
45
67
  end
46
68
 
47
69
  def to_html
48
- first_value = parameter_one.map(&:to_html).join
70
+ first_value = value.map(&:to_html).join
49
71
  "<table>#{first_value}</table>"
50
72
  end
73
+
74
+ def to_omml_without_math_tag
75
+ if value.map { |d| d.parameter_one.length == 1 }.all?
76
+ single_td_table
77
+ else
78
+ multiple_td_table
79
+ end
80
+ end
81
+
82
+ def class_name
83
+ self.class.name.split("::").last.downcase
84
+ end
85
+
86
+ protected
87
+
88
+ def present?(field)
89
+ !(field.nil? || field.empty?)
90
+ end
91
+
92
+ def mathml_parenthesis(field)
93
+ return "" if field&.include?(":")
94
+
95
+ present?(field) ? field : ""
96
+ end
97
+
98
+ def latex_parenthesis(field)
99
+ return " ." if field&.include?(":")
100
+
101
+ return "\\#{field}" if ["{", "}"].include?(field)
102
+
103
+ field
104
+ end
105
+
106
+ def table_attribute(type = :mathml)
107
+ column_string = column_lines
108
+ case type
109
+ when :mathml
110
+ mathml_attrs(column_string)
111
+ when :latex
112
+ column_string.insert(0, "none") if column_string.include?("solid")
113
+ column_string&.map { |d| d == "solid" ? "|" : "a" }&.join
114
+ end
115
+ end
116
+
117
+ def column_lines
118
+ columns_array = []
119
+ value.first.parameter_one.each_with_index do |td, i|
120
+ if td.parameter_one.find { |obj| Utility.symbol_value(obj, "|") }
121
+ columns_array.empty? ? columns_array = ["solid"] : columns_array[i - 1] = "solid"
122
+ else
123
+ columns_array << "none"
124
+ end
125
+ end
126
+ columns_array
127
+ end
128
+
129
+ def mathml_attrs(column_strings)
130
+ args = options&.dup&.reject { |arg| arg.to_s == "asterisk" }
131
+ args[:columnlines] = column_strings.join(" ") if column_strings.include?("solid")
132
+ args
133
+ end
134
+
135
+ def latex_content
136
+ value&.map(&:to_latex)&.join(" \\\\ ")
137
+ end
138
+
139
+ def matrix_class
140
+ matrix = if open_paren
141
+ Latex::Constants::MATRICES.invert[open_paren]
142
+ else
143
+ class_name
144
+ end
145
+ options&.key?(:asterisk) ? "{#{matrix}*}" : "{#{matrix}}"
146
+ end
147
+
148
+ def opening
149
+ "#{matrix_class}#{latex_columnalign}"
150
+ end
151
+
152
+ def latex_columnalign
153
+ return "" unless Hash(options)[:asterisk]
154
+
155
+ columnalign = Hash(value&.first&.parameter_one&.first&.parameter_two)[:columnalign]
156
+ "[#{Utility::ALIGNMENT_LETTERS.invert[columnalign]}]"
157
+ end
158
+
159
+ def environment
160
+ matrices_hash = Latex::Constants::MATRICES
161
+ matric_value = matrices_hash.value?(open_paren)
162
+ matrices_hash.invert[open_paren].to_s if matric_value
163
+ end
164
+
165
+ def single_td_table
166
+ eqarr = Utility.ox_element("eqArr", namespace: "m")
167
+ eqarrpr = Utility.ox_element("eqArrPr", namespace: "m")
168
+ eqarrpr << Utility.pr_element("ctrl", true, namespace: "m")
169
+ eqarr << eqarrpr
170
+ tr_value = value.map(&:to_omml_without_math_tag).flatten
171
+ Utility.update_nodes(eqarr, tr_value.compact)
172
+ end
173
+
174
+ def multiple_td_table
175
+ count = { "m:val": value&.first&.parameter_one&.count }
176
+ mcjc = { "m:val": "center" }
177
+ mm = Utility.ox_element("m", namespace: "m")
178
+ mpr = Utility.ox_element("mpr", namespace: "m")
179
+ mcs = Utility.ox_element("mcs", namespace: "m")
180
+ mc = Utility.ox_element("mc", namespace: "m")
181
+ mcpr = Utility.ox_element("mcPr", namespace: "m")
182
+ mcount = Utility.ox_element(
183
+ "count",
184
+ namespace: "m",
185
+ attributes: count,
186
+ )
187
+ mcjc = Utility.ox_element(
188
+ "mcJc",
189
+ namespace: "m",
190
+ attributes: mcjc,
191
+ )
192
+ ctrlpr = Utility.pr_element("ctrl", true, namespace: "m")
193
+ Utility.update_nodes(mcpr, [mcount, mcjc])
194
+ mc << mcpr
195
+ mcs << mc
196
+ mpr << mcs
197
+ mpr << ctrlpr
198
+ mm_value = value&.map(&:to_omml_without_math_tag)
199
+ Utility.update_nodes(mm, mm_value.insert(0, mpr).flatten)
200
+ end
201
+
202
+ def norm_table(table_tag)
203
+ mo_tag = Utility.ox_element("mo") << "&#x2225;"
204
+ Utility.update_nodes(
205
+ Utility.ox_element("mrow"),
206
+ [mo_tag, table_tag, mo_tag],
207
+ )
208
+ end
51
209
  end
52
210
  end
53
211
  end
@@ -1,31 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "unary_function"
3
+ require_relative "binary_function"
4
4
 
5
5
  module Plurimath
6
6
  module Math
7
7
  module Function
8
- class Td < UnaryFunction
8
+ class Td < BinaryFunction
9
9
  def to_asciimath
10
- if parameter_one.length > 1
11
- "[#{parameter_one.map(&:to_asciimath).join(',')}]"
12
- else
13
- parameter_one.map(&:to_asciimath).join(",")
14
- end
10
+ parameter_one.map(&:to_asciimath).join(" ")
15
11
  end
16
12
 
17
13
  def to_mathml_without_math_tag
18
- "<mtd>#{parameter_one.map(&:to_mathml_without_math_tag).join}</mtd>"
14
+ return "" if Utility.symbol_value(parameter_one.first, "|")
15
+
16
+ td_attribute = parameter_two if parameter_two&.any?
17
+
18
+ Utility.update_nodes(
19
+ Utility.ox_element("mtd", attributes: td_attribute),
20
+ parameter_one.map(&:to_mathml_without_math_tag),
21
+ )
19
22
  end
20
23
 
21
24
  def to_latex
22
- parameter_one.map(&:to_latex).join
25
+ return "" if Utility.symbol_value(parameter_one.first, "|")
26
+
27
+ parameter_one.map(&:to_latex).join(" ")
23
28
  end
24
29
 
25
30
  def to_html
26
31
  first_value = parameter_one.map(&:to_html).join
27
32
  "<td>#{first_value}</td>"
28
33
  end
34
+
35
+ def to_omml_without_math_tag
36
+ me = Utility.ox_element("e", namespace: "m")
37
+ Utility.update_nodes(
38
+ me,
39
+ parameter_one&.map(&:to_omml_without_math_tag),
40
+ )
41
+ end
29
42
  end
30
43
  end
31
44
  end