git.iko.soy/typeable/pandoc
on master help sign in
Modified s5 fancy test to include new ASCIIMathML.js.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1122 788f1e2b-df1e-0410-8736-df70ead52e1b

commit7ddd01eb3a7279b38b4a34055481403e16a2e512 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 1 Dec 2007, 03:11 (19 years ago) parentb6f1ccc
1 file changed+2517−198
tests/s5.fancy.html+2517−198
tests/s5.fancy.html+2517−198
@@ -12,66 +12,151 @@
1212/* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
1313See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
1414
15−var checkForMathML = true; // check if browser can display MathML
16−var notifyIfNoMathML = true; // display note if no MathML capability
17−var alertIfNoMathML = false; // show alert box if no MathML capability
18−var mathcolor = ""; // change it to "" (to inherit) or any other color
19−var mathfontfamily = "serif"; // change to "" to inherit (works in IE)
20− // or another family (e.g. "arial")
15+var mathcolor = ""; // change it to "" (to inherit) or another color
16+var mathfontsize = "1em"; // change to e.g. 1.2em for larger math
17+var mathfontfamily = "serif"; // change to "" to inherit (works in IE)
18+ // or another family (e.g. "arial")
19+var automathrecognize = false; // writing "amath" on page makes this true
20+var checkForMathML = true; // check if browser can display MathML
21+var notifyIfNoMathML = true; // display note at top if no MathML capability
22+var alertIfNoMathML = false; // show alert box if no MathML capability
23+var translateOnLoad = true; // set to false to do call translators from js
24+var translateLaTeX = true; // false to preserve $..$, $$..$$
25+var translateLaTeXformatting = true; // false to preserve \emph,\begin{},\end{}
26+var translateASCIIMath = true; // false to preserve `..`
27+var translateASCIIsvg = true; // false to preserve agraph.., \begin{graph}..
28+var avoidinnerHTML = false; // set true if assigning to innerHTML gives error
2129var displaystyle = true; // puts limits above and below large operators
2230var showasciiformulaonhover = true; // helps students learn ASCIIMath
2331var decimalsign = "."; // change to "," if you like, beware of `(1,2)`!
2432var AMdelimiter1 = "`", AMescape1 = "\\\\`"; // can use other characters
25−var AMdelimiter2 = "$", AMescape2 = "\\\\\\$", AMdelimiter2regexp = "\\$";
26−var doubleblankmathdelimiter = false; // if true, x+1 is equal to `x+1`
27− // for IE this works only in <!-- -->
28−//var separatetokens;// has been removed (email me if this is a problem)
29−var isIE = document.createElementNS==null;
33+var AMdocumentId = "wikitext" // PmWiki element containing math (default=body)
34+var checkforprocessasciimathinmoodle = false; // true for systems like Moodle
35+var dsvglocation = ""; // path to d.svg (blank if same as ASCIIMathML.js loc)
3036
31−if (document.getElementById==null)
32− alert("This webpage requires a recent browser such as\
33−\nMozilla/Netscape 7+ or Internet Explorer 6+MathPlayer")
37+/* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
38+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
3439
35−// all further global variables start with "AM"
40+var isIE = document.createElementNS==null;
41+var noMathML = false, translated = false;
3642
37−function AMcreateElementXHTML(t) {
38− if (isIE) return document.createElement(t);
39− else return document.createElementNS("http://www.w3.org/1999/xhtml",t);
43+if (isIE) { // avoid adding MathPlayer info explicitly to each webpage
44+ document.write("<object id=\"mathplayer\"\
45+ classid=\"clsid:32F66A20-7614-11D4-BD11-00104BD3F987\"></object>");
46+ document.write("<?import namespace=\"m\" implementation=\"#mathplayer\"?>");
4047}
4148
42−function AMnoMathMLNote() {
43− var nd = AMcreateElementXHTML("h3");
44− nd.setAttribute("align","center")
45− nd.appendChild(AMcreateElementXHTML("p"));
46− nd.appendChild(document.createTextNode("To view the "));
47− var an = AMcreateElementXHTML("a");
48− an.appendChild(document.createTextNode("ASCIIMathML"));
49− an.setAttribute("href","http://www.chapman.edu/~jipsen/asciimath.html");
50− nd.appendChild(an);
51− nd.appendChild(document.createTextNode(" notation use Internet Explorer 6+"));
52− an = AMcreateElementXHTML("a");
53− an.appendChild(document.createTextNode("MathPlayer"));
54− an.setAttribute("href","http://www.dessci.com/en/products/mathplayer/download.htm");
55− nd.appendChild(an);
56− nd.appendChild(document.createTextNode(" or Netscape/Mozilla/Firefox"));
57− nd.appendChild(AMcreateElementXHTML("p"));
58− return nd;
49+// Add a stylesheet, replacing any previous custom stylesheet (adapted from TW)
50+function setStylesheet(s) {
51+ var id = "AMMLcustomStyleSheet";
52+ var n = document.getElementById(id);
53+ if(document.createStyleSheet) {
54+ // Test for IE's non-standard createStyleSheet method
55+ if(n)
56+ n.parentNode.removeChild(n);
57+ // This failed without the &nbsp;
58+ document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeEnd","&nbsp;<style id='" + id + "'>" + s + "</style>");
59+ } else {
60+ if(n) {
61+ n.replaceChild(document.createTextNode(s),n.firstChild);
62+ } else {
63+ n = document.createElement("style");
64+ n.type = "text/css";
65+ n.id = id;
66+ n.appendChild(document.createTextNode(s));
67+ document.getElementsByTagName("head")[0].appendChild(n);
68+ }
69+ }
5970}
6071
61−function AMisMathMLavailable() {
62− var regex = /KHTML/; /* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
63−See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
64− if (navigator.appName.slice(0,8)=="Netscape")
65− if (navigator.appVersion.slice(0,1)>="5" && !regex.test(navigator.userAgent)) return null;
66− else return AMnoMathMLNote();
72+setStylesheet("#AMMLcloseDiv \{font-size:0.8em; padding-top:1em; color:#014\}\n#AMMLwarningBox \{position:absolute; width:100%; top:0; left:0; z-index:200; text-align:center; font-size:1em; font-weight:bold; padding:0.5em 0 0.5em 0; color:#ffc; background:#c30\}");
73+
74+function init(){
75+ var msg, warnings = new Array();
76+ if (document.getElementById==null){
77+ alert("This webpage requires a recent browser such as Mozilla Firefox/Netscape 7+ or Internet Explorer 6+ with MathPlayer and Adobe SVGviewer");
78+ return null;
79+ }
80+ if (checkForMathML && (msg = checkMathML())) warnings.push(msg);
81+ if (checkIfSVGavailable && (msg = checkSVG())) warnings.push(msg);
82+ if (warnings.length>0) displayWarnings(warnings);
83+ if (!noMathML) initSymbols();
84+ return true;
85+}
86+
87+function checkMathML(){
88+ if (navigator.appName.slice(0,8)=="Netscape")
89+ if (navigator.appVersion.slice(0,1)>="5") noMathML = null;
90+ else noMathML = true;
6791 else if (navigator.appName.slice(0,9)=="Microsoft")
6892 try {
6993 var ActiveX = new ActiveXObject("MathPlayer.Factory.1");
70− return null;
94+ noMathML = null;
7195 } catch (e) {
72− return AMnoMathMLNote();
96+ noMathML = true;
7397 }
74− else return AMnoMathMLNote();
98+ else noMathML = true;
99+//noMathML = true; //uncomment to check
100+ if (noMathML && notifyIfNoMathML) {
101+ var msg = "To view the ASCIIMathML notation use Internet Explorer + MathPlayer or Mozilla Firefox 2.0 or later.";
102+ if (alertIfNoMathML)
103+ alert(msg);
104+ else return msg;
105+ }
106+}
107+
108+function hideWarning(){
109+ var body = document.getElementsByTagName("body")[0];
110+ body.removeChild(document.getElementById('AMMLwarningBox'));
111+ body.onclick = null;
112+}
113+
114+function displayWarnings(warnings) {
115+ var i, frag, nd = createElementXHTML("div");
116+ var body = document.getElementsByTagName("body")[0];
117+ body.onclick=hideWarning;
118+ nd.id = 'AMMLwarningBox';
119+ for (i=0; i<warnings.length; i++) {
120+ frag = createElementXHTML("div");
121+ frag.appendChild(document.createTextNode(warnings[i]));
122+ frag.style.paddingBottom = "1.0em";
123+ nd.appendChild(frag);
124+ }
125+ nd.appendChild(createElementXHTML("p"));
126+ nd.appendChild(document.createTextNode("For instructions see the "));
127+ var an = createElementXHTML("a");
128+ an.appendChild(document.createTextNode("ASCIIMathML"));
129+ an.setAttribute("href","http://www.chapman.edu/~jipsen/asciimath.html");
130+ nd.appendChild(an);
131+ nd.appendChild(document.createTextNode(" homepage"));
132+ an = createElementXHTML("div");
133+ an.id = 'AMMLcloseDiv';
134+ an.appendChild(document.createTextNode('(click anywhere to close this warning)'));
135+ nd.appendChild(an);
136+ var body = document.getElementsByTagName("body")[0];
137+ body.insertBefore(nd,body.childNodes[0]);
138+}
139+
140+function translate(spanclassAM) {
141+ if (!translated) { // run this only once
142+ translated = true;
143+ var body = document.getElementsByTagName("body")[0];
144+ var processN = document.getElementById(AMdocumentId);
145+ if (translateLaTeX) LMprocessNode((processN!=null?processN:body));
146+ if (translateASCIIMath) AMprocessNode((processN!=null?processN:body), false, spanclassAM);
147+ }
148+}
149+
150+function createElementXHTML(t) {
151+ if (isIE) return document.createElement(t);
152+ else return document.createElementNS("http://www.w3.org/1999/xhtml",t);
153+}
154+
155+function createMmlNode(t,frag) {
156+ if (isIE) var node = document.createElement("m:"+t);
157+ else var node = document.createElementNS("http://www.w3.org/1998/Math/MathML",t);
158+ if (frag) node.appendChild(frag);
159+ return node;
75160}
76161
77162// character lists for Mozilla/Netscape fonts
@@ -79,20 +164,12 @@ var AMcal = [0xEF35,0x212C,0xEF36,0xEF37,0x2130,0x2131,0xEF38,0x210B,0x2110,0xEF
79164var 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];
80165var 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];
81166
82−var CONST = 0, UNARY = 1, BINARY = 2, INFIX = 3, LEFTBRACKET = 4,
167+var CONST = 0, UNARY = 1, BINARY = 2, INFIX = 3, LEFTBRACKET = 4,
83168 RIGHTBRACKET = 5, SPACE = 6, UNDEROVER = 7, DEFINITION = 8,
84− LEFTRIGHT = 9, TEXT = 10; // token types
85−
86−var AMsqrt = {input:"sqrt", tag:"msqrt", output:"sqrt", tex:null, ttype:UNARY},
87− AMroot = {input:"root", tag:"mroot", output:"root", tex:null, ttype:BINARY},
88− AMfrac = {input:"frac", tag:"mfrac", output:"/", tex:null, ttype:BINARY},
89− AMdiv = {input:"/", tag:"mfrac", output:"/", tex:null, ttype:INFIX},
90− AMover = {input:"stackrel", tag:"mover", output:"stackrel", tex:null, ttype:BINARY},
91− AMsub = {input:"_", tag:"msub", output:"_", tex:null, ttype:INFIX},
92− AMsup = {input:"^", tag:"msup", output:"^", tex:null, ttype:INFIX},
93− AMtext = {input:"text", tag:"mtext", output:"text", tex:null, ttype:TEXT},
94− AMmbox = {input:"mbox", tag:"mtext", output:"mbox", tex:null, ttype:TEXT},
95− AMquote = {input:"\"", tag:"mtext", output:"mbox", tex:null, ttype:TEXT};
169+ LEFTRIGHT = 9, TEXT = 10, BIG = 11, LONG = 12, STRETCHY = 13,
170+ MATRIX = 14;; // token types
171+
172+var AMquote = {input:"\"", tag:"mtext", output:"mbox", tex:null, ttype:TEXT};
96173
97174var AMsymbols = [
98175//some greek symbols
@@ -134,6 +211,7 @@ var AMsymbols = [
134211{input:"zeta", tag:"mi", output:"\u03B6", tex:null, ttype:CONST},
135212
136213//binary operation symbols
214+//{input:"-", tag:"mo", output:"\u0096", tex:null, ttype:CONST},
137215{input:"*", tag:"mo", output:"\u22C5", tex:"cdot", ttype:CONST},
138216{input:"**", tag:"mo", output:"\u22C6", tex:"star", ttype:CONST},
139217{input:"//", tag:"mo", output:"/", tex:null, ttype:CONST},
@@ -275,22 +353,32 @@ var AMsymbols = [
275353{input:"darr", tag:"mo", output:"\u2193", tex:"downarrow", ttype:CONST},
276354{input:"rarr", tag:"mo", output:"\u2192", tex:"rightarrow", ttype:CONST},
277355{input:"->", tag:"mo", output:"\u2192", tex:"to", ttype:CONST},
356+{input:">->", tag:"mo", output:"\u21A3", tex:"rightarrowtail", ttype:CONST},
357+{input:"->>", tag:"mo", output:"\u21A0", tex:"twoheadrightarrow", ttype:CONST},
358+{input:">->>", tag:"mo", output:"\u2916", tex:"twoheadrightarrowtail", ttype:CONST},
278359{input:"|->", tag:"mo", output:"\u21A6", tex:"mapsto", ttype:CONST},
279360{input:"larr", tag:"mo", output:"\u2190", tex:"leftarrow", ttype:CONST},
280361{input:"harr", tag:"mo", output:"\u2194", tex:"leftrightarrow", ttype:CONST},
281362{input:"rArr", tag:"mo", output:"\u21D2", tex:"Rightarrow", ttype:CONST},
282363{input:"lArr", tag:"mo", output:"\u21D0", tex:"Leftarrow", ttype:CONST},
283364{input:"hArr", tag:"mo", output:"\u21D4", tex:"Leftrightarrow", ttype:CONST},
284−
285365//commands with argument
286−AMsqrt, AMroot, AMfrac, AMdiv, AMover, AMsub, AMsup,
366+{input:"sqrt", tag:"msqrt", output:"sqrt", tex:null, ttype:UNARY},
367+{input:"root", tag:"mroot", output:"root", tex:null, ttype:BINARY},
368+{input:"frac", tag:"mfrac", output:"/", tex:null, ttype:BINARY},
369+{input:"/", tag:"mfrac", output:"/", tex:null, ttype:INFIX},
370+{input:"stackrel", tag:"mover", output:"stackrel", tex:null, ttype:BINARY},
371+{input:"_", tag:"msub", output:"_", tex:null, ttype:INFIX},
372+{input:"^", tag:"msup", output:"^", tex:null, ttype:INFIX},
287373{input:"hat", tag:"mover", output:"\u005E", tex:null, ttype:UNARY, acc:true},
288374{input:"bar", tag:"mover", output:"\u00AF", tex:"overline", ttype:UNARY, acc:true},
289375{input:"vec", tag:"mover", output:"\u2192", tex:null, ttype:UNARY, acc:true},
290376{input:"dot", tag:"mover", output:".", tex:null, ttype:UNARY, acc:true},
291377{input:"ddot", tag:"mover", output:"..", tex:null, ttype:UNARY, acc:true},
292378{input:"ul", tag:"munder", output:"\u0332", tex:"underline", ttype:UNARY, acc:true},
293−AMtext, AMmbox, AMquote,
379+{input:"text", tag:"mtext", output:"text", tex:null, ttype:TEXT},
380+{input:"mbox", tag:"mtext", output:"mbox", tex:null, ttype:TEXT},
381+AMquote,
294382{input:"bb", tag:"mstyle", atname:"fontweight", atval:"bold", output:"bb", tex:null, ttype:UNARY},
295383{input:"mathbf", tag:"mstyle", atname:"fontweight", atval:"bold", output:"mathbf", tex:null, ttype:UNARY},
296384{input:"sf", tag:"mstyle", atname:"fontfamily", atval:"sans-serif", output:"sf", tex:null, ttype:UNARY},
@@ -312,35 +400,32 @@ function compareNames(s1,s2) {
312400
313401var AMnames = []; //list of input symbols
314402
315−function AMinitSymbols() {
403+function initSymbols() {
316404 var texsymbols = [], i;
317405 for (i=0; i<AMsymbols.length; i++)
318406 if (AMsymbols[i].tex)
319407 texsymbols[texsymbols.length] = {input:AMsymbols[i].tex,
320408 tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype};
321409 AMsymbols = AMsymbols.concat(texsymbols);
322− AMsymbols.sort(compareNames);
323− for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
410+ refreshSymbols();
324411}
325412
326−var AMmathml = "http://www.w3.org/1998/Math/MathML";
327−
328−function AMcreateElementMathML(t) {
329− if (isIE) return document.createElement("m:"+t);
330− else return document.createElementNS(AMmathml,t);
331−}
332−
333−function AMcreateMmlNode(t,frag) {
334−// var node = AMcreateElementMathML(name);
335− if (isIE) var node = document.createElement("m:"+t);
336− else var node = document.createElementNS(AMmathml,t);
337− node.appendChild(frag);
338− return node;
413+function refreshSymbols(){
414+ var i;
415+ AMsymbols.sort(compareNames);
416+ for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
417+ LMsymbols.sort(compareNames);
418+ for (i=0; i<LMsymbols.length; i++) LMnames[i] = LMsymbols[i].input;
339419}
340420
341−function newcommand(oldstr,newstr) {
342− AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
421+function define(oldstr,newstr) {
422+ if(oldstr.substr(0,1)=="\\")
423+ LMsymbols = LMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
424+ ttype:DEFINITION}]);
425+ else
426+ AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
343427 tex:null, ttype:DEFINITION}]);
428+ refreshSymbols(); // this may be a problem if many symbols are defined!
344429}
345430
346431function AMremoveCharsAndBlanks(str,n) {
@@ -353,7 +438,7 @@ function AMremoveCharsAndBlanks(str,n) {
353438 return st.slice(i);
354439}
355440
356−function AMposition(arr, str, n) {
441+function position(arr, str, n) {
357442// return position >=n where str appears or would be inserted
358443// assumes arr is sorted
359444 if (n==0) {
@@ -383,7 +468,7 @@ function AMgetSymbol(str) {
383468 for (var i=1; i<=str.length && more; i++) {
384469 st = str.slice(0,i); //initial substring of length i
385470 j = k;
386− k = AMposition(AMnames, st, j);
471+ k = position(AMnames, st, j);
387472 if (k<AMnames.length && str.slice(0,AMnames[k].length)==AMnames[k]){
388473 match = AMnames[k];
389474 mk = k;
@@ -460,11 +545,10 @@ function AMparseSexpr(str) { //parses str and returns [node,tailstr]
460545 str = symbol.output+AMremoveCharsAndBlanks(str,symbol.input.length);
461546 symbol = AMgetSymbol(str);
462547 }
463− switch (symbol.ttype) {
464− case UNDEROVER:
548+ switch (symbol.ttype) { case UNDEROVER:
465549 case CONST:
466550 str = AMremoveCharsAndBlanks(str,symbol.input.length);
467− return [AMcreateMmlNode(symbol.tag, //its a constant
551+ return [createMmlNode(symbol.tag, //its a constant
468552 document.createTextNode(symbol.output)),str];
469553 case LEFTBRACKET: //read (expr+)
470554 AMnestingDepth++;
@@ -472,10 +556,10 @@ function AMparseSexpr(str) { //parses str and returns [node,tailstr]
472556 result = AMparseExpr(str,true);
473557 AMnestingDepth--;
474558 if (typeof symbol.invisible == "boolean" && symbol.invisible)
475− node = AMcreateMmlNode("mrow",result[0]);
559+ node = createMmlNode("mrow",result[0]);
476560 else {
477− node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
478− node = AMcreateMmlNode("mrow",node);
561+ node = createMmlNode("mo",document.createTextNode(symbol.output));
562+ node = createMmlNode("mrow",node);
479563 node.appendChild(result[0]);
480564 }
481565 return [node,result[1]];
@@ -489,42 +573,42 @@ function AMparseSexpr(str) { //parses str and returns [node,tailstr]
489573 if (i==-1) i = str.length;
490574 st = str.slice(1,i);
491575 if (st.charAt(0) == " ") {
492− node = AMcreateElementMathML("mspace");
576+ node = createMmlNode("mspace");
493577 node.setAttribute("width","1ex");
494578 newFrag.appendChild(node);
495579 }
496580 newFrag.appendChild(
497− AMcreateMmlNode(symbol.tag,document.createTextNode(st)));
581+ createMmlNode(symbol.tag,document.createTextNode(st)));
498582 if (st.charAt(st.length-1) == " ") {
499− node = AMcreateElementMathML("mspace");
583+ node = createMmlNode("mspace");
500584 node.setAttribute("width","1ex");
501585 newFrag.appendChild(node);
502586 }
503587 str = AMremoveCharsAndBlanks(str,i+1);
504− return [AMcreateMmlNode("mrow",newFrag),str];
588+ return [createMmlNode("mrow",newFrag),str];
505589 case UNARY:
506590 str = AMremoveCharsAndBlanks(str,symbol.input.length);
507591 result = AMparseSexpr(str);
508− if (result[0]==null) return [AMcreateMmlNode(symbol.tag,
592+ if (result[0]==null) return [createMmlNode(symbol.tag,
509593 document.createTextNode(symbol.output)),str];
510594 if (typeof symbol.func == "boolean" && symbol.func) { // functions hack
511595 st = str.charAt(0);
512596 if (st=="^" || st=="_" || st=="/" || st=="|" || st==",") {
513− return [AMcreateMmlNode(symbol.tag,
597+ return [createMmlNode(symbol.tag,
514598 document.createTextNode(symbol.output)),str];
515599 } else {
516− node = AMcreateMmlNode("mrow",
517− AMcreateMmlNode(symbol.tag,document.createTextNode(symbol.output)));
600+ node = createMmlNode("mrow",
601+ createMmlNode(symbol.tag,document.createTextNode(symbol.output)));
518602 node.appendChild(result[0]);
519603 return [node,result[1]];
520604 }
521605 }
522606 AMremoveBrackets(result[0]);
523607 if (symbol.input == "sqrt") { // sqrt
524− return [AMcreateMmlNode(symbol.tag,result[0]),result[1]];
608+ return [createMmlNode(symbol.tag,result[0]),result[1]];
525609 } else if (typeof symbol.acc == "boolean" && symbol.acc) { // accent
526− node = AMcreateMmlNode(symbol.tag,result[0]);
527− node.appendChild(AMcreateMmlNode("mo",document.createTextNode(symbol.output)));
610+ node = createMmlNode(symbol.tag,result[0]);
611+ node.appendChild(createMmlNode("mo",document.createTextNode(symbol.output)));
528612 return [node,result[1]];
529613 } else { // font change command
530614 if (!isIE && typeof symbol.codes != "undefined") {
@@ -538,45 +622,46 @@ function AMparseSexpr(str) { //parses str and returns [node,tailstr]
538622 String.fromCharCode(symbol.codes[st.charCodeAt(j)-65]);
539623 else newst = newst + st.charAt(j);
540624 if (result[0].nodeName=="mi")
541− result[0]=AMcreateElementMathML("mo").
625+ result[0]=createMmlNode("mo").
542626 appendChild(document.createTextNode(newst));
543− else result[0].replaceChild(AMcreateElementMathML("mo").
544− appendChild(document.createTextNode(newst)),result[0].childNodes[i]);
627+ else result[0].replaceChild(createMmlNode("mo").
628+ appendChild(document.createTextNode(newst)),
629+ result[0].childNodes[i]);
545630 }
546631 }
547− node = AMcreateMmlNode(symbol.tag,result[0]);
632+ node = createMmlNode(symbol.tag,result[0]);
548633 node.setAttribute(symbol.atname,symbol.atval);
549634 return [node,result[1]];
550635 }
551636 case BINARY:
552637 str = AMremoveCharsAndBlanks(str,symbol.input.length);
553638 result = AMparseSexpr(str);
554− if (result[0]==null) return [AMcreateMmlNode("mo",
639+ if (result[0]==null) return [createMmlNode("mo",
555640 document.createTextNode(symbol.input)),str];
556641 AMremoveBrackets(result[0]);
557642 var result2 = AMparseSexpr(result[1]);
558− if (result2[0]==null) return [AMcreateMmlNode("mo",
643+ if (result2[0]==null) return [createMmlNode("mo",
559644 document.createTextNode(symbol.input)),str];
560645 AMremoveBrackets(result2[0]);
561646 if (symbol.input=="root" || symbol.input=="stackrel")
562647 newFrag.appendChild(result2[0]);
563648 newFrag.appendChild(result[0]);
564649 if (symbol.input=="frac") newFrag.appendChild(result2[0]);
565− return [AMcreateMmlNode(symbol.tag,newFrag),result2[1]];
650+ return [createMmlNode(symbol.tag,newFrag),result2[1]];
566651 case INFIX:
567652 str = AMremoveCharsAndBlanks(str,symbol.input.length);
568− return [AMcreateMmlNode("mo",document.createTextNode(symbol.output)),str];
653+ return [createMmlNode("mo",document.createTextNode(symbol.output)),str];
569654 case SPACE:
570655 str = AMremoveCharsAndBlanks(str,symbol.input.length);
571− node = AMcreateElementMathML("mspace");
656+ node = createMmlNode("mspace");
572657 node.setAttribute("width","1ex");
573658 newFrag.appendChild(node);
574659 newFrag.appendChild(
575− AMcreateMmlNode(symbol.tag,document.createTextNode(symbol.output)));
576− node = AMcreateElementMathML("mspace");
660+ createMmlNode(symbol.tag,document.createTextNode(symbol.output)));
661+ node = createMmlNode("mspace");
577662 node.setAttribute("width","1ex");
578663 newFrag.appendChild(node);
579− return [AMcreateMmlNode("mrow",newFrag),str];
664+ return [createMmlNode("mrow",newFrag),str];
580665 case LEFTRIGHT:
581666// if (rightvert) return [null,str]; else rightvert = true;
582667 AMnestingDepth++;
@@ -587,19 +672,19 @@ function AMparseSexpr(str) { //parses str and returns [node,tailstr]
587672 if (result[0].lastChild!=null)
588673 st = result[0].lastChild.firstChild.nodeValue;
589674 if (st == "|") { // its an absolute value subterm
590− node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
591− node = AMcreateMmlNode("mrow",node);
675+ node = createMmlNode("mo",document.createTextNode(symbol.output));
676+ node = createMmlNode("mrow",node);
592677 node.appendChild(result[0]);
593678 return [node,result[1]];
594− } else { // the "|" is a \mid
595− node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
596− node = AMcreateMmlNode("mrow",node);
679+ } else { // the "|" is a \mid so use unicode 2223 (divides) for spacing
680+ node = createMmlNode("mo",document.createTextNode("\u2223"));
681+ node = createMmlNode("mrow",node);
597682 return [node,str];
598683 }
599684 default:
600685//alert("default");
601686 str = AMremoveCharsAndBlanks(str,symbol.input.length);
602− return [AMcreateMmlNode(symbol.tag, //its a constant
687+ return [createMmlNode(symbol.tag, //its a constant
603688 document.createTextNode(symbol.output)),str];
604689 }
605690}
@@ -617,7 +702,7 @@ function AMparseIexpr(str) {
617702// if (symbol.input == "/") result = AMparseIexpr(str); else ...
618703 result = AMparseSexpr(str);
619704 if (result[0] == null) // show box in place of missing argument
620− result[0] = AMcreateMmlNode("mo",document.createTextNode("\u25A1"));
705+ result[0] = createMmlNode("mo",document.createTextNode("\u25A1"));
621706 else AMremoveBrackets(result[0]);
622707 str = result[1];
623708// if (symbol.input == "/") AMremoveBrackets(node);
@@ -629,16 +714,16 @@ function AMparseIexpr(str) {
629714 var res2 = AMparseSexpr(str);
630715 AMremoveBrackets(res2[0]);
631716 str = res2[1];
632− node = AMcreateMmlNode((underover?"munderover":"msubsup"),node);
717+ node = createMmlNode((underover?"munderover":"msubsup"),node);
633718 node.appendChild(result[0]);
634719 node.appendChild(res2[0]);
635− node = AMcreateMmlNode("mrow",node); // so sum does not stretch
720+ node = createMmlNode("mrow",node); // so sum does not stretch
636721 } else {
637− node = AMcreateMmlNode((underover?"munder":"msub"),node);
722+ node = createMmlNode((underover?"munder":"msub"),node);
638723 node.appendChild(result[0]);
639724 }
640725 } else {
641− node = AMcreateMmlNode(symbol.tag,node);
726+ node = createMmlNode(symbol.tag,node);
642727 node.appendChild(result[0]);
643728 }
644729 }
@@ -658,11 +743,11 @@ function AMparseExpr(str,rightbracket) {
658743 str = AMremoveCharsAndBlanks(str,symbol.input.length);
659744 result = AMparseIexpr(str);
660745 if (result[0] == null) // show box in place of missing argument
661− result[0] = AMcreateMmlNode("mo",document.createTextNode("\u25A1"));
746+ result[0] = createMmlNode("mo",document.createTextNode("\u25A1"));
662747 else AMremoveBrackets(result[0]);
663748 str = result[1];
664749 AMremoveBrackets(node);
665− node = AMcreateMmlNode(symbol.tag,node);
750+ node = createMmlNode(symbol.tag,node);
666751 node.appendChild(result[0]);
667752 newFrag.appendChild(node);
668753 symbol = AMgetSymbol(str);
@@ -711,18 +796,18 @@ function AMparseExpr(str,rightbracket) {
711796 for (j=1; j<n-1; j++) {
712797 if (typeof pos[i][k] != "undefined" && j==pos[i][k]){
713798 node.removeChild(node.firstChild); //remove ,
714− row.appendChild(AMcreateMmlNode("mtd",frag));
799+ row.appendChild(createMmlNode("mtd",frag));
715800 k++;
716801 } else frag.appendChild(node.firstChild);
717802 }
718− row.appendChild(AMcreateMmlNode("mtd",frag));
803+ row.appendChild(createMmlNode("mtd",frag));
719804 if (newFrag.childNodes.length>2) {
720805 newFrag.removeChild(newFrag.firstChild); //remove <mrow>)</mrow>
721806 newFrag.removeChild(newFrag.firstChild); //remove <mo>,</mo>
722807 }
723− table.appendChild(AMcreateMmlNode("mtr",row));
808+ table.appendChild(createMmlNode("mtr",row));
724809 }
725− node = AMcreateMmlNode("mtable",table);
810+ node = createMmlNode("mtable",table);
726811 if (typeof symbol.invisible == "boolean" && symbol.invisible) node.setAttribute("columnalign","left");
727812 newFrag.replaceChild(node,newFrag.firstChild);
728813 }
@@ -731,44 +816,40 @@ function AMparseExpr(str,rightbracket) {
731816 }
732817 str = AMremoveCharsAndBlanks(str,symbol.input.length);
733818 if (typeof symbol.invisible != "boolean" || !symbol.invisible) {
734− node = AMcreateMmlNode("mo",document.createTextNode(symbol.output));
819+ node = createMmlNode("mo",document.createTextNode(symbol.output));
735820 newFrag.appendChild(node);
736821 }
737822 }
738823 return [newFrag,str];
739824}
740825
741−function AMparseMath(str) {
742− var result, node = AMcreateElementMathML("mstyle");
743− if (mathcolor != "") node.setAttribute("mathcolor",mathcolor);
744− if (displaystyle) node.setAttribute("displaystyle","true");
745− if (mathfontfamily != "") node.setAttribute("fontfamily",mathfontfamily);
826+function parseMath(str,latex) {
827+ var frag, node;
746828 AMnestingDepth = 0;
747− node.appendChild(AMparseExpr(str.replace(/^\s+/g,""),false)[0]);
748− node = AMcreateMmlNode("math",node);
829+ frag = latex ? LMparseExpr(str.replace(/^\s+/g,""),false,false)[0] : AMparseExpr(str.replace(/^\s+/g,""),false)[0];
830+ node = createMmlNode("mstyle",frag);
831+ node.setAttribute("mathcolor",mathcolor);
832+ node.setAttribute("fontfamily",mathfontfamily);
833+ node.setAttribute("mathsize",mathfontsize);
834+ if (displaystyle) node.setAttribute("displaystyle","true");
835+ node = createMmlNode("math",node);
749836 if (showasciiformulaonhover) //fixed by djhsu so newline
750837 node.setAttribute("title",str.replace(/\s+/g," "));//does not show in Gecko
751− if (mathfontfamily != "" && (isIE || mathfontfamily != "serif")) {
752− var fnode = AMcreateElementXHTML("font");
753− fnode.setAttribute("face",mathfontfamily);
754− fnode.appendChild(node);
755− return fnode;
756− }
757838 return node;
758839}
759840
760−function AMstrarr2docFrag(arr, linebreaks) {
841+function strarr2docFrag(arr, linebreaks, latex) {
761842 var newFrag=document.createDocumentFragment();
762843 var expr = false;
763844 for (var i=0; i<arr.length; i++) {
764− if (expr) newFrag.appendChild(AMparseMath(arr[i]));
845+ if (expr) newFrag.appendChild(parseMath(arr[i],latex));
765846 else {
766847 var arri = (linebreaks ? arr[i].split("\n\n") : [arr[i]]);
767− newFrag.appendChild(AMcreateElementXHTML("span").
848+ newFrag.appendChild(createElementXHTML("span").
768849 appendChild(document.createTextNode(arri[0])));
769850 for (var j=1; j<arri.length; j++) {
770− newFrag.appendChild(AMcreateElementXHTML("p"));
771− newFrag.appendChild(AMcreateElementXHTML("span").
851+ newFrag.appendChild(createElementXHTML("p"));
852+ newFrag.appendChild(createElementXHTML("span").
772853 appendChild(document.createTextNode(arri[j])));
773854 }
774855 }
@@ -777,48 +858,77 @@ function AMstrarr2docFrag(arr, linebreaks) {
777858 return newFrag;
778859}
779860
780−function AMprocessNodeR(n, linebreaks) {
861+function AMautomathrec(str) {
862+//formula is a space (or start of str) followed by a maximal sequence of *two* or more tokens, possibly separated by runs of digits and/or space.
863+//tokens are single letters (except a, A, I) and ASCIIMathML tokens
864+ var texcommand = "\\\\[a-zA-Z]+|\\\\\\s|";
865+ var ambigAMtoken = "\\b(?:oo|lim|ln|int|oint|del|grad|aleph|prod|prop|sinh|cosh|tanh|cos|sec|pi|tt|fr|sf|sube|supe|sub|sup|det|mod|gcd|lcm|min|max|vec|ddot|ul|chi|eta|nu|mu)(?![a-z])|";
866+ var englishAMtoken = "\\b(?:sum|ox|log|sin|tan|dim|hat|bar|dot)(?![a-z])|";
867+ var secondenglishAMtoken = "|\\bI\\b|\\bin\\b|\\btext\\b"; // took if and or not out
868+ var simpleAMtoken = "NN|ZZ|QQ|RR|CC|TT|AA|EE|sqrt|dx|dy|dz|dt|xx|vv|uu|nn|bb|cc|csc|cot|alpha|beta|delta|Delta|epsilon|gamma|Gamma|kappa|lambda|Lambda|omega|phi|Phi|Pi|psi|Psi|rho|sigma|Sigma|tau|theta|Theta|xi|Xi|zeta"; // uuu nnn?
869+ var letter = "[a-zA-HJ-Z](?=(?:[^a-zA-Z]|$|"+ambigAMtoken+englishAMtoken+simpleAMtoken+"))|";
870+ var token = letter+texcommand+"\\d+|[-()[\\]{}+=*&^_%\\\@/<>,\\|!:;'~]|\\.(?!(?:\x20|$))|"+ambigAMtoken+englishAMtoken+simpleAMtoken;
871+ var re = new RegExp("(^|\\s)((("+token+")\\s?)(("+token+secondenglishAMtoken+")\\s?)+)([,.?]?(?=\\s|$))","g");
872+ str = str.replace(re," `$2`$7");
873+ var arr = str.split(AMdelimiter1);
874+ var re1 = new RegExp("(^|\\s)([b-zB-HJ-Z+*<>]|"+texcommand+ambigAMtoken+simpleAMtoken+")(\\s|\\n|$)","g");
875+ var re2 = new RegExp("(^|\\s)([a-z]|"+texcommand+ambigAMtoken+simpleAMtoken+")([,.])","g"); // removed |\d+ for now
876+ for (i=0; i<arr.length; i++) //single nonenglish tokens
877+ if (i%2==0) {
878+ arr[i] = arr[i].replace(re1," `$2`$3");
879+ arr[i] = arr[i].replace(re2," `$2`$3");
880+ arr[i] = arr[i].replace(/([{}[\]])/,"`$1`");
881+ }
882+ str = arr.join(AMdelimiter1);
883+ str = str.replace(/((^|\s)\([a-zA-Z]{2,}.*?)\)`/g,"$1`)"); //fix parentheses
884+ str = str.replace(/`(\((a\s|in\s))(.*?[a-zA-Z]{2,}\))/g,"$1`$3"); //fix parentheses
885+ str = str.replace(/\sin`/g,"` in");
886+ str = str.replace(/`(\(\w\)[,.]?(\s|\n|$))/g,"$1`");
887+ str = str.replace(/`([0-9.]+|e.g|i.e)`(\.?)/gi,"$1$2");
888+ str = str.replace(/`([0-9.]+:)`/g,"$1");
889+ return str;
890+}
891+
892+function processNodeR(n, linebreaks,latex) {
781893 var mtch, str, arr, frg, i;
782894 if (n.childNodes.length == 0) {
783895 if ((n.nodeType!=8 || linebreaks) &&
784896 n.parentNode.nodeName!="form" && n.parentNode.nodeName!="FORM" &&
785− n.parentNode.nodeName!="textarea" && n.parentNode.nodeName!="TEXTAREA" &&
786− n.parentNode.nodeName!="code" && n.parentNode.nodeName!="CODE" && /* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
787−See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
788− n.parentNode.nodeName!="pre" && n.parentNode.nodeName!="PRE") {
897+ n.parentNode.nodeName!="textarea" && n.parentNode.nodeName!="TEXTAREA" /* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
898+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */) {
789899 str = n.nodeValue;
790900 if (!(str == null)) {
791901 str = str.replace(/\r\n\r\n/g,"\n\n");
792− if (doubleblankmathdelimiter) {
793− str = str.replace(/\x20\x20\./g," "+AMdelimiter1+".");
794− str = str.replace(/\x20\x20,/g," "+AMdelimiter1+",");
795− str = str.replace(/\x20\x20/g," "+AMdelimiter1+" ");
796− }
797902 str = str.replace(/\x20+/g," ");
798903 str = str.replace(/\s*\r\n/g," ");
904+ if(latex) {
905+// DELIMITERS:
906+ mtch = (str.indexOf("\$")==-1 ? false : true);
907+ str = str.replace(/([^\\])\$/g,"$1 \$");
908+ str = str.replace(/^\$/," \$"); // in case \$ at start of string
909+ arr = str.split(" \$");
910+ for (i=0; i<arr.length; i++)
911+ arr[i]=arr[i].replace(/\\\$/g,"\$");
912+ } else {
799913 mtch = false;
800− str = str.replace(new RegExp(AMescape2, "g"),
801− function(st){mtch=true;return "AMescape2"});
802914 str = str.replace(new RegExp(AMescape1, "g"),
803− function(st){mtch=true;return "AMescape1"});
804− str = str.replace(new RegExp(AMdelimiter2regexp, "g"),AMdelimiter1);
915+ function(){mtch = true; return "AMescape1"});
916+ str = str.replace(/\\?end{?a?math}?/i,
917+ function(){automathrecognize = false; mtch = true; return ""});
918+ str = str.replace(/amath\b|\\begin{a?math}/i,
919+ function(){automathrecognize = true; mtch = true; return ""});
920+ arr = str.split(AMdelimiter1);
921+ if (automathrecognize)
922+ for (i=0; i<arr.length; i++)
923+ if (i%2==0) arr[i] = AMautomathrec(arr[i]);
924+ str = arr.join(AMdelimiter1);
805925 arr = str.split(AMdelimiter1);
806− for (i=0; i<arr.length; i++)
807− arr[i]=arr[i].replace(/AMescape2/g,AMdelimiter2).
808− replace(/AMescape1/g,AMdelimiter1);
926+ for (i=0; i<arr.length; i++) // this is a problem ************
927+ arr[i]=arr[i].replace(/AMescape1/g,AMdelimiter1);
928+ }
809929 if (arr.length>1 || mtch) {
810− if (checkForMathML) {
811− checkForMathML = false;
812− var nd = AMisMathMLavailable();
813− AMnoMathML = nd != null;
814− if (AMnoMathML && notifyIfNoMathML)
815− if (alertIfNoMathML)
816− alert("To view the ASCIIMathML notation use Internet Explorer 6 +\nMathPlayer (free from www.dessci.com)\n\
817− or Firefox/Mozilla/Netscape");
818− else AMbody.insertBefore(nd,AMbody.childNodes[0]);
819− }
820− if (!AMnoMathML) {
821− frg = AMstrarr2docFrag(arr,n.nodeType==8);
930+ if (!noMathML) {
931+ frg = strarr2docFrag(arr,n.nodeType==8,latex);
822932 var len = frg.childNodes.length;
823933 n.parentNode.replaceChild(frg,n);
824934 return len-1;
@@ -828,7 +938,7 @@ See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
828938 } else return 0;
829939 } else if (n.nodeName!="math") {
830940 for (i=0; i<n.childNodes.length; i++)
831− i += AMprocessNodeR(n.childNodes[i], linebreaks);
941+ i += processNodeR(n.childNodes[i], linebreaks,latex);
832942 }
833943 return 0;
834944}
@@ -838,46 +948,2255 @@ function AMprocessNode(n, linebreaks, spanclassAM) {
838948 if (spanclassAM!=null) {
839949 frag = document.getElementsByTagName("span")
840950 for (var i=0;i<frag.length;i++)
841− if (frag[i].className == "AM")
842− AMprocessNodeR(frag[i],linebreaks);
951+ if (frag[i].className == "AM")
952+ processNodeR(frag[i],linebreaks,false);
843953 } else {
844954 try {
845− st = n.innerHTML;
955+ st = n.innerHTML; // look for AMdelimiter on page
846956 } catch(err) {}
847− if (st==null ||
848− st.indexOf(AMdelimiter1)!=-1 || st.indexOf(AMdelimiter2)!=-1)
849− AMprocessNodeR(n,linebreaks);
957+//alert(st)
958+ if (st==null || /amath\b|\\begin{a?math}/i.test(st) ||
959+ st.indexOf(AMdelimiter1+" ")!=-1 || st.slice(-1)==AMdelimiter1 ||
960+ st.indexOf(AMdelimiter1+"<")!=-1 || st.indexOf(AMdelimiter1+"\n")!=-1) {
961+ processNodeR(n,linebreaks,false);
962+ }
850963 }
851− if (isIE) { //needed to match size and font of formula to surrounding text
852− frag = document.getElementsByTagName('math');
853− for (var i=0;i<frag.length;i++) frag[i].update()
964+/* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
965+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
966+}
967+
968+/* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
969+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
970+
971+// all further global variables start with "LM"
972+
973+// Commented out by DRW to prevent 1/2 turning into a 2-line fraction
974+// LMdiv = {input:"/", tag:"mfrac", output:"/", ttype:INFIX},
975+// Commented out by DRW so that " prints literally in equations
976+// LMquote = {input:"\"", tag:"mtext", output:"mbox", ttype:TEXT};
977+
978+var LMsymbols = [
979+//Greek letters
980+{input:"\\alpha", tag:"mi", output:"\u03B1", ttype:CONST},
981+{input:"\\beta", tag:"mi", output:"\u03B2", ttype:CONST},
982+{input:"\\gamma", tag:"mi", output:"\u03B3", ttype:CONST},
983+{input:"\\delta", tag:"mi", output:"\u03B4", ttype:CONST},
984+{input:"\\epsilon", tag:"mi", output:"\u03B5", ttype:CONST},
985+{input:"\\varepsilon", tag:"mi", output:"\u025B", ttype:CONST},
986+{input:"\\zeta", tag:"mi", output:"\u03B6", ttype:CONST},
987+{input:"\\eta", tag:"mi", output:"\u03B7", ttype:CONST},
988+{input:"\\theta", tag:"mi", output:"\u03B8", ttype:CONST},
989+{input:"\\vartheta", tag:"mi", output:"\u03D1", ttype:CONST},
990+{input:"\\iota", tag:"mi", output:"\u03B9", ttype:CONST},
991+{input:"\\kappa", tag:"mi", output:"\u03BA", ttype:CONST},
992+{input:"\\lambda", tag:"mi", output:"\u03BB", ttype:CONST},
993+{input:"\\mu", tag:"mi", output:"\u03BC", ttype:CONST},
994+{input:"\\nu", tag:"mi", output:"\u03BD", ttype:CONST},
995+{input:"\\xi", tag:"mi", output:"\u03BE", ttype:CONST},
996+{input:"\\pi", tag:"mi", output:"\u03C0", ttype:CONST},
997+{input:"\\varpi", tag:"mi", output:"\u03D6", ttype:CONST},
998+{input:"\\rho", tag:"mi", output:"\u03C1", ttype:CONST},
999+{input:"\\varrho", tag:"mi", output:"\u03F1", ttype:CONST},
1000+{input:"\\varsigma", tag:"mi", output:"\u03C2", ttype:CONST},
1001+{input:"\\sigma", tag:"mi", output:"\u03C3", ttype:CONST},
1002+{input:"\\tau", tag:"mi", output:"\u03C4", ttype:CONST},
1003+{input:"\\upsilon", tag:"mi", output:"\u03C5", ttype:CONST},
1004+{input:"\\phi", tag:"mi", output:"\u03C6", ttype:CONST},
1005+{input:"\\varphi", tag:"mi", output:"\u03D5", ttype:CONST},
1006+{input:"\\chi", tag:"mi", output:"\u03C7", ttype:CONST},
1007+{input:"\\psi", tag:"mi", output:"\u03C8", ttype:CONST},
1008+{input:"\\omega", tag:"mi", output:"\u03C9", ttype:CONST},
1009+{input:"\\Gamma", tag:"mo", output:"\u0393", ttype:CONST},
1010+{input:"\\Delta", tag:"mo", output:"\u0394", ttype:CONST},
1011+{input:"\\Theta", tag:"mo", output:"\u0398", ttype:CONST},
1012+{input:"\\Lambda", tag:"mo", output:"\u039B", ttype:CONST},
1013+{input:"\\Xi", tag:"mo", output:"\u039E", ttype:CONST},
1014+{input:"\\Pi", tag:"mo", output:"\u03A0", ttype:CONST},
1015+{input:"\\Sigma", tag:"mo", output:"\u03A3", ttype:CONST},
1016+{input:"\\Upsilon", tag:"mo", output:"\u03A5", ttype:CONST},
1017+{input:"\\Phi", tag:"mo", output:"\u03A6", ttype:CONST},
1018+{input:"\\Psi", tag:"mo", output:"\u03A8", ttype:CONST},
1019+{input:"\\Omega", tag:"mo", output:"\u03A9", ttype:CONST},
1020+
1021+//fractions
1022+{input:"\\frac12", tag:"mo", output:"\u00BD", ttype:CONST},
1023+{input:"\\frac14", tag:"mo", output:"\u00BC", ttype:CONST},
1024+{input:"\\frac34", tag:"mo", output:"\u00BE", ttype:CONST},
1025+{input:"\\frac13", tag:"mo", output:"\u2153", ttype:CONST},
1026+{input:"\\frac23", tag:"mo", output:"\u2154", ttype:CONST},
1027+{input:"\\frac15", tag:"mo", output:"\u2155", ttype:CONST},
1028+{input:"\\frac25", tag:"mo", output:"\u2156", ttype:CONST},
1029+{input:"\\frac35", tag:"mo", output:"\u2157", ttype:CONST},
1030+{input:"\\frac45", tag:"mo", output:"\u2158", ttype:CONST},
1031+{input:"\\frac16", tag:"mo", output:"\u2159", ttype:CONST},
1032+{input:"\\frac56", tag:"mo", output:"\u215A", ttype:CONST},
1033+{input:"\\frac18", tag:"mo", output:"\u215B", ttype:CONST},
1034+{input:"\\frac38", tag:"mo", output:"\u215C", ttype:CONST},
1035+{input:"\\frac58", tag:"mo", output:"\u215D", ttype:CONST},
1036+{input:"\\frac78", tag:"mo", output:"\u215E", ttype:CONST},
1037+
1038+//binary operation symbols
1039+{input:"\\pm", tag:"mo", output:"\u00B1", ttype:CONST},
1040+{input:"\\mp", tag:"mo", output:"\u2213", ttype:CONST},
1041+{input:"\\triangleleft",tag:"mo", output:"\u22B2", ttype:CONST},
1042+{input:"\\triangleright",tag:"mo",output:"\u22B3", ttype:CONST},
1043+{input:"\\cdot", tag:"mo", output:"\u22C5", ttype:CONST},
1044+{input:"\\star", tag:"mo", output:"\u22C6", ttype:CONST},
1045+{input:"\\ast", tag:"mo", output:"\u002A", ttype:CONST},
1046+{input:"\\times", tag:"mo", output:"\u00D7", ttype:CONST},
1047+{input:"\\div", tag:"mo", output:"\u00F7", ttype:CONST},
1048+{input:"\\circ", tag:"mo", output:"\u2218", ttype:CONST},
1049+//{input:"\\bullet", tag:"mo", output:"\u2219", ttype:CONST},
1050+{input:"\\bullet", tag:"mo", output:"\u2022", ttype:CONST},
1051+{input:"\\oplus", tag:"mo", output:"\u2295", ttype:CONST},
1052+{input:"\\ominus", tag:"mo", output:"\u2296", ttype:CONST},
1053+{input:"\\otimes", tag:"mo", output:"\u2297", ttype:CONST},
1054+{input:"\\bigcirc", tag:"mo", output:"\u25CB", ttype:CONST},
1055+{input:"\\oslash", tag:"mo", output:"\u2298", ttype:CONST},
1056+{input:"\\odot", tag:"mo", output:"\u2299", ttype:CONST},
1057+{input:"\\land", tag:"mo", output:"\u2227", ttype:CONST},
1058+{input:"\\wedge", tag:"mo", output:"\u2227", ttype:CONST},
1059+{input:"\\lor", tag:"mo", output:"\u2228", ttype:CONST},
1060+{input:"\\vee", tag:"mo", output:"\u2228", ttype:CONST},
1061+{input:"\\cap", tag:"mo", output:"\u2229", ttype:CONST},
1062+{input:"\\cup", tag:"mo", output:"\u222A", ttype:CONST},
1063+{input:"\\sqcap", tag:"mo", output:"\u2293", ttype:CONST},
1064+{input:"\\sqcup", tag:"mo", output:"\u2294", ttype:CONST},
1065+{input:"\\uplus", tag:"mo", output:"\u228E", ttype:CONST},
1066+{input:"\\amalg", tag:"mo", output:"\u2210", ttype:CONST},
1067+{input:"\\bigtriangleup",tag:"mo",output:"\u25B3", ttype:CONST},
1068+{input:"\\bigtriangledown",tag:"mo",output:"\u25BD", ttype:CONST},
1069+{input:"\\dag", tag:"mo", output:"\u2020", ttype:CONST},
1070+{input:"\\dagger", tag:"mo", output:"\u2020", ttype:CONST},
1071+{input:"\\ddag", tag:"mo", output:"\u2021", ttype:CONST},
1072+{input:"\\ddagger", tag:"mo", output:"\u2021", ttype:CONST},
1073+{input:"\\lhd", tag:"mo", output:"\u22B2", ttype:CONST},
1074+{input:"\\rhd", tag:"mo", output:"\u22B3", ttype:CONST},
1075+{input:"\\unlhd", tag:"mo", output:"\u22B4", ttype:CONST},
1076+{input:"\\unrhd", tag:"mo", output:"\u22B5", ttype:CONST},
1077+
1078+
1079+//BIG Operators
1080+{input:"\\sum", tag:"mo", output:"\u2211", ttype:UNDEROVER},
1081+{input:"\\prod", tag:"mo", output:"\u220F", ttype:UNDEROVER},
1082+{input:"\\bigcap", tag:"mo", output:"\u22C2", ttype:UNDEROVER},
1083+{input:"\\bigcup", tag:"mo", output:"\u22C3", ttype:UNDEROVER},
1084+{input:"\\bigwedge", tag:"mo", output:"\u22C0", ttype:UNDEROVER},
1085+{input:"\\bigvee", tag:"mo", output:"\u22C1", ttype:UNDEROVER},
1086+{input:"\\bigsqcap", tag:"mo", output:"\u2A05", ttype:UNDEROVER},
1087+{input:"\\bigsqcup", tag:"mo", output:"\u2A06", ttype:UNDEROVER},
1088+{input:"\\coprod", tag:"mo", output:"\u2210", ttype:UNDEROVER},
1089+{input:"\\bigoplus", tag:"mo", output:"\u2A01", ttype:UNDEROVER},
1090+{input:"\\bigotimes", tag:"mo", output:"\u2A02", ttype:UNDEROVER},
1091+{input:"\\bigodot", tag:"mo", output:"\u2A00", ttype:UNDEROVER},
1092+{input:"\\biguplus", tag:"mo", output:"\u2A04", ttype:UNDEROVER},
1093+{input:"\\int", tag:"mo", output:"\u222B", ttype:CONST},
1094+{input:"\\oint", tag:"mo", output:"\u222E", ttype:CONST},
1095+
1096+//binary relation symbols
1097+{input:":=", tag:"mo", output:":=", ttype:CONST},
1098+{input:"\\lt", tag:"mo", output:"<", ttype:CONST},
1099+{input:"\\gt", tag:"mo", output:">", ttype:CONST},
1100+{input:"\\ne", tag:"mo", output:"\u2260", ttype:CONST},
1101+{input:"\\neq", tag:"mo", output:"\u2260", ttype:CONST},
1102+{input:"\\le", tag:"mo", output:"\u2264", ttype:CONST},
1103+{input:"\\leq", tag:"mo", output:"\u2264", ttype:CONST},
1104+{input:"\\leqslant", tag:"mo", output:"\u2264", ttype:CONST},
1105+{input:"\\ge", tag:"mo", output:"\u2265", ttype:CONST},
1106+{input:"\\geq", tag:"mo", output:"\u2265", ttype:CONST},
1107+{input:"\\geqslant", tag:"mo", output:"\u2265", ttype:CONST},
1108+{input:"\\equiv", tag:"mo", output:"\u2261", ttype:CONST},
1109+{input:"\\ll", tag:"mo", output:"\u226A", ttype:CONST},
1110+{input:"\\gg", tag:"mo", output:"\u226B", ttype:CONST},
1111+{input:"\\doteq", tag:"mo", output:"\u2250", ttype:CONST},
1112+{input:"\\prec", tag:"mo", output:"\u227A", ttype:CONST},
1113+{input:"\\succ", tag:"mo", output:"\u227B", ttype:CONST},
1114+{input:"\\preceq", tag:"mo", output:"\u227C", ttype:CONST},
1115+{input:"\\succeq", tag:"mo", output:"\u227D", ttype:CONST},
1116+{input:"\\subset", tag:"mo", output:"\u2282", ttype:CONST},
1117+{input:"\\supset", tag:"mo", output:"\u2283", ttype:CONST},
1118+{input:"\\subseteq", tag:"mo", output:"\u2286", ttype:CONST},
1119+{input:"\\supseteq", tag:"mo", output:"\u2287", ttype:CONST},
1120+{input:"\\sqsubset", tag:"mo", output:"\u228F", ttype:CONST},
1121+{input:"\\sqsupset", tag:"mo", output:"\u2290", ttype:CONST},
1122+{input:"\\sqsubseteq", tag:"mo", output:"\u2291", ttype:CONST},
1123+{input:"\\sqsupseteq", tag:"mo", output:"\u2292", ttype:CONST},
1124+{input:"\\sim", tag:"mo", output:"\u223C", ttype:CONST},
1125+{input:"\\simeq", tag:"mo", output:"\u2243", ttype:CONST},
1126+{input:"\\approx", tag:"mo", output:"\u2248", ttype:CONST},
1127+{input:"\\cong", tag:"mo", output:"\u2245", ttype:CONST},
1128+{input:"\\Join", tag:"mo", output:"\u22C8", ttype:CONST},
1129+{input:"\\bowtie", tag:"mo", output:"\u22C8", ttype:CONST},
1130+{input:"\\in", tag:"mo", output:"\u2208", ttype:CONST},
1131+{input:"\\ni", tag:"mo", output:"\u220B", ttype:CONST},
1132+{input:"\\owns", tag:"mo", output:"\u220B", ttype:CONST},
1133+{input:"\\propto", tag:"mo", output:"\u221D", ttype:CONST},
1134+{input:"\\vdash", tag:"mo", output:"\u22A2", ttype:CONST},
1135+{input:"\\dashv", tag:"mo", output:"\u22A3", ttype:CONST},
1136+{input:"\\models", tag:"mo", output:"\u22A8", ttype:CONST},
1137+{input:"\\perp", tag:"mo", output:"\u22A5", ttype:CONST},
1138+{input:"\\smile", tag:"mo", output:"\u2323", ttype:CONST},
1139+{input:"\\frown", tag:"mo", output:"\u2322", ttype:CONST},
1140+{input:"\\asymp", tag:"mo", output:"\u224D", ttype:CONST},
1141+{input:"\\notin", tag:"mo", output:"\u2209", ttype:CONST},
1142+
1143+//matrices
1144+{input:"\\begin{eqnarray}", output:"X", ttype:MATRIX, invisible:true},
1145+{input:"\\begin{array}", output:"X", ttype:MATRIX, invisible:true},
1146+{input:"\\\\", output:"}&{", ttype:DEFINITION},
1147+{input:"\\end{eqnarray}", output:"}}", ttype:DEFINITION},
1148+{input:"\\end{array}", output:"}}", ttype:DEFINITION},
1149+
1150+//grouping and literal brackets -- ieval is for IE
1151+{input:"\\big", tag:"mo", output:"X", atval:"1.2", ieval:"2.2", ttype:BIG},
1152+{input:"\\Big", tag:"mo", output:"X", atval:"1.6", ieval:"2.6", ttype:BIG},
1153+{input:"\\bigg", tag:"mo", output:"X", atval:"2.2", ieval:"3.2", ttype:BIG},
1154+{input:"\\Bigg", tag:"mo", output:"X", atval:"2.9", ieval:"3.9", ttype:BIG},
1155+{input:"\\left", tag:"mo", output:"X", ttype:LEFTBRACKET},
1156+{input:"\\right", tag:"mo", output:"X", ttype:RIGHTBRACKET},
1157+{input:"{", output:"{", ttype:LEFTBRACKET, invisible:true},
1158+{input:"}", output:"}", ttype:RIGHTBRACKET, invisible:true},
1159+
1160+{input:"(", tag:"mo", output:"(", atval:"1", ttype:STRETCHY},
1161+{input:"[", tag:"mo", output:"[", atval:"1", ttype:STRETCHY},
1162+{input:"\\lbrack", tag:"mo", output:"[", atval:"1", ttype:STRETCHY},
1163+{input:"\\{", tag:"mo", output:"{", atval:"1", ttype:STRETCHY},
1164+{input:"\\lbrace", tag:"mo", output:"{", atval:"1", ttype:STRETCHY},
1165+{input:"\\langle", tag:"mo", output:"\u2329", atval:"1", ttype:STRETCHY},
1166+{input:"\\lfloor", tag:"mo", output:"\u230A", atval:"1", ttype:STRETCHY},
1167+{input:"\\lceil", tag:"mo", output:"\u2308", atval:"1", ttype:STRETCHY},
1168+
1169+// rtag:"mi" causes space to be inserted before a following sin, cos, etc.
1170+// (see function LMparseExpr() )
1171+{input:")", tag:"mo",output:")", rtag:"mi",atval:"1",ttype:STRETCHY},
1172+{input:"]", tag:"mo",output:"]", rtag:"mi",atval:"1",ttype:STRETCHY},
1173+{input:"\\rbrack",tag:"mo",output:"]", rtag:"mi",atval:"1",ttype:STRETCHY},
1174+{input:"\\}", tag:"mo",output:"}", rtag:"mi",atval:"1",ttype:STRETCHY},
1175+{input:"\\rbrace",tag:"mo",output:"}", rtag:"mi",atval:"1",ttype:STRETCHY},
1176+{input:"\\rangle",tag:"mo",output:"\u232A", rtag:"mi",atval:"1",ttype:STRETCHY},
1177+{input:"\\rfloor",tag:"mo",output:"\u230B", rtag:"mi",atval:"1",ttype:STRETCHY},
1178+{input:"\\rceil", tag:"mo",output:"\u2309", rtag:"mi",atval:"1",ttype:STRETCHY},
1179+
1180+// "|", "\\|", "\\vert" and "\\Vert" modified later: lspace = rspace = 0em
1181+{input:"|", tag:"mo", output:"\u2223", atval:"1", ttype:STRETCHY},
1182+{input:"\\|", tag:"mo", output:"\u2225", atval:"1", ttype:STRETCHY},
1183+{input:"\\vert", tag:"mo", output:"\u2223", atval:"1", ttype:STRETCHY},
1184+{input:"\\Vert", tag:"mo", output:"\u2225", atval:"1", ttype:STRETCHY},
1185+{input:"\\mid", tag:"mo", output:"\u2223", atval:"1", ttype:STRETCHY},
1186+{input:"\\parallel", tag:"mo", output:"\u2225", atval:"1", ttype:STRETCHY},
1187+{input:"/", tag:"mo", output:"/", atval:"1.01", ttype:STRETCHY},
1188+{input:"\\backslash", tag:"mo", output:"\u2216", atval:"1", ttype:STRETCHY},
1189+{input:"\\setminus", tag:"mo", output:"\\", ttype:CONST},
1190+
1191+//miscellaneous symbols
1192+{input:"\\!", tag:"mspace", atname:"width", atval:"-0.167em", ttype:SPACE},
1193+{input:"\\,", tag:"mspace", atname:"width", atval:"0.167em", ttype:SPACE},
1194+{input:"\\>", tag:"mspace", atname:"width", atval:"0.222em", ttype:SPACE},
1195+{input:"\\:", tag:"mspace", atname:"width", atval:"0.222em", ttype:SPACE},
1196+{input:"\\;", tag:"mspace", atname:"width", atval:"0.278em", ttype:SPACE},
1197+{input:"~", tag:"mspace", atname:"width", atval:"0.333em", ttype:SPACE},
1198+{input:"\\quad", tag:"mspace", atname:"width", atval:"1em", ttype:SPACE},
1199+{input:"\\qquad", tag:"mspace", atname:"width", atval:"2em", ttype:SPACE},
1200+//{input:"{}", tag:"mo", output:"\u200B", ttype:CONST}, // zero-width
1201+{input:"\\prime", tag:"mo", output:"\u2032", ttype:CONST},
1202+{input:"'", tag:"mo", output:"\u02B9", ttype:CONST},
1203+{input:"''", tag:"mo", output:"\u02BA", ttype:CONST},
1204+{input:"'''", tag:"mo", output:"\u2034", ttype:CONST},
1205+{input:"''''", tag:"mo", output:"\u2057", ttype:CONST},
1206+{input:"\\ldots", tag:"mo", output:"\u2026", ttype:CONST},
1207+{input:"\\cdots", tag:"mo", output:"\u22EF", ttype:CONST},
1208+{input:"\\vdots", tag:"mo", output:"\u22EE", ttype:CONST},
1209+{input:"\\ddots", tag:"mo", output:"\u22F1", ttype:CONST},
1210+{input:"\\forall", tag:"mo", output:"\u2200", ttype:CONST},
1211+{input:"\\exists", tag:"mo", output:"\u2203", ttype:CONST},
1212+{input:"\\Re", tag:"mo", output:"\u211C", ttype:CONST},
1213+{input:"\\Im", tag:"mo", output:"\u2111", ttype:CONST},
1214+{input:"\\aleph", tag:"mo", output:"\u2135", ttype:CONST},
1215+{input:"\\hbar", tag:"mo", output:"\u210F", ttype:CONST},
1216+{input:"\\ell", tag:"mo", output:"\u2113", ttype:CONST},
1217+{input:"\\wp", tag:"mo", output:"\u2118", ttype:CONST},
1218+{input:"\\emptyset", tag:"mo", output:"\u2205", ttype:CONST},
1219+{input:"\\infty", tag:"mo", output:"\u221E", ttype:CONST},
1220+{input:"\\surd", tag:"mo", output:"\\sqrt{}", ttype:DEFINITION},
1221+{input:"\\partial", tag:"mo", output:"\u2202", ttype:CONST},
1222+{input:"\\nabla", tag:"mo", output:"\u2207", ttype:CONST},
1223+{input:"\\triangle", tag:"mo", output:"\u25B3", ttype:CONST},
1224+{input:"\\therefore", tag:"mo", output:"\u2234", ttype:CONST},
1225+{input:"\\angle", tag:"mo", output:"\u2220", ttype:CONST},
1226+//{input:"\\\\ ", tag:"mo", output:"\u00A0", ttype:CONST},
1227+{input:"\\diamond", tag:"mo", output:"\u22C4", ttype:CONST},
1228+//{input:"\\Diamond", tag:"mo", output:"\u25CA", ttype:CONST},
1229+{input:"\\Diamond", tag:"mo", output:"\u25C7", ttype:CONST},
1230+{input:"\\neg", tag:"mo", output:"\u00AC", ttype:CONST},
1231+{input:"\\lnot", tag:"mo", output:"\u00AC", ttype:CONST},
1232+{input:"\\bot", tag:"mo", output:"\u22A5", ttype:CONST},
1233+{input:"\\top", tag:"mo", output:"\u22A4", ttype:CONST},
1234+{input:"\\square", tag:"mo", output:"\u25AB", ttype:CONST},
1235+{input:"\\Box", tag:"mo", output:"\u25A1", ttype:CONST},
1236+{input:"\\wr", tag:"mo", output:"\u2240", ttype:CONST},
1237+
1238+//standard functions
1239+//Note UNDEROVER *must* have tag:"mo" to work properly
1240+{input:"\\arccos", tag:"mi", output:"arccos", ttype:UNARY, func:true},
1241+{input:"\\arcsin", tag:"mi", output:"arcsin", ttype:UNARY, func:true},
1242+{input:"\\arctan", tag:"mi", output:"arctan", ttype:UNARY, func:true},
1243+{input:"\\arg", tag:"mi", output:"arg", ttype:UNARY, func:true},
1244+{input:"\\cos", tag:"mi", output:"cos", ttype:UNARY, func:true},
1245+{input:"\\cosh", tag:"mi", output:"cosh", ttype:UNARY, func:true},
1246+{input:"\\cot", tag:"mi", output:"cot", ttype:UNARY, func:true},
1247+{input:"\\coth", tag:"mi", output:"coth", ttype:UNARY, func:true},
1248+{input:"\\csc", tag:"mi", output:"csc", ttype:UNARY, func:true},
1249+{input:"\\deg", tag:"mi", output:"deg", ttype:UNARY, func:true},
1250+{input:"\\det", tag:"mi", output:"det", ttype:UNARY, func:true},
1251+{input:"\\dim", tag:"mi", output:"dim", ttype:UNARY, func:true}, //CONST?
1252+{input:"\\exp", tag:"mi", output:"exp", ttype:UNARY, func:true},
1253+{input:"\\gcd", tag:"mi", output:"gcd", ttype:UNARY, func:true}, //CONST?
1254+{input:"\\hom", tag:"mi", output:"hom", ttype:UNARY, func:true},
1255+{input:"\\inf", tag:"mo", output:"inf", ttype:UNDEROVER},
1256+{input:"\\ker", tag:"mi", output:"ker", ttype:UNARY, func:true},
1257+{input:"\\lg", tag:"mi", output:"lg", ttype:UNARY, func:true},
1258+{input:"\\lim", tag:"mo", output:"lim", ttype:UNDEROVER},
1259+{input:"\\liminf", tag:"mo", output:"liminf", ttype:UNDEROVER},
1260+{input:"\\limsup", tag:"mo", output:"limsup", ttype:UNDEROVER},
1261+{input:"\\ln", tag:"mi", output:"ln", ttype:UNARY, func:true},
1262+{input:"\\log", tag:"mi", output:"log", ttype:UNARY, func:true},
1263+{input:"\\max", tag:"mo", output:"max", ttype:UNDEROVER},
1264+{input:"\\min", tag:"mo", output:"min", ttype:UNDEROVER},
1265+{input:"\\Pr", tag:"mi", output:"Pr", ttype:UNARY, func:true},
1266+{input:"\\sec", tag:"mi", output:"sec", ttype:UNARY, func:true},
1267+{input:"\\sin", tag:"mi", output:"sin", ttype:UNARY, func:true},
1268+{input:"\\sinh", tag:"mi", output:"sinh", ttype:UNARY, func:true},
1269+{input:"\\sup", tag:"mo", output:"sup", ttype:UNDEROVER},
1270+{input:"\\tan", tag:"mi", output:"tan", ttype:UNARY, func:true},
1271+{input:"\\tanh", tag:"mi", output:"tanh", ttype:UNARY, func:true},
1272+
1273+//arrows
1274+{input:"\\gets", tag:"mo", output:"\u2190", ttype:CONST},
1275+{input:"\\leftarrow", tag:"mo", output:"\u2190", ttype:CONST},
1276+{input:"\\to", tag:"mo", output:"\u2192", ttype:CONST},
1277+{input:"\\rightarrow", tag:"mo", output:"\u2192", ttype:CONST},
1278+{input:"\\leftrightarrow", tag:"mo", output:"\u2194", ttype:CONST},
1279+{input:"\\uparrow", tag:"mo", output:"\u2191", ttype:CONST},
1280+{input:"\\downarrow", tag:"mo", output:"\u2193", ttype:CONST},
1281+{input:"\\updownarrow", tag:"mo", output:"\u2195", ttype:CONST},
1282+{input:"\\Leftarrow", tag:"mo", output:"\u21D0", ttype:CONST},
1283+{input:"\\Rightarrow", tag:"mo", output:"\u21D2", ttype:CONST},
1284+{input:"\\Leftrightarrow", tag:"mo", output:"\u21D4", ttype:CONST},
1285+{input:"\\iff", tag:"mo", output:"~\\Longleftrightarrow~", ttype:DEFINITION},
1286+{input:"\\Uparrow", tag:"mo", output:"\u21D1", ttype:CONST},
1287+{input:"\\Downarrow", tag:"mo", output:"\u21D3", ttype:CONST},
1288+{input:"\\Updownarrow", tag:"mo", output:"\u21D5", ttype:CONST},
1289+{input:"\\mapsto", tag:"mo", output:"\u21A6", ttype:CONST},
1290+{input:"\\longleftarrow", tag:"mo", output:"\u2190", ttype:LONG},
1291+{input:"\\longrightarrow", tag:"mo", output:"\u2192", ttype:LONG},
1292+{input:"\\longleftrightarrow", tag:"mo", output:"\u2194", ttype:LONG},
1293+{input:"\\Longleftarrow", tag:"mo", output:"\u21D0", ttype:LONG},
1294+{input:"\\Longrightarrow", tag:"mo", output:"\u21D2", ttype:LONG},
1295+{input:"\\implies", tag:"mo", output:"\u21D2", ttype:LONG},
1296+{input:"\\Longleftrightarrow", tag:"mo", output:"\u21D4", ttype:LONG},
1297+{input:"\\longmapsto", tag:"mo", output:"\u21A6", ttype:CONST},
1298+ // disaster if LONG
1299+
1300+//commands with argument
1301+
1302+{input:"\\sqrt", tag:"msqrt", output:"sqrt", ttype:UNARY},
1303+{input:"\\root", tag:"mroot", output:"root", ttype:BINARY},
1304+{input:"\\frac", tag:"mfrac", output:"/", ttype:BINARY},
1305+{input:"\\stackrel", tag:"mover", output:"stackrel", ttype:BINARY},
1306+{input:"\\atop", tag:"mfrac", output:"", ttype:INFIX},
1307+{input:"\\choose", tag:"mfrac", output:"", ttype:INFIX},
1308+{input:"_", tag:"msub", output:"_", ttype:INFIX},
1309+{input:"^", tag:"msup", output:"^", ttype:INFIX},
1310+{input:"\\mathrm", tag:"mtext", output:"text", ttype:TEXT},
1311+{input:"\\mbox", tag:"mtext", output:"mbox", ttype:TEXT},
1312+
1313+//diacritical marks
1314+{input:"\\acute", tag:"mover", output:"\u00B4", ttype:UNARY, acc:true},
1315+//{input:"\\acute", tag:"mover", output:"\u0317", ttype:UNARY, acc:true},
1316+//{input:"\\acute", tag:"mover", output:"\u0301", ttype:UNARY, acc:true},
1317+//{input:"\\grave", tag:"mover", output:"\u0300", ttype:UNARY, acc:true},
1318+//{input:"\\grave", tag:"mover", output:"\u0316", ttype:UNARY, acc:true},
1319+{input:"\\grave", tag:"mover", output:"\u0060", ttype:UNARY, acc:true},
1320+{input:"\\breve", tag:"mover", output:"\u02D8", ttype:UNARY, acc:true},
1321+{input:"\\check", tag:"mover", output:"\u02C7", ttype:UNARY, acc:true},
1322+{input:"\\dot", tag:"mover", output:".", ttype:UNARY, acc:true},
1323+{input:"\\ddot", tag:"mover", output:"..", ttype:UNARY, acc:true},
1324+//{input:"\\ddot", tag:"mover", output:"\u00A8", ttype:UNARY, acc:true},
1325+{input:"\\mathring", tag:"mover", output:"\u00B0", ttype:UNARY, acc:true},
1326+{input:"\\vec", tag:"mover", output:"\u20D7", ttype:UNARY, acc:true},
1327+{input:"\\overrightarrow",tag:"mover",output:"\u20D7", ttype:UNARY, acc:true},
1328+{input:"\\overleftarrow",tag:"mover", output:"\u20D6", ttype:UNARY, acc:true},
1329+{input:"\\hat", tag:"mover", output:"\u005E", ttype:UNARY, acc:true},
1330+{input:"\\widehat", tag:"mover", output:"\u0302", ttype:UNARY, acc:true},
1331+{input:"\\tilde", tag:"mover", output:"~", ttype:UNARY, acc:true},
1332+//{input:"\\tilde", tag:"mover", output:"\u0303", ttype:UNARY, acc:true},
1333+{input:"\\widetilde", tag:"mover", output:"\u02DC", ttype:UNARY, acc:true},
1334+{input:"\\bar", tag:"mover", output:"\u203E", ttype:UNARY, acc:true},
1335+{input:"\\overbrace", tag:"mover", output:"\u23B4", ttype:UNARY, acc:true},
1336+{input:"\\overline", tag:"mover", output:"\u00AF", ttype:UNARY, acc:true},
1337+{input:"\\underbrace", tag:"munder", output:"\u23B5", ttype:UNARY, acc:true},
1338+{input:"\\underline", tag:"munder", output:"\u00AF", ttype:UNARY, acc:true},
1339+//{input:"underline", tag:"munder", output:"\u0332", ttype:UNARY, acc:true},
1340+
1341+//typestyles and fonts
1342+{input:"\\displaystyle",tag:"mstyle",atname:"displaystyle",atval:"true", ttype:UNARY},
1343+{input:"\\textstyle",tag:"mstyle",atname:"displaystyle",atval:"false", ttype:UNARY},
1344+{input:"\\scriptstyle",tag:"mstyle",atname:"scriptlevel",atval:"1", ttype:UNARY},
1345+{input:"\\scriptscriptstyle",tag:"mstyle",atname:"scriptlevel",atval:"2", ttype:UNARY},
1346+{input:"\\textrm", tag:"mstyle", output:"\\mathrm", ttype: DEFINITION},
1347+{input:"\\mathbf", tag:"mstyle", atname:"mathvariant", atval:"bold", ttype:UNARY},
1348+{input:"\\textbf", tag:"mstyle", atname:"mathvariant", atval:"bold", ttype:UNARY},
1349+{input:"\\mathit", tag:"mstyle", atname:"mathvariant", atval:"italic", ttype:UNARY},
1350+{input:"\\textit", tag:"mstyle", atname:"mathvariant", atval:"italic", ttype:UNARY},
1351+{input:"\\mathtt", tag:"mstyle", atname:"mathvariant", atval:"monospace", ttype:UNARY},
1352+{input:"\\texttt", tag:"mstyle", atname:"mathvariant", atval:"monospace", ttype:UNARY},
1353+{input:"\\mathsf", tag:"mstyle", atname:"mathvariant", atval:"sans-serif", ttype:UNARY},
1354+{input:"\\mathbb", tag:"mstyle", atname:"mathvariant", atval:"double-struck", ttype:UNARY, codes:AMbbb},
1355+{input:"\\mathcal",tag:"mstyle", atname:"mathvariant", atval:"script", ttype:UNARY, codes:AMcal},
1356+{input:"\\mathfrak",tag:"mstyle",atname:"mathvariant", atval:"fraktur",ttype:UNARY, codes:AMfrk}
1357+];
1358+
1359+var LMnames = []; //list of input symbols
1360+
1361+function LMremoveCharsAndBlanks(str,n) {
1362+//remove n characters and any following blanks
1363+ var st;
1364+ st = str.slice(n);
1365+ for (var i=0; i<st.length && st.charCodeAt(i)<=32; i=i+1);
1366+ return st.slice(i);
1367+}
1368+
1369+function LMgetSymbol(str) {
1370+//return maximal initial substring of str that appears in names
1371+//return null if there is none
1372+ var k = 0; //new pos
1373+ var j = 0; //old pos
1374+ var mk; //match pos
1375+ var st;
1376+ var tagst;
1377+ var match = "";
1378+ var more = true;
1379+ for (var i=1; i<=str.length && more; i++) {
1380+ st = str.slice(0,i); //initial substring of length i
1381+ j = k;
1382+ k = position(LMnames, st, j);
1383+ if (k<LMnames.length && str.slice(0,LMnames[k].length)==LMnames[k]){
1384+ match = LMnames[k];
1385+ mk = k;
1386+ i = match.length;
1387+ }
1388+ more = k<LMnames.length && str.slice(0,LMnames[k].length)>=LMnames[k];
1389+ }
1390+ LMpreviousSymbol=LMcurrentSymbol;
1391+ if (match!=""){
1392+ LMcurrentSymbol=LMsymbols[mk].ttype;
1393+ return LMsymbols[mk];
8541394 }
1395+ LMcurrentSymbol=CONST;
1396+ k = 1;
1397+ st = str.slice(0,1); //take 1 character
1398+ if ("0"<=st && st<="9") tagst = "mn";
1399+ else tagst = (("A">st || st>"Z") && ("a">st || st>"z")?"mo":"mi");
1400+/* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
1401+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
1402+ return {input:st, tag:tagst, output:st, ttype:CONST};
8551403}
8561404
857−var AMbody;
858−var AMnoMathML = false, AMtranslated = false;
8591405
860−function translate(spanclassAM) {
861− if (!AMtranslated) { // run this only once
862− AMtranslated = true;
863− AMinitSymbols();
864− AMbody = document.getElementsByTagName("body")[0];
865− AMprocessNode(AMbody, false, spanclassAM);
1406+/* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
1407+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
1408+
1409+var LMpreviousSymbol,LMcurrentSymbol;
1410+
1411+function LMparseSexpr(str) { //parses str and returns [node,tailstr,(node)tag]
1412+ var symbol, node, result, result2, i, st,// rightvert = false,
1413+ newFrag = document.createDocumentFragment();
1414+ str = LMremoveCharsAndBlanks(str,0);
1415+ symbol = LMgetSymbol(str); //either a token or a bracket or empty
1416+ if (symbol == null || symbol.ttype == RIGHTBRACKET)
1417+ return [null,str,null];
1418+ if (symbol.ttype == DEFINITION) {
1419+ str = symbol.output+LMremoveCharsAndBlanks(str,symbol.input.length);
1420+ symbol = LMgetSymbol(str);
1421+ if (symbol == null || symbol.ttype == RIGHTBRACKET)
1422+ return [null,str,null];
1423+ }
1424+ str = LMremoveCharsAndBlanks(str,symbol.input.length);
1425+ switch (symbol.ttype) {
1426+ case SPACE:
1427+ node = createMmlNode(symbol.tag);
1428+ node.setAttribute(symbol.atname,symbol.atval);
1429+ return [node,str,symbol.tag];
1430+ case UNDEROVER:
1431+ if (isIE) {
1432+ if (symbol.input.substr(0,4) == "\\big") { // botch for missing symbols
1433+ str = "\\"+symbol.input.substr(4)+str; // make \bigcup = \cup etc.
1434+ symbol = LMgetSymbol(str);
1435+ symbol.ttype = UNDEROVER;
1436+ str = LMremoveCharsAndBlanks(str,symbol.input.length);
1437+ }
1438+ }
1439+ return [createMmlNode(symbol.tag,
1440+ document.createTextNode(symbol.output)),str,symbol.tag];
1441+ case CONST:
1442+ var output = symbol.output;
1443+ if (isIE) {
1444+ if (symbol.input == "'")
1445+ output = "\u2032";
1446+ else if (symbol.input == "''")
1447+ output = "\u2033";
1448+ else if (symbol.input == "'''")
1449+ output = "\u2033\u2032";
1450+ else if (symbol.input == "''''")
1451+ output = "\u2033\u2033";
1452+ else if (symbol.input == "\\square")
1453+ output = "\u25A1"; // same as \Box
1454+ else if (symbol.input.substr(0,5) == "\\frac") {
1455+ // botch for missing fractions
1456+ var denom = symbol.input.substr(6,1);
1457+ if (denom == "5" || denom == "6") {
1458+ str = symbol.input.replace(/\\frac/,"\\frac ")+str;
1459+ return [node,str,symbol.tag];
1460+ }
1461+ }
1462+ }
1463+ node = createMmlNode(symbol.tag,document.createTextNode(output));
1464+ return [node,str,symbol.tag];
1465+ case LONG: // added by DRW
1466+ node = createMmlNode(symbol.tag,document.createTextNode(symbol.output));
1467+ node.setAttribute("minsize","1.5");
1468+ node.setAttribute("maxsize","1.5");
1469+ node = createMmlNode("mover",node);
1470+ node.appendChild(createMmlNode("mspace"));
1471+ return [node,str,symbol.tag];
1472+ case STRETCHY: // added by DRW
1473+ if (isIE && symbol.input == "\\backslash")
1474+ symbol.output = "\\"; // doesn't expand, but then nor does "\u2216"
1475+ node = createMmlNode(symbol.tag,document.createTextNode(symbol.output));
1476+ if (symbol.input == "|" || symbol.input == "\\vert" ||
1477+ symbol.input == "\\|" || symbol.input == "\\Vert") {
1478+ node.setAttribute("lspace","0em");
1479+ node.setAttribute("rspace","0em");
1480+ }
1481+ node.setAttribute("maxsize",symbol.atval); // don't allow to stretch here
1482+ if (symbol.rtag != null)
1483+ return [node,str,symbol.rtag];
1484+ else
1485+ return [node,str,symbol.tag];
1486+ case BIG: // added by DRW
1487+ var atval = symbol.atval;
1488+ if (isIE)
1489+ atval = symbol.ieval;
1490+ symbol = LMgetSymbol(str);
1491+ if (symbol == null)
1492+ return [null,str,null];
1493+ str = LMremoveCharsAndBlanks(str,symbol.input.length);
1494+ node = createMmlNode(symbol.tag,document.createTextNode(symbol.output));
1495+ if (isIE) { // to get brackets to expand
1496+ var space = createMmlNode("mspace");
1497+ space.setAttribute("height",atval+"ex");
1498+ node = createMmlNode("mrow",node);
1499+ node.appendChild(space);
1500+ } else { // ignored in IE
1501+ node.setAttribute("minsize",atval);
1502+ node.setAttribute("maxsize",atval);
1503+ }
1504+ return [node,str,symbol.tag];
1505+ case LEFTBRACKET: //read (expr+)
1506+ if (symbol.input == "\\left") { // left what?
1507+ symbol = LMgetSymbol(str);
1508+ if (symbol != null) {
1509+ if (symbol.input == ".")
1510+ symbol.invisible = true;
1511+ str = LMremoveCharsAndBlanks(str,symbol.input.length);
1512+ }
1513+ }
1514+ result = LMparseExpr(str,true,false);
1515+ if (symbol==null ||
1516+ (typeof symbol.invisible == "boolean" && symbol.invisible))
1517+ node = createMmlNode("mrow",result[0]);
1518+ else {
1519+ node = createMmlNode("mo",document.createTextNode(symbol.output));
1520+ node = createMmlNode("mrow",node);
1521+ node.appendChild(result[0]);
1522+ }
1523+ return [node,result[1],result[2]];
1524+ case MATRIX: //read (expr+)
1525+ if (symbol.input == "\\begin{array}") {
1526+ var mask = "";
1527+ symbol = LMgetSymbol(str);
1528+ str = LMremoveCharsAndBlanks(str,0);
1529+ if (symbol == null)
1530+ mask = "l";
1531+ else {
1532+ str = LMremoveCharsAndBlanks(str,symbol.input.length);
1533+ if (symbol.input != "{")
1534+ mask = "l";
1535+ else do {
1536+ symbol = LMgetSymbol(str);
1537+ if (symbol != null) {
1538+ str = LMremoveCharsAndBlanks(str,symbol.input.length);
1539+ if (symbol.input != "}")
1540+ mask = mask+symbol.input;
1541+ }
1542+ } while (symbol != null && symbol.input != "" && symbol.input != "}");
1543+ }
1544+ result = LMparseExpr("{"+str,true,true);
1545+// if (result[0]==null) return [createMmlNode("mo",
1546+// document.createTextNode(symbol.input)),str];
1547+ node = createMmlNode("mtable",result[0]);
1548+ mask = mask.replace(/l/g,"left ");
1549+ mask = mask.replace(/r/g,"right ");
1550+ mask = mask.replace(/c/g,"center ");
1551+ node.setAttribute("columnalign",mask);
1552+ node.setAttribute("displaystyle","false");
1553+ if (isIE)
1554+ return [node,result[1],null];
1555+// trying to get a *little* bit of space around the array
1556+// (IE already includes it)
1557+ var lspace = createMmlNode("mspace");
1558+ lspace.setAttribute("width","0.167em");
1559+ var rspace = createMmlNode("mspace");
1560+ rspace.setAttribute("width","0.167em");
1561+ var node1 = createMmlNode("mrow",lspace);
1562+ node1.appendChild(node);
1563+ node1.appendChild(rspace);
1564+ return [node1,result[1],null];
1565+ } else { // eqnarray
1566+ result = LMparseExpr("{"+str,true,true);
1567+ node = createMmlNode("mtable",result[0]);
1568+ if (isIE)
1569+ node.setAttribute("columnspacing","0.25em"); // best in practice?
1570+ else
1571+ node.setAttribute("columnspacing","0.167em"); // correct (but ignored?)
1572+ node.setAttribute("columnalign","right center left");
1573+ node.setAttribute("displaystyle","true");
1574+ node = createMmlNode("mrow",node);
1575+ return [node,result[1],null];
1576+ }
1577+ case TEXT:
1578+ if (str.charAt(0)=="{") i=str.indexOf("}");
1579+ else i = 0;
1580+ if (i==-1)
1581+ i = str.length;
1582+ st = str.slice(1,i);
1583+ if (st.charAt(0) == " ") {
1584+ node = createMmlNode("mspace");
1585+ node.setAttribute("width","0.33em"); // was 1ex
1586+ newFrag.appendChild(node);
1587+ }
1588+ newFrag.appendChild(
1589+ createMmlNode(symbol.tag,document.createTextNode(st)));
1590+ if (st.charAt(st.length-1) == " ") {
1591+ node = createMmlNode("mspace");
1592+ node.setAttribute("width","0.33em"); // was 1ex
1593+ newFrag.appendChild(node);
1594+ }
1595+ str = LMremoveCharsAndBlanks(str,i+1);
1596+ return [createMmlNode("mrow",newFrag),str,null];
1597+ case UNARY:
1598+ result = LMparseSexpr(str);
1599+ if (result[0]==null) return [createMmlNode(symbol.tag,
1600+ document.createTextNode(symbol.output)),str];
1601+ if (typeof symbol.func == "boolean" && symbol.func) { // functions hack
1602+ st = str.charAt(0);
1603+// if (st=="^" || st=="_" || st=="/" || st=="|" || st==",") {
1604+ if (st=="^" || st=="_" || st==",") {
1605+ return [createMmlNode(symbol.tag,
1606+ document.createTextNode(symbol.output)),str,symbol.tag];
1607+ } else {
1608+ node = createMmlNode("mrow",
1609+ createMmlNode(symbol.tag,document.createTextNode(symbol.output)));
1610+ if (isIE) {
1611+ var space = createMmlNode("mspace");
1612+ space.setAttribute("width","0.167em");
1613+ node.appendChild(space);
1614+ }
1615+ node.appendChild(result[0]);
1616+ return [node,result[1],symbol.tag];
1617+ }
1618+ }
1619+ if (symbol.input == "\\sqrt") { // sqrt
1620+ if (isIE) { // set minsize, for \surd
1621+ var space = createMmlNode("mspace");
1622+ space.setAttribute("height","1.2ex");
1623+ space.setAttribute("width","0em"); // probably no effect
1624+ node = createMmlNode(symbol.tag,result[0])
1625+// node.setAttribute("minsize","1"); // ignored
1626+// node = createMmlNode("mrow",node); // hopefully unnecessary
1627+ node.appendChild(space);
1628+ return [node,result[1],symbol.tag];
1629+ } else
1630+ return [createMmlNode(symbol.tag,result[0]),result[1],symbol.tag];
1631+ } else if (typeof symbol.acc == "boolean" && symbol.acc) { // accent
1632+ node = createMmlNode(symbol.tag,result[0]);
1633+ var output = symbol.output;
1634+ if (isIE) {
1635+ if (symbol.input == "\\hat")
1636+ output = "\u0302";
1637+ else if (symbol.input == "\\widehat")
1638+ output = "\u005E";
1639+ else if (symbol.input == "\\bar")
1640+ output = "\u00AF";
1641+ else if (symbol.input == "\\grave")
1642+ output = "\u0300";
1643+ else if (symbol.input == "\\tilde")
1644+ output = "\u0303";
1645+ }
1646+ var node1 = createMmlNode("mo",document.createTextNode(output));
1647+ if (symbol.input == "\\vec" || symbol.input == "\\check")
1648+ // don't allow to stretch
1649+ node1.setAttribute("maxsize","1.2");
1650+ // why doesn't "1" work? \vec nearly disappears in firefox
1651+ if (isIE && symbol.input == "\\bar")
1652+ node1.setAttribute("maxsize","0.5");
1653+ if (symbol.input == "\\underbrace" || symbol.input == "\\underline")
1654+ node1.setAttribute("accentunder","true");
1655+ else
1656+ node1.setAttribute("accent","true");
1657+ node.appendChild(node1);
1658+ if (symbol.input == "\\overbrace" || symbol.input == "\\underbrace")
1659+ node.ttype = UNDEROVER;
1660+ return [node,result[1],symbol.tag];
1661+ } else { // font change or displaystyle command
1662+ if (!isIE && typeof symbol.codes != "undefined") {
1663+ for (i=0; i<result[0].childNodes.length; i++)
1664+ if (result[0].childNodes[i].nodeName=="mi" || result[0].nodeName=="mi") {
1665+ st = (result[0].nodeName=="mi"?result[0].firstChild.nodeValue:
1666+ result[0].childNodes[i].firstChild.nodeValue);
1667+ var newst = [];
1668+ for (var j=0; j<st.length; j++)
1669+ if (st.charCodeAt(j)>64 && st.charCodeAt(j)<91) newst = newst +
1670+ String.fromCharCode(symbol.codes[st.charCodeAt(j)-65]);
1671+ else newst = newst + st.charAt(j);
1672+ if (result[0].nodeName=="mi")
1673+ result[0]=createMmlNode("mo").
1674+ appendChild(document.createTextNode(newst));
1675+ else result[0].replaceChild(createMmlNode("mo").
1676+ appendChild(document.createTextNode(newst)),result[0].childNodes[i]);
1677+ }
1678+ }
1679+ node = createMmlNode(symbol.tag,result[0]);
1680+ node.setAttribute(symbol.atname,symbol.atval);
1681+ if (symbol.input == "\\scriptstyle" ||
1682+ symbol.input == "\\scriptscriptstyle")
1683+ node.setAttribute("displaystyle","false");
1684+ return [node,result[1],symbol.tag];
1685+ }
1686+ case BINARY:
1687+ result = LMparseSexpr(str);
1688+ if (result[0]==null) return [createMmlNode("mo",
1689+ document.createTextNode(symbol.input)),str,null];
1690+ result2 = LMparseSexpr(result[1]);
1691+ if (result2[0]==null) return [createMmlNode("mo",
1692+ document.createTextNode(symbol.input)),str,null];
1693+ if (symbol.input=="\\root" || symbol.input=="\\stackrel")
1694+ newFrag.appendChild(result2[0]);
1695+ newFrag.appendChild(result[0]);
1696+ if (symbol.input=="\\frac") newFrag.appendChild(result2[0]);
1697+ return [createMmlNode(symbol.tag,newFrag),result2[1],symbol.tag];
1698+ case INFIX:
1699+ str = LMremoveCharsAndBlanks(str,symbol.input.length);
1700+ return [createMmlNode("mo",document.createTextNode(symbol.output)),
1701+ str,symbol.tag];
1702+ default:
1703+ return [createMmlNode(symbol.tag, //its a constant
1704+ document.createTextNode(symbol.output)),str,symbol.tag];
8661705 }
8671706}
8681707
869−if (isIE) { // avoid adding MathPlayer info explicitly to each webpage
870− document.write("<object id=\"mathplayer\"\
871− classid=\"clsid:32F66A20-7614-11D4-BD11-00104BD3F987\"></object>");
872− document.write("<?import namespace=\"m\" implementation=\"#mathplayer\"?>");
1708+function LMparseIexpr(str) {
1709+ var symbol, sym1, sym2, node, result, tag, underover;
1710+ str = LMremoveCharsAndBlanks(str,0);
1711+ sym1 = LMgetSymbol(str);
1712+ result = LMparseSexpr(str);
1713+ node = result[0];
1714+ str = result[1];
1715+ tag = result[2];
1716+ symbol = LMgetSymbol(str);
1717+ if (symbol.ttype == INFIX) {
1718+ str = LMremoveCharsAndBlanks(str,symbol.input.length);
1719+ result = LMparseSexpr(str);
1720+ if (result[0] == null) // show box in place of missing argument
1721+ result[0] = createMmlNode("mo",document.createTextNode("\u25A1"));
1722+ str = result[1];
1723+ tag = result[2];
1724+ if (symbol.input == "_" || symbol.input == "^") {
1725+ sym2 = LMgetSymbol(str);
1726+ tag = null; // no space between x^2 and a following sin, cos, etc.
1727+// This is for \underbrace and \overbrace
1728+ underover = ((sym1.ttype == UNDEROVER) || (node.ttype == UNDEROVER));
1729+// underover = (sym1.ttype == UNDEROVER);
1730+ if (symbol.input == "_" && sym2.input == "^") {
1731+ str = LMremoveCharsAndBlanks(str,sym2.input.length);
1732+ var res2 = LMparseSexpr(str);
1733+ str = res2[1];
1734+ tag = res2[2]; // leave space between x_1^2 and a following sin etc.
1735+ node = createMmlNode((underover?"munderover":"msubsup"),node);
1736+ node.appendChild(result[0]);
1737+ node.appendChild(res2[0]);
1738+ } else if (symbol.input == "_") {
1739+ node = createMmlNode((underover?"munder":"msub"),node);
1740+ node.appendChild(result[0]);
1741+ } else {
1742+ node = createMmlNode((underover?"mover":"msup"),node);
1743+ node.appendChild(result[0]);
1744+ }
1745+ node = createMmlNode("mrow",node); // so sum does not stretch
1746+ } else {
1747+ node = createMmlNode(symbol.tag,node);
1748+ if (symbol.input == "\\atop" || symbol.input == "\\choose")
1749+ node.setAttribute("linethickness","0ex");
1750+ node.appendChild(result[0]);
1751+ if (symbol.input == "\\choose")
1752+ node = createMmlNode("mfenced",node);
1753+ }
1754+ }
1755+ return [node,str,tag];
8731756}
8741757
875−// GO1.1 Generic onload by Brothercake
1758+function LMparseExpr(str,rightbracket,matrix) {
1759+ var symbol, node, result, i, tag,
1760+ newFrag = document.createDocumentFragment();
1761+ do {
1762+ str = LMremoveCharsAndBlanks(str,0);
1763+ result = LMparseIexpr(str);
1764+ node = result[0];
1765+ str = result[1];
1766+ tag = result[2];
1767+ symbol = LMgetSymbol(str);
1768+ if (node!=undefined) {
1769+ if ((tag == "mn" || tag == "mi") && symbol!=null &&
1770+ typeof symbol.func == "boolean" && symbol.func) {
1771+ // Add space before \sin in 2\sin x or x\sin x
1772+ var space = createMmlNode("mspace");
1773+ space.setAttribute("width","0.167em");
1774+ node = createMmlNode("mrow",node);
1775+ node.appendChild(space);
1776+ }
1777+ newFrag.appendChild(node);
1778+ }
1779+ } while ((symbol.ttype != RIGHTBRACKET)
1780+ && symbol!=null && symbol.output!="");
1781+ tag = null;
1782+ if (symbol.ttype == RIGHTBRACKET) {
1783+ if (symbol.input == "\\right") { // right what?
1784+ str = LMremoveCharsAndBlanks(str,symbol.input.length);
1785+ symbol = LMgetSymbol(str);
1786+ if (symbol != null && symbol.input == ".")
1787+ symbol.invisible = true;
1788+ if (symbol != null)
1789+ tag = symbol.rtag;
1790+ }
1791+ if (symbol!=null)
1792+ str = LMremoveCharsAndBlanks(str,symbol.input.length); // ready to return
1793+ var len = newFrag.childNodes.length;
1794+ if (matrix &&
1795+ len>0 && newFrag.childNodes[len-1].nodeName == "mrow" && len>1 &&
1796+ newFrag.childNodes[len-2].nodeName == "mo" &&
1797+ newFrag.childNodes[len-2].firstChild.nodeValue == "&") { //matrix
1798+ var pos = []; // positions of ampersands
1799+ var m = newFrag.childNodes.length;
1800+ for (i=0; matrix && i<m; i=i+2) {
1801+ pos[i] = [];
1802+ node = newFrag.childNodes[i];
1803+ for (var j=0; j<node.childNodes.length; j++)
1804+ if (node.childNodes[j].firstChild.nodeValue=="&")
1805+ pos[i][pos[i].length]=j;
1806+ }
1807+ var row, frag, n, k, table = document.createDocumentFragment();
1808+ for (i=0; i<m; i=i+2) {
1809+ row = document.createDocumentFragment();
1810+ frag = document.createDocumentFragment();
1811+ node = newFrag.firstChild; // <mrow> -&-&...&-&- </mrow>
1812+ n = node.childNodes.length;
1813+ k = 0;
1814+ for (j=0; j<n; j++) {
1815+ if (typeof pos[i][k] != "undefined" && j==pos[i][k]){
1816+ node.removeChild(node.firstChild); //remove &
1817+ row.appendChild(createMmlNode("mtd",frag));
1818+ k++;
1819+ } else frag.appendChild(node.firstChild);
1820+ }
1821+ row.appendChild(createMmlNode("mtd",frag));
1822+ if (newFrag.childNodes.length>2) {
1823+ newFrag.removeChild(newFrag.firstChild); //remove <mrow> </mrow>
1824+ newFrag.removeChild(newFrag.firstChild); //remove <mo>&</mo>
1825+ }
1826+ table.appendChild(createMmlNode("mtr",row));
1827+ }
1828+ return [table,str];
1829+ }
1830+ if (typeof symbol.invisible != "boolean" || !symbol.invisible) {
1831+ node = createMmlNode("mo",document.createTextNode(symbol.output));
1832+ newFrag.appendChild(node);
1833+ }
1834+ }
1835+ return [newFrag,str,tag];
1836+}
1837+
1838+var tcnt = 0, dcnt = 0; //theorem and definition counters
1839+
1840+function simpleLaTeXformatting(st) {
1841+ st = st.replace(/\$\$((.|\n)*?)\$\$/g,"<p align=\"center\">$\\displaystyle{$1}$</p>");
1842+ st = st.replace(/\\begin{(theorem|lemma|proposition|corollary)}((.|\n)*?)\\end{\1}/g,function(r,s,t){tcnt++; return "<b>"+s.charAt(0).toUpperCase()+s.slice(1)+" "+tcnt+".</b> <i>"+t.replace(/^\s*<\/?\w+\/?>|\s*<\/?\w+\/?>$/g,"")+"</i>"});
1843+ st = st.replace(/\\begin{(definition|example|remark|problem|exercise|conjecture|solution)}((.|\n)*?)\\end{\1}/g,function(r,s,t){dcnt++; return "<b>"+s.charAt(0).toUpperCase()+s.slice(1)+" "+dcnt+".</b> "+t.replace(/^\s*<\/?\w+\/?>|\s*<\/?\w+\/?>$/g,"")});
1844+ st = st.replace(/\\begin{proof}((.|\n)*?)\\end{proof}/g,function(s,t){return "<i>Proof:</i> "+t.replace(/^\s*<\/?\w+\/?>|\s*<\/?\w+\/?>$/g,"")+" &#x25A1;"});
1845+ st = st.replace(/\\emph{(.*?)}/g,"<em>$1</em>");
1846+ st = st.replace(/\\textbf{(.*?)}/g,"<b>$1</b>");
1847+ st = st.replace(/\\cite{(.*?)}/g,"[$1]");
1848+ st = st.replace(/\\chapter{(.*?)}/g,"<h2>$1</h2>");
1849+ st = st.replace(/\\section{(.*?)}(\s*<\/?(br|p)\s?\/?>)?/g,"<h3>$1</h3>");
1850+ st = st.replace(/\\subsection{((.|\n)*?)}/g,"<h4>$1</h4>");
1851+ st = st.replace(/\\begin{itemize}(\s*<\/?(br|p)\s?\/?>)?/g,"<ul>");
1852+ st = st.replace(/\\item\s((.|\n)*?)(?=(\\item|\\end))/g,"<li>$1</li>");
1853+ st = st.replace(/\\end{itemize}(\s*<\/?(br|p)\s?\/?>)?/g,"</ul>");
1854+ st = st.replace(/\\begin{enumerate}(\s*<\/?(br|p)\s?\/?>)?/g,"<ol>");
1855+ st = st.replace(/\\end{enumerate}(\s*<\/?(br|p)\s?\/?>)?/g,"</ol>");
1856+ st = st.replace(/\\item\[(.*?)]{(.*?)}/g,"<dt>$1</dt><dd>$2</dd>");
1857+ st = st.replace(/\\begin{description}/g,"<dl>");
1858+ st = st.replace(/\\end{description}/g,"</dl>");
1859+ st = st.replace(/\\newline\b/g,"<br/>");
1860+ st = st.replace(/\\newpage\b/g,"<br style=\"page-break-after:always;\">");
1861+ st = st.replace(/\\par\b/g,"<p>&nbsp;</p>");
1862+ st = st.replace(/\\bigskip/g,"<p style=\"margin-bottom:0.5in\">&nbsp;</p>");
1863+ st = st.replace(/\\medskip/g,"<p style=\"margin-bottom:0.3in\">&nbsp;</p>");
1864+ st = st.replace(/\\smallskip/g,"<p style=\"margin-bottom:0.15in\">&nbsp;</p>");
1865+ st = st.replace(/\\begin{center}((.|\n)*?)\\end{center}/g,"<center>$1</center>");
1866+ return st
1867+}
1868+
1869+function ASCIIandgraphformatting(st) {
1870+ st = st.replace(/<sup>(.*?)<\/sup>(\s|(\S))/gi,"^{$1} $3");
1871+//st = st.replace(/<\/?font.*?>/gi,""); // do this only in amath...endamath
1872+ st = st.replace(/(Proof:)/g,"<i>$1</i>");
1873+ st = st.replace(/QED/g,"&nbsp; &nbsp; &#x25A1;");
1874+ st = st.replace(/(\\?end{?a?math}?)/ig,"<span></span>$1");
1875+ st = st.replace(/(\bamath\b|\\begin{a?math})/ig,"<span></span>$1");
1876+ st = st.replace(/([>\n])(Theorem|Lemma|Proposition|Corollary|Definition|Example|Remark|Problem|Exercise|Conjecture|Solution)(:|\W\W?(\w|\s|-|\.)*?\W?:)/g,"$1<b>$2$3</b>");
1877+ st = st.replace(/<embed\s+class\s?=\s?"?ASCIIsvg"?/gi,"<embed class=\"ASCIIsvg\" src=\""+dsvglocation+"d.svg\" wmode=\"transparent\"");
1878+ st = st.replace(/(?:\\begin{a?graph}|\bagraph|\(:graph\s)((.|\n)*?)(?:\\end{a?graph}|enda?graph|:\))/g,function(s,t){return "<table><tr><td><div class=\"ASCIIsvg\"><embed class=\"ASCIIsvg\" src=\""+dsvglocation+"d.svg\" wmode=\"transparent\" script=\'"+t.replace(/<\/?(br|p|pre)\s?\/?>/gi,"\n")+"\'/></div></td></tr></table>"});
1879+ st = st.replace(/insertASCIIMathCalculator/g,"<div class=\"ASCIIMathCalculator\"></div>");
1880+//alert(dsvglocation)
1881+ return st
1882+}
1883+
1884+function LMprocessNode(n) {
1885+ var frag,st;
1886+ try {
1887+ st = n.innerHTML;
1888+ } catch(err) {}
1889+ var am = /amath\b|graph/i.test(st);
1890+ if ((st==null || st.indexOf("\$ ")!=-1 || st.indexOf("\$<")!=-1 ||
1891+ st.indexOf("\\begin")!=-1 || am || st.slice(-1)=="$" ||
1892+ st.indexOf("\$\n")!=-1)&& !/edit-content|HTMLArea|wikiedit|wpTextbox1/.test(st)){
1893+ if (!avoidinnerHTML && translateLaTeXformatting)
1894+ st = simpleLaTeXformatting(st);
1895+ if (st!=null && am && !avoidinnerHTML) {
1896+ st = ASCIIandgraphformatting(st);
1897+ }
1898+ st = st.replace(/%7E/g,"~"); // else PmWiki has url issues
1899+//alert(st)
1900+ if (!avoidinnerHTML) n.innerHTML = st;
1901+ processNodeR(n,false,true);
1902+ }
1903+/* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
1904+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
1905+}
1906+
1907+/* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
1908+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
1909+
1910+// you can change these
1911+var checkIfSVGavailable = true;
1912+var notifyIfNoSVG = true;
1913+var alertIfNoSVG = false;
1914+var noSVG = false;
1915+
1916+// global defaults used if not specified by graph (you can change these)
1917+var defaultwidth = 300; defaultheight = 200; // in pixels
1918+var defaultxmin = -5.5; defaultxmax = 5.5; // in usercoords
1919+var defaultborder = 0; border = defaultborder; // in pixel
1920+var defaultstrokewidth = "1"; // default line width in pixel
1921+var defaultstroke = "blue"; // default line color
1922+var defaultstrokeopacity = 1; // transparent = 0, solid =1
1923+var defaultstrokedasharray = null; // "10,10" gives 10px long dashes
1924+var defaultfill = "none"; // default fill color
1925+var defaultfillopacity = 1; // transparent = 0, solid =1
1926+var defaultfontstyle = "normal"; // default text shape normal|italic|inherit
1927+var defaultfontfamily = "times"; // default font times|ariel|helvetica|...
1928+var defaultfontsize = "16"; // default size (scaled automatically)
1929+var defaultfontweight = "normal";// normal|bold|bolder|lighter|100|...|900
1930+var defaultfontstroke = "none"; // default font outline color
1931+var defaultfontfill = "none"; // default font color
1932+var defaultmarker = "none"; // "dot" | "arrow" | "+" | "-" | "|"
1933+var defaultendpoints = ""; // "c-d" where c is <|o|* and d is >|o|*
1934+
1935+// global values used for all pictures (you can change these)
1936+var showcoordinates = true;
1937+var markerstrokewidth = "1";
1938+var markerstroke = "black";
1939+var markerfill = "yellow";
1940+var markersize = 4;
1941+var arrowfill = stroke;
1942+var dotradius = 4;
1943+var ticklength = 4;
1944+var axesstroke = "black";
1945+var gridstroke = "grey";
1946+var backgroundstyle = "fill-opacity:0; fill:white";
1947+var singlelettersitalic = true;
1948+
1949+// internal variables (probably no need to change these)
1950+var picturepos = null; // position of picture relative to top of HTML page
1951+var xunitlength; // in pixels, used to convert to user coordinates
1952+var yunitlength; // in pixels
1953+var origin = [0,0]; // in pixels (default is bottom left corner)
1954+var above = "above"; // shorthands (to avoid typing quotes)
1955+var below = "below";
1956+var left = "left";
1957+var right = "right";
1958+var aboveleft = "aboveleft";
1959+var aboveright = "aboveright";
1960+var belowleft = "belowleft";
1961+var belowright = "belowright";
1962+var xmin, xmax, ymin, ymax, xscl, yscl,
1963+ xgrid, ygrid, xtick, ytick, initialized;
1964+var strokewidth, strokedasharray, stroke, fill, strokeopacity, fillopacity;
1965+var fontstyle, fontfamily, fontsize, fontweight, fontstroke, fontfill;
1966+var marker, endpoints, dynamic = {};
1967+var picture, svgpicture, doc, width, height;
1968+var isIE = document.createElementNS==null;
1969+
1970+//this is not used! var cpi = "\u03C0", ctheta = "\u03B8"; // character for pi, theta
1971+var log = function(x) { return ln(x)/ln(10) };
1972+var pi = Math.PI, e = Math.E, ln = Math.log, sqrt = Math.sqrt;
1973+var floor = Math.floor, ceil = Math.ceil, abs = Math.abs;
1974+var sin = Math.sin, cos = Math.cos, tan = Math.tan;
1975+var arcsin = Math.asin, arccos = Math.acos, arctan = Math.atan;
1976+var sec = function(x) { return 1/Math.cos(x) };
1977+var csc = function(x) { return 1/Math.sin(x) };
1978+var cot = function(x) { return 1/Math.tan(x) };
1979+var arcsec = function(x) { return arccos(1/x) };
1980+var arccsc = function(x) { return arcsin(1/x) };
1981+var arccot = function(x) { return arctan(1/x) };
1982+var sinh = function(x) { return (Math.exp(x)-Math.exp(-x))/2 };
1983+var cosh = function(x) { return (Math.exp(x)+Math.exp(-x))/2 };
1984+var tanh =
1985+ function(x) { return (Math.exp(x)-Math.exp(-x))/(Math.exp(x)+Math.exp(-x)) };
1986+var sech = function(x) { return 1/cosh(x) };
1987+var csch = function(x) { return 1/sinh(x) };
1988+var coth = function(x) { return 1/tanh(x) };
1989+var arcsinh = function(x) { return ln(x+Math.sqrt(x*x+1)) };
1990+var arccosh = function(x) { return ln(x+Math.sqrt(x*x-1)) };
1991+var arctanh = function(x) { return ln((1+x)/(1-x))/2 };
1992+var sech = function(x) { return 1/cosh(x) };
1993+var csch = function(x) { return 1/sinh(x) };
1994+var coth = function(x) { return 1/tanh(x) };
1995+var arcsech = function(x) { return arccosh(1/x) };
1996+var arccsch = function(x) { return arcsinh(1/x) };
1997+var arccoth = function(x) { return arctanh(1/x) };
1998+var sign = function(x) { return (x==0?0:(x<0?-1:1)) };
1999+
2000+function factorial(x,n) { // Factorial function
2001+ if (n==null) n=1;
2002+ if (Math.abs(x-Math.round(x*1000000)/1000000)<1e-15)
2003+ x = Math.round(x*1000000)/1000000;
2004+ if (x-Math.floor(x)!=0) return NaN;
2005+ for (var i=x-n; i>0; i-=n) x*=i;
2006+ return (x<0?NaN:(x==0?1:x));
2007+}
2008+
2009+function C(x,k) { // Binomial coefficient function
2010+ var res=1;
2011+ for (var i=0; i<k; i++) res*=(x-i)/(k-i);
2012+ return res;
2013+}
2014+
2015+function chop(x,n) { // Truncate decimal number to n places after decimal point
2016+ if (n==null) n=0;
2017+ return Math.floor(x*Math.pow(10,n))/Math.pow(10,n);
2018+}
2019+
2020+function ran(a,b,n) { // Generate random number in [a,b] with n digits after .
2021+ if (n==null) n=0;
2022+ return chop((b+Math.pow(10,-n)-a)*Math.random()+a,n);
2023+}
2024+
2025+function myCreateElementSVG(t) {
2026+ if (isIE) return doc.createElement(t);
2027+ else return doc.createElementNS("http://www.w3.org/2000/svg",t);
2028+}
2029+
2030+function getElementsByClass(container, tagName, clsName){
2031+ var list = new Array(0);
2032+ var collection = container.getElementsByTagName(tagName);
2033+ for(var i = 0; i < collection.length; i++)
2034+ if(collection[i].className.slice(0,clsName.length)==clsName)
2035+ list[list.length] = collection[i];
2036+ return list;
2037+}
2038+
2039+function showobj(obj) {
2040+ var st="", i;
2041+ for (i in obj)
2042+ st += (obj.getAttribute(i)==null?"":" "+i+":"+obj.getAttribute(i));
2043+ return st;
2044+}
2045+
2046+function findPos(obj) { // top-left corner of obj on HTML page in pixel
2047+ var curleft = curtop = 0;
2048+ if (obj.offsetParent) {
2049+ curleft = obj.offsetLeft
2050+ curtop = obj.offsetTop
2051+ while (obj = obj.offsetParent) {
2052+ curleft += obj.offsetLeft
2053+ curtop += obj.offsetTop
2054+//alert(showobj(obj)+[curleft,curtop])
2055+ }
2056+ }
2057+ return [curleft,curtop];
2058+}
2059+
2060+function checkSVG(){
2061+ if (navigator.appName.slice(0,8)=="Netscape")
2062+ if (window['SVGElement']) noSVG = null;
2063+ else noSVG = true;
2064+ else if (navigator.appName.slice(0,9)=="Microsoft")
2065+ try {
2066+ var oSVG=eval("new ActiveXObject('Adobe.SVGCtl.3');");
2067+ noSVG = null;
2068+ } catch (e) {
2069+ noSVG = true;
2070+ }
2071+ else if (navigator.appName.slice(0,5)=="Opera") // works only for 9.50b1
2072+ noSVG = null;
2073+ else noSVG = true;
2074+//noSVG = true; //uncomment to check
2075+ if (noSVG && notifyIfNoSVG) {
2076+ var msg = "To view the ASCIIsvg images use Internet Explorer + Adobe SVGviewer or Mozilla Firefox 2.0 or later."
2077+ if (alertIfNoSVG)
2078+ alert(msg);
2079+ else return msg;
2080+ }
2081+}
2082+
2083+function setText(st,id) { // add text to an existing node with given id
2084+ var node = document.getElementById(id);
2085+ if (node!=null)
2086+ if (node.childNodes.length!=0) node.childNodes[0].nodeValue = st;
2087+ else node.appendChild(document.createTextNode(st));
2088+}
2089+
2090+function getX(evt) { // return mouse x-coord in user coordinate system
2091+ var svgroot = evt.target.parentNode;
2092+ pos = findPos(svgroot.parentNode);
2093+ return (evt.clientX+(isIE?0:window.pageXOffset)-pos[0]-svgroot.getAttribute("ox"))/parseFloat(svgroot.getAttribute("xunitlength"));
2094+}
2095+
2096+function getY(evt) { // return mouse y-coord in user coordinate system
2097+ var svgroot = evt.target.parentNode;
2098+ pos = findPos(svgroot.parentNode);
2099+//alert(showobj(svgroot)+svgroot.getAttribute("mytop"))
2100+ return (svgroot.getAttribute("height")-svgroot.getAttribute("oy")-(evt.clientY+(isIE?0:window.pageYOffset)-pos[1]))/parseFloat(svgroot.getAttribute("yunitlength"));
2101+}
2102+
2103+function translateandeval(src) { //modify user input to JavaScript syntax
2104+ var errstr;
2105+ // replace plot(f(x),...) with plot("f(x)",...)
2106+ src = src.replace(/plot\(\x20*([^\"f\[][^\n\r;]+?)\,/g,"plot\(\"$1\",");
2107+ src = src.replace(/plot\(\x20*([^\"f\[][^\n\r;]+)\)/g,"plot(\"$1\")");
2108+
2109+ // replace (expr,expr) by [expr,expr] where expr has no (,) in it
2110+ src = src.replace(/([=[(,]\x20*)\(([-a-z0-9./+*]+?),([-a-z0-9./+*]+?)\)/g,"$1[$2,$3]");
2111+//alert(src)
2112+ // insert * between digit and letter e.g. 2x --> 2*x
2113+ src = src.replace(/([0-9])([a-df-zA-Z]|e^)/g,"$1*$2");
2114+ src = src.replace(/\)([\(0-9a-zA-Z])/g,"\)*$1");
2115+
2116+ try {
2117+ with (Math) eval(src); // here the svgpicture object is created
2118+ } catch(err) {
2119+ if (err!="wait") {
2120+//alert(dsvglocation)
2121+ if (typeof err=="object")
2122+ errstr = err.name+" "+err.message+" "+err.number+" "+err.description;
2123+ else errstr = err;
2124+ alert(errstr+"\n"+src)
2125+ }
2126+ }
2127+}
2128+
2129+var lastSlot = 0;
2130+
2131+function drawPictures() { // main routine; called after webpage has loaded
2132+ var src, id, dsvg, nd, node, ht, index, cols, arr, i, node2;
2133+ var ASbody = document.getElementsByTagName("body")[0];
2134+ pictures = getElementsByClass(ASbody,"embed","ASCIIsvg");
2135+ var len = pictures.length;
2136+ if(len==0) return;
2137+ for (index = lastSlot; index < len+lastSlot; index++) {
2138+ width = null; height = null;
2139+ xmin = null; xmax = null; ymin = null; ymax = null;
2140+ xscl = null; xgrid = null; yscl = null; ygrid = null;
2141+ initialized = false;
2142+ picture = pictures[index-lastSlot]; // current picture object
2143+ src = picture.getAttribute("script"); // get the ASCIIsvg code
2144+ if (src==null) src = "";
2145+ // insert "axes()" if not present ******** experimental
2146+ if (!/axes\b|initPicture/.test(src)) {
2147+ var i = 0;
2148+ while (/((yscl|ymax|ymin|xscl|xmax|xmin|\bwidth|\bheight)\s*=\s*-?\d*(\d\.|\.\d|\d)\d*\s*;?)/.test(src.slice(i))) i++;
2149+ src = (i==0?"axes(); "+src: src.slice(0,i)+src.slice(i).replace(/((scl|max|min|idth|eight)\s*=\s*-?\d*(\d\.|\.\d|\d)\d*\s*;?)/,"$1\naxes();"));
2150+ }
2151+ ht = picture.getAttribute("height");
2152+ if (isIE) {
2153+ picture.setAttribute("wmode","transparent");
2154+//alert("*"+picture.getAttribute("src")+dsvglocation);
2155+//adding d.svg dynamically greates problems in IE...
2156+// if (picture.getAttribute("src")=="") picture.setAttribute("src",dsvglocation+"d.svg");
2157+ }
2158+ if (document.getElementById("picture"+(index+1)+"mml")==null) {
2159+ picture.parentNode.style.position = "relative";
2160+ node = createElementXHTML("div");
2161+ node.style.position = "absolute";
2162+ node.style.top = "0px";
2163+ node.style.left = "0px";
2164+ node.setAttribute("id","picture"+(index+1)+"mml");
2165+ picture.parentNode.insertBefore(node,picture.nextSibling);
2166+ }
2167+ if (ht==null) ht ="";
2168+// if (ht!="") defaultborder = 25;
2169+ if (ht=="" || src=="")
2170+ if (document.getElementById("picture"+(index+1)+"input")==null) {
2171+ node = createElementXHTML("textarea");
2172+ arr = src.split("\n");
2173+ cols = 0;
2174+ for (i=0;i<arr.length;i++) cols = Math.max(cols,arr[i].length);
2175+ node.setAttribute("rows",Math.min(10,arr.length)+1);
2176+ node.setAttribute("cols",Math.max(Math.min(60,cols),20)+5);
2177+// node.setAttribute("style","display:block");
2178+ if (isIE) src = src.replace(/([^\r])\n/g,"$1\r");
2179+ node.appendChild(document.createTextNode(src));
2180+ if (src.indexOf("showcode()")==-1) node.style.display = "none";
2181+ node.setAttribute("id","picture"+(index+1)+"input");
2182+ picture.parentNode.insertBefore(node,picture.nextSibling);
2183+ picture.parentNode.insertBefore(createElementXHTML("br"),node);
2184+ node2 = createElementXHTML("button");
2185+ node2.setAttribute("id","picture"+(index+1)+"button");
2186+ if (isIE) node2.onclick = function() {updatePicture(this)};
2187+ else node2.setAttribute("onclick","updatePicture(this)");
2188+ node2.appendChild(document.createTextNode("Update"));
2189+ if (src.indexOf("showcode()")==-1) node2.style.display = "none";
2190+ picture.parentNode.insertBefore(node2,node);
2191+// picture.parentNode.insertBefore(document.createTextNode("ASCII"),node);
2192+ picture.parentNode.insertBefore(createElementXHTML("br"),node);
2193+ } else src = document.getElementById("picture"+(index+1)+"input").value;
2194+ id = picture.getAttribute("id");
2195+ dsvg = picture.getAttribute("src");
2196+ if (id == null || id == "") {
2197+ id = "picture"+(index+1);
2198+ picture.setAttribute("id",id);
2199+ }
2200+ translateandeval(src);
2201+ }
2202+ lastSlot+=len;
2203+}
2204+
2205+function setdefaults() { //called before each graph is evaluated
2206+ strokewidth = defaultstrokewidth;
2207+ stroke = defaultstroke;
2208+ strokeopacity = defaultstrokeopacity;
2209+ strokedasharray = defaultstrokedasharray;
2210+ fill = defaultfill;
2211+ fillopacity = defaultfillopacity;
2212+ fontstyle = defaultfontstyle;
2213+ fontfamily = defaultfontfamily;
2214+ fontsize = defaultfontsize;
2215+ fontweight = defaultfontweight;
2216+ fontstroke = defaultfontstroke;
2217+ fontfill = defaultfontfill;
2218+ marker = defaultmarker;
2219+ endpoints = defaultendpoints;
2220+}
2221+
2222+function switchTo(id) { // used by dynamic code to select appropriate graph
2223+ if (id==undefined) return;
2224+ var name = id;
2225+ if (typeof name!="string") name = id.target.parentNode.getAttribute("name");
2226+ picture = document.getElementById(name);
2227+ width = picture.getAttribute("width")-0;
2228+ height = picture.getAttribute("height")-0;
2229+ setdefaults();
2230+ if ((picture.nodeName == "EMBED" || picture.nodeName == "embed") && isIE) {
2231+ svgpicture = picture.getSVGDocument().getElementById("root");
2232+ doc = picture.getSVGDocument();
2233+ } else {
2234+ svgpicture = picture;
2235+ doc = document;
2236+ }
2237+ xunitlength = parseFloat(svgpicture.getAttribute("xunitlength"));
2238+ yunitlength = parseFloat(svgpicture.getAttribute("yunitlength"));
2239+ xmin = parseFloat(svgpicture.getAttribute("xmin"));
2240+ xmax = parseFloat(svgpicture.getAttribute("xmax"));
2241+ ymin = parseFloat(svgpicture.getAttribute("ymin"));
2242+ ymax = parseFloat(svgpicture.getAttribute("ymax"));
2243+ origin = [svgpicture.getAttribute("ox")-0,svgpicture.getAttribute("oy")-0];
2244+}
2245+
2246+function updatePicture(obj) {
2247+ var node, src, id, top, left;
2248+ if (typeof obj=="object") id = obj.id.slice(0,-6);
2249+ else id = (typeof obj=="string"?obj:"picture"+(obj+1));
2250+ src = document.getElementById(id+"input").value;
2251+ xmin = null; xmax = null; ymin = null; ymax = null;
2252+ xscl = null; xgrid = null; yscl = null; ygrid = null;
2253+ initialized = false;
2254+ picture = document.getElementById(id);
2255+ translateandeval(src)
2256+}
2257+
2258+function changepicturesize(evt,factor) {
2259+ var obj = evt.target;
2260+ var name = obj.parentNode.getAttribute("name");
2261+ var pic = document.getElementById(name);
2262+ var src = document.getElementById(name+"input").value;
2263+ if (!/height/.test(src)) src = "height=0; "+src;
2264+ if (!/width/.test(src)) src = "width=0; "+src;
2265+ src = src.replace(/width\s*=\s*\d+/,"width="+(factor*(pic.getAttribute("width")-0)));
2266+ src = src.replace(/height\s*=\s*\d+/,"height="+(factor*(pic.getAttribute("height")-0)));
2267+ document.getElementById(name+"input").value = src;
2268+//alert(getKey(evt.keycode))
2269+ updatePicture(name);
2270+}
2271+
2272+function zoom(evt,factor) {
2273+ switchTo(evt);
2274+ var obj = evt.target;
2275+ var name = obj.parentNode.getAttribute("name");
2276+ var pic = document.getElementById(name);
2277+ var src = document.getElementById(name+"input").value;
2278+ var xlen = (xmax-xmin)/2;
2279+ var ylen = (ymax-ymin)/2;
2280+ var xcen = getX(evt), ycen = getY(evt);
2281+ if (!/ymax/.test(src)) src = "ymax=0; "+src;
2282+ if (!/ymin/.test(src)) src = "ymin=0; "+src;
2283+ if (!/xmax/.test(src)) src = "xmax=0; "+src;
2284+ if (!/xmin/.test(src)) src = "xmin=0; "+src;
2285+ src = src.replace(/xmin\s*=\s*[-\d.e]+/,"xmin="+(xcen-factor*xlen));
2286+ src = src.replace(/xmax\s*=\s*[-\d.e]+/,"xmax="+(xcen+factor*xlen));
2287+ src = src.replace(/ymin\s*=\s*[-\d.e]+/,"ymin="+(ycen-factor*ylen));
2288+ src = src.replace(/ymax\s*=\s*[-\d.e]+/,"ymax="+(ycen+factor*ylen));
2289+ document.getElementById(name+"input").value = src;
2290+ updatePicture(name);
2291+}
2292+
2293+var sinceFirstClick = 0; // ondblclick simulation from
2294+var dblClkTimer; // http://www.enja.org/david/?cat=13 Thanks!
2295+function timer() {
2296+ if(sinceFirstClick<60) {
2297+ sinceFirstClick++;
2298+ setTimeout("timer()",10);
2299+ } else {
2300+ clearTimeout(dblClkTimer);
2301+ dblClkTimer = "";
2302+ }
2303+}
2304+function mClick(evt) {
2305+ if(sinceFirstClick!=0) {
2306+ if(sinceFirstClick <= 40) {
2307+ if (evt.shiftKey) {
2308+ if (evt.altKey) changepicturesize(evt,2);
2309+ else zoom(evt,.5);
2310+ } else if (evt.altKey) zoom(evt,2);//changepicturesize(evt,.5);
2311+ else showHideCode(evt); // do this on dblclick
2312+ clearTimeout(dblClkTimer);
2313+ dblClkTimer = "";
2314+ } else {
2315+ clearTimeout(dblClkTimer);
2316+ sinceFirstClick = 0;
2317+ dblClkTimer = setTimeout("timer()",10);
2318+ }
2319+ } else {
2320+ sinceFirstClick = 0;
2321+ dblClkTimer = setTimeout("timer()",10);
2322+ }
2323+}
2324+
2325+function showHideCode(evt) { // called by onclick event
2326+// if (evt.getDetail()==2) {//getDetail unfortunately not in Firefox
2327+ var obj=evt.target;
2328+ var name = obj.parentNode.getAttribute("name");
2329+ var node = document.getElementById(name+"input");
2330+ node.style.display = (node.style.display == "none"?"":"none");
2331+ var node = document.getElementById(name+"button");
2332+ node.style.display = (node.style.display == "none"?"":"none");
2333+// }
2334+}
2335+
2336+function showcode() {} // do nothing
2337+
2338+function setBorder(x) { border = x } //deprecate
2339+
2340+function initPicture(x_min,x_max,y_min,y_max) { // set up the graph
2341+// usually called by axes() or noaxes(), but can be used directly
2342+ if (!initialized) {
2343+ setdefaults();
2344+ initialized = true;
2345+ if (x_min!=null) xmin = x_min;
2346+ if (x_max!=null) xmax = x_max;
2347+ if (y_min!=null) ymin = y_min;
2348+ if (y_max!=null) ymax = y_max;
2349+ if (xmin==null) xmin = defaultxmin;
2350+ if (xmax==null) xmax = defaultxmax;
2351+ if (typeof xmin != "number" || typeof xmax != "number" || xmin >= xmax)
2352+ alert("Picture requires at least two numbers: xmin < xmax");
2353+ else if (y_max != null && (typeof y_min != "number" ||
2354+ typeof y_max != "number" || y_min >= y_max))
2355+ alert("initPicture(xmin,xmax,ymin,ymax) requires numbers ymin < ymax");
2356+ else {
2357+ if (width==null) {
2358+ width = picture.getAttribute("width");
2359+ if (width==null || width=="") width=defaultwidth;
2360+ }
2361+ picture.setAttribute("width",width);
2362+ if (height==null) {
2363+ height = picture.getAttribute("height");
2364+ if (height==null || height=="") height=defaultheight;
2365+ }
2366+ picture.setAttribute("height",height);
2367+ xunitlength = (width-2*border)/(xmax-xmin);
2368+ yunitlength = xunitlength;
2369+//alert(xmin+" "+xmax+" "+ymin+" "+ymax)
2370+ if (ymin==null) {
2371+ origin = [-xmin*xunitlength+border,height/2];
2372+ ymin = -(height-2*border)/(2*yunitlength);
2373+ ymax = -ymin;
2374+ } else {
2375+ if (ymax!=null) yunitlength = (height-2*border)/(ymax-ymin);
2376+ else ymax = (height-2*border)/yunitlength + ymin;
2377+ origin = [-xmin*xunitlength+border,-ymin*yunitlength+border];
2378+ }
2379+ if (isIE) {
2380+ if (picture.FULLSCREEN==undefined) {
2381+ setTimeout('drawPictures()',50);
2382+ throw "wait";
2383+ }
2384+ svgpicture = picture.getSVGDocument().getElementById("root");
2385+ if (svgpicture==null) {
2386+ setTimeout('drawPictures()',50);
2387+ throw "wait";
2388+ }
2389+ svgpicture = picture.getSVGDocument().getElementById("root");
2390+ while (svgpicture.childNodes.length>0)
2391+ svgpicture.removeChild(svgpicture.lastChild);
2392+ svgpicture.setAttribute("width",width);
2393+ svgpicture.setAttribute("height",height);
2394+ svgpicture.setAttribute("name",picture.getAttribute("id"));
2395+ doc = picture.getSVGDocument();
2396+ } else {
2397+ var qnode = document.createElementNS("http://www.w3.org/2000/svg","svg");
2398+ qnode.setAttribute("id",picture.getAttribute("id"));
2399+ qnode.setAttribute("name",picture.getAttribute("id"));
2400+// qnode.setAttribute("style","display:inline");
2401+ qnode.setAttribute("width",picture.getAttribute("width"));
2402+ qnode.setAttribute("height",picture.getAttribute("height"));
2403+ picturepos = findPos(picture);
2404+// qnode.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");
2405+ if (picture.parentNode!=null) {
2406+ picture.parentNode.replaceChild(qnode,picture);
2407+ } else {
2408+ svgpicture.parentNode.replaceChild(qnode,svgpicture);
2409+ }
2410+ svgpicture = qnode;
2411+ doc = document;
2412+ }
2413+ var nd = document.getElementById(picture.getAttribute("id")+"mml");
2414+ if (nd!=null) // clear out MathML layer
2415+ while (nd.childNodes.length>0) nd.removeChild(nd.lastChild);
2416+ svgpicture.setAttribute("xunitlength",xunitlength);
2417+ svgpicture.setAttribute("yunitlength",yunitlength);
2418+ svgpicture.setAttribute("xmin",xmin);
2419+ svgpicture.setAttribute("xmax",xmax);
2420+ svgpicture.setAttribute("ymin",ymin);
2421+ svgpicture.setAttribute("ymax",ymax);
2422+ svgpicture.setAttribute("ox",origin[0]);
2423+ svgpicture.setAttribute("oy",origin[1]);
2424+ var node = myCreateElementSVG("rect");
2425+ node.setAttribute("x","0");
2426+ node.setAttribute("y","0");
2427+ node.setAttribute("width",width);
2428+ node.setAttribute("height",height);
2429+ node.setAttribute("style",backgroundstyle);
2430+ svgpicture.appendChild(node);
2431+ svgpicture.setAttribute("onmousemove","displayCoord(evt)");
2432+ svgpicture.setAttribute("onmouseout","removeCoord(evt)");
2433+ svgpicture.setAttribute("onclick","mClick(evt)");
2434+ node = myCreateElementSVG("text"); // used for displayCoord
2435+ node.appendChild(doc.createTextNode(" "));
2436+ node.setAttribute("id","coords");
2437+ svgpicture.appendChild(node);
2438+ node = myCreateElementSVG("text"); // used for text display
2439+ node.appendChild(doc.createTextNode(" "));
2440+ node.setAttribute("id","coords");
2441+ svgpicture.appendChild(node);
2442+ border = defaultborder;
2443+ }
2444+ }
2445+}
2446+
2447+//////////////////////////user graphics commands start/////////////////////////
2448+
2449+function line(p,q,id,endpts) { // segment connecting points p,q (coordinates in units)
2450+ var node;
2451+ if (id!=null) node = doc.getElementById(id);
2452+ if (node==null) {
2453+ node = myCreateElementSVG("path");
2454+ node.setAttribute("id", id);
2455+ svgpicture.appendChild(node);
2456+ }
2457+ node.setAttribute("d","M"+(p[0]*xunitlength+origin[0])+","+
2458+ (height-p[1]*yunitlength-origin[1])+" "+
2459+ (q[0]*xunitlength+origin[0])+","+(height-q[1]*yunitlength-origin[1]));
2460+ node.setAttribute("stroke-width", strokewidth);
2461+ if (strokedasharray!=null)
2462+ node.setAttribute("stroke-dasharray", strokedasharray);
2463+ node.setAttribute("stroke", stroke);
2464+ node.setAttribute("fill", fill);
2465+ node.setAttribute("stroke-opacity", strokeopacity);
2466+ node.setAttribute("fill-opacity", fillopacity);
2467+ if (marker=="dot" || marker=="arrowdot") {
2468+ ASdot(p,markersize,markerstroke,markerfill);
2469+ if (marker=="arrowdot") arrowhead(p,q);
2470+ ASdot(q,markersize,markerstroke,markerfill);
2471+ } else if (marker=="arrow") arrowhead(p,q);
2472+ if (endpts==null && endpoints!="") endpts = endpoints;
2473+ if (endpts!=null) {
2474+ if (endpts.indexOf("<-") != -1) arrowhead(q,p);
2475+ if (endpts.indexOf("o-") != -1) dot(p, "open");
2476+ if (endpts.indexOf("*-") != -1) dot(p, "closed");
2477+ if (endpts.indexOf("->") != -1) arrowhead(p,q);
2478+ if (endpts.indexOf("-o") != -1) dot(q, "open");
2479+ if (endpts.indexOf("-*") != -1) dot(q, "closed");
2480+ }
2481+}
2482+
2483+function path(plist,id,c,endpts) {
2484+ if (c==null) c="";
2485+ var node, st, i;
2486+ if (id!=null) node = doc.getElementById(id);
2487+ if (node==null) {
2488+ node = myCreateElementSVG("path");
2489+ node.setAttribute("id", id);
2490+ svgpicture.appendChild(node);
2491+ }
2492+ if (typeof plist == "string") st = plist;
2493+ else {
2494+ st = "M";
2495+ st += (plist[0][0]*xunitlength+origin[0])+","+
2496+ (height-plist[0][1]*yunitlength-origin[1])+" "+c;
2497+ for (i=1; i<plist.length; i++)
2498+ st += (plist[i][0]*xunitlength+origin[0])+","+
2499+ (height-plist[i][1]*yunitlength-origin[1])+" ";
2500+ }
2501+ node.setAttribute("d", st);
2502+ node.setAttribute("stroke-width", strokewidth);
2503+ if (strokedasharray!=null)
2504+ node.setAttribute("stroke-dasharray", strokedasharray);
2505+ node.setAttribute("stroke", stroke);
2506+ node.setAttribute("fill", fill);
2507+ node.setAttribute("stroke-opacity", strokeopacity);
2508+ node.setAttribute("fill-opacity", fillopacity);
2509+ if (marker=="dot" || marker=="arrowdot")
2510+ for (i=0; i<plist.length; i++)
2511+ if (c!="C" && c!="T" || i!=1 && i!=2)
2512+ ASdot(plist[i],markersize,markerstroke,markerfill);
2513+ if (endpts==null && endpoints!="") endpts = endpoints;
2514+ if (endpts!=null) {
2515+ if (endpts.indexOf("<-") != -1) arrowhead(plist[1],plist[0]);
2516+ if (endpts.indexOf("o-") != -1) dot(plist[0], "open");
2517+ if (endpts.indexOf("*-") != -1) dot(plist[0], "closed");
2518+ if (endpts.indexOf("->") != -1) arrowhead(plist[plist.length-2],plist[plist.length-1]);
2519+ if (endpts.indexOf("-o") != -1) dot(plist[plist.length-1], "open");
2520+ if (endpts.indexOf("-*") != -1) dot(plist[plist.length-1], "closed");
2521+ }
2522+}
2523+
2524+function curve(plist,id,endpts) {
2525+ path(plist,id,"T",endpts);
2526+}
2527+
2528+function vector(p,q,id) {
2529+ line(p,q,id,"","->");
2530+}
2531+
2532+function circle(center,radius,id) { // coordinates in units
2533+ var node;
2534+ if (id!=null) node = doc.getElementById(id);
2535+ if (node==null) {
2536+ node = myCreateElementSVG("circle");
2537+ node.setAttribute("id", id);
2538+ svgpicture.appendChild(node);
2539+ }
2540+ node.setAttribute("cx",center[0]*xunitlength+origin[0]);
2541+ node.setAttribute("cy",height-center[1]*yunitlength-origin[1]);
2542+ node.setAttribute("r",radius*xunitlength);
2543+ node.setAttribute("stroke-width", strokewidth);
2544+ node.setAttribute("stroke", stroke);
2545+ node.setAttribute("fill", fill);
2546+ node.setAttribute("stroke-opacity", strokeopacity);
2547+ node.setAttribute("fill-opacity", fillopacity);
2548+}
2549+
2550+function loop(p,d,id) {
2551+// d is a direction vector e.g. [1,0] means loop starts in that direction
2552+ if (d==null) d=[1,0];
2553+ path([p,[p[0]+d[0],p[1]+d[1]],[p[0]-d[1],p[1]+d[0]],p],id,"C");
2554+ if (marker=="arrow" || marker=="arrowdot")
2555+ arrowhead([p[0]+Math.cos(1.4)*d[0]-Math.sin(1.4)*d[1],
2556+ p[1]+Math.sin(1.4)*d[0]+Math.cos(1.4)*d[1]],p);
2557+}
2558+
2559+function arc(start,end,radius,id,largearc) { // coordinates in units
2560+ var node, v;
2561+//alert([fill, stroke, origin, xunitlength, yunitlength, height])
2562+ if (id!=null) node = doc.getElementById(id);
2563+ if (largearc==null) largearc=0;
2564+ if (radius==null) {
2565+ v=[end[0]-start[0],end[1]-start[1]];
2566+ radius = Math.sqrt(v[0]*v[0]+v[1]*v[1]);
2567+ }
2568+ if (node==null) {
2569+ node = myCreateElementSVG("path");
2570+ node.setAttribute("id", id);
2571+ svgpicture.appendChild(node);
2572+ }
2573+ node.setAttribute("d","M"+(start[0]*xunitlength+origin[0])+","+
2574+ (height-start[1]*yunitlength-origin[1])+" A"+radius*xunitlength+","+
2575+ radius*yunitlength+" 0 "+largearc+",0 "+(end[0]*xunitlength+origin[0])+","+
2576+ (height-end[1]*yunitlength-origin[1]));
2577+ node.setAttribute("stroke-width", strokewidth);
2578+ node.setAttribute("stroke", stroke);
2579+ node.setAttribute("fill", fill);
2580+ node.setAttribute("stroke-opacity", strokeopacity);
2581+ node.setAttribute("fill-opacity", fillopacity);
2582+ if (marker=="arrow" || marker=="arrowdot") {
2583+ u = [(end[1]-start[1])/4,(start[0]-end[0])/4];
2584+ v = [(end[0]-start[0])/2,(end[1]-start[1])/2];
2585+//alert([u,v])
2586+ v = [start[0]+v[0]+u[0],start[1]+v[1]+u[1]];
2587+ } else v=[start[0],start[1]];
2588+ if (marker=="dot" || marker=="arrowdot") {
2589+ ASdot(start,markersize,markerstroke,markerfill);
2590+ if (marker=="arrowdot") arrowhead(v,end);
2591+ ASdot(end,markersize,markerstroke,markerfill);
2592+ } else if (marker=="arrow") arrowhead(v,end);
2593+}
2594+
2595+function sector(center,start,end,id) { // center,start,end should be isoceles
2596+ var rx = start[0]-center[0], ry = start[1]-center[1];
2597+ arc(start,end,Math.sqrt(rx*rx+ry*ry),id+"arc");
2598+ path([end,center,start],id+"path");
2599+}
2600+
2601+function ellipse(center,rx,ry,id) { // coordinates in units
2602+ var node;
2603+ if (id!=null) node = doc.getElementById(id);
2604+ if (node==null) {
2605+ node = myCreateElementSVG("ellipse");
2606+ node.setAttribute("id", id);
2607+ svgpicture.appendChild(node);
2608+ }
2609+ node.setAttribute("cx",center[0]*xunitlength+origin[0]);
2610+ node.setAttribute("cy",height-center[1]*yunitlength-origin[1]);
2611+ node.setAttribute("rx",rx*xunitlength);
2612+ node.setAttribute("ry",ry*yunitlength);
2613+ node.setAttribute("stroke-width", strokewidth);
2614+ node.setAttribute("stroke", stroke);
2615+ node.setAttribute("fill", fill);
2616+ node.setAttribute("stroke-opacity", strokeopacity);
2617+ node.setAttribute("fill-opacity", fillopacity);
2618+}
2619+
2620+function triangle(p,q,r,id) {
2621+ path([p,q,r,p],id)
2622+}
2623+
2624+function rect(p,q,id,rx,ry) { // opposite corners in units, rounded by radii
2625+ var node;
2626+ if (id!=null) node = doc.getElementById(id);
2627+ if (node==null) {
2628+ node = myCreateElementSVG("rect");
2629+ node.setAttribute("id", id);
2630+ svgpicture.appendChild(node);
2631+ }
2632+ node.setAttribute("x",p[0]*xunitlength+origin[0]);
2633+ node.setAttribute("y",height-q[1]*yunitlength-origin[1]);
2634+ node.setAttribute("width",(q[0]-p[0])*xunitlength);
2635+ node.setAttribute("height",(q[1]-p[1])*yunitlength);
2636+ if (rx!=null) node.setAttribute("rx",rx*xunitlength);
2637+ if (ry!=null) node.setAttribute("ry",ry*yunitlength);
2638+ node.setAttribute("stroke-width", strokewidth);
2639+ node.setAttribute("stroke", stroke);
2640+ node.setAttribute("fill", fill);
2641+ node.setAttribute("stroke-opacity", strokeopacity);
2642+ node.setAttribute("fill-opacity", fillopacity);
2643+}
2644+
2645+function text(p,st,pos,id,fontsty) {
2646+ var dnode, node, dx = 0, dy = fontsize/3, str = st.toString();
2647+ if (/(`|\$)/.test(str)) { // layer for ASCIIMathML and LaTeXMathML
2648+ dnode = document.getElementById(svgpicture.getAttribute("name")+"mml");
2649+ if (dnode!=null) {
2650+ if (id!=null) node = document.getElementById(id);
2651+ if (node==null) {
2652+//alert(dnode.childNodes.length)
2653+ node = createElementXHTML("div");
2654+ node.setAttribute("id", id);
2655+ node.style.position = "absolute";
2656+ dnode.appendChild(node);
2657+ }
2658+ while (node.childNodes.length>0) node.removeChild(node.lastChild);
2659+ node.appendChild(document.createTextNode(str));
2660+ if (/`/.test(str)) AMprocessNode(node); else LMprocessNode(node);
2661+ dx = -node.offsetWidth/2;
2662+ dy = -node.offsetHeight/2;
2663+ if (pos!=null) {
2664+ if (/above/.test(pos)) dy = -node.offsetHeight;
2665+ if (/below/.test(pos)) dy = 0;
2666+ if (/right/.test(pos)) dx = 0;
2667+ if ( /left/.test(pos)) dx = -node.offsetWidth;
2668+ }
2669+ node.style.left = ""+(p[0]*xunitlength+origin[0]+dx)+"px";
2670+ node.style.top = ""+(height-p[1]*yunitlength-origin[1]+dy)+"px";
2671+ }
2672+ return p;
2673+ }
2674+ var textanchor = "middle"; // regular text goes into SVG
2675+ if (pos!=null) {
2676+ if (/above/.test(pos)) dy = -fontsize/2;
2677+ if (/below/.test(pos)) dy = fontsize-0;
2678+ if (/right/.test(pos)) {textanchor = "start"; dx = fontsize/4;}
2679+ if ( /left/.test(pos)) {textanchor = "end"; dx = -fontsize/4;}
2680+ }
2681+ if (id!=null) node = doc.getElementById(id);
2682+ if (node==null) {
2683+ node = myCreateElementSVG("text");
2684+ node.setAttribute("id", id);
2685+ svgpicture.appendChild(node);
2686+ node.appendChild(doc.createTextNode(str));
2687+ }
2688+ while (node.childNodes.length>1) node.removeChild(node.lastChild);
2689+ node.lastChild.nodeValue = "\xA0"+str+"\xA0";
2690+ node.setAttribute("x",p[0]*xunitlength+origin[0]+dx);
2691+ node.setAttribute("y",height-p[1]*yunitlength-origin[1]+dy);
2692+ node.setAttribute("font-style",(fontsty!=null?fontsty:
2693+ (str.search(/^[a-zA-Z]$/)!=-1?"italic":fontstyle)));
2694+ node.setAttribute("font-family",fontfamily);
2695+ node.setAttribute("font-size",fontsize);
2696+ node.setAttribute("font-weight",fontweight);
2697+ node.setAttribute("text-anchor",textanchor);
2698+ if (fontstroke!="none") node.setAttribute("stroke",fontstroke);
2699+ if (fontfill!="none") node.setAttribute("fill",fontfill);
2700+ return p;
2701+}
2702+
2703+function mtext(p,st,pos,fontsty,fontsz) { // method for updating text on an svg
2704+// "this" is the text object or the svgpicture object
2705+ var textanchor = "middle";
2706+ var dx = 0; var dy = fontsize/3;
2707+ if (pos!=null) {
2708+ if (pos.slice(0,5)=="above") dy = -fontsize/2;
2709+ if (pos.slice(0,5)=="below") dy = fontsize-0;
2710+ if (pos.slice(0,5)=="right" || pos.slice(5,10)=="right") {
2711+ textanchor = "start";
2712+ dx = fontsize/2;
2713+ }
2714+ if (pos.slice(0,4)=="left" || pos.slice(5,9)=="left") {
2715+ textanchor = "end";
2716+ dx = -fontsize/2;
2717+ }
2718+ }
2719+ var node = this;
2720+ if (this.nodeName=="svg") {
2721+ node = myCreateElementSVG("text");
2722+ this.appendChild(node);
2723+ node.appendChild(doc.createTextNode(st));
2724+ }
2725+ node.lastChild.nodeValue = st;
2726+ node.setAttribute("x",p[0]+dx);
2727+ node.setAttribute("y",p[1]+dy);
2728+ node.setAttribute("font-style",(fontsty!=null?fontsty:fontstyle));
2729+ node.setAttribute("font-family",fontfamily);
2730+ node.setAttribute("font-size",(fontsz!=null?fontsz:fontsize));
2731+ node.setAttribute("font-weight",fontweight);
2732+ node.setAttribute("text-anchor",textanchor);
2733+ if (fontstroke!="none") node.setAttribute("stroke",fontstroke);
2734+ if (fontfill!="none") node.setAttribute("fill",fontfill);
2735+}
2736+
2737+function image(imgurl,p,w,h,id) { // not working yet
2738+ var node;
2739+ if (id!=null) node = doc.getElementById(id);
2740+ if (node==null) {
2741+ node = myCreateElementSVG("image");
2742+ node.setAttribute("id", id);
2743+ svgpicture.appendChild(node);
2744+ }
2745+ node.setAttribute("x",p[0]*xunitlength+origin[0]);
2746+ node.setAttribute("y",height-p[1]*yunitlength-origin[1]);
2747+ node.setAttribute("width",w);
2748+ node.setAttribute("height",h);
2749+ node.setAttribute("xlink:href", imgurl);
2750+}
2751+
2752+function ASdot(center,radius,s,f) { // coordinates in units, radius in pixel
2753+ if (s==null) s = stroke; if (f==null) f = fill;
2754+ var node = myCreateElementSVG("circle");
2755+ node.setAttribute("cx",center[0]*xunitlength+origin[0]);
2756+ node.setAttribute("cy",height-center[1]*yunitlength-origin[1]);
2757+ node.setAttribute("r",radius);
2758+ node.setAttribute("stroke-width", strokewidth);
2759+ node.setAttribute("stroke", s);
2760+ node.setAttribute("fill", f);
2761+ svgpicture.appendChild(node);
2762+}
2763+
2764+function dot(center, typ, label, pos, id) {
2765+ var node;
2766+ var cx = center[0]*xunitlength+origin[0];
2767+ var cy = height-center[1]*yunitlength-origin[1];
2768+ if (id!=null) node = doc.getElementById(id);
2769+ if (typ=="+" || typ=="-" || typ=="|") {
2770+ if (node==null) {
2771+ node = myCreateElementSVG("path");
2772+ node.setAttribute("id", id);
2773+ svgpicture.appendChild(node);
2774+ }
2775+ if (typ=="+") {
2776+ node.setAttribute("d",
2777+ " M "+(cx-ticklength)+" "+cy+" L "+(cx+ticklength)+" "+cy+
2778+ " M "+cx+" "+(cy-ticklength)+" L "+cx+" "+(cy+ticklength));
2779+ node.setAttribute("stroke-width", .5);
2780+ node.setAttribute("stroke", axesstroke);
2781+ } else {
2782+ if (typ=="-") node.setAttribute("d",
2783+ " M "+(cx-ticklength)+" "+cy+" L "+(cx+ticklength)+" "+cy);
2784+ else node.setAttribute("d",
2785+ " M "+cx+" "+(cy-ticklength)+" L "+cx+" "+(cy+ticklength));
2786+ node.setAttribute("stroke-width", strokewidth);
2787+ node.setAttribute("stroke", stroke);
2788+ }
2789+ } else {
2790+ if (node==null) {
2791+ node = myCreateElementSVG("circle");
2792+ node.setAttribute("id", id);
2793+ svgpicture.appendChild(node);
2794+ }
2795+ node.setAttribute("cx",cx);
2796+ node.setAttribute("cy",cy);
2797+ node.setAttribute("r",dotradius);
2798+ node.setAttribute("stroke-width", strokewidth);
2799+ node.setAttribute("stroke", stroke);
2800+ node.setAttribute("fill", (typ=="open"?"white":
2801+ (typ=="closed"?stroke:markerfill)));
2802+ }
2803+ if (label!=null)
2804+ text(center,label,(pos==null?"below":pos),(id==null?id:id+"label"))
2805+}
2806+
2807+point = dot; //alternative name
2808+
2809+function arrowhead(p,q) { // draw arrowhead at q (in units) add size param
2810+ var up;
2811+ var v = [p[0]*xunitlength+origin[0],height-p[1]*yunitlength-origin[1]];
2812+ var w = [q[0]*xunitlength+origin[0],height-q[1]*yunitlength-origin[1]];
2813+ var u = [w[0]-v[0],w[1]-v[1]];
2814+ var d = Math.sqrt(u[0]*u[0]+u[1]*u[1]);
2815+ if (d > 0.00000001) {
2816+ u = [u[0]/d, u[1]/d];
2817+ up = [-u[1],u[0]];
2818+ var node = myCreateElementSVG("path");
2819+ node.setAttribute("d","M "+(w[0]-15*u[0]-4*up[0])+" "+
2820+ (w[1]-15*u[1]-4*up[1])+" L "+(w[0]-3*u[0])+" "+(w[1]-3*u[1])+" L "+
2821+ (w[0]-15*u[0]+4*up[0])+" "+(w[1]-15*u[1]+4*up[1])+" z");
2822+ node.setAttribute("stroke-width", markerstrokewidth);
2823+ node.setAttribute("stroke", stroke); /* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
2824+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
2825+ node.setAttribute("fill", stroke); /* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
2826+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */
2827+ node.setAttribute("stroke-opacity", strokeopacity);
2828+ node.setAttribute("fill-opacity", fillopacity);
2829+ svgpicture.appendChild(node);
2830+ }
2831+}
2832+
2833+function chopZ(st) {
2834+ var k = st.indexOf(".");
2835+ if (k==-1) return st;
2836+ for (var i=st.length-1; i>k && st.charAt(i)=="0"; i--);
2837+ if (i==k) i--;
2838+ return st.slice(0,i+1);
2839+}
2840+
2841+function grid(dx,dy) { // for backward compatibility
2842+ axes(dx,dy,null,dx,dy)
2843+}
2844+
2845+function noaxes() {
2846+ if (!initialized) initPicture();
2847+}
2848+
2849+function axes(dx,dy,labels,gdx,gdy) {
2850+//xscl=x is equivalent to xtick=x; xgrid=x; labels=true;
2851+ var x, y, ldx, ldy, lx, ly, lxp, lyp, pnode, st;
2852+ if (!initialized) initPicture();
2853+ if (typeof dx=="string") { labels = dx; dx = null; }
2854+ if (typeof dy=="string") { gdx = dy; dy = null; }
2855+ if (xscl!=null) {dx = xscl; gdx = xscl; labels = dx}
2856+ if (yscl!=null) {dy = yscl; gdy = yscl}
2857+ if (xtick!=null) {dx = xtick}
2858+ if (ytick!=null) {dy = ytick}
2859+ dx = (dx==null?xunitlength:dx*xunitlength);
2860+ dy = (dy==null?dx:dy*yunitlength);
2861+ fontsize = Math.min(dx/2,dy/2,16); //alert(fontsize)
2862+ ticklength = fontsize/4;
2863+ if (xgrid!=null) gdx = xgrid;
2864+ if (ygrid!=null) gdy = ygrid;
2865+ if (gdx!=null) {
2866+ gdx = (typeof gdx=="string"?dx:gdx*xunitlength);
2867+ gdy = (gdy==null?dy:gdy*yunitlength);
2868+ pnode = myCreateElementSVG("path");
2869+ st="";
2870+ for (x = origin[0]; x<width; x = x+gdx)
2871+ st += " M"+x+",0"+" "+x+","+height;
2872+ for (x = origin[0]-gdx; x>0; x = x-gdx)
2873+ st += " M"+x+",0"+" "+x+","+height;
2874+ for (y = height-origin[1]; y<height; y = y+gdy)
2875+ st += " M0,"+y+" "+width+","+y;
2876+ for (y = height-origin[1]-gdy; y>0; y = y-gdy)
2877+ st += " M0,"+y+" "+width+","+y;
2878+ pnode.setAttribute("d",st);
2879+ pnode.setAttribute("stroke-width", .5);
2880+ pnode.setAttribute("stroke", gridstroke);
2881+ pnode.setAttribute("fill", fill);
2882+ svgpicture.appendChild(pnode);
2883+ }
2884+ pnode = myCreateElementSVG("path");
2885+ st="M0,"+(height-origin[1])+" "+width+","+
2886+ (height-origin[1])+" M"+origin[0]+",0 "+origin[0]+","+height;
2887+ for (x = origin[0]+dx; x<width; x = x+dx)
2888+ st += " M"+x+","+(height-origin[1]+ticklength)+" "+x+","+
2889+ (height-origin[1]-ticklength);
2890+ for (x = origin[0]-dx; x>0; x = x-dx)
2891+ st += " M"+x+","+(height-origin[1]+ticklength)+" "+x+","+
2892+ (height-origin[1]-ticklength);
2893+ for (y = height-origin[1]+dy; y<height; y = y+dy)
2894+ st += " M"+(origin[0]+ticklength)+","+y+" "+(origin[0]-ticklength)+","+y;
2895+ for (y = height-origin[1]-dy; y>0; y = y-dy)
2896+ st += " M"+(origin[0]+ticklength)+","+y+" "+(origin[0]-ticklength)+","+y;
2897+ if (labels!=null) with (Math) {
2898+ ldx = dx/xunitlength;
2899+ ldy = dy/yunitlength;
2900+ lx = (xmin>0 || xmax<0?xmin:0);
2901+ ly = (ymin>0 || ymax<0?ymin:0);
2902+ lxp = (ly==0?"below":"above");
2903+ lyp = (lx==0?"left":"right");
2904+ var ddx = floor(1.1-log(ldx)/log(10))+1;
2905+ var ddy = floor(1.1-log(ldy)/log(10))+1;
2906+ for (x = ldx; x<=xmax; x = x+ldx)
2907+ text([x,ly],chopZ(x.toFixed(ddx)),lxp);
2908+ for (x = -ldx; xmin<=x; x = x-ldx)
2909+ text([x,ly],chopZ(x.toFixed(ddx)),lxp);
2910+ for (y = ldy; y<=ymax; y = y+ldy)
2911+ text([lx,y],chopZ(y.toFixed(ddy)),lyp);
2912+ for (y = -ldy; ymin<=y; y = y-ldy)
2913+ text([lx,y],chopZ(y.toFixed(ddy)),lyp);
2914+ }
2915+ fontsize = defaultfontsize;
2916+ pnode.setAttribute("d",st);
2917+ pnode.setAttribute("stroke-width", .5);
2918+ pnode.setAttribute("stroke", axesstroke);
2919+ pnode.setAttribute("fill", fill);
2920+ pnode.setAttribute("stroke-opacity", strokeopacity);
2921+ pnode.setAttribute("fill-opacity", fillopacity);
2922+ svgpicture.appendChild(pnode);
2923+}
2924+
2925+function mathjs(st) {
2926+ //translate a math formula to js function notation
2927+ // a^b --> pow(a,b)
2928+ // na --> n*a
2929+ // (...)d --> (...)*d
2930+ // n! --> factorial(n)
2931+ // sin^-1 --> arcsin etc.
2932+ //while ^ in string, find term on left and right
2933+ //slice and concat new formula string
2934+ st = st.replace(/\s/g,"");
2935+ if (st.indexOf("^-1")!=-1) {
2936+ st = st.replace(/sin\^-1/g,"arcsin");
2937+ st = st.replace(/cos\^-1/g,"arccos");
2938+ st = st.replace(/tan\^-1/g,"arctan");
2939+ st = st.replace(/sec\^-1/g,"arcsec");
2940+ st = st.replace(/csc\^-1/g,"arccsc");
2941+ st = st.replace(/cot\^-1/g,"arccot");
2942+ st = st.replace(/sinh\^-1/g,"arcsinh");
2943+ st = st.replace(/cosh\^-1/g,"arccosh");
2944+ st = st.replace(/tanh\^-1/g,"arctanh");
2945+ st = st.replace(/sech\^-1/g,"arcsech");
2946+ st = st.replace(/csch\^-1/g,"arccsch");
2947+ st = st.replace(/coth\^-1/g,"arccoth");
2948+ }
2949+ st = st.replace(/^e$/g,"(Math.E)");
2950+ st = st.replace(/^e([^a-zA-Z])/g,"(Math.E)$1");
2951+ st = st.replace(/([^a-zA-Z])e/g,"$1(Math.E)");
2952+// st = st.replace(/([^a-zA-Z])e([^a-zA-Z])/g,"$1(Math.E)$2");
2953+ st = st.replace(/([0-9])([\(a-zA-Z])/g,"$1*$2");
2954+ st = st.replace(/\)([\(0-9a-zA-Z])/g,"\)*$1");
2955+ var i,j,k, ch, nested;
2956+ while ((i=st.indexOf("^"))!=-1) {
2957+ //find left argument
2958+ if (i==0) return "Error: missing argument";
2959+ j = i-1;
2960+ ch = st.charAt(j);
2961+ if (ch>="0" && ch<="9") {// look for (decimal) number
2962+ j--;
2963+ while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
2964+ if (ch==".") {
2965+ j--;
2966+ while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
2967+ }
2968+ } else if (ch==")") {// look for matching opening bracket and function name
2969+ nested = 1;
2970+ j--;
2971+ while (j>=0 && nested>0) {
2972+ ch = st.charAt(j);
2973+ if (ch=="(") nested--;
2974+ else if (ch==")") nested++;
2975+ j--;
2976+ }
2977+ while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
2978+ j--;
2979+ } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
2980+ j--;
2981+ while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
2982+ j--;
2983+ } else {
2984+ return "Error: incorrect syntax in "+st+" at position "+j;
2985+ }
2986+ //find right argument
2987+ if (i==st.length-1) return "Error: missing argument";
2988+ k = i+1;
2989+ ch = st.charAt(k);
2990+ if (ch>="0" && ch<="9" || ch=="-") {// look for signed (decimal) number
2991+ k++;
2992+ while (k<st.length && (ch=st.charAt(k))>="0" && ch<="9") k++;
2993+ if (ch==".") {
2994+ k++;
2995+ while (k<st.length && (ch=st.charAt(k))>="0" && ch<="9") k++;
2996+ }
2997+ } else if (ch=="(") {// look for matching closing bracket and function name
2998+ nested = 1;
2999+ k++;
3000+ while (k<st.length && nested>0) {
3001+ ch = st.charAt(k);
3002+ if (ch=="(") nested++;
3003+ else if (ch==")") nested--;
3004+ k++;
3005+ }
3006+ } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
3007+ k++;
3008+ while (k<st.length && (ch=st.charAt(k))>="a" && ch<="z" ||
3009+ ch>="A" && ch<="Z") k++;
3010+ } else {
3011+ return "Error: incorrect syntax in "+st+" at position "+k;
3012+ }
3013+ st = st.slice(0,j+1)+"Math.pow("+st.slice(j+1,i)+","+st.slice(i+1,k)+")"+
3014+ st.slice(k);
3015+ }
3016+ while ((i=st.indexOf("!"))!=-1) {
3017+ //find left argument
3018+ if (i==0) return "Error: missing argument";
3019+ j = i-1;
3020+ ch = st.charAt(j);
3021+ if (ch>="0" && ch<="9") {// look for (decimal) number
3022+ j--;
3023+ while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
3024+ if (ch==".") {
3025+ j--;
3026+ while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
3027+ }
3028+ } else if (ch==")") {// look for matching opening bracket and function name
3029+ nested = 1;
3030+ j--;
3031+ while (j>=0 && nested>0) {
3032+ ch = st.charAt(j);
3033+ if (ch=="(") nested--;
3034+ else if (ch==")") nested++;
3035+ j--;
3036+ }
3037+ while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
3038+ j--;
3039+ } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
3040+ j--;
3041+ while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
3042+ j--;
3043+ } else {
3044+ return "Error: incorrect syntax in "+st+" at position "+j;
3045+ }
3046+ st = st.slice(0,j+1)+"factorial("+st.slice(j+1,i)+")"+st.slice(i+1);
3047+ }
3048+ return st;
3049+}
3050+
3051+function plot(fun,x_min,x_max,points,id,endpts) {
3052+ var pth = [];
3053+ var f = function(x) { return x }, g = fun;
3054+ var name = null;
3055+ if (typeof fun=="string")
3056+ eval("g = function(x){ with(Math) return "+mathjs(fun)+" }");
3057+ else if (typeof fun=="object") {
3058+ eval("f = function(t){ with(Math) return "+mathjs(fun[0])+" }");
3059+ eval("g = function(t){ with(Math) return "+mathjs(fun[1])+" }");
3060+ }
3061+ if (typeof x_min=="string") { name = x_min; x_min = xmin }
3062+ else name = id;
3063+ var min = (x_min==null?xmin:x_min);
3064+ var max = (x_max==null?xmax:x_max);
3065+ var inc = max-min-0.000001*(max-min);
3066+ inc = (points==null?inc/200:inc/points);
3067+ var gt;
3068+//alert(typeof g(min))
3069+ for (var t = min; t <= max; t += inc) {
3070+ gt = g(t);
3071+ if (!(isNaN(gt)||Math.abs(gt)=="Infinity")) pth[pth.length] = [f(t), gt];
3072+ }
3073+ path(pth,name,null,endpts);
3074+ return pth;
3075+}
3076+
3077+// make polar plot
3078+
3079+// make Riemann sums
3080+
3081+function slopefield(fun,dx,dy) {
3082+ var g = fun;
3083+ if (typeof fun=="string")
3084+ eval("g = function(x,y){ with(Math) return "+mathjs(fun)+" }");
3085+ var gxy,x,y,u,v,dz;
3086+ if (dx==null) dx=1;
3087+ if (dy==null) dy=1;
3088+ dz = Math.sqrt(dx*dx+dy*dy)/6;
3089+ var x_min = Math.ceil(xmin/dx);
3090+ var y_min = Math.ceil(ymin/dy);
3091+ for (x = x_min; x <= xmax; x += dx)
3092+ for (y = y_min; y <= ymax; y += dy) {
3093+ gxy = g(x,y);
3094+ if (!isNaN(gxy)) {
3095+ if (Math.abs(gxy)=="Infinity") {u = 0; v = dz;}
3096+ else {u = dz/Math.sqrt(1+gxy*gxy); v = gxy*u;}
3097+ line([x-u,y-v],[x+u,y+v]);
3098+ }
3099+ }
3100+}
3101+
3102+///////////////////////user graphics commands end here/////////////////////////
3103+
3104+function show_props(obj) {
3105+ var result = "";
3106+ for (var i=0; i< obj.childNodes.length; i++)
3107+ result += obj.childNodes.item(i) + "\n";
3108+ return result;
3109+}
3110+
3111+function displayCoord(evt) {
3112+ if (showcoordinates) {
3113+ var svgroot = evt.target.parentNode;
3114+ var nl = svgroot.childNodes;
3115+ for (var i=0; i<nl.length && nl.item(i).nodeName!="text"; i++);
3116+ var cnode = nl.item(i);
3117+ cnode.mtext = mtext;
3118+ cnode.mtext([svgroot.getAttribute("width")-(-7),svgroot.getAttribute("height")-7],"("+getX(evt).toFixed(2)+", "+getY(evt).toFixed(2)+")", "left", "", "11");
3119+/* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
3120+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */ }
3121+}
3122+
3123+function removeCoord(evt) {
3124+ var svgroot = evt.target.parentNode;
3125+ var nl = svgroot.childNodes;
3126+ for (var i=0; i<nl.length && nl.item(i).nodeName!="text"; i++);
3127+ var cnode = nl.item(i);
3128+ cnode.mtext = mtext;
3129+ cnode.mtext([svgroot.getAttribute("width")-0,svgroot.getAttribute("height")-0],"", "aboveleft", "");
3130+/* ASCIIMathML.js - copyright Peter Jipsen, released under the GPL
3131+See http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ */}
3132+
3133+function initASCIIMathCalculators(li) {
3134+ var i;
3135+ for (i=0; i<li.length; i++) {
3136+ li[i].innerHTML = calcstr;
3137+ AMprocessNode(li[i]);
3138+ }
3139+ li = document.getElementsByTagName("textarea");
3140+ var st;
3141+ for (i=0; i<li.length; i++) {
3142+ st = li[i].getAttribute("onkeyup");
3143+ if (st!=null) eval(String(st).replace(/function anonymous\(\)/,""));
3144+ }
3145+}
3146+
3147+function calculate(inputId,outputId) {
3148+ var str = document.getElementById(inputId).value;
3149+ var err = "";
3150+ var ind = str.lastIndexOf("\n");
3151+ if (ind==str.length-1) str = str.slice(0,ind);
3152+ str = str.slice(str.lastIndexOf("\n")+1);
3153+ try {
3154+ var res = eval(mathjs(str));
3155+ } catch(e) {
3156+ err = "syntax incomplete";
3157+ }
3158+ if (!isNaN(res) && res!="Infinity")
3159+ str = "`"+str+" =` "+(Math.abs(res-Math.round(res*1000000)/1000000)<1e-15?Math.round(res*1000000)/1000000:res)+err;
3160+ else if (str!="") str = "`"+str+"` = undefined"; //debug:+mathjs(str);
3161+ var outnode = document.getElementById(outputId);
3162+ var n = outnode.childNodes.length;
3163+ for (var i=0; i<n; i++)
3164+ outnode.removeChild(outnode.firstChild);
3165+ outnode.appendChild(document.createTextNode(str));
3166+ AMprocessNode(outnode);
3167+}
3168+
3169+function append(st){
3170+ document.getElementById('in').value+=st;
3171+ calculate('in','out');
3172+ document.getElementById('in').scrollTop = 1000;
3173+ document.getElementById('in').focus();
3174+}
3175+
3176+function clearTextArea(){
3177+ document.getElementById('in').value="";
3178+ calculate('in','out');
3179+ document.getElementById('in').focus();
3180+}
3181+
3182+var calcstr = "<table align=\"center\">\n<tr><th>\nASCIIMath Scientific Calculator\n</th></tr>\n<tr><td>\nClick in the box to use your keyboard or use the buttons\n</td></tr>\n<tr><td>\n<textarea id=\"in\" rows=\"3\" cols=\"40\" onkeyup=\"calculate('in','out')\"></textarea></td></tr>\n<tr><td height=\"50\">Result: &nbsp; &nbsp; <span id=\"out\"></span></td></tr>\n</table>\n<table align=\"center\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody align=\"center\">\n<tr>\n<td colspan=\"4\">\n<button onclick=\"append('sin^-1(')\"><font size=2>`sin^-1`</font></button><button onclick=\"append('cos^-1(')\"><font size=2>`cos^-1`</font></button><button onclick=\"append('tan^-1(')\"><font size=2>`tan^-1`</font></button></td>\n<td><button onclick=\"clearTextArea()\">&nbsp;`C`&nbsp;</button></td>\n\n</tr>\n<tr>\n<td><button onclick=\"append('pi')\">&nbsp;`pi` &nbsp;</button></td>\n<td><button onclick=\"append('sin(')\">&nbsp;`sin`</button></td>\n<td><button onclick=\"append('cos(')\">&nbsp;`cos`</button></td>\n<td><button onclick=\"append('tan(')\">&nbsp;`tan`</button></td>\n<td><button onclick=\"append('^')\">`x^y`</button></td>\n</tr>\n<tr>\n<td><button onclick=\"append('!')\">&nbsp; `!` &nbsp;</button></td>\n\n<td><button onclick=\"append('(')\"><font size=2>&nbsp;&nbsp;`(`&nbsp;&nbsp;</font></button></td>\n<td><button onclick=\"append(')')\"><font size=2>&nbsp;&nbsp;`)`&nbsp;&nbsp;</font></button></td>\n<td><button onclick=\"append('sqrt(')\"><font size=2>`sqrt({::}^\ )`</font></button></td>\n<td><button onclick=\"append('/')\">&nbsp;`-:\ `</button></td>\n</tr>\n<tr>\n<td><button onclick=\"append('log(')\">`log`</button></td>\n<td><button onclick=\"append('7')\">&nbsp; `7` &nbsp;</button></td>\n<td><button onclick=\"append('8')\">&nbsp; `8` &nbsp;</button></td>\n\n<td><button onclick=\"append('9')\">&nbsp; `9` &nbsp;</button></td>\n<td><button onclick=\"append('*')\">&nbsp;`times`&nbsp;</button></td>\n</tr>\n<tr>\n<td><button onclick=\"append('ln(')\">&nbsp;`ln`&nbsp;</button></td>\n<td><button onclick=\"append('4')\">&nbsp; `4` &nbsp;</button></td>\n<td><button onclick=\"append('5')\">&nbsp; `5` &nbsp;</button></td>\n<td><button onclick=\"append('6')\">&nbsp; `6` &nbsp;</button></td>\n\n<td><button onclick=\"append('-')\">&nbsp;`-{::}`&nbsp;</button></td>\n</tr>\n<tr>\n<td><button onclick=\"append('e')\">&nbsp; `e` &nbsp;</button></td>\n<td><button onclick=\"append('1')\">&nbsp;&nbsp;`1` &nbsp;</button></td>\n<td><button onclick=\"append('2')\">&nbsp; `2` &nbsp;</button></td>\n<td><button onclick=\"append('3')\">&nbsp; `3` &nbsp;</button></td>\n<td><button onclick=\"append('+')\">&nbsp;`+{::}`&nbsp;</button></td>\n\n</tr>\n<tr>\n<td> <!--button onclick=\"append('pi')\">&nbsp;`pi` &nbsp;</button--></td>\n<td><button onclick=\"append('0')\">&nbsp; `0` &nbsp;</button></td>\n<td><button onclick=\"append('.')\">&nbsp; `.` &nbsp;</button></td>\n<td><button onclick=\"append('\\n')\">&nbsp;`\"ent\"`</button></td>\n</tr>\n</tbody>\n</table>";
3183+
3184+// GO1.1 Generic onload by Brothercake
8763185// http://www.brothercake.com/
8773186//onload function (replaces the onload="translate()" in the <body> tag)
8783187function generic()
8793188{
880− translate();
3189+ if(!init()) return;
3190+ if (translateOnLoad) {
3191+ var nd = document.getElementById("processasciimathinmoodle");
3192+ if (nd!=null) dsvglocation = nd.className;
3193+ if (nd!=null || !checkforprocessasciimathinmoodle) {
3194+ translate();
3195+ if (!noSVG && translateASCIIsvg) drawPictures();
3196+ }
3197+ var li = getElementsByClass(document,"div","ASCIIMathCalculator");
3198+ if (!noMathML && li.length>0) initASCIIMathCalculators(li);
3199+ }
8813200};
8823201//setup onload function
8833202if(typeof window.addEventListener != 'undefined')