mathml2asciimath 0.0.9 → 0.0.10

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: 43c4f60fbcf9b1119395d0149960d84e16746522ea840e5b57c25578b51a35b3
4
- data.tar.gz: 4a5d43531774ad6ed874e023a010b51a2bb0613cbf9ce024ad29d35eb4f91662
3
+ metadata.gz: 33c1a220449e32db88e0458a39097709a101f72e819830bcf96324aee0747bea
4
+ data.tar.gz: d8bf9f51b4b4be32c8a77005b956186559b0dc204325eb2d7d0a5fbae2403868
5
5
  SHA512:
6
- metadata.gz: 9855d06f3c4dafa65f336ed9f78efd3858d83d30a81a78aee3ba3f9c73d202c1bf772c13394f79940ed5451b171a8a112740d732d1c13cf10ae048b1725cb4f4
7
- data.tar.gz: b5f226d83b1418a2427e53527cc7154eff5aadd75563d653f459cb56f2bccbd312b1ce75cdee163d9974b7579112616010f387cf4e1caaf123b8ae0659e41f1c
6
+ metadata.gz: 4a4180b45fe10bfed82dc94f3191f89e3ad61761b913962fbf9ba4236785128bbf837658a1e27a16df3d4f252724d8ba78256efa061b50634ded28859d07fef7
7
+ data.tar.gz: 578be8ba61afb2b70639b458b43daf22fffc9cdee5574f4b8cbf9465d3910dd8b7b52916ac51fc6938c8c48d772b1da227ac0133933d84e645ddec167a7546e6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mathml2asciimath (0.0.8)
4
+ mathml2asciimath (0.0.9)
5
5
  htmlentities (~> 4.3.4)
6
6
  nokogiri (>= 1.10.4)
7
7
 
@@ -15,7 +15,7 @@ GEM
15
15
  docile (1.3.2)
16
16
  ffi (1.12.2)
17
17
  formatador (0.2.5)
18
- guard (2.16.1)
18
+ guard (2.16.2)
19
19
  formatador (>= 0.2.4)
20
20
  listen (>= 2.7, < 4.0)
21
21
  lumberjack (>= 1.0.12, < 2.0)
@@ -34,21 +34,21 @@ GEM
34
34
  rb-fsevent (~> 0.10, >= 0.10.3)
35
35
  rb-inotify (~> 0.9, >= 0.9.10)
36
36
  lumberjack (1.2.4)
37
- method_source (0.9.2)
37
+ method_source (1.0.0)
38
38
  mini_portile2 (2.4.0)
39
39
  nenv (0.3.0)
40
- nokogiri (1.10.8)
40
+ nokogiri (1.10.9)
41
41
  mini_portile2 (~> 2.4.0)
42
42
  notiffany (0.1.3)
43
43
  nenv (~> 0.1)
44
44
  shellany (~> 0.0)
45
45
  parallel (1.19.1)
46
- parser (2.7.0.3)
46
+ parser (2.7.1.1)
47
47
  ast (~> 2.4.0)
48
48
  powerpack (0.1.2)
49
- pry (0.12.2)
50
- coderay (~> 1.1.0)
51
- method_source (~> 0.9.0)
49
+ pry (0.13.1)
50
+ coderay (~> 1.1)
51
+ method_source (~> 1.0)
52
52
  rainbow (3.0.0)
53
53
  rake (12.3.3)
54
54
  rb-fsevent (0.10.3)
@@ -60,7 +60,7 @@ GEM
60
60
  rspec-mocks (~> 3.9.0)
61
61
  rspec-core (3.9.1)
62
62
  rspec-support (~> 3.9.1)
63
- rspec-expectations (3.9.0)
63
+ rspec-expectations (3.9.1)
64
64
  diff-lcs (>= 1.2.0, < 2.0)
65
65
  rspec-support (~> 3.9.0)
66
66
  rspec-match_fuzzy (0.1.3)
@@ -81,10 +81,10 @@ GEM
81
81
  simplecov (0.18.5)
82
82
  docile (~> 1.1)
83
83
  simplecov-html (~> 0.11)
84
- simplecov-html (0.12.1)
84
+ simplecov-html (0.12.2)
85
85
  thor (1.0.1)
86
86
  timecop (0.9.1)
87
- unicode-display_width (1.6.1)
87
+ unicode-display_width (1.7.0)
88
88
 
89
89
  PLATFORMS
90
90
  ruby
@@ -103,4 +103,4 @@ DEPENDENCIES
103
103
  timecop (~> 0.9)
104
104
 
105
105
  BUNDLED WITH
106
- 2.0.2
106
+ 2.1.4
data/bin/m2a.rb CHANGED
@@ -1,9 +1,9 @@
1
- require "mathml2asciimath"
1
+ require 'mathml2asciimath'
2
2
 
3
- STDIN.set_encoding("UTF-8")
3
+ STDIN.set_encoding('UTF-8')
4
4
  while a = gets
5
5
  matches = a.split(%r{(<math.*?</math>)})
6
- out = ""
6
+ out = ''
7
7
  matches.each do |x|
8
8
  if /<math/.match x
9
9
  out += MathML2AsciiMath.m2a(x)
@@ -1,5 +1,5 @@
1
1
  require_relative "mathml2asciimath/version"
2
2
  require_relative "mathml2asciimath/m2a"
3
3
 
4
- require "nokogiri"
5
- require "htmlentities"
4
+ require 'nokogiri'
5
+ require 'htmlentities'
@@ -5,203 +5,206 @@ require "pp"
5
5
  module MathML2AsciiMath
6
6
 
7
7
  def self.m2a(x)
8
- docxml = Nokogiri::XML(x)
9
- parse(docxml.root).gsub(/ /, " ").
10
- sub(/^\s+/, "").
11
- sub(/\s+$/, "")
8
+ normalized = x
9
+
10
+ # &:noblanks skips non-significant whitespaces in MathML
11
+ docxml = Nokogiri::XML.parse(normalized, &:noblanks)
12
+
13
+ # Get rid of things like
14
+ # <mtext>&#x2009;</mtext>
15
+ parse(docxml.root).gsub(/[[:blank:]]/, ' ').unicode_normalize.squeeze(' ')
12
16
  end
13
17
 
14
18
  def self.encodechars(x)
15
- x.gsub(/\u03b1/, "alpha").
16
- gsub(/\u03b2/, "beta").
17
- gsub(/\u03b3/, "gamma").
18
- gsub(/\u0393/, "Gamma").
19
- gsub(/\u03b4/, "delta").
20
- gsub(/\u0394/, "Delta").
21
- gsub(/\u2206/, "Delta").
22
- gsub(/\u03b5/, "epsilon").
23
- gsub(/\u025b/, "varepsilon").
24
- gsub(/\u03b6/, "zeta").
25
- gsub(/\u03b7/, "eta").
26
- gsub(/\u03b8/, "theta").
27
- gsub(/\u0398/, "Theta").
28
- gsub(/\u03d1/, "vartheta").
29
- gsub(/\u03b9/, "iota").
30
- gsub(/\u03ba/, "kappa").
31
- gsub(/\u03bb/, "lambda").
32
- gsub(/\u039b/, "Lambda").
33
- gsub(/\u03bc/, "mu").
34
- gsub(/\u03bd/, "nu").
35
- gsub(/\u03be/, "xi").
36
- gsub(/\u039e/, "Xi").
37
- gsub(/\u03c0/, "pi").
38
- gsub(/\u03a0/, "Pi").
39
- gsub(/\u03c1/, "rho").
40
- gsub(/\u03c2/, "beta").
41
- gsub(/\u03c3/, "sigma").
42
- gsub(/\u03a3/, "Sigma").
43
- gsub(/\u03c4/, "tau").
44
- gsub(/\u03c5/, "upsilon").
45
- gsub(/\u03c6/, "phi").
46
- gsub(/\u03a6/, "Phi").
47
- gsub(/\u03d5/, "varphi").
48
- gsub(/\u03c7/, "chi").
49
- gsub(/\u03c8/, "psi").
50
- gsub(/\u03a8/, "Psi").
51
- gsub(/\u03c9/, "omega").
52
- gsub(/\u03a9/, "omega").
53
- gsub(/\u22c5/, "*").
54
- gsub(/\u2219/, "*").
55
- gsub(/\u00b7/, "*").
56
- gsub(/\u2217/, "**").
57
- gsub(/\u22c6/, "***").
58
- gsub(/\//, "//").
19
+ x.gsub(/\u03b1/, 'alpha').
20
+ gsub(/\u03b2/, 'beta').
21
+ gsub(/\u03b3/, 'gamma').
22
+ gsub(/\u0393/, 'Gamma').
23
+ gsub(/\u03b4/, 'delta').
24
+ gsub(/\u0394/, 'Delta').
25
+ gsub(/\u2206/, 'Delta').
26
+ gsub(/\u03b5/, 'epsilon').
27
+ gsub(/\u025b/, 'varepsilon').
28
+ gsub(/\u03b6/, 'zeta').
29
+ gsub(/\u03b7/, 'eta').
30
+ gsub(/\u03b8/, 'theta').
31
+ gsub(/\u0398/, 'Theta').
32
+ gsub(/\u03d1/, 'vartheta').
33
+ gsub(/\u03b9/, 'iota').
34
+ gsub(/\u03ba/, 'kappa').
35
+ gsub(/\u03bb/, 'lambda').
36
+ gsub(/\u039b/, 'Lambda').
37
+ gsub(/\u03bc/, 'mu').
38
+ gsub(/\u03bd/, 'nu').
39
+ gsub(/\u03be/, 'xi').
40
+ gsub(/\u039e/, 'Xi').
41
+ gsub(/\u03c0/, 'pi').
42
+ gsub(/\u03a0/, 'Pi').
43
+ gsub(/\u03c1/, 'rho').
44
+ gsub(/\u03c2/, 'beta').
45
+ gsub(/\u03c3/, 'sigma').
46
+ gsub(/\u03a3/, 'Sigma').
47
+ gsub(/\u03c4/, 'tau').
48
+ gsub(/\u03c5/, 'upsilon').
49
+ gsub(/\u03c6/, 'phi').
50
+ gsub(/\u03a6/, 'Phi').
51
+ gsub(/\u03d5/, 'varphi').
52
+ gsub(/\u03c7/, 'chi').
53
+ gsub(/\u03c8/, 'psi').
54
+ gsub(/\u03a8/, 'Psi').
55
+ gsub(/\u03c9/, 'omega').
56
+ gsub(/\u03a9/, 'omega').
57
+ gsub(/\u22c5/, '*').
58
+ gsub(/\u2219/, '*').
59
+ gsub(/\u00b7/, '*').
60
+ gsub(/\u2217/, '**').
61
+ gsub(/\u22c6/, '***').
62
+ gsub(/\//, '//').
59
63
  gsub(/\\/, "\\\\").
60
- gsub(/\u00d7/, "xx").
61
- gsub(/\u22c9/, "|><").
62
- gsub(/\u22ca/, "><|").
63
- gsub(/\u22c8/, "|><|").
64
- gsub(/\u00f7/, "-:").
65
- gsub(/\u2218/, "@").
66
- gsub(/\u2295/, "o+").
67
- gsub(/\u2a01/, "o+").
68
- gsub(/\u2297/, "ox").
69
- gsub(/\u2299/, "o.").
70
- gsub(/\u2211/, "sum").
71
- gsub(/\u220f/, "prod").
72
- gsub(/\u2227/, "^^").
73
- gsub(/\u22c0/, "^^^").
74
- gsub(/\u2228/, "vv").
75
- gsub(/\u22c1/, "vvv").
76
- gsub(/\u2229/, "nn").
77
- gsub(/\u22c2/, "nnn").
78
- gsub(/\u222a/, "uu").
79
- gsub(/\u22c3/, "uuu").
80
- gsub(/\u2260/, "!=").
81
- gsub(/\u2264/, "<=").
82
- gsub(/\u2265/, ">=").
83
- gsub(/\u227a/, "-<").
84
- gsub(/\u227b/, ">-").
85
- gsub(/\u2aaf/, "-<=").
86
- gsub(/\u2ab0/, ">-=").
87
- gsub(/\u2208/, "in").
88
- gsub(/\u2209/, "!in").
89
- gsub(/\u2282/, "sub").
90
- gsub(/\u2283/, "sup").
91
- gsub(/\u2286/, "sube").
92
- gsub(/\u2287/, "supe").
93
- gsub(/\u2261/, "-=").
94
- gsub(/\u2245/, "~=").
95
- gsub(/\u2248/, "~~").
96
- gsub(/\u221d/, "prop").
97
- gsub(/\u00ac/, "not").
98
- gsub(/\u21d2/, "=>").
99
- gsub(/\u21d4/, "<=>").
100
- gsub(/\u2200/, "AA").
101
- gsub(/\u2203/, "EE").
102
- gsub(/\u22a5/, "_|_").
103
- gsub(/\u22a4/, "TT").
104
- gsub(/\u22a2/, "|--").
105
- gsub(/\u22a8/, "|==").
106
- gsub(/\u22a8/, "|==").
107
- gsub(/\u2329/, "(:").
108
- gsub(/\u232a/, ":)").
109
- gsub(/\u2329/, "<<").
110
- gsub(/\u27e8/, "<<").
111
- gsub(/\u232a/, ">>").
112
- gsub(/\u27e9/, ">>").
113
- gsub(/\u222e/, "oint").
114
- gsub(/\u2202/, "del").
115
- gsub(/\u2207/, "grad").
116
- gsub(/\u00b1/, "+-").
64
+ gsub(/\u00d7/, 'xx').
65
+ gsub(/\u22c9/, '|><').
66
+ gsub(/\u22ca/, '><|').
67
+ gsub(/\u22c8/, '|><|').
68
+ gsub(/\u00f7/, '-:').
69
+ gsub(/\u2218/, '@').
70
+ gsub(/\u2295/, 'o+').
71
+ gsub(/\u2a01/, 'o+').
72
+ gsub(/\u2297/, 'ox').
73
+ gsub(/\u2299/, 'o.').
74
+ gsub(/\u2211/, 'sum').
75
+ gsub(/\u220f/, 'prod').
76
+ gsub(/\u2227/, '^^').
77
+ gsub(/\u22c0/, '^^^').
78
+ gsub(/\u2228/, 'vv').
79
+ gsub(/\u22c1/, 'vvv').
80
+ gsub(/\u2229/, 'nn').
81
+ gsub(/\u22c2/, 'nnn').
82
+ gsub(/\u222a/, 'uu').
83
+ gsub(/\u22c3/, 'uuu').
84
+ gsub(/\u2260/, '!=').
85
+ gsub(/\u2264/, '<=').
86
+ gsub(/\u2265/, '>=').
87
+ gsub(/\u227a/, '-<').
88
+ gsub(/\u227b/, '>-').
89
+ gsub(/\u2aaf/, '-<=').
90
+ gsub(/\u2ab0/, '>-=').
91
+ gsub(/\u2208/, 'in').
92
+ gsub(/\u2209/, '!in').
93
+ gsub(/\u2282/, 'sub').
94
+ gsub(/\u2283/, 'sup').
95
+ gsub(/\u2286/, 'sube').
96
+ gsub(/\u2287/, 'supe').
97
+ gsub(/\u2261/, '-=').
98
+ gsub(/\u2245/, '~=').
99
+ gsub(/\u2248/, '~~').
100
+ gsub(/\u221d/, 'prop').
101
+ gsub(/\u00ac/, 'not').
102
+ gsub(/\u21d2/, '=>').
103
+ gsub(/\u21d4/, '<=>').
104
+ gsub(/\u2200/, 'AA').
105
+ gsub(/\u2203/, 'EE').
106
+ gsub(/\u22a5/, '_|_').
107
+ gsub(/\u22a4/, 'TT').
108
+ gsub(/\u22a2/, '|--').
109
+ gsub(/\u22a8/, '|==').
110
+ gsub(/\u22a8/, '|==').
111
+ gsub(/\u2329/, '(:').
112
+ gsub(/\u232a/, ':)').
113
+ gsub(/\u2329/, '<<').
114
+ gsub(/\u27e8/, '<<').
115
+ gsub(/\u232a/, '>>').
116
+ gsub(/\u27e9/, '>>').
117
+ gsub(/\u222b/, 'int').
118
+ gsub(/\u222e/, 'oint').
119
+ gsub(/\u2202/, 'del').
120
+ gsub(/\u2207/, 'grad').
121
+ gsub(/\u00b1/, '+-').
117
122
  gsub(/\u2205/, "O/").
118
- gsub(/\u221e/, "oo").
119
- gsub(/\u2135/, "aleph").
120
- gsub(/\u2234/, ":.").
123
+ gsub(/\u221e/, 'oo').
124
+ gsub(/\u2135/, 'aleph').
125
+ gsub(/\u2234/, ':.').
121
126
  gsub(/\u2235/, ":'").
122
127
  gsub(/\u2220/, "/_").
123
128
  gsub(/\u25b3/, "/_\\").
124
129
  gsub(/\u2032/, "'").
125
- gsub(/~/, "tilde").
126
- gsub(/\u00a0\u00a0\u00a0\u00a0/, "qquad").
127
- gsub(/\u00a0\u00a0/, "quad").
130
+ gsub(/~/, 'tilde').
131
+ gsub(/\u00a0\u00a0\u00a0\u00a0/, 'qquad').
132
+ gsub(/\u00a0\u00a0/, 'quad').
128
133
  gsub(/\u00a0/, "\\ ").
129
- gsub(/\u2322/, "frown").
130
- gsub(/\u00a0/, "quad").
131
- gsub(/\u22ef/, "cdots").
132
- gsub(/\u22ee/, "vdots").
133
- gsub(/\u22f1/, "ddots").
134
- gsub(/\u22c4/, "diamond").
135
- gsub(/\u25a1/, "square").
136
- gsub(/\u230a/, "|__").
137
- gsub(/\u230b/, "__|").
138
- gsub(/\u2308/, "|~").
139
- gsub(/\u2309/, "~|").
140
- gsub(/\u2102/, "CC").
141
- gsub(/\u2115/, "NN").
142
- gsub(/\u211a/, "QQ").
143
- gsub(/\u211d/, "RR").
144
- gsub(/\u2124/, "ZZ").
145
- gsub(/\u2191/, "uarr").
146
- gsub(/\u2193/, "darr").
147
- gsub(/\u2190/, "larr").
148
- gsub(/\u2194/, "harr").
149
- gsub(/\u21d2/, "rArr").
150
- gsub(/\u21d0/, "lArr").
151
- gsub(/\u21d4/, "hArr").
152
- gsub(/\u2192/, "->").
153
- gsub(/\u21a3/, ">->").
154
- gsub(/\u21a0/, "->>").
155
- gsub(/\u2916/, ">->>").
156
- gsub(/\u21a6/, "|->").
157
- gsub(/\u2026/, "...").
158
- gsub(/\u2212/, "-").
159
- gsub(/\u2061/, ""). # function application
160
- gsub(/\u2751/, "square")
134
+ gsub(/\u2322/, 'frown').
135
+ gsub(/\u00a0/, 'quad').
136
+ gsub(/\u22ef/, 'cdots').
137
+ gsub(/\u22ee/, 'vdots').
138
+ gsub(/\u22f1/, 'ddots').
139
+ gsub(/\u22c4/, 'diamond').
140
+ gsub(/\u25a1/, 'square').
141
+ gsub(/\u230a/, '|__').
142
+ gsub(/\u230b/, '__|').
143
+ gsub(/\u2308/, '|~').
144
+ gsub(/\u2309/, '~|').
145
+ gsub(/\u2102/, 'CC').
146
+ gsub(/\u2115/, 'NN').
147
+ gsub(/\u211a/, 'QQ').
148
+ gsub(/\u211d/, 'RR').
149
+ gsub(/\u2124/, 'ZZ').
150
+ gsub(/\u2191/, 'uarr').
151
+ gsub(/\u2193/, 'darr').
152
+ gsub(/\u2190/, 'larr').
153
+ gsub(/\u2194/, 'harr').
154
+ gsub(/\u21d2/, 'rArr').
155
+ gsub(/\u21d0/, 'lArr').
156
+ gsub(/\u21d4/, 'hArr').
157
+ gsub(/\u2192/, '->').
158
+ gsub(/\u21a3/, '>->').
159
+ gsub(/\u21a0/, '->>').
160
+ gsub(/\u2916/, '>->>').
161
+ gsub(/\u21a6/, '|->').
162
+ gsub(/\u2026/, '...').
163
+ gsub(/\u2212/, '-').
164
+ gsub(/\u2061/, ''). # function application
165
+ gsub(/\u2751/, 'square').
166
+ gsub(/[\u2028\u2029]/, ' ') # normalize thin spaces like \u2009, \u2008
167
+ end
168
+
169
+ def self.join_parsed_children(children, delimiter=' ')
170
+ children.map do |n|
171
+ parse(n).strip
172
+ end.join(delimiter)
161
173
  end
162
174
 
163
175
  def self.parse(node)
164
- out = ""
176
+ out = ''
165
177
  if node.text?
166
178
  return encodechars(HTMLEntities.new.decode(node.text))
167
179
  end
168
180
 
169
- case node.name.sub(/^[^:]*:/, "")
181
+ case node.name.sub(/^[^:]*:/, '')
170
182
  when "math"
171
- outarr = []
172
- node.elements.each { |n| outarr << parse(n).strip }
173
- return outarr.join(" ")
183
+ return join_parsed_children(node.elements)
174
184
 
175
185
  when "annotation"
176
- return ""
186
+ return ''
177
187
 
178
188
  when "semantics"
179
- outarr = []
180
- node.elements.each { |n| outarr << parse(n).strip }
181
- return outarr.join(" ")
189
+ return join_parsed_children(node.elements)
182
190
 
183
191
  when "mrow"
184
- outarr = []
185
- node.children.each { |n| outarr << parse(n).strip }
186
- out = outarr.join(" ")
187
- if %w{mfrac msub munder munderover}.include? node.parent.name.sub(/^[^:]*:/, "")
192
+ out = join_parsed_children(node.elements)
193
+ if %w[mfrac msub munder munderover].include? node.parent.name.sub(/^[^:]*:/, '')
188
194
  out = "(#{out})"
189
195
  end
190
196
  return out
191
197
 
192
198
  when "mfenced"
193
- outarr = []
194
- open = node["open"] || "("
195
- close = node["close"] || ")"
199
+ sym_open = node["open"] || "("
200
+ sym_close = node["close"] || ")"
201
+
196
202
  separator = "," # TODO currently ignore the supplied separators
197
- node.elements.each { |n| outarr << parse(n).strip }
198
- out = outarr.join(separator)
199
- return "#{open}#{out}#{close}"
203
+ out = join_parsed_children(node.elements, separator)
204
+ return "#{sym_open}#{out}#{sym_close}"
200
205
 
201
206
  when "msqrt"
202
- outarr = []
203
- node.elements.each { |n| outarr << parse(n).strip }
204
- return "sqrt(#{outarr.join(" ")})"
207
+ return "sqrt(#{join_parsed_children(node.elements)})"
205
208
 
206
209
  when "mfrac"
207
210
  return "(#{parse(node.elements[0])})/(#{parse(node.elements[1])})"
@@ -209,13 +212,13 @@ module MathML2AsciiMath
209
212
  when "msup"
210
213
  sup = parse(node.elements[1])
211
214
  sup = "(#{sup})" unless sup.length == 1
212
- op = parse(node.elements[0]).gsub(/ $/, "")
215
+ op = parse(node.elements[0]).gsub(/ $/, '')
213
216
  return "#{op}^#{sup}"
214
217
 
215
218
  when "msub"
216
219
  sub = parse(node.elements[1])
217
220
  sub = "(#{sub})" unless sub.length == 1
218
- op = parse(node.elements[0]).gsub(/ $/, "")
221
+ op = parse(node.elements[0]).gsub(/ $/, '')
219
222
  return "#{op}_#{sub}"
220
223
 
221
224
  when "munderover", "msubsup"
@@ -223,24 +226,26 @@ module MathML2AsciiMath
223
226
  sub = "(#{sub})" unless sub.length == 1
224
227
  sup = parse(node.elements[2])
225
228
  sup = "(#{sup})" unless sup.length == 1
226
- op = parse(node.elements[0]).gsub(/ $/, "")
229
+ op = parse(node.elements[0]).gsub(/ $/, '')
227
230
  return "#{op}_#{sub}^#{sup}"
228
231
 
229
232
  when "munder"
230
- elem1 = parse(node.elements[1]).sub(/^\s+/, "").sub(/\s+$/, "")
233
+ elem1 = parse(node.elements[1]).strip
231
234
  accent = case elem1
232
235
  when "\u0332" then "ul"
233
236
  when "\u23df" then "ubrace"
234
237
  else
235
238
  "underset"
236
239
  end
240
+
237
241
  if accent == "underset"
238
242
  return "underset(#{elem1})(#{parse(node.elements[0])})"
239
243
  else
240
244
  return "#{accent} #{parse(node.elements[0])}"
241
245
  end
246
+
242
247
  when "mover"
243
- elem1 = parse(node.elements[1]).sub(/^\s+/, "").sub(/\s+$/, "")
248
+ elem1 = parse(node.elements[1]).strip
244
249
  accent = case elem1
245
250
  when "\u005e" then "hat"
246
251
  when "\u00af" then "bar"
@@ -252,6 +257,7 @@ module MathML2AsciiMath
252
257
  else
253
258
  "overset"
254
259
  end
260
+
255
261
  if accent == "overset"
256
262
  return "overset(#{elem1})(#{parse(node.elements[0])})"
257
263
  else
@@ -259,46 +265,38 @@ module MathML2AsciiMath
259
265
  end
260
266
 
261
267
  when "mtable"
262
- outarr = []
263
- node.elements.each { |n| outarr << parse(n).strip }
264
- return "[#{outarr.join(",")}]"
268
+ return "[#{join_parsed_children(node.elements, ',')}]"
265
269
 
266
270
  when "mtr"
267
- outarr = []
268
- node.elements.each { |n| outarr << parse(n).strip }
269
- return "[#{outarr.join(",")}]"
271
+ return "[#{join_parsed_children(node.elements, ',')}]"
270
272
 
271
273
  when "mtd"
272
- outarr = []
273
- node.elements.each { |n| outarr << parse(n).strip }
274
- return "#{outarr.join(",")}"
274
+ return join_parsed_children(node.elements, ',')
275
275
 
276
276
  when "mn", "mtext"
277
- outarr = []
278
- node.children.each { |n| outarr << parse(n).strip }
279
- return "#{outarr.join("")}"
277
+ return join_parsed_children(node.children, '')
280
278
 
281
279
  when "mi"
280
+ # FIXME: What does this comment have to do with Word?
282
281
  # mi is not meant to have space around it, but Word is conflating operators and operands
283
- outarr = []
284
- node.children.each { |n| outarr << parse(n).strip }
285
- out = outarr.join(" ")
286
- out = " #{out} " if /[^a-zA-Z0-9',]|[a-z][a-z]/.match out
282
+ out = join_parsed_children(node.children)
283
+
284
+ # FIXME: Why do we need to add extra spaces?
285
+ # out = " #{out} " if /[^a-zA-Z0-9',]|[a-z][a-z]/.match out
287
286
  return out
288
287
 
289
288
  when "mo"
290
- outarr = []
291
- node.children.each { |n| outarr << parse(n).strip }
292
- out = outarr.join(" ")
293
- out = " #{out} " unless node["fence"]
289
+ out = join_parsed_children(node.children)
290
+ out = " #{out} " unless node['fence']
294
291
  return out
295
292
 
296
293
  when "mstyle"
297
- outarr = []
298
- node.children.each { |n| outarr << parse(n).strip }
299
- out = outarr.join(" ")
294
+ return join_parsed_children(node.children)
295
+
300
296
  else
301
- node.to_xml
297
+ "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">" +
298
+ node.to_xml +
299
+ "</math>"
302
300
 
303
301
  end
304
302
  end
@@ -1,4 +1,4 @@
1
1
  module MathML2AsciiMath
2
- VERSION = "0.0.9".freeze
2
+ VERSION = '0.0.10'.freeze
3
3
  end
4
4
 
@@ -1,319 +1,312 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  RSpec.describe MathML2AsciiMath do
4
- it "processes some MathML" do
5
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
4
+ it 'processes mstyle and mrow' do
5
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip.strip
6
6
  <math xmlns="http://www.w3.org/1998/Math/MathML">
7
- <mstyle>
8
- <mrow>
9
- <mi>a</mi> <mo>⋄</mo> <msup><mi>x</mi><mn>2</mn></msup>
10
- <mo>+</mo><mi>b</mi><mo>×</mo><mi>x</mi>
11
- <mo>+</mo><msub><mi>c</mi><mn>3</mn></msub>
12
- </mrow>
13
- </mstyle>
7
+ <mstyle>
8
+ <mrow>
9
+ <mi>a</mi> <mo>⋄</mo> <msup><mi>x</mi><mn>2</mn></msup>
10
+ <mo>+</mo><mi>b</mi><mo>×</mo><mi>x</mi>
11
+ <mo>+</mo><msub><mi>c</mi><mn>3</mn></msub>
12
+ </mrow>
13
+ </mstyle>
14
14
  </math>
15
15
  INPUT
16
16
  a diamond x^2 + b xx x + c_3
17
17
  OUTPUT
18
18
  end
19
19
 
20
- it "processes some MathML" do
21
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
20
+ it 'processes mrow' do
21
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
22
22
  <math xmlns="http://www.w3.org/1998/Math/MathML">
23
- <mrow>
24
- <mi>a</mi> <mo>⋄</mo> <msup><mi>x</mi><mn>2d</mn></msup>
25
- <mo>+</mo><mi>b</mi><mo>×</mo><mi>x</mi>
26
- <mo>+</mo><msub><mi>c</mi><mn>ab</mn></msub>
27
- </mrow>
23
+ <mrow>
24
+ <mi>a</mi> <mo>⋄</mo> <msup><mi>x</mi><mn>2d</mn></msup>
25
+ <mo>+</mo><mi>b</mi><mo>×</mo><mi>x</mi>
26
+ <mo>+</mo><msub><mi>c</mi><mn>ab</mn></msub>
27
+ </mrow>
28
28
  </math>
29
29
  INPUT
30
30
  a diamond x^(2d) + b xx x + c_(ab)
31
31
  OUTPUT
32
32
  end
33
33
 
34
- it "processes some MathML" do
35
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
34
+ it 'processes mfrac' do
35
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
36
36
  <math xmlns="http://www.w3.org/1998/Math/MathML">
37
- <mfrac>
38
- <mrow> <mn> 1 </mn> <mo> + </mo> <msqrt> <mn> 5 </mn> </msqrt> </mrow>
39
- <mn> 2 </mn>
40
- </mfrac>
37
+ <mfrac>
38
+ <mrow> <mn> 1 </mn> <mo> + </mo> <msqrt> <mn> 5 </mn> </msqrt> </mrow>
39
+ <mn> 2 </mn>
40
+ </mfrac>
41
41
  </math>
42
42
  INPUT
43
- (( 1 + sqrt( 5 ) ))/( 2 )
43
+ ((1 + sqrt(5)))/(2)
44
44
  OUTPUT
45
45
  end
46
46
 
47
- it "processes some MathML" do
48
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
47
+ it 'processes mfenced default' do
48
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
49
49
  <math xmlns="http://www.w3.org/1998/Math/MathML">
50
- <mfenced><mrow><mi> a </mi> <mo> + </mo> <mi> b </mi></mrow></mfenced>
50
+ <mfenced><mrow><mi> a </mi> <mo> + </mo> <mi> b </mi></mrow></mfenced>
51
51
  </math>
52
52
  INPUT
53
- ( a + b )
53
+ (a + b)
54
54
  OUTPUT
55
55
  end
56
56
 
57
- it "processes some MathML" do
58
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
57
+ it 'processes mfenced with unmatching braces' do
58
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.to_s.strip
59
59
  <math xmlns="http://www.w3.org/1998/Math/MathML">
60
- <mfenced open="["> <mn> 0 </mn> <mn> 1 </mn> </mfenced>
60
+ <mfenced open="["> <mn> 0 </mn> <mn> 1 </mn> </mfenced>
61
61
  </math>
62
62
  INPUT
63
- [ 0 , 1 )
63
+ [0,1)
64
64
  OUTPUT
65
65
  end
66
66
 
67
- it "processes some MathML" do
68
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
67
+ it 'processes munderover' do
68
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
69
69
  <math xmlns="http://www.w3.org/1998/Math/MathML">
70
- <munderover>
71
- <mo>&#x222B;</mo> <mn>0</mn> <mi>&#x221E;</mi>
72
- </munderover>
70
+ <munderover>
71
+ <mo>&#x222B;</mo> <mn>0</mn> <mi>&#x221E;</mi>
72
+ </munderover>
73
73
  </math>
74
74
  INPUT
75
- \u222B_0^( oo )
75
+ int_0^(oo)
76
76
  OUTPUT
77
77
  end
78
78
 
79
- it "processes some MathML" do
80
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
79
+ it 'processes msubsup' do
80
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
81
81
  <math xmlns="http://www.w3.org/1998/Math/MathML">
82
- <msubsup>
83
- <mo>&#x222B;</mo>
84
- <mn>ab</mn>
85
- <mn>ds</mn>
86
- </msubsup>
82
+ <msubsup>
83
+ <mo>&#x222B;</mo>
84
+ <mn>ab</mn>
85
+ <mn>ds</mn>
86
+ </msubsup>
87
87
  </math>
88
88
  INPUT
89
- \u222B_(ab)^(ds)
89
+ int_(ab)^(ds)
90
90
  OUTPUT
91
91
  end
92
92
 
93
- it "processes some MathML" do
94
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
93
+ it 'processes ubrace' do
94
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
95
95
  <math xmlns="http://www.w3.org/1998/Math/MathML">
96
- <munder>
97
- <mrow>
98
- <mi> x </mi>
99
- <mo> + </mo>
100
- <mi> y </mi>
101
- <mo> + </mo>
102
- <mi> z </mi>
103
- </mrow>
104
- <mo> &#x23DF;</mo>
105
- </munder>
96
+ <munder>
97
+ <mrow>
98
+ <mi> x </mi>
99
+ <mo> + </mo>
100
+ <mi> y </mi>
101
+ <mo> + </mo>
102
+ <mi> z </mi>
103
+ </mrow>
104
+ <mo> &#x23DF;</mo>
105
+ </munder>
106
106
  </math>
107
107
  INPUT
108
- ubrace ( x + y + z )
108
+ ubrace (x + y + z)
109
109
  OUTPUT
110
110
  end
111
111
 
112
- it "processes some MathML" do
113
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
112
+ it 'processes ul' do
113
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
114
114
  <math xmlns="http://www.w3.org/1998/Math/MathML">
115
- <munder>
116
- <mrow>
117
- <mi> x </mi>
118
- <mo> + </mo>
119
- <mi> y </mi>
120
- <mo> + </mo>
121
- <mi> z </mi>
122
- </mrow>
123
- <mo> &#x0332;</mo>
124
- </munder>
115
+ <munder>
116
+ <mrow>
117
+ <mi> x </mi>
118
+ <mo> + </mo>
119
+ <mi> y </mi>
120
+ <mo> + </mo>
121
+ <mi> z </mi>
122
+ </mrow>
123
+ <mo> &#x0332;</mo>
124
+ </munder>
125
125
  </math>
126
126
  INPUT
127
- ul ( x + y + z )
127
+ ul (x + y + z)
128
128
  OUTPUT
129
129
  end
130
130
 
131
- it "processes some MathML" do
132
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
131
+ it 'processes underset' do
132
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
133
133
  <math xmlns="http://www.w3.org/1998/Math/MathML">
134
- <munder>
135
- <mrow>
136
- <mi> x </mi>
137
- <mo> + </mo>
138
- <mi> y </mi>
139
- <mo> + </mo>
140
- <mi> z </mi>
141
- </mrow>
142
- <mo>fred </mo>
143
- </munder>
134
+ <munder>
135
+ <mrow>
136
+ <mi> x </mi>
137
+ <mo> + </mo>
138
+ <mi> y </mi>
139
+ <mo> + </mo>
140
+ <mi> z </mi>
141
+ </mrow>
142
+ <mo>fred </mo>
143
+ </munder>
144
144
  </math>
145
145
  INPUT
146
- underset(fred)(( x + y + z ))
146
+ underset(fred)((x + y + z))
147
147
  OUTPUT
148
148
  end
149
149
 
150
- it "processes some MathML" do
151
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
150
+ it 'processes obrace' do
151
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
152
152
  <math xmlns="http://www.w3.org/1998/Math/MathML">
153
- <mover accent="true">
154
- <mrow>
155
- <mi> x </mi>
156
- <mo> + </mo>
157
- <mi> y </mi>
158
- <mo> + </mo>
159
- <mi> z </mi>
160
- </mrow>
161
- <mo> &#x23DE;</mo>
162
- </mover>
163
-
153
+ <mover accent="true">
154
+ <mrow>
155
+ <mi> x </mi>
156
+ <mo> + </mo>
157
+ <mi> y </mi>
158
+ <mo> + </mo>
159
+ <mi> z </mi>
160
+ </mrow>
161
+ <mo> &#x23DE;</mo>
162
+ </mover>
164
163
  </math>
165
164
  INPUT
166
165
  obrace x + y + z
167
166
  OUTPUT
168
167
  end
169
168
 
170
- it "processes some MathML" do
171
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
169
+ it 'processes hat' do
170
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
172
171
  <math xmlns="http://www.w3.org/1998/Math/MathML">
173
- <mover accent="true">
174
- <mrow>
175
- <mi> x </mi>
176
- <mo> + </mo>
177
- <mi> y </mi>
178
- <mo> + </mo>
179
- <mi> z </mi>
180
- </mrow>
181
- <mo> &#x5e;</mo>
182
- </mover>
183
-
172
+ <mover accent="true">
173
+ <mrow>
174
+ <mi> x </mi>
175
+ <mo> + </mo>
176
+ <mi> y </mi>
177
+ <mo> + </mo>
178
+ <mi> z </mi>
179
+ </mrow>
180
+ <mo> &#x5e;</mo>
181
+ </mover>
184
182
  </math>
185
183
  INPUT
186
184
  hat x + y + z
187
185
  OUTPUT
188
186
  end
189
187
 
190
- it "processes some MathML" do
191
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
188
+ it 'processes bar' do
189
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
192
190
  <math xmlns="http://www.w3.org/1998/Math/MathML">
193
- <mover accent="true">
194
- <mrow>
195
- <mi> x </mi>
196
- <mo> + </mo>
197
- <mi> y </mi>
198
- <mo> + </mo>
199
- <mi> z </mi>
200
- </mrow>
201
- <mo> &#xaf;</mo>
202
- </mover>
203
-
191
+ <mover accent="true">
192
+ <mrow>
193
+ <mi> x </mi>
194
+ <mo> + </mo>
195
+ <mi> y </mi>
196
+ <mo> + </mo>
197
+ <mi> z </mi>
198
+ </mrow>
199
+ <mo> &#xaf;</mo>
200
+ </mover>
204
201
  </math>
205
202
  INPUT
206
203
  bar x + y + z
207
204
  OUTPUT
208
205
  end
209
206
 
210
- it "processes some MathML" do
211
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
207
+ it 'processes vec' do
208
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
212
209
  <math xmlns="http://www.w3.org/1998/Math/MathML">
213
- <mover accent="true">
214
- <mrow>
215
- <mi> x </mi>
216
- <mo> + </mo>
217
- <mi> y </mi>
218
- <mo> + </mo>
219
- <mi> z </mi>
220
- </mrow>
221
- <mo>&#x2192;</mo>
222
- </mover>
223
-
210
+ <mover accent="true">
211
+ <mrow>
212
+ <mi> x </mi>
213
+ <mo> + </mo>
214
+ <mi> y </mi>
215
+ <mo> + </mo>
216
+ <mi> z </mi>
217
+ </mrow>
218
+ <mo>&#x2192;</mo>
219
+ </mover>
224
220
  </math>
225
221
  INPUT
226
222
  vec x + y + z
227
223
  OUTPUT
228
224
  end
229
225
 
230
- it "processes some MathML" do
231
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
226
+ it 'processes dot' do
227
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
232
228
  <math xmlns="http://www.w3.org/1998/Math/MathML">
233
- <mover accent="true">
234
- <mrow>
235
- <mi> x </mi>
236
- <mo> + </mo>
237
- <mi> y </mi>
238
- <mo> + </mo>
239
- <mi> z </mi>
240
- </mrow>
241
- <mo> .</mo>
242
- </mover>
243
-
229
+ <mover accent="true">
230
+ <mrow>
231
+ <mi> x </mi>
232
+ <mo> + </mo>
233
+ <mi> y </mi>
234
+ <mo> + </mo>
235
+ <mi> z </mi>
236
+ </mrow>
237
+ <mo> .</mo>
238
+ </mover>
244
239
  </math>
245
240
  INPUT
246
241
  dot x + y + z
247
242
  OUTPUT
248
243
  end
249
244
 
250
- it "processes some MathML" do
251
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
245
+ it 'processes ddot' do
246
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
252
247
  <math xmlns="http://www.w3.org/1998/Math/MathML">
253
- <mover accent="true">
254
- <mrow>
255
- <mi> x </mi>
256
- <mo> + </mo>
257
- <mi> y </mi>
258
- <mo> + </mo>
259
- <mi> z </mi>
260
- </mrow>
261
- <mo>..</mo>
262
- </mover>
263
-
248
+ <mover accent="true">
249
+ <mrow>
250
+ <mi> x </mi>
251
+ <mo> + </mo>
252
+ <mi> y </mi>
253
+ <mo> + </mo>
254
+ <mi> z </mi>
255
+ </mrow>
256
+ <mo>..</mo>
257
+ </mover>
264
258
  </math>
265
259
  INPUT
266
260
  ddot x + y + z
267
261
  OUTPUT
268
262
  end
269
263
 
270
- it "processes some MathML" do
271
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
264
+ it 'processes overset' do
265
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
272
266
  <math xmlns="http://www.w3.org/1998/Math/MathML">
273
- <mover accent="true">
274
- <mrow>
275
- <mi> x </mi>
276
- <mo> + </mo>
277
- <mi> y </mi>
278
- <mo> + </mo>
279
- <mi> z </mi>
280
- </mrow>
281
- <mo>fred</mo>
282
- </mover>
283
-
267
+ <mover accent="true">
268
+ <mrow>
269
+ <mi> x </mi>
270
+ <mo> + </mo>
271
+ <mi> y </mi>
272
+ <mo> + </mo>
273
+ <mi> z </mi>
274
+ </mrow>
275
+ <mo>fred</mo>
276
+ </mover>
284
277
  </math>
285
278
  INPUT
286
- overset(fred)( x + y + z )
279
+ overset(fred)(x + y + z)
287
280
  OUTPUT
288
281
  end
289
282
 
290
- it "processes some MathML" do
291
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
283
+ it 'processes mtable' do
284
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
292
285
  <math xmlns="http://www.w3.org/1998/Math/MathML">
293
- <mi>X</mi>
294
- <mo>=</mo>
295
- <mtable frame="solid" rowlines="solid" align="axis 3">
296
- <mtr>
297
- <mtd><mi>A</mi></mtd>
298
- <mtd><mi>B</mi></mtd>
299
- </mtr>
300
- <mtr>
301
- <mtd><mi>C</mi></mtd>
302
- <mtd><mi>D</mi></mtd>
303
- </mtr>
304
- <mtr>
305
- <mtd><mi>E</mi></mtd>
306
- <mtd><mi>F</mi></mtd>
307
- </mtr>
308
- </mtable>
286
+ <mi>X</mi>
287
+ <mo>=</mo>
288
+ <mtable frame="solid" rowlines="solid" align="axis 3">
289
+ <mtr>
290
+ <mtd><mi>A</mi></mtd>
291
+ <mtd><mi>B</mi></mtd>
292
+ </mtr>
293
+ <mtr>
294
+ <mtd><mi>C</mi></mtd>
295
+ <mtd><mi>D</mi></mtd>
296
+ </mtr>
297
+ <mtr>
298
+ <mtd><mi>E</mi></mtd>
299
+ <mtd><mi>F</mi></mtd>
300
+ </mtr>
301
+ </mtable>
309
302
  </math>
310
303
  INPUT
311
304
  X = [[A,B],[C,D],[E,F]]
312
305
  OUTPUT
313
306
  end
314
307
 
315
- it "processes <semantics> wrapping element" do
316
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
308
+ it 'processes <semantics> wrapping element' do
309
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
317
310
  <math xmlns="http://www.w3.org/1998/Math/MathML">
318
311
  <semantics>
319
312
  <mrow>
@@ -341,8 +334,8 @@ RSpec.describe MathML2AsciiMath do
341
334
  OUTPUT
342
335
  end
343
336
 
344
- it "processes <math> without xmlns" do
345
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
337
+ it 'processes <math> without xmlns' do
338
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
346
339
  <math>
347
340
  <semantics>
348
341
  <mrow>
@@ -370,8 +363,8 @@ RSpec.describe MathML2AsciiMath do
370
363
  OUTPUT
371
364
  end
372
365
 
373
- it "processes and skips <annotation> element" do
374
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
366
+ it 'processes and skips <annotation> element' do
367
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
375
368
  <math>
376
369
  <semantics>
377
370
  <mrow>
@@ -400,21 +393,32 @@ RSpec.describe MathML2AsciiMath do
400
393
  OUTPUT
401
394
  end
402
395
 
403
- it "processes some unknown MathML" do
404
- expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
396
+ it 'does not include non-significant whitespaces (spaces between nodes)' do
397
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
398
+ <math> <semantics> <mrow> <msub> <mi>x</mi> <mn>1</mn> </msub> <mo>,</mo><mtext> </mtext><msub> <mi>x</mi> <mn>2</mn> </msub> <mo>,</mo><mtext> </mtext><mtext> </mtext><mo>…</mo><mtext> </mtext><mtext> </mtext><mtext> </mtext><msub> <mi>x</mi> <mi>n</mi> </msub> </mrow> <annotation encoding='MathType-MTEF'>MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbbjxAHX garuavP1wzZbItLDhis9wBH5garmWu51MyVXgarqqtubsr4rNCHbGe aGqipG0dh9qqWrVepG0dbbL8F4rqqrVepeea0xe9LqFf0xc9q8qqaq Fn0lXdHiVcFbIOFHK8Feea0dXdar=Jb9hs0dXdHuk9fr=xfr=xfrpe WZqaaeGaciWaamGadaGadeaabaGaaqaaaOqaaiaadIhadaWgaaWcba GaaGymaaqabaGccaGGSaGaaGjbVlaadIhadaWgaaWcbaGaaGOmaaqa baGccaGGSaGaaGjbVlaaykW7cqWIMaYscaaMc8UaaGPaVlaaysW7ca WG4bWaaSbaaSqaaiaad6gaaeqaaaaa@4713@ </annotation> </semantics> </math>
399
+ INPUT
400
+ x_1 , x_2 , ... x_n
401
+ OUTPUT
402
+ end
403
+
404
+ it 'processes unknown MathML' do
405
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to eq <<~OUTPUT.strip
405
406
  <math xmlns="http://www.w3.org/1998/Math/MathML">
406
- <mrow>
407
- <mi> x </mi>
408
- <mo> + </mo>
409
- <mphantom>
410
- <mi> y </mi>
411
- <mo> + </mo>
412
- </mphantom>
413
- <mi> z </mi>
414
- </mrow>
407
+ <mrow>
408
+ <mi> x </mi>
409
+ <mo> + </mo>
410
+ <mphantom>
411
+ <mi> y </mi>
412
+ <mo> + </mo>
413
+ </mphantom>
414
+ <mi> z </mi>
415
+ </mrow>
415
416
  </math>
416
417
  INPUT
417
- x + <mphantom>\n<mi> y </mi>\n<mo> + </mo>\n</mphantom> z
418
+ x + <math xmlns="http://www.w3.org/1998/Math/MathML"><mphantom>
419
+ <mi> y </mi>
420
+ <mo> + </mo>
421
+ </mphantom></math> z
418
422
  OUTPUT
419
423
  end
420
424
 
@@ -8,5 +8,5 @@ end
8
8
  SimpleCov.start 'gem'
9
9
 
10
10
  require "rspec/match_fuzzy"
11
- require "mathml2asciimath"
11
+ require 'mathml2asciimath'
12
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mathml2asciimath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-08 00:00:00.000000000 Z
11
+ date: 2020-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities