plurimath 0.8.1 → 0.8.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43bfa34fd25956b0ee8308569e2f42f83f25a714e1d1f736d0b39f9fb464a312
4
- data.tar.gz: df1e211c96baf094adb4d5fdb784b24d47750ac15c00ddfcd4ca9565f8d2e916
3
+ metadata.gz: f961f580d6f46c943b805f8c2f2a77281151ddcb76eab4a7e7adabbfe61b2b6b
4
+ data.tar.gz: fbe6a5651b11576a161fe0620780aa359151688d97fac674874679d138c8c34d
5
5
  SHA512:
6
- metadata.gz: 6119f28efdfb00ad31b7fa32bab9d21b95c50c92a24be7610988677cb9708debcc9a8fd71d1896cea6595f9fe2ca1e7b5c1e33ca109aa9577b9bd1d246fc8cc3
7
- data.tar.gz: 864c82b97e142080d9a5f2524e3879d0102721adb5788dbadfa1baaa3e7c89ea433c395e1b43d447556a72ae078b23b43d7dbb24d0032d9a19d2844bbfefc75b
6
+ metadata.gz: badfd5bd7eb9f2b84ef7604c21ab4f82fa93de5c52df760ee2fcc7ade85cd6900dbc527d41faf2c2521ae6dfbeb2cf79f8af0028927c6a1049bd921836fdec41
7
+ data.tar.gz: 886be496741ca30633f2ca6d25a5d39f1e5986065adb07cbc961a08ebb6fc04f4d060037afaafec59fb4fbcc5510c968aa1b06bfec366388d7bab1eaad2add99
@@ -896,6 +896,11 @@ module Plurimath
896
896
  Math::Formula.new([table] + expr.flatten.compact)
897
897
  end
898
898
 
899
+ rule(table: simple(:table),
900
+ left_right: simple(:left_right)) do
901
+ Math::Formula.new([table, left_right])
902
+ end
903
+
899
904
  rule(table: simple(:table),
900
905
  expr: simple(:expr)) do
901
906
  formula_array = [table]
@@ -288,26 +288,19 @@ module Plurimath
288
288
 
289
289
  def unitsml_post_processing(nodes)
290
290
  nodes.each.with_index do |node, index|
291
- if node.is_a?(Ox::Element) && node.attributes&.dig(:unitsml)
292
- previous = nodes[index-1]
293
- if previous && ["mi", "mn"].include?(previous.name)
294
- if text_in_tag?(node.nodes)
295
- nodes.insert(index, space_element(attributes: true))
296
- else
297
- nodes.insert(index, space_element)
298
- end
299
- end
300
-
301
- node.attributes.delete_if {|k, v| k == :unitsml }
291
+ if node.is_a?(Ox::Element) && node&.attributes&.dig(:unitsml)
292
+ pre_index = index - 1
293
+ pre_node = nodes[pre_index] if pre_index.zero? || pre_index.positive?
294
+ nodes.insert(index, space_element(node)) if valid_previous?(pre_node)
295
+ node.attributes.delete_if { |k, _| k == :unitsml }
302
296
  end
303
-
304
- unitsml_post_processing(node.nodes) if !node.nodes.any?(String)
297
+ unitsml_post_processing(node.nodes) if node.nodes.none?(String)
305
298
  end
306
299
  end
307
300
 
308
- def space_element(attributes: false)
301
+ def space_element(node)
309
302
  element = (ox_element("mo") << "&#x2062;")
310
- element.attributes[:rspace] = "thickmathspace" if attributes
303
+ element.attributes[:rspace] = "thickmathspace" if text_in_tag?(node.nodes)
311
304
  element
312
305
  end
313
306
 
@@ -327,6 +320,17 @@ module Plurimath
327
320
  def unicodemath_value
328
321
  (negated_value? || mini_sized?) ? value&.map(&:to_unicodemath)&.join : value&.map(&:to_unicodemath)&.join(" ")
329
322
  end
323
+
324
+ def valid_previous?(previous)
325
+ return unless previous
326
+
327
+ ["mi", "mn"].include?(previous.name) ||
328
+ inside_tag?(previous)
329
+ end
330
+
331
+ def inside_tag?(previous)
332
+ previous&.nodes&.any? { |node| valid_previous?(node) if node.is_a?(Ox::Element) }
333
+ end
330
334
  end
331
335
  end
332
336
  end
@@ -191,8 +191,12 @@ module Plurimath
191
191
  elsif flatten_mrow&.first&.is_nary_function? && flatten_mrow.length == 2
192
192
  nary_function = flatten_mrow.first
193
193
  if nary_function.is_ternary_function? && nary_function.all_values_exist?
194
- flatten_mrow[0] = nary_function.new_nary_function(flatten_mrow.delete_at(1))
195
- flatten_mrow
194
+ if nary_function.respond_to?(:new_nary_function)
195
+ flatten_mrow[0] = nary_function.new_nary_function(flatten_mrow.delete_at(1))
196
+ flatten_mrow
197
+ else
198
+ Utility.filter_values(flatten_mrow)
199
+ end
196
200
  elsif nary_function.is_binary_function? && nary_function.any_value_exist?
197
201
  flatten_mrow[0] = nary_function.new_nary_function(flatten_mrow.delete_at(1))
198
202
  flatten_mrow
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plurimath
4
- VERSION = "0.8.1"
4
+ VERSION = "0.8.2"
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.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-11 00:00:00.000000000 Z
11
+ date: 2024-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet