jax.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
  2. /* vim: set ts=2 et sw=2 tw=80: */
  3. /*************************************************************
  4. *
  5. * MathJax/jax/input/AsciiMath/jax.js
  6. *
  7. * An Input Jax for AsciiMath notation
  8. * (see http://www1.chapman.edu/~jipsen/mathml/asciimath.html).
  9. *
  10. * Originally adapted for MathJax by David Lippman.
  11. * Additional work done by Davide P. Cervone.
  12. *
  13. * A portion of this file is taken from
  14. * ASCIIMathML.js Version 1.4.7 Aug 30, 2005, (c) Peter Jipsen http://www.chapman.edu/~jipsen
  15. * and is used by permission of Peter Jipsen, who has agreed to allow us to
  16. * release it under the Apache2 license (see below). That portion is indicated
  17. * via comments.
  18. *
  19. * The remainder falls under the copyright that follows.
  20. *
  21. * ---------------------------------------------------------------------
  22. *
  23. * Copyright (c) 2012-2013 The MathJax Consortium
  24. *
  25. * Licensed under the Apache License, Version 2.0 (the "License");
  26. * you may not use this file except in compliance with the License.
  27. * You may obtain a copy of the License at
  28. *
  29. * http://www.apache.org/licenses/LICENSE-2.0
  30. *
  31. * Unless required by applicable law or agreed to in writing, software
  32. * distributed under the License is distributed on an "AS IS" BASIS,
  33. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. * See the License for the specific language governing permissions and
  35. * limitations under the License.
  36. */
  37. (function (ASCIIMATH) {
  38. var MML; // Filled in later
  39. //
  40. // Make a documentFragment work-alike that uses MML objects
  41. // rather than DOM objects.
  42. //
  43. var DOCFRAG = MathJax.Object.Subclass({
  44. firstChild: null,
  45. lastChild: null,
  46. Init: function () {
  47. this.childNodes = [];
  48. },
  49. appendChild: function (node) {
  50. if (node.parent) {node.parent.removeChild(node)}
  51. if (this.lastChild) {this.lastChild.nextSibling = node}
  52. if (!this.firstChild) {this.firstChild = node}
  53. this.childNodes.push(node); node.parent = this;
  54. this.lastChild = node;
  55. return node;
  56. },
  57. removeChild: function (node) {
  58. for (var i = 0, m = this.childNodes.length; i < m; i++)
  59. {if (this.childNodes[i] === node) break}
  60. if (i === m) return;
  61. this.childNodes.splice(i,1);
  62. if (node === this.firstChild) {this.firstChild = node.nextSibling}
  63. if (node === this.lastChild) {
  64. if (!this.childNodes.length) {this.lastChild = null}
  65. else {this.lastChild = this.childNodes[this.childNodes.length-1]}
  66. }
  67. if (i) {this.childNodes[i-1].nextSibling = node.nextSibling}
  68. node.nextSibling = node.parent = null;
  69. return node;
  70. },
  71. replaceChild: function (node,old) {
  72. for (var i = 0, m = this.childNodes.length; i < m; i++)
  73. {if (this.childNodes[i] === old) break}
  74. if (i) {this.childNodes[i-1].nextSibling = node} else {this.firstChild = node}
  75. if (i >= m-1) {this.lastChild = node}
  76. this.childNodes[i] = node; node.nextSibling = old.nextSibling;
  77. old.nextSibling = old.parent = null;
  78. return old;
  79. },
  80. toString: function () {return "{"+this.childNodes.join("")+"}"}
  81. });
  82. var INITASCIIMATH = function () {
  83. MML = MathJax.ElementJax.mml;
  84. var MBASEINIT = MML.mbase.prototype.Init;
  85. //
  86. // Make MML elements looks like DOM elements (add the
  87. // methods that AsciiMath needs)
  88. //
  89. MML.mbase.Augment({
  90. firstChild: null,
  91. lastChild: null,
  92. nodeValue: "",
  93. nextSibling: null,
  94. Init: function () {
  95. var obj = MBASEINIT.apply(this,arguments) || this;
  96. obj.childNodes = obj.data;
  97. obj.nodeName = obj.type;
  98. return obj;
  99. },
  100. appendChild: function (node) {
  101. if (node.parent) {node.parent.removeChild(node)}
  102. var nodes = arguments;
  103. if (node.isa(DOCFRAG)) {
  104. nodes = node.childNodes;
  105. node.data = node.childNodes = [];
  106. node.firstChild = node.lastChild = null;
  107. }
  108. for (var i = 0, m = nodes.length; i < m; i++) {
  109. node = nodes[i];
  110. if (this.lastChild) {this.lastChild.nextSibling = node}
  111. if (!this.firstChild) {this.firstChild = node}
  112. this.Append(node);
  113. this.lastChild = node;
  114. this.nodeValue += node.nodeValue;
  115. }
  116. return node;
  117. },
  118. removeChild: function (node) {
  119. for (var i = 0, m = this.childNodes.length; i < m; i++)
  120. {if (this.childNodes[i] === node) break}
  121. if (i === m) return;
  122. this.childNodes.splice(i,1);
  123. if (node === this.firstChild) {this.firstChild = node.nextSibling}
  124. if (node === this.lastChild) {
  125. if (!this.childNodes.length) {this.lastChild = null}
  126. else {this.lastChild = this.childNodes[this.childNodes.length-1]}
  127. }
  128. if (i) {this.childNodes[i-1].nextSibling = node.nextSibling}
  129. this.nodeValue = "";
  130. for (i = 0, m = this.childNodes.length; i < m; i++)
  131. {this.nodeValue += this.childNodes[i].nodeValue}
  132. node.nextSibling = node.parent = null;
  133. return node;
  134. },
  135. replaceChild: function (node,old) {
  136. for (var i = 0, m = this.childNodes.length; i < m; i++)
  137. {if (this.childNodes[i] === old) break}
  138. // FIXME: make this work with DOCFRAG's?
  139. if (i) {this.childNodes[i-1].nextSibling = node} else {this.firstChild = node}
  140. if (i >= m-1) {this.lastChild = node}
  141. this.SetData(i,node); node.nextSibling = old.nextSibling;
  142. this.nodeValue = "";
  143. for (i = 0, m = this.childNodes.length; i < m; i++)
  144. {this.nodeValue += this.childNodes[i].nodeValue}
  145. old.nextSibling = old.parent = null;
  146. return old;
  147. },
  148. setAttribute: function (name,value) {this[name] = value}
  149. });
  150. };
  151. //
  152. // Set up to isolate ASCIIMathML.js
  153. //
  154. var window = {}; // hide the true window
  155. //
  156. // Hide the true document, and add functions that
  157. // use and produce MML objects instead of DOM objects
  158. //
  159. var document = {
  160. getElementById: true,
  161. createElementNS: function (ns,type) {return MML[type]()},
  162. createTextNode: function (text) {return MML.chars(text).With({nodeValue:text})},
  163. createDocumentFragment: function () {return DOCFRAG()}
  164. };
  165. var navigator = {appName: "MathJax"}; // hide the true navigator object
  166. var i; // avoid global variable used in code below
  167. /******************************************************************
  168. *
  169. * The following section is ASCIIMathML.js Version 1.4.7
  170. * (c) Peter Jipsen, used with permission.
  171. *
  172. * Some sections are commented out to save space in the
  173. * minified version (but that is not strictly necessary).
  174. * A few items are commented out and marked with DPVC comments
  175. * in order to keep the minifier from complaining about the
  176. * coding practices in ASCIIMathML.js
  177. *
  178. * Two sections are modified to include changes from version 2.0.1 of
  179. * ASCIIMathML.js and are marked with comments to that effect. This
  180. * makes this version effectively the same as version 2.0.1, but
  181. * without the overhead of the LaTeX-processing code.
  182. *
  183. ******************************************************************/
  184. /*
  185. ASCIIMathML.js
  186. ==============
  187. This file contains JavaScript functions to convert ASCII math notation
  188. to Presentation MathML. The conversion is done while the (X)HTML page
  189. loads, and should work with Firefox/Mozilla/Netscape 7+ and Internet
  190. Explorer 6+MathPlayer (http://www.dessci.com/en/products/mathplayer/).
  191. Just add the next line to your (X)HTML page with this file in the same folder:
  192. <script type="text/javascript" src="ASCIIMathML.js"></script>
  193. This is a convenient and inexpensive solution for authoring MathML.
  194. Version 1.4.7 Aug 30, 2005, (c) Peter Jipsen http://www.chapman.edu/~jipsen
  195. Latest version at http://www.chapman.edu/~jipsen/mathml/ASCIIMathML.js
  196. For changes see http://www.chapman.edu/~jipsen/mathml/asciimathchanges.txt
  197. If you use it on a webpage, please send the URL to jipsen@chapman.edu
  198. This program is free software; you can redistribute it and/or modify
  199. it under the terms of the GNU General Public License as published by
  200. the Free Software Foundation; either version 2 of the License, or (at
  201. your option) any later version.
  202. This program is distributed in the hope that it will be useful,
  203. but WITHOUT ANY WARRANTY; without even the implied warranty of
  204. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  205. General Public License (at http://www.gnu.org/copyleft/gpl.html)
  206. for more details.
  207. */
  208. //var checkForMathML = true; // check if browser can display MathML
  209. //var notifyIfNoMathML = true; // display note if no MathML capability
  210. //var alertIfNoMathML = true; // show alert box if no MathML capability
  211. var mathcolor = "red"; // change it to "" (to inherit) or any other color
  212. var mathfontfamily = "serif"; // change to "" to inherit (works in IE)
  213. // or another family (e.g. "arial")
  214. var displaystyle = true; // puts limits above and below large operators
  215. var showasciiformulaonhover = true; // helps students learn ASCIIMath
  216. var decimalsign = "."; // change to "," if you like, beware of `(1,2)`!
  217. //var AMdelimiter1 = "`", AMescape1 = "\\\\`"; // can use other characters
  218. //var AMdelimiter2 = "$", AMescape2 = "\\\\\\$", AMdelimiter2regexp = "\\$";
  219. //var doubleblankmathdelimiter = false; // if true, x+1 is equal to `x+1`
  220. // for IE this works only in <!-- -->
  221. //var separatetokens;// has been removed (email me if this is a problem)
  222. var isIE = document.createElementNS==null;
  223. /*
  224. * if (document.getElementById==null)
  225. * alert("This webpage requires a recent browser such as\
  226. * \nMozilla/Netscape 7+ or Internet Explorer 6+MathPlayer")
  227. */
  228. // all further global variables start with "AM"
  229. function AMcreateElementXHTML(t) {
  230. if (isIE) return document.createElement(t);
  231. else return document.createElementNS("http://www.w3.org/1999/xhtml",t);
  232. }
  233. /*
  234. * function AMnoMathMLNote() {
  235. * var nd = AMcreateElementXHTML("h3");
  236. * nd.setAttribute("align","center")
  237. * nd.appendChild(AMcreateElementXHTML("p"));
  238. * nd.appendChild(document.createTextNode("To view the "));
  239. * var an = AMcreateElementXHTML("a");
  240. * an.appendChild(document.createTextNode("ASCIIMathML"));
  241. * an.setAttribute("href","http://www.chapman.edu/~jipsen/asciimath.html");
  242. * nd.appendChild(an);
  243. * nd.appendChild(document.createTextNode(" notation use Internet Explorer 6+"));
  244. * an = AMcreateElementXHTML("a");
  245. * an.appendChild(document.createTextNode("MathPlayer"));
  246. * an.setAttribute("href","http://www.dessci.com/en/products/mathplayer/download.htm");
  247. * nd.appendChild(an);
  248. * nd.appendChild(document.createTextNode(" or Netscape/Mozilla/Firefox"));
  249. * nd.appendChild(AMcreateElementXHTML("p"));
  250. * return nd;
  251. * }
  252. *
  253. * function AMisMathMLavailable() {
  254. * if (navigator.appName.slice(0,8)=="Netscape")
  255. * if (navigator.appVersion.slice(0,1)>="5") return null;
  256. * else return AMnoMathMLNote();
  257. * else if (navigator.appName.slice(0,9)=="Microsoft")
  258. * try {
  259. * var ActiveX = new ActiveXObject("MathPlayer.Factory.1");
  260. * return null;
  261. * } catch (e) {
  262. * return AMnoMathMLNote();
  263. * }
  264. * else return AMnoMathMLNote();
  265. * }
  266. */
  267. // character lists for Mozilla/Netscape fonts
  268. var AMcal = [0xEF35,0x212C,0xEF36,0xEF37,0x2130,0x2131,0xEF38,0x210B,0x2110,0xEF39,0xEF3A,0x2112,0x2133,0xEF3B,0xEF3C,0xEF3D,0xEF3E,0x211B,0xEF3F,0xEF40,0xEF41,0xEF42,0xEF43,0xEF44,0xEF45,0xEF46];
  269. var AMfrk = [0xEF5D,0xEF5E,0x212D,0xEF5F,0xEF60,0xEF61,0xEF62,0x210C,0x2111,0xEF63,0xEF64,0xEF65,0xEF66,0xEF67,0xEF68,0xEF69,0xEF6A,0x211C,0xEF6B,0xEF6C,0xEF6D,0xEF6E,0xEF6F,0xEF70,0xEF71,0x2128];
  270. var AMbbb = [0xEF8C,0xEF8D,0x2102,0xEF8E,0xEF8F,0xEF90,0xEF91,0x210D,0xEF92,0xEF93,0xEF94,0xEF95,0xEF96,0x2115,0xEF97,0x2119,0x211A,0x211D,0xEF98,0xEF99,0xEF9A,0xEF9B,0xEF9C,0xEF9D,0xEF9E,0x2124];
  271. var CONST = 0, UNARY = 1, BINARY = 2, INFIX = 3, LEFTBRACKET = 4,
  272. RIGHTBRACKET = 5, SPACE = 6, UNDEROVER = 7, DEFINITION = 8,
  273. LEFTRIGHT = 9, TEXT = 10; // token types
  274. var AMsqrt = {input:"sqrt", tag:"msqrt", output:"sqrt", tex:null, ttype:UNARY},
  275. AMroot = {input:"root", tag:"mroot", output:"root", tex:null, ttype:BINARY},
  276. AMfrac = {input:"frac", tag:"mfrac", output:"/", tex:null, ttype:BINARY},
  277. AMdiv = {input:"/", tag:"mfrac", output:"/", tex:null, ttype:INFIX},
  278. AMover = {input:"stackrel", tag:"mover", output:"stackrel", tex:null, ttype:BINARY},
  279. AMsub = {input:"_", tag:"msub", output:"_", tex:null, ttype:INFIX},
  280. AMsup = {input:"^", tag:"msup", output:"^", tex:null, ttype:INFIX},
  281. AMtext = {input:"text", tag:"mtext", output:"text", tex:null, ttype:TEXT},
  282. AMmbox = {input:"mbox", tag:"mtext", output:"mbox", tex:null, ttype:TEXT},
  283. AMquote = {input:"\"", tag:"mtext", output:"mbox", tex:null, ttype:TEXT};
  284. var AMsymbols = [
  285. //some greek symbols
  286. {input:"alpha", tag:"mi", output:"\u03B1", tex:null, ttype:CONST},
  287. {input:"beta", tag:"mi", output:"\u03B2", tex:null, ttype:CONST},
  288. {input:"chi", tag:"mi", output:"\u03C7", tex:null, ttype:CONST},
  289. {input:"delta", tag:"mi", output:"\u03B4", tex:null, ttype:CONST},
  290. {input:"Delta", tag:"mo", output:"\u0394", tex:null, ttype:CONST},
  291. {input:"epsi", tag:"mi", output:"\u03B5", tex:"epsilon", ttype:CONST},
  292. {input:"varepsilon", tag:"mi", output:"\u025B", tex:null, ttype:CONST},
  293. {input:"eta", tag:"mi", output:"\u03B7", tex:null, ttype:CONST},
  294. {input:"gamma", tag:"mi", output:"\u03B3", tex:null, ttype:CONST},
  295. {input:"Gamma", tag:"mo", output:"\u0393", tex:null, ttype:CONST},
  296. {input:"iota", tag:"mi", output:"\u03B9", tex:null, ttype:CONST},
  297. {input:"kappa", tag:"mi", output:"\u03BA", tex:null, ttype:CONST},
  298. {input:"lambda", tag:"mi", output:"\u03BB", tex:null, ttype:CONST},
  299. {input:"Lambda", tag:"mo", output:"\u039B", tex:null, ttype:CONST},
  300. {input:"mu", tag:"mi", output:"\u03BC", tex:null, ttype:CONST},
  301. {input:"nu", tag:"mi", output:"\u03BD", tex:null, ttype:CONST},
  302. {input:"omega", tag:"mi", output:"\u03C9", tex:null, ttype:CONST},
  303. {input:"Omega", tag:"mo", output:"\u03A9", tex:null, ttype:CONST},
  304. {input:"phi", tag:"mi", output:"\u03C6", tex:null, ttype:CONST},
  305. {input:"varphi", tag:"mi", output:"\u03D5", tex:null, ttype:CONST},
  306. {input:"Phi", tag:"mo", output:"\u03A6", tex:null, ttype:CONST},
  307. {input:"pi", tag:"mi", output:"\u03C0", tex:null, ttype:CONST},
  308. {input:"Pi", tag:"mo", output:"\u03A0", tex:null, ttype:CONST},
  309. {input:"psi", tag:"mi", output:"\u03C8", tex:null, ttype:CONST},
  310. {input:"Psi", tag:"mi", output:"\u03A8", tex:null, ttype:CONST},
  311. {input:"rho", tag:"mi", output:"\u03C1", tex:null, ttype:CONST},
  312. {input:"sigma", tag:"mi", output:"\u03C3", tex:null, ttype:CONST},
  313. {input:"Sigma", tag:"mo", output:"\u03A3", tex:null, ttype:CONST},
  314. {input:"tau", tag:"mi", output:"\u03C4", tex:null, ttype:CONST},
  315. {input:"theta", tag:"mi", output:"\u03B8", tex:null, ttype:CONST},
  316. {input:"vartheta", tag:"mi", output:"\u03D1", tex:null, ttype:CONST},
  317. {input:"Theta", tag:"mo", output:"\u0398", tex:null, ttype:CONST},
  318. {input:"upsilon", tag:"mi", output:"\u03C5", tex:null, ttype:CONST},
  319. {input:"xi", tag:"mi", output:"\u03BE", tex:null, ttype:CONST},
  320. {input:"Xi", tag:"mo", output:"\u039E", tex:null, ttype:CONST},
  321. {input:"zeta", tag:"mi", output:"\u03B6", tex:null, ttype:CONST},
  322. //binary operation symbols
  323. {input:"*", tag:"mo", output:"\u22C5", tex:"cdot", ttype:CONST},
  324. {input:"**", tag:"mo", output:"\u22C6", tex:"star", ttype:CONST},
  325. {input:"//", tag:"mo", output:"/", tex:null, ttype:CONST},
  326. {input:"\\\\", tag:"mo", output:"\\", tex:"backslash", ttype:CONST},
  327. {input:"setminus", tag:"mo", output:"\\", tex:null, ttype:CONST},
  328. {input:"xx", tag:"mo", output:"\u00D7", tex:"times", ttype:CONST},
  329. {input:"-:", tag:"mo", output:"\u00F7", tex:"divide", ttype:CONST},
  330. {input:"@", tag:"mo", output:"\u2218", tex:"circ", ttype:CONST},
  331. {input:"o+", tag:"mo", output:"\u2295", tex:"oplus", ttype:CONST},
  332. {input:"ox", tag:"mo", output:"\u2297", tex:"otimes", ttype:CONST},
  333. {input:"o.", tag:"mo", output:"\u2299", tex:"odot", ttype:CONST},
  334. {input:"sum", tag:"mo", output:"\u2211", tex:null, ttype:UNDEROVER},
  335. {input:"prod", tag:"mo", output:"\u220F", tex:null, ttype:UNDEROVER},
  336. {input:"^^", tag:"mo", output:"\u2227", tex:"wedge", ttype:CONST},
  337. {input:"^^^", tag:"mo", output:"\u22C0", tex:"bigwedge", ttype:UNDEROVER},
  338. {input:"vv", tag:"mo", output:"\u2228", tex:"vee", ttype:CONST},
  339. {input:"vvv", tag:"mo", output:"\u22C1", tex:"bigvee", ttype:UNDEROVER},
  340. {input:"nn", tag:"mo", output:"\u2229", tex:"cap", ttype:CONST},
  341. {input:"nnn", tag:"mo", output:"\u22C2", tex:"bigcap", ttype:UNDEROVER},
  342. {input:"uu", tag:"mo", output:"\u222A", tex:"cup", ttype:CONST},
  343. {input:"uuu", tag:"mo", output:"\u22C3", tex:"bigcup", ttype:UNDEROVER},
  344. //binary relation symbols
  345. {input:"!=", tag:"mo", output:"\u2260", tex:"ne", ttype:CONST},
  346. {input:":=", tag:"mo", output:":=", tex:null, ttype:CONST},
  347. {input:"lt", tag:"mo", output:"<", tex:null, ttype:CONST},
  348. {input:"<=", tag:"mo", output:"\u2264", tex:"le", ttype:CONST},
  349. {input:"lt=", tag:"mo", output:"\u2264", tex:"leq", ttype:CONST},
  350. {input:">=", tag:"mo", output:"\u2265", tex:"ge", ttype:CONST},
  351. {input:"geq", tag:"mo", output:"\u2265", tex:null, ttype:CONST},
  352. {input:"-<", tag:"mo", output:"\u227A", tex:"prec", ttype:CONST},
  353. {input:"-lt", tag:"mo", output:"\u227A", tex:null, ttype:CONST},
  354. {input:">-", tag:"mo", output:"\u227B", tex:"succ", ttype:CONST},
  355. {input:"in", tag:"mo", output:"\u2208", tex:null, ttype:CONST},
  356. {input:"!in", tag:"mo", output:"\u2209", tex:"notin", ttype:CONST},
  357. {input:"sub", tag:"mo", output:"\u2282", tex:"subset", ttype:CONST},
  358. {input:"sup", tag:"mo", output:"\u2283", tex:"supset", ttype:CONST},
  359. {input:"sube", tag:"mo", output:"\u2286", tex:"subseteq", ttype:CONST},
  360. {input:"supe", tag:"mo", output:"\u2287", tex:"supseteq", ttype:CONST},
  361. {input:"-=", tag:"mo", output:"\u2261", tex:"equiv", ttype:CONST},
  362. {input:"~=", tag:"mo", output:"\u2245", tex:"cong", ttype:CONST},
  363. {input:"~~", tag:"mo", output:"\u2248", tex:"approx", ttype:CONST},
  364. {input:"prop", tag:"mo", output:"\u221D", tex:"propto", ttype:CONST},
  365. //logical symbols
  366. {input:"and", tag:"mtext", output:"and", tex:null, ttype:SPACE},
  367. {input:"or", tag:"mtext", output:"or", tex:null, ttype:SPACE},
  368. {input:"not", tag:"mo", output:"\u00AC", tex:"neg", ttype:CONST},
  369. {input:"=>", tag:"mo", output:"\u21D2", tex:"implies", ttype:CONST},
  370. {input:"if", tag:"mo", output:"if", tex:null, ttype:SPACE},
  371. {input:"<=>", tag:"mo", output:"\u21D4", tex:"iff", ttype:CONST},
  372. {input:"AA", tag:"mo", output:"\u2200", tex:"forall", ttype:CONST},
  373. {input:"EE", tag:"mo", output:"\u2203", tex:"exists", ttype:CONST},
  374. {input:"_|_", tag:"mo", output:"\u22A5", tex:"bot", ttype:CONST},
  375. {input:"TT", tag:"mo", output:"\u22A4", tex:"top", ttype:CONST},
  376. {input:"|--", tag:"mo", output:"\u22A2", tex:"vdash", ttype:CONST},
  377. {input:"|==", tag:"mo", output:"\u22A8", tex:"models", ttype:CONST},
  378. //grouping brackets
  379. {input:"(", tag:"mo", output:"(", tex:null, ttype:LEFTBRACKET},
  380. {input:")", tag:"mo", output:")", tex:null, ttype:RIGHTBRACKET},
  381. {input:"[", tag:"mo", output:"[", tex:null, ttype:LEFTBRACKET},
  382. {input:"]", tag:"mo", output:"]", tex:null, ttype:RIGHTBRACKET},
  383. {input:"{", tag:"mo", output:"{", tex:null, ttype:LEFTBRACKET},
  384. {input:"}", tag:"mo", output:"}", tex:null, ttype:RIGHTBRACKET},
  385. {input:"|", tag:"mo", output:"|", tex:null, ttype:LEFTRIGHT},
  386. //{input:"||", tag:"mo", output:"||", tex:null, ttype:LEFTRIGHT},
  387. {input:"(:", tag:"mo", output:"\u2329", tex:"langle", ttype:LEFTBRACKET},
  388. {input:":)", tag:"mo", output:"\u232A", tex:"rangle", ttype:RIGHTBRACKET},
  389. {input:"<<", tag:"mo", output:"\u2329", tex:null, ttype:LEFTBRACKET},
  390. {input:">>", tag:"mo", output:"\u232A", tex:null, ttype:RIGHTBRACKET},
  391. {input:"{:", tag:"mo", output:"{:", tex:null, ttype:LEFTBRACKET, invisible:true},
  392. {input:":}", tag:"mo", output:":}", tex:null, ttype:RIGHTBRACKET, invisible:true},
  393. //miscellaneous symbols
  394. {input:"int", tag:"mo", output:"\u222B", tex:null, ttype:CONST},
  395. {input:"dx", tag:"mi", output:"{:d x:}", tex:null, ttype:DEFINITION},
  396. {input:"dy", tag:"mi", output:"{:d y:}", tex:null, ttype:DEFINITION},
  397. {input:"dz", tag:"mi", output:"{:d z:}", tex:null, ttype:DEFINITION},
  398. {input:"dt", tag:"mi", output:"{:d t:}", tex:null, ttype:DEFINITION},
  399. {input:"oint", tag:"mo", output:"\u222E", tex:null, ttype:CONST},
  400. {input:"del", tag:"mo", output:"\u2202", tex:"partial", ttype:CONST},
  401. {input:"grad", tag:"mo", output:"\u2207", tex:"nabla", ttype:CONST},
  402. {input:"+-", tag:"mo", output:"\u00B1", tex:"pm", ttype:CONST},
  403. {input:"O/", tag:"mo", output:"\u2205", tex:"emptyset", ttype:CONST},
  404. {input:"oo", tag:"mo", output:"\u221E", tex:"infty", ttype:CONST},
  405. {input:"aleph", tag:"mo", output:"\u2135", tex:null, ttype:CONST},
  406. {input:"...", tag:"mo", output:"...", tex:"ldots", ttype:CONST},
  407. {input:":.", tag:"mo", output:"\u2234", tex:"therefore", ttype:CONST},
  408. {input:"/_", tag:"mo", output:"\u2220", tex:"angle", ttype:CONST},
  409. {input:"\\ ", tag:"mo", output:"\u00A0", tex:null, ttype:CONST},
  410. {input:"quad", tag:"mo", output:"\u00A0\u00A0", tex:null, ttype:CONST},
  411. {input:"qquad", tag:"mo", output:"\u00A0\u00A0\u00A0\u00A0", tex:null, ttype:CONST},
  412. {input:"cdots", tag:"mo", output:"\u22EF", tex:null, ttype:CONST},
  413. {input:"vdots", tag:"mo", output:"\u22EE", tex:null, ttype:CONST},
  414. {input:"ddots", tag:"mo", output:"\u22F1", tex:null, ttype:CONST},
  415. {input:"diamond", tag:"mo", output:"\u22C4", tex:null, ttype:CONST},
  416. {input:"square", tag:"mo", output:"\u25A1", tex:null, ttype:CONST},
  417. {input:"|__", tag:"mo", output:"\u230A", tex:"lfloor", ttype:CONST},
  418. {input:"__|", tag:"mo", output:"\u230B", tex:"rfloor", ttype:CONST},
  419. {input:"|~", tag:"mo", output:"\u2308", tex:"lceiling", ttype:CONST},
  420. {input:"~|", tag:"mo", output:"\u2309", tex:"rceiling", ttype:CONST},
  421. {input:"CC", tag:"mo", output:"\u2102", tex:null, ttype:CONST},
  422. {input:"NN", tag:"mo", output:"\u2115", tex:null, ttype:CONST},
  423. {input:"QQ", tag:"mo", output:"\u211A", tex:null, ttype:CONST},
  424. {input:"RR", tag:"mo", output:"\u211D", tex:null, ttype:CONST},
  425. {input:"ZZ", tag:"mo", output:"\u2124", tex:null, ttype:CONST},
  426. {input:"f", tag:"mi", output:"f", tex:null, ttype:UNARY, func:true},
  427. {input:"g", tag:"mi", output:"g", tex:null, ttype:UNARY, func:true},
  428. //standard functions
  429. {input:"lim", tag:"mo", output:"lim", tex:null, ttype:UNDEROVER},
  430. {input:"Lim", tag:"mo", output:"Lim", tex:null, ttype:UNDEROVER},
  431. {input:"sin", tag:"mo", output:"sin", tex:null, ttype:UNARY, func:true},
  432. {input:"cos", tag:"mo", output:"cos", tex:null, ttype:UNARY, func:true},
  433. {input:"tan", tag:"mo", output:"tan", tex:null, ttype:UNARY, func:true},
  434. {input:"sinh", tag:"mo", output:"sinh", tex:null, ttype:UNARY, func:true},
  435. {input:"cosh", tag:"mo", output:"cosh", tex:null, ttype:UNARY, func:true},
  436. {input:"tanh", tag:"mo", output:"tanh", tex:null, ttype:UNARY, func:true},
  437. {input:"cot", tag:"mo", output:"cot", tex:null, ttype:UNARY, func:true},
  438. {input:"sec", tag:"mo", output:"sec", tex:null, ttype:UNARY, func:true},
  439. {input:"csc", tag:"mo", output:"csc", tex:null, ttype:UNARY, func:true},
  440. {input:"log", tag:"mo", output:"log", tex:null, ttype:UNARY, func:true},
  441. {input:"ln", tag:"mo", output:"ln", tex:null, ttype:UNARY, func:true},
  442. {input:"det", tag:"mo", output:"det", tex:null, ttype:UNARY, func:true},
  443. {input:"dim", tag:"mo", output:"dim", tex:null, ttype:CONST},
  444. {input:"mod", tag:"mo", output:"mod", tex:null, ttype:CONST},
  445. {input:"gcd", tag:"mo", output:"gcd", tex:null, ttype:UNARY, func:true},
  446. {input:"lcm", tag:"mo", output:"lcm", tex:null, ttype:UNARY, func:true},
  447. {input:"lub", tag:"mo", output:"lub", tex:null, ttype:CONST},
  448. {input:"glb", tag:"mo", output:"glb", tex:null, ttype:CONST},
  449. {input:"min", tag:"mo", output:"min", tex:null, ttype:UNDEROVER},
  450. {input:"max", tag:"mo", output:"max", tex:null, ttype:UNDEROVER},
  451. //arrows
  452. {input:"uarr", tag:"mo", output:"\u2191", tex:"uparrow", ttype:CONST},
  453. {input:"darr", tag:"mo", output:"\u2193", tex:"downarrow", ttype:CONST},
  454. {input:"rarr", tag:"mo", output:"\u2192", tex:"rightarrow", ttype:CONST},
  455. {input:"->", tag:"mo", output:"\u2192", tex:"to", ttype:CONST},
  456. {input:"|->", tag:"mo", output:"\u21A6", tex:"mapsto", ttype:CONST},
  457. {input:"larr", tag:"mo", output:"\u2190", tex:"leftarrow", ttype:CONST},
  458. {input:"harr", tag:"mo", output:"\u2194", tex:"leftrightarrow", ttype:CONST},
  459. {input:"rArr", tag:"mo", output:"\u21D2", tex:"Rightarrow", ttype:CONST},
  460. {input:"lArr", tag:"mo", output:"\u21D0", tex:"Leftarrow", ttype:CONST},
  461. {input:"hArr", tag:"mo", output:"\u21D4", tex:"Leftrightarrow", ttype:CONST},
  462. //commands with argument
  463. AMsqrt, AMroot, AMfrac, AMdiv, AMover, AMsub, AMsup,
  464. {input:"hat", tag:"mover", output:"\u005E", tex:null, ttype:UNARY, acc:true},
  465. {input:"bar", tag:"mover", output:"\u00AF", tex:"overline", ttype:UNARY, acc:true},
  466. {input:"vec", tag:"mover", output:"\u2192", tex:null, ttype:UNARY, acc:true},
  467. {input:"dot", tag:"mover", output:".", tex:null, ttype:UNARY, acc:true},
  468. {input:"ddot", tag:"mover", output:"..", tex:null, ttype:UNARY, acc:true},
  469. {input:"ul", tag:"munder", output:"\u0332", tex:"underline", ttype:UNARY, acc:true},
  470. AMtext, AMmbox, AMquote,
  471. {input:"bb", tag:"mstyle", atname:"fontweight", atval:"bold", output:"bb", tex:null, ttype:UNARY},
  472. {input:"mathbf", tag:"mstyle", atname:"fontweight", atval:"bold", output:"mathbf", tex:null, ttype:UNARY},
  473. {input:"sf", tag:"mstyle", atname:"fontfamily", atval:"sans-serif", output:"sf", tex:null, ttype:UNARY},
  474. {input:"mathsf", tag:"mstyle", atname:"fontfamily", atval:"sans-serif", output:"mathsf", tex:null, ttype:UNARY},
  475. {input:"bbb", tag:"mstyle", atname:"mathvariant", atval:"double-struck", output:"bbb", tex:null, ttype:UNARY, codes:AMbbb},
  476. {input:"mathbb", tag:"mstyle", atname:"mathvariant", atval:"double-struck", output:"mathbb", tex:null, ttype:UNARY, codes:AMbbb},
  477. {input:"cc", tag:"mstyle", atname:"mathvariant", atval:"script", output:"cc", tex:null, ttype:UNARY, codes:AMcal},
  478. {input:"mathcal", tag:"mstyle", atname:"mathvariant", atval:"script", output:"mathcal", tex:null, ttype:UNARY, codes:AMcal},
  479. {input:"tt", tag:"mstyle", atname:"fontfamily", atval:"monospace", output:"tt", tex:null, ttype:UNARY},
  480. {input:"mathtt", tag:"mstyle", atname:"fontfamily", atval:"monospace", output:"mathtt", tex:null, ttype:UNARY},
  481. {input:"fr", tag:"mstyle", atname:"mathvariant", atval:"fraktur", output:"fr", tex:null, ttype:UNARY, codes:AMfrk},
  482. {input:"mathfrak", tag:"mstyle", atname:"mathvariant", atval:"fraktur", output:"mathfrak", tex:null, ttype:UNARY, codes:AMfrk}
  483. ];
  484. function compareNames(s1,s2) {
  485. if (s1.input > s2.input) return 1
  486. else return -1;
  487. }
  488. var AMnames = []; //list of input symbols
  489. function AMinitSymbols() {
  490. var texsymbols = [], i;
  491. for (i=0; i<AMsymbols.length; i++)
  492. if (AMsymbols[i].tex)
  493. texsymbols[texsymbols.length] = {input:AMsymbols[i].tex,
  494. tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype};
  495. AMsymbols = AMsymbols.concat(texsymbols);
  496. AMsymbols.sort(compareNames);
  497. for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
  498. }
  499. var AMmathml = "http://www.w3.org/1998/Math/MathML";
  500. function AMcreateElementMathML(t) {
  501. if (isIE) return document.createElement("m:"+t);
  502. else return document.createElementNS(AMmathml,t);
  503. }
  504. function AMcreateMmlNode(t,frag) {
  505. // var node = AMcreateElementMathML(name);
  506. if (isIE) var node = document.createElement("m:"+t);
  507. else /*var*//*DPVC*/ node = document.createElementNS(AMmathml,t);
  508. node.appendChild(frag);
  509. return node;
  510. }
  511. function newcommand(oldstr,newstr) {
  512. AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
  513. tex:null, ttype:DEFINITION}]);
  514. // #### Added from Version 2.0.1 #### //
  515. AMsymbols.sort(compareNames);
  516. for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
  517. // #### End of Addition #### //
  518. }
  519. function AMremoveCharsAndBlanks(str,n) {
  520. //remove n characters and any following blanks
  521. var st;
  522. if (str.charAt(n)=="\\" && str.charAt(n+1)!="\\" && str.charAt(n+1)!=" ")
  523. st = str.slice(n+1);
  524. else st = str.slice(n);
  525. for (var i=0; i<st.length && st.charCodeAt(i)<=32; i=i+1);
  526. return st.slice(i);
  527. }
  528. function AMposition(arr, str, n) {
  529. // return position >=n where str appears or would be inserted
  530. // assumes arr is sorted
  531. if (n==0) {
  532. var h,m;
  533. n = -1;
  534. h = arr.length;
  535. while (n+1<h) {
  536. m = (n+h) >> 1;
  537. if (arr[m]<str) n = m; else h = m;
  538. }
  539. return h;
  540. } else
  541. for (var i=n; i<arr.length && arr[i]<str; i++);
  542. return i; // i=arr.length || arr[i]>=str
  543. }
  544. function AMgetSymbol(str) {
  545. //return maximal initial substring of str that appears in names
  546. //return null if there is none
  547. var k = 0; //new pos
  548. var j = 0; //old pos
  549. var mk; //match pos
  550. var st;
  551. var tagst;
  552. var match = "";
  553. var more = true;
  554. for (var i=1; i<=str.length && more; i++) {
  555. st = str.slice(0,i); //initial substring of length i
  556. j = k;
  557. k = AMposition(AMnames, st, j);
  558. if (k<AMnames.length && str.slice(0,AMnames[k].length)==AMnames[k]){
  559. match = AMnames[k];
  560. mk = k;
  561. i = match.length;
  562. }
  563. more = k<AMnames.length && str.slice(0,AMnames[k].length)>=AMnames[k];
  564. }
  565. AMpreviousSymbol=AMcurrentSymbol;
  566. if (match!=""){
  567. AMcurrentSymbol=AMsymbols[mk].ttype;
  568. return AMsymbols[mk];
  569. }
  570. // if str[0] is a digit or - return maxsubstring of digits.digits
  571. AMcurrentSymbol=CONST;
  572. k = 1;
  573. st = str.slice(0,1);
  574. var integ = true;
  575. while ("0"<=st && st<="9" && k<=str.length) {
  576. st = str.slice(k,k+1);
  577. k++;
  578. }
  579. if (st == decimalsign) {
  580. st = str.slice(k,k+1);
  581. if ("0"<=st && st<="9") {
  582. integ = false;
  583. k++;
  584. while ("0"<=st && st<="9" && k<=str.length) {
  585. st = str.slice(k,k+1);
  586. k++;
  587. }
  588. }
  589. }
  590. if ((integ && k>1) || k>2) {
  591. st = str.slice(0,k-1);
  592. tagst = "mn";
  593. } else {
  594. k = 2;
  595. st = str.slice(0,1); //take 1 character
  596. tagst = (("A">st || st>"Z") && ("a">st || st>"z")?"mo":"mi");
  597. }
  598. // #### Replaced by lines from Version 2.0.1 #### //
  599. if (st=="-" && AMpreviousSymbol==INFIX) {
  600. AMcurrentSymbol = INFIX; //trick "/" into recognizing "-" on second parse
  601. return {input:st, tag:tagst, output:st, ttype:UNARY, func:true};
  602. }
  603. // #### End of Replacement #### //
  604. return {input:st, tag:tagst, output:st, ttype:CONST};
  605. }
  606. function AMremoveBrackets(node) {
  607. var st;
  608. if (node.nodeName=="mrow") {
  609. st = node.firstChild.firstChild.nodeValue;
  610. if (st=="(" || st=="[" || st=="{") node.removeChild(node.firstChild);
  611. }
  612. if (node.nodeName=="mrow") {
  613. st = node.lastChild.firstChild.nodeValue;
  614. if (st==")" || st=="]" || st=="}") node.removeChild(node.lastChild);
  615. }
  616. }
  617. /*Parsing ASCII math expressions with the following grammar
  618. v ::= [A-Za-z] | greek letters | numbers | other constant symbols
  619. u ::= sqrt | text | bb | other unary symbols for font commands
  620. b ::= frac | root | stackrel binary symbols
  621. l ::= ( | [ | { | (: | {: left brackets
  622. r ::= ) | ] | } | :) | :} right brackets
  623. S ::= v | lEr | uS | bSS Simple expression
  624. I ::= S_S | S^S | S_S^S | S Intermediate expression
  625. E ::= IE | I/I Expression
  626. Each terminal symbol is translated into a corresponding mathml node.*/
  627. var AMnestingDepth,AMpreviousSymbol,AMcurrentSymbol;
  628. function AMparseSexpr(str) { //parses str and returns [node,tailstr]
  629. var symbol, node, result, i, st,// rightvert = false,
  630. newFrag = document.createDocumentFragment();
  631. str = AMremoveCharsAndBlanks(str,0);
  632. symbol = AMgetSymbol(str); //either a token or a bracket or empty
  633. if (symbol == null || symbol.ttype == RIGHTBRACKET && AMnestingDepth > 0) {
  634. return [null,str];
  635. }
  636. if (symbol.ttype == DEFINITION) {
  637. str = symbol.output+AMremoveCharsAndBlanks(str,symbol.input.length);
  638. symbol = AMgetSymbol(str);
  639. }
  640. switch (symbol.ttype) {
  641. case UNDEROVER:
  642. case CONST:
  643. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  644. return [AMcreateMmlNode(symbol.tag, //its a constant
  645. document.createTextNode(symbol.output)),str];
  646. case LEFTBRACKET: //read (expr+)
  647. AMnestingDepth++;
  648. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  649. result = AMparseExpr(str,true);
  650. AMnestingDepth--;
  651. if (typeof symbol.invisible == "boolean" && symbol.invisible)
  652. node = AMcreateMmlNode("mrow",result[0]);
  653. else {
  654. node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
  655. node = AMcreateMmlNode("mrow",node);
  656. node.appendChild(result[0]);
  657. }
  658. return [node,result[1]];
  659. case TEXT:
  660. if (symbol!=AMquote) str = AMremoveCharsAndBlanks(str,symbol.input.length);
  661. if (str.charAt(0)=="{") i=str.indexOf("}");
  662. else if (str.charAt(0)=="(") i=str.indexOf(")");
  663. else if (str.charAt(0)=="[") i=str.indexOf("]");
  664. else if (symbol==AMquote) i=str.slice(1).indexOf("\"")+1;
  665. else i = 0;
  666. if (i==-1) i = str.length;
  667. st = str.slice(1,i);
  668. if (st.charAt(0) == " ") {
  669. node = AMcreateElementMathML("mspace");
  670. node.setAttribute("width","1ex");
  671. newFrag.appendChild(node);
  672. }
  673. newFrag.appendChild(
  674. AMcreateMmlNode(symbol.tag,document.createTextNode(st)));
  675. if (st.charAt(st.length-1) == " ") {
  676. node = AMcreateElementMathML("mspace");
  677. node.setAttribute("width","1ex");
  678. newFrag.appendChild(node);
  679. }
  680. str = AMremoveCharsAndBlanks(str,i+1);
  681. return [AMcreateMmlNode("mrow",newFrag),str];
  682. case UNARY:
  683. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  684. result = AMparseSexpr(str);
  685. if (result[0]==null) return [AMcreateMmlNode(symbol.tag,
  686. document.createTextNode(symbol.output)),str];
  687. if (typeof symbol.func == "boolean" && symbol.func) { // functions hack
  688. st = str.charAt(0);
  689. if (st=="^" || st=="_" || st=="/" || st=="|" || st==",") {
  690. return [AMcreateMmlNode(symbol.tag,
  691. document.createTextNode(symbol.output)),str];
  692. } else {
  693. node = AMcreateMmlNode("mrow",
  694. AMcreateMmlNode(symbol.tag,document.createTextNode(symbol.output)));
  695. node.appendChild(result[0]);
  696. return [node,result[1]];
  697. }
  698. }
  699. AMremoveBrackets(result[0]);
  700. if (symbol.input == "sqrt") { // sqrt
  701. return [AMcreateMmlNode(symbol.tag,result[0]),result[1]];
  702. } else if (typeof symbol.acc == "boolean" && symbol.acc) { // accent
  703. node = AMcreateMmlNode(symbol.tag,result[0]);
  704. node.appendChild(AMcreateMmlNode("mo",document.createTextNode(symbol.output)));
  705. return [node,result[1]];
  706. } else { // font change command
  707. if (!isIE && typeof symbol.codes != "undefined") {
  708. for (i=0; i<result[0].childNodes.length; i++)
  709. if (result[0].childNodes[i].nodeName=="mi" || result[0].nodeName=="mi") {
  710. st = (result[0].nodeName=="mi"?result[0].firstChild.nodeValue:
  711. result[0].childNodes[i].firstChild.nodeValue);
  712. var newst = [];
  713. for (var j=0; j<st.length; j++)
  714. if (st.charCodeAt(j)>64 && st.charCodeAt(j)<91) newst = newst +
  715. String.fromCharCode(symbol.codes[st.charCodeAt(j)-65]);
  716. else newst = newst + st.charAt(j);
  717. if (result[0].nodeName=="mi")
  718. result[0]=AMcreateElementMathML("mo").
  719. appendChild(document.createTextNode(newst));
  720. else result[0].replaceChild(AMcreateElementMathML("mo").
  721. appendChild(document.createTextNode(newst)),result[0].childNodes[i]);
  722. }
  723. }
  724. node = AMcreateMmlNode(symbol.tag,result[0]);
  725. node.setAttribute(symbol.atname,symbol.atval);
  726. return [node,result[1]];
  727. }
  728. case BINARY:
  729. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  730. result = AMparseSexpr(str);
  731. if (result[0]==null) return [AMcreateMmlNode("mo",
  732. document.createTextNode(symbol.input)),str];
  733. AMremoveBrackets(result[0]);
  734. var result2 = AMparseSexpr(result[1]);
  735. if (result2[0]==null) return [AMcreateMmlNode("mo",
  736. document.createTextNode(symbol.input)),str];
  737. AMremoveBrackets(result2[0]);
  738. if (symbol.input=="root" || symbol.input=="stackrel")
  739. newFrag.appendChild(result2[0]);
  740. newFrag.appendChild(result[0]);
  741. if (symbol.input=="frac") newFrag.appendChild(result2[0]);
  742. return [AMcreateMmlNode(symbol.tag,newFrag),result2[1]];
  743. case INFIX:
  744. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  745. return [AMcreateMmlNode("mo",document.createTextNode(symbol.output)),str];
  746. case SPACE:
  747. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  748. node = AMcreateElementMathML("mspace");
  749. node.setAttribute("width","1ex");
  750. newFrag.appendChild(node);
  751. newFrag.appendChild(
  752. AMcreateMmlNode(symbol.tag,document.createTextNode(symbol.output)));
  753. node = AMcreateElementMathML("mspace");
  754. node.setAttribute("width","1ex");
  755. newFrag.appendChild(node);
  756. return [AMcreateMmlNode("mrow",newFrag),str];
  757. case LEFTRIGHT:
  758. // if (rightvert) return [null,str]; else rightvert = true;
  759. AMnestingDepth++;
  760. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  761. result = AMparseExpr(str,false);
  762. AMnestingDepth--;
  763. /*var*//*DPVC*/ st = "";
  764. if (result[0].lastChild!=null)
  765. st = result[0].lastChild.firstChild.nodeValue;
  766. //alert(result[0].lastChild+"***"+st);
  767. if (st == "|") { // its an absolute value subterm
  768. node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
  769. node = AMcreateMmlNode("mrow",node);
  770. node.appendChild(result[0]);
  771. return [node,result[1]];
  772. } else { // the "|" is a \mid
  773. node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
  774. node = AMcreateMmlNode("mrow",node);
  775. return [node,str];
  776. }
  777. default:
  778. //alert("default");
  779. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  780. return [AMcreateMmlNode(symbol.tag, //its a constant
  781. document.createTextNode(symbol.output)),str];
  782. }
  783. }
  784. function AMparseIexpr(str) {
  785. var symbol, sym1, sym2, node, result, underover;
  786. str = AMremoveCharsAndBlanks(str,0);
  787. sym1 = AMgetSymbol(str);
  788. result = AMparseSexpr(str);
  789. node = result[0];
  790. str = result[1];
  791. symbol = AMgetSymbol(str);
  792. if (symbol.ttype == INFIX && symbol.input != "/") {
  793. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  794. // if (symbol.input == "/") result = AMparseIexpr(str); else ...
  795. result = AMparseSexpr(str);
  796. if (result[0] == null) // show box in place of missing argument
  797. result[0] = AMcreateMmlNode("mo",document.createTextNode("\u25A1"));
  798. else AMremoveBrackets(result[0]);
  799. str = result[1];
  800. // if (symbol.input == "/") AMremoveBrackets(node);
  801. if (symbol.input == "_") {
  802. sym2 = AMgetSymbol(str);
  803. underover = (sym1.ttype == UNDEROVER);
  804. if (sym2.input == "^") {
  805. str = AMremoveCharsAndBlanks(str,sym2.input.length);
  806. var res2 = AMparseSexpr(str);
  807. AMremoveBrackets(res2[0]);
  808. str = res2[1];
  809. node = AMcreateMmlNode((underover?"munderover":"msubsup"),node);
  810. node.appendChild(result[0]);
  811. node.appendChild(res2[0]);
  812. node = AMcreateMmlNode("mrow",node); // so sum does not stretch
  813. } else {
  814. node = AMcreateMmlNode((underover?"munder":"msub"),node);
  815. node.appendChild(result[0]);
  816. }
  817. } else {
  818. node = AMcreateMmlNode(symbol.tag,node);
  819. node.appendChild(result[0]);
  820. }
  821. }
  822. return [node,str];
  823. }
  824. function AMparseExpr(str,rightbracket) {
  825. var symbol, node, result, i, /*nodeList = [],*//*DPVC*/
  826. newFrag = document.createDocumentFragment();
  827. do {
  828. str = AMremoveCharsAndBlanks(str,0);
  829. result = AMparseIexpr(str);
  830. node = result[0];
  831. str = result[1];
  832. symbol = AMgetSymbol(str);
  833. if (symbol.ttype == INFIX && symbol.input == "/") {
  834. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  835. result = AMparseIexpr(str);
  836. if (result[0] == null) // show box in place of missing argument
  837. result[0] = AMcreateMmlNode("mo",document.createTextNode("\u25A1"));
  838. else AMremoveBrackets(result[0]);
  839. str = result[1];
  840. AMremoveBrackets(node);
  841. node = AMcreateMmlNode(symbol.tag,node);
  842. node.appendChild(result[0]);
  843. newFrag.appendChild(node);
  844. symbol = AMgetSymbol(str);
  845. }
  846. else if (node!=undefined) newFrag.appendChild(node);
  847. } while ((symbol.ttype != RIGHTBRACKET &&
  848. (symbol.ttype != LEFTRIGHT || rightbracket)
  849. || AMnestingDepth == 0) && symbol!=null && symbol.output!="");
  850. if (symbol.ttype == RIGHTBRACKET || symbol.ttype == LEFTRIGHT) {
  851. // if (AMnestingDepth > 0) AMnestingDepth--;
  852. var len = newFrag.childNodes.length;
  853. if (len>0 && newFrag.childNodes[len-1].nodeName == "mrow" && len>1 &&
  854. newFrag.childNodes[len-2].nodeName == "mo" &&
  855. newFrag.childNodes[len-2].firstChild.nodeValue == ",") { //matrix
  856. var right = newFrag.childNodes[len-1].lastChild.firstChild.nodeValue;
  857. if (right==")" || right=="]") {
  858. var left = newFrag.childNodes[len-1].firstChild.firstChild.nodeValue;
  859. if (left=="(" && right==")" && symbol.output != "}" ||
  860. left=="[" && right=="]") {
  861. var pos = []; // positions of commas
  862. var matrix = true;
  863. var m = newFrag.childNodes.length;
  864. for (i=0; matrix && i<m; i=i+2) {
  865. pos[i] = [];
  866. node = newFrag.childNodes[i];
  867. if (matrix) matrix = node.nodeName=="mrow" &&
  868. (i==m-1 || node.nextSibling.nodeName=="mo" &&
  869. node.nextSibling.firstChild.nodeValue==",")&&
  870. node.firstChild.firstChild.nodeValue==left &&
  871. node.lastChild.firstChild.nodeValue==right;
  872. if (matrix)
  873. for (var j=0; j<node.childNodes.length; j++)
  874. if (node.childNodes[j].firstChild.nodeValue==",")
  875. pos[i][pos[i].length]=j;
  876. if (matrix && i>1) matrix = pos[i].length == pos[i-2].length;
  877. }
  878. if (matrix) {
  879. var row, frag, n, k, table = document.createDocumentFragment();
  880. for (i=0; i<m; i=i+2) {
  881. row = document.createDocumentFragment();
  882. frag = document.createDocumentFragment();
  883. node = newFrag.firstChild; // <mrow>(-,-,...,-,-)</mrow>
  884. n = node.childNodes.length;
  885. k = 0;
  886. node.removeChild(node.firstChild); //remove (
  887. for (j=1; j<n-1; j++) {
  888. if (typeof pos[i][k] != "undefined" && j==pos[i][k]){
  889. node.removeChild(node.firstChild); //remove ,
  890. row.appendChild(AMcreateMmlNode("mtd",frag));
  891. k++;
  892. } else frag.appendChild(node.firstChild);
  893. }
  894. row.appendChild(AMcreateMmlNode("mtd",frag));
  895. if (newFrag.childNodes.length>2) {
  896. newFrag.removeChild(newFrag.firstChild); //remove <mrow>)</mrow>
  897. newFrag.removeChild(newFrag.firstChild); //remove <mo>,</mo>
  898. }
  899. table.appendChild(AMcreateMmlNode("mtr",row));
  900. }
  901. node = AMcreateMmlNode("mtable",table);
  902. if (typeof symbol.invisible == "boolean" && symbol.invisible) node.setAttribute("columnalign","left");
  903. newFrag.replaceChild(node,newFrag.firstChild);
  904. }
  905. }
  906. }
  907. }
  908. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  909. if (typeof symbol.invisible != "boolean" || !symbol.invisible) {
  910. node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
  911. newFrag.appendChild(node);
  912. }
  913. }
  914. return [newFrag,str];
  915. }
  916. function AMparseMath(str) {
  917. var /*result,*//*DPVC*/ node = AMcreateElementMathML("mstyle");
  918. if (mathcolor != "") node.setAttribute("mathcolor",mathcolor);
  919. if (displaystyle) node.setAttribute("displaystyle","true");
  920. if (mathfontfamily != "") node.setAttribute("fontfamily",mathfontfamily);
  921. AMnestingDepth = 0;
  922. node.appendChild(AMparseExpr(str.replace(/^\s+/g,""),false)[0]);
  923. node = AMcreateMmlNode("math",node);
  924. if (showasciiformulaonhover) //fixed by djhsu so newline
  925. node.setAttribute("title",str.replace(/\s+/g," "));//does not show in Gecko
  926. if (mathfontfamily != "" && (isIE || mathfontfamily != "serif")) {
  927. var fnode = AMcreateElementXHTML("font");
  928. fnode.setAttribute("face",mathfontfamily);
  929. fnode.appendChild(node);
  930. return fnode;
  931. }
  932. return node;
  933. }
  934. /*
  935. * function AMstrarr2docFrag(arr, linebreaks) {
  936. * var newFrag=document.createDocumentFragment();
  937. * var expr = false;
  938. * for (var i=0; i<arr.length; i++) {
  939. * if (expr) newFrag.appendChild(AMparseMath(arr[i]));
  940. * else {
  941. * var arri = (linebreaks ? arr[i].split("\n\n") : [arr[i]]);
  942. * newFrag.appendChild(AMcreateElementXHTML("span").
  943. * appendChild(document.createTextNode(arri[0])));
  944. * for (var j=1; j<arri.length; j++) {
  945. * newFrag.appendChild(AMcreateElementXHTML("p"));
  946. * newFrag.appendChild(AMcreateElementXHTML("span").
  947. * appendChild(document.createTextNode(arri[j])));
  948. * }
  949. * }
  950. * expr = !expr;
  951. * }
  952. * return newFrag;
  953. * }
  954. *
  955. * function AMprocessNodeR(n, linebreaks) {
  956. * var mtch, str, arr, frg, i;
  957. * if (n.childNodes.length == 0) {
  958. * if ((n.nodeType!=8 || linebreaks) &&
  959. * n.parentNode.nodeName!="form" && n.parentNode.nodeName!="FORM" &&
  960. * n.parentNode.nodeName!="textarea" && n.parentNode.nodeName!="TEXTAREA" &&
  961. * n.parentNode.nodeName!="pre" && n.parentNode.nodeName!="PRE") {
  962. * str = n.nodeValue;
  963. * if (!(str == null)) {
  964. * str = str.replace(/\r\n\r\n/g,"\n\n");
  965. * if (doubleblankmathdelimiter) {
  966. * str = str.replace(/\x20\x20\./g," "+AMdelimiter1+".");
  967. * str = str.replace(/\x20\x20,/g," "+AMdelimiter1+",");
  968. * str = str.replace(/\x20\x20/g," "+AMdelimiter1+" ");
  969. * }
  970. * str = str.replace(/\x20+/g," ");
  971. * str = str.replace(/\s*\r\n/g," ");
  972. * mtch = false;
  973. * str = str.replace(new RegExp(AMescape2, "g"),
  974. * function(st){mtch=true;return "AMescape2"});
  975. * str = str.replace(new RegExp(AMescape1, "g"),
  976. * function(st){mtch=true;return "AMescape1"});
  977. * str = str.replace(new RegExp(AMdelimiter2regexp, "g"),AMdelimiter1);
  978. * arr = str.split(AMdelimiter1);
  979. * for (i=0; i<arr.length; i++)
  980. * arr[i]=arr[i].replace(/AMescape2/g,AMdelimiter2).
  981. * replace(/AMescape1/g,AMdelimiter1);
  982. * if (arr.length>1 || mtch) {
  983. * if (checkForMathML) {
  984. * checkForMathML = false;
  985. * var nd = AMisMathMLavailable();
  986. * AMnoMathML = nd != null;
  987. * if (AMnoMathML && notifyIfNoMathML)
  988. * if (alertIfNoMathML)
  989. * alert("To view the ASCIIMathML notation use Internet Explorer 6 +\nMathPlayer (free from www.dessci.com)\n\
  990. * or Firefox/Mozilla/Netscape");
  991. * else AMbody.insertBefore(nd,AMbody.childNodes[0]);
  992. * }
  993. * if (!AMnoMathML) {
  994. * frg = AMstrarr2docFrag(arr,n.nodeType==8);
  995. * var len = frg.childNodes.length;
  996. * n.parentNode.replaceChild(frg,n);
  997. * return len-1;
  998. * } else return 0;
  999. * }
  1000. * }
  1001. * } else return 0;
  1002. * } else if (n.nodeName!="math") {
  1003. * for (i=0; i<n.childNodes.length; i++)
  1004. * i += AMprocessNodeR(n.childNodes[i], linebreaks);
  1005. * }
  1006. * return 0;
  1007. * }
  1008. *
  1009. * function AMprocessNode(n, linebreaks, spanclassAM) {
  1010. * var frag,st;
  1011. * if (spanclassAM!=null) {
  1012. * frag = document.getElementsByTagName("span")
  1013. * for (var i=0;i<frag.length;i++)
  1014. * if (frag[i].className == "AM")
  1015. * AMprocessNodeR(frag[i],linebreaks);
  1016. * } else {
  1017. * try {
  1018. * st = n.innerHTML;
  1019. * } catch(err) {}
  1020. * if (st==null ||
  1021. * st.indexOf(AMdelimiter1)!=-1 || st.indexOf(AMdelimiter2)!=-1)
  1022. * AMprocessNodeR(n,linebreaks);
  1023. * }
  1024. * if (isIE) { //needed to match size and font of formula to surrounding text
  1025. * frag = document.getElementsByTagName('math');
  1026. * for (var i=0;i<frag.length;i++) frag[i].update()
  1027. * }
  1028. * }
  1029. *
  1030. * var AMbody;
  1031. * var AMnoMathML = false, AMtranslated = false;
  1032. *
  1033. * function translate(spanclassAM) {
  1034. * if (!AMtranslated) { // run this only once
  1035. * AMtranslated = true;
  1036. * AMinitSymbols();
  1037. * AMbody = document.getElementsByTagName("body")[0];
  1038. * AMprocessNode(AMbody, false, spanclassAM);
  1039. * }
  1040. * }
  1041. *
  1042. * if (isIE) { // avoid adding MathPlayer info explicitly to each webpage
  1043. * document.write("<object id=\"mathplayer\"\
  1044. * classid=\"clsid:32F66A20-7614-11D4-BD11-00104BD3F987\"></object>");
  1045. * document.write("<?import namespace=\"m\" implementation=\"#mathplayer\"?>");
  1046. * }
  1047. *
  1048. * // GO1.1 Generic onload by Brothercake
  1049. * // http://www.brothercake.com/
  1050. * //onload function (replaces the onload="translate()" in the <body> tag)
  1051. * function generic()
  1052. * {
  1053. * translate();
  1054. * };
  1055. * //setup onload function
  1056. * if(typeof window.addEventListener != 'undefined')
  1057. * {
  1058. * //.. gecko, safari, konqueror and standard
  1059. * window.addEventListener('load', generic, false);
  1060. * }
  1061. * else if(typeof document.addEventListener != 'undefined')
  1062. * {
  1063. * //.. opera 7
  1064. * document.addEventListener('load', generic, false);
  1065. * }
  1066. * else if(typeof window.attachEvent != 'undefined')
  1067. * {
  1068. * //.. win/ie
  1069. * window.attachEvent('onload', generic);
  1070. * }
  1071. * //** remove this condition to degrade older browsers
  1072. * else
  1073. * {
  1074. * //.. mac/ie5 and anything else that gets this far
  1075. * //if there's an existing onload function
  1076. * if(typeof window.onload == 'function')
  1077. * {
  1078. * //store it
  1079. * var existing = onload;
  1080. * //add new onload handler
  1081. * window.onload = function()
  1082. * {
  1083. * //call existing onload function
  1084. * existing();
  1085. * //call generic onload function
  1086. * generic();
  1087. * };
  1088. * }
  1089. * else
  1090. * {
  1091. * //setup onload function
  1092. * window.onload = generic;
  1093. * }
  1094. * }
  1095. */
  1096. /******************************************************************
  1097. *
  1098. * The previous section is ASCIIMathML.js Version 1.4.7
  1099. * (c) Peter Jipsen, used with permission.
  1100. *
  1101. ******************************************************************/
  1102. showasciiformulaonhover = false;
  1103. mathfontfamily = "";
  1104. mathcolor = "";
  1105. //
  1106. // Remove remapping of mathvariants to plane1 (MathJax handles that)
  1107. // Change functions to mi rather than mo (to get spacing right)
  1108. //
  1109. (function () {
  1110. for (var i = 0, m = AMsymbols.length; i < m; i++) {
  1111. if (AMsymbols[i].codes) {delete AMsymbols[i].codes}
  1112. if (AMsymbols[i].func) {AMsymbols[i].tag = "mi"}
  1113. if (AMsymbols[i].atname === "fontfamily" || AMsymbols[i].atname === "fontweight")
  1114. {AMsymbols[i].atname = "mathvariant"}
  1115. }
  1116. })();
  1117. //
  1118. // Add some missing symbols
  1119. //
  1120. AMsymbols.push(
  1121. {input:"gt", tag:"mo", output:">", tex:null, ttype:CONST},
  1122. {input:"gt=", tag:"mo", output:"\u2265", tex:"geq", ttype:CONST},
  1123. {input:"-<=", tag:"mo", output:"\u2AAF", tex:"preceq", ttype:CONST},
  1124. {input:">-=", tag:"mo", output:"\u2AB0", tex:"succeq", ttype:CONST},
  1125. {input:"'", tag:"mo", output:"\u2032", tex:"prime", ttype:CONST},
  1126. {input:"arcsin", tag:"mi", output:"arcsin", tex:null, ttype:UNARY, func:true},
  1127. {input:"arccos", tag:"mi", output:"arccos", tex:null, ttype:UNARY, func:true},
  1128. {input:"arctan", tag:"mi", output:"arctan", tex:null, ttype:UNARY, func:true},
  1129. {input:"coth", tag:"mi", output:"coth", tex:null, ttype:UNARY, func:true},
  1130. {input:"sech", tag:"mi", output:"sech", tex:null, ttype:UNARY, func:true},
  1131. {input:"csch", tag:"mi", output:"csch", tex:null, ttype:UNARY, func:true},
  1132. {input:"abs", tag:"mi", output:"abs", tex:null, ttype:UNARY, func:true},
  1133. {input:"exp", tag:"mi", output:"exp", tex:null, ttype:UNARY, func:true},
  1134. {input:"tilde", tag:"mover", output:"~", tex:null, ttype:UNARY, acc:true}
  1135. )
  1136. //
  1137. // Access to AsciiMath functions and values
  1138. //
  1139. ASCIIMATH.Augment({
  1140. AM: {
  1141. Init: function () {
  1142. displaystyle = ASCIIMATH.config.displaystyle;
  1143. // Old versions use the "decimal" option, so take it into account if it
  1144. // is defined by the user. See issue 384.
  1145. decimalsign = (ASCIIMATH.config.decimal || ASCIIMATH.config.decimalsign);
  1146. INITASCIIMATH();
  1147. AMinitSymbols();
  1148. },
  1149. Augment: function (def) {
  1150. for (var id in def) {if (def.hasOwnProperty(id)) {
  1151. switch (id) {
  1152. case "displaystyle": displaystyle = def[id]; break;
  1153. case "decimal": decimal = def[id]; break;
  1154. case "parseMath": AMparseMath = def[id]; break;
  1155. case "parseExpr": AMparseExpr = def[id]; break;
  1156. case "parseIexpr": AMparseIexpr = def[id]; break;
  1157. case "parseSexpr": AMparseSexpr = def[id]; break;
  1158. case "removeBrackets": AMremoveBrackets = def[id]; break;
  1159. case "getSymbol": AMgetSymbol = def[id]; break;
  1160. case "position": AMposition = def[id]; break;
  1161. case "removeCharsAndBlanks": AMremoveCharsAndBlanks = def[id]; break;
  1162. case "createMmlNode": AMcreateMmlNode = def[id]; break;
  1163. case "createElementMathML": AMcreateElementMathML = def[id]; break;
  1164. case "createElementXHTML": AMcreateElementXHTML = def[id]; break;
  1165. case "initSymbols": AMinitSymbols = def[id]; break;
  1166. case "compareNames": comareNames = def[id]; break;
  1167. };
  1168. this[id] = def[id];
  1169. }};
  1170. },
  1171. parseMath: AMparseMath,
  1172. parseExpr: AMparseExpr,
  1173. parseIexpr: AMparseIexpr,
  1174. parseSexr: AMparseSexpr,
  1175. removeBrackets: AMremoveBrackets,
  1176. getSymbol: AMgetSymbol,
  1177. position: AMposition,
  1178. removeCharsAndBlanks: AMremoveCharsAndBlanks,
  1179. createMmlNode: AMcreateMmlNode,
  1180. createElementMathML: AMcreateElementMathML,
  1181. createElementXHTML: AMcreateElementXHTML,
  1182. initSymbols: AMinitSymbols,
  1183. compareNames: compareNames,
  1184. createDocumentFragment: DOCFRAG,
  1185. document: document,
  1186. define: newcommand,
  1187. symbols: AMsymbols,
  1188. names: AMnames,
  1189. TOKEN: {
  1190. CONST:CONST, UNARY:UNARY, BINARY:BINARY, INFIX:INFIX,
  1191. LEFTBRACKET:LEFTBRACKET, RIGHTBRACKET:RIGHTBRACKET, SPACE:SPACE,
  1192. UNDEROVER:UNDEROVER, DEFINITION:DEFINITION, LEFTRIGHT:LEFTRIGHT, TEXT:TEXT
  1193. }
  1194. }
  1195. });
  1196. //
  1197. // Make minimizer think these have been used
  1198. var junk = [
  1199. window, navigator //,
  1200. // checkForMathML, notifyIfNoMathML, alertIfNoMathML, AMdelimiter1, AMescape1,
  1201. // AMdelimiter2, AMescape2, AMdelimiter2regexp, doubleblankmathdelimiter
  1202. ];
  1203. junk = null;
  1204. })(MathJax.InputJax.AsciiMath);
  1205. /************************************************************************/
  1206. (function (ASCIIMATH) {
  1207. var MML;
  1208. ASCIIMATH.Augment({
  1209. sourceMenuTitle: /*_(MathMenu)*/ ["AsciiMathInput","AsciiMath Input"],
  1210. prefilterHooks: MathJax.Callback.Hooks(true), // hooks to run before processing AsciiMath
  1211. postfilterHooks: MathJax.Callback.Hooks(true), // hooks to run after processing AsciiMath
  1212. Translate: function (script) {
  1213. var mml, math = MathJax.HTML.getScript(script);
  1214. var data = {math:math, script:script};
  1215. this.prefilterHooks.Execute(data); math = data.math;
  1216. try {
  1217. mml = this.AM.parseMath(math);
  1218. } catch(err) {
  1219. if (!err.asciimathError) {throw err}
  1220. mml = this.formatError(err,math);
  1221. }
  1222. data.math = MML(mml); this.postfilterHooks.Execute(data);
  1223. return data.math;
  1224. },
  1225. formatError: function (err,math,script) {
  1226. var message = err.message.replace(/\n.*/,"");
  1227. MathJax.Hub.signal.Post(["AsciiMath Jax - parse error",message,math,script]);
  1228. return MML.merror(message);
  1229. },
  1230. Error: function (message) {
  1231. throw MathJax.Hub.Insert(Error(message),{asciimathError: true});
  1232. },
  1233. //
  1234. // Initialize the MML variable and AsciiMath itself
  1235. //
  1236. Startup: function () {
  1237. MML = MathJax.ElementJax.mml;
  1238. this.AM.Init();
  1239. }
  1240. });
  1241. ASCIIMATH.loadComplete("jax.js");
  1242. })(MathJax.InputJax.AsciiMath);