Debian Codegraph @

unpacked/jax/output/CommonHTML/jax.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/CommonHTML/jax.js
7 *
8 * Implements the CommonHTML OutputJax that displays mathematics
9 * using HTML and CSS to position the characters from math fonts
10 * in their proper locations. Unlike the HTML-CSS output jax,
11 * this HTML is browser and OS independent.
12 *
13 * ---------------------------------------------------------------------
14 *
15 * Copyright (c) 2013-2020 The MathJax Consortium
16 *
17 * Licensed under the Apache License, Version 2.0 (the "License");
18 * you may not use this file except in compliance with the License.
19 * You may obtain a copy of the License at
20 *
21 * http://www.apache.org/licenses/LICENSE-2.0
22 *
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS,
25 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
28 */
29
30
31 (function (AJAX,HUB,HTML,CHTML) {
32 var MML;
33 var isArray = MathJax.Object.isArray;
34
35 var EVENT, TOUCH, HOVER; // filled in later
36
37 var STRUTHEIGHT = 1,
38 EFUZZ = .1, // overlap needed for stretchy delimiters
39 HFUZZ = .025, DFUZZ = .025; // adjustments to bounding box of character boxes
40
41 var STYLES = {
42 ".mjx-chtml": {
43 display: "inline-block",
44 "line-height": 0,
45 "text-indent": 0,
46 "text-align": "left",
47 "text-transform": "none",
48 "font-style": "normal",
49 "font-weight": "normal",
50 "font-size": "100%",
51 "font-size-adjust":"none",
52 "letter-spacing": "normal",
53 "word-wrap": "normal",
54 "word-spacing": "normal",
55 "white-space": "nowrap",
56 "float": "none",
57 "direction": "ltr",
58 "max-width": "none",
59 "max-height": "none",
60 "min-width": 0,
61 "min-height": 0,
62 border: 0,
63 margin: 0,
64 padding: "1px 0"
65 },
66 ".MJXc-display": {
67 display: "block",
68 "text-align": "center",
69 "margin": "1em 0",
70 padding: 0
71 },
72 ".mjx-chtml[tabindex]:focus, body :focus .mjx-chtml[tabindex]": {
73 display: "inline-table" // see issues #1282 and #1338
74 },
75 ".mjx-full-width": {
76 "text-align": "center",
77 display: "table-cell!important",
78 width: "10000em"
79 },
80
81 ".mjx-math": {
82 "display": "inline-block",
83 "border-collapse": "separate",
84 "border-spacing": 0
85 },
86 ".mjx-math *": {
87 display:"inline-block",
88 "-webkit-box-sizing": "content-box!important",
89 "-moz-box-sizing": "content-box!important",
90 "box-sizing": "content-box!important", // override bootstrap settings
91 "text-align":"left"
92 },
93
94 ".mjx-numerator": {display:"block", "text-align":"center"},
95 ".mjx-denominator": {display:"block", "text-align":"center"},
96 ".MJXc-stacked": {height:0, position:"relative"},
97 ".MJXc-stacked > *": {position: "absolute"},
98 ".MJXc-bevelled > *": {display:"inline-block"},
99
100 ".mjx-stack": {display:"inline-block"},
101 ".mjx-op": {display:"block"},
102 ".mjx-under": {display:"table-cell"},
103 ".mjx-over": {display:"block"},
104 ".mjx-over > *": {"padding-left":"0px!important", "padding-right":"0px!important"},
105 ".mjx-under > *": {"padding-left":"0px!important", "padding-right":"0px!important"},
106
107 ".mjx-stack > .mjx-sup": {display:"block"},
108 ".mjx-stack > .mjx-sub": {display:"block"},
109 ".mjx-prestack > .mjx-presup": {display:"block"},
110 ".mjx-prestack > .mjx-presub": {display:"block"},
111
112 ".mjx-delim-h > .mjx-char": {display:"inline-block"},
113
114 ".mjx-surd": {"vertical-align":"top"},
115 ".mjx-surd + .mjx-box": {display:"inline-flex"},
116
117 ".mjx-mphantom *": {visibility:"hidden"},
118
119 ".mjx-merror": {
120 "background-color":"#FFFF88",
121 color: "#CC0000",
122 border: "1px solid #CC0000",
123 padding: "2px 3px",
124 "font-style": "normal",
125 "font-size": "90%"
126 },
127
128 ".mjx-annotation-xml": {"line-height":"normal"},
129
130 ".mjx-menclose > svg": {fill:"none", stroke:"currentColor", overflow:"visible"},
131
132 ".mjx-mtr": {display:"table-row"},
133 ".mjx-mlabeledtr": {display:"table-row"},
134 ".mjx-mtd": {display:"table-cell", "text-align":"center"},
135 ".mjx-label": {display:"table-row"},
136
137 ".mjx-box": {display:"inline-block"},
138 ".mjx-block": {display:"block"},
139 ".mjx-span": {display:"inline"},
140 ".mjx-char": {display:"block", "white-space":"pre"},
141 ".mjx-itable": {display:"inline-table", width:"auto"},
142 ".mjx-row": {display:"table-row"},
143 ".mjx-cell": {display:"table-cell"},
144 ".mjx-table": {display:"table", width:"100%"},
145 ".mjx-line": {display:"block", height:0},
146 ".mjx-strut": {width:0, "padding-top":STRUTHEIGHT+"em"},
147 ".mjx-vsize": {width:0},
148
149 ".MJXc-space1": {"margin-left":".167em"},
150 ".MJXc-space2": {"margin-left":".222em"},
151 ".MJXc-space3": {"margin-left":".278em"},
152
153 ".mjx-chartest": {
154 display:"block",
155 visibility: "hidden",
156 position:"absolute", top:0,
157 "line-height":"normal",
158 "font-size":"500%"
159 },
160 ".mjx-chartest .mjx-char": {display:"inline"},
161 ".mjx-chartest .mjx-box": {"padding-top": "1000px"},
162
163 ".MJXc-processing": {
164 visibility: "hidden", position:"fixed",
165 width: 0, height: 0, overflow:"hidden"
166 },
167 ".MJXc-processed": {display:"none"},
168
169 ".mjx-test": {
170 "font-style": "normal",
171 "font-weight": "normal",
172 "font-size": "100%",
173 "font-size-adjust":"none",
174 "text-indent": 0,
175 "text-transform": "none",
176 "letter-spacing": "normal",
177 "word-spacing": "normal",
178 overflow: "hidden",
179 height: "1px"
180 },
181 ".mjx-test.mjx-test-display": {
182 display: "table!important"
183 },
184 ".mjx-test.mjx-test-inline": {
185 display: "inline!important",
186 "margin-right": "-1px"
187 },
188 ".mjx-test.mjx-test-default": {
189 display: "block!important",
190 clear: "both"
191 },
192 ".mjx-ex-box": {
193 display: "inline-block!important",
194 position: "absolute",
195 overflow: "hidden",
196 "min-height": 0, "max-height":"none",
197 padding:0, border: 0, margin: 0,
198 width:"1px", height:"60ex"
199 },
200 ".mjx-test-inline .mjx-left-box": {
201 display: "inline-block",
202 width: 0,
203 "float":"left"
204 },
205 ".mjx-test-inline .mjx-right-box": {
206 display: "inline-block",
207 width: 0,
208 "float":"right"
209 },
210 ".mjx-test-display .mjx-right-box": {
211 display: "table-cell!important",
212 width: "10000em!important",
213 "min-width":0, "max-width":"none",
214 padding:0, border:0, margin:0
215 },
216
217 "#MathJax_CHTML_Tooltip": {
218 "background-color": "InfoBackground", color: "InfoText",
219 border: "1px solid black",
220 "box-shadow": "2px 2px 5px #AAAAAA", // Opera 10.5
221 "-webkit-box-shadow": "2px 2px 5px #AAAAAA", // Safari 3 and Chrome
222 "-moz-box-shadow": "2px 2px 5px #AAAAAA", // Firefox 3.5
223 "-khtml-box-shadow": "2px 2px 5px #AAAAAA", // Konqueror
224 padding: "3px 4px",
225 "z-index": 401,
226 position: "absolute", left: 0, top: 0,
227 width: "auto", height: "auto",
228 display: "none"
229 }
230
231 };
232
233
234 /************************************************************/
235
236 var BIGDIMEN = 1000000;
237 var MAXREMAP = 5;
238 var LINEBREAKS = {}, CONFIG = MathJax.Hub.config;
239
240 CHTML.Augment({
241 settings: HUB.config.menuSettings,
242 config: {styles: STYLES},
243
244 /********************************************/
245
246 Config: function () {
247 if (!this.require) {this.require = []}
248 this.SUPER(arguments).Config.call(this); var settings = this.settings;
249 if (settings.scale) {this.config.scale = settings.scale}
250 this.require.push(this.fontDir+"/TeX/fontdata.js");
251 this.require.push(MathJax.OutputJax.extensionDir+"/MathEvents.js");
252 LINEBREAKS = this.config.linebreaks;
253 },
254
255 Startup: function () {
256 //
257 // Set up event handling
258 //
259 EVENT = MathJax.Extension.MathEvents.Event;
260 TOUCH = MathJax.Extension.MathEvents.Touch;
261 HOVER = MathJax.Extension.MathEvents.Hover;
262 this.ContextMenu = EVENT.ContextMenu;
263 this.Mousedown = EVENT.AltContextMenu;
264 this.Mouseover = HOVER.Mouseover;
265 this.Mouseout = HOVER.Mouseout;
266 this.Mousemove = HOVER.Mousemove;
267
268 //
269 // Determine pixels per inch
270 //
271 var div = CHTML.addElement(document.body,"mjx-block",{style:{display:"block",width:"5in"}});
272 this.pxPerInch = div.offsetWidth/5; div.parentNode.removeChild(div);
273
274 //
275 // Used in preTranslate to get scaling factors and line width
276 //
277 this.TestSpan = CHTML.Element("mjx-test",{style:{left:"1em"}},
278 [["mjx-left-box"],["mjx-ex-box"],["mjx-right-box"]]);
279
280 //
281 // Set up styles and preload web fonts
282 //
283 return AJAX.Styles(this.config.styles,["InitializeCHTML",this]);
284 },
285
286 InitializeCHTML: function () {
287 this.getDefaultExEm();
288 //
289 // If the defaultEm size is zero, it might be that a web font hasn't
290 // arrived yet, so try to wait for it, but don't wait too long.
291 //
292 if (this.defaultEm) return;
293 var ready = MathJax.Callback();
294 AJAX.timer.start(AJAX,function (check) {
295 if (check.time(ready)) {HUB.signal.Post(["CommonHTML Jax - no default em size"]); return}
296 CHTML.getDefaultExEm();
297 if (CHTML.defaultEm) {ready()} else {setTimeout(check,check.delay)}
298 },this.defaultEmDelay,this.defaultEmTimeout);
299 return ready;
300 },
301 defaultEmDelay: 100, // initial delay when checking for defaultEm
302 defaultEmTimeout: 1000, // when to stop looking for defaultEm
303 getDefaultExEm: function () {
304 //
305 // Get the default sizes (need styles in place to do this)
306 //
307 var test = document.body.appendChild(this.TestSpan.cloneNode(true));
308 test.className += " mjx-test-inline mjx-test-default";
309 this.defaultEm = this.getFontSize(test);
310 this.defaultEx = test.childNodes[1].offsetHeight/60;
311 this.defaultWidth = Math.max(0,test.lastChild.offsetLeft-test.firstChild.offsetLeft-2);
312 document.body.removeChild(test);
313 },
314 getFontSize: (window.getComputedStyle ?
315 function (node) {
316 var style = window.getComputedStyle(node);
317 return parseFloat(style.fontSize);
318 } :
319 //
320 // IE 8 doesn't do getComputedStyle, so use
321 // an alternative approach
322 //
323 function (node) {
324 return node.style.pixelLeft;
325 }
326 ),
327 getMaxWidth: (window.getComputedStyle ?
328 function (node) {
329 var style = window.getComputedStyle(node);
330 if (style.maxWidth !== "none") return parseFloat(style.maxWidth);
331 return 0;
332 } :
333 //
334 // IE 8 doesn't do getComputedStyle, so use
335 // currentStyle, and a hack to get the pixels for
336 // a non-px max-width
337 //
338 function (node) {
339 var max = node.currentStyle.maxWidth;
340 if (max !== "none") {
341 if (max.match(/\d*px/)) return parseFloat(max);
342 var left = node.style.left;
343 node.style.left = max; max = node.style.pixelLeft;
344 node.style.left = left;
345 return max;
346 }
347 return 0;
348 }
349 ),
350
351 //
352 // Load data for a font
353 //
354 loadFont: function (font) {
355 HUB.RestartAfter(AJAX.Require(this.fontDir+"/"+font));
356 },
357 //
358 // Signal that the font data are loaded
359 //
360 fontLoaded: function (font) {
361 if (!font.match(/-|fontdata/)) font += "-Regular";
362 if (!font.match(/\.js$/)) font += ".js"
363 MathJax.Callback.Queue(
364 ["Post",HUB.Startup.signal,"CommonHTML - font data loaded for " + font],
365 ["loadComplete",AJAX,this.fontDir+"/"+font]
366 );
367 },
368
369 Element: function (type,def,content) {
370 if (type.substr(0,4) === "mjx-") {
371 if (!def) def = {};
372 if (def.isMathJax == null) def.isMathJax = true;
373 if (def.className) def.className = type+" "+def.className; else def.className = type;
374 type = "span";
375 }
376 return this.HTMLElement(type,def,content);
377 },
378 addElement: function (node,type,def,content) {
379 return node.appendChild(this.Element(type,def,content));
380 },
381 HTMLElement: HTML.Element,
382 ucMatch: HTML.ucMatch,
383 setScript: HTML.setScript,
384
385 //
386 // Look through the direct children of a node for one with the given
387 // type (but if the node has intervening containers for its children,
388 // step into them; note that elements corresponding to MathML nodes
389 // will have id's so we don't step into them).
390 //
391 // This is used by munderover and msubsup to locate their child elements
392 // when they are part of an embellished operator that is being stretched.
393 // We don't use querySelector because we want to find only the direct child
394 // nodes, not nodes that might be nested deeper in the tree (see issue #1447).
395 //
396 getNode: function (node,type) {
397 var name = RegExp("\\b"+type+"\\b");
398 var nodes = [];
399 while (node) {
400 for (var i = 0, m = node.childNodes.length; i < m; i++) {
401 var child = node.childNodes[i];
402 if (child) {
403 if (name.test(child.className)) return child;
404 if (child.id === "") nodes.push(child);
405 }
406 }
407 node = nodes.shift();
408 }
409 return null;
410 },
411
412 /********************************************/
413
414 preTranslate: function (state) {
415 var scripts = state.jax[this.id], i, m = scripts.length,
416 script, prev, node, test, jax, ex, em, scale;
417 //
418 // Get linebreaking information
419 //
420 var maxwidth = 100000, relwidth = false, cwidth = 0,
421 linebreak = LINEBREAKS.automatic, width = LINEBREAKS.width;
422 if (linebreak) {
423 relwidth = !!width.match(/^\s*(\d+(\.\d*)?%\s*)?container\s*$/);
424 if (relwidth) {width = width.replace(/\s*container\s*/,"")}
425 else {maxwidth = this.defaultWidth}
426 if (width === "") {width = "100%"}
427 }
428 //
429 // Loop through the scripts
430 //
431 for (i = 0; i < m; i++) {
432 script = scripts[i]; if (!script.parentNode) continue;
433 //
434 // Remove any existing output
435 //
436 prev = script.previousSibling;
437 if (prev && prev.className && String(prev.className).substr(0,9) === "mjx-chtml")
438 prev.parentNode.removeChild(prev);
439 if (script.MathJax.preview) script.MathJax.preview.style.display = "none";
440 //
441 // Add the node for the math and mark it as being processed
442 //
443 jax = script.MathJax.elementJax; if (!jax) continue;
444 jax.CHTML = {
445 display: (jax.root.Get("display") === "block"),
446 preview: (jax.CHTML||{}).preview // in case typeset calls are interleaved
447 };
448 node = CHTML.Element("mjx-chtml",{
449 id:jax.inputID+"-Frame", className:"MathJax_CHTML", isMathJax:true, jaxID:this.id,
450 oncontextmenu:EVENT.Menu, onmousedown: EVENT.Mousedown,
451 onmouseover:EVENT.Mouseover, onmouseout:EVENT.Mouseout, onmousemove:EVENT.Mousemove,
452 onclick:EVENT.Click, ondblclick:EVENT.DblClick,
453 // Added for keyboard accessible menu.
454 onkeydown: EVENT.Keydown, tabIndex: HUB.getTabOrder(jax)
455 });
456 if (jax.CHTML.display) {
457 //
458 // Zoom box requires an outer container to get the positioning right.
459 //
460 var NODE = CHTML.Element("mjx-chtml",{className:"MJXc-display",isMathJax:false});
461 NODE.appendChild(node); node = NODE;
462 }
463 if (HUB.Browser.noContextMenu) {
464 node.ontouchstart = TOUCH.start;
465 node.ontouchend = TOUCH.end;
466 }
467 //
468 node.className += " MJXc-processing";
469 script.parentNode.insertBefore(node,script);
470 //
471 // Add test nodes for determining scales and linebreak widths
472 //
473 test = this.TestSpan.cloneNode(true);
474 test.className += " mjx-test-" + (jax.CHTML.display ? "display" : "inline");
475 script.parentNode.insertBefore(test,script);
476 }
477 //
478 // Determine the scaling factors for each script
479 // (this only requires one reflow rather than a reflow for each equation)
480 //
481 for (i = 0; i < m; i++) {
482 script = scripts[i]; if (!script.parentNode) continue;
483 test = script.previousSibling;
484 jax = script.MathJax.elementJax; if (!jax) continue;
485 em = CHTML.getFontSize(test);
486 ex = test.childNodes[1].offsetHeight/60;
487 cwidth = Math.max(0, jax.CHTML.display ? test.lastChild.offsetWidth - 1:
488 test.lastChild.offsetLeft - test.firstChild.offsetLeft - 2);
489 if (ex === 0 || ex === "NaN") {
490 ex = this.defaultEx;
491 cwidth = this.defaultWidth;
492 }
493 if (cwidth === 0 && !jax.CHTML.display) cwidth = this.defaultWidth;
494 if (relwidth) maxwidth = cwidth;
495 scale = (this.config.matchFontHeight ? ex/this.TEX.x_height/em : 1);
496 scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale)*this.config.scale);
497 jax.CHTML.scale = scale/100; jax.CHTML.fontSize = scale+"%";
498 jax.CHTML.outerEm = em; jax.CHTML.em = this.em = em * scale/100;
499 jax.CHTML.ex = ex; jax.CHTML.cwidth = cwidth/this.em;
500 jax.CHTML.lineWidth = (linebreak ? this.length2em(width,maxwidth/this.em,1) : maxwidth);
501 }
502 //
503 // Remove the test spans used for determining scales and linebreak widths
504 //
505 for (i = 0; i < m; i++) {
506 script = scripts[i]; if (!script.parentNode) continue;
507 jax = script.MathJax.elementJax; if (!jax) continue;
508 script.parentNode.removeChild(script.previousSibling);
509 if (script.MathJax.preview) script.MathJax.preview.style.display = "";
510 }
511 state.CHTMLeqn = state.CHTMLlast = 0; state.CHTMLi = -1;
512 state.CHTMLchunk = this.config.EqnChunk;
513 state.CHTMLdelay = false;
514 },
515
516 /********************************************/
517
518 Translate: function (script,state) {
519 if (!script.parentNode) return;
520
521 //
522 // If we are supposed to do a chunk delay, do it
523 //
524 if (state.CHTMLdelay) {
525 state.CHTMLdelay = false;
526 HUB.RestartAfter(MathJax.Callback.Delay(this.config.EqnChunkDelay));
527 }
528
529 //
530 // Get the data about the math
531 //
532 var jax = script.MathJax.elementJax, math = jax.root,
533 node = document.getElementById(jax.inputID+"-Frame");
534 if (!node) return;
535 this.getMetrics(jax);
536 if (this.scale !== 1) node.style.fontSize = jax.CHTML.fontSize;
537 //
538 // Typeset the math
539 //
540 this.initCHTML(math,node);
541 this.savePreview(script);
542 this.CHTMLnode = node;
543 try {
544 math.setTeXclass();
545 math.toCommonHTML(node);
546 } catch (err) {
547 while (node.firstChild) node.removeChild(node.firstChild);
548 delete this.CHTMLnode;
549 this.restorePreview(script);
550 throw err;
551 }
552 delete this.CHTMLnode;
553 this.restorePreview(script);
554 //
555 // Put it in place, and remove the processing marker
556 //
557 if (jax.CHTML.display) node = node.parentNode;
558 node.className = node.className.replace(/ [^ ]+$/,"");
559 //
560 // Hide the math and don't let its preview be removed
561 //
562 node.className += " MJXc-processed";
563 if (script.MathJax.preview) {
564 jax.CHTML.preview = script.MathJax.preview;
565 delete script.MathJax.preview;
566 }
567 //
568 // Check if we should show this chunk of equations
569 //
570 state.CHTMLeqn += (state.i - state.CHTMLi); state.CHTMLi = state.i;
571 if (state.CHTMLeqn >= state.CHTMLlast + state.CHTMLchunk) {
572 this.postTranslate(state);
573 state.CHTMLchunk = Math.floor(state.CHTMLchunk*this.config.EqnChunkFactor);
574 state.CHTMLdelay = true; // delay if there are more scripts
575 }
576 },
577
578 initCHTML: function (math,node) {},
579
580 //
581 // MathML previews can contain the same ID's as the HTML output,
582 // which confuses CHTMLnodeElement(), so remove the preview temporarily
583 // and restore it after typesetting the math.
584 //
585 savePreview: function (script) {
586 var preview = script.MathJax.preview;
587 if (preview && preview.parentNode) {
588 script.MathJax.tmpPreview = document.createElement("span");
589 preview.parentNode.replaceChild(script.MathJax.tmpPreview,preview);
590 }
591 },
592 restorePreview: function (script) {
593 var tmpPreview = script.MathJax.tmpPreview;
594 if (tmpPreview) {
595 tmpPreview.parentNode.replaceChild(script.MathJax.preview,tmpPreview);
596 delete script.MathJax.tmpPreview;
597 }
598 },
599 //
600 // Get the jax metric information
601 //
602 getMetrics: function(jax) {
603 var data = jax.CHTML;
604 this.jax = jax;
605 this.em = data.em;
606 this.outerEm = data.outerEm;
607 this.scale = data.scale;
608 this.cwidth = data.cwidth;
609 this.linebreakWidth = data.lineWidth;
610 },
611
612 /********************************************/
613
614 postTranslate: function (state) {
615 var scripts = state.jax[this.id];
616 //
617 // Reveal this chunk of math
618 //
619 for (var i = state.CHTMLlast, m = state.CHTMLeqn; i < m; i++) {
620 var script = scripts[i];
621 if (script && script.MathJax.elementJax) {
622 //
623 // Remove the processed marker
624 //
625 script.previousSibling.className = script.previousSibling.className.replace(/ [^ ]+$/,"");
626 var data = script.MathJax.elementJax.CHTML;
627 //
628 // Remove the preview, if any
629 //
630 if (data.preview) {
631 data.preview.innerHTML = "";
632 script.MathJax.preview = data.preview;
633 delete data.preview;
634 }
635 }
636 }
637 //
638 // Save our place so we know what is revealed
639 //
640 state.CHTMLlast = state.CHTMLeqn;
641 },
642
643 /********************************************/
644
645 getJaxFromMath: function (math) {
646 if (math.parentNode.className.match(/MJXc-display/)) math = math.parentNode;
647 do {math = math.nextSibling} while (math && math.nodeName.toLowerCase() !== "script");
648 return HUB.getJaxFor(math);
649 },
650 getHoverSpan: function (jax,math) {return jax.root.CHTMLnodeElement()},
651 getHoverBBox: function (jax,span,math) {
652 var bbox = jax.root.CHTML, em = jax.CHTML.outerEm;
653 var BBOX = {w:bbox.w*em, h:bbox.h*em, d:bbox.d*em};
654 if (bbox.width) {BBOX.width = bbox.width}
655 return BBOX;
656 },
657
658 Zoom: function (jax,span,math,Mw,Mh) {
659 //
660 // Re-render at larger size
661 //
662 this.getMetrics(jax);
663 var node = CHTML.addElement(span,"mjx-chtml",{style:{"font-size":Math.floor(CHTML.scale*100)+"%"},isMathJax:false});
664 CHTML.CHTMLnode = node;
665 this.idPostfix = "-zoom"; jax.root.toCommonHTML(node); this.idPostfix = "";
666 //
667 // Adjust margins to prevent overlaps at the edges
668 //
669 var style = node.style, bbox = jax.root.CHTML;
670 if (bbox.t > bbox.h) style.marginTop = CHTML.Em(bbox.t-bbox.h);
671 if (bbox.b > bbox.d) style.marginBottom = CHTML.Em(bbox.b-bbox.d);
672 if (bbox.l < 0) style.paddingLeft = CHTML.Em(-bbox.l);
673 if (bbox.r > bbox.w) style.marginRight = CHTML.Em(bbox.r-bbox.w);
674 //
675 // Get height and width of zoomed math and original math
676 //
677 style.position = "absolute";
678 var zW = node.offsetWidth, zH = node.offsetHeight,
679 mH = math.firstChild.offsetHeight, mW = math.firstChild.offsetWidth;
680 node.style.position = "";
681 //
682 return {Y:-EVENT.getBBox(span).h, mW:mW, mH:mH, zW:zW, zH:zH};
683 },
684
685 Remove: function (jax) {
686 var node = document.getElementById(jax.inputID+"-Frame");
687 if (node && jax.CHTML.display) node = node.parentNode;
688 if (node) node.parentNode.removeChild(node);
689 delete jax.CHTML;
690 },
691
692 /********************************************/
693
694 ID: 0, idPostfix: "",
695 GetID: function () {this.ID++; return this.ID},
696
697 /********************************************/
698
699 MATHSPACE: {
700 veryverythinmathspace: 1/18,
701 verythinmathspace: 2/18,
702 thinmathspace: 3/18,
703 mediummathspace: 4/18,
704 thickmathspace: 5/18,
705 verythickmathspace: 6/18,
706 veryverythickmathspace: 7/18,
707 negativeveryverythinmathspace: -1/18,
708 negativeverythinmathspace: -2/18,
709 negativethinmathspace: -3/18,
710 negativemediummathspace: -4/18,
711 negativethickmathspace: -5/18,
712 negativeverythickmathspace: -6/18,
713 negativeveryverythickmathspace: -7/18,
714
715 thin: .04,
716 medium: .06,
717 thick: .1,
718
719 infinity: BIGDIMEN
720 },
721 SPACECLASS: {
722 thinmathspace: "MJXc-space1",
723 mediummathspace: "MJXc-space2",
724 thickmathspace: "MJXc-space3"
725 },
726 pxPerInch: 96,
727 em: 16,
728
729 maxStretchyParts: 1000, // limit the number of parts allowed for
730 // stretchy operators. See issue 366.
731
732 FONTDEF: {},
733 TEXDEF: {
734 x_height: .442,
735 quad: 1,
736 num1: .676508,
737 num2: .393732,
738 num3: .44373,
739 denom1: .685951,
740 denom2: .344841,
741 sup1: .412892,
742 sup2: .362892,
743 sup3: .288888,
744 sub1: .15,
745 sub2: .247217,
746 sup_drop: .386108,
747 sub_drop: .05,
748 delim1: 2.39,
749 delim2: 1.0,
750 axis_height: .25,
751 rule_thickness: .06,
752 big_op_spacing1: .111111,
753 big_op_spacing2: .166666,
754 big_op_spacing3: .2,
755 big_op_spacing4: .45, //.6, // better spacing for under arrows and braces
756 big_op_spacing5: .1,
757
758 surd_height: .075,
759
760 scriptspace: .05,
761 nulldelimiterspace: .12,
762 delimiterfactor: 901,
763 delimitershortfall: .3,
764
765 min_rule_thickness: 1.25 // in pixels
766 },
767
768 /********************************************************/
769
770 //
771 // True if text holds a single (unicode) glyph
772 //
773 isChar: function (text) {
774 if (text.length === 1) return true;
775 if (text.length !== 2) return false;
776 var n = text.charCodeAt(0);
777 return (n >= 0xD800 && n < 0xDBFF);
778 },
779 //
780 // Get a unicode character by number (even when it takes two character)
781 //
782 unicodeChar: function (n) {
783 if (n < 0xFFFF) return String.fromCharCode(n);
784 n -= 0x10000;
785 return String.fromCharCode((n>>10)+0xD800) + String.fromCharCode((n&0x3FF)+0xDC00);
786 },
787 //
788 // Get the unicode number of a (possibly multi-character) string
789 //
790 getUnicode: function (string) {
791 var n = string.text.charCodeAt(string.i); string.i++;
792 if (n >= 0xD800 && n < 0xDBFF) {
793 n = (((n-0xD800)<<10)+(string.text.charCodeAt(string.i)-0xDC00))+0x10000;
794 string.i++;
795 }
796 return n;
797 },
798 //
799 // Get the list of actions for a given character in a given variant
800 // (processing remaps, multi-character results, and so on). Results are
801 // cached so that future lookups for the same variant/n pair will not
802 // require looking through the data again.
803 //
804 getCharList: function (variant,n) {
805 var id, M, cache = variant.cache, nn = n;
806 if (cache[n]) return cache[n];
807 if (n > 0xFFFF && this.FONTDATA.RemapPlane1) {
808 var nv = this.FONTDATA.RemapPlane1(n,variant);
809 n = nv.n; variant = nv.variant;
810 }
811 var RANGES = this.FONTDATA.RANGES, VARIANT = this.FONTDATA.VARIANT;
812 if (n >= RANGES[0].low && n <= RANGES[RANGES.length-1].high) {
813 for (id = 0, M = RANGES.length; id < M; id++) {
814 if (RANGES[id].name === "alpha" && variant.noLowerCase) continue;
815 var N = variant["offset"+RANGES[id].offset];
816 if (N && n >= RANGES[id].low && n <= RANGES[id].high) {
817 if (RANGES[id].remap && RANGES[id].remap[n]) {
818 n = N + RANGES[id].remap[n];
819 } else {
820 n = n - RANGES[id].low + N;
821 if (RANGES[id].add) {n += RANGES[id].add}
822 }
823 if (variant["variant"+RANGES[id].offset])
824 variant = VARIANT[variant["variant"+RANGES[id].offset]];
825 break;
826 }
827 }
828 }
829 cache[nn] = this.remapChar(variant,n,0);
830 return cache[nn];
831 },
832 remapChar: function (variant,n,N) {
833 var list = [], VARIANT = this.FONTDATA.VARIANT;
834 if (variant.remap && variant.remap[n]) {
835 n = variant.remap[n];
836 if (variant.remap.variant) {variant = VARIANT[variant.remap.variant]}
837 } else if (this.FONTDATA.REMAP[n] && !variant.noRemap) {
838 n = this.FONTDATA.REMAP[n];
839 }
840 if (isArray(n)) {
841 if (n[2]) N = MAXREMAP; // stop remapping
842 variant = VARIANT[n[1]]; n = n[0];
843 }
844 if (typeof(n) === "string") {
845 var string = {text:n, i:0, length:n.length};
846 while (string.i < string.length) {
847 n = this.getUnicode(string);
848 var chars = this.getCharList(variant,n);
849 if (chars) list.push.apply(list,chars);
850 }
851 } else {
852 if (variant.cache[n]) {list = variant.cache[n]}
853 else {variant.cache[n] = list = this.lookupChar(variant,n,N)}
854 }
855 return list;
856 },
857 //
858 // After all remapping has been done, look up a character
859 // in the fonts for a given variant, chaining to other
860 // variants as needed. Return an undefined character if
861 // it isn't found in the given variant.
862 //
863 lookupChar: function (variant,n,N) {
864 var VARIANT = variant;
865 while (variant) {
866 for (var i = 0, m = variant.fonts.length; i < m; i++) {
867 var font = this.FONTDATA.FONTS[variant.fonts[i]];
868 if (typeof(font) === "string") this.loadFont(font);
869 var C = font[n];
870 if (C) {
871 this.fixChar(C,n);
872 if (C[5].space) return [{type:"space", w:C[2], font:font}];
873 return [{type:"char", font:font, n:n}];
874 } else if (font.Extra) {
875 this.findBlock(font,n);
876 }
877 }
878 variant = this.FONTDATA.VARIANT[variant.chain];
879 if (variant && variant.remap && variant.remap[n] && N++ < MAXREMAP) {
880 return this.remapChar(variant,n,N);
881 }
882 }
883 return [this.unknownChar(VARIANT,n)];
884 },
885 fixChar: function (C,n) {
886 if (C.length === 5) C[5] = {};
887 if (C.c == null) {
888 C[0] /= 1000; C[1] /= 1000; C[2] /= 1000; C[3] /= 1000; C[4] /= 1000;
889 C.c = this.unicodeChar(n);
890 }
891 return C;
892 },
893 findBlock: function (font,n) {
894 var extra = font.Extra, name = font.file, file;
895 for (var i = 0, m = extra.length; i < m; i++) {
896 if (typeof(extra[i]) === "number") {
897 if (n === extra[i]) {file = name; break}
898 } else {
899 if (n < extra[i][0]) return;
900 if (n <= extra[i][1]) {file = name; break}
901 }
902 }
903 //
904 // Currently this only loads one extra file, but that
905 // might need to be expanded in the future.
906 //
907 if (file) {delete font.Extra; this.loadFont(name)}
908 },
909 //
910 // Create a fake font entry for an unknown character.
911 //
912 unknownChar: function (variant,n) {
913 HUB.signal.Post(["CommonHTML Jax - unknown char",n,variant]);
914 var id = ""; if (variant.bold) id += "B"; if (variant.italic) id += "I";
915 var unknown = this.FONTDATA.UNKNOWN[id||"R"]; // cache of previously measured characters
916 if (!unknown[n]) this.getUnknownChar(unknown,n);
917 return {type:"unknown", n:n, font:unknown};
918 },
919 getUnknownChar: function (unknown,n) {
920 var c = this.unicodeChar(n);
921 var HDW = this.getHDW(c,unknown.className);
922 // ### FIXME: provide a means of setting the height and depth for individual characters
923 unknown[n] = [.8,.2,HDW.w,0,HDW.w,{a:Math.max(0,(HDW.h-HDW.d)/2), h:HDW.h, d:HDW.d}];
924 unknown[n].c = c;
925 },
926 styledText: function (variant,text) {
927 HUB.signal.Post(["CommonHTML Jax - styled text",text,variant]);
928 var style = variant.style;
929 var id = "_"+(style["font-family"]||variant.className||"");
930 if (style["font-weight"]) id += "_"+style["font-weight"];
931 if (style["font-style"]) id += "_"+style["font-style"];
932 if (!this.STYLEDTEXT) this.STYLEDTEXT = {};
933 if (!this.STYLEDTEXT[id]) this.STYLEDTEXT[id] = {className:variant.className||""};
934 var unknown = this.STYLEDTEXT[id];
935 if (!unknown["_"+text]) {
936 var HDW = this.getHDW(text,variant.className||"",style);
937 unknown["_"+text] = [.8,.2,HDW.w,0,HDW.w,{a:Math.max(0,(HDW.h-HDW.d)/2), h:HDW.h, d:HDW.d}];
938 unknown["_"+text].c = text;
939 }
940 return {type:"unknown", n:"_"+text, font:unknown, style:style, rscale:variant.rscale};
941 },
942
943 //
944 // Get the height, depth, and width of a character
945 // (height and depth are of the font, not the character).
946 // WARNING: causes reflow of the page!
947 //
948 getHDW: function (c,name,styles) {
949 var test1 = CHTML.addElement(CHTML.CHTMLnode,"mjx-chartest",{className:name},[["mjx-char",{style:styles},[c]]]);
950 var test2 = CHTML.addElement(CHTML.CHTMLnode,"mjx-chartest",{className:name},[["mjx-char",{style:styles},[c,["mjx-box"]]]]);
951 test1.firstChild.style.fontSize = test2.firstChild.style.fontSize = "";
952 var em = 5*CHTML.em;
953 var H1 = test1.offsetHeight, H2 = test2.offsetHeight, W = test1.offsetWidth;
954 CHTML.CHTMLnode.removeChild(test1);
955 CHTML.CHTMLnode.removeChild(test2);
956 if (H2 === 0) {
957 em = 5*CHTML.defaultEm;
958 var test = document.body.appendChild(document.createElement("div"));
959 test.appendChild(test1); test.appendChild(test2);
960 H1 = test1.offsetHeight, H2 = test2.offsetHeight, W = test1.offsetWidth;
961 document.body.removeChild(test);
962 }
963 var d = (H2-1000)/em, w = W/em, h = H1/em - d;
964 return {h:h, d:d, w:w}
965 },
966
967
968 /********************************************************/
969
970 //
971 // Process a character list into a given node and return
972 // the updated bounding box.
973 //
974 addCharList: function (node,list,bbox) {
975 var state = {text:"", className:null, a:0};
976 for (var i = 0, m = list.length; i < m; i++) {
977 var item = list[i];
978 if (this.charList[item.type]) (this.charList[item.type])(item,node,bbox,state,m);
979 }
980 if (state.text !== "") {
981 if (node.childNodes.length) {
982 this.charList.flushText(node,state);
983 } else {
984 HTML.addText(node,state.text);
985 if (node.className) node.className += " "+state.className;
986 else node.className = state.className;
987 }
988 }
989 bbox.b = (state.flushed ? 0 : bbox.a);
990 },
991 //
992 // The various item types are processed by these
993 // functions.
994 //
995 charList: {
996 //
997 // Character from the known fonts
998 //
999 "char": function (item,node,bbox,state,m) {
1000 var font = item.font, remap = (font.remapCombining||{})[item.n];
1001 if (font.className === state.className) {
1002 remap = null;
1003 } else if (state.className || (remap && state.text !== "")) {
1004 this.flushText(node,state);
1005 }
1006 if (!state.a) state.a = font.centerline/1000;
1007 if (state.a > (bbox.a||0)) bbox.a = state.a;
1008 state.className = font.className;
1009 var C = font[item.n];
1010 if (remap) {
1011 var FONT = font;
1012 if (isArray(remap)) {
1013 FONT = CHTML.FONTDATA.FONTS[remap[1]];
1014 remap = remap[0];
1015 if (typeof(FONT) === 'string') CHTML.loadFont(FONT);
1016 }
1017 if (FONT[item.n]) CHTML.fixChar(FONT[item.n],item.n);
1018 C = CHTML.fixChar(FONT[remap],remap);
1019 state.className = FONT.className;
1020 }
1021 state.text += C.c;
1022 if (bbox.h < C[0]+HFUZZ) bbox.t = bbox.h = C[0]+HFUZZ;
1023 if (bbox.d < C[1]+DFUZZ) bbox.b = bbox.d = C[1]+DFUZZ;
1024 if (bbox.l > bbox.w+C[3]) bbox.l = bbox.w+C[3];
1025 if (bbox.r < bbox.w+C[4]) bbox.r = bbox.w+C[4];
1026 bbox.w += C[2] * (item.rscale||1);
1027 if (m == 1 && font.skew && font.skew[item.n]) bbox.skew = font.skew[item.n];
1028 if (C[5] && C[5].rfix) this.flushText(node,state).style.marginRight = CHTML.Em(C[5].rfix/1000);
1029 if (remap) {
1030 //
1031 // Remap combining characters to non-combining versions since Safari
1032 // handles them differently from everyone else. (#1709)
1033 //
1034 var chr = this.flushText(node,state);
1035 var r = (FONT[item.n]||font[item.n])[4] - (C[4] - C[2]);
1036 chr.style.marginLeft = CHTML.Em(-C[2]-r);
1037 if (r < 0) chr.style.marginRight = CHTML.Em(-r);
1038 }
1039 },
1040 //
1041 // Space characters (not actually in the fonts)
1042 //
1043 space: function (item,node,bbox,state) {
1044 if (item.w) {
1045 if (state.text === "") state.className = item.font.className;
1046 this.flushText(node,state).style.marginRight = CHTML.Em(item.w);
1047 bbox.w += item.w;
1048 }
1049 },
1050 //
1051 // An unknown character (one not in the font data)
1052 //
1053 unknown: function (item,node,bbox,state) {
1054 (this["char"])(item,node,bbox,state,0);
1055 var C = item.font[item.n];
1056 if (C[5].a) {
1057 state.a = C[5].a;
1058 if (bbox.a == null || state.a > bbox.a) bbox.a = state.a;
1059 }
1060 node = this.flushText(node,state,item.style);
1061 if (C[2] < 3) node.style.width = CHTML.Em(C[2]); // only force width if not too large (#1718)
1062 },
1063 //
1064 // Put the pending text into a box of the class, and
1065 // reset the data about the text.
1066 //
1067 flushText: function (node,state,style) {
1068 node = CHTML.addElement(node,"mjx-charbox",
1069 {className:state.className,style:style},[state.text]);
1070 if (state.a) node.style.paddingBottom = CHTML.Em(state.a);
1071 state.text = ""; state.className = null; state.a = 0; state.flushed = true;
1072 return node;
1073 }
1074 },
1075
1076 //
1077 // Add the given text (in the given variant) into the given node, and
1078 // update the bounding box of the result. Make sure the node's DOM
1079 // bounding box matches the contents.
1080 //
1081 handleText: function (node,text,variant,bbox) {
1082 if (node.childNodes.length === 0) {
1083 CHTML.addElement(node,"mjx-char");
1084 bbox = CHTML.BBOX.empty(bbox);
1085 }
1086 if (typeof(variant) === "string") variant = this.FONTDATA.VARIANT[variant];
1087 if (!variant) variant = this.FONTDATA.VARIANT[MML.VARIANT.NORMAL];
1088 var string = {text:text, i:0, length:text.length}, list = [];
1089 if (variant.style && string.length) {
1090 list.push(this.styledText(variant,text));
1091 } else {
1092 while (string.i < string.length) {
1093 var n = this.getUnicode(string);
1094 list.push.apply(list,this.getCharList(variant,n));
1095 }
1096 }
1097 if (list.length) this.addCharList(node.firstChild,list,bbox);
1098 bbox.clean();
1099 if (bbox.d < 0) {bbox.D = bbox.d; bbox.d = 0}
1100 if (bbox.h - bbox.a) node.firstChild.style[bbox.h - bbox.a < 0 ? "marginTop" : "paddingTop"] = this.EmRounded(bbox.h-bbox.a);
1101 if (bbox.d > -bbox.b) node.firstChild.style.paddingBottom = this.EmRounded(bbox.d+bbox.b);
1102 return bbox;
1103 },
1104
1105 /********************************************************/
1106
1107 createDelimiter: function (node,code,HW,BBOX,font) {
1108 if (!code) {
1109 var bbox = this.BBOX.zero();
1110 bbox.w = bbox.r = this.TEX.nulldelimiterspace;
1111 CHTML.addElement(node,"mjx-box",{style:{width:bbox.w}});
1112 return bbox;
1113 }
1114 if (!(HW instanceof Array)) HW = [HW,HW];
1115 var hw = HW[1]; HW = HW[0];
1116 var delim = {alias: code};
1117 while (delim.alias) {
1118 code = delim.alias; delim = this.FONTDATA.DELIMITERS[code];
1119 if (!delim) {delim = {HW: [0,this.FONTDATA.VARIANT[MML.VARIANT.NORMAL]]}}
1120 }
1121 if (delim.load) HUB.RestartAfter(AJAX.Require(this.fontDir+"/TeX/fontdata-"+delim.load+".js"));
1122 for (var i = 0, m = delim.HW.length; i < m; i++) {
1123 if (delim.HW[i][0] >= HW-.01 || (i == m-1 && !delim.stretch)) {
1124 if (delim.HW[i][3]) code = delim.HW[i][3];
1125 bbox = this.createChar(node,[code,delim.HW[i][1]],(delim.HW[i][2]||1),font);
1126 bbox.offset = .6 * bbox.w;
1127 if (BBOX) {bbox.scale = BBOX.scale; BBOX.rscale = BBOX.rscale}
1128 return bbox;
1129 }
1130 }
1131 if (!delim.stretch) return bbox;
1132 return this["extendDelimiter"+delim.dir](node,hw,delim.stretch,BBOX,font);
1133 },
1134 extendDelimiterV: function (node,H,delim,BBOX,font) {
1135 node = CHTML.addElement(node,"mjx-delim-v"); var tmp = CHTML.Element("span");
1136 var top, bot, mid, ext, tbox, bbox, mbox, ebox, k = 1, c;
1137 tbox = this.createChar(tmp,(delim.top||delim.ext),1,font); top = tmp.removeChild(tmp.firstChild);
1138 bbox = this.createChar(tmp,(delim.bot||delim.ext),1,font); bot = tmp.removeChild(tmp.firstChild);
1139 mbox = ebox = CHTML.BBOX.zero();
1140 var h = tbox.h + tbox.d + bbox.h + bbox.d - EFUZZ;
1141 node.appendChild(top);
1142 if (delim.mid) {
1143 mbox = this.createChar(tmp,delim.mid,1,font); mid = tmp.removeChild(tmp.firstChild);
1144 h += mbox.h + mbox.d; k = 2;
1145 }
1146 if (delim.min && H < h*delim.min) H = h*delim.min;
1147 if (H > h) {
1148 ebox = this.createChar(tmp,delim.ext,1,font); ext = tmp.removeChild(tmp.firstChild);
1149 var eH = ebox.h + ebox.d, eh = eH - EFUZZ;
1150 var n = Math.min(Math.ceil((H-h)/(k*eh)),this.maxStretchyParts);
1151 if (delim.fullExtenders) H = n*k*eh + h; else eh = (H-h)/(k*n);
1152 c = ebox.d + ebox.a - eH/2; // for centering of extenders
1153 ext.style.margin = ext.style.padding = "";
1154 ext.style.lineHeight = CHTML.Em(eh);
1155 ext.style.marginBottom = CHTML.Em(c-EFUZZ/2/k);
1156 ext.style.marginTop = CHTML.Em(-c-EFUZZ/2/k);
1157 var TEXT = ext.textContent, text = "\n"+TEXT;
1158 while (--n > 0) TEXT += text;
1159 ext.textContent = TEXT;
1160 node.appendChild(ext);
1161 if (delim.mid) {
1162 node.appendChild(mid);
1163 node.appendChild(ext.cloneNode(true));
1164 }
1165 } else {
1166 c = (H-h-EFUZZ) / k;
1167 top.style.marginBottom = CHTML.Em(c+parseFloat(top.style.marginBottom||"0"));
1168 if (delim.mid) node.appendChild(mid);
1169 bot.style.marginTop = CHTML.Em(c+parseFloat(bot.style.marginTop||"0"));
1170 }
1171 node.appendChild(bot);
1172 var vbox = CHTML.BBOX({
1173 w: Math.max(tbox.w,ebox.w,bbox.w,mbox.w),
1174 l: Math.min(tbox.l,ebox.l,bbox.l,mbox.l),
1175 r: Math.max(tbox.r,ebox.r,bbox.r,mbox.r),
1176 h: H-bbox.d, d: bbox.d, t: H-bbox.d, b: bbox.d
1177 });
1178 vbox.offset = .5 * vbox.w;
1179 if (BBOX) {vbox.scale = BBOX.scale; vbox.rscale = BBOX.rscale}
1180 return vbox;
1181 },
1182 extendDelimiterH: function (node,W,delim,BBOX,font) {
1183 node = CHTML.addElement(node,"mjx-delim-h"); var tmp = CHTML.Element("span");
1184 var left, right, mid, ext, ext2, lbox, rbox, mbox, ebox, k = 1;
1185 lbox = this.createChar(tmp,(delim.left||delim.rep),1,font); left = tmp.removeChild(tmp.firstChild);
1186 rbox = this.createChar(tmp,(delim.right||delim.rep),1,font); right = tmp.removeChild(tmp.firstChild);
1187 ebox = this.createChar(tmp,delim.rep,1,font); ext = tmp.removeChild(tmp.firstChild);
1188 left.style.marginLeft = CHTML.Em(-lbox.l);
1189 right.style.marginRight = CHTML.Em(rbox.r-rbox.w);
1190 node.appendChild(left);
1191 var hbox = CHTML.BBOX.zero();
1192 hbox.h = Math.max(lbox.h,rbox.h,ebox.h);
1193 hbox.d = Math.max(lbox.D||lbox.d,rbox.D||rbox.d,ebox.D||ebox.d);
1194 var w = (lbox.r - lbox.l) + (rbox.r - rbox.l) - EFUZZ;
1195 if (delim.mid) {
1196 mbox = this.createChar(tmp,delim.mid,1,font);
1197 mid = tmp.removeChild(tmp.firstChild);
1198 mid.style.marginleft = CHTML.Em(-mbox.l); mid.style.marginRight = CHTML.Em(mbox.r-mbox.w);
1199 w += mbox.r - mbox.l + EFUZZ; k = 2;
1200 if (mbox.h > hbox.h) hbox.h = mbox.h;
1201 if (mbox.d > hbox.d) hbox.d = mbox.d;
1202 }
1203 if (delim.min && W < w*delim.min) W = w*delim.min;
1204 hbox.w = hbox.r = W;
1205 if (W > w) {
1206 var eW = ebox.r-ebox.l, ew = eW - EFUZZ;
1207 var n = Math.min(Math.ceil((W-w)/(k*ew)),this.maxStretchyParts);
1208 if (delim.fullExtenders) W = n*k*ew + w; else ew = (W-w)/(k*n);
1209 var c = (eW - ew + EFUZZ/k) / 2; // for centering of extenders
1210 ext.style.marginLeft = CHTML.Em(-ebox.l-c);
1211 ext.style.marginRight = CHTML.Em(ebox.r-ebox.w+c);
1212 ext.style.letterSpacing = CHTML.Em(-(ebox.w-ew));
1213 left.style.marginRight = CHTML.Em(lbox.r-lbox.w);
1214 right.style.marginleft = CHTML.Em(-rbox.l);
1215 var TEXT = ext.textContent, text = TEXT;
1216 while (--n > 0) TEXT += text;
1217 ext.textContent = TEXT;
1218 node.appendChild(ext);
1219 if (delim.mid) {
1220 node.appendChild(mid);
1221 ext2 = node.appendChild(ext.cloneNode(true));
1222 }
1223 } else {
1224 c = (W-w-EFUZZ/k) / 2;
1225 left.style.marginRight = CHTML.Em(lbox.r-lbox.w+c);
1226 if (delim.mid) node.appendChild(mid);
1227 right.style.marginLeft = CHTML.Em(-rbox.l+c);
1228 }
1229 node.appendChild(right);
1230 this.adjustHeights([left,ext,mid,ext2,right],[lbox,ebox,mbox,ebox,rbox],hbox);
1231 if (BBOX) {hbox.scale = BBOX.scale; hbox.rscale = BBOX.rscale}
1232 return hbox;
1233 },
1234 adjustHeights: function (nodes,box,bbox) {
1235 //
1236 // To get alignment right in horizontal delimiters, we force all
1237 // the elements to the same height and depth
1238 //
1239 var T = bbox.h, B = bbox.d;
1240 if (bbox.d < 0) {B = -bbox.d; bbox.D = bbox.d; bbox.d = 0}
1241 for (var i = 0, m = nodes.length; i < m; i++) if (nodes[i]) {
1242 nodes[i].style.paddingTop = CHTML.Em(T-box[i].a);
1243 nodes[i].style.paddingBottom = CHTML.Em(B+box[i].a);
1244 nodes[i].style.marginTop = nodes[i].style.marginBottom = 0;
1245 }
1246 },
1247 createChar: function (node,data,scale,font) {
1248 // ### FIXME: handle cache better (by data[1] and font)
1249 var text = "", variant = {fonts: [data[1]], noRemap:true, cache:{}};
1250 if (font && font === MML.VARIANT.BOLD && this.FONTDATA.FONTS[data[1]+"-Bold"])
1251 variant.fonts = [data[1]+"-Bold",data[1]];
1252 if (typeof(data[1]) !== "string") variant = data[1];
1253 if (data[0] instanceof Array) {
1254 for (var i = 0, m = data[0].length; i < m; i++) text += String.fromCharCode(data[0][i]);
1255 } else text = String.fromCharCode(data[0]);
1256 if (data[4]) scale *= data[4];
1257 var bbox = this.handleText(node,text,variant), style = node.firstChild.style;
1258 if (scale !== 1) style.fontSize = this.Percent(scale);
1259 if (data[2]) { // x offset
1260 style.paddingLeft = this.Em(data[2]);
1261 bbox.w += data[2]; bbox.r += data[2];
1262 }
1263 if (data[3]) { // y offset
1264 style.verticalAlign = this.Em(data[3]);
1265 bbox.h += data[3]; if (bbox.h < 0) bbox.h = 0;
1266 }
1267 if (data[5]) { // extra height
1268 style.marginTop = this.Em(data[5]);
1269 bbox.h += data[5]; bbox.t += data[5];
1270 }
1271 if (data[6]) { // extra depth
1272 style.marginBottom = this.Em(data[6]);
1273 bbox.d += data[6]; bbox.b += data[6];
1274 }
1275 return bbox;
1276 },
1277
1278 /********************************************************/
1279
1280 //
1281 // ### FIXME: Handle mu's
1282 //
1283 length2em: function (length,size,scale) {
1284 if (typeof(length) !== "string") length = length.toString();
1285 if (length === "") return "";
1286 if (length === MML.SIZE.NORMAL) return 1;
1287 if (length === MML.SIZE.BIG) return 2;
1288 if (length === MML.SIZE.SMALL) return .71;
1289 if (this.MATHSPACE[length]) return this.MATHSPACE[length];
1290 var match = length.match(/^\s*([-+]?(?:\.\d+|\d+(?:\.\d*)?))?(pt|em|ex|mu|px|pc|in|mm|cm|%)?/);
1291 var m = parseFloat(match[1]||"1"), unit = match[2];
1292 if (size == null) size = 1; if (!scale) scale = 1;
1293 scale = 1 /this.em / scale;
1294 if (unit === "em") return m;
1295 if (unit === "ex") return m * this.TEX.x_height;
1296 if (unit === "%") return m / 100 * size;
1297 if (unit === "px") return m * scale;
1298 if (unit === "pt") return m / 10; // 10 pt to an em
1299 if (unit === "pc") return m * 1.2; // 12 pt to a pc
1300 scale *= this.pxPerInch;
1301 if (unit === "in") return m * scale;
1302 if (unit === "cm") return m * scale / 2.54; // 2.54 cm to an inch
1303 if (unit === "mm") return m * scale / 25.4; // 10 mm to a cm
1304 if (unit === "mu") return m / 18; // 18mu to an em for the scriptlevel
1305 return m*size; // relative to given size (or 1em as default)
1306 },
1307 thickness2em: function (length,scale) {
1308 var thick = CHTML.TEX.rule_thickness/(scale||1);
1309 if (length === MML.LINETHICKNESS.MEDIUM) return thick;
1310 if (length === MML.LINETHICKNESS.THIN) return .67*thick;
1311 if (length === MML.LINETHICKNESS.THICK) return 1.67*thick;
1312 return this.length2em(length,thick,scale);
1313 },
1314
1315 Em: function (m) {
1316 if (Math.abs(m) < .001) return "0";
1317 return (m.toFixed(3).replace(/\.?0+$/,""))+"em";
1318 },
1319 EmRounded: function (m) {
1320 m = (Math.round(m*CHTML.em)+.05)/CHTML.em;
1321 if (Math.abs(m) < .0006) {return "0em"}
1322 return m.toFixed(3).replace(/\.?0+$/,"") + "em";
1323 },
1324 unEm: function (m) {
1325 return parseFloat(m);
1326 },
1327 Px: function (m,M) {
1328 m *= this.em;
1329 if (M && m < M) m = M;
1330 if (Math.abs(m) < .1) return "0";
1331 return m.toFixed(1).replace(/\.0$/,"")+"px";
1332 },
1333
1334 Percent: function (m) {
1335 return (100*m).toFixed(1).replace(/\.?0+$/,"") + "%";
1336 },
1337
1338 Transform: function (node,trans,origin) {
1339 var style = node.style;
1340 style.transform = style.WebkitTransform = style.MozTransform = style["-ms-transform"] = trans;
1341 if (origin)
1342 style.transformOrigin = style.WebkitTransformOrigin =
1343 style.MozTransformOrigin = style["-ms-transform-origin"] = origin;
1344 },
1345
1346 /********************************************************/
1347
1348 arrayEntry: function (a,i) {return a[Math.max(0,Math.min(i,a.length-1))]},
1349
1350 //
1351 // Styles to be removed from style="..." attributes
1352 //
1353 removeStyles: ["fontSize","fontFamily","fontWeight","fontStyle","fontVariant","font"]
1354
1355 });
1356
1357 /**********************************************************/
1358
1359 CHTML.BBOX = MathJax.Object.Subclass({
1360 Init: function (def) {
1361 for (var id in def) {
1362 if (def.hasOwnProperty(id)) this[id] = def[id];
1363 }
1364 },
1365 clean: function () {
1366 if (this.h === -BIGDIMEN) this.h = 0;
1367 if (this.d === -BIGDIMEN) this.d = 0;
1368 if (this.l === BIGDIMEN) this.l = 0;
1369 if (this.r === -BIGDIMEN) this.r = 0;
1370 if (this.t === -BIGDIMEN) this.t = 0;
1371 if (this.b === -BIGDIMEN) this.b = 0;
1372 if (this.D && this.d > 0) delete this.D;
1373 },
1374 rescale: function (scale) {
1375 this.w *= scale; this.h *= scale; this.d *= scale;
1376 this.l *= scale; this.r *= scale; this.t *= scale; this.b *= scale;
1377 if (this.L) this.L *= scale;
1378 if (this.R) this.R *= scale;
1379 if (this.D) this.D *= scale;
1380 },
1381 combine: function (cbox,x,y) {
1382 cbox.X = x; cbox.Y = y; // save for use with line breaking
1383 var scale = cbox.rscale;
1384 if (x + scale*cbox.r > this.r) this.r = x + scale*cbox.r;
1385 if (x + scale*cbox.l < this.l) this.l = x + scale*cbox.l;
1386 if (x + scale*(cbox.w+(cbox.L||0)+(cbox.R||0)) > this.w)
1387 this.w = x + scale*(cbox.w + (cbox.L||0) + (cbox.R||0));
1388 if (y + scale*cbox.h > this.h) this.h = y + scale*cbox.h;
1389 if (cbox.D && (this.D == null || scale*cbox.D - y > this.D) && scale*cbox.D > this.d) this.D = scale*cbox.D - y;
1390 else if (cbox.D == null && this.D) delete this.D;
1391 if (scale*cbox.d - y > this.d) this.d = scale*cbox.d - y;
1392 if (y + scale*cbox.t > this.t) this.t = y + scale*cbox.t;
1393 if (scale*cbox.b - y > this.b) this.b = scale*cbox.b - y;
1394 },
1395 append: function (cbox) {
1396 var scale = cbox.rscale; var x = this.w;
1397 if (x + scale*cbox.r > this.r) this.r = x + scale*cbox.r;
1398 if (x + scale*cbox.l < this.l) this.l = x + scale*cbox.l;
1399 this.w += scale*(cbox.w+(cbox.L||0)+(cbox.R||0)) ;
1400 if (scale*cbox.h > this.h) this.h = scale*cbox.h;
1401 if (cbox.D && (this.D == null || scale*cbox.D > this.D) && scale*cbox.D > this.d) this.D = scale*cbox.D;
1402 else if (cbox.D == null && this.D) delete this.D;
1403 if (scale*cbox.d > this.d) this.d = scale*cbox.d;
1404 if (scale*cbox.t > this.t) this.t = scale*cbox.t;
1405 if (scale*cbox.b > this.b) this.b = scale*cbox.b;
1406 },
1407 updateFrom: function (cbox) {
1408 this.h = cbox.h; this.d = cbox.d; this.w = cbox.w; this.r = cbox.r; this.l = cbox.l;
1409 this.t = cbox.t; this.b = cbox.b;
1410 if (cbox.pwidth) this.pwidth = cbox.pwidth;
1411 if (cbox.D) this.D = cbox.D; else delete this.D;
1412 },
1413 adjust: function (m,x,X,M) {
1414 this[x] += CHTML.length2em(m,1,this.scale);
1415 if (M == null) {
1416 if (this[x] > this[X]) this[X] = this[x];
1417 } else {
1418 if (this[X] < M) this[X] = M;
1419 }
1420 }
1421 },{
1422 zero: function () {
1423 return CHTML.BBOX({h:0, d:0, w:0, l:0, r:0, t:0, b:0, scale:1, rscale:1});
1424 },
1425 empty: function (bbox) {
1426 if (!bbox) bbox = CHTML.BBOX.zero();
1427 bbox.h = bbox.d = bbox.r = bbox.t = bbox.b = -BIGDIMEN;
1428 bbox.w = 0; bbox.l = BIGDIMEN;
1429 delete bbox.pwidth;
1430 return bbox;
1431 },
1432 //
1433 // CSS styles that affect BBOXes
1434 //
1435 styleAdjust: [
1436 ["borderTopWidth","h","t"],
1437 ["borderRightWidth","w","r"],
1438 ["borderBottomWidth","d","b"],
1439 ["borderLeftWidth","w","l",0],
1440 ["paddingTop","h","t"],
1441 ["paddingRight","w","r"],
1442 ["paddingBottom","d","b"],
1443 ["paddingLeft","w","l",0],
1444 ]
1445 });
1446
1447 /**********************************************************/
1448
1449 MathJax.Hub.Register.StartupHook("mml Jax Ready",function () {
1450 MML = MathJax.ElementJax.mml;
1451
1452 /********************************************************/
1453
1454 MML.mbase.Augment({
1455 toCommonHTML: function (node,options) {
1456 return this.CHTMLdefaultNode(node,options);
1457 },
1458 CHTMLmultiline: function () {MML.mbase.CHTMLautoloadFile("multiline")},
1459
1460 CHTMLdefaultNode: function (node,options) {
1461 if (!options) options = {};
1462 node = this.CHTMLcreateNode(node); this.CHTML = CHTML.BBOX.empty();
1463 this.CHTMLhandleStyle(node);
1464 if (this.isToken) this.CHTMLgetVariant();
1465 this.CHTMLhandleScale(node);
1466 var m = Math.max((options.minChildren||0),this.data.length);
1467 for (var i = 0; i < m; i++) this.CHTMLaddChild(node,i,options);
1468 if (!options.noBBox) this.CHTML.clean();
1469 this.CHTMLhandleSpace(node);
1470 this.CHTMLhandleBBox(node);
1471 this.CHTMLhandleColor(node);
1472 return node;
1473 },
1474 CHTMLaddChild: function (node,i,options) {
1475 var child = this.data[i], cnode;
1476 var type = options.childNodes;
1477 if (type instanceof Array) type = type[i]||"span";
1478 if (child) {
1479 if (type) node = CHTML.addElement(node,type);
1480 cnode = child.toCommonHTML(node,options.childOptions);
1481 if (type && child.CHTML.rscale !== 1) {
1482 // move scale factor to outer container (which seems to be more accurate)
1483 node.style.fontSize = node.firstChild.style.fontSize;
1484 node.firstChild.style.fontSize = "";
1485 }
1486 if (!options.noBBox) {
1487 var bbox = this.CHTML, cbox = child.CHTML;
1488 bbox.append(cbox);
1489 if (this.data.length === 1) {
1490 if (cbox.ic) bbox.ic = cbox.ic;
1491 if (cbox.skew) bbox.skew = cbox.skew;
1492 } else {
1493 delete bbox.ic;
1494 delete bbox.skew;
1495 }
1496 if (cbox.pwidth) bbox.pwidth = cbox.pwidth;
1497 }
1498 } else if (options.forceChild) {
1499 cnode = CHTML.addElement(node,(type||"mjx-box"));
1500 }
1501 return cnode;
1502 },
1503
1504 CHTMLchildNode: function (node,i) {
1505 node = node.childNodes[i];
1506 if (node.nodeName.toLowerCase() === "a") node = node.firstChild;
1507 return node;
1508 },
1509 CHTMLcoreNode: function (node) {
1510 if (this.inferRow && this.data[0]) return this.data[0].CHTMLcoreNode(node.firstChild);
1511 return this.CHTMLchildNode(node,this.CoreIndex());
1512 },
1513
1514 CHTMLstretchChildV: function (i,H,D) {
1515 var data = this.data[i];
1516 if (data) {
1517 var bbox = this.CHTML, dbox = data.CHTML;
1518 if (dbox.stretch || (dbox.stretch == null && data.CHTMLcanStretch("Vertical",H,D))) {
1519 var w = dbox.w;
1520 dbox = data.CHTMLstretchV(H,D);
1521 bbox.w += dbox.w - w;
1522 if (bbox.w > bbox.r) bbox.r = bbox.w;
1523 if (dbox.h > bbox.h) bbox.h = dbox.h;
1524 if (dbox.d > bbox.d) bbox.d = dbox.d;
1525 if (dbox.t > bbox.t) bbox.t = dbox.t;
1526 if (dbox.b > bbox.b) bbox.b = dbox.b;
1527 }
1528 }
1529 },
1530 CHTMLstretchChildH: function (i,W,node) {
1531 var data = this.data[i];
1532 if (data) {
1533 var bbox = this.CHTML, dbox = data.CHTML;
1534 if (dbox.stretch || (dbox.stretch == null && data.CHTMLcanStretch("Horizontal",W))) {
1535 var w = dbox.w;
1536 dbox = data.CHTMLstretchH(this.CHTMLchildNode(node,i),W);
1537 bbox.w += dbox.w - w;
1538 if (bbox.w > bbox.r) bbox.r = bbox.w;
1539 if (dbox.h > bbox.h) bbox.h = dbox.h;
1540 if (dbox.d > bbox.d) bbox.d = dbox.d;
1541 if (dbox.t > bbox.t) bbox.t = dbox.t;
1542 if (dbox.b > bbox.b) bbox.b = dbox.b;
1543 }
1544 }
1545 },
1546 CHTMLupdateFrom: function (bbox) {
1547 this.CHTML.updateFrom(bbox);
1548 if (this.inferRow) this.data[0].CHTML.updateFrom(bbox);
1549 },
1550
1551 CHTMLcanStretch: function (direction,H,D) {
1552 var stretch = false;
1553 if (this.isEmbellished()) {
1554 var core = this.Core();
1555 if (core && core !== this) stretch = core.CHTMLcanStretch(direction,H,D);
1556 }
1557 this.CHTML.stretch = stretch;
1558 return stretch;
1559 },
1560 CHTMLstretchV: function (h,d) {
1561 this.CHTMLupdateFrom(this.Core().CHTMLstretchV(h,d));
1562 return this.CHTML;
1563 },
1564 CHTMLstretchH: function (node,w) {
1565 this.CHTMLupdateFrom(this.CHTMLstretchCoreH(node,w));
1566 return this.CHTML;
1567 },
1568 CHTMLstretchCoreH: function (node,w) {
1569 return this.Core().CHTMLstretchH(this.CHTMLcoreNode(node),w);
1570 },
1571
1572 CHTMLcreateNode: function (node) {
1573 if (!this.CHTML) this.CHTML = {};
1574 this.CHTML = CHTML.BBOX.zero();
1575 if (this.href) node = CHTML.addElement(node,"a",{href:this.href, isMathJax:true});
1576 if (!this.CHTMLnodeID) this.CHTMLnodeID = CHTML.GetID();
1577 var id = (this.id || "MJXc-Node-"+this.CHTMLnodeID)+CHTML.idPostfix;
1578 return this.CHTMLhandleAttributes(CHTML.addElement(node,"mjx-"+this.type,{id:id}));
1579 },
1580 CHTMLnodeElement: function () {
1581 if (!this.CHTMLnodeID) {return null}
1582 return document.getElementById((this.id||"MJXc-Node-"+this.CHTMLnodeID)+CHTML.idPostfix);
1583 },
1584
1585 CHTMLlength2em: function (length,size) {
1586 return CHTML.length2em(length,size,this.CHTML.scale);
1587 },
1588
1589 CHTMLhandleAttributes: function (node) {
1590 if (this["class"]) {
1591 if (node.className) node.className += " "+this["class"];
1592 else node.className = this["class"];
1593 }
1594 //
1595 // Copy RDFa, aria, and other tags from the MathML to the CHTML
1596 // output nodes. Don't copy those in the MML.nocopyAttributes list,
1597 // the ignoreMMLattributes configuration list, or anything that
1598 // already exists as a property of the node (e.g., no "onlick", etc.)
1599 // If a name in the ignoreMMLattributes object is set to false, then
1600 // the attribute WILL be copied.
1601 //
1602 if (this.attrNames) {
1603 var copy = this.attrNames, skip = MML.nocopyAttributes, ignore = HUB.config.ignoreMMLattributes;
1604 var defaults = (this.type === "mstyle" ? MML.math.prototype.defaults : this.defaults);
1605 for (var i = 0, m = copy.length; i < m; i++) {
1606 var id = copy[i];
1607 if (ignore[id] == false || (!skip[id] && !ignore[id] &&
1608 defaults[id] == null && typeof(node[id]) === "undefined")) {
1609 node.setAttribute(id,this.attr[id])
1610 }
1611 }
1612 }
1613 return node;
1614 },
1615
1616 CHTMLhandleScale: function (node) {
1617 var scale = 1, parent = this.parent, pscale = (parent ? parent.CHTML.scale : 1);
1618 var values = this.getValues("scriptlevel","fontsize");
1619 values.mathsize = this.Get("mathsize",null,!this.isToken);
1620 if (values.scriptlevel !== 0) {
1621 if (values.scriptlevel > 2) values.scriptlevel = 2;
1622 scale = Math.pow(this.Get("scriptsizemultiplier"),values.scriptlevel);
1623 values.scriptminsize = CHTML.length2em(this.Get("scriptminsize"),.8,1);
1624 if (scale < values.scriptminsize) scale = values.scriptminsize;
1625 }
1626 if (this.removedStyles && this.removedStyles.fontSize && !values.fontsize)
1627 values.fontsize = this.removedStyles.fontSize;
1628 if (values.fontsize && !this.mathsize) values.mathsize = values.fontsize;
1629 if (values.mathsize !== 1) scale *= CHTML.length2em(values.mathsize,1,1);
1630 var variant = this.CHTMLvariant;
1631 if (variant && variant.style && variant.style["font-family"])
1632 scale *= (CHTML.config.scale/100)/CHTML.scale;
1633 this.CHTML.scale = scale; pscale = this.CHTML.rscale = scale/pscale;
1634 if (Math.abs(pscale-1) < .001) pscale = 1;
1635 if (node && pscale !== 1) node.style.fontSize = CHTML.Percent(pscale);
1636 return scale;
1637 },
1638
1639 CHTMLhandleStyle: function (node) {
1640 if (!this.style) return;
1641 var style = node.style;
1642 style.cssText = this.style; this.removedStyles = {};
1643 for (var i = 0, m = CHTML.removeStyles.length; i < m; i++) {
1644 var id = CHTML.removeStyles[i];
1645 if (style[id]) {
1646 this.removedStyles[id] = style[id];
1647 style[id] = "";
1648 }
1649 }
1650 },
1651
1652 CHTMLhandleBBox: function (node) {
1653 var BBOX = this.CHTML, style = node.style;
1654 if (this.data.length === 1 && (this.data[0].CHTML||{}).pwidth) {
1655 BBOX.pwidth = this.data[0].CHTML.pwidth;
1656 BBOX.mwidth = this.data[0].CHTML.mwidth;
1657 style.width = "100%";
1658 } else if (BBOX.pwidth) {
1659 BBOX.mwidth = CHTML.Em(BBOX.w);
1660 style.width = "100%";
1661 } else if (BBOX.w < 0) {
1662 style.width = "0px";
1663 style.marginRight = CHTML.Em(BBOX.w);
1664 }
1665 if (!this.style) return;
1666 // ### FIXME: adjust for width, height, vertical-align?
1667 for (var i = 0, m = CHTML.BBOX.styleAdjust.length; i < m; i++) {
1668 var data = CHTML.BBOX.styleAdjust[i];
1669 if (data && style[data[0]]) BBOX.adjust(style[data[0]],data[1],data[2],data[3]);
1670 }
1671 },
1672
1673 CHTMLhandleColor: function (node) {
1674 if (this.mathcolor) {node.style.color = this.mathcolor}
1675 else if (this.color) {node.style.color = this.color}
1676 if (this.mathbackground) {node.style.backgroundColor = this.mathbackground}
1677 else if (this.background) {node.style.backgroundColor = this.background}
1678 },
1679
1680 CHTMLhandleSpace: function (node) {
1681 if (!this.useMMLspacing) {
1682 var space = this.texSpacing();
1683 if (space !== "") {
1684 this.CHTML.L = this.CHTMLlength2em(space);
1685 node.className += " "+CHTML.SPACECLASS[space];
1686 }
1687 }
1688 },
1689
1690 CHTMLhandleText: function (node,text,variant) {
1691 if (node.firstChild && !this.CHTML) this.CHTML = CHTML.BBOX.empty();
1692 this.CHTML = CHTML.handleText(node,text,variant,this.CHTML);
1693 },
1694
1695 CHTMLgetVariant: function () {
1696 var values = this.getValues("mathvariant","fontfamily","fontweight","fontstyle"), style;
1697 values.hasVariant = this.Get("mathvariant",true); // null if not explicitly specified
1698 if (this.removedStyles) {
1699 style = this.removedStyles;
1700 if (style.fontFamily) values.family = style.fontFamily;
1701 if (style.fontWeight) values.weight = style.fontWeight;
1702 if (style.fontStyle) values.style = style.fontStyle;
1703 }
1704 if (!values.hasVariant) {
1705 if (values.fontfamily) values.family = values.fontfamily;
1706 if (values.fontweight) values.weight = values.fontweight;
1707 if (values.fontstyle) values.style = values.fontstyle;
1708 }
1709 if (values.weight && values.weight.match(/^\d+$/))
1710 values.weight = (parseInt(values.weight) > 600 ? "bold" : "normal");
1711 var variant = values.mathvariant; if (this.variantForm) variant = "-TeX-variant";
1712 if (values.family && !values.hasVariant) {
1713 if (!values.weight && values.mathvariant.match(/bold/)) values.weight = "bold";
1714 if (!values.style && values.mathvariant.match(/italic/)) values.style = "italic";
1715 this.CHTMLvariant = {fonts:[], noRemap:true, cache:{}, style: {
1716 "font-family":values.family, "font-weight":values.weight||"normal", "font-style":values.style||"normal"
1717 }};
1718 return;
1719 }
1720 if (values.weight === "bold") {
1721 variant = {
1722 normal:MML.VARIANT.BOLD, italic:MML.VARIANT.BOLDITALIC,
1723 fraktur:MML.VARIANT.BOLDFRAKTUR, script:MML.VARIANT.BOLDSCRIPT,
1724 "sans-serif":MML.VARIANT.BOLDSANSSERIF,
1725 "sans-serif-italic":MML.VARIANT.SANSSERIFBOLDITALIC
1726 }[variant]||variant;
1727 } else if (values.weight === "normal") {
1728 variant = {
1729 bold:MML.VARIANT.normal, "bold-italic":MML.VARIANT.ITALIC,
1730 "bold-fraktur":MML.VARIANT.FRAKTUR, "bold-script":MML.VARIANT.SCRIPT,
1731 "bold-sans-serif":MML.VARIANT.SANSSERIF,
1732 "sans-serif-bold-italic":MML.VARIANT.SANSSERIFITALIC
1733 }[variant]||variant;
1734 }
1735 if (values.style === "italic") {
1736 variant = {
1737 normal:MML.VARIANT.ITALIC, bold:MML.VARIANT.BOLDITALIC,
1738 "sans-serif":MML.VARIANT.SANSSERIFITALIC,
1739 "bold-sans-serif":MML.VARIANT.SANSSERIFBOLDITALIC
1740 }[variant]||variant;
1741 } else if (values.style === "normal") {
1742 variant = {
1743 italic:MML.VARIANT.NORMAL, "bold-italic":MML.VARIANT.BOLD,
1744 "sans-serif-italic":MML.VARIANT.SANSSERIF,
1745 "sans-serif-bold-italic":MML.VARIANT.BOLDSANSSERIF
1746 }[variant]||variant;
1747 }
1748 this.CHTMLvariant = CHTML.FONTDATA.VARIANT[variant] ||
1749 CHTML.FONTDATA.VARIANT[MML.VARIANT.NORMAL];
1750 },
1751
1752 CHTMLbboxFor: function (n) {
1753 if (this.data[n] && this.data[n].CHTML) return this.data[n].CHTML;
1754 return CHTML.BBOX.zero();
1755 },
1756 //
1757 // Debugging function to see if internal BBox matches actual bbox
1758 //
1759 CHTMLdrawBBox: function (node,bbox) {
1760 if (!bbox) bbox = this.CHTML;
1761 var box = CHTML.Element("mjx-box",
1762 {style:{opacity:.25,"margin-left":CHTML.Em(-(bbox.w+(bbox.R||0)))}},[
1763 ["mjx-box",{style:{
1764 height:CHTML.Em(bbox.h),width:CHTML.Em(bbox.w),
1765 "background-color":"red"
1766 }}],
1767 ["mjx-box",{style:{
1768 height:CHTML.Em(bbox.d),width:CHTML.Em(bbox.w),
1769 "margin-left":CHTML.Em(-bbox.w),"vertical-align":CHTML.Em(-bbox.d),
1770 "background-color":"green"
1771 }}]
1772 ]);
1773 if (node.nextSibling) {node.parentNode.insertBefore(box,node.nextSibling)}
1774 else {node.parentNode.appendChild(box)}
1775 },
1776
1777 CHTMLnotEmpty: function (mml) {
1778 while (mml && mml.data.length < 2 && (mml.type === "mrow" || mml.type === "texatom"))
1779 mml = mml.data[0];
1780 return !!mml;
1781 }
1782
1783 },{
1784 //
1785 // Autoload files based on node type or file name
1786 //
1787 CHTMLautoload: function () {
1788 this.constructor.Augment({toCommonHTML: MML.mbase.CHTMLautoloadFail});
1789 var file = CHTML.autoloadDir+"/"+this.type+".js";
1790 HUB.RestartAfter(AJAX.Require(file));
1791 },
1792 CHTMLautoloadFail: function () {
1793 throw Error("CommonHTML can't autoload '"+ this.type + "'");
1794 },
1795 CHTMLautoloadList: {},
1796 CHTMLautoloadFile: function (name) {
1797 if (MML.mbase.CHTMLautoloadList.hasOwnProperty(name)) {
1798 throw Error("CommonHTML can't autoload file '"+name+"'");
1799 }
1800 MML.mbase.CHTMLautoloadList[name] = true;
1801 var file = CHTML.autoloadDir+"/"+name+".js";
1802 HUB.RestartAfter(AJAX.Require(file));
1803 },
1804 //
1805 // For use with embellished operators
1806 //
1807 CHTMLstretchV: function (h,d) {
1808 this.Core().CHTMLstretchV(h,d);
1809 this.toCommonHTML(this.CHTMLnodeElement(),{stretch:true});
1810 return this.CHTML;
1811 },
1812 CHTMLstretchH: function (node,w) {
1813 this.CHTMLupdateFrom(this.CHTMLstretchCoreH(node,w));
1814 this.toCommonHTML(node,{stretch:true});
1815 return this.CHTML;
1816 }
1817 });
1818
1819 /********************************************************/
1820
1821 MML.chars.Augment({
1822 toCommonHTML: function (node,options) {
1823 this.CHTML = null;
1824 if (options == null) options = {};
1825 var text = this.toString();
1826 if (options.remap) text = options.remap(text,options.remapchars);
1827 this.CHTMLhandleText(node,text,options.variant||this.parent.CHTMLvariant);
1828 }
1829 });
1830 MML.entity.Augment({
1831 toCommonHTML: function (node,options) {
1832 if (options == null) options = {};
1833 var text = this.toString();
1834 if (options.remapchars) text = options.remap(text,options.remapchars);
1835 this.CHTMLhandleText(node,text,options.variant||this.parent.CHTMLvariant);
1836 }
1837 });
1838
1839 /********************************************************/
1840
1841 MML.math.Augment({
1842 toCommonHTML: function (node) {
1843 node = this.CHTMLdefaultNode(node);
1844 if (this.CHTML.w < 0) {
1845 node.parentNode.style.width = "0px";
1846 node.parentNode.style.marginRight = CHTML.Em(this.CHTML.w);
1847 }
1848 var alttext = this.Get("alttext");
1849 if (alttext && !node.getAttribute("aria-label")) node.setAttribute("aria-label",alttext);
1850 if (this.CHTML.pwidth) {
1851 node.parentNode.style.minWidth = this.CHTML.mwidth||CHTML.Em(this.CHTML.w);
1852 node.parentNode.className = "mjx-full-width "+node.parentNode.className;
1853 node.style.width = this.CHTML.pwidth;
1854 } else if (!this.isMultiline && this.Get("display") === "block") {
1855 var values = this.getValues("indentalignfirst","indentshiftfirst","indentalign","indentshift");
1856 if (values.indentalignfirst !== MML.INDENTALIGN.INDENTALIGN) values.indentalign = values.indentalignfirst;
1857 if (values.indentalign === MML.INDENTALIGN.AUTO) values.indentalign = CONFIG.displayAlign;
1858 if (values.indentshiftfirst !== MML.INDENTSHIFT.INDENTSHIFT) values.indentshift = values.indentshiftfirst;
1859 if (values.indentshift === "auto") values.indentshift = "0";
1860 var shift = this.CHTMLlength2em(values.indentshift,CHTML.cwidth);
1861 if (CONFIG.displayIndent !== "0") {
1862 var indent = this.CHTMLlength2em(CONFIG.displayIndent,CHTML.cwidth);
1863 shift += (values.indentalign === MML.INDENTALIGN.RIGHT ? -indent : indent);
1864 }
1865 var styles = node.parentNode.parentNode.style;
1866 node.parentNode.style.textAlign = styles.textAlign = values.indentalign;
1867 // ### FIXME: make percentage widths respond to changes in container
1868 if (shift) {
1869 if (values.indentalign === 'right') node.style.marginRight = CHTML.Em(-shift);
1870 shift *= CHTML.em/CHTML.outerEm;
1871 HUB.Insert(styles,({
1872 left: {textIndent: CHTML.Em(shift)},
1873 right: {display: 'flex', flexDirection: 'row-reverse'},
1874 center: {textIndent: CHTML.Em(2*shift)}
1875 })[values.indentalign]);
1876 }
1877 }
1878 return node;
1879 }
1880 });
1881
1882 /********************************************************/
1883
1884 MML.mi.Augment({
1885 toCommonHTML: function (node) {
1886 node = this.CHTMLdefaultNode(node);
1887 var bbox = this.CHTML, text = this.data.join("");
1888 if (bbox.skew != null && !CHTML.isChar(text)) delete bbox.skew;
1889 if (bbox.r > bbox.w && CHTML.isChar(text) && !this.CHTMLvariant.noIC) {
1890 bbox.ic = bbox.r - bbox.w; bbox.w = bbox.r;
1891 node.lastChild.style.paddingRight = CHTML.Em(bbox.ic);
1892 }
1893 return node;
1894 }
1895 });
1896
1897 /********************************************************/
1898
1899 MML.mn.Augment({
1900 CHTMLremapMinus: function (text) {return text.replace(/^-/,"\u2212")},
1901 toCommonHTML: function (node) {
1902 node = this.CHTMLdefaultNode(node,{childOptions:{remap:this.CHTMLremapMinus}});
1903 var bbox = this.CHTML, text = this.data.join("");
1904 if (bbox.skew != null && !CHTML.isChar(text)) delete bbox.skew;
1905 if (bbox.r > bbox.w && CHTML.isChar(text) && !this.CHTMLvariant.noIC) {
1906 bbox.ic = bbox.r - bbox.w; bbox.w = bbox.r;
1907 node.lastChild.style.paddingRight = CHTML.Em(bbox.ic);
1908 }
1909 return node;
1910 }
1911 });
1912
1913 /********************************************************/
1914
1915 MML.mo.Augment({
1916 toCommonHTML: function (node) {
1917 node = this.CHTMLcreateNode(node);
1918 this.CHTMLhandleStyle(node);
1919 this.CHTMLgetVariant();
1920 this.CHTMLhandleScale(node);
1921 CHTML.BBOX.empty(this.CHTML);
1922
1923 var values = this.getValues("displaystyle","largeop");
1924 values.variant = this.CHTMLvariant;
1925 values.text = this.data.join("");
1926 if (values.text == "") {
1927 if (this.fence) node.style.width = CHTML.Em(CHTML.TEX.nulldelimiterspace);
1928 } else {
1929 this.CHTMLadjustAccent(values);
1930 this.CHTMLadjustVariant(values);
1931
1932 for (var i = 0, m = this.data.length; i < m; i++) {
1933 this.CHTMLaddChild(node,i,{childOptions:{
1934 variant: values.mathvariant,
1935 remap: this.remap,
1936 remapchars: values.remapchars
1937 }});
1938 }
1939 if (!CHTML.isChar(values.text)) delete this.CHTML.skew;
1940 else if (this.CHTML.w === 0 && this.CHTML.l < 0) this.CHTMLfixCombiningChar(node);
1941 if (values.largeop) this.CHTMLcenterOp(node);
1942 }
1943
1944 this.CHTML.clean();
1945 this.CHTMLhandleBBox(node);
1946 this.CHTMLhandleSpace(node);
1947 this.CHTMLhandleColor(node);
1948
1949 return node;
1950 },
1951 CHTMLhandleSpace: function (node) {
1952 if (this.hasMMLspacing()) {
1953 var values = this.getValues("scriptlevel","lspace","rspace");
1954 values.lspace = Math.max(0,this.CHTMLlength2em(values.lspace));
1955 values.rspace = Math.max(0,this.CHTMLlength2em(values.rspace));
1956 if (values.scriptlevel > 0) {
1957 if (!this.hasValue("lspace")) values.lspace = .15;
1958 if (!this.hasValue("rspace")) values.rspace = .15;
1959 }
1960 var core = this, parent = this.Parent();
1961 while (parent && parent.isEmbellished() && parent.Core() === core)
1962 {core = parent; parent = parent.Parent(); node = core.CHTMLnodeElement()}
1963 if (values.lspace) node.style.paddingLeft = CHTML.Em(values.lspace);
1964 if (values.rspace) node.style.paddingRight = CHTML.Em(values.rspace);
1965 this.CHTML.L = values.lspace; this.CHTML.R = values.rspace;
1966 } else {
1967 this.SUPER(arguments).CHTMLhandleSpace.apply(this,arguments);
1968 }
1969 },
1970 CHTMLadjustAccent: function (data) {
1971 var parent = this.CoreParent(); data.parent = parent;
1972 if (CHTML.isChar(data.text) && parent && parent.isa(MML.munderover)) {
1973 var over = parent.data[parent.over], under = parent.data[parent.under];
1974 if (over && this === over.CoreMO() && parent.Get("accent")) {
1975 data.remapchars = CHTML.FONTDATA.REMAPACCENT;
1976 } else if (under && this === under.CoreMO() && parent.Get("accentunder")) {
1977 data.remapchars = CHTML.FONTDATA.REMAPACCENTUNDER;
1978 }
1979 }
1980 },
1981 CHTMLadjustVariant: function (data) {
1982 var parent = data.parent,
1983 isScript = (parent && parent.isa(MML.msubsup) && this !== parent.data[parent.base]);
1984 if (data.largeop) data.mathvariant = (data.displaystyle ? "-largeOp" : "-smallOp");
1985 if (isScript) {
1986 data.remapchars = this.remapChars;
1987 if (data.text.match(/['`"\u00B4\u2032-\u2037\u2057]/))
1988 data.mathvariant = "-TeX-variant"; // ### FIXME: handle other fonts
1989 }
1990 },
1991 CHTMLfixCombiningChar: function (node) {
1992 //
1993 // IE doesn't display combining chararacters unless they combine with
1994 // something, so put them over a space and remove the space's width
1995 //
1996 node = node.firstChild;
1997 var space = CHTML.Element("mjx-box",{style:{width:".25em","margin-left":"-.25em"}});
1998 node.insertBefore(space,node.firstChild);
1999 },
2000 CHTMLcenterOp: function (node) {
2001 var bbox = this.CHTML;
2002 var p = (bbox.h - bbox.d)/2 - CHTML.TEX.axis_height;
2003 if (Math.abs(p) > .001) node.style.verticalAlign = CHTML.Em(-p);
2004 bbox.h -= p; bbox.d += p;
2005 if (bbox.r > bbox.w) {
2006 bbox.ic = bbox.r - bbox.w; bbox.w = bbox.r;
2007 node.style.paddingRight = CHTML.Em(bbox.ic);
2008 }
2009 },
2010 CHTMLcanStretch: function (direction,H,D) {
2011 if (!this.Get("stretchy")) return false;
2012 var c = this.data.join(""); if (!CHTML.isChar(c)) return false;
2013 var values = {text: c};
2014 this.CHTMLadjustAccent(values);
2015 if (values.remapchars) c = values.remapchars[c]||c;
2016 c = CHTML.FONTDATA.DELIMITERS[c.charCodeAt(0)];
2017 var stretch = (c && c.dir === direction.substr(0,1));
2018 if (stretch) {
2019 stretch = (this.CHTML.h !== H || this.CHTML.d !== D ||
2020 !!this.Get("minsize",true) || !!this.Get("maxsize",true));
2021 if (stretch) this.CHTML.stretch = true;
2022 }
2023 return stretch;
2024 },
2025 CHTMLstretchV: function (h,d) {
2026 var node = this.CHTMLnodeElement(), bbox = this.CHTML;
2027 var values = this.getValues("symmetric","maxsize","minsize");
2028 //
2029 // Determine the height needed
2030 //
2031 var H, a = CHTML.TEX.axis_height;
2032 if (values.symmetric) {H = 2*Math.max(h-a,d+a)} else {H = h + d}
2033 values.maxsize = this.CHTMLlength2em(values.maxsize,bbox.h+bbox.d);
2034 values.minsize = this.CHTMLlength2em(values.minsize,bbox.h+bbox.d);
2035 H = Math.max(values.minsize,Math.min(values.maxsize,H));
2036 //
2037 // If we are not already stretched to this height
2038 //
2039 if (H !== bbox.sH) {
2040 //
2041 // Get a delimiter of the proper height and save the height
2042 //
2043 if (H != values.minsize)
2044 {H = [Math.max(H*CHTML.TEX.delimiterfactor/1000,H-CHTML.TEX.delimitershortfall),H]}
2045 while (node.firstChild) node.removeChild(node.firstChild);
2046 this.CHTML = bbox = CHTML.createDelimiter(node,this.data.join("").charCodeAt(0),H,bbox);
2047 bbox.sH = (H instanceof Array ? H[1] : H);
2048 //
2049 // Reposition as needed
2050 //
2051 if (values.symmetric) {H = (bbox.h + bbox.d)/2 + a}
2052 else {H = (bbox.h + bbox.d) * h/(h + d)}
2053 H -= bbox.h;
2054 if (Math.abs(H) > .05) {
2055 node.style.verticalAlign = CHTML.Em(H);
2056 bbox.h += H; bbox.d -= H; bbox.t += H; bbox.b -= H;
2057 }
2058 }
2059 return this.CHTML;
2060 },
2061 CHTMLstretchH: function (node,W) {
2062 var bbox = this.CHTML;
2063 var values = this.getValues("maxsize","minsize","mathvariant","fontweight");
2064 if ((values.fontweight === "bold" || (this.removedStyles||{}).fontWeight === "bold" ||
2065 parseInt(values.fontweight) >= 600) && !this.Get("mathvariant",true))
2066 values.mathvariant = MML.VARIANT.BOLD;
2067 values.maxsize = this.CHTMLlength2em(values.maxsize,bbox.w);
2068 values.minsize = this.CHTMLlength2em(values.minsize,bbox.w);
2069 W = Math.max(values.minsize,Math.min(values.maxsize,W));
2070 if (W !== bbox.sW) {
2071 while (node.firstChild) node.removeChild(node.firstChild);
2072 this.CHTML = bbox = CHTML.createDelimiter(node,this.data.join("").charCodeAt(0),W,bbox,values.mathvariant);
2073 bbox.sW = W;
2074 }
2075 return this.CHTML;
2076 }
2077
2078 });
2079
2080 /********************************************************/
2081
2082 MML.mtext.Augment({
2083 CHTMLgetVariant: function () {
2084 if (CHTML.config.mtextFontInherit || this.Parent().type === "merror") {
2085 var scale = (CHTML.config.scale/100)/CHTML.scale;
2086 var variant = {cache:{}, fonts:[], className:"MJXc-font-inherit", rscale:scale,
2087 style:{"font-size":CHTML.Percent(scale)}};
2088 var name = this.Get("mathvariant");
2089 if (name.match(/bold/)) variant.style["font-weight"] = "bold";
2090 if (name.match(/italic|-tex-mathit/)) variant.style["font-style"] = "italic";
2091 if (name === "monospace") variant.className += " MJXc-monospace-font";
2092 if (name === "double-struck") variant.className += " MJXc-double-struck-font";
2093 if (name.match(/fraktur/)) variant.className += " MJXc-fraktur-font";
2094 if (name.match(/sans-serif/)) variant.className += " MJXc-sans-serif-font";
2095 if (name.match(/script/)) variant.className += " MJXc-script-font";
2096 this.CHTMLvariant = variant;
2097 } else {
2098 this.SUPER(arguments).CHTMLgetVariant.call(this);
2099 }
2100 }
2101 });
2102
2103 /********************************************************/
2104
2105 MML.merror.Augment({
2106 toCommonHTML: function (node) {
2107 node = this.CHTMLdefaultNode(node);
2108 var bbox = this.CHTML;
2109 //
2110 // Adjust for font-size: 90%
2111 //
2112 bbox.rescale(.9);
2113 //
2114 // Adjust for padding and border
2115 //
2116 bbox.h += 3/CHTML.em; if (bbox.h > bbox.t) bbox.t = bbox.h;
2117 bbox.d += 3/CHTML.em; if (bbox.d > bbox.b) bbox.b = bbox.d;
2118 bbox.w += 8/CHTML.em; bbox.r = bbox.w; bbox.l = 0;
2119 return node;
2120 }
2121 });
2122
2123 /********************************************************/
2124
2125 MML.mspace.Augment({
2126 toCommonHTML: function (node) {
2127 node = this.CHTMLcreateNode(node);
2128 this.CHTMLhandleStyle(node);
2129 this.CHTMLhandleScale(node);
2130 var values = this.getValues("height","depth","width");
2131 var w = this.CHTMLlength2em(values.width),
2132 h = this.CHTMLlength2em(values.height),
2133 d = this.CHTMLlength2em(values.depth);
2134 var bbox = this.CHTML;
2135 bbox.w = bbox.r = w; bbox.h = bbox.t = h; bbox.d = bbox.b = d; bbox.l = 0;
2136 if (w < 0) {node.style.marginRight = CHTML.Em(w); w = 0}
2137 node.style.width = CHTML.Em(w);
2138 node.style.height = CHTML.Em(Math.max(0,h+d));
2139 if (d) node.style.verticalAlign = CHTML.Em(-d);
2140 this.CHTMLhandleBBox(node);
2141 this.CHTMLhandleColor(node);
2142 return node;
2143 }
2144 });
2145
2146 /********************************************************/
2147
2148 MML.mpadded.Augment({
2149 toCommonHTML: function (node,options) {
2150 var child;
2151 if (options && options.stretch) {
2152 node = node.firstChild; child = node.firstChild;
2153 } else {
2154 node = this.CHTMLdefaultNode(node,{childNodes:"mjx-box", forceChild:true});
2155 child = node.firstChild; node = CHTML.addElement(node,"mjx-block");
2156 node.appendChild(child); CHTML.addElement(node,"mjx-strut"); // force proper alignment of short heights
2157 }
2158 var cbox = this.CHTMLbboxFor(0);
2159 var values = this.getValues("width","height","depth","lspace","voffset");
2160 var x = 0, y = 0, w = cbox.w, h = cbox.h, d = cbox.d;
2161 child.style.width = 0; child.style.margin = CHTML.Em(-h)+" 0 "+CHTML.Em(-d);
2162 if (values.width !== "") w = this.CHTMLdimen(values.width,"w",w,0);
2163 if (values.height !== "") h = this.CHTMLdimen(values.height,"h",h,0);
2164 if (values.depth !== "") d = this.CHTMLdimen(values.depth,"d",d,0);
2165 if (values.voffset !== "") {
2166 y = this.CHTMLdimen(values.voffset);
2167 if (y) {
2168 child.style.position = "relative";
2169 child.style.top = CHTML.Em(-y);
2170 }
2171 }
2172 if (values.lspace !== "") {
2173 x = this.CHTMLdimen(values.lspace);
2174 if (x) {
2175 child.style.position = "relative";
2176 child.style.left = CHTML.Em(x);
2177 }
2178 }
2179 node.style.width = 0;
2180 node.style.marginTop = CHTML.Em(h-STRUTHEIGHT);
2181 node.style.padding = "0 "+CHTML.Em(w)+" "+CHTML.Em(d)+" 0";
2182 var bbox = CHTML.BBOX({w:w, h:h, d:d, l:0, r:w, t:h, b:d,
2183 scale:this.CHTML.scale, rscale:this.CHTML.rscale});
2184 bbox.combine(cbox,x,y);
2185 bbox.w = w; bbox.h = h; bbox.d = d;
2186 this.CHTML = bbox;
2187 return node.parentNode;
2188 },
2189 CHTMLstretchV: MML.mbase.CHTMLstretchV,
2190 CHTMLstretchH: MML.mbase.CHTMLstretchH,
2191 CHTMLdimen: function (length,d,D,m) {
2192 if (m == null) {m = -BIGDIMEN}
2193 length = String(length);
2194 var match = length.match(/width|height|depth/);
2195 var size = (match ? this.CHTML[match[0].charAt(0)] : (d ? this.CHTML[d] : 0));
2196 var dimen = (this.CHTMLlength2em(length,size)||0);
2197 if (length.match(/^[-+]/) && D != null) dimen += D;
2198 if (m != null) dimen = Math.max(m,dimen);
2199 return dimen;
2200 }
2201 });
2202
2203 /********************************************************/
2204
2205 MML.munderover.Augment({
2206 toCommonHTML: function (node,options) {
2207 var values = this.getValues("displaystyle","accent","accentunder","align");
2208 var base = this.data[this.base];
2209 if (!values.displaystyle && base != null &&
2210 (base.movablelimits || base.CoreMO().Get("movablelimits")))
2211 return MML.msubsup.prototype.toCommonHTML.call(this,node,stretch);
2212 //
2213 // Get the nodes for base and limits
2214 //
2215 var under, over, nodes = [], stretch = false;
2216 if (options && options.stretch) {
2217 if (this.data[this.base]) base = CHTML.getNode(node,"mjx-op");
2218 if (this.data[this.under]) under = CHTML.getNode(node,"mjx-under");
2219 if (this.data[this.over]) over = CHTML.getNode(node,"mjx-over");
2220 nodes[0] = base; nodes[1] = under||over; nodes[2] = over;
2221 stretch = true;
2222 } else {
2223 var types = ["mjx-op","mjx-under","mjx-over"];
2224 if (this.over === 1) types[1] = types[2];
2225 node = this.CHTMLdefaultNode(node,{
2226 childNodes:types, noBBox:true, forceChild:true, minChildren: 2
2227 });
2228 nodes[0] = base = node.removeChild(node.firstChild);
2229 nodes[1] = under = over = node.removeChild(node.firstChild);
2230 if (node.firstChild) nodes[2] = over = node.removeChild(node.firstChild);
2231 }
2232 //
2233 // Get the bounding boxes and the maximum width
2234 //
2235 var boxes = [], W = this.CHTMLgetBBoxes(boxes,nodes,values);
2236 var bbox = boxes[this.base], BBOX = this.CHTML;
2237 BBOX.w = W; BBOX.h = bbox.h; BBOX.d = bbox.d; // modified below
2238 //
2239 // Adjust for bases shorter than the center line (#1657)
2240 // (the center line really depends on the surrounding font, so
2241 // it should be measured along with ems and exs, but currently isn't.
2242 // so this value is an approximation that is reasonable for most fonts.)
2243 //
2244 if (bbox.h < .35) base.style.marginTop = CHTML.Em(bbox.h - .35);
2245 //
2246 // Use a minimum height for accents (#1706)
2247 // (same issues with the center line as above)
2248 //
2249 if (values.accent && bbox.h < CHTML.TEX.x_height) {
2250 BBOX.h += CHTML.TEX.x_height - bbox.h;
2251 base.style.marginTop = CHTML.Em(CHTML.TEX.x_height - Math.max(bbox.h,.35));
2252 bbox.h = CHTML.TEX.x_height;
2253 }
2254 //
2255 // Add over- and under-scripts
2256 //
2257 var stack = base, delta = 0;
2258 if (bbox.ic) {delta = 1.3*bbox.ic + .05} // make faked IC be closer to expeted results
2259 if (this.data[this.over]) stack = this.CHTMLaddOverscript(over,boxes,values,delta,base,stretch);
2260 if (this.data[this.under]) this.CHTMLaddUnderscript(under,boxes,values,delta,node,stack,stretch);
2261 else if (!stretch) node.appendChild(stack);
2262 //
2263 // Handle horizontal positions
2264 //
2265 this.CHTMLplaceBoxes(base,under,over,values,boxes);
2266 return node;
2267 },
2268 //
2269 // Get the bounding boxes for the children, stretch
2270 // any stretchable elements, and compute the maximum width
2271 //
2272 CHTMLgetBBoxes: function (bbox,nodes,values) {
2273 var i, m = this.data.length, scale,
2274 w = -BIGDIMEN, // maximum width of non-stretchy items
2275 W = w; // maximum width of all items
2276 //
2277 // Get the maximum width
2278 //
2279 for (i = 0; i < m; i++) {
2280 bbox[i] = this.CHTMLbboxFor(i); bbox[i].x = bbox[i].y = 0;
2281 if (this.data[i]) bbox[i].stretch = this.data[i].CHTMLcanStretch("Horizontal");
2282 scale = (i === this.base ? 1 : bbox[i].rscale);
2283 if (i !== this.base) {delete bbox[i].L; delete bbox[i].R} // these are overridden by CSS
2284 W = Math.max(W,scale*(bbox[i].w + (bbox[i].L||0) + (bbox[i].R||0)));
2285 if (!bbox[i].stretch && W > w) w = W;
2286 }
2287 if (w === -BIGDIMEN) w = W;
2288 //
2289 // Stretch those parts that need it
2290 //
2291 for (i = 0; i < m; i++) {
2292 if (bbox[i].stretch) {
2293 scale = (i === this.base ? 1 : bbox[i].rscale);
2294 bbox[i] = this.data[i].CHTMLstretchH(nodes[i].firstChild,w/scale);
2295 bbox[i].x = bbox[i].y = 0;
2296 W = Math.max(W,scale*(bbox[i].w + (bbox[i].L||0) + (bbox[i].R||0)));
2297 }
2298 }
2299 if (!bbox[this.base]) bbox[this.base] = CHTML.BBOX.empty();
2300 return W;
2301 },
2302 //
2303 // Add an overscript
2304 //
2305 CHTMLaddOverscript: function (over,boxes,values,delta,base,stretch) {
2306 var BBOX = this.CHTML;
2307 var z1, z2, z3 = CHTML.TEX.big_op_spacing5, k;
2308 var obox = boxes[this.over], bbox = boxes[this.base], scale = obox.rscale;
2309 //
2310 // Put the base and script into a stack
2311 //
2312 if (!stretch) {
2313 var stack = CHTML.Element("mjx-stack");
2314 stack.appendChild(over); stack.appendChild(base);
2315 }
2316 if (obox.D) obox.d = obox.D;
2317 if (obox.d < 0) {
2318 //
2319 // For negative depths, set the height and align to top
2320 // in order to avoid extra baseline space
2321 //
2322 over.firstChild.style.verticalAlign = "top";
2323 over.style.height = CHTML.Em(obox.h+obox.d);
2324 }
2325 //
2326 // Determine the spacing
2327 //
2328 obox.x = 0;
2329 if (values.accent) {
2330 if (obox.w < .001) obox.x += (obox.r - obox.l)/2; // center combining accents
2331 k = CHTML.TEX.rule_thickness; z3 = 0;
2332 if (bbox.skew) {
2333 obox.x += scale*bbox.skew; BBOX.skew = scale*bbox.skew;
2334 if (obox.x+scale*obox.w > BBOX.w) BBOX.skew += (BBOX.w - (obox.x+scale*obox.w))/2;
2335 }
2336 } else {
2337 z1 = CHTML.TEX.big_op_spacing1;
2338 z2 = CHTML.TEX.big_op_spacing3;
2339 k = Math.max(z1,z2-Math.max(0,scale*obox.d));
2340 }
2341 obox.x += delta/2; obox.y = BBOX.h + k + z3 + scale*obox.d;
2342 //
2343 // Position the overscript
2344 //
2345 if (k) over.style.paddingBottom = CHTML.Em(k/scale);
2346 if (z3) over.style.paddingTop = CHTML.Em(z3/scale);
2347 return stack;
2348 },
2349 //
2350 // Add an underscript
2351 //
2352 CHTMLaddUnderscript: function (under,boxes,values,delta,node,stack,stretch) {
2353 var BBOX = this.CHTML;
2354 var z1, z2, z3 = CHTML.TEX.big_op_spacing5, k;
2355 var ubox = boxes[this.under], scale = ubox.rscale;
2356 //
2357 // Create a table for the underscript
2358 //
2359 if (!stretch) {
2360 CHTML.addElement(node,"mjx-itable",{},[
2361 ["mjx-row",{},[["mjx-cell"]]],
2362 ["mjx-row"]
2363 ]);
2364 node.firstChild.firstChild.firstChild.appendChild(stack);
2365 node.firstChild.lastChild.appendChild(under);
2366 }
2367 if (ubox.D) ubox.d = ubox.D;
2368 if (ubox.d < 0) {
2369 //
2370 // For negative depths, set the height and align to top
2371 // in order to avoid extra baseline space
2372 //
2373 under.firstChild.style.verticalAlign = "top";
2374 node.firstChild.style.marginBottom = CHTML.Em(ubox.d);
2375 }
2376 //
2377 // determine the spacing
2378 //
2379 if (values.accentunder) {
2380 k = 2*CHTML.TEX.rule_thickness; z3 = 0;
2381 } else {
2382 z1 = CHTML.TEX.big_op_spacing2;
2383 z2 = CHTML.TEX.big_op_spacing4;
2384 k = Math.max(z1,z2-scale*ubox.h);
2385 }
2386 ubox.x = -delta/2; ubox.y = -(BBOX.d + k + z3 + scale*ubox.h);
2387 //
2388 // Position the underscript
2389 //
2390 if (k) under.style.paddingTop = CHTML.Em(k/scale);
2391 if (z3) under.style.paddingBottom = CHTML.Em(z3/scale);
2392 },
2393 //
2394 // Center boxes horizontally, taking offsets into account
2395 //
2396 CHTMLplaceBoxes: function (base,under,over,values,boxes) {
2397 var W = this.CHTML.w, i, m = boxes.length, scale;
2398 var BBOX = CHTML.BBOX.zero();
2399 BBOX.scale = this.CHTML.scale; BBOX.rscale = this.CHTML.rscale;
2400 boxes[this.base].x = boxes[this.base].y = 0; var dx = BIGDIMEN;
2401 for (i = 0; i < m; i++) {
2402 scale = (i === this.base ? 1 : boxes[i].rscale);
2403 var w = scale*(boxes[i].w + (boxes[i].L||0) + (boxes[i].R||0));
2404 boxes[i].x += {left:0, center:(W-w)/2, right:W-w}[values.align];
2405 if (boxes[i].x < dx) dx = boxes[i].x;
2406 }
2407 for (i = 0; i < m; i++) {
2408 if (this.data[i]) {
2409 scale = (i === this.base ? 1 : boxes[i].rscale);
2410 if (boxes[i].x - dx) {
2411 var node = (i === this.base ? base : i === this.over ? over : under);
2412 node.style.paddingLeft = CHTML.Em((boxes[i].x-dx)/scale);
2413 }
2414 BBOX.combine(boxes[i],boxes[i].x-dx,boxes[i].y);
2415 }
2416 }
2417 this.CHTML = BBOX;
2418 },
2419 CHTMLstretchV: MML.mbase.CHTMLstretchV,
2420 CHTMLstretchH: MML.mbase.CHTMLstretchH,
2421 CHTMLchildNode: function (node,i) {
2422 var types = ["mjx-op","mjx-under","mjx-over"];
2423 if (this.over === 1) types[1] = types[2];
2424 return CHTML.getNode(node,types[i]);
2425 }
2426 });
2427
2428 /********************************************************/
2429
2430 MML.msubsup.Augment({
2431 toCommonHTML: function (node,options) {
2432 var values = this.getValues(
2433 "displaystyle","subscriptshift","superscriptshift","texprimestyle"
2434 );
2435 //
2436 // Get the nodes for base and limits
2437 //
2438 var base, sub, sup;
2439 if (options && options.stretch) {
2440 if (this.data[this.base]) base = CHTML.getNode(node,"mjx-base");
2441 if (this.data[this.sub]) sub = CHTML.getNode(node,"mjx-sub");
2442 if (this.data[this.sup]) sup = CHTML.getNode(node,"mjx-sup");
2443 stack = CHTML.getNode(node,"mjx-stack");
2444 } else {
2445 var types = ["mjx-base","mjx-sub","mjx-sup"];
2446 if (this.sup === 1) types[1] = types[2];
2447 node = this.CHTMLdefaultNode(node,{
2448 childNodes:types, noBBox:true, forceChild:true, minChildren: 3
2449 });
2450 base = node.childNodes[this.base];
2451 sub = node.childNodes[this.sub]; sup = node.childNodes[this.sup];
2452 if (!this.CHTMLnotEmpty(this.data[this.sub])) {node.removeChild(sub); sub = null}
2453 if (!this.CHTMLnotEmpty(this.data[this.sup])) {node.removeChild(sup); sup = null}
2454 if (node.childNodes.length === 3) {
2455 var stack = CHTML.addElement(node,"mjx-stack");
2456 stack.appendChild(sup); stack.appendChild(sub);
2457 }
2458 }
2459 //
2460 // Get the bounding boxes and maximum width of scripts
2461 //
2462 var boxes = [], BBOX = CHTML.BBOX.empty(this.CHTML);
2463 for (var i = 0, m = this.data.length; i < m; i++) boxes[i] = this.CHTMLbboxFor(i);
2464 var bbox = boxes[this.base] || CHTML.BBOX.empty(),
2465 sbox = boxes[this.sub], Sbox = boxes[this.sup];
2466 var sscale = (sub ? sbox.rscale : 1), Sscale = (sup ? Sbox.rscale : 1);
2467 BBOX.combine(bbox,0,0);
2468 //
2469 // Get initial values for parameters
2470 //
2471 var ex = CHTML.TEX.x_height, s = CHTML.TEX.scriptspace;
2472 var q = CHTML.TEX.sup_drop * Sscale, r = CHTML.TEX.sub_drop * sscale;
2473 var u = bbox.h - q, v = bbox.d + r, delta = 0, p;
2474 if (bbox.ic) {
2475 BBOX.w -= bbox.ic; // remove IC (added by mo and mi)
2476 base.style.marginRight = CHTML.Em(-bbox.ic);
2477 delta = 1.3*bbox.ic + .05; // make faked IC be closer to expeted results
2478 }
2479 var bmml = this.data[this.base];
2480 if (bmml) {
2481 if ((bmml.type === "mrow" || bmml.type === "mstyle") && bmml.data.length === 1) bmml = bmml.data[0];
2482 if (bmml.type === "mi" || bmml.type === "mo") {
2483 if (CHTML.isChar(bmml.data.join("")) && bbox.rscale === 1 && !bbox.sH &&
2484 !bmml.Get("largeop")) {u = v = 0}
2485 }
2486 }
2487 values.subscriptshift = (values.subscriptshift === "" ? 0 : this.CHTMLlength2em(values.subscriptshift));
2488 values.superscriptshift = (values.superscriptshift === "" ? 0 : this.CHTMLlength2em(values.superscriptshift));
2489 //
2490 // Add the super- and subscripts
2491 //
2492 var x = BBOX.w; if (sub) sbox.w += s; if (sup) Sbox.w += s;
2493 if (!sup) {
2494 if (sub) {
2495 v = Math.max(v,CHTML.TEX.sub1,sscale*sbox.h-(4/5)*ex,values.subscriptshift);
2496 sub.style.verticalAlign = CHTML.Em(-v/sscale);
2497 sub.style.paddingRight = CHTML.Em(s/sscale);
2498 BBOX.combine(sbox,x,-v);
2499 }
2500 } else {
2501 if (!sub) {
2502 p = CHTML.TEX[(values.displaystyle ? "sup1" : (values.texprimestyle ? "sup3" : "sup2"))];
2503 u = Math.max(u,p,Sscale*Sbox.d+(1/4)*ex,values.superscriptshift);
2504 sup.style.verticalAlign = CHTML.Em(u/Sscale);
2505 sup.style.paddingLeft = CHTML.Em(delta/Sscale);
2506 sup.style.paddingRight = CHTML.Em(s/Sscale);
2507 BBOX.combine(Sbox,x+delta,u);
2508 } else {
2509 v = Math.max(v,CHTML.TEX.sub2);
2510 var t = CHTML.TEX.rule_thickness;
2511 if ((u - Sscale*Sbox.d) - (sscale*sbox.h - v) < 3*t) {
2512 v = 3*t - u + Sscale*Sbox.d + sscale*sbox.h;
2513 q = (4/5)*ex - (u - Sscale*Sbox.d);
2514 if (q > 0) {u += q; v -= q}
2515 }
2516 u = Math.max(u,values.superscriptshift);
2517 v = Math.max(v,values.subscriptshift);
2518 sub.style.paddingRight = CHTML.Em(s/sscale);
2519 sup.style.paddingBottom = CHTML.Em(u/Sscale+v/sscale-Sbox.d-sbox.h/sscale*Sscale);
2520 sup.style.paddingLeft = CHTML.Em(delta/Sscale);
2521 sup.style.paddingRight = CHTML.Em(s/Sscale);
2522 stack.style.verticalAlign = CHTML.Em(-v);
2523 BBOX.combine(Sbox,x+delta,u);
2524 BBOX.combine(sbox,x,-v);
2525 }
2526 }
2527 BBOX.clean();
2528 return node;
2529 },
2530 CHTMLstretchV: MML.mbase.CHTMLstretchV,
2531 CHTMLstretchH: MML.mbase.CHTMLstretchH,
2532 CHTMLchildNode: function (node,i) {
2533 var types = ["mjx-base","mjx-sub","mjx-sup"];
2534 if (this.over === 1) types[1] = types[2];
2535 return CHTML.getNode(node,types[i]);
2536 }
2537 });
2538
2539 /********************************************************/
2540
2541 MML.mfrac.Augment({
2542 toCommonHTML: function (node) {
2543 node = this.CHTMLdefaultNode(node,{
2544 childNodes:["mjx-numerator","mjx-denominator"],
2545 childOptions: {autowidth: true},
2546 forceChild:true, noBBox:true, minChildren:2
2547 });
2548 var values = this.getValues("linethickness","displaystyle",
2549 "numalign","denomalign","bevelled");
2550 var isDisplay = values.displaystyle;
2551 //
2552 // Create the table for the fraction and set the alignment
2553 //
2554 var num = node.firstChild, denom = node.lastChild;
2555 var frac = CHTML.addElement(node,"mjx-box");
2556 frac.appendChild(num); frac.appendChild(denom); node.appendChild(frac);
2557 if (values.numalign !== "center") num.style.textAlign = values.numalign;
2558 if (values.denomalign !== "center") denom.style.textAlign = values.denomalign;
2559 //
2560 // Get the bounding boxes for the parts, and determine the placement
2561 // of the numerator and denominator
2562 //
2563 var nbox = this.CHTMLbboxFor(0), dbox = this.CHTMLbboxFor(1),
2564 BBOX = CHTML.BBOX.empty(this.CHTML), nscale = nbox.rscale, dscale = dbox.rscale;
2565 values.linethickness = Math.max(0,CHTML.thickness2em(values.linethickness||"0",BBOX.scale));
2566 var mt = CHTML.TEX.min_rule_thickness/CHTML.em, a = CHTML.TEX.axis_height;
2567 var t = values.linethickness, p,q, u,v;
2568 if (values.bevelled) {
2569 frac.className += " MJXc-bevelled";
2570 var delta = (isDisplay ? .4 : .15);
2571 var H = Math.max(nscale*(nbox.h+nbox.d),dscale*(dbox.h+dbox.d)) + 2*delta;
2572 var bevel = CHTML.Element("mjx-bevel"); frac.insertBefore(bevel,denom);
2573 var bbox = CHTML.createDelimiter(bevel,0x2F,H);
2574 u = nscale*(nbox.d-nbox.h)/2+a+delta;
2575 v = dscale*(dbox.d-dbox.h)/2+a-delta;
2576 if (u) num.style.verticalAlign = CHTML.Em(u/nscale);
2577 if (v) denom.style.verticalAlign = CHTML.Em(v/dscale);
2578 bevel.style.marginLeft = bevel.style.marginRight = CHTML.Em(-delta/2);
2579 BBOX.combine(nbox,0,u);
2580 BBOX.combine(bbox,nscale*nbox.w-delta/2,0);
2581 BBOX.combine(dbox,nscale*nbox.w+bbox.w-delta,v);
2582 BBOX.clean();
2583 } else {
2584 frac.className += " MJXc-stacked";
2585 if (isDisplay) {u = CHTML.TEX.num1; v = CHTML.TEX.denom1}
2586 else {u = (t === 0 ? CHTML.TEX.num3 : CHTML.TEX.num2); v = CHTML.TEX.denom2}
2587 if (t === 0) { // \atop
2588 p = Math.max((isDisplay ? 7 : 3) * CHTML.TEX.rule_thickness, 2*mt); // force to at least 2 px
2589 q = (u - nbox.d*nscale) - (dbox.h*dscale - v);
2590 if (q < p) {u += (p - q)/2; v += (p - q)/2}
2591 } else { // \over
2592 p = Math.max((isDisplay ? 2 : 0) * mt + t, t/2 + 1.5*mt);
2593 t = Math.max(t,mt);
2594 q = (u - nbox.d*nscale) - (a + t/2); if (q < p) u += (p - q);
2595 q = (a - t/2) - (dbox.h*dscale - v); if (q < p) v += (p - q);
2596 nbox.L = nbox.R = dbox.L = dbox.R = .1; // account for padding in BBOX width
2597 var rule = CHTML.addElement(frac,"mjx-line",{style: {
2598 "border-bottom":CHTML.Px(t*BBOX.scale,1)+" solid", top: CHTML.Em(-t/2-a)
2599 }});
2600 }
2601 //
2602 // Determine the new bounding box and place the parts
2603 //
2604 BBOX.combine(nbox,0,u);
2605 BBOX.combine(dbox,0,-v);
2606 BBOX.clean();
2607 //
2608 // Force elements to the correct width
2609 //
2610 frac.style.width = CHTML.Em(BBOX.w);
2611 num.style.width = CHTML.Em(BBOX.w/nscale);
2612 denom.style.width = CHTML.Em(BBOX.w/dscale);
2613 if (rule) rule.style.width = frac.style.width;
2614 //
2615 // Place the numerator and denominator in relation to the baseline
2616 //
2617 num.style.top = CHTML.Em(-BBOX.h/nscale);
2618 denom.style.bottom = CHTML.Em(-BBOX.d/dscale);
2619 //
2620 // Force the size of the surrounding box, since everything is absolutely positioned
2621 //
2622 CHTML.addElement(node,"mjx-vsize",{style: {
2623 height: CHTML.Em(BBOX.h+BBOX.d), verticalAlign: CHTML.Em(-BBOX.d)
2624 }});
2625 }
2626 //
2627 // Add nulldelimiterspace around the fraction
2628 // (TeXBook pg 150 and Appendix G rule 15e)
2629 //
2630 if (!this.texWithDelims) {
2631 var space = CHTML.TEX.nulldelimiterspace;
2632 frac.style.padding = "0 "+CHTML.Em(space);
2633 BBOX.l += space; BBOX.r += space; BBOX.w += 2*space;
2634 }
2635 //
2636 // Return the completed fraction
2637 //
2638 return node;
2639 },
2640 CHTMLcanStretch: function (direction) {return false}
2641 });
2642
2643 /********************************************************/
2644
2645 MML.msqrt.Augment({
2646 toCommonHTML: function (node) {
2647 node = this.CHTMLdefaultNode(node,{
2648 childNodes:["mjx-box","mjx-root"], forceChild:true, noBBox:true
2649 });
2650 var base = node.firstChild || CHTML.Element("mjx-box");
2651 var sqrt = CHTML.addElement(node,"mjx-box"); sqrt.appendChild(base);
2652 var bbox = this.CHTMLbboxFor(0), BBOX = CHTML.BBOX.empty(this.CHTML);
2653 var t = CHTML.TEX.rule_thickness, T = CHTML.TEX.surd_height, p = t, q, H;
2654 if (this.Get("displaystyle")) p = CHTML.TEX.x_height;
2655 q = t + p/4;
2656 H = bbox.h + bbox.d + q + t;
2657 var surd = CHTML.Element("mjx-surd"); sqrt.insertBefore(surd,base);
2658 var sbox = CHTML.createDelimiter(surd,0x221A,[H-.04,H]);
2659 if (sbox.h + sbox.d > H) q = ((sbox.h+sbox.d) - (H-t))/2;
2660 H = bbox.h + q + t;
2661 var x = this.CHTMLaddRoot(node,sbox,sbox.h+sbox.d-H);
2662 base.style.paddingTop = CHTML.Em(q);
2663 base.style.borderTop = CHTML.Px(T*bbox.scale,1)+" solid";
2664 sqrt.style.paddingTop = CHTML.Em(2*t-T); // use wider line, but don't affect height
2665 bbox.h += q + 2*t;
2666 BBOX.combine(sbox,x,H-sbox.h);
2667 BBOX.combine(bbox,x+sbox.w,0);
2668 BBOX.clean();
2669 return node;
2670 },
2671 CHTMLaddRoot: function () {return 0},
2672 CHTMLhandleBBox: function (node) {
2673 var bbox = this.CHTMLbboxFor(0);
2674 delete bbox.pwidth;
2675 this.SUPER(arguments).CHTMLhandleBBox.apply(this,arguments);
2676 }
2677 });
2678
2679 /********************************************************/
2680
2681 MML.mroot.Augment({
2682 toCommonHTML: MML.msqrt.prototype.toCommonHTML,
2683 CHTMLhandleBBox: MML.msqrt.prototype.CHTMLhandleBBox,
2684 CHTMLaddRoot: function (sqrt,sbox,d) {
2685 if (!this.data[1]) return;
2686 var BBOX = this.CHTML, bbox = this.data[1].CHTML, root = sqrt.firstChild;
2687 var scale = bbox.rscale;
2688 var h = this.CHTMLrootHeight(bbox,sbox,BBOX.scale)-d;
2689 var w = Math.min(bbox.w,bbox.r); // remove extra right-hand padding, if any
2690 var dx = Math.max(w,sbox.offset/scale);
2691 if (h) root.style.verticalAlign = CHTML.Em(h/scale);
2692 if (dx > w) root.firstChild.style.paddingLeft = CHTML.Em(dx-w);
2693 dx -= sbox.offset/scale;
2694 root.style.width = CHTML.Em(dx);
2695 BBOX.combine(bbox,0,h);
2696 return dx*scale;
2697 },
2698 CHTMLrootHeight: function (bbox,sbox,scale) {
2699 return .45*(sbox.h+sbox.d-.9*scale) + .6*scale + Math.max(0,bbox.d*bbox.scale-.075);
2700 }
2701 });
2702
2703 /********************************************************/
2704
2705 MML.mfenced.Augment({
2706 toCommonHTML: function (node) {
2707 node = this.CHTMLcreateNode(node);
2708 this.CHTMLhandleStyle(node);
2709 this.CHTMLhandleScale(node);
2710 //
2711 // Make row of open, data, sep, ... data, close
2712 //
2713 this.CHTMLaddChild(node,"open",{});
2714 for (var i = 0, m = this.data.length; i < m; i++) {
2715 this.CHTMLaddChild(node,"sep"+i,{});
2716 this.CHTMLaddChild(node,i,{});
2717 }
2718 this.CHTMLaddChild(node,"close",{});
2719 //
2720 // Check for stretching the elements
2721 //
2722 var H = this.CHTML.h, D = this.CHTML.d;
2723 this.CHTMLstretchChildV("open",H,D);
2724 for (i = 0, m = this.data.length; i < m; i++) {
2725 this.CHTMLstretchChildV("sep"+i,H,D);
2726 this.CHTMLstretchChildV(i,H,D);
2727 }
2728 this.CHTMLstretchChildV("close",H,D);
2729 this.CHTMLhandleSpace(node);
2730 this.CHTMLhandleBBox(node);
2731 this.CHTMLhandleColor(node);
2732 return node;
2733 }
2734 });
2735
2736 /********************************************************/
2737
2738 MML.mrow.Augment({
2739 toCommonHTML: function (node,options) {
2740 options = options || {};
2741 node = this.CHTMLdefaultNode(node);
2742 var bbox = this.CHTML, H = bbox.h, D = bbox.d, hasNegative;
2743 for (var i = 0, m = this.data.length; i < m; i++) {
2744 this.CHTMLstretchChildV(i,H,D);
2745 if (this.data[i] && this.data[i].CHTML && this.data[i].CHTML.w < 0) hasNegative = true;
2746 }
2747 if (this.CHTMLlineBreaks()) {
2748 this.CHTMLmultiline(node);
2749 if (options.autowidth) node.style.width = "";
2750 } else {
2751 if (hasNegative && bbox.w) node.style.width = CHTML.Em(Math.max(0,bbox.w));
2752 if (bbox.w < 0) node.style.marginRight = CHTML.Em(bbox.w);
2753 }
2754 return node;
2755 },
2756 CHTMLlineBreaks: function () {
2757 if (!this.parent.linebreakContainer) return false;
2758 return (LINEBREAKS.automatic && this.CHTML.w > CHTML.linebreakWidth) || this.hasNewline();
2759 },
2760 CHTMLstretchV: function (h,d) {
2761 this.CHTMLstretchChildV(this.CoreIndex(),h,d);
2762 return this.CHTML;
2763 },
2764 CHTMLstretchH: function (node,w) {
2765 this.CHTMLstretchChildH(this.CoreIndex(),w,node);
2766 return this.CHTML;
2767 }
2768 });
2769
2770 /********************************************************/
2771
2772 MML.TeXAtom.Augment({
2773 toCommonHTML: function (node,options) {
2774 if (!options || !options.stretch) node = this.CHTMLdefaultNode(node);
2775 if (this.texClass === MML.TEXCLASS.VCENTER) {
2776 var a = CHTML.TEX.axis_height, BBOX = this.CHTML;
2777 var v = a-(BBOX.h+BBOX.d)/2+BBOX.d;
2778 if (Math.abs(v) > .001) {
2779 node.style.verticalAlign = CHTML.Em(v);
2780 BBOX.h += v; BBOX.t += v; BBOX.d -= v; BBOX.b -= v;
2781 }
2782 }
2783 return node;
2784 },
2785 CHTMLstretchV: function (h,d) {
2786 this.CHTMLupdateFrom(this.Core().CHTMLstretchV(h,d));
2787 this.toCommonHTML(this.CHTMLnodeElement(),{stretch:true});
2788 return this.CHTML;
2789 },
2790 CHTMLstretchH: function (node,w) {
2791 this.CHTMLupdateFrom(this.CHTMLstretchCoreH(node,w));
2792 this.toCommonHTML(node,{stretch:true});
2793 return this.CHTML;
2794 }
2795 });
2796
2797 /********************************************************/
2798
2799 MML.semantics.Augment({
2800 toCommonHTML: function (node) {
2801 node = this.CHTMLcreateNode(node);
2802 if (this.data[0]) {
2803 this.data[0].toCommonHTML(node);
2804 this.CHTMLupdateFrom(this.data[0].CHTML);
2805 this.CHTMLhandleBBox(node);
2806 }
2807 return node;
2808 }
2809 });
2810 MML.annotation.Augment({toCommonHTML: function(node) {return this.CHTMLcreateNode(node)}});
2811 MML["annotation-xml"].Augment({toCommonHTML: MML.mbase.CHTMLautoload});
2812
2813 /********************************************************/
2814
2815 MML.ms.Augment({toCommonHTML: MML.mbase.CHTMLautoload});
2816 MML.mglyph.Augment({toCommonHTML: MML.mbase.CHTMLautoload});
2817 MML.menclose.Augment({toCommonHTML: MML.mbase.CHTMLautoload});
2818 MML.maction.Augment({toCommonHTML: MML.mbase.CHTMLautoload});
2819 MML.mmultiscripts.Augment({toCommonHTML: MML.mbase.CHTMLautoload});
2820 MML.mtable.Augment({toCommonHTML: MML.mbase.CHTMLautoload});
2821
2822 /********************************************************/
2823
2824 //
2825 // Loading isn't complete until the element jax is modified,
2826 // but can't call loadComplete within the callback for "mml Jax Ready"
2827 // (it would call CommonHTML's Require routine, asking for the mml jax again)
2828 // so wait until after the mml jax has finished processing.
2829 //
2830 // We also need to wait for the onload handler to run, since the loadComplete
2831 // will call Config and Startup, which need to modify the body.
2832 //
2833 MathJax.Hub.Register.StartupHook("onLoad",function () {
2834 setTimeout(MathJax.Callback(["loadComplete",CHTML,"jax.js"]),0);
2835 });
2836 });
2837
2838 MathJax.Hub.Register.StartupHook("End Cookie", function () {
2839 if (HUB.config.menuSettings.zoom !== "None")
2840 {AJAX.Require("[MathJax]/extensions/MathZoom.js")}
2841 });
2842
2843 })(MathJax.Ajax,MathJax.Hub,MathJax.HTML,MathJax.OutputJax.CommonHTML);