Debian Codegraph @

unpacked/jax/output/HTML-CSS/autoload/mmultiscripts.js

raw
1 /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3
4 /*************************************************************
5 *
6 * MathJax/jax/output/HTML-CSS/autoload/mmultiscripts.js
7 *
8 * Implements the HTML-CSS output for <mmultiscripts> elements.
9 *
10 * ---------------------------------------------------------------------
11 *
12 * Copyright (c) 2010-2020 The MathJax Consortium
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 */
26
27 MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
28 var VERSION = "2.7.9";
29 var MML = MathJax.ElementJax.mml,
30 HTMLCSS = MathJax.OutputJax["HTML-CSS"];
31
32 MML.mmultiscripts.Augment({
33 toHTML: function (span,HW,D) {
34 span = this.HTMLcreateSpan(span); var scale = this.HTMLgetScale();
35 var stack = HTMLCSS.createStack(span), values;
36 var base = HTMLCSS.createBox(stack);
37 if (this.data[this.base]) {
38 var child = this.data[this.base].toHTML(base);
39 if (D != null) {this.data[this.base].HTMLstretchV(base,HW,D)}
40 else if (HW != null) {this.data[this.base].HTMLstretchH(base,HW)}
41 HTMLCSS.Measured(child,base);
42 } else {base.bbox = this.HTMLzeroBBox()}
43 var x_height = HTMLCSS.TeX.x_height * scale,
44 s = HTMLCSS.TeX.scriptspace * scale * .75; // FIXME: .75 can be removed when IC is right?
45
46 var BOX = this.HTMLgetScripts(stack,s);
47 var sub = BOX[0], sup = BOX[1], presub = BOX[2], presup = BOX[3];
48
49 //
50 // <mmultiscripts> children other than the base can be <none/>,
51 // <mprescripts/>, <mrow></mrow> etc so try to get HTMLgetScale from the
52 // first element with a spanID. See issue 362.
53 //
54 var sscale = scale;
55 for (var i = 1; i < this.data.length; i++) {
56 if (this.data[i] && this.data[i].spanID) {
57 sscale = this.data[i].HTMLgetScale();
58 break;
59 }
60 }
61
62 var q = HTMLCSS.TeX.sup_drop * sscale, r = HTMLCSS.TeX.sub_drop * sscale;
63 var u = base.bbox.h - q, v = base.bbox.d + r, delta = 0, p;
64 if (base.bbox.ic) {delta = base.bbox.ic}
65 if (this.data[this.base] &&
66 (this.data[this.base].type === "mi" || this.data[this.base].type === "mo")) {
67 if (HTMLCSS.isChar(this.data[this.base].data.join("")) && base.bbox.scale === 1 &&
68 !this.data[this.base].Get("largeop")) {u = v = 0}
69 }
70 var min = this.getValues("subscriptshift","superscriptshift"), mu = this.HTMLgetMu(span);
71 min.subscriptshift = (min.subscriptshift === "" ? 0 : HTMLCSS.length2em(min.subscriptshift,mu));
72 min.superscriptshift = (min.superscriptshift === "" ? 0 : HTMLCSS.length2em(min.superscriptshift,mu));
73
74 var dx = 0;
75 if (presub) {dx = presub.bbox.w+delta} else if (presup) {dx = presup.bbox.w-delta}
76 if (dx < 0) {dx = 0};
77 HTMLCSS.placeBox(base,dx,0);
78
79 if (!sup && !presup) {
80 v = Math.max(v,HTMLCSS.TeX.sub1*scale,min.subscriptshift);
81 if (sub) {v = Math.max(v,sub.bbox.h-(4/5)*x_height)}
82 if (presub) {v = Math.max(v,presub.bbox.h-(4/5)*x_height)}
83 if (sub) {HTMLCSS.placeBox(sub,dx+base.bbox.w+s-delta,-v)}
84 if (presub) {HTMLCSS.placeBox(presub,0,-v)}
85 } else {
86 if (!sub && !presub) {
87 values = this.getValues("displaystyle","texprimestyle");
88 p = HTMLCSS.TeX[(values.displaystyle ? "sup1" : (values.texprimestyle ? "sup3" : "sup2"))];
89 u = Math.max(u,p*scale,min.superscriptshift);
90 if (sup) {u = Math.max(u,sup.bbox.d+(1/4)*x_height)}
91 if (presup) {u = Math.max(u,presup.bbox.d+(1/4)*x_height)}
92 if (sup) {HTMLCSS.placeBox(sup,dx+base.bbox.w+s,u)}
93 if (presup) {HTMLCSS.placeBox(presup,0,u)}
94 } else {
95 v = Math.max(v,HTMLCSS.TeX.sub2*scale);
96 var t = HTMLCSS.TeX.rule_thickness * scale;
97 var h = (sub||presub).bbox.h, d = (sup||presup).bbox.d;
98 if (presub) {h = Math.max(h,presub.bbox.h)}
99 if (presup) {d = Math.max(d,presup.bbox.d)}
100 if ((u - d) - (h - v) < 3*t) {
101 v = 3*t - u + d + h; q = (4/5)*x_height - (u - d);
102 if (q > 0) {u += q; v -= q}
103 }
104 u = Math.max(u,min.superscriptshift); v = Math.max(v,min.subscriptshift);
105 if (sup) {HTMLCSS.placeBox(sup,dx+base.bbox.w+s,u)}
106 if (presup) {HTMLCSS.placeBox(presup,dx+delta-presup.bbox.w,u)}
107 if (sub) {HTMLCSS.placeBox(sub,dx+base.bbox.w+s-delta,-v)}
108 if (presub) {HTMLCSS.placeBox(presub,dx-presub.bbox.w,-v)}
109 }
110 }
111 this.HTMLhandleSpace(span);
112 this.HTMLhandleColor(span);
113 var bbox = span.bbox;
114 bbox.dx = dx; bbox.s = s; bbox.u = u; bbox.v = v; bbox.delta = delta;
115 bbox.px = dx+base.bbox.w;
116 return span;
117 },
118 HTMLgetScripts: function (stack,s) {
119 var sup, sub, BOX = [];
120 var i = 1, m = this.data.length, W = 0;
121 for (var k = 0; k < 4; k += 2) {
122 while (i < m && (this.data[i]||{}).type !== "mprescripts") {
123 var box = [null,null,null,null];
124 for (var j = k; j < k+2; j++) {
125 if (this.data[i] && this.data[i].type !== "none" && this.data[i].type !== "mprescripts") {
126 if (!BOX[j]) {
127 BOX[j] = HTMLCSS.createBox(stack); BOX[j].bbox = this.HTMLemptyBBox({});
128 if (W) {HTMLCSS.createBlank(BOX[j],W); BOX[j].bbox.w = BOX[j].bbox.rw = W}
129 }
130 box[j] = this.data[i].toHTML(BOX[j]);
131 } else {
132 box[j] = MathJax.HTML.Element("span",{bbox:this.HTMLemptyBBox({})});
133 }
134 if ((this.data[i]||{}).type !== "mprescripts") i++;
135 }
136 var isPre = (k === 2);
137 sub = BOX[k]; sup = BOX[k+1];
138 if (sub && sup) {
139 var w = box[k+1].bbox.w - box[k].bbox.w;
140 if (w > 0) {
141 if (isPre) {
142 this.HTMLmoveColor(box[k],w,1);
143 BOX[k].w += w;
144 } else {
145 HTMLCSS.createBlank(sub,w);
146 }
147 } else if (w < 0) {
148 if (isPre) {
149 this.HTMLmoveColor(box[k+1],-w,-1);
150 BOX[k+1].w += -w;
151 } else {
152 HTMLCSS.createBlank(sup,-w);
153 }
154 }
155 this.HTMLcombineBBoxes(box[k],sub.bbox);
156 this.HTMLcombineBBoxes(box[k+1],sup.bbox);
157 if (w > 0) {
158 sub.bbox.w = sup.bbox.w;
159 sub.bbox.rw = Math.max(sub.bbox.w,sub.bbox.rw);
160 } else if (w < 0) {
161 sup.bbox.w = sub.bbox.w;
162 sup.bbox.rw = Math.max(sup.bbox.w,sup.bbox.rw);
163 }
164 } else {
165 if (sub) this.HTMLcombineBBoxes(box[k],sub.bbox);
166 if (sup) this.HTMLcombineBBoxes(box[k+1],sup.bbox);
167 }
168 if (sub) {W = sub.bbox.w} else if (sup) {W = sup.bbox.w}
169 }
170 i++; W = 0;
171 }
172 for (j = 0; j < 4; j++) {
173 if (BOX[j]) {
174 BOX[j].bbox.w += s;
175 BOX[j].bbox.rw = Math.max(BOX[j].bbox.w,BOX[j].bbox.rw);
176 BOX[j].bbox.name = (["sub","sup","presub","presup"])[j];
177 this.HTMLcleanBBox(BOX[j].bbox);
178 }
179 }
180 return BOX;
181 },
182 HTMLmoveColor: function (box,w,sign) {
183 var W = w/(box.scale||1);
184 box.style.paddingLeft = HTMLCSS.Em(W);
185 var color = box.previousSibling;
186 if (color && (color.id||"").match(/^MathJax-Color-/)) {
187 color.style.marginLeft = HTMLCSS.Em(W+parseFloat(color.style.marginLeft));
188 color.style.marginRight = HTMLCSS.Em(sign*(W-parseFloat(color.style.marginRight)));
189 }
190
191 },
192 HTMLstretchH: MML.mbase.HTMLstretchH,
193 HTMLstretchV: MML.mbase.HTMLstretchV
194 });
195
196 MathJax.Hub.Startup.signal.Post("HTML-CSS mmultiscripts Ready");
197 MathJax.Ajax.loadComplete(HTMLCSS.autoloadDir+"/mmultiscripts.js");
198
199 });
200