jax.js 44 KB

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