/* * /MathJax/jax/input/MathML/jax.js * * Copyright (c) 2009-2013 The MathJax Consortium * * Part of the MathJax library. * See http://www.mathjax.org for details. * * Licensed under the Apache License, Version 2.0; * you may not use this file except in compliance with the License. * * http://www.apache.org/licenses/LICENSE-2.0 */(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]* 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(/^(])+)>)/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(/^]* xmlns=/)&&(a=a.replace(/^<(math)/i,'\x3cmath xmlns\x3d"http://www.w3.org/1998/Math/MathML"'));a=a.replace(/^\s*(?:\/\/)?\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(/( )+$/,"")),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