/* * /MathJax/extensions/TeX/newcommand.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 */MathJax.Extension["TeX/newcommand"]={version:"2.2"};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var f=MathJax.InputJax.TeX,g=f.Definitions;g.Add({macros:{newcommand:"NewCommand",renewcommand:"NewCommand",newenvironment:"NewEnvironment",renewenvironment:"NewEnvironment",def:"MacroDef",let:"Let"}},null,!0);f.Parse.Augment({NewCommand:function(a){var c=this.trimSpaces(this.GetArgument(a)),b=this.GetBrackets(a),d=this.GetBrackets(a),e=this.GetArgument(a);"\\"===c.charAt(0)&&(c=c.substr(1));c.match(/^(.|[a-z]+)$/i)||f.Error(["IllegalControlSequenceName","Illegal control sequence name for %1",a]);b&&(b=this.trimSpaces(b),b.match(/^[0-9]+$/)||f.Error(["IllegalParamNumber","Illegal number of parameters specified in %1",a]));this.setDef(c,["Macro",e,b,d])},NewEnvironment:function(a){var c=this.trimSpaces(this.GetArgument(a)),b=this.GetBrackets(a),d=this.GetArgument(a),e=this.GetArgument(a);b&&(b=this.trimSpaces(b),b.match(/^[0-9]+$/)||f.Error(["IllegalParamNumber","Illegal number of parameters specified in %1",a]));this.setEnv(c,["BeginEnv","EndEnv",d,e,b])},MacroDef:function(a){var c=this.GetCSname(a),b=this.GetTemplate(a,"\\"+c);a=this.GetArgument(a);b instanceof Array?this.setDef(c,["MacroWithTemplate",a].concat(b)):this.setDef(c,["Macro",a,b])},Let:function(a){var c=this.GetCSname(a),b;b=this.GetNext();"\x3d"===b&&(this.i++,b=this.GetNext());"\\"===b?(a=this.GetCSname(a),(b=this.csFindMacro(a))||(g.mathchar0mi[a]?b=["csMathchar0mi",g.mathchar0mi[a]]:g.mathchar0mo[a]?b=["csMathchar0mo",g.mathchar0mo[a]]:g.mathchar7[a]?b=["csMathchar7",g.mathchar7[a]]:null!=g.delimiter["\\"+a]&&(b=["csDelimiter",g.delimiter["\\"+a]]))):(b=["Macro",b],this.i++);this.setDef(c,b)},setDef:function(a,c){c.isUser=!0;g.macros[a]=c},setEnv:function(a,c){c.isUser=!0;g.environment[a]=c},GetCSname:function(a){"\\"!==this.GetNext()&&f.Error(["DoubleBackSlash","\\ must be followed by a control sequence"]);return this.trimSpaces(this.GetArgument(a)).substr(1)},GetTemplate:function(a,c){var b,d=[],e=0;this.GetNext();for(var h=this.i;this.if.config.MAXMACROS&&f.Error(["MaxMacroSub1","MathJax maximum macro substitution count exceeded; is there a recursive macro call?"])},BeginEnv:function(a,c,b,d){if(d){for(var e=[],f=0;f