plurimath 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/lib/plurimath/asciimath/parse.rb +3 -2
  4. data/lib/plurimath/asciimath/transform.rb +32 -5
  5. data/lib/plurimath/latex/constants.rb +2 -1
  6. data/lib/plurimath/latex/transform.rb +9 -13
  7. data/lib/plurimath/math/core.rb +134 -20
  8. data/lib/plurimath/math/formula.rb +88 -18
  9. data/lib/plurimath/math/function/abs.rb +28 -15
  10. data/lib/plurimath/math/function/bar.rb +5 -0
  11. data/lib/plurimath/math/function/base.rb +14 -0
  12. data/lib/plurimath/math/function/binary_function.rb +2 -8
  13. data/lib/plurimath/math/function/ceil.rb +24 -9
  14. data/lib/plurimath/math/function/ddot.rb +6 -1
  15. data/lib/plurimath/math/function/deg.rb +4 -1
  16. data/lib/plurimath/math/function/det.rb +4 -1
  17. data/lib/plurimath/math/function/dim.rb +4 -1
  18. data/lib/plurimath/math/function/dot.rb +5 -0
  19. data/lib/plurimath/math/function/exp.rb +4 -1
  20. data/lib/plurimath/math/function/fenced.rb +25 -16
  21. data/lib/plurimath/math/function/floor.rb +23 -13
  22. data/lib/plurimath/math/function/font_style.rb +18 -8
  23. data/lib/plurimath/math/function/frac.rb +32 -18
  24. data/lib/plurimath/math/function/gcd.rb +4 -1
  25. data/lib/plurimath/math/function/glb.rb +8 -1
  26. data/lib/plurimath/math/function/hat.rb +16 -5
  27. data/lib/plurimath/math/function/hom.rb +4 -1
  28. data/lib/plurimath/math/function/inf.rb +16 -0
  29. data/lib/plurimath/math/function/int.rb +28 -9
  30. data/lib/plurimath/math/function/ker.rb +4 -1
  31. data/lib/plurimath/math/function/lcm.rb +17 -1
  32. data/lib/plurimath/math/function/left.rb +1 -1
  33. data/lib/plurimath/math/function/lg.rb +4 -1
  34. data/lib/plurimath/math/function/lim.rb +10 -0
  35. data/lib/plurimath/math/function/liminf.rb +4 -1
  36. data/lib/plurimath/math/function/limits.rb +22 -9
  37. data/lib/plurimath/math/function/limsup.rb +4 -1
  38. data/lib/plurimath/math/function/linebreak.rb +95 -0
  39. data/lib/plurimath/math/function/ln.rb +4 -1
  40. data/lib/plurimath/math/function/log.rb +21 -12
  41. data/lib/plurimath/math/function/longdiv.rb +19 -0
  42. data/lib/plurimath/math/function/lub.rb +4 -1
  43. data/lib/plurimath/math/function/max.rb +4 -1
  44. data/lib/plurimath/math/function/mbox.rb +8 -7
  45. data/lib/plurimath/math/function/merror.rb +12 -3
  46. data/lib/plurimath/math/function/min.rb +4 -1
  47. data/lib/plurimath/math/function/mod.rb +42 -15
  48. data/lib/plurimath/math/function/msgroup.rb +4 -0
  49. data/lib/plurimath/math/function/msline.rb +10 -0
  50. data/lib/plurimath/math/function/multiscript.rb +20 -0
  51. data/lib/plurimath/math/function/nary.rb +39 -5
  52. data/lib/plurimath/math/function/norm.rb +24 -15
  53. data/lib/plurimath/math/function/obrace.rb +5 -0
  54. data/lib/plurimath/math/function/oint.rb +42 -20
  55. data/lib/plurimath/math/function/over.rb +23 -10
  56. data/lib/plurimath/math/function/overset.rb +13 -10
  57. data/lib/plurimath/math/function/phantom.rb +24 -6
  58. data/lib/plurimath/math/function/power.rb +13 -4
  59. data/lib/plurimath/math/function/power_base.rb +28 -6
  60. data/lib/plurimath/math/function/prod.rb +33 -14
  61. data/lib/plurimath/math/function/right.rb +1 -1
  62. data/lib/plurimath/math/function/rule.rb +1 -1
  63. data/lib/plurimath/math/function/scarries.rb +14 -0
  64. data/lib/plurimath/math/function/semantics.rb +9 -0
  65. data/lib/plurimath/math/function/sqrt.rb +5 -0
  66. data/lib/plurimath/math/function/stackrel.rb +8 -0
  67. data/lib/plurimath/math/function/substack.rb +12 -51
  68. data/lib/plurimath/math/function/sum.rb +43 -20
  69. data/lib/plurimath/math/function/sup.rb +11 -2
  70. data/lib/plurimath/math/function/table/array.rb +1 -1
  71. data/lib/plurimath/math/function/table/matrix.rb +4 -0
  72. data/lib/plurimath/math/function/table.rb +10 -2
  73. data/lib/plurimath/math/function/td.rb +14 -4
  74. data/lib/plurimath/math/function/ternary_function.rb +8 -10
  75. data/lib/plurimath/math/function/text.rb +1 -1
  76. data/lib/plurimath/math/function/tilde.rb +5 -0
  77. data/lib/plurimath/math/function/tr.rb +1 -1
  78. data/lib/plurimath/math/function/ubrace.rb +5 -0
  79. data/lib/plurimath/math/function/unary_function.rb +72 -26
  80. data/lib/plurimath/math/function/underover.rb +25 -8
  81. data/lib/plurimath/math/function/underset.rb +19 -9
  82. data/lib/plurimath/math/function/vec.rb +5 -0
  83. data/lib/plurimath/math/number.rb +3 -3
  84. data/lib/plurimath/math/symbol.rb +13 -5
  85. data/lib/plurimath/mathml/parser.rb +2 -0
  86. data/lib/plurimath/mathml/transform.rb +23 -15
  87. data/lib/plurimath/omml/transform.rb +22 -10
  88. data/lib/plurimath/unitsml.rb +2 -1
  89. data/lib/plurimath/utility.rb +29 -28
  90. data/lib/plurimath/version.rb +1 -1
  91. metadata +3 -3
  92. data/lib/plurimath/math/function/scarry.rb +0 -12
@@ -21,6 +21,7 @@ module Plurimath
21
21
  mathrm: Math::Function::FontStyle::Normal,
22
22
  textrm: Math::Function::FontStyle::Normal,
23
23
  italic: Math::Function::FontStyle::Italic,
24
+ mathit: Math::Function::FontStyle::Italic,
24
25
  mathbf: Math::Function::FontStyle::Bold,
25
26
  textbf: Math::Function::FontStyle::Bold,
26
27
  script: Math::Function::FontStyle::Script,
@@ -46,6 +47,8 @@ module Plurimath
46
47
  arccos
47
48
  arcsin
48
49
  arctan
50
+ liminf
51
+ limsup
49
52
  right
50
53
  sech
51
54
  sinh
@@ -58,6 +61,7 @@ module Plurimath
58
61
  min
59
62
  sec
60
63
  sin
64
+ sup
61
65
  deg
62
66
  det
63
67
  dim
@@ -65,6 +69,8 @@ module Plurimath
65
69
  gcd
66
70
  glb
67
71
  lub
72
+ lcm
73
+ ker
68
74
  tan
69
75
  cos
70
76
  cot
@@ -103,14 +109,13 @@ module Plurimath
103
109
  table = []
104
110
  table_data = []
105
111
  table_row = []
106
- table_separators = ["&", "\\\\"].freeze
107
112
  organize_options(array, column_align) if options
108
113
  string_columns = column_align&.map(&:value)
109
114
  array.each do |data|
110
- if data.is_a?(Math::Symbol) && table_separators.include?(data.value)
115
+ if data&.separate_table
111
116
  table_row << Math::Function::Td.new(filter_table_data(table_data).compact)
112
117
  table_data = []
113
- if data.value == "\\\\"
118
+ if data.linebreak
114
119
  organize_tds(table_row.flatten, string_columns.dup, options)
115
120
  table << Math::Function::Tr.new(table_row)
116
121
  table_row = []
@@ -230,12 +235,10 @@ module Plurimath
230
235
  end
231
236
 
232
237
  def filter_values(array)
233
- return array unless array.is_a?(Array)
238
+ return array unless array.is_a?(Array) || array.is_a?(Math::Formula)
234
239
 
235
- array = array.flatten.compact
236
- if array.length > 1
237
- return Math::Formula.new(array)
238
- end
240
+ array = array.is_a?(Math::Formula) ? array.value : array.flatten.compact
241
+ return Math::Formula.new(array) if array.length > 1
239
242
 
240
243
  array.first
241
244
  end
@@ -266,11 +269,6 @@ module Plurimath
266
269
  )
267
270
  end
268
271
 
269
- def find_class_name(object)
270
- new_object = object.value.first.parameter_one if object.is_a?(Math::Formula)
271
- get_class(new_object) unless new_object.nil?
272
- end
273
-
274
272
  def find_pos_chr(fonts_array, key)
275
273
  fonts_array.find { |d| d.is_a?(Hash) && d[key] }
276
274
  end
@@ -287,7 +285,8 @@ module Plurimath
287
285
  end
288
286
 
289
287
  def symbol_value(object, value)
290
- object.is_a?(Math::Symbol) && object.value.include?(value)
288
+ (object.is_a?(Math::Symbol) && object.value.include?(value)) ||
289
+ (value == "\\\\" && object.is_a?(Math::Function::Linebreak))
291
290
  end
292
291
 
293
292
  def td_value(td_object)
@@ -299,20 +298,18 @@ module Plurimath
299
298
  td_object
300
299
  end
301
300
 
302
- def mathml_unary_classes(text_array, omml: false)
301
+ def mathml_unary_classes(text_array, omml: false, unicode_only: false)
303
302
  return [] if text_array.empty?
304
303
 
305
304
  compacted = text_array.compact
306
- string = if compacted.count == 1
307
- compacted.first
308
- else
309
- compacted.join
310
- end
311
- return string unless string.is_a?(String)
305
+ return filter_values(compacted) unless compacted.any?(String)
312
306
 
307
+ string = compacted.join
313
308
  classes = Mathml::Constants::CLASSES
314
309
  unicode = string_to_html_entity(string)
315
- symbol = Mathml::Constants::UNICODE_SYMBOLS[unicode.strip.to_sym]
310
+ return Math::Symbol.new(unicode) if unicode_only && unicode
311
+
312
+ symbol = Mathml::Constants::UNICODE_SYMBOLS[unicode.strip.to_sym]
316
313
  if classes.include?(symbol&.strip)
317
314
  get_class(symbol.strip).new
318
315
  elsif classes.any?(string&.strip)
@@ -347,17 +344,21 @@ module Plurimath
347
344
  value
348
345
  end
349
346
 
350
- def join_attr_value(attrs, value)
347
+ def join_attr_value(attrs, value, unicode_only: false)
351
348
  if value.any?(String)
352
- new_value = mathml_unary_classes(value)
349
+ new_value = mathml_unary_classes(value, unicode_only: unicode_only)
353
350
  array_value = Array(new_value)
354
- attrs.nil? ? array_value : join_attr_value(attrs, array_value)
351
+ attrs.nil? ? array_value : join_attr_value(attrs, array_value, unicode_only: unicode_only)
355
352
  elsif attrs.nil?
356
353
  value
357
354
  elsif attrs.is_a?(String) && ["solid", "none"].include?(attrs.split.first.downcase)
358
355
  table_separator(attrs.split, value)
359
- elsif attrs.is_a?(Hash) && (attrs.key?(:accent) || attrs.key?(:accentunder))
360
- attr_is_accent(attrs, value)
356
+ elsif attrs.is_a?(Hash)
357
+ if (attrs.key?(:accent) || attrs.key?(:accentunder))
358
+ attr_is_accent(attrs, value)
359
+ elsif attrs.key?(:linebreak)
360
+ Math::Function::Linebreak.new(value.first, attrs)
361
+ end
361
362
  elsif attrs.is_a?(Math::Core)
362
363
  attr_is_function(attrs, value)
363
364
  end
@@ -470,7 +471,7 @@ module Plurimath
470
471
  end
471
472
 
472
473
  def valid_class(object)
473
- text = object.extract_class_from_text
474
+ text = object.extract_class_name_from_text
474
475
  (object.extractable? && Asciimath::Constants::SUB_SUP_CLASSES.include?(text)) ||
475
476
  Latex::Constants::SYMBOLS[text.to_sym] == :power_base
476
477
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plurimath
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plurimath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-21 00:00:00.000000000 Z
11
+ date: 2023-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -135,6 +135,7 @@ files:
135
135
  - lib/plurimath/math/function/liminf.rb
136
136
  - lib/plurimath/math/function/limits.rb
137
137
  - lib/plurimath/math/function/limsup.rb
138
+ - lib/plurimath/math/function/linebreak.rb
138
139
  - lib/plurimath/math/function/ln.rb
139
140
  - lib/plurimath/math/function/log.rb
140
141
  - lib/plurimath/math/function/longdiv.rb
@@ -162,7 +163,6 @@ files:
162
163
  - lib/plurimath/math/function/root.rb
163
164
  - lib/plurimath/math/function/rule.rb
164
165
  - lib/plurimath/math/function/scarries.rb
165
- - lib/plurimath/math/function/scarry.rb
166
166
  - lib/plurimath/math/function/sec.rb
167
167
  - lib/plurimath/math/function/sech.rb
168
168
  - lib/plurimath/math/function/semantics.rb
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "unary_function"
4
-
5
- module Plurimath
6
- module Math
7
- module Function
8
- class Scarry < UnaryFunction
9
- end
10
- end
11
- end
12
- end