jax.js 136 KB

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