mmultiscripts.js
6.99 KB
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
/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*************************************************************
*
* MathJax/jax/output/HTML-CSS/autoload/mmultiscripts.js
*
* Implements the HTML-CSS output for <mmultiscripts> elements.
*
* ---------------------------------------------------------------------
*
* Copyright (c) 2010-2014 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
var VERSION = "2.4.0";
var MML = MathJax.ElementJax.mml,
HTMLCSS = MathJax.OutputJax["HTML-CSS"];
MML.mmultiscripts.Augment({
toHTML: function (span,HW,D) {
span = this.HTMLcreateSpan(span); var scale = this.HTMLgetScale();
var stack = HTMLCSS.createStack(span), values;
var base = HTMLCSS.createBox(stack);
if (this.data[this.base]) {
var child = this.data[this.base].toHTML(base);
if (D != null) {this.data[this.base].HTMLstretchV(base,HW,D)}
else if (HW != null) {this.data[this.base].HTMLstretchH(base,HW)}
HTMLCSS.Measured(child,base);
} else {base.bbox = this.HTMLzeroBBox()}
var x_height = HTMLCSS.TeX.x_height * scale,
s = HTMLCSS.TeX.scriptspace * scale * .75; // FIXME: .75 can be removed when IC is right?
var BOX = this.HTMLgetScripts(stack,s);
var sub = BOX[0], sup = BOX[1], presub = BOX[2], presup = BOX[3];
//
// <mmultiscripts> children other than the base can be <none/>,
// <mprescripts/>, <mrow></mrow> etc so try to get HTMLgetScale from the
// first element with a spanID. See issue 362.
//
var sscale = scale;
for (var i = 1; i < this.data.length; i++) {
if (this.data[i] && this.data[i].spanID) {
sscale = this.data[i].HTMLgetScale();
break;
}
}
var q = HTMLCSS.TeX.sup_drop * sscale, r = HTMLCSS.TeX.sub_drop * sscale;
var u = base.bbox.h - q, v = base.bbox.d + r, delta = 0, p;
if (base.bbox.ic) {delta = base.bbox.ic}
if (this.data[this.base] &&
(this.data[this.base].type === "mi" || this.data[this.base].type === "mo")) {
if (this.data[this.base].data.join("").length === 1 && base.bbox.scale === 1 &&
!this.data[this.base].Get("largeop")) {u = v = 0}
}
var min = this.getValues("subscriptshift","superscriptshift"), mu = this.HTMLgetMu(span);
min.subscriptshift = (min.subscriptshift === "" ? 0 : HTMLCSS.length2em(min.subscriptshift,mu));
min.superscriptshift = (min.superscriptshift === "" ? 0 : HTMLCSS.length2em(min.superscriptshift,mu));
var dx = 0;
if (presub) {dx = presub.bbox.w+delta} else if (presup) {dx = presup.bbox.w-delta}
if (dx < 0) {dx = 0};
HTMLCSS.placeBox(base,dx,0);
if (!sup && !presup) {
v = Math.max(v,HTMLCSS.TeX.sub1*scale,min.subscriptshift);
if (sub) {v = Math.max(v,sub.bbox.h-(4/5)*x_height)}
if (presub) {v = Math.max(v,presub.bbox.h-(4/5)*x_height)}
if (sub) {HTMLCSS.placeBox(sub,dx+base.bbox.w+s-delta,-v)}
if (presub) {HTMLCSS.placeBox(presub,0,-v)}
} else {
if (!sub && !presub) {
values = this.getValues("displaystyle","texprimestyle");
p = HTMLCSS.TeX[(values.displaystyle ? "sup1" : (values.texprimestyle ? "sup3" : "sup2"))];
u = Math.max(u,p*scale,min.superscriptshift);
if (sup) {u = Math.max(u,sup.bbox.d+(1/4)*x_height)}
if (presup) {u = Math.max(u,presup.bbox.d+(1/4)*x_height)}
if (sup) {HTMLCSS.placeBox(sup,dx+base.bbox.w+s,u)}
if (presup) {HTMLCSS.placeBox(presup,0,u)}
} else {
v = Math.max(v,HTMLCSS.TeX.sub2*scale);
var t = HTMLCSS.TeX.rule_thickness * scale;
var h = (sub||presub).bbox.h, d = (sup||presup).bbox.d;
if (presub) {h = Math.max(h,presub.bbox.h)}
if (presup) {d = Math.max(d,presup.bbox.d)}
if ((u - d) - (h - v) < 3*t) {
v = 3*t - u + d + h; q = (4/5)*x_height - (u - d);
if (q > 0) {u += q; v -= q}
}
u = Math.max(u,min.superscriptshift); v = Math.max(v,min.subscriptshift);
if (sup) {HTMLCSS.placeBox(sup,dx+base.bbox.w+s,u)}
if (presup) {HTMLCSS.placeBox(presup,dx+delta-presup.bbox.w,u)}
if (sub) {HTMLCSS.placeBox(sub,dx+base.bbox.w+s-delta,-v)}
if (presub) {HTMLCSS.placeBox(presub,dx-presub.bbox.w,-v)}
}
}
this.HTMLhandleSpace(span);
this.HTMLhandleColor(span);
var bbox = span.bbox;
bbox.dx = dx; bbox.s = s; bbox.u = u; bbox.v = v; bbox.delta = delta;
bbox.px = dx+base.bbox.w;
return span;
},
HTMLgetScripts: function (stack,s) {
var sup, sub, BOX = [];
var i = 1, m = this.data.length, W = 0;
for (var k = 0; k < 4; k += 2) {
while (i < m && this.data[i].type !== "mprescripts") {
for (var j = k; j < k+2; j++) {
if (this.data[i] && this.data[i].type !== "none") {
if (!BOX[j]) {
BOX[j] = HTMLCSS.createBox(stack); BOX[j].bbox = this.HTMLemptyBBox({});
if (W) {HTMLCSS.createBlank(BOX[j],W); BOX[j].bbox.w = BOX[j].bbox.rw = W}
}
this.data[i].toHTML(BOX[j]); this.HTMLcombineBBoxes(this.data[i],BOX[j].bbox);
}
i++;
}
sub = BOX[k]; sup = BOX[k+1];
if (sub && sup) {
if (sub.bbox.w < sup.bbox.w) {
HTMLCSS.createBlank(sub,sup.bbox.w-sub.bbox.w);
sub.bbox.w = sup.bbox.w; sub.bbox.rw = Math.max(sub.bbox.w,sub.bbox.rw);
} else if (sub.bbox.w > sup.bbox.w) {
HTMLCSS.createBlank(sup,sub.bbox.w-sup.bbox.w);
sup.bbox.w = sub.bbox.w; sup.bbox.rw = Math.max(sup.bbox.w,sup.bbox.rw);
}
}
if (sub) {W = sub.bbox.w} else if (sup) {W = sup.bbox.w}
}
i++; W = 0;
}
for (j = 0; j < 4; j++) {
if (BOX[j]) {
BOX[j].bbox.w += s;
BOX[j].bbox.rw = Math.max(BOX[j].bbox.w,BOX[j].bbox.rw);
BOX[j].bbox.name = (["sub","sup","presub","presup"])[j];
this.HTMLcleanBBox(BOX[j].bbox);
}
}
return BOX;
},
HTMLstretchH: MML.mbase.HTMLstretchH,
HTMLstretchV: MML.mbase.HTMLstretchV
});
MathJax.Hub.Startup.signal.Post("HTML-CSS mmultiscripts Ready");
MathJax.Ajax.loadComplete(HTMLCSS.autoloadDir+"/mmultiscripts.js");
});