MathJax.js 124 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.js
  6. *
  7. * The main support code for the MathJax Hub, including the
  8. * Ajax, Callback, Messaging, and Object-Oriented Programming
  9. * libraries, as well as the base Jax classes, and startup
  10. * processing code.
  11. *
  12. * ---------------------------------------------------------------------
  13. *
  14. * Copyright (c) 2009-2017 The MathJax Consortium
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the "License");
  17. * you may not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * http://www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an "AS IS" BASIS,
  24. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. //
  29. // Check if browser can support MathJax (no one fails this nowadays)
  30. //
  31. if (document.getElementById && document.childNodes && document.createElement) {
  32. //
  33. // Skip if MathJax is already loaded
  34. //
  35. if (!(window.MathJax && MathJax.Hub)) {
  36. //
  37. // Get author configuration from MathJax variable, if any
  38. //
  39. if (window.MathJax) {window.MathJax = {AuthorConfig: window.MathJax}}
  40. else {window.MathJax = {}}
  41. // MathJax.isPacked = true; // This line is uncommented by the packer.
  42. MathJax.version = "2.7.2";
  43. MathJax.fileversion = "2.7.2";
  44. MathJax.cdnVersion = "2.7.2"; // specifies a revision to break caching
  45. MathJax.cdnFileVersions = {}; // can be used to specify revisions for individual files
  46. /**********************************************************/
  47. (function (BASENAME) {
  48. var BASE = window[BASENAME];
  49. if (!BASE) {BASE = window[BASENAME] = {}}
  50. var PROTO = []; // a static object used to indicate when a prototype is being created
  51. var OBJECT = function (def) {
  52. var obj = def.constructor; if (!obj) {obj = function () {}}
  53. for (var id in def) {if (id !== 'constructor' && def.hasOwnProperty(id)) {obj[id] = def[id]}}
  54. return obj;
  55. };
  56. var CONSTRUCTOR = function () {
  57. return function () {return arguments.callee.Init.call(this,arguments)};
  58. };
  59. BASE.Object = OBJECT({
  60. constructor: CONSTRUCTOR(),
  61. Subclass: function (def,classdef) {
  62. var obj = CONSTRUCTOR();
  63. obj.SUPER = this; obj.Init = this.Init;
  64. obj.Subclass = this.Subclass; obj.Augment = this.Augment;
  65. obj.protoFunction = this.protoFunction;
  66. obj.can = this.can; obj.has = this.has; obj.isa = this.isa;
  67. obj.prototype = new this(PROTO);
  68. obj.prototype.constructor = obj; // the real constructor
  69. obj.Augment(def,classdef);
  70. return obj;
  71. },
  72. Init: function (args) {
  73. var obj = this;
  74. if (args.length === 1 && args[0] === PROTO) {return obj}
  75. if (!(obj instanceof args.callee)) {obj = new args.callee(PROTO)}
  76. return obj.Init.apply(obj,args) || obj;
  77. },
  78. Augment: function (def,classdef) {
  79. var id;
  80. if (def != null) {
  81. for (id in def) {if (def.hasOwnProperty(id)) {this.protoFunction(id,def[id])}}
  82. // MSIE doesn't list toString even if it is not native so handle it separately
  83. if (def.toString !== this.prototype.toString && def.toString !== {}.toString)
  84. {this.protoFunction('toString',def.toString)}
  85. }
  86. if (classdef != null) {
  87. for (id in classdef) {if (classdef.hasOwnProperty(id)) {this[id] = classdef[id]}}
  88. }
  89. return this;
  90. },
  91. protoFunction: function (id,def) {
  92. this.prototype[id] = def;
  93. if (typeof def === "function") {def.SUPER = this.SUPER.prototype}
  94. },
  95. prototype: {
  96. Init: function () {},
  97. SUPER: function (fn) {return fn.callee.SUPER},
  98. can: function (method) {return typeof(this[method]) === "function"},
  99. has: function (property) {return typeof(this[property]) !== "undefined"},
  100. isa: function (obj) {return (obj instanceof Object) && (this instanceof obj)}
  101. },
  102. can: function (method) {return this.prototype.can.call(this,method)},
  103. has: function (property) {return this.prototype.has.call(this,property)},
  104. isa: function (obj) {
  105. var constructor = this;
  106. while (constructor) {
  107. if (constructor === obj) {return true} else {constructor = constructor.SUPER}
  108. }
  109. return false;
  110. },
  111. SimpleSUPER: OBJECT({
  112. constructor: function (def) {return this.SimpleSUPER.define(def)},
  113. define: function (src) {
  114. var dst = {};
  115. if (src != null) {
  116. for (var id in src) {if (src.hasOwnProperty(id)) {dst[id] = this.wrap(id,src[id])}}
  117. // MSIE doesn't list toString even if it is not native so handle it separately
  118. if (src.toString !== this.prototype.toString && src.toString !== {}.toString)
  119. {dst.toString = this.wrap('toString',src.toString)}
  120. }
  121. return dst;
  122. },
  123. wrap: function (id,f) {
  124. if (typeof(f) !== 'function' || !f.toString().match(/\.\s*SUPER\s*\(/)) {return f}
  125. var fn = function () {
  126. this.SUPER = fn.SUPER[id];
  127. try {var result = f.apply(this,arguments)} catch (err) {delete this.SUPER; throw err}
  128. delete this.SUPER;
  129. return result;
  130. }
  131. fn.toString = function () {return f.toString.apply(f,arguments)}
  132. return fn;
  133. }
  134. })
  135. });
  136. BASE.Object.isArray = Array.isArray || function (obj) {
  137. return Object.prototype.toString.call(obj) === "[object Array]";
  138. };
  139. BASE.Object.Array = Array;
  140. })("MathJax");
  141. /**********************************************************/
  142. /*
  143. * Create a callback function from various forms of data:
  144. *
  145. * MathJax.Callback(fn) -- callback to a function
  146. *
  147. * MathJax.Callback([fn]) -- callback to function
  148. * MathJax.Callback([fn,data...])
  149. * -- callback to function with given data as arguments
  150. * MathJax.Callback([object,fn])
  151. * -- call fn with object as "this"
  152. * MathJax.Callback([object,fn,data...])
  153. * -- call fn with object as "this" and data as arguments
  154. * MathJax.Callback(["method",object])
  155. * -- call method of object wth object as "this"
  156. * MathJax.Callback(["method",object,data...])
  157. * -- as above, but with data as arguments to method
  158. *
  159. * MathJax.Callback({hook: fn, data: [...], object: this})
  160. * -- give function, data, and object to act as "this" explicitly
  161. *
  162. * MathJax.Callback("code") -- callback that compiles and executes a string
  163. *
  164. * MathJax.Callback([...],i)
  165. * -- use slice of array starting at i and interpret
  166. * result as above. (Used for passing "arguments" array
  167. * and trimming initial arguments, if any.)
  168. */
  169. /*
  170. * MathJax.Callback.After([...],cb1,cb2,...)
  171. * -- make a callback that isn't called until all the other
  172. * ones are called first. I.e., wait for a union of
  173. * callbacks to occur before making the given callback.
  174. */
  175. /*
  176. * MathJax.Callback.Queue([callback,...])
  177. * -- make a synchronized queue of commands that process
  178. * sequentially, waiting for those that return uncalled
  179. * callbacks.
  180. */
  181. /*
  182. * MathJax.Callback.Signal(name)
  183. * -- finds or creates a names signal, to which listeners
  184. * can be attached and are signaled by messages posted
  185. * to the signal. Responses can be asynchronous.
  186. */
  187. (function (BASENAME) {
  188. var BASE = window[BASENAME];
  189. if (!BASE) {BASE = window[BASENAME] = {}}
  190. var isArray = BASE.Object.isArray;
  191. //
  192. // Create a callback from an associative array
  193. //
  194. var CALLBACK = function (data) {
  195. var cb = function () {return arguments.callee.execute.apply(arguments.callee,arguments)};
  196. for (var id in CALLBACK.prototype) {
  197. if (CALLBACK.prototype.hasOwnProperty(id)) {
  198. if (typeof(data[id]) !== 'undefined') {cb[id] = data[id]}
  199. else {cb[id] = CALLBACK.prototype[id]}
  200. }
  201. }
  202. cb.toString = CALLBACK.prototype.toString;
  203. return cb;
  204. };
  205. CALLBACK.prototype = {
  206. isCallback: true,
  207. hook: function () {},
  208. data: [],
  209. object: window,
  210. execute: function () {
  211. if (!this.called || this.autoReset) {
  212. this.called = !this.autoReset;
  213. return this.hook.apply(this.object,this.data.concat([].slice.call(arguments,0)));
  214. }
  215. },
  216. reset: function () {delete this.called},
  217. toString: function () {return this.hook.toString.apply(this.hook,arguments)}
  218. };
  219. var ISCALLBACK = function (f) {
  220. return (typeof(f) === "function" && f.isCallback);
  221. }
  222. //
  223. // Evaluate a string in global context
  224. //
  225. var EVAL = function (code) {return eval.call(window,code)}
  226. var TESTEVAL = function () {
  227. EVAL("var __TeSt_VaR__ = 1"); // check if it works in global context
  228. if (window.__TeSt_VaR__) {
  229. try { delete window.__TeSt_VaR__; } // NOTE IE9 throws when in IE7 mode
  230. catch (error) { window.__TeSt_VaR__ = null; }
  231. } else {
  232. if (window.execScript) {
  233. // IE
  234. EVAL = function (code) {
  235. BASE.__code = code;
  236. code = "try {"+BASENAME+".__result = eval("+BASENAME+".__code)} catch(err) {"+BASENAME+".__result = err}";
  237. window.execScript(code);
  238. var result = BASE.__result; delete BASE.__result; delete BASE.__code;
  239. if (result instanceof Error) {throw result}
  240. return result;
  241. }
  242. } else {
  243. // Safari2
  244. EVAL = function (code) {
  245. BASE.__code = code;
  246. code = "try {"+BASENAME+".__result = eval("+BASENAME+".__code)} catch(err) {"+BASENAME+".__result = err}";
  247. var head = (document.getElementsByTagName("head"))[0]; if (!head) {head = document.body}
  248. var script = document.createElement("script");
  249. script.appendChild(document.createTextNode(code));
  250. head.appendChild(script); head.removeChild(script);
  251. var result = BASE.__result; delete BASE.__result; delete BASE.__code;
  252. if (result instanceof Error) {throw result}
  253. return result;
  254. }
  255. }
  256. }
  257. TESTEVAL = null;
  258. };
  259. //
  260. // Create a callback from various types of data
  261. //
  262. var USING = function (args,i) {
  263. if (arguments.length > 1) {
  264. if (arguments.length === 2 && !(typeof arguments[0] === 'function') &&
  265. arguments[0] instanceof Object && typeof arguments[1] === 'number')
  266. {args = [].slice.call(args,i)}
  267. else {args = [].slice.call(arguments,0)}
  268. }
  269. if (isArray(args) && args.length === 1 && typeof(args[0]) === 'function') {args = args[0]}
  270. if (typeof args === 'function') {
  271. if (args.execute === CALLBACK.prototype.execute) {return args}
  272. return CALLBACK({hook: args});
  273. } else if (isArray(args)) {
  274. if (typeof(args[0]) === 'string' && args[1] instanceof Object &&
  275. typeof args[1][args[0]] === 'function') {
  276. return CALLBACK({hook: args[1][args[0]], object: args[1], data: args.slice(2)});
  277. } else if (typeof args[0] === 'function') {
  278. return CALLBACK({hook: args[0], data: args.slice(1)});
  279. } else if (typeof args[1] === 'function') {
  280. return CALLBACK({hook: args[1], object: args[0], data: args.slice(2)});
  281. }
  282. } else if (typeof(args) === 'string') {
  283. if (TESTEVAL) TESTEVAL();
  284. return CALLBACK({hook: EVAL, data: [args]});
  285. } else if (args instanceof Object) {
  286. return CALLBACK(args);
  287. } else if (typeof(args) === 'undefined') {
  288. return CALLBACK({});
  289. }
  290. throw Error("Can't make callback from given data");
  291. };
  292. //
  293. // Wait for a given time to elapse and then perform the callback
  294. //
  295. var DELAY = function (time,callback) {
  296. callback = USING(callback);
  297. callback.timeout = setTimeout(callback,time);
  298. return callback;
  299. };
  300. //
  301. // Callback used by AFTER, QUEUE, and SIGNAL to check if calls have completed
  302. //
  303. var WAITFOR = function (callback,signal) {
  304. callback = USING(callback);
  305. if (!callback.called) {WAITSIGNAL(callback,signal); signal.pending++}
  306. };
  307. var WAITEXECUTE = function () {
  308. var signals = this.signal; delete this.signal;
  309. this.execute = this.oldExecute; delete this.oldExecute;
  310. var result = this.execute.apply(this,arguments);
  311. if (ISCALLBACK(result) && !result.called) {WAITSIGNAL(result,signals)} else {
  312. for (var i = 0, m = signals.length; i < m; i++) {
  313. signals[i].pending--;
  314. if (signals[i].pending <= 0) {signals[i].call()}
  315. }
  316. }
  317. };
  318. var WAITSIGNAL = function (callback,signals) {
  319. if (!isArray(signals)) {signals = [signals]}
  320. if (!callback.signal) {
  321. callback.oldExecute = callback.execute;
  322. callback.execute = WAITEXECUTE;
  323. callback.signal = signals;
  324. } else if (signals.length === 1) {callback.signal.push(signals[0])}
  325. else {callback.signal = callback.signal.concat(signals)}
  326. };
  327. //
  328. // Create a callback that is called when a collection of other callbacks have
  329. // all been executed. If the callback gets called immediately (i.e., the
  330. // others are all already called), check if it returns another callback
  331. // and return that instead.
  332. //
  333. var AFTER = function (callback) {
  334. callback = USING(callback);
  335. callback.pending = 0;
  336. for (var i = 1, m = arguments.length; i < m; i++)
  337. {if (arguments[i]) {WAITFOR(arguments[i],callback)}}
  338. if (callback.pending === 0) {
  339. var result = callback();
  340. if (ISCALLBACK(result)) {callback = result}
  341. }
  342. return callback;
  343. };
  344. //
  345. // An array of prioritized hooks that are executed sequentially
  346. // with a given set of data.
  347. //
  348. var HOOKS = MathJax.Object.Subclass({
  349. //
  350. // Initialize the array and the auto-reset status
  351. //
  352. Init: function (reset) {
  353. this.hooks = [];
  354. this.remove = []; // used when hooks are removed during execution of list
  355. this.reset = reset;
  356. this.running = false;
  357. },
  358. //
  359. // Add a callback to the list, in priority order (default priority is 10)
  360. //
  361. Add: function (hook,priority) {
  362. if (priority == null) {priority = 10}
  363. if (!ISCALLBACK(hook)) {hook = USING(hook)}
  364. hook.priority = priority;
  365. var i = this.hooks.length;
  366. while (i > 0 && priority < this.hooks[i-1].priority) {i--}
  367. this.hooks.splice(i,0,hook);
  368. return hook;
  369. },
  370. Remove: function (hook) {
  371. for (var i = 0, m = this.hooks.length; i < m; i++) {
  372. if (this.hooks[i] === hook) {
  373. if (this.running) {this.remove.push(i)}
  374. else {this.hooks.splice(i,1)}
  375. return;
  376. }
  377. }
  378. },
  379. //
  380. // Execute the list of callbacks, resetting them if requested.
  381. // If any return callbacks, return a callback that will be
  382. // executed when they all have completed.
  383. // Remove any hooks that requested being removed during processing.
  384. //
  385. Execute: function () {
  386. var callbacks = [{}];
  387. this.running = true;
  388. for (var i = 0, m = this.hooks.length; i < m; i++) {
  389. if (this.reset) {this.hooks[i].reset()}
  390. var result = this.hooks[i].apply(window,arguments);
  391. if (ISCALLBACK(result) && !result.called) {callbacks.push(result)}
  392. }
  393. this.running = false;
  394. if (this.remove.length) {this.RemovePending()}
  395. if (callbacks.length === 1) {return null}
  396. if (callbacks.length === 2) {return callbacks[1]}
  397. return AFTER.apply({},callbacks);
  398. },
  399. //
  400. // Remove hooks that asked to be removed during execution of list
  401. //
  402. RemovePending: function () {
  403. this.remove = this.remove.sort();
  404. for (var i = this.remove.length-1; i >= 0; i--) {this.hooks.splice(i,1)}
  405. this.remove = [];
  406. }
  407. });
  408. //
  409. // Run an array of callbacks passing them the given data.
  410. // (Legacy function, since this has been replaced by the HOOKS object).
  411. //
  412. var EXECUTEHOOKS = function (hooks,data,reset) {
  413. if (!hooks) {return null}
  414. if (!isArray(hooks)) {hooks = [hooks]}
  415. if (!isArray(data)) {data = (data == null ? [] : [data])}
  416. var handler = HOOKS(reset);
  417. for (var i = 0, m = hooks.length; i < m; i++) {handler.Add(hooks[i])}
  418. return handler.Execute.apply(handler,data);
  419. };
  420. //
  421. // Command queue that performs commands in order, waiting when
  422. // necessary for commands to complete asynchronousely
  423. //
  424. var QUEUE = BASE.Object.Subclass({
  425. //
  426. // Create the queue and push any commands that are specified
  427. //
  428. Init: function () {
  429. this.pending = this.running = 0;
  430. this.queue = [];
  431. this.Push.apply(this,arguments);
  432. },
  433. //
  434. // Add commands to the queue and run them. Adding a callback object
  435. // (rather than a callback specification) queues a wait for that callback.
  436. // Return the final callback for synchronization purposes.
  437. //
  438. Push: function () {
  439. var callback;
  440. for (var i = 0, m = arguments.length; i < m; i++) {
  441. callback = USING(arguments[i]);
  442. if (callback === arguments[i] && !callback.called)
  443. {callback = USING(["wait",this,callback])}
  444. this.queue.push(callback);
  445. }
  446. if (!this.running && !this.pending) {this.Process()}
  447. return callback;
  448. },
  449. //
  450. // Process the command queue if we aren't waiting on another command
  451. //
  452. Process: function (queue) {
  453. while (!this.running && !this.pending && this.queue.length) {
  454. var callback = this.queue[0];
  455. queue = this.queue.slice(1); this.queue = [];
  456. this.Suspend(); var result = callback(); this.Resume();
  457. if (queue.length) {this.queue = queue.concat(this.queue)}
  458. if (ISCALLBACK(result) && !result.called) {WAITFOR(result,this)}
  459. }
  460. },
  461. //
  462. // Suspend/Resume command processing on this queue
  463. //
  464. Suspend: function () {this.running++},
  465. Resume: function () {if (this.running) {this.running--}},
  466. //
  467. // Used by WAITFOR to restart the queue when an action completes
  468. //
  469. call: function () {this.Process.apply(this,arguments)},
  470. wait: function (callback) {return callback}
  471. });
  472. //
  473. // Create a named signal that listeners can attach to, to be signaled by
  474. // postings made to the signal. Posts are queued if they occur while one
  475. // is already in process.
  476. //
  477. var SIGNAL = QUEUE.Subclass({
  478. Init: function (name) {
  479. QUEUE.prototype.Init.call(this);
  480. this.name = name;
  481. this.posted = []; // the messages posted so far
  482. this.listeners = HOOKS(true); // those with interest in this signal
  483. this.posting = false;
  484. this.callback = null;
  485. },
  486. //
  487. // Post a message to the signal listeners, with callback for when complete
  488. //
  489. Post: function (message,callback,forget) {
  490. callback = USING(callback);
  491. if (this.posting || this.pending) {
  492. this.Push(["Post",this,message,callback,forget]);
  493. } else {
  494. this.callback = callback; callback.reset();
  495. if (!forget) {this.posted.push(message)}
  496. this.Suspend(); this.posting = true;
  497. var result = this.listeners.Execute(message);
  498. if (ISCALLBACK(result) && !result.called) {WAITFOR(result,this)}
  499. this.Resume(); this.posting = false;
  500. if (!this.pending) {this.call()}
  501. }
  502. return callback;
  503. },
  504. //
  505. // Clear the post history (so new listeners won't get old messages)
  506. //
  507. Clear: function (callback) {
  508. callback = USING(callback);
  509. if (this.posting || this.pending) {
  510. callback = this.Push(["Clear",this,callback]);
  511. } else {
  512. this.posted = [];
  513. callback();
  514. }
  515. return callback;
  516. },
  517. //
  518. // Call the callback (all replies are in) and process the command queue
  519. //
  520. call: function () {this.callback(this); this.Process()},
  521. //
  522. // A listener calls this to register interest in the signal (so it will be called
  523. // when posts occur). If ignorePast is true, it will not be sent the post history.
  524. //
  525. Interest: function (callback,ignorePast,priority) {
  526. callback = USING(callback);
  527. this.listeners.Add(callback,priority);
  528. if (!ignorePast) {
  529. for (var i = 0, m = this.posted.length; i < m; i++) {
  530. callback.reset();
  531. var result = callback(this.posted[i]);
  532. if (ISCALLBACK(result) && i === this.posted.length-1) {WAITFOR(result,this)}
  533. }
  534. }
  535. return callback;
  536. },
  537. //
  538. // A listener calls this to remove itself from a signal
  539. //
  540. NoInterest: function (callback) {
  541. this.listeners.Remove(callback);
  542. },
  543. //
  544. // Hook a callback to a particular message on this signal
  545. //
  546. MessageHook: function (msg,callback,priority) {
  547. callback = USING(callback);
  548. if (!this.hooks) {this.hooks = {}; this.Interest(["ExecuteHooks",this])}
  549. if (!this.hooks[msg]) {this.hooks[msg] = HOOKS(true)}
  550. this.hooks[msg].Add(callback,priority);
  551. for (var i = 0, m = this.posted.length; i < m; i++)
  552. {if (this.posted[i] == msg) {callback.reset(); callback(this.posted[i])}}
  553. callback.msg = msg; // keep track so we can remove it
  554. return callback;
  555. },
  556. //
  557. // Execute the message hooks for the given message
  558. //
  559. ExecuteHooks: function (msg) {
  560. var type = (isArray(msg) ? msg[0] : msg);
  561. if (!this.hooks[type]) {return null}
  562. return this.hooks[type].Execute(msg);
  563. },
  564. //
  565. // Remove a hook safely
  566. //
  567. RemoveHook: function (hook) {
  568. this.hooks[hook.msg].Remove(hook);
  569. }
  570. },{
  571. signals: {}, // the named signals
  572. find: function (name) {
  573. if (!SIGNAL.signals[name]) {SIGNAL.signals[name] = new SIGNAL(name)}
  574. return SIGNAL.signals[name];
  575. }
  576. });
  577. //
  578. // The main entry-points
  579. //
  580. BASE.Callback = BASE.CallBack = USING;
  581. BASE.Callback.Delay = DELAY;
  582. BASE.Callback.After = AFTER;
  583. BASE.Callback.Queue = QUEUE;
  584. BASE.Callback.Signal = SIGNAL.find;
  585. BASE.Callback.Hooks = HOOKS;
  586. BASE.Callback.ExecuteHooks = EXECUTEHOOKS;
  587. })("MathJax");
  588. /**********************************************************/
  589. (function (BASENAME) {
  590. var BASE = window[BASENAME];
  591. if (!BASE) {BASE = window[BASENAME] = {}}
  592. var isSafari2 = (navigator.vendor === "Apple Computer, Inc." &&
  593. typeof navigator.vendorSub === "undefined");
  594. var sheets = 0; // used by Safari2
  595. //
  596. // Update sheets count and look up the head object
  597. //
  598. var HEAD = function (head) {
  599. if (document.styleSheets && document.styleSheets.length > sheets)
  600. {sheets = document.styleSheets.length}
  601. if (!head) {
  602. head = document.head || ((document.getElementsByTagName("head"))[0]);
  603. if (!head) {head = document.body}
  604. }
  605. return head;
  606. };
  607. //
  608. // Remove scripts that are completed so they don't clutter up the HEAD.
  609. // This runs via setTimeout since IE7 can't remove the script while it is running.
  610. //
  611. var SCRIPTS = []; // stores scripts to be removed after a delay
  612. var REMOVESCRIPTS = function () {
  613. for (var i = 0, m = SCRIPTS.length; i < m; i++) {BASE.Ajax.head.removeChild(SCRIPTS[i])}
  614. SCRIPTS = [];
  615. };
  616. var PATH = {};
  617. PATH[BASENAME] = ""; // empty path gets the root URL
  618. PATH.a11y = '[MathJax]/extensions/a11y'; // a11y extensions
  619. PATH.Contrib = "https://cdn.mathjax.org/mathjax/contrib"; // the third-party extensions
  620. BASE.Ajax = {
  621. loaded: {}, // files already loaded
  622. loading: {}, // files currently in process of loading
  623. loadHooks: {}, // hooks to call when files are loaded
  624. timeout: 15*1000, // timeout for loading of files (15 seconds)
  625. styleDelay: 1, // delay to use before styles are available
  626. config: {
  627. root: "", // URL of root directory to load from
  628. path: PATH // paths to named URL's (e.g., [MathJax]/...)
  629. },
  630. params: {}, // filled in from MathJax.js?...
  631. STATUS: {
  632. OK: 1, // file is loading or did load OK
  633. ERROR: -1 // file timed out during load
  634. },
  635. //
  636. // Return a complete URL to a file (replacing any root names)
  637. //
  638. fileURL: function (file) {
  639. var match;
  640. while ((match = file.match(/^\[([-._a-z0-9]+)\]/i)) && PATH.hasOwnProperty(match[1])) {
  641. file = (PATH[match[1]]||this.config.root) + file.substr(match[1].length+2);
  642. }
  643. return file;
  644. },
  645. //
  646. // Replace root names if URL includes one
  647. //
  648. fileName: function (url) {
  649. var root = this.config.root;
  650. if (url.substr(0,root.length) === root) {url = "["+BASENAME+"]"+url.substr(root.length)}
  651. do {
  652. var recheck = false;
  653. for (var id in PATH) {if (PATH.hasOwnProperty(id) && PATH[id]) {
  654. if (url.substr(0,PATH[id].length) === PATH[id]) {
  655. url = "["+id+"]"+url.substr(PATH[id].length);
  656. recheck = true;
  657. break;
  658. }
  659. }}
  660. } while (recheck);
  661. return url;
  662. },
  663. //
  664. // Cache-breaking revision number for file
  665. //
  666. fileRev: function (file) {
  667. var V = BASE.cdnFileVersions[file] || BASE.cdnVersion || '';
  668. if (V) {V = "?V="+V}
  669. return V;
  670. },
  671. urlRev: function (file) {return this.fileURL(file)+this.fileRev(file)},
  672. //
  673. // Load a file if it hasn't been already.
  674. // Make sure the file URL is "safe"?
  675. //
  676. Require: function (file,callback) {
  677. callback = BASE.Callback(callback); var type;
  678. if (file instanceof Object) {
  679. for (var i in file)
  680. {if (file.hasOwnProperty(i)) {type = i.toUpperCase(); file = file[i]}}
  681. } else {type = file.split(/\./).pop().toUpperCase()}
  682. if (this.params.noContrib && file.substr(0,9) === "[Contrib]") {
  683. callback(this.STATUS.ERROR);
  684. } else {
  685. file = this.fileURL(file);
  686. // FIXME: check that URL is OK
  687. if (this.loaded[file]) {
  688. callback(this.loaded[file]);
  689. } else {
  690. var FILE = {}; FILE[type] = file;
  691. this.Load(FILE,callback);
  692. }
  693. }
  694. return callback;
  695. },
  696. //
  697. // Load a file regardless of where it is and whether it has
  698. // already been loaded.
  699. //
  700. Load: function (file,callback) {
  701. callback = BASE.Callback(callback); var type;
  702. if (file instanceof Object) {
  703. for (var i in file)
  704. {if (file.hasOwnProperty(i)) {type = i.toUpperCase(); file = file[i]}}
  705. } else {type = file.split(/\./).pop().toUpperCase()}
  706. file = this.fileURL(file);
  707. if (this.loading[file]) {
  708. this.addHook(file,callback);
  709. } else {
  710. this.head = HEAD(this.head);
  711. if (this.loader[type]) {this.loader[type].call(this,file,callback)}
  712. else {throw Error("Can't load files of type "+type)}
  713. }
  714. return callback;
  715. },
  716. //
  717. // Register a load hook for a particular file (it will be called when
  718. // loadComplete() is called for that file)
  719. //
  720. LoadHook: function (file,callback,priority) {
  721. callback = BASE.Callback(callback);
  722. if (file instanceof Object)
  723. {for (var i in file) {if (file.hasOwnProperty(i)) {file = file[i]}}}
  724. file = this.fileURL(file);
  725. if (this.loaded[file]) {callback(this.loaded[file])}
  726. else {this.addHook(file,callback,priority)}
  727. return callback;
  728. },
  729. addHook: function (file,callback,priority) {
  730. if (!this.loadHooks[file]) {this.loadHooks[file] = MathJax.Callback.Hooks()}
  731. this.loadHooks[file].Add(callback,priority);
  732. callback.file = file;
  733. },
  734. removeHook: function (hook) {
  735. if (this.loadHooks[hook.file]) {
  736. this.loadHooks[hook.file].Remove(hook);
  737. if (!this.loadHooks[hook.file].hooks.length) {delete this.loadHooks[hook.file]}
  738. }
  739. },
  740. //
  741. // Used when files are combined in a preloading configuration file
  742. //
  743. Preloading: function () {
  744. for (var i = 0, m = arguments.length; i < m; i++) {
  745. var file = this.fileURL(arguments[i]);
  746. if (!this.loading[file]) {this.loading[file] = {preloaded: true}}
  747. }
  748. },
  749. //
  750. // Code used to load the various types of files
  751. // (JS for JavaScript, CSS for style sheets)
  752. //
  753. loader: {
  754. //
  755. // Create a SCRIPT tag to load the file
  756. //
  757. JS: function (file,callback) {
  758. var name = this.fileName(file);
  759. var script = document.createElement("script");
  760. var timeout = BASE.Callback(["loadTimeout",this,file]);
  761. this.loading[file] = {
  762. callback: callback,
  763. timeout: setTimeout(timeout,this.timeout),
  764. status: this.STATUS.OK,
  765. script: script
  766. };
  767. //
  768. // Add this to the structure above after it is created to prevent recursion
  769. // when loading the initial localization file (before loading messsage is available)
  770. //
  771. this.loading[file].message = BASE.Message.File(name);
  772. script.onerror = timeout; // doesn't work in IE and no apparent substitute
  773. script.type = "text/javascript";
  774. script.src = file+this.fileRev(name);
  775. this.head.appendChild(script);
  776. },
  777. //
  778. // Create a LINK tag to load the style sheet
  779. //
  780. CSS: function (file,callback) {
  781. var name = this.fileName(file);
  782. var link = document.createElement("link");
  783. link.rel = "stylesheet"; link.type = "text/css";
  784. link.href = file+this.fileRev(name);
  785. this.loading[file] = {
  786. callback: callback,
  787. message: BASE.Message.File(name),
  788. status: this.STATUS.OK
  789. };
  790. this.head.appendChild(link);
  791. this.timer.create.call(this,[this.timer.file,file],link);
  792. }
  793. },
  794. //
  795. // Timing code for checking when style sheets are available.
  796. //
  797. timer: {
  798. //
  799. // Create the timing callback and start the timing loop.
  800. // We use a delay because some browsers need it to allow the styles
  801. // to be processed.
  802. //
  803. create: function (callback,node) {
  804. callback = BASE.Callback(callback);
  805. if (node.nodeName === "STYLE" && node.styleSheet &&
  806. typeof(node.styleSheet.cssText) !== 'undefined') {
  807. callback(this.STATUS.OK); // MSIE processes style immediately, but doesn't set its styleSheet!
  808. } else if (window.chrome && node.nodeName === "LINK") {
  809. callback(this.STATUS.OK); // Chrome doesn't give access to cssRules for stylesheet in
  810. // a link node, so we can't detect when it is loaded.
  811. } else if (isSafari2) {
  812. this.timer.start(this,[this.timer.checkSafari2,sheets++,callback],this.styleDelay);
  813. } else {
  814. this.timer.start(this,[this.timer.checkLength,node,callback],this.styleDelay);
  815. }
  816. return callback;
  817. },
  818. //
  819. // Start the timer for the given callback checker
  820. //
  821. start: function (AJAX,check,delay,timeout) {
  822. check = BASE.Callback(check);
  823. check.execute = this.execute; check.time = this.time;
  824. check.STATUS = AJAX.STATUS; check.timeout = timeout || AJAX.timeout;
  825. check.delay = check.total = delay || 0;
  826. if (delay) {setTimeout(check,delay)} else {check()}
  827. },
  828. //
  829. // Increment the time total, increase the delay
  830. // and test if we are past the timeout time.
  831. //
  832. time: function (callback) {
  833. this.total += this.delay;
  834. this.delay = Math.floor(this.delay * 1.05 + 5);
  835. if (this.total >= this.timeout) {callback(this.STATUS.ERROR); return 1}
  836. return 0;
  837. },
  838. //
  839. // For JS file loads, call the proper routine according to status
  840. //
  841. file: function (file,status) {
  842. if (status < 0) {BASE.Ajax.loadTimeout(file)} else {BASE.Ajax.loadComplete(file)}
  843. },
  844. //
  845. // Call the hook with the required data
  846. //
  847. execute: function () {this.hook.call(this.object,this,this.data[0],this.data[1])},
  848. //
  849. // Safari2 doesn't set the link's stylesheet, so we need to look in the
  850. // document.styleSheets array for the new sheet when it is created
  851. //
  852. checkSafari2: function (check,length,callback) {
  853. if (check.time(callback)) return;
  854. if (document.styleSheets.length > length &&
  855. document.styleSheets[length].cssRules &&
  856. document.styleSheets[length].cssRules.length)
  857. {callback(check.STATUS.OK)} else {setTimeout(check,check.delay)}
  858. },
  859. //
  860. // Look for the stylesheets rules and check when they are defined
  861. // and no longer of length zero. (This assumes there actually ARE
  862. // some rules in the stylesheet.)
  863. //
  864. checkLength: function (check,node,callback) {
  865. if (check.time(callback)) return;
  866. var isStyle = 0; var sheet = (node.sheet || node.styleSheet);
  867. try {if ((sheet.cssRules||sheet.rules||[]).length > 0) {isStyle = 1}} catch(err) {
  868. if (err.message.match(/protected variable|restricted URI/)) {isStyle = 1}
  869. else if (err.message.match(/Security error/)) {
  870. // Firefox3 gives "Security error" for missing files, so
  871. // can't distinguish that from OK files on remote servers.
  872. // or OK files in different directory from local files.
  873. isStyle = 1; // just say it is OK (can't really tell)
  874. }
  875. }
  876. if (isStyle) {
  877. // Opera 9.6 requires this setTimeout
  878. setTimeout(BASE.Callback([callback,check.STATUS.OK]),0);
  879. } else {
  880. setTimeout(check,check.delay);
  881. }
  882. }
  883. },
  884. //
  885. // JavaScript code must call this when they are completely initialized
  886. // (this allows them to perform asynchronous actions before indicating
  887. // that they are complete).
  888. //
  889. loadComplete: function (file) {
  890. file = this.fileURL(file);
  891. var loading = this.loading[file];
  892. if (loading && !loading.preloaded) {
  893. BASE.Message.Clear(loading.message);
  894. clearTimeout(loading.timeout);
  895. if (loading.script) {
  896. if (SCRIPTS.length === 0) {setTimeout(REMOVESCRIPTS,0)}
  897. SCRIPTS.push(loading.script);
  898. }
  899. this.loaded[file] = loading.status; delete this.loading[file];
  900. this.addHook(file,loading.callback);
  901. } else {
  902. if (loading) {delete this.loading[file]}
  903. this.loaded[file] = this.STATUS.OK;
  904. loading = {status: this.STATUS.OK}
  905. }
  906. if (!this.loadHooks[file]) {return null}
  907. return this.loadHooks[file].Execute(loading.status);
  908. },
  909. //
  910. // If a file fails to load within the timeout period (or the onerror handler
  911. // is called), this routine runs to signal the error condition.
  912. //
  913. loadTimeout: function (file) {
  914. if (this.loading[file].timeout) {clearTimeout(this.loading[file].timeout)}
  915. this.loading[file].status = this.STATUS.ERROR;
  916. this.loadError(file);
  917. this.loadComplete(file);
  918. },
  919. //
  920. // The default error hook for file load failures
  921. //
  922. loadError: function (file) {
  923. BASE.Message.Set(["LoadFailed","File failed to load: %1",file],null,2000);
  924. BASE.Hub.signal.Post(["file load error",file]);
  925. },
  926. //
  927. // Defines a style sheet from a hash of style declarations (key:value pairs
  928. // where the key is the style selector and the value is a hash of CSS attributes
  929. // and values).
  930. //
  931. Styles: function (styles,callback) {
  932. var styleString = this.StyleString(styles);
  933. if (styleString === "") {
  934. callback = BASE.Callback(callback);
  935. callback();
  936. } else {
  937. var style = document.createElement("style"); style.type = "text/css";
  938. this.head = HEAD(this.head);
  939. this.head.appendChild(style);
  940. if (style.styleSheet && typeof(style.styleSheet.cssText) !== 'undefined') {
  941. style.styleSheet.cssText = styleString;
  942. } else {
  943. style.appendChild(document.createTextNode(styleString));
  944. }
  945. callback = this.timer.create.call(this,callback,style);
  946. }
  947. return callback;
  948. },
  949. //
  950. // Create a stylesheet string from a style declaration object
  951. //
  952. StyleString: function (styles) {
  953. if (typeof(styles) === 'string') {return styles}
  954. var string = "", id, style;
  955. for (id in styles) {if (styles.hasOwnProperty(id)) {
  956. if (typeof styles[id] === 'string') {
  957. string += id + " {"+styles[id]+"}\n";
  958. } else if (BASE.Object.isArray(styles[id])) {
  959. for (var i = 0; i < styles[id].length; i++) {
  960. style = {}; style[id] = styles[id][i];
  961. string += this.StyleString(style);
  962. }
  963. } else if (id.substr(0,6) === '@media') {
  964. string += id + " {"+this.StyleString(styles[id])+"}\n";
  965. } else if (styles[id] != null) {
  966. style = [];
  967. for (var name in styles[id]) {if (styles[id].hasOwnProperty(name)) {
  968. if (styles[id][name] != null)
  969. {style[style.length] = name + ': ' + styles[id][name]}
  970. }}
  971. string += id +" {"+style.join('; ')+"}\n";
  972. }
  973. }}
  974. return string;
  975. }
  976. };
  977. })("MathJax");
  978. /**********************************************************/
  979. MathJax.HTML = {
  980. //
  981. // Create an HTML element with given attributes and content.
  982. // The def parameter is an (optional) object containing key:value pairs
  983. // of the attributes and their values, and contents is an (optional)
  984. // array of strings to be inserted as text, or arrays of the form
  985. // [type,def,contents] that describes an HTML element to be inserted
  986. // into the current element. Thus the contents can describe a complete
  987. // HTML snippet of arbitrary complexity. E.g.:
  988. //
  989. // MathJax.HTML.Element("span",{id:"mySpan",style{"font-style":"italic"}},[
  990. // "(See the ",["a",{href:"http://www.mathjax.org"},["MathJax home page"]],
  991. // " for more details.)"]);
  992. //
  993. Element: function (type,def,contents) {
  994. var obj = document.createElement(type), id;
  995. if (def) {
  996. if (def.hasOwnProperty("style")) {
  997. var style = def.style; def.style = {};
  998. for (id in style) {if (style.hasOwnProperty(id))
  999. {def.style[id.replace(/-([a-z])/g,this.ucMatch)] = style[id]}}
  1000. }
  1001. MathJax.Hub.Insert(obj,def);
  1002. for (id in def) {
  1003. if (id === "role" || id.substr(0,5) === "aria-") obj.setAttribute(id,def[id]);
  1004. }
  1005. }
  1006. if (contents) {
  1007. if (!MathJax.Object.isArray(contents)) {contents = [contents]}
  1008. for (var i = 0, m = contents.length; i < m; i++) {
  1009. if (MathJax.Object.isArray(contents[i])) {
  1010. obj.appendChild(this.Element(contents[i][0],contents[i][1],contents[i][2]));
  1011. } else if (type === "script") { // IE throws an error if script is added as a text node
  1012. this.setScript(obj, contents[i]);
  1013. } else {
  1014. obj.appendChild(document.createTextNode(contents[i]));
  1015. }
  1016. }
  1017. }
  1018. return obj;
  1019. },
  1020. ucMatch: function (match,c) {return c.toUpperCase()},
  1021. addElement: function (span,type,def,contents) {return span.appendChild(this.Element(type,def,contents))},
  1022. TextNode: function (text) {return document.createTextNode(text)},
  1023. addText: function (span,text) {return span.appendChild(this.TextNode(text))},
  1024. //
  1025. // Set and get the text of a script
  1026. //
  1027. setScript: function (script,text) {
  1028. if (this.setScriptBug) {script.text = text} else {
  1029. while (script.firstChild) {script.removeChild(script.firstChild)}
  1030. this.addText(script,text);
  1031. }
  1032. },
  1033. getScript: function (script) {
  1034. var text = (script.text === "" ? script.innerHTML : script.text);
  1035. return text.replace(/^\s+/,"").replace(/\s+$/,"");
  1036. },
  1037. //
  1038. // Manage cookies
  1039. //
  1040. Cookie: {
  1041. prefix: "mjx",
  1042. expires: 365,
  1043. //
  1044. // Save an object as a named cookie
  1045. //
  1046. Set: function (name,def) {
  1047. var keys = [];
  1048. if (def) {
  1049. for (var id in def) {if (def.hasOwnProperty(id)) {
  1050. keys.push(id+":"+def[id].toString().replace(/&/g,"&&"));
  1051. }}
  1052. }
  1053. var cookie = this.prefix+"."+name+"="+escape(keys.join('&;'));
  1054. if (this.expires) {
  1055. var time = new Date(); time.setDate(time.getDate() + this.expires);
  1056. cookie += '; expires='+time.toGMTString();
  1057. }
  1058. try {document.cookie = cookie+"; path=/"} catch (err) {} // ignore errors saving cookies
  1059. },
  1060. //
  1061. // Get the contents of a named cookie and incorporate
  1062. // it into the given object (or return a fresh one)
  1063. //
  1064. Get: function (name,obj) {
  1065. if (!obj) {obj = {}}
  1066. var pattern = new RegExp("(?:^|;\\s*)"+this.prefix+"\\."+name+"=([^;]*)(?:;|$)");
  1067. var match;
  1068. try {match = pattern.exec(document.cookie)} catch (err) {}; // ignore errors reading cookies
  1069. if (match && match[1] !== "") {
  1070. var keys = unescape(match[1]).split('&;');
  1071. for (var i = 0, m = keys.length; i < m; i++) {
  1072. match = keys[i].match(/([^:]+):(.*)/);
  1073. var value = match[2].replace(/&&/g,'&');
  1074. if (value === "true") {value = true} else if (value === "false") {value = false}
  1075. else if (value.match(/^-?(\d+(\.\d+)?|\.\d+)$/)) {value = parseFloat(value)}
  1076. obj[match[1]] = value;
  1077. }
  1078. }
  1079. return obj;
  1080. }
  1081. }
  1082. };
  1083. /**********************************************************/
  1084. MathJax.Localization = {
  1085. locale: "en",
  1086. directory: "[MathJax]/localization",
  1087. strings: {
  1088. // Currently, this list is not modified by the MathJax-i18n script. You can
  1089. // run the following command in MathJax/unpacked/localization to update it:
  1090. //
  1091. // find . -name "*.js" | xargs grep menuTitle\: | grep -v qqq | sed 's/^\.\/\(.*\)\/.*\.js\: / "\1"\: \{/' | sed 's/,$/\},/' | sed 's/"English"/"English", isLoaded: true/' > tmp ; sort tmp > tmp2 ; sed '$ s/,$//' tmp2 ; rm tmp*
  1092. //
  1093. // This only takes languages with localization data so you must also add
  1094. // the languages that use a remap but are not translated at all.
  1095. //
  1096. "ar": {menuTitle: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629"},
  1097. "ast": {menuTitle: "asturianu"},
  1098. "bg": {menuTitle: "\u0431\u044A\u043B\u0433\u0430\u0440\u0441\u043A\u0438"},
  1099. "bcc": {menuTitle: "\u0628\u0644\u0648\u0686\u06CC"},
  1100. "br": {menuTitle: "brezhoneg"},
  1101. "ca": {menuTitle: "catal\u00E0"},
  1102. "cdo": {menuTitle: "M\u00ECng-d\u0115\u0324ng-ng\u1E73\u0304"},
  1103. "cs": {menuTitle: "\u010De\u0161tina"},
  1104. "da": {menuTitle: "dansk"},
  1105. "de": {menuTitle: "Deutsch"},
  1106. "diq": {menuTitle: "Zazaki"},
  1107. "en": {menuTitle: "English", isLoaded: true},
  1108. "eo": {menuTitle: "Esperanto"},
  1109. "es": {menuTitle: "espa\u00F1ol"},
  1110. "fa": {menuTitle: "\u0641\u0627\u0631\u0633\u06CC"},
  1111. "fi": {menuTitle: "suomi"},
  1112. "fr": {menuTitle: "fran\u00E7ais"},
  1113. "gl": {menuTitle: "galego"},
  1114. "he": {menuTitle: "\u05E2\u05D1\u05E8\u05D9\u05EA"},
  1115. "ia": {menuTitle: "interlingua"},
  1116. "it": {menuTitle: "italiano"},
  1117. "ja": {menuTitle: "\u65E5\u672C\u8A9E"},
  1118. "kn": {menuTitle: "\u0C95\u0CA8\u0CCD\u0CA8\u0CA1"},
  1119. "ko": {menuTitle: "\uD55C\uAD6D\uC5B4"},
  1120. "lb": {menuTitle: "L\u00EBtzebuergesch"},
  1121. "lki": {menuTitle: "\u0644\u06D5\u06A9\u06CC"},
  1122. "lt": {menuTitle: "lietuvi\u0173"},
  1123. "mk": {menuTitle: "\u043C\u0430\u043A\u0435\u0434\u043E\u043D\u0441\u043A\u0438"},
  1124. "nl": {menuTitle: "Nederlands"},
  1125. "oc": {menuTitle: "occitan"},
  1126. "pl": {menuTitle: "polski"},
  1127. "pt": {menuTitle: "portugu\u00EAs"},
  1128. "pt-br": {menuTitle: "portugu\u00EAs do Brasil"},
  1129. "ru": {menuTitle: "\u0440\u0443\u0441\u0441\u043A\u0438\u0439"},
  1130. "sco": {menuTitle: "Scots"},
  1131. "scn": {menuTitle: "sicilianu"},
  1132. "sk": {menuTitle: "sloven\u010Dina"},
  1133. "sl": {menuTitle: "sloven\u0161\u010Dina"},
  1134. "sv": {menuTitle: "svenska"},
  1135. "th": {menuTitle: "\u0E44\u0E17\u0E22"},
  1136. "tr": {menuTitle: "T\u00FCrk\u00E7e"},
  1137. "uk": {menuTitle: "\u0443\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430"},
  1138. "vi": {menuTitle: "Ti\u1EBFng Vi\u1EC7t"},
  1139. "zh-hans": {menuTitle: "\u4E2D\u6587\uFF08\u7B80\u4F53\uFF09"},
  1140. "zh-hant": {menuTitle: "\u6C49\u8BED"}
  1141. },
  1142. //
  1143. // The pattern for substitution escapes:
  1144. // %n or %{n} or %{plural:%n|option1|option1|...} or %c
  1145. //
  1146. pattern: /%(\d+|\{\d+\}|\{[a-z]+:\%\d+(?:\|(?:%\{\d+\}|%.|[^\}])*)+\}|.)/g,
  1147. SPLIT: ("axb".split(/(x)/).length === 3 ?
  1148. function (string,regex) {return string.split(regex)} :
  1149. //
  1150. // IE8 and below don't do split() correctly when the pattern includes
  1151. // parentheses (the split should include the matched exrepssions).
  1152. // So implement it by hand here.
  1153. //
  1154. function (string,regex) {
  1155. var result = [], match, last = 0;
  1156. regex.lastIndex = 0;
  1157. while ((match = regex.exec(string))) {
  1158. result.push(string.substr(last,match.index-last));
  1159. result.push.apply(result,match.slice(1));
  1160. last = match.index + match[0].length;
  1161. }
  1162. result.push(string.substr(last));
  1163. return result;
  1164. }),
  1165. _: function (id,phrase) {
  1166. if (MathJax.Object.isArray(phrase)) {return this.processSnippet(id,phrase)}
  1167. return this.processString(this.lookupPhrase(id,phrase),[].slice.call(arguments,2));
  1168. },
  1169. processString: function (string,args,domain) {
  1170. //
  1171. // Process arguments for substitution
  1172. // If the argument is a snippet (and we are processing snippets) do so,
  1173. // Otherwise, if it is a number, convert it for the lacale
  1174. //
  1175. var i, m, isArray = MathJax.Object.isArray;
  1176. for (i = 0, m = args.length; i < m; i++) {
  1177. if (domain && isArray(args[i])) {args[i] = this.processSnippet(domain,args[i])}
  1178. }
  1179. //
  1180. // Split string at escapes and process them individually
  1181. //
  1182. var parts = this.SPLIT(string,this.pattern);
  1183. for (i = 1, m = parts.length; i < m; i += 2) {
  1184. var c = parts[i].charAt(0); // first char will be { or \d or a char to be kept literally
  1185. if (c >= "0" && c <= "9") { // %n
  1186. parts[i] = args[parts[i]-1];
  1187. if (typeof parts[i] === "number") parts[i] = this.number(parts[i]);
  1188. } else if (c === "{") { // %{n} or %{plural:%n|...}
  1189. c = parts[i].substr(1);
  1190. if (c >= "0" && c <= "9") { // %{n}
  1191. parts[i] = args[parts[i].substr(1,parts[i].length-2)-1];
  1192. if (typeof parts[i] === "number") parts[i] = this.number(parts[i]);
  1193. } else { // %{plural:%n|...}
  1194. var match = parts[i].match(/^\{([a-z]+):%(\d+)\|(.*)\}$/);
  1195. if (match) {
  1196. if (match[1] === "plural") {
  1197. var n = args[match[2]-1];
  1198. if (typeof n === "undefined") {
  1199. parts[i] = "???"; // argument doesn't exist
  1200. } else {
  1201. n = this.plural(n) - 1; // index of the form to use
  1202. var plurals = match[3].replace(/(^|[^%])(%%)*%\|/g,"$1$2%\uEFEF").split(/\|/); // the parts (replacing %| with a special character)
  1203. if (n >= 0 && n < plurals.length) {
  1204. parts[i] = this.processString(plurals[n].replace(/\uEFEF/g,"|"),args,domain);
  1205. } else {
  1206. parts[i] = "???"; // no string for this index
  1207. }
  1208. }
  1209. } else {parts[i] = "%"+parts[i]} // not "plural", put back the % and leave unchanged
  1210. }
  1211. }
  1212. }
  1213. if (parts[i] == null) {parts[i] = "???"}
  1214. }
  1215. //
  1216. // If we are not forming a snippet, return the completed string
  1217. //
  1218. if (!domain) {return parts.join("")}
  1219. //
  1220. // We need to return an HTML snippet, so buld it from the
  1221. // broken up string with inserted parts (that could be snippets)
  1222. //
  1223. var snippet = [], part = "";
  1224. for (i = 0; i < m; i++) {
  1225. part += parts[i]; i++; // add the string and move on to substitution result
  1226. if (i < m) {
  1227. if (isArray(parts[i])) { // substitution was a snippet
  1228. snippet.push(part); // add the accumulated string
  1229. snippet = snippet.concat(parts[i]); // concatenate the substution snippet
  1230. part = ""; // start accumulating a new string
  1231. } else { // substitution was a string
  1232. part += parts[i]; // add to accumulating string
  1233. }
  1234. }
  1235. }
  1236. if (part !== "") {snippet.push(part)} // add final string
  1237. return snippet;
  1238. },
  1239. processSnippet: function (domain,snippet) {
  1240. var result = []; // the new snippet
  1241. //
  1242. // Look through the original snippet for
  1243. // strings or snippets to translate
  1244. //
  1245. for (var i = 0, m = snippet.length; i < m; i++) {
  1246. if (MathJax.Object.isArray(snippet[i])) {
  1247. //
  1248. // This could be a sub-snippet:
  1249. // ["tag"] or ["tag",{properties}] or ["tag",{properties},snippet]
  1250. // Or it could be something to translate:
  1251. // [id,string,args] or [domain,snippet]
  1252. var data = snippet[i];
  1253. if (typeof data[1] === "string") { // [id,string,args]
  1254. var id = data[0]; if (!MathJax.Object.isArray(id)) {id = [domain,id]}
  1255. var phrase = this.lookupPhrase(id,data[1]);
  1256. result = result.concat(this.processMarkdown(phrase,data.slice(2),domain));
  1257. } else if (MathJax.Object.isArray(data[1])) { // [domain,snippet]
  1258. result = result.concat(this.processSnippet.apply(this,data));
  1259. } else if (data.length >= 3) { // ["tag",{properties},snippet]
  1260. result.push([data[0],data[1],this.processSnippet(domain,data[2])]);
  1261. } else { // ["tag"] or ["tag",{properties}]
  1262. result.push(snippet[i]);
  1263. }
  1264. } else { // a string
  1265. result.push(snippet[i]);
  1266. }
  1267. }
  1268. return result;
  1269. },
  1270. markdownPattern: /(%.)|(\*{1,3})((?:%.|.)+?)\2|(`+)((?:%.|.)+?)\4|\[((?:%.|.)+?)\]\(([^\s\)]+)\)/,
  1271. // %c or *bold*, **italics**, ***bold-italics***, or `code`, or [link](url)
  1272. processMarkdown: function (phrase,args,domain) {
  1273. var result = [], data;
  1274. //
  1275. // Split the string by the Markdown pattern
  1276. // (the text blocks are separated by
  1277. // c,stars,star-text,backtics,code-text,link-text,URL).
  1278. // Start with teh first text string from the split.
  1279. //
  1280. var parts = phrase.split(this.markdownPattern);
  1281. var string = parts[0];
  1282. //
  1283. // Loop through the matches and process them
  1284. //
  1285. for (var i = 1, m = parts.length; i < m; i += 8) {
  1286. if (parts[i+1]) { // stars (for bold/italic)
  1287. //
  1288. // Select the tag to use by number of stars (three stars requires two tags)
  1289. //
  1290. data = this.processString(parts[i+2],args,domain);
  1291. if (!MathJax.Object.isArray(data)) {data = [data]}
  1292. data = [["b","i","i"][parts[i+1].length-1],{},data]; // number of stars determines type
  1293. if (parts[i+1].length === 3) {data = ["b",{},data]} // bold-italic
  1294. } else if (parts[i+3]) { // backtics (for code)
  1295. //
  1296. // Remove one leading or trailing space, and process substitutions
  1297. // Make a <code> tag
  1298. //
  1299. data = this.processString(parts[i+4].replace(/^\s/,"").replace(/\s$/,""),args,domain);
  1300. if (!MathJax.Object.isArray(data)) {data = [data]}
  1301. data = ["code",{},data];
  1302. } else if (parts[i+5]) { // hyperlink
  1303. //
  1304. // Process the link text, and make an <a> tag with the URL
  1305. //
  1306. data = this.processString(parts[i+5],args,domain);
  1307. if (!MathJax.Object.isArray(data)) {data = [data]}
  1308. data = ["a",{href:this.processString(parts[i+6],args),target:"_blank"},data];
  1309. } else {
  1310. //
  1311. // Escaped character (%c) gets added into the string.
  1312. //
  1313. string += parts[i]; data = null;
  1314. }
  1315. //
  1316. // If there is a tag to insert,
  1317. // Add any pending string, then push the tag
  1318. //
  1319. if (data) {
  1320. result = this.concatString(result,string,args,domain);
  1321. result.push(data); string = "";
  1322. }
  1323. //
  1324. // Process the string that follows matches pattern
  1325. //
  1326. if (parts[i+7] !== "") {string += parts[i+7]}
  1327. };
  1328. //
  1329. // Add any pending string and return the resulting snippet
  1330. //
  1331. result = this.concatString(result,string,args,domain);
  1332. return result;
  1333. },
  1334. concatString: function (result,string,args,domain) {
  1335. if (string != "") {
  1336. //
  1337. // Process the substutions.
  1338. // If the result is not a snippet, turn it into one.
  1339. // Then concatenate the snippet to the current one
  1340. //
  1341. string = this.processString(string,args,domain);
  1342. if (!MathJax.Object.isArray(string)) {string = [string]}
  1343. result = result.concat(string);
  1344. }
  1345. return result;
  1346. },
  1347. lookupPhrase: function (id,phrase,domain) {
  1348. //
  1349. // Get the domain and messageID
  1350. //
  1351. if (!domain) {domain = "_"}
  1352. if (MathJax.Object.isArray(id)) {domain = (id[0] || "_"); id = (id[1] || "")}
  1353. //
  1354. // Check if the data is available and if not,
  1355. // load it and throw a restart error so the calling
  1356. // code can wait for the load and try again.
  1357. //
  1358. var load = this.loadDomain(domain);
  1359. if (load) {MathJax.Hub.RestartAfter(load)}
  1360. //
  1361. // Look up the message in the localization data
  1362. // (if not found, the original English is used)
  1363. //
  1364. var localeData = this.strings[this.locale];
  1365. if (localeData) {
  1366. if (localeData.domains && domain in localeData.domains) {
  1367. var domainData = localeData.domains[domain];
  1368. if (domainData.strings && id in domainData.strings)
  1369. {phrase = domainData.strings[id]}
  1370. }
  1371. }
  1372. //
  1373. // return the translated phrase
  1374. //
  1375. return phrase;
  1376. },
  1377. //
  1378. // Load a langauge data file from the proper
  1379. // directory and file.
  1380. //
  1381. loadFile: function (file,data,callback) {
  1382. callback = MathJax.Callback(callback);
  1383. file = (data.file || file); // the data's file name or the default name
  1384. if (!file.match(/\.js$/)) {file += ".js"} // add .js if needed
  1385. //
  1386. // Add the directory if the file doesn't
  1387. // contain a full URL already.
  1388. //
  1389. if (!file.match(/^([a-z]+:|\[MathJax\])/)) {
  1390. var dir = (this.strings[this.locale].directory ||
  1391. this.directory + "/" + this.locale ||
  1392. "[MathJax]/localization/" + this.locale);
  1393. file = dir + "/" + file;
  1394. }
  1395. //
  1396. // Load the file and mark the data as loaded (even if it
  1397. // failed to load, so we don't continue to try to load it
  1398. // over and over).
  1399. //
  1400. var load = MathJax.Ajax.Require(file,function () {data.isLoaded = true; return callback()});
  1401. //
  1402. // Return the callback if needed, otherwise null.
  1403. //
  1404. return (load.called ? null : load);
  1405. },
  1406. //
  1407. // Check to see if the localization data are loaded
  1408. // for the given domain; if not, load the data file,
  1409. // and return a callback for the loading operation.
  1410. // Otherwise return null (data are loaded).
  1411. //
  1412. loadDomain: function (domain,callback) {
  1413. var load, localeData = this.strings[this.locale];
  1414. if (localeData) {
  1415. if (!localeData.isLoaded) {
  1416. load = this.loadFile(this.locale,localeData);
  1417. if (load) {
  1418. return MathJax.Callback.Queue(
  1419. load,["loadDomain",this,domain] // call again to load domain
  1420. ).Push(callback||{});
  1421. }
  1422. }
  1423. if (localeData.domains && domain in localeData.domains) {
  1424. var domainData = localeData.domains[domain];
  1425. if (!domainData.isLoaded) {
  1426. load = this.loadFile(domain,domainData);
  1427. if (load) {return MathJax.Callback.Queue(load).Push(callback)}
  1428. }
  1429. }
  1430. }
  1431. // localization data are loaded, so just do the callback
  1432. return MathJax.Callback(callback)();
  1433. },
  1434. //
  1435. // Perform a function, properly handling
  1436. // restarts due to localization file loads.
  1437. //
  1438. // Note that this may return before the function
  1439. // has been called successfully, so you should
  1440. // consider fn as running asynchronously. (Callbacks
  1441. // can be used to synchronize it with other actions.)
  1442. //
  1443. Try: function (fn) {
  1444. fn = MathJax.Callback(fn); fn.autoReset = true;
  1445. try {fn()} catch (err) {
  1446. if (!err.restart) {throw err}
  1447. MathJax.Callback.After(["Try",this,fn],err.restart);
  1448. }
  1449. },
  1450. //
  1451. // Reset the current language
  1452. //
  1453. resetLocale: function(locale) {
  1454. // Selection algorithm:
  1455. // 1) Downcase locale name (e.g. "en-US" => "en-us")
  1456. // 2) Try a parent language (e.g. "en-us" => "en")
  1457. // 3) Try the fallback specified in the data (e.g. "pt" => "pt-br")
  1458. // 4) Otherwise don't change the locale.
  1459. if (!locale) return;
  1460. locale = locale.toLowerCase();
  1461. while (!this.strings[locale]) {
  1462. var dashPos = locale.lastIndexOf("-");
  1463. if (dashPos === -1) return;
  1464. locale = locale.substring(0, dashPos);
  1465. }
  1466. var remap = this.strings[locale].remap;
  1467. this.locale = remap ? remap : locale;
  1468. },
  1469. //
  1470. // Set the current language
  1471. //
  1472. setLocale: function(locale) {
  1473. this.resetLocale(locale);
  1474. if (MathJax.Menu) {this.loadDomain("MathMenu")}
  1475. },
  1476. //
  1477. // Add or update a language or domain
  1478. //
  1479. addTranslation: function (locale,domain,definition) {
  1480. var data = this.strings[locale], isNew = false;
  1481. if (!data) {data = this.strings[locale] = {}; isNew = true}
  1482. if (!data.domains) {data.domains = {}}
  1483. if (domain) {
  1484. if (!data.domains[domain]) {data.domains[domain] = {}}
  1485. data = data.domains[domain];
  1486. }
  1487. MathJax.Hub.Insert(data,definition);
  1488. if (isNew && MathJax.Menu.menu) {MathJax.Menu.CreateLocaleMenu()}
  1489. },
  1490. //
  1491. // Set CSS for an element based on font requirements
  1492. //
  1493. setCSS: function (div) {
  1494. var locale = this.strings[this.locale];
  1495. if (locale) {
  1496. if (locale.fontFamily) {div.style.fontFamily = locale.fontFamily}
  1497. if (locale.fontDirection) {
  1498. div.style.direction = locale.fontDirection;
  1499. if (locale.fontDirection === "rtl") {div.style.textAlign = "right"}
  1500. }
  1501. }
  1502. return div;
  1503. },
  1504. //
  1505. // Get the language's font family or direction
  1506. //
  1507. fontFamily: function () {
  1508. var locale = this.strings[this.locale];
  1509. return (locale ? locale.fontFamily : null);
  1510. },
  1511. fontDirection: function () {
  1512. var locale = this.strings[this.locale];
  1513. return (locale ? locale.fontDirection : null);
  1514. },
  1515. //
  1516. // Get the language's plural index for a number
  1517. //
  1518. plural: function (n) {
  1519. var locale = this.strings[this.locale];
  1520. if (locale && locale.plural) {return locale.plural(n)}
  1521. // default
  1522. if (n == 1) {return 1} // one
  1523. return 2; // other
  1524. },
  1525. //
  1526. // Convert a number to language-specific form
  1527. //
  1528. number: function(n) {
  1529. var locale = this.strings[this.locale];
  1530. if (locale && locale.number) {return locale.number(n)}
  1531. // default
  1532. return n;
  1533. }
  1534. };
  1535. /**********************************************************/
  1536. MathJax.Message = {
  1537. ready: false, // used to tell when the styles are available
  1538. log: [{}], current: null,
  1539. textNodeBug: (navigator.vendor === "Apple Computer, Inc." &&
  1540. typeof navigator.vendorSub === "undefined") ||
  1541. (window.hasOwnProperty && window.hasOwnProperty("konqueror")), // Konqueror displays some gibberish with text.nodeValue = "..."
  1542. styles: {
  1543. "#MathJax_Message": {
  1544. position: "fixed", left: "1px", bottom: "2px",
  1545. 'background-color': "#E6E6E6", border: "1px solid #959595",
  1546. margin: "0px", padding: "2px 8px",
  1547. 'z-index': "102", color: "black", 'font-size': "80%",
  1548. width: "auto", 'white-space': "nowrap"
  1549. },
  1550. "#MathJax_MSIE_Frame": {
  1551. position: "absolute",
  1552. top:0, left: 0, width: "0px", 'z-index': 101,
  1553. border: "0px", margin: "0px", padding: "0px"
  1554. }
  1555. },
  1556. browsers: {
  1557. MSIE: function (browser) {
  1558. MathJax.Message.msieFixedPositionBug = ((document.documentMode||0) < 7);
  1559. if (MathJax.Message.msieFixedPositionBug)
  1560. {MathJax.Hub.config.styles["#MathJax_Message"].position = "absolute"}
  1561. MathJax.Message.quirks = (document.compatMode === "BackCompat");
  1562. },
  1563. Chrome: function (browser) {
  1564. MathJax.Hub.config.styles["#MathJax_Message"].bottom = "1.5em";
  1565. MathJax.Hub.config.styles["#MathJax_Message"].left = "1em";
  1566. }
  1567. },
  1568. Init: function (styles) {
  1569. if (styles) {this.ready = true}
  1570. if (!document.body || !this.ready) {return false}
  1571. //
  1572. // ASCIIMathML replaces the entire page with a copy of itself (@#!#%@!!)
  1573. // so check that this.div is still part of the page, otherwise look up
  1574. // the copy and use that.
  1575. //
  1576. if (this.div && this.div.parentNode == null) {
  1577. this.div = document.getElementById("MathJax_Message");
  1578. if (this.div) {this.text = this.div.firstChild}
  1579. }
  1580. if (!this.div) {
  1581. var frame = document.body;
  1582. if (this.msieFixedPositionBug && window.attachEvent) {
  1583. frame = this.frame = this.addDiv(document.body); frame.removeAttribute("id");
  1584. frame.style.position = "absolute";
  1585. frame.style.border = frame.style.margin = frame.style.padding = "0px";
  1586. frame.style.zIndex = "101"; frame.style.height = "0px";
  1587. frame = this.addDiv(frame);
  1588. frame.id = "MathJax_MSIE_Frame";
  1589. window.attachEvent("onscroll",this.MoveFrame);
  1590. window.attachEvent("onresize",this.MoveFrame);
  1591. this.MoveFrame();
  1592. }
  1593. this.div = this.addDiv(frame); this.div.style.display = "none";
  1594. this.text = this.div.appendChild(document.createTextNode(""));
  1595. }
  1596. return true;
  1597. },
  1598. addDiv: function (parent) {
  1599. var div = document.createElement("div");
  1600. div.id = "MathJax_Message";
  1601. if (parent.firstChild) {parent.insertBefore(div,parent.firstChild)}
  1602. else {parent.appendChild(div)}
  1603. return div;
  1604. },
  1605. MoveFrame: function () {
  1606. var body = (MathJax.Message.quirks ? document.body : document.documentElement);
  1607. var frame = MathJax.Message.frame;
  1608. frame.style.left = body.scrollLeft + 'px';
  1609. frame.style.top = body.scrollTop + 'px';
  1610. frame.style.width = body.clientWidth + 'px';
  1611. frame = frame.firstChild;
  1612. frame.style.height = body.clientHeight + 'px';
  1613. },
  1614. localize: function (message) {
  1615. return MathJax.Localization._(message,message);
  1616. },
  1617. filterText: function (text,n,id) {
  1618. if (MathJax.Hub.config.messageStyle === "simple") {
  1619. if (id === "LoadFile") {
  1620. if (!this.loading) {this.loading = this.localize("Loading") + " "}
  1621. text = this.loading; this.loading += ".";
  1622. } else if (id === "ProcessMath") {
  1623. if (!this.processing) {this.processing = this.localize("Processing") + " "}
  1624. text = this.processing; this.processing += ".";
  1625. } else if (id === "TypesetMath") {
  1626. if (!this.typesetting) {this.typesetting = this.localize("Typesetting") + " "}
  1627. text = this.typesetting; this.typesetting += ".";
  1628. }
  1629. }
  1630. return text;
  1631. },
  1632. clearCounts: function () {
  1633. delete this.loading;
  1634. delete this.processing;
  1635. delete this.typesetting;
  1636. },
  1637. Set: function (text,n,clearDelay) {
  1638. if (n == null) {n = this.log.length; this.log[n] = {}}
  1639. //
  1640. // Translate message if it is [id,message,arguments]
  1641. //
  1642. var id = "";
  1643. if (MathJax.Object.isArray(text)) {
  1644. id = text[0]; if (MathJax.Object.isArray(id)) {id = id[1]}
  1645. //
  1646. // Localization._() will throw a restart error if a localization file
  1647. // needs to be loaded, so trap that and redo the Set() call
  1648. // after it is loaded.
  1649. //
  1650. try {
  1651. text = MathJax.Localization._.apply(MathJax.Localization,text);
  1652. } catch (err) {
  1653. if (!err.restart) {throw err}
  1654. if (!err.restart.called) {
  1655. //
  1656. // Mark it so we can tell if the Clear() comes before the message is displayed
  1657. //
  1658. if (this.log[n].restarted == null) {this.log[n].restarted = 0}
  1659. this.log[n].restarted++; delete this.log[n].cleared;
  1660. MathJax.Callback.After(["Set",this,text,n,clearDelay],err.restart);
  1661. return n;
  1662. }
  1663. }
  1664. }
  1665. //
  1666. // Clear the timout timer.
  1667. //
  1668. if (this.timer) {clearTimeout(this.timer); delete this.timer}
  1669. //
  1670. // Save the message and filtered message.
  1671. //
  1672. this.log[n].text = text; this.log[n].filteredText = text = this.filterText(text,n,id);
  1673. //
  1674. // Hook the message into the message list so we can tell
  1675. // what message to put up when this one is removed.
  1676. //
  1677. if (typeof(this.log[n].next) === "undefined") {
  1678. this.log[n].next = this.current;
  1679. if (this.current != null) {this.log[this.current].prev = n}
  1680. this.current = n;
  1681. }
  1682. //
  1683. // Show the message if it is the currently active one.
  1684. //
  1685. if (this.current === n && MathJax.Hub.config.messageStyle !== "none") {
  1686. if (this.Init()) {
  1687. if (this.textNodeBug) {this.div.innerHTML = text} else {this.text.nodeValue = text}
  1688. this.div.style.display = "";
  1689. if (this.status) {window.status = ""; delete this.status}
  1690. } else {
  1691. window.status = text;
  1692. this.status = true;
  1693. }
  1694. }
  1695. //
  1696. // Check if the message was resetarted to load a localization file
  1697. // and if it has been cleared in the meanwhile.
  1698. //
  1699. if (this.log[n].restarted) {
  1700. if (this.log[n].cleared) {clearDelay = 0}
  1701. if (--this.log[n].restarted === 0) {delete this.log[n].cleared}
  1702. }
  1703. //
  1704. // Check if we need to clear the message automatically.
  1705. //
  1706. if (clearDelay) {setTimeout(MathJax.Callback(["Clear",this,n]),clearDelay)}
  1707. else if (clearDelay == 0) {this.Clear(n,0)}
  1708. //
  1709. // Return the message number.
  1710. //
  1711. return n;
  1712. },
  1713. Clear: function (n,delay) {
  1714. //
  1715. // Detatch the message from the active list.
  1716. //
  1717. if (this.log[n].prev != null) {this.log[this.log[n].prev].next = this.log[n].next}
  1718. if (this.log[n].next != null) {this.log[this.log[n].next].prev = this.log[n].prev}
  1719. //
  1720. // If it is the current message, get the next one to show.
  1721. //
  1722. if (this.current === n) {
  1723. this.current = this.log[n].next;
  1724. if (this.text) {
  1725. if (this.div.parentNode == null) {this.Init()} // see ASCIIMathML comments above
  1726. if (this.current == null) {
  1727. //
  1728. // If there are no more messages, remove the message box.
  1729. //
  1730. if (this.timer) {clearTimeout(this.timer); delete this.timer}
  1731. if (delay == null) {delay = 600}
  1732. if (delay === 0) {this.Remove()}
  1733. else {this.timer = setTimeout(MathJax.Callback(["Remove",this]),delay)}
  1734. } else if (MathJax.Hub.config.messageStyle !== "none") {
  1735. //
  1736. // If there is an old message, put it in place
  1737. //
  1738. if (this.textNodeBug) {this.div.innerHTML = this.log[this.current].filteredText}
  1739. else {this.text.nodeValue = this.log[this.current].filteredText}
  1740. }
  1741. if (this.status) {window.status = ""; delete this.status}
  1742. } else if (this.status) {
  1743. window.status = (this.current == null ? "" : this.log[this.current].text);
  1744. }
  1745. }
  1746. //
  1747. // Clean up the log data no longer needed
  1748. //
  1749. delete this.log[n].next; delete this.log[n].prev;
  1750. delete this.log[n].filteredText;
  1751. //
  1752. // If this is a restarted localization message, mark that it has been cleared
  1753. // while waiting for the file to load.
  1754. //
  1755. if (this.log[n].restarted) {this.log[n].cleared = true}
  1756. },
  1757. Remove: function () {
  1758. // FIXME: do a fade out or something else interesting?
  1759. this.text.nodeValue = "";
  1760. this.div.style.display = "none";
  1761. },
  1762. File: function (file) {
  1763. return this.Set(["LoadFile","Loading %1",file],null,null);
  1764. },
  1765. Log: function () {
  1766. var strings = [];
  1767. for (var i = 1, m = this.log.length; i < m; i++) {strings[i] = this.log[i].text}
  1768. return strings.join("\n");
  1769. }
  1770. };
  1771. /**********************************************************/
  1772. MathJax.Hub = {
  1773. config: {
  1774. root: "",
  1775. config: [], // list of configuration files to load
  1776. styleSheets: [], // list of CSS files to load
  1777. styles: { // styles to generate in-line
  1778. ".MathJax_Preview": {color: "#888"}
  1779. },
  1780. jax: [], // list of input and output jax to load
  1781. extensions: [], // list of extensions to load
  1782. preJax: null, // pattern to remove from before math script tag
  1783. postJax: null, // pattern to remove from after math script tag
  1784. displayAlign: 'center', // how to align displayed equations (left, center, right)
  1785. displayIndent: '0', // indentation for displayed equations (when not centered)
  1786. preRemoveClass: 'MathJax_Preview', // class of objects to remove preceeding math script
  1787. showProcessingMessages: true, // display "Processing math: nn%" messages or not
  1788. messageStyle: "normal", // set to "none" or "simple" (for "Loading..." and "Processing...")
  1789. delayStartupUntil: "none", // set to "onload" to delay setup until the onload handler runs
  1790. // set to "configured" to delay startup until MathJax.Hub.Configured() is called
  1791. // set to a Callback to wait for before continuing with the startup
  1792. skipStartupTypeset: false, // set to true to skip PreProcess and Process during startup
  1793. elements: [], // array of elements to process when none is given explicitly
  1794. positionToHash: true, // after initial typeset pass, position to #hash location?
  1795. showMathMenu: true, // attach math context menu to typeset math?
  1796. showMathMenuMSIE: true, // separtely determine if MSIE should have math menu
  1797. // (since the code for that is a bit delicate)
  1798. menuSettings: {
  1799. zoom: "None", // when to do MathZoom
  1800. CTRL: false, // require CTRL for MathZoom?
  1801. ALT: false, // require Alt or Option?
  1802. CMD: false, // require CMD?
  1803. Shift: false, // require Shift?
  1804. discoverable: false, // make math menu discoverable on hover?
  1805. zscale: "200%", // the scaling factor for MathZoom
  1806. renderer: null, // set when Jax are loaded
  1807. font: "Auto", // what font HTML-CSS should use
  1808. context: "MathJax", // or "Browser" for pass-through to browser menu
  1809. locale: null, // the language to use for messages
  1810. mpContext: false, // true means pass menu events to MathPlayer in IE
  1811. mpMouse: false, // true means pass mouse events to MathPlayer in IE
  1812. texHints: true, // include class names for TeXAtom elements
  1813. FastPreview: null, // use PreviewHTML output as preview?
  1814. assistiveMML: null, // include hidden MathML for screen readers?
  1815. inTabOrder: true, // set to false if math elements should be included in the tabindex
  1816. semantics: false // add semantics tag with original form in MathML output
  1817. },
  1818. errorSettings: {
  1819. // localized HTML snippet structure for message to use
  1820. message: ["[",["MathProcessingError","Math Processing Error"],"]"],
  1821. style: {color: "#CC0000", "font-style":"italic"} // style for message
  1822. },
  1823. ignoreMMLattributes: {} // attributes not to copy to HTML-CSS or SVG output
  1824. // from MathML input (in addition to the ones in MML.nocopyAttributes).
  1825. // An id set to true will be ignored, one set to false will
  1826. // be allowed (even if other criteria normally would prevent
  1827. // it from being copied); use false carefully!
  1828. },
  1829. preProcessors: MathJax.Callback.Hooks(true), // list of callbacks for preprocessing (initialized by extensions)
  1830. inputJax: {}, // mime-type mapped to input jax (by registration)
  1831. outputJax: {order:{}}, // mime-type mapped to output jax list (by registration)
  1832. processSectionDelay: 50, // pause between input and output phases of processing
  1833. processUpdateTime: 250, // time between screen updates when processing math (milliseconds)
  1834. processUpdateDelay: 10, // pause between screen updates to allow other processing (milliseconds)
  1835. signal: MathJax.Callback.Signal("Hub"), // Signal used for Hub events
  1836. Config: function (def) {
  1837. this.Insert(this.config,def);
  1838. if (this.config.Augment) {this.Augment(this.config.Augment)}
  1839. },
  1840. CombineConfig: function (name,def) {
  1841. var config = this.config, id, parent; name = name.split(/\./);
  1842. for (var i = 0, m = name.length; i < m; i++) {
  1843. id = name[i]; if (!config[id]) {config[id] = {}}
  1844. parent = config; config = config[id];
  1845. }
  1846. parent[id] = config = this.Insert(def,config);
  1847. return config;
  1848. },
  1849. Register: {
  1850. PreProcessor: function () {return MathJax.Hub.preProcessors.Add.apply(MathJax.Hub.preProcessors,arguments)},
  1851. MessageHook: function () {return MathJax.Hub.signal.MessageHook.apply(MathJax.Hub.signal,arguments)},
  1852. StartupHook: function () {return MathJax.Hub.Startup.signal.MessageHook.apply(MathJax.Hub.Startup.signal,arguments)},
  1853. LoadHook: function () {return MathJax.Ajax.LoadHook.apply(MathJax.Ajax,arguments)}
  1854. },
  1855. UnRegister: {
  1856. PreProcessor: function (hook) {MathJax.Hub.preProcessors.Remove(hook)},
  1857. MessageHook: function (hook) {MathJax.Hub.signal.RemoveHook(hook)},
  1858. StartupHook: function (hook) {MathJax.Hub.Startup.signal.RemoveHook(hook)},
  1859. LoadHook: function (hook) {MathJax.Ajax.removeHook(hook)}
  1860. },
  1861. getAllJax: function (element) {
  1862. var jax = [], scripts = this.elementScripts(element);
  1863. for (var i = 0, m = scripts.length; i < m; i++) {
  1864. if (scripts[i].MathJax && scripts[i].MathJax.elementJax)
  1865. {jax.push(scripts[i].MathJax.elementJax)}
  1866. }
  1867. return jax;
  1868. },
  1869. getJaxByType: function (type,element) {
  1870. var jax = [], scripts = this.elementScripts(element);
  1871. for (var i = 0, m = scripts.length; i < m; i++) {
  1872. if (scripts[i].MathJax && scripts[i].MathJax.elementJax &&
  1873. scripts[i].MathJax.elementJax.mimeType === type)
  1874. {jax.push(scripts[i].MathJax.elementJax)}
  1875. }
  1876. return jax;
  1877. },
  1878. getJaxByInputType: function (type,element) {
  1879. var jax = [], scripts = this.elementScripts(element);
  1880. for (var i = 0, m = scripts.length; i < m; i++) {
  1881. if (scripts[i].MathJax && scripts[i].MathJax.elementJax &&
  1882. scripts[i].type && scripts[i].type.replace(/ *;(.|\s)*/,"") === type)
  1883. {jax.push(scripts[i].MathJax.elementJax)}
  1884. }
  1885. return jax;
  1886. },
  1887. getJaxFor: function (element) {
  1888. if (typeof(element) === 'string') {element = document.getElementById(element)}
  1889. if (element && element.MathJax) {return element.MathJax.elementJax}
  1890. if (this.isMathJaxNode(element)) {
  1891. if (!element.isMathJax) {element = element.firstChild} // for NativeMML output
  1892. while (element && !element.jaxID) {element = element.parentNode}
  1893. if (element) {return MathJax.OutputJax[element.jaxID].getJaxFromMath(element)}
  1894. }
  1895. return null;
  1896. },
  1897. isJax: function (element) {
  1898. if (typeof(element) === 'string') {element = document.getElementById(element)}
  1899. if (this.isMathJaxNode(element)) {return 1}
  1900. if (element && (element.tagName||"").toLowerCase() === 'script') {
  1901. if (element.MathJax)
  1902. {return (element.MathJax.state === MathJax.ElementJax.STATE.PROCESSED ? 1 : -1)}
  1903. if (element.type && this.inputJax[element.type.replace(/ *;(.|\s)*/,"")]) {return -1}
  1904. }
  1905. return 0;
  1906. },
  1907. isMathJaxNode: function (element) {
  1908. return !!element && (element.isMathJax || (element.className||"") === "MathJax_MathML");
  1909. },
  1910. setRenderer: function (renderer,type) {
  1911. if (!renderer) return;
  1912. if (!MathJax.OutputJax[renderer]) {
  1913. this.config.menuSettings.renderer = "";
  1914. var file = "[MathJax]/jax/output/"+renderer+"/config.js";
  1915. return MathJax.Ajax.Require(file,["setRenderer",this,renderer,type]);
  1916. } else {
  1917. this.config.menuSettings.renderer = renderer;
  1918. if (type == null) {type = "jax/mml"}
  1919. var jax = this.outputJax;
  1920. if (jax[type] && jax[type].length) {
  1921. if (renderer !== jax[type][0].id) {
  1922. jax[type].unshift(MathJax.OutputJax[renderer]);
  1923. return this.signal.Post(["Renderer Selected",renderer]);
  1924. }
  1925. }
  1926. return null;
  1927. }
  1928. },
  1929. Queue: function () {
  1930. return this.queue.Push.apply(this.queue,arguments);
  1931. },
  1932. Typeset: function (element,callback) {
  1933. if (!MathJax.isReady) return null;
  1934. var ec = this.elementCallback(element,callback);
  1935. if (ec.count) {
  1936. var queue = MathJax.Callback.Queue(
  1937. ["PreProcess",this,ec.elements],
  1938. ["Process",this,ec.elements]
  1939. );
  1940. }
  1941. return queue.Push(ec.callback);
  1942. },
  1943. PreProcess: function (element,callback) {
  1944. var ec = this.elementCallback(element,callback);
  1945. var queue = MathJax.Callback.Queue();
  1946. if (ec.count) {
  1947. var elements = (ec.count === 1 ? [ec.elements] : ec.elements);
  1948. queue.Push(["Post",this.signal,["Begin PreProcess",ec.elements]]);
  1949. for (var i = 0, m = elements.length; i < m; i++) {
  1950. if (elements[i]) {queue.Push(["Execute",this.preProcessors,elements[i]])}
  1951. }
  1952. queue.Push(["Post",this.signal,["End PreProcess",ec.elements]]);
  1953. }
  1954. return queue.Push(ec.callback);
  1955. },
  1956. Process: function (element,callback) {return this.takeAction("Process",element,callback)},
  1957. Update: function (element,callback) {return this.takeAction("Update",element,callback)},
  1958. Reprocess: function (element,callback) {return this.takeAction("Reprocess",element,callback)},
  1959. Rerender: function (element,callback) {return this.takeAction("Rerender",element,callback)},
  1960. takeAction: function (action,element,callback) {
  1961. var ec = this.elementCallback(element,callback);
  1962. var elements = ec.elements;
  1963. var queue = MathJax.Callback.Queue(["Clear",this.signal]);
  1964. var state = {
  1965. scripts: [], // filled in by prepareScripts
  1966. start: new Date().getTime(), // timer for processing messages
  1967. i: 0, j: 0, // current script, current jax
  1968. jax: {}, // scripts grouped by output jax
  1969. jaxIDs: [] // id's of jax used
  1970. };
  1971. if (ec.count) {
  1972. var delay = ["Delay",MathJax.Callback,this.processSectionDelay];
  1973. if (!delay[2]) {delay = {}}
  1974. queue.Push(
  1975. ["clearCounts",MathJax.Message],
  1976. ["Post",this.signal,["Begin "+action,elements]],
  1977. ["Post",this.signal,["Begin Math",elements,action]],
  1978. ["prepareScripts",this,action,elements,state],
  1979. ["Post",this.signal,["Begin Math Input",elements,action]],
  1980. ["processInput",this,state],
  1981. ["Post",this.signal,["End Math Input",elements,action]],
  1982. delay,
  1983. ["prepareOutput",this,state,"preProcess"],
  1984. delay,
  1985. ["Post",this.signal,["Begin Math Output",elements,action]],
  1986. ["processOutput",this,state],
  1987. ["Post",this.signal,["End Math Output",elements,action]],
  1988. delay,
  1989. ["prepareOutput",this,state,"postProcess"],
  1990. delay,
  1991. ["Post",this.signal,["End Math",elements,action]],
  1992. ["Post",this.signal,["End "+action,elements]],
  1993. ["clearCounts",MathJax.Message]
  1994. );
  1995. }
  1996. return queue.Push(ec.callback);
  1997. },
  1998. scriptAction: {
  1999. Process: function (script) {},
  2000. Update: function (script) {
  2001. var jax = script.MathJax.elementJax;
  2002. if (jax && jax.needsUpdate()) {jax.Remove(true); script.MathJax.state = jax.STATE.UPDATE}
  2003. else {script.MathJax.state = jax.STATE.PROCESSED}
  2004. },
  2005. Reprocess: function (script) {
  2006. var jax = script.MathJax.elementJax;
  2007. if (jax) {jax.Remove(true); script.MathJax.state = jax.STATE.UPDATE}
  2008. },
  2009. Rerender: function (script) {
  2010. var jax = script.MathJax.elementJax;
  2011. if (jax) {jax.Remove(true); script.MathJax.state = jax.STATE.OUTPUT}
  2012. }
  2013. },
  2014. prepareScripts: function (action,element,state) {
  2015. if (arguments.callee.disabled) return;
  2016. var scripts = this.elementScripts(element);
  2017. var STATE = MathJax.ElementJax.STATE;
  2018. for (var i = 0, m = scripts.length; i < m; i++) {
  2019. var script = scripts[i];
  2020. if (script.type && this.inputJax[script.type.replace(/ *;(.|\n)*/,"")]) {
  2021. if (script.MathJax) {
  2022. if (script.MathJax.elementJax && script.MathJax.elementJax.hover) {
  2023. MathJax.Extension.MathEvents.Hover.ClearHover(script.MathJax.elementJax);
  2024. }
  2025. if (script.MathJax.state !== STATE.PENDING) {this.scriptAction[action](script)}
  2026. }
  2027. if (!script.MathJax) {script.MathJax = {state: STATE.PENDING}}
  2028. if (script.MathJax.error) delete script.MathJax.error;
  2029. if (script.MathJax.state !== STATE.PROCESSED) {state.scripts.push(script)}
  2030. }
  2031. }
  2032. },
  2033. checkScriptSiblings: function (script) {
  2034. if (script.MathJax.checked) return;
  2035. var config = this.config, pre = script.previousSibling;
  2036. if (pre && pre.nodeName === "#text") {
  2037. var preJax,postJax, post = script.nextSibling;
  2038. if (post && post.nodeName !== "#text") {post = null}
  2039. if (config.preJax) {
  2040. if (typeof(config.preJax) === "string") {config.preJax = new RegExp(config.preJax+"$")}
  2041. preJax = pre.nodeValue.match(config.preJax);
  2042. }
  2043. if (config.postJax && post) {
  2044. if (typeof(config.postJax) === "string") {config.postJax = new RegExp("^"+config.postJax)}
  2045. postJax = post.nodeValue.match(config.postJax);
  2046. }
  2047. if (preJax && (!config.postJax || postJax)) {
  2048. pre.nodeValue = pre.nodeValue.replace
  2049. (config.preJax,(preJax.length > 1? preJax[1] : ""));
  2050. pre = null;
  2051. }
  2052. if (postJax && (!config.preJax || preJax)) {
  2053. post.nodeValue = post.nodeValue.replace
  2054. (config.postJax,(postJax.length > 1? postJax[1] : ""));
  2055. }
  2056. if (pre && !pre.nodeValue.match(/\S/)) {pre = pre.previousSibling}
  2057. }
  2058. if (config.preRemoveClass && pre && pre.className === config.preRemoveClass)
  2059. {script.MathJax.preview = pre}
  2060. script.MathJax.checked = 1;
  2061. },
  2062. processInput: function (state) {
  2063. var jax, STATE = MathJax.ElementJax.STATE;
  2064. var script, prev, m = state.scripts.length;
  2065. try {
  2066. //
  2067. // Loop through the scripts
  2068. //
  2069. while (state.i < m) {
  2070. script = state.scripts[state.i]; if (!script) {state.i++; continue}
  2071. //
  2072. // Remove previous error marker, if any
  2073. //
  2074. prev = script.previousSibling;
  2075. if (prev && prev.className === "MathJax_Error") {prev.parentNode.removeChild(prev)}
  2076. //
  2077. // Check if already processed or needs processing
  2078. //
  2079. if (!script.parentNode || !script.MathJax || script.MathJax.state === STATE.PROCESSED) {state.i++; continue};
  2080. if (!script.MathJax.elementJax || script.MathJax.state === STATE.UPDATE) {
  2081. this.checkScriptSiblings(script); // remove preJax/postJax etc.
  2082. var type = script.type.replace(/ *;(.|\s)*/,""); // the input jax type
  2083. var input = this.inputJax[type]; // the input jax itself
  2084. jax = input.Process(script,state); // run the input jax
  2085. if (typeof jax === 'function') { // if a callback was returned
  2086. if (jax.called) continue; // go back and call Process() again
  2087. this.RestartAfter(jax); // wait for the callback
  2088. }
  2089. jax = jax.Attach(script,input.id); // register the jax on the script
  2090. this.saveScript(jax,state,script,STATE); // add script to state
  2091. this.postInputHooks.Execute(jax,input.id,script); // run global jax filters
  2092. } else if (script.MathJax.state === STATE.OUTPUT) {
  2093. this.saveScript(script.MathJax.elementJax,state,script,STATE); // add script to state
  2094. }
  2095. //
  2096. // Go on to the next script, and check if we need to update the processing message
  2097. //
  2098. state.i++; var now = new Date().getTime();
  2099. if (now - state.start > this.processUpdateTime && state.i < state.scripts.length)
  2100. {state.start = now; this.RestartAfter(MathJax.Callback.Delay(1))}
  2101. }
  2102. } catch (err) {return this.processError(err,state,"Input")}
  2103. //
  2104. // Put up final message, reset the state and return
  2105. //
  2106. if (state.scripts.length && this.config.showProcessingMessages)
  2107. {MathJax.Message.Set(["ProcessMath","Processing math: %1%%",100],0)}
  2108. state.start = new Date().getTime(); state.i = state.j = 0;
  2109. return null;
  2110. },
  2111. postInputHooks: MathJax.Callback.Hooks(true), // hooks to run after element jax is created
  2112. saveScript: function (jax,state,script,STATE) {
  2113. //
  2114. // Check that output jax exists
  2115. //
  2116. if (!this.outputJax[jax.mimeType]) {
  2117. script.MathJax.state = STATE.UPDATE;
  2118. throw Error("No output jax registered for "+jax.mimeType);
  2119. }
  2120. //
  2121. // Record the output jax
  2122. // and put this script in the queue for that jax
  2123. //
  2124. jax.outputJax = this.outputJax[jax.mimeType][0].id;
  2125. if (!state.jax[jax.outputJax]) {
  2126. if (state.jaxIDs.length === 0) {
  2127. // use original array until we know there are more (rather than two copies)
  2128. state.jax[jax.outputJax] = state.scripts;
  2129. } else {
  2130. if (state.jaxIDs.length === 1) // get the script so far for the existing jax
  2131. {state.jax[state.jaxIDs[0]] = state.scripts.slice(0,state.i)}
  2132. state.jax[jax.outputJax] = []; // start a new array for the new jax
  2133. }
  2134. state.jaxIDs.push(jax.outputJax); // save the ID of the jax
  2135. }
  2136. if (state.jaxIDs.length > 1) {state.jax[jax.outputJax].push(script)}
  2137. //
  2138. // Mark script as needing output
  2139. //
  2140. script.MathJax.state = STATE.OUTPUT;
  2141. },
  2142. //
  2143. // Pre- and post-process scripts by jax
  2144. // (to get scaling factors, hide/show output, and so on)
  2145. // Since this can cause the jax to load, we need to trap restarts
  2146. //
  2147. prepareOutput: function (state,method) {
  2148. while (state.j < state.jaxIDs.length) {
  2149. var id = state.jaxIDs[state.j], JAX = MathJax.OutputJax[id];
  2150. if (JAX[method]) {
  2151. try {
  2152. var result = JAX[method](state);
  2153. if (typeof result === 'function') {
  2154. if (result.called) continue; // go back and try again
  2155. this.RestartAfter(result);
  2156. }
  2157. } catch (err) {
  2158. if (!err.restart) {
  2159. MathJax.Message.Set(["PrepError","Error preparing %1 output (%2)",id,method],null,600);
  2160. MathJax.Hub.lastPrepError = err;
  2161. state.j++;
  2162. }
  2163. return MathJax.Callback.After(["prepareOutput",this,state,method],err.restart);
  2164. }
  2165. }
  2166. state.j++;
  2167. }
  2168. return null;
  2169. },
  2170. processOutput: function (state) {
  2171. var result, STATE = MathJax.ElementJax.STATE, script, m = state.scripts.length;
  2172. try {
  2173. //
  2174. // Loop through the scripts
  2175. //
  2176. while (state.i < m) {
  2177. //
  2178. // Check that there is an element jax
  2179. //
  2180. script = state.scripts[state.i];
  2181. if (!script || !script.parentNode || !script.MathJax || script.MathJax.error) {state.i++; continue}
  2182. var jax = script.MathJax.elementJax; if (!jax) {state.i++; continue}
  2183. //
  2184. // Call the output Jax's Process method (which will be its Translate()
  2185. // method once loaded). Mark it as complete and remove the preview unless
  2186. // the Process() call returns an explicit false value (in which case, it will
  2187. // handle this later during the postProcess phase, as HTML-CSS does).
  2188. //
  2189. result = MathJax.OutputJax[jax.outputJax].Process(script,state);
  2190. if (result !== false) {
  2191. script.MathJax.state = STATE.PROCESSED;
  2192. if (script.MathJax.preview) {
  2193. script.MathJax.preview.innerHTML = "";
  2194. script.MathJax.preview.style.display = "none";
  2195. }
  2196. //
  2197. // Signal that new math is available
  2198. //
  2199. this.signal.Post(["New Math",jax.inputID]); // FIXME: wait for this? (i.e., restart if returns uncalled callback)
  2200. }
  2201. //
  2202. // Go on to next math expression
  2203. //
  2204. state.i++;
  2205. //
  2206. // Update the processing message, if needed
  2207. //
  2208. var now = new Date().getTime();
  2209. if (now - state.start > this.processUpdateTime && state.i < state.scripts.length)
  2210. {state.start = now; this.RestartAfter(MathJax.Callback.Delay(this.processUpdateDelay))}
  2211. }
  2212. } catch (err) {return this.processError(err,state,"Output")}
  2213. //
  2214. // Put up the typesetting-complete message
  2215. //
  2216. if (state.scripts.length && this.config.showProcessingMessages) {
  2217. MathJax.Message.Set(["TypesetMath","Typesetting math: %1%%",100],0);
  2218. MathJax.Message.Clear(0);
  2219. }
  2220. state.i = state.j = 0;
  2221. return null;
  2222. },
  2223. processMessage: function (state,type) {
  2224. var m = Math.floor(state.i/(state.scripts.length)*100);
  2225. var message = (type === "Output" ? ["TypesetMath","Typesetting math: %1%%"] :
  2226. ["ProcessMath","Processing math: %1%%"]);
  2227. if (this.config.showProcessingMessages) {MathJax.Message.Set(message.concat(m),0)}
  2228. },
  2229. processError: function (err,state,type) {
  2230. if (!err.restart) {
  2231. if (!this.config.errorSettings.message) {throw err}
  2232. this.formatError(state.scripts[state.i],err); state.i++;
  2233. }
  2234. this.processMessage(state,type);
  2235. return MathJax.Callback.After(["process"+type,this,state],err.restart);
  2236. },
  2237. formatError: function (script,err) {
  2238. var LOCALIZE = function (id,text,arg1,arg2) {return MathJax.Localization._(id,text,arg1,arg2)};
  2239. //
  2240. // Get the error message, URL, and line, and save it for
  2241. // reporting in the Show Math As Error menu
  2242. //
  2243. var message = LOCALIZE("ErrorMessage","Error: %1",err.message)+"\n";
  2244. if (err.sourceURL||err.fileName) message += "\n"+LOCALIZE("ErrorFile","file: %1",err.sourceURL||err.fileName);
  2245. if (err.line||err.lineNumber) message += "\n"+LOCALIZE("ErrorLine","line: %1",err.line||err.lineNumber);
  2246. message += "\n\n"+LOCALIZE("ErrorTips","Debugging tips: use %1, inspect %2 in the browser console","'unpacked/MathJax.js'","'MathJax.Hub.lastError'");
  2247. script.MathJax.error = MathJax.OutputJax.Error.Jax(message,script);
  2248. if (script.MathJax.elementJax)
  2249. script.MathJax.error.inputID = script.MathJax.elementJax.inputID;
  2250. //
  2251. // Create the [Math Processing Error] span
  2252. //
  2253. var errorSettings = this.config.errorSettings;
  2254. var errorText = LOCALIZE(errorSettings.messageId,errorSettings.message);
  2255. var error = MathJax.HTML.Element("span", {
  2256. className:"MathJax_Error", jaxID:"Error", isMathJax:true,
  2257. id: script.MathJax.error.inputID+"-Frame"
  2258. },[["span",null,errorText]]);
  2259. //
  2260. // Attach the menu events
  2261. //
  2262. MathJax.Ajax.Require("[MathJax]/extensions/MathEvents.js",function () {
  2263. var EVENT = MathJax.Extension.MathEvents.Event,
  2264. HUB = MathJax.Hub;
  2265. error.oncontextmenu = EVENT.Menu;
  2266. error.onmousedown = EVENT.Mousedown;
  2267. error.onkeydown = EVENT.Keydown;
  2268. error.tabIndex = HUB.getTabOrder(HUB.getJaxFor(script));
  2269. });
  2270. //
  2271. // Insert the error into the page and remove any preview
  2272. //
  2273. var node = document.getElementById(error.id);
  2274. if (node) node.parentNode.removeChild(node);
  2275. if (script.parentNode) script.parentNode.insertBefore(error,script);
  2276. if (script.MathJax.preview) {
  2277. script.MathJax.preview.innerHTML = "";
  2278. script.MathJax.preview.style.display = "none";
  2279. }
  2280. //
  2281. // Save the error for debugging purposes
  2282. // Report the error as a signal
  2283. //
  2284. this.lastError = err;
  2285. this.signal.Post(["Math Processing Error",script,err]);
  2286. },
  2287. RestartAfter: function (callback) {
  2288. throw this.Insert(Error("restart"),{restart: MathJax.Callback(callback)});
  2289. },
  2290. elementCallback: function (element,callback) {
  2291. if (callback == null && (MathJax.Object.isArray(element) || typeof element === 'function'))
  2292. {try {MathJax.Callback(element); callback = element; element = null} catch(e) {}}
  2293. if (element == null) {element = this.config.elements || []}
  2294. if (this.isHTMLCollection(element)) {element = this.HTMLCollection2Array(element)}
  2295. if (!MathJax.Object.isArray(element)) {element = [element]}
  2296. element = [].concat(element); // make a copy so the original isn't changed
  2297. for (var i = 0, m = element.length; i < m; i++)
  2298. {if (typeof(element[i]) === 'string') {element[i] = document.getElementById(element[i])}}
  2299. if (!document.body) {document.body = document.getElementsByTagName("body")[0]}
  2300. if (element.length == 0) {element.push(document.body)}
  2301. if (!callback) {callback = {}}
  2302. return {
  2303. count: element.length,
  2304. elements: (element.length === 1 ? element[0] : element),
  2305. callback: callback
  2306. };
  2307. },
  2308. elementScripts: function (element) {
  2309. var scripts = [];
  2310. if (MathJax.Object.isArray(element) || this.isHTMLCollection(element)) {
  2311. for (var i = 0, m = element.length; i < m; i++) {
  2312. var alreadyDone = 0;
  2313. for (var j = 0; j < i && !alreadyDone; j++)
  2314. {alreadyDone = element[j].contains(element[i])}
  2315. if (!alreadyDone) scripts.push.apply(scripts,this.elementScripts(element[i]));
  2316. }
  2317. return scripts;
  2318. }
  2319. if (typeof(element) === 'string') {element = document.getElementById(element)}
  2320. if (!document.body) {document.body = document.getElementsByTagName("body")[0]}
  2321. if (element == null) {element = document.body}
  2322. if (element.tagName != null && element.tagName.toLowerCase() === "script") {return [element]}
  2323. scripts = element.getElementsByTagName("script");
  2324. if (this.msieHTMLCollectionBug) {scripts = this.HTMLCollection2Array(scripts)}
  2325. return scripts;
  2326. },
  2327. //
  2328. // IE8 fails to check "obj instanceof HTMLCollection" for some values of obj.
  2329. //
  2330. isHTMLCollection: function (obj) {
  2331. return ("HTMLCollection" in window && typeof(obj) === "object" && obj instanceof HTMLCollection);
  2332. },
  2333. //
  2334. // IE8 doesn't deal with HTMLCollection as an array, so convert to array
  2335. //
  2336. HTMLCollection2Array: function (nodes) {
  2337. if (!this.msieHTMLCollectionBug) {return [].slice.call(nodes)}
  2338. var NODES = [];
  2339. for (var i = 0, m = nodes.length; i < m; i++) {NODES[i] = nodes[i]}
  2340. return NODES;
  2341. },
  2342. Insert: function (dst,src) {
  2343. for (var id in src) {if (src.hasOwnProperty(id)) {
  2344. // allow for concatenation of arrays?
  2345. if (typeof src[id] === 'object' && !(MathJax.Object.isArray(src[id])) &&
  2346. (typeof dst[id] === 'object' || typeof dst[id] === 'function')) {
  2347. this.Insert(dst[id],src[id]);
  2348. } else {
  2349. dst[id] = src[id];
  2350. }
  2351. }}
  2352. return dst;
  2353. },
  2354. getTabOrder: function(script) {
  2355. return this.config.menuSettings.inTabOrder ? 0 : -1;
  2356. },
  2357. // Old browsers (e.g. Internet Explorer <= 8) do not support trim().
  2358. SplitList: ("trim" in String.prototype ?
  2359. function (list) {return list.trim().split(/\s+/)} :
  2360. function (list) {return list.replace(/^\s+/,'').
  2361. replace(/\s+$/,'').split(/\s+/)})
  2362. };
  2363. MathJax.Hub.Insert(MathJax.Hub.config.styles,MathJax.Message.styles);
  2364. MathJax.Hub.Insert(MathJax.Hub.config.styles,{".MathJax_Error":MathJax.Hub.config.errorSettings.style});
  2365. //
  2366. // Storage area for extensions and preprocessors
  2367. //
  2368. MathJax.Extension = {};
  2369. //
  2370. // Hub Startup code
  2371. //
  2372. MathJax.Hub.Configured = MathJax.Callback({}); // called when configuration is complete
  2373. MathJax.Hub.Startup = {
  2374. script: "", // the startup script from the SCRIPT call that loads MathJax.js
  2375. queue: MathJax.Callback.Queue(), // Queue used for startup actions
  2376. signal: MathJax.Callback.Signal("Startup"), // Signal used for startup events
  2377. params: {},
  2378. //
  2379. // Load the configuration files
  2380. //
  2381. Config: function () {
  2382. this.queue.Push(["Post",this.signal,"Begin Config"]);
  2383. //
  2384. // Make sure root is set before loading any files
  2385. //
  2386. if (MathJax.AuthorConfig && MathJax.AuthorConfig.root)
  2387. MathJax.Ajax.config.root = MathJax.AuthorConfig.root;
  2388. //
  2389. // If a locale is given as a parameter,
  2390. // set the locale and the default menu value for the locale
  2391. //
  2392. if (this.params.locale) {
  2393. MathJax.Localization.resetLocale(this.params.locale);
  2394. MathJax.Hub.config.menuSettings.locale = this.params.locale;
  2395. }
  2396. //
  2397. // Run the config files, if any are given in the parameter list
  2398. //
  2399. if (this.params.config) {
  2400. var files = this.params.config.split(/,/);
  2401. for (var i = 0, m = files.length; i < m; i++) {
  2402. if (!files[i].match(/\.js$/)) {files[i] += ".js"}
  2403. this.queue.Push(["Require",MathJax.Ajax,this.URL("config",files[i])]);
  2404. }
  2405. }
  2406. //
  2407. // Perform author configuration from in-line MathJax = {...}
  2408. //
  2409. this.queue.Push(["Config",MathJax.Hub,MathJax.AuthorConfig]);
  2410. //
  2411. // Run the deprecated configuration script, if any (ignoring return value)
  2412. // Wait for the startup delay signal
  2413. // Run the mathjax-config blocks
  2414. // Load the files in the configuration's config array
  2415. //
  2416. if (this.script.match(/\S/)) {this.queue.Push(this.script+";\n1;")}
  2417. this.queue.Push(
  2418. ["ConfigDelay",this],
  2419. ["ConfigBlocks",this],
  2420. [function (THIS) {return THIS.loadArray(MathJax.Hub.config.config,"config",null,true)},this],
  2421. ["Post",this.signal,"End Config"]
  2422. );
  2423. },
  2424. //
  2425. // Return the delay callback
  2426. //
  2427. ConfigDelay: function () {
  2428. var delay = this.params.delayStartupUntil || MathJax.Hub.config.delayStartupUntil;
  2429. if (delay === "onload") {return this.onload}
  2430. if (delay === "configured") {return MathJax.Hub.Configured}
  2431. return delay;
  2432. },
  2433. //
  2434. // Run the scripts of type=text/x-mathjax-config
  2435. //
  2436. ConfigBlocks: function () {
  2437. var scripts = document.getElementsByTagName("script");
  2438. var queue = MathJax.Callback.Queue();
  2439. for (var i = 0, m = scripts.length; i < m; i++) {
  2440. var type = String(scripts[i].type).replace(/ /g,"");
  2441. if (type.match(/^text\/x-mathjax-config(;.*)?$/) && !type.match(/;executed=true/)) {
  2442. scripts[i].type += ";executed=true";
  2443. queue.Push(scripts[i].innerHTML+";\n1;");
  2444. }
  2445. }
  2446. return queue.Push(function () {MathJax.Ajax.config.root = MathJax.Hub.config.root});
  2447. },
  2448. //
  2449. // Read cookie and set up menu defaults
  2450. // (set the locale according to the cookie)
  2451. // (adjust the jax to accommodate renderer preferences)
  2452. //
  2453. Cookie: function () {
  2454. return this.queue.Push(
  2455. ["Post",this.signal,"Begin Cookie"],
  2456. ["Get",MathJax.HTML.Cookie,"menu",MathJax.Hub.config.menuSettings],
  2457. [function (config) {
  2458. var SETTINGS = config.menuSettings;
  2459. if (SETTINGS.locale) MathJax.Localization.resetLocale(SETTINGS.locale);
  2460. var renderer = config.menuSettings.renderer, jax = config.jax;
  2461. if (renderer) {
  2462. var name = "output/"+renderer; jax.sort();
  2463. for (var i = 0, m = jax.length; i < m; i++) {
  2464. if (jax[i].substr(0,7) === "output/") break;
  2465. }
  2466. if (i == m-1) {jax.pop()} else {
  2467. while (i < m) {if (jax[i] === name) {jax.splice(i,1); break}; i++}
  2468. }
  2469. jax.unshift(name);
  2470. }
  2471. if (SETTINGS.CHTMLpreview != null) {
  2472. if (SETTINGS.FastPreview == null) SETTINGS.FastPreview = SETTINGS.CHTMLpreview;
  2473. delete SETTINGS.CHTMLpreview;
  2474. }
  2475. if (SETTINGS.FastPreview && !MathJax.Extension["fast-preview"])
  2476. MathJax.Hub.config.extensions.push("fast-preview.js");
  2477. if (config.menuSettings.assistiveMML && !MathJax.Extension.AssistiveMML)
  2478. MathJax.Hub.config.extensions.push("AssistiveMML.js");
  2479. },MathJax.Hub.config],
  2480. ["Post",this.signal,"End Cookie"]
  2481. );
  2482. },
  2483. //
  2484. // Setup stylesheets and extra styles
  2485. //
  2486. Styles: function () {
  2487. return this.queue.Push(
  2488. ["Post",this.signal,"Begin Styles"],
  2489. ["loadArray",this,MathJax.Hub.config.styleSheets,"config"],
  2490. ["Styles",MathJax.Ajax,MathJax.Hub.config.styles],
  2491. ["Post",this.signal,"End Styles"]
  2492. );
  2493. },
  2494. //
  2495. // Load the input and output jax
  2496. //
  2497. Jax: function () {
  2498. var config = MathJax.Hub.config, jax = MathJax.Hub.outputJax;
  2499. // Save the order of the output jax since they are loading asynchronously
  2500. for (var i = 0, m = config.jax.length, k = 0; i < m; i++) {
  2501. var name = config.jax[i].substr(7);
  2502. if (config.jax[i].substr(0,7) === "output/" && jax.order[name] == null)
  2503. {jax.order[name] = k; k++}
  2504. }
  2505. var queue = MathJax.Callback.Queue();
  2506. return queue.Push(
  2507. ["Post",this.signal,"Begin Jax"],
  2508. ["loadArray",this,config.jax,"jax","config.js"],
  2509. ["Post",this.signal,"End Jax"]
  2510. );
  2511. },
  2512. //
  2513. // Load the extensions
  2514. //
  2515. Extensions: function () {
  2516. var queue = MathJax.Callback.Queue();
  2517. return queue.Push(
  2518. ["Post",this.signal,"Begin Extensions"],
  2519. ["loadArray",this,MathJax.Hub.config.extensions,"extensions"],
  2520. ["Post",this.signal,"End Extensions"]
  2521. );
  2522. },
  2523. //
  2524. // Initialize the Message system
  2525. //
  2526. Message: function () {
  2527. MathJax.Message.Init(true);
  2528. },
  2529. //
  2530. // Set the math menu renderer, if it isn't already
  2531. // (this must come after the jax are loaded)
  2532. //
  2533. Menu: function () {
  2534. var menu = MathJax.Hub.config.menuSettings, jax = MathJax.Hub.outputJax, registered;
  2535. for (var id in jax) {if (jax.hasOwnProperty(id)) {
  2536. if (jax[id].length) {registered = jax[id]; break}
  2537. }}
  2538. if (registered && registered.length) {
  2539. if (menu.renderer && menu.renderer !== registered[0].id)
  2540. {registered.unshift(MathJax.OutputJax[menu.renderer])}
  2541. menu.renderer = registered[0].id;
  2542. }
  2543. },
  2544. //
  2545. // Set the location to the designated hash position
  2546. //
  2547. Hash: function () {
  2548. if (MathJax.Hub.config.positionToHash && document.location.hash &&
  2549. document.body && document.body.scrollIntoView) {
  2550. var name = document.location.hash.substr(1);
  2551. var target = document.getElementById(name);
  2552. if (!target) {
  2553. var a = document.getElementsByTagName("a");
  2554. for (var i = 0, m = a.length; i < m; i++)
  2555. {if (a[i].name === name) {target = a[i]; break}}
  2556. }
  2557. if (target) {
  2558. while (!target.scrollIntoView) {target = target.parentNode}
  2559. target = this.HashCheck(target);
  2560. if (target && target.scrollIntoView)
  2561. {setTimeout(function () {target.scrollIntoView(true)},1)}
  2562. }
  2563. }
  2564. },
  2565. HashCheck: function (target) {
  2566. var jax = MathJax.Hub.getJaxFor(target);
  2567. if (jax && MathJax.OutputJax[jax.outputJax].hashCheck)
  2568. {target = MathJax.OutputJax[jax.outputJax].hashCheck(target)}
  2569. return target;
  2570. },
  2571. //
  2572. // Load the Menu and Zoom code, if it hasn't already been loaded.
  2573. // This is called after the initial typeset, so should no longer be
  2574. // competing with other page loads, but will make these available
  2575. // if needed later on.
  2576. //
  2577. MenuZoom: function () {
  2578. if (MathJax.Hub.config.showMathMenu) {
  2579. if (!MathJax.Extension.MathMenu) {
  2580. setTimeout(
  2581. function () {
  2582. MathJax.Callback.Queue(
  2583. ["Require",MathJax.Ajax,"[MathJax]/extensions/MathMenu.js",{}],
  2584. ["loadDomain",MathJax.Localization,"MathMenu"]
  2585. )
  2586. },1000
  2587. );
  2588. } else {
  2589. setTimeout(
  2590. MathJax.Callback(["loadDomain",MathJax.Localization,"MathMenu"]),
  2591. 1000
  2592. );
  2593. }
  2594. if (!MathJax.Extension.MathZoom) {
  2595. setTimeout(
  2596. MathJax.Callback(["Require",MathJax.Ajax,"[MathJax]/extensions/MathZoom.js",{}]),
  2597. 2000
  2598. );
  2599. }
  2600. }
  2601. },
  2602. //
  2603. // Setup the onload callback
  2604. //
  2605. onLoad: function () {
  2606. var onload = this.onload =
  2607. MathJax.Callback(function () {MathJax.Hub.Startup.signal.Post("onLoad")});
  2608. if (document.body && document.readyState)
  2609. if (MathJax.Hub.Browser.isMSIE) {
  2610. // IE can change from loading to interactive before
  2611. // full page is ready, so go with complete (even though
  2612. // that means we may have to wait longer).
  2613. if (document.readyState === "complete") {return [onload]}
  2614. } else if (document.readyState !== "loading") {return [onload]}
  2615. if (window.addEventListener) {
  2616. window.addEventListener("load",onload,false);
  2617. if (!this.params.noDOMContentEvent)
  2618. {window.addEventListener("DOMContentLoaded",onload,false)}
  2619. }
  2620. else if (window.attachEvent) {window.attachEvent("onload",onload)}
  2621. else {window.onload = onload}
  2622. return onload;
  2623. },
  2624. //
  2625. // Perform the initial typesetting (or skip if configuration says to)
  2626. //
  2627. Typeset: function (element,callback) {
  2628. if (MathJax.Hub.config.skipStartupTypeset) {return function () {}}
  2629. return this.queue.Push(
  2630. ["Post",this.signal,"Begin Typeset"],
  2631. ["Typeset",MathJax.Hub,element,callback],
  2632. ["Post",this.signal,"End Typeset"]
  2633. );
  2634. },
  2635. //
  2636. // Create a URL in the MathJax hierarchy
  2637. //
  2638. URL: function (dir,name) {
  2639. if (!name.match(/^([a-z]+:\/\/|\[|\/)/)) {name = "[MathJax]/"+dir+"/"+name}
  2640. return name;
  2641. },
  2642. //
  2643. // Load an array of files, waiting for all of them
  2644. // to be loaded before going on
  2645. //
  2646. loadArray: function (files,dir,name,synchronous) {
  2647. if (files) {
  2648. if (!MathJax.Object.isArray(files)) {files = [files]}
  2649. if (files.length) {
  2650. var queue = MathJax.Callback.Queue(), callback = {}, file;
  2651. for (var i = 0, m = files.length; i < m; i++) {
  2652. file = this.URL(dir,files[i]);
  2653. if (name) {file += "/" + name}
  2654. if (synchronous) {queue.Push(["Require",MathJax.Ajax,file,callback])}
  2655. else {queue.Push(MathJax.Ajax.Require(file,callback))}
  2656. }
  2657. return queue.Push({}); // wait for everything to finish
  2658. }
  2659. }
  2660. return null;
  2661. }
  2662. };
  2663. /**********************************************************/
  2664. (function (BASENAME) {
  2665. var BASE = window[BASENAME], ROOT = "["+BASENAME+"]";
  2666. var HUB = BASE.Hub, AJAX = BASE.Ajax, CALLBACK = BASE.Callback;
  2667. var JAX = MathJax.Object.Subclass({
  2668. JAXFILE: "jax.js",
  2669. require: null, // array of files to load before jax.js is complete
  2670. config: {},
  2671. //
  2672. // Make a subclass and return an instance of it.
  2673. // (FIXME: should we replace config with a copy of the constructor's
  2674. // config? Otherwise all subclasses share the same config structure.)
  2675. //
  2676. Init: function (def,cdef) {
  2677. if (arguments.length === 0) {return this}
  2678. return (this.constructor.Subclass(def,cdef))();
  2679. },
  2680. //
  2681. // Augment by merging with class definition (not replacing)
  2682. //
  2683. Augment: function (def,cdef) {
  2684. var cObject = this.constructor, ndef = {};
  2685. if (def != null) {
  2686. for (var id in def) {if (def.hasOwnProperty(id)) {
  2687. if (typeof def[id] === "function")
  2688. {cObject.protoFunction(id,def[id])} else {ndef[id] = def[id]}
  2689. }}
  2690. // MSIE doesn't list toString even if it is not native so handle it separately
  2691. if (def.toString !== cObject.prototype.toString && def.toString !== {}.toString)
  2692. {cObject.protoFunction('toString',def.toString)}
  2693. }
  2694. HUB.Insert(cObject.prototype,ndef);
  2695. cObject.Augment(null,cdef);
  2696. return this;
  2697. },
  2698. Translate: function (script,state) {
  2699. throw Error(this.directory+"/"+this.JAXFILE+" failed to define the Translate() method");
  2700. },
  2701. Register: function (mimetype) {},
  2702. Config: function () {
  2703. this.config = HUB.CombineConfig(this.id,this.config);
  2704. if (this.config.Augment) {this.Augment(this.config.Augment)}
  2705. },
  2706. Startup: function () {},
  2707. loadComplete: function (file) {
  2708. if (file === "config.js") {
  2709. return AJAX.loadComplete(this.directory+"/"+file);
  2710. } else {
  2711. var queue = CALLBACK.Queue();
  2712. queue.Push(
  2713. HUB.Register.StartupHook("End Config",{}), // wait until config complete
  2714. ["Post",HUB.Startup.signal,this.id+" Jax Config"],
  2715. ["Config",this],
  2716. ["Post",HUB.Startup.signal,this.id+" Jax Require"],
  2717. // Config may set the required and extensions array,
  2718. // so use functions to delay making the reference until needed
  2719. [function (THIS) {return MathJax.Hub.Startup.loadArray(THIS.require,this.directory)},this],
  2720. [function (config,id) {return MathJax.Hub.Startup.loadArray(config.extensions,"extensions/"+id)},this.config||{},this.id],
  2721. ["Post",HUB.Startup.signal,this.id+" Jax Startup"],
  2722. ["Startup",this],
  2723. ["Post",HUB.Startup.signal,this.id+" Jax Ready"]
  2724. );
  2725. if (this.copyTranslate) {
  2726. queue.Push(
  2727. [function (THIS) {
  2728. THIS.preProcess = THIS.preTranslate;
  2729. THIS.Process = THIS.Translate;
  2730. THIS.postProcess = THIS.postTranslate;
  2731. },this.constructor.prototype]
  2732. );
  2733. }
  2734. return queue.Push(["loadComplete",AJAX,this.directory+"/"+file]);
  2735. }
  2736. }
  2737. },{
  2738. id: "Jax",
  2739. version: "2.7.2",
  2740. directory: ROOT+"/jax",
  2741. extensionDir: ROOT+"/extensions"
  2742. });
  2743. /***********************************/
  2744. BASE.InputJax = JAX.Subclass({
  2745. elementJax: "mml", // the element jax to load for this input jax
  2746. sourceMenuTitle: /*_(MathMenu)*/ ["Original","Original Form"],
  2747. copyTranslate: true,
  2748. Process: function (script,state) {
  2749. var queue = CALLBACK.Queue(), file;
  2750. // Load any needed element jax
  2751. var jax = this.elementJax; if (!BASE.Object.isArray(jax)) {jax = [jax]}
  2752. for (var i = 0, m = jax.length; i < m; i++) {
  2753. file = BASE.ElementJax.directory+"/"+jax[i]+"/"+this.JAXFILE;
  2754. if (!this.require) {this.require = []}
  2755. else if (!BASE.Object.isArray(this.require)) {this.require = [this.require]};
  2756. this.require.push(file); // so Startup will wait for it to be loaded
  2757. queue.Push(AJAX.Require(file));
  2758. }
  2759. // Load the input jax
  2760. file = this.directory+"/"+this.JAXFILE;
  2761. var load = queue.Push(AJAX.Require(file));
  2762. if (!load.called) {
  2763. this.constructor.prototype.Process = function () {
  2764. if (!load.called) {return load}
  2765. throw Error(file+" failed to load properly");
  2766. }
  2767. }
  2768. // Load the associated output jax
  2769. jax = HUB.outputJax["jax/"+jax[0]];
  2770. if (jax) {queue.Push(AJAX.Require(jax[0].directory+"/"+this.JAXFILE))}
  2771. return queue.Push({});
  2772. },
  2773. needsUpdate: function (jax) {
  2774. var script = jax.SourceElement();
  2775. return (jax.originalText !== BASE.HTML.getScript(script));
  2776. },
  2777. Register: function (mimetype) {
  2778. if (!HUB.inputJax) {HUB.inputJax = {}}
  2779. HUB.inputJax[mimetype] = this;
  2780. }
  2781. },{
  2782. id: "InputJax",
  2783. version: "2.7.2",
  2784. directory: JAX.directory+"/input",
  2785. extensionDir: JAX.extensionDir
  2786. });
  2787. /***********************************/
  2788. BASE.OutputJax = JAX.Subclass({
  2789. copyTranslate: true,
  2790. preProcess: function (state) {
  2791. var load, file = this.directory+"/"+this.JAXFILE;
  2792. this.constructor.prototype.preProcess = function (state) {
  2793. if (!load.called) {return load}
  2794. throw Error(file+" failed to load properly");
  2795. }
  2796. load = AJAX.Require(file);
  2797. return load;
  2798. },
  2799. Register: function (mimetype) {
  2800. var jax = HUB.outputJax;
  2801. if (!jax[mimetype]) {jax[mimetype] = []}
  2802. // If the output jax is earlier in the original configuration list, put it first here
  2803. if (jax[mimetype].length && (this.id === HUB.config.menuSettings.renderer ||
  2804. (jax.order[this.id]||0) < (jax.order[jax[mimetype][0].id]||0)))
  2805. {jax[mimetype].unshift(this)} else {jax[mimetype].push(this)}
  2806. // Make sure the element jax is loaded before Startup is called
  2807. if (!this.require) {this.require = []}
  2808. else if (!BASE.Object.isArray(this.require)) {this.require = [this.require]};
  2809. this.require.push(BASE.ElementJax.directory+"/"+(mimetype.split(/\//)[1])+"/"+this.JAXFILE);
  2810. },
  2811. Remove: function (jax) {}
  2812. },{
  2813. id: "OutputJax",
  2814. version: "2.7.2",
  2815. directory: JAX.directory+"/output",
  2816. extensionDir: JAX.extensionDir,
  2817. fontDir: ROOT+(BASE.isPacked?"":"/..")+"/fonts",
  2818. imageDir: ROOT+(BASE.isPacked?"":"/..")+"/images"
  2819. });
  2820. /***********************************/
  2821. BASE.ElementJax = JAX.Subclass({
  2822. // make a subclass, not an instance
  2823. Init: function (def,cdef) {return this.constructor.Subclass(def,cdef)},
  2824. inputJax: null,
  2825. outputJax: null,
  2826. inputID: null,
  2827. originalText: "",
  2828. mimeType: "",
  2829. sourceMenuTitle: /*_(MathMenu)*/ ["MathMLcode","MathML Code"],
  2830. Text: function (text,callback) {
  2831. var script = this.SourceElement();
  2832. BASE.HTML.setScript(script,text);
  2833. script.MathJax.state = this.STATE.UPDATE;
  2834. return HUB.Update(script,callback);
  2835. },
  2836. Reprocess: function (callback) {
  2837. var script = this.SourceElement();
  2838. script.MathJax.state = this.STATE.UPDATE;
  2839. return HUB.Reprocess(script,callback);
  2840. },
  2841. Update: function (callback) {return this.Rerender(callback)},
  2842. Rerender: function (callback) {
  2843. var script = this.SourceElement();
  2844. script.MathJax.state = this.STATE.OUTPUT;
  2845. return HUB.Process(script,callback);
  2846. },
  2847. Remove: function (keep) {
  2848. if (this.hover) {this.hover.clear(this)}
  2849. BASE.OutputJax[this.outputJax].Remove(this);
  2850. if (!keep) {
  2851. HUB.signal.Post(["Remove Math",this.inputID]); // wait for this to finish?
  2852. this.Detach();
  2853. }
  2854. },
  2855. needsUpdate: function () {
  2856. return BASE.InputJax[this.inputJax].needsUpdate(this);
  2857. },
  2858. SourceElement: function () {return document.getElementById(this.inputID)},
  2859. Attach: function (script,inputJax) {
  2860. var jax = script.MathJax.elementJax;
  2861. if (script.MathJax.state === this.STATE.UPDATE) {
  2862. jax.Clone(this);
  2863. } else {
  2864. jax = script.MathJax.elementJax = this;
  2865. if (script.id) {this.inputID = script.id}
  2866. else {script.id = this.inputID = BASE.ElementJax.GetID(); this.newID = 1}
  2867. }
  2868. jax.originalText = BASE.HTML.getScript(script);
  2869. jax.inputJax = inputJax;
  2870. if (jax.root) {jax.root.inputID = jax.inputID}
  2871. return jax;
  2872. },
  2873. Detach: function () {
  2874. var script = this.SourceElement(); if (!script) return;
  2875. try {delete script.MathJax} catch(err) {script.MathJax = null}
  2876. if (this.newID) {script.id = ""}
  2877. },
  2878. Clone: function (jax) {
  2879. var id;
  2880. for (id in this) {
  2881. if (!this.hasOwnProperty(id)) continue;
  2882. if (typeof(jax[id]) === 'undefined' && id !== 'newID') {delete this[id]}
  2883. }
  2884. for (id in jax) {
  2885. if (!jax.hasOwnProperty(id)) continue;
  2886. if (typeof(this[id]) === 'undefined' || (this[id] !== jax[id] && id !== 'inputID'))
  2887. {this[id] = jax[id]}
  2888. }
  2889. }
  2890. },{
  2891. id: "ElementJax",
  2892. version: "2.7.2",
  2893. directory: JAX.directory+"/element",
  2894. extensionDir: JAX.extensionDir,
  2895. ID: 0, // jax counter (for IDs)
  2896. STATE: {
  2897. PENDING: 1, // script is identified as math but not yet processed
  2898. PROCESSED: 2, // script has been processed
  2899. UPDATE: 3, // elementJax should be updated
  2900. OUTPUT: 4 // output should be updated (input is OK)
  2901. },
  2902. GetID: function () {this.ID++; return "MathJax-Element-"+this.ID},
  2903. Subclass: function () {
  2904. var obj = JAX.Subclass.apply(this,arguments);
  2905. obj.loadComplete = this.prototype.loadComplete;
  2906. return obj;
  2907. }
  2908. });
  2909. BASE.ElementJax.prototype.STATE = BASE.ElementJax.STATE;
  2910. //
  2911. // Some "Fake" jax used to allow menu access for "Math Processing Error" messages
  2912. //
  2913. BASE.OutputJax.Error = {
  2914. id: "Error", version: "2.7.2", config: {}, errors: 0,
  2915. ContextMenu: function () {return BASE.Extension.MathEvents.Event.ContextMenu.apply(BASE.Extension.MathEvents.Event,arguments)},
  2916. Mousedown: function () {return BASE.Extension.MathEvents.Event.AltContextMenu.apply(BASE.Extension.MathEvents.Event,arguments)},
  2917. getJaxFromMath: function (math) {return (math.nextSibling.MathJax||{}).error},
  2918. Jax: function (text,script) {
  2919. var jax = MathJax.Hub.inputJax[script.type.replace(/ *;(.|\s)*/,"")];
  2920. this.errors++;
  2921. return {
  2922. inputJax: (jax||{id:"Error"}).id, // Use Error InputJax as fallback
  2923. outputJax: "Error",
  2924. inputID: "MathJax-Error-"+this.errors,
  2925. sourceMenuTitle: /*_(MathMenu)*/ ["ErrorMessage","Error Message"],
  2926. sourceMenuFormat: "Error",
  2927. originalText: MathJax.HTML.getScript(script),
  2928. errorText: text
  2929. }
  2930. }
  2931. };
  2932. BASE.InputJax.Error = {
  2933. id: "Error", version: "2.7.2", config: {},
  2934. sourceMenuTitle: /*_(MathMenu)*/ ["Original","Original Form"]
  2935. };
  2936. })("MathJax");
  2937. /**********************************************************/
  2938. (function (BASENAME) {
  2939. var BASE = window[BASENAME];
  2940. if (!BASE) {BASE = window[BASENAME] = {}}
  2941. var HUB = BASE.Hub; var STARTUP = HUB.Startup; var CONFIG = HUB.config;
  2942. var HEAD = document.head || (document.getElementsByTagName("head")[0]);
  2943. if (!HEAD) {HEAD = document.childNodes[0]};
  2944. var scripts = (document.documentElement || document).getElementsByTagName("script");
  2945. if (scripts.length === 0 && HEAD.namespaceURI)
  2946. scripts = document.getElementsByTagNameNS(HEAD.namespaceURI,"script");
  2947. var namePattern = new RegExp("(^|/)"+BASENAME+"\\.js(\\?.*)?$");
  2948. for (var i = scripts.length-1; i >= 0; i--) {
  2949. if ((scripts[i].src||"").match(namePattern)) {
  2950. STARTUP.script = scripts[i].innerHTML;
  2951. if (RegExp.$2) {
  2952. var params = RegExp.$2.substr(1).split(/\&/);
  2953. for (var j = 0, m = params.length; j < m; j++) {
  2954. var KV = params[j].match(/(.*)=(.*)/);
  2955. if (KV) {STARTUP.params[unescape(KV[1])] = unescape(KV[2])}
  2956. else {STARTUP.params[params[j]] = true}
  2957. }
  2958. }
  2959. CONFIG.root = scripts[i].src.replace(/(^|\/)[^\/]*(\?.*)?$/,'');
  2960. BASE.Ajax.config.root = CONFIG.root;
  2961. BASE.Ajax.params = STARTUP.params;
  2962. break;
  2963. }
  2964. }
  2965. var AGENT = navigator.userAgent;
  2966. var BROWSERS = {
  2967. isMac: (navigator.platform.substr(0,3) === "Mac"),
  2968. isPC: (navigator.platform.substr(0,3) === "Win"),
  2969. isMSIE: ("ActiveXObject" in window && "clipboardData" in window),
  2970. isEdge: ("MSGestureEvent" in window && "chrome" in window &&
  2971. window.chrome.loadTimes == null),
  2972. isFirefox: (!!AGENT.match(/Gecko\//) && !AGENT.match(/like Gecko/)),
  2973. isSafari: (!!AGENT.match(/ (Apple)?WebKit\//) && !AGENT.match(/ like iPhone /) &&
  2974. (!window.chrome || window.chrome.app == null)),
  2975. isChrome: ("chrome" in window && window.chrome.loadTimes != null),
  2976. isOpera: ("opera" in window && window.opera.version != null),
  2977. isKonqueror: ("konqueror" in window && navigator.vendor == "KDE"),
  2978. versionAtLeast: function (v) {
  2979. var bv = (this.version).split('.'); v = (new String(v)).split('.');
  2980. for (var i = 0, m = v.length; i < m; i++)
  2981. {if (bv[i] != v[i]) {return parseInt(bv[i]||"0") >= parseInt(v[i])}}
  2982. return true;
  2983. },
  2984. Select: function (choices) {
  2985. var browser = choices[HUB.Browser];
  2986. if (browser) {return browser(HUB.Browser)}
  2987. return null;
  2988. }
  2989. };
  2990. var xAGENT = AGENT
  2991. .replace(/^Mozilla\/(\d+\.)+\d+ /,"") // remove initial Mozilla, which is never right
  2992. .replace(/[a-z][-a-z0-9._: ]+\/\d+[^ ]*-[^ ]*\.([a-z][a-z])?\d+ /i,"") // remove linux version
  2993. .replace(/Gentoo |Ubuntu\/(\d+\.)*\d+ (\([^)]*\) )?/,""); // special case for these
  2994. HUB.Browser = HUB.Insert(HUB.Insert(new String("Unknown"),{version: "0.0"}),BROWSERS);
  2995. for (var browser in BROWSERS) {if (BROWSERS.hasOwnProperty(browser)) {
  2996. if (BROWSERS[browser] && browser.substr(0,2) === "is") {
  2997. browser = browser.slice(2);
  2998. if (browser === "Mac" || browser === "PC") continue;
  2999. HUB.Browser = HUB.Insert(new String(browser),BROWSERS);
  3000. var VERSION = new RegExp(
  3001. ".*(Version/| Trident/.*; rv:)((?:\\d+\\.)+\\d+)|" + // for Safari, Opera10, and IE11+
  3002. ".*("+browser+")"+(browser == "MSIE" ? " " : "/")+"((?:\\d+\\.)*\\d+)|"+ // for one of the main browsers
  3003. "(?:^|\\(| )([a-z][-a-z0-9._: ]+|(?:Apple)?WebKit)/((?:\\d+\\.)+\\d+)"); // for unrecognized browser
  3004. var MATCH = VERSION.exec(xAGENT) || ["","","","unknown","0.0"];
  3005. HUB.Browser.name = (MATCH[1] != "" ? browser : (MATCH[3] || MATCH[5]));
  3006. HUB.Browser.version = MATCH[2] || MATCH[4] || MATCH[6];
  3007. break;
  3008. }
  3009. }};
  3010. //
  3011. // Initial browser-specific info (e.g., touch up version or name, check for MathPlayer, etc.)
  3012. // Wrap in try/catch just in case of error (see issue #1155).
  3013. //
  3014. try {HUB.Browser.Select({
  3015. Safari: function (browser) {
  3016. var v = parseInt((String(browser.version).split("."))[0]);
  3017. if (v > 85) {browser.webkit = browser.version}
  3018. if (v >= 538) {browser.version = "8.0"}
  3019. else if (v >= 537) {browser.version = "7.0"}
  3020. else if (v >= 536) {browser.version = "6.0"}
  3021. else if (v >= 534) {browser.version = "5.1"}
  3022. else if (v >= 533) {browser.version = "5.0"}
  3023. else if (v >= 526) {browser.version = "4.0"}
  3024. else if (v >= 525) {browser.version = "3.1"}
  3025. else if (v > 500) {browser.version = "3.0"}
  3026. else if (v > 400) {browser.version = "2.0"}
  3027. else if (v > 85) {browser.version = "1.0"}
  3028. browser.webkit = (navigator.appVersion.match(/WebKit\/(\d+)\./))[1];
  3029. browser.isMobile = (navigator.appVersion.match(/Mobile/i) != null);
  3030. browser.noContextMenu = browser.isMobile;
  3031. },
  3032. Firefox: function (browser) {
  3033. if ((browser.version === "0.0" || AGENT.match(/Firefox/) == null) &&
  3034. navigator.product === "Gecko") {
  3035. var rv = AGENT.match(/[\/ ]rv:(\d+\.\d.*?)[\) ]/);
  3036. if (rv) {browser.version = rv[1]}
  3037. else {
  3038. var date = (navigator.buildID||navigator.productSub||"0").substr(0,8);
  3039. if (date >= "20111220") {browser.version = "9.0"}
  3040. else if (date >= "20111120") {browser.version = "8.0"}
  3041. else if (date >= "20110927") {browser.version = "7.0"}
  3042. else if (date >= "20110816") {browser.version = "6.0"}
  3043. else if (date >= "20110621") {browser.version = "5.0"}
  3044. else if (date >= "20110320") {browser.version = "4.0"}
  3045. else if (date >= "20100121") {browser.version = "3.6"}
  3046. else if (date >= "20090630") {browser.version = "3.5"}
  3047. else if (date >= "20080617") {browser.version = "3.0"}
  3048. else if (date >= "20061024") {browser.version = "2.0"}
  3049. }
  3050. }
  3051. browser.isMobile = (navigator.appVersion.match(/Android/i) != null ||
  3052. AGENT.match(/ Fennec\//) != null ||
  3053. AGENT.match(/Mobile/) != null);
  3054. },
  3055. Chrome: function (browser) {
  3056. browser.noContextMenu = browser.isMobile = !!navigator.userAgent.match(/ Mobile[ \/]/);
  3057. },
  3058. Opera: function (browser) {browser.version = opera.version()},
  3059. Edge: function (browser) {
  3060. browser.isMobile = !!navigator.userAgent.match(/ Phone/);
  3061. },
  3062. MSIE: function (browser) {
  3063. browser.isMobile = !!navigator.userAgent.match(/ Phone/);
  3064. browser.isIE9 = !!(document.documentMode && (window.performance || window.msPerformance));
  3065. MathJax.HTML.setScriptBug = !browser.isIE9 || document.documentMode < 9;
  3066. MathJax.Hub.msieHTMLCollectionBug = (document.documentMode < 9);
  3067. //
  3068. // MathPlayer doesn't function properly in IE10, and not at all in IE11,
  3069. // so don't even try to load it.
  3070. //
  3071. if (document.documentMode < 10 && !STARTUP.params.NoMathPlayer) {
  3072. try {
  3073. new ActiveXObject("MathPlayer.Factory.1");
  3074. browser.hasMathPlayer = true;
  3075. } catch (err) {}
  3076. try {
  3077. if (browser.hasMathPlayer) {
  3078. var mathplayer = document.createElement("object");
  3079. mathplayer.id = "mathplayer"; mathplayer.classid = "clsid:32F66A20-7614-11D4-BD11-00104BD3F987";
  3080. HEAD.appendChild(mathplayer);
  3081. document.namespaces.add("m","http://www.w3.org/1998/Math/MathML");
  3082. browser.mpNamespace = true;
  3083. if (document.readyState && (document.readyState === "loading" ||
  3084. document.readyState === "interactive")) {
  3085. document.write('<?import namespace="m" implementation="#MathPlayer">');
  3086. browser.mpImported = true;
  3087. }
  3088. } else {
  3089. // Adding any namespace avoids a crash in IE9 in IE9-standards mode
  3090. // (any reference to document.namespaces before document.readyState is
  3091. // "complete" causes an "unspecified error" to be thrown)
  3092. document.namespaces.add("mjx_IE_fix","http://www.w3.org/1999/xlink");
  3093. }
  3094. } catch (err) {}
  3095. }
  3096. }
  3097. });} catch (err) {
  3098. console.error(err.message);
  3099. }
  3100. HUB.Browser.Select(MathJax.Message.browsers);
  3101. if (BASE.AuthorConfig && typeof BASE.AuthorConfig.AuthorInit === "function") {BASE.AuthorConfig.AuthorInit()}
  3102. HUB.queue = BASE.Callback.Queue();
  3103. HUB.queue.Push(
  3104. ["Post",STARTUP.signal,"Begin"],
  3105. ["Config",STARTUP],
  3106. ["Cookie",STARTUP],
  3107. ["Styles",STARTUP],
  3108. ["Message",STARTUP],
  3109. function () {
  3110. // Do Jax and Extensions in parallel, but wait for them all to complete
  3111. var queue = BASE.Callback.Queue(
  3112. STARTUP.Jax(),
  3113. STARTUP.Extensions()
  3114. );
  3115. return queue.Push({});
  3116. },
  3117. ["Menu",STARTUP],
  3118. STARTUP.onLoad(),
  3119. function () {MathJax.isReady = true}, // indicates that MathJax is ready to process math
  3120. ["Typeset",STARTUP],
  3121. ["Hash",STARTUP],
  3122. ["MenuZoom",STARTUP],
  3123. ["Post",STARTUP.signal,"End"]
  3124. );
  3125. })("MathJax");
  3126. }}