]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/furnace-onigiri/resources/wiky/wiky.math.js
Fix Windows bootstrap
[factor.git] / unmaintained / furnace-onigiri / resources / wiky / wiky.math.js
1 /*      This work is licensed under Creative Commons GNU LGPL License.
2
3         License: http://creativecommons.org/licenses/LGPL/2.1/
4
5         Author:  Stefan Goessner/2005-06
6         Web:     http://goessner.net/ 
7    inspired by: http://xml-maiden.com/
8 */
9 Wiky.rules.math = {
10    version: 0.95,
11    preshortcuts: [
12 //      { rex:/[ ]/g, tmplt:"`"},   // omit due to charset support ie6
13       { rex:/\+\-/g, tmplt:"±"},
14       { rex:/\/O|\\Oslash/g, tmplt:"Ø"},
15       { rex:/\/o|\\oslash/g, tmplt:"ø"},
16       { rex:/<->|\\harr/g, tmplt:"&#8596;"},
17       { rex:/<-|\\larr/g, tmplt:"&#8592;"},
18       { rex:/->|\\rarr/g, tmplt:"&#8594;"},
19       { rex:/<=>|\\hArr/g, tmplt:"&#8660;"},
20       { rex:/=>|\\rArr/g, tmplt:"&#8658;"},
21       { rex:/-=|\\equiv/g, tmplt:"&#8801;"},
22       { rex:/<=|\\le/g, tmplt:"&#8804;"},
23       { rex:/>=|\\ge/g, tmplt:"&#8805;"},
24       { rex:/</g, tmplt:"&lt;"},
25       { rex:/>/g, tmplt:"&gt;"}
26    ],
27    postshortcuts: [
28       { rex:/\*|\\middot/g, tmplt:"&#183;"},
29       { rex:/\\x|\\times/g, tmplt:"&#215;"},
30       { rex:/~=|\\cong/g, tmplt:"&#8773;"},
31       { rex:/~~|\\asymp/g, tmplt:"&#8776;"},
32       { rex:/~|\\sim/g, tmplt:"&#8764;"},
33       { rex:/!=|\\neq|\\ne/g, tmplt:"&#8800;"},
34       { rex:/\.\.\.|\\ldots/g, tmplt:"&#8230;"},
35       { rex:/\\in|\\isin/g, tmplt:"&#8712;"},
36       { rex:/([0-9])x([0-9])/g, tmplt:"$1&#215;$2"}, 
37       { rex:/([A-Za-z]) x ([A-Za-z])/g, tmplt:"$1&#215;$2"},
38 //      { rex:/[`]{4}/g, tmplt:"&#8195;"},  // omit due to charset support ie6
39 //      { rex:/[`]{3}/g, tmplt:"&#8194;"},
40 //      { rex:/[`]{2}/g, tmplt:"  "},
41 //      { rex:/[`]/g, tmplt:"&#8201;"},
42       { rex:/\{/g, tmplt:"&#8206;"},  // unvisible left-to-right mark,
43       { rex:/\}/g, tmplt:"&#8207;"}   // unvisible right-to-left mark,
44    ],
45    expr: [
46       { rex:/\^\^/g, tmplt:"^&#94;"},  // ^ overindex
47       { rex:/(\\sum|\\prod|\\int)_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"o\"><span class=\"x\">$3</span>$1<span class=\"x\">$2</span></span>"}, // over-/underscript (\sum, \prod, \int)
48       { rex:/(\\sum|\\prod|\\int)\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"o\"><span class=\"x\">$2</span>$1<span>&#160;</span></span>"},
49       { rex:/(\\sum|\\prod|\\int)_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"o\"><span>&#160;</span>$1<span class=\"x\">$2</span></span>"},
50       { rex:/_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"s\"><span class=\"i\">$2</span><span class=\"i\">$1</span></span>"}, // over-/underindex
51       { rex:/\^([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<sup class=\"i\">$1</sup>"}, // overindex
52       { rex:/_([-]?[a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<sub class=\"i\">$1</sub>"}, // underindex
53       { rex:/-/g, tmplt:"&#8722;"},
54       { rex:/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<span class=\"f\"><span class=\"n\">$1</span><span class=\"d\">$2</span></span>"},  // fraction
55       { rex:/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})\/\/([a-zA-Z0-9\.&;#\\]+|\{@[0-9]+@\})/g, tmplt:"<sup>$1</sup>&#8260;<sub>$2</sub>"}, // fraction 
56       { rex:/\[((\[(([^,\]]+[,]){1,}[^\]]+)\][ \n]*){1,})\]/g, tmplt:function($0,$1){var m=Wiky.math.transpose($1.replace(/(^\[|\]$)/g,"").replace(/(\][ \n]*\[)/g,"|").split("|")),sz=" style=\"font-size:"+(m.len)+"00%;\"";/*alert("{("+m.mat.join(")}\n{(").split(",").join(")(")+")}");*/ return "<span class=\"lb\""+sz+">"+Wiky.math.fence()+"</span><span class=\"m\"><span class=\"e\">"+m.mat.join("</span></span>\n<span class=\"m\"><span class=\"e\">").split(",").join("</span><span class=\"e\">")+"</span></span><span class=\"rb\""+sz+">"+Wiky.math.fence()+"</span>";}}, // matrix
57       { rex:/\[((?:[^,\]]){1,}[^\]]+)\]/g, tmplt:function($0,$1){var v=$1.split(","),sz=" style=\"font-size:"+v.length+"00%;\""; return "<span class=\"lb\""+sz+">"+Wiky.math.fence()+"</span><span class=\"v\"><span class=\"e\">"+v.join("</span><span class=\"e\">")+"</span></span><span class=\"rb\""+sz+">"+Wiky.math.fence()+"</span>";}}, // vector
58       { rex:/!([a-zA-Z0-9\.&;]+)/g, tmplt:"<span class=\"b\">$1</span>" }, // bold vector symbol ..
59       { rex:/\\prod/g, tmplt:"<span class=\"h\">&#8719;</span>"},
60       { rex:/\\sum/g, tmplt:"<span class=\"h\">&#8721;</span>"},
61       { rex:/\\int/g, tmplt:"<span class=\"h\">&#8747;</span>"},
62       "Wiky.rules.math.postshortcuts"
63    ],
64    symbols: [
65       { rex:/\\Alpha/g, tmplt:"&#913;"},
66       { rex:/\\Beta/g, tmplt:"&#914;"},
67       { rex:/\\Gamma/g, tmplt:"&#915;"},
68       { rex:/\\Delta/g, tmplt:"&#916;"},
69       { rex:/\\Epsilon/g, tmplt:"&#917;"},
70       { rex:/\\Zeta/g, tmplt:"&#918;"},
71       { rex:/\\Eta/g, tmplt:"&#919;"},
72       { rex:/\\Theta/g, tmplt:"&#920;"},
73       { rex:/\\Iota/g, tmplt:"&#921;"},
74       { rex:/\\Kappa/g, tmplt:"&#922;"},
75       { rex:/\\Lambda/g, tmplt:"&#923;"},
76       { rex:/\\Mu/g, tmplt:"&#924;"},
77       { rex:/\\Nu/g, tmplt:"&#925;"},
78       { rex:/\\Xi/g, tmplt:"&#926;"},
79       { rex:/\\Omicron/g, tmplt:"&#927;"},
80       { rex:/\\Pi/g, tmplt:"&#928;"},
81       { rex:/\\Rho/g, tmplt:"&#929;"},
82       { rex:/\\Sigma/g, tmplt:"&#931;"},
83       { rex:/\\Tau/g, tmplt:"&#932;"},
84       { rex:/\\Upsilon/g, tmplt:"&#933;"},
85       { rex:/\\Phi/g, tmplt:"&#934;"},
86       { rex:/\\Chi/g, tmplt:"&#935;"},
87       { rex:/\\Psi/g, tmplt:"&#936;"},
88       { rex:/\\Omega/g, tmplt:"&#937;"},
89       { rex:/\\alpha/g, tmplt:"&#945;"},
90       { rex:/\\beta/g, tmplt:"&#946;"},
91       { rex:/\\gamma/g, tmplt:"&#947;"},
92       { rex:/\\delta/g, tmplt:"&#948;"},
93       { rex:/\\epsilon/g, tmplt:"&#949;"},
94       { rex:/\\zeta/g, tmplt:"&#950;"},
95       { rex:/\\eta/g, tmplt:"&#951;"},
96       { rex:/\\thetasym/g, tmplt:"&#977;"},
97       { rex:/\\theta/g, tmplt:"&#952;"},
98       { rex:/\\iota/g, tmplt:"&#953;"},
99       { rex:/\\kappa/g, tmplt:"&#954;"},
100       { rex:/\\lambda/g, tmplt:"&#955;"},
101       { rex:/\\mu/g, tmplt:"&#956;"},
102       { rex:/\\nu/g, tmplt:"&#957;"},
103       { rex:/\\xi/g, tmplt:"&#958;"},
104       { rex:/\\omicron/g, tmplt:"&#959;"},
105       { rex:/\\piv/g, tmplt:"&#982;"},
106       { rex:/\\pi/g, tmplt:"&#960;"},
107       { rex:/\\rho/g, tmplt:"&#961;"},
108       { rex:/\\sigmaf/g, tmplt:"&#962;"},
109       { rex:/\\sigma/g, tmplt:"&#963;"},
110       { rex:/\\tau/g, tmplt:"&#964;"},
111       { rex:/\\upsilon/g, tmplt:"&#965;"},
112       { rex:/\\phi/g, tmplt:"&#966;"},
113       { rex:/\\chi/g, tmplt:"&#967;"},
114       { rex:/\\psi/g, tmplt:"&#968;"},
115       { rex:/\\omega/g, tmplt:"&#969;"},
116       { rex:/\\upsih/g, tmplt:"&#978;"},
117       // miscellaneous symbols
118       { rex:/\\bull/g, tmplt:"&#8226;"},
119       { rex:/\\uarr/g, tmplt:"&#8593;"},
120       { rex:/\\darr/g, tmplt:"&#8595;"},
121       { rex:/\\crarr/g, tmplt:"&#8629;"},
122       { rex:/\\lArr/g, tmplt:"&#8656;"},
123       { rex:/\\uArr/g, tmplt:"&#8657;"},
124       { rex:/\\dArr/g, tmplt:"&#8659;"},
125       { rex:/\\forall/g, tmplt:"&#8704;"},
126       { rex:/\\part/g, tmplt:"&#8706;"},
127       { rex:/\\exist/g, tmplt:"&#8707;"},
128       { rex:/\\empty/g, tmplt:"&#8709;"},
129       { rex:/\\nabla/g, tmplt:"&#8711;"},
130       { rex:/\\notin/g, tmplt:"&#8713;"},
131       { rex:/\\ni/g, tmplt:"&#8715;"},
132       { rex:/\\minus/g, tmplt:"&#8722;"},
133       { rex:/\\lowast/g, tmplt:"&#8727;"},
134       { rex:/\\sqrt|\\radic/g, tmplt:"&#8730;"},
135       { rex:/\\prop/g, tmplt:"&#8733;"},
136       { rex:/\\infin/g, tmplt:"&#8734;"},
137       { rex:/\\ang/g, tmplt:"&#8736;"},
138       { rex:/\\and/g, tmplt:"&#8743;"},
139       { rex:/\\or/g, tmplt:"&#8744;"},
140       { rex:/\\cap/g, tmplt:"&#8745;"},
141       { rex:/\\cup/g, tmplt:"&#8746;"},
142       { rex:/\\there4/g, tmplt:"&#8756;"},
143       { rex:/\\sub/g, tmplt:"&#8834;"},
144       { rex:/\\sup/g, tmplt:"&#8835;"},
145       { rex:/\\nsub/g, tmplt:"&#8836;"},
146       { rex:/\\sube/g, tmplt:"&#8838;"},
147       { rex:/\\supe/g, tmplt:"&#8839;"},
148       { rex:/\\oplus/g, tmplt:"&#8853;"},
149       { rex:/\\otimes/g, tmplt:"&#8855;"},
150       { rex:/\\perp/g, tmplt:"&#8869;"},
151       { rex:/\\sdot/g, tmplt:"&#8901;"}
152    ]
153 };
154
155 Wiky.inverse.math = {
156    pre: [
157       { rex:/&#8722;|\u2212/g, tmplt:"-"},
158       { rex:/&#8201;|\u2009/g, tmplt:"&#8201;"},
159       { rex:/&#8206;|\u200E/g, tmplt:"{"},
160       { rex:/&#8207;|\u200F/g, tmplt:"}"}
161    ],
162    post: [
163 //      { rex:/([$])/g, tmplt:"\\$1" },
164       { rex:/&#94;|\x5E/g, tmplt:"^"},
165       { rex:/&lt;/g, tmplt:"<"},
166       { rex:/&gt;/g, tmplt:">"}
167    ],
168    shortcuts: [
169 //      { rex:/&#8195;|\u2003/g, tmplt:"    "}, // omit due to charset support ie6
170 //      { rex:/&#8194;|\u2002/g, tmplt:"   "},
171 //      { rex:/&#8201;|\u2009/g, tmplt:" "},
172       { rex:/&#177;|\xB1/g, tmplt:"+-"},
173       { rex:/&#183;|\xB7/g, tmplt:"*"},
174       { rex:/&#215;|\xD7/g, tmplt:"\\x"},
175       { rex:/&#216;|\xD8/g, tmplt:"/O"},
176       { rex:/&#248;|\xF8/g, tmplt:"/o"},
177       { rex:/&#8592;|\u2190/g, tmplt:"&lt;-"},
178       { rex:/&#8594;|\u2192/g, tmplt:"-&gt;"},
179       { rex:/&#8596;|\u2194/g, tmplt:"&lt;-&gt;"},
180       { rex:/&#8658;|\u21D2/g, tmplt:"=&gt;"},
181       { rex:/&#8660;|\u21D4/g, tmplt:"&lt;=&gt;"},
182       { rex:/&#8764;|\u223C/g, tmplt:"~"},
183       { rex:/&#8773;|\u2245/g, tmplt:"~="},
184       { rex:/&#8776;|\u2248/g, tmplt:"~~"},
185       { rex:/&#8800;|\u2260/g, tmplt:"!="},
186       { rex:/&#8230;/g, tmplt:"..."},
187       { rex:/&#8801;|\u2261/g, tmplt:"-="},
188       { rex:/&#8804;|\u2264/g, tmplt:"&lt;="},
189       { rex:/&#8805;|\u2265/g, tmplt:"&gt;="}
190    ],
191    expr: [
192       { rex:/<span class=\"s\"><span class=\"i\">(\{?@[0-9]+@\}?)<\/span><span class="i">(\{?@[0-9]+@\}?)<\/span><\/span>/g, tmplt:"_$2^$1"}, // superscript + subscript
193       { rex:/<span class=\"o\"><span class=\"x\">(\{?@[0-9]+@\}?)<\/span>(\\prod|\\sum|\\int)<span class=\"x\">(\{?@[0-9]+@\}?)<\/span><\/span>/g, tmplt:"$2_$3^$1"},  // overscript + underscript
194       { rex:/<span class=\"o\"><span>@[0-9]+@<\/span>(\\prod|\\sum|\\int)<span class=\"x\">(\{?@[0-9]+@\}?)<\/span><\/span>/mgi, tmplt:"$1_$2", dbg:true},  // underscript
195       { rex:/<span class=\"o\"><span class=\"x\">(\{?@[0-9]+@\}?)<\/span>(\\prod|\\sum|\\int)<span>@[0-9]+@<\/span><\/span>/mgi, tmplt:"$2^$1"},  // overscript
196       { rex:/<span class=\"f\"><span class=\"n\">(\{?@[0-9]+@\}?)<\/span><span class="d">(\{?@[0-9]+@\}?)<\/span><\/span>/mgi, tmplt:"$1/$2"},  // fraction
197       { rex:/<span class=\"lb\"[^>]*>&[^;]+;<\/span><span class=\"v\">((?:<span class=\"e\">[^>]*<\/span>){2,})<\/span><span class=\"rb\"[^>]*>&[^;]+;<\/span>/mgi, tmplt:function($0,$1){return "["+$1.replace(/(?:^<span class=\"e\">|<\/span>$)/g,"").replace(/<\/span><span class=\"e\">/g,",")+"]";}}, // vector ..
198       { rex:/<span class=\"lb\"[^>]*>&[^;]+;<\/span>((?:<span class=\"m\">(?:(?:<span class=\"e\">[^>]*<\/span>){2,})<\/span>[^>]*){2,})<span class=\"rb\"[^>]*>&[^;]+;<\/span>/mgi, tmplt:function($0,$1){return "[["+Wiky.math.transpose($1.replace(/(?:^<span class=\"m\"><span class=\"e\">|<\/span><\/span>$)/g,"").replace(/<\/span><span class=\"e\">/g,",").replace(/<\/span><\/span>[^>]*<span class=\"m\"><span class=\"e\">/g,"|").split("|")).mat.join("][")+"]]";}}, // matrix ..
199       { rex:/<span class=\"b\">(@[0-9]+@)<\/span>/mgi, tmplt:"!$1"}, // bold vector ..
200       { rex:/<sup>(\{?@[0-9]+@\}?)<\/sup>&#8260;<sub>(\{?@[0-9]+@\}?)<\/sub>/mgi, tmplt:"$1//$2"},
201       { rex:/<sup class=\"i\">(\{?@[0-9]+@\}?)<\/sup>/mgi, tmplt:"^$1" }, 
202       { rex:/<sub class=\"i\">(\{?@[0-9]+@\}?)<\/sub>/mgi, tmplt:"_$1" }
203    ],
204    symbols: [
205       // greek symbols
206       { rex:/&#913;|\u391/g, tmplt:"\\Alpha"},
207       { rex:/&#914;|\u392/g, tmplt:"\\Beta"},
208       { rex:/&#915;|\u393/g, tmplt:"\\Gamma"},
209       { rex:/&#916;|\u394/g, tmplt:"\\Delta"},
210       { rex:/&#917;|\u395/g, tmplt:"\\Epsilon"},
211       { rex:/&#918;|\u396/g, tmplt:"\\Zeta"},
212       { rex:/&#919;|\u397/g, tmplt:"\\Eta"},
213       { rex:/&#920;|\u398/g, tmplt:"\\Theta"},
214       { rex:/&#921;|\u399/g, tmplt:"\\Iota"},
215       { rex:/&#922;|\u39A/g, tmplt:"\\Kappa"},
216       { rex:/&#923;|\u39B/g, tmplt:"\\Lambda"},
217       { rex:/&#924;|\u39C/g, tmplt:"\\Mu"},
218       { rex:/&#925;|\u39D/g, tmplt:"\\Nu"},
219       { rex:/&#926;|\u39E/g, tmplt:"\\Xi"},
220       { rex:/&#927;|\u39F/g, tmplt:"\\Omicron"},
221       { rex:/&#928;|\u3A0/g, tmplt:"\\Pi"},
222       { rex:/&#929;|\u3A1/g, tmplt:"\\Rho"},
223       { rex:/&#931;|\u3A3/g, tmplt:"\\Sigma"},
224       { rex:/&#932;|\u3A4/g, tmplt:"\\Tau"},
225       { rex:/&#933;|\u3A5/g, tmplt:"\\Upsilon"},
226       { rex:/&#934;|\u3A6/g, tmplt:"\\Phi"},
227       { rex:/&#935;|\u3A7/g, tmplt:"\\Chi"},
228       { rex:/&#936;|\u3A8/g, tmplt:"\\Psi"},
229       { rex:/&#937;|\u3A9/g, tmplt:"\\Omega"},
230       { rex:/&#945;|\u3B1/g, tmplt:"\\alpha"},
231       { rex:/&#946;|\u3B2/g, tmplt:"\\beta"},
232       { rex:/&#947;|\u3B3/g, tmplt:"\\gamma"},
233       { rex:/&#948;|\u3B4/g, tmplt:"\\delta"},
234       { rex:/&#949;|\u3B5/g, tmplt:"\\epsilon"},
235       { rex:/&#950;|\u3B6/g, tmplt:"\\zeta"},
236       { rex:/&#951;|\u3B7/g, tmplt:"\\eta"},
237       { rex:/&#977;|\u3D1/g, tmplt:"\\thetasym"},
238       { rex:/&#952;|\u3B8/g, tmplt:"\\theta"},
239       { rex:/&#953;|\u3B9/g, tmplt:"\\iota"},
240       { rex:/&#954;|\u3BA/g, tmplt:"\\kappa"},
241       { rex:/&#955;|\u3BB/g, tmplt:"\\lambda"},
242       { rex:/&#956;|\u3BC/g, tmplt:"\\mu"},
243       { rex:/&#957;|\u3BD/g, tmplt:"\\nu"},
244       { rex:/&#958;|\u3BE/g, tmplt:"\\xi"},
245       { rex:/&#959;|\u3BF/g, tmplt:"\\omicron"},
246       { rex:/&#960;|\u3C0/g, tmplt:"\\pi"},
247       { rex:/&#961;|\u3C1/g, tmplt:"\\rho"},
248       { rex:/&#962;|\u3C2/g, tmplt:"\\sigmaf"},
249       { rex:/&#963;|\u3C3/g, tmplt:"\\sigma"},
250       { rex:/&#964;|\u3C4/g, tmplt:"\\tau"},
251       { rex:/&#965;|\u3C5/g, tmplt:"\\upsilon"},
252       { rex:/&#966;|\u3C6/g, tmplt:"\\phi"},
253       { rex:/&#967;|\u3C7/g, tmplt:"\\chi"},
254       { rex:/&#968;|\u3C8/g, tmplt:"\\psi"},
255       { rex:/&#969;|\u3C9/g, tmplt:"\\omega"},
256       // miscellaneous symbols
257       { rex:/&#978;|\u3D2/g, tmplt:"\\upsih"},
258       { rex:/&#982;|\u3D6/g, tmplt:"\\piv"},
259       { rex:/&#8226;|\u2022/g, tmplt:"\\bull"},
260       { rex:/&#8593;|\u2191/g, tmplt:"\\uarr"},
261       { rex:/&#8595;|\u2193/g, tmplt:"\\darr"},
262       { rex:/&#8629;|\u21B5/g, tmplt:"\\crarr"},
263       { rex:/&#8656;|\u21D0/g, tmplt:"\\lArr"},
264       { rex:/&#8657;|\u21D1/g, tmplt:"\\uArr"},
265       { rex:/&#8659;|\u21D3/g, tmplt:"\\dArr"},
266       { rex:/&#8704;|\u2200/g, tmplt:"\\forall"},
267       { rex:/&#8706;|\u2202/g, tmplt:"\\part"},
268       { rex:/&#8707;|\u2203/g, tmplt:"\\exist"},
269       { rex:/&#8709;|\u2205/g, tmplt:"\\empty"},
270       { rex:/&#8711;|\u2207/g, tmplt:"\\nabla"},
271       { rex:/&#8712;|\u2208/g, tmplt:"\\isin"},
272       { rex:/&#8713;|\u2209/g, tmplt:"\\notin"},
273       { rex:/&#8715;|\u220B/g, tmplt:"\\ni"},
274       { rex:/<span class=\"h\">(&#8719;|\u220F)<\/span>/g, tmplt:"\\prod"},
275       { rex:/<span class=\"h\">(&#8721;|\u2211)<\/span>/g, tmplt:"\\sum"},
276       { rex:/&#8727;|\u2217/g, tmplt:"\\lowast"},
277       { rex:/&#8730;|\u221A/g, tmplt:"\\sqrt"},
278       { rex:/&#8733;|\u221D/g, tmplt:"\\prop"},
279       { rex:/&#8734;|\u221E/g, tmplt:"\\infin"},
280       { rex:/&#8736;|\u2220/g, tmplt:"\\ang"},
281       { rex:/&#8743;|\u2227/g, tmplt:"\\and"},
282       { rex:/&#8744;|\u2228/g, tmplt:"\\or"},
283       { rex:/&#8745;|\u2229/g, tmplt:"\\cap"},
284       { rex:/&#8746;|\u222A/g, tmplt:"\\cup"},
285       { rex:/<span class=\"h\">(?:&#8747;|\u222B)<\/span>/g, tmplt:"\\int"},
286       { rex:/&#8756;|\u2234/g, tmplt:"\\there4"},
287       { rex:/&#8834;|\u2282/g, tmplt:"\\sub"},
288       { rex:/&#8835;|\u2283/g, tmplt:"\\sup"},
289       { rex:/&#8836;|\u2284/g, tmplt:"\\nsub"},
290       { rex:/&#8838;|\u2286/g, tmplt:"\\sube"},
291       { rex:/&#8839;|\u2287/g, tmplt:"\\supe"},
292       { rex:/&#8853;|\u2295/g, tmplt:"\\oplus"},
293       { rex:/&#8855;|\u2297/g, tmplt:"\\otimes"},
294       { rex:/&#8869;|\u22A5/g, tmplt:"\\perp"},
295       { rex:/&#8901;|\u22C5/g, tmplt:"\\sdot"}
296    ]
297 };
298
299 Wiky.math = {
300    toHtml: function(str) {
301       var expr = function(itr) {  // region from "{" to "}", nesting allowed ..
302          var s = "";
303          for (var c = itr.str.charAt(itr.pos++); itr.pos <= itr.str.length && c != "}"; c = itr.str.charAt(itr.pos++))
304             s += (c == "{") ? ("{"+expr(itr)+"}") : c;
305          return Wiky.store(Wiky.apply(s, Wiky.rules.math.expr));
306       };
307       str = Wiky.apply(str, Wiky.rules.math.preshortcuts);
308       str = Wiky.apply(str, Wiky.rules.math.symbols);
309       str = expr({str:str,pos:0});
310       return str;
311    },
312    toWiki: function(str) {
313       var parseTree = function(itr, endtag) {
314          var c, s="",gt,nam,idxof=function(s,c,p){var i=s.indexOf(c,p);return i>=0?i:s.length;}
315          for (itr.buf=itr.str.substr(itr.pos,endtag.length); 
316               itr.pos<itr.str.length && (!endtag || itr.buf!=endtag); 
317               itr.buf=itr.str.substr(++itr.pos,endtag.length)) {
318             if ((c=itr.str.charAt(itr.pos))=="<" && (gt=idxof(itr.str,">",itr.pos)) < idxof(itr.str,"/",itr.pos)) { // start tags .. no empty elements or endtags ..
319                nam = itr.str.substring(itr.pos+1,Math.min(idxof(itr.str," ",itr.pos),gt));
320                s += itr.str.substring(itr.pos,itr.pos=gt+1) + parseTree(itr, "</" + nam + ">") + "</" + nam + ">";
321                itr.pos += nam.length+3;
322             }
323             else
324                s += c;
325          }
326          itr.pos--;
327          return Wiky.store(s, true);
328       };
329       str = Wiky.apply(str, Wiky.inverse.math.pre);
330       str = Wiky.apply(str, Wiky.inverse.math.symbols);
331       str = parseTree({str:str,pos:0,buf:null}, "");
332       while (str.match(/@[0-9]+@/g) != null)
333          str = Wiky.apply(str.replace(/@([0-9]+)@/g, function($0,$1){return Wiky.restore($1);}), Wiky.inverse.math.expr);
334       str = Wiky.apply(str, Wiky.inverse.math.shortcuts);
335       str = Wiky.apply(str, Wiky.inverse.math.post);
336       return str;
337    },
338    fence: function(str) {
339       return window && window.ActiveXObject ? "&#160;" : "&#8201;";
340    },
341    transpose: function (m) {
342       var t=[];
343       for (var i in m) {
344          m[i] = m[i].split(",");
345          for (var j in m[i]) {
346             if (!t[j]) t[j]=[];
347             t[j][i] = m[i][j];
348          }
349       }
350       for (var i in t)
351          t[i] = t[i].join(",");
352      return {mat:t, len:m.length};
353   }
354 };
355
356 Wiky.rules.pre = Wiky.rules.pre.concat({ rex:/\\([$])/g, tmplt:function($0,$1){return Wiky.store($1);} });
357 Wiky.rules.nonwikiblocks = Wiky.rules.nonwikiblocks.concat(
358 [
359     { rex:/\[\(([a-zA-Z0-9\.-]+)\)\$([^$]*)\$\]/g, tmplt:function($0,$1,$2){return ":p]<div class=\"eq\"><a name=\"eq"+$1+"\">("+$1+")</a>" + Wiky.math.toHtml($2) + "</div>[p:";} }, // numbered equation
360     { rex:/\[\$([^$]*)\$\]/g, tmplt:function($0,$1){return ":p]<div class=\"eq\">" + Wiky.math.toHtml($1) + "</div>[p:";} }, // equation
361 ]);
362 Wiky.rules.nonwikiinlines = Wiky.rules.nonwikiinlines.concat(
363     { rex:/\$([^$]*)\$/g, tmplt:function($0,$1){return "<dfn>" + Wiky.math.toHtml($1) + "</dfn>";} } // inline equation
364 );
365
366 Wiky.inverse.pre = Wiky.inverse.pre.concat({ rex:/([\$])/g, tmplt:"\\$1" });
367 Wiky.inverse.nonwikiblocks = Wiky.inverse.nonwikiblocks.concat(
368 [
369     { rex:/<div class=\"eq\"><a name=\"eq([0-9]+)\">(?:.*?)<\/a>(.*?)<\/div>/g, tmplt:function($0,$1,$2){return Wiky.store("[("+$1+")$"+Wiky.math.toWiki($2)+"$]");} }, // numbered equation
370     { rex:/<div class=\"eq\">(.*?)<\/div>/g, tmplt:function($0,$1){return Wiky.store("[$"+Wiky.math.toWiki($1)+"$]");} }, // equation
371 ]);
372 Wiky.inverse.nonwikiinlines = Wiky.inverse.nonwikiinlines.concat(
373     { rex:/<dfn>(.*?)<\/dfn>/g, tmplt:function($0,$1){return Wiky.store("$"+Wiky.math.toWiki($1)+"$");} } // inline equation
374 );