我决定测试我对扩展和嵌入\g@addto@macro
另外三个宏的理解。
\g@addto@macro
\appendmacro
\layertwo
\activatelayerone
据我理解,下面示例的日志输出应该是:
==> item1item2\item \undefinedmacroA item5\undefinedmacroB
但事实上是这样的:
==> item1item2\item \undefinedmacroA \undefinedmacroB
例子
\documentclass{article}
\def\macrolist{}
\makeatletter
\def\appendmacro#1{%
\g@addto@macro\macrolist{#1}
}%
\makeatother
\def\activatelayerone#1{%
\def\layertwo##1{%
\appendmacro{##1}
}%
}%
\begin{document}
\null
\appendmacro{item1}
\appendmacro{item2}
\appendmacro{\unexpanded{\item}} % Demonstrate that \unexpanded must be called by the sender
\appendmacro{\unexpanded{\undefinedmacroA}}
\activatelayerone
\layertwo{item5}
\layertwo{\unexpanded{\undefinedmacroB}}
\typeout{ ==> \macrolist}
\end{document}
答案1
\def\activatelayerone#1{%
\def\layertwo##1{%
\appendmacro{##1}
}%
}%
除了定义\layertwo
为附加并由于缺少而添加虚假空格之外%
,这还起到\@gobble
丢弃下一个#1
未使用的标记的作用。此处下一个标记是,\layertwo
因此被丢弃并{item5}
在该点进行排版。