plurimath 0.3.9 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/lib/plurimath/latex/constants.rb +1 -0
  3. data/lib/plurimath/latex/parse.rb +11 -3
  4. data/lib/plurimath/latex/transform.rb +93 -7
  5. data/lib/plurimath/math/core.rb +16 -4
  6. data/lib/plurimath/math/formula.rb +24 -20
  7. data/lib/plurimath/math/function/abs.rb +2 -2
  8. data/lib/plurimath/math/function/bar.rb +48 -10
  9. data/lib/plurimath/math/function/base.rb +3 -3
  10. data/lib/plurimath/math/function/binary_function.rb +20 -10
  11. data/lib/plurimath/math/function/cancel.rb +2 -2
  12. data/lib/plurimath/math/function/ceil.rb +7 -2
  13. data/lib/plurimath/math/function/color.rb +2 -2
  14. data/lib/plurimath/math/function/ddot.rb +17 -12
  15. data/lib/plurimath/math/function/deg.rb +2 -2
  16. data/lib/plurimath/math/function/det.rb +2 -2
  17. data/lib/plurimath/math/function/dim.rb +2 -2
  18. data/lib/plurimath/math/function/dot.rb +26 -2
  19. data/lib/plurimath/math/function/exp.rb +2 -2
  20. data/lib/plurimath/math/function/fenced.rb +6 -7
  21. data/lib/plurimath/math/function/floor.rb +2 -2
  22. data/lib/plurimath/math/function/font_style/bold-fraktur.rb +17 -0
  23. data/lib/plurimath/math/function/font_style/bold-italic.rb +17 -0
  24. data/lib/plurimath/math/function/font_style/bold-sans-serif.rb +17 -0
  25. data/lib/plurimath/math/function/font_style/bold-script.rb +17 -0
  26. data/lib/plurimath/math/function/font_style/bold.rb +4 -0
  27. data/lib/plurimath/math/function/font_style/double_struck.rb +4 -0
  28. data/lib/plurimath/math/function/font_style/fraktur.rb +4 -0
  29. data/lib/plurimath/math/function/font_style/italic.rb +4 -0
  30. data/lib/plurimath/math/function/font_style/monospace.rb +4 -0
  31. data/lib/plurimath/math/function/font_style/normal.rb +4 -0
  32. data/lib/plurimath/math/function/font_style/sans-serif-bold-italic.rb +17 -0
  33. data/lib/plurimath/math/function/font_style/sans-serif-italic.rb +17 -0
  34. data/lib/plurimath/math/function/font_style/sans-serif.rb +4 -0
  35. data/lib/plurimath/math/function/font_style/script.rb +4 -0
  36. data/lib/plurimath/math/function/font_style.rb +24 -2
  37. data/lib/plurimath/math/function/frac.rb +3 -3
  38. data/lib/plurimath/math/function/gcd.rb +2 -2
  39. data/lib/plurimath/math/function/glb.rb +2 -2
  40. data/lib/plurimath/math/function/hat.rb +42 -9
  41. data/lib/plurimath/math/function/hom.rb +2 -2
  42. data/lib/plurimath/math/function/inf.rb +2 -2
  43. data/lib/plurimath/math/function/int.rb +4 -4
  44. data/lib/plurimath/math/function/ker.rb +2 -2
  45. data/lib/plurimath/math/function/lcm.rb +2 -2
  46. data/lib/plurimath/math/function/left.rb +1 -1
  47. data/lib/plurimath/math/function/lg.rb +2 -2
  48. data/lib/plurimath/math/function/lim.rb +2 -2
  49. data/lib/plurimath/math/function/liminf.rb +2 -2
  50. data/lib/plurimath/math/function/limits.rb +4 -4
  51. data/lib/plurimath/math/function/limsup.rb +2 -2
  52. data/lib/plurimath/math/function/ln.rb +2 -2
  53. data/lib/plurimath/math/function/log.rb +5 -3
  54. data/lib/plurimath/math/function/longdiv.rb +2 -2
  55. data/lib/plurimath/math/function/lub.rb +2 -2
  56. data/lib/plurimath/math/function/max.rb +2 -2
  57. data/lib/plurimath/math/function/mbox.rb +2 -2
  58. data/lib/plurimath/math/function/menclose.rb +2 -2
  59. data/lib/plurimath/math/function/merror.rb +1 -1
  60. data/lib/plurimath/math/function/min.rb +2 -2
  61. data/lib/plurimath/math/function/mod.rb +3 -3
  62. data/lib/plurimath/math/function/msgroup.rb +2 -2
  63. data/lib/plurimath/math/function/msline.rb +2 -2
  64. data/lib/plurimath/math/function/multiscript.rb +4 -4
  65. data/lib/plurimath/math/function/norm.rb +2 -2
  66. data/lib/plurimath/math/function/obrace.rb +40 -26
  67. data/lib/plurimath/math/function/oint.rb +4 -4
  68. data/lib/plurimath/math/function/over.rb +3 -3
  69. data/lib/plurimath/math/function/overset.rb +8 -3
  70. data/lib/plurimath/math/function/power.rb +3 -3
  71. data/lib/plurimath/math/function/power_base.rb +8 -8
  72. data/lib/plurimath/math/function/prod.rb +4 -4
  73. data/lib/plurimath/math/function/right.rb +1 -1
  74. data/lib/plurimath/math/function/root.rb +3 -3
  75. data/lib/plurimath/math/function/rule.rb +1 -1
  76. data/lib/plurimath/math/function/scarries.rb +2 -2
  77. data/lib/plurimath/math/function/semantics.rb +2 -2
  78. data/lib/plurimath/math/function/sqrt.rb +2 -2
  79. data/lib/plurimath/math/function/stackrel.rb +3 -3
  80. data/lib/plurimath/math/function/substack.rb +3 -3
  81. data/lib/plurimath/math/function/sum.rb +14 -19
  82. data/lib/plurimath/math/function/sup.rb +2 -2
  83. data/lib/plurimath/math/function/table.rb +7 -7
  84. data/lib/plurimath/math/function/td.rb +2 -2
  85. data/lib/plurimath/math/function/ternary_function.rb +13 -9
  86. data/lib/plurimath/math/function/text.rb +6 -5
  87. data/lib/plurimath/math/function/tilde.rb +27 -2
  88. data/lib/plurimath/math/function/tr.rb +2 -2
  89. data/lib/plurimath/math/function/ubrace.rb +28 -21
  90. data/lib/plurimath/math/function/ul.rb +55 -18
  91. data/lib/plurimath/math/function/unary_function.rb +13 -8
  92. data/lib/plurimath/math/function/underover.rb +10 -5
  93. data/lib/plurimath/math/function/underset.rb +8 -3
  94. data/lib/plurimath/math/function/vec.rb +25 -3
  95. data/lib/plurimath/math/number.rb +6 -2
  96. data/lib/plurimath/math/symbol.rb +6 -2
  97. data/lib/plurimath/math.rb +1 -0
  98. data/lib/plurimath/mathml/constants.rb +9 -1
  99. data/lib/plurimath/mathml/parser.rb +16 -10
  100. data/lib/plurimath/mathml/transform.rb +59 -31
  101. data/lib/plurimath/omml/parser.rb +24 -1
  102. data/lib/plurimath/omml/transform.rb +56 -41
  103. data/lib/plurimath/utility.rb +154 -9
  104. data/lib/plurimath/version.rb +1 -1
  105. metadata +8 -2
@@ -51,6 +51,14 @@ module Plurimath
51
51
  "#{first_value}#{second_value}#{third_value}"
52
52
  end
53
53
 
54
+ def any_value_exist?
55
+ !(parameter_one.nil? || parameter_two.nil? || parameter_three.nil?)
56
+ end
57
+
58
+ def all_values_exist?
59
+ !(parameter_one.nil? && parameter_two.nil? && parameter_three.nil?)
60
+ end
61
+
54
62
  protected
55
63
 
56
64
  def latex_wrapped(field)
@@ -104,8 +112,8 @@ module Plurimath
104
112
  def narypr(function_symbol, function_type: "undOvr")
105
113
  chr_arg = { "m:val": function_symbol }
106
114
  limloc_arg = { "m:val": function_type }
107
- subhide_arg = { "m:val": "0" }
108
- suphide_arg = { "m:val": "0" }
115
+ subhide_arg = { "m:val": parameter_one ? "0" : "1" }
116
+ suphide_arg = { "m:val": parameter_two ? "0" : "1" }
109
117
  chr_tag = Utility.ox_element("chr", attributes: chr_arg, namespace: "m")
110
118
  limloc_tag = Utility.ox_element("limLoc", attributes: limloc_arg, namespace: "m")
111
119
  subhide_tag = Utility.ox_element("subHide", attributes: subhide_arg, namespace: "m")
@@ -122,21 +130,17 @@ module Plurimath
122
130
  )
123
131
  end
124
132
 
125
- def all_values_exist?
126
- !(parameter_one.nil? && parameter_two.nil? && parameter_three.nil?)
127
- end
128
-
129
133
  def validate_mathml_tag(parameter)
130
134
  return Array(Utility.ox_element("mrow")) unless parameter
131
135
 
132
136
  Array(parameter.to_mathml_without_math_tag)
133
137
  end
134
138
 
135
- def underover
139
+ def underover(display_style)
136
140
  overset = Overset.new(parameter_one, parameter_three)
137
- return overset unless parameter_two
141
+ return overset.to_omml_without_math_tag(display_style) unless parameter_two
138
142
 
139
- Underset.new(overset, parameter_two)&.to_omml_without_math_tag
143
+ Underset.new(overset, parameter_two)&.to_omml_without_math_tag(display_style)
140
144
  end
141
145
  end
142
146
  end
@@ -27,15 +27,15 @@ module Plurimath
27
27
  parse_text("html") || parameter_one
28
28
  end
29
29
 
30
- def to_omml_without_math_tag
30
+ def to_omml_without_math_tag(_display_style)
31
31
  text = Utility.ox_element("t", namespace: "m")
32
32
  text << (parse_text("omml") || parameter_one)
33
33
  [text]
34
34
  end
35
35
 
36
- def insert_t_tag
36
+ def insert_t_tag(display_style)
37
37
  r_tag = Utility.ox_element("r", namespace: "m")
38
- Utility.update_nodes(r_tag, to_omml_without_math_tag)
38
+ Utility.update_nodes(r_tag, to_omml_without_math_tag(display_style))
39
39
  [r_tag]
40
40
  end
41
41
 
@@ -54,7 +54,8 @@ module Plurimath
54
54
  html_value = first_value(lang).dup
55
55
  html_value&.gsub!(PARSER_REGEX) do |_text|
56
56
  last_match = Regexp.last_match
57
- if ["mathml", "html"].include?(lang)
57
+ case lang
58
+ when "mathml", "html"
58
59
  symbol_value(last_match[:unicode])
59
60
  else
60
61
  last_match[:unicode]
@@ -67,7 +68,7 @@ module Plurimath
67
68
  if lang == "omml"
68
69
  entities = HTMLEntities.new
69
70
  entities.encode(
70
- entities.decode(parameter_one),
71
+ entities.decode(parameter_one&.gsub(/ /, "&#xa0;")),
71
72
  :named,
72
73
  )
73
74
  else
@@ -6,14 +6,39 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Tilde < UnaryFunction
9
+ attr_accessor :attributes
10
+
11
+ def initialize(parameter_one = nil, attributes = {})
12
+ super(parameter_one)
13
+ @attributes = attributes
14
+ end
15
+
9
16
  def to_mathml_without_math_tag
10
17
  mover = Utility.ox_element("mover")
18
+ mover.attributes.merge!({ accent: attributes[:accent]}) if attributes && attributes[:accent]
11
19
  first_value = (Utility.ox_element("mo") << "~")
12
20
  second_value = parameter_one.to_mathml_without_math_tag if parameter_one
13
21
  Utility.update_nodes(mover, [second_value, first_value])
14
22
  end
15
23
 
16
- def to_omml_without_math_tag
24
+ def to_omml_without_math_tag(display_style)
25
+ return r_element("~", rpr_tag: false) unless parameter_one
26
+
27
+ if attributes && attributes[:accent]
28
+ acc_tag(display_style)
29
+ else
30
+ symbol = Symbol.new("~")
31
+ Overset.new(parameter_one, symbol).to_omml_without_math_tag(true)
32
+ end
33
+ end
34
+
35
+ def validate_function_formula
36
+ false
37
+ end
38
+
39
+ protected
40
+
41
+ def acc_tag(display_style)
17
42
  acc_tag = Utility.ox_element("acc", namespace: "m")
18
43
  acc_pr_tag = Utility.ox_element("accPr", namespace: "m")
19
44
  acc_pr_tag << (Utility.ox_element("chr", namespace: "m", attributes: { "m:val": "˜" }))
@@ -21,7 +46,7 @@ module Plurimath
21
46
  acc_tag,
22
47
  [
23
48
  acc_pr_tag,
24
- omml_parameter(parameter_one, tag_name: "e"),
49
+ omml_parameter(parameter_one, display_style, tag_name: "e"),
25
50
  ],
26
51
  )
27
52
  [acc_tag]
@@ -31,8 +31,8 @@ module Plurimath
31
31
  "<tr>#{first_value}</tr>"
32
32
  end
33
33
 
34
- def to_omml_without_math_tag
35
- omml_content = parameter_one&.map(&:to_omml_without_math_tag)
34
+ def to_omml_without_math_tag(display_style)
35
+ omml_content = parameter_one&.map { |obj| obj.to_omml_without_math_tag(display_style) }
36
36
  if parameter_one.count.eql?(1)
37
37
  omml_content
38
38
  else
@@ -6,6 +6,18 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Ubrace < UnaryFunction
9
+ attr_accessor :attributes
10
+
11
+ def initialize(parameter_one = nil, attributes = {})
12
+ super(parameter_one)
13
+ @attributes = attributes
14
+ end
15
+
16
+ def to_asciimath
17
+ first_value = "(#{parameter_one.to_asciimath})" if parameter_one
18
+ "ubrace#{first_value}"
19
+ end
20
+
9
21
  def to_latex
10
22
  first_value = "{#{parameter_one.to_latex}}" if parameter_one
11
23
  "\\underbrace#{first_value}"
@@ -13,13 +25,17 @@ module Plurimath
13
25
 
14
26
  def to_mathml_without_math_tag
15
27
  mo_tag = (Utility.ox_element("mo") << "&#x23df;")
16
- if parameter_one
17
- over_tag = Utility.ox_element("munder")
18
- arr_value = mathml_value
19
- Utility.update_nodes(over_tag, (arr_value << mo_tag))
20
- else
21
- mo_tag
22
- end
28
+ return mo_tag unless parameter_one
29
+
30
+ over_tag = Utility.ox_element("munder")
31
+ over_tag.attributes.merge!(attributes) if attributes && !attributes.empty?
32
+ Utility.update_nodes(
33
+ over_tag,
34
+ [
35
+ parameter_one.to_mathml_without_math_tag,
36
+ mo_tag,
37
+ ],
38
+ )
23
39
  end
24
40
 
25
41
  def tag_name
@@ -34,20 +50,11 @@ module Plurimath
34
50
  false
35
51
  end
36
52
 
37
- def to_omml_without_math_tag
38
- limlow = Utility.ox_element("limLow", namespace: "m")
39
- limlowpr = Utility.ox_element("limLowPr", namespace: "m")
40
- limlowpr << Utility.pr_element("ctrl", true, namespace: "m")
41
- lim = Utility.ox_element("lim", namespace: "m")
42
- Utility.update_nodes(
43
- limlow,
44
- [
45
- limlowpr,
46
- omml_parameter(parameter_one, tag_name: "e"),
47
- Utility.update_nodes(lim, r_element("⏟")),
48
- ],
49
- )
50
- [limlow]
53
+ def to_omml_without_math_tag(display_style)
54
+ return r_element("", rpr_tag: false) unless parameter_one
55
+
56
+ symbol = Symbol.new("")
57
+ Underset.new(parameter_one, symbol).to_omml_without_math_tag(true)
51
58
  end
52
59
  end
53
60
 
@@ -6,36 +6,73 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Ul < UnaryFunction
9
+ attr_accessor :attributes
10
+
11
+ def initialize(parameter_one = nil, attributes = {})
12
+ super(parameter_one)
13
+ @attributes = attributes
14
+ end
15
+
16
+ def to_asciimath
17
+ first_value = "(#{parameter_one.to_asciimath})" if parameter_one
18
+ "underline#{first_value}"
19
+ end
20
+
21
+ def to_latex
22
+ first_value = "{#{parameter_one.to_latex}}" if parameter_one
23
+ "\\underline#{first_value}"
24
+ end
25
+
9
26
  def to_mathml_without_math_tag
10
- first_value = parameter_one&.to_mathml_without_math_tag
27
+ mo_tag = Utility.ox_element("mo") << "&#x332;"
28
+ return mo_tag unless parameter_one
29
+
30
+ munder_tag = Utility.ox_element("munder")
31
+ munder_tag.attributes.merge!(attributes) if attributes && !attributes.empty?
11
32
  Utility.update_nodes(
12
- Utility.ox_element("munder"),
33
+ munder_tag,
13
34
  [
14
- first_value,
15
- Utility.ox_element("mo") << "&#xaf;",
35
+ parameter_one&.to_mathml_without_math_tag,
36
+ mo_tag,
16
37
  ],
17
38
  )
18
39
  end
19
40
 
20
- def to_omml_without_math_tag
21
- bar = Utility.ox_element("bar", namespace: "m")
22
- barpr = Utility.ox_element("barPr", namespace: "m")
23
- barpr << Utility.pr_element("ctrl", true, namespace: "m")
24
- me = Utility.ox_element("e", namespace: "m")
25
- Utility.update_nodes(me, omml_value)
26
- Utility.update_nodes(
27
- bar,
28
- [
29
- barpr,
30
- me,
31
- ],
32
- )
33
- [bar]
41
+ def to_omml_without_math_tag(display_style)
42
+ return r_element("&#x332;", rpr_tag: false) unless parameter_one
43
+
44
+ if attributes && attributes[:accentunder]
45
+ groupchr_tag(display_style)
46
+ else
47
+ symbol = Symbol.new("&#x332;")
48
+ Underset.new(parameter_one, symbol).to_omml_without_math_tag(true)
49
+ end
34
50
  end
35
51
 
36
52
  def class_name
37
53
  "underline"
38
54
  end
55
+
56
+ def swap_class
57
+ Bar.new(parameter_one, attributes)
58
+ end
59
+
60
+ protected
61
+
62
+ def groupchr_tag(display_style)
63
+ groupchr = Utility.ox_element("groupChr", namespace: "m")
64
+ groupchrpr = Utility.ox_element("groupChrPR", namespace: "m")
65
+ chr = Utility.ox_element("chr", namespace: "m", attributes: { "m:val": "_" })
66
+ pos = Utility.ox_element("pos", namespace: "m", attributes: { "m:val": "bot" })
67
+ Utility.update_nodes(groupchrpr, [chr, pos])
68
+ Utility.update_nodes(
69
+ groupchr,
70
+ [
71
+ groupchrpr,
72
+ omml_parameter(parameter_one, display_style, tag_name: "e", namespace: "m"),
73
+ ],
74
+ )
75
+ end
39
76
  end
40
77
 
41
78
  Underline = Ul
@@ -39,8 +39,7 @@ module Plurimath
39
39
  end
40
40
 
41
41
  def to_latex
42
- first_value = "{#{latex_value}}" if parameter_one
43
- "\\#{class_name}#{first_value}"
42
+ "\\#{class_name}{#{latex_value}}"
44
43
  end
45
44
 
46
45
  def to_html
@@ -49,10 +48,12 @@ module Plurimath
49
48
  elsif parameter_one
50
49
  "<i>#{parameter_one.to_html}</i>"
51
50
  end
52
- "<i>#{class_name}</i>#{first_value}"
51
+ "<i>#{invert_unicode_symbols}</i>#{first_value}"
53
52
  end
54
53
 
55
- def to_omml_without_math_tag
54
+ def to_omml_without_math_tag(display_style)
55
+ return r_element(class_name, rpr_tag: false) unless parameter_one
56
+
56
57
  func = Utility.ox_element("func", namespace: "m")
57
58
  funcpr = Utility.ox_element("funcPr", namespace: "m")
58
59
  funcpr << Utility.pr_element("ctrl", true, namespace: "m")
@@ -62,7 +63,7 @@ module Plurimath
62
63
  mt = Utility.ox_element("t", namespace: "m") << class_name
63
64
  fname << Utility.update_nodes(mr, [rpr, mt])
64
65
  me = Utility.ox_element("e", namespace: "m")
65
- Utility.update_nodes(me, omml_value) if parameter_one
66
+ Utility.update_nodes(me, omml_value(display_style)) if parameter_one
66
67
  Utility.update_nodes(
67
68
  func,
68
69
  [
@@ -76,6 +77,10 @@ module Plurimath
76
77
 
77
78
  protected
78
79
 
80
+ def invert_unicode_symbols
81
+ Mathml::Constants::UNICODE_SYMBOLS.invert[class_name] || class_name
82
+ end
83
+
79
84
  def asciimath_value
80
85
  return "" unless parameter_one
81
86
 
@@ -104,12 +109,12 @@ module Plurimath
104
109
  parameter_one&.to_latex
105
110
  end
106
111
 
107
- def omml_value
112
+ def omml_value(display_style)
108
113
  if parameter_one.is_a?(Array)
109
- return parameter_one&.compact&.map(&:insert_t_tag)
114
+ return parameter_one&.compact&.map { |obj| obj.insert_t_tag(display_style) }
110
115
  end
111
116
 
112
- Array(parameter_one&.insert_t_tag)
117
+ Array(parameter_one&.insert_t_tag(display_style))
113
118
  end
114
119
  end
115
120
  end
@@ -35,16 +35,21 @@ module Plurimath
35
35
  )
36
36
  end
37
37
 
38
- def to_omml_without_math_tag
39
- underover
38
+ def to_omml_without_math_tag(display_style)
39
+ if !display_style
40
+ power_base = PowerBase.new(parameter_one, parameter_two, parameter_three)
41
+ return power_base.to_omml_without_math_tag(display_style)
42
+ end
43
+
44
+ underover(display_style)
40
45
  end
41
46
 
42
- def omml_nary_tag
47
+ def omml_nary_tag(display_style)
43
48
  pr = Utility.ox_element("naryPr", namespace: "m")
44
49
  [
45
50
  pr_element_value(pr),
46
- omml_parameter(parameter_two, tag_name: "sub"),
47
- omml_parameter(parameter_three, tag_name: "sup"),
51
+ omml_parameter(parameter_two, display_style, tag_name: "sub"),
52
+ omml_parameter(parameter_three, display_style, tag_name: "sup"),
48
53
  ]
49
54
  end
50
55
 
@@ -18,7 +18,12 @@ module Plurimath
18
18
  )
19
19
  end
20
20
 
21
- def to_omml_without_math_tag
21
+ def to_omml_without_math_tag(display_style)
22
+ if !display_style
23
+ base = Base.new(parameter_one, parameter_two)
24
+ return base.to_omml_without_math_tag(display_style)
25
+ end
26
+
22
27
  limlow = Utility.ox_element("limLow", namespace: "m")
23
28
  limlowpr = Utility.ox_element("limLowPr", namespace: "m")
24
29
  limlowpr << Utility.pr_element("ctrl", true, namespace: "m")
@@ -26,8 +31,8 @@ module Plurimath
26
31
  limlow,
27
32
  [
28
33
  limlowpr,
29
- omml_parameter(parameter_one, tag_name: "e"),
30
- omml_parameter(parameter_two, tag_name: "lim"),
34
+ omml_parameter(parameter_one, display_style, tag_name: "e"),
35
+ omml_parameter(parameter_two, display_style, tag_name: "lim"),
31
36
  ],
32
37
  )
33
38
  [limlow]
@@ -6,10 +6,19 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Vec < UnaryFunction
9
+ attr_accessor :attributes
10
+
11
+ def initialize(parameter_one = nil, attributes = {})
12
+ super(parameter_one)
13
+ @attributes = attributes
14
+ end
15
+
9
16
  def to_mathml_without_math_tag
17
+ mover = Utility.ox_element("mover")
10
18
  first_value = parameter_one&.to_mathml_without_math_tag
19
+ mover.attributes.merge!({ accent: attributes[:accent] }) if attributes && attributes[:accent]
11
20
  Utility.update_nodes(
12
- Utility.ox_element("mover"),
21
+ mover,
13
22
  [
14
23
  first_value,
15
24
  Utility.ox_element("mo") << "&#x2192;",
@@ -17,7 +26,20 @@ module Plurimath
17
26
  )
18
27
  end
19
28
 
20
- def to_omml_without_math_tag
29
+ def to_omml_without_math_tag(display_style)
30
+ return r_element("&#x2192;", rpr_tag: false) unless parameter_one
31
+
32
+ if attributes && attributes[:accent]
33
+ acc_tag(display_style)
34
+ else
35
+ symbol = Symbol.new("→")
36
+ Overset.new(parameter_one, symbol).to_omml_without_math_tag(true)
37
+ end
38
+ end
39
+
40
+ protected
41
+
42
+ def acc_tag(display_style)
21
43
  acc_tag = Utility.ox_element("acc", namespace: "m")
22
44
  acc_pr_tag = Utility.ox_element("accPr", namespace: "m")
23
45
  acc_pr_tag << (Utility.ox_element("chr", namespace: "m", attributes: { "m:val": "→" }))
@@ -25,7 +47,7 @@ module Plurimath
25
47
  acc_tag,
26
48
  [
27
49
  acc_pr_tag,
28
- omml_parameter(parameter_one, tag_name: "e"),
50
+ omml_parameter(parameter_one, display_style, tag_name: "e"),
29
51
  ],
30
52
  )
31
53
  [acc_tag]
@@ -29,16 +29,20 @@ module Plurimath
29
29
  value
30
30
  end
31
31
 
32
- def to_omml_without_math_tag
32
+ def to_omml_without_math_tag(_display_style)
33
33
  [(Utility.ox_element("t", namespace: "m") << value)]
34
34
  end
35
35
 
36
- def insert_t_tag
36
+ def insert_t_tag(_display_style)
37
37
  r_tag = Utility.ox_element("r", namespace: "m")
38
38
  r_tag << (Utility.ox_element("t", namespace: "m") << value)
39
39
  [r_tag]
40
40
  end
41
41
 
42
+ def font_style_t_tag(_display_style)
43
+ Utility.ox_element("t", namespace: "m") << value
44
+ end
45
+
42
46
  def nary_attr_value
43
47
  value
44
48
  end
@@ -58,11 +58,11 @@ module Plurimath
58
58
  value
59
59
  end
60
60
 
61
- def to_omml_without_math_tag
61
+ def to_omml_without_math_tag(_display_style)
62
62
  value
63
63
  end
64
64
 
65
- def insert_t_tag
65
+ def insert_t_tag(_display_style)
66
66
  r_tag = Utility.ox_element("r", namespace: "m")
67
67
  r_tag << (Utility.ox_element("t", namespace: "m") << value)
68
68
  [r_tag]
@@ -80,6 +80,10 @@ module Plurimath
80
80
  "subSup"
81
81
  end
82
82
 
83
+ def font_style_t_tag(_display_style)
84
+ Utility.ox_element("t", namespace: "m") << value
85
+ end
86
+
83
87
  def nary_attr_value
84
88
  value
85
89
  end
@@ -20,6 +20,7 @@ require_relative "html/parser"
20
20
  require_relative "omml/parser"
21
21
  require_relative "utility"
22
22
  require "ox"
23
+ require "yaml"
23
24
  Ox.default_options = { encoding: "UTF-8" }
24
25
 
25
26
  module Plurimath
@@ -130,7 +130,6 @@ module Plurimath
130
130
  "&#x21d2;": "rArr",
131
131
  "&#x21d0;": "lArr",
132
132
  "&#x21d4;": "hArr",
133
- "&#x2192;": "->",
134
133
  "&#x21a3;": ">->",
135
134
  "&#x21a0;": "->>",
136
135
  "&#x2916;": ">->>",
@@ -139,10 +138,19 @@ module Plurimath
139
138
  "&#x2212;": "-",
140
139
  "&#x23de;": "obrace",
141
140
  "&#x23df;": "ubrace",
141
+ "&#x2192;": "vec",
142
+ "&#x302;": "hat",
143
+ "&#x332;": "ul",
144
+ "&#xaf;": "bar",
142
145
  "&#x26;": "&",
143
146
  "&#x3e;": ">",
144
147
  "&#x3c;": "<",
145
148
  "&amp;": "&",
149
+ "~": "tilde",
150
+ "..": "ddot",
151
+ "^": "hat",
152
+ "¯": "bar",
153
+ "_": "ul",
146
154
  }.freeze
147
155
  SYMBOLS = {
148
156
  "|": "|",
@@ -7,11 +7,13 @@ module Plurimath
7
7
  class Parser
8
8
  attr_accessor :text
9
9
 
10
- SUPPORTED_ATTRIBUTES = %w[
10
+ SUPPORTED_ATTRS = %w[
11
11
  columnlines
12
12
  mathvariant
13
+ accentunder
13
14
  mathcolor
14
15
  notation
16
+ accent
15
17
  close
16
18
  open
17
19
  ].freeze
@@ -22,11 +24,11 @@ module Plurimath
22
24
 
23
25
  def parse
24
26
  ox_nodes = Ox.load(text, strip_namespace: true)
25
- display_style = ox_nodes&.locate("*/mstyle/@displaystyle")&.first || true
27
+ display_style = ox_nodes&.locate("*/mstyle/@displaystyle")&.first
26
28
  nodes = parse_nodes(ox_nodes.nodes)
27
29
  Math::Formula.new(
28
30
  Transform.new.apply(nodes).flatten.compact,
29
- displaystyle: display_style,
31
+ display_style: (display_style || true),
30
32
  )
31
33
  end
32
34
 
@@ -37,12 +39,7 @@ module Plurimath
37
39
  if node.is_a?(String)
38
40
  node
39
41
  elsif !node.attributes.empty?
40
- {
41
- node.name.to_sym => {
42
- attributes: validate_attributes(node.attributes),
43
- value: parse_nodes(node.nodes),
44
- },
45
- }
42
+ attrs_hash(node)
46
43
  else
47
44
  { node.name.to_sym => parse_nodes(node.nodes) }
48
45
  end
@@ -50,9 +47,18 @@ module Plurimath
50
47
  end
51
48
 
52
49
  def validate_attributes(attributes)
53
- attributes&.select! { |key, _| SUPPORTED_ATTRIBUTES.include?(key&.to_s) }
50
+ attributes&.select! { |key, _| SUPPORTED_ATTRS.include?(key&.to_s) }
54
51
  attributes&.transform_keys(&:to_sym) if attributes&.any?
55
52
  end
53
+
54
+ def attrs_hash(node)
55
+ {
56
+ node.name.to_sym => {
57
+ attributes: validate_attributes(node.attributes),
58
+ value: parse_nodes(node.nodes),
59
+ },
60
+ }
61
+ end
56
62
  end
57
63
  end
58
64
  end