Forgot password?
 Create new account
View 150|Reply 9

能不能让反斜线后的内容自动成为operatorname?

[Copy link]

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

abababa Posted at 2024-5-3 19:51:05 |Read mode
如题,比如我之前定义了很多像Im,tr,diag,rank等等,都是用\DeclareMathOperator{\xxx}{xxx}这样定义的,如果后面还遇到这种,就还要再定义。我想能不能加个前缀,比如x,然后我输入\xtr{A},就显示tr(A)这样的,输入\xdiag{\lambda_1,\cdots,\lambda_n},就显示diag(\lambda_1,\cdots,\lambda_n)这样的,不管x后面是什么,都是变成它的MathOperator形式,这个能用latex弄吗?

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-5-3 19:53:14
那以 x 开头的命令咋办,比如 \xrightarrow

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2024-5-4 02:28:56
tex.stackexchange.com/questions/437359/replac … quence-automatically

\$\Var\$, \$\PDFAg\$, \$\Egreg\$, \$\Mond\$, \$\Moon\$, \$\Sun\$
bxdYb[1].png

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2024-5-4 19:21:06
kuing 发表于 2024-5-3 19:53
那以 x 开头的命令咋办,比如 \xrightarrow
以x开头的已经存在的就不动了,不存在的变成这种自动的。

Comment

那我就不会啦  Posted at 2024-5-4 22:19

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2024-5-4 19:22:11
hbghlyj 发表于 2024-5-4 02:28
https://tex.stackexchange.com/questions/437359/replace-undefined-control-sequence-automatically

\$\ ...
看了这个,也是通过循环一个个来定义的,要在那个数组里明确写出来都需要哪些,不写的就还是不行,和我想要的效果还是差一些。

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2024-5-18 06:32:28

\?后的内容(直到空格)放入operatorname

Can I define a macro that accepts everything until the next space?
  1. \documentclass{article}
  2. \usepackage{amsmath}
  3. \def\?#1 {\operatorname{#1}}
  4. \begin{document}
  5. $\?arcsinh (\alpha)$
  6. $\?arcsech (\alpha)$
  7. \end{document}
Copy the Code

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-5-18 15:02:10
hbghlyj 发表于 2024-5-18 06:32
Can I define a macro that accepts everything until the next space?
这都行😅

不过估计实际使用时会很容易漏掉空格导致出错……

701

Threads

110K

Posts

910K

Credits

Credits
94172
QQ

Show all posts

kuing Posted at 2024-5-18 15:02:48
咦,我忽然发现这帖的 tid=12345 😃

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2024-5-18 20:20:45
hbghlyj 发表于 2024-5-18 06:32
Can I define a macro that accepts everything until the next space?
是用了问号和后面的东西不能连在一起吧,然后就把后面的识别成参数了。

手机版Mobile version|Leisure Math Forum

2025-4-20 22:18 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list