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 +4 -4
- data/lib/plurimath/latex/constants.rb +1 -0
- data/lib/plurimath/latex/parse.rb +9 -3
- data/lib/plurimath/latex/transform.rb +16 -0
- data/lib/plurimath/math/formula.rb +1 -0
- data/lib/plurimath/math/function/fenced.rb +1 -0
- data/lib/plurimath/math/function/font_style.rb +1 -0
- data/lib/plurimath/math/function/sqrt.rb +4 -2
- data/lib/plurimath/math/function/text.rb +1 -1
- data/lib/plurimath/mathml/constants.rb +1 -0
- data/lib/plurimath/omml/parser.rb +16 -0
- data/lib/plurimath/omml/transform.rb +25 -7
- data/lib/plurimath/utility.rb +14 -23
- data/lib/plurimath/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fabed12e1b85fa2c5d7b2cacfebaf2bafb8481025f6f0a9b072649ff2991131
|
4
|
+
data.tar.gz: ec912de1e4e356af0d7458c0b2147ea9aee1fb4676506429ac5e4161cd974c79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d31d2f5b644402ab58c0f19a9c14e88f91fff26d44dff6c89484b66d45d3760087be0827002c87c3b9ca540ac7dd52ad2ceb014f4b0f6b16fc9f94630f823c70
|
7
|
+
data.tar.gz: 8f5ea828f70451af6ae075d8e06db4055145e096c83fc39b9a31cdcc57ddfff57afdd736e9f696d83e68d7b6c50ada74fa68f46acc00e878e08c1db22050ed2d
|
@@ -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)
|
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
|
-
(
|
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};/)
|
@@ -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
|
-
|
12
|
-
|
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
|
|
@@ -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::
|
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::
|
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
|
|
data/lib/plurimath/utility.rb
CHANGED
@@ -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
|
"〈": "〉",
|
93
84
|
"⌊": "⌋",
|
@@ -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
|
[
|
data/lib/plurimath/version.rb
CHANGED
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
|
+
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
|
11
|
+
date: 2023-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|