如果重新定义不使用参数,则环境内部命令的重新定义可以正常工作,但如果在新定义中使用了参数,则重新定义会失败。
错误信息是:
\inversion 定义中的参数数量非法。
(倒置是所涉及的环境,仅被定义,尚未使用)
以下是两个例子
%% FIRST
\documentclass{minimal}
%
% a command with two arguments,
% the two argument are printed in natural order
\newcommand{\printtwoarg}[2]{TwoArg: #1 #2}
% the new command is redefined INSIDE a new environment, WITHOUT using the arguments
\newenvironment{noprint}{\renewcommand{\printtwoarg}[2]{TwoArg: \relax}}{\relax}
%% the new command is redefined INSIDE a new environment: the arguments are printed in inverted order
%%\newenvironment{inversion}{\renewcommand{\printtwoarg}[2]{TwoArg: #2 #1}}{\relax}
%
\begin{document}
Using the new command:\\
\printtwoarg{TheFirst}{TheSecond} \\
%
\begin{noprint}
Using the new command INSIDE the new environment:\\
\printtwoarg{TheFirst}{TheSecond} \\
\end{noprint}
%
... and OUTSIDE again:\\
\printtwoarg{TheFirst}{TheSecond} \\
%
\end{document}
进而
%% SECOND
\documentclass{minimal}
%
% a command with two arguments,
% the two argument are printed in natural order
\newcommand{\printtwoarg}[2]{TwoArg: #1 #2}
% the new command is redefined INSIDE a new environment, WITHOUT using the arguments
\newenvironment{noprint}{\renewcommand{\printtwoarg}[2]{TwoArg: \relax}}{\relax}
% the new command is redefined INSIDE a new environment: the arguments are printed in inverted order
\newenvironment{inversion}{\renewcommand{\printtwoarg}[2]{TwoArg: #2 #1}}{\relax}
%
\begin{document}
Using the new command:\\
\printtwoarg{TheFirst}{TheSecond} \\
%
\begin{noprint}
Using the new command INSIDE the new environment:\\
\printtwoarg{TheFirst}{TheSecond} \\
\end{noprint}
%
... and OUTSIDE again:\\
\printtwoarg{TheFirst}{TheSecond} \\
%
\end{document}
第一个例子运行良好,第二个例子失败。区别在于定义环境反转的未注释行。
我真的不知道这是一个难题还是一个小问题!!
谨致问候并提前致谢
巴蒂斯塔·本乔利尼