/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */ /* vim: set ts=2 et sw=2 tw=80: */ /************************************************************* * * MathJax/extensions/TeX/newcommand.js * * Implements the \newcommand, \newenvironment and \def * macros, and is loaded automatically when needed. * * --------------------------------------------------------------------- * * Copyright (c) 2009-2013 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.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