plurimath 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d69a05ccfdd97b4b313df9c6bec1682ab39078adbb43c8823880f90df142f6f1
4
- data.tar.gz: 441f919b29159720405b0bd685405e8ecb527a2716c0ac1427fff3c11575fa22
3
+ metadata.gz: 6fabed12e1b85fa2c5d7b2cacfebaf2bafb8481025f6f0a9b072649ff2991131
4
+ data.tar.gz: ec912de1e4e356af0d7458c0b2147ea9aee1fb4676506429ac5e4161cd974c79
5
5
  SHA512:
6
- metadata.gz: f97960509050b66f88da2d6bb7b5f5466d6a2b0d51e06ad63322e39859aa84416a4996ae6df3403dffc838ac2d14edcb5f707fec3b4607b0ce367c13cf0df1eb
7
- data.tar.gz: 1e7e533e85719d23428cdaad2aa218692802a20525059b6cd99951a0b63fffb2f00b4c6325f39bc039056f99c4ea72a80cb8a7660aebde916520f992ae69c5ea
6
+ metadata.gz: d31d2f5b644402ab58c0f19a9c14e88f91fff26d44dff6c89484b66d45d3760087be0827002c87c3b9ca540ac7dd52ad2ceb014f4b0f6b16fc9f94630f823c70
7
+ data.tar.gz: 8f5ea828f70451af6ae075d8e06db4055145e096c83fc39b9a31cdcc57ddfff57afdd736e9f696d83e68d7b6c50ada74fa68f46acc00e878e08c1db22050ed2d
@@ -3783,6 +3783,7 @@ module Plurimath
3783
3783
  UNDEROVER_CLASSES = %w[
3784
3784
  bmod
3785
3785
  pmod
3786
+ mod
3786
3787
  ].freeze
3787
3788
  LEFT_RIGHT_PARENTHESIS = {
3788
3789
  "\\backslash": "\",
@@ -15,7 +15,12 @@ module Plurimath
15
15
  end
16
16
 
17
17
  rule(:begining) do
18
- (slash >> str("begin") >> (str("{") >> symbol_text_or_integer >> str("*").as(:asterisk).maybe >> str("}")) >> optional_args)
18
+ (slash >> str("begin") >> (str("{") >> symbol_text_or_integer >> str("*").as(:asterisk) >> str("}")) >> optional_args.maybe) |
19
+ (slash >> str("begin") >> (str("{") >> symbol_text_or_integer >> str("}")))
20
+ end
21
+
22
+ rule(:array_begin) do
23
+ (str("\\begin{") >> str("array").as(:environment) >> str("}"))
19
24
  end
20
25
 
21
26
  rule(:ending) do
@@ -91,7 +96,8 @@ module Plurimath
91
96
  match["a-zA-Z"].as(:symbols) |
92
97
  match(/\d+(\.[0-9]+)|\d/).repeat(1).as(:number) |
93
98
  (str("\\\\").as("\\\\") >> match(/\s/).repeat) |
94
- str("\\ ").as(:space)
99
+ str("\\ ").as(:space) |
100
+ (str("\\operatorname{") >> match("[^}]").repeat.as(:symbols) >> str("}"))
95
101
  end
96
102
 
97
103
  rule(:intermediate_exp) do
@@ -133,7 +139,7 @@ module Plurimath
133
139
  (left_right.as(:left_right) >> base >> intermediate_exp.as(:subscript)) |
134
140
  left_right.as(:left_right) |
135
141
  (slash >> str("substack").as(:substack) >> intermediate_exp) |
136
- (begining >> array_args >> expression.as(:table_data) >> ending).as(:environment) |
142
+ (array_begin >> array_args >> expression.as(:table_data) >> ending).as(:environment) |
137
143
  (begining >> expression.as(:table_data) >> ending).as(:environment) |
138
144
  (slash >> environment >> intermediate_exp).as(:table_data) |
139
145
  power_base |
@@ -275,6 +275,14 @@ module Plurimath
275
275
  )
276
276
  end
277
277
 
278
+ rule(operant: simple(:operant),
279
+ supscript: simple(:supscript)) do
280
+ Math::Function::Power.new(
281
+ Math::Symbol.new(operant),
282
+ supscript,
283
+ )
284
+ end
285
+
278
286
  rule(sequence: simple(:sequence),
279
287
  expression: simple(:expr)) do
280
288
  [sequence, expr].compact
@@ -446,6 +454,14 @@ module Plurimath
446
454
  )
447
455
  end
448
456
 
457
+ rule(intermediate_exp: simple(:int_exp),
458
+ subscript: simple(:subscript)) do
459
+ Math::Function::Base.new(
460
+ int_exp,
461
+ subscript,
462
+ )
463
+ end
464
+
449
465
  rule(unicode_symbols: simple(:sym),
450
466
  subscript: simple(:subscript)) do
451
467
  Math::Function::Base.new(
@@ -139,6 +139,7 @@ module Plurimath
139
139
  def nary_tag_able?(display_style)
140
140
  value.length == 2 &&
141
141
  ["underover", "powerbase"].include?(value&.first&.class_name) &&
142
+ !value.first.parameter_one.is_a?(Function::FontStyle) &&
142
143
  (
143
144
  value&.first&.parameter_one&.to_omml_without_math_tag(display_style)&.length == 1 ||
144
145
  value&.first&.parameter_one.to_omml_without_math_tag(display_style).match?(/^&#x\w*\d*;$/)
@@ -84,6 +84,7 @@ module Plurimath
84
84
 
85
85
  def latex_paren(paren)
86
86
  return "" if paren.nil? || paren.empty?
87
+ return paren.gsub(":", "") if paren.include?(":") && ["{:", ":}"].include?(paren)
87
88
 
88
89
  paren = %w[{ }].include?(paren) ? "\\#{paren}" : paren
89
90
  paren = "\\#{Latex::Constants::UNICODE_SYMBOLS.invert[paren]}" if paren&.to_s&.match?(/&#x.{0,4};/)
@@ -57,6 +57,7 @@ module Plurimath
57
57
  r_tag,
58
58
  Array(parameter_one.font_style_t_tag(display_style)),
59
59
  )
60
+ [r_tag]
60
61
  end
61
62
  end
62
63
  end
@@ -8,8 +8,10 @@ module Plurimath
8
8
  class Sqrt < UnaryFunction
9
9
  def to_mathml_without_math_tag
10
10
  sqrt_tag = Utility.ox_element("msqrt")
11
- first_value = parameter_one&.to_mathml_without_math_tag
12
- sqrt_tag << first_value if first_value
11
+ Utility.update_nodes(
12
+ sqrt_tag,
13
+ Array(parameter_one&.to_mathml_without_math_tag),
14
+ )
13
15
  sqrt_tag
14
16
  end
15
17
 
@@ -55,7 +55,7 @@ module Plurimath
55
55
  html_value&.gsub!(PARSER_REGEX) do |_text|
56
56
  last_match = Regexp.last_match
57
57
  case lang
58
- when "mathml", "html"
58
+ when "mathml", "html", "omml"
59
59
  symbol_value(last_match[:unicode])
60
60
  else
61
61
  last_match[:unicode]
@@ -108,6 +108,7 @@ module Plurimath
108
108
  "&#x2032;": "'",
109
109
  "&#xa0;&#xa0;": "quad",
110
110
  "&#xa0;&#xa0;&#xa0;&#xa0;": "qquad",
111
+ "&#x203e;": "overline",
111
112
  "&#x2322;": "frown",
112
113
  "&#x22ef;": "cdots",
113
114
  "&#x22ee;": "vdots",
@@ -11,6 +11,22 @@ module Plurimath
11
11
  mr
12
12
  r
13
13
  ].freeze
14
+ SUPPORTED_FONTS = {
15
+ "sans-serif-bi": "sans-serif-bold-italic",
16
+ "double-struck": "double-struck",
17
+ "sans-serif-i": "sans-serif-italic",
18
+ "sans-serif-b": "bold-sans-serif",
19
+ "sans-serif-p": "sans-serif",
20
+ "fraktur-p": "fraktur",
21
+ "fraktur-b": "bold-fraktur",
22
+ "script-b": "bold-script",
23
+ "script-p": "script",
24
+ monospace: "monospace",
25
+ bi: "bold-italic",
26
+ p: "normal",
27
+ i: "italic",
28
+ b: "bold",
29
+ }.freeze
14
30
 
15
31
  def initialize(text)
16
32
  @text = text
@@ -12,7 +12,6 @@ module Plurimath
12
12
  rule(val: simple(:val)) { val }
13
13
  rule(scr: simple(:scr)) { scr }
14
14
  rule(sty: simple(:sty)) { sty }
15
- rule(dPr: subtree(:dpr)) { dpr }
16
15
  rule(num: subtree(:num)) { num }
17
16
  rule(den: subtree(:den)) { den }
18
17
  rule(fPr: subtree(:fPr)) { nil }
@@ -22,7 +21,6 @@ module Plurimath
22
21
  rule(deg: sequence(:deg)) { Utility.filter_values(deg) }
23
22
  rule(sub: sequence(:sub)) { Utility.filter_values(sub) }
24
23
  rule(sup: sequence(:sup)) { Utility.filter_values(sup) }
25
- rule(mtd: sequence(:mtd)) { mtd.flatten.compact }
26
24
  rule(boxPr: subtree(:box)) { nil }
27
25
  rule(argPr: subtree(:arg)) { nil }
28
26
  rule(accPr: subtree(:acc)) { acc.flatten.compact }
@@ -74,7 +72,7 @@ module Plurimath
74
72
  font = flatten_row.shift
75
73
  font.new(
76
74
  Utility.filter_values(flatten_row),
77
- Utility::OMML_FONTS.invert[font].to_s,
75
+ Utility::FONT_STYLES.key(font).to_s,
78
76
  )
79
77
  else
80
78
  Utility.filter_values(flatten_row)
@@ -107,19 +105,39 @@ module Plurimath
107
105
  )
108
106
  end
109
107
 
108
+ rule(dPr: subtree(:dpr)) do
109
+ dpr.reject! { |d| d.is_a?(Hash) }
110
+ dpr
111
+ end
112
+
113
+ rule(mtd: sequence(:mtd)) do
114
+ flatten_mtd = mtd&.flatten&.compact
115
+ if flatten_mtd.length > 1 && !flatten_mtd.first.is_a?(Math::Core)
116
+ font = flatten_mtd.shift
117
+ font.new(
118
+ Utility.filter_values(flatten_mtd),
119
+ Utility::FONT_STYLES.rassoc(font).first.to_s,
120
+ )
121
+ else
122
+ flatten_mtd
123
+ end
124
+ end
125
+
110
126
  rule(mr: subtree(:mr)) do
111
127
  row = []
112
128
  mr.each do |td|
113
- row << Math::Function::Td.new(
114
- Array(td),
115
- )
129
+ row << Math::Function::Td.new(Array(td))
116
130
  end
117
131
  Math::Function::Tr.new(row)
118
132
  end
119
133
 
120
134
  rule(rPr: subtree(:rpr)) do
121
135
  if rpr.is_a?(Array)
122
- Utility::OMML_FONTS[rpr.join("-").to_sym]
136
+ Utility::FONT_STYLES[
137
+ Omml::Parser::SUPPORTED_FONTS[
138
+ rpr&.join("-")&.to_sym,
139
+ ]&.to_sym,
140
+ ]
123
141
  end
124
142
  end
125
143
 
@@ -4,24 +4,30 @@ module Plurimath
4
4
  class Utility
5
5
  FONT_STYLES = {
6
6
  "double-struck": Math::Function::FontStyle::DoubleStruck,
7
+ "sans-serif-bold-italic": Math::Function::FontStyle::SansSerifBoldItalic,
8
+ "sans-serif-italic": Math::Function::FontStyle::SansSerifItalic,
9
+ "bold-sans-serif": Math::Function::FontStyle::BoldSansSerif,
7
10
  "sans-serif": Math::Function::FontStyle::SansSerif,
11
+ "bold-fraktur": Math::Function::FontStyle::BoldFraktur,
12
+ "bold-italic": Math::Function::FontStyle::BoldItalic,
13
+ "bold-script": Math::Function::FontStyle::BoldScript,
8
14
  monospace: Math::Function::FontStyle::Monospace,
9
- fraktur: Math::Function::FontStyle::Fraktur,
10
- script: Math::Function::FontStyle::Script,
11
- normal: Math::Function::FontStyle::Normal,
12
- bold: Math::Function::FontStyle::Bold,
13
15
  mathfrak: Math::Function::FontStyle::Fraktur,
14
16
  mathcal: Math::Function::FontStyle::Script,
17
+ fraktur: Math::Function::FontStyle::Fraktur,
15
18
  mathbb: Math::Function::FontStyle::DoubleStruck,
16
19
  mathtt: Math::Function::FontStyle::Monospace,
17
20
  mathsf: Math::Function::FontStyle::SansSerif,
18
21
  mathrm: Math::Function::FontStyle::Normal,
19
22
  textrm: Math::Function::FontStyle::Normal,
23
+ italic: Math::Function::FontStyle::Italic,
20
24
  mathbf: Math::Function::FontStyle::Bold,
21
25
  textbf: Math::Function::FontStyle::Bold,
26
+ script: Math::Function::FontStyle::Script,
27
+ normal: Math::Function::FontStyle::Normal,
28
+ bold: Math::Function::FontStyle::Bold,
22
29
  bbb: Math::Function::FontStyle::DoubleStruck,
23
30
  cal: Math::Function::FontStyle::Script,
24
- bf: Math::Function::FontStyle::Bold,
25
31
  sf: Math::Function::FontStyle::SansSerif,
26
32
  tt: Math::Function::FontStyle::Monospace,
27
33
  fr: Math::Function::FontStyle::Fraktur,
@@ -29,6 +35,7 @@ module Plurimath
29
35
  cc: Math::Function::FontStyle::Script,
30
36
  ii: Math::Function::FontStyle::Italic,
31
37
  bb: Math::Function::FontStyle::Bold,
38
+ bf: Math::Function::FontStyle::Bold,
32
39
  }.freeze
33
40
  ALIGNMENT_LETTERS = {
34
41
  c: "center",
@@ -72,22 +79,6 @@ module Plurimath
72
79
  max
73
80
  min
74
81
  ].freeze
75
- OMML_FONTS = {
76
- "sans-serif-bi": Math::Function::FontStyle::SansSerifBoldItalic,
77
- "sans-serif-i": Math::Function::FontStyle::SansSerifItalic,
78
- "sans-serif-b": Math::Function::FontStyle::BoldSansSerif,
79
- "double-struck": Math::Function::FontStyle::DoubleStruck,
80
- "sans-serif-p": Math::Function::FontStyle::SansSerif,
81
- "fraktur-p": Math::Function::FontStyle::Fraktur,
82
- "fraktur-b": Math::Function::FontStyle::BoldFraktur,
83
- "script-b": Math::Function::FontStyle::BoldScript,
84
- "script-p": Math::Function::FontStyle::Script,
85
- monospace: Math::Function::FontStyle::Monospace,
86
- bi: Math::Function::FontStyle::BoldItalic,
87
- p: Math::Function::FontStyle::Normal,
88
- i: Math::Function::FontStyle::Italic,
89
- b: Math::Function::FontStyle::Bold,
90
- }.freeze
91
82
  PARENTHESIS = {
92
83
  "&#x2329;": "&#x232a;",
93
84
  "&#x230a;": "&#x230b;",
@@ -562,8 +553,8 @@ module Plurimath
562
553
  close_paren = mrow.pop
563
554
  if mrow.length == 1 && mrow.first.is_a?(Math::Function::Table)
564
555
  table = mrow.first
565
- table.open_paren = open_paren
566
- table.close_paren = close_paren
556
+ table.open_paren = open_paren.value
557
+ table.close_paren = close_paren.value
567
558
  else
568
559
  mrow.replace(
569
560
  [
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plurimath
4
- VERSION = "0.4.3"
4
+ VERSION = "0.5.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.4.3
4
+ version: 0.5.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-08-30 00:00:00.000000000 Z
11
+ date: 2023-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet