真尴尬!我找不到 \newcommand 的基本定义,尽管它被使用了无数次。
我怀疑它需要改进。
答案1
第 838 行latex.ltx
是定义的开始。
\def\@star@or@long#1{%
\@ifstar
{\let\l@ngrel@x\relax#1}%
{\let\l@ngrel@x\long#1}}
\let\l@ngrel@x\relax
\def\newcommand{\@star@or@long\new@command}
\def\new@command#1{%
\@testopt{\@newcommand#1}0}
\def\@newcommand#1[#2]{%
\kernel@ifnextchar [{\@xargdef#1[#2]}%
{\@argdef#1[#2]}}
\long\def\@argdef#1[#2]#3{%
\@ifdefinable #1{\@yargdef#1\@ne{#2}{#3}}}
\long\def\@xargdef#1[#2][#3]#4{%
\@ifdefinable#1{%
\expandafter\def\expandafter#1\expandafter{%
\expandafter
\@protected@testopt
\expandafter
#1%
\csname\string#1\endcsname
{#3}}%
\expandafter\@yargdef
\csname\string#1\endcsname
\tw@
{#2}%
{#4}}}
\long\def\@testopt#1#2{%
\kernel@ifnextchar[{#1}{#1[{#2}]}}
\def\@protected@testopt#1{%
\ifx\protect\@typeset@protect
\expandafter\@testopt
\else
\@x@protect#1%
\fi}
\long \def \@yargdef #1#2#3{%
\ifx#2\tw@
\def\reserved@b##11{[####1]}%
\else
\let\reserved@b\@gobble
\fi
\expandafter
\@yargd@f \expandafter{\number #3}#1%
}
\long \def \@yargd@f#1#2{%
\def \reserved@a ##1#1##2##{%
\expandafter\def\expandafter#2\reserved@b ##1#1%
}%
\l@ngrel@x \reserved@a 0##1##2##3##4##5##6##7##8##9###1%
}
\long\def\@reargdef#1[#2]{%
\@yargdef#1\@ne{#2}}