Forgot password
 Register account
View 255|Reply 9

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

[Copy link]

414

Threads

1641

Posts

15

Reputation

Show all posts

abababa posted 2024-5-3 19:51 |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弄吗?

673

Threads

110K

Posts

218

Reputation

Show all posts

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

3211

Threads

7832

Posts

52

Reputation

Show all posts

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

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

414

Threads

1641

Posts

15

Reputation

Show all posts

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

Comment

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

414

Threads

1641

Posts

15

Reputation

Show all posts

original poster abababa posted 2024-5-4 19:22
hbghlyj 发表于 2024-5-4 02:28
https://tex.stackexchange.com/questions/437359/replace-undefined-control-sequence-automatically

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

3211

Threads

7832

Posts

52

Reputation

Show all posts

hbghlyj posted 2024-5-18 06:32

\?后的内容(直到空格)放入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

673

Threads

110K

Posts

218

Reputation

Show all posts

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

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

673

Threads

110K

Posts

218

Reputation

Show all posts

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

414

Threads

1641

Posts

15

Reputation

Show all posts

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

Quick Reply

Advanced Mode
B Color Image Link Quote Code Smilies
You have to log in before you can reply Login | Register account

$\LaTeX$ formula tutorial

Mobile version

2025-7-20 05:54 GMT+8

Powered by Discuz!

Processed in 0.013960 seconds, 26 queries