PageRenderTime 1775ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 1ms

/talk2/mathjax/unpacked/jax/output/HTML-CSS/jax.js

https://github.com/williamstein/mazur-explicit-formula
JavaScript | 2835 lines | 2516 code | 123 blank | 196 comment | 946 complexity | 3c116987da8483df9c7c8141e7dc5ee5 MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0, MIT

Large files files are truncated, but you can click here to view the full file

  1. /*************************************************************
  2. *
  3. * MathJax/jax/output/HTML-CSS/jax.js
  4. *
  5. * Implements the HTML-CSS OutputJax that displays mathematics
  6. * using HTML and CSS to position the characters from math fonts
  7. * in their proper locations.
  8. *
  9. * ---------------------------------------------------------------------
  10. *
  11. * Copyright (c) 2009-2012 Design Science, Inc.
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License");
  14. * you may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. (function (AJAX,HUB,HTMLCSS) {
  26. var MML, isMobile = HUB.Browser.isMobile;
  27. var FONTTEST = MathJax.Object.Subclass({
  28. timeout: (isMobile? 15:8)*1000, // timeout for loading web fonts
  29. FontInfo: {
  30. STIX: {family: "STIXSizeOneSym", testString: "() {} []"},
  31. TeX: {family: "MathJax_Size1", testString: "() {} []"}
  32. },
  33. comparisonFont: ["sans-serif","monospace","script","Times","Courier","Arial","Helvetica"],
  34. testSize: ["40px","50px","60px","30px","20px"],
  35. Init: function () {
  36. this.div = MathJax.HTML.addElement(document.body,"div",{
  37. id: "MathJax_Font_Test",
  38. style: {position:"absolute", visibility:"hidden", top:0, left:0, width: "auto",
  39. padding:0, border:0, margin:0, whiteSpace:"nowrap",
  40. textAlign:"left", textIndent:0, textTransform:"none",
  41. lineHeight:"normal", letterSpacing:"normal", wordSpacing:"normal",
  42. fontSize:this.testSize[0], fontWeight:"normal", fontStyle:"normal",
  43. fontSizeAdjust:"none"}
  44. },[""]);
  45. this.text = this.div.firstChild;
  46. },
  47. findFont: function (fonts,pref) {
  48. if (pref && this.testCollection(pref)) {return pref}
  49. for (var i = 0, m = fonts.length; i < m; i++) {
  50. if (fonts[i] === pref) continue;
  51. if (this.testCollection(fonts[i])) {return fonts[i]}
  52. }
  53. return null;
  54. },
  55. testCollection: function (name) {return this.testFont(this.FontInfo[name])},
  56. testFont: function (font) {
  57. if (font.isWebFont && HTMLCSS.FontFaceBug) {
  58. this.div.style.fontWeight = this.div.style.fontStyle = "normal";
  59. } else {
  60. this.div.style.fontWeight = (font.weight||"normal");
  61. this.div.style.fontStyle = (font.style||"normal");
  62. }
  63. var W = this.getComparisonWidths(font.testString,font.noStyleChar);
  64. if (W) {
  65. this.div.style.fontFamily = "'"+font.family+"',"+this.comparisonFont[0];
  66. if (this.div.offsetWidth == W[0]) {
  67. this.div.style.fontFamily = "'"+font.family+"',"+this.comparisonFont[W[2]];
  68. if (this.div.offsetWidth == W[1]) {return false}
  69. }
  70. if (this.div.offsetWidth != W[3] || this.div.offsetHeight != W[4]) {
  71. if (font.noStyleChar || !HTMLCSS.FONTDATA || !HTMLCSS.FONTDATA.hasStyleChar) {return true}
  72. for (var i = 0, m = this.testSize.length; i < m; i++)
  73. {if (this.testStyleChar(font,this.testSize[i])) {return true}}
  74. }
  75. }
  76. return false;
  77. },
  78. styleChar: "\uEFFD", // width encodes style
  79. versionChar: "\uEFFE", // width encodes version
  80. compChar: "\uEFFF", // "standard" width to compare to
  81. testStyleChar: function (font,size) {
  82. var n = 3 + (font.weight ? 2 : 0) + (font.style ? 4 : 0);
  83. var extra = "", dw = 0;
  84. var SIZE = this.div.style.fontSize; this.div.style.fontSize = size;
  85. if (HTMLCSS.msieItalicWidthBug && font.style === "italic") {
  86. this.text.nodeValue = extra = this.compChar;
  87. dw = this.div.offsetWidth;
  88. }
  89. if (HTMLCSS.safariTextNodeBug) {this.div.innerHTML = this.compChar+extra}
  90. else {this.text.nodeValue = this.compChar+extra}
  91. var W = this.div.offsetWidth-dw;
  92. if (HTMLCSS.safariTextNodeBug) {this.div.innerHTML = this.styleChar+extra}
  93. else {this.text.nodeValue = this.styleChar+extra}
  94. var N = Math.floor((this.div.offsetWidth-dw)/W+.5);
  95. if (N === n) {
  96. if (HTMLCSS.safariTextNodeBug) {this.div.innerHTML = this.versionChar+extra}
  97. else {this.text.nodeValue = this.versionChar+extra}
  98. font.version = Math.floor((this.div.offsetWidth-dw)/W+1.5)/2;
  99. }
  100. this.div.style.fontSize = SIZE;
  101. return (N === n);
  102. },
  103. getComparisonWidths: function (string,noStyleChar) {
  104. if (HTMLCSS.FONTDATA && HTMLCSS.FONTDATA.hasStyleChar && !noStyleChar)
  105. {string += this.styleChar + " " + this.compChar}
  106. if (HTMLCSS.safariTextNodeBug) {this.div.innerHTML = string}
  107. else {this.text.nodeValue = string}
  108. this.div.style.fontFamily = this.comparisonFont[0];
  109. var W = this.div.offsetWidth;
  110. this.div.style.fontFamily = HTMLCSS.webFontDefault;
  111. var sW = this.div.offsetWidth, sH = this.div.offsetHeight;
  112. for (var i = 1, m = this.comparisonFont.length; i < m; i++) {
  113. this.div.style.fontFamily = this.comparisonFont[i];
  114. if (this.div.offsetWidth != W) {return [W,this.div.offsetWidth,i,sW,sH]}
  115. }
  116. return null;
  117. },
  118. loadWebFont: function (font) {
  119. HUB.Startup.signal.Post("HTML-CSS Jax - Web-Font "+HTMLCSS.fontInUse+"/"+font.directory);
  120. var n = MathJax.Message.File("Web-Font "+HTMLCSS.fontInUse+"/"+font.directory);
  121. var done = MathJax.Callback({}); // called when font is loaded
  122. var callback = MathJax.Callback(["loadComplete",this,font,n,done]);
  123. AJAX.timer.start(AJAX,[this.checkWebFont,font,callback],0,this.timeout);
  124. return done;
  125. },
  126. loadComplete: function (font,n,done,status) {
  127. MathJax.Message.Clear(n);
  128. if (status === AJAX.STATUS.OK) {this.webFontLoaded = true; done(); return}
  129. this.loadError(font);
  130. if (HUB.Browser.isFirefox && HTMLCSS.allowWebFonts) {
  131. var host = document.location.protocol + "//" + document.location.hostname;
  132. if (document.location.port != "") {host += ":" + document.location.port}
  133. host += "/";
  134. if (AJAX.fileURL(HTMLCSS.webfontDir).substr(0,host.length) !== host)
  135. {this.firefoxFontError(font)}
  136. }
  137. if (!this.webFontLoaded) {HTMLCSS.loadWebFontError(font,done)} else {done()}
  138. },
  139. loadError: function (font) {
  140. MathJax.Message.Set("Can't load web font "+HTMLCSS.fontInUse+"/"+font.directory,null,2000);
  141. HUB.Startup.signal.Post(["HTML-CSS Jax - web font error",HTMLCSS.fontInUse+"/"+font.directory,font]);
  142. },
  143. firefoxFontError: function (font) {
  144. MathJax.Message.Set("Firefox can't load web fonts from a remote host",null,3000);
  145. HUB.Startup.signal.Post("HTML-CSS Jax - Firefox web fonts on remote host error");
  146. },
  147. checkWebFont: function (check,font,callback) {
  148. if (check.time(callback)) return;
  149. if (HTMLCSS.Font.testFont(font)) {callback(check.STATUS.OK)}
  150. else {setTimeout(check,check.delay)}
  151. },
  152. fontFace: function (name) {
  153. var type = HTMLCSS.allowWebFonts;
  154. var FONT = HTMLCSS.FONTDATA.FONTS[name];
  155. if (HTMLCSS.msieFontCSSBug && !FONT.family.match(/-Web$/)) {FONT.family += "-Web"}
  156. var dir = AJAX.fileURL(HTMLCSS.webfontDir+"/"+type);
  157. var fullname = name.replace(/-b/,"-B").replace(/-i/,"-I").replace(/-Bold-/,"-Bold");
  158. if (!fullname.match(/-/)) {fullname += "-Regular"}
  159. if (type === "svg") {fullname += ".svg#"+fullname} else {fullname += "."+type}
  160. var def = {
  161. "font-family": FONT.family,
  162. src: "url('"+dir+"/"+fullname+"')"
  163. };
  164. if (type === "otf") {
  165. def.src += " format('opentype')";
  166. dir = AJAX.fileURL(HTMLCSS.webfontDir+"/woff"); // add woff fonts as well
  167. def.src = "url('"+dir+"/"+fullname.replace(/otf$/,"woff")+"') format('woff'), "+def.src;
  168. } else if (type !== "eot") {def.src += " format('"+type+"')"}
  169. if (!(HTMLCSS.FontFaceBug && FONT.isWebFont)) {
  170. if (name.match(/-bold/)) {def["font-weight"] = "bold"}
  171. if (name.match(/-italic/)) {def["font-style"] = "italic"}
  172. }
  173. return def;
  174. }
  175. });
  176. var EVENT, TOUCH, HOVER; // filled in later
  177. HTMLCSS.Augment({
  178. config: {
  179. styles: {
  180. ".MathJax": {
  181. "display": "inline",
  182. "font-style": "normal",
  183. "font-weight": "normal",
  184. "line-height": "normal",
  185. "font-size": "100%",
  186. "font-size-adjust":"none",
  187. "text-indent": 0,
  188. "text-align": "left",
  189. "text-transform": "none",
  190. "letter-spacing": "normal",
  191. "word-spacing": "normal",
  192. "word-wrap": "normal",
  193. "white-space": "nowrap",
  194. "float": "none",
  195. "direction": "ltr",
  196. border: 0, padding: 0, margin: 0
  197. },
  198. ".MathJax_Display": {
  199. position: "relative",
  200. display: "block",
  201. width: "100%"
  202. },
  203. ".MathJax img, .MathJax nobr, .MathJax a": {
  204. border: 0, padding: 0, margin: 0, "max-width": "none", "max-height": "none",
  205. "vertical-align": 0, "line-height": "normal",
  206. "text-decoration": "none"
  207. },
  208. "img.MathJax_strut": {
  209. border:"0 !important", padding:"0 !important", margin: "0 !important",
  210. "vertical-align": "0 !important"
  211. },
  212. ".MathJax span": {
  213. display: "inline", position: "static",
  214. border: 0, padding: 0, margin: 0,
  215. "vertical-align": 0, "line-height": "normal",
  216. "text-decoration": "none"
  217. },
  218. ".MathJax nobr": {
  219. "white-space": "nowrap ! important"
  220. },
  221. ".MathJax img": {
  222. display: "inline ! important",
  223. "float": "none ! important"
  224. },
  225. ".MathJax_Processing": {
  226. visibility: "hidden", position:"fixed",
  227. width: 0, height: 0, overflow:"hidden"
  228. },
  229. ".MathJax_Processed": {display:"none!important"},
  230. ".MathJax_ExBox": {
  231. display:"block", overflow:"hidden",
  232. width:"1px", height:"60ex"
  233. },
  234. ".MathJax .MathJax_EmBox": {
  235. display:"block", overflow:"hidden",
  236. width:"1px", height:"60em"
  237. },
  238. ".MathJax .MathJax_HitBox": {
  239. cursor: "text",
  240. background: "white",
  241. opacity:0, filter:"alpha(opacity=0)"
  242. },
  243. ".MathJax .MathJax_HitBox *": {
  244. filter: "none", opacity:1, background:"transparent" // for IE
  245. },
  246. "#MathJax_Tooltip": {
  247. position: "absolute", left: 0, top: 0,
  248. width: "auto", height: "auto",
  249. display: "none"
  250. },
  251. "#MathJax_Tooltip *": {
  252. filter: "none", opacity:1, background:"transparent" // for IE
  253. },
  254. //
  255. // Used for testing web fonts against the default font used while
  256. // web fonts are loading
  257. //
  258. "@font-face": {
  259. "font-family": "MathJax_Blank",
  260. "src": "url('about:blank')"
  261. }
  262. }
  263. },
  264. settings: HUB.config.menuSettings,
  265. hideProcessedMath: true, // use display:none until all math is processed
  266. Font: null, // created by Config() below
  267. webFontDefault: "MathJax_Blank",
  268. allowWebFonts: "otf", // assume browser can use OTF web fonts
  269. Config: function () {
  270. if (!this.require) {this.require = []}
  271. this.Font = FONTTEST();
  272. this.SUPER(arguments).Config.call(this); var settings = this.settings;
  273. if (this.adjustAvailableFonts) {this.adjustAvailableFonts(this.config.availableFonts)}
  274. if (settings.scale) {this.config.scale = settings.scale}
  275. if (settings.font && settings.font !== "Auto") {
  276. if (settings.font === "TeX (local)")
  277. {this.config.availableFonts = ["TeX"]; this.config.preferredFont = "TeX"; this.config.webFont = "TeX"}
  278. else if (settings.font === "STIX (local)")
  279. {this.config.availableFonts = ["STIX"]; this.config.preferredFont = "STIX"; this.config.webFont = "TeX"}
  280. else if (settings.font === "TeX (web)") {this.config.availableFonts = []; this.config.preferredFont = ""; this.config.webFont = "TeX"}
  281. else if (settings.font === "TeX (image)") {this.config.availableFonts = []; this.config.preferredFont = ""; this.config.webFont = ""}
  282. }
  283. var font = this.Font.findFont(this.config.availableFonts,this.config.preferredFont);
  284. if (!font && this.allowWebFonts) {font = this.config.webFont; if (font) {this.webFonts = true}}
  285. if (!font && this.config.imageFont) {font = this.config.imageFont; this.imgFonts = true}
  286. if (font) {
  287. this.fontInUse = font; this.fontDir += "/" + font; this.webfontDir += "/" + font;
  288. this.require.push(this.fontDir+"/fontdata.js");
  289. if (this.imgFonts) {
  290. this.require.push(this.directory+"/imageFonts.js");
  291. HUB.Startup.signal.Post("HTML-CSS Jax - using image fonts");
  292. }
  293. } else {
  294. MathJax.Message.Set("Can't find a valid font using ["+this.config.availableFonts.join(", ")+"]",null,3000);
  295. this.FONTDATA = {
  296. TeX_factor: 1, baselineskip: 1.2, lineH: .8, lineD: .2, ffLineH: .8,
  297. FONTS: {}, VARIANT: {normal: {fonts:[]}}, RANGES: [],
  298. DELIMITERS: {}, RULECHAR: 0x2D, REMAP: {}
  299. };
  300. if (MathJax.InputJax.TeX && MathJax.InputJax.TeX.Definitions) {
  301. MathJax.InputJax.TeX.Definitions.macros.overline[1] = "002D";
  302. MathJax.InputJax.TeX.Definitions.macros.underline[1] = "002D";
  303. }
  304. HUB.Startup.signal.Post("HTML-CSS Jax - no valid font");
  305. }
  306. this.require.push(MathJax.OutputJax.extensionDir+"/MathEvents.js");
  307. },
  308. Startup: function () {
  309. // Set up event handling
  310. EVENT = MathJax.Extension.MathEvents.Event;
  311. TOUCH = MathJax.Extension.MathEvents.Touch;
  312. HOVER = MathJax.Extension.MathEvents.Hover;
  313. this.ContextMenu = EVENT.ContextMenu;
  314. this.Mousedown = EVENT.AltContextMenu;
  315. this.Mouseover = HOVER.Mouseover;
  316. this.Mouseout = HOVER.Mouseout;
  317. this.Mousemove = HOVER.Mousemove;
  318. // Make hidden div for when math is in a display:none block
  319. this.hiddenDiv = this.Element("div",{
  320. style:{visibility:"hidden", overflow:"hidden", position:"absolute", top:0,
  321. height:"1px", width: "auto", padding:0, border:0, margin:0,
  322. textAlign:"left", textIndent:0, textTransform:"none",
  323. lineHeight:"normal", letterSpacing:"normal", wordSpacing:"normal"}
  324. });
  325. if (!document.body.firstChild) {document.body.appendChild(this.hiddenDiv)}
  326. else {document.body.insertBefore(this.hiddenDiv,document.body.firstChild)}
  327. this.hiddenDiv = this.addElement(this.hiddenDiv,"div",{id:"MathJax_Hidden"});
  328. // Determine pixels per inch
  329. var div = this.addElement(this.hiddenDiv,"div",{style:{width:"5in"}});
  330. this.pxPerInch = div.offsetWidth/5; this.hiddenDiv.removeChild(div);
  331. // Markers used by getW
  332. this.startMarker = this.createStrut(this.Element("span"),10,true);
  333. this.endMarker = this.addText(this.Element("span"),"x").parentNode;
  334. // Used in getHD
  335. this.HDspan = this.Element("span");
  336. if (this.operaHeightBug) {this.createStrut(this.HDspan,0)}
  337. if (this.msieInlineBlockAlignBug) {
  338. this.HDimg = this.addElement(this.HDspan,"img",{style:{height:"0px", width:"1px"}});
  339. try {this.HDimg.src = "about:blank"} catch(err) {}
  340. } else {
  341. this.HDimg = this.createStrut(this.HDspan,0);
  342. }
  343. // Used in preTranslate to get scaling factors
  344. this.EmExSpan = this.Element("span",
  345. {style:{position:"absolute","font-size-adjust":"none"}},
  346. [
  347. ["span",{className:"MathJax_ExBox"}],
  348. ["span",{className:"MathJax"},
  349. [["span",{className:"MathJax_EmBox"}]]
  350. ]
  351. ]
  352. );
  353. // Used in preTranslate to get linebreak width
  354. this.linebreakSpan = this.Element("span",null,
  355. [["hr",{style: {width:"100%", size:1, padding:0, border:0, margin:0}}]]);
  356. // Set up styles and preload web fonts
  357. return AJAX.Styles(this.config.styles,["InitializeHTML",this]);
  358. },
  359. removeSTIXfonts: function (fonts) {
  360. //
  361. // Opera doesn't display large chunks of the STIX fonts, and
  362. // Safari/Windows doesn't display Plane1,
  363. // so disable STIX for these browsers.
  364. //
  365. for (var i = 0, m = fonts.length; i < m; i++)
  366. {if (fonts[i] === "STIX") {fonts.splice(i,1); m--; i--;}}
  367. if (this.config.preferredFont === "STIX") {this.config.preferredFont = fonts[0]}
  368. },
  369. PreloadWebFonts: function () {
  370. if (!HTMLCSS.allowWebFonts || !HTMLCSS.config.preloadWebFonts) return;
  371. for (var i = 0, m = HTMLCSS.config.preloadWebFonts.length; i < m; i++) {
  372. var FONT = HTMLCSS.FONTDATA.FONTS[HTMLCSS.config.preloadWebFonts[i]];
  373. if (!FONT.available) {HTMLCSS.Font.testFont(FONT)}
  374. }
  375. },
  376. //
  377. // Handle initialization that requires styles to be set up
  378. //
  379. InitializeHTML: function () {
  380. this.PreloadWebFonts();
  381. //
  382. // Get the default sizes (need styles in place to do this)
  383. //
  384. document.body.appendChild(this.EmExSpan);
  385. document.body.appendChild(this.linebreakSpan);
  386. this.defaultEx = this.EmExSpan.firstChild.offsetHeight/60;
  387. this.defaultEm = this.EmExSpan.lastChild.firstChild.offsetHeight/60;
  388. this.defaultWidth = this.linebreakSpan.firstChild.offsetWidth;
  389. document.body.removeChild(this.linebreakSpan);
  390. document.body.removeChild(this.EmExSpan);
  391. },
  392. preTranslate: function (state) {
  393. var scripts = state.jax[this.id], i, m = scripts.length,
  394. script, prev, span, div, test, jax, ex, em, scale, maxwidth, relwidth = false,
  395. linebreak = this.config.linebreaks.automatic, width = this.config.linebreaks.width;
  396. if (linebreak) {
  397. relwidth = (width.match(/^\s*(\d+(\.\d*)?%\s*)?container\s*$/) != null);
  398. if (relwidth) {width = width.replace(/\s*container\s*/,"")}
  399. else {maxwidth = this.defaultWidth}
  400. if (width === "") {width = "100%"}
  401. } else {maxwidth = 100000} // a big width, so no implicit line breaks
  402. //
  403. // Loop through the scripts
  404. //
  405. for (i = 0; i < m; i++) {
  406. script = scripts[i]; if (!script.parentNode) continue;
  407. //
  408. // Remove any existing output
  409. //
  410. prev = script.previousSibling;
  411. if (prev && String(prev.className).match(/^MathJax(_Display)?( MathJax_Processing)?$/))
  412. {prev.parentNode.removeChild(prev)}
  413. //
  414. // Add the span, and a div if in display mode,
  415. // then set the role and mark it as being processed
  416. //
  417. jax = script.MathJax.elementJax; if (!jax) continue;
  418. jax.HTMLCSS = {display: (jax.root.Get("display") === "block")}
  419. span = div = this.Element("span",{
  420. className:"MathJax", id:jax.inputID+"-Frame", isMathJax:true, jaxID:this.id,
  421. oncontextmenu:EVENT.Menu, onmousedown: EVENT.Mousedown,
  422. onmouseover:EVENT.Mouseover, onmouseout:EVENT.Mouseout, onmousemove:EVENT.Mousemove,
  423. onclick:EVENT.Click, ondblclick:EVENT.DblClick
  424. });
  425. if (HUB.Browser.noContextMenu) {
  426. span.ontouchstart = TOUCH.start;
  427. span.ontouchend = TOUCH.end;
  428. }
  429. if (jax.HTMLCSS.display) {
  430. div = this.Element("div",{className:"MathJax_Display"});
  431. div.appendChild(span);
  432. } else if (this.msieDisappearingBug) {span.style.display = "inline-block"}
  433. //
  434. // Mark math for screen readers
  435. // (screen readers don't know about role="math" yet, so use "textbox" instead)
  436. //
  437. div.setAttribute("role","textbox"); div.setAttribute("aria-readonly","true");
  438. div.className += " MathJax_Processing";
  439. script.parentNode.insertBefore(div,script);
  440. //
  441. // Add the test span for determining scales and linebreak widths
  442. //
  443. script.parentNode.insertBefore(this.EmExSpan.cloneNode(true),script);
  444. if (relwidth) {div.parentNode.insertBefore(this.linebreakSpan.cloneNode(true),div)}
  445. }
  446. //
  447. // Determine the scaling factors for each script
  448. // (this only requires one reflow rather than a reflow for each equation)
  449. //
  450. for (i = 0; i < m; i++) {
  451. script = scripts[i]; if (!script.parentNode) continue;
  452. test = script.previousSibling; div = test.previousSibling;
  453. jax = script.MathJax.elementJax; if (!jax) continue;
  454. ex = test.firstChild.offsetHeight/60;
  455. em = test.lastChild.firstChild.offsetHeight/60;
  456. if (relwidth) {maxwidth = div.previousSibling.firstChild.offsetWidth}
  457. if (ex === 0 || ex === "NaN") {
  458. // can't read width, so move to hidden div for processing
  459. // (this will cause a reflow for each math element that is hidden)
  460. this.hiddenDiv.appendChild(div);
  461. jax.HTMLCSS.isHidden = true;
  462. ex = this.defaultEx; em = this.defaultEm;
  463. if (relwidth) {maxwidth = this.defaultWidth}
  464. }
  465. scale = Math.floor(Math.max(this.config.minScaleAdjust/100,(ex/this.TeX.x_height)/em) * this.config.scale);
  466. jax.HTMLCSS.scale = scale/100; jax.HTMLCSS.fontSize = scale+"%";
  467. jax.HTMLCSS.em = jax.HTMLCSS.outerEm = em; this.em = em * scale/100; jax.HTMLCSS.ex = ex;
  468. jax.HTMLCSS.lineWidth = (linebreak ? this.length2em(width,1,maxwidth/this.em) : 1000000);
  469. }
  470. //
  471. // Remove the test spans used for determining scales and linebreak widths
  472. //
  473. for (i = 0; i < m; i++) {
  474. script = scripts[i]; if (!script.parentNode) continue;
  475. test = scripts[i].previousSibling;
  476. jax = scripts[i].MathJax.elementJax; if (!jax) continue;
  477. if (relwidth) {
  478. span = test.previousSibling;
  479. if (!jax.HTMLCSS.isHidden) {span = span.previousSibling}
  480. span.parentNode.removeChild(span);
  481. }
  482. test.parentNode.removeChild(test);
  483. }
  484. //
  485. // Set state variables used for displaying equations in chunks
  486. //
  487. state.HTMLCSSeqn = state.HTMLCSSlast = 0; state.HTMLCSSi = -1;
  488. state.HTMLCSSchunk = this.config.EqnChunk;
  489. state.HTMLCSSdelay = false;
  490. },
  491. Translate: function (script,state) {
  492. if (!script.parentNode) return;
  493. //
  494. // If we are supposed to do a chunk delay, do it
  495. //
  496. if (state.HTMLCSSdelay) {
  497. state.HTMLCSSdelay = false;
  498. HUB.RestartAfter(MathJax.Callback.Delay(this.config.EqnChunkDelay));
  499. }
  500. //
  501. // Get the data about the math
  502. //
  503. var jax = script.MathJax.elementJax, math = jax.root,
  504. span = document.getElementById(jax.inputID+"-Frame"),
  505. div = (jax.HTMLCSS.display ? span.parentNode : span);
  506. //
  507. // Set the font metrics
  508. //
  509. this.em = MML.mbase.prototype.em = jax.HTMLCSS.em * jax.HTMLCSS.scale;
  510. this.outerEm = jax.HTMLCSS.em; this.scale = jax.HTMLCSS.scale;
  511. this.linebreakWidth = jax.HTMLCSS.lineWidth;
  512. span.style.fontSize = jax.HTMLCSS.fontSize;
  513. //
  514. // Typeset the math
  515. //
  516. this.initImg(span);
  517. this.initHTML(math,span);
  518. math.setTeXclass();
  519. try {math.toHTML(span,div)} catch (err) {
  520. if (err.restart) {while (span.firstChild) {span.removeChild(span.firstChild)}}
  521. throw err;
  522. }
  523. //
  524. // Put it in place, and remove the processing marker
  525. //
  526. if (jax.HTMLCSS.isHidden) {script.parentNode.insertBefore(div,script)}
  527. div.className = div.className.split(/ /)[0];
  528. //
  529. // Check if we are hiding the math until more is processed
  530. //
  531. if (this.hideProcessedMath) {
  532. //
  533. // Hide the math and don't let its preview be removed
  534. //
  535. div.className += " MathJax_Processed";
  536. if (script.MathJax.preview) {
  537. jax.HTMLCSS.preview = script.MathJax.preview;
  538. delete script.MathJax.preview;
  539. }
  540. //
  541. // Check if we should show this chunk of equations
  542. //
  543. state.HTMLCSSeqn += (state.i - state.HTMLCSSi); state.HTMLCSSi = state.i;
  544. if (state.HTMLCSSeqn >= state.HTMLCSSlast + state.HTMLCSSchunk) {
  545. this.postTranslate(state);
  546. state.HTMLCSSchunk = Math.floor(state.HTMLCSSchunk*this.config.EqnChunkFactor);
  547. state.HTMLCSSdelay = true; // delay if there are more scripts
  548. }
  549. }
  550. },
  551. postTranslate: function (state) {
  552. var scripts = state.jax[this.id];
  553. if (!this.hideProcessedMath) return;
  554. //
  555. // Reveal this chunk of math
  556. //
  557. for (var i = state.HTMLCSSlast, m = state.HTMLCSSeqn; i < m; i++) {
  558. var script = scripts[i];
  559. if (script && script.MathJax.elementJax) {
  560. //
  561. // Remove the processed marker
  562. //
  563. script.previousSibling.className = script.previousSibling.className.split(/ /)[0];
  564. var data = script.MathJax.elementJax.HTMLCSS;
  565. //
  566. // Remove the preview, if any
  567. //
  568. if (data.preview) {
  569. data.preview.innerHTML = "";
  570. script.MathJax.preview = data.preview;
  571. delete data.preview;
  572. }
  573. }
  574. }
  575. if (this.forceReflow) {
  576. // WebKit can misplace some elements that should wrap to the next line
  577. // but gets them right ona reflow, so force reflow by toggling a stylesheet
  578. var sheet = (document.styleSheets||[])[0]||{};
  579. sheet.disabled = true; sheet.disabled = false;
  580. }
  581. //
  582. // Save our place so we know what is revealed
  583. //
  584. state.HTMLCSSlast = state.HTMLCSSeqn;
  585. },
  586. getJaxFromMath: function (math) {
  587. if (math.parentNode.className === "MathJax_Display") {math = math.parentNode}
  588. do {math = math.nextSibling} while (math && math.nodeName.toLowerCase() !== "script");
  589. return HUB.getJaxFor(math);
  590. },
  591. getHoverSpan: function (jax,math) {return jax.root.HTMLspanElement()},
  592. getHoverBBox: function (jax,span,math) {
  593. var bbox = span.bbox, em = jax.HTMLCSS.outerEm;
  594. var BBOX = {w:bbox.w*em, h:bbox.h*em, d:bbox.d*em};
  595. if (bbox.width) {BBOX.width = bbox.width}
  596. return BBOX;
  597. },
  598. Zoom: function (jax,span,math,Mw,Mh) {
  599. //
  600. // Re-render at larger size
  601. //
  602. span.className = "MathJax";
  603. span.style.fontSize = jax.HTMLCSS.fontSize;
  604. //
  605. // get em sizes (taken from HTMLCSS.preTranslate)
  606. //
  607. var emex = span.appendChild(this.EmExSpan.cloneNode(true));
  608. var em = emex.lastChild.firstChild.offsetHeight/60;
  609. this.em = MML.mbase.prototype.em = em;
  610. this.outerEm = em / jax.HTMLCSS.scale;
  611. emex.parentNode.removeChild(emex);
  612. this.idPostfix = "-zoom"; jax.root.toHTML(span,span); this.idPostfix = "";
  613. var width = jax.root.HTMLspanElement().bbox.width;
  614. if (width) {
  615. // Handle full-width displayed equations
  616. // FIXME: this is a hack for now
  617. span.style.width = Math.floor(Mw-1.5*HTMLCSS.em)+"px"; span.style.display="inline-block";
  618. var id = (jax.root.id||"MathJax-Span-"+jax.root.spanID)+"-zoom";
  619. var child = document.getElementById(id).firstChild;
  620. while (child && child.style.width !== width) {child = child.nextSibling}
  621. if (child) {child.style.width = "100%"}
  622. }
  623. //
  624. // Get height and width of zoomed math and original math
  625. //
  626. span.style.position = math.style.position = "absolute";
  627. var zW = span.offsetWidth, zH = span.offsetHeight,
  628. mH = math.offsetHeight, mW = math.offsetWidth;
  629. if (mW === 0) {mW = math.parentNode.offsetWidth}; // IE7 gets mW == 0?
  630. span.style.position = math.style.position = "";
  631. //
  632. return {Y:-EVENT.getBBox(span).h, mW:mW, mH:mH, zW:zW, zH:zH};
  633. },
  634. initImg: function (span) {},
  635. initHTML: function (math,span) {},
  636. initFont: function (name) {
  637. var FONTS = HTMLCSS.FONTDATA.FONTS, AVAIL = HTMLCSS.config.availableFonts;
  638. if (AVAIL && AVAIL.length && HTMLCSS.Font.testFont(FONTS[name]))
  639. {FONTS[name].available = true; return null}
  640. if (!this.allowWebFonts) {return null}
  641. FONTS[name].isWebFont = true;
  642. if (HTMLCSS.FontFaceBug) {
  643. FONTS[name].family = name;
  644. if (HTMLCSS.msieFontCSSBug) {FONTS[name].family += "-Web"}
  645. }
  646. return AJAX.Styles({"@font-face":this.Font.fontFace(name)});
  647. },
  648. Remove: function (jax) {
  649. var span = document.getElementById(jax.inputID+"-Frame");
  650. if (span) {
  651. if (jax.HTMLCSS.display) {span = span.parentNode}
  652. span.parentNode.removeChild(span);
  653. }
  654. delete jax.HTMLCSS;
  655. },
  656. getHD: function (span) {
  657. var position = span.style.position;
  658. span.style.position = "absolute";
  659. this.HDimg.style.height = "0px";
  660. span.appendChild(this.HDspan);
  661. var HD = {h:span.offsetHeight};
  662. this.HDimg.style.height = HD.h+"px";
  663. HD.d = span.offsetHeight - HD.h; HD.h -= HD.d;
  664. HD.h /= this.em; HD.d /= this.em;
  665. span.removeChild(this.HDspan);
  666. span.style.position = position;
  667. return HD;
  668. },
  669. getW: function (span) {
  670. var W, H, w = (span.bbox||{}).w, start = span;
  671. if (span.bbox && span.bbox.exactW) {return w}
  672. if ((span.bbox && w >= 0 && !this.initialSkipBug) || this.negativeBBoxes || !span.firstChild) {
  673. W = span.offsetWidth; H = span.parentNode.offsetHeight;
  674. } else if (span.bbox && w < 0 && this.msieNegativeBBoxBug) {
  675. W = -span.offsetWidth, H = span.parentNode.offsetHeight;
  676. } else {
  677. // IE can't deal with a space at the beginning, so put something else first
  678. if (this.initialSkipBug) {
  679. var position = span.style.position; span.style.position = "absolute";
  680. start = this.startMarker; span.insertBefore(start,span.firstChild)
  681. }
  682. span.appendChild(this.endMarker);
  683. W = this.endMarker.offsetLeft - start.offsetLeft;
  684. span.removeChild(this.endMarker);
  685. if (this.initialSkipBug) {span.removeChild(start); span.style.position = position}
  686. }
  687. if (H != null) {span.parentNode.HH = H/this.em}
  688. return W/this.em;
  689. },
  690. Measured: function (span,parent) {
  691. var bbox = span.bbox;
  692. if (bbox.width == null && bbox.w && !bbox.isMultiline) {
  693. var w = this.getW(span);
  694. bbox.rw += w - bbox.w;
  695. bbox.w = w; bbox.exactW = true;
  696. }
  697. if (!parent) {parent = span.parentNode}
  698. if (!parent.bbox) {parent.bbox = bbox}
  699. return span;
  700. },
  701. Remeasured: function (span,parent) {
  702. parent.bbox = this.Measured(span,parent).bbox;
  703. },
  704. MeasureSpans: function (SPANS) {
  705. var spans = [], span, i, m, bbox, start, end, W;
  706. //
  707. // Insert the needed markers
  708. //
  709. for (i = 0, m = SPANS.length; i < m; i++) {
  710. span = SPANS[i]; if (!span) continue;
  711. bbox = span.bbox;
  712. if (bbox.exactW || bbox.width || bbox.w === 0 || bbox.isMultiline) {
  713. if (!span.parentNode.bbox) {span.parentNode.bbox = bbox}
  714. continue;
  715. }
  716. if (this.negativeBBoxes || !span.firstChild || (bbox.w >= 0 && !this.initialSkipBug) ||
  717. (bbox.w < 0 && this.msieNegativeBBoxBug)) {
  718. spans.push([span]);
  719. } else if (this.initialSkipBug) {
  720. start = this.startMarker.cloneNode(true); end = this.endMarker.cloneNode(true);
  721. span.insertBefore(start,span.firstChild); span.appendChild(end);
  722. spans.push([span,start,end,span.style.position]); span.style.position = "absolute";
  723. } else {
  724. end = this.endMarker.cloneNode(true);
  725. span.appendChild(end); spans.push([span,null,end]);
  726. }
  727. }
  728. //
  729. // Read the widths and heights
  730. //
  731. for (i = 0, m = spans.length; i < m; i++) {
  732. span = spans[i][0]; bbox = span.bbox; var parent = span.parentNode;
  733. if ((bbox.w >= 0 && !this.initialSkipBug) || this.negativeBBoxes || !span.firstChild) {
  734. W = span.offsetWidth; parent.HH = span.parentNode.offsetHeight/this.em;
  735. } else if (bbox.w < 0 && this.msieNegativeBBoxBug) {
  736. W = -span.offsetWidth, parent.HH = span.parentNode.offsetHeight/this.em;
  737. } else {
  738. W = spans[i][2].offsetLeft - ((spans[i][1]||{}).offsetLeft||0);
  739. }
  740. W /= this.em;
  741. bbox.rw += W - bbox.w;
  742. bbox.w = W; bbox.exactW = true;
  743. if (!parent.bbox) {parent.bbox = bbox}
  744. }
  745. //
  746. // Remove markers
  747. //
  748. for (i = 0, m = spans.length; i < m; i++) {
  749. span = spans[i];
  750. if (span[1]) {span[1].parentNode.removeChild(span[1]), span[0].style.position = span[3]}
  751. if (span[2]) {span[2].parentNode.removeChild(span[2])}
  752. }
  753. },
  754. Em: function (m) {
  755. if (Math.abs(m) < .0006) {return "0em"}
  756. return m.toFixed(3).replace(/\.?0+$/,"") + "em";
  757. },
  758. unEm: function (m) {
  759. return parseFloat(m);
  760. },
  761. Px: function (m) {
  762. m *= this.em; var s = (m < 0? "-" : "");
  763. return s+Math.abs(m).toFixed(1).replace(/\.?0+$/,"") + "px";
  764. },
  765. unPx: function (m) {
  766. return parseFloat(m)/this.em;
  767. },
  768. Percent: function (m) {
  769. return (100*m).toFixed(1).replace(/\.?0+$/,"") + "%";
  770. },
  771. length2em: function (length,mu,size) {
  772. if (typeof(length) !== "string") {length = length.toString()}
  773. if (length === "") {return ""}
  774. if (length === MML.SIZE.NORMAL) {return 1}
  775. if (length === MML.SIZE.BIG) {return 2}
  776. if (length === MML.SIZE.SMALL) {return .71}
  777. if (length === "infinity") {return HTMLCSS.BIGDIMEN}
  778. var factor = this.FONTDATA.TeX_factor;
  779. if (length.match(/mathspace$/)) {return HTMLCSS.MATHSPACE[length]*factor}
  780. var match = length.match(/^\s*([-+]?(?:\.\d+|\d+(?:\.\d*)?))?(pt|em|ex|mu|px|pc|in|mm|cm|%)?/);
  781. var m = parseFloat(match[1]||"1"), unit = match[2];
  782. if (size == null) {size = 1}; if (mu == null) {mu = 1}
  783. if (unit === "em") {return m * factor}
  784. if (unit === "ex") {return m * HTMLCSS.TeX.x_height * factor}
  785. if (unit === "%") {return m / 100 * size}
  786. if (unit === "px") {return m / HTMLCSS.em}
  787. if (unit === "pt") {return m / 10 * factor} // 10 pt to an em
  788. if (unit === "pc") {return m * 1.2 * factor} // 12 pt to a pc
  789. if (unit === "in") {return m * this.pxPerInch / HTMLCSS.em}
  790. if (unit === "cm") {return m * this.pxPerInch / HTMLCSS.em / 2.54} // 2.54 cm to an inch
  791. if (unit === "mm") {return m * this.pxPerInch / HTMLCSS.em / 25.4} // 10 mm to a cm
  792. if (unit === "mu") {return m / 18 * factor * mu} // 18mu to an em for the scriptlevel
  793. return m*factor*size; // relative to given size (or 1em as default)
  794. },
  795. thickness2em: function (length,mu) {
  796. var thick = HTMLCSS.TeX.rule_thickness;
  797. if (length === MML.LINETHICKNESS.MEDIUM) {return thick}
  798. if (length === MML.LINETHICKNESS.THIN) {return .67*thick}
  799. if (length === MML.LINETHICKNESS.THICK) {return 1.67*thick}
  800. return this.length2em(length,mu,thick);
  801. },
  802. getPadding: function (span) {
  803. var padding = {top:0, right:0, bottom:0, left:0}, has = false;
  804. for (var id in padding) {if (padding.hasOwnProperty(id)) {
  805. var pad = span.style["padding"+id.charAt(0).toUpperCase()+id.substr(1)];
  806. if (pad) {padding[id] = this.length2em(pad); has = true;}
  807. }}
  808. return (has ? padding : false);
  809. },
  810. getBorders: function (span) {
  811. var border = {top:0, right:0, bottom:0, left:0}, css = {}, has = false;
  812. for (var id in border) {if (border.hasOwnProperty(id)) {
  813. var ID = "border"+id.charAt(0).toUpperCase()+id.substr(1);
  814. var style = span.style[ID+"Style"];
  815. if (style) {
  816. has = true;
  817. border[id] = this.length2em(span.style[ID+"Width"]);
  818. css[ID] = [span.style[ID+"Width"],span.style[ID+"Style"],span.style[ID+"Color"]].join(" ");
  819. }
  820. }}
  821. border.css = css;
  822. return (has ? border : false);
  823. },
  824. setBorders: function (span,borders) {
  825. if (borders) {
  826. for (var id in borders.css) {if (borders.css.hasOwnProperty(id)) {
  827. span.style[id] = borders.css[id];
  828. }}
  829. }
  830. },
  831. createStrut: function (span,h,before) {
  832. var strut = this.Element("span",{
  833. isMathJax: true,
  834. style:{display:"inline-block", overflow:"hidden", height:h+"px",
  835. width:"1px", marginRight:"-1px"}
  836. });
  837. if (before) {span.insertBefore(strut,span.firstChild)} else {span.appendChild(strut)}
  838. return strut;
  839. },
  840. createBlank: function (span,w,before) {
  841. var blank = this.Element("span",{
  842. isMathJax: true,
  843. style: {display:"inline-block", overflow:"hidden", height:"1px", width:this.Em(w)}
  844. });
  845. if (before) {span.insertBefore(blank,span.firstChild)} else {span.appendChild(blank)}
  846. return blank;
  847. },
  848. createShift: function (span,w,before) {
  849. var space = this.Element("span",{style:{marginLeft:this.Em(w)}, isMathJax:true});
  850. if (before) {span.insertBefore(space,span.firstChild)} else {span.appendChild(space)}
  851. return space;
  852. },
  853. createSpace: function (span,h,d,w,color,isSpace) {
  854. if (h < -d) {d = -h} // make sure h is above d
  855. var H = this.Em(h+d), D = this.Em(-d);
  856. if (this.msieInlineBlockAlignBug) {D = this.Em(HTMLCSS.getHD(span.parentNode).d-d)}
  857. if (span.isBox || isSpace) {
  858. var scale = (span.scale == null ? 1 : span.scale);
  859. span.bbox = {exactW: true, h: h*scale, d: d*scale, w: w*scale, rw: w*scale, lw: 0};
  860. span.style.height = H; span.style.verticalAlign = D;
  861. span.HH = (h+d)*scale;
  862. } else {
  863. span = this.addElement(span,"span",{style: {height:H, verticalAlign:D}, isMathJax:true});
  864. }
  865. if (w >= 0) {
  866. span.style.width = this.Em(w);
  867. span.style.display = "inline-block";
  868. span.style.overflow = "hidden"; // for IE in quirks mode
  869. } else {
  870. if (this.msieNegativeSpaceBug) {span.style.height = ""}
  871. span.style.marginLeft = this.Em(w);
  872. if (HTMLCSS.safariNegativeSpaceBug && span.parentNode.firstChild == span)
  873. {this.createBlank(span,0,true)}
  874. }
  875. if (color && color !== MML.COLOR.TRANSPARENT) {
  876. span.style.backgroundColor = color;
  877. span.style.position = "relative"; // make sure it covers earlier items
  878. }
  879. return span;
  880. },
  881. createRule: function (span,h,d,w,color) {
  882. if (h < -d) {d = -h} // make sure h is above d
  883. var min = HTMLCSS.TeX.min_rule_thickness, f = 1;
  884. // If rule is very thin, make it at least min_rule_thickness so it doesn't disappear
  885. if (w > 0 && w*this.em < min) {w = min/this.em}
  886. if (h+d > 0 && (h+d)*this.em < min) {f = 1/(h+d)*(min/this.em); h *= f; d *= f}
  887. if (!color) {color = "solid"} else {color = "solid "+color}
  888. color = this.Em(w)+" "+color;
  889. var H = (f === 1 ? this.Em(h+d) : min+"px"), D = this.Em(-d);
  890. var rule = this.addElement(span,"span",{
  891. style: {borderLeft: color, display: "inline-block", overflow:"hidden",
  892. width:0, height:H, verticalAlign:D},
  893. bbox: {h:h, d:d, w:w, rw:w, lw:0, exactW:true}, noAdjust:true, HH:h+d, isMathJax:true
  894. });
  895. if (w > 0 && rule.offsetWidth == 0) {rule.style.width = this.Em(w)}
  896. if (span.isBox || span.className == "mspace") {span.bbox = rule.bbox, span.HH = h+d}
  897. return rule;
  898. },
  899. createFrame: function (span,h,d,w,t,style) {
  900. if (h < -d) {d = -h} // make sure h is above d
  901. var T = 2*t;
  902. if (this.msieFrameSizeBug) {if (w < T) {w = T}; if (h+d < T) {h = T-d}}
  903. if (this.msieBorderWidthBug) {T = 0}
  904. var H = this.Em(h+d-T), D = this.Em(-d-t), W = this.Em(w-T);
  905. var B = this.Em(t)+" "+style;
  906. var frame = this.addElement(span,"span",{
  907. style: {border: B, display:"inline-block", overflow:"hidden", width:W, height:H},
  908. bbox: {h:h, d:d, w:w, rw:w, lw:0, exactW:true}, noAdjust: true, HH:h+d, isMathJax:true
  909. });
  910. if (D) {frame.style.verticalAlign = D}
  911. return frame;
  912. },
  913. createStack: function (span,nobbox,w) {
  914. if (this.msiePaddingWidthBug) {this.createStrut(span,0)}
  915. var relativeW = String(w).match(/%$/);
  916. var W = (!relativeW && w != null ? w : 0);
  917. span = this.addElement(span,"span",{
  918. noAdjust: true, HH: 0, isMathJax: true,
  919. style: {display:"inline-block", position:"relative",
  920. width:(relativeW ? "100%" : this.Em(W)), height:0}
  921. });
  922. if (!nobbox) {
  923. span.parentNode.bbox = span.bbox = {
  924. exactW: true,
  925. h: -this.BIGDIMEN, d: -this.BIGDIMEN,
  926. w:W, lw: this.BIGDIMEN, rw: (!relativeW && w != null ? w : -this.BIGDIMEN)
  927. };
  928. if (relativeW) {span.bbox.width = w}
  929. }
  930. return span;
  931. },
  932. createBox: function (span,w) {
  933. var box = this.addElement(span,"span",{style:{position:"absolute"}, isBox: true, isMathJax:true});
  934. if (w != null) {box.style.width = w}
  935. return box;
  936. },
  937. addBox: function (span,box) {
  938. box.style.position = "absolute"; box.isBox = box.isMathJax = true;
  939. return span.appendChild(box);
  940. },
  941. placeBox: function (span,x,y,noclip) {
  942. span.isMathJax = true;
  943. var parent = span.parentNode, bbox = span.bbox, BBOX = parent.bbox;
  944. if (this.msiePlaceBoxBug) {this.addText(span,this.NBSP)}
  945. if (this.imgSpaceBug) {this.addText(span,this.imgSpace)}
  946. // Place the box
  947. var HH, dx = 0;
  948. if (span.HH != null) {HH = span.HH}
  949. else if (bbox) {HH = Math.max(3,bbox.h+bbox.d)}
  950. else {HH = span.offsetHeight/this.em}
  951. if (!span.noAdjust) {
  952. HH += 1;
  953. HH = Math.round(HH*this.em)/this.em; // make this an integer number of pixels (for Chrome)
  954. if (this.msieInlineBlockAlignBug) {
  955. this.addElement(span,"img",{
  956. className:"MathJax_strut", border:0, src:"about:blank", isMathJax:true,
  957. style:{width:0,height:this.Em(HH)}
  958. });
  959. } else {
  960. this.addElement(span,"span",{
  961. isMathJax: true, style:{display:"inline-block",width:0,height:this.Em(HH)}
  962. });
  963. if (HTMLCSS.chromeHeightBug)
  964. {HH -= (span.lastChild.offsetHeight - Math.round(HH*this.em))/this.em}
  965. }
  966. }
  967. // Clip so that bbox doesn't include extra height and depth
  968. if (bbox) {
  969. if (this.initialSkipBug) {
  970. if (bbox.lw < 0) {dx = bbox.lw; HTMLCSS.createBlank(span,-dx,true)}
  971. if (bbox.rw > bbox.w) {HTMLCSS.createBlank(span,bbox.rw-bbox.w+.1)}
  972. }
  973. if (!this.msieClipRectBug && !bbox.noclip && !noclip) {
  974. var dd = 3/this.em;
  975. var H = (bbox.H == null ? bbox.h : bbox.H), D = (bbox.D == null ? bbox.d : bbox.D);
  976. var t = HH - H - dd, b = HH + D + dd, l = bbox.lw - 3*dd, r = 1000;
  977. if (this.initialSkipBug && bbox.lw < 0) {l = -3*dd}
  978. if (bbox.isFixed) {r = bbox.width-l}
  979. span.style.clip = "rect("+this.Em(t)+" "+this.Em(r)+" "+this.Em(b)+" "+this.Em(l)+")";
  980. }
  981. }
  982. // Place the box
  983. span.style.top = this.Em(-y-HH);
  984. span.style.left = this.Em(x+dx);
  985. // Update the bounding box
  986. if (bbox && BBOX) {
  987. if (bbox.H != null && (BBOX.H == null || bbox.H + y > BBOX.H)) {BBOX.H = bbox.H + y}
  988. if (bbox.D != null && (BBOX.D == null || bbox.D - y > BBOX.D)) {BBOX.D = bbox.D - y}
  989. if (bbox.h + y > BBOX.h) {BBOX.h = bbox.h + y}
  990. if (bbox.d - y > BBOX.d) {BBOX.d = bbox.d - y}
  991. if (BBOX.H != null && BBOX.H <= BBOX.h) {delete BBOX.H}
  992. if (BBOX.D != null && BBOX.D <= BBOX.d) {delete BBOX.D}
  993. if (bbox.w + x > BBOX.w) {
  994. BBOX.w = bbox.w + x;
  995. if (BBOX.width == null) {parent.style.width = this.Em(BBOX.w)}
  996. }
  997. if (bbox.rw + x > BBOX.rw) {BBOX.rw = bbox.rw + x}
  998. if (bbox.lw + x < BBOX.lw) {BBOX.lw = bbox.lw + x}
  999. if (bbox.width != null && !bbox.isFixed) {
  1000. if (BBOX.width == null) {parent.style.width = BBOX.width = "100%"}
  1001. span.style.width = bbox.width;
  1002. }
  1003. }
  1004. },
  1005. alignBox: function (span,align,y) {
  1006. this.placeBox(span,0,y); // set y position (and left aligned)
  1007. var bbox = span.bbox; if (bbox.isMultiline) return;
  1008. var isRelative = bbox.width != null && !bbox.isFixed;
  1009. var r = 0, c = -bbox.w/2, l = "50%";
  1010. if (this.initialSkipBug) {r = bbox.w-bbox.rw-.1; c += bbox.lw}
  1011. if (this.msieMarginScaleBug) {c = (c*this.em) + "px"} else {c = this.Em(c)}
  1012. if (isRelative) {c = ""; l = (50 - parseFloat(bbox.width)/2) + "%"}
  1013. HUB.Insert(span.style,({
  1014. right: {left:"", right: this.Em(r)},
  1015. center: {left:l, marginLeft: c}
  1016. })[align]);
  1017. },
  1018. setStackWidth: function (span,w) {
  1019. if (typeof(w) === "number") {
  1020. span.style.width = this.Em(Math.max(0,w));
  1021. var bbox = span.bbox; if (bbox) {bbox.w = w; bbox.exactW = true};
  1022. bbox = span.parentNode.bbox; if (bbox) {bbox.w = w; bbox.exactW = true};
  1023. } else {
  1024. span.style.width = span.parentNode.style.width = "100%";
  1025. if (span.bbox) {span.bbox.width = w}
  1026. if (span.parentNode.bbox) {span.parentNode.bbox.width = w}
  1027. }
  1028. },
  1029. createDelimiter: function (span,code,HW,scale,font) {
  1030. if (!code) {
  1031. span.bbox = {h:0, d:0, w:this.TeX.nulldelimiterspace, lw: 0};
  1032. span.bbox.rw = span.bbox.w;
  1033. this.createSpace(span,span.bbox.h,span.bbox.d,span.bbox.w);
  1034. return;
  1035. }
  1036. if (!scale) {scale = 1};
  1037. if (!(HW instanceof Array)) {HW = [HW,HW]}
  1038. var hw = HW[1]; HW = HW[0];
  1039. var delim = {alias: code};
  1040. while (delim.alias) {
  1041. code = delim.alias; delim = this.FONTDATA.DELIMITERS[code];
  1042. if (!delim) {delim = {HW: [0,this.FONTDATA.VARIANT[MML.VARIANT.NORMAL]]}}
  1043. }
  1044. if (delim.load) {HUB.RestartAfter(AJAX.Require(this.fontDir+"/fontdata-"+delim.load+".js"))}
  1045. for (var i = 0, m = delim.HW.length; i < m; i++) {
  1046. if (delim.HW[i][0]*scale >= HW-.01 || (i == m-1 && !delim.stretch)) {
  1047. if (delim.HW[i][2]) {scale *= delim.HW[i][2]}
  1048. if (delim.HW[i][3]) {code = delim.HW[i][3]}
  1049. var chr = this.addElement(span,"span");
  1050. this.createChar(chr,[code,delim.HW[i][1]],scale,font);
  1051. span.bbox = chr.bbox;
  1052. span.offset = .65 * span.bbox.w;
  1053. span.scale = scale;
  1054. return;
  1055. }
  1056. }
  1057. if (delim.stretch) {this["extendDelimiter"+delim.dir](span,hw,delim.stretch,scale,font)}
  1058. },
  1059. extendDelimiterV: function (span,H,delim,scale,font) {
  1060. var stack = this.createStack(span,true);
  1061. var top = this.createBox(stack), bot = this.createBox(stack);
  1062. this.createChar(top,(delim.top||delim.ext),scale,font);
  1063. this.createChar(bot,(delim.bot||delim.ext),scale,font);
  1064. var ext = {bbox:{w:0,lw:0,rw:0}}, mid = ext, EXT;
  1065. var h = top.bbox.h + top.bbox.d + bot.bbox.h + bot.bbox.d;
  1066. var y = -top.bbox.h; this.placeBox(top,0,y,true); y -= top.bbox.d;
  1067. if (delim.mid) {
  1068. mid = this.createBox(stack); this.createChar(mid,delim.mid,scale,font);
  1069. h += mid.bbox.h + mid.bbox.d;
  1070. }
  1071. if (delim.min && H < h*delim.min) {H = h*delim.min}
  1072. if (H > h) {
  1073. ext = this.Element("span"); this.createChar(ext,delim.ext,scale,font);
  1074. var eH = ext.bbox.h + ext.bbox.d, eh = eH - .05, n, N, k = (delim.mid ? 2 : 1);
  1075. N = n = Math.ceil((H-h)/(k*eh));
  1076. if (!delim.fullExtenders) {eh = (H-h)/(k*n)}
  1077. var dy = (n/(n+1))*(eH - eh); eh = eH - dy; y += dy + eh - ext.bbox.h;
  1078. while (k-- > 0) {
  1079. while (n-- > 0) {
  1080. if (!this.msieCloneNodeBug) {EXT = ext.cloneNode(true)}
  1081. else {EXT = this.Element("span"); this.createChar(EXT,delim.ext,scale,font)}
  1082. EXT.bbox = ext.bbox;
  1083. y -= eh; this.placeBox(this.addBox(stack,EXT),0,y,true);
  1084. }
  1085. y += dy - ext.bbox.d;
  1086. if (delim.mid && k) {
  1087. this.placeBox(mid,0,y-mid.bbox.h,true); n = N;
  1088. y += -(mid.bbox.h + mid.bbox.d) + dy + eh - ext.bbox.h;
  1089. }
  1090. }
  1091. } else {
  1092. y += (h - H)/2;
  1093. if (delim.mid) {this.placeBox(mid,0,y-mid.bbox.h,true); y += -(mid.bbox.h + mid.bbox.d)}
  1094. y += (h - H)/2;
  1095. }
  1096. this.placeBox(bot,0,y-bot.bbox.h,true); y -= bot.bbox.h + bot.bbox.d;
  1097. span.bbox = {
  1098. w: Math.max(top.bbox.w,ext.bbox.w,bot.bbox.w,mid.bbox.w),
  1099. lw: Math.min(top.bbox.lw,ext.bbox.lw,bot.bbox.lw,mid.bbox.lw),
  1100. rw: Math.max(top.bbox.rw,ext.bbox.rw,bot.bbox.rw,mid.bbox.rw),
  1101. h: 0, d: -y, exactW: true
  1102. }
  1103. span.scale = scale;
  1104. span.offset = .55 * span.bbox.w;
  1105. span.isMultiChar = true;
  1106. this.setStackWidth(stack,span.bbox.w);
  1107. },
  1108. extendDelimiterH: function (span,W,delim,scale,font) {
  1109. var stack = this.createStack(span,true);
  1110. var left = this.createBox(stack), right = this.createBox(stack);
  1111. this.createChar(left,(delim.left||delim.rep),scale,font);
  1112. this.createChar(right,(delim.right||delim.rep),scale,font);
  1113. var rep = this.Element("span"); this.createChar(rep,delim.rep,scale,font);
  1114. var mid = {bbox: {h:-this.BIGDIMEN, d:-this.BIGDIMEN}}, REP;
  1115. this.placeBox(left,-left.bbox.lw,0,true);
  1116. var w = (

Large files files are truncated, but you can click here to view the full file