PageRenderTime 82ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  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 = (left.bbox.rw - left.bbox.lw) + (right.bbox.rw - right.bbox.lw) - .05,
  1117. x = left.bbox.rw - left.bbox.lw - .025, dx;
  1118. if (delim.mid) {
  1119. mid = this.createBox(stack); this.createChar(mid,delim.mid,scale,font);
  1120. w += mid.bbox.w;
  1121. }
  1122. if (delim.min && W < w*delim.min) {W = w*delim.min}
  1123. if (W > w) {
  1124. var rW = rep.bbox.rw-rep.bbox.lw, rw = rW - .05, n, N, k = (delim.mid ? 2 : 1);
  1125. N = n = Math.ceil((W-w)/(k*rw));
  1126. if (!delim.fillExtenders) {rw = (W-w)/(k*n)}
  1127. dx = (n/(n+1))*(rW - rw); rw = rW - dx; x -= rep.bbox.lw + dx;
  1128. while (k-- > 0) {
  1129. while (n-- > 0) {
  1130. if (!this.cloneNodeBug) {REP = rep.cloneNode(true)}
  1131. else {REP = this.Element("span"); this.createChar(REP,delim.rep,scale,font)}
  1132. REP.bbox = rep.bbox;
  1133. this.placeBox(this.addBox(stack,REP),x,0,true); x += rw;
  1134. }
  1135. if (delim.mid && k) {this.placeBox(mid,x,0,true); x += mid.bbox.w - dx; n = N}
  1136. }
  1137. } else {
  1138. x -= (w - W)/2;
  1139. if (delim.mid) {this.placeBox(mid,x,0,true); x += mid.bbox.w};
  1140. x -= (w - W)/2;
  1141. }
  1142. this.placeBox(right,x,0,true);
  1143. span.bbox = {
  1144. w: x+right.bbox.rw, lw: 0, rw: x+right.bbox.rw,
  1145. H: Math.max(left.bbox.h,rep.bbox.h,right.bbox.h,mid.bbox.h),
  1146. D: Math.max(left.bbox.d,rep.bbox.d,right.bbox.d,mid.bbox.d),
  1147. h: rep.bbox.h, d: rep.bbox.d, exactW: true
  1148. }
  1149. span.scale = scale;
  1150. span.isMultiChar = true;
  1151. this.setStackWidth(stack,span.bbox.w);
  1152. },
  1153. createChar: function (span,data,scale,font) {
  1154. span.isMathJax = true;
  1155. var SPAN = span, text = "", variant = {fonts: [data[1]], noRemap:true};
  1156. if (font && font === MML.VARIANT.BOLD) {variant.fonts = [data[1]+"-bold",data[1]]}
  1157. if (typeof(data[1]) !== "string") {variant = data[1]}
  1158. if (data[0] instanceof Array) {
  1159. for (var i = 0, m = data[0].length; i < m; i++) {text += String.fromCharCode(data[0][i])}
  1160. } else {text = String.fromCharCode(data[0])}
  1161. if (data[4]) {scale *= data[4]}
  1162. if (scale !== 1 || data[3]) {
  1163. SPAN = this.addElement(span,"span",{style:{fontSize: this.Percent(scale)}, scale:scale, isMathJax:true});
  1164. this.handleVariant(SPAN,variant,text);
  1165. span.bbox = SPAN.bbox;
  1166. } else {this.handleVariant(span,variant,text)}
  1167. if (data[2]) {span.style.marginLeft = this.Em(data[2])} // x offset
  1168. if (data[3]) { // y offset
  1169. span.firstChild.style.verticalAlign = this.Em(data[3]);
  1170. span.bbox.h += data[3]; if (span.bbox.h < 0) {span.bbox.h = 0}
  1171. }
  1172. if (data[5]) {span.bbox.h += data[5]} // extra height
  1173. if (data[6]) {span.bbox.d += data[6]} // extra depth
  1174. // Handle combining characters by adding a non-breaking space so it shows up
  1175. if (this.AccentBug && span.bbox.w === 0) {SPAN.firstChild.nodeValue += this.NBSP}
  1176. },
  1177. positionDelimiter: function (span,h) {
  1178. h -= span.bbox.h; span.bbox.d -= h; span.bbox.h += h;
  1179. if (h) {
  1180. if (this.safariVerticalAlignBug || this.konquerorVerticalAlignBug ||
  1181. (this.operaVerticalAlignBug && span.isMultiChar)) {
  1182. if (span.firstChild.style.display === "" && span.style.top !== "")
  1183. {span = span.firstChild; h -= HTMLCSS.unEm(span.style.top)}
  1184. span.style.position = "relative";
  1185. span.style.top = this.Em(-h);
  1186. } else {
  1187. span.style.verticalAlign = this.Em(h);
  1188. if (HTMLCSS.ffVerticalAlignBug) {HTMLCSS.createRule(span.parentNode,span.bbox.h,0,0)}
  1189. }
  1190. }
  1191. },
  1192. handleVariant: function (span,variant,text) {
  1193. var newtext = "", n, c, font, VARIANT, SPAN = span, force = !!span.style.fontFamily;
  1194. if (text.length === 0) return;
  1195. if (!span.bbox) {
  1196. span.bbox = {
  1197. w: 0, h: -this.BIGDIMEN, d: -this.BIGDIMEN,
  1198. rw: -this.BIGDIMEN, lw: this.BIGDIMEN
  1199. };
  1200. }
  1201. if (!variant) {variant = this.FONTDATA.VARIANT[MML.VARIANT.NORMAL]}
  1202. VARIANT = variant;
  1203. for (var i = 0, m = text.length; i < m; i++) {
  1204. variant = VARIANT;
  1205. n = text.charCodeAt(i); c = text.charAt(i);
  1206. if (n >= 0xD800 && n < 0xDBFF) {
  1207. i++; n = (((n-0xD800)<<10)+(text.charCodeAt(i)-0xDC00))+0x10000;
  1208. if (this.FONTDATA.RemapPlane1) {
  1209. var nv = this.FONTDATA.RemapPlane1(n,variant);
  1210. n = nv.n; variant = nv.variant;
  1211. }
  1212. } else {
  1213. var id, M, RANGES = this.FONTDATA.RANGES;
  1214. for (id = 0, M = RANGES.length; id < M; id++) {
  1215. if (RANGES[id].name === "alpha" && variant.noLowerCase) continue;
  1216. var N = variant["offset"+RANGES[id].offset];
  1217. if (N && n >= RANGES[id].low && n <= RANGES[id].high) {
  1218. if (RANGES[id].remap && RANGES[id].remap[n]) {
  1219. n = N + RANGES[id].remap[n];
  1220. } else {
  1221. n = n - RANGES[id].low + N;
  1222. if (RANGES[id].add) {n += RANGES[id].add}
  1223. }
  1224. if (variant["variant"+RANGES[id].offset])
  1225. {variant = this.FONTDATA.VARIANT[variant["variant"+RANGES[id].offset]]}
  1226. break;
  1227. }
  1228. }
  1229. }
  1230. if (variant.remap && variant.remap[n]) {
  1231. if (variant.remap[n] instanceof Array) {
  1232. var remap = variant.remap[n];
  1233. n = remap[0]; variant = this.FONTDATA.VARIANT[remap[1]];
  1234. } else if (typeof(variant.remap[n]) === "string") {
  1235. text = variant.remap[n]+text.substr(i+1);
  1236. i = 0; m = text.length; n = text.charCodeAt(0);
  1237. } else {
  1238. n = variant.remap[n];
  1239. if (variant.remap.variant) {variant = this.FONTDATA.VARIANT[variant.remap.variant]}
  1240. }
  1241. }
  1242. if (this.FONTDATA.REMAP[n] && !variant.noRemap) {
  1243. n = this.FONTDATA.REMAP[n];
  1244. if (n instanceof Array) {variant = this.FONTDATA.VARIANT[n[1]]; n = n[0]}
  1245. if (typeof(n) === "string") {
  1246. text = n+text.substr(i+1);
  1247. i = 0; m = text.length; n = n.charCodeAt(0);
  1248. }
  1249. }
  1250. font = this.lookupChar(variant,n); c = font[n];
  1251. if (force || (!this.checkFont(font,SPAN.style) && !c[5].img)) {
  1252. if (newtext.length) {this.addText(SPAN,newtext); newtext = ""};
  1253. var addSpan = !!SPAN.style.fontFamily || !!span.style.fontStyle ||
  1254. !!span.style.fontWeight || !font.directory || force; force = false;
  1255. if (SPAN !== span) {addSpan = !this.checkFont(font,span.style); SPAN = span}
  1256. if (addSpan) {SPAN = this.addElement(span,"span",{isMathJax:true, subSpan:true})}
  1257. this.handleFont(SPAN,font,SPAN !== span);
  1258. }
  1259. newtext = this.handleChar(SPAN,font,c,n,newtext);
  1260. if (!(c[5]||{}).space) {
  1261. if (c[0]/1000 > span.bbox.h) {span.bbox.h = c[0]/1000}
  1262. if (c[1]/1000 > span.bbox.d) {span.bbox.d = c[1]/1000}
  1263. }
  1264. if (span.bbox.w + c[3]/1000 < span.bbox.lw) {span.bbox.lw = span.bbox.w + c[3]/1000}
  1265. if (span.bbox.w + c[4]/1000 > span.bbox.rw) {span.bbox.rw = span.bbox.w + c[4]/1000}
  1266. span.bbox.w += c[2]/1000;
  1267. }
  1268. if (newtext.length) {this.addText(SPAN,newtext)}
  1269. if (span.scale && span.scale !== 1) {
  1270. span.bbox.h *= span.scale; span.bbox.d *= span.scale;
  1271. span.bbox.w *= span.scale; span.bbox.lw *= span.scale; span.bbox.rw *= span.scale;
  1272. }
  1273. if (text.length == 1 && font.skew && font.skew[n]) {span.bbox.skew = font.skew[n]}
  1274. },
  1275. checkFont: function (font,style) {
  1276. var weight = (style.fontWeight||"normal");
  1277. if (weight.match(/^\d+$/)) {weight = (parseInt(weight) >= 600 ? "bold" : "normal")}
  1278. return (font.family.replace(/'/g,"") === style.fontFamily.replace(/'/g,"") &&
  1279. (font.style||"normal") === (style.fontStyle||"normal") &&
  1280. (font.weight||"normal") === weight);
  1281. },
  1282. handleFont: function (span,font,force) {
  1283. span.style.fontFamily = font.family;
  1284. if (!font.directory) {span.style.fontSize = Math.floor(100/HTMLCSS.scale+.5) + "%"}
  1285. if (!(HTMLCSS.FontFaceBug && font.isWebFont)) {
  1286. var style = font.style || "normal", weight = font.weight || "normal";
  1287. if (style !== "normal" || force) {span.style.fontStyle = style}
  1288. if (weight !== "normal" || force) {span.style.fontWeight = weight}
  1289. }
  1290. },
  1291. handleChar: function (span,font,c,n,text) {
  1292. var C = c[5];
  1293. if (C.space) {
  1294. if (text.length) {this.addText(span,text)}
  1295. HTMLCSS.createShift(span,c[2]/1000);
  1296. return "";
  1297. }
  1298. if (C.img) {return this.handleImg(span,font,c,n,text)}
  1299. if (C.isUnknown && this.FONTDATA.DELIMITERS[n]) {
  1300. if (text.length) {this.addText(span,text)}
  1301. var scale = span.scale;
  1302. HTMLCSS.createDelimiter(span,n,0,1,font);
  1303. if (this.FONTDATA.DELIMITERS[n].dir === "V") {
  1304. span.style.verticalAlign = this.Em(span.bbox.d);
  1305. span.bbox.h += span.bbox.d; span.bbox.d = 0;
  1306. }
  1307. span.scale = scale;
  1308. c[0] = span.bbox.h*1000; c[1] = span.bbox.d*1000;
  1309. c[2] = span.bbox.w*1000; c[3] = span.bbox.lw*1000; c[4] = span.bbox.rw*1000;
  1310. return "";
  1311. }
  1312. if (C.c == null) {
  1313. if (n <= 0xFFFF) {C.c = String.fromCharCode(n)} else {
  1314. var N = n - 0x10000;
  1315. C.c = String.fromCharCode((N>>10)+0xD800)
  1316. + String.fromCharCode((N&0x3FF)+0xDC00);
  1317. }
  1318. }
  1319. if (C.rfix) {this.addText(span,text+C.c); HTMLCSS.createShift(span,C.rfix/1000); return ""}
  1320. if (c[2] || !this.msieAccentBug || text.length) {return text + C.c}
  1321. // Handle IE accent clipping bug
  1322. HTMLCSS.createShift(span,c[3]/1000);
  1323. HTMLCSS.createShift(span,(c[4]-c[3])/1000);
  1324. this.addText(span,C.c);
  1325. HTMLCSS.createShift(span,-c[4]/1000);
  1326. return "";
  1327. },
  1328. handleImg: function (span,font,c,n,text) {return text}, // replaced by imageFont extension
  1329. lookupChar: function (variant,n) {
  1330. var i, m;
  1331. if (!variant.FONTS) {
  1332. var FONTS = this.FONTDATA.FONTS;
  1333. var fonts = (variant.fonts || this.FONTDATA.VARIANT.normal.fonts);
  1334. if (!(fonts instanceof Array)) {fonts = [fonts]}
  1335. if (variant.fonts != fonts) {variant.fonts = fonts}
  1336. variant.FONTS = [];
  1337. for (i = 0, m = fonts.length; i < m; i++) {
  1338. if (FONTS[fonts[i]]) {
  1339. variant.FONTS.push(FONTS[fonts[i]]);
  1340. FONTS[fonts[i]].name = fonts[i]; // FIXME: should really be in the font files
  1341. }
  1342. }
  1343. }
  1344. for (i = 0, m = variant.FONTS.length; i < m; i++) {
  1345. var font = variant.FONTS[i];
  1346. if (typeof(font) === "string") {
  1347. delete variant.FONTS; this.loadFont(font);
  1348. }
  1349. if (font[n]) {
  1350. if (font[n].length === 5) {font[n][5] = {}}
  1351. if (HTMLCSS.allowWebFonts && !font.available)
  1352. {this.loadWebFont(font)} else {return font}
  1353. } else {this.findBlock(font,n)}
  1354. }
  1355. return this.unknownChar(variant,n);
  1356. },
  1357. unknownChar: function (variant,n) {
  1358. var unknown = (variant.defaultFont || {family:HTMLCSS.config.undefinedFamily});
  1359. if (variant.bold) {unknown.weight = "bold"}; if (variant.italic) {unknown.style = "italic"}
  1360. if (!unknown[n]) {unknown[n] = [800,200,500,0,500,{isUnknown:true}]} // [h,d,w,lw,rw,{data}]
  1361. HUB.signal.Post(["HTML-CSS Jax - unknown char",n,variant]);
  1362. return unknown;
  1363. },
  1364. findBlock: function (font,c) {
  1365. if (font.Ranges) {
  1366. // FIXME: do binary search?
  1367. for (var i = 0, m = font.Ranges.length; i < m; i++) {
  1368. if (c < font.Ranges[i][0]) return;
  1369. if (c <= font.Ranges[i][1]) {
  1370. var file = font.Ranges[i][2];
  1371. for (var j = font.Ranges.length-1; j >= 0; j--)
  1372. {if (font.Ranges[j][2] == file) {font.Ranges.splice(j,1)}}
  1373. this.loadFont(font.directory+"/"+file+".js");
  1374. }
  1375. }
  1376. }
  1377. },
  1378. loadFont: function (file) {
  1379. var queue = MathJax.Callback.Queue();
  1380. queue.Push(["Require",AJAX,this.fontDir+"/"+file]);
  1381. if (this.imgFonts) {
  1382. if (!MathJax.isPacked) {file = file.replace(/\/([^\/]*)$/,HTMLCSS.imgPacked+"/$1")}
  1383. queue.Push(["Require",AJAX,this.webfontDir+"/png/"+file]);
  1384. }
  1385. HUB.RestartAfter(queue.Push({}));
  1386. },
  1387. loadWebFont: function (font) {
  1388. font.available = font.isWebFont = true;
  1389. if (HTMLCSS.FontFaceBug) {
  1390. font.family = font.name;
  1391. if (HTMLCSS.msieFontCSSBug) {font.family += "-Web"}
  1392. }
  1393. HUB.RestartAfter(this.Font.loadWebFont(font));
  1394. },
  1395. loadWebFontError: function (font,done) {
  1396. //
  1397. // After the first web font fails to load, switch to image fonts, if possible
  1398. // otherwise, give up on web fonts all together
  1399. //
  1400. HUB.Startup.signal.Post("HTML-CSS Jax - disable web fonts");
  1401. font.isWebFont = false;
  1402. if (this.config.imageFont && this.config.imageFont === this.fontInUse) {
  1403. this.imgFonts = true;
  1404. HUB.Startup.signal.Post("HTML-CSS Jax - switch to image fonts");
  1405. HUB.Startup.signal.Post("HTML-CSS Jax - using image fonts");
  1406. MathJax.Message.Set("Web-Fonts not available -- using image fonts instead",null,3000);
  1407. AJAX.Require(this.directory+"/imageFonts.js",done);
  1408. } else {
  1409. this.allowWebFonts = false;
  1410. done();
  1411. }
  1412. },
  1413. Element: MathJax.HTML.Element,
  1414. addElement: MathJax.HTML.addElement,
  1415. TextNode: MathJax.HTML.TextNode,
  1416. addText: MathJax.HTML.addText,
  1417. ucMatch: MathJax.HTML.ucMatch,
  1418. BIGDIMEN: 10000000,
  1419. ID: 0, idPostfix: "",
  1420. GetID: function () {this.ID++; return this.ID},
  1421. MATHSPACE: {
  1422. veryverythinmathspace: 1/18,
  1423. verythinmathspace: 2/18,
  1424. thinmathspace: 3/18,
  1425. mediummathspace: 4/18,
  1426. thickmathspace: 5/18,
  1427. verythickmathspace: 6/18,
  1428. veryverythickmathspace: 7/18,
  1429. negativeveryverythinmathspace: -1/18,
  1430. negativeverythinmathspace: -2/18,
  1431. negativethinmathspace: -3/18,
  1432. negativemediummathspace: -4/18,
  1433. negativethickmathspace: -5/18,
  1434. negativeverythickmathspace: -6/18,
  1435. negativeveryverythickmathspace: -7/18
  1436. },
  1437. TeX: {
  1438. x_height: .430554,
  1439. quad: 1,
  1440. num1: .676508,
  1441. num2: .393732,
  1442. num3: .44373,
  1443. denom1: .685951,
  1444. denom2: .344841,
  1445. sup1: .412892,
  1446. sup2: .362892,
  1447. sup3: .288888,
  1448. sub1: .15,
  1449. sub2: .247217,
  1450. sup_drop: .386108,
  1451. sub_drop: .05,
  1452. delim1: 2.39,
  1453. delim2: 1.0,
  1454. axis_height: .25,
  1455. rule_thickness: .06,
  1456. big_op_spacing1: .111111,
  1457. big_op_spacing2: .166666,
  1458. big_op_spacing3: .2,
  1459. big_op_spacing4: .6,
  1460. big_op_spacing5: .1,
  1461. scriptspace: .1,
  1462. nulldelimiterspace: .12,
  1463. delimiterfactor: 901,
  1464. delimitershortfall: .1, // originally .3,
  1465. min_rule_thickness: 1.25 // in pixels
  1466. },
  1467. NBSP: "\u00A0",
  1468. rfuzz: 0 // adjustment to rule placements in roots
  1469. });
  1470. MathJax.Hub.Register.StartupHook("mml Jax Ready",function () {
  1471. MML = MathJax.ElementJax.mml;
  1472. MML.mbase.Augment({
  1473. toHTML: function (span) {
  1474. span = this.HTMLcreateSpan(span); if (this.type != "mrow") {span = this.HTMLhandleSize(span)}
  1475. for (var i = 0, m = this.data.length; i < m; i++)
  1476. {if (this.data[i]) {this.data[i].toHTML(span)}}
  1477. var stretchy = this.HTMLcomputeBBox(span);
  1478. var h = span.bbox.h, d = span.bbox.d;
  1479. for (i = 0, m = stretchy.length; i < m; i++) {stretchy[i].HTMLstretchV(span,h,d)}
  1480. if (stretchy.length) {this.HTMLcomputeBBox(span,true)}
  1481. if (this.HTMLlineBreaks(span)) {span = this.HTMLmultiline(span)}
  1482. this.HTMLhandleSpace(span);
  1483. this.HTMLhandleColor(span);
  1484. return span;
  1485. },
  1486. HTMLlineBreaks: function () {return false},
  1487. HTMLmultiline: function () {MML.mbase.HTMLautoloadFile("multiline")},
  1488. HTMLcomputeBBox: function (span,full,i,m) {
  1489. if (i == null) {i = 0}; if (m == null) {m = this.data.length}
  1490. var BBOX = span.bbox = {exactW: true}, stretchy = [];
  1491. while (i < m) {
  1492. var core = this.data[i]; if (!core) continue;
  1493. if (!full && core.HTMLcanStretch("Vertical"))
  1494. {stretchy.push(core); core = (core.CoreMO()||core)}
  1495. this.HTMLcombineBBoxes(core,BBOX); i++;
  1496. }
  1497. this.HTMLcleanBBox(BBOX);
  1498. return stretchy;
  1499. },
  1500. HTMLcombineBBoxes: function (core,BBOX) {
  1501. if (BBOX.w == null) {this.HTMLemptyBBox(BBOX)}
  1502. var child = (core.bbox ? core : core.HTMLspanElement());
  1503. if (!child || !child.bbox) return;
  1504. var bbox = child.bbox;
  1505. if (bbox.d > BBOX.d) {BBOX.d = bbox.d}
  1506. if (bbox.h > BBOX.h) {BBOX.h = bbox.h}
  1507. if (bbox.D != null && bbox.D > BBOX.D) {BBOX.D = bbox.D}
  1508. if (bbox.H != null && bbox.H > BBOX.H) {BBOX.H = bbox.H}
  1509. if (child.style.paddingLeft) {BBOX.w += HTMLCSS.unEm(child.style.paddingLeft)*(child.scale||1)}
  1510. if (BBOX.w + bbox.lw < BBOX.lw) {BBOX.lw = BBOX.w + bbox.lw}
  1511. if (BBOX.w + bbox.rw > BBOX.rw) {BBOX.rw = BBOX.w + bbox.rw}
  1512. BBOX.w += bbox.w;
  1513. if (child.style.paddingRight) {BBOX.w += HTMLCSS.unEm(child.style.paddingRight)*(child.scale||1)}
  1514. if (bbox.width) {BBOX.width = bbox.width}
  1515. if (bbox.ic) {BBOX.ic = bbox.ic} else {delete BBOX.ic}
  1516. if (BBOX.exactW && !bbox.exactW) {delete BBOX.exactW}
  1517. },
  1518. HTMLemptyBBox: function (BBOX) {
  1519. BBOX.h = BBOX.d = BBOX.H = BBOX.D = BBOX.rw = -HTMLCSS.BIGDIMEN;
  1520. BBOX.w = 0; BBOX.lw = HTMLCSS.BIGDIMEN;
  1521. return BBOX;
  1522. },
  1523. HTMLcleanBBox: function (BBOX) {
  1524. if (BBOX.h === this.BIGDIMEN)
  1525. {BBOX.h = BBOX.d = BBOX.H = BBOX.D = BBOX.w = BBOX.rw = BBOX.lw = 0}
  1526. if (BBOX.D <= BBOX.d) {delete BBOX.D}; if (BBOX.H <= BBOX.h) {delete BBOX.H}
  1527. },
  1528. HTMLzeroBBox: function () {return {h:0, d:0, w:0, lw: 0, rw:0}},
  1529. HTMLcanStretch: function (direction) {
  1530. if (this.isEmbellished()) {
  1531. var core = this.Core();
  1532. if (core && core !== this) {return core.HTMLcanStretch(direction)}
  1533. }
  1534. return false;
  1535. },
  1536. HTMLstretchH: function (box,W) {return this.HTMLspanElement()},
  1537. HTMLstretchV: function (box,h,d) {return this.HTMLspanElement()},
  1538. HTMLnotEmpty: function (data) {
  1539. while (data) {
  1540. if ((data.type !== "mrow" && data.type !== "texatom") ||
  1541. data.data.length > 1) {return true}
  1542. data = data.data[0];
  1543. }
  1544. return false;
  1545. },
  1546. HTMLmeasureChild: function (n,box) {
  1547. if (this.data[n]) {HTMLCSS.Measured(this.data[n].toHTML(box),box)}
  1548. else {box.bbox = this.HTMLzeroBBox()}
  1549. },
  1550. HTMLboxChild: function (n,box) {
  1551. if (this.data[n]) {return this.data[n].toHTML(box)}
  1552. if (!box.bbox) {box.bbox = this.HTMLzeroBBox()}
  1553. return null;
  1554. },
  1555. HTMLcreateSpan: function (span) {
  1556. if (this.spanID) {
  1557. var SPAN = this.HTMLspanElement();
  1558. if (SPAN && (SPAN.parentNode === span || (SPAN.parentNode||{}).parentNode === span)) {
  1559. while (SPAN.firstChild) {SPAN.removeChild(SPAN.firstChild)}
  1560. SPAN.bbox = {w:0, h:0, d:0, lw:0, rw:0};
  1561. SPAN.scale = 1; SPAN.isMultChar = SPAN.HH = null;
  1562. SPAN.style.cssText = "";
  1563. return SPAN;
  1564. }
  1565. }
  1566. if (this.href) {span = HTMLCSS.addElement(span,"a",{href:this.href, isMathJax:true})}
  1567. span = HTMLCSS.addElement(span,"span",{className: this.type, isMathJax:true});
  1568. if (HTMLCSS.imgHeightBug) {span.style.display = "inline-block"}
  1569. if (this["class"]) {span.className += " "+this["class"]}
  1570. if (!this.spanID) {this.spanID = HTMLCSS.GetID()}
  1571. span.id = (this.id || "MathJax-Span-"+this.spanID) + HTMLCSS.idPostfix;
  1572. span.bbox = {w:0, h:0, d:0, lw:0, rw:0}; this.styles = {};
  1573. if (this.style) {
  1574. span.style.cssText = this.style;
  1575. if (span.style.fontSize) {this.mathsize = span.style.fontSize; span.style.fontSize = ""}
  1576. this.styles = {border:HTMLCSS.getBorders(span), padding:HTMLCSS.getPadding(span)}
  1577. if (this.styles.border) {span.style.border = ""} // IE needs "0px none"?
  1578. if (this.styles.padding) {span.style.padding = ""}
  1579. }
  1580. if (this.href) {span.parentNode.bbox = span.bbox}
  1581. return span;
  1582. },
  1583. HTMLspanElement: function () {
  1584. if (!this.spanID) {return null}
  1585. return document.getElementById((this.id||"MathJax-Span-"+this.spanID)+HTMLCSS.idPostfix);
  1586. },
  1587. HTMLhandleVariant: function (span,variant,text) {HTMLCSS.handleVariant(span,variant,text)},
  1588. HTMLhandleSize: function (span) {
  1589. if (!span.scale) {
  1590. span.scale = this.HTMLgetScale();
  1591. if (span.scale !== 1) {span.style.fontSize = HTMLCSS.Percent(span.scale)}
  1592. }
  1593. return span;
  1594. },
  1595. HTMLhandleColor: function (span) {
  1596. var values = this.getValues("mathcolor","color");
  1597. if (this.mathbackground) {values.mathbackground = this.mathbackground}
  1598. if (this.background) {values.background = this.background}
  1599. if (this.style && span.style.backgroundColor) {
  1600. values.mathbackground = span.style.backgroundColor;
  1601. span.style.backgroundColor = "transparent";
  1602. }
  1603. var borders = (this.styles||{}).border, padding = (this.styles||{}).padding;
  1604. if (values.color && !this.mathcolor) {values.mathcolor = values.color}
  1605. if (values.background && !this.mathbackground) {values.mathbackground = values.background}
  1606. if (values.mathcolor) {span.style.color = values.mathcolor}
  1607. if ((values.mathbackground && values.mathbackground !== MML.COLOR.TRANSPARENT) ||
  1608. borders || padding) {
  1609. var bbox = span.bbox, dd = (bbox.exact ? 0 : 1/HTMLCSS.em), lW = 0, rW = 0,
  1610. lpad = span.style.paddingLeft, rpad = span.style.paddingRight;
  1611. if (this.isToken) {lW = bbox.lw; rW = bbox.rw - bbox.w}
  1612. if (lpad !== "") {lW += HTMLCSS.unEm(lpad)*(span.scale||1)}
  1613. if (rpad !== "") {rW -= HTMLCSS.unEm(rpad)*(span.scale||1)}
  1614. var dw = (HTMLCSS.PaddingWidthBug || bbox.keepPadding || bbox.exactW ? 0 : rW - lW);
  1615. var W = Math.max(0,HTMLCSS.getW(span) + dw);
  1616. var H = bbox.h + bbox.d, D = -bbox.d, lp = 0, rp = 0;
  1617. if (W > 0) {W += 2*dd; lW -= dd}; if (H > 0) {H += 2*dd; D -= dd}; rW = -W-lW;
  1618. if (borders) {
  1619. rW -= borders.right; D -= borders.bottom; lp += borders.left; rp += borders.right;
  1620. bbox.h += borders.top; bbox.d += borders.bottom;
  1621. bbox.w += borders.left + borders.right;
  1622. bbox.lw -= borders.left; bbox.rw += borders.right;
  1623. }
  1624. if (padding) {
  1625. H += padding.top + padding.bottom; W += padding.left + padding.right;
  1626. rW -= padding.right; D -= padding.bottom; lp += padding.left; rp += padding.right;
  1627. bbox.h += padding.top; bbox.d += padding.bottom;
  1628. bbox.w += padding.left + padding.right;
  1629. bbox.lw -= padding.left; bbox.rw += padding.right;
  1630. }
  1631. if (rp) {span.style.paddingRight = HTMLCSS.Em(rp)}
  1632. var frame = HTMLCSS.Element("span",{
  1633. id:"MathJax-Color-"+this.spanID+HTMLCSS.idPostfix, isMathJax: true,
  1634. style:{display:"inline-block", backgroundColor:values.mathbackground,
  1635. width: HTMLCSS.Em(W), height:HTMLCSS.Em(H), verticalAlign: HTMLCSS.Em(D),
  1636. marginLeft: HTMLCSS.Em(lW), marginRight: HTMLCSS.Em(rW)}
  1637. });
  1638. HTMLCSS.setBorders(frame,borders);
  1639. if (bbox.width) {frame.style.width = bbox.width; frame.style.marginRight = "-"+bbox.width}
  1640. if (HTMLCSS.msieInlineBlockAlignBug) {
  1641. // FIXME: handle variable width background
  1642. frame.style.position = "relative"; frame.style.width = frame.style.height = 0;
  1643. frame.style.verticalAlign = frame.style.marginLeft = frame.style.marginRight = "";
  1644. frame.style.border = frame.style.padding = "";
  1645. if (borders && HTMLCSS.msieBorderWidthBug)
  1646. {H += borders.top + borders.bottom; W += borders.left + borders.right}
  1647. frame.style.width = HTMLCSS.Em(lp+dd);
  1648. HTMLCSS.placeBox(HTMLCSS.addElement(frame,"span",{
  1649. noAdjust: true, isMathJax: true,
  1650. style: {display:"inline-block", position:"absolute", overflow:"hidden",
  1651. background:(values.mathbackground||"transparent"),
  1652. width: HTMLCSS.Em(W), height: HTMLCSS.Em(H)}
  1653. }),lW,bbox.h+dd);
  1654. HTMLCSS.setBorders(frame.firstChild,borders);
  1655. }
  1656. span.parentNode.insertBefore(frame,span);
  1657. if (HTMLCSS.msieColorPositionBug) {span.style.position = "relative"}
  1658. return frame;
  1659. }
  1660. return null;
  1661. },
  1662. HTMLremoveColor: function () {
  1663. var color = document.getElementById("MathJax-Color-"+this.spanID+HTMLCSS.idPostfix);
  1664. if (color) {color.parentNode.removeChild(color)}
  1665. },
  1666. HTMLhandleSpace: function (span) {
  1667. if (this.useMMLspacing) {
  1668. if (this.type !== "mo") return;
  1669. var values = this.getValues("scriptlevel","lspace","rspace");
  1670. if (values.scriptlevel <= 0 || this.hasValue("lspace") || this.hasValue("rspace")) {
  1671. var mu = this.HTMLgetMu(span);
  1672. values.lspace = Math.max(0,HTMLCSS.length2em(values.lspace,mu));
  1673. values.rspace = Math.max(0,HTMLCSS.length2em(values.rspace,mu));
  1674. var core = this, parent = this.Parent();
  1675. while (parent && parent.isEmbellished() && parent.Core() === core)
  1676. {core = parent; parent = parent.Parent(); span = core.HTMLspanElement()}
  1677. if (values.lspace) {span.style.paddingLeft = HTMLCSS.Em(values.lspace)}
  1678. if (values.rspace) {span.style.paddingRight = HTMLCSS.Em(values.rspace)}
  1679. }
  1680. } else {
  1681. var space = this.texSpacing();
  1682. if (space !== "") {
  1683. space = HTMLCSS.length2em(space,this.HTMLgetScale())/(span.scale||1);
  1684. if (span.style.paddingLeft) {space += HTMLCSS.unEm(span.style.paddingLeft)}
  1685. span.style.paddingLeft = HTMLCSS.Em(space);
  1686. }
  1687. }
  1688. },
  1689. HTMLgetScale: function () {
  1690. var scale = 1, values = this.getValues("mathsize","scriptlevel","fontsize");
  1691. if (this.style) {
  1692. var span = this.HTMLspanElement();
  1693. if (span.style.fontSize != "") {values.fontsize = span.style.fontSize}
  1694. }
  1695. if (values.fontsize && !this.mathsize) {values.mathsize = values.fontsize}
  1696. if (values.scriptlevel !== 0) {
  1697. if (values.scriptlevel > 2) {values.scriptlevel = 2}
  1698. scale = Math.pow(this.Get("scriptsizemultiplier"),values.scriptlevel);
  1699. values.scriptminsize = HTMLCSS.length2em(this.Get("scriptminsize"));
  1700. if (scale < values.scriptminsize) {scale = values.scriptminsize}
  1701. }
  1702. if (this.isToken) {scale *= HTMLCSS.length2em(values.mathsize)}
  1703. return scale;
  1704. },
  1705. HTMLgetMu: function (span) {
  1706. var mu = 1, values = this.getValues("scriptlevel","scriptsizemultiplier");
  1707. if (span.scale && span.scale !== 1) {mu = 1/span.scale}
  1708. if (values.scriptlevel !== 0) {
  1709. if (values.scriptlevel > 2) {values.scriptlevel = 2}
  1710. mu = Math.sqrt(Math.pow(values.scriptsizemultiplier,values.scriptlevel));
  1711. }
  1712. return mu;
  1713. },
  1714. HTMLgetVariant: function () {
  1715. var values = this.getValues("mathvariant","fontfamily","fontweight","fontstyle");
  1716. values.hasVariant = this.Get("mathvariant",true); // null if not explicitly specified
  1717. if (!values.hasVariant) {
  1718. values.family = values.fontfamily;
  1719. values.weight = values.fontweight;
  1720. values.style = values.fontstyle;
  1721. }
  1722. if (this.style) {
  1723. var span = this.HTMLspanElement();
  1724. if (!values.family && span.style.fontFamily) {values.family = span.style.fontFamily}
  1725. if (!values.weight && span.style.fontWeight) {values.weight = span.style.fontWeight}
  1726. if (!values.style && span.style.fontStyle) {values.style = span.style.fontStyle}
  1727. }
  1728. if (values.weight && values.weight.match(/^\d+$/))
  1729. {values.weight = (parseInt(values.weight) > 600 ? "bold" : "normal")}
  1730. var variant = values.mathvariant; if (this.variantForm) {variant = "-"+HTMLCSS.fontInUse+"-variant"}
  1731. if (values.family && !values.hasVariant) {
  1732. if (!values.weight && values.mathvariant.match(/bold/)) {values.weight = "bold"}
  1733. if (!values.style && values.mathvariant.match(/italic/)) {values.style = "italic"}
  1734. return {FONTS:[], fonts:[], noRemap:true,
  1735. defaultFont: {family:values.family, style:values.style, weight:values.weight}};
  1736. }
  1737. if (values.weight === "bold") {
  1738. variant = {
  1739. normal:MML.VARIANT.BOLD, italic:MML.VARIANT.BOLDITALIC,
  1740. fraktur:MML.VARIANT.BOLDFRAKTUR, script:MML.VARIANT.BOLDSCRIPT,
  1741. "sans-serif":MML.VARIANT.BOLDSANSSERIF,
  1742. "sans-serif-italic":MML.VARIANT.SANSSERIFBOLDITALIC
  1743. }[variant]||variant;
  1744. } else if (values.weight === "normal") {
  1745. variant = {
  1746. bold:MML.VARIANT.normal, "bold-italic":MML.VARIANT.ITALIC,
  1747. "bold-fraktur":MML.VARIANT.FRAKTUR, "bold-script":MML.VARIANT.SCRIPT,
  1748. "bold-sans-serif":MML.VARIANT.SANSSERIF,
  1749. "sans-serif-bold-italic":MML.VARIANT.SANSSERIFITALIC
  1750. }[variant]||variant;
  1751. }
  1752. if (values.style === "italic") {
  1753. variant = {
  1754. normal:MML.VARIANT.ITALIC, bold:MML.VARIANT.BOLDITALIC,
  1755. "sans-serif":MML.VARIANT.SANSSERIFITALIC,
  1756. "bold-sans-serif":MML.VARIANT.SANSSERIFBOLDITALIC
  1757. }[variant]||variant;
  1758. } else if (values.style === "normal") {
  1759. variant = {
  1760. italic:MML.VARIANT.NORMAL, "bold-italic":MML.VARIANT.BOLD,
  1761. "sans-serif-italic":MML.VARIANT.SANSSERIF,
  1762. "sans-serif-bold-italic":MML.VARIANT.BOLDSANSSERIF
  1763. }[variant]||variant;
  1764. }
  1765. return HTMLCSS.FONTDATA.VARIANT[variant];
  1766. }
  1767. },{
  1768. HTMLautoload: function () {
  1769. var file = HTMLCSS.autoloadDir+"/"+this.type+".js";
  1770. HUB.RestartAfter(AJAX.Require(file));
  1771. },
  1772. HTMLautoloadFile: function (name) {
  1773. var file = HTMLCSS.autoloadDir+"/"+name+".js";
  1774. HUB.RestartAfter(AJAX.Require(file));
  1775. },
  1776. HTMLstretchH: function (box,w) {
  1777. this.HTMLremoveColor();
  1778. return this.toHTML(box,w);
  1779. },
  1780. HTMLstretchV: function (box,h,d) {
  1781. this.HTMLremoveColor();
  1782. return this.toHTML(box,h,d);
  1783. }
  1784. });
  1785. MML.chars.Augment({
  1786. toHTML: function (span,variant,remap,chars) {
  1787. var text = this.data.join("").replace(/[\u2061-\u2064]/g,""); // remove invisibles
  1788. if (remap) {text = remap(text,chars)}
  1789. if (variant.fontInherit) {
  1790. var scale = Math.floor(100/HTMLCSS.scale+.5) + "%";
  1791. HTMLCSS.addElement(span,"span",{style:{"font-size":scale}},[text]);
  1792. if (variant.bold) {span.lastChild.style.fontWeight = "bold"}
  1793. if (variant.italic) {span.lastChild.style.fontStyle = "italic"}
  1794. var HD = HTMLCSS.getHD(span), W = HTMLCSS.getW(span);
  1795. span.bbox = {h:HD.h, d:HD.d, w:W, lw:0, rw:W, exactW: true};
  1796. } else {
  1797. this.HTMLhandleVariant(span,variant,text);
  1798. }
  1799. }
  1800. });
  1801. MML.entity.Augment({
  1802. toHTML: function (span,variant,remap,chars) {
  1803. var text = this.toString().replace(/[\u2061-\u2064]/g,""); // remove invisibles
  1804. if (remap) {text = remap(text,chars)}
  1805. if (variant.fontInherit) {
  1806. var scale = Math.floor(100/HTMLCSS.scale+.5) + "%";
  1807. HTMLCSS.addElement(span,"span",{style:{"font-size":scale}},[text]);
  1808. if (variant.bold) {span.lastChild.style.fontWeight = "bold"}
  1809. if (variant.italic) {span.lastChild.style.fontStyle = "italic"}
  1810. var HD = HTMLCSS.getHD(span), W = HTMLCSS.getW(span);
  1811. span.bbox = {h:HD.h, d:HD.d, w:W, lw:0, rw:W, exactW: true};
  1812. } else {
  1813. this.HTMLhandleVariant(span,variant,text);
  1814. }
  1815. }
  1816. });
  1817. MML.mi.Augment({
  1818. toHTML: function (span) {
  1819. span = this.HTMLhandleSize(this.HTMLcreateSpan(span)); span.bbox = null;
  1820. var variant = this.HTMLgetVariant();
  1821. for (var i = 0, m = this.data.length; i < m; i++)
  1822. {if (this.data[i]) {this.data[i].toHTML(span,variant)}}
  1823. if (!span.bbox) {span.bbox = {w:0, h:0, d:0, rw:0, lw:0}}
  1824. var text = this.data.join(""), bbox = span.bbox;
  1825. if (bbox.skew && text.length !== 1) {delete bbox.skew}
  1826. if (bbox.rw > bbox.w && text.length === 1 && !variant.noIC) {
  1827. bbox.ic = bbox.rw - bbox.w;
  1828. HTMLCSS.createBlank(span,bbox.ic);
  1829. bbox.w = bbox.rw;
  1830. }
  1831. this.HTMLhandleSpace(span);
  1832. this.HTMLhandleColor(span);
  1833. return span;
  1834. }
  1835. });
  1836. MML.mn.Augment({
  1837. toHTML: function (span) {
  1838. span = this.HTMLhandleSize(this.HTMLcreateSpan(span)); span.bbox = null;
  1839. var variant = this.HTMLgetVariant();
  1840. for (var i = 0, m = this.data.length; i < m; i++)
  1841. {if (this.data[i]) {this.data[i].toHTML(span,variant)}}
  1842. if (!span.bbox) {span.bbox = {w:0, h:0, d:0, rw:0, lw:0}}
  1843. if (this.data.join("").length !== 1) {delete span.bbox.skew}
  1844. this.HTMLhandleSpace(span);
  1845. this.HTMLhandleColor(span);
  1846. return span;
  1847. }
  1848. });
  1849. MML.mo.Augment({
  1850. toHTML: function (span) {
  1851. span = this.HTMLhandleSize(this.HTMLcreateSpan(span));
  1852. if (this.data.length == 0) {return span} else {span.bbox = null}
  1853. var text = this.data.join("");
  1854. //
  1855. // Get the variant, and check for operator size
  1856. //
  1857. var variant = this.HTMLgetVariant();
  1858. var values = this.getValues("largeop","displaystyle");
  1859. if (values.largeop)
  1860. {variant = HTMLCSS.FONTDATA.VARIANT[values.displaystyle ? "-largeOp" : "-smallOp"]}
  1861. //
  1862. // Get character translation for superscript and accents
  1863. //
  1864. var parent = this.CoreParent(),
  1865. isScript = (parent && parent.isa(MML.msubsup) && this !== parent.data[parent.base]),
  1866. mapchars = (isScript?this.HTMLremapChars:null);
  1867. if (text.length === 1 && parent && parent.isa(MML.munderover) &&
  1868. this.CoreText(parent.data[parent.base]).length === 1) {
  1869. var over = parent.data[parent.over], under = parent.data[parent.under];
  1870. if (over && this === over.CoreMO() && parent.Get("accent")) {mapchars = HTMLCSS.FONTDATA.REMAPACCENT}
  1871. else if (under && this === under.CoreMO() && parent.Get("accentunder")) {mapchars = HTMLCSS.FONTDATA.REMAPACCENTUNDER}
  1872. }
  1873. //
  1874. // STIX and TeX fonts need quotes from variant font
  1875. //
  1876. if (isScript && text.match(/['`"\u00B4\u2032-\u2037\u2057]/))
  1877. {variant = HTMLCSS.FONTDATA.VARIANT["-"+HTMLCSS.fontInUse+"-variant"]}
  1878. //
  1879. // Typeset contents
  1880. //
  1881. for (var i = 0, m = this.data.length; i < m; i++)
  1882. {if (this.data[i]) {this.data[i].toHTML(span,variant,this.HTMLremap,mapchars)}}
  1883. if (!span.bbox) {span.bbox = {w:0, h:0, d:0, rw:0, lw:0}}
  1884. if (text.length !== 1) {delete span.bbox.skew}
  1885. //
  1886. // Handle combining characters by adding a non-breaking space and removing that width
  1887. //
  1888. if (HTMLCSS.AccentBug && span.bbox.w === 0 && text.length === 1 && span.firstChild) {
  1889. span.firstChild.nodeValue += HTMLCSS.NBSP;
  1890. HTMLCSS.createSpace(span,0,0,-span.offsetWidth/HTMLCSS.em);
  1891. }
  1892. //
  1893. // Handle large operator centering
  1894. //
  1895. if (values.largeop) {
  1896. var p = (span.bbox.h - span.bbox.d)/2 - HTMLCSS.TeX.axis_height*span.scale;
  1897. if (HTMLCSS.safariVerticalAlignBug && span.lastChild.nodeName === "IMG") {
  1898. span.lastChild.style.verticalAlign =
  1899. HTMLCSS.Em(HTMLCSS.unEm(span.lastChild.style.verticalAlign||0)/HTMLCSS.em-p/span.scale);
  1900. } else if (HTMLCSS.konquerorVerticalAlignBug && span.lastChild.nodeName === "IMG") {
  1901. span.style.position = "relative";
  1902. span.lastChild.style.position="relative";
  1903. span.lastChild.style.top = HTMLCSS.Em(p/span.scale);
  1904. } else {
  1905. span.style.verticalAlign = HTMLCSS.Em(-p/span.scale);
  1906. }
  1907. span.bbox.h -= p; span.bbox.d += p;
  1908. if (span.bbox.rw > span.bbox.w) {
  1909. span.bbox.ic = span.bbox.rw-span.bbox.w;
  1910. HTMLCSS.createBlank(span,span.bbox.ic);
  1911. span.bbox.w = span.bbox.rw;
  1912. }
  1913. }
  1914. //
  1915. // Finish up
  1916. //
  1917. this.HTMLhandleSpace(span);
  1918. this.HTMLhandleColor(span);
  1919. return span;
  1920. },
  1921. CoreParent: function () {
  1922. var parent = this;
  1923. while (parent && parent.isEmbellished() &&
  1924. parent.CoreMO() === this && !parent.isa(MML.math)) {parent = parent.Parent()}
  1925. return parent;
  1926. },
  1927. CoreText: function (parent) {
  1928. if (!parent) {return ""}
  1929. if (parent.isEmbellished()) {return parent.CoreMO().data.join("")}
  1930. while ((parent.isa(MML.mrow) || parent.isa(MML.TeXAtom)) &&
  1931. parent.data.length === 1 && parent.data[0]) {parent = parent.data[0]}
  1932. if (!parent.isToken) {return ""} else {return parent.data.join("")}
  1933. },
  1934. HTMLremapChars: {
  1935. '*':"\u2217",
  1936. '"':"\u2033",
  1937. "\u00B0":"\u2218",
  1938. "\u00B2":"2",
  1939. "\u00B3":"3",
  1940. "\u00B4":"\u2032",
  1941. "\u00B9":"1"
  1942. },
  1943. HTMLremap: function (text,map) {
  1944. text = text.replace(/-/g,"\u2212");
  1945. if (map) {
  1946. text = text.replace(/'/g,"\u2032").replace(/`/g,"\u2035");
  1947. if (text.length === 1) {text = map[text]||text}
  1948. }
  1949. return text;
  1950. },
  1951. HTMLcanStretch: function (direction) {
  1952. if (!this.Get("stretchy")) {return false}
  1953. var c = this.data.join("");
  1954. if (c.length > 1) {return false}
  1955. var parent = this.CoreParent();
  1956. if (parent && parent.isa(MML.munderover) &&
  1957. this.CoreText(parent.data[parent.base]).length === 1) {
  1958. var over = parent.data[parent.over], under = parent.data[parent.under];
  1959. if (over && this === over.CoreMO() && parent.Get("accent")) {c = HTMLCSS.FONTDATA.REMAPACCENT[c]||c}
  1960. else if (under && this === under.CoreMO() && parent.Get("accentunder")) {c = HTMLCSS.FONTDATA.REMAPACCENTUNDER[c]||c}
  1961. }
  1962. c = HTMLCSS.FONTDATA.DELIMITERS[c.charCodeAt(0)];
  1963. return (c && c.dir == direction.substr(0,1));
  1964. },
  1965. HTMLstretchV: function (box,h,d) {
  1966. this.HTMLremoveColor();
  1967. var values = this.getValues("symmetric","maxsize","minsize");
  1968. var span = this.HTMLspanElement(), mu = this.HTMLgetMu(span), H;
  1969. var axis = HTMLCSS.TeX.axis_height, scale = span.scale;
  1970. if (values.symmetric) {H = 2*Math.max(h-axis,d+axis)} else {H = h + d}
  1971. values.maxsize = HTMLCSS.length2em(values.maxsize,mu,span.bbox.h+span.bbox.d);
  1972. values.minsize = HTMLCSS.length2em(values.minsize,mu,span.bbox.h+span.bbox.d);
  1973. H = Math.max(values.minsize,Math.min(values.maxsize,H));
  1974. span = this.HTMLcreateSpan(box); // clear contents and attributes
  1975. HTMLCSS.createDelimiter(span,this.data.join("").charCodeAt(0),H,scale);
  1976. if (values.symmetric) {H = (span.bbox.h + span.bbox.d)/2 + axis}
  1977. else {H = (span.bbox.h + span.bbox.d) * h/(h + d)}
  1978. HTMLCSS.positionDelimiter(span,H);
  1979. this.HTMLhandleSpace(span); // add in lspace/rspace, if any
  1980. this.HTMLhandleColor(span);
  1981. return span;
  1982. },
  1983. HTMLstretchH: function (box,W) {
  1984. this.HTMLremoveColor();
  1985. var values = this.getValues("maxsize","minsize","mathvariant","fontweight");
  1986. // FIXME: should take style="font-weight:bold" into account as well
  1987. if ((values.fontweight === "bold" || parseInt(values.fontweight) >= 600) &&
  1988. !this.Get("mathvariant",true)) {values.mathvariant = MML.VARIANT.BOLD}
  1989. var span = this.HTMLspanElement(), mu = this.HTMLgetMu(span), scale = span.scale;
  1990. values.maxsize = HTMLCSS.length2em(values.maxsize,mu,span.bbox.w);
  1991. values.minsize = HTMLCSS.length2em(values.minsize,mu,span.bbox.w);
  1992. W = Math.max(values.minsize,Math.min(values.maxsize,W));
  1993. span = this.HTMLcreateSpan(box); // clear contents and attributes
  1994. HTMLCSS.createDelimiter(span,this.data.join("").charCodeAt(0),W,scale,values.mathvariant);
  1995. this.HTMLhandleSpace(span); // add in lspace/rspace, if any
  1996. this.HTMLhandleColor(span);
  1997. return span;
  1998. }
  1999. });
  2000. MML.mtext.Augment({
  2001. toHTML: function (span) {
  2002. span = this.HTMLhandleSize(this.HTMLcreateSpan(span));
  2003. var variant = this.HTMLgetVariant();
  2004. // Avoid setting the font style for error text or if mtextFontInherit is set
  2005. if (HTMLCSS.config.mtextFontInherit || this.Parent().type === "merror")
  2006. {variant = {bold:variant.bold, italic:variant.italic, fontInherit: true}}
  2007. for (var i = 0, m = this.data.length; i < m; i++)
  2008. {if (this.data[i]) {this.data[i].toHTML(span,variant)}}
  2009. if (!span.bbox) {span.bbox = {w:0, h:0, d:0, rw:0, lw:0}}
  2010. if (this.data.join("").length !== 1) {delete span.bbox.skew}
  2011. this.HTMLhandleSpace(span);
  2012. this.HTMLhandleColor(span);
  2013. return span;
  2014. }
  2015. });
  2016. MML.merror.Augment({
  2017. toHTML: function (span) {
  2018. //
  2019. // Width doesn't include padding and border, so use an extra inline block
  2020. // element to capture it.
  2021. //
  2022. var SPAN = MathJax.HTML.addElement(span,"span",{style:{display:"inline-block"}});
  2023. span = this.SUPER(arguments).toHTML.call(this,SPAN);
  2024. var HD = HTMLCSS.getHD(SPAN), W = HTMLCSS.getW(SPAN);
  2025. SPAN.bbox = {h:HD.h, d:HD.d, w:W, lw:0, rw:W, exactW: true};
  2026. SPAN.id = span.id; span.id = null;
  2027. return SPAN;
  2028. }
  2029. });
  2030. MML.ms.Augment({toHTML: MML.mbase.HTMLautoload});
  2031. MML.mglyph.Augment({toHTML: MML.mbase.HTMLautoload});
  2032. MML.mspace.Augment({
  2033. toHTML: function (span) {
  2034. span = this.HTMLcreateSpan(span);
  2035. var values = this.getValues("height","depth","width");
  2036. var mu = this.HTMLgetMu(span);
  2037. values.mathbackground = this.mathbackground;
  2038. if (this.background && !this.mathbackground) {values.mathbackground = this.background}
  2039. var h = HTMLCSS.length2em(values.height,mu),
  2040. d = HTMLCSS.length2em(values.depth,mu),
  2041. w = HTMLCSS.length2em(values.width,mu);
  2042. HTMLCSS.createSpace(span,h,d,w,values.mathbackground,true);
  2043. return span;
  2044. }
  2045. });
  2046. MML.mphantom.Augment({
  2047. toHTML: function (span,HW,D) {
  2048. span = this.HTMLcreateSpan(span);
  2049. if (this.data[0] != null) {
  2050. var box = this.data[0].toHTML(span);
  2051. if (D != null) {HTMLCSS.Remeasured(this.data[0].HTMLstretchV(span,HW,D),span)}
  2052. else if (HW != null) {HTMLCSS.Remeasured(this.data[0].HTMLstretchH(span,HW),span)}
  2053. else {box = HTMLCSS.Measured(box,span)}
  2054. span.bbox = {w: box.bbox.w, h: box.bbox.h, d: box.bbox.d, lw: 0, rw: 0, exactW: true};
  2055. for (var i = 0, m = span.childNodes.length; i < m; i++)
  2056. {span.childNodes[i].style.visibility = "hidden"}
  2057. }
  2058. this.HTMLhandleSpace(span);
  2059. this.HTMLhandleColor(span);
  2060. return span;
  2061. },
  2062. HTMLstretchH: MML.mbase.HTMLstretchH,
  2063. HTMLstretchV: MML.mbase.HTMLstretchV
  2064. });
  2065. MML.mpadded.Augment({
  2066. toHTML: function (span,HW,D) {
  2067. span = this.HTMLcreateSpan(span);
  2068. if (this.data[0] != null) {
  2069. var stack = HTMLCSS.createStack(span,true);
  2070. var box = HTMLCSS.createBox(stack);
  2071. var child = this.data[0].toHTML(box);
  2072. if (D != null) {HTMLCSS.Remeasured(this.data[0].HTMLstretchV(box,HW,D),box)}
  2073. else if (HW != null) {HTMLCSS.Remeasured(this.data[0].HTMLstretchH(box,HW),box)}
  2074. else {HTMLCSS.Measured(child,box)}
  2075. var values = this.getValues("height","depth","width","lspace","voffset"),
  2076. x = 0, y = 0, mu = this.HTMLgetMu(span);
  2077. if (values.lspace) {x = this.HTMLlength2em(box,values.lspace,mu)}
  2078. if (values.voffset) {y = this.HTMLlength2em(box,values.voffset,mu)}
  2079. HTMLCSS.placeBox(box,x,y);
  2080. span.bbox = {
  2081. h: box.bbox.h, d: box.bbox.d, w: box.bbox.w, exactW: true,
  2082. lw: Math.min(0,box.bbox.lw+x), rw: Math.max(box.bbox.w,box.bbox.rw+x),
  2083. H: Math.max((box.bbox.H == null ? -HTMLCSS.BIGDIMEN : box.bbox.H),box.bbox.h+y),
  2084. D: Math.max((box.bbox.D == null ? -HTMLCSS.BIGDIMEN : box.bbox.D),box.bbox.d-y)
  2085. };
  2086. if (values.height !== "") {span.bbox.h = this.HTMLlength2em(box,values.height,mu,"h",0)}
  2087. if (values.depth !== "") {span.bbox.d = this.HTMLlength2em(box,values.depth,mu,"d",0)}
  2088. if (values.width !== "") {span.bbox.w = this.HTMLlength2em(box,values.width,mu,"w",0)}
  2089. if (span.bbox.H <= span.bbox.h) {delete span.bbox.H}
  2090. if (span.bbox.D <= span.bbox.d) {delete span.bbox.D}
  2091. var dimen = /^\s*(\d+(\.\d*)?|\.\d+)\s*(pt|em|ex|mu|px|pc|in|mm|cm)\s*$/
  2092. span.bbox.exact = !!((this.data[0] && this.data[0].data.length == 0) ||
  2093. dimen.exec(values.height) || dimen.exec(values.width) || dimen.exec(values.depth));
  2094. HTMLCSS.setStackWidth(stack,span.bbox.w);
  2095. }
  2096. this.HTMLhandleSpace(span);
  2097. this.HTMLhandleColor(span);
  2098. return span;
  2099. },
  2100. HTMLlength2em: function (span,length,mu,d,m) {
  2101. if (m == null) {m = -HTMLCSS.BIGDIMEN}
  2102. var match = String(length).match(/width|height|depth/);
  2103. var size = (match ? span.bbox[match[0].charAt(0)] : (d ? span.bbox[d] : 0));
  2104. var v = HTMLCSS.length2em(length,mu,size);
  2105. if (d && String(length).match(/^\s*[-+]/))
  2106. {return Math.max(m,span.bbox[d]+v)} else {return v}
  2107. },
  2108. HTMLstretchH: MML.mbase.HTMLstretchH,
  2109. HTMLstretchV: MML.mbase.HTMLstretchV
  2110. });
  2111. MML.mrow.Augment({
  2112. HTMLlineBreaks: function (span) {
  2113. if (!this.parent.linebreakContainer) {return false}
  2114. return (HTMLCSS.config.linebreaks.automatic &&
  2115. span.bbox.w > HTMLCSS.linebreakWidth) || this.hasNewline();
  2116. },
  2117. HTMLstretchH: function (box,w) {
  2118. this.HTMLremoveColor();
  2119. var span = this.HTMLspanElement();
  2120. this.data[this.core].HTMLstretchH(span,w);
  2121. this.HTMLcomputeBBox(span,true);
  2122. this.HTMLhandleColor(span);
  2123. return span;
  2124. },
  2125. HTMLstretchV: function (box,h,d) {
  2126. this.HTMLremoveColor();
  2127. var span = this.HTMLspanElement();
  2128. this.data[this.core].HTMLstretchV(span,h,d);
  2129. this.HTMLcomputeBBox(span,true);
  2130. this.HTMLhandleColor(span);
  2131. return span;
  2132. }
  2133. });
  2134. MML.mstyle.Augment({
  2135. toHTML: function (span,HW,D) {
  2136. span = this.HTMLcreateSpan(span);
  2137. if (this.data[0] != null) {
  2138. var SPAN = this.data[0].toHTML(span);
  2139. if (D != null) {this.data[0].HTMLstretchV(span,HW,D)}
  2140. else if (HW != null) {this.data[0].HTMLstretchH(span,HW)}
  2141. span.bbox = SPAN.bbox;
  2142. }
  2143. this.HTMLhandleSpace(span);
  2144. this.HTMLhandleColor(span);
  2145. return span;
  2146. },
  2147. HTMLstretchH: MML.mbase.HTMLstretchH,
  2148. HTMLstretchV: MML.mbase.HTMLstretchV
  2149. });
  2150. MML.mfrac.Augment({
  2151. toHTML: function (span) {
  2152. span = this.HTMLcreateSpan(span);
  2153. var frac = HTMLCSS.createStack(span);
  2154. var num = HTMLCSS.createBox(frac), den = HTMLCSS.createBox(frac);
  2155. HTMLCSS.MeasureSpans([this.HTMLboxChild(0,num),this.HTMLboxChild(1,den)]);
  2156. var values = this.getValues("displaystyle","linethickness","numalign","denomalign","bevelled");
  2157. var scale = this.HTMLgetScale(), isDisplay = values.displaystyle;
  2158. var a = HTMLCSS.TeX.axis_height * scale;
  2159. if (values.bevelled) {
  2160. var delta = (isDisplay ? .4 : .15);
  2161. var H = Math.max(num.bbox.h+num.bbox.d,den.bbox.h+den.bbox.d)+2*delta;
  2162. var bevel = HTMLCSS.createBox(frac);
  2163. HTMLCSS.createDelimiter(bevel,0x2F,H);
  2164. HTMLCSS.placeBox(num,0,(num.bbox.d-num.bbox.h)/2+a+delta);
  2165. HTMLCSS.placeBox(bevel,num.bbox.w-delta/2,(bevel.bbox.d-bevel.bbox.h)/2+a);
  2166. HTMLCSS.placeBox(den,num.bbox.w+bevel.bbox.w-delta,(den.bbox.d-den.bbox.h)/2+a-delta);
  2167. } else {
  2168. var W = Math.max(num.bbox.w,den.bbox.w);
  2169. var t = HTMLCSS.thickness2em(values.linethickness,scale), p,q, u,v;
  2170. var mt = HTMLCSS.TeX.min_rule_thickness/this.em;
  2171. if (isDisplay) {u = HTMLCSS.TeX.num1; v = HTMLCSS.TeX.denom1}
  2172. else {u = (t === 0 ? HTMLCSS.TeX.num3 : HTMLCSS.TeX.num2); v = HTMLCSS.TeX.denom2}
  2173. u *= scale; v *= scale;
  2174. if (t === 0) {// \atop
  2175. p = Math.max((isDisplay ? 7 : 3) * HTMLCSS.TeX.rule_thickness, 2*mt); // force to at least 2 px
  2176. q = (u - num.bbox.d) - (den.bbox.h - v);
  2177. if (q < p) {u += (p - q)/2; v += (p - q)/2}
  2178. } else {// \over
  2179. p = Math.max((isDisplay ? 2 : 0) * mt + t, t/2 + 1.5*mt); // force to be at least 1.5px
  2180. q = (u - num.bbox.d) - (a + t/2); if (q < p) {u += p - q}
  2181. q = (a - t/2) - (den.bbox.h - v); if (q < p) {v += p - q}
  2182. var rule = HTMLCSS.createBox(frac);
  2183. HTMLCSS.createRule(rule,t,0,W+2*t);
  2184. HTMLCSS.placeBox(rule,0,a-t/2);
  2185. }
  2186. HTMLCSS.alignBox(num,values.numalign,u);
  2187. HTMLCSS.alignBox(den,values.denomalign,-v);
  2188. }
  2189. this.HTMLhandleSpace(span);
  2190. this.HTMLhandleColor(span);
  2191. return span;
  2192. },
  2193. HTMLcanStretch: function (direction) {return false},
  2194. HTMLhandleSpace: function (span) {
  2195. if (!this.texWithDelims) {
  2196. var space = (this.useMMLspacing ? 0 : HTMLCSS.length2em(this.texSpacing()||0)) + .12;
  2197. span.style.paddingLeft = HTMLCSS.Em(space);
  2198. span.style.paddingRight = HTMLCSS.Em(.12);
  2199. }
  2200. }
  2201. });
  2202. MML.msqrt.Augment({
  2203. toHTML: function (span) {
  2204. span = this.HTMLcreateSpan(span);
  2205. var sqrt = HTMLCSS.createStack(span);
  2206. var base = HTMLCSS.createBox(sqrt),
  2207. rule = HTMLCSS.createBox(sqrt),
  2208. surd = HTMLCSS.createBox(sqrt);
  2209. var scale = this.HTMLgetScale();
  2210. var t = HTMLCSS.TeX.rule_thickness * scale, p,q, H, W;
  2211. if (this.Get("displaystyle")) {p = HTMLCSS.TeX.x_height * scale} else {p = t}
  2212. q = Math.max(t + p/4,1.5*HTMLCSS.TeX.min_rule_thickness/this.em); // force to be at least 1px
  2213. var BASE = this.HTMLboxChild(0,base);
  2214. H = BASE.bbox.h + BASE.bbox.d + q + t;
  2215. HTMLCSS.createDelimiter(surd,0x221A,H,scale);
  2216. HTMLCSS.MeasureSpans([BASE,surd]);
  2217. W = BASE.bbox.w;
  2218. var x = 0;
  2219. if (surd.isMultiChar || (HTMLCSS.AdjustSurd && HTMLCSS.imgFonts)) {surd.bbox.w *= .95}
  2220. if (surd.bbox.h + surd.bbox.d > H) {q = ((surd.bbox.h+surd.bbox.d) - (H-t))/2}
  2221. var ruleC = HTMLCSS.FONTDATA.DELIMITERS[HTMLCSS.FONTDATA.RULECHAR];
  2222. if (!ruleC || W < ruleC.HW[0][0]*scale || scale < .75) {
  2223. HTMLCSS.createRule(rule,0,t,W);
  2224. } else {
  2225. HTMLCSS.createDelimiter(rule,HTMLCSS.FONTDATA.RULECHAR,W,scale);
  2226. }
  2227. H = BASE.bbox.h + q + t;
  2228. q = H*HTMLCSS.rfuzz; if (surd.isMultiChar) {q = HTMLCSS.rfuzz}
  2229. x = this.HTMLaddRoot(sqrt,surd,x,surd.bbox.h+surd.bbox.d-H,scale);
  2230. HTMLCSS.placeBox(surd,x,H-surd.bbox.h);
  2231. HTMLCSS.placeBox(rule,x+surd.bbox.w,H-rule.bbox.h+q);
  2232. HTMLCSS.placeBox(base,x+surd.bbox.w,0);
  2233. this.HTMLhandleSpace(span);
  2234. this.HTMLhandleColor(span);
  2235. return span;
  2236. },
  2237. HTMLaddRoot: function (sqrt,surd,x,d,scale) {return x}
  2238. });
  2239. MML.mroot.Augment({
  2240. toHTML: MML.msqrt.prototype.toHTML,
  2241. HTMLaddRoot: function (sqrt,surd,x,d,scale) {
  2242. var box = HTMLCSS.createBox(sqrt);
  2243. if (this.data[1]) {
  2244. var root = this.data[1].toHTML(box);
  2245. root.style.paddingRight = root.style.paddingLeft = ""; // remove extra padding, if any
  2246. HTMLCSS.Measured(root,box);
  2247. } else {box.bbox = this.HTMLzeroBBox()}
  2248. var h = this.HTMLrootHeight(surd.bbox.h+surd.bbox.d,scale,box)-d;
  2249. var w = Math.min(box.bbox.w,box.bbox.rw); // remove extra right-hand padding, if any
  2250. x = Math.max(w,surd.offset);
  2251. HTMLCSS.placeBox(box,x-w,h);
  2252. return x - surd.offset;
  2253. },
  2254. HTMLrootHeight: function (d,scale,root) {
  2255. return .45*(d-.9*scale)+.6*scale + Math.max(0,root.bbox.d-.075);
  2256. }
  2257. });
  2258. MML.mfenced.Augment({
  2259. toHTML: function (span) {
  2260. span = this.HTMLcreateSpan(span);
  2261. if (this.data.open) {this.data.open.toHTML(span)}
  2262. if (this.data[0] != null) {this.data[0].toHTML(span)}
  2263. for (var i = 1, m = this.data.length; i < m; i++) {
  2264. if (this.data[i]) {
  2265. if (this.data["sep"+i]) {this.data["sep"+i].toHTML(span)}
  2266. this.data[i].toHTML(span);
  2267. }
  2268. }
  2269. if (this.data.close) {this.data.close.toHTML(span)}
  2270. var stretchy = this.HTMLcomputeBBox(span);
  2271. var h = span.bbox.h, d = span.bbox.d;
  2272. for (i = 0, m = stretchy.length; i < m; i++) {stretchy[i].HTMLstretchV(span,h,d)}
  2273. if (stretchy.length) {this.HTMLcomputeBBox(span,true)}
  2274. this.HTMLhandleSpace(span);
  2275. this.HTMLhandleColor(span);
  2276. return span;
  2277. },
  2278. HTMLcomputeBBox: function (span,full) {
  2279. var BBOX = span.bbox = {}, stretchy = [];
  2280. this.HTMLcheckStretchy(this.data.open,BBOX,stretchy,full);
  2281. this.HTMLcheckStretchy(this.data[0],BBOX,stretchy,full);
  2282. for (var i = 1, m = this.data.length; i < m; i++) {
  2283. if (this.data[i]) {
  2284. this.HTMLcheckStretchy(this.data["sep"+i],BBOX,stretchy,full);
  2285. this.HTMLcheckStretchy(this.data[i],BBOX,stretchy,full);
  2286. }
  2287. }
  2288. this.HTMLcheckStretchy(this.data.close,BBOX,stretchy,full);
  2289. this.HTMLcleanBBox(BBOX);
  2290. return stretchy;
  2291. },
  2292. HTMLcheckStretchy: function (core,BBOX,stretchy,full) {
  2293. if (core) {
  2294. if (!full && core.HTMLcanStretch("Vertical"))
  2295. {stretchy.push(core); core = (core.CoreMO()||core)}
  2296. this.HTMLcombineBBoxes(core,BBOX);
  2297. }
  2298. }
  2299. });
  2300. MML.menclose.Augment({toHTML: MML.mbase.HTMLautoload});
  2301. MML.maction.Augment({toHTML: MML.mbase.HTMLautoload});
  2302. MML.semantics.Augment({
  2303. toHTML: function (span,HW,D) {
  2304. span = this.HTMLcreateSpan(span);
  2305. if (this.data[0] != null) {
  2306. var SPAN = this.data[0].toHTML(span);
  2307. if (D != null) {this.data[0].HTMLstretchV(span,HW,D)}
  2308. else if (HW != null) {this.data[0].HTMLstretchH(span,HW)}
  2309. span.bbox = SPAN.bbox;
  2310. }
  2311. this.HTMLhandleSpace(span);
  2312. return span;
  2313. },
  2314. HTMLstretchH: MML.mbase.HTMLstretchH,
  2315. HTMLstretchV: MML.mbase.HTMLstretchV
  2316. });
  2317. MML.munderover.Augment({
  2318. toHTML: function (span,HW,D) {
  2319. var values = this.getValues("displaystyle","accent","accentunder","align");
  2320. if (!values.displaystyle && this.data[this.base] != null &&
  2321. this.data[this.base].CoreMO().Get("movablelimits"))
  2322. {return MML.msubsup.prototype.toHTML.call(this,span)}
  2323. span = this.HTMLcreateSpan(span); var scale = this.HTMLgetScale();
  2324. var stack = HTMLCSS.createStack(span);
  2325. var boxes = [], children = [], stretch = [], box, i, m;
  2326. for (i = 0, m = this.data.length; i < m; i++) {
  2327. if (this.data[i] != null) {
  2328. box = boxes[i] = HTMLCSS.createBox(stack);
  2329. children[i] = this.data[i].toHTML(box);
  2330. if (i == this.base) {
  2331. if (D != null) {this.data[this.base].HTMLstretchV(box,HW,D)}
  2332. else if (HW != null) {this.data[this.base].HTMLstretchH(box,HW)}
  2333. stretch[i] = (D == null && HW != null ? false :
  2334. this.data[i].HTMLcanStretch("Horizontal"));
  2335. } else {
  2336. stretch[i] = this.data[i].HTMLcanStretch("Horizontal");
  2337. }
  2338. }
  2339. }
  2340. HTMLCSS.MeasureSpans(children);
  2341. var W = -HTMLCSS.BIGDIMEN, WW = W;
  2342. for (i = 0, m = this.data.length; i < m; i++) {
  2343. if (this.data[i]) {
  2344. if (boxes[i].bbox.w > WW) {WW = boxes[i].bbox.w}
  2345. if (!stretch[i] && WW > W) {W = WW}
  2346. }
  2347. }
  2348. if (D == null && HW != null) {W = HW} else if (W == -HTMLCSS.BIGDIMEN) {W = WW}
  2349. for (i = WW = 0, m = this.data.length; i < m; i++) {if (this.data[i]) {
  2350. box = boxes[i];
  2351. if (stretch[i]) {box.bbox = this.data[i].HTMLstretchH(box,W).bbox}
  2352. if (box.bbox.w > WW) {WW = box.bbox.w}
  2353. }}
  2354. var t = HTMLCSS.TeX.rule_thickness, factor = HTMLCSS.FONTDATA.TeX_factor;
  2355. var base = boxes[this.base] || {bbox: this.HTMLzeroBBox()};
  2356. var x, y, z1, z2, z3, dw, k, delta = 0;
  2357. if (base.bbox.ic) {delta = 1.3*base.bbox.ic + .05} // adjust faked IC to be more in line with expeted results
  2358. for (i = 0, m = this.data.length; i < m; i++) {
  2359. if (this.data[i] != null) {
  2360. box = boxes[i];
  2361. z3 = HTMLCSS.TeX.big_op_spacing5 * scale;
  2362. var accent = (i != this.base && values[this.ACCENTS[i]]);
  2363. if (accent && box.bbox.w <= 1/HTMLCSS.em+.0001) { // images can get the width off by 1px
  2364. box.bbox.w = box.bbox.rw - box.bbox.lw; box.bbox.noclip = true;
  2365. if (box.bbox.lw)
  2366. {box.insertBefore(HTMLCSS.createSpace(box.parentNode,0,0,-box.bbox.lw),box.firstChild)}
  2367. HTMLCSS.createBlank(box,0,0,box.bbox.rw+.1);
  2368. }
  2369. dw = {left:0, center:(WW-box.bbox.w)/2, right:WW-box.bbox.w}[values.align];
  2370. x = dw; y = 0;
  2371. if (i == this.over) {
  2372. if (accent) {
  2373. k = Math.max(t * scale * factor,2.5/this.em); z3 = 0;
  2374. if (base.bbox.skew) {x += base.bbox.skew}
  2375. } else {
  2376. z1 = HTMLCSS.TeX.big_op_spacing1 * scale * factor;
  2377. z2 = HTMLCSS.TeX.big_op_spacing3 * scale * factor;
  2378. k = Math.max(z1,z2-Math.max(0,box.bbox.d));
  2379. }
  2380. k = Math.max(k,1.5/this.em); // force to be at least 1.5px
  2381. x += delta/2; y = base.bbox.h + box.bbox.d + k;
  2382. box.bbox.h += z3;
  2383. } else if (i == this.under) {
  2384. if (accent) {
  2385. k = 3*t * scale * factor; z3 = 0;
  2386. } else {
  2387. z1 = HTMLCSS.TeX.big_op_spacing2 * scale * factor;
  2388. z2 = HTMLCSS.TeX.big_op_spacing4 * scale * factor;
  2389. k = Math.max(z1,z2-box.bbox.h);
  2390. }
  2391. k = Math.max(k,1.5/this.em); // force to be at least 1.5px
  2392. x -= delta/2; y = -(base.bbox.d + box.bbox.h + k);
  2393. box.bbox.d += z3;
  2394. }
  2395. HTMLCSS.placeBox(box,x,y);
  2396. }
  2397. }
  2398. this.HTMLhandleSpace(span);
  2399. this.HTMLhandleColor(span);
  2400. return span;
  2401. },
  2402. HTMLstretchH: MML.mbase.HTMLstretchH,
  2403. HTMLstretchV: MML.mbase.HTMLstretchV
  2404. });
  2405. MML.msubsup.Augment({
  2406. toHTML: function (span,HW,D) {
  2407. span = this.HTMLcreateSpan(span);
  2408. var scale = this.HTMLgetScale(), mu = this.HTMLgetMu(span);
  2409. var stack = HTMLCSS.createStack(span), values, children = [];
  2410. var base = HTMLCSS.createBox(stack);
  2411. if (this.data[this.base]) {
  2412. children.push(this.data[this.base].toHTML(base));
  2413. if (D != null) {this.data[this.base].HTMLstretchV(base,HW,D)}
  2414. else if (HW != null) {this.data[this.base].HTMLstretchH(base,HW)}
  2415. } else {base.bbox = this.HTMLzeroBBox()}
  2416. var x_height = HTMLCSS.TeX.x_height * scale,
  2417. s = HTMLCSS.TeX.scriptspace * scale * .75; // FIXME: .75 can be removed when IC is right?
  2418. var sup, sub;
  2419. if (this.HTMLnotEmpty(this.data[this.sup]))
  2420. {sup = HTMLCSS.createBox(stack); children.push(this.data[this.sup].toHTML(sup))}
  2421. if (this.HTMLnotEmpty(this.data[this.sub]))
  2422. {sub = HTMLCSS.createBox(stack); children.push(this.data[this.sub].toHTML(sub))}
  2423. HTMLCSS.MeasureSpans(children);
  2424. if (sup) {sup.bbox.w += s; sup.bbox.rw = Math.max(sup.bbox.w,sup.bbox.rw)}
  2425. if (sub) {sub.bbox.w += s; sub.bbox.rw = Math.max(sub.bbox.w,sub.bbox.rw)}
  2426. HTMLCSS.placeBox(base,0,0);
  2427. var sscale = (this.data[this.sup] || this.data[this.sub] || this).HTMLgetScale();
  2428. var q = HTMLCSS.TeX.sup_drop * sscale, r = HTMLCSS.TeX.sub_drop * sscale;
  2429. var u = base.bbox.h - q, v = base.bbox.d + r, delta = 0, p;
  2430. if (base.bbox.ic) {
  2431. base.bbox.w -= base.bbox.ic; // remove IC (added by mo and mi)
  2432. delta = 1.3*base.bbox.ic + .05; // adjust faked IC to be more in line with expected results
  2433. }
  2434. if (this.data[this.base] &&
  2435. (this.data[this.base].type === "mi" || this.data[this.base].type === "mo")) {
  2436. if (this.data[this.base].data.join("").length === 1 && base.bbox.scale === 1 &&
  2437. !this.data[this.base].Get("largeop")) {u = v = 0}
  2438. }
  2439. var min = this.getValues("subscriptshift","superscriptshift");
  2440. min.subscriptshift = (min.subscriptshift === "" ? 0 : HTMLCSS.length2em(min.subscriptshift,mu));
  2441. min.superscriptshift = (min.superscriptshift === "" ? 0 : HTMLCSS.length2em(min.superscriptshift,mu));
  2442. if (!sup) {
  2443. if (sub) {
  2444. v = Math.max(v,HTMLCSS.TeX.sub1*scale,sub.bbox.h-(4/5)*x_height,min.subscriptshift);
  2445. HTMLCSS.placeBox(sub,base.bbox.w,-v,sub.bbox);
  2446. }
  2447. } else {
  2448. if (!sub) {
  2449. values = this.getValues("displaystyle","texprimestyle");
  2450. p = HTMLCSS.TeX[(values.displaystyle ? "sup1" : (values.texprimestyle ? "sup3" : "sup2"))];
  2451. u = Math.max(u,p*scale,sup.bbox.d+(1/4)*x_height,min.superscriptshift);
  2452. HTMLCSS.placeBox(sup,base.bbox.w+delta,u,sup.bbox);
  2453. } else {
  2454. v = Math.max(v,HTMLCSS.TeX.sub2*scale);
  2455. var t = HTMLCSS.TeX.rule_thickness * scale;
  2456. if ((u - sup.bbox.d) - (sub.bbox.h - v) < 3*t) {
  2457. v = 3*t - u + sup.bbox.d + sub.bbox.h;
  2458. q = (4/5)*x_height - (u - sup.bbox.d);
  2459. if (q > 0) {u += q; v -= q}
  2460. }
  2461. HTMLCSS.placeBox(sup,base.bbox.w+delta,Math.max(u,min.superscriptshift));
  2462. HTMLCSS.placeBox(sub,base.bbox.w,-Math.max(v,min.subscriptshift));
  2463. }
  2464. }
  2465. this.HTMLhandleSpace(span);
  2466. this.HTMLhandleColor(span);
  2467. return span;
  2468. },
  2469. HTMLstretchH: MML.mbase.HTMLstretchH,
  2470. HTMLstretchV: MML.mbase.HTMLstretchV
  2471. });
  2472. MML.mmultiscripts.Augment({toHTML: MML.mbase.HTMLautoload});
  2473. MML.mtable.Augment({toHTML: MML.mbase.HTMLautoload});
  2474. MML["annotation-xml"].Augment({toHTML: MML.mbase.HTMLautoload});
  2475. MML.math.Augment({
  2476. toHTML: function (span,node) {
  2477. var alttext = this.Get("alttext");
  2478. if (alttext && alttext !== "") {node.setAttribute("aria-label",alttext)}
  2479. var nobr = HTMLCSS.addElement(span,"nobr",{isMathJax: true});
  2480. span = this.HTMLcreateSpan(nobr);
  2481. var stack = HTMLCSS.createStack(span), box = HTMLCSS.createBox(stack), math;
  2482. // Move font-size from outer span to stack to avoid line separation
  2483. // problem in strict HTML mode
  2484. stack.style.fontSize = nobr.parentNode.style.fontSize; nobr.parentNode.style.fontSize = "";
  2485. if (this.data[0] != null) {
  2486. if (HTMLCSS.msieColorBug) {
  2487. if (this.background) {this.data[0].background = this.background; delete this.background}
  2488. if (this.mathbackground) {this.data[0].mathbackground = this.mathbackground; delete this.mathbackground}
  2489. }
  2490. MML.mbase.prototype.displayAlign = HUB.config.displayAlign;
  2491. MML.mbase.prototype.displayIndent = HUB.config.displayIndent;
  2492. var html = this.data[0].toHTML(box); html.bbox.exactW = false; // force remeasure just to be sure
  2493. math = HTMLCSS.Measured(html,box);
  2494. }
  2495. HTMLCSS.placeBox(box,0,0);
  2496. stack.style.width = Math.round(HTMLCSS.unEm(stack.style.width)*this.em)+"px"; // get width right if minimum font size is set
  2497. //
  2498. // Adjust bbox to match outer em-size
  2499. //
  2500. var p = 1/HTMLCSS.em, f = HTMLCSS.em / HTMLCSS.outerEm; HTMLCSS.em /= f;
  2501. span.bbox.h *= f; span.bbox.d *= f; span.bbox.w *= f;
  2502. span.bbox.lw *= f; span.bbox.rw *= f;
  2503. if (math && math.bbox.width != null) {
  2504. stack.style.width = math.bbox.width;
  2505. box.style.width = "100%";
  2506. }
  2507. //
  2508. // Add color (if any)
  2509. //
  2510. this.HTMLhandleColor(span);
  2511. //
  2512. // Make math span be the correct height and depth
  2513. //
  2514. if (math) {HTMLCSS.createRule(span,(math.bbox.h+p)*f,(math.bbox.d+p)*f,0)}
  2515. //
  2516. // Handle indentalign and indentshift for single-line display equations
  2517. //
  2518. if (!this.isMultiline && this.Get("display") === "block" && span.bbox.width == null) {
  2519. var values = this.getValues("indentalignfirst","indentshiftfirst","indentalign","indentshift");
  2520. if (values.indentalignfirst !== MML.INDENTALIGN.INDENTALIGN) {values.indentalign = values.indentalignfirst}
  2521. if (values.indentalign === MML.INDENTALIGN.AUTO) {values.indentalign = this.displayAlign}
  2522. node.style.textAlign = values.indentalign;
  2523. if (values.indentshiftfirst !== MML.INDENTSHIFT.INDENTSHIFT) {values.indentshift = values.indentshiftfirst}
  2524. if (values.indentshift === "auto") {values.indentshift = this.displayIndent}
  2525. if (values.indentshift && values.indentalign !== MML.INDENTALIGN.CENTER) {
  2526. span.style[{left:"marginLeft",right:"marginRight"}[values.indentalign]] =
  2527. HTMLCSS.Em(HTMLCSS.length2em(values.indentshift));
  2528. }
  2529. }
  2530. return span;
  2531. },
  2532. HTMLspanElement: MML.mbase.prototype.HTMLspanElement
  2533. });
  2534. MML.TeXAtom.Augment({
  2535. toHTML: function (span) {
  2536. span = this.HTMLcreateSpan(span);
  2537. if (this.data[0] != null) {
  2538. if (this.texClass === MML.TEXCLASS.VCENTER) {
  2539. var stack = HTMLCSS.createStack(span);
  2540. var box = HTMLCSS.createBox(stack);
  2541. HTMLCSS.Measured(this.data[0].toHTML(box),box);
  2542. // FIXME: should the axis height be scaled?
  2543. HTMLCSS.placeBox(box,0,HTMLCSS.TeX.axis_height-(box.bbox.h+box.bbox.d)/2+box.bbox.d);
  2544. } else {
  2545. span.bbox = this.data[0].toHTML(span).bbox;
  2546. }
  2547. }
  2548. this.HTMLhandleSpace(span);
  2549. this.HTMLhandleColor(span);
  2550. return span;
  2551. }
  2552. });
  2553. //
  2554. // Loading isn't complete until the element jax is modified,
  2555. // but can't call loadComplete within the callback for "mml Jax Ready"
  2556. // (it would call HTMLCSS's Require routine, asking for the mml jax again)
  2557. // so wait until after the mml jax has finished processing.
  2558. //
  2559. // We also need to wait for the onload handler to run, since the loadComplete
  2560. // will call Config and Startup, which need to modify the body.
  2561. //
  2562. MathJax.Hub.Register.StartupHook("onLoad",function () {
  2563. setTimeout(MathJax.Callback(["loadComplete",HTMLCSS,"jax.js"]),0);
  2564. });
  2565. });
  2566. HUB.Register.StartupHook("End Config",function () {
  2567. //
  2568. // Handle browser-specific setup
  2569. //
  2570. HUB.Browser.Select({
  2571. MSIE: function (browser) {
  2572. var mode = (document.documentMode || 0);
  2573. var isIE7 = browser.versionAtLeast("7.0");
  2574. var isIE8 = browser.versionAtLeast("8.0") && mode > 7;
  2575. var quirks = (document.compatMode === "BackCompat");
  2576. if (mode < 9) {
  2577. // IE doesn't do mouse events on trasparent objects,
  2578. // so give a background color, but opacity makes it transparent
  2579. HTMLCSS.config.styles[".MathJax .MathJax_HitBox"]["background-color"] = "white";
  2580. HTMLCSS.config.styles[".MathJax .MathJax_HitBox"].opacity = 0
  2581. HTMLCSS.config.styles[".MathJax .MathJax_HitBox"].filter = "alpha(opacity=0)";
  2582. }
  2583. // FIXME: work out tests for these?
  2584. HTMLCSS.Augment({
  2585. PaddingWidthBug: true,
  2586. msieAccentBug: true,
  2587. msieColorBug: true,
  2588. msieColorPositionBug: true, // needs position:relative to put color behind text
  2589. msieRelativeWidthBug: quirks,
  2590. msieDisappearingBug: (mode >= 8), // inline math disappears
  2591. msieMarginScaleBug: (mode < 8), // relative margins are not scaled properly by font-size
  2592. msiePaddingWidthBug: true,
  2593. msieBorderWidthBug: quirks,
  2594. msieFrameSizeBug: (mode <= 8), // crashes if size of box isn't big enough for border
  2595. msieInlineBlockAlignBug: (!isIE8 || quirks),
  2596. msiePlaceBoxBug: (isIE8 && !quirks),
  2597. msieClipRectBug: !isIE8,
  2598. msieNegativeSpaceBug: quirks,
  2599. cloneNodeBug: (isIE8 && browser.version === "8.0"),
  2600. initialSkipBug: (mode < 8), // confused by initial left-margin values
  2601. msieNegativeBBoxBug: (mode >= 8), // negative bboxes have positive widths
  2602. msieIE6: !isIE7,
  2603. msieItalicWidthBug: true,
  2604. FontFaceBug: true,
  2605. msieFontCSSBug: browser.isIE9,
  2606. allowWebFonts: (mode >= 9 ? "woff" : "eot")
  2607. });
  2608. },
  2609. Firefox: function (browser) {
  2610. var webFonts = false;
  2611. if (browser.versionAtLeast("3.5")) {
  2612. var root = String(document.location).replace(/[^\/]*$/,"");
  2613. if (document.location.protocol !== "file:" || HUB.config.root.match(/^https?:\/\//) ||
  2614. (HUB.config.root+"/").substr(0,root.length) === root) {webFonts = "otf"}
  2615. }
  2616. HTMLCSS.Augment({
  2617. ffVerticalAlignBug: true,
  2618. AccentBug: true,
  2619. allowWebFonts: webFonts
  2620. });
  2621. },
  2622. Safari: function (browser) {
  2623. var v3p0 = browser.versionAtLeast("3.0");
  2624. var v3p1 = browser.versionAtLeast("3.1");
  2625. var trueSafari = navigator.appVersion.match(/ Safari\/\d/) &&
  2626. navigator.appVersion.match(/ Version\/\d/) &&
  2627. navigator.vendor.match(/Apple/);
  2628. var android = (navigator.appVersion.match(/ Android (\d+)\.(\d+)/));
  2629. var forceImages = (v3p1 && browser.isMobile && (
  2630. (navigator.platform.match(/iPad|iPod|iPhone/) && !browser.versionAtLeast("5.0")) ||
  2631. (android != null && (android[1] < 2 || (android[1] == 2 && android[2] < 2)))
  2632. ));
  2633. HTMLCSS.Augment({
  2634. config: {
  2635. styles: {
  2636. ".MathJax img, .MathJax nobr, .MathJax a": {
  2637. // "none" seems to work like "0px" when width is initially 0
  2638. "max-width": "5000em", "max-height": "5000em"
  2639. }
  2640. }
  2641. },
  2642. rfuzz: .011,
  2643. AccentBug: true,
  2644. AdjustSurd: true,
  2645. negativeBBoxes: true,
  2646. safariNegativeSpaceBug: true,
  2647. safariVerticalAlignBug: !v3p1,
  2648. safariTextNodeBug: !v3p0,
  2649. forceReflow: true,
  2650. allowWebFonts: (v3p1 && !forceImages ? "otf" : false)
  2651. });
  2652. if (trueSafari) {
  2653. HTMLCSS.Augment({
  2654. webFontDefault: (browser.isMobile ? "sans-serif" : "serif")
  2655. });
  2656. }
  2657. if (browser.isPC) {
  2658. HTMLCSS.Augment({
  2659. adjustAvailableFonts: HTMLCSS.removeSTIXfonts, // can't access plane1
  2660. checkWebFontsTwice: true // bug in Safari/Win that doesn't update font test div properly
  2661. });
  2662. }
  2663. if (forceImages) {
  2664. // Force image mode for iOS prior to 4.2 and Droid prior to 2.2
  2665. var config = HUB.config["HTML-CSS"];
  2666. if (config) {config.availableFonts = []; config.preferredFont = null}
  2667. else {HUB.config["HTML-CSS"] = {availableFonts: [], preferredFont: null}}
  2668. }
  2669. },
  2670. Chrome: function (browser) {
  2671. HTMLCSS.Augment({
  2672. Em: HTMLCSS.Px, // vertical alignment is better in pixels (since around v20)
  2673. unEm: HTMLCSS.unPx,
  2674. chromeHeightBug: true, // heights can be 1px off from the explicitly set size
  2675. cloneNodeBug: true, // Chrome gets heights wrong with the cloned ones
  2676. rfuzz: .011,
  2677. AccentBug: true,
  2678. AdjustSurd: true,
  2679. negativeBBoxes: true,
  2680. safariNegativeSpaceBug: true,
  2681. safariWebFontSerif: [""],
  2682. forceReflow: true,
  2683. allowWebFonts: (browser.versionAtLeast("4.0") ? "otf" : "svg")
  2684. });
  2685. },
  2686. Opera: function (browser) {
  2687. browser.isMini = (navigator.appVersion.match("Opera Mini") != null);
  2688. HTMLCSS.config.styles[".MathJax .merror"]["vertical-align"] = null;
  2689. HTMLCSS.config.styles[".MathJax span"]["z-index"] = 0;
  2690. HTMLCSS.Augment({
  2691. operaHeightBug: true,
  2692. operaVerticalAlignBug: true,
  2693. operaFontSizeBug: browser.versionAtLeast("10.61"),
  2694. initialSkipBug: true,
  2695. FontFaceBug: true,
  2696. PaddingWidthBug: true,
  2697. allowWebFonts: (browser.versionAtLeast("10.0") && !browser.isMini ? "otf" : false),
  2698. adjustAvailableFonts: HTMLCSS.removeSTIXfonts
  2699. });
  2700. },
  2701. Konqueror: function (browser) {
  2702. HTMLCSS.Augment({
  2703. konquerorVerticalAlignBug: true
  2704. });
  2705. }
  2706. });
  2707. });
  2708. MathJax.Hub.Register.StartupHook("End Cookie", function () {
  2709. if (HUB.config.menuSettings.zoom !== "None")
  2710. {AJAX.Require("[MathJax]/extensions/MathZoom.js")}
  2711. });
  2712. })(MathJax.Ajax, MathJax.Hub, MathJax.OutputJax["HTML-CSS"]);