Forgot password?
 Create new account
View 1316|Reply 0

\@for 的试验,批量生成数列命令

[Copy link]

700

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

kuing Posted at 2015-1-16 02:30:26 |Read mode
最近没事学了一些的底层命令,挺有意思的。

刚才试了一下 latex 中的 \@for 命令,以及练习一下 \expandafter, \csname 等命令的用法。

这里我想是通过列表来批量构造数列命令(置顶贴最近新增的 \an, \bn 等)。

\newcommand\slcmds{a,b,c,x,y,z,A,B,C,S,T}
\newcommand\getslcmd[1]{%
\expandafter\newcommand\csname #1n\endcsname{\ensuremath{\{#1_n\}}}}
\makeatletter
\@for\x:=\slcmds\do{\expandafter\getslcmd\expandafter{\x}}
\makeatother

然后正文直接用 \an, \bn 等就可以了,美元可以不加,因为用了 \ensuremath ,会自动加的。

测试文档: $type forshulie.tex (441 Bytes, Downloads: 704)

手机版Mobile version|Leisure Math Forum

2025-4-21 01:15 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list