/* * /MathJax/extensions/TeX/newcommand.js * * Copyright (c) 2009-2018 The MathJax Consortium * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ MathJax.Extension["TeX/newcommand"]={version:"2.7.5"};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var b=MathJax.InputJax.TeX;var a=b.Definitions;a.Add({macros:{newcommand:"NewCommand",renewcommand:"NewCommand",newenvironment:"NewEnvironment",renewenvironment:"NewEnvironment",def:"MacroDef",let:"Let"}},null,true);b.Parse.Augment({NewCommand:function(c){var e=this.trimSpaces(this.GetArgument(c)),g=this.GetBrackets(c),d=this.GetBrackets(c),f=this.GetArgument(c);if(e.charAt(0)==="\\"){e=e.substr(1)}if(!e.match(/^(.|[a-z]+)$/i)){b.Error(["IllegalControlSequenceName","Illegal control sequence name for %1",c])}if(g){g=this.trimSpaces(g);if(!g.match(/^[0-9]+$/)){b.Error(["IllegalParamNumber","Illegal number of parameters specified in %1",c])}}this.setDef(e,["Macro",f,g,d])},NewEnvironment:function(d){var f=this.trimSpaces(this.GetArgument(d)),h=this.GetBrackets(d),e=this.GetBrackets(d),g=this.GetArgument(d),c=this.GetArgument(d);if(h){h=this.trimSpaces(h);if(!h.match(/^[0-9]+$/)){b.Error(["IllegalParamNumber","Illegal number of parameters specified in %1",d])}}this.setEnv(f,["BeginEnv",[null,"EndEnv"],g,c,h,e])},MacroDef:function(c){var d=this.GetCSname(c),f=this.GetTemplate(c,"\\"+d),e=this.GetArgument(c);if(!(f instanceof Array)){this.setDef(d,["Macro",e,f])}else{this.setDef(d,["MacroWithTemplate",e].concat(f))}},Let:function(d){var e=this.GetCSname(d),f;var g=this.GetNext();if(g==="="){this.i++;g=this.GetNext()}if(g==="\\"){d=this.GetCSname(d);f=this.csFindMacro(d);if(!f){if(a.mathchar0mi.hasOwnProperty(d)){f=["csMathchar0mi",a.mathchar0mi[d]]}else{if(a.mathchar0mo.hasOwnProperty(d)){f=["csMathchar0mo",a.mathchar0mo[d]]}else{if(a.mathchar7.hasOwnProperty(d)){f=["csMathchar7",a.mathchar7[d]]}else{if(a.delimiter.hasOwnProperty("\\"+d)){f=["csDelimiter",a.delimiter["\\"+d]]}else{return}}}}}}else{f=["Macro",g];this.i++}this.setDef(e,f)},GetCSname:function(e){var f=this.GetNext();if(f!=="\\"){b.Error(["MissingCS","%1 must be followed by a control sequence",e])}var d=this.trimSpaces(this.GetArgument(e));return d.substr(1)},GetTemplate:function(f,e){var j,g=[],h=0;j=this.GetNext();var d=this.i;while(this.i0){return[h,g]}else{return h}}}this.i++}b.Error(["MissingReplacementString","Missing replacement string for definition of %1",f])},MacroWithTemplate:function(d,g,h,f){if(h){var c=[];this.GetNext();if(f[0]&&!this.MatchParam(f[0])){b.Error(["MismatchUseDef","Use of %1 doesn't match its definition",d])}for(var e=0;eb.config.MAXMACROS){b.Error(["MaxMacroSub1","MathJax maximum macro substitution count exceeded; is there a recursive macro call?"])}},BeginEnv:function(g,k,c,j,h){if(j){var e=[];if(h!=null){var d=this.GetBrackets("\\begin{"+name+"}");e.push(d==null?h:d)}for(var f=e.length;f