mathml2asciimath 0.0.8 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +32 -0
- data/.gitignore +1 -0
- data/.hound.yml +3 -1
- data/.rubocop.yml +7 -7
- data/Gemfile +1 -2
- data/README.adoc +6 -5
- data/Rakefile +1 -1
- data/bin/m2a.rb +5 -7
- data/bin/rspec +1 -1
- data/lib/mathml2asciimath/m2a.rb +284 -252
- data/lib/mathml2asciimath/version.rb +1 -2
- data/mathml2asciimath.gemspec +7 -7
- data/spec/mathml_spec.rb +341 -251
- data/spec/spec_helper.rb +6 -7
- metadata +36 -41
- data/.github/workflows/macos.yml +0 -27
- data/.github/workflows/ubuntu.yml +0 -27
- data/.github/workflows/windows.yml +0 -30
- data/.rubocop.ribose.yml +0 -65
- data/.rubocop.tb.yml +0 -650
- data/Gemfile.lock +0 -108
data/lib/mathml2asciimath/m2a.rb
CHANGED
@@ -3,269 +3,301 @@ require "htmlentities"
|
|
3
3
|
require "pp"
|
4
4
|
|
5
5
|
module MathML2AsciiMath
|
6
|
+
def self.m2a(xml)
|
7
|
+
normalized = xml
|
6
8
|
|
7
|
-
|
8
|
-
docxml = Nokogiri::XML(
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
# &:noblanks skips non-significant whitespaces in MathML
|
10
|
+
docxml = Nokogiri::XML.parse(normalized, &:noblanks)
|
11
|
+
|
12
|
+
# Get rid of things like
|
13
|
+
# <mtext> </mtext>
|
14
|
+
parse(docxml.root).gsub(/[[:blank:]]/, " ").unicode_normalize.squeeze(" ")
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.encodechars(xml)
|
18
|
+
xml.gsub(/\u03b1/, "alpha")
|
19
|
+
.gsub(/\u03b2/, "beta")
|
20
|
+
.gsub(/\u03b3/, "gamma")
|
21
|
+
.gsub(/\u0393/, "Gamma")
|
22
|
+
.gsub(/\u03b4/, "delta")
|
23
|
+
.gsub(/\u0394/, "Delta")
|
24
|
+
.gsub(/\u2206/, "Delta")
|
25
|
+
.gsub(/\u03b5/, "epsilon")
|
26
|
+
.gsub(/\u025b/, "varepsilon")
|
27
|
+
.gsub(/\u03b6/, "zeta")
|
28
|
+
.gsub(/\u03b7/, "eta")
|
29
|
+
.gsub(/\u03b8/, "theta")
|
30
|
+
.gsub(/\u0398/, "Theta")
|
31
|
+
.gsub(/\u03d1/, "vartheta")
|
32
|
+
.gsub(/\u03b9/, "iota")
|
33
|
+
.gsub(/\u03ba/, "kappa")
|
34
|
+
.gsub(/\u03bb/, "lambda")
|
35
|
+
.gsub(/\u039b/, "Lambda")
|
36
|
+
.gsub(/\u03bc/, "mu")
|
37
|
+
.gsub(/\u03bd/, "nu")
|
38
|
+
.gsub(/\u03be/, "xi")
|
39
|
+
.gsub(/\u039e/, "Xi")
|
40
|
+
.gsub(/\u03c0/, "pi")
|
41
|
+
.gsub(/\u03a0/, "Pi")
|
42
|
+
.gsub(/\u03c1/, "rho")
|
43
|
+
.gsub(/\u03c2/, "beta")
|
44
|
+
.gsub(/\u03c3/, "sigma")
|
45
|
+
.gsub(/\u03a3/, "Sigma")
|
46
|
+
.gsub(/\u03c4/, "tau")
|
47
|
+
.gsub(/\u03c5/, "upsilon")
|
48
|
+
.gsub(/\u03c6/, "phi")
|
49
|
+
.gsub(/\u03a6/, "Phi")
|
50
|
+
.gsub(/\u03d5/, "varphi")
|
51
|
+
.gsub(/\u03c7/, "chi")
|
52
|
+
.gsub(/\u03c8/, "psi")
|
53
|
+
.gsub(/\u03a8/, "Psi")
|
54
|
+
.gsub(/\u03c9/, "omega")
|
55
|
+
.gsub(/\u03a9/, "omega")
|
56
|
+
.gsub(/\u22c5/, "*")
|
57
|
+
.gsub(/\u2219/, "*")
|
58
|
+
.gsub(/\u00b7/, "*")
|
59
|
+
.gsub(/\u2217/, "**")
|
60
|
+
.gsub(/\u22c6/, "***")
|
61
|
+
.gsub(/\//, "//")
|
62
|
+
.gsub(/\\/, "\\\\")
|
63
|
+
.gsub(/\u00d7/, "xx")
|
64
|
+
.gsub(/\u22c9/, "|><")
|
65
|
+
.gsub(/\u22ca/, "><|")
|
66
|
+
.gsub(/\u22c8/, "|><|")
|
67
|
+
.gsub(/\u00f7/, "-:")
|
68
|
+
.gsub(/\u2218/, "@")
|
69
|
+
.gsub(/\u2295/, "o+")
|
70
|
+
.gsub(/\u2a01/, "o+")
|
71
|
+
.gsub(/\u2297/, "ox")
|
72
|
+
.gsub(/\u2299/, "o.")
|
73
|
+
.gsub(/\u2211/, "sum")
|
74
|
+
.gsub(/\u220f/, "prod")
|
75
|
+
.gsub(/\u2227/, "^^")
|
76
|
+
.gsub(/\u22c0/, "^^^")
|
77
|
+
.gsub(/\u2228/, "vv")
|
78
|
+
.gsub(/\u22c1/, "vvv")
|
79
|
+
.gsub(/\u2229/, "nn")
|
80
|
+
.gsub(/\u22c2/, "nnn")
|
81
|
+
.gsub(/\u222a/, "uu")
|
82
|
+
.gsub(/\u22c3/, "uuu")
|
83
|
+
.gsub(/\u2260/, "!=")
|
84
|
+
.gsub(/\u2264/, "<=")
|
85
|
+
.gsub(/\u2265/, ">=")
|
86
|
+
.gsub(/\u227a/, "-<")
|
87
|
+
.gsub(/\u227b/, ">-")
|
88
|
+
.gsub(/\u2aaf/, "-<=")
|
89
|
+
.gsub(/\u2ab0/, ">-=")
|
90
|
+
.gsub(/\u2208/, "in")
|
91
|
+
.gsub(/\u2209/, "!in")
|
92
|
+
.gsub(/\u2282/, "sub")
|
93
|
+
.gsub(/\u2283/, "sup")
|
94
|
+
.gsub(/\u2286/, "sube")
|
95
|
+
.gsub(/\u2287/, "supe")
|
96
|
+
.gsub(/\u2261/, "-=")
|
97
|
+
.gsub(/\u2245/, "~=")
|
98
|
+
.gsub(/\u2248/, "~~")
|
99
|
+
.gsub(/\u221d/, "prop")
|
100
|
+
.gsub(/\u00ac/, "not")
|
101
|
+
.gsub(/\u21d2/, "=>")
|
102
|
+
.gsub(/\u21d4/, "<=>")
|
103
|
+
.gsub(/\u2200/, "AA")
|
104
|
+
.gsub(/\u2203/, "EE")
|
105
|
+
.gsub(/\u22a5/, "_|_")
|
106
|
+
.gsub(/\u22a4/, "TT")
|
107
|
+
.gsub(/\u22a2/, "|--")
|
108
|
+
.gsub(/\u22a8/, "|==")
|
109
|
+
.gsub(/\u22a8/, "|==")
|
110
|
+
.gsub(/\u2329/, "(:")
|
111
|
+
.gsub(/\u232a/, ":)")
|
112
|
+
.gsub(/\u2329/, "<<")
|
113
|
+
.gsub(/\u27e8/, "<<")
|
114
|
+
.gsub(/\u232a/, ">>")
|
115
|
+
.gsub(/\u27e9/, ">>")
|
116
|
+
.gsub(/\u222b/, "int")
|
117
|
+
.gsub(/\u222e/, "oint")
|
118
|
+
.gsub(/\u2202/, "del")
|
119
|
+
.gsub(/\u2207/, "grad")
|
120
|
+
.gsub(/\u00b1/, "+-")
|
121
|
+
.gsub(/\u2205/, "O/")
|
122
|
+
.gsub(/\u221e/, "oo")
|
123
|
+
.gsub(/\u2135/, "aleph")
|
124
|
+
.gsub(/\u2234/, ":.")
|
125
|
+
.gsub(/\u2235/, ":'")
|
126
|
+
.gsub(/\u2220/, "/_")
|
127
|
+
.gsub(/\u25b3/, "/_\\")
|
128
|
+
.gsub(/\u2032/, "'")
|
129
|
+
.gsub(/~/, "tilde")
|
130
|
+
.gsub(/\u00a0\u00a0\u00a0\u00a0/, "qquad")
|
131
|
+
.gsub(/\u00a0\u00a0/, "quad")
|
132
|
+
.gsub(/\u00a0/, "\\ ")
|
133
|
+
.gsub(/\u2322/, "frown")
|
134
|
+
.gsub(/\u00a0/, "quad")
|
135
|
+
.gsub(/\u22ef/, "cdots")
|
136
|
+
.gsub(/\u22ee/, "vdots")
|
137
|
+
.gsub(/\u22f1/, "ddots")
|
138
|
+
.gsub(/\u22c4/, "diamond")
|
139
|
+
.gsub(/\u25a1/, "square")
|
140
|
+
.gsub(/\u230a/, "|__")
|
141
|
+
.gsub(/\u230b/, "__|")
|
142
|
+
.gsub(/\u2308/, "|~")
|
143
|
+
.gsub(/\u2309/, "~|")
|
144
|
+
.gsub(/\u2102/, "CC")
|
145
|
+
.gsub(/\u2115/, "NN")
|
146
|
+
.gsub(/\u211a/, "QQ")
|
147
|
+
.gsub(/\u211d/, "RR")
|
148
|
+
.gsub(/\u2124/, "ZZ")
|
149
|
+
.gsub(/\u2191/, "uarr")
|
150
|
+
.gsub(/\u2193/, "darr")
|
151
|
+
.gsub(/\u2190/, "larr")
|
152
|
+
.gsub(/\u2194/, "harr")
|
153
|
+
.gsub(/\u21d2/, "rArr")
|
154
|
+
.gsub(/\u21d0/, "lArr")
|
155
|
+
.gsub(/\u21d4/, "hArr")
|
156
|
+
.gsub(/\u2192/, "->")
|
157
|
+
.gsub(/\u21a3/, ">->")
|
158
|
+
.gsub(/\u21a0/, "->>")
|
159
|
+
.gsub(/\u2916/, ">->>")
|
160
|
+
.gsub(/\u21a6/, "|->")
|
161
|
+
.gsub(/\u2026/, "...")
|
162
|
+
.gsub(/\u2212/, "-")
|
163
|
+
.gsub(/\u2061/, "") # function application
|
164
|
+
.gsub(/\u2751/, "square")
|
165
|
+
.gsub(/[\u2028\u2029]/, " ") # normalize thin spaces like \u2009, \u2008
|
12
166
|
end
|
13
167
|
|
14
|
-
def self.
|
15
|
-
|
16
|
-
|
17
|
-
|
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(/\u22c5/, "*").
|
53
|
-
gsub(/\u2219/, "*").
|
54
|
-
gsub(/\u00b7/, "*").
|
55
|
-
gsub(/\u2217/, "**").
|
56
|
-
gsub(/\u22c6/, "***").
|
57
|
-
gsub(/\//, "//").
|
58
|
-
gsub(/\\/, "\\\\").
|
59
|
-
gsub(/\u00d7/, "xx").
|
60
|
-
gsub(/\u22c9/, "|><").
|
61
|
-
gsub(/\u22ca/, "><|").
|
62
|
-
gsub(/\u22c8/, "|><|").
|
63
|
-
gsub(/\u00f7/, "-:").
|
64
|
-
gsub(/\u2218/, "@").
|
65
|
-
gsub(/\u2295/, "o+").
|
66
|
-
gsub(/\u2a01/, "o+").
|
67
|
-
gsub(/\u2297/, "ox").
|
68
|
-
gsub(/\u2299/, "o.").
|
69
|
-
gsub(/\u2211/, "sum").
|
70
|
-
gsub(/\u220f/, "prod").
|
71
|
-
gsub(/\u2227/, "^^").
|
72
|
-
gsub(/\u22c0/, "^^^").
|
73
|
-
gsub(/\u2228/, "vv").
|
74
|
-
gsub(/\u22c1/, "vvv").
|
75
|
-
gsub(/\u2229/, "nn").
|
76
|
-
gsub(/\u22c2/, "nnn").
|
77
|
-
gsub(/\u222a/, "uu").
|
78
|
-
gsub(/\u22c3/, "uuu").
|
79
|
-
gsub(/\u2260/, "!=").
|
80
|
-
gsub(/\u2264/, "<=").
|
81
|
-
gsub(/\u2265/, ">=").
|
82
|
-
gsub(/\u227a/, "-<").
|
83
|
-
gsub(/\u227b/, ">-").
|
84
|
-
gsub(/\u2aaf/, "-<=").
|
85
|
-
gsub(/\u2ab0/, ">-=").
|
86
|
-
gsub(/\u2208/, "in").
|
87
|
-
gsub(/\u2209/, "!in").
|
88
|
-
gsub(/\u2282/, "sub").
|
89
|
-
gsub(/\u2283/, "sup").
|
90
|
-
gsub(/\u2286/, "sube").
|
91
|
-
gsub(/\u2287/, "supe").
|
92
|
-
gsub(/\u2261/, "-=").
|
93
|
-
gsub(/\u2245/, "~=").
|
94
|
-
gsub(/\u2248/, "~~").
|
95
|
-
gsub(/\u221d/, "prop").
|
96
|
-
gsub(/\u00ac/, "not").
|
97
|
-
gsub(/\u21d2/, "=>").
|
98
|
-
gsub(/\u21d4/, "<=>").
|
99
|
-
gsub(/\u2200/, "AA").
|
100
|
-
gsub(/\u2203/, "EE").
|
101
|
-
gsub(/\u22a5/, "_|_").
|
102
|
-
gsub(/\u22a4/, "TT").
|
103
|
-
gsub(/\u22a2/, "|--").
|
104
|
-
gsub(/\u22a8/, "|==").
|
105
|
-
gsub(/\u22a8/, "|==").
|
106
|
-
gsub(/\u2329/, "(:").
|
107
|
-
gsub(/\u232a/, ":)").
|
108
|
-
gsub(/\u2329/, "<<").
|
109
|
-
gsub(/\u27e8/, "<<").
|
110
|
-
gsub(/\u232a/, ">>").
|
111
|
-
gsub(/\u27e9/, ">>").
|
112
|
-
gsub(/\u222e/, "oint").
|
113
|
-
gsub(/\u2202/, "del").
|
114
|
-
gsub(/\u2207/, "grad").
|
115
|
-
gsub(/\u00b1/, "+-").
|
116
|
-
gsub(/\u2205/, "O/").
|
117
|
-
gsub(/\u221e/, "oo").
|
118
|
-
gsub(/\u2135/, "aleph").
|
119
|
-
gsub(/\u2234/, ":.").
|
120
|
-
gsub(/\u2235/, ":'").
|
121
|
-
gsub(/\u2220/, "/_").
|
122
|
-
gsub(/\u25b3/, "/_\\").
|
123
|
-
gsub(/\u2032/, "'").
|
124
|
-
gsub(/~/, "tilde").
|
125
|
-
gsub(/\u00a0\u00a0\u00a0\u00a0/, "qquad").
|
126
|
-
gsub(/\u00a0\u00a0/, "quad").
|
127
|
-
gsub(/\u00a0/, "\\ ").
|
128
|
-
gsub(/\u2322/, "frown").
|
129
|
-
gsub(/\u00a0/, "quad").
|
130
|
-
gsub(/\u22ef/, "cdots").
|
131
|
-
gsub(/\u22ee/, "vdots").
|
132
|
-
gsub(/\u22f1/, "ddots").
|
133
|
-
gsub(/\u22c4/, "diamond").
|
134
|
-
gsub(/\u25a1/, "square").
|
135
|
-
gsub(/\u230a/, "|__").
|
136
|
-
gsub(/\u230b/, "__|").
|
137
|
-
gsub(/\u2308/, "|~").
|
138
|
-
gsub(/\u2309/, "~|").
|
139
|
-
gsub(/\u2102/, "CC").
|
140
|
-
gsub(/\u2115/, "NN").
|
141
|
-
gsub(/\u211a/, "QQ").
|
142
|
-
gsub(/\u211d/, "RR").
|
143
|
-
gsub(/\u2124/, "ZZ").
|
144
|
-
gsub(/\u2191/, "uarr").
|
145
|
-
gsub(/\u2193/, "darr").
|
146
|
-
gsub(/\u2190/, "larr").
|
147
|
-
gsub(/\u2194/, "harr").
|
148
|
-
gsub(/\u21d2/, "rArr").
|
149
|
-
gsub(/\u21d0/, "lArr").
|
150
|
-
gsub(/\u21d4/, "hArr").
|
151
|
-
gsub(/\u2192/, "->").
|
152
|
-
gsub(/\u21a3/, ">->").
|
153
|
-
gsub(/\u21a0/, "->>").
|
154
|
-
gsub(/\u2916/, ">->>").
|
155
|
-
gsub(/\u21a6/, "|->").
|
156
|
-
gsub(/\u2026/, "...").
|
157
|
-
gsub(/\u2212/, "-").
|
158
|
-
gsub(/\u2061/, ""). # function application
|
159
|
-
gsub(/\u2751/, "square")
|
168
|
+
def self.join_parsed_children(children, delimiter = " ")
|
169
|
+
children.map do |n|
|
170
|
+
parse(n).strip
|
171
|
+
end.join(delimiter)
|
160
172
|
end
|
161
173
|
|
162
174
|
def self.parse(node)
|
163
175
|
out = ""
|
164
176
|
if node.text?
|
165
177
|
return encodechars(HTMLEntities.new.decode(node.text))
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
when "\u23de" then "obrace"
|
232
|
-
else
|
233
|
-
"overset"
|
234
|
-
end
|
235
|
-
if accent == "overset"
|
236
|
-
return "overset(#{elem1})(#{parse(node.elements[0])})"
|
237
|
-
else
|
238
|
-
return "#{accent} #{parse(node.elements[0])}"
|
239
|
-
end
|
240
|
-
when "mtable"
|
241
|
-
rows = []
|
242
|
-
node.elements.each { |n| rows << parse(n) }
|
243
|
-
return "[#{rows.join(",")}]"
|
244
|
-
when "mtr"
|
245
|
-
cols = []
|
246
|
-
node.elements.each { |n| cols << parse(n) }
|
247
|
-
return "[#{cols.join(",")}]"
|
248
|
-
when "mtd"
|
249
|
-
node.elements.each { |n| out << parse(n) }
|
250
|
-
return "#{out}"
|
251
|
-
when "mn", "mtext"
|
252
|
-
node.children.each { |n| out << parse(n) }
|
253
|
-
return "#{out}"
|
254
|
-
when "mi"
|
255
|
-
# mi is not meant to have space around it, but Word is conflating operators and operands
|
256
|
-
node.children.each { |n| out << parse(n) }
|
257
|
-
out = " #{out} " if /[^a-zA-Z0-9',]|[a-z][a-z]/.match out
|
258
|
-
return out
|
259
|
-
when "mo"
|
260
|
-
node.children.each { |n| out << parse(n) }
|
261
|
-
out = " #{out} " unless node["fence"]
|
262
|
-
return out
|
263
|
-
when "mstyle"
|
264
|
-
node.children.each { |n| out << parse(n) }
|
265
|
-
return out
|
178
|
+
end
|
179
|
+
|
180
|
+
case node.name.sub(/^[^:]*:/, "")
|
181
|
+
when "math"
|
182
|
+
join_parsed_children(node.elements)
|
183
|
+
|
184
|
+
when "annotation"
|
185
|
+
""
|
186
|
+
|
187
|
+
when "semantics"
|
188
|
+
join_parsed_children(node.elements)
|
189
|
+
|
190
|
+
when "mrow"
|
191
|
+
out = join_parsed_children(node.elements)
|
192
|
+
if %w[mfrac msub munder munderover]
|
193
|
+
.include? node.parent.name.sub(/^[^:]*:/, "")
|
194
|
+
out = "(#{out})"
|
195
|
+
end
|
196
|
+
out
|
197
|
+
|
198
|
+
when "mfenced"
|
199
|
+
sym_open = node["open"] || "("
|
200
|
+
sym_close = node["close"] || ")"
|
201
|
+
|
202
|
+
separator = "," # TODO currently ignore the supplied separators
|
203
|
+
out = join_parsed_children(node.elements, separator)
|
204
|
+
"#{sym_open}#{out}#{sym_close}"
|
205
|
+
|
206
|
+
when "msqrt"
|
207
|
+
"sqrt(#{join_parsed_children(node.elements)})"
|
208
|
+
|
209
|
+
when "mfrac"
|
210
|
+
"(#{parse(node.elements[0])})/(#{parse(node.elements[1])})"
|
211
|
+
|
212
|
+
when "msup"
|
213
|
+
sup = parse(node.elements[1])
|
214
|
+
sup = "(#{sup})" unless sup.length == 1
|
215
|
+
op = parse(node.elements[0]).gsub(/ $/, "")
|
216
|
+
"#{op}^#{sup}"
|
217
|
+
|
218
|
+
when "msub"
|
219
|
+
sub = parse(node.elements[1])
|
220
|
+
sub = "(#{sub})" unless sub.length == 1
|
221
|
+
op = parse(node.elements[0]).gsub(/ $/, "")
|
222
|
+
"#{op}_#{sub}"
|
223
|
+
|
224
|
+
when "munderover", "msubsup"
|
225
|
+
sub = parse(node.elements[1])
|
226
|
+
sub = "(#{sub})" unless sub.length == 1
|
227
|
+
sup = parse(node.elements[2])
|
228
|
+
sup = "(#{sup})" unless sup.length == 1
|
229
|
+
op = parse(node.elements[0]).gsub(/ $/, "")
|
230
|
+
"#{op}_#{sub}^#{sup}"
|
231
|
+
|
232
|
+
when "munder"
|
233
|
+
elem1 = parse(node.elements[1]).strip
|
234
|
+
accent = case elem1
|
235
|
+
when "\u0332" then "ul"
|
236
|
+
when "\u23df" then "ubrace"
|
237
|
+
else
|
238
|
+
"underset"
|
239
|
+
end
|
240
|
+
|
241
|
+
if accent == "underset"
|
242
|
+
"underset(#{elem1})(#{parse(node.elements[0])})"
|
266
243
|
else
|
267
|
-
node.
|
244
|
+
"#{accent} #{parse(node.elements[0])}"
|
268
245
|
end
|
246
|
+
|
247
|
+
when "mover"
|
248
|
+
elem1 = parse(node.elements[1]).strip
|
249
|
+
accent = case elem1
|
250
|
+
when "\u005e" then "hat"
|
251
|
+
when "\u00af" then "bar"
|
252
|
+
# when "\u2192" then "vec"
|
253
|
+
when "->" then "vec"
|
254
|
+
when "." then "dot"
|
255
|
+
when ".." then "ddot"
|
256
|
+
when "\u23de" then "obrace"
|
257
|
+
else
|
258
|
+
"overset"
|
259
|
+
end
|
260
|
+
|
261
|
+
if accent == "overset"
|
262
|
+
"overset(#{elem1})(#{parse(node.elements[0])})"
|
263
|
+
else
|
264
|
+
"#{accent} #{parse(node.elements[0])}"
|
265
|
+
end
|
266
|
+
|
267
|
+
when "mtable"
|
268
|
+
"[#{join_parsed_children(node.elements, ',')}]"
|
269
|
+
|
270
|
+
when "mtr"
|
271
|
+
"[#{join_parsed_children(node.elements, ',')}]"
|
272
|
+
|
273
|
+
when "mtd"
|
274
|
+
join_parsed_children(node.elements, ",")
|
275
|
+
|
276
|
+
when "mn", "mtext"
|
277
|
+
join_parsed_children(node.children, "")
|
278
|
+
|
279
|
+
when "mi"
|
280
|
+
# FIXME: What does this comment have to do with Word?
|
281
|
+
# mi is not meant to have space around it,
|
282
|
+
# but Word is conflating operators and operands
|
283
|
+
join_parsed_children(node.children)
|
284
|
+
|
285
|
+
# FIXME: Why do we need to add extra spaces?
|
286
|
+
# out = " #{out} " if /[^a-zA-Z0-9',]|[a-z][a-z]/.match out
|
287
|
+
|
288
|
+
when "mo"
|
289
|
+
out = join_parsed_children(node.children)
|
290
|
+
out = " #{out} " unless node["fence"]
|
291
|
+
out
|
292
|
+
|
293
|
+
when "mstyle"
|
294
|
+
join_parsed_children(node.children)
|
295
|
+
|
296
|
+
else
|
297
|
+
"<math xmlns=\"http://www.w3.org/1998/Math/MathML\">" +
|
298
|
+
node.to_xml +
|
299
|
+
"</math>"
|
300
|
+
|
269
301
|
end
|
270
302
|
end
|
271
303
|
end
|
data/mathml2asciimath.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
lib = File.expand_path("
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require "mathml2asciimath/version"
|
6
6
|
|
@@ -17,26 +17,26 @@ Gem::Specification.new do |spec|
|
|
17
17
|
This gem is in active development.
|
18
18
|
DESCRIPTION
|
19
19
|
|
20
|
-
spec.homepage = "https://github.com/
|
20
|
+
spec.homepage = "https://github.com/plurimath/mathml2asciimath"
|
21
21
|
spec.license = "BSD-2-Clause"
|
22
22
|
|
23
23
|
spec.bindir = "bin"
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
spec.files = `git ls-files`.split("\n")
|
26
26
|
spec.test_files = `git ls-files -- {spec}/*`.split("\n")
|
27
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
27
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
28
28
|
|
29
29
|
spec.add_dependency "htmlentities", "~> 4.3.4"
|
30
|
-
spec.add_dependency "nokogiri", "
|
30
|
+
spec.add_dependency "nokogiri", "~> 1.12"
|
31
31
|
|
32
|
-
spec.add_development_dependency "bundler"
|
32
|
+
spec.add_development_dependency "bundler"
|
33
33
|
spec.add_development_dependency "byebug", "~> 9.1"
|
34
|
-
spec.add_development_dependency "rspec-match_fuzzy", "~> 0.1.3"
|
35
34
|
spec.add_development_dependency "guard", "~> 2.14"
|
36
35
|
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
37
36
|
spec.add_development_dependency "rake", "~> 12.0"
|
38
37
|
spec.add_development_dependency "rspec", "~> 3.6"
|
39
|
-
spec.add_development_dependency "
|
38
|
+
spec.add_development_dependency "rspec-match_fuzzy", "~> 0.1.3"
|
39
|
+
spec.add_development_dependency "rubocop", "~> 1.5.2"
|
40
40
|
spec.add_development_dependency "simplecov", "~> 0.15"
|
41
41
|
spec.add_development_dependency "timecop", "~> 0.9"
|
42
42
|
end
|