是否可以要求 Latex 评估命令

发布于 2024-09-07 18:20:20 字数 360 浏览 2 评论 0原文

这段代码:

\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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新人笑 2024-09-14 18:20:20

使用 \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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文