-
Notifications
You must be signed in to change notification settings - Fork 1
/
jqmath-vanilla.js
1610 lines (1537 loc) · 64.2 KB
/
jqmath-vanilla.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* jscurry.js: a JavaScript module for functional programming; requires ECMAScript 3. These
definitions are based on Haskell's, but allow side effects, and do not use automatic lazy
evaluation, compile-time type checking, or automatic Currying.
We believe that "member functions" are the wrong technique in general for implementing
function closures or passing functions to polymorphic algorithms.
Variable suffixes (in this and other modules):
F: function
P ("Possible" or "Pointer"): undefined and maybe null treated specially
Q ("Question"): value effectively converted to a boolean when used
S: string
_: a (usually non-constant) variable with a large scope
$: DOM element(s) or "wrapped set"
These library modules aim to be small, efficient, compatible with standards, and hopefully
elegant. */
/* Copyright 2016, Mathscribe, Inc. Released under the MIT license (same as jQuery).
See e.g. http://jquery.org/license for an explanation of this license. */
"use strict";
var jsCurry = function() {
var sliceMF = Array.prototype.slice; // slice "Member Function"
// provide a few basic ECMAScript 5 functions if they are missing:
// Chrome < 7, FF < 4, Opera < 11.6, Safari < 5.1, IE < 9
if (! Function.prototype.bind) Function.prototype.bind = function(thisArg /* , ... */) {
var f = this, args0 = sliceMF.call(arguments, 1);
return function(/* ... */) {
return f.apply(thisArg, args0.concat(sliceMF.call(arguments, 0)));
};
};
// Chrome < 5, FF < 4, Opera < 10.5, Safari < 5, IE < 9
if (! Array.isArray) Array.isArray = function(x) {
return typeof x == 'object' && x !== null &&
Object.prototype.toString.call(x) === '[object Array]';
};
function F(x /* , ... */) { // F() shorthand notation for some basic operations
if (typeof x == 'function') return F.curry.apply(undefined, arguments);
if (arguments.length == 2) {
var y = arguments[1];
if (typeof x == 'string') return y[x].bind(y);
if (typeof y == 'function')
return (typeof x == 'number' ? F.aritize : F.partial)(x, y);
}
arguments.length == 1 || F.err(err_F_1_);
if (typeof x == 'number' || typeof x == 'string') return F.pToF(x);
//if (x.nodeType == 1 /* Element */) // requires jQuery 1.4+; e.g. for widget ops
// return jQuery.data(x);
if (x && typeof x == 'object') return F.aToF(x);
F.err(err_F_2_);
}
F.err = function() { if (F.debug) debugger; throw Error('Assertion failed'); };
// usually argument evaluation intentionally fails, to report its line number
F.applyF = function(f, args) { return f.apply(undefined, args); }
F.curry = function(f /* , ... */)
{ var g = f; arguments[0] = undefined; return g.bind.apply(g, arguments); };
F._ = {}; // needed since e.g. (0 in [ , 3]) is apparently wrong in e.g. Firefox 3.0
F.partial = function(a, f) { // 'a' supplies some arguments to 'f'
var n = a.length;
return function(/* ... */) {
var args = sliceMF.call(arguments, 0);
for (var i = 0; i < n; i++)
if (a[i] !== F._) args.splice(i, 0, a[i]);
else if (args.length == i) args.push(undefined);
return f.apply(this, args);
};
};
F.o = function(/* ... */) { // composition of 1 or more functions
var fs = arguments;
return function(/* ... */) {
var n = fs.length, res = fs[--n].apply(undefined, arguments);
while (n > 0) res = fs[--n](res);
return res;
};
};
F.oMap = function(f, g) // composition, using F.map(g, <arguments>)
{ return function(/* ... */) { return F.applyF(f, F.map(g, arguments)); }; };
F.aritize = function(n, f) // for discarding optional trailing arguments
{ return function(/* ... */) { return F.applyF(f, sliceMF.call(arguments, 0, n)); }; };
F.not = function(x) { return ! x; };
F.defOr = function(xP, y) { return xP !== undefined ? xP : y; };
/* The following functions that act on arrays also work on "array-like" objects (with a
'length' property), including array-like host objects. The functions may or may not
skip missing elements. */
// A "cmp" function returns 0, < 0, or > 0 for ==, <, or > respectively.
F.cmpX = function(x, y) { return x - y; }; // for finite numbers, or Dates
F.cmpLex = function(cmpE, v, w) // "lexicographic order"; cmpE need not return a number
{ return F.any(function(e, i) { return i == w.length ? 1 : cmpE(e, w[i]); }, v) ||
v.length - w.length; };
F.eqTo = function(x, cmpP) {
if (! cmpP) cmpP = function(y, z) { return y !== z; };
return F.o(F.not, F(cmpP, x));
};
F.pToF = function(p) { return function(obj) { return obj[p]; }; };
F.aToF = function(obj) { return function(p) { return obj[p]; }; };
F.slice = function(a, startP, endP) {
if (startP == null) startP = 0;
if (Array.isArray(a)) return a.slice(startP, endP);
var n = a.length;
startP = startP < 0 ? Math.max(0, n + startP) : Math.min(n, startP);
endP = endP === undefined ? n : endP < 0 ? Math.max(0, n + endP) : Math.min(n, endP);
var res = [];
while (startP < endP) res.push(a[startP++]);
return res;
};
F.concatArgs = F.oMap(F('concat', []),
function(a) { return Array.isArray(a) ? a : F.slice(a); });
F.concatMap = function(f, a) { return F.applyF(F.concatArgs, F.map(f, a)); };
F.findIndex = function(qF, a) {
var n = a.length;
for (var i = 0; i < n; i++) if (qF(a[i], i, a)) return i;
return -1;
};
F.elemIndex = function(e, a, cmpP) {
if (a.indexOf && ! cmpP && Array.isArray(a)) return a.indexOf(e);
return F.findIndex(F.eqTo(e, cmpP), a);
};
F.elem = function(e, a, cmpP) { return F.elemIndex(e, a, cmpP) != -1; };
F.any = function(f, a) /* note result may be non-boolean */ {
var n = a.length, y = false /* in case n == 0 */;
for (var i = 0; i < n; i++) {
y = f(a[i], i, a);
if (y) return y;
}
return y;
};
F.iter = function(f, a /* , ... */) {
if (arguments.length == 2) { // for speed
if (a.forEach && Array.isArray(a)) return a.forEach(f);
var n = a.length;
for (var i = 0; i < n; i++) f(a[i], i, a);
} else {
arguments.length > 2 || F.err(err_iter_);
var args = sliceMF.call(arguments, 1),
n = F.applyF(Math.min, F.map(F('length'), args));
for (var i = 0; i < n; i++) F.applyF(f, F.map(F(i), args).concat(i, args));
}
};
F.map = function(f, a) {
if (a.map && Array.isArray(a)) return a.map(f);
var n = a.length, res = new Array(n);
for (var i = 0; i < n; i++) res[i] = f(a[i], i, a);
return res;
};
F.sum = function(a) {
var n = a.length, res = 0;
for (var i = 0; i < n; i++) res += a[i];
return res;
};
return F;
}();
var F; if (F === undefined) F = jsCurry;
//if (typeof module == 'object') module.exports = jsCurry;
/* jqmath.js: a JavaScript module for symbolic expressions, e.g. formatted mathematical
formulas. This file uses charset UTF-8, and requires jsCurry, and jqmath.css.
By default, we use Presentation MathML when available, else simple HTML and CSS.
Expressions may be constructed programmatically, or using a simple TeX-like syntax.
To use symbolic expressions in a web page or problem domain, one must choose a set of
symbols, ensure they can be viewed by users, and specify precedences for the operator
symbols. We use Unicode character numbers for encoding, and fonts for display. Normally
standard characters and fonts suffice, but "private use" character numbers and custom fonts
can be used when necessary. By default, this module currently uses standard MathML 3
precedences for operator symbols, except we omit "multiple character operator"s like && or
<=, and choose a single precedence for each of |, ^, and _.
The algorithm to detect MathML only works after some document.body is defined and available.
Thus it should probably not be used during document loading.
See http://mathscribe.com/author/jqmath.html for usage documentation and examples, and
jscurry.js for some coding conventions and goals. */
/* Copyright 2017, Mathscribe, Inc. Released under the MIT license (same as jQuery).
See e.g. http://jquery.org/license for an explanation of this license. */
var jqMath = function() {
var F = jsCurry;
// Chrome < 38, FF < 25, Opera < 25, Safari < 9, IE6-11
if (! Math.sign) Math.sign = function(x) {
x = Number(x);
return x > 0 ? 1 : x < 0 ? -1 : x /* +0, -0, or NaN */;
};
// Chrome < 38, FF < 25, Opera < 25, Safari < 9, IE6-11
if (! Math.trunc) Math.trunc = function(x) {
return (x < 0 ? Math.ceil : Math.floor)(x);
};
function M(x, y, z) /* any number of arguments */ {
if (typeof x == 'number') x = String(x); // e.g. for small integers
if (typeof x == 'string' || Array.isArray(x)) return M.sToMathE(x, y, z);
if (x.nodeType == 1 /* Element */ && x.tagName.toLowerCase() == 'math')
return M.eToMathE(x);
F.err(err_M_);
}
M.getSpecAttrP = function(e, attrName) {
var attrP = e.getAttributeNode(attrName);
return attrP && /* for IE6-7: */ attrP.specified !== false ? attrP.value : undefined;
};
M.objToAttrs = function(obj) {
var res = [];
for (var p in obj) res.push({ name: p, value: obj[p] });
return res;
};
M.setAttrs = function(e, attrsP) /* uses attr.name/value/[specified for IE6-7] */ {
if (attrsP && attrsP.length == null) attrsP = M.objToAttrs(attrsP);
F.iter(function(attr) {
if (attr.specified !== false /* for IE6-7 */)
e.setAttribute(attr.name, attr.value);
}, attrsP || []);
return e;
};
M.addClass = function(e, ws) {
// $(e).addClass(ws) doesn't seem to work for XML elements
if (typeof e.className != 'undefined') { // needed for old IE, works for non-XML
var classes = e.className;
e.className = (classes ? classes+' ' : '')+ws;
} else { // needed for XML, would work for non-IE
var classes = e.getAttribute('class');
e.setAttribute('class', (classes ? classes+' ' : '')+ws);
}
return e;
};
M.eToClassesS = function(e) {
var sP = typeof e.className != 'undefined' ? e.className : e.getAttribute('class');
return sP || '';
};
M.hasClass = function(e, w) { // works for HTML or XML elements, unlike jQuery e.g. 1.4.3
return (' '+M.eToClassesS(e)+' ').replace(/[\n\t]/g, ' ').indexOf(' '+w+' ') != -1;
// we replace /[\n\t]/g to be consistent with jQuery
};
M.mathmlNS = "http://www.w3.org/1998/Math/MathML"; // MathML namespace
function appendMeArgs(e, args /* null/undefined, string, node, or array-like of nodes incl.
live NodeList */, attrsP) {
if (args == null) {}
else if (typeof args == 'string')
e.appendChild(e.ownerDocument.createTextNode(args));
else if (args.nodeType) e.appendChild(args);
else {
if (args.constructor != Array) args = F.slice(args); // for live NodeList
F.iter(function(x) { e.appendChild(x); }, args);
}
return M.setAttrs(e, attrsP);
}
var fixMathMLQ_ = false;
(function() { // M.webkitVersion, M.operaVersion, M.msieVersion, M.mozillaVersion
var ua = navigator.userAgent.toLowerCase(), match = ua.match(/webkit[ \/](\d+)\.(\d+)/);
if (match) {
M.webkitVersion = [Number(match[1]), Number(match[2])];
fixMathMLQ_ = M.webkitVersion[0] <= 540 /*@@*/;
} else {
match = ua.match(/(opera)(?:.*version)?[ \/]([\w.]+)/) ||
ua.match(/(msie) ([\w.]+)/) ||
ua.indexOf("compatible") < 0 && ua.match(/(mozilla)(?:.*? rv:([\w.]+))?/);
if (match) M[match[1]+'Version'] = match[2] || "0";
}
})();
if (M.msieVersion)
document.write(
'<object id=MathPlayer classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987">',
'</object><?IMPORT namespace="m" implementation="#MathPlayer" ?>');
// M.MathPlayer controls whether the IE plugin MathPlayer can be used.
function checkMathMLAttrs(e) {
if (M.MathML && ! fixMathMLQ_) return e;
var tagName = e.tagName.toLowerCase(), doc = e.ownerDocument;
function new1(k) { return doc.createElementNS(M.mathmlNS, k); }
if (tagName == 'mi') {
if (! e.getAttribute('mathvariant') && e.firstChild
&& e.firstChild.nodeType == 3 /* Text */)
e.setAttribute('mathvariant',
e.firstChild.data.length == 1 ? 'italic' : 'normal');
} else if (tagName == 'mo') {
if (e.childNodes.length == 1 && e.firstChild.nodeType == 3 /* Text */) {
var s = e.firstChild.data;
if (/^[\u2061-\u2064]$/.test(s)) M.addClass(e, 'ma-non-marking');
/*@@ move parse_mxP_tokP fm- operator spacing here!? */
}
} else if (tagName == 'mspace') { //@@ combine with M.newMe 'mspace' clause
if (M.webkitVersion && M.MathML) {
e.style.display = 'inline-block';
e.style.minWidth = e.getAttribute('width') || '0px';
}
} else if (tagName == 'menclose') {
if (M.webkitVersion && M.MathML) M.addClass(e, 'fm-menclose');
} else if (tagName == 'mmultiscripts') {
if (M.webkitVersion) {
var a = F.slice(e.childNodes); // partly because e.childNodes is dynamic
if (a.length == 0) throw 'Wrong number of <mmultiscripts> arguments: 0';
var rowA = [a[0]];
for (var i = 1; i < a.length; i++) {
if (a[i].tagName == 'mprescripts') {
rowA.unshift(new1('none'));
continue;
}
if (i + 1 == a.length) throw 'Missing argument in <mmultiscripts>';
var a3 = [rowA[0], a[i], a[i + 1]];
i++;
rowA[0] = new1('msubsup');
F.iter(function(arg) { rowA[0].appendChild(arg); }, a3);
}
var oldE = e;
e = appendMeArgs(new1('mrow'), rowA, e.attributes);
if (oldE.parentNode) oldE.parentNode.replaceChild(e, oldE);
}
}
var colorOpt = e.getAttribute('mathcolor'), hrefOpt = e.getAttribute('href');
if (colorOpt && e.style) e.style.color = colorOpt;
if (hrefOpt && (! M.MathML || M.webkitVersion)) {
var aE = doc.createElement('A'), parentP = e.parentNode, nextP = e.nextSibling;
aE.appendChild(e);
aE.href = hrefOpt;
e = aE;
if (parentP) parentP.insertBefore(e, nextP);
}
return e;
}
function newMeNS(tagName, argsP /* for appendMeArgs() */, attrsP, doc)
/* tries to use the MathML namespace, perhaps with prefix 'm' */ {
if (! doc) doc = document;
var e = M.MathPlayer ? doc.createElement('m:'+tagName) :
doc.createElementNS(M.mathmlNS, tagName);
return checkMathMLAttrs(appendMeArgs(e, argsP, attrsP));
}
// M.MathML controls whether MathML is used.
(function() {
if (self.location) {
var match = location.search.match(/[?&;]mathml=(?:(off|false)|(on|true))\b/i);
if (match) M.MathML = ! match[1];
else if (M.webkitVersion && F.cmpLex(F.cmpX, M.webkitVersion, [537, 17]) < 0
|| M.operaVersion)
M.MathML = false;
}
})();
M.canMathML = function() /* requires document.body */ {
if (M.msieVersion && ! M.MathPlayer)
try {
new ActiveXObject("MathPlayer.Factory.1");
if (M.MathPlayer == null) M.MathPlayer = true;
else if (! M.MathPlayer) return false; // for Carlisle's MathPlayer 3
} catch(exc) {
M.MathPlayer = false;
}
if (! M.MathPlayer && typeof document.createElementNS == 'undefined') return false;
var e1 = newMeNS('math', newMeNS('mn', '1')),
e2 = newMeNS('math', newMeNS('mfrac', [newMeNS('mn', '1'), newMeNS('mn', '2')])),
es$ = document.createElement('div');
// e1.style is set to null in Chrome 25-44 (no MathML support)
if (typeof e1.style === 'undefined' || e1.style === null) return false;
e1.setAttribute('display', 'block');
e2.setAttribute('display', 'block');
e1.style.visibility = e2.style.visibility = 'hidden';
es$.appendChild(e1);
es$.appendChild(e2);
document.body.appendChild(es$);
// Could use .bottom-.top instead of .height, but IE6-8 don't get this far anyway
var res = e2.getBoundingClientRect().height > e1.getBoundingClientRect().height + 2;
document.body.removeChild(es$);
return res;
};
// fmUp is mid-x to outer top, fmDn is mid-x to outer bottom, both approx. & in parent ems
function checkVertStretch(up, dn, g, doP) /* non-MathML */ {
if (g.nodeName.toLowerCase() == 'mo' && g.childNodes.length == 1) {
var c = g.firstChild, s = c.data;
if (c.nodeType == 3 /* Text */ && (up > 0.9 || dn > 0.9)
&& (M.prefix_[s] < 25 || M.postfix_[s] < 25
|| '|\u2016\u221A' /* ‖ √ */.indexOf(s) != -1 || doP)) {
var r = (up + dn) / 1.2, radicQ = s == '\u221A',
v = (radicQ ? 0.26 : 0.35) + ((radicQ ? 0.15 : 0.25) - dn) / r;
g.style.fontSize = r.toFixed(3)+'em';
g.style.verticalAlign = v.toFixed(3)+'em';
g.fmUp = up;
g.fmDn = dn;
g.style.display = 'inline-block';
g.style.transform = g.style.msTransform = g.style.MozTransform =
g.style.WebkitTransform = 'scaleX(0.5)';
}
}
}
function vertAlignE$(up, dn, fmVert) /* non-MathML */ {
var e$ = document.createElement('span');
e$.appendChild(fmVert);
//JQuery: var e$ = $('<span/>').append(fmVert);
e$.fmUp = up;
e$.fmDn = dn;
e$.style.verticalAlign = (0.5 * (up - dn)).toFixed(3)+'em';
return e$;
}
M.mtagName = function(e) /* returns 'fmath' for non-MathML 'math' */ {
if (e.tagName == 'A' && e.childNodes.length == 1) e = e.firstChild;
return e.getAttribute('mtagname') || e.tagName.toLowerCase().replace(/^m:/, '');
};
M.mchilds = function(e) {
if (e.tagName == 'A' && e.childNodes.length == 1) e = e.firstChild;
var mSP = e.getAttribute('mtagname');
while (e.tagName == 'SPAN') e = e.firstChild;
function span0(g) { g.tagName == 'SPAN' || F.err(err_span0_); return g.firstChild; }
if (e.tagName == 'TABLE') {
e = e.firstChild;
e.tagName == 'TBODY' || F.err(err_mchilds_tbody_);
if (mSP == 'mtable') return e.childNodes;
var a = e.childNodes; // <tr>s for mfrac munder mover munderover
if (mSP == 'mover') a = [a[1], a[0]];
else if (mSP == 'munderover') a = [a[1], a[2], a[0]];
return F.map(function(tr) { return tr.firstChild.firstChild; }, a);
} else if (e.tagName == 'MROW' && mSP) {
var a = e.childNodes;
if (mSP == 'msqrt') return [span0(span0(a[1]))];
if (mSP == 'mroot') return [span0(span0(a[2])), span0(a[0])];
mSP == 'mmultiscripts' || F.err(err_mchilds_mrow_);
var nPrescripts = Number(e.getAttribute('nprescripts'));
0 <= nPrescripts && nPrescripts < a.length && nPrescripts % 2 == 0 ||
F.err(err_mchilds_mmultiscripts_);
var res = [a[nPrescripts]];
for (var i = nPrescripts + 1; i < a.length; i++) res.push(span0(a[i]));
if (nPrescripts) {
res.push(e.ownerDocument.createElement('mprescripts'));
for (var i = 0; i < nPrescripts; i++) res.push(span0(a[i]));
}
return res;
} else if (F.elem(e.tagName, ['MSUB', 'MSUP', 'MSUBSUP']))
return F.map(function(c, i) { return i ? span0(c) : c; }, e.childNodes);
else if (e.tagName == 'MSPACE') return [];
else return e.childNodes;
};
var mtokens_ = ['mn', 'mi', 'mo', 'mtext', 'mspace', 'ms'],
impMRows_ =
['fmath', 'msqrt', 'mtd', 'mstyle', 'merror', 'mpadded', 'mphantom', 'menclose'],
accentDsByS_ = { // top and bottom space in ems
'\xAF' /* ¯ macron */: [0, 0.85], '\u203E' /* ‾ overline */: [0, 0.85],
'\u02D9' /* ˙ dot above */: [0, 0.75], '\u02C7' /* ˇ caron */: [0, 0.7],
'^': [0, 0.5], '~': [0, 0.4], '\u2192' /* → rightwards arrow */: [0.25, 0.25],
'_': [0.7, 0],
// not accents in MathML 3 operator dictionary:
'\u2212' /* − */: [0.25, 0.45], '.': [0.6, 0.1]
};
M.newMe = function(tagName, argsP /* for appendMeArgs() */, attrsP, docP) {
if (! docP) {
if (attrsP && attrsP.nodeType == 9 /* Document */) {
docP = attrsP;
attrsP = undefined;
} else docP = document;
}
M.MathML != null || F.err(err_newMe_MathML_);
if (M.MathML) return newMeNS(tagName, argsP, attrsP, docP);
if (tagName == 'math') tagName = 'fmath';
var e$ = appendMeArgs(docP.createElement(tagName.toUpperCase()), argsP),
a = F.slice(e$.childNodes); // partly because e$.childNodes is dynamic
if (F.elem(tagName, impMRows_) && a.length != 1) {
a = [M.newMe('mrow', a, undefined, docP)];
e$.childNodes.length == 0 || F.err(err_newMe_imp_mrow_);
e$.appendChild(a[0]);
}
var ups = F.map(function(g) { return Number(g.fmUp || 0.6); }, a),
dns = F.map(function(g) { return Number(g.fmDn || 0.6); }, a);
if (tagName == 'fmath' || tagName == 'mn' || tagName == 'mtext'
|| tagName == 'mprescripts' || tagName == 'none') {
} else if (tagName == 'mstyle' || tagName == 'merror' || tagName == 'mpadded'
|| tagName == 'mphantom' || tagName == 'menclose') {
if (a[0].fmUp) e$.fmUp = a[0].fmUp;
if (a[0].fmDn) e$.fmDn = a[0].fmDn;
} else if (tagName == 'mi') {
var c = a.length == 1 ? a[0] : {};
if (c.nodeType == 3 /* Text */ && c.data.length == 1) {
M.addClass(e$, 'fm-mi-length-1');
if (c.data == 'f') e$.style.paddingRight = '0.44ex';
// e.g. on a Mac, unnec. on netrenderer.com 12/20/16
}
} else if (tagName == 'mo') {
var c = a.length == 1 ? a[0] : {};
if (c.nodeType == 3 /* Text */ && /[\]|([{‖)}]/.test(c.data))
M.addClass(e$, 'fm-mo-Luc');
} else if (tagName == 'mspace') {
var e = M.setAttrs(e$, attrsP);
attrsP = undefined;
e.style.marginRight = e.getAttribute('width') || '0px'; // may be negative
e.style.paddingRight = '0.001em'; // Firefox work-around
e$.innerHTML = '\u200C' /* ‌ */; // for Safari/Chrome
e$.style.visibility = 'hidden'; // e.g. for iPad Mobile Safari 4.0.4
} else if (tagName == 'mrow') {
var up = F.applyF(Math.max, ups), dn = F.applyF(Math.max, dns);
if (up > 0.65 || dn > 0.65) {
e$.fmUp = up;
e$.fmDn = dn;
F.iter(F([up, dn, F._, undefined], checkVertStretch), a);
}
} else if (tagName == 'mfrac') {
if (a.length != 2) throw 'Wrong number of <mfrac> arguments: '+a.length;
var num$ = docP.createElement('td'), den$ = docP.createElement('td');
num$.className = 'fm-num-frac fm-inline';
num$.appendChild(a[0]);
den$.className = 'fm-den-frac fm-inline';
den$.appendChild(a[1]);
//JQuery: num$ = $('<td class="fm-num-frac fm-inline"></td>', docP).append(a[0]),
//JQuery: den$ = $('<td class="fm-den-frac fm-inline"></td>', docP).append(a[1]);
var tr1$ = docP.createElement('tr'), tr2$ = docP.createElement('tr'),
tbody$ = docP.createElement('tbody'), table$ = docP.createElement('table'),
span$ = docP.createElement('span');
tr1$.appendChild(den$);
tr2$.appendChild(num$);
tbody$.appendChild(tr2$);
tbody$.appendChild(tr1$);
table$.appendChild(tbody$);
span$.appendChild(table$);
span$.className = 'fm-vert fm-frac';
e$ = vertAlignE$(ups[0] + dns[0] + 0.03, ups[1] + dns[1] + 0.03, span$);
//JQuery: e$ = vertAlignE$(ups[0] + dns[0] + 0.03, ups[1] + dns[1] + 0.03,
// $('<span class="fm-vert fm-frac"></span>', docP).
// <span> partly for IE6-7, see www.quirksmode.org/css/display.html
// append($('<table/>', docP).
// append($('<tbody/>', docP).
// append($('<tr/>', docP).append(num$)).
// append($('<tr/>', docP).append(den$))))).
// attr('mtagname', tagName);
e$.setAttribute('mtagname', tagName);
} else if (tagName == 'msqrt' || tagName == 'mroot') {
if (a.length != (tagName == 'msqrt' ? 1 : 2))
throw 'Wrong number of <'+tagName+'> arguments: '+a.length;
e$ = docP.createElement('mrow');
e$.setAttribute('mtagname', tagName);
//JQuery: e$ = $('<mrow/>', docP).attr('mtagname', tagName);
var t = 0.06*(ups[0] + dns[0]), up = ups[0] + t + 0.1, dn = dns[0];
if (tagName == 'mroot') {
var ht = 0.6 * (ups[1] + dns[1]), d = 0.25/0.6 - 0.25;
if (up > ht) d += up/0.6 - ups[1];
else {
d += dns[1];
up = ht;
}
var span$ = docP.createElement('span');
span$.className = 'fm-root fm-inline';
span$.appendChild(a[1]);
span$.style.verticalAlign = d.toFixed(2)+'em';
e$.appendChild(span$);
//JQuery: e$.append($('<span class="fm-root fm-inline"></span>', docP).append(a[1]).
// css('verticalAlign', d.toFixed(2)+'em'));
}
var mo$ = docP.createElement('mo'), span$ = docP.createElement('span'), y$;
mo$.innerHTML = '\u221A' /* √ */;
mo$.className = 'fm-radic';
//JQuery: $('<mo/>', docP).addClass('fm-radic').append('\u221A' /* √ */),
// IE8 doesn't like $('<mo class="fm-radic"></mo>').append(...)
//JQuery: $('<span class="fm-vert fm-radicand"></span>', docP).append(a[0]).css('borderTopWidth', t.toFixed(3)+'em'));
span$.appendChild(a[0]);
span$.className = 'fm-vert fm-radicand';
span$.style.borderTopWidth = t.toFixed(3)+'em';
y$ = vertAlignE$(up, dn, span$);
checkVertStretch(up, dn, mo$);
e$.appendChild(mo$);
e$.appendChild(y$);
e$.fmUp = up;
e$.fmDn = dn;
} else if (tagName == 'msub' || tagName == 'msup' || tagName == 'msubsup'
|| tagName == 'mmultiscripts') {
if (tagName != 'mmultiscripts' && a.length != (tagName == 'msubsup' ? 3 : 2))
throw 'Wrong number of <'+tagName+'> arguments: '+a.length;
var up = ups[0], dn = dns[0], oddQ = tagName == 'msup',
dUp = up/0.71 - 0.6, dDn = dn/0.71 - 0.6;
for (var i = 1; i < a.length; i++) {
if (tagName == 'mmultiscripts') {
var w = M.mtagName(a[i]);
if (w == 'none') continue;
if (w == 'mprescripts') {
if (oddQ) throw 'Repeated "mprescripts"';
oddQ = true;
continue;
}
}
if (i % 2 == (oddQ ? 0 : 1)) dDn = Math.max(dDn, ups[i]);
else dUp = Math.max(dUp, dns[i]);
}
var preAP = undefined, postA = [], nPrescripts = 0;
for (var i = 1; i < a.length; i++) {
if (tagName == 'mmultiscripts') {
var w = M.mtagName(a[i]);
if (w == 'mprescripts') {
preAP = [];
nPrescripts = a.length - i - 1;
continue;
}
}
var d = 0.25/0.71 - 0.25;
if (i % 2 == (preAP ? 0 : 1) && tagName != 'msup') {
d -= dDn;
dn = Math.max(dn, 0.71*(dDn + dns[i]));
} else {
d += dUp;
up = Math.max(up, 0.71*(dUp + ups[i]));
}
var span$ = document.createElement('span');
span$.className = 'fm-script fm-inline';
a[i].parentNode.insertBefore(span$, a[i]);
span$.appendChild(a[i]);
span$.style.verticalAlign = d.toFixed(2)+'em';
//JQuery: $(a[i]).wrap('<span class="fm-script fm-inline"></span>').parent().
// css('verticalAlign', d.toFixed(2)+'em');
if (M.msieVersion && (document.documentMode || M.msieVersion) < 8)
a[i].style.zoom = 1; // to set hasLayout
if (tagName == 'mmultiscripts') (preAP || postA).push(a[i].parentNode);
}
if (tagName == 'mmultiscripts') {
e$ = document.createElement('mrow');
var ap = (preAP || []).concat(a[0], postA);
for (var i=0; i < ap.length; i++)
e$.appendChild(ap[i]);
e$.setAttribute('mtagname', 'mmultiscripts');
e$.setAttribute('nprescripts', 'nPrescripts');
//JQuery: e$ = $('<mrow/>'). // $('<mrow mtagname="mmultiscripts"></mrow>') fails in IE8
// append($((preAP || []).concat(a[0], postA))).
// attr({ mtagname: 'mmultiscripts', nprescripts: nPrescripts });
}
e$.fmUp = up;
e$.fmDn = dn;
} else if (tagName == 'munder' || tagName == 'mover' || tagName == 'munderover') {
if (a.length != (tagName == 'munderover' ? 3 : 2))
throw 'Wrong number of <'+tagName+'> arguments: '+a.length;
var tbody$ = docP.createElement('tbody'), td$, up = 0.85 * ups[0], dn = 0.85 * dns[0];
if (tagName != 'munder') {
var overE = a[a.length - 1], accentDsP = undefined;
td$ = docP.createElement('td');
td$.appendChild(overE);
//JQuery: td$ = $('<td/>', docP).append(overE);
if (overE.nodeName == 'MO' && overE.childNodes.length == 1) {
var c = overE.firstChild;
if (c.nodeType == 3 /* Text */) accentDsP = accentDsByS_[c.data];
}
if (accentDsP) {
overE.style.display = 'block';
overE.style.marginTop = (- accentDsP[0]).toFixed(2) + 'em';
overE.style.marginBottom = (- accentDsP[1]).toFixed(2) + 'em';
up += 1.2 - F.sum(accentDsP);
} else {
td$.className = 'fm-script fm-inline';
up += 0.71 * (ups[a.length - 1] + dns[a.length - 1]);
}
var tr$ = docP.createElement('tr');
tr$.appendChild(td$);
tbody$.appendChild(tr$);
//JQuery: tbody$.append($('<tr/>', docP).append(td$));
}
if (a[0].nodeName == 'MI' && a[0].childNodes.length == 1) {
var c = a[0].firstChild, s = c.data;
if (c.nodeType == 3 /* Text */ && s.length == 1) {
var d = 'acegmnopqrsuvwxyz'.indexOf(s) != -1 ? 0.25 : s == 't' ? 0.15 : 0;
if (d) {
a[0].style.display = 'block';
a[0].style.marginTop = (- d).toFixed(2) + 'em';
up -= d;
}
}
}
td$ = docP.createElement('td');
td$.appendChild(a[0]);
td$.className = 'fm-underover-base';
//JQuery: td$ = $('<td class="fm-underover-base"></td>', docP).append(a[0]);
var tr$ = docP.createElement('tr');
tr$.appendChild(td$);
tbody$.appendChild(tr$);
//JQuery: tbody$.append($('<tr/>', docP).append(td$));
if (tagName != 'mover') {
td$ = docP.createElement('td');
td$.appendChild(a[1]);
td$.className = 'fm-script fm-inline';
//JQuery: td$ = $('<td class="fm-script fm-inline"></td>', docP).append(a[1]);
var tr$ = docP.createElement('tr');
tr$.appendChild(td$);
tbody$.appendChild(tr$);
//JQuery: tbody$.append($('<tr/>', docP).append(td$));
dn += 0.71 * (ups[1] + dns[1]);
}
var span$ = docP.createElement('span'), table$ = docP.createElement('table');
span$.className = 'fm-vert';
table$.appendChild(tbody$);
span$.appendChild(table$);
e$ = vertAlignE$(up, dn, span$);
e$.setAttribute('mtagname', tagName);
//JQuery: e$ = vertAlignE$(up, dn, $('<span class="fm-vert"></span>', docP).
// append($('<table/>', docP).append(tbody$))).
// attr('mtagname', tagName);
} else if (tagName == 'mtable') {
var tbody$ = docP.createElement('tbody');
for (var i=0; i < a.length; i++)
tbody$.appendChild(a[i]);
//JQuery: var tbody$ = $('<tbody/>', docP).append($(a));
e$ = docP.createElement('span');
e$.className = 'fm-vert';
e$.setAttribute('mtagname', 'mtable');
var table$ = docP.createElement('table');
table$.appendChild(tbody$);
e$.appendChild(table$);
//JQuery: e$ = $('<span class="fm-vert" mtagname="mtable"></span>', docP)
// .append($('<table/>', docP).append(tbody$));
var r = F.sum(ups) + F.sum(dns);
e$.fmUp = e$.fmDn = 0.5 * r; // binomScan() may modify
} else if (tagName == 'mtr') {
e$ = docP.createElement('tr');
for (var i=0; i < a.length; i++)
e$.appendChild(a[i]);
e$.className = 'fm-mtr';
e$.setAttribute('mtagname', 'mtr');
//JQuery: e$ = $('<tr class="fm-mtr" mtagname="mtr"></tr>', docP).append($(a));
var up = 0.6, dn = 0.6;
F.iter(function(e, i) {
if ((e.getAttribute(M.MathML ? 'rowspan' : 'rowSpan') || 1) == 1) {
up = Math.max(up, ups[i]);
dn = Math.max(dn, dns[i]);
}
}, a);
e$.fmUp = up + 0.25;
e$.fmDn = dn + 0.25;
} else if (tagName == 'mtd') { // return <td> partly so rowspan/colspan work
e$ = docP.createElement('td');
for (var i=0; i < a.length; i++)
e$.appendChild(a[i]);
e$.className = 'fm-mtd';
e$.setAttribute('mtagname', 'mtd');
//JQuery: e$ = $('<td class="fm-mtd" mtagname="mtd"></td>', docP).append($(a));
if (ups[0] > 0.65) e$.fmUp = ups[0];
if (dns[0] > 0.65) e$.fmDn = dns[0];
var e = M.setAttrs(e$, attrsP);
attrsP = undefined;
var rowspan = e.getAttribute('rowspan'), colspan = e.getAttribute('columnspan');
if (rowspan) {
e.setAttribute('rowSpan', rowspan); // for IE6-7
if (! M.hasClass(e, 'middle')) M.addClass(e, 'middle');
}
if (colspan) e.setAttribute('colSpan', colspan);
} else if (tagName == 'mfenced') {
var e = M.setAttrs(e$, attrsP);
return M.newMe('mrow', M.mfencedToMRowArgs(e), attrsP, docP);
} else throw 'Unrecognized or unimplemented MathML tagName: '+tagName;
return checkMathMLAttrs(M.setAttrs(e$, attrsP));
};
M.mfencedToMRowArgs = function(e) {
e.tagName.toLowerCase() == 'mfenced' || F.err(err_mfencedToMRowArgs_);
var doc = e.ownerDocument;
function newMo(s) { return M.newMe('mo', s, undefined, doc); }
var res = [newMo(F.defOr(M.getSpecAttrP(e, 'open'), '(')),
newMo(F.defOr(M.getSpecAttrP(e, 'close'), ')'))],
es = F.slice(e.childNodes);
if (es.length == 0) return res;
var inner;
if (es.length == 1) inner = es[0];
else {
var sepsP = F.defOr(M.getSpecAttrP(e, 'separators'), ',').match(/\S/g),
n = sepsP ? es.length - 1 : 0;
for (var i = 0; i < n; i++)
es.splice(2*i + 1, 0, newMo(sepsP[Math.min(i, sepsP.length - 1)]));
inner = M.newMe('mrow', es, undefined, doc);
}
res.splice(1, 0, inner);
return res;
};
M.spaceMe = function(widthS, docP) /* incl. avoid bad font support for \u2009   */
/* E.g. in Firefox 3.6.12, the DOM/jQuery don't like '' as a <mi>/<mo>/<mtext> child,
and also padding doesn't seem to work on e.g. <mn>/<mrow>/<mspace> elements;
also any kind of unicode space inside an <mo> might be stripped by the browser: */
{ return M.newMe('mspace', undefined, { width: widthS }, docP); };
M.fenceMe = function(me1, leftP, rightP, docP)
{ return M.newMe('mrow',
[M.newMe('mo', F.defOr(leftP, '('), docP), me1,
M.newMe('mo', F.defOr(rightP, ')'), docP)],
docP); };
F.iter(function(tagName) { M[tagName] = F(M.newMe, tagName); },
['mn', 'mi', 'mo', 'mtext', 'mspace', 'mrow', 'mfenced', 'mfrac', 'msqrt', 'mroot',
'msub', 'msup', 'msubsup', 'mmultiscripts', 'mprescripts', 'none',
'munder', 'mover', 'munderover', 'mtable', 'mtr', 'mtd',
'mstyle', 'merror', 'mpadded', 'mphantom', 'menclose']);
M.setMathBlockQ = function(e, blockQ) {
if (blockQ) {
e.setAttribute('display', 'block');
M.addClass(e, 'ma-block');
} else if (! M.MathML) M.addClass(e, 'fm-inline');
return e;
};
M.math = function(argsP /* for appendMeArgs() */, blockQ, docP)
{ return M.setMathBlockQ(M.newMe('math', argsP, docP), blockQ); };
M.eToMathE = function(mathE) /* 'mathE' has been parsed from MathML syntax */ {
if (M.MathML == null || mathE.tagName.toLowerCase() != 'math') F.err(err_eToMathE_);
function fixMathMLDeep(nod) {
if (nod.nodeType != 1 /* Element */) return nod;
if (! F.elem(nod.tagName, mtokens_)) F.iter(fixMathMLDeep, nod.childNodes);
return checkMathMLAttrs(nod);
}
if (M.MathML && mathE.tagName == 'math')
return fixMathMLQ_ ? fixMathMLDeep(mathE) : mathE;
var doc = mathE.ownerDocument;
function newMeDeep(me) {
var tagName = me.tagName.toLowerCase(), args = me.childNodes;
function nodeToMes(nod) {
// BUG: M.mtext() doesn't exist
if (nod.nodeType == 3 /* Text */)
return /^\s*$/.test(nod.data) ? [] : [M.mtext(nod.data, doc)];
if (nod.nodeType == 8 /* Comment */) return [];
me.nodeType == 1 /* Element */ || F.err(err_newMeDeep_);
return [newMeDeep(nod)];
}
if (F.elem(tagName, mtokens_)) {
if (tagName == 'mo' && args.length == 1 && args[0].nodeType == 3 /* Text */
&& args[0].data == '-') args = M['-'];
} else args = F.concatMap(nodeToMes, args);
var res = M.newMe(tagName, args, me.attributes, doc);
if (tagName == 'math') M.setMathBlockQ(res, me.getAttribute('display') == 'block');
return res;
}
return newMeDeep(mathE);
};
M['-'] = '\u2212'; // − −
M.trimNumS = function(s) /* trims trailing 0s after decimal point, trailing ., -0 */ {
return s.replace(/(\d\.\d*?)0+(?!\d)/g, '$1').replace(/(\d)\.(?!\d)/g, '$1').
replace(/[-\u2212]0(?![.\d])/g, '0');
};
M.numS = function(s, trimQ) /* converts a numeric string to jqMath notation */ {
if (trimQ) s = M.trimNumS(s);
return s.replace(/Infinity/ig, '\u221E' /* ∞ */).replace(/NaN/ig, '{?}').
replace(/e(-\d+)/ig, '\xB710^{$1}').replace(/e\+?(\d+)/ig, '\xB710^$1').
replace(/-/g, M['-']); // \xB7 is ·
};
/* Like TeX, we use ^ for superscripts, _ for subscripts, {} for grouping, and \ (or `) as
an escape character. Spaces and newline characters are ignored. We also use ↖ (\u2196)
and ↙ (\u2199) to put limits above and below an operator or expression. You can
$.extend() or even replace M.infix_, M.prefix_, M.postfix_, M.macros_, M.macro1s_, and
M.alias_ as needed. */
M.combiningChar_ = '[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]';
M.surrPair_ = '[\uD800-\uDBFF][\uDC00-\uDFFF]';
var decComma_, escPat_ = '[\\\\`]([A-Za-z]+|.)';
M.decimalComma = function(qP) /* whether to allow decimal commas */ {
if (qP != null) {
decComma_ = qP;
var numPat = (qP ? '\\d*,\\d+|' : '') + '\\d+\\.?\\d*|\\.\\d+';
M.re_ /* .lastIndex set during use */ = RegExp(
'('+numPat+')|'+escPat_+'|'+M.surrPair_+'|\\S'+M.combiningChar_+'*', 'g');
}
return decComma_;
};
var commaLangs = 'af|an|ar|av|az|ba|be|bg|bs|ca|ce|co|cs|cu|cv|da|de|el|es|et|eu|fi|fo|fr|'+
'gl|hr|hu|hy|id|is|it|jv|kk|kl|kv|lb|lt|lv|mk|mn|mo|nl|no|os|pl|pt|ro|ru|sc|sk|sq|sr|'+
'su|sv|tr|tt|ug|uk|vi|yi';
M.decimalComma(RegExp('^('+commaLangs+')\\b', 'i').test(document.documentElement.lang));
M.infix_ = { // operator precedences, see http://www.w3.org/TR/MathML3/appendixc.html
'⊂⃒': 240, '⊃⃒': 240,
'≪̸': 260, '≫̸': 260, '⪯̸': 260, '⪰̸': 260,
'∽̱': 265, '≂̸': 265, '≎̸': 265, '≏̸': 265, '≦̸': 265, '≿̸': 265, '⊏̸': 265, '⊐̸': 265, '⧏̸': 265,
'⧐̸': 265, '⩽̸': 265, '⩾̸': 265, '⪡̸': 265, '⪢̸': 265,
// if non-MathML and precedence <= 270, then class is 'fm-infix-loose' not 'fm-infix'
/* '-' is converted to '\u2212' − − */
'\u2009' /*   ' ', currently generates an <mspace> */: 390,
'' /* no <mo> is generated */: 500 /* not 390 or 850 */
/* \^ or `^ 880 not 780, \_ or `_ 880 not 900 */
// unescaped ^ _ ↖ (\u2196) ↙ (\u2199) have precedence 999
};
// If an infix op is also prefix or postfix, it must use the same precedence in each form.
// Also, we omit "multiple character operator"s like && or <=.
M.prefix_ = {};
// prefix precedence < 25 => thin space not inserted between multi-letter <mi> and it;
// (prefix or postfix precedence < 25) and non-MathML => <mo> stretchy;
// precedence < 25 => can be a fence
// can use {|...|} for absolute value
// + - % and other infix ops can automatically be used as prefix and postfix ops
// if non-MathML and prefix and 290 <= precedence <= 350, then 'fm-large-op'
M.postfix_ = {
// (unquoted) ' is converted to '\u2032' ′ ′
};
function setPrecs(precs, precCharsA) {
F.iter(function(prec_chars) {
var prec = prec_chars[0];
F.iter(function(c) { precs[c] = prec; }, prec_chars[1].split(''));
}, precCharsA);
}
setPrecs(M.infix_, [
[21, '|'], // | not 20 or 270
[30, ';'],
[40, ',\u2063'],
[70, '∴∵'],
[100, ':'],
[110, '϶'],
[150, '…⋮⋯⋱'],
[160, '∋'],
[170, '⊢⊣⊤⊨⊩⊬⊭⊮⊯'],
[190, '∨'],
[200, '∧'],
[240, '∁∈∉∌⊂⊃⊄⊅⊆⊇⊈⊉⊊⊋'],
[241, '≤'],
[242, '≥'],
[243, '>'],
[244, '≯'],
[245, '<'],
[246, '≮'],
[247, '≈'],
[250, '∼≉'],
[252, '≢'],
[255, '≠'],
[260, '=∝∤∥∦≁≃≄≅≆≇≍≔≗≙≚≜≟≡≨≩≪≫≭≰≱≺≻≼≽⊀⊁⊥⊴⊵⋉⋊⋋⋌⋔⋖⋗⋘⋙⋪⋫⋬⋭■□▪▫▭▮▯▰▱△▴▵▶▷▸▹▼▽▾▿◀◁◂◃'+
'◄◅◆◇◈◉◌◍◎●◖◗◦⧀⧁⧣⧤⧥⧦⧳⪇⪈⪯⪰'],
[265, '⁄∆∊∍∎∕∗∘∙∟∣∶∷∸∹∺∻∽∾∿≂≊≋≌≎≏≐≑≒≓≕≖≘≝≞≣≦≧≬≲≳≴≵≶≷≸≹≾≿⊌⊍⊎⊏⊐⊑⊒⊓⊔⊚⊛⊜⊝⊦⊧⊪⊫⊰⊱⊲⊳⊶⊷⊹⊺⊻⊼⊽⊾⊿⋄⋆⋇'+
'⋈⋍⋎⋏⋐⋑⋒⋓⋕⋚⋛⋜⋝⋞⋟⋠⋡⋢⋣⋤⋥⋦⋧⋨⋩⋰⋲⋳⋴⋵⋶⋷⋸⋹⋺⋻⋼⋽⋾⋿▲❘⦁⦂⦠⦡⦢⦣⦤⦥⦦⦧⦨⦩⦪⦫⦬⦭⦮⦯⦰⦱⦲⦳⦴⦵⦶⦷⦸⦹⦺⦻⦼⦽⦾⦿⧂⧃⧄'+
'⧅⧆⧇⧈⧉⧊⧋⧌⧍⧎⧏⧐⧑⧒⧓⧔⧕⧖⧗⧘⧙⧛⧜⧝⧞⧠⧡⧢⧧⧨⧩⧪⧫⧬⧭⧮⧰⧱⧲⧵⧶⧷⧸⧹⧺⧻⧾⧿⨝⨞⨟⨠⨡⨢⨣⨤⨥⨦⨧⨨⨩⨪⨫⨬⨭⨮⨰⨱⨲⨳⨴⨵⨶⨷⨸⨹'+
'⨺⨻⨼⨽⨾⩀⩁⩂⩃⩄⩅⩆⩇⩈⩉⩊⩋⩌⩍⩎⩏⩐⩑⩒⩓⩔⩕⩖⩗⩘⩙⩚⩛⩜⩝⩞⩟⩠⩡⩢⩣⩤⩥⩦⩧⩨⩩⩪⩫⩬⩭⩮⩯⩰⩱⩲⩳⩴⩵⩶⩷⩸⩹⩺⩻⩼⩽⩾⩿⪀⪁⪂⪃⪄⪅⪆⪉⪊⪋⪌⪍⪎⪏'+
'⪐⪑⪒⪓⪔⪕⪖⪗⪘⪙⪚⪛⪜⪝⪞⪟⪠⪡⪢⪣⪤⪥⪦⪧⪨⪩⪪⪫⪬⪭⪮⪱⪲⪳⪴⪵⪶⪷⪸⪹⪺⪻⪼⪽⪾⪿⫀⫁⫂⫃⫄⫅⫆⫇⫈⫉⫊⫋⫌⫍⫎⫏⫐⫑⫒⫓⫔⫕⫖⫗⫘⫙⫚⫛⫝⫝⫞⫟⫠⫡⫢⫣⫤⫥⫦'+
'⫧⫨⫩⫪⫫⫬⫭⫮⫯⫰⫱⫲⫳⫴⫵⫶⫷⫸⫹⫺⫻⫽⫾'],
[270, '←↑→↓↔↕↖↗↘↙↚↛↜↝↞↟↠↡↢↣↤↥↦↧↨↩↪↫↬↭↮↯↰↱↲↳↴↵↶↷↸↹↺↻↼↽↾↿⇀⇁⇂⇃⇄⇅⇆⇇⇈⇉⇊⇋⇌⇍⇎⇏⇐⇑'+
'⇒⇓⇔⇕⇖⇗⇘⇙⇚⇛⇜⇝⇞⇟⇠⇡⇢⇣⇤⇥⇦⇧⇨⇩⇪⇫⇬⇭⇮⇯⇰⇱⇲⇳⇴⇵⇶⇷⇸⇹⇺⇻⇼⇽⇾⇿⊸⟰⟱⟵⟶⟷⟸⟹⟺⟻⟼⟽⟾⟿⤀⤁⤂⤃⤄'+
'⤅⤆⤇⤈⤉⤊⤋⤌⤍⤎⤏⤐⤑⤒⤓⤔⤕⤖⤗⤘⤙⤚⤛⤜⤝⤞⤟⤠⤡⤢⤣⤤⤥⤦⤧⤨⤩⤪⤫⤬⤭⤮⤯⤰⤱⤲⤳⤴⤵⤶⤷⤸⤹⤺⤻⤼⤽⤾⤿⥀⥁⥂⥃⥄⥅⥆⥇⥈⥉⥊⥋⥌⥍⥎⥏⥐⥑⥒'+
'⥓⥔⥕⥖⥗⥘⥙⥚⥛⥜⥝⥞⥟⥠⥡⥢⥣⥤⥥⥦⥧⥨⥩⥪⥫⥬⥭⥮⥯⥰⥱⥲⥳⥴⥵⥶⥷⥸⥹⥺⥻⥼⥽⥾⥿⦙⦚⦛⦜⦝⦞⦟⧟⧯⧴⭅⭆'],
[275, '+-±−∓∔⊞⊟'],
[300, '⊕⊖⊘'],
[340, '≀'],
[350, '∩∪'],
[390, '*.ו\u2062⊠⊡⋅⨯⨿'],
[400, '·'],
[410, '⊗'],
[640, '%'],
[650, '\\∖'],
[660, '/÷'],
[710, '⊙'],
[825, '@'],
[835, '?'],
[850, '\u2061'],
[880, '^_\u2064']]);
setPrecs(M.prefix_, [
[10, '‘“'],
[20, '([{‖⌈⌊❲⟦⟨⟪⟬⟮⦀⦃⦅⦇⦉⦋⦍⦏⦑⦓⦕⦗⧼'],
[230, '∀∃∄'],
[290, '∑⨊⨋'],
[300, '∬∭⨁'],
[310, '∫∮∯∰∱∲∳⨌⨍⨎⨏⨐⨑⨒⨓⨔⨕⨖⨗⨘⨙⨚⨛⨜'],
[320, '⋃⨃⨄'],
[330, '⋀⋁⋂⨀⨂⨅⨆⨇⨈⨉⫼⫿'],
[350, '∏∐'],
[670, '∠∡∢'],
[680, '¬'],
[740, '∂∇'],
[845, 'ⅅⅆ√∛∜']]);
setPrecs(M.postfix_, [
[10, '’”'],
[20, ')]}‖⌉⌋❳⟧⟩⟫⟭⟯⦀⦄⦆⦈⦊⦌⦎⦐⦒⦔⦖⦘⧽'],
[800, '′♭♮♯'],
[810, '!'],
[880, '&\'`~¨¯°´¸ˆˇˉˊˋˍ˘˙˚˜˝˷\u0302\u0311‾\u20db\u20dc⎴⎵⏜⏝⏞⏟⏠⏡']]);
var s_, s_or_mx_a_, s_or_mx_i_, docP_, precAdj_;
/* A "tok" (scanner token or similar) here is an [meP, opSP], with at least one != null.
The meP may be non-atomic. Thus a tok is either an me, possibly with a precedence given
by an operator, or else either a meta-operator or "macro1" for building an me. */
function newMe_(tagName, argsP, attrsP) { return M.newMe(tagName, argsP, attrsP, docP_); }
function emptyMe_() { return newMe_('mspace' /* or 'mrow'? */); }
function scanWord(descP) /* use scanString() instead if any quotes should be stripped */ {
var re = /\s*([-\w.]*)/g; //+ could allow all unicode alphabetics
re.lastIndex = M.re_.lastIndex;
var match = re.exec(s_);
if (! match[1]) throw 'Missing '+(descP || 'word');
M.re_.lastIndex = re.lastIndex;
return match[1];
}
function scanString(descP) /* scans a word or quoted string */ {
var re = /\s*(?:(["'])|([-\w.]*))/g;
re.lastIndex = M.re_.lastIndex;