jax.js 15 KB

12345678910111213
  1. /*
  2. * /MathJax/jax/input/MathML/jax.js
  3. *
  4. * Copyright (c) 2009-2013 The MathJax Consortium
  5. *
  6. * Part of the MathJax library.
  7. * See http://www.mathjax.org for details.
  8. *
  9. * Licensed under the Apache License, Version 2.0;
  10. * you may not use this file except in compliance with the License.
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. */(function(d,k){var g,h=function(a){return MathJax.Localization._.apply(MathJax.Localization,[["MathML",a]].concat([].slice.call(arguments,1)))};d.Parse=MathJax.Object.Subclass({Init:function(a){this.Parse(a)},Parse:function(a){"string"!==typeof a?a=a.parentNode:(a=d.ParseXML(this.preProcessMath.call(this,a)),null==a&&d.Error(["ErrorParsingMathML","Error parsing MathML"]));var c=a.getElementsByTagName("parsererror")[0];c&&d.Error(["ParsingError","Error parsing MathML: %1",c.textContent.replace(/This page.*?errors:|XML Parsing Error: |Below is a rendering of the page.*/g,"")]);1!==a.childNodes.length&&d.Error(["MathMLSingleElement","MathML must be formed by a single element"]);"html"===a.firstChild.nodeName.toLowerCase()&&(c=a.getElementsByTagName("h1")[0])&&"XML parsing error"===c.textContent&&c.nextSibling&&d.Error(["ParsingError","Error parsing MathML: %1",String(c.nextSibling.nodeValue).replace(/fatal parsing error: /,"")]);"math"!==a.firstChild.nodeName.toLowerCase().replace(/^[a-z]+:/,"")&&d.Error(["MathMLRootElement","MathML must be formed by a \x3cmath\x3e element, not %1","\x3c"+a.firstChild.nodeName+"\x3e"]);this.mml=this.MakeMML(a.firstChild)},MakeMML:function(a){var c=String(a.getAttribute("class")||""),b;b=a.nodeName.toLowerCase().replace(/^[a-z]+:/,"");if(c=c.match(/(^| )MJX-TeXAtom-([^ ]*)/))b=this.TeXAtom(c[2]);else if(g[b]&&g[b].isa&&g[b].isa(g.mbase))b=g[b]();else return MathJax.Hub.signal.Post(["MathML Jax - unknown node type",b]),g.merror(h("UnknownNodeType","Unknown node type: %1",b));this.AddAttributes(b,a);this.CheckClass(b,b["class"]);this.AddChildren(b,a);d.config.useMathMLspacing&&(b.useMMLspacing=8);return b},TeXAtom:function(a){a=g.TeXAtom().With({texClass:g.TEXCLASS[a]});a.texClass===g.TEXCLASS.OP&&(a.movesupsub=a.movablelimits=!0);return a},CheckClass:function(a,c){c=(c||"").split(/ /);for(var b=[],f=0,e=c.length;f<e;f++)"MJX-"===c[f].substr(0,4)?"MJX-arrow"===c[f]?a.arrow=!0:"MJX-variant"===c[f]?(a.variantForm=!0,MathJax.Extension["TeX/AMSsymbols"]||MathJax.Hub.RestartAfter(MathJax.Ajax.Require("[MathJax]/extensions/TeX/AMSsymbols.js"))):"MJX-TeXAtom"!==c[f].substr(0,11)&&(a.mathvariant=c[f].substr(3),"-tex-caligraphic-bold"===a.mathvariant||"-tex-oldstyle-bold"===a.mathvariant)&&(MathJax.Extension["TeX/boldsymbol"]||MathJax.Hub.RestartAfter(MathJax.Ajax.Require("[MathJax]/extensions/TeX/boldsymbol.js"))):b.push(c[f]);b.length?a["class"]=b.join(" "):delete a["class"]},AddAttributes:function(a,c){a.attr={};a.attrNames=[];for(var b=0,f=c.attributes.length;b<f;b++){var e=c.attributes[b].name;"xlink:href"==e&&(e="href");if(!e.match(/:/)&&!e.match(/^_moz-math-((column|row)(align|line)|font-style)$/)){var d=c.attributes[b].value,d=this.filterAttribute(e,d);null!=d&&("true"===d.toLowerCase()?d=!0:"false"===d.toLowerCase()&&(d=!1),null!=a.defaults[e]||g.copyAttributes[e]?a[e]=d:a.attr[e]=d,a.attrNames.push(e))}}},filterAttribute:function(a,c){return c},AddChildren:function(a,c){for(var b=0,f=c.childNodes.length;b<f;b++){var e=c.childNodes[b];"#comment"!==e.nodeName&&("#text"===e.nodeName?a.isToken&&!a.mmlSelfClosing?(e=e.nodeValue.replace(/&([a-z][a-z0-9]*);/ig,this.replaceEntity),a.Append(g.chars(this.trimSpace(e)))):e.nodeValue.match(/\S/)&&d.Error(["UnexpectedTextNode","Unexpected text node: %1","'"+e.nodeValue+"'"]):"annotation-xml"===a.type?a.Append(g.xml(e)):(e=this.MakeMML(e),a.Append(e),e.mmlSelfClosing&&e.data.length&&(a.Append.apply(a,e.data),e.data=[])))}"mrow"===a.type&&2<=a.data.length&&(b=a.data[0],f=a.data[a.data.length-1],"mo"===b.type&&b.Get("fence")&&"mo"===f.type&&f.Get("fence")&&(b.data[0]&&(a.open=b.data.join("")),f.data[0]&&(a.close=f.data.join(""))))},preProcessMath:function(a){a.match(/^<[a-z]+:/i)&&!a.match(/^<[^<>]* xmlns:/)&&(a=a.replace(/^<([a-z]+)(:math)/i,'\x3c$1$2 xmlns:$1\x3d"http://www.w3.org/1998/Math/MathML"'));var c=a.match(/^(<math( ('.*?'|".*?"|[^>])+)>)/i);c&&c[2].match(/ (?!xmlns=)[a-z]+=\"http:/i)&&(a=c[1].replace(/ (?!xmlns=)([a-z]+=(['"])http:.*?\2)/ig," xmlns:$1 $1")+a.substr(c[0].length));a.match(/^<math/i)&&!a.match(/^<[^<>]* xmlns=/)&&(a=a.replace(/^<(math)/i,'\x3cmath xmlns\x3d"http://www.w3.org/1998/Math/MathML"'));a=a.replace(/^\s*(?:\/\/)?<!(--)?\[CDATA\[((.|\n)*)(\/\/)?\]\]\1>\s*$/,"$2");return a.replace(/&([a-z][a-z0-9]*);/ig,this.replaceEntity)},trimSpace:function(a){return a.replace(/[\t\n\r]/g," ").replace(/^ +/,"").replace(/ +$/,"").replace(/ +/g," ")},replaceEntity:function(a,c){if(c.match(/^(lt|amp|quot)$/))return a;if(d.Parse.Entity[c])return d.Parse.Entity[c];var b=c.charAt(0).toLowerCase(),f=c.match(/^[a-zA-Z](fr|scr|opf)$/);f&&(b=f[1]);d.Parse.loaded[b]||(d.Parse.loaded[b]=!0,MathJax.Hub.RestartAfter(MathJax.Ajax.Require(d.entityDir+"/"+b+".js")));return a}},{loaded:[]});d.Augment({sourceMenuTitle:["OriginalMathML","Original MathML"],prefilterHooks:MathJax.Callback.Hooks(!0),postfilterHooks:MathJax.Callback.Hooks(!0),Translate:function(a){this.ParseXML||(this.ParseXML=this.createParser());var c,b,f={script:a};a.firstChild&&"math"===a.firstChild.nodeName.toLowerCase().replace(/^[a-z]+:/,"")?f.math=a.firstChild:(b=MathJax.HTML.getScript(a),k.isMSIE&&(b=b.replace(/(&nbsp;)+$/,"")),f.math=b);this.prefilterHooks.Execute(f);b=f.math;try{c=d.Parse(b).mml}catch(e){if(!e.mathmlError)throw e;c=this.formatError(e,b,a)}f.math=g(c);this.postfilterHooks.Execute(f);return f.math},prefilterMath:function(a,c){return a},prefilterMathML:function(a,c){return a},formatError:function(a,c,b){a=a.message.replace(/\n.*/,"");MathJax.Hub.signal.Post(["MathML Jax - parse error",a,c,b]);return g.merror(a)},Error:function(a){a instanceof Array&&(a=h.apply(h,a));throw MathJax.Hub.Insert(Error(a),{mathmlError:!0});},parseDOM:function(a){return this.parser.parseFromString(a,"text/xml")},parseMS:function(a){return this.parser.loadXML(a)?this.parser:null},parseDIV:function(a){this.div.innerHTML=a.replace(/<([a-z]+)([^>]*)\/>/g,"\x3c$1$2\x3e\x3c/$1\x3e");return this.div},parseError:function(a){return null},createMSParser:function(){for(var a=null,c="MSXML2.DOMDocument.6.0 MSXML2.DOMDocument.5.0 MSXML2.DOMDocument.4.0 MSXML2.DOMDocument.3.0 MSXML2.DOMDocument.2.0 Microsoft.XMLDOM".split(" "),b=0,d=c.length;b<d&&!a;b++)try{a=new ActiveXObject(c[b])}catch(e){}return a},createParser:function(){if(window.DOMParser)return this.parser=new DOMParser,this.parseDOM;if(window.ActiveXObject){this.parser=this.createMSParser();if(!this.parser)return MathJax.Localization.Try(this.parserCreationError),this.parseError;this.parser.async=!1;return this.parseMS}this.div=MathJax.Hub.Insert(document.createElement("div"),{style:{visibility:"hidden",overflow:"hidden",height:"1px",position:"absolute",top:0}});document.body.firstChild?document.body.insertBefore(this.div,document.body.firstChild):document.body.appendChild(this.div);return this.parseDIV},parserCreationError:function(){alert(h("CantCreateXMLParser","MathJax can't create an XML parser for MathML. Check that\nthe 'Script ActiveX controls marked safe for scripting' security\nsetting is enabled (use the Internet Options item in the Tools\nmenu, and select the Security panel, then press the Custom Level\nbutton to check this).\n\nMathML equations will not be able to be processed by MathJax."))},Startup:function(){g=MathJax.ElementJax.mml;g.mspace.Augment({mmlSelfClosing:!0});g.none.Augment({mmlSelfClosing:!0});g.mprescripts.Augment({mmlSelfClosing:!0})}});d.prefilterHooks.Add(function(a){a.math="string"===typeof a.math?d.prefilterMath(a.math,a.script):d.prefilterMathML(a.math,a.script)});d.Parse.Entity={ApplyFunction:"\u2061",Backslash:"\u2216",Because:"\u2235",Breve:"\u02d8",Cap:"\u22d2",CenterDot:"\u00b7",CircleDot:"\u2299",CircleMinus:"\u2296",CirclePlus:"\u2295",CircleTimes:"\u2297",Congruent:"\u2261",ContourIntegral:"\u222e",Coproduct:"\u2210",Cross:"\u2a2f",Cup:"\u22d3",CupCap:"\u224d",Dagger:"\u2021",Del:"\u2207",Delta:"\u0394",Diamond:"\u22c4",DifferentialD:"\u2146",DotEqual:"\u2250",DoubleDot:"\u00a8",DoubleRightTee:"\u22a8",DoubleVerticalBar:"\u2225",DownArrow:"\u2193",DownLeftVector:"\u21bd",DownRightVector:"\u21c1",DownTee:"\u22a4",Downarrow:"\u21d3",Element:"\u2208",EqualTilde:"\u2242",Equilibrium:"\u21cc",Exists:"\u2203",ExponentialE:"\u2147",FilledVerySmallSquare:"\u25aa",ForAll:"\u2200",Gamma:"\u0393",Gg:"\u22d9",GreaterEqual:"\u2265",GreaterEqualLess:"\u22db",GreaterFullEqual:"\u2267",GreaterLess:"\u2277",GreaterSlantEqual:"\u2a7e",GreaterTilde:"\u2273",Hacek:"\u02c7",Hat:"^",HumpDownHump:"\u224e",HumpEqual:"\u224f",Im:"\u2111",ImaginaryI:"\u2148",Integral:"\u222b",Intersection:"\u22c2",InvisibleComma:"\u2063",InvisibleTimes:"\u2062",Lambda:"\u039b",Larr:"\u219e",LeftAngleBracket:"\u27e8",LeftArrow:"\u2190",LeftArrowRightArrow:"\u21c6",LeftCeiling:"\u2308",LeftDownVector:"\u21c3",LeftFloor:"\u230a",LeftRightArrow:"\u2194",LeftTee:"\u22a3",LeftTriangle:"\u22b2",LeftTriangleEqual:"\u22b4",LeftUpVector:"\u21bf",LeftVector:"\u21bc",Leftarrow:"\u21d0",Leftrightarrow:"\u21d4",LessEqualGreater:"\u22da",LessFullEqual:"\u2266",LessGreater:"\u2276",LessSlantEqual:"\u2a7d",LessTilde:"\u2272",Ll:"\u22d8",Lleftarrow:"\u21da",LongLeftArrow:"\u27f5",LongLeftRightArrow:"\u27f7",LongRightArrow:"\u27f6",Longleftarrow:"\u27f8",Longleftrightarrow:"\u27fa",Longrightarrow:"\u27f9",Lsh:"\u21b0",MinusPlus:"\u2213",NestedGreaterGreater:"\u226b",NestedLessLess:"\u226a",NotDoubleVerticalBar:"\u2226",NotElement:"\u2209",NotEqual:"\u2260",NotExists:"\u2204",NotGreater:"\u226f",NotGreaterEqual:"\u2271",NotLeftTriangle:"\u22ea",NotLeftTriangleEqual:"\u22ec",NotLess:"\u226e",NotLessEqual:"\u2270",NotPrecedes:"\u2280",NotPrecedesSlantEqual:"\u22e0",NotRightTriangle:"\u22eb",NotRightTriangleEqual:"\u22ed",NotSubsetEqual:"\u2288",NotSucceeds:"\u2281",NotSucceedsSlantEqual:"\u22e1",NotSupersetEqual:"\u2289",NotTilde:"\u2241",NotVerticalBar:"\u2224",Omega:"\u03a9",OverBar:"\u203e",OverBrace:"\u23de",PartialD:"\u2202",Phi:"\u03a6",Pi:"\u03a0",PlusMinus:"\u00b1",Precedes:"\u227a",PrecedesEqual:"\u2aaf",PrecedesSlantEqual:"\u227c",PrecedesTilde:"\u227e",Product:"\u220f",Proportional:"\u221d",Psi:"\u03a8",Rarr:"\u21a0",Re:"\u211c",ReverseEquilibrium:"\u21cb",RightAngleBracket:"\u27e9",RightArrow:"\u2192",RightArrowLeftArrow:"\u21c4",RightCeiling:"\u2309",RightDownVector:"\u21c2",RightFloor:"\u230b",RightTee:"\u22a2",RightTeeArrow:"\u21a6",RightTriangle:"\u22b3",RightTriangleEqual:"\u22b5",RightUpVector:"\u21be",RightVector:"\u21c0",Rightarrow:"\u21d2",Rrightarrow:"\u21db",Rsh:"\u21b1",Sigma:"\u03a3",SmallCircle:"\u2218",Sqrt:"\u221a",Square:"\u25a1",SquareIntersection:"\u2293",SquareSubset:"\u228f",SquareSubsetEqual:"\u2291",SquareSuperset:"\u2290",SquareSupersetEqual:"\u2292",SquareUnion:"\u2294",Star:"\u22c6",Subset:"\u22d0",SubsetEqual:"\u2286",Succeeds:"\u227b",SucceedsEqual:"\u2ab0",SucceedsSlantEqual:"\u227d",SucceedsTilde:"\u227f",SuchThat:"\u220b",Sum:"\u2211",Superset:"\u2283",SupersetEqual:"\u2287",Supset:"\u22d1",Therefore:"\u2234",Theta:"\u0398",Tilde:"\u223c",TildeEqual:"\u2243",TildeFullEqual:"\u2245",TildeTilde:"\u2248",UnderBar:"_",UnderBrace:"\u23df",Union:"\u22c3",UnionPlus:"\u228e",UpArrow:"\u2191",UpDownArrow:"\u2195",UpTee:"\u22a5",Uparrow:"\u21d1",Updownarrow:"\u21d5",Upsilon:"\u03a5",Vdash:"\u22a9",Vee:"\u22c1",VerticalBar:"\u2223",VerticalTilde:"\u2240",Vvdash:"\u22aa",Wedge:"\u22c0",Xi:"\u039e",acute:"\u00b4",aleph:"\u2135",alpha:"\u03b1",amalg:"\u2a3f",and:"\u2227",ang:"\u2220",angmsd:"\u2221",angsph:"\u2222",ape:"\u224a",backprime:"\u2035",backsim:"\u223d",backsimeq:"\u22cd",beta:"\u03b2",beth:"\u2136",between:"\u226c",bigcirc:"\u25ef",bigodot:"\u2a00",bigoplus:"\u2a01",bigotimes:"\u2a02",bigsqcup:"\u2a06",bigstar:"\u2605",bigtriangledown:"\u25bd",bigtriangleup:"\u25b3",biguplus:"\u2a04",blacklozenge:"\u29eb",blacktriangle:"\u25b4",blacktriangledown:"\u25be",blacktriangleleft:"\u25c2",bowtie:"\u22c8",boxdl:"\u2510",boxdr:"\u250c",boxminus:"\u229f",boxplus:"\u229e",boxtimes:"\u22a0",boxul:"\u2518",boxur:"\u2514",bsol:"\\",bull:"\u2022",cap:"\u2229",check:"\u2713",chi:"\u03c7",circ:"\u02c6",circeq:"\u2257",circlearrowleft:"\u21ba",circlearrowright:"\u21bb",circledR:"\u00ae",circledS:"\u24c8",circledast:"\u229b",circledcirc:"\u229a",circleddash:"\u229d",clubs:"\u2663",colon:":",comp:"\u2201",ctdot:"\u22ef",cuepr:"\u22de",cuesc:"\u22df",cularr:"\u21b6",cup:"\u222a",curarr:"\u21b7",curlyvee:"\u22ce",curlywedge:"\u22cf",dagger:"\u2020",daleth:"\u2138",ddarr:"\u21ca",deg:"\u00b0",delta:"\u03b4",digamma:"\u03dd",div:"\u00f7",divideontimes:"\u22c7",dot:"\u02d9",doteqdot:"\u2251",dotplus:"\u2214",dotsquare:"\u22a1",dtdot:"\u22f1",ecir:"\u2256",efDot:"\u2252",egs:"\u2a96",ell:"\u2113",els:"\u2a95",empty:"\u2205",epsi:"\u03b5",epsiv:"\u03f5",erDot:"\u2253",eta:"\u03b7",eth:"\u00f0",flat:"\u266d",fork:"\u22d4",frown:"\u2322",gEl:"\u2a8c",gamma:"\u03b3",gap:"\u2a86",gimel:"\u2137",gnE:"\u2269",gnap:"\u2a8a",gne:"\u2a88",gnsim:"\u22e7",gt:"\x3e",gtdot:"\u22d7",harrw:"\u21ad",hbar:"\u210f",hellip:"\u2026",hookleftarrow:"\u21a9",hookrightarrow:"\u21aa",imath:"\u0131",infin:"\u221e",intcal:"\u22ba",iota:"\u03b9",jmath:"\u0237",kappa:"\u03ba",kappav:"\u03f0",lEg:"\u2a8b",lambda:"\u03bb",lap:"\u2a85",larrlp:"\u21ab",larrtl:"\u21a2",lbrace:"{",lbrack:"[",le:"\u2264",leftleftarrows:"\u21c7",leftthreetimes:"\u22cb",lessdot:"\u22d6",lmoust:"\u23b0",lnE:"\u2268",lnap:"\u2a89",lne:"\u2a87",lnsim:"\u22e6",longmapsto:"\u27fc",looparrowright:"\u21ac",lowast:"\u2217",loz:"\u25ca",lt:"\x3c",ltimes:"\u22c9",ltri:"\u25c3",macr:"\u00af",malt:"\u2720",mho:"\u2127",mu:"\u03bc",multimap:"\u22b8",nLeftarrow:"\u21cd",nLeftrightarrow:"\u21ce",nRightarrow:"\u21cf",nVDash:"\u22af",nVdash:"\u22ae",natur:"\u266e",nearr:"\u2197",nharr:"\u21ae",nlarr:"\u219a",not:"\u00ac",nrarr:"\u219b",nu:"\u03bd",nvDash:"\u22ad",nvdash:"\u22ac",nwarr:"\u2196",omega:"\u03c9",omicron:"\u03bf",or:"\u2228",osol:"\u2298",period:".",phi:"\u03c6",phiv:"\u03d5",pi:"\u03c0",piv:"\u03d6",prap:"\u2ab7",precnapprox:"\u2ab9",precneqq:"\u2ab5",precnsim:"\u22e8",prime:"\u2032",psi:"\u03c8",rarrtl:"\u21a3",rbrace:"}",rbrack:"]",rho:"\u03c1",rhov:"\u03f1",rightrightarrows:"\u21c9",rightthreetimes:"\u22cc",ring:"\u02da",rmoust:"\u23b1",rtimes:"\u22ca",rtri:"\u25b9",scap:"\u2ab8",scnE:"\u2ab6",scnap:"\u2aba",scnsim:"\u22e9",sdot:"\u22c5",searr:"\u2198",sect:"\u00a7",sharp:"\u266f",sigma:"\u03c3",sigmav:"\u03c2",simne:"\u2246",smile:"\u2323",spades:"\u2660",sub:"\u2282",subE:"\u2ac5",subnE:"\u2acb",subne:"\u228a",supE:"\u2ac6",supnE:"\u2acc",supne:"\u228b",swarr:"\u2199",tau:"\u03c4",theta:"\u03b8",thetav:"\u03d1",tilde:"\u02dc",times:"\u00d7",triangle:"\u25b5",triangleq:"\u225c",upsi:"\u03c5",upuparrows:"\u21c8",veebar:"\u22bb",vellip:"\u22ee",weierp:"\u2118",xi:"\u03be",yen:"\u00a5",zeta:"\u03b6",zigrarr:"\u21dd"};d.loadComplete("jax.js")})(MathJax.InputJax.MathML,MathJax.Hub.Browser);