我首先定义一个命令来存储字符串"Hello":
\newcommand{\textstring}{Hello}
Run Code Online (Sandbox Code Playgroud)
我想追加字符串"world"但不幸的是这段代码会导致错误:
\renewcommand{\textstring}{\textstring world}
Run Code Online (Sandbox Code Playgroud)
Dav*_*ill 12
你可以通过使用来实现这一点\expandafter
.例如:
% redefine \textstring by appending " world" to it
\expandafter\def\expandafter\textstring\expandafter{\textstring { }world}
Run Code Online (Sandbox Code Playgroud)
如果你不使用\expandafter
那么你最终会出现递归问题.你可以在这里阅读更多相关信息.