jax.js 138 KB

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