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
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ module Math
5
+ class Base
6
+ def initialize(field)
7
+ field.is_a?(Parslet::Slice) ? field.to_s : field
8
+ end
9
+
10
+ def class_name
11
+ self.class.name.split("::").last.downcase
12
+ end
13
+ end
14
+ end
15
+ end
@@ -14,37 +14,114 @@ module Plurimath
14
14
  end
15
15
 
16
16
  def to_asciimath
17
- value.map(&:to_asciimath).join
17
+ value.map(&:to_asciimath).join(" ")
18
18
  end
19
19
 
20
20
  def to_mathml
21
- <<~MATHML
22
- <math xmlns='http://www.w3.org/1998/Math/MathML' display='block'>
23
- <mstyle displaystyle='true'>
24
- #{mathml_content}
25
- </mstyle>
26
- </math>
27
- MATHML
21
+ math_attrs = {
22
+ xmlns: "http://www.w3.org/1998/Math/MathML",
23
+ display: "block",
24
+ }
25
+ style_attrs = { displaystyle: "true" }
26
+ math = Utility.ox_element("math", attributes: math_attrs)
27
+ style = Utility.ox_element("mstyle", attributes: style_attrs)
28
+ Utility.update_nodes(style, mathml_content)
29
+ Utility.update_nodes(math, [style])
30
+ Ox.dump(math, indent: 2).gsub("&amp;", "&")
28
31
  end
29
32
 
30
33
  def to_mathml_without_math_tag
31
- "<mrow>#{mathml_content}</mrow>"
34
+ Utility.update_nodes(
35
+ Utility.ox_element("mrow"),
36
+ mathml_content,
37
+ )
32
38
  end
33
39
 
34
40
  def mathml_content
35
- value.map(&:to_mathml_without_math_tag).join
41
+ value.map(&:to_mathml_without_math_tag)
36
42
  end
37
43
 
38
44
  def to_latex
39
- value.map(&:to_latex).join
45
+ value.map(&:to_latex).join(" ")
40
46
  end
41
47
 
42
48
  def to_html
43
- value.map(&:to_html).join
49
+ value.map(&:to_html).join(" ")
50
+ end
51
+
52
+ def omml_math_attrs
53
+ {
54
+ "xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math",
55
+ "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
56
+ "xmlns:mo": "http://schemas.microsoft.com/office/mac/office/2008/main",
57
+ "xmlns:mv": "urn:schemas-microsoft-com:mac:vml",
58
+ "xmlns:o": "urn:schemas-microsoft-com:office:office",
59
+ "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
60
+ "xmlns:v": "urn:schemas-microsoft-com:vml",
61
+ "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
62
+ "xmlns:w10": "urn:schemas-microsoft-com:office:word",
63
+ "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
64
+ "xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml",
65
+ "xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml",
66
+ "xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
67
+ "xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",
68
+ "xmlns:wpc": "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
69
+ "xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
70
+ "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
71
+ "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
72
+ }
73
+ end
74
+
75
+ def to_omml
76
+ para_element = Utility.ox_element(
77
+ "oMathPara",
78
+ attributes: omml_math_attrs,
79
+ namespace: "m",
80
+ )
81
+ math_element = Utility.ox_element("oMath", namespace: "m")
82
+ Utility.update_nodes(math_element, omml_content)
83
+ para_element << math_element
84
+ Ox.dump(para_element, indent: 2).gsub("&amp;", "&")
85
+ end
86
+
87
+ def omml_content
88
+ value.map do |object|
89
+ if object.is_a?(Symbol)
90
+ mt = Utility.ox_element("t", namespace: "m")
91
+ mt << object.value
92
+ else
93
+ object.to_omml_without_math_tag
94
+ end
95
+ end
96
+ end
97
+
98
+ def to_omml_without_math_tag
99
+ if value.length == 2 && ["underover", "powerbase"].include?(
100
+ value&.first&.class_name,
101
+ )
102
+ nary_tag
103
+ else
104
+ r_element = Utility.ox_element("r", namespace: "m")
105
+ r_element << Utility.rpr_element if ["symbol", "number", "text"].include?(value&.first&.class_name)
106
+ Utility.update_nodes(r_element, omml_content)
107
+ end
108
+ end
109
+
110
+ def nary_tag
111
+ nary_tag = Utility.ox_element("nary", namespace: "m")
112
+ e_tag = Utility.ox_element("e", namespace: "m")
113
+ e_tag << value&.last&.to_omml_without_math_tag
114
+ Utility.update_nodes(
115
+ nary_tag,
116
+ [
117
+ value.first.omml_nary_tag,
118
+ e_tag,
119
+ ].flatten.compact,
120
+ )
44
121
  end
45
122
 
46
123
  def class_name
47
- "formula"
124
+ self.class.name.split("::").last.downcase
48
125
  end
49
126
  end
50
127
  end
@@ -8,7 +8,41 @@ module Plurimath
8
8
  class Bar < UnaryFunction
9
9
  def to_latex
10
10
  first_value = "{#{parameter_one.to_latex}}" if parameter_one
11
- "\\bar#{first_value}"
11
+ "\\overline#{first_value}"
12
+ end
13
+
14
+ def to_mathml_without_math_tag
15
+ first_value = parameter_one&.to_mathml_without_math_tag
16
+ Utility.update_nodes(
17
+ Utility.ox_element("mover"),
18
+ [
19
+ first_value,
20
+ Utility.ox_element("mo") << "&#xaf;",
21
+ ],
22
+ )
23
+ end
24
+
25
+ def to_omml_without_math_tag
26
+ bar = Utility.ox_element("bar", namespace: "m")
27
+ me = Utility.ox_element("e", namespace: "m")
28
+ me << parameter_one.to_omml_without_math_tag if parameter_one
29
+ Utility.update_nodes(
30
+ bar,
31
+ [
32
+ bar_pr,
33
+ me,
34
+ ],
35
+ )
36
+ end
37
+
38
+ protected
39
+
40
+ def bar_pr
41
+ attrs = { "m:val": "top" }
42
+ barpr = Utility.ox_element("barPr", namespace: "m")
43
+ pos = Utility.ox_element("pos", namespace: "m", attributes: attrs)
44
+ ctrlp = Utility.pr_element("ctrl", true, namespace: "m")
45
+ Utility.update_nodes(barpr, [pos, ctrlp])
12
46
  end
13
47
  end
14
48
  end
@@ -8,14 +8,18 @@ module Plurimath
8
8
  class Base < BinaryFunction
9
9
  def to_asciimath
10
10
  first_value = parameter_one.to_asciimath if parameter_one
11
- second_value = "_#{parameter_two.to_asciimath}" if parameter_two
11
+ second_value = "_#{wrapped(parameter_two)}" if parameter_two
12
12
  "#{first_value}#{second_value}"
13
13
  end
14
14
 
15
15
  def to_mathml_without_math_tag
16
- first_value = parameter_one.to_mathml_without_math_tag
17
- second_value = parameter_two.to_mathml_without_math_tag
18
- "<msub>#{first_value}#{second_value}</msub>"
16
+ under_classes = ["ubrace", "obrace"] + Utility::UNARY_CLASSES
17
+ tag_name = (under_classes.include?(parameter_one&.class_name) ? "under" : "sub")
18
+ sub_tag = Utility.ox_element("m#{tag_name}")
19
+ mathml_value = []
20
+ mathml_value << parameter_one&.to_mathml_without_math_tag
21
+ mathml_value << parameter_two&.to_mathml_without_math_tag if parameter_two
22
+ Utility.update_nodes(sub_tag, mathml_value)
19
23
  end
20
24
 
21
25
  def to_latex
@@ -30,6 +34,23 @@ module Plurimath
30
34
  second_value = "<sub>#{parameter_two.to_html}</sub>" if parameter_two
31
35
  "#{first_value}#{second_value}"
32
36
  end
37
+
38
+ def to_omml_without_math_tag
39
+ ssub_element = Utility.ox_element("sSub", namespace: "m")
40
+ subpr_element = Utility.ox_element("sSubPr", namespace: "m")
41
+ e_element = Utility.ox_element("e", namespace: "m")
42
+ sub_element = Utility.ox_element("sub", namespace: "m")
43
+ sub_element << parameter_two.to_omml_without_math_tag if parameter_two
44
+ Utility.update_nodes(
45
+ ssub_element,
46
+ [
47
+ subpr_element << Utility.pr_element("ctrl", true, namespace: "m"),
48
+ e_element << parameter_one.to_omml_without_math_tag,
49
+ sub_element,
50
+ ],
51
+ )
52
+ ssub_element
53
+ end
33
54
  end
34
55
  end
35
56
  end
@@ -12,13 +12,7 @@ module Plurimath
12
12
  end
13
13
 
14
14
  def to_asciimath
15
- "#{class_name}#{value_to_asciimath}"
16
- end
17
-
18
- def value_to_asciimath
19
- first_value = "(#{parameter_one.to_asciimath})" if parameter_one
20
- second_value = "(#{parameter_two.to_asciimath})" if parameter_two
21
- "#{first_value}#{second_value}"
15
+ "#{class_name}#{wrapped(parameter_one)}#{wrapped(parameter_two)}"
22
16
  end
23
17
 
24
18
  def ==(object)
@@ -28,30 +22,118 @@ module Plurimath
28
22
  end
29
23
 
30
24
  def to_mathml_without_math_tag
31
- first_value = parameter_one&.to_mathml_without_math_tag
32
- second_value = parameter_two&.to_mathml_without_math_tag
33
- "<mo>#{invert_unicode_symbols}</mo>#{first_value}#{second_value}"
34
- end
35
-
36
- def invert_unicode_symbols
37
- Mathml::Constants::UNICODE_SYMBOLS.invert[class_name] || class_name
25
+ mrow_tag = Utility.ox_element("mrow")
26
+ mo_tag = Utility.ox_element("mo") << invert_unicode_symbols.to_s
27
+ first_value = parameter_one&.to_mathml_without_math_tag if parameter_one
28
+ second_value = parameter_two&.to_mathml_without_math_tag if parameter_two
29
+ Utility.update_nodes(
30
+ mrow_tag,
31
+ [
32
+ first_value,
33
+ mo_tag,
34
+ second_value,
35
+ ],
36
+ )
38
37
  end
39
38
 
40
39
  def to_latex
41
- first_value = "{#{parameter_one.to_latex}}" if parameter_one
42
- second_value = "{#{parameter_two.to_latex}}" if parameter_two
40
+ first_value = latex_wrapped(parameter_one) if parameter_one
41
+ second_value = latex_wrapped(parameter_two) if parameter_two
43
42
  "\\#{class_name}#{first_value}#{second_value}"
44
43
  end
45
44
 
46
45
  def to_html
47
- first_value = "<i>#{parameter_one.to_latex}</i>" if parameter_one
48
- second_value = "<i>#{parameter_two.to_latex}</i>" if parameter_two
49
- "<i>#{class_name}</i>#{first_value}#{second_value}"
46
+ first_value = "<i>#{parameter_one.to_html}</i>" if parameter_one
47
+ second_value = "<i>#{parameter_two.to_html}</i>" if parameter_two
48
+ "#{first_value}#{second_value}"
49
+ end
50
+
51
+ def to_omml_without_math_tag
52
+ r_tag = Utility.ox_element("r", namespace: "m")
53
+ update_row_tag(r_tag, parameter_one) if parameter_one
54
+ update_row_tag(r_tag, parameter_two) if parameter_two
55
+ r_tag
50
56
  end
51
57
 
52
58
  def class_name
53
59
  self.class.name.split("::").last.downcase
54
60
  end
61
+
62
+ protected
63
+
64
+ def update_row_tag(tag, field)
65
+ first_value = field.to_omml_without_math_tag
66
+ first_value = if first_value.is_a?(String)
67
+ Utility.ox_element("t", namespace: "m") << first_value
68
+ end
69
+ Utility.update_nodes(
70
+ tag,
71
+ first_value.is_a?(Array) ? first_value : [first_value],
72
+ )
73
+ end
74
+
75
+ def latex_wrapped(field)
76
+ if validate_function_formula(field)
77
+ "{ \\left ( #{field.to_latex} \\right ) }"
78
+ else
79
+ "{#{field.to_latex}}"
80
+ end
81
+ end
82
+
83
+ def validate_function_formula(field)
84
+ unary_classes = (Utility::UNARY_CLASSES + ["obrace", "ubrace", "hat"])
85
+ if field.is_a?(Formula)
86
+ !(field.value.any?(Left) || field.value.any?(Right))
87
+ elsif unary_classes.include?(field.class_name)
88
+ false
89
+ elsif field.class.name.include?("Function") || field.is_a?(FontStyle)
90
+ !field.is_a?(Text)
91
+ end
92
+ end
93
+
94
+ def mathml_wrapped(field)
95
+ if validate_function_formula(field)
96
+ mrow_tag = Utility.ox_element("mrow")
97
+ open_paren = (Utility.ox_element("mo") << "(")
98
+ close_paren = (Utility.ox_element("mo") << ")")
99
+ Utility.update_nodes(
100
+ mrow_tag,
101
+ [
102
+ open_paren,
103
+ field.to_mathml_without_math_tag,
104
+ close_paren,
105
+ ],
106
+ )
107
+ else
108
+ field.to_mathml_without_math_tag
109
+ end
110
+ end
111
+
112
+ def wrapped(field)
113
+ return "" unless field
114
+
115
+ "(#{field.to_asciimath})"
116
+ end
117
+
118
+ def asciimath_base_value(field)
119
+ if validate_function_formula(field)
120
+ "(#{field.to_asciimath})"
121
+ else
122
+ field.to_asciimath
123
+ end
124
+ end
125
+
126
+ def latex_base_value(field)
127
+ if validate_function_formula(field)
128
+ "{ \\left ( #{field.to_latex} \\right ) }"
129
+ else
130
+ field.to_latex
131
+ end
132
+ end
133
+
134
+ def invert_unicode_symbols
135
+ Mathml::Constants::UNICODE_SYMBOLS.invert[class_name] || class_name
136
+ end
55
137
  end
56
138
  end
57
139
  end
@@ -6,6 +6,14 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Cancel < UnaryFunction
9
+ def to_mathml_without_math_tag
10
+ cancel_tag = Utility.ox_element(
11
+ "menclose",
12
+ attributes: { notation: "updiagonalstrike" },
13
+ )
14
+ first_value = parameter_one&.to_mathml_without_math_tag
15
+ Utility.update_nodes(cancel_tag, [first_value])
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -6,6 +6,9 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Ceil < UnaryFunction
9
+ def to_latex
10
+ "{\\lceil #{latex_value} \\rceil}"
11
+ end
9
12
  end
10
13
  end
11
14
  end
@@ -6,16 +6,26 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Color < BinaryFunction
9
+ def to_asciimath
10
+ first_value = "(#{parameter_one&.to_asciimath&.gsub(/\s/, '')})"
11
+ second_value = "(#{parameter_two&.to_asciimath})"
12
+ "color#{first_value}#{second_value}"
13
+ end
14
+
9
15
  def to_mathml_without_math_tag
10
- first_value = parameter_one&.value
11
- second_value = parameter_two&.to_mathml_without_math_tag
12
- "<mstyle mathcolor='#{first_value}'>#{second_value}</mstyle>"
16
+ Utility.update_nodes(
17
+ Utility.ox_element(
18
+ "mstyle",
19
+ attributes: { mathcolor: parameter_one&.to_asciimath&.gsub(/\s/, "")&.gsub(/"/, "") },
20
+ ),
21
+ [parameter_two&.to_mathml_without_math_tag],
22
+ )
13
23
  end
14
24
 
15
25
  def to_latex
16
- first_value = parameter_one&.to_latex
26
+ first_value = parameter_one&.to_asciimath&.gsub(/\s/, "")
17
27
  second_value = parameter_two&.to_latex
18
- "\\#{class_name}{#{first_value}}#{second_value}"
28
+ "{\\#{class_name}{#{first_value}} #{second_value}}"
19
29
  end
20
30
  end
21
31
  end
@@ -6,6 +6,14 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class F < UnaryFunction
9
+ def to_asciimath
10
+ "f#{parameter_one&.to_asciimath}"
11
+ end
12
+
13
+ def to_latex
14
+ first_value = latex_value if parameter_one
15
+ "f#{first_value}"
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -8,18 +8,105 @@ module Plurimath
8
8
  class Fenced < TernaryFunction
9
9
  def to_asciimath
10
10
  first_value = parameter_one ? parameter_one.to_asciimath : "("
11
- second_value = parameter_two&.map(&:to_asciimath)&.join(",")
12
11
  third_value = parameter_three ? parameter_three.to_asciimath : ")"
13
- "#{first_value}#{second_value}#{third_value}"
12
+ "#{first_value}#{parameter_two&.map(&:to_asciimath)&.join(' ')}#{third_value}"
14
13
  end
15
14
 
16
15
  def to_mathml_without_math_tag
17
- first_value = parameter_one.value
18
- second_value = parameter_two.map(&:to_mathml_without_math_tag).join
19
- third_value = parameter_three.value
20
- "<mfenced open='#{first_value}' close='#{third_value}'>"\
21
- "#{second_value}"\
22
- "</mfenced>"
16
+ first_value = Utility.ox_element("mo") << (mathml_paren(parameter_one) || "")
17
+ second_value = parameter_two&.map(&:to_mathml_without_math_tag) || []
18
+ third_value = Utility.ox_element("mo") << (mathml_paren(parameter_three) || "")
19
+ Utility.update_nodes(
20
+ Utility.ox_element("mrow"),
21
+ (second_value.insert(0, first_value) << third_value),
22
+ )
23
+ end
24
+
25
+ def to_html
26
+ first_value = "<i>#{parameter_one.value}</i>" if parameter_one
27
+ second_value = parameter_two.map(&:to_html).join if parameter_two
28
+ third_value = "<i>#{parameter_three.value}</i>" if parameter_three
29
+ "#{first_value}#{second_value}#{third_value}"
30
+ end
31
+
32
+ def to_latex
33
+ open_paren = parameter_one ? parameter_one.value : "("
34
+ fenced_value = parameter_two&.map(&:to_latex)&.join(" ")
35
+ close_paren = parameter_three ? parameter_three.value : ")"
36
+ first_value = latex_paren(open_paren, false)
37
+ second_value = latex_paren(close_paren, true)
38
+ "#{first_value}#{fenced_value}#{second_value}"
39
+ end
40
+
41
+ def to_omml_without_math_tag
42
+ d = Utility.ox_element("d", namespace: "m")
43
+ dpr = Utility.ox_element("dPr", namespace: "m")
44
+ first_value(dpr)
45
+ third_value(dpr)
46
+ dpr << Utility.pr_element("ctrl", true, namespace: "m")
47
+ Utility.update_nodes(
48
+ d,
49
+ [dpr] + second_value,
50
+ )
51
+ end
52
+
53
+ protected
54
+
55
+ def second_value
56
+ class_names = ["number", "symbol"].freeze
57
+ parameter_two.map do |object|
58
+ e_tag = Utility.ox_element("e", namespace: "m")
59
+ e_tag << if class_names.include?(object.class_name)
60
+ fenced_omml_value(object)
61
+ else
62
+ object.to_omml_without_math_tag
63
+ end
64
+ end
65
+ end
66
+
67
+ def fenced_omml_value(object)
68
+ r_tag = Utility.ox_element("r", namespace: "m")
69
+ t_tag = Utility.ox_element("t", namespace: "m")
70
+ t_tag << object.value
71
+ r_tag << t_tag
72
+ end
73
+
74
+ def first_value(dpr)
75
+ first_value = parameter_one&.value
76
+ return dpr if first_value.nil? || first_value.empty?
77
+
78
+ attributes = { "m:val": first_value }
79
+ dpr << Utility.ox_element(
80
+ "begChr",
81
+ namespace: "m",
82
+ attributes: attributes,
83
+ )
84
+ end
85
+
86
+ def third_value(dpr)
87
+ third_value = parameter_three&.value
88
+ return dpr if third_value.nil? || third_value.empty?
89
+
90
+ attributes = { "m:val": third_value }
91
+ dpr << Utility.ox_element(
92
+ "endChr",
93
+ namespace: "m",
94
+ attributes: attributes,
95
+ )
96
+ end
97
+
98
+ def latex_paren(paren, right)
99
+ paren_side = right ? "\\right" : "\\left"
100
+ return "#{paren_side} ." if paren.include?(":")
101
+
102
+ paren = %w[{ }].include?(paren) ? "\\#{paren}" : paren
103
+ " #{paren_side} #{paren} "
104
+ end
105
+
106
+ def mathml_paren(field)
107
+ return "" if field.value.include?(":")
108
+
109
+ field.value
23
110
  end
24
111
  end
25
112
  end
@@ -6,6 +6,21 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Floor < UnaryFunction
9
+ def to_latex
10
+ "\\lfloor #{parameter_one.to_latex} \\rfloor"
11
+ end
12
+
13
+ def to_mathml_without_math_tag
14
+ first_value = parameter_one&.to_mathml_without_math_tag
15
+ Utility.update_nodes(
16
+ Utility.ox_element("mrow"),
17
+ [
18
+ Utility.ox_element("mo") << "&#x230a;",
19
+ first_value,
20
+ Utility.ox_element("mo") << "&#x230b;",
21
+ ],
22
+ )
23
+ end
9
24
  end
10
25
  end
11
26
  end
@@ -11,6 +11,25 @@ module Plurimath
11
11
  parameter_two = "bold")
12
12
  super
13
13
  end
14
+
15
+ def to_asciimath
16
+ "mathbf(#{parameter_one.to_asciimath})"
17
+ end
18
+
19
+ def to_latex
20
+ first_value = parameter_one.to_latex if parameter_one
21
+ "\\mathbf{#{first_value}}"
22
+ end
23
+
24
+ def to_mathml_without_math_tag
25
+ Utility.update_nodes(
26
+ Utility.ox_element(
27
+ "mstyle",
28
+ attributes: { mathvariant: "bold" },
29
+ ),
30
+ [parameter_one.to_mathml_without_math_tag],
31
+ )
32
+ end
14
33
  end
15
34
  end
16
35
  end
@@ -11,6 +11,25 @@ module Plurimath
11
11
  parameter_two = "double-struck")
12
12
  super
13
13
  end
14
+
15
+ def to_asciimath
16
+ "mathbb(#{parameter_one.to_asciimath})"
17
+ end
18
+
19
+ def to_latex
20
+ first_value = parameter_one.to_latex if parameter_one
21
+ "\\mathbb{#{first_value}}"
22
+ end
23
+
24
+ def to_mathml_without_math_tag
25
+ Utility.update_nodes(
26
+ Utility.ox_element(
27
+ "mstyle",
28
+ attributes: { mathvariant: "double-struck" },
29
+ ),
30
+ [parameter_one.to_mathml_without_math_tag],
31
+ )
32
+ end
14
33
  end
15
34
  end
16
35
  end
@@ -11,6 +11,25 @@ module Plurimath
11
11
  parameter_two = "fraktur")
12
12
  super
13
13
  end
14
+
15
+ def to_asciimath
16
+ "mathfrak(#{parameter_one.to_asciimath})"
17
+ end
18
+
19
+ def to_latex
20
+ first_value = parameter_one.to_latex if parameter_one
21
+ "\\mathfrak{#{first_value}}"
22
+ end
23
+
24
+ def to_mathml_without_math_tag
25
+ Utility.update_nodes(
26
+ Utility.ox_element(
27
+ "mstyle",
28
+ attributes: { mathvariant: "fraktur" },
29
+ ),
30
+ [parameter_one.to_mathml_without_math_tag],
31
+ )
32
+ end
14
33
  end
15
34
  end
16
35
  end