是否可以要求 Latex 评估命令
这段代码:
\begin{枚举}
\item 项目一 \def\commandOne{\alph{enumi} : One}
\item 项目二 \def\commandTwo{\alph{enumi} : 两个}
\item \commandOne、\commandTwo
\end{枚举}
给出以下输出:
项目一
第二项
c:一,c:二
我希望 Latex 在定义命令时而不是在调用命令时评估 \alph{enumi} ,这可能吗?
This code:
\begin{enumerate}
\item Item One \def\commandOne{\alph{enumi} : One}
\item Item Two \def\commandTwo{\alph{enumi} : Two}
\item \commandOne, \commandTwo
\end{enumerate}
Gives this output:
Item One
Item Two
c : One, c : Two
I want that Latex evaluate \alph{enumi} when the command is defined instead of when the command is called, is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
\edef
代替\def
,其中 在定义时扩展(另请参见\gdef
和\xdef
)。如果您不希望其中的某些部分扩展,这当然会导致问题。对于这些情况,您可以使用\expandafter
如 此答案。Instead of
\def
, use\edef
which expands at the time of definition (see also\gdef
and\xdef
). This can of course cause problems if you want parts of it not expanded. For those cases you can use\expandafter
as shown in this answer.