mathml2asciimath 0.0.3 → 0.0.4

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: d473374d6a28e51bfb004b04b096b9b23a347811f1eec64d9c6fd2b2bf69b943
4
- data.tar.gz: 76167939b53649ff8f8b6f0e81a78bf06fe7c36fc50f7736265830eb68f4bfcc
3
+ metadata.gz: c8e025f89f1377ddee1208333287bb3946f26d6519c6425316997a80b32b5a2d
4
+ data.tar.gz: a910706c12896faa62eedcb04863f3fa8ccf1984ac273a428e629389e3bf0111
5
5
  SHA512:
6
- metadata.gz: 2b532bc911c74921778aef02e322c5e73a73c196a4ca01d370998d7914c343a640615e25e8bd9b547a31efff8587eee747bc802f8e988a1f51dce577fbf900ac
7
- data.tar.gz: 24eff8467bf26462e0adc79c698b785331c86320f6dac467c4a6c6f4c25e35482fe622b539da424256337e8b502680ad7403d447bfa012f9b797c37db43cb084
6
+ metadata.gz: 9e4f8388a919a0b5c374785ace17771722b73c7b763a6a7febad8263302f1b1d28b4316938ace7c9b731fd494e29f7be67cdfa8c1be96a7c595d2093c9df14d5
7
+ data.tar.gz: e2f13b12044db5589a096cdedb014304f49cc06f97c0aba87f127e3f003306e0089792b878041afaa0a63161c56bce855a1f0fd70ceb77969d633ade8b2c0912
@@ -181,7 +181,7 @@ module MathML2AsciiMath
181
181
  open = node["open"] || "("
182
182
  close = node["close"] || ")"
183
183
  separator = "," # TODO currently ignore the supplied separators
184
- node.children.each { |n| outarr << parse(n) }
184
+ node.elements.each { |n| outarr << parse(n) }
185
185
  out = outarr.join(separator)
186
186
  return "#{open}#{out}#{close}"
187
187
  when "msqrt"
@@ -224,7 +224,8 @@ module MathML2AsciiMath
224
224
  accent = case elem1
225
225
  when "\u005e" then "hat"
226
226
  when "\u00af" then "bar"
227
- when "\u2192" then "vec"
227
+ #when "\u2192" then "vec"
228
+ when "->" then "vec"
228
229
  when "." then "dot"
229
230
  when ".." then "ddot"
230
231
  when "\u23de" then "obrace"
@@ -238,14 +239,14 @@ module MathML2AsciiMath
238
239
  end
239
240
  when "mtable"
240
241
  rows = []
241
- node.children.each { |n| rows << parse(n) }
242
+ node.elements.each { |n| rows << parse(n) }
242
243
  return "[#{rows.join(",")}]"
243
244
  when "mtr"
244
245
  cols = []
245
- node.children.each { |n| cols << parse(n) }
246
+ node.elements.each { |n| cols << parse(n) }
246
247
  return "[#{cols.join(",")}]"
247
248
  when "mtd"
248
- node.children.each { |n| out << parse(n) }
249
+ node.elements.each { |n| out << parse(n) }
249
250
  return "#{out}"
250
251
  when "mn", "mtext"
251
252
  node.children.each { |n| out << parse(n) }
@@ -1,4 +1,4 @@
1
1
  module MathML2AsciiMath
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
4
4
 
data/spec/mathml_spec.rb CHANGED
@@ -7,11 +7,326 @@ RSpec.describe MathML2AsciiMath do
7
7
  <mrow>
8
8
  <mi>a</mi> <mo>⋄</mo> <msup><mi>x</mi><mn>2</mn></msup>
9
9
  <mo>+</mo><mi>b</mi><mo>×</mo><mi>x</mi>
10
- <mo>+</mo><mi>c</mi>
10
+ <mo>+</mo><msub><mi>c</mi><mn>3</mn></msub>
11
11
  </mrow>
12
12
  </math>
13
13
  INPUT
14
- a diamond x^2\n + b xx x\n + c
14
+ a diamond x^2\n + b xx x\n + c_3
15
15
  OUTPUT
16
16
  end
17
+
18
+ it "processes some MathML" do
19
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
20
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
21
+ <mrow>
22
+ <mi>a</mi> <mo>⋄</mo> <msup><mi>x</mi><mn>2d</mn></msup>
23
+ <mo>+</mo><mi>b</mi><mo>×</mo><mi>x</mi>
24
+ <mo>+</mo><msub><mi>c</mi><mn>ab</mn></msub>
25
+ </mrow>
26
+ </math>
27
+ INPUT
28
+ a diamond x^(2d)\n+ b xx x\n+ c_(ab)
29
+ OUTPUT
30
+ end
31
+
32
+ it "processes some MathML" do
33
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
34
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
35
+ <mfrac>
36
+ <mrow> <mn> 1 </mn> <mo> + </mo> <msqrt> <mn> 5 </mn> </msqrt> </mrow>
37
+ <mn> 2 </mn>
38
+ </mfrac>
39
+ </math>
40
+ INPUT
41
+ (( 1 + sqrt( 5 ) ))/( 2 )
42
+ OUTPUT
43
+ end
44
+
45
+ it "processes some MathML" do
46
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
47
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
48
+ <mfenced><mrow><mi> a </mi> <mo> + </mo> <mi> b </mi></mrow></mfenced>
49
+ </math>
50
+ INPUT
51
+ ( a + b )
52
+ OUTPUT
53
+ end
54
+
55
+ it "processes some MathML" do
56
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
57
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
58
+ <mfenced open="["> <mn> 0 </mn> <mn> 1 </mn> </mfenced>
59
+ </math>
60
+ INPUT
61
+ [ 0 , 1 )
62
+ OUTPUT
63
+ end
64
+
65
+ it "processes some MathML" do
66
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
67
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
68
+ <munderover>
69
+ <mo>&#x222B;</mo> <mn>0</mn> <mi>&#x221E;</mi>
70
+ </munderover>
71
+ </math>
72
+ INPUT
73
+ \u222B_0^( oo )
74
+ OUTPUT
75
+ end
76
+
77
+ it "processes some MathML" do
78
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
79
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
80
+ <msubsup>
81
+ <mo>&#x222B;</mo>
82
+ <mn>ab</mn>
83
+ <mn>ds</mn>
84
+ </msubsup>
85
+ </math>
86
+ INPUT
87
+ \u222B_(ab)^(ds)
88
+ OUTPUT
89
+ end
90
+
91
+ it "processes some MathML" do
92
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
93
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
94
+ <munder>
95
+ <mrow>
96
+ <mi> x </mi>
97
+ <mo> + </mo>
98
+ <mi> y </mi>
99
+ <mo> + </mo>
100
+ <mi> z </mi>
101
+ </mrow>
102
+ <mo> &#x23DF;</mo>
103
+ </munder>
104
+ </math>
105
+ INPUT
106
+ ubrace (\nx\n+\ny\n+\nz\n)
107
+ OUTPUT
108
+ end
109
+
110
+ it "processes some MathML" do
111
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
112
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
113
+ <munder>
114
+ <mrow>
115
+ <mi> x </mi>
116
+ <mo> + </mo>
117
+ <mi> y </mi>
118
+ <mo> + </mo>
119
+ <mi> z </mi>
120
+ </mrow>
121
+ <mo> &#x0332;</mo>
122
+ </munder>
123
+ </math>
124
+ INPUT
125
+ ul (\nx\n+\ny\n+\nz\n)
126
+ OUTPUT
127
+ end
128
+
129
+ it "processes some MathML" do
130
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
131
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
132
+ <munder>
133
+ <mrow>
134
+ <mi> x </mi>
135
+ <mo> + </mo>
136
+ <mi> y </mi>
137
+ <mo> + </mo>
138
+ <mi> z </mi>
139
+ </mrow>
140
+ <mo>fred </mo>
141
+ </munder>
142
+ </math>
143
+ INPUT
144
+ underset(fred)((\nx\n+\ny\n+\nz\n))
145
+ OUTPUT
146
+ end
147
+
148
+ it "processes some MathML" do
149
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
150
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
151
+ <mover accent="true">
152
+ <mrow>
153
+ <mi> x </mi>
154
+ <mo> + </mo>
155
+ <mi> y </mi>
156
+ <mo> + </mo>
157
+ <mi> z </mi>
158
+ </mrow>
159
+ <mo> &#x23DE;</mo>
160
+ </mover>
161
+
162
+ </math>
163
+ INPUT
164
+ obrace\nx\n+\ny\n+\nz
165
+ OUTPUT
166
+ end
167
+
168
+ it "processes some MathML" do
169
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
170
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
171
+ <mover accent="true">
172
+ <mrow>
173
+ <mi> x </mi>
174
+ <mo> + </mo>
175
+ <mi> y </mi>
176
+ <mo> + </mo>
177
+ <mi> z </mi>
178
+ </mrow>
179
+ <mo> &#x5e;</mo>
180
+ </mover>
181
+
182
+ </math>
183
+ INPUT
184
+ hat\nx\n+\ny\n+\nz
185
+ OUTPUT
186
+ end
187
+
188
+ it "processes some MathML" do
189
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
190
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
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>
201
+
202
+ </math>
203
+ INPUT
204
+ bar\nx\n+\ny\n+\nz
205
+ OUTPUT
206
+ end
207
+
208
+ it "processes some MathML" do
209
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
210
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
211
+ <mover accent="true">
212
+ <mrow>
213
+ <mi> x </mi>
214
+ <mo> + </mo>
215
+ <mi> y </mi>
216
+ <mo> + </mo>
217
+ <mi> z </mi>
218
+ </mrow>
219
+ <mo>&#x2192;</mo>
220
+ </mover>
221
+
222
+ </math>
223
+ INPUT
224
+ vec\nx\n+\ny\n+\nz
225
+ OUTPUT
226
+ end
227
+
228
+ it "processes some MathML" do
229
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
230
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
231
+ <mover accent="true">
232
+ <mrow>
233
+ <mi> x </mi>
234
+ <mo> + </mo>
235
+ <mi> y </mi>
236
+ <mo> + </mo>
237
+ <mi> z </mi>
238
+ </mrow>
239
+ <mo> .</mo>
240
+ </mover>
241
+
242
+ </math>
243
+ INPUT
244
+ dot\nx\n+\ny\n+\nz
245
+ OUTPUT
246
+ end
247
+
248
+ it "processes some MathML" do
249
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
250
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
251
+ <mover accent="true">
252
+ <mrow>
253
+ <mi> x </mi>
254
+ <mo> + </mo>
255
+ <mi> y </mi>
256
+ <mo> + </mo>
257
+ <mi> z </mi>
258
+ </mrow>
259
+ <mo>..</mo>
260
+ </mover>
261
+
262
+ </math>
263
+ INPUT
264
+ ddot\nx\n+\ny\n+\nz
265
+ OUTPUT
266
+ end
267
+
268
+ it "processes some MathML" do
269
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
270
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
271
+ <mover accent="true">
272
+ <mrow>
273
+ <mi> x </mi>
274
+ <mo> + </mo>
275
+ <mi> y </mi>
276
+ <mo> + </mo>
277
+ <mi> z </mi>
278
+ </mrow>
279
+ <mo>fred</mo>
280
+ </mover>
281
+
282
+ </math>
283
+ INPUT
284
+ overset(fred)(\nx\n+\ny\n+\nz\n)
285
+ OUTPUT
286
+ end
287
+
288
+ it "processes some MathML" do
289
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
290
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
291
+ <mi>X</mi>
292
+ <mo>=</mo>
293
+ <mtable frame="solid" rowlines="solid" align="axis 3">
294
+ <mtr>
295
+ <mtd><mi>A</mi></mtd>
296
+ <mtd><mi>B</mi></mtd>
297
+ </mtr>
298
+ <mtr>
299
+ <mtd><mi>C</mi></mtd>
300
+ <mtd><mi>D</mi></mtd>
301
+ </mtr>
302
+ <mtr>
303
+ <mtd><mi>E</mi></mtd>
304
+ <mtd><mi>F</mi></mtd>
305
+ </mtr>
306
+ </mtable>
307
+ </math>
308
+ INPUT
309
+ X = [[A,B],[C,D],[E,F]]
310
+ OUTPUT
311
+ end
312
+
313
+ it "processes some unknown MathML" do
314
+ expect(MathML2AsciiMath.m2a(<<~INPUT)).to match_fuzzy <<~OUTPUT
315
+ <math xmlns="http://www.w3.org/1998/Math/MathML">
316
+ <mrow>
317
+ <mi> x </mi>
318
+ <mo> + </mo>
319
+ <mphantom>
320
+ <mi> y </mi>
321
+ <mo> + </mo>
322
+ </mphantom>
323
+ <mi> z </mi>
324
+ </mrow>
325
+ </math>
326
+ INPUT
327
+ x\n+\n<mphantom>\n<mi> y </mi>\n<mo> + </mo>\n</mphantom>\nz
328
+ OUTPUT
329
+ end
330
+
331
+
17
332
  end
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-11 00:00:00.000000000 Z
11
+ date: 2018-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities