jax.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
  2. /* vim: set ts=2 et sw=2 tw=80: */
  3. /*************************************************************
  4. *
  5. * MathJax/jax/output/PreviewHTML/jax.js
  6. *
  7. * Implements the PreviewHTML OutputJax that displays mathematics
  8. * using HTML to position the characters from math fonts
  9. * in their proper locations.
  10. *
  11. * ---------------------------------------------------------------------
  12. *
  13. * Copyright (c) 2013-2017 The MathJax Consortium
  14. *
  15. * Licensed under the Apache License, Version 2.0 (the "License");
  16. * you may not use this file except in compliance with the License.
  17. * You may obtain a copy of the License at
  18. *
  19. * http://www.apache.org/licenses/LICENSE-2.0
  20. *
  21. * Unless required by applicable law or agreed to in writing, software
  22. * distributed under the License is distributed on an "AS IS" BASIS,
  23. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24. * See the License for the specific language governing permissions and
  25. * limitations under the License.
  26. */
  27. (function (AJAX,HUB,HTML,PHTML) {
  28. var MML;
  29. var EVENT, TOUCH, HOVER; // filled in later
  30. var FONTS = "'Times New Roman',Times,STIXGeneral,serif";
  31. var STYLES = {
  32. ".MJXp-script": {"font-size":".8em"},
  33. ".MJXp-right": {
  34. "-webkit-transform-origin":"right",
  35. "-moz-transform-origin":"right",
  36. "-ms-transform-origin":"right",
  37. "-o-transform-origin":"right",
  38. "transform-origin":"right"
  39. },
  40. ".MJXp-bold": {"font-weight":"bold"},
  41. ".MJXp-italic": {"font-style":"italic"},
  42. ".MJXp-scr": {"font-family":"MathJax_Script,"+FONTS},
  43. ".MJXp-frak": {"font-family":"MathJax_Fraktur,"+FONTS},
  44. ".MJXp-sf": {"font-family":"MathJax_SansSerif,"+FONTS},
  45. ".MJXp-cal": {"font-family":"MathJax_Caligraphic,"+FONTS},
  46. ".MJXp-mono": {"font-family":"MathJax_Typewriter,"+FONTS},
  47. ".MJXp-largeop": {"font-size":"150%"},
  48. ".MJXp-largeop.MJXp-int": {"vertical-align":"-.2em"},
  49. ".MJXp-math": {
  50. "display": "inline-block",
  51. "line-height": "1.2",
  52. "text-indent": "0",
  53. "font-family": FONTS,
  54. "white-space":"nowrap",
  55. "border-collapse":"collapse"
  56. },
  57. ".MJXp-display": {
  58. "display": "block",
  59. "text-align": "center",
  60. "margin": "1em 0"
  61. },
  62. ".MJXp-math span": {"display": "inline-block"},
  63. ".MJXp-box": {"display":"block!important", "text-align": "center"},
  64. ".MJXp-box:after": {"content": '" "'}, // needed for when there is no DOCTYPE
  65. ".MJXp-rule": {"display":"block!important", "margin-top":".1em"},
  66. ".MJXp-char": {"display":"block!important"},
  67. ".MJXp-mo": {"margin": "0 .15em"},
  68. ".MJXp-mfrac": {"margin": "0 .125em", "vertical-align":".25em"},
  69. ".MJXp-denom": {"display": "inline-table!important", "width":"100%"},
  70. ".MJXp-denom > *": {"display": "table-row!important"},
  71. ".MJXp-surd": {"vertical-align":"top"},
  72. ".MJXp-surd > *": {"display":"block!important"},
  73. ".MJXp-script-box > * ": {"display":"table!important", "height":"50%"},
  74. ".MJXp-script-box > * > *": {"display":"table-cell!important","vertical-align":"top"},
  75. ".MJXp-script-box > *:last-child > *": {"vertical-align":"bottom"},
  76. ".MJXp-script-box > * > * > *": {"display":"block!important"},
  77. ".MJXp-mphantom": {"visibility": "hidden"},
  78. ".MJXp-munderover": {"display":"inline-table!important"},
  79. ".MJXp-over": {"display":"inline-block!important","text-align":"center"},
  80. ".MJXp-over > *": {"display":"block!important"},
  81. ".MJXp-munderover > *": {"display":"table-row!important"},
  82. ".MJXp-mtable": {"vertical-align":".25em", "margin":"0 .125em"},
  83. ".MJXp-mtable > *": {"display":"inline-table!important", "vertical-align":"middle"},
  84. ".MJXp-mtr": {"display":"table-row!important"},
  85. ".MJXp-mtd": {"display":"table-cell!important","text-align":"center","padding":".5em 0 0 .5em"},
  86. ".MJXp-mtr > .MJXp-mtd:first-child": {"padding-left":0},
  87. ".MJXp-mtr:first-child > .MJXp-mtd": {"padding-top":0},
  88. ".MJXp-mlabeledtr": {"display":"table-row!important"},
  89. ".MJXp-mlabeledtr > .MJXp-mtd:first-child": {"padding-left":0},
  90. ".MJXp-mlabeledtr:first-child > .MJXp-mtd": {"padding-top":0},
  91. ".MJXp-merror": {
  92. "background-color": "#FFFF88",
  93. color: "#CC0000",
  94. border: "1px solid #CC0000",
  95. padding: "1px 3px",
  96. "font-style": "normal",
  97. "font-size": "90%"
  98. }
  99. };
  100. (function () {
  101. for (var i = 0; i < 10; i++) {
  102. var scale = "scaleX(."+i+")";
  103. STYLES[".MJXp-scale"+i] = {
  104. "-webkit-transform":scale,
  105. "-moz-transform":scale,
  106. "-ms-transform":scale,
  107. "-o-transform":scale,
  108. "transform":scale
  109. }
  110. }
  111. })();
  112. var BIGDIMEN = 1000000;
  113. var V = "V", H = "H";
  114. PHTML.Augment({
  115. settings: HUB.config.menuSettings,
  116. config: {styles: STYLES},
  117. hideProcessedMath: false, // use display:none until all math is processed
  118. maxStretchyParts: 1000, // limit the number of parts allowed for
  119. // stretchy operators. See issue 366.
  120. Config: function () {
  121. if (!this.require) {this.require = []}
  122. this.SUPER(arguments).Config.call(this); var settings = this.settings;
  123. if (settings.scale) {this.config.scale = settings.scale}
  124. this.require.push(MathJax.OutputJax.extensionDir+"/MathEvents.js");
  125. },
  126. Startup: function () {
  127. //
  128. // Set up event handling
  129. //
  130. EVENT = MathJax.Extension.MathEvents.Event;
  131. TOUCH = MathJax.Extension.MathEvents.Touch;
  132. HOVER = MathJax.Extension.MathEvents.Hover;
  133. this.ContextMenu = EVENT.ContextMenu;
  134. this.Mousedown = EVENT.AltContextMenu;
  135. this.Mouseover = HOVER.Mouseover;
  136. this.Mouseout = HOVER.Mouseout;
  137. this.Mousemove = HOVER.Mousemove;
  138. //
  139. // Determine pixels per inch
  140. //
  141. var div = HTML.addElement(document.body,"div",{style:{width:"5in"}});
  142. this.pxPerInch = div.offsetWidth/5; div.parentNode.removeChild(div);
  143. //
  144. // Set up styles and preload web fonts
  145. //
  146. return AJAX.Styles(this.config.styles,["InitializePHTML",this]);
  147. },
  148. InitializePHTML: function () {
  149. },
  150. preTranslate: function (state) {
  151. var scripts = state.jax[this.id], i, m = scripts.length,
  152. script, prev, span, div, jax;
  153. //
  154. // Loop through the scripts
  155. //
  156. for (i = 0; i < m; i++) {
  157. script = scripts[i]; if (!script.parentNode) continue;
  158. //
  159. // Remove any existing output
  160. //
  161. prev = script.previousSibling;
  162. if (prev && String(prev.className).match(/^MathJax(_PHTML)?(_Display)?( MathJax_Process(ing|ed))?$/))
  163. {prev.parentNode.removeChild(prev)}
  164. //
  165. // Add the span, and a div if in display mode,
  166. // then mark it as being processed
  167. //
  168. jax = script.MathJax.elementJax; if (!jax) continue;
  169. jax.PHTML = {display: (jax.root.Get("display") === "block")}
  170. span = div = HTML.Element("span",{
  171. className:"MathJax_PHTML", id:jax.inputID+"-Frame", isMathJax:true, jaxID:this.id,
  172. oncontextmenu:EVENT.Menu, onmousedown: EVENT.Mousedown,
  173. onmouseover:EVENT.Mouseover, onmouseout:EVENT.Mouseout, onmousemove:EVENT.Mousemove,
  174. onclick:EVENT.Click, ondblclick:EVENT.DblClick,
  175. // Added for keyboard accessible menu.
  176. onkeydown: EVENT.Keydown, tabIndex: HUB.getTabOrder(jax)
  177. });
  178. if (HUB.Browser.noContextMenu) {
  179. span.ontouchstart = TOUCH.start;
  180. span.ontouchend = TOUCH.end;
  181. }
  182. if (jax.PHTML.display) {
  183. div = HTML.Element("div",{className:"MathJax_PHTML_Display"});
  184. div.appendChild(span);
  185. }
  186. //
  187. div.className += " MathJax_Processing";
  188. script.parentNode.insertBefore(div,script);
  189. }
  190. },
  191. Translate: function (script,state) {
  192. if (!script.parentNode) return;
  193. //
  194. // Get the data about the math
  195. //
  196. var jax = script.MathJax.elementJax, math = jax.root,
  197. span = document.getElementById(jax.inputID+"-Frame"),
  198. div = (jax.PHTML.display ? span.parentNode : span);
  199. //
  200. // Typeset the math
  201. //
  202. this.initPHTML(math,span);
  203. // math.setTeXclass();
  204. try {math.toPreviewHTML(span)} catch (err) {
  205. if (err.restart) {while (span.firstChild) {span.removeChild(span.firstChild)}}
  206. throw err;
  207. }
  208. //
  209. // Put it in place, and remove the processing marker
  210. //
  211. div.className = div.className.split(/ /)[0];
  212. //
  213. // Check if we are hiding the math until more is processed
  214. //
  215. if (this.hideProcessedMath) {
  216. //
  217. // Hide the math and don't let its preview be removed
  218. //
  219. div.className += " MathJax_Processed";
  220. if (script.MathJax.preview) {
  221. jax.PHTML.preview = script.MathJax.preview;
  222. delete script.MathJax.preview;
  223. }
  224. }
  225. },
  226. postTranslate: function (state) {
  227. var scripts = state.jax[this.id];
  228. if (!this.hideProcessedMath) return;
  229. for (var i = 0, m = scripts.length; i < m; i++) {
  230. var script = scripts[i];
  231. if (script && script.MathJax.elementJax) {
  232. //
  233. // Remove the processed marker
  234. //
  235. script.previousSibling.className = script.previousSibling.className.split(/ /)[0];
  236. var data = script.MathJax.elementJax.PHTML;
  237. //
  238. // Remove the preview, if any
  239. //
  240. if (data.preview) {
  241. data.preview.innerHTML = "";
  242. data.preview.style.display = "none";
  243. script.MathJax.preview = data.preview;
  244. delete data.preview;
  245. }
  246. }
  247. }
  248. },
  249. getJaxFromMath: function (math) {
  250. if (math.parentNode.className.match(/MathJax_PHTML_Display/)) {math = math.parentNode}
  251. do {math = math.nextSibling} while (math && math.nodeName.toLowerCase() !== "script");
  252. return HUB.getJaxFor(math);
  253. },
  254. getHoverSpan: function (jax,math) {return jax.root.PHTMLspanElement()},
  255. getHoverBBox: function (jax,span,math) {
  256. var bbox = jax.root.PHTML, em = jax.PHTML.outerEm;
  257. var BBOX = {w:bbox.w*em, h:bbox.h*em, d:bbox.d*em};
  258. if (bbox.width) {BBOX.width = bbox.width}
  259. return BBOX;
  260. },
  261. Zoom: function (jax,span,math,Mw,Mh) {
  262. //
  263. // Re-render at larger size
  264. //
  265. span.className = "MathJax";
  266. this.idPostfix = "-zoom"; jax.root.toPHTML(span,span); this.idPostfix = "";
  267. //
  268. // Get height and width of zoomed math and original math
  269. //
  270. span.style.position = "absolute";
  271. if (!width) {math.style.position = "absolute"}
  272. var zW = span.offsetWidth, zH = span.offsetHeight,
  273. mH = math.offsetHeight, mW = math.offsetWidth;
  274. if (mW === 0) {mW = math.parentNode.offsetWidth}; // IE7 gets mW == 0?
  275. span.style.position = math.style.position = "";
  276. //
  277. return {Y:-EVENT.getBBox(span).h, mW:mW, mH:mH, zW:zW, zH:zH};
  278. },
  279. initPHTML: function (math,span) {},
  280. Remove: function (jax) {
  281. var span = document.getElementById(jax.inputID+"-Frame");
  282. if (span) {
  283. if (jax.PHTML.display) {span = span.parentNode}
  284. span.parentNode.removeChild(span);
  285. }
  286. delete jax.PHTML;
  287. },
  288. ID: 0, idPostfix: "",
  289. GetID: function () {this.ID++; return this.ID},
  290. VARIANT: {
  291. "bold": "MJXp-bold",
  292. "italic": "MJXp-italic",
  293. "bold-italic": "MJXp-bold MJXp-italic",
  294. "script": "MJXp-scr",
  295. "bold-script": "MJXp-scr MJXp-bold",
  296. "fraktur": "MJXp-frak",
  297. "bold-fraktur": "MJXp-frak MJXp-bold",
  298. "monospace": "MJXp-mono",
  299. "sans-serif": "MJXp-sf",
  300. "-tex-caligraphic": "MJXp-cal"
  301. },
  302. MATHSPACE: {
  303. veryverythinmathspace: 1/18,
  304. verythinmathspace: 2/18,
  305. thinmathspace: 3/18,
  306. mediummathspace: 4/18,
  307. thickmathspace: 5/18,
  308. verythickmathspace: 6/18,
  309. veryverythickmathspace: 7/18,
  310. negativeveryverythinmathspace: -1/18,
  311. negativeverythinmathspace: -2/18,
  312. negativethinmathspace: -3/18,
  313. negativemediummathspace: -4/18,
  314. negativethickmathspace: -5/18,
  315. negativeverythickmathspace: -6/18,
  316. negativeveryverythickmathspace: -7/18,
  317. thin: .08,
  318. medium: .1,
  319. thick: .15,
  320. infinity: BIGDIMEN
  321. },
  322. TeX: {
  323. x_height: .430554
  324. },
  325. pxPerInch: 72,
  326. em: 16,
  327. // ### FIXME: add more here
  328. DELIMITERS: {
  329. "(": {dir:V},
  330. "{": {dir:V, w:.58},
  331. "[": {dir:V},
  332. "|": {dir:V, w:.275},
  333. ")": {dir:V},
  334. "}": {dir:V, w:.58},
  335. "]": {dir:V},
  336. "/": {dir:V},
  337. "\\": {dir:V},
  338. "\u2223": {dir:V, w:.275},
  339. "\u2225": {dir:V, w:.55},
  340. "\u230A": {dir:V, w:.5},
  341. "\u230B": {dir:V, w:.5},
  342. "\u2308": {dir:V, w:.5},
  343. "\u2309": {dir:V, w:.5},
  344. "\u27E8": {dir:V, w:.5},
  345. "\u27E9": {dir:V, w:.5},
  346. "\u2191": {dir:V, w:.65},
  347. "\u2193": {dir:V, w:.65},
  348. "\u21D1": {dir:V, w:.75},
  349. "\u21D3": {dir:V, w:.75},
  350. "\u2195": {dir:V, w:.65},
  351. "\u21D5": {dir:V, w:.75},
  352. "\u27EE": {dir:V, w:.275},
  353. "\u27EF": {dir:V, w:.275},
  354. "\u23B0": {dir:V, w:.6},
  355. "\u23B1": {dir:V, w:.6}
  356. },
  357. REMAPACCENT: {
  358. "\u20D7":"\u2192", // vector arrow
  359. "'": "\u02CB",
  360. "`": "\u02CA",
  361. ".": "\u02D9",
  362. "^": "\u02C6",
  363. "-": "\u02C9",
  364. "~": "\u02DC",
  365. "\u00AF": "\u02C9", // macron
  366. "\u00B0": "\u02DA", // degree sign
  367. "\u00B4": "\u02CA", // acute accent
  368. "\u0300": "\u02CB", // combining grave
  369. "\u0301": "\u02CA", // combining acute
  370. "\u0302": "\u02C6", // combining circumflex
  371. "\u0303": "\u02DC", // combinig tilde
  372. "\u0304": "\u02C9", // combining macron
  373. "\u0305": "\u02C9", // combining overline
  374. "\u0306": "\u02D8", // combining breve
  375. "\u0307": "\u02D9", // combining dot
  376. "\u0308": "\u00A8", // combining double dot
  377. "\u030C": "\u02C7" // combining caron
  378. },
  379. REMAPACCENTUNDER: {
  380. },
  381. length2em: function (length,size) {
  382. if (typeof(length) !== "string") {length = length.toString()}
  383. if (length === "") {return ""}
  384. if (length === MML.SIZE.NORMAL) {return 1}
  385. if (length === MML.SIZE.BIG) {return 2}
  386. if (length === MML.SIZE.SMALL) {return .71}
  387. if (this.MATHSPACE[length]) {return this.MATHSPACE[length]}
  388. var match = length.match(/^\s*([-+]?(?:\.\d+|\d+(?:\.\d*)?))?(pt|em|ex|mu|px|pc|in|mm|cm|%)?/);
  389. var m = parseFloat(match[1]||"1"), unit = match[2];
  390. if (size == null) {size = 1}
  391. if (unit === "em") {return m}
  392. if (unit === "ex") {return m * this.TeX.x_height}
  393. if (unit === "%") {return m / 100 * size}
  394. if (unit === "px") {return m / this.em}
  395. if (unit === "pt") {return m / 10} // 10 pt to an em
  396. if (unit === "pc") {return m * 1.2} // 12 pt to a pc
  397. if (unit === "in") {return m * this.pxPerInch / this.em}
  398. if (unit === "cm") {return m * this.pxPerInch / this.em / 2.54} // 2.54 cm to an inch
  399. if (unit === "mm") {return m * this.pxPerInch / this.em / 25.4} // 10 mm to a cm
  400. if (unit === "mu") {return m / 18} // 18mu to an em for the scriptlevel
  401. return m*size; // relative to given size (or 1em as default)
  402. },
  403. Em: function (m) {
  404. if (Math.abs(m) < .001) return "0em";
  405. return (m.toFixed(3).replace(/\.?0+$/,""))+"em";
  406. },
  407. arrayEntry: function (a,i) {return a[Math.max(0,Math.min(i,a.length-1))]}
  408. });
  409. MathJax.Hub.Register.StartupHook("mml Jax Ready",function () {
  410. MML = MathJax.ElementJax.mml;
  411. MML.mbase.Augment({
  412. toPreviewHTML: function (span,options) {
  413. return this.PHTMLdefaultSpan(span,options);
  414. },
  415. PHTMLdefaultSpan: function (span,options) {
  416. if (!options) options = {};
  417. span = this.PHTMLcreateSpan(span);
  418. this.PHTMLhandleStyle(span);
  419. this.PHTMLhandleColor(span);
  420. if (this.isToken) this.PHTMLhandleToken(span);
  421. for (var i = 0, m = this.data.length; i < m; i++) this.PHTMLaddChild(span,i,options);
  422. return span;
  423. },
  424. PHTMLaddChild: function (span,i,options) {
  425. var child = this.data[i];
  426. if (child) {
  427. if (options.childSpans)
  428. span = HTML.addElement(span,"span",{className:options.className});
  429. child.toPreviewHTML(span);
  430. if (!options.noBBox) {
  431. this.PHTML.w += child.PHTML.w + child.PHTML.l + child.PHTML.r;
  432. if (child.PHTML.h > this.PHTML.h) this.PHTML.h = child.PHTML.h;
  433. if (child.PHTML.d > this.PHTML.d) this.PHTML.d = child.PHTML.d;
  434. if (child.PHTML.t > this.PHTML.t) this.PHTML.t = child.PHTML.t;
  435. if (child.PHTML.b > this.PHTML.b) this.PHTML.b = child.PHTML.b;
  436. }
  437. } else if (options.forceChild) {HTML.addElement(span,"span")}
  438. },
  439. PHTMLstretchChild: function (i,H,D) {
  440. var data = this.data[i];
  441. if (data && data.PHTMLcanStretch("Vertical",H,D)) {
  442. var bbox = this.PHTML, dbox = data.PHTML, w = dbox.w;
  443. data.PHTMLstretchV(H,D);
  444. bbox.w += dbox.w - w;
  445. if (dbox.h > bbox.h) bbox.h = dbox.h;
  446. if (dbox.d > bbox.d) bbox.d = dbox.d;
  447. }
  448. },
  449. PHTMLcreateSpan: function (span) {
  450. if (!this.PHTML) this.PHTML = {};
  451. this.PHTML = {w:0, h:0, d:0, l:0, r:0, t:0, b:0};
  452. if (this.inferred) return span;
  453. // ### FIXME: This is a hack to handle the different spacing of the
  454. // ### integral sign in Times compared to CM fonts
  455. if (this.type === "mo" && this.data.join("") === "\u222B") {PHTML.lastIsInt = true}
  456. else if (this.type !== "mspace" || this.width !== "negativethinmathspace") {PHTML.lastIsInt = false}
  457. // ###
  458. if (!this.PHTMLspanID) {this.PHTMLspanID = PHTML.GetID()};
  459. var id = (this.id || "MJXp-Span-"+this.PHTMLspanID);
  460. return HTML.addElement(span,"span",{className:"MJXp-"+this.type, id:id});
  461. },
  462. PHTMLspanElement: function () {
  463. if (!this.PHTMLspanID) {return null}
  464. return document.getElementById(this.id||"MJXp-Span-"+this.PHTMLspanID);
  465. },
  466. PHTMLhandleToken: function (span) {
  467. var values = this.getValues("mathvariant");
  468. if (values.mathvariant !== MML.VARIANT.NORMAL) {
  469. span.className += " "+PHTML.VARIANT[values.mathvariant];
  470. }
  471. },
  472. PHTMLhandleStyle: function (span) {
  473. if (this.style) span.style.cssText = this.style;
  474. },
  475. PHTMLhandleColor: function (span) {
  476. if (this.mathcolor) {span.style.color = this.mathcolor}
  477. if (this.mathbackground) {span.style.backgroundColor = this.mathbackground}
  478. },
  479. PHTMLhandleScriptlevel: function (span) {
  480. // ### FIXME: Need to prevent getting too small
  481. // ### and should keep track of scaling so it can be compensated for
  482. var level = this.Get("scriptlevel");
  483. if (level) span.className += " MJXp-script";
  484. },
  485. PHTMLhandleText: function (span,text) {
  486. var c, n;
  487. var H = 0, D = 0, W = 0;
  488. for (var i = 0, m = text.length; i < m; i++) {
  489. n = text.charCodeAt(i); c = text.charAt(i);
  490. if (n >= 0xD800 && n < 0xDBFF) {
  491. i++; n = (((n-0xD800)<<10)+(text.charCodeAt(i)-0xDC00))+0x10000;
  492. }
  493. var h = .7, d = .22, w = .5;
  494. if (n < 127) {
  495. if (c.match(/[A-Za-ehik-or-xz0-9]/)) d = 0;
  496. if (c.match(/[A-HK-Z]/)) {w = .67} else if (c.match(/[IJ]/)) {w = .36}
  497. if (c.match(/[acegm-su-z]/)) {h = .45} else if (c.match(/[ij]/)) {h = .75}
  498. if (c.match(/[ijlt]/)) w = .28;
  499. }
  500. if (PHTML.DELIMITERS[c]) {w = PHTML.DELIMITERS[c].w || .4}
  501. // ### FIXME: handle Greek
  502. // ### Combining diacriticals (all sets), spacing modifiers
  503. // ### arrows (all sets), widths of braces
  504. if (h > H) H = h; if (d > D) D = d; W += w;
  505. }
  506. if (!this.CHML) this.PHTML = {};
  507. this.PHTML = {h:.9, d:.3, w:W, l:0, r:0, t:H, b:D};
  508. HTML.addText(span,text);
  509. },
  510. PHTMLbboxFor: function (n) {
  511. if (this.data[n] && this.data[n].PHTML) return this.data[n].PHTML;
  512. return {w:0, h:0, d:0, l:0, r:0, t:0, b:0};
  513. },
  514. PHTMLcanStretch: function (direction,H,D) {
  515. if (this.isEmbellished()) {
  516. var core = this.Core();
  517. if (core && core !== this) {return core.PHTMLcanStretch(direction,H,D)}
  518. }
  519. return false;
  520. },
  521. PHTMLstretchV: function (h,d) {},
  522. PHTMLstretchH: function (w) {},
  523. CoreParent: function () {
  524. var parent = this;
  525. while (parent && parent.isEmbellished() &&
  526. parent.CoreMO() === this && !parent.isa(MML.math)) {parent = parent.Parent()}
  527. return parent;
  528. },
  529. CoreText: function (parent) {
  530. if (!parent) {return ""}
  531. if (parent.isEmbellished()) {return parent.CoreMO().data.join("")}
  532. while ((parent.isa(MML.mrow) || parent.isa(MML.TeXAtom) ||
  533. parent.isa(MML.mstyle) || parent.isa(MML.mphantom)) &&
  534. parent.data.length === 1 && parent.data[0]) {parent = parent.data[0]}
  535. if (!parent.isToken) {return ""} else {return parent.data.join("")}
  536. }
  537. });
  538. MML.chars.Augment({
  539. toPreviewHTML: function (span) {
  540. var text = this.toString().replace(/[\u2061-\u2064]/g,"");
  541. this.PHTMLhandleText(span,text);
  542. }
  543. });
  544. MML.entity.Augment({
  545. toPreviewHTML: function (span) {
  546. var text = this.toString().replace(/[\u2061-\u2064]/g,"");
  547. this.PHTMLhandleText(span,text);
  548. }
  549. });
  550. MML.math.Augment({
  551. toPreviewHTML: function (span) {
  552. span = this.PHTMLdefaultSpan(span);
  553. if (this.Get("display") === "block") {span.className += " MJXp-display"}
  554. return span;
  555. }
  556. });
  557. MML.mo.Augment({
  558. toPreviewHTML: function (span) {
  559. span = this.PHTMLdefaultSpan(span);
  560. this.PHTMLadjustAccent(span);
  561. var values = this.getValues("lspace","rspace","scriptlevel","displaystyle","largeop");
  562. if (values.scriptlevel === 0) {
  563. this.PHTML.l = PHTML.length2em(values.lspace);
  564. this.PHTML.r = PHTML.length2em(values.rspace);
  565. span.style.marginLeft = PHTML.Em(this.PHTML.l);
  566. span.style.marginRight = PHTML.Em(this.PHTML.r);
  567. } else {
  568. this.PHTML.l = .15;
  569. this.PHTML.r = .1;
  570. }
  571. if (values.displaystyle && values.largeop) {
  572. var box = HTML.Element("span",{className:"MJXp-largeop"});
  573. box.appendChild(span.firstChild); span.appendChild(box);
  574. this.PHTML.h *= 1.2; this.PHTML.d *= 1.2;
  575. if (this.data.join("") === "\u222B") box.className += " MJXp-int";
  576. }
  577. // ### FIXME: Handle embellished op spacing
  578. // ### FIXME: Remap minus signs
  579. return span;
  580. },
  581. PHTMLadjustAccent: function (span) {
  582. var parent = this.CoreParent();
  583. if (parent && parent.isa(MML.munderover) &&
  584. this.CoreText(parent.data[parent.base]).length === 1) {
  585. var over = parent.data[parent.over], under = parent.data[parent.under];
  586. var c = this.data.join(""), C;
  587. if (over && this === over.CoreMO() && parent.Get("accent")) {C = PHTML.REMAPACCENT[c]}
  588. else if (under && this === under.CoreMO() && parent.Get("accentunder")) {C = PHTML.REMAPACCENTUNDER[c]}
  589. if (C) c = span.innerHTML = C;
  590. if (c.match(/[\u02C6-\u02DC\u00A8]/)) {this.PHTML.acc = -.52}
  591. else if (c === "\u2192") {this.PHTML.acc = -.15; this.PHTML.vec = true}
  592. }
  593. },
  594. PHTMLcanStretch: function (direction,H,D) {
  595. if (!this.Get("stretchy")) {return false}
  596. var c = this.data.join("");
  597. if (c.length > 1) {return false}
  598. c = PHTML.DELIMITERS[c];
  599. var stretch = (c && c.dir === direction.substr(0,1));
  600. if (stretch) {
  601. stretch = (this.PHTML.h !== H || this.PHTML.d !== D ||
  602. (this.Get("minsize",true) || this.Get("maxsize",true)));
  603. }
  604. return stretch;
  605. },
  606. PHTMLstretchV: function (h,d) {
  607. var span = this.PHTMLspanElement(), bbox = this.PHTML; //bbox.w = .4; // ## adjust width
  608. var values = this.getValues("symmetric","maxsize","minsize");
  609. if (values.symmetric) {H = 2*Math.max(h-.25,d+.25)} else {H = h + d}
  610. values.maxsize = PHTML.length2em(values.maxsize,bbox.h+bbox.d);
  611. values.minsize = PHTML.length2em(values.minsize,bbox.h+bbox.d);
  612. H = Math.max(values.minsize,Math.min(values.maxsize,H));
  613. var scale = H/(bbox.h+bbox.d-.3); // ### adjusted for extra tall bbox
  614. var box = HTML.Element("span",{style:{"font-size":PHTML.Em(scale)}});
  615. if (scale > 1.25) {
  616. var sX = Math.ceil(1.25/scale * 10);
  617. box.className = "MJXp-right MJXp-scale"+sX;
  618. box.style.marginLeft = PHTML.Em(bbox.w*(sX/10-1)+.07);
  619. bbox.w *= scale*sX/10;
  620. }
  621. box.appendChild(span.firstChild); span.appendChild(box);
  622. if (values.symmetric) span.style.verticalAlign = PHTML.Em(.25*(1-scale));
  623. }
  624. });
  625. MML.mspace.Augment({
  626. toPreviewHTML: function (span) {
  627. span = this.PHTMLdefaultSpan(span);
  628. var values = this.getValues("height","depth","width");
  629. var w = PHTML.length2em(values.width),
  630. h = PHTML.length2em(values.height),
  631. d = PHTML.length2em(values.depth);
  632. var bbox = this.PHTML;
  633. bbox.w = w; bbox.h = h; bbox.d = d;
  634. if (w < 0) {
  635. // ### FIXME: lastIsInt hack
  636. if (!PHTML.lastIsInt) span.style.marginLeft = PHTML.Em(w);
  637. w = 0;
  638. }
  639. span.style.width = PHTML.Em(w);
  640. span.style.height = PHTML.Em(h+d);
  641. if (d) span.style.verticalAlign = PHTML.Em(-d);
  642. return span;
  643. }
  644. });
  645. MML.mpadded.Augment({
  646. toPreviewHTML: function (span) {
  647. span = this.PHTMLdefaultSpan(span,{
  648. childSpans:true, className:"MJXp-box", forceChild:true
  649. });
  650. var child = span.firstChild;
  651. var values = this.getValues("width","height","depth","lspace","voffset");
  652. var dimen = this.PHTMLdimen(values.lspace);
  653. var T = 0, B = 0, L = dimen.len, R = -dimen.len, V = 0;
  654. if (values.width !== "") {
  655. dimen = this.PHTMLdimen(values.width,"w",0);
  656. if (dimen.pm) {R += dimen.len} else {span.style.width = PHTML.Em(dimen.len)}
  657. }
  658. if (values.height !== "") {
  659. dimen = this.PHTMLdimen(values.height,"h",0);
  660. if (!dimen.pm) T += -this.PHTMLbboxFor(0).h;
  661. T += dimen.len;
  662. }
  663. if (values.depth !== "") {
  664. dimen = this.PHTMLdimen(values.depth,"d",0);
  665. if (!dimen.pm) {B += -this.PHTMLbboxFor(0).d; V += -dimen.len}
  666. B += dimen.len;
  667. }
  668. if (values.voffset !== "") {
  669. dimen = this.PHTMLdimen(values.voffset);
  670. T -= dimen.len; B += dimen.len;
  671. V += dimen.len;
  672. }
  673. if (T) child.style.marginTop = PHTML.Em(T);
  674. if (B) child.style.marginBottom = PHTML.Em(B);
  675. if (L) child.style.marginLeft = PHTML.Em(L);
  676. if (R) child.style.marginRight = PHTML.Em(R);
  677. if (V) span.style.verticalAlign = PHTML.Em(V);
  678. return span;
  679. },
  680. PHTMLdimen: function (length,d,m) {
  681. if (m == null) {m = -BIGDIMEN}
  682. length = String(length);
  683. var match = length.match(/width|height|depth/);
  684. var size = (match ? this.PHTML[match[0].charAt(0)] : (d ? this.PHTML[d] : 0));
  685. return {len: PHTML.length2em(length,size)||0, pm: !!length.match(/^[-+]/)};
  686. }
  687. });
  688. MML.munderover.Augment({
  689. toPreviewHTML: function (span) {
  690. var values = this.getValues("displaystyle","accent","accentunder","align");
  691. var base = this.data[this.base];
  692. if (!values.displaystyle && base != null &&
  693. (base.movablelimits || base.CoreMO().Get("movablelimits"))) {
  694. span = MML.msubsup.prototype.toPreviewHTML.call(this,span);
  695. //
  696. // Change class to msubsup for CSS rules.
  697. // ### FIXME: should this be handled via adding another class instead?
  698. //
  699. span.className = span.className.replace(/munderover/,"msubsup");
  700. return span;
  701. }
  702. span = this.PHTMLdefaultSpan(span,{childSpans:true, className:"", noBBox:true});
  703. var obox = this.PHTMLbboxFor(this.over),
  704. ubox = this.PHTMLbboxFor(this.under),
  705. bbox = this.PHTMLbboxFor(this.base),
  706. BBOX = this.PHTML, acc = obox.acc;
  707. if (this.data[this.over]) {
  708. if (span.lastChild.firstChild){
  709. span.lastChild.firstChild.style.marginLeft = obox.l =
  710. span.lastChild.firstChild.style.marginRight = obox.r = 0;
  711. }
  712. var over = HTML.Element("span",{},[["span",{className:"MJXp-over"}]]);
  713. over.firstChild.appendChild(span.lastChild);
  714. if (span.childNodes.length > (this.data[this.under] ? 1 : 0))
  715. over.firstChild.appendChild(span.firstChild);
  716. this.data[this.over].PHTMLhandleScriptlevel(over.firstChild.firstChild);
  717. if (acc != null) {
  718. if (obox.vec) {
  719. over.firstChild.firstChild.firstChild.style.fontSize = "60%";
  720. obox.h *= .6; obox.d *= .6; obox.w *= .6;
  721. }
  722. acc = acc - obox.d + .1; if (bbox.t != null) {acc += bbox.t - bbox.h}
  723. over.firstChild.firstChild.style.marginBottom = PHTML.Em(acc);
  724. }
  725. if (span.firstChild) {span.insertBefore(over,span.firstChild)}
  726. else {span.appendChild(over)}
  727. }
  728. if (this.data[this.under]) {
  729. if (span.lastChild.firstChild) {
  730. span.lastChild.firstChild.style.marginLeft = ubox.l =
  731. span.lastChild.firstChild.marginRight = ubox.r = 0;
  732. }
  733. this.data[this.under].PHTMLhandleScriptlevel(span.lastChild);
  734. }
  735. BBOX.w = Math.max(.8*obox.w,.8*ubox.w,bbox.w);
  736. BBOX.h = .8*(obox.h+obox.d+(acc||0)) + bbox.h;
  737. BBOX.d = bbox.d + .8*(ubox.h+ubox.d);
  738. return span;
  739. }
  740. });
  741. MML.msubsup.Augment({
  742. toPreviewHTML: function (span) {
  743. span = this.PHTMLdefaultSpan(span,{noBBox:true});
  744. if (!this.data[this.base]) {
  745. if (span.firstChild) {span.insertBefore(HTML.Element("span"),span.firstChild)}
  746. else {span.appendChild(HTML.Element("span"))}
  747. }
  748. var base = this.data[this.base], sub = this.data[this.sub], sup = this.data[this.sup];
  749. if (!base) base = {bbox: {h:.8, d:.2}};
  750. span.firstChild.style.marginRight = ".05em";
  751. var h = Math.max(.4,base.PHTML.h-.4),
  752. d = Math.max(.2,base.PHTML.d+.1);
  753. var bbox = this.PHTML;
  754. if (sup && sub) {
  755. var box = HTML.Element("span",{className:"MJXp-script-box", style:{
  756. height: PHTML.Em(h+sup.PHTML.h*.8 + d+sub.PHTML.d*.8),
  757. "vertical-align": PHTML.Em(-d-sub.PHTML.d*.8)
  758. }},[
  759. ["span",{},[["span",{},[["span",{
  760. style:{"margin-bottom":PHTML.Em(-(sup.PHTML.d-.05))}
  761. }]]]]],
  762. ["span",{},[["span",{},[["span",{
  763. style:{"margin-top":PHTML.Em(-(sup.PHTML.h-.05))}
  764. }]]]]]
  765. ]);
  766. sub.PHTMLhandleScriptlevel(box.firstChild);
  767. sup.PHTMLhandleScriptlevel(box.lastChild);
  768. box.firstChild.firstChild.firstChild.appendChild(span.lastChild);
  769. box.lastChild.firstChild.firstChild.appendChild(span.lastChild);
  770. span.appendChild(box);
  771. bbox.h = Math.max(base.PHTML.h,sup.PHTML.h*.8+h);
  772. bbox.d = Math.max(base.PHTML.d,sub.PHTML.d*.8+d);
  773. bbox.w = base.PHTML.w + Math.max(sup.PHTML.w,sub.PHTML.w) + .07;
  774. } else if (sup) {
  775. span.lastChild.style.verticalAlign = PHTML.Em(h);
  776. sup.PHTMLhandleScriptlevel(span.lastChild);
  777. bbox.h = Math.max(base.PHTML.h,sup.PHTML.h*.8+h);
  778. bbox.d = Math.max(base.PHTML.d,sup.PHTML.d*.8-h);
  779. bbox.w = base.PHTML.w + sup.PHTML.w + .07;
  780. } else if (sub) {
  781. span.lastChild.style.verticalAlign = PHTML.Em(-d);
  782. sub.PHTMLhandleScriptlevel(span.lastChild);
  783. bbox.h = Math.max(base.PHTML.h,sub.PHTML.h*.8-d);
  784. bbox.d = Math.max(base.PHTML.d,sub.PHTML.d*.8+d);
  785. bbox.w = base.PHTML.w + sub.PHTML.w + .07;
  786. }
  787. return span;
  788. }
  789. });
  790. MML.mfrac.Augment({
  791. toPreviewHTML: function (span) {
  792. span = this.PHTMLdefaultSpan(span,{
  793. childSpans:true, className:"MJXp-box", forceChild:true, noBBox:true
  794. });
  795. var values = this.getValues("linethickness","displaystyle");
  796. if (!values.displaystyle) {
  797. if (this.data[0]) this.data[0].PHTMLhandleScriptlevel(span.firstChild);
  798. if (this.data[1]) this.data[1].PHTMLhandleScriptlevel(span.lastChild);
  799. }
  800. var denom = HTML.Element("span",{className:"MJXp-box"},[
  801. ["span",{className:"MJXp-denom"},[ // inline-table
  802. ["span",{},[["span",{className:"MJXp-rule",style:{height:"1em"}}]]],
  803. ["span"] // spans are table-row
  804. ]]
  805. ]);
  806. denom.firstChild.lastChild.appendChild(span.lastChild);
  807. span.appendChild(denom);
  808. var nbox = this.PHTMLbboxFor(0), dbox = this.PHTMLbboxFor(1), bbox = this.PHTML;
  809. bbox.w = Math.max(nbox.w,dbox.w) * .8;
  810. bbox.h = nbox.h+nbox.d + .1 + .25;
  811. bbox.d = dbox.h+dbox.d - .25;
  812. bbox.l = bbox.r = .125;
  813. values.linethickness = Math.max(0,PHTML.length2em(values.linethickness||"0",0));
  814. if (values.linethickness) {
  815. var rule = denom.firstChild.firstChild.firstChild;
  816. var t = PHTML.Em(values.linethickness);
  817. rule.style.borderTop = "none";
  818. rule.style.borderBottom = (values.linethickness < .15 ? "1px" : t)+" solid";
  819. rule.style.margin = t+" 0";
  820. t = values.linethickness;
  821. denom.style.marginTop = PHTML.Em(3*t-1.2);
  822. span.style.verticalAlign = PHTML.Em(1.5*t + .1);
  823. bbox.h += 1.5*t - .1; bbox.d += 1.5*t;
  824. } else {
  825. denom.style.marginTop = "-.7em";
  826. }
  827. return span;
  828. }
  829. });
  830. MML.msqrt.Augment({
  831. toPreviewHTML: function (span) {
  832. span = this.PHTMLdefaultSpan(span,{
  833. childSpans:true, className:"MJXp-box", forceChild:true, noBBox:true
  834. });
  835. this.PHTMLlayoutRoot(span,span.firstChild);
  836. return span;
  837. },
  838. PHTMLlayoutRoot: function (span,base) {
  839. var bbox = this.PHTMLbboxFor(0);
  840. var scale = Math.ceil((bbox.h+bbox.d+.14)*100), t = PHTML.Em(14/scale);
  841. var surd = HTML.Element("span",{className:"MJXp-surd"},[
  842. ["span",{style:{"font-size":scale+"%","margin-top":t}},["\u221A"]]
  843. ]);
  844. var root = HTML.Element("span",{className:"MJXp-root"},[
  845. ["span",{className:"MJXp-rule",style:{"border-top":".08em solid"}}]
  846. ]);
  847. var W = (1.2/2.2)*scale/100; // width-of-surd = (height/H-to-W-ratio)
  848. if (scale > 150) {
  849. var sX = Math.ceil(150/scale * 10);
  850. surd.firstChild.className = "MJXp-right MJXp-scale"+sX;
  851. surd.firstChild.style.marginLeft = PHTML.Em(W*(sX/10-1)/scale*100);
  852. W = W*sX/10;
  853. root.firstChild.style.borderTopWidth = PHTML.Em(.08/Math.sqrt(sX/10));
  854. }
  855. root.appendChild(base);
  856. span.appendChild(surd);
  857. span.appendChild(root);
  858. this.PHTML.h = bbox.h + .18; this.PHTML.d = bbox.d;
  859. this.PHTML.w = bbox.w + W;
  860. return span;
  861. }
  862. });
  863. MML.mroot.Augment({
  864. toPreviewHTML: function (span) {
  865. span = this.PHTMLdefaultSpan(span,{
  866. childSpans:true, className:"MJXp-box", forceChild:true, noBBox:true
  867. });
  868. var rbox = this.PHTMLbboxFor(1), root = span.removeChild(span.lastChild);
  869. var sqrt = this.PHTMLlayoutRoot(HTML.Element("span"),span.firstChild);
  870. root.className = "MJXp-script"; // ### FIXME: should be scriptscript
  871. var scale = parseInt(sqrt.firstChild.firstChild.style.fontSize);
  872. var v = .55*(scale/120) + rbox.d*.8, r = -.6*(scale/120);
  873. if (scale > 150) {r *= .95*Math.ceil(150/scale*10)/10}
  874. root.style.marginRight = PHTML.Em(r); root.style.verticalAlign = PHTML.Em(v);
  875. if (-r > rbox.w*.8) root.style.marginLeft = PHTML.Em(-r-rbox.w*.8); // ### depends on rbox.w
  876. span.appendChild(root); span.appendChild(sqrt);
  877. this.PHTML.w += Math.max(0,rbox.w*.8+r);
  878. this.PHTML.h = Math.max(this.PHTML.h,rbox.h*.8+v);
  879. return span;
  880. },
  881. PHTMLlayoutRoot: MML.msqrt.prototype.PHTMLlayoutRoot
  882. });
  883. MML.mfenced.Augment({
  884. toPreviewHTML: function (span) {
  885. span = this.PHTMLcreateSpan(span);
  886. this.PHTMLhandleStyle(span);
  887. this.PHTMLhandleColor(span);
  888. //
  889. // Make row of open, data, sep, ... data, close
  890. //
  891. this.addFakeNodes();
  892. this.PHTMLaddChild(span,"open",{});
  893. for (var i = 0, m = this.data.length; i < m; i++) {
  894. this.PHTMLaddChild(span,"sep"+i,{});
  895. this.PHTMLaddChild(span,i,{});
  896. }
  897. this.PHTMLaddChild(span,"close",{});
  898. //
  899. // Check for streching the elements
  900. //
  901. var H = this.PHTML.h, D = this.PHTML.d;
  902. this.PHTMLstretchChild("open",H,D);
  903. for (i = 0, m = this.data.length; i < m; i++) {
  904. this.PHTMLstretchChild("sep"+i,H,D);
  905. this.PHTMLstretchChild(i,H,D);
  906. }
  907. this.PHTMLstretchChild("close",H,D);
  908. return span;
  909. }
  910. });
  911. MML.mrow.Augment({
  912. toPreviewHTML: function (span) {
  913. span = this.PHTMLdefaultSpan(span);
  914. var H = this.PHTML.h, D = this.PHTML.d;
  915. for (var i = 0, m = this.data.length; i < m; i++) this.PHTMLstretchChild(i,H,D);
  916. return span;
  917. }
  918. });
  919. MML.mstyle.Augment({
  920. toPreviewHTML: function (span) {
  921. span = this.PHTMLdefaultSpan(span);
  922. this.PHTMLhandleScriptlevel(span);
  923. return span;
  924. }
  925. });
  926. MML.TeXAtom.Augment({
  927. toPreviewHTML: function (span) {
  928. span = this.PHTMLdefaultSpan(span);
  929. // ### FIXME: handle TeX class?
  930. span.className = "MJXp-mrow";
  931. return span;
  932. }
  933. });
  934. MML.mtable.Augment({
  935. toPreviewHTML: function (span) {
  936. span = this.PHTMLdefaultSpan(span,{noBBox:true});
  937. var values = this.getValues("columnalign","rowalign","columnspacing","rowspacing",
  938. "columnwidth","equalcolumns","equalrows",
  939. "columnlines","rowlines","frame","framespacing",
  940. "align","width");
  941. var SPLIT = MathJax.Hub.SplitList, i, m, j, n;
  942. var CSPACE = SPLIT(values.columnspacing),
  943. RSPACE = SPLIT(values.rowspacing),
  944. CALIGN = SPLIT(values.columnalign),
  945. RALIGN = SPLIT(values.rowalign);
  946. for (i = 0, m = CSPACE.length; i < m; i++) {CSPACE[i] = PHTML.length2em(CSPACE[i])}
  947. for (i = 0, m = RSPACE.length; i < m; i++) {RSPACE[i] = PHTML.length2em(RSPACE[i])}
  948. var table = HTML.Element("span");
  949. while (span.firstChild) table.appendChild(span.firstChild);
  950. span.appendChild(table);
  951. var H = 0, W = 0;
  952. for (i = 0, m = this.data.length; i < m; i++) {
  953. var row = this.data[i];
  954. if (row) {
  955. var rspace = PHTML.arrayEntry(RSPACE,i-1), ralign = PHTML.arrayEntry(RALIGN,i);
  956. var rbox = row.PHTML, rspan = row.PHTMLspanElement();
  957. rspan.style.verticalAlign = ralign;
  958. var k = (row.type === "mlabeledtr" ? 1 : 0);
  959. for (j = 0, n = row.data.length; j < n-k; j++) {
  960. var cell = row.data[j+k];
  961. if (cell) {
  962. var cspace = PHTML.arrayEntry(CSPACE,j-1), calign = PHTML.arrayEntry(CALIGN,j);
  963. var cspan = cell.PHTMLspanElement();
  964. if (j) {rbox.w += cspace; cspan.style.paddingLeft = PHTML.Em(cspace)}
  965. if (i) cspan.style.paddingTop = PHTML.Em(rspace);
  966. cspan.style.textAlign = calign;
  967. }
  968. }
  969. H += rbox.h + rbox.d; if (i) {H += rspace}
  970. if (rbox.w > W) W = rbox.w;
  971. }
  972. }
  973. var bbox = this.PHTML;
  974. bbox.w = W; bbox.h = H/2 + .25; bbox.d = H/2 - .25;
  975. bbox.l = bbox.r = .125;
  976. return span;
  977. }
  978. });
  979. MML.mlabeledtr.Augment({
  980. PHTMLdefaultSpan: function (span,options) {
  981. if (!options) options = {};
  982. span = this.PHTMLcreateSpan(span);
  983. this.PHTMLhandleStyle(span);
  984. this.PHTMLhandleColor(span);
  985. if (this.isToken) this.PHTMLhandleToken(span);
  986. // skip label for now
  987. for (var i = 1, m = this.data.length; i < m; i++) this.PHTMLaddChild(span,i,options);
  988. return span;
  989. }
  990. });
  991. MML.semantics.Augment({
  992. toPreviewHTML: function (span) {
  993. span = this.PHTMLcreateSpan(span);
  994. if (this.data[0]) {
  995. this.data[0].toPreviewHTML(span);
  996. MathJax.Hub.Insert(this.data[0].PHTML||{},this.PHTML);
  997. }
  998. return span;
  999. }
  1000. });
  1001. MML.annotation.Augment({toPreviewHTML: function(span) {}});
  1002. MML["annotation-xml"].Augment({toPreviewHTML: function(span) {}});
  1003. //
  1004. // Loading isn't complete until the element jax is modified,
  1005. // but can't call loadComplete within the callback for "mml Jax Ready"
  1006. // (it would call PreviewHTML's Require routine, asking for the mml jax again)
  1007. // so wait until after the mml jax has finished processing.
  1008. //
  1009. // We also need to wait for the onload handler to run, since the loadComplete
  1010. // will call Config and Startup, which need to modify the body.
  1011. //
  1012. MathJax.Hub.Register.StartupHook("onLoad",function () {
  1013. setTimeout(MathJax.Callback(["loadComplete",PHTML,"jax.js"]),0);
  1014. });
  1015. });
  1016. MathJax.Hub.Register.StartupHook("End Cookie", function () {
  1017. if (HUB.config.menuSettings.zoom !== "None")
  1018. {AJAX.Require("[MathJax]/extensions/MathZoom.js")}
  1019. });
  1020. })(MathJax.Ajax,MathJax.Hub,MathJax.HTML,MathJax.OutputJax.PreviewHTML);