jax.js 133 KB

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