Forgot password
 Register account
View 945|Reply 2

定义数学符号时能不能加颜色?

[Copy link]

414

Threads

1641

Posts

15

Reputation

Show all posts

abababa posted 2021-3-25 21:32 |Read mode
Last edited by abababa 2021-3-26 09:23如题,比如我定义最小公倍数:
\DeclareMathOperator{\lcm}{lcm}%最小公倍数
我想在使用\lcm(3,6)=6时,把那个lcm()加上颜色,这个要怎么做?
然后还有我定义了虚数部分:
\newcommand{\myim}[1]{\textcolor{blue}{\operatorname{Im}\left({\normalcolor #1}\right)}}%虚数部分
这种定义方法和上面那个有什么不同吗?而这个要加颜色的话就能直接在定义里加了。

673

Threads

110K

Posts

218

Reputation

Show all posts

kuing posted 2021-3-25 22:37
你可以看成:
\DeclareMathOperator{\xxx}{yyy} = \DeclareRobustCommand{\xxx}{\operatorname{yyy}}

\DeclareRobustCommand 就是强壮版的 \newcommand
(脆弱命令在某些情况下有可能报错,比如在标题中使用,具体就不说了)

所以你可以像你定义虚数部分那样来定义 \lcm ,安全点就用 \DeclareRobustCommand
(或者你可以试试在标题中用一下你的 \myim 看会不会报错)

PS、你的 normalcolor 前面是不是多了个 \ ?

414

Threads

1641

Posts

15

Reputation

Show all posts

original poster abababa posted 2021-3-26 09:23
回复 2# kuing

原来如此,我的那个lcm用在section里,正文是没什么问题,但目录的那个标签页里变成乱码了。
是的,是多了个\,我改过来。

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-15 14:45 GMT+8

Powered by Discuz!

Processed in 0.014208 seconds, 23 queries