jax.js 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901
  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/HTML-CSS/jax.js
  6. *
  7. * Implements the HTML-CSS OutputJax that displays mathematics
  8. * using HTML and CSS to position the characters from math fonts
  9. * in their proper locations.
  10. *
  11. * ---------------------------------------------------------------------
  12. *
  13. * Copyright (c) 2009-2013 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,HTMLCSS) {
  28. var MML, isMobile = HUB.Browser.isMobile;
  29. var MESSAGE = function () {
  30. var data = [].slice.call(arguments,0);
  31. data[0][0] = ["HTML-CSS",data[0][0]];
  32. return MathJax.Message.Set.apply(MathJax.Message,data);
  33. };
  34. var FONTTEST = MathJax.Object.Subclass({
  35. timeout: (isMobile? 15:8)*1000, // timeout for loading web fonts
  36. FontInfo: {
  37. STIX: {family: "STIXSizeOneSym", testString: "() {} []"},
  38. TeX: {family: "MathJax_Size1", testString: "() {} []"}
  39. },
  40. comparisonFont: ["sans-serif","monospace","script","Times","Courier","Arial","Helvetica"],
  41. testSize: ["40px","50px","60px","30px","20px"],
  42. Init: function () {
  43. this.div = MathJax.HTML.addElement(document.body,"div",{
  44. id: "MathJax_Font_Test",
  45. style: {position:"absolute", visibility:"hidden", top:0, left:0, width: "auto",
  46. padding:0, border:0, margin:0, whiteSpace:"nowrap",
  47. textAlign:"left", textIndent:0, textTransform:"none",
  48. lineHeight:"normal", letterSpacing:"normal", wordSpacing:"normal",
  49. fontSize:this.testSize[0], fontWeight:"normal", fontStyle:"normal",
  50. fontSizeAdjust:"none"}
  51. },[""]);
  52. this.text = this.div.firstChild;
  53. },
  54. findFont: function (fonts,pref) {
  55. if (pref && this.testCollection(pref)) {return pref}
  56. for (var i = 0, m = fonts.length; i < m; i++) {
  57. if (fonts[i] === pref) continue;
  58. if (this.testCollection(fonts[i])) {return fonts[i]}
  59. }
  60. return null;
  61. },
  62. testCollection: function (name) {return this.testFont(this.FontInfo[name])},
  63. testFont: function (font) {
  64. if (font.isWebFont && HTMLCSS.FontFaceBug) {
  65. this.div.style.fontWeight = this.div.style.fontStyle = "normal";
  66. } else {
  67. this.div.style.fontWeight = (font.weight||"normal");
  68. this.div.style.fontStyle = (font.style||"normal");
  69. }
  70. var W = this.getComparisonWidths(font.testString,font.noStyleChar);
  71. if (W) {
  72. this.div.style.fontFamily = "'"+font.family+"',"+this.comparisonFont[0];
  73. if (this.div.offsetWidth == W[0]) {
  74. this.div.style.fontFamily = "'"+font.family+"',"+this.comparisonFont[W[2]];
  75. if (this.div.offsetWidth == W[1]) {return false}
  76. }
  77. if (this.div.offsetWidth != W[3] || this.div.offsetHeight != W[4]) {
  78. if (font.noStyleChar || !HTMLCSS.FONTDATA || !HTMLCSS.FONTDATA.hasStyleChar) {return true}
  79. for (var i = 0, m = this.testSize.length; i < m; i++)
  80. {if (this.testStyleChar(font,this.testSize[i])) {return true}}
  81. }
  82. }
  83. return false;
  84. },
  85. styleChar: "\uEFFD", // width encodes style
  86. versionChar: "\uEFFE", // width encodes version
  87. compChar: "\uEFFF", // "standard" width to compare to
  88. testStyleChar: function (font,size) {
  89. var n = 3 + (font.weight ? 2 : 0) + (font.style ? 4 : 0);
  90. var extra = "", dw = 0;
  91. var SIZE = this.div.style.fontSize; this.div.style.fontSize = size;
  92. if (HTMLCSS.msieItalicWidthBug && font.style === "italic") {
  93. this.text.nodeValue = extra = this.compChar;
  94. dw = this.div.offsetWidth;
  95. }
  96. if (HTMLCSS.safariTextNodeBug) {this.div.innerHTML = this.compChar+extra}
  97. else {this.text.nodeValue = this.compChar+extra}
  98. var W = this.div.offsetWidth-dw;
  99. if (HTMLCSS.safariTextNodeBug) {this.div.innerHTML = this.styleChar+extra}
  100. else {this.text.nodeValue = this.styleChar+extra}
  101. var N = Math.floor((this.div.offsetWidth-dw)/W+.5);
  102. if (N === n) {
  103. if (HTMLCSS.safariTextNodeBug) {this.div.innerHTML = this.versionChar+extra}
  104. else {this.text.nodeValue = this.versionChar+extra}
  105. font.version = Math.floor((this.div.offsetWidth-dw)/W+1.5)/2;
  106. }
  107. this.div.style.fontSize = SIZE;
  108. return (N === n);
  109. },
  110. getComparisonWidths: function (string,noStyleChar) {
  111. if (HTMLCSS.FONTDATA && HTMLCSS.FONTDATA.hasStyleChar && !noStyleChar)
  112. {string += this.styleChar + " " + this.compChar}
  113. if (HTMLCSS.safariTextNodeBug) {this.div.innerHTML = string}
  114. else {this.text.nodeValue = string}
  115. this.div.style.fontFamily = this.comparisonFont[0];
  116. var W = this.div.offsetWidth;
  117. this.div.style.fontFamily = HTMLCSS.webFontDefault;
  118. var sW = this.div.offsetWidth, sH = this.div.offsetHeight;
  119. for (var i = 1, m = this.comparisonFont.length; i < m; i++) {
  120. this.div.style.fontFamily = this.comparisonFont[i];
  121. if (this.div.offsetWidth != W) {return [W,this.div.offsetWidth,i,sW,sH]}
  122. }
  123. return null;
  124. },
  125. loadWebFont: function (font) {
  126. HUB.Startup.signal.Post("HTML-CSS Jax - Web-Font "+HTMLCSS.fontInUse+"/"+font.directory);
  127. var n = MESSAGE(["LoadWebFont","Loading web-font %1",HTMLCSS.fontInUse+"/"+font.directory]);
  128. var done = MathJax.Callback({}); // called when font is loaded
  129. var callback = MathJax.Callback(["loadComplete",this,font,n,done]);
  130. AJAX.timer.start(AJAX,[this.checkWebFont,font,callback],0,this.timeout);
  131. return done;
  132. },
  133. loadComplete: function (font,n,done,status) {
  134. MathJax.Message.Clear(n);
  135. if (status === AJAX.STATUS.OK) {this.webFontLoaded = true; done(); return}
  136. this.loadError(font);
  137. if (HUB.Browser.isFirefox && HTMLCSS.allowWebFonts) {
  138. var host = document.location.protocol + "//" + document.location.hostname;
  139. if (document.location.port != "") {host += ":" + document.location.port}
  140. host += "/";
  141. if (AJAX.fileURL(HTMLCSS.webfontDir).substr(0,host.length) !== host)
  142. {this.firefoxFontError(font)}
  143. }
  144. if (!this.webFontLoaded) {HTMLCSS.loadWebFontError(font,done)} else {done()}
  145. },
  146. loadError: function (font) {
  147. MESSAGE(["CantLoadWebFont","Can't load web font %1",HTMLCSS.fontInUse+"/"+font.directory],null,2000);
  148. HUB.Startup.signal.Post(["HTML-CSS Jax - web font error",HTMLCSS.fontInUse+"/"+font.directory,font]);
  149. },
  150. firefoxFontError: function (font) {
  151. MESSAGE(["FirefoxCantLoadWebFont","Firefox can't load web fonts from a remote host"],null,3000);
  152. HUB.Startup.signal.Post("HTML-CSS Jax - Firefox web fonts on remote host error");
  153. },
  154. checkWebFont: function (check,font,callback) {
  155. if (check.time(callback)) return;
  156. if (HTMLCSS.Font.testFont(font)) {callback(check.STATUS.OK)}
  157. else {setTimeout(check,check.delay)}
  158. },
  159. fontFace: function (name) {
  160. var type = HTMLCSS.allowWebFonts;
  161. var FONT = HTMLCSS.FONTDATA.FONTS[name];
  162. if (HTMLCSS.msieFontCSSBug && !FONT.family.match(/-Web$/)) {FONT.family += "-Web"}
  163. var dir = AJAX.fileURL(HTMLCSS.webfontDir+"/"+type);
  164. var fullname = name.replace(/-b/,"-B").replace(/-i/,"-I").replace(/-Bold-/,"-Bold");
  165. if (!fullname.match(/-/)) {fullname += "-Regular"}
  166. if (type === "svg") {fullname += ".svg#"+fullname} else {fullname += "."+type}
  167. var def = {
  168. "font-family": FONT.family,
  169. src: "url('"+dir+"/"+fullname+"')"
  170. };
  171. if (type === "otf") {
  172. def.src += " format('opentype')";
  173. dir = AJAX.fileURL(HTMLCSS.webfontDir+"/woff"); // add woff fonts as well
  174. def.src = "url('"+dir+"/"+fullname.replace(/otf$/,"woff")+"') format('woff'), "+def.src;
  175. } else if (type !== "eot") {def.src += " format('"+type+"')"}
  176. if (!(HTMLCSS.FontFaceBug && FONT.isWebFont)) {
  177. if (name.match(/-bold/)) {def["font-weight"] = "bold"}
  178. if (name.match(/-italic/)) {def["font-style"] = "italic"}
  179. }
  180. return def;
  181. }
  182. });
  183. var EVENT, TOUCH, HOVER; // filled in later
  184. HTMLCSS.Augment({
  185. config: {
  186. styles: {
  187. ".MathJax": {
  188. "display": "inline",
  189. "font-style": "normal",
  190. "font-weight": "normal",
  191. "line-height": "normal",
  192. "font-size": "100%",
  193. "font-size-adjust":"none",
  194. "text-indent": 0,
  195. "text-align": "left",
  196. "text-transform": "none",
  197. "letter-spacing": "normal",
  198. "word-spacing": "normal",
  199. "word-wrap": "normal",
  200. "white-space": "nowrap",
  201. "float": "none",
  202. "direction": "ltr",
  203. border: 0, padding: 0, margin: 0
  204. },
  205. ".MathJax_Display": {
  206. position: "relative",
  207. display: "block",
  208. width: "100%"
  209. },
  210. ".MathJax img, .MathJax nobr, .MathJax a": {
  211. border: 0, padding: 0, margin: 0, "max-width": "none", "max-height": "none",
  212. "vertical-align": 0, "line-height": "normal",
  213. "text-decoration": "none"
  214. },
  215. "img.MathJax_strut": {
  216. border:"0 !important", padding:"0 !important", margin: "0 !important",
  217. "vertical-align": "0 !important"
  218. },
  219. ".MathJax span": {
  220. display: "inline", position: "static",
  221. border: 0, padding: 0, margin: 0,
  222. "vertical-align": 0, "line-height": "normal",
  223. "text-decoration": "none"
  224. },
  225. ".MathJax nobr": {
  226. "white-space": "nowrap ! important"
  227. },
  228. ".MathJax img": {
  229. display: "inline ! important",
  230. "float": "none ! important"
  231. },
  232. ".MathJax *": {
  233. transition: "none",
  234. "-webkit-transition": "none",
  235. "-moz-transition": "none",
  236. "-ms-transition": "none",
  237. "-o-transition": "none"
  238. },
  239. ".MathJax_Processing": {
  240. visibility: "hidden", position:"fixed",
  241. width: 0, height: 0, overflow:"hidden"
  242. },
  243. ".MathJax_Processed": {display:"none!important"},
  244. ".MathJax_ExBox": {
  245. display:"block", overflow:"hidden",
  246. width:"1px", height:"60ex"
  247. },
  248. ".MathJax .MathJax_EmBox": {
  249. display:"block", overflow:"hidden",
  250. width:"1px", height:"60em"
  251. },
  252. ".MathJax .MathJax_HitBox": {
  253. cursor: "text",
  254. background: "white",
  255. opacity:0, filter:"alpha(opacity=0)"
  256. },
  257. ".MathJax .MathJax_HitBox *": {
  258. filter: "none", opacity:1, background:"transparent" // for IE
  259. },
  260. "#MathJax_Tooltip": {
  261. position: "absolute", left: 0, top: 0,
  262. width: "auto", height: "auto",
  263. display: "none"
  264. },
  265. "#MathJax_Tooltip *": {
  266. filter: "none", opacity:1, background:"transparent" // for IE
  267. },
  268. //
  269. // Used for testing web fonts against the default font used while
  270. // web fonts are loading
  271. //
  272. "@font-face": {
  273. "font-family": "MathJax_Blank",
  274. "src": "url('about:blank')"
  275. }
  276. }
  277. },
  278. settings: HUB.config.menuSettings,
  279. hideProcessedMath: true, // use display:none until all math is processed
  280. Font: null, // created by Config() below
  281. webFontDefault: "MathJax_Blank",
  282. allowWebFonts: "otf", // assume browser can use OTF web fonts
  283. maxStretchyParts: 1000, // limit the number of parts allowed for
  284. // stretchy operators. See issue 366.
  285. Config: function () {
  286. if (!this.require) {this.require = []}
  287. this.Font = FONTTEST();
  288. this.SUPER(arguments).Config.call(this); var settings = this.settings;
  289. if (this.adjustAvailableFonts) {this.adjustAvailableFonts(this.config.availableFonts)}
  290. if (settings.scale) {this.config.scale = settings.scale}
  291. if (settings.font && settings.font !== "Auto") {
  292. if (settings.font === "TeX (local)") {
  293. this.config.availableFonts = ["TeX"];
  294. this.config.preferredFont = this.config.webFont = "TeX";
  295. } else if (settings.font === "STIX (local)") {
  296. this.config.availableFonts = ["STIX"];
  297. this.config.preferredFont = "STIX";
  298. this.config.webFont = "TeX";
  299. } else if (settings.font === "TeX (web)") {
  300. this.config.availableFonts = [];
  301. this.config.preferredFont = "";
  302. this.config.webFont = "TeX";
  303. } else if (settings.font === "TeX (image)") {
  304. this.config.availableFonts = [];
  305. this.config.preferredFont = this.config.webFont = "";
  306. }
  307. }
  308. var font = this.Font.findFont(this.config.availableFonts,this.config.preferredFont);
  309. if (!font && this.allowWebFonts) {font = this.config.webFont; if (font) {this.webFonts = true}}
  310. if (!font && this.config.imageFont) {font = this.config.imageFont; this.imgFonts = true}
  311. if (font) {
  312. this.fontInUse = font; this.fontDir += "/" + font; this.webfontDir += "/" + font;
  313. this.require.push(this.fontDir+"/fontdata.js");
  314. if (this.imgFonts) {
  315. this.require.push(this.directory+"/imageFonts.js");
  316. HUB.Startup.signal.Post("HTML-CSS Jax - using image fonts");
  317. }
  318. } else {
  319. MESSAGE(["CantFindFontUsing","Can't find a valid font using %1",
  320. "["+this.config.availableFonts.join(", ")+"]"],null,3000);
  321. this.fontInUse = "generic";
  322. this.FONTDATA = {
  323. TeX_factor: 1, baselineskip: 1.2, lineH: .8, lineD: .2, ffLineH: .8,
  324. FONTS: {},
  325. VARIANT: {
  326. "normal": {fonts:[]}, "-generic-variant": {fonts:[]},
  327. "-largeOp": {fonts:[]}, "-smallOp": {fonts:[]}
  328. }, RANGES: [], DELIMITERS: {}, RULECHAR: 0x2D, REMAP: {}
  329. };
  330. HUB.Startup.signal.Post("HTML-CSS Jax - no valid font");
  331. }
  332. this.require.push(MathJax.OutputJax.extensionDir+"/MathEvents.js");
  333. },
  334. Startup: function () {
  335. // Set up event handling
  336. EVENT = MathJax.Extension.MathEvents.Event;
  337. TOUCH = MathJax.Extension.MathEvents.Touch;
  338. HOVER = MathJax.Extension.MathEvents.Hover;
  339. this.ContextMenu = EVENT.ContextMenu;
  340. this.Mousedown = EVENT.AltContextMenu;
  341. this.Mouseover = HOVER.Mouseover;
  342. this.Mouseout = HOVER.Mouseout;
  343. this.Mousemove = HOVER.Mousemove;
  344. // Make hidden div for when math is in a display:none block
  345. this.hiddenDiv = this.Element("div",{
  346. style:{visibility:"hidden", overflow:"hidden", position:"absolute", top:0,
  347. height:"1px", width: "auto", padding:0, border:0, margin:0,
  348. textAlign:"left", textIndent:0, textTransform:"none",
  349. lineHeight:"normal", letterSpacing:"normal", wordSpacing:"normal"}
  350. });
  351. if (!document.body.firstChild) {document.body.appendChild(this.hiddenDiv)}
  352. else {document.body.insertBefore(this.hiddenDiv,document.body.firstChild)}
  353. this.hiddenDiv = this.addElement(this.hiddenDiv,"div",{id:"MathJax_Hidden"});
  354. // Determine pixels per inch
  355. var div = this.addElement(this.hiddenDiv,"div",{style:{width:"5in"}});
  356. this.pxPerInch = div.offsetWidth/5; this.hiddenDiv.removeChild(div);
  357. // Markers used by getW
  358. this.startMarker = this.createStrut(this.Element("span"),10,true);
  359. this.endMarker = this.addText(this.Element("span"),"x").parentNode;
  360. // Used in getHD
  361. this.HDspan = this.Element("span");
  362. if (this.operaHeightBug) {this.createStrut(this.HDspan,0)}
  363. if (this.msieInlineBlockAlignBug) {
  364. this.HDimg = this.addElement(this.HDspan,"img",{style:{height:"0px", width:"1px"}});
  365. try {this.HDimg.src = "about:blank"} catch(err) {}
  366. } else {
  367. this.HDimg = this.createStrut(this.HDspan,0);
  368. }
  369. // Used in preTranslate to get scaling factors
  370. this.EmExSpan = this.Element("span",
  371. {style:{position:"absolute","font-size-adjust":"none"}},
  372. [
  373. ["span",{className:"MathJax_ExBox"}],
  374. ["span",{className:"MathJax"},
  375. [["span",{className:"MathJax_EmBox"}]]
  376. ]
  377. ]
  378. );
  379. // Used in preTranslate to get linebreak width
  380. this.linebreakSpan = this.Element("span",null,
  381. [["hr",{style: {width:"100%", size:1, padding:0, border:0, margin:0}}]]);
  382. // Set up styles and preload web fonts
  383. return AJAX.Styles(this.config.styles,["InitializeHTML",this]);
  384. },
  385. removeSTIXfonts: function (fonts) {
  386. //
  387. // Opera doesn't display large chunks of the STIX fonts, and
  388. // Safari/Windows doesn't display Plane1,
  389. // so disable STIX for these browsers.
  390. //
  391. for (var i = 0, m = fonts.length; i < m; i++)
  392. {if (fonts[i] === "STIX") {fonts.splice(i,1); m--; i--;}}
  393. if (this.config.preferredFont === "STIX") {this.config.preferredFont = fonts[0]}
  394. },
  395. PreloadWebFonts: function () {
  396. if (!HTMLCSS.allowWebFonts || !HTMLCSS.config.preloadWebFonts) return;
  397. for (var i = 0, m = HTMLCSS.config.preloadWebFonts.length; i < m; i++) {
  398. var FONT = HTMLCSS.FONTDATA.FONTS[HTMLCSS.config.preloadWebFonts[i]];
  399. if (!FONT.available) {HTMLCSS.Font.testFont(FONT)}
  400. }
  401. },
  402. //
  403. // Handle initialization that requires styles to be set up
  404. //
  405. InitializeHTML: function () {
  406. this.PreloadWebFonts();
  407. //
  408. // Get the default sizes (need styles in place to do this)
  409. //
  410. document.body.appendChild(this.EmExSpan);
  411. document.body.appendChild(this.linebreakSpan);
  412. this.defaultEx = this.EmExSpan.firstChild.offsetHeight/60;
  413. this.defaultEm = this.EmExSpan.lastChild.firstChild.offsetHeight/60;
  414. this.defaultWidth = this.linebreakSpan.firstChild.offsetWidth;
  415. document.body.removeChild(this.linebreakSpan);
  416. document.body.removeChild(this.EmExSpan);
  417. },
  418. preTranslate: function (state) {
  419. var scripts = state.jax[this.id], i, m = scripts.length,
  420. script, prev, span, div, test, jax, ex, em, scale, maxwidth, relwidth = false,
  421. linebreak = this.config.linebreaks.automatic, width = this.config.linebreaks.width;
  422. if (linebreak) {
  423. relwidth = (width.match(/^\s*(\d+(\.\d*)?%\s*)?container\s*$/) != null);
  424. if (relwidth) {width = width.replace(/\s*container\s*/,"")}
  425. else {maxwidth = this.defaultWidth}
  426. if (width === "") {width = "100%"}
  427. } else {maxwidth = 100000} // a big width, so no implicit line breaks
  428. //
  429. // Loop through the scripts
  430. //
  431. for (i = 0; i < m; i++) {
  432. script = scripts[i]; if (!script.parentNode) continue;
  433. //
  434. // Remove any existing output
  435. //
  436. prev = script.previousSibling;
  437. if (prev && String(prev.className).match(/^MathJax(_Display)?( MathJax_Processing)?$/))
  438. {prev.parentNode.removeChild(prev)}
  439. //
  440. // Add the span, and a div if in display mode,
  441. // then set the role and mark it as being processed
  442. //
  443. jax = script.MathJax.elementJax; if (!jax) continue;
  444. jax.HTMLCSS = {display: (jax.root.Get("display") === "block")}
  445. span = div = this.Element("span",{
  446. className:"MathJax", id:jax.inputID+"-Frame", isMathJax:true, jaxID:this.id,
  447. oncontextmenu:EVENT.Menu, onmousedown: EVENT.Mousedown,
  448. onmouseover:EVENT.Mouseover, onmouseout:EVENT.Mouseout, onmousemove:EVENT.Mousemove,
  449. onclick:EVENT.Click, ondblclick:EVENT.DblClick
  450. });
  451. if (HUB.Browser.noContextMenu) {
  452. span.ontouchstart = TOUCH.start;
  453. span.ontouchend = TOUCH.end;
  454. }
  455. if (jax.HTMLCSS.display) {
  456. div = this.Element("div",{className:"MathJax_Display"});
  457. div.appendChild(span);
  458. } else if (this.msieDisappearingBug) {span.style.display = "inline-block"}
  459. //
  460. // Mark math for screen readers
  461. // (screen readers don't know about role="math" yet, so use "textbox" instead)
  462. //
  463. div.setAttribute("role","textbox"); div.setAttribute("aria-readonly","true");
  464. div.className += " MathJax_Processing";
  465. script.parentNode.insertBefore(div,script);
  466. //
  467. // Add the test span for determining scales and linebreak widths
  468. //
  469. script.parentNode.insertBefore(this.EmExSpan.cloneNode(true),script);
  470. if (relwidth) {div.parentNode.insertBefore(this.linebreakSpan.cloneNode(true),div)}
  471. }
  472. //
  473. // Determine the scaling factors for each script
  474. // (this only requires one reflow rather than a reflow for each equation)
  475. //
  476. for (i = 0; i < m; i++) {
  477. script = scripts[i]; if (!script.parentNode) continue;
  478. test = script.previousSibling; div = test.previousSibling;
  479. jax = script.MathJax.elementJax; if (!jax) continue;
  480. ex = test.firstChild.offsetHeight/60;
  481. em = test.lastChild.firstChild.offsetHeight/60;
  482. if (relwidth) {maxwidth = div.previousSibling.firstChild.offsetWidth}
  483. if (ex === 0 || ex === "NaN") {
  484. // can't read width, so move to hidden div for processing
  485. // (this will cause a reflow for each math element that is hidden)
  486. this.hiddenDiv.appendChild(div);
  487. jax.HTMLCSS.isHidden = true;
  488. ex = this.defaultEx; em = this.defaultEm;
  489. if (relwidth) {maxwidth = this.defaultWidth}
  490. }
  491. scale = Math.floor(Math.max(this.config.minScaleAdjust/100,(ex/this.TeX.x_height)/em) * this.config.scale);
  492. jax.HTMLCSS.scale = scale/100; jax.HTMLCSS.fontSize = scale+"%";
  493. jax.HTMLCSS.em = jax.HTMLCSS.outerEm = em; this.em = em * scale/100; jax.HTMLCSS.ex = ex;
  494. jax.HTMLCSS.lineWidth = (linebreak ? this.length2em(width,1,maxwidth/this.em) : 1000000);
  495. }
  496. //
  497. // Remove the test spans used for determining scales and linebreak widths
  498. //
  499. for (i = 0; i < m; i++) {
  500. script = scripts[i]; if (!script.parentNode) continue;
  501. test = scripts[i].previousSibling;
  502. jax = scripts[i].MathJax.elementJax; if (!jax) continue;
  503. if (relwidth) {
  504. span = test.previousSibling;
  505. if (!jax.HTMLCSS.isHidden) {span = span.previousSibling}
  506. span.parentNode.removeChild(span);
  507. }
  508. test.parentNode.removeChild(test);
  509. }
  510. //
  511. // Set state variables used for displaying equations in chunks
  512. //
  513. state.HTMLCSSeqn = state.HTMLCSSlast = 0; state.HTMLCSSi = -1;
  514. state.HTMLCSSchunk = this.config.EqnChunk;
  515. state.HTMLCSSdelay = false;
  516. },
  517. Translate: function (script,state) {
  518. if (!script.parentNode) return;
  519. //
  520. // If we are supposed to do a chunk delay, do it
  521. //
  522. if (state.HTMLCSSdelay) {
  523. state.HTMLCSSdelay = false;
  524. HUB.RestartAfter(MathJax.Callback.Delay(this.config.EqnChunkDelay));
  525. }
  526. //
  527. // Get the data about the math
  528. //
  529. var jax = script.MathJax.elementJax, math = jax.root,
  530. span = document.getElementById(jax.inputID+"-Frame"),
  531. div = (jax.HTMLCSS.display ? span.parentNode : span);
  532. //
  533. // Set the font metrics
  534. //
  535. this.em = MML.mbase.prototype.em = jax.HTMLCSS.em * jax.HTMLCSS.scale;
  536. this.outerEm = jax.HTMLCSS.em; this.scale = jax.HTMLCSS.scale;
  537. this.linebreakWidth = jax.HTMLCSS.lineWidth;
  538. span.style.fontSize = jax.HTMLCSS.fontSize;
  539. //
  540. // Typeset the math
  541. //
  542. this.initImg(span);
  543. this.initHTML(math,span);
  544. math.setTeXclass();
  545. try {math.toHTML(span,div)} catch (err) {
  546. if (err.restart) {while (span.firstChild) {span.removeChild(span.firstChild)}}
  547. throw err;
  548. }
  549. //
  550. // Put it in place, and remove the processing marker
  551. //
  552. if (jax.HTMLCSS.isHidden) {script.parentNode.insertBefore(div,script)}
  553. div.className = div.className.split(/ /)[0];
  554. //
  555. // Check if we are hiding the math until more is processed
  556. //
  557. if (this.hideProcessedMath) {
  558. //
  559. // Hide the math and don't let its preview be removed
  560. //
  561. div.className += " MathJax_Processed";
  562. if (script.MathJax.preview) {
  563. jax.HTMLCSS.preview = script.MathJax.preview;
  564. delete script.MathJax.preview;
  565. }
  566. //
  567. // Check if we should show this chunk of equations
  568. //
  569. state.HTMLCSSeqn += (state.i - state.HTMLCSSi); state.HTMLCSSi = state.i;
  570. if (state.HTMLCSSeqn >= state.HTMLCSSlast + state.HTMLCSSchunk) {
  571. this.postTranslate(state);
  572. state.HTMLCSSchunk = Math.floor(state.HTMLCSSchunk*this.config.EqnChunkFactor);
  573. state.HTMLCSSdelay = true; // delay if there are more scripts
  574. }
  575. }
  576. },
  577. postTranslate: function (state) {
  578. var scripts = state.jax[this.id];
  579. if (!this.hideProcessedMath) return;
  580. //
  581. // Reveal this chunk of math
  582. //
  583. for (var i = state.HTMLCSSlast, m = state.HTMLCSSeqn; i < m; i++) {
  584. var script = scripts[i];
  585. if (script && script.MathJax.elementJax) {
  586. //
  587. // Remove the processed marker
  588. //
  589. script.previousSibling.className = script.previousSibling.className.split(/ /)[0];
  590. var data = script.MathJax.elementJax.HTMLCSS;
  591. //
  592. // Remove the preview, if any
  593. //
  594. if (data.preview) {
  595. data.preview.innerHTML = "";
  596. script.MathJax.preview = data.preview;
  597. delete data.preview;
  598. }
  599. }
  600. }
  601. if (this.forceReflow) {
  602. // WebKit can misplace some elements that should wrap to the next line
  603. // but gets them right ona reflow, so force reflow by toggling a stylesheet
  604. var sheet = (document.styleSheets||[])[0]||{};
  605. sheet.disabled = true; sheet.disabled = false;
  606. }
  607. //
  608. // Save our place so we know what is revealed
  609. //
  610. state.HTMLCSSlast = state.HTMLCSSeqn;
  611. },
  612. getJaxFromMath: function (math) {
  613. if (math.parentNode.className === "MathJax_Display") {math = math.parentNode}
  614. do {math = math.nextSibling} while (math && math.nodeName.toLowerCase() !== "script");
  615. return HUB.getJaxFor(math);
  616. },
  617. getHoverSpan: function (jax,math) {return jax.root.HTMLspanElement()},
  618. getHoverBBox: function (jax,span,math) {
  619. var bbox = span.bbox, em = jax.HTMLCSS.outerEm;
  620. var BBOX = {w:bbox.w*em, h:bbox.h*em, d:bbox.d*em};
  621. if (bbox.width) {BBOX.width = bbox.width}
  622. return BBOX;
  623. },
  624. Zoom: function (jax,span,math,Mw,Mh) {
  625. //
  626. // Re-render at larger size
  627. //
  628. span.className = "MathJax";
  629. span.style.fontSize = jax.HTMLCSS.fontSize;
  630. //
  631. // get em sizes (taken from HTMLCSS.preTranslate)
  632. //
  633. var emex = span.appendChild(this.EmExSpan.cloneNode(true));
  634. var em = emex.lastChild.firstChild.offsetHeight/60;
  635. this.em = MML.mbase.prototype.em = em;
  636. this.outerEm = em / jax.HTMLCSS.scale;
  637. emex.parentNode.removeChild(emex);
  638. this.idPostfix = "-zoom"; jax.root.toHTML(span,span); this.idPostfix = "";
  639. var width = jax.root.HTMLspanElement().bbox.width;
  640. if (width) {
  641. // Handle full-width displayed equations
  642. // FIXME: this is a hack for now
  643. span.style.width = Math.floor(Mw-1.5*HTMLCSS.em)+"px"; span.style.display="inline-block";
  644. var id = (jax.root.id||"MathJax-Span-"+jax.root.spanID)+"-zoom";
  645. var child = document.getElementById(id).firstChild;
  646. while (child && child.style.width !== width) {child = child.nextSibling}
  647. if (child) {child.style.width = "100%"}
  648. }
  649. //
  650. // Get height and width of zoomed math and original math
  651. //
  652. span.style.position = "absolute";
  653. if (!width) {math.style.position = "absolute"}
  654. var zW = span.offsetWidth, zH = span.offsetHeight,
  655. mH = math.offsetHeight, mW = math.offsetWidth;
  656. if (mW === 0) {mW = math.parentNode.offsetWidth}; // IE7 gets mW == 0?
  657. span.style.position = math.style.position = "";
  658. //
  659. return {Y:-EVENT.getBBox(span).h, mW:mW, mH:mH, zW:zW, zH:zH};
  660. },
  661. initImg: function (span) {},
  662. initHTML: function (math,span) {},
  663. initFont: function (name) {
  664. var FONTS = HTMLCSS.FONTDATA.FONTS, AVAIL = HTMLCSS.config.availableFonts;
  665. if (AVAIL && AVAIL.length && HTMLCSS.Font.testFont(FONTS[name]))
  666. {FONTS[name].available = true; return null}
  667. if (!this.allowWebFonts) {return null}
  668. FONTS[name].isWebFont = true;
  669. if (HTMLCSS.FontFaceBug) {
  670. FONTS[name].family = name;
  671. if (HTMLCSS.msieFontCSSBug) {FONTS[name].family += "-Web"}
  672. }
  673. return AJAX.Styles({"@font-face":this.Font.fontFace(name)});
  674. },
  675. Remove: function (jax) {
  676. var span = document.getElementById(jax.inputID+"-Frame");
  677. if (span) {
  678. if (jax.HTMLCSS.display) {span = span.parentNode}
  679. span.parentNode.removeChild(span);
  680. }
  681. delete jax.HTMLCSS;
  682. },
  683. getHD: function (span) {
  684. var position = span.style.position;
  685. span.style.position = "absolute";
  686. this.HDimg.style.height = "0px";
  687. span.appendChild(this.HDspan);
  688. var HD = {h:span.offsetHeight};
  689. this.HDimg.style.height = HD.h+"px";
  690. HD.d = span.offsetHeight - HD.h; HD.h -= HD.d;
  691. HD.h /= this.em; HD.d /= this.em;
  692. span.removeChild(this.HDspan);
  693. span.style.position = position;
  694. return HD;
  695. },
  696. getW: function (span) {
  697. var W, H, w = (span.bbox||{}).w, start = span;
  698. if (span.bbox && span.bbox.exactW) {return w}
  699. if ((span.bbox && w >= 0 && !this.initialSkipBug) || this.negativeBBoxes || !span.firstChild) {
  700. W = span.offsetWidth; H = span.parentNode.offsetHeight;
  701. } else if (span.bbox && w < 0 && this.msieNegativeBBoxBug) {
  702. W = -span.offsetWidth, H = span.parentNode.offsetHeight;
  703. } else {
  704. // IE can't deal with a space at the beginning, so put something else first
  705. if (this.initialSkipBug) {
  706. var position = span.style.position; span.style.position = "absolute";
  707. start = this.startMarker; span.insertBefore(start,span.firstChild)
  708. }
  709. span.appendChild(this.endMarker);
  710. W = this.endMarker.offsetLeft - start.offsetLeft;
  711. span.removeChild(this.endMarker);
  712. if (this.initialSkipBug) {span.removeChild(start); span.style.position = position}
  713. }
  714. if (H != null) {span.parentNode.HH = H/this.em}
  715. return W/this.em;
  716. },
  717. Measured: function (span,parent) {
  718. var bbox = span.bbox;
  719. if (bbox.width == null && bbox.w && !bbox.isMultiline) {
  720. var w = this.getW(span);
  721. bbox.rw += w - bbox.w;
  722. bbox.w = w; bbox.exactW = true;
  723. }
  724. if (!parent) {parent = span.parentNode}
  725. if (!parent.bbox) {parent.bbox = bbox}
  726. return span;
  727. },
  728. Remeasured: function (span,parent) {
  729. parent.bbox = this.Measured(span,parent).bbox;
  730. },
  731. MeasureSpans: function (SPANS) {
  732. var spans = [], span, i, m, bbox, start, end, W, parent;
  733. //
  734. // Insert the needed markers
  735. //
  736. for (i = 0, m = SPANS.length; i < m; i++) {
  737. span = SPANS[i]; if (!span) continue;
  738. bbox = span.bbox; parent = this.parentNode(span);
  739. if (bbox.exactW || bbox.width || bbox.w === 0 || bbox.isMultiline) {
  740. if (!parent.bbox) {parent.bbox = bbox}
  741. continue;
  742. }
  743. if (this.negativeBBoxes || !span.firstChild || (bbox.w >= 0 && !this.initialSkipBug) ||
  744. (bbox.w < 0 && this.msieNegativeBBoxBug)) {
  745. spans.push([span]);
  746. } else if (this.initialSkipBug) {
  747. start = this.startMarker.cloneNode(true); end = this.endMarker.cloneNode(true);
  748. span.insertBefore(start,span.firstChild); span.appendChild(end);
  749. spans.push([span,start,end,span.style.position]); span.style.position = "absolute";
  750. } else {
  751. end = this.endMarker.cloneNode(true);
  752. span.appendChild(end); spans.push([span,null,end]);
  753. }
  754. }
  755. //
  756. // Read the widths and heights
  757. //
  758. for (i = 0, m = spans.length; i < m; i++) {
  759. span = spans[i][0]; bbox = span.bbox; parent = this.parentNode(span);
  760. if ((bbox.w >= 0 && !this.initialSkipBug) || this.negativeBBoxes || !span.firstChild) {
  761. W = span.offsetWidth; parent.HH = parent.offsetHeight/this.em;
  762. } else if (bbox.w < 0 && this.msieNegativeBBoxBug) {
  763. W = -span.offsetWidth, parent.HH = parent.offsetHeight/this.em;
  764. } else {
  765. W = spans[i][2].offsetLeft - ((spans[i][1]||{}).offsetLeft||0);
  766. }
  767. W /= this.em;
  768. bbox.rw += W - bbox.w;
  769. bbox.w = W; bbox.exactW = true;
  770. if (!parent.bbox) {parent.bbox = bbox}
  771. }
  772. //
  773. // Remove markers
  774. //
  775. for (i = 0, m = spans.length; i < m; i++) {
  776. span = spans[i];
  777. if (span[1]) {span[1].parentNode.removeChild(span[1]), span[0].style.position = span[3]}
  778. if (span[2]) {span[2].parentNode.removeChild(span[2])}
  779. }
  780. },
  781. Em: function (m) {
  782. if (Math.abs(m) < .0006) {return "0em"}
  783. return m.toFixed(3).replace(/\.?0+$/,"") + "em";
  784. },
  785. EmRounded: function (m) {
  786. m = (Math.round(m*HTMLCSS.em)+.05)/HTMLCSS.em;
  787. if (Math.abs(m) < .0006) {return "0em"}
  788. return m.toFixed(3).replace(/\.?0+$/,"") + "em";
  789. },
  790. unEm: function (m) {
  791. return parseFloat(m);
  792. },
  793. Px: function (m) {
  794. m *= this.em; var s = (m < 0? "-" : "");
  795. return s+Math.abs(m).toFixed(1).replace(/\.?0+$/,"") + "px";
  796. },
  797. unPx: function (m) {
  798. return parseFloat(m)/this.em;
  799. },
  800. Percent: function (m) {
  801. return (100*m).toFixed(1).replace(/\.?0+$/,"") + "%";
  802. },
  803. length2em: function (length,mu,size) {
  804. if (typeof(length) !== "string") {length = length.toString()}
  805. if (length === "") {return ""}
  806. if (length === MML.SIZE.NORMAL) {return 1}
  807. if (length === MML.SIZE.BIG) {return 2}
  808. if (length === MML.SIZE.SMALL) {return .71}
  809. if (length === "infinity") {return HTMLCSS.BIGDIMEN}
  810. var factor = this.FONTDATA.TeX_factor;
  811. if (length.match(/mathspace$/)) {return HTMLCSS.MATHSPACE[length]*factor}
  812. var match = length.match(/^\s*([-+]?(?:\.\d+|\d+(?:\.\d*)?))?(pt|em|ex|mu|px|pc|in|mm|cm|%)?/);
  813. var m = parseFloat(match[1]||"1"), unit = match[2];
  814. if (size == null) {size = 1}; if (mu == null) {mu = 1}
  815. if (unit === "em") {return m * factor}
  816. if (unit === "ex") {return m * HTMLCSS.TeX.x_height * factor}
  817. if (unit === "%") {return m / 100 * size}
  818. if (unit === "px") {return m / HTMLCSS.em}
  819. if (unit === "pt") {return m / 10 * factor} // 10 pt to an em
  820. if (unit === "pc") {return m * 1.2 * factor} // 12 pt to a pc
  821. if (unit === "in") {return m * this.pxPerInch / HTMLCSS.em}
  822. if (unit === "cm") {return m * this.pxPerInch / HTMLCSS.em / 2.54} // 2.54 cm to an inch
  823. if (unit === "mm") {return m * this.pxPerInch / HTMLCSS.em / 25.4} // 10 mm to a cm
  824. if (unit === "mu") {return m / 18 * factor * mu} // 18mu to an em for the scriptlevel
  825. return m*factor*size; // relative to given size (or 1em as default)
  826. },
  827. thickness2em: function (length,mu) {
  828. var thick = HTMLCSS.TeX.rule_thickness;
  829. if (length === MML.LINETHICKNESS.MEDIUM) {return thick}
  830. if (length === MML.LINETHICKNESS.THIN) {return .67*thick}
  831. if (length === MML.LINETHICKNESS.THICK) {return 1.67*thick}
  832. return this.length2em(length,mu,thick);
  833. },
  834. getPadding: function (span) {
  835. var padding = {top:0, right:0, bottom:0, left:0}, has = false;
  836. for (var id in padding) {if (padding.hasOwnProperty(id)) {
  837. var pad = span.style["padding"+id.charAt(0).toUpperCase()+id.substr(1)];
  838. if (pad) {padding[id] = this.length2em(pad); has = true;}
  839. }}
  840. return (has ? padding : false);
  841. },
  842. getBorders: function (span) {
  843. var border = {top:0, right:0, bottom:0, left:0}, css = {}, has = false;
  844. for (var id in border) {if (border.hasOwnProperty(id)) {
  845. var ID = "border"+id.charAt(0).toUpperCase()+id.substr(1);
  846. var style = span.style[ID+"Style"];
  847. if (style) {
  848. has = true;
  849. border[id] = this.length2em(span.style[ID+"Width"]);
  850. css[ID] = [span.style[ID+"Width"],span.style[ID+"Style"],span.style[ID+"Color"]].join(" ");
  851. }
  852. }}
  853. border.css = css;
  854. return (has ? border : false);
  855. },
  856. setBorders: function (span,borders) {
  857. if (borders) {
  858. for (var id in borders.css) {if (borders.css.hasOwnProperty(id)) {
  859. span.style[id] = borders.css[id];
  860. }}
  861. }
  862. },
  863. createStrut: function (span,h,before) {
  864. var strut = this.Element("span",{
  865. isMathJax: true,
  866. style:{display:"inline-block", overflow:"hidden", height:h+"px",
  867. width:"1px", marginRight:"-1px"}
  868. });
  869. if (before) {span.insertBefore(strut,span.firstChild)} else {span.appendChild(strut)}
  870. return strut;
  871. },
  872. createBlank: function (span,w,before) {
  873. var blank = this.Element("span",{
  874. isMathJax: true,
  875. style: {display:"inline-block", overflow:"hidden", height:"1px", width:this.Em(w)}
  876. });
  877. if (before) {span.insertBefore(blank,span.firstChild)} else {span.appendChild(blank)}
  878. return blank;
  879. },
  880. createShift: function (span,w,before) {
  881. var space = this.Element("span",{style:{marginLeft:this.Em(w)}, isMathJax:true});
  882. if (before) {span.insertBefore(space,span.firstChild)} else {span.appendChild(space)}
  883. return space;
  884. },
  885. createSpace: function (span,h,d,w,color,isSpace) {
  886. if (h < -d) {d = -h} // make sure h is above d
  887. var H = this.Em(h+d), D = this.Em(-d);
  888. if (this.msieInlineBlockAlignBug) {D = this.Em(HTMLCSS.getHD(span.parentNode).d-d)}
  889. if (span.isBox || isSpace) {
  890. var scale = (span.scale == null ? 1 : span.scale);
  891. span.bbox = {exactW: true, h: h*scale, d: d*scale, w: w*scale, rw: w*scale, lw: 0};
  892. span.style.height = H; span.style.verticalAlign = D;
  893. span.HH = (h+d)*scale;
  894. } else {
  895. span = this.addElement(span,"span",{style: {height:H, verticalAlign:D}, isMathJax:true});
  896. }
  897. if (w >= 0) {
  898. span.style.width = this.Em(w);
  899. span.style.display = "inline-block";
  900. span.style.overflow = "hidden"; // for IE in quirks mode
  901. } else {
  902. if (this.msieNegativeSpaceBug) {span.style.height = ""}
  903. span.style.marginLeft = this.Em(w);
  904. if (HTMLCSS.safariNegativeSpaceBug && span.parentNode.firstChild == span)
  905. {this.createBlank(span,0,true)}
  906. }
  907. if (color && color !== MML.COLOR.TRANSPARENT) {
  908. span.style.backgroundColor = color;
  909. span.style.position = "relative"; // make sure it covers earlier items
  910. }
  911. return span;
  912. },
  913. createRule: function (span,h,d,w,color) {
  914. if (h < -d) {d = -h} // make sure h is above d
  915. var min = HTMLCSS.TeX.min_rule_thickness, f = 1;
  916. // If rule is very thin, make it at least min_rule_thickness so it doesn't disappear
  917. if (w > 0 && w*this.em < min) {w = min/this.em}
  918. if (h+d > 0 && (h+d)*this.em < min) {f = 1/(h+d)*(min/this.em); h *= f; d *= f}
  919. if (!color) {color = "solid"} else {color = "solid "+color}
  920. color = this.Em(w)+" "+color;
  921. var H = (f === 1 ? this.Em(h+d) : min+"px"), D = this.Em(-d);
  922. var rule = this.addElement(span,"span",{
  923. style: {borderLeft: color, display: "inline-block", overflow:"hidden",
  924. width:0, height:H, verticalAlign:D},
  925. bbox: {h:h, d:d, w:w, rw:w, lw:0, exactW:true}, noAdjust:true, HH:h+d, isMathJax:true
  926. });
  927. if (w > 0 && rule.offsetWidth == 0) {rule.style.width = this.Em(w)}
  928. if (span.isBox || span.className == "mspace") {span.bbox = rule.bbox, span.HH = h+d}
  929. return rule;
  930. },
  931. createFrame: function (span,h,d,w,t,style) {
  932. if (h < -d) {d = -h} // make sure h is above d
  933. var T = 2*t;
  934. if (this.msieFrameSizeBug) {if (w < T) {w = T}; if (h+d < T) {h = T-d}}
  935. if (this.msieBorderWidthBug) {T = 0}
  936. var H = this.Em(h+d-T), D = this.Em(-d-t), W = this.Em(w-T);
  937. var B = this.Em(t)+" "+style;
  938. var frame = this.addElement(span,"span",{
  939. style: {border: B, display:"inline-block", overflow:"hidden", width:W, height:H},
  940. bbox: {h:h, d:d, w:w, rw:w, lw:0, exactW:true}, noAdjust: true, HH:h+d, isMathJax:true
  941. });
  942. if (D) {frame.style.verticalAlign = D}
  943. return frame;
  944. },
  945. //
  946. // Find parent span (skipping over <a> tags)
  947. //
  948. parentNode: function (span) {
  949. var parent = span.parentNode;
  950. if (parent.nodeName.toLowerCase() === "a") {parent = parent.parentNode}
  951. return parent;
  952. },
  953. createStack: function (span,nobbox,w) {
  954. if (this.msiePaddingWidthBug) {this.createStrut(span,0)}
  955. var relativeW = String(w).match(/%$/);
  956. var W = (!relativeW && w != null ? w : 0);
  957. span = this.addElement(span,"span",{
  958. noAdjust: true, HH: 0, isMathJax: true,
  959. style: {display:"inline-block", position:"relative",
  960. width:(relativeW ? "100%" : this.Em(W)), height:0}
  961. });
  962. if (!nobbox) {
  963. span.parentNode.bbox = span.bbox = {
  964. exactW: true,
  965. h: -this.BIGDIMEN, d: -this.BIGDIMEN,
  966. w:W, lw: this.BIGDIMEN, rw: (!relativeW && w != null ? w : -this.BIGDIMEN)
  967. };
  968. if (relativeW) {span.bbox.width = w}
  969. }
  970. return span;
  971. },
  972. createBox: function (span,w) {
  973. var box = this.addElement(span,"span",{style:{position:"absolute"}, isBox: true, isMathJax:true});
  974. if (w != null) {box.style.width = w}
  975. return box;
  976. },
  977. addBox: function (span,box) {
  978. box.style.position = "absolute"; box.isBox = box.isMathJax = true;
  979. return span.appendChild(box);
  980. },
  981. placeBox: function (span,x,y,noclip) {
  982. span.isMathJax = true;
  983. var parent = HTMLCSS.parentNode(span), bbox = span.bbox, BBOX = parent.bbox;
  984. if (this.msiePlaceBoxBug) {this.addText(span,this.NBSP)}
  985. if (this.imgSpaceBug) {this.addText(span,this.imgSpace)}
  986. // Place the box
  987. var HH, dx = 0;
  988. if (span.HH != null) {HH = span.HH}
  989. else if (bbox) {HH = Math.max(3,bbox.h+bbox.d)}
  990. else {HH = span.offsetHeight/this.em}
  991. if (!span.noAdjust) {
  992. HH += 1;
  993. HH = Math.round(HH*this.em)/this.em; // make this an integer number of pixels (for Chrome)
  994. if (this.msieInlineBlockAlignBug) {
  995. this.addElement(span,"img",{
  996. className:"MathJax_strut", border:0, src:"about:blank", isMathJax:true,
  997. style:{width:0,height:this.Em(HH)}
  998. });
  999. } else {
  1000. this.addElement(span,"span",{
  1001. isMathJax: true, style:{display:"inline-block",width:0,height:this.Em(HH)}
  1002. });
  1003. if (HTMLCSS.chromeHeightBug)
  1004. {HH -= (span.lastChild.offsetHeight - Math.round(HH*this.em))/this.em}
  1005. }
  1006. }
  1007. // Clip so that bbox doesn't include extra height and depth
  1008. if (bbox) {
  1009. if (this.initialSkipBug) {
  1010. if (bbox.lw < 0) {dx = bbox.lw; HTMLCSS.createBlank(span,-dx,true)}
  1011. if (bbox.rw > bbox.w) {HTMLCSS.createBlank(span,bbox.rw-bbox.w+.1)}
  1012. }
  1013. if (!this.msieClipRectBug && !bbox.noclip && !noclip) {
  1014. var dd = 3/this.em;
  1015. var H = (bbox.H == null ? bbox.h : bbox.H), D = (bbox.D == null ? bbox.d : bbox.D);
  1016. var t = HH - H - dd, b = HH + D + dd, l = bbox.lw - 3*dd, r = 1000;
  1017. if (this.initialSkipBug && bbox.lw < 0) {l = -3*dd}
  1018. if (bbox.isFixed) {r = bbox.width-l}
  1019. span.style.clip = "rect("+this.Em(t)+" "+this.Em(r)+" "+this.Em(b)+" "+this.Em(l)+")";
  1020. }
  1021. }
  1022. // Place the box
  1023. span.style.top = this.Em(-y-HH);
  1024. span.style.left = this.Em(x+dx);
  1025. // Update the bounding box
  1026. if (bbox && BBOX) {
  1027. if (bbox.H != null && (BBOX.H == null || bbox.H + y > BBOX.H)) {BBOX.H = bbox.H + y}
  1028. if (bbox.D != null && (BBOX.D == null || bbox.D - y > BBOX.D)) {BBOX.D = bbox.D - y}
  1029. if (bbox.h + y > BBOX.h) {BBOX.h = bbox.h + y}
  1030. if (bbox.d - y > BBOX.d) {BBOX.d = bbox.d - y}
  1031. if (BBOX.H != null && BBOX.H <= BBOX.h) {delete BBOX.H}
  1032. if (BBOX.D != null && BBOX.D <= BBOX.d) {delete BBOX.D}
  1033. if (bbox.w + x > BBOX.w) {
  1034. BBOX.w = bbox.w + x;
  1035. if (BBOX.width == null) {parent.style.width = this.Em(BBOX.w)}
  1036. }
  1037. if (bbox.rw + x > BBOX.rw) {BBOX.rw = bbox.rw + x}
  1038. if (bbox.lw + x < BBOX.lw) {BBOX.lw = bbox.lw + x}
  1039. if (bbox.width != null && !bbox.isFixed) {
  1040. if (BBOX.width == null) {
  1041. parent.style.width = BBOX.width = "100%";
  1042. if (bbox.minWidth) {parent.style.minWidth = BBOX.minWidth = bbox.minWidth}
  1043. }
  1044. span.style.width = bbox.width;
  1045. }
  1046. }
  1047. },
  1048. alignBox: function (span,align,y) {
  1049. this.placeBox(span,0,y); // set y position (and left aligned)
  1050. var bbox = span.bbox; if (bbox.isMultiline) return;
  1051. var isRelative = bbox.width != null && !bbox.isFixed;
  1052. var r = 0, c = -bbox.w/2, l = "50%";
  1053. if (this.initialSkipBug) {r = bbox.w-bbox.rw-.1; c += bbox.lw}
  1054. if (this.msieMarginScaleBug) {c = (c*this.em) + "px"} else {c = this.Em(c)}
  1055. if (isRelative) {c = ""; l = (50 - parseFloat(bbox.width)/2) + "%"}
  1056. HUB.Insert(span.style,({
  1057. right: {left:"", right: this.Em(r)},
  1058. center: {left:l, marginLeft: c}
  1059. })[align]);
  1060. },
  1061. setStackWidth: function (span,w) {
  1062. if (typeof(w) === "number") {
  1063. span.style.width = this.Em(Math.max(0,w));
  1064. var bbox = span.bbox; if (bbox) {bbox.w = w; bbox.exactW = true};
  1065. bbox = span.parentNode.bbox; if (bbox) {bbox.w = w; bbox.exactW = true};
  1066. } else {
  1067. span.style.width = span.parentNode.style.width = "100%";
  1068. if (span.bbox) {span.bbox.width = w}
  1069. if (span.parentNode.bbox) {span.parentNode.bbox.width = w}
  1070. }
  1071. },
  1072. createDelimiter: function (span,code,HW,scale,font) {
  1073. if (!code) {
  1074. span.bbox = {h:0, d:0, w:this.TeX.nulldelimiterspace, lw: 0};
  1075. span.bbox.rw = span.bbox.w;
  1076. this.createSpace(span,span.bbox.h,span.bbox.d,span.bbox.w);
  1077. return;
  1078. }
  1079. if (!scale) {scale = 1};
  1080. if (!(HW instanceof Array)) {HW = [HW,HW]}
  1081. var hw = HW[1]; HW = HW[0];
  1082. var delim = {alias: code};
  1083. while (delim.alias) {
  1084. code = delim.alias; delim = this.FONTDATA.DELIMITERS[code];
  1085. if (!delim) {delim = {HW: [0,this.FONTDATA.VARIANT[MML.VARIANT.NORMAL]]}}
  1086. }
  1087. if (delim.load) {HUB.RestartAfter(AJAX.Require(this.fontDir+"/fontdata-"+delim.load+".js"))}
  1088. for (var i = 0, m = delim.HW.length; i < m; i++) {
  1089. if (delim.HW[i][0]*scale >= HW-.01 || (i == m-1 && !delim.stretch)) {
  1090. if (delim.HW[i][2]) {scale *= delim.HW[i][2]}
  1091. if (delim.HW[i][3]) {code = delim.HW[i][3]}
  1092. var chr = this.addElement(span,"span");
  1093. this.createChar(chr,[code,delim.HW[i][1]],scale,font);
  1094. span.bbox = chr.bbox;
  1095. span.offset = .65 * span.bbox.w;
  1096. span.scale = scale;
  1097. return;
  1098. }
  1099. }
  1100. if (delim.stretch) {this["extendDelimiter"+delim.dir](span,hw,delim.stretch,scale,font)}
  1101. },
  1102. extendDelimiterV: function (span,H,delim,scale,font) {
  1103. var stack = this.createStack(span,true);
  1104. var top = this.createBox(stack), bot = this.createBox(stack);
  1105. this.createChar(top,(delim.top||delim.ext),scale,font);
  1106. this.createChar(bot,(delim.bot||delim.ext),scale,font);
  1107. var ext = {bbox:{w:0,lw:0,rw:0}}, mid = ext, EXT;
  1108. var h = top.bbox.h + top.bbox.d + bot.bbox.h + bot.bbox.d;
  1109. var y = -top.bbox.h; this.placeBox(top,0,y,true); y -= top.bbox.d;
  1110. if (delim.mid) {
  1111. mid = this.createBox(stack); this.createChar(mid,delim.mid,scale,font);
  1112. h += mid.bbox.h + mid.bbox.d;
  1113. }
  1114. if (delim.min && H < h*delim.min) {H = h*delim.min}
  1115. if (H > h) {
  1116. ext = this.Element("span"); this.createChar(ext,delim.ext,scale,font);
  1117. var eH = ext.bbox.h + ext.bbox.d, eh = eH - .05, n, N, k = (delim.mid ? 2 : 1);
  1118. N = n = Math.min(Math.ceil((H-h)/(k*eh)), this.maxStretchyParts);
  1119. if (!delim.fullExtenders) {eh = (H-h)/(k*n)}
  1120. var dy = (n/(n+1))*(eH - eh); eh = eH - dy; y += dy + eh - ext.bbox.h;
  1121. while (k-- > 0) {
  1122. while (n-- > 0) {
  1123. if (!this.msieCloneNodeBug) {EXT = ext.cloneNode(true)}
  1124. else {EXT = this.Element("span"); this.createChar(EXT,delim.ext,scale,font)}
  1125. EXT.bbox = ext.bbox;
  1126. y -= eh; this.placeBox(this.addBox(stack,EXT),0,y,true);
  1127. }
  1128. y += dy - ext.bbox.d;
  1129. if (delim.mid && k) {
  1130. this.placeBox(mid,0,y-mid.bbox.h,true); n = N;
  1131. y += -(mid.bbox.h + mid.bbox.d) + dy + eh - ext.bbox.h;
  1132. }
  1133. }
  1134. } else {
  1135. y += (h - H)/2;
  1136. if (delim.mid) {this.placeBox(mid,0,y-mid.bbox.h,true); y += -(mid.bbox.h + mid.bbox.d)}
  1137. y += (h - H)/2;
  1138. }
  1139. this.placeBox(bot,0,y-bot.bbox.h,true); y -= bot.bbox.h + bot.bbox.d;
  1140. span.bbox = {
  1141. w: Math.max(top.bbox.w,ext.bbox.w,bot.bbox.w,mid.bbox.w),
  1142. lw: Math.min(top.bbox.lw,ext.bbox.lw,bot.bbox.lw,mid.bbox.lw),
  1143. rw: Math.max(top.bbox.rw,ext.bbox.rw,bot.bbox.rw,mid.bbox.rw),
  1144. h: 0, d: -y, exactW: true
  1145. }
  1146. span.scale = scale;
  1147. span.offset = .55 * span.bbox.w;
  1148. span.isMultiChar = true;
  1149. this.setStackWidth(stack,span.bbox.w);
  1150. },
  1151. extendDelimiterH: function (span,W,delim,scale,font) {
  1152. var stack = this.createStack(span,true);
  1153. var left = this.createBox(stack), right = this.createBox(stack);
  1154. this.createChar(left,(delim.left||delim.rep),scale,font);
  1155. this.createChar(right,(delim.right||delim.rep),scale,font);
  1156. var rep = this.Element("span"); this.createChar(rep,delim.rep,scale,font);
  1157. var mid = {bbox: {h:-this.BIGDIMEN, d:-this.BIGDIMEN}}, REP;
  1158. this.placeBox(left,-left.bbox.lw,0,true);
  1159. var w = (left.bbox.rw - left.bbox.lw) + (right.bbox.rw - right.bbox.lw) - .05,
  1160. x = left.bbox.rw - left.bbox.lw - .025, dx;
  1161. if (delim.mid) {
  1162. mid = this.createBox(stack); this.createChar(mid,delim.mid,scale,font);
  1163. w += mid.bbox.w;
  1164. }
  1165. if (delim.min && W < w*delim.min) {W = w*delim.min}
  1166. if (W > w) {
  1167. var rW = rep.bbox.rw-rep.bbox.lw, rw = rW - .05, n, N, k = (delim.mid ? 2 : 1);
  1168. N = n = Math.min(Math.ceil((W-w)/(k*rw)), this.maxStretchyParts);
  1169. if (!delim.fillExtenders) {rw = (W-w)/(k*n)}
  1170. dx = (n/(n+1))*(rW - rw); rw = rW - dx; x -= rep.bbox.lw + dx;
  1171. while (k-- > 0) {
  1172. while (n-- > 0) {
  1173. if (!this.cloneNodeBug) {REP = rep.cloneNode(true)}
  1174. else {REP = this.Element("span"); this.createChar(REP,delim.rep,scale,font)}
  1175. REP.bbox = rep.bbox;
  1176. this.placeBox(this.addBox(stack,REP),x,0,true); x += rw;
  1177. }
  1178. if (delim.mid && k) {this.placeBox(mid,x,0,true); x += mid.bbox.w - dx; n = N}
  1179. }
  1180. } else {
  1181. x -= (w - W)/2;
  1182. if (delim.mid) {this.placeBox(mid,x,0,true); x += mid.bbox.w};
  1183. x -= (w - W)/2;
  1184. }
  1185. this.placeBox(right,x,0,true);
  1186. span.bbox = {
  1187. w: x+right.bbox.rw, lw: 0, rw: x+right.bbox.rw,
  1188. H: Math.max(left.bbox.h,rep.bbox.h,right.bbox.h,mid.bbox.h),
  1189. D: Math.max(left.bbox.d,rep.bbox.d,right.bbox.d,mid.bbox.d),
  1190. h: rep.bbox.h, d: rep.bbox.d, exactW: true
  1191. }
  1192. span.scale = scale;
  1193. span.isMultiChar = true;
  1194. this.setStackWidth(stack,span.bbox.w);
  1195. },
  1196. createChar: function (span,data,scale,font) {
  1197. span.isMathJax = true;
  1198. var SPAN = span, text = "", variant = {fonts: [data[1]], noRemap:true};
  1199. if (font && font === MML.VARIANT.BOLD) {variant.fonts = [data[1]+"-bold",data[1]]}
  1200. if (typeof(data[1]) !== "string") {variant = data[1]}
  1201. if (data[0] instanceof Array) {
  1202. for (var i = 0, m = data[0].length; i < m; i++) {text += String.fromCharCode(data[0][i])}
  1203. } else {text = String.fromCharCode(data[0])}
  1204. if (data[4]) {scale *= data[4]}
  1205. if (scale !== 1 || data[3]) {
  1206. SPAN = this.addElement(span,"span",{style:{fontSize: this.Percent(scale)}, scale:scale, isMathJax:true});
  1207. this.handleVariant(SPAN,variant,text);
  1208. span.bbox = SPAN.bbox;
  1209. } else {this.handleVariant(span,variant,text)}
  1210. if (data[2]) {span.style.marginLeft = this.Em(data[2])} // x offset
  1211. if (data[3]) { // y offset
  1212. span.firstChild.style.verticalAlign = this.Em(data[3]);
  1213. span.bbox.h += data[3]; if (span.bbox.h < 0) {span.bbox.h = 0}
  1214. }
  1215. if (data[5]) {span.bbox.h += data[5]} // extra height
  1216. if (data[6]) {span.bbox.d += data[6]} // extra depth
  1217. // Handle combining characters by adding a non-breaking space so it shows up
  1218. if (this.AccentBug && span.bbox.w === 0) {SPAN.firstChild.nodeValue += this.NBSP}
  1219. },
  1220. positionDelimiter: function (span,h) {
  1221. h -= span.bbox.h; span.bbox.d -= h; span.bbox.h += h;
  1222. if (h) {
  1223. if (this.safariVerticalAlignBug || this.konquerorVerticalAlignBug ||
  1224. (this.operaVerticalAlignBug && span.isMultiChar)) {
  1225. if (span.firstChild.style.display === "" && span.style.top !== "")
  1226. {span = span.firstChild; h -= HTMLCSS.unEm(span.style.top)}
  1227. span.style.position = "relative";
  1228. span.style.top = this.Em(-h);
  1229. } else {
  1230. span.style.verticalAlign = this.Em(h);
  1231. if (HTMLCSS.ffVerticalAlignBug) {HTMLCSS.createRule(span.parentNode,span.bbox.h,0,0)}
  1232. }
  1233. }
  1234. },
  1235. handleVariant: function (span,variant,text) {
  1236. var newtext = "", n, c, font, VARIANT, SPAN = span, force = !!span.style.fontFamily;
  1237. if (text.length === 0) return;
  1238. if (!span.bbox) {
  1239. span.bbox = {
  1240. w: 0, h: -this.BIGDIMEN, d: -this.BIGDIMEN,
  1241. rw: -this.BIGDIMEN, lw: this.BIGDIMEN
  1242. };
  1243. }
  1244. if (!variant) {variant = this.FONTDATA.VARIANT[MML.VARIANT.NORMAL]}
  1245. VARIANT = variant;
  1246. for (var i = 0, m = text.length; i < m; i++) {
  1247. variant = VARIANT;
  1248. n = text.charCodeAt(i); c = text.charAt(i);
  1249. if (n >= 0xD800 && n < 0xDBFF) {
  1250. i++; n = (((n-0xD800)<<10)+(text.charCodeAt(i)-0xDC00))+0x10000;
  1251. if (this.FONTDATA.RemapPlane1) {
  1252. var nv = this.FONTDATA.RemapPlane1(n,variant);
  1253. n = nv.n; variant = nv.variant;
  1254. }
  1255. } else {
  1256. var id, M, RANGES = this.FONTDATA.RANGES;
  1257. for (id = 0, M = RANGES.length; id < M; id++) {
  1258. if (RANGES[id].name === "alpha" && variant.noLowerCase) continue;
  1259. var N = variant["offset"+RANGES[id].offset];
  1260. if (N && n >= RANGES[id].low && n <= RANGES[id].high) {
  1261. if (RANGES[id].remap && RANGES[id].remap[n]) {
  1262. n = N + RANGES[id].remap[n];
  1263. } else {
  1264. n = n - RANGES[id].low + N;
  1265. if (RANGES[id].add) {n += RANGES[id].add}
  1266. }
  1267. if (variant["variant"+RANGES[id].offset])
  1268. {variant = this.FONTDATA.VARIANT[variant["variant"+RANGES[id].offset]]}
  1269. break;
  1270. }
  1271. }
  1272. }
  1273. if (variant.remap && variant.remap[n]) {
  1274. if (variant.remap[n] instanceof Array) {
  1275. var remap = variant.remap[n];
  1276. n = remap[0]; variant = this.FONTDATA.VARIANT[remap[1]];
  1277. } else if (typeof(variant.remap[n]) === "string") {
  1278. text = variant.remap[n]+text.substr(i+1);
  1279. i = 0; m = text.length; n = text.charCodeAt(0);
  1280. } else {
  1281. n = variant.remap[n];
  1282. if (variant.remap.variant) {variant = this.FONTDATA.VARIANT[variant.remap.variant]}
  1283. }
  1284. }
  1285. if (this.FONTDATA.REMAP[n] && !variant.noRemap) {
  1286. n = this.FONTDATA.REMAP[n];
  1287. if (n instanceof Array) {variant = this.FONTDATA.VARIANT[n[1]]; n = n[0]}
  1288. if (typeof(n) === "string") {
  1289. text = n+text.substr(i+1);
  1290. i = 0; m = text.length; n = n.charCodeAt(0);
  1291. }
  1292. }
  1293. font = this.lookupChar(variant,n); c = font[n];
  1294. if (force || (!this.checkFont(font,SPAN.style) && !c[5].img)) {
  1295. if (newtext.length) {this.addText(SPAN,newtext); newtext = ""};
  1296. var addSpan = !!SPAN.style.fontFamily || !!span.style.fontStyle ||
  1297. !!span.style.fontWeight || !font.directory || force; force = false;
  1298. if (SPAN !== span) {addSpan = !this.checkFont(font,span.style); SPAN = span}
  1299. if (addSpan) {SPAN = this.addElement(span,"span",{isMathJax:true, subSpan:true})}
  1300. this.handleFont(SPAN,font,SPAN !== span);
  1301. }
  1302. newtext = this.handleChar(SPAN,font,c,n,newtext);
  1303. if (!(c[5]||{}).space) {
  1304. if (c[0]/1000 > span.bbox.h) {span.bbox.h = c[0]/1000}
  1305. if (c[1]/1000 > span.bbox.d) {span.bbox.d = c[1]/1000}
  1306. }
  1307. if (span.bbox.w + c[3]/1000 < span.bbox.lw) {span.bbox.lw = span.bbox.w + c[3]/1000}
  1308. if (span.bbox.w + c[4]/1000 > span.bbox.rw) {span.bbox.rw = span.bbox.w + c[4]/1000}
  1309. span.bbox.w += c[2]/1000;
  1310. }
  1311. if (newtext.length) {this.addText(SPAN,newtext)}
  1312. if (span.scale && span.scale !== 1) {
  1313. span.bbox.h *= span.scale; span.bbox.d *= span.scale;
  1314. span.bbox.w *= span.scale; span.bbox.lw *= span.scale; span.bbox.rw *= span.scale;
  1315. }
  1316. if (text.length == 1 && font.skew && font.skew[n]) {span.bbox.skew = font.skew[n]}
  1317. },
  1318. checkFont: function (font,style) {
  1319. var weight = (style.fontWeight||"normal");
  1320. if (weight.match(/^\d+$/)) {weight = (parseInt(weight) >= 600 ? "bold" : "normal")}
  1321. return (font.family.replace(/'/g,"") === style.fontFamily.replace(/'/g,"") &&
  1322. (font.style||"normal") === (style.fontStyle||"normal") &&
  1323. (font.weight||"normal") === weight);
  1324. },
  1325. handleFont: function (span,font,force) {
  1326. span.style.fontFamily = font.family;
  1327. if (!font.directory) {span.style.fontSize = Math.floor(100/HTMLCSS.scale+.5) + "%"}
  1328. if (!(HTMLCSS.FontFaceBug && font.isWebFont)) {
  1329. var style = font.style || "normal", weight = font.weight || "normal";
  1330. if (style !== "normal" || force) {span.style.fontStyle = style}
  1331. if (weight !== "normal" || force) {span.style.fontWeight = weight}
  1332. }
  1333. },
  1334. handleChar: function (span,font,c,n,text) {
  1335. var C = c[5];
  1336. if (C.space) {
  1337. if (text.length) {this.addText(span,text)}
  1338. HTMLCSS.createShift(span,c[2]/1000);
  1339. return "";
  1340. }
  1341. if (C.img) {return this.handleImg(span,font,c,n,text)}
  1342. if (C.isUnknown && this.FONTDATA.DELIMITERS[n]) {
  1343. if (text.length) {this.addText(span,text)}
  1344. var scale = span.scale;
  1345. HTMLCSS.createDelimiter(span,n,0,1,font);
  1346. if (this.FONTDATA.DELIMITERS[n].dir === "V") {
  1347. span.style.verticalAlign = this.Em(span.bbox.d);
  1348. span.bbox.h += span.bbox.d; span.bbox.d = 0;
  1349. }
  1350. span.scale = scale;
  1351. c[0] = span.bbox.h*1000; c[1] = span.bbox.d*1000;
  1352. c[2] = span.bbox.w*1000; c[3] = span.bbox.lw*1000; c[4] = span.bbox.rw*1000;
  1353. return "";
  1354. }
  1355. if (C.c == null) {
  1356. if (n <= 0xFFFF) {C.c = String.fromCharCode(n)} else {
  1357. var N = n - 0x10000;
  1358. C.c = String.fromCharCode((N>>10)+0xD800)
  1359. + String.fromCharCode((N&0x3FF)+0xDC00);
  1360. }
  1361. }
  1362. if (C.rfix) {this.addText(span,text+C.c); HTMLCSS.createShift(span,C.rfix/1000); return ""}
  1363. if (c[2] || !this.msieAccentBug || text.length) {return text + C.c}
  1364. // Handle IE accent clipping bug
  1365. HTMLCSS.createShift(span,c[3]/1000);
  1366. HTMLCSS.createShift(span,(c[4]-c[3])/1000);
  1367. this.addText(span,C.c);
  1368. HTMLCSS.createShift(span,-c[4]/1000);
  1369. return "";
  1370. },
  1371. handleImg: function (span,font,c,n,text) {return text}, // replaced by imageFont extension
  1372. lookupChar: function (variant,n) {
  1373. var i, m;
  1374. if (!variant.FONTS) {
  1375. var FONTS = this.FONTDATA.FONTS;
  1376. var fonts = (variant.fonts || this.FONTDATA.VARIANT.normal.fonts);
  1377. if (!(fonts instanceof Array)) {fonts = [fonts]}
  1378. if (variant.fonts != fonts) {variant.fonts = fonts}
  1379. variant.FONTS = [];
  1380. for (i = 0, m = fonts.length; i < m; i++) {
  1381. if (FONTS[fonts[i]]) {
  1382. variant.FONTS.push(FONTS[fonts[i]]);
  1383. FONTS[fonts[i]].name = fonts[i]; // FIXME: should really be in the font files
  1384. }
  1385. }
  1386. }
  1387. for (i = 0, m = variant.FONTS.length; i < m; i++) {
  1388. var font = variant.FONTS[i];
  1389. if (typeof(font) === "string") {
  1390. delete variant.FONTS; this.loadFont(font);
  1391. }
  1392. if (font[n]) {
  1393. if (font[n].length === 5) {font[n][5] = {}}
  1394. if (HTMLCSS.allowWebFonts && !font.available)
  1395. {this.loadWebFont(font)} else {return font}
  1396. } else {this.findBlock(font,n)}
  1397. }
  1398. return this.unknownChar(variant,n);
  1399. },
  1400. unknownChar: function (variant,n) {
  1401. var unknown = (variant.defaultFont || {family:HTMLCSS.config.undefinedFamily});
  1402. if (variant.bold) {unknown.weight = "bold"}; if (variant.italic) {unknown.style = "italic"}
  1403. if (!unknown[n]) {unknown[n] = [800,200,500,0,500,{isUnknown:true}]} // [h,d,w,lw,rw,{data}]
  1404. HUB.signal.Post(["HTML-CSS Jax - unknown char",n,variant]);
  1405. return unknown;
  1406. },
  1407. findBlock: function (font,c) {
  1408. if (font.Ranges) {
  1409. // FIXME: do binary search?
  1410. for (var i = 0, m = font.Ranges.length; i < m; i++) {
  1411. if (c < font.Ranges[i][0]) return;
  1412. if (c <= font.Ranges[i][1]) {
  1413. var file = font.Ranges[i][2];
  1414. for (var j = font.Ranges.length-1; j >= 0; j--)
  1415. {if (font.Ranges[j][2] == file) {font.Ranges.splice(j,1)}}
  1416. this.loadFont(font.directory+"/"+file+".js");
  1417. }
  1418. }
  1419. }
  1420. },
  1421. loadFont: function (file) {
  1422. var queue = MathJax.Callback.Queue();
  1423. queue.Push(["Require",AJAX,this.fontDir+"/"+file]);
  1424. if (this.imgFonts) {
  1425. if (!MathJax.isPacked) {file = file.replace(/\/([^\/]*)$/,HTMLCSS.imgPacked+"/$1")}
  1426. queue.Push(["Require",AJAX,this.webfontDir+"/png/"+file]);
  1427. }
  1428. HUB.RestartAfter(queue.Push({}));
  1429. },
  1430. loadWebFont: function (font) {
  1431. font.available = font.isWebFont = true;
  1432. if (HTMLCSS.FontFaceBug) {
  1433. font.family = font.name;
  1434. if (HTMLCSS.msieFontCSSBug) {font.family += "-Web"}
  1435. }
  1436. HUB.RestartAfter(this.Font.loadWebFont(font));
  1437. },
  1438. loadWebFontError: function (font,done) {
  1439. //
  1440. // After the first web font fails to load, switch to image fonts, if possible
  1441. // otherwise, give up on web fonts all together
  1442. //
  1443. HUB.Startup.signal.Post("HTML-CSS Jax - disable web fonts");
  1444. font.isWebFont = false;
  1445. if (this.config.imageFont && this.config.imageFont === this.fontInUse) {
  1446. this.imgFonts = true;
  1447. HUB.Startup.signal.Post("HTML-CSS Jax - switch to image fonts");
  1448. HUB.Startup.signal.Post("HTML-CSS Jax - using image fonts");
  1449. MESSAGE(["WebFontNotAvailable","Web-Fonts not available -- using image fonts instead"],null,3000);
  1450. AJAX.Require(this.directory+"/imageFonts.js",done);
  1451. } else {
  1452. this.allowWebFonts = false;
  1453. done();
  1454. }
  1455. },
  1456. Element: MathJax.HTML.Element,
  1457. addElement: MathJax.HTML.addElement,
  1458. TextNode: MathJax.HTML.TextNode,
  1459. addText: MathJax.HTML.addText,
  1460. ucMatch: MathJax.HTML.ucMatch,
  1461. BIGDIMEN: 10000000,
  1462. ID: 0, idPostfix: "",
  1463. GetID: function () {this.ID++; return this.ID},
  1464. MATHSPACE: {
  1465. veryverythinmathspace: 1/18,
  1466. verythinmathspace: 2/18,
  1467. thinmathspace: 3/18,
  1468. mediummathspace: 4/18,
  1469. thickmathspace: 5/18,
  1470. verythickmathspace: 6/18,
  1471. veryverythickmathspace: 7/18,
  1472. negativeveryverythinmathspace: -1/18,
  1473. negativeverythinmathspace: -2/18,
  1474. negativethinmathspace: -3/18,
  1475. negativemediummathspace: -4/18,
  1476. negativethickmathspace: -5/18,
  1477. negativeverythickmathspace: -6/18,
  1478. negativeveryverythickmathspace: -7/18
  1479. },
  1480. TeX: {
  1481. x_height: .430554,
  1482. quad: 1,
  1483. num1: .676508,
  1484. num2: .393732,
  1485. num3: .44373,
  1486. denom1: .685951,
  1487. denom2: .344841,
  1488. sup1: .412892,
  1489. sup2: .362892,
  1490. sup3: .288888,
  1491. sub1: .15,
  1492. sub2: .247217,
  1493. sup_drop: .386108,
  1494. sub_drop: .05,
  1495. delim1: 2.39,
  1496. delim2: 1.0,
  1497. axis_height: .25,
  1498. rule_thickness: .06,
  1499. big_op_spacing1: .111111,
  1500. big_op_spacing2: .166666,
  1501. big_op_spacing3: .2,
  1502. big_op_spacing4: .6,
  1503. big_op_spacing5: .1,
  1504. scriptspace: .1,
  1505. nulldelimiterspace: .12,
  1506. delimiterfactor: 901,
  1507. delimitershortfall: .1, // originally .3,
  1508. min_rule_thickness: 1.25 // in pixels
  1509. },
  1510. NBSP: "\u00A0",
  1511. rfuzz: 0 // adjustment to rule placements in roots
  1512. });
  1513. MathJax.Hub.Register.StartupHook("mml Jax Ready",function () {
  1514. MML = MathJax.ElementJax.mml;
  1515. MML.mbase.Augment({
  1516. toHTML: function (span) {
  1517. span = this.HTMLcreateSpan(span); if (this.type != "mrow") {span = this.HTMLhandleSize(span)}
  1518. for (var i = 0, m = this.data.length; i < m; i++)
  1519. {if (this.data[i]) {this.data[i].toHTML(span)}}
  1520. var stretchy = this.HTMLcomputeBBox(span);
  1521. var h = span.bbox.h, d = span.bbox.d;
  1522. for (i = 0, m = stretchy.length; i < m; i++) {stretchy[i].HTMLstretchV(span,h,d)}
  1523. if (stretchy.length) {this.HTMLcomputeBBox(span,true)}
  1524. if (this.HTMLlineBreaks(span)) {span = this.HTMLmultiline(span)}
  1525. this.HTMLhandleSpace(span);
  1526. this.HTMLhandleColor(span);
  1527. return span;
  1528. },
  1529. HTMLlineBreaks: function () {return false},
  1530. HTMLmultiline: function () {MML.mbase.HTMLautoloadFile("multiline")},
  1531. HTMLcomputeBBox: function (span,full,i,m) {
  1532. if (i == null) {i = 0}; if (m == null) {m = this.data.length}
  1533. var BBOX = span.bbox = {exactW: true}, stretchy = [];
  1534. while (i < m) {
  1535. var core = this.data[i]; if (!core) continue;
  1536. if (!full && core.HTMLcanStretch("Vertical"))
  1537. {stretchy.push(core); core = (core.CoreMO()||core)}
  1538. this.HTMLcombineBBoxes(core,BBOX); i++;
  1539. }
  1540. this.HTMLcleanBBox(BBOX);
  1541. return stretchy;
  1542. },
  1543. HTMLcombineBBoxes: function (core,BBOX) {
  1544. if (BBOX.w == null) {this.HTMLemptyBBox(BBOX)}
  1545. var child = (core.bbox ? core : core.HTMLspanElement());
  1546. if (!child || !child.bbox) return;
  1547. var bbox = child.bbox;
  1548. if (bbox.d > BBOX.d) {BBOX.d = bbox.d}
  1549. if (bbox.h > BBOX.h) {BBOX.h = bbox.h}
  1550. if (bbox.D != null && bbox.D > BBOX.D) {BBOX.D = bbox.D}
  1551. if (bbox.H != null && bbox.H > BBOX.H) {BBOX.H = bbox.H}
  1552. if (child.style.paddingLeft) {BBOX.w += HTMLCSS.unEm(child.style.paddingLeft)*(child.scale||1)}
  1553. if (BBOX.w + bbox.lw < BBOX.lw) {BBOX.lw = BBOX.w + bbox.lw}
  1554. if (BBOX.w + bbox.rw > BBOX.rw) {BBOX.rw = BBOX.w + bbox.rw}
  1555. BBOX.w += bbox.w;
  1556. if (child.style.paddingRight) {BBOX.w += HTMLCSS.unEm(child.style.paddingRight)*(child.scale||1)}
  1557. if (bbox.width) {BBOX.width = bbox.width; BBOX.minWidth = bbox.minWidth}
  1558. if (bbox.ic) {BBOX.ic = bbox.ic} else {delete BBOX.ic}
  1559. if (BBOX.exactW && !bbox.exactW) {delete BBOX.exactW}
  1560. },
  1561. HTMLemptyBBox: function (BBOX) {
  1562. BBOX.h = BBOX.d = BBOX.H = BBOX.D = BBOX.rw = -HTMLCSS.BIGDIMEN;
  1563. BBOX.w = 0; BBOX.lw = HTMLCSS.BIGDIMEN;
  1564. return BBOX;
  1565. },
  1566. HTMLcleanBBox: function (BBOX) {
  1567. if (BBOX.h === this.BIGDIMEN)
  1568. {BBOX.h = BBOX.d = BBOX.H = BBOX.D = BBOX.w = BBOX.rw = BBOX.lw = 0}
  1569. if (BBOX.D <= BBOX.d) {delete BBOX.D}; if (BBOX.H <= BBOX.h) {delete BBOX.H}
  1570. },
  1571. HTMLzeroBBox: function () {return {h:0, d:0, w:0, lw: 0, rw:0}},
  1572. HTMLcanStretch: function (direction) {
  1573. if (this.isEmbellished()) {
  1574. var core = this.Core();
  1575. if (core && core !== this) {return core.HTMLcanStretch(direction)}
  1576. }
  1577. return false;
  1578. },
  1579. HTMLstretchH: function (box,W) {return this.HTMLspanElement()},
  1580. HTMLstretchV: function (box,h,d) {return this.HTMLspanElement()},
  1581. HTMLnotEmpty: function (data) {
  1582. while (data) {
  1583. if ((data.type !== "mrow" && data.type !== "texatom") ||
  1584. data.data.length > 1) {return true}
  1585. data = data.data[0];
  1586. }
  1587. return false;
  1588. },
  1589. HTMLmeasureChild: function (n,box) {
  1590. if (this.data[n]) {HTMLCSS.Measured(this.data[n].toHTML(box),box)}
  1591. else {box.bbox = this.HTMLzeroBBox()}
  1592. },
  1593. HTMLboxChild: function (n,box) {
  1594. if (!this.data[n]) {this.SetData(n,MML.mrow())}
  1595. return this.data[n].toHTML(box);
  1596. },
  1597. HTMLcreateSpan: function (span) {
  1598. if (this.spanID) {
  1599. var SPAN = this.HTMLspanElement();
  1600. if (SPAN && (SPAN.parentNode === span || (SPAN.parentNode||{}).parentNode === span)) {
  1601. while (SPAN.firstChild) {SPAN.removeChild(SPAN.firstChild)}
  1602. SPAN.bbox = this.HTMLzeroBBox();
  1603. SPAN.scale = 1; SPAN.isMultChar = SPAN.HH = null;
  1604. SPAN.style.cssText = "";
  1605. return SPAN;
  1606. }
  1607. }
  1608. if (this.href) {span = HTMLCSS.addElement(span,"a",{href:this.href, isMathJax:true})}
  1609. span = HTMLCSS.addElement(span,"span",{className: this.type, isMathJax:true});
  1610. if (HTMLCSS.imgHeightBug) {span.style.display = "inline-block"}
  1611. if (this["class"]) {span.className += " "+this["class"]}
  1612. if (!this.spanID) {this.spanID = HTMLCSS.GetID()}
  1613. span.id = (this.id || "MathJax-Span-"+this.spanID) + HTMLCSS.idPostfix;
  1614. span.bbox = this.HTMLzeroBBox(); this.styles = {};
  1615. if (this.style) {
  1616. span.style.cssText = this.style;
  1617. if (span.style.fontSize) {this.mathsize = span.style.fontSize; span.style.fontSize = ""}
  1618. this.styles = {border:HTMLCSS.getBorders(span), padding:HTMLCSS.getPadding(span)}
  1619. if (this.styles.border) {span.style.border = ""} // IE needs "0px none"?
  1620. if (this.styles.padding) {span.style.padding = ""}
  1621. }
  1622. if (this.href) {span.parentNode.bbox = span.bbox}
  1623. return span;
  1624. },
  1625. HTMLspanElement: function () {
  1626. if (!this.spanID) {return null}
  1627. return document.getElementById((this.id||"MathJax-Span-"+this.spanID)+HTMLCSS.idPostfix);
  1628. },
  1629. HTMLhandleVariant: function (span,variant,text) {HTMLCSS.handleVariant(span,variant,text)},
  1630. HTMLhandleSize: function (span) {
  1631. if (!span.scale) {
  1632. span.scale = this.HTMLgetScale();
  1633. if (span.scale !== 1) {span.style.fontSize = HTMLCSS.Percent(span.scale)}
  1634. }
  1635. return span;
  1636. },
  1637. HTMLhandleColor: function (span) {
  1638. var values = this.getValues("mathcolor","color");
  1639. if (this.mathbackground) {values.mathbackground = this.mathbackground}
  1640. if (this.background) {values.background = this.background}
  1641. if (this.style && span.style.backgroundColor) {
  1642. values.mathbackground = span.style.backgroundColor;
  1643. span.style.backgroundColor = "transparent";
  1644. }
  1645. var borders = (this.styles||{}).border, padding = (this.styles||{}).padding;
  1646. if (values.color && !this.mathcolor) {values.mathcolor = values.color}
  1647. if (values.background && !this.mathbackground) {values.mathbackground = values.background}
  1648. if (values.mathcolor) {span.style.color = values.mathcolor}
  1649. if ((values.mathbackground && values.mathbackground !== MML.COLOR.TRANSPARENT) ||
  1650. borders || padding) {
  1651. var bbox = span.bbox, dd = (bbox.exact ? 0 : 1/HTMLCSS.em), lW = 0, rW = 0,
  1652. lpad = span.style.paddingLeft, rpad = span.style.paddingRight;
  1653. if (this.isToken) {lW = bbox.lw; rW = bbox.rw - bbox.w}
  1654. if (lpad !== "") {lW += HTMLCSS.unEm(lpad)*(span.scale||1)}
  1655. if (rpad !== "") {rW -= HTMLCSS.unEm(rpad)*(span.scale||1)}
  1656. var dw = (HTMLCSS.PaddingWidthBug || bbox.keepPadding || bbox.exactW ? 0 : rW - lW);
  1657. var W = Math.max(0,HTMLCSS.getW(span) + dw);
  1658. var H = bbox.h + bbox.d, D = -bbox.d, lp = 0, rp = 0;
  1659. if (W > 0) {W += 2*dd; lW -= dd}; if (H > 0) {H += 2*dd; D -= dd}; rW = -W-lW;
  1660. if (borders) {
  1661. rW -= borders.right; D -= borders.bottom; lp += borders.left; rp += borders.right;
  1662. bbox.h += borders.top; bbox.d += borders.bottom;
  1663. bbox.w += borders.left + borders.right;
  1664. bbox.lw -= borders.left; bbox.rw += borders.right;
  1665. }
  1666. if (padding) {
  1667. H += padding.top + padding.bottom; W += padding.left + padding.right;
  1668. rW -= padding.right; D -= padding.bottom; lp += padding.left; rp += padding.right;
  1669. bbox.h += padding.top; bbox.d += padding.bottom;
  1670. bbox.w += padding.left + padding.right;
  1671. bbox.lw -= padding.left; bbox.rw += padding.right;
  1672. }
  1673. if (rp) {span.style.paddingRight = HTMLCSS.Em(rp)}
  1674. var frame = HTMLCSS.Element("span",{
  1675. id:"MathJax-Color-"+this.spanID+HTMLCSS.idPostfix, isMathJax: true,
  1676. style:{display:"inline-block", backgroundColor:values.mathbackground,
  1677. width: HTMLCSS.Em(W), height:HTMLCSS.Em(H), verticalAlign: HTMLCSS.Em(D),
  1678. marginLeft: HTMLCSS.Em(lW), marginRight: HTMLCSS.Em(rW)}
  1679. });
  1680. HTMLCSS.setBorders(frame,borders);
  1681. if (bbox.width) {frame.style.width = bbox.width; frame.style.marginRight = "-"+bbox.width}
  1682. if (HTMLCSS.msieInlineBlockAlignBug) {
  1683. // FIXME: handle variable width background
  1684. frame.style.position = "relative"; frame.style.width = frame.style.height = 0;
  1685. frame.style.verticalAlign = frame.style.marginLeft = frame.style.marginRight = "";
  1686. frame.style.border = frame.style.padding = "";
  1687. if (borders && HTMLCSS.msieBorderWidthBug)
  1688. {H += borders.top + borders.bottom; W += borders.left + borders.right}
  1689. frame.style.width = HTMLCSS.Em(lp+dd);
  1690. HTMLCSS.placeBox(HTMLCSS.addElement(frame,"span",{
  1691. noAdjust: true, isMathJax: true,
  1692. style: {display:"inline-block", position:"absolute", overflow:"hidden",
  1693. background:(values.mathbackground||"transparent"),
  1694. width: HTMLCSS.Em(W), height: HTMLCSS.Em(H)}
  1695. }),lW,bbox.h+dd);
  1696. HTMLCSS.setBorders(frame.firstChild,borders);
  1697. }
  1698. span.parentNode.insertBefore(frame,span);
  1699. if (HTMLCSS.msieColorPositionBug) {span.style.position = "relative"}
  1700. return frame;
  1701. }
  1702. return null;
  1703. },
  1704. HTMLremoveColor: function () {
  1705. var color = document.getElementById("MathJax-Color-"+this.spanID+HTMLCSS.idPostfix);
  1706. if (color) {color.parentNode.removeChild(color)}
  1707. },
  1708. HTMLhandleSpace: function (span) {
  1709. if (this.useMMLspacing) {
  1710. if (this.type !== "mo") return;
  1711. var values = this.getValues("scriptlevel","lspace","rspace");
  1712. if (values.scriptlevel <= 0 || this.hasValue("lspace") || this.hasValue("rspace")) {
  1713. var mu = this.HTMLgetMu(span);
  1714. values.lspace = Math.max(0,HTMLCSS.length2em(values.lspace,mu));
  1715. values.rspace = Math.max(0,HTMLCSS.length2em(values.rspace,mu));
  1716. var core = this, parent = this.Parent();
  1717. while (parent && parent.isEmbellished() && parent.Core() === core)
  1718. {core = parent; parent = parent.Parent(); span = core.HTMLspanElement()}
  1719. if (values.lspace) {span.style.paddingLeft = HTMLCSS.Em(values.lspace)}
  1720. if (values.rspace) {span.style.paddingRight = HTMLCSS.Em(values.rspace)}
  1721. }
  1722. } else {
  1723. var space = this.texSpacing();
  1724. if (space !== "") {
  1725. space = HTMLCSS.length2em(space,this.HTMLgetScale())/(span.scale||1);
  1726. if (span.style.paddingLeft) {space += HTMLCSS.unEm(span.style.paddingLeft)}
  1727. span.style.paddingLeft = HTMLCSS.Em(space);
  1728. }
  1729. }
  1730. },
  1731. HTMLgetScale: function () {
  1732. var scale = 1, values = this.getValues("mathsize","scriptlevel","fontsize");
  1733. if (this.style) {
  1734. var span = this.HTMLspanElement();
  1735. if (span.style.fontSize != "") {values.fontsize = span.style.fontSize}
  1736. }
  1737. if (values.fontsize && !this.mathsize) {values.mathsize = values.fontsize}
  1738. if (values.scriptlevel !== 0) {
  1739. if (values.scriptlevel > 2) {values.scriptlevel = 2}
  1740. scale = Math.pow(this.Get("scriptsizemultiplier"),values.scriptlevel);
  1741. values.scriptminsize = HTMLCSS.length2em(this.Get("scriptminsize"));
  1742. if (scale < values.scriptminsize) {scale = values.scriptminsize}
  1743. }
  1744. if (this.isToken) {scale *= HTMLCSS.length2em(values.mathsize)}
  1745. return scale;
  1746. },
  1747. HTMLgetMu: function (span) {
  1748. var mu = 1, values = this.getValues("scriptlevel","scriptsizemultiplier");
  1749. if (span.scale && span.scale !== 1) {mu = 1/span.scale}
  1750. if (values.scriptlevel !== 0) {
  1751. if (values.scriptlevel > 2) {values.scriptlevel = 2}
  1752. mu = Math.sqrt(Math.pow(values.scriptsizemultiplier,values.scriptlevel));
  1753. }
  1754. return mu;
  1755. },
  1756. HTMLgetVariant: function () {
  1757. var values = this.getValues("mathvariant","fontfamily","fontweight","fontstyle");
  1758. values.hasVariant = this.Get("mathvariant",true); // null if not explicitly specified
  1759. if (!values.hasVariant) {
  1760. values.family = values.fontfamily;
  1761. values.weight = values.fontweight;
  1762. values.style = values.fontstyle;
  1763. }
  1764. if (this.style) {
  1765. var span = this.HTMLspanElement();
  1766. if (!values.family && span.style.fontFamily) {values.family = span.style.fontFamily}
  1767. if (!values.weight && span.style.fontWeight) {values.weight = span.style.fontWeight}
  1768. if (!values.style && span.style.fontStyle) {values.style = span.style.fontStyle}
  1769. }
  1770. if (values.weight && values.weight.match(/^\d+$/))
  1771. {values.weight = (parseInt(values.weight) > 600 ? "bold" : "normal")}
  1772. var variant = values.mathvariant; if (this.variantForm) {variant = "-"+HTMLCSS.fontInUse+"-variant"}
  1773. if (values.family && !values.hasVariant) {
  1774. if (!values.weight && values.mathvariant.match(/bold/)) {values.weight = "bold"}
  1775. if (!values.style && values.mathvariant.match(/italic/)) {values.style = "italic"}
  1776. return {FONTS:[], fonts:[], noRemap:true,
  1777. defaultFont: {family:values.family, style:values.style, weight:values.weight}};
  1778. }
  1779. if (values.weight === "bold") {
  1780. variant = {
  1781. normal:MML.VARIANT.BOLD, italic:MML.VARIANT.BOLDITALIC,
  1782. fraktur:MML.VARIANT.BOLDFRAKTUR, script:MML.VARIANT.BOLDSCRIPT,
  1783. "sans-serif":MML.VARIANT.BOLDSANSSERIF,
  1784. "sans-serif-italic":MML.VARIANT.SANSSERIFBOLDITALIC
  1785. }[variant]||variant;
  1786. } else if (values.weight === "normal") {
  1787. variant = {
  1788. bold:MML.VARIANT.normal, "bold-italic":MML.VARIANT.ITALIC,
  1789. "bold-fraktur":MML.VARIANT.FRAKTUR, "bold-script":MML.VARIANT.SCRIPT,
  1790. "bold-sans-serif":MML.VARIANT.SANSSERIF,
  1791. "sans-serif-bold-italic":MML.VARIANT.SANSSERIFITALIC
  1792. }[variant]||variant;
  1793. }
  1794. if (values.style === "italic") {
  1795. variant = {
  1796. normal:MML.VARIANT.ITALIC, bold:MML.VARIANT.BOLDITALIC,
  1797. "sans-serif":MML.VARIANT.SANSSERIFITALIC,
  1798. "bold-sans-serif":MML.VARIANT.SANSSERIFBOLDITALIC
  1799. }[variant]||variant;
  1800. } else if (values.style === "normal") {
  1801. variant = {
  1802. italic:MML.VARIANT.NORMAL, "bold-italic":MML.VARIANT.BOLD,
  1803. "sans-serif-italic":MML.VARIANT.SANSSERIF,
  1804. "sans-serif-bold-italic":MML.VARIANT.BOLDSANSSERIF
  1805. }[variant]||variant;
  1806. }
  1807. if (!(variant in HTMLCSS.FONTDATA.VARIANT)) {
  1808. // If the mathvariant value is invalid or not supported by this
  1809. // font, fallback to normal. See issue 363.
  1810. variant = "normal";
  1811. }
  1812. return HTMLCSS.FONTDATA.VARIANT[variant];
  1813. }
  1814. },{
  1815. HTMLautoload: function () {
  1816. var file = HTMLCSS.autoloadDir+"/"+this.type+".js";
  1817. HUB.RestartAfter(AJAX.Require(file));
  1818. },
  1819. HTMLautoloadFile: function (name) {
  1820. var file = HTMLCSS.autoloadDir+"/"+name+".js";
  1821. HUB.RestartAfter(AJAX.Require(file));
  1822. },
  1823. HTMLstretchH: function (box,w) {
  1824. this.HTMLremoveColor();
  1825. return this.toHTML(box,w);
  1826. },
  1827. HTMLstretchV: function (box,h,d) {
  1828. this.HTMLremoveColor();
  1829. return this.toHTML(box,h,d);
  1830. }
  1831. });
  1832. MML.chars.Augment({
  1833. toHTML: function (span,variant,remap,chars) {
  1834. var text = this.data.join("").replace(/[\u2061-\u2064]/g,""); // remove invisibles
  1835. if (remap) {text = remap(text,chars)}
  1836. if (variant.fontInherit) {
  1837. var scale = Math.floor(100/HTMLCSS.scale+.5) + "%";
  1838. HTMLCSS.addElement(span,"span",{style:{"font-size":scale}},[text]);
  1839. if (variant.bold) {span.lastChild.style.fontWeight = "bold"}
  1840. if (variant.italic) {span.lastChild.style.fontStyle = "italic"}
  1841. var HD = HTMLCSS.getHD(span), W = HTMLCSS.getW(span);
  1842. span.bbox = {h:HD.h, d:HD.d, w:W, lw:0, rw:W, exactW: true};
  1843. } else {
  1844. this.HTMLhandleVariant(span,variant,text);
  1845. }
  1846. }
  1847. });
  1848. MML.entity.Augment({
  1849. toHTML: function (span,variant,remap,chars) {
  1850. var text = this.toString().replace(/[\u2061-\u2064]/g,""); // remove invisibles
  1851. if (remap) {text = remap(text,chars)}
  1852. if (variant.fontInherit) {
  1853. var scale = Math.floor(100/HTMLCSS.scale+.5) + "%";
  1854. HTMLCSS.addElement(span,"span",{style:{"font-size":scale}},[text]);
  1855. if (variant.bold) {span.lastChild.style.fontWeight = "bold"}
  1856. if (variant.italic) {span.lastChild.style.fontStyle = "italic"}
  1857. var HD = HTMLCSS.getHD(span), W = HTMLCSS.getW(span);
  1858. span.bbox = {h:HD.h, d:HD.d, w:W, lw:0, rw:W, exactW: true};
  1859. } else {
  1860. this.HTMLhandleVariant(span,variant,text);
  1861. }
  1862. }
  1863. });
  1864. MML.mi.Augment({
  1865. toHTML: function (span) {
  1866. span = this.HTMLhandleSize(this.HTMLcreateSpan(span)); span.bbox = null;
  1867. var variant = this.HTMLgetVariant();
  1868. for (var i = 0, m = this.data.length; i < m; i++)
  1869. {if (this.data[i]) {this.data[i].toHTML(span,variant)}}
  1870. if (!span.bbox) {span.bbox = this.HTMLzeroBBox()}
  1871. var text = this.data.join(""), bbox = span.bbox;
  1872. if (bbox.skew && text.length !== 1) {delete bbox.skew}
  1873. if (bbox.rw > bbox.w && text.length === 1 && !variant.noIC) {
  1874. bbox.ic = bbox.rw - bbox.w;
  1875. HTMLCSS.createBlank(span,bbox.ic);
  1876. bbox.w = bbox.rw;
  1877. }
  1878. this.HTMLhandleSpace(span);
  1879. this.HTMLhandleColor(span);
  1880. return span;
  1881. }
  1882. });
  1883. MML.mn.Augment({
  1884. toHTML: function (span) {
  1885. span = this.HTMLhandleSize(this.HTMLcreateSpan(span)); span.bbox = null;
  1886. var variant = this.HTMLgetVariant();
  1887. for (var i = 0, m = this.data.length; i < m; i++)
  1888. {if (this.data[i]) {this.data[i].toHTML(span,variant)}}
  1889. if (!span.bbox) {span.bbox = this.HTMLzeroBBox()}
  1890. if (this.data.join("").length !== 1) {delete span.bbox.skew}
  1891. this.HTMLhandleSpace(span);
  1892. this.HTMLhandleColor(span);
  1893. return span;
  1894. }
  1895. });
  1896. MML.mo.Augment({
  1897. toHTML: function (span) {
  1898. span = this.HTMLhandleSize(this.HTMLcreateSpan(span));
  1899. if (this.data.length == 0) {return span} else {span.bbox = null}
  1900. var text = this.data.join("");
  1901. //
  1902. // Get the variant, and check for operator size
  1903. //
  1904. var variant = this.HTMLgetVariant();
  1905. var values = this.getValues("largeop","displaystyle");
  1906. if (values.largeop)
  1907. {variant = HTMLCSS.FONTDATA.VARIANT[values.displaystyle ? "-largeOp" : "-smallOp"]}
  1908. //
  1909. // Get character translation for superscript and accents
  1910. //
  1911. var parent = this.CoreParent(),
  1912. isScript = (parent && parent.isa(MML.msubsup) && this !== parent.data[parent.base]),
  1913. mapchars = (isScript?this.HTMLremapChars:null);
  1914. if (text.length === 1 && parent && parent.isa(MML.munderover) &&
  1915. this.CoreText(parent.data[parent.base]).length === 1) {
  1916. var over = parent.data[parent.over], under = parent.data[parent.under];
  1917. if (over && this === over.CoreMO() && parent.Get("accent")) {mapchars = HTMLCSS.FONTDATA.REMAPACCENT}
  1918. else if (under && this === under.CoreMO() && parent.Get("accentunder")) {mapchars = HTMLCSS.FONTDATA.REMAPACCENTUNDER}
  1919. }
  1920. //
  1921. // STIX and TeX fonts need quotes from variant font
  1922. //
  1923. if (isScript && text.match(/['`"\u00B4\u2032-\u2037\u2057]/))
  1924. {variant = HTMLCSS.FONTDATA.VARIANT["-"+HTMLCSS.fontInUse+"-variant"]}
  1925. //
  1926. // Typeset contents
  1927. //
  1928. for (var i = 0, m = this.data.length; i < m; i++)
  1929. {if (this.data[i]) {this.data[i].toHTML(span,variant,this.HTMLremap,mapchars)}}
  1930. if (!span.bbox) {span.bbox = this.HTMLzeroBBox()}
  1931. if (text.length !== 1) {delete span.bbox.skew}
  1932. //
  1933. // Handle combining characters by adding a non-breaking space and removing that width
  1934. //
  1935. if (HTMLCSS.AccentBug && span.bbox.w === 0 && text.length === 1 && span.firstChild) {
  1936. span.firstChild.nodeValue += HTMLCSS.NBSP;
  1937. HTMLCSS.createSpace(span,0,0,-span.offsetWidth/HTMLCSS.em);
  1938. }
  1939. //
  1940. // Handle large operator centering
  1941. //
  1942. if (values.largeop) {
  1943. var p = (span.bbox.h - span.bbox.d)/2 - HTMLCSS.TeX.axis_height*span.scale;
  1944. if (HTMLCSS.safariVerticalAlignBug && span.lastChild.nodeName === "IMG") {
  1945. span.lastChild.style.verticalAlign =
  1946. HTMLCSS.Em(HTMLCSS.unEm(span.lastChild.style.verticalAlign||0)/HTMLCSS.em-p/span.scale);
  1947. } else if (HTMLCSS.konquerorVerticalAlignBug && span.lastChild.nodeName === "IMG") {
  1948. span.style.position = "relative";
  1949. span.lastChild.style.position="relative";
  1950. span.lastChild.style.top = HTMLCSS.Em(p/span.scale);
  1951. } else {
  1952. span.style.verticalAlign = HTMLCSS.Em(-p/span.scale);
  1953. }
  1954. span.bbox.h -= p; span.bbox.d += p;
  1955. if (span.bbox.rw > span.bbox.w) {
  1956. span.bbox.ic = span.bbox.rw-span.bbox.w;
  1957. HTMLCSS.createBlank(span,span.bbox.ic);
  1958. span.bbox.w = span.bbox.rw;
  1959. }
  1960. }
  1961. //
  1962. // Finish up
  1963. //
  1964. this.HTMLhandleSpace(span);
  1965. this.HTMLhandleColor(span);
  1966. return span;
  1967. },
  1968. CoreParent: function () {
  1969. var parent = this;
  1970. while (parent && parent.isEmbellished() &&
  1971. parent.CoreMO() === this && !parent.isa(MML.math)) {parent = parent.Parent()}
  1972. return parent;
  1973. },
  1974. CoreText: function (parent) {
  1975. if (!parent) {return ""}
  1976. if (parent.isEmbellished()) {return parent.CoreMO().data.join("")}
  1977. while ((parent.isa(MML.mrow) || parent.isa(MML.TeXAtom) ||
  1978. parent.isa(MML.mstyle) || parent.isa(MML.mphantom)) &&
  1979. parent.data.length === 1 && parent.data[0]) {parent = parent.data[0]}
  1980. if (!parent.isToken) {return ""} else {return parent.data.join("")}
  1981. },
  1982. HTMLremapChars: {
  1983. '*':"\u2217",
  1984. '"':"\u2033",
  1985. "\u00B0":"\u2218",
  1986. "\u00B2":"2",
  1987. "\u00B3":"3",
  1988. "\u00B4":"\u2032",
  1989. "\u00B9":"1"
  1990. },
  1991. HTMLremap: function (text,map) {
  1992. text = text.replace(/-/g,"\u2212");
  1993. if (map) {
  1994. text = text.replace(/'/g,"\u2032").replace(/`/g,"\u2035");
  1995. if (text.length === 1) {text = map[text]||text}
  1996. }
  1997. return text;
  1998. },
  1999. HTMLcanStretch: function (direction) {
  2000. if (!this.Get("stretchy")) {return false}
  2001. var c = this.data.join("");
  2002. if (c.length > 1) {return false}
  2003. var parent = this.CoreParent();
  2004. if (parent && parent.isa(MML.munderover) &&
  2005. this.CoreText(parent.data[parent.base]).length === 1) {
  2006. var over = parent.data[parent.over], under = parent.data[parent.under];
  2007. if (over && this === over.CoreMO() && parent.Get("accent")) {c = HTMLCSS.FONTDATA.REMAPACCENT[c]||c}
  2008. else if (under && this === under.CoreMO() && parent.Get("accentunder")) {c = HTMLCSS.FONTDATA.REMAPACCENTUNDER[c]||c}
  2009. }
  2010. c = HTMLCSS.FONTDATA.DELIMITERS[c.charCodeAt(0)];
  2011. return (c && c.dir == direction.substr(0,1));
  2012. },
  2013. HTMLstretchV: function (box,h,d) {
  2014. this.HTMLremoveColor();
  2015. var values = this.getValues("symmetric","maxsize","minsize");
  2016. var span = this.HTMLspanElement(), mu = this.HTMLgetMu(span), H;
  2017. var axis = HTMLCSS.TeX.axis_height, scale = span.scale;
  2018. if (values.symmetric) {H = 2*Math.max(h-axis,d+axis)} else {H = h + d}
  2019. values.maxsize = HTMLCSS.length2em(values.maxsize,mu,span.bbox.h+span.bbox.d);
  2020. values.minsize = HTMLCSS.length2em(values.minsize,mu,span.bbox.h+span.bbox.d);
  2021. H = Math.max(values.minsize,Math.min(values.maxsize,H));
  2022. span = this.HTMLcreateSpan(box); // clear contents and attributes
  2023. HTMLCSS.createDelimiter(span,this.data.join("").charCodeAt(0),H,scale);
  2024. if (values.symmetric) {H = (span.bbox.h + span.bbox.d)/2 + axis}
  2025. else {H = (span.bbox.h + span.bbox.d) * h/(h + d)}
  2026. HTMLCSS.positionDelimiter(span,H);
  2027. this.HTMLhandleSpace(span); // add in lspace/rspace, if any
  2028. this.HTMLhandleColor(span);
  2029. return span;
  2030. },
  2031. HTMLstretchH: function (box,W) {
  2032. this.HTMLremoveColor();
  2033. var values = this.getValues("maxsize","minsize","mathvariant","fontweight");
  2034. // FIXME: should take style="font-weight:bold" into account as well
  2035. if ((values.fontweight === "bold" || parseInt(values.fontweight) >= 600) &&
  2036. !this.Get("mathvariant",true)) {values.mathvariant = MML.VARIANT.BOLD}
  2037. var span = this.HTMLspanElement(), mu = this.HTMLgetMu(span), scale = span.scale;
  2038. values.maxsize = HTMLCSS.length2em(values.maxsize,mu,span.bbox.w);
  2039. values.minsize = HTMLCSS.length2em(values.minsize,mu,span.bbox.w);
  2040. W = Math.max(values.minsize,Math.min(values.maxsize,W));
  2041. span = this.HTMLcreateSpan(box); // clear contents and attributes
  2042. HTMLCSS.createDelimiter(span,this.data.join("").charCodeAt(0),W,scale,values.mathvariant);
  2043. this.HTMLhandleSpace(span); // add in lspace/rspace, if any
  2044. this.HTMLhandleColor(span);
  2045. return span;
  2046. }
  2047. });
  2048. MML.mtext.Augment({
  2049. toHTML: function (span) {
  2050. span = this.HTMLhandleSize(this.HTMLcreateSpan(span));
  2051. var variant = this.HTMLgetVariant();
  2052. // Avoid setting the font style for error text or if mtextFontInherit is set
  2053. if (HTMLCSS.config.mtextFontInherit || this.Parent().type === "merror")
  2054. {variant = {bold:variant.bold, italic:variant.italic, fontInherit: true}}
  2055. for (var i = 0, m = this.data.length; i < m; i++)
  2056. {if (this.data[i]) {this.data[i].toHTML(span,variant)}}
  2057. if (!span.bbox) {span.bbox = this.HTMLzeroBBox()}
  2058. if (this.data.join("").length !== 1) {delete span.bbox.skew}
  2059. this.HTMLhandleSpace(span);
  2060. this.HTMLhandleColor(span);
  2061. return span;
  2062. }
  2063. });
  2064. MML.merror.Augment({
  2065. toHTML: function (span) {
  2066. //
  2067. // Width doesn't include padding and border, so use an extra inline block
  2068. // element to capture it.
  2069. //
  2070. var SPAN = MathJax.HTML.addElement(span,"span",{style:{display:"inline-block"}});
  2071. span = this.SUPER(arguments).toHTML.call(this,SPAN);
  2072. var HD = HTMLCSS.getHD(SPAN), W = HTMLCSS.getW(SPAN);
  2073. SPAN.bbox = {h:HD.h, d:HD.d, w:W, lw:0, rw:W, exactW: true};
  2074. SPAN.id = span.id; span.id = null;
  2075. return SPAN;
  2076. }
  2077. });
  2078. MML.ms.Augment({toHTML: MML.mbase.HTMLautoload});
  2079. MML.mglyph.Augment({toHTML: MML.mbase.HTMLautoload});
  2080. MML.mspace.Augment({
  2081. toHTML: function (span) {
  2082. span = this.HTMLcreateSpan(span);
  2083. var values = this.getValues("height","depth","width");
  2084. var mu = this.HTMLgetMu(span);
  2085. values.mathbackground = this.mathbackground;
  2086. if (this.background && !this.mathbackground) {values.mathbackground = this.background}
  2087. var h = HTMLCSS.length2em(values.height,mu),
  2088. d = HTMLCSS.length2em(values.depth,mu),
  2089. w = HTMLCSS.length2em(values.width,mu);
  2090. HTMLCSS.createSpace(span,h,d,w,values.mathbackground,true);
  2091. return span;
  2092. }
  2093. });
  2094. MML.mphantom.Augment({
  2095. toHTML: function (span,HW,D) {
  2096. span = this.HTMLcreateSpan(span);
  2097. if (this.data[0] != null) {
  2098. var box = this.data[0].toHTML(span);
  2099. if (D != null) {HTMLCSS.Remeasured(this.data[0].HTMLstretchV(span,HW,D),span)}
  2100. else if (HW != null) {HTMLCSS.Remeasured(this.data[0].HTMLstretchH(span,HW),span)}
  2101. else {box = HTMLCSS.Measured(box,span)}
  2102. span.bbox = {w: box.bbox.w, h: box.bbox.h, d: box.bbox.d, lw: 0, rw: 0, exactW: true};
  2103. for (var i = 0, m = span.childNodes.length; i < m; i++)
  2104. {span.childNodes[i].style.visibility = "hidden"}
  2105. }
  2106. this.HTMLhandleSpace(span);
  2107. this.HTMLhandleColor(span);
  2108. return span;
  2109. },
  2110. HTMLstretchH: MML.mbase.HTMLstretchH,
  2111. HTMLstretchV: MML.mbase.HTMLstretchV
  2112. });
  2113. MML.mpadded.Augment({
  2114. toHTML: function (span,HW,D) {
  2115. span = this.HTMLcreateSpan(span);
  2116. if (this.data[0] != null) {
  2117. var stack = HTMLCSS.createStack(span,true);
  2118. var box = HTMLCSS.createBox(stack);
  2119. var child = this.data[0].toHTML(box);
  2120. if (D != null) {HTMLCSS.Remeasured(this.data[0].HTMLstretchV(box,HW,D),box)}
  2121. else if (HW != null) {HTMLCSS.Remeasured(this.data[0].HTMLstretchH(box,HW),box)}
  2122. else {HTMLCSS.Measured(child,box)}
  2123. var values = this.getValues("height","depth","width","lspace","voffset"),
  2124. x = 0, y = 0, mu = this.HTMLgetMu(span);
  2125. if (values.lspace) {x = this.HTMLlength2em(box,values.lspace,mu)}
  2126. if (values.voffset) {y = this.HTMLlength2em(box,values.voffset,mu)}
  2127. HTMLCSS.placeBox(box,x,y);
  2128. span.bbox = {
  2129. h: box.bbox.h, d: box.bbox.d, w: box.bbox.w, exactW: true,
  2130. lw: Math.min(0,box.bbox.lw+x), rw: Math.max(box.bbox.w,box.bbox.rw+x),
  2131. H: Math.max((box.bbox.H == null ? -HTMLCSS.BIGDIMEN : box.bbox.H),box.bbox.h+y),
  2132. D: Math.max((box.bbox.D == null ? -HTMLCSS.BIGDIMEN : box.bbox.D),box.bbox.d-y)
  2133. };
  2134. if (values.height !== "") {span.bbox.h = this.HTMLlength2em(box,values.height,mu,"h",0)}
  2135. if (values.depth !== "") {span.bbox.d = this.HTMLlength2em(box,values.depth,mu,"d",0)}
  2136. if (values.width !== "") {span.bbox.w = this.HTMLlength2em(box,values.width,mu,"w",0)}
  2137. if (span.bbox.H <= span.bbox.h) {delete span.bbox.H}
  2138. if (span.bbox.D <= span.bbox.d) {delete span.bbox.D}
  2139. var dimen = /^\s*(\d+(\.\d*)?|\.\d+)\s*(pt|em|ex|mu|px|pc|in|mm|cm)\s*$/
  2140. span.bbox.exact = !!((this.data[0] && this.data[0].data.length == 0) ||
  2141. dimen.exec(values.height) || dimen.exec(values.width) || dimen.exec(values.depth));
  2142. HTMLCSS.setStackWidth(stack,span.bbox.w);
  2143. }
  2144. this.HTMLhandleSpace(span);
  2145. this.HTMLhandleColor(span);
  2146. return span;
  2147. },
  2148. HTMLlength2em: function (span,length,mu,d,m) {
  2149. if (m == null) {m = -HTMLCSS.BIGDIMEN}
  2150. var match = String(length).match(/width|height|depth/);
  2151. var size = (match ? span.bbox[match[0].charAt(0)] : (d ? span.bbox[d] : 0));
  2152. var v = HTMLCSS.length2em(length,mu,size);
  2153. if (d && String(length).match(/^\s*[-+]/))
  2154. {return Math.max(m,span.bbox[d]+v)} else {return v}
  2155. },
  2156. HTMLstretchH: MML.mbase.HTMLstretchH,
  2157. HTMLstretchV: MML.mbase.HTMLstretchV
  2158. });
  2159. MML.mrow.Augment({
  2160. HTMLlineBreaks: function (span) {
  2161. if (!this.parent.linebreakContainer) {return false}
  2162. return (HTMLCSS.config.linebreaks.automatic &&
  2163. span.bbox.w > HTMLCSS.linebreakWidth) || this.hasNewline();
  2164. },
  2165. HTMLstretchH: function (box,w) {
  2166. this.HTMLremoveColor();
  2167. var span = this.HTMLspanElement();
  2168. this.data[this.core].HTMLstretchH(span,w);
  2169. this.HTMLcomputeBBox(span,true);
  2170. this.HTMLhandleColor(span);
  2171. return span;
  2172. },
  2173. HTMLstretchV: function (box,h,d) {
  2174. this.HTMLremoveColor();
  2175. var span = this.HTMLspanElement();
  2176. this.data[this.core].HTMLstretchV(span,h,d);
  2177. this.HTMLcomputeBBox(span,true);
  2178. this.HTMLhandleColor(span);
  2179. return span;
  2180. }
  2181. });
  2182. MML.mstyle.Augment({
  2183. toHTML: function (span,HW,D) {
  2184. span = this.HTMLcreateSpan(span);
  2185. if (this.data[0] != null) {
  2186. var SPAN = this.data[0].toHTML(span);
  2187. if (D != null) {this.data[0].HTMLstretchV(span,HW,D)}
  2188. else if (HW != null) {this.data[0].HTMLstretchH(span,HW)}
  2189. span.bbox = SPAN.bbox;
  2190. }
  2191. this.HTMLhandleSpace(span);
  2192. this.HTMLhandleColor(span);
  2193. return span;
  2194. },
  2195. HTMLstretchH: MML.mbase.HTMLstretchH,
  2196. HTMLstretchV: MML.mbase.HTMLstretchV
  2197. });
  2198. MML.mfrac.Augment({
  2199. toHTML: function (span) {
  2200. span = this.HTMLcreateSpan(span);
  2201. var frac = HTMLCSS.createStack(span);
  2202. var num = HTMLCSS.createBox(frac), den = HTMLCSS.createBox(frac);
  2203. HTMLCSS.MeasureSpans([this.HTMLboxChild(0,num),this.HTMLboxChild(1,den)]);
  2204. var values = this.getValues("displaystyle","linethickness","numalign","denomalign","bevelled");
  2205. var scale = this.HTMLgetScale(), isDisplay = values.displaystyle;
  2206. var a = HTMLCSS.TeX.axis_height * scale;
  2207. if (values.bevelled) {
  2208. var delta = (isDisplay ? .4 : .15);
  2209. var H = Math.max(num.bbox.h+num.bbox.d,den.bbox.h+den.bbox.d)+2*delta;
  2210. var bevel = HTMLCSS.createBox(frac);
  2211. HTMLCSS.createDelimiter(bevel,0x2F,H);
  2212. HTMLCSS.placeBox(num,0,(num.bbox.d-num.bbox.h)/2+a+delta);
  2213. HTMLCSS.placeBox(bevel,num.bbox.w-delta/2,(bevel.bbox.d-bevel.bbox.h)/2+a);
  2214. HTMLCSS.placeBox(den,num.bbox.w+bevel.bbox.w-delta,(den.bbox.d-den.bbox.h)/2+a-delta);
  2215. } else {
  2216. var W = Math.max(num.bbox.w,den.bbox.w);
  2217. var t = HTMLCSS.thickness2em(values.linethickness,scale), p,q, u,v;
  2218. var mt = HTMLCSS.TeX.min_rule_thickness/this.em;
  2219. if (isDisplay) {u = HTMLCSS.TeX.num1; v = HTMLCSS.TeX.denom1}
  2220. else {u = (t === 0 ? HTMLCSS.TeX.num3 : HTMLCSS.TeX.num2); v = HTMLCSS.TeX.denom2}
  2221. u *= scale; v *= scale;
  2222. if (t === 0) {// \atop
  2223. p = Math.max((isDisplay ? 7 : 3) * HTMLCSS.TeX.rule_thickness, 2*mt); // force to at least 2 px
  2224. q = (u - num.bbox.d) - (den.bbox.h - v);
  2225. if (q < p) {u += (p - q)/2; v += (p - q)/2}
  2226. } else {// \over
  2227. p = Math.max((isDisplay ? 2 : 0) * mt + t, t/2 + 1.5*mt); // force to be at least 1.5px
  2228. q = (u - num.bbox.d) - (a + t/2); if (q < p) {u += p - q}
  2229. q = (a - t/2) - (den.bbox.h - v); if (q < p) {v += p - q}
  2230. var rule = HTMLCSS.createBox(frac);
  2231. HTMLCSS.createRule(rule,t,0,W+2*t);
  2232. HTMLCSS.placeBox(rule,0,a-t/2);
  2233. }
  2234. HTMLCSS.alignBox(num,values.numalign,u);
  2235. HTMLCSS.alignBox(den,values.denomalign,-v);
  2236. }
  2237. this.HTMLhandleSpace(span);
  2238. this.HTMLhandleColor(span);
  2239. return span;
  2240. },
  2241. HTMLcanStretch: function (direction) {return false},
  2242. HTMLhandleSpace: function (span) {
  2243. if (!this.texWithDelims) {
  2244. var space = (this.useMMLspacing ? 0 : HTMLCSS.length2em(this.texSpacing()||0)) + .12;
  2245. span.style.paddingLeft = HTMLCSS.Em(space);
  2246. span.style.paddingRight = HTMLCSS.Em(.12);
  2247. }
  2248. }
  2249. });
  2250. MML.msqrt.Augment({
  2251. toHTML: function (span) {
  2252. span = this.HTMLcreateSpan(span);
  2253. var sqrt = HTMLCSS.createStack(span);
  2254. var base = HTMLCSS.createBox(sqrt),
  2255. rule = HTMLCSS.createBox(sqrt),
  2256. surd = HTMLCSS.createBox(sqrt);
  2257. var scale = this.HTMLgetScale();
  2258. var t = HTMLCSS.TeX.rule_thickness * scale, p,q, H, W;
  2259. if (this.Get("displaystyle")) {p = HTMLCSS.TeX.x_height * scale} else {p = t}
  2260. q = Math.max(t + p/4,1.5*HTMLCSS.TeX.min_rule_thickness/this.em); // force to be at least 1px
  2261. var BASE = this.HTMLboxChild(0,base);
  2262. H = BASE.bbox.h + BASE.bbox.d + q + t;
  2263. HTMLCSS.createDelimiter(surd,0x221A,H,scale);
  2264. HTMLCSS.MeasureSpans([BASE,surd]);
  2265. W = BASE.bbox.w;
  2266. var x = 0;
  2267. if (surd.isMultiChar || (HTMLCSS.AdjustSurd && HTMLCSS.imgFonts)) {surd.bbox.w *= .95}
  2268. if (surd.bbox.h + surd.bbox.d > H) {q = ((surd.bbox.h+surd.bbox.d) - (H-t))/2}
  2269. var ruleC = HTMLCSS.FONTDATA.DELIMITERS[HTMLCSS.FONTDATA.RULECHAR];
  2270. if (!ruleC || W < ruleC.HW[0][0]*scale || scale < .75) {
  2271. HTMLCSS.createRule(rule,0,t,W);
  2272. } else {
  2273. HTMLCSS.createDelimiter(rule,HTMLCSS.FONTDATA.RULECHAR,W,scale);
  2274. }
  2275. H = BASE.bbox.h + q + t;
  2276. q = H*HTMLCSS.rfuzz; if (surd.isMultiChar) {q = HTMLCSS.rfuzz}
  2277. x = this.HTMLaddRoot(sqrt,surd,x,surd.bbox.h+surd.bbox.d-H,scale);
  2278. HTMLCSS.placeBox(surd,x,H-surd.bbox.h);
  2279. HTMLCSS.placeBox(rule,x+surd.bbox.w,H-rule.bbox.h+q);
  2280. HTMLCSS.placeBox(base,x+surd.bbox.w,0);
  2281. this.HTMLhandleSpace(span);
  2282. this.HTMLhandleColor(span);
  2283. return span;
  2284. },
  2285. HTMLaddRoot: function (sqrt,surd,x,d,scale) {return x}
  2286. });
  2287. MML.mroot.Augment({
  2288. toHTML: MML.msqrt.prototype.toHTML,
  2289. HTMLaddRoot: function (sqrt,surd,x,d,scale) {
  2290. var box = HTMLCSS.createBox(sqrt);
  2291. if (this.data[1]) {
  2292. var root = this.data[1].toHTML(box);
  2293. root.style.paddingRight = root.style.paddingLeft = ""; // remove extra padding, if any
  2294. HTMLCSS.Measured(root,box);
  2295. } else {box.bbox = this.HTMLzeroBBox()}
  2296. var h = this.HTMLrootHeight(surd.bbox.h+surd.bbox.d,scale,box)-d;
  2297. var w = Math.min(box.bbox.w,box.bbox.rw); // remove extra right-hand padding, if any
  2298. x = Math.max(w,surd.offset);
  2299. HTMLCSS.placeBox(box,x-w,h);
  2300. return x - surd.offset;
  2301. },
  2302. HTMLrootHeight: function (d,scale,root) {
  2303. return .45*(d-.9*scale)+.6*scale + Math.max(0,root.bbox.d-.075);
  2304. }
  2305. });
  2306. MML.mfenced.Augment({
  2307. toHTML: function (span) {
  2308. span = this.HTMLcreateSpan(span);
  2309. if (this.data.open) {this.data.open.toHTML(span)}
  2310. if (this.data[0] != null) {this.data[0].toHTML(span)}
  2311. for (var i = 1, m = this.data.length; i < m; i++) {
  2312. if (this.data[i]) {
  2313. if (this.data["sep"+i]) {this.data["sep"+i].toHTML(span)}
  2314. this.data[i].toHTML(span);
  2315. }
  2316. }
  2317. if (this.data.close) {this.data.close.toHTML(span)}
  2318. var stretchy = this.HTMLcomputeBBox(span);
  2319. var h = span.bbox.h, d = span.bbox.d;
  2320. for (i = 0, m = stretchy.length; i < m; i++) {stretchy[i].HTMLstretchV(span,h,d)}
  2321. if (stretchy.length) {this.HTMLcomputeBBox(span,true)}
  2322. this.HTMLhandleSpace(span);
  2323. this.HTMLhandleColor(span);
  2324. return span;
  2325. },
  2326. HTMLcomputeBBox: function (span,full) {
  2327. var BBOX = span.bbox = {}, stretchy = [];
  2328. this.HTMLcheckStretchy(this.data.open,BBOX,stretchy,full);
  2329. this.HTMLcheckStretchy(this.data[0],BBOX,stretchy,full);
  2330. for (var i = 1, m = this.data.length; i < m; i++) {
  2331. if (this.data[i]) {
  2332. this.HTMLcheckStretchy(this.data["sep"+i],BBOX,stretchy,full);
  2333. this.HTMLcheckStretchy(this.data[i],BBOX,stretchy,full);
  2334. }
  2335. }
  2336. this.HTMLcheckStretchy(this.data.close,BBOX,stretchy,full);
  2337. this.HTMLcleanBBox(BBOX);
  2338. return stretchy;
  2339. },
  2340. HTMLcheckStretchy: function (core,BBOX,stretchy,full) {
  2341. if (core) {
  2342. if (!full && core.HTMLcanStretch("Vertical"))
  2343. {stretchy.push(core); core = (core.CoreMO()||core)}
  2344. this.HTMLcombineBBoxes(core,BBOX);
  2345. }
  2346. }
  2347. });
  2348. MML.menclose.Augment({toHTML: MML.mbase.HTMLautoload});
  2349. MML.maction.Augment({toHTML: MML.mbase.HTMLautoload});
  2350. MML.semantics.Augment({
  2351. toHTML: function (span,HW,D) {
  2352. span = this.HTMLcreateSpan(span);
  2353. if (this.data[0] != null) {
  2354. var SPAN = this.data[0].toHTML(span);
  2355. if (D != null) {this.data[0].HTMLstretchV(span,HW,D)}
  2356. else if (HW != null) {this.data[0].HTMLstretchH(span,HW)}
  2357. span.bbox = SPAN.bbox;
  2358. }
  2359. this.HTMLhandleSpace(span);
  2360. return span;
  2361. },
  2362. HTMLstretchH: MML.mbase.HTMLstretchH,
  2363. HTMLstretchV: MML.mbase.HTMLstretchV
  2364. });
  2365. MML.munderover.Augment({
  2366. toHTML: function (span,HW,D) {
  2367. var values = this.getValues("displaystyle","accent","accentunder","align");
  2368. if (!values.displaystyle && this.data[this.base] != null &&
  2369. this.data[this.base].CoreMO().Get("movablelimits"))
  2370. {return MML.msubsup.prototype.toHTML.call(this,span)}
  2371. span = this.HTMLcreateSpan(span); var scale = this.HTMLgetScale();
  2372. var stack = HTMLCSS.createStack(span);
  2373. var boxes = [], children = [], stretch = [], box, i, m;
  2374. for (i = 0, m = this.data.length; i < m; i++) {
  2375. if (this.data[i] != null) {
  2376. box = boxes[i] = HTMLCSS.createBox(stack);
  2377. children[i] = this.data[i].toHTML(box);
  2378. if (i == this.base) {
  2379. if (D != null) {this.data[this.base].HTMLstretchV(box,HW,D)}
  2380. else if (HW != null) {this.data[this.base].HTMLstretchH(box,HW)}
  2381. stretch[i] = (D == null && HW != null ? false :
  2382. this.data[i].HTMLcanStretch("Horizontal"));
  2383. } else {
  2384. stretch[i] = this.data[i].HTMLcanStretch("Horizontal");
  2385. }
  2386. }
  2387. }
  2388. HTMLCSS.MeasureSpans(children);
  2389. var W = -HTMLCSS.BIGDIMEN, WW = W;
  2390. for (i = 0, m = this.data.length; i < m; i++) {
  2391. if (this.data[i]) {
  2392. if (boxes[i].bbox.w > WW) {WW = boxes[i].bbox.w}
  2393. if (!stretch[i] && WW > W) {W = WW}
  2394. }
  2395. }
  2396. if (D == null && HW != null) {W = HW} else if (W == -HTMLCSS.BIGDIMEN) {W = WW}
  2397. for (i = WW = 0, m = this.data.length; i < m; i++) {if (this.data[i]) {
  2398. box = boxes[i];
  2399. if (stretch[i]) {box.bbox = this.data[i].HTMLstretchH(box,W).bbox}
  2400. if (box.bbox.w > WW) {WW = box.bbox.w}
  2401. }}
  2402. var t = HTMLCSS.TeX.rule_thickness, factor = HTMLCSS.FONTDATA.TeX_factor;
  2403. var base = boxes[this.base] || {bbox: this.HTMLzeroBBox()};
  2404. var x, y, z1, z2, z3, dw, k, delta = 0;
  2405. if (base.bbox.ic) {delta = 1.3*base.bbox.ic + .05} // adjust faked IC to be more in line with expeted results
  2406. for (i = 0, m = this.data.length; i < m; i++) {
  2407. if (this.data[i] != null) {
  2408. box = boxes[i];
  2409. z3 = HTMLCSS.TeX.big_op_spacing5 * scale;
  2410. var accent = (i != this.base && values[this.ACCENTS[i]]);
  2411. if (accent && box.bbox.w <= 1/HTMLCSS.em+.0001) { // images can get the width off by 1px
  2412. box.bbox.w = box.bbox.rw - box.bbox.lw; box.bbox.noclip = true;
  2413. if (box.bbox.lw)
  2414. {box.insertBefore(HTMLCSS.createSpace(box.parentNode,0,0,-box.bbox.lw),box.firstChild)}
  2415. HTMLCSS.createBlank(box,0,0,box.bbox.rw+.1);
  2416. }
  2417. dw = {left:0, center:(WW-box.bbox.w)/2, right:WW-box.bbox.w}[values.align];
  2418. x = dw; y = 0;
  2419. if (i == this.over) {
  2420. if (accent) {
  2421. k = Math.max(t * scale * factor,2.5/this.em); z3 = 0;
  2422. if (base.bbox.skew) {x += base.bbox.skew}
  2423. } else {
  2424. z1 = HTMLCSS.TeX.big_op_spacing1 * scale * factor;
  2425. z2 = HTMLCSS.TeX.big_op_spacing3 * scale * factor;
  2426. k = Math.max(z1,z2-Math.max(0,box.bbox.d));
  2427. }
  2428. k = Math.max(k,1.5/this.em); // force to be at least 1.5px
  2429. x += delta/2; y = base.bbox.h + box.bbox.d + k;
  2430. box.bbox.h += z3;
  2431. } else if (i == this.under) {
  2432. if (accent) {
  2433. k = 3*t * scale * factor; z3 = 0;
  2434. } else {
  2435. z1 = HTMLCSS.TeX.big_op_spacing2 * scale * factor;
  2436. z2 = HTMLCSS.TeX.big_op_spacing4 * scale * factor;
  2437. k = Math.max(z1,z2-box.bbox.h);
  2438. }
  2439. k = Math.max(k,1.5/this.em); // force to be at least 1.5px
  2440. x -= delta/2; y = -(base.bbox.d + box.bbox.h + k);
  2441. box.bbox.d += z3;
  2442. }
  2443. HTMLCSS.placeBox(box,x,y);
  2444. }
  2445. }
  2446. this.HTMLhandleSpace(span);
  2447. this.HTMLhandleColor(span);
  2448. return span;
  2449. },
  2450. HTMLstretchH: MML.mbase.HTMLstretchH,
  2451. HTMLstretchV: MML.mbase.HTMLstretchV
  2452. });
  2453. MML.msubsup.Augment({
  2454. toHTML: function (span,HW,D) {
  2455. span = this.HTMLcreateSpan(span);
  2456. var scale = this.HTMLgetScale(), mu = this.HTMLgetMu(span);
  2457. var stack = HTMLCSS.createStack(span), values, children = [];
  2458. var base = HTMLCSS.createBox(stack);
  2459. if (this.data[this.base]) {
  2460. children.push(this.data[this.base].toHTML(base));
  2461. if (D != null) {this.data[this.base].HTMLstretchV(base,HW,D)}
  2462. else if (HW != null) {this.data[this.base].HTMLstretchH(base,HW)}
  2463. } else {base.bbox = this.HTMLzeroBBox()}
  2464. var x_height = HTMLCSS.TeX.x_height * scale,
  2465. s = HTMLCSS.TeX.scriptspace * scale * .75; // FIXME: .75 can be removed when IC is right?
  2466. var sup, sub;
  2467. if (this.HTMLnotEmpty(this.data[this.sup]))
  2468. {sup = HTMLCSS.createBox(stack); children.push(this.data[this.sup].toHTML(sup))}
  2469. if (this.HTMLnotEmpty(this.data[this.sub]))
  2470. {sub = HTMLCSS.createBox(stack); children.push(this.data[this.sub].toHTML(sub))}
  2471. HTMLCSS.MeasureSpans(children);
  2472. if (sup) {sup.bbox.w += s; sup.bbox.rw = Math.max(sup.bbox.w,sup.bbox.rw)}
  2473. if (sub) {sub.bbox.w += s; sub.bbox.rw = Math.max(sub.bbox.w,sub.bbox.rw)}
  2474. HTMLCSS.placeBox(base,0,0);
  2475. var sscale;
  2476. if (sup) {
  2477. sscale = this.data[this.sup].HTMLgetScale();
  2478. } else if (sub) {
  2479. sscale = this.data[this.sub].HTMLgetScale();
  2480. } else {
  2481. sscale = this.HTMLgetScale();
  2482. }
  2483. var q = HTMLCSS.TeX.sup_drop * sscale, r = HTMLCSS.TeX.sub_drop * sscale;
  2484. var u = base.bbox.h - q, v = base.bbox.d + r, delta = 0, p;
  2485. if (base.bbox.ic) {
  2486. base.bbox.w -= base.bbox.ic; // remove IC (added by mo and mi)
  2487. delta = 1.3*base.bbox.ic + .05; // adjust faked IC to be more in line with expected results
  2488. }
  2489. if (this.data[this.base] &&
  2490. (this.data[this.base].type === "mi" || this.data[this.base].type === "mo")) {
  2491. if (this.data[this.base].data.join("").length === 1 && base.bbox.scale === 1 &&
  2492. !this.data[this.base].Get("largeop")) {u = v = 0}
  2493. }
  2494. var min = this.getValues("subscriptshift","superscriptshift");
  2495. min.subscriptshift = (min.subscriptshift === "" ? 0 : HTMLCSS.length2em(min.subscriptshift,mu));
  2496. min.superscriptshift = (min.superscriptshift === "" ? 0 : HTMLCSS.length2em(min.superscriptshift,mu));
  2497. if (!sup) {
  2498. if (sub) {
  2499. v = Math.max(v,HTMLCSS.TeX.sub1*scale,sub.bbox.h-(4/5)*x_height,min.subscriptshift);
  2500. HTMLCSS.placeBox(sub,base.bbox.w,-v,sub.bbox);
  2501. }
  2502. } else {
  2503. if (!sub) {
  2504. values = this.getValues("displaystyle","texprimestyle");
  2505. p = HTMLCSS.TeX[(values.displaystyle ? "sup1" : (values.texprimestyle ? "sup3" : "sup2"))];
  2506. u = Math.max(u,p*scale,sup.bbox.d+(1/4)*x_height,min.superscriptshift);
  2507. HTMLCSS.placeBox(sup,base.bbox.w+delta,u,sup.bbox);
  2508. } else {
  2509. v = Math.max(v,HTMLCSS.TeX.sub2*scale);
  2510. var t = HTMLCSS.TeX.rule_thickness * scale;
  2511. if ((u - sup.bbox.d) - (sub.bbox.h - v) < 3*t) {
  2512. v = 3*t - u + sup.bbox.d + sub.bbox.h;
  2513. q = (4/5)*x_height - (u - sup.bbox.d);
  2514. if (q > 0) {u += q; v -= q}
  2515. }
  2516. HTMLCSS.placeBox(sup,base.bbox.w+delta,Math.max(u,min.superscriptshift));
  2517. HTMLCSS.placeBox(sub,base.bbox.w,-Math.max(v,min.subscriptshift));
  2518. }
  2519. }
  2520. this.HTMLhandleSpace(span);
  2521. this.HTMLhandleColor(span);
  2522. return span;
  2523. },
  2524. HTMLstretchH: MML.mbase.HTMLstretchH,
  2525. HTMLstretchV: MML.mbase.HTMLstretchV
  2526. });
  2527. MML.mmultiscripts.Augment({toHTML: MML.mbase.HTMLautoload});
  2528. MML.mtable.Augment({toHTML: MML.mbase.HTMLautoload});
  2529. MML["annotation-xml"].Augment({toHTML: MML.mbase.HTMLautoload});
  2530. MML.math.Augment({
  2531. toHTML: function (span,node) {
  2532. var alttext = this.Get("alttext");
  2533. if (alttext && alttext !== "") {node.setAttribute("aria-label",alttext)}
  2534. var nobr = HTMLCSS.addElement(span,"nobr",{isMathJax: true});
  2535. span = this.HTMLcreateSpan(nobr);
  2536. var stack = HTMLCSS.createStack(span), box = HTMLCSS.createBox(stack), math;
  2537. // Move font-size from outer span to stack to avoid line separation
  2538. // problem in strict HTML mode
  2539. stack.style.fontSize = nobr.parentNode.style.fontSize; nobr.parentNode.style.fontSize = "";
  2540. if (this.data[0] != null) {
  2541. if (HTMLCSS.msieColorBug) {
  2542. if (this.background) {this.data[0].background = this.background; delete this.background}
  2543. if (this.mathbackground) {this.data[0].mathbackground = this.mathbackground; delete this.mathbackground}
  2544. }
  2545. MML.mbase.prototype.displayAlign = HUB.config.displayAlign;
  2546. MML.mbase.prototype.displayIndent = HUB.config.displayIndent;
  2547. var html = this.data[0].toHTML(box); html.bbox.exactW = false; // force remeasure just to be sure
  2548. math = HTMLCSS.Measured(html,box);
  2549. }
  2550. HTMLCSS.placeBox(box,0,0);
  2551. //
  2552. // Get width right if minimum font size is set:
  2553. // Round to nearest pixel (plus a small amount), and convert back to outer-em's.
  2554. // Add the width to the span (outside the MathJax class, so uses outer em size,
  2555. // which makes it work even when minimum font size is in effect).
  2556. //
  2557. span.style.width = HTMLCSS.Em((Math.round(math.bbox.w*this.em)+.25)/HTMLCSS.outerEm);
  2558. span.style.display = "inline-block";
  2559. //
  2560. // Adjust bbox to match outer em-size
  2561. //
  2562. var p = 1/HTMLCSS.em, f = HTMLCSS.em / HTMLCSS.outerEm; HTMLCSS.em /= f;
  2563. span.bbox.h *= f; span.bbox.d *= f; span.bbox.w *= f;
  2564. span.bbox.lw *= f; span.bbox.rw *= f;
  2565. if (math && math.bbox.width != null) {
  2566. span.style.minWidth = (math.bbox.minWidth || span.style.width);
  2567. span.style.width = stack.style.width = math.bbox.width;
  2568. box.style.width = "100%";
  2569. }
  2570. //
  2571. // Add color (if any)
  2572. //
  2573. this.HTMLhandleColor(span);
  2574. //
  2575. // Make math span be the correct height and depth
  2576. //
  2577. if (math) {HTMLCSS.createRule(span,(math.bbox.h+p)*f,(math.bbox.d+p)*f,0)}
  2578. //
  2579. // Handle indentalign and indentshift for single-line display equations
  2580. //
  2581. if (!this.isMultiline && this.Get("display") === "block" && span.bbox.width == null) {
  2582. var values = this.getValues("indentalignfirst","indentshiftfirst","indentalign","indentshift");
  2583. if (values.indentalignfirst !== MML.INDENTALIGN.INDENTALIGN) {values.indentalign = values.indentalignfirst}
  2584. if (values.indentalign === MML.INDENTALIGN.AUTO) {values.indentalign = this.displayAlign}
  2585. node.style.textAlign = values.indentalign;
  2586. if (values.indentshiftfirst !== MML.INDENTSHIFT.INDENTSHIFT) {values.indentshift = values.indentshiftfirst}
  2587. if (values.indentshift === "auto") {values.indentshift = this.displayIndent}
  2588. if (values.indentshift && values.indentalign !== MML.INDENTALIGN.CENTER) {
  2589. span.style[{left:"marginLeft",right:"marginRight"}[values.indentalign]] =
  2590. HTMLCSS.Em(HTMLCSS.length2em(values.indentshift));
  2591. }
  2592. }
  2593. return span;
  2594. },
  2595. HTMLspanElement: MML.mbase.prototype.HTMLspanElement
  2596. });
  2597. MML.TeXAtom.Augment({
  2598. toHTML: function (span) {
  2599. span = this.HTMLcreateSpan(span);
  2600. if (this.data[0] != null) {
  2601. if (this.texClass === MML.TEXCLASS.VCENTER) {
  2602. var stack = HTMLCSS.createStack(span);
  2603. var box = HTMLCSS.createBox(stack);
  2604. HTMLCSS.Measured(this.data[0].toHTML(box),box);
  2605. // FIXME: should the axis height be scaled?
  2606. HTMLCSS.placeBox(box,0,HTMLCSS.TeX.axis_height-(box.bbox.h+box.bbox.d)/2+box.bbox.d);
  2607. } else {
  2608. span.bbox = this.data[0].toHTML(span).bbox;
  2609. }
  2610. }
  2611. this.HTMLhandleSpace(span);
  2612. this.HTMLhandleColor(span);
  2613. return span;
  2614. }
  2615. });
  2616. //
  2617. // Loading isn't complete until the element jax is modified,
  2618. // but can't call loadComplete within the callback for "mml Jax Ready"
  2619. // (it would call HTMLCSS's Require routine, asking for the mml jax again)
  2620. // so wait until after the mml jax has finished processing.
  2621. //
  2622. // We also need to wait for the onload handler to run, since the loadComplete
  2623. // will call Config and Startup, which need to modify the body.
  2624. //
  2625. MathJax.Hub.Register.StartupHook("onLoad",function () {
  2626. setTimeout(MathJax.Callback(["loadComplete",HTMLCSS,"jax.js"]),0);
  2627. });
  2628. });
  2629. HUB.Register.StartupHook("End Config",function () {
  2630. //
  2631. // Handle browser-specific setup
  2632. //
  2633. HUB.Browser.Select({
  2634. MSIE: function (browser) {
  2635. var mode = (document.documentMode || 0);
  2636. var isIE7 = browser.versionAtLeast("7.0");
  2637. var isIE8 = browser.versionAtLeast("8.0") && mode > 7;
  2638. var quirks = (document.compatMode === "BackCompat");
  2639. if (mode < 9) {
  2640. // IE doesn't do mouse events on trasparent objects,
  2641. // so give a background color, but opacity makes it transparent
  2642. HTMLCSS.config.styles[".MathJax .MathJax_HitBox"]["background-color"] = "white";
  2643. HTMLCSS.config.styles[".MathJax .MathJax_HitBox"].opacity = 0
  2644. HTMLCSS.config.styles[".MathJax .MathJax_HitBox"].filter = "alpha(opacity=0)";
  2645. }
  2646. // FIXME: work out tests for these?
  2647. HTMLCSS.Augment({
  2648. PaddingWidthBug: true,
  2649. msieAccentBug: true,
  2650. msieColorBug: true,
  2651. msieColorPositionBug: true, // needs position:relative to put color behind text
  2652. msieRelativeWidthBug: quirks,
  2653. msieDisappearingBug: (mode >= 8), // inline math disappears
  2654. msieMarginScaleBug: (mode < 8), // relative margins are not scaled properly by font-size
  2655. msiePaddingWidthBug: true,
  2656. msieBorderWidthBug: quirks,
  2657. msieFrameSizeBug: (mode <= 8), // crashes if size of box isn't big enough for border
  2658. msieInlineBlockAlignBug: (!isIE8 || quirks),
  2659. msiePlaceBoxBug: (isIE8 && !quirks),
  2660. msieClipRectBug: !isIE8,
  2661. msieNegativeSpaceBug: quirks,
  2662. cloneNodeBug: (isIE8 && browser.version === "8.0"),
  2663. initialSkipBug: (mode < 8), // confused by initial left-margin values
  2664. msieNegativeBBoxBug: (mode >= 8), // negative bboxes have positive widths
  2665. msieIE6: !isIE7,
  2666. msieItalicWidthBug: true,
  2667. FontFaceBug: true,
  2668. msieFontCSSBug: browser.isIE9,
  2669. allowWebFonts: (mode >= 9 ? "woff" : "eot")
  2670. });
  2671. },
  2672. Firefox: function (browser) {
  2673. var webFonts = false;
  2674. if (browser.versionAtLeast("3.5")) {
  2675. var root = String(document.location).replace(/[^\/]*$/,"");
  2676. if (document.location.protocol !== "file:" || HUB.config.root.match(/^https?:\/\//) ||
  2677. (HUB.config.root+"/").substr(0,root.length) === root) {webFonts = "otf"}
  2678. }
  2679. HTMLCSS.Augment({
  2680. ffVerticalAlignBug: true,
  2681. AccentBug: true,
  2682. allowWebFonts: webFonts
  2683. });
  2684. },
  2685. Safari: function (browser) {
  2686. var v3p0 = browser.versionAtLeast("3.0");
  2687. var v3p1 = browser.versionAtLeast("3.1");
  2688. var trueSafari = navigator.appVersion.match(/ Safari\/\d/) &&
  2689. navigator.appVersion.match(/ Version\/\d/) &&
  2690. navigator.vendor.match(/Apple/);
  2691. var android = (navigator.appVersion.match(/ Android (\d+)\.(\d+)/));
  2692. var forceImages = (v3p1 && browser.isMobile && (
  2693. (navigator.platform.match(/iPad|iPod|iPhone/) && !browser.versionAtLeast("5.0")) ||
  2694. (android != null && (android[1] < 2 || (android[1] == 2 && android[2] < 2)))
  2695. ));
  2696. HTMLCSS.Augment({
  2697. config: {
  2698. styles: {
  2699. ".MathJax img, .MathJax nobr, .MathJax a": {
  2700. // "none" seems to work like "0px" when width is initially 0
  2701. "max-width": "5000em", "max-height": "5000em"
  2702. }
  2703. }
  2704. },
  2705. rfuzz: .011,
  2706. AccentBug: true,
  2707. AdjustSurd: true,
  2708. negativeBBoxes: true,
  2709. safariNegativeSpaceBug: true,
  2710. safariVerticalAlignBug: !v3p1,
  2711. safariTextNodeBug: !v3p0,
  2712. forceReflow: true,
  2713. allowWebFonts: (v3p1 && !forceImages ? "otf" : false)
  2714. });
  2715. if (trueSafari) {
  2716. HTMLCSS.Augment({
  2717. webFontDefault: (browser.isMobile ? "sans-serif" : "serif")
  2718. });
  2719. }
  2720. if (browser.isPC) {
  2721. HTMLCSS.Augment({
  2722. adjustAvailableFonts: HTMLCSS.removeSTIXfonts, // can't access plane1
  2723. checkWebFontsTwice: true // bug in Safari/Win that doesn't update font test div properly
  2724. });
  2725. }
  2726. if (forceImages) {
  2727. // Force image mode for iOS prior to 4.2 and Droid prior to 2.2
  2728. var config = HUB.config["HTML-CSS"];
  2729. if (config) {config.availableFonts = []; config.preferredFont = null}
  2730. else {HUB.config["HTML-CSS"] = {availableFonts: [], preferredFont: null}}
  2731. }
  2732. },
  2733. Chrome: function (browser) {
  2734. HTMLCSS.Augment({
  2735. Em: HTMLCSS.EmRounded, // vertical alignment needs help (since around v20)
  2736. cloneNodeBug: true, // Chrome gets heights wrong with the cloned ones
  2737. rfuzz: .011,
  2738. AccentBug: true,
  2739. AdjustSurd: true,
  2740. negativeBBoxes: true,
  2741. safariNegativeSpaceBug: true,
  2742. safariWebFontSerif: [""],
  2743. forceReflow: true,
  2744. allowWebFonts: (browser.versionAtLeast("4.0") ? "otf" : "svg")
  2745. });
  2746. },
  2747. Opera: function (browser) {
  2748. browser.isMini = (navigator.appVersion.match("Opera Mini") != null);
  2749. HTMLCSS.config.styles[".MathJax .merror"]["vertical-align"] = null;
  2750. HTMLCSS.config.styles[".MathJax span"]["z-index"] = 0;
  2751. HTMLCSS.Augment({
  2752. operaHeightBug: true,
  2753. operaVerticalAlignBug: true,
  2754. operaFontSizeBug: browser.versionAtLeast("10.61"),
  2755. initialSkipBug: true,
  2756. FontFaceBug: true,
  2757. PaddingWidthBug: true,
  2758. allowWebFonts: (browser.versionAtLeast("10.0") && !browser.isMini ? "otf" : false),
  2759. adjustAvailableFonts: HTMLCSS.removeSTIXfonts
  2760. });
  2761. },
  2762. Konqueror: function (browser) {
  2763. HTMLCSS.Augment({
  2764. konquerorVerticalAlignBug: true
  2765. });
  2766. }
  2767. });
  2768. });
  2769. MathJax.Hub.Register.StartupHook("End Cookie", function () {
  2770. if (HUB.config.menuSettings.zoom !== "None")
  2771. {AJAX.Require("[MathJax]/extensions/MathZoom.js")}
  2772. });
  2773. })(MathJax.Ajax, MathJax.Hub, MathJax.OutputJax["HTML-CSS"]);