newcommand
The newcommand extension provides the \def, \newcommand,
\renewcommand, \let, \newenvironment, and
\renewenvironment macros for creating new macros and environments
in TeX. For example,
\(
\def\RR{{\bf R}}
\def\bold#1{{\bf #1}}
\)
defines a macro \RR that produces a bold “R”, while
\bold{math} typesets its argument using a bold font. See
Defining TeX macros for more information, and for mechanisms for
pre-defining macros at startup.
This extension is already loaded in all the components that include
the TeX input jax, other than input/tex-base. To load the
newcommand extension explicitly (when using input/tex-base for
example), add '[tex]/newcommand' to the load array of the
loader block of your MathJax configuration, and add
'newcommand' to the packages array of the tex
block.
window.MathJax = {
loader: {load: ['[tex]/newcommand']},
tex: {packages: {'[+]': ['newcommand']}}
};
Alternatively, use \require{newcommand} in a TeX expression to
load it dynamically from within the math on the page, if the
require extension is loaded.
Since the newcommand extension is included in the combined components that contain the TeX input jax, it may already be in the package list. In that case, if you want to disable it, you can remove it:
window.MathJax = {
tex: {packages: {'[-]': ['newcommand']}}
};
newcommand Options
When the newcommand extension is added to the packages array
for the tex block of your MathJax configuration (as it is in
all the combined components), two new options are made available in
the tex block:
MathJax = {
tex: {
maxMacros: 10000, // maximum number of macro substitutions per expression
protectedMacros: ['begingroupSandbox'], // macros that can't be redefined
}
};
- maxMacros: 10000
Because a definition of the form
\def\x{\x} \xwould cause MathJax to loop infinitely, themaxMacrosconstant will limit the number of macro substitutions allowed in any expression processed by MathJax.
- protectedMacros: ['begingroupSandbox']
This array lists the macro names that can’t be redefined by
\let,\def,\newcommand, or other commands the define TeX control sequences. For example, in a question-and-answer website where users can enter mathemtical expressions, this protects the listed macro from being overwritten by a user, possibly interfering with another user. See the begingroup for more on isolating users from one another.
newcommand Commands
The newcommand extension implements the following macros:
\def, \let, \newcommand, \newenvironment, \renewcommand, \renewenvironment