MathJax.js 112 KB

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