asciimath 1.0.6 → 1.0.7
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 +5 -5
- data/CHANGELOG.adoc +7 -0
- data/lib/asciimath/html.rb +11 -9
- data/lib/asciimath/mathml.rb +1 -1
- data/lib/asciimath/parser.rb +208 -177
- data/lib/asciimath/version.rb +1 -1
- data/spec/parser_spec.rb +37 -30
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d2a221676ad606382d11b321c85c1ab20181b811889ecbde2fffe9001ba49a2e
|
4
|
+
data.tar.gz: 632181cf62e5be454815f56892d39686dbc423b9e93c06e78efe9099a5bae47e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55682f13d5f1803dcf677a9cd71753397c736087ce7e91ca27023e93185b643c1c4a040cfe490b01f2500e13b1ac453e5de4224f0bdcd703487eec61485fb36a
|
7
|
+
data.tar.gz: b944a87b4b2fea973d832248c0dd5e6344b3e26a5623067a9ecc40bbf562a4efa4c3c6ba9740cd305c776625961d256195c707cf633bdf599e067e440a5fbfd0
|
data/CHANGELOG.adoc
CHANGED
data/lib/asciimath/html.rb
CHANGED
@@ -23,6 +23,8 @@ module AsciiMath
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
+
ZWJ = "\u8205"
|
27
|
+
|
26
28
|
def append(expression, opts = {})
|
27
29
|
case expression
|
28
30
|
when Array
|
@@ -98,7 +100,7 @@ module AsciiMath
|
|
98
100
|
if expression[:lparen]
|
99
101
|
brace(expression[:lparen], {:style => brace_height})
|
100
102
|
else
|
101
|
-
blank(
|
103
|
+
blank(ZWJ)
|
102
104
|
end
|
103
105
|
matrix_width = "grid-template-columns:repeat(" + expression[:rows][0].length.to_s + ",1fr);"
|
104
106
|
matrix_height = "grid-template-rows:repeat(" + expression[:rows].length.to_s + ",1fr);"
|
@@ -115,7 +117,7 @@ module AsciiMath
|
|
115
117
|
if expression[:rparen]
|
116
118
|
brace(expression[:rparen], {:style => brace_height})
|
117
119
|
else
|
118
|
-
blank(
|
120
|
+
blank(ZWJ)
|
119
121
|
end
|
120
122
|
end
|
121
123
|
end
|
@@ -130,26 +132,26 @@ module AsciiMath
|
|
130
132
|
append(sup, :strip_paren => true)
|
131
133
|
end
|
132
134
|
else
|
133
|
-
smaller(
|
135
|
+
smaller(ZWJ)
|
134
136
|
end
|
135
137
|
if sub
|
136
138
|
smaller do
|
137
139
|
append(sub, :strip_paren => true)
|
138
140
|
end
|
139
141
|
else
|
140
|
-
smaller(
|
142
|
+
smaller(ZWJ)
|
141
143
|
end
|
142
144
|
end
|
143
145
|
end
|
144
146
|
|
145
147
|
def append_underover(base, under, over)
|
146
|
-
blank(
|
148
|
+
blank(ZWJ)
|
147
149
|
underover do
|
148
150
|
smaller do
|
149
151
|
if over
|
150
152
|
append(over, :strip_paren => true)
|
151
153
|
else
|
152
|
-
blank(
|
154
|
+
blank(ZWJ)
|
153
155
|
end
|
154
156
|
end
|
155
157
|
append(base)
|
@@ -157,14 +159,14 @@ module AsciiMath
|
|
157
159
|
if under
|
158
160
|
append(under, :strip_paren => true)
|
159
161
|
else
|
160
|
-
blank(
|
162
|
+
blank(ZWJ)
|
161
163
|
end
|
162
164
|
end
|
163
165
|
end
|
164
166
|
end
|
165
167
|
|
166
168
|
def append_fraction(numerator, denominator)
|
167
|
-
blank(
|
169
|
+
blank(ZWJ)
|
168
170
|
fraction do
|
169
171
|
fraction_row do
|
170
172
|
fraction_cell do
|
@@ -203,7 +205,7 @@ module AsciiMath
|
|
203
205
|
|
204
206
|
if block_given? || text
|
205
207
|
@html << '>'
|
206
|
-
@html << text
|
208
|
+
@html << text.encode(Encoding::US_ASCII, :xml => :text) if text
|
207
209
|
yield if block_given?
|
208
210
|
@html << '</span>'
|
209
211
|
else
|
data/lib/asciimath/mathml.rb
CHANGED
data/lib/asciimath/parser.rb
CHANGED
@@ -55,7 +55,8 @@ module AsciiMath
|
|
55
55
|
class Tokenizer
|
56
56
|
WHITESPACE = /^\s+/
|
57
57
|
NUMBER = /-?[0-9]+(?:\.[0-9]+)?/
|
58
|
-
|
58
|
+
QUOTED_TEXT = /"[^"]*"/
|
59
|
+
TEX_TEXT = /text\([^)]*\)/
|
59
60
|
|
60
61
|
# Public: Initializes an ASCIIMath tokenizer.
|
61
62
|
#
|
@@ -85,12 +86,19 @@ module AsciiMath
|
|
85
86
|
return {:value => nil, :type => :eof} if @string.eos?
|
86
87
|
|
87
88
|
case @string.peek(1)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
when '"'
|
90
|
+
read_quoted_text
|
91
|
+
when 't'
|
92
|
+
case @string.peek(5)
|
93
|
+
when 'text('
|
94
|
+
read_tex_text
|
92
95
|
else
|
93
|
-
read_symbol
|
96
|
+
read_symbol
|
97
|
+
end
|
98
|
+
when '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
99
|
+
read_number || read_symbol
|
100
|
+
else
|
101
|
+
read_symbol
|
94
102
|
end
|
95
103
|
end
|
96
104
|
|
@@ -109,12 +117,22 @@ module AsciiMath
|
|
109
117
|
#
|
110
118
|
# Returns the text token or nil if a text token could not be matched at
|
111
119
|
# the current position
|
112
|
-
def
|
113
|
-
read_value(
|
120
|
+
def read_quoted_text
|
121
|
+
read_value(QUOTED_TEXT) do |text|
|
114
122
|
{:value => text[1..-2], :type => :text}
|
115
123
|
end
|
116
124
|
end
|
117
125
|
|
126
|
+
# Private: Reads a text token from the input string
|
127
|
+
#
|
128
|
+
# Returns the text token or nil if a text token could not be matched at
|
129
|
+
# the current position
|
130
|
+
def read_tex_text
|
131
|
+
read_value(TEX_TEXT) do |text|
|
132
|
+
{:value => text[5..-2], :type => :text}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
118
136
|
# Private: Reads a number token from the input string
|
119
137
|
#
|
120
138
|
# Returns the number token or nil if a number token could not be matched at
|
@@ -185,69 +203,72 @@ module AsciiMath
|
|
185
203
|
SYMBOLS = {
|
186
204
|
# Operation symbols
|
187
205
|
'+' => {:value => '+', :type => :operator},
|
188
|
-
'-' => {:value =>
|
189
|
-
'*' => {:value =>
|
190
|
-
'**' => {:value =>
|
206
|
+
'-' => {:value => "\u2212", :type => :operator},
|
207
|
+
'*' => {:value => "\u22C5", :type => :operator},
|
208
|
+
'**' => {:value => "\u002A", :type => :operator},
|
209
|
+
'***' => {:value => "\u22C6", :type => :operator},
|
191
210
|
'//' => {:value => '/', :type => :operator},
|
192
211
|
'\\\\' => {:value => '\\', :type => :operator},
|
193
|
-
'xx' => {:value =>
|
194
|
-
'-:' => {:value =>
|
195
|
-
'
|
196
|
-
'
|
197
|
-
'
|
198
|
-
'
|
199
|
-
'
|
200
|
-
'
|
201
|
-
'
|
202
|
-
'
|
203
|
-
'
|
204
|
-
'
|
205
|
-
'
|
206
|
-
'
|
207
|
-
'
|
208
|
-
'
|
212
|
+
'xx' => {:value => "\u00D7", :type => :operator},
|
213
|
+
'-:' => {:value => "\u00F7", :type => :operator},
|
214
|
+
'|><' => {:value => "\u22C9", :type => :operator},
|
215
|
+
'><|' => {:value => "\u22CA", :type => :operator},
|
216
|
+
'|><|' => {:value => "\u22C8", :type => :operator},
|
217
|
+
'@' => {:value => "\u26AC", :type => :operator},
|
218
|
+
'o+' => {:value => "\u2295", :type => :operator},
|
219
|
+
'ox' => {:value => "\u2297", :type => :operator},
|
220
|
+
'o.' => {:value => "\u2299", :type => :operator},
|
221
|
+
'sum' => {:value => "\u2211", :type => :operator, :underover => true},
|
222
|
+
'prod' => {:value => "\u220F", :type => :operator, :underover => true},
|
223
|
+
'^^' => {:value => "\u2227", :type => :operator},
|
224
|
+
'^^^' => {:value => "\u22C0", :type => :operator, :underover => true},
|
225
|
+
'vv' => {:value => "\u2228", :type => :operator},
|
226
|
+
'vvv' => {:value => "\u22C1", :type => :operator, :underover => true},
|
227
|
+
'nn' => {:value => "\u2229", :type => :operator},
|
228
|
+
'nnn' => {:value => "\u22C2", :type => :operator, :underover => true},
|
229
|
+
'uu' => {:value => "\u222A", :type => :operator},
|
230
|
+
'uuu' => {:value => "\u22C3", :type => :operator, :underover => true},
|
209
231
|
|
210
232
|
# Relation symbols
|
211
233
|
'=' => {:value => '=', :type => :operator},
|
212
|
-
'!=' => {:value =>
|
234
|
+
'!=' => {:value => "\u2260", :type => :operator},
|
213
235
|
':=' => {:value => ':=', :type => :operator},
|
214
|
-
'<' => {:value =>
|
215
|
-
'lt' => {:value =>
|
216
|
-
'>' => {:value =>
|
217
|
-
'gt' => {:value =>
|
218
|
-
'<=' => {:value =>
|
219
|
-
'
|
220
|
-
'>=' => {:value =>
|
221
|
-
'
|
222
|
-
'-<' => {:value =>
|
223
|
-
'
|
224
|
-
'
|
225
|
-
'
|
226
|
-
'
|
227
|
-
'in' => {:value =>
|
228
|
-
'
|
229
|
-
'
|
230
|
-
'
|
231
|
-
'
|
232
|
-
'
|
233
|
-
'
|
234
|
-
'
|
235
|
-
'
|
236
|
-
'prop' => {:value => '∝', :type => :operator},
|
236
|
+
'<' => {:value => "\u003C", :type => :operator},
|
237
|
+
'lt' => {:value => "\u003C", :type => :operator},
|
238
|
+
'>' => {:value => "\u003E", :type => :operator},
|
239
|
+
'gt' => {:value => "\u003E", :type => :operator},
|
240
|
+
'<=' => {:value => "\u2264", :type => :operator},
|
241
|
+
'le' => {:value => "\u2264", :type => :operator},
|
242
|
+
'>=' => {:value => "\u2265", :type => :operator},
|
243
|
+
'ge' => {:value => "\u2265", :type => :operator},
|
244
|
+
'-<' => {:value => "\u227A", :type => :operator},
|
245
|
+
'>-' => {:value => "\u227B", :type => :operator},
|
246
|
+
'-<=' => {:value => "\u2AAF", :type => :operator},
|
247
|
+
'>-=' => {:value => "\u2AB0", :type => :operator},
|
248
|
+
'in' => {:value => "\u2208", :type => :operator},
|
249
|
+
'!in' => {:value => "\u2209", :type => :operator},
|
250
|
+
'sub' => {:value => "\u2282", :type => :operator},
|
251
|
+
'sup' => {:value => "\u2283", :type => :operator},
|
252
|
+
'sube' => {:value => "\u2286", :type => :operator},
|
253
|
+
'supe' => {:value => "\u2287", :type => :operator},
|
254
|
+
'-=' => {:value => "\u2261", :type => :operator},
|
255
|
+
'~=' => {:value => "\u2245", :type => :operator},
|
256
|
+
'~~' => {:value => "\u2248", :type => :operator},
|
257
|
+
'prop' => {:value => "\u221D", :type => :operator},
|
237
258
|
|
238
259
|
# Logical symbols
|
239
260
|
'and' => {:value => 'and', :type => :text},
|
240
261
|
'or' => {:value => 'or', :type => :text},
|
241
|
-
'not' => {:value =>
|
242
|
-
'=>' => {:value =>
|
262
|
+
'not' => {:value => "\u00AC", :type => :operator},
|
263
|
+
'=>' => {:value => "\u21D2", :type => :operator},
|
243
264
|
'if' => {:value => 'if', :type => :operator},
|
244
|
-
'<=>' => {:value =>
|
245
|
-
'AA' => {:value =>
|
246
|
-
'EE' => {:value =>
|
247
|
-
'_|_' => {:value =>
|
248
|
-
'TT' => {:value =>
|
249
|
-
'|--' => {:value =>
|
250
|
-
'|==' => {:value =>
|
265
|
+
'<=>' => {:value => "\u21D4", :type => :operator},
|
266
|
+
'AA' => {:value => "\u2200", :type => :operator},
|
267
|
+
'EE' => {:value => "\u2203", :type => :operator},
|
268
|
+
'_|_' => {:value => "\u22A5", :type => :operator},
|
269
|
+
'TT' => {:value => "\u22A4", :type => :operator},
|
270
|
+
'|--' => {:value => "\u22A2", :type => :operator},
|
271
|
+
'|==' => {:value => "\u22A8", :type => :operator},
|
251
272
|
|
252
273
|
# Grouping brackets
|
253
274
|
'(' => {:value => '(', :type => :lparen},
|
@@ -256,97 +277,107 @@ module AsciiMath
|
|
256
277
|
']' => {:value => ']', :type => :rparen},
|
257
278
|
'{' => {:value => '{', :type => :lparen},
|
258
279
|
'}' => {:value => '}', :type => :rparen},
|
280
|
+
'(:' => {:value => "\u2329", :type => :lparen},
|
281
|
+
':)' => {:value => "\u232A", :type => :rparen},
|
282
|
+
'<<' => {:value => "\u2329", :type => :lparen},
|
283
|
+
'>>' => {:value => "\u232A", :type => :rparen},
|
259
284
|
'|' => {:value => '|', :type => :lrparen},
|
260
285
|
'||' => {:value => '||', :type => :lrparen},
|
261
|
-
'(:' => {:value => '〈', :type => :lparen},
|
262
|
-
':)' => {:value => '〉', :type => :rparen},
|
263
|
-
'<<' => {:value => '〈', :type => :lparen},
|
264
|
-
'>>' => {:value => '〉', :type => :rparen},
|
265
286
|
'{:' => {:value => nil, :type => :lparen},
|
266
287
|
':}' => {:value => nil, :type => :rparen},
|
267
288
|
|
268
289
|
# Miscellaneous symbols
|
269
|
-
'int' => {:value =>
|
290
|
+
'int' => {:value => "\u222B", :type => :operator},
|
270
291
|
'dx' => {:value => 'dx', :type => :identifier},
|
271
292
|
'dy' => {:value => 'dy', :type => :identifier},
|
272
293
|
'dz' => {:value => 'dz', :type => :identifier},
|
273
294
|
'dt' => {:value => 'dt', :type => :identifier},
|
274
|
-
'oint' => {:value =>
|
275
|
-
'del' => {:value =>
|
276
|
-
'grad' => {:value =>
|
277
|
-
'+-' => {:value =>
|
278
|
-
'O/' => {:value =>
|
279
|
-
'oo' => {:value =>
|
280
|
-
'aleph' => {:value =>
|
295
|
+
'oint' => {:value => "\u222E", :type => :operator},
|
296
|
+
'del' => {:value => "\u2202", :type => :operator},
|
297
|
+
'grad' => {:value => "\u2207", :type => :operator},
|
298
|
+
'+-' => {:value => "\u00B1", :type => :operator},
|
299
|
+
'O/' => {:value => "\u2205", :type => :operator},
|
300
|
+
'oo' => {:value => "\u221E", :type => :operator},
|
301
|
+
'aleph' => {:value => "\u2135", :type => :operator},
|
281
302
|
'...' => {:value => '...', :type => :operator},
|
282
|
-
':.' => {:value =>
|
283
|
-
'/_' => {:value =>
|
284
|
-
'\\ ' => {:value =>
|
303
|
+
':.' => {:value => "\u2234", :type => :operator},
|
304
|
+
'/_' => {:value => "\u2220", :type => :operator},
|
305
|
+
'\\ ' => {:value => "\u00A0", :type => :operator},
|
285
306
|
'quad' => {:value => '\u00A0\u00A0', :type => :operator},
|
286
307
|
'qquad' => {:value => '\u00A0\u00A0\u00A0\u00A0', :type => :operator},
|
287
|
-
'cdots' => {:value =>
|
288
|
-
'vdots' => {:value =>
|
289
|
-
'ddots' => {:value =>
|
290
|
-
'diamond' => {:value =>
|
291
|
-
'square' => {:value =>
|
292
|
-
'|__' => {:value =>
|
293
|
-
'__|' => {:value =>
|
294
|
-
'|~' => {:value =>
|
295
|
-
'~|' => {:value =>
|
296
|
-
'CC' => {:value =>
|
297
|
-
'NN' => {:value =>
|
298
|
-
'QQ' => {:value =>
|
299
|
-
'RR' => {:value =>
|
300
|
-
'ZZ' => {:value =>
|
301
|
-
'f' => {:value => 'f', :type => :identifier},
|
302
|
-
'g' => {:value => 'g', :type => :identifier},
|
308
|
+
'cdots' => {:value => "\u22EF", :type => :operator},
|
309
|
+
'vdots' => {:value => "\u22EE", :type => :operator},
|
310
|
+
'ddots' => {:value => "\u22F1", :type => :operator},
|
311
|
+
'diamond' => {:value => "\u22C4", :type => :operator},
|
312
|
+
'square' => {:value => "\u25A1", :type => :operator},
|
313
|
+
'|__' => {:value => "\u230A", :type => :operator},
|
314
|
+
'__|' => {:value => "\u230B", :type => :operator},
|
315
|
+
'|~' => {:value => "\u2308", :type => :operator},
|
316
|
+
'~|' => {:value => "\u2309", :type => :operator},
|
317
|
+
'CC' => {:value => "\u2102", :type => :operator},
|
318
|
+
'NN' => {:value => "\u2115", :type => :operator},
|
319
|
+
'QQ' => {:value => "\u211A", :type => :operator},
|
320
|
+
'RR' => {:value => "\u211D", :type => :operator},
|
321
|
+
'ZZ' => {:value => "\u2124", :type => :operator},
|
303
322
|
|
304
|
-
# Standard functions
|
305
323
|
'lim' => {:value => 'lim', :type => :operator, :underover => true},
|
306
324
|
'Lim' => {:value => 'Lim', :type => :operator, :underover => true},
|
307
|
-
|
308
|
-
|
309
|
-
'
|
310
|
-
'
|
311
|
-
'
|
312
|
-
'
|
313
|
-
'
|
314
|
-
'
|
315
|
-
'
|
316
|
-
'
|
317
|
-
'
|
318
|
-
'
|
319
|
-
'
|
320
|
-
'
|
321
|
-
'
|
322
|
-
'
|
323
|
-
'
|
324
|
-
'
|
325
|
-
'
|
326
|
-
'
|
325
|
+
|
326
|
+
# Standard functions
|
327
|
+
'sin' => {:value => 'sin', :type => :identifier},
|
328
|
+
'cos' => {:value => 'cos', :type => :identifier},
|
329
|
+
'tan' => {:value => 'tan', :type => :identifier},
|
330
|
+
'sec' => {:value => 'sec', :type => :identifier},
|
331
|
+
'csc' => {:value => 'csc', :type => :identifier},
|
332
|
+
'cot' => {:value => 'cot', :type => :identifier},
|
333
|
+
'arcsin' => {:value => 'arcsin', :type => :identifier},
|
334
|
+
'arccos' => {:value => 'arccos', :type => :identifier},
|
335
|
+
'arctan' => {:value => 'arctan', :type => :identifier},
|
336
|
+
'sinh' => {:value => 'sinh', :type => :identifier},
|
337
|
+
'cosh' => {:value => 'cosh', :type => :identifier},
|
338
|
+
'tanh' => {:value => 'tanh', :type => :identifier},
|
339
|
+
'sech' => {:value => 'sech', :type => :identifier},
|
340
|
+
'csch' => {:value => 'csch', :type => :identifier},
|
341
|
+
'coth' => {:value => 'coth', :type => :identifier},
|
342
|
+
'exp' => {:value => 'exp', :type => :identifier},
|
343
|
+
'log' => {:value => 'log', :type => :identifier},
|
344
|
+
'ln' => {:value => 'ln', :type => :identifier},
|
345
|
+
'det' => {:value => 'det', :type => :identifier},
|
346
|
+
'dim' => {:value => 'dim', :type => :identifier},
|
347
|
+
'mod' => {:value => 'mod', :type => :identifier},
|
348
|
+
'gcd' => {:value => 'gcd', :type => :identifier},
|
349
|
+
'lcm' => {:value => 'lcm', :type => :identifier},
|
350
|
+
'lub' => {:value => 'lub', :type => :identifier},
|
351
|
+
'glb' => {:value => 'glb', :type => :identifier},
|
352
|
+
'min' => {:value => 'min', :type => :identifier, :underover => true},
|
353
|
+
'max' => {:value => 'max', :type => :identifier, :underover => true},
|
354
|
+
'f' => {:value => 'f', :type => :identifier},
|
355
|
+
'g' => {:value => 'g', :type => :identifier},
|
327
356
|
|
328
357
|
# Accents
|
329
|
-
'hat' => {:value =>
|
330
|
-
'bar' => {:value =>
|
358
|
+
'hat' => {:value => "\u005E", :type => :accent, :position => :over},
|
359
|
+
'bar' => {:value => "\u00AF", :type => :accent, :position => :over},
|
331
360
|
'ul' => {:value => '_', :type => :accent, :position => :under},
|
332
|
-
'vec' => {:value =>
|
361
|
+
'vec' => {:value => "\u2192", :type => :accent, :position => :over},
|
333
362
|
'dot' => {:value => '.', :type => :accent, :position => :over},
|
334
363
|
'ddot' => {:value => '..', :type => :accent, :position => :over},
|
364
|
+
'obrace' => {:value => "\u23DE", :type => :accent, :position => :over},
|
365
|
+
'ubrace' => {:value => "\u23DF", :type => :accent, :position => :under},
|
335
366
|
|
336
367
|
# Arrows
|
337
|
-
'uarr' => {:value =>
|
338
|
-
'darr' => {:value =>
|
339
|
-
'rarr' => {:value =>
|
340
|
-
'->' => {:value =>
|
341
|
-
'>->' => {:value =>
|
342
|
-
'->>' => {:value =>
|
343
|
-
'>->>' => {:value =>
|
344
|
-
'|->' => {:value =>
|
345
|
-
'larr' => {:value =>
|
346
|
-
'harr' => {:value =>
|
347
|
-
'rArr' => {:value =>
|
348
|
-
'lArr' => {:value =>
|
349
|
-
'hArr' => {:value =>
|
368
|
+
'uarr' => {:value => "\u2191", :type => :operator},
|
369
|
+
'darr' => {:value => "\u2193", :type => :operator},
|
370
|
+
'rarr' => {:value => "\u2192", :type => :operator},
|
371
|
+
'->' => {:value => "\u2192", :type => :operator},
|
372
|
+
'>->' => {:value => "\u21A3", :type => :operator},
|
373
|
+
'->>' => {:value => "\u21A0", :type => :operator},
|
374
|
+
'>->>' => {:value => "\u2916", :type => :operator},
|
375
|
+
'|->' => {:value => "\u21A6", :type => :operator},
|
376
|
+
'larr' => {:value => "\u2190", :type => :operator},
|
377
|
+
'harr' => {:value => "\u2194", :type => :operator},
|
378
|
+
'rArr' => {:value => "\u21D2", :type => :operator},
|
379
|
+
'lArr' => {:value => "\u21D0", :type => :operator},
|
380
|
+
'hArr' => {:value => "\u21D4", :type => :operator},
|
350
381
|
|
351
382
|
# Other
|
352
383
|
'sqrt' => {:value => :sqrt, :type => :unary},
|
@@ -372,57 +403,57 @@ module AsciiMath
|
|
372
403
|
'^' => {:value => :sup, :type => :infix},
|
373
404
|
|
374
405
|
# Greek letters
|
375
|
-
'alpha' => {:value =>
|
376
|
-
'Alpha' => {:value =>
|
377
|
-
'beta' => {:value =>
|
378
|
-
'Beta' => {:value =>
|
379
|
-
'gamma' => {:value =>
|
380
|
-
'Gamma' => {:value =>
|
381
|
-
'delta' => {:value =>
|
382
|
-
'Delta' => {:value =>
|
383
|
-
'epsilon' => {:value =>
|
384
|
-
'Epsilon' => {:value =>
|
385
|
-
'varepsilon' => {:value =>
|
386
|
-
'zeta' => {:value =>
|
387
|
-
'Zeta' => {:value =>
|
388
|
-
'eta' => {:value =>
|
389
|
-
'Eta' => {:value =>
|
390
|
-
'theta' => {:value =>
|
391
|
-
'Theta' => {:value =>
|
392
|
-
'vartheta' => {:value =>
|
393
|
-
'iota' => {:value =>
|
394
|
-
'Iota' => {:value =>
|
395
|
-
'kappa' => {:value =>
|
396
|
-
'Kappa' => {:value =>
|
397
|
-
'lambda' => {:value =>
|
398
|
-
'Lambda' => {:value =>
|
399
|
-
'mu' => {:value =>
|
400
|
-
'Mu' => {:value =>
|
401
|
-
'nu' => {:value =>
|
402
|
-
'Nu' => {:value =>
|
403
|
-
'xi' => {:value =>
|
404
|
-
'Xi' => {:value =>
|
405
|
-
'omicron' => {:value =>
|
406
|
-
'Omicron' => {:value =>
|
407
|
-
'pi' => {:value =>
|
408
|
-
'Pi' => {:value =>
|
409
|
-
'rho' => {:value =>
|
410
|
-
'Rho' => {:value =>
|
411
|
-
'sigma' => {:value =>
|
412
|
-
'Sigma' => {:value =>
|
413
|
-
'tau' => {:value =>
|
414
|
-
'Tau' => {:value =>
|
415
|
-
'upsilon' => {:value =>
|
416
|
-
'Upsilon' => {:value =>
|
417
|
-
'phi' => {:value =>
|
418
|
-
'Phi' => {:value =>
|
419
|
-
'varphi' => {:value =>
|
406
|
+
'alpha' => {:value => "\u03b1", :type => :identifier},
|
407
|
+
'Alpha' => {:value => "\u0391", :type => :identifier},
|
408
|
+
'beta' => {:value => "\u03b2", :type => :identifier},
|
409
|
+
'Beta' => {:value => "\u0392", :type => :identifier},
|
410
|
+
'gamma' => {:value => "\u03b3", :type => :identifier},
|
411
|
+
'Gamma' => {:value => "\u0393", :type => :operator},
|
412
|
+
'delta' => {:value => "\u03b4", :type => :identifier},
|
413
|
+
'Delta' => {:value => "\u0394", :type => :operator},
|
414
|
+
'epsilon' => {:value => "\u03b5", :type => :identifier},
|
415
|
+
'Epsilon' => {:value => "\u0395", :type => :identifier},
|
416
|
+
'varepsilon' => {:value => "\u025b", :type => :identifier},
|
417
|
+
'zeta' => {:value => "\u03b6", :type => :identifier},
|
418
|
+
'Zeta' => {:value => "\u0396", :type => :identifier},
|
419
|
+
'eta' => {:value => "\u03b7", :type => :identifier},
|
420
|
+
'Eta' => {:value => "\u0397", :type => :identifier},
|
421
|
+
'theta' => {:value => "\u03b8", :type => :identifier},
|
422
|
+
'Theta' => {:value => "\u0398", :type => :operator},
|
423
|
+
'vartheta' => {:value => "\u03d1", :type => :identifier},
|
424
|
+
'iota' => {:value => "\u03b9", :type => :identifier},
|
425
|
+
'Iota' => {:value => "\u0399", :type => :identifier},
|
426
|
+
'kappa' => {:value => "\u03ba", :type => :identifier},
|
427
|
+
'Kappa' => {:value => "\u039a", :type => :identifier},
|
428
|
+
'lambda' => {:value => "\u03bb", :type => :identifier},
|
429
|
+
'Lambda' => {:value => "\u039b", :type => :operator},
|
430
|
+
'mu' => {:value => "\u03bc", :type => :identifier},
|
431
|
+
'Mu' => {:value => "\u039c", :type => :identifier},
|
432
|
+
'nu' => {:value => "\u03bd", :type => :identifier},
|
433
|
+
'Nu' => {:value => "\u039d", :type => :identifier},
|
434
|
+
'xi' => {:value => "\u03be", :type => :identifier},
|
435
|
+
'Xi' => {:value => "\u039e", :type => :operator},
|
436
|
+
'omicron' => {:value => "\u03bf", :type => :identifier},
|
437
|
+
'Omicron' => {:value => "\u039f", :type => :identifier},
|
438
|
+
'pi' => {:value => "\u03c0", :type => :identifier},
|
439
|
+
'Pi' => {:value => "\u03a0", :type => :operator},
|
440
|
+
'rho' => {:value => "\u03c1", :type => :identifier},
|
441
|
+
'Rho' => {:value => "\u03a1", :type => :identifier},
|
442
|
+
'sigma' => {:value => "\u03c3", :type => :identifier},
|
443
|
+
'Sigma' => {:value => "\u03a3", :type => :operator},
|
444
|
+
'tau' => {:value => "\u03c4", :type => :identifier},
|
445
|
+
'Tau' => {:value => "\u03a4", :type => :identifier},
|
446
|
+
'upsilon' => {:value => "\u03c5", :type => :identifier},
|
447
|
+
'Upsilon' => {:value => "\u03a5", :type => :identifier},
|
448
|
+
'phi' => {:value => "\u03c6", :type => :identifier},
|
449
|
+
'Phi' => {:value => "\u03a6", :type => :identifier},
|
450
|
+
'varphi' => {:value => "\u03d5", :type => :identifier},
|
420
451
|
'chi' => {:value => '\u03b3c7', :type => :identifier},
|
421
452
|
'Chi' => {:value => '\u0393a7', :type => :identifier},
|
422
|
-
'psi' => {:value =>
|
423
|
-
'Psi' => {:value =>
|
424
|
-
'omega' => {:value =>
|
425
|
-
'Omega' => {:value =>
|
453
|
+
'psi' => {:value => "\u03c8", :type => :identifier},
|
454
|
+
'Psi' => {:value => "\u03a8", :type => :identifier},
|
455
|
+
'omega' => {:value => "\u03c9", :type => :identifier},
|
456
|
+
'Omega' => {:value => "\u03a9", :type => :operator},
|
426
457
|
}
|
427
458
|
|
428
459
|
def parse(input)
|
data/lib/asciimath/version.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -5,33 +5,33 @@ require 'asciimath'
|
|
5
5
|
TEST_CASES = {
|
6
6
|
'x+b/(2a)<+-sqrt((b^2)/(4a^2)-c/a)' =>
|
7
7
|
{
|
8
|
-
:mathml => '<math><mi>x</mi><mo>+</mo><mfrac><mi>b</mi><mrow><mn>2</mn><mi>a</mi></mrow></mfrac><mo
|
9
|
-
:html =>
|
8
|
+
:mathml => '<math><mi>x</mi><mo>+</mo><mfrac><mi>b</mi><mrow><mn>2</mn><mi>a</mi></mrow></mfrac><mo><</mo><mo>±</mo><msqrt><mrow><mfrac><msup><mi>b</mi><mn>2</mn></msup><mrow><mn>4</mn><msup><mi>a</mi><mn>2</mn></msup></mrow></mfrac><mo>−</mo><mfrac><mi>c</mi><mi>a</mi></mfrac></mrow></msqrt></math>',
|
9
|
+
:html => nil,
|
10
10
|
},
|
11
11
|
'a^2 + b^2 = c^2' =>
|
12
12
|
{
|
13
13
|
:mathml => '<math><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup><mo>=</mo><msup><mi>c</mi><mn>2</mn></msup></math>',
|
14
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller"><span class="math-number">2</span></span><span class="math-smaller"
|
14
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller"><span class="math-number">2</span></span><span class="math-smaller">舅</span></span><span class="math-operator">+</span><span class="math-identifier">b</span><span class="math-subsup"><span class="math-smaller"><span class="math-number">2</span></span><span class="math-smaller">舅</span></span><span class="math-operator">=</span><span class="math-identifier">c</span><span class="math-subsup"><span class="math-smaller"><span class="math-number">2</span></span><span class="math-smaller">舅</span></span></span></span>',
|
15
15
|
},
|
16
16
|
'x = (-b+-sqrt(b^2-4ac))/(2a)' =>
|
17
17
|
{
|
18
|
-
:mathml => '<math><mi>x</mi><mo>=</mo><mfrac><mrow><mo>−</mo><mi>b</mi><mo>&#
|
19
|
-
:html =>
|
18
|
+
:mathml => '<math><mi>x</mi><mo>=</mo><mfrac><mrow><mo>−</mo><mi>b</mi><mo>±</mo><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mn>-4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></math>',
|
19
|
+
:html => nil
|
20
20
|
},
|
21
21
|
'm = (y_2 - y_1)/(x_2 - x_1) = (Deltay)/(Deltax)' =>
|
22
22
|
{
|
23
|
-
:mathml => '<math><mi>m</mi><mo>=</mo><mfrac><mrow><msub><mi>y</mi><mn>2</mn></msub><mo>−</mo><msub><mi>y</mi><mn>1</mn></msub></mrow><mrow><msub><mi>x</mi><mn>2</mn></msub><mo>−</mo><msub><mi>x</mi><mn>1</mn></msub></mrow></mfrac><mo>=</mo><mfrac><mrow><mo>&#
|
24
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">m</span><span class="math-operator">=</span><span class="math-blank"
|
23
|
+
:mathml => '<math><mi>m</mi><mo>=</mo><mfrac><mrow><msub><mi>y</mi><mn>2</mn></msub><mo>−</mo><msub><mi>y</mi><mn>1</mn></msub></mrow><mrow><msub><mi>x</mi><mn>2</mn></msub><mo>−</mo><msub><mi>x</mi><mn>1</mn></msub></mrow></mfrac><mo>=</mo><mfrac><mrow><mo>Δ</mo><mi>y</mi></mrow><mrow><mo>Δ</mo><mi>x</mi></mrow></mfrac></math>',
|
24
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">m</span><span class="math-operator">=</span><span class="math-blank">舅</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">y</span><span class="math-subsup"><span class="math-smaller">舅</span><span class="math-smaller"><span class="math-number">2</span></span></span><span class="math-operator">−</span><span class="math-identifier">y</span><span class="math-subsup"><span class="math-smaller">舅</span><span class="math-smaller"><span class="math-number">1</span></span></span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">x</span><span class="math-subsup"><span class="math-smaller">舅</span><span class="math-smaller"><span class="math-number">2</span></span></span><span class="math-operator">−</span><span class="math-identifier">x</span><span class="math-subsup"><span class="math-smaller">舅</span><span class="math-smaller"><span class="math-number">1</span></span></span></span></span></span></span></span></span><span class="math-operator">=</span><span class="math-blank">舅</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-operator">Δ</span><span class="math-identifier">y</span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-operator">Δ</span><span class="math-identifier">x</span></span></span></span></span></span></span></span></span>'
|
25
25
|
},
|
26
26
|
'f\'(x) = lim_(Deltax->0)(f(x+Deltax)-f(x))/(Deltax)' =>
|
27
27
|
{
|
28
|
-
:mathml => '<math><mi>f</mi><mi>\'</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>=</mo><munder><mo>lim</mo><mrow><mo>&#
|
29
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">f</span><span class="math-identifier">\'</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-operator">=</span><span class="math-blank"
|
28
|
+
:mathml => '<math><mi>f</mi><mi>\'</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>=</mo><munder><mo>lim</mo><mrow><mo>Δ</mo><mi>x</mi><mo>→</mo><mn>0</mn></mrow></munder><mfrac><mrow><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>+</mo><mo>Δ</mo><mi>x</mi><mo>)</mo></mrow><mo>−</mo><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow></mrow><mrow><mo>Δ</mo><mi>x</mi></mrow></mfrac></math>',
|
29
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">f</span><span class="math-identifier">\'</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-operator">=</span><span class="math-blank">舅</span><span class="math-underover"><span class="math-smaller"><span class="math-blank">舅</span></span><span class="math-operator">lim</span><span class="math-smaller"><span class="math-row"><span class="math-operator">Δ</span><span class="math-identifier">x</span><span class="math-operator">→</span><span class="math-number">0</span></span></span></span><span class="math-blank">舅</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span><span class="math-operator">+</span><span class="math-operator">Δ</span><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-operator">−</span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-operator">Δ</span><span class="math-identifier">x</span></span></span></span></span></span></span></span></span>'
|
30
30
|
},
|
31
31
|
'd/dx [x^n] = nx^(n - 1)' =>
|
32
32
|
{
|
33
33
|
:mathml => '<math><mfrac><mi>d</mi><mi>dx</mi></mfrac><mrow><mo>[</mo><msup><mi>x</mi><mi>n</mi></msup><mo>]</mo></mrow><mo>=</mo><mi>n</mi><msup><mi>x</mi><mrow><mi>n</mi><mo>−</mo><mn>1</mn></mrow></msup></math>',
|
34
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank"
|
34
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank">舅</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-identifier">d</span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-identifier">dx</span></span></span></span></span></span><span class="math-row"><span class="math-brace">[</span><span class="math-row"><span class="math-identifier">x</span><span class="math-subsup"><span class="math-smaller"><span class="math-identifier">n</span></span><span class="math-smaller">舅</span></span></span><span class="math-brace">]</span></span><span class="math-operator">=</span><span class="math-identifier">n</span><span class="math-identifier">x</span><span class="math-subsup"><span class="math-smaller"><span class="math-row"><span class="math-identifier">n</span><span class="math-operator">−</span><span class="math-number">1</span></span></span><span class="math-smaller">舅</span></span></span></span>'
|
35
35
|
},
|
36
36
|
'int_a^b f(x) dx = [F(x)]_a^b = F(b) - F(a)' =>
|
37
37
|
{
|
@@ -46,22 +46,22 @@ TEST_CASES = {
|
|
46
46
|
'ax^2 + bx + c = 0' =>
|
47
47
|
{
|
48
48
|
:mathml => '<math><mi>a</mi><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>b</mi><mi>x</mi><mo>+</mo><mi>c</mi><mo>=</mo><mn>0</mn></math>',
|
49
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">a</span><span class="math-identifier">x</span><span class="math-subsup"><span class="math-smaller"><span class="math-number">2</span></span><span class="math-smaller"
|
49
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">a</span><span class="math-identifier">x</span><span class="math-subsup"><span class="math-smaller"><span class="math-number">2</span></span><span class="math-smaller">舅</span></span><span class="math-operator">+</span><span class="math-identifier">b</span><span class="math-identifier">x</span><span class="math-operator">+</span><span class="math-identifier">c</span><span class="math-operator">=</span><span class="math-number">0</span></span></span>'
|
50
50
|
},
|
51
51
|
'"average value"=1/(b-a) int_a^b f(x) dx' =>
|
52
52
|
{
|
53
53
|
:mathml => '<math><mtext>average value</mtext><mo>=</mo><mfrac><mn>1</mn><mrow><mi>b</mi><mo>−</mo><mi>a</mi></mrow></mfrac><msubsup><mo>∫</mo><mi>a</mi><mi>b</mi></msubsup><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mi>dx</mi></math>',
|
54
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-text">average value</span><span class="math-operator">=</span><span class="math-blank"
|
54
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-text">average value</span><span class="math-operator">=</span><span class="math-blank">舅</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-number">1</span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">b</span><span class="math-operator">−</span><span class="math-identifier">a</span></span></span></span></span></span></span><span class="math-operator">∫</span><span class="math-subsup"><span class="math-smaller"><span class="math-identifier">b</span></span><span class="math-smaller"><span class="math-identifier">a</span></span></span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-identifier">dx</span></span></span>'
|
55
55
|
},
|
56
56
|
'd/dx[int_a^x f(t) dt] = f(x)' =>
|
57
57
|
{
|
58
58
|
:mathml => '<math><mfrac><mi>d</mi><mi>dx</mi></mfrac><mrow><mo>[</mo><msubsup><mo>∫</mo><mi>a</mi><mi>x</mi></msubsup><mi>f</mi><mrow><mo>(</mo><mi>t</mi><mo>)</mo></mrow><mi>dt</mi><mo>]</mo></mrow><mo>=</mo><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow></math>',
|
59
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank"
|
59
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank">舅</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-identifier">d</span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-identifier">dx</span></span></span></span></span></span><span class="math-row"><span class="math-brace">[</span><span class="math-row"><span class="math-operator">∫</span><span class="math-subsup"><span class="math-smaller"><span class="math-identifier">x</span></span><span class="math-smaller"><span class="math-identifier">a</span></span></span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">t</span></span><span class="math-brace">)</span></span><span class="math-identifier">dt</span></span><span class="math-brace">]</span></span><span class="math-operator">=</span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span></span></span>'
|
60
60
|
},
|
61
61
|
'hat(ab) bar(xy) ul(A) vec(v)' =>
|
62
62
|
{
|
63
|
-
:mathml => '<math><mover><mrow><mi>a</mi><mi>b</mi></mrow><mo
|
64
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank"
|
63
|
+
:mathml => '<math><mover><mrow><mi>a</mi><mi>b</mi></mrow><mo>^</mo></mover><mover><mrow><mi>x</mi><mi>y</mi></mrow><mo>¯</mo></mover><munder><mi>A</mi><mo>_</mo></munder><mover><mi>v</mi><mo>→</mo></mover></math>',
|
64
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank">舅</span><span class="math-underover"><span class="math-smaller"><span class="math-operator">^</span></span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">a</span><span class="math-identifier">b</span></span><span class="math-brace">)</span></span><span class="math-smaller"><span class="math-blank">舅</span></span></span><span class="math-blank">舅</span><span class="math-underover"><span class="math-smaller"><span class="math-operator">¯</span></span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span><span class="math-identifier">y</span></span><span class="math-brace">)</span></span><span class="math-smaller"><span class="math-blank">舅</span></span></span><span class="math-blank">舅</span><span class="math-underover"><span class="math-smaller"><span class="math-blank">舅</span></span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">A</span></span><span class="math-brace">)</span></span><span class="math-smaller"><span class="math-operator">_</span></span></span><span class="math-blank">舅</span><span class="math-underover"><span class="math-smaller"><span class="math-operator">→</span></span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">v</span></span><span class="math-brace">)</span></span><span class="math-smaller"><span class="math-blank">舅</span></span></span></span></span>'
|
65
65
|
},
|
66
66
|
'z_12^34' =>
|
67
67
|
{
|
@@ -71,17 +71,17 @@ TEST_CASES = {
|
|
71
71
|
'lim_(x->c)(f(x)-f(c))/(x-c)' =>
|
72
72
|
{
|
73
73
|
:mathml => '<math><munder><mo>lim</mo><mrow><mi>x</mi><mo>→</mo><mi>c</mi></mrow></munder><mfrac><mrow><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>−</mo><mi>f</mi><mrow><mo>(</mo><mi>c</mi><mo>)</mo></mrow></mrow><mrow><mi>x</mi><mo>−</mo><mi>c</mi></mrow></mfrac></math>',
|
74
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank"
|
74
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank">舅</span><span class="math-underover"><span class="math-smaller"><span class="math-blank">舅</span></span><span class="math-operator">lim</span><span class="math-smaller"><span class="math-row"><span class="math-identifier">x</span><span class="math-operator">→</span><span class="math-identifier">c</span></span></span></span><span class="math-blank">舅</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-operator">−</span><span class="math-identifier">f</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">c</span></span><span class="math-brace">)</span></span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">x</span><span class="math-operator">−</span><span class="math-identifier">c</span></span></span></span></span></span></span></span></span>'
|
75
75
|
},
|
76
76
|
'int_0^(pi/2) g(x) dx' =>
|
77
77
|
{
|
78
|
-
:mathml => '<math><msubsup><mo>∫</mo><mn>0</mn><mfrac><mi>&#
|
79
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-operator">∫</span><span class="math-subsup"><span class="math-smaller"><span class="math-row"><span class="math-blank"
|
78
|
+
:mathml => '<math><msubsup><mo>∫</mo><mn>0</mn><mfrac><mi>π</mi><mn>2</mn></mfrac></msubsup><mi>g</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mi>dx</mi></math>',
|
79
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-operator">∫</span><span class="math-subsup"><span class="math-smaller"><span class="math-row"><span class="math-blank">舅</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-identifier">π</span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-number">2</span></span></span></span></span></span></span></span><span class="math-smaller"><span class="math-number">0</span></span></span><span class="math-identifier">g</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">x</span></span><span class="math-brace">)</span></span><span class="math-identifier">dx</span></span></span>'
|
80
80
|
},
|
81
81
|
'sum_(n=0)^oo a_n' =>
|
82
82
|
{
|
83
83
|
:mathml => '<math><munderover><mo>∑</mo><mrow><mi>n</mi><mo>=</mo><mn>0</mn></mrow><mo>∞</mo></munderover><msub><mi>a</mi><mi>n</mi></msub></math>',
|
84
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank"
|
84
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank">舅</span><span class="math-underover"><span class="math-smaller"><span class="math-operator">∞</span></span><span class="math-operator">∑</span><span class="math-smaller"><span class="math-row"><span class="math-identifier">n</span><span class="math-operator">=</span><span class="math-number">0</span></span></span></span><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller">舅</span><span class="math-smaller"><span class="math-identifier">n</span></span></span></span></span>'
|
85
85
|
},
|
86
86
|
'((1,2,3),(4,5,6),(7,8,9))' =>
|
87
87
|
{
|
@@ -96,27 +96,34 @@ TEST_CASES = {
|
|
96
96
|
'((a_(11), cdots , a_(1n)),(vdots, ddots, vdots),(a_(m1), cdots , a_(mn)))' =>
|
97
97
|
{
|
98
98
|
:mathml => '<math><mrow><mo>(</mo><mtable><mtr><mtd><msub><mi>a</mi><mn>11</mn></msub></mtd><mtd><mo>⋯</mo></mtd><mtd><msub><mi>a</mi><mrow><mn>1</mn><mi>n</mi></mrow></msub></mtd></mtr><mtr><mtd><mo>⋮</mo></mtd><mtd><mo>⋱</mo></mtd><mtd><mo>⋮</mo></mtd></mtr><mtr><mtd><msub><mi>a</mi><mrow><mi>m</mi><mn>1</mn></mrow></msub></mtd><mtd><mo>⋯</mo></mtd><mtd><msub><mi>a</mi><mrow><mi>m</mi><mi>n</mi></mrow></msub></mtd></mtr></mtable><mo>)</mo></mrow></math>',
|
99
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-row"><span class="math-brace" style="font-size: 300%;">(</span><span class="math-matrix" style="grid-template-columns:repeat(3,1fr);grid-template-rows:repeat(3,1fr);"><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller"
|
99
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-row"><span class="math-brace" style="font-size: 300%;">(</span><span class="math-matrix" style="grid-template-columns:repeat(3,1fr);grid-template-rows:repeat(3,1fr);"><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller">舅</span><span class="math-smaller"><span class="math-row"><span class="math-number">11</span></span></span></span></span><span class="math-row"><span class="math-operator">⋯</span></span><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller">舅</span><span class="math-smaller"><span class="math-row"><span class="math-number">1</span><span class="math-identifier">n</span></span></span></span></span><span class="math-row"><span class="math-operator">⋮</span></span><span class="math-row"><span class="math-operator">⋱</span></span><span class="math-row"><span class="math-operator">⋮</span></span><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller">舅</span><span class="math-smaller"><span class="math-row"><span class="math-identifier">m</span><span class="math-number">1</span></span></span></span></span><span class="math-row"><span class="math-operator">⋯</span></span><span class="math-row"><span class="math-identifier">a</span><span class="math-subsup"><span class="math-smaller">舅</span><span class="math-smaller"><span class="math-row"><span class="math-identifier">m</span><span class="math-identifier">n</span></span></span></span></span></span><span class="math-brace" style="font-size: 300%;">)</span></span></span></span>'
|
100
100
|
},
|
101
101
|
'sum_(k=1)^n k = 1+2+ cdots +n=(n(n+1))/2' =>
|
102
102
|
{
|
103
103
|
:mathml => '<math><munderover><mo>∑</mo><mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><mi>k</mi><mo>=</mo><mn>1</mn><mo>+</mo><mn>2</mn><mo>+</mo><mo>⋯</mo><mo>+</mo><mi>n</mi><mo>=</mo><mfrac><mrow><mi>n</mi><mrow><mo>(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo>)</mo></mrow></mrow><mn>2</mn></mfrac></math>',
|
104
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank"
|
104
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-blank">舅</span><span class="math-underover"><span class="math-smaller"><span class="math-identifier">n</span></span><span class="math-operator">∑</span><span class="math-smaller"><span class="math-row"><span class="math-identifier">k</span><span class="math-operator">=</span><span class="math-number">1</span></span></span></span><span class="math-identifier">k</span><span class="math-operator">=</span><span class="math-number">1</span><span class="math-operator">+</span><span class="math-number">2</span><span class="math-operator">+</span><span class="math-operator">⋯</span><span class="math-operator">+</span><span class="math-identifier">n</span><span class="math-operator">=</span><span class="math-blank">舅</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">n</span><span class="math-row"><span class="math-brace">(</span><span class="math-row"><span class="math-identifier">n</span><span class="math-operator">+</span><span class="math-number">1</span></span><span class="math-brace">)</span></span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-number">2</span></span></span></span></span></span></span></span>'
|
105
105
|
},
|
106
106
|
'"Скорость"=("Расстояние")/("Время")' =>
|
107
107
|
{
|
108
|
-
:mathml => '<math><mtext
|
109
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-text"
|
108
|
+
:mathml => '<math><mtext>Скорость</mtext><mo>=</mo><mfrac><mtext>Расстояние</mtext><mtext>Время</mtext></mfrac></math>',
|
109
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-text">Скорость</span><span class="math-operator">=</span><span class="math-blank">舅</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-text">Расстояние</span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-text">Время</span></span></span></span></span></span></span></span></span>'
|
110
110
|
},
|
111
111
|
'bb (a + b) + cc c = fr (d^n)' =>
|
112
112
|
{
|
113
113
|
:mathml => '<math><mstyle mathvariant="bold"><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow></mstyle><mo>+</mo><mstyle mathvariant="script"><mi>c</mi></mstyle><mo>=</mo><mstyle mathvariant="fraktur"><msup><mi>d</mi><mi>n</mi></msup></mstyle></math>',
|
114
|
-
:html =>
|
114
|
+
:html => nil
|
115
115
|
},
|
116
116
|
'max()' =>
|
117
117
|
{
|
118
|
-
:mathml => '<math><
|
119
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-
|
118
|
+
:mathml => '<math><mi>max</mi><mrow><mo>(</mo><mo>)</mo></mrow></math>',
|
119
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">max</span><span class="math-row"><span class="math-brace">(</span><span class="math-brace">)</span></span></span></span>'
|
120
|
+
},
|
121
|
+
'text("foo")' => {
|
122
|
+
:mathml => '<math><mtext>"foo"</mtext></math>',
|
123
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-text">"foo"</span></span></span>'
|
124
|
+
},
|
125
|
+
'ubrace(1 + 2) obrace(3 + 4' => {
|
126
|
+
:mathml => '<math><munder><mrow><mn>1</mn><mo>+</mo><mn>2</mn></mrow><mo>⏟</mo></munder><mover><mrow><mn>3</mn><mo>+</mo><mn>4</mn></mrow><mo>⏞</mo></mover></math>'
|
120
127
|
}
|
121
128
|
}
|
122
129
|
|
@@ -125,9 +132,9 @@ version = RUBY_VERSION.split('.').map { |s| s.to_i }
|
|
125
132
|
if version[0] > 1 || version[1] > 8
|
126
133
|
TEST_CASES['Скорость=(Расстояние)/(Время)'] =
|
127
134
|
{
|
128
|
-
:mathml => '<math><mi
|
129
|
-
:html => '<span class="math-inline"><span class="math-row"><span class="math-identifier"
|
130
|
-
|
135
|
+
:mathml => '<math><mi>С</mi><mi>к</mi><mi>о</mi><mi>р</mi><mi>о</mi><mi>с</mi><mi>т</mi><mi>ь</mi><mo>=</mo><mfrac><mrow><mi>Р</mi><mi>а</mi><mi>с</mi><mi>с</mi><mi>т</mi><mi>о</mi><mi>я</mi><mi>н</mi><mi>и</mi><mi>е</mi></mrow><mrow><mi>В</mi><mi>р</mi><mi>е</mi><mi>м</mi><mi>я</mi></mrow></mfrac></math>',
|
136
|
+
:html => '<span class="math-inline"><span class="math-row"><span class="math-identifier">С</span><span class="math-identifier">к</span><span class="math-identifier">о</span><span class="math-identifier">р</span><span class="math-identifier">о</span><span class="math-identifier">с</span><span class="math-identifier">т</span><span class="math-identifier">ь</span><span class="math-operator">=</span><span class="math-blank">舅</span><span class="math-fraction"><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">Р</span><span class="math-identifier">а</span><span class="math-identifier">с</span><span class="math-identifier">с</span><span class="math-identifier">т</span><span class="math-identifier">о</span><span class="math-identifier">я</span><span class="math-identifier">н</span><span class="math-identifier">и</span><span class="math-identifier">е</span></span></span></span></span></span><span class="math-fraction_row"><span class="math-fraction_cell"><span class="math-smaller"><span class="math-row"><span class="math-row"><span class="math-identifier">В</span><span class="math-identifier">р</span><span class="math-identifier">е</span><span class="math-identifier">м</span><span class="math-identifier">я</span></span></span></span></span></span></span></span></span>'
|
137
|
+
}
|
131
138
|
end
|
132
139
|
|
133
140
|
module AsciiMathHelper
|
@@ -149,7 +156,7 @@ describe "AsciiMath::MathMLBuilder" do
|
|
149
156
|
it "should produce identical output to asciimathml.js for '#{asciimath}'" do
|
150
157
|
expect_mathml(asciimath, output[:mathml])
|
151
158
|
end
|
152
|
-
if output[:html]
|
159
|
+
if output[:html]
|
153
160
|
it "should produce html that looks like the output from asciimathml.js for '#{asciimath}'" do
|
154
161
|
expect_html(asciimath, output[:html])
|
155
162
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciimath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pepijn Van Eeckhoudt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
requirements: []
|
99
99
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
100
|
+
rubygems_version: 2.7.6
|
101
101
|
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: AsciiMath parser and converter
|