![更改“ddot”符号中单个点的颜色](https://linux22.com/image/392589/%E6%9B%B4%E6%94%B9%E2%80%9Cddot%E2%80%9D%E7%AC%A6%E5%8F%B7%E4%B8%AD%E5%8D%95%E4%B8%AA%E7%82%B9%E7%9A%84%E9%A2%9C%E8%89%B2.png)
答案1
下面使用了两个稍微偏移的彩色\dot
宏。位置并不完美,对于某些字母来说可能真的很糟糕。
\documentclass[]{article}
% for colours
\usepackage{xcolor}
% for mighty interface to define new macros, it also loads the l3 kernel
\usepackage{xparse}
% for \mathrlap
\usepackage{mathtools}
% change to the coding language of LaTeX3 (in which spaces are ignored, that why
% I can do stuff like { #2 } etc., also _ is a character now and can be part of
% macro names)
\ExplSyntaxOn
% define a user facing macro, it takes one optional argument, which by default
% is empty and a mandatory one (neither of them can contain a \par). The
% optional argument will be split at a "," once.
\NewDocumentCommand \cddot { >{\SplitArgument{1}{,}}O{} m }
{
% pass on the now split argument #1 and the mandatory argument #2. #1 will
% be something like { #1.1 } { #1.2 }
\__manooooh_cddot:nnn #1 { #2 }
}
% define a new internal macro (\cs_new_protected:Npn is like \protected\def)
\cs_new_protected:Npn \__manooooh_cddot:nnn #1 #2 #3
{
% start a new group
\group_begin:
% check whether the first argument is blank (meaning it only contains spaces
% or nothing), if it isn't blank change the \color. It will be blank if you
% don't use an optional argument or if you start your optional argument with
% a ","
\tl_if_blank:nF { #1 } { \color { #1 } }
% \mathrlap will print its argument without really taking any space, phantom
% will only take the space of #3, \mkern-1.5mu will move the dot slightly to
% the left
\mathrlap { \mkern-1.25mu \dot { \phantom { #3 } } }
% end the group containing the first \color
\group_end:
% start a new group
\group_begin:
% IfValueT will check whether the second part of the split argument was
% available (so will result in True if there was a comma in [#1]). If there
% was a second argument assume it is the second \color
\IfValueT { #2 } { \color { #2 } }
% again \mathrlap and a phantom #3, this time shifting the dot slightly to
% the right by 2mu
\mathrlap { \mkern+2.25mu \dot { \phantom { #3 } } }
% end the second \color's group
\group_end:
% print #3 without further ado (since we used \mathrlap previously we're
% still on the same spot and due to the \phantom #3 will only be printed
% visible once
#3
}
% end the LaTeX3 programming syntax
\ExplSyntaxOff
\begin{document}
% without optional argument
$\cddot{x}$
% with the first half of the optional argument
$\cddot[blue]{x}$
% with the second half of the optional argument
$\cddot[,green]{x}$
% with both halves of the optional argument
$\cddot[blue,green]{x}$
% for comparison
$\ddot{x}$
\end{document}
答案2
\dddot
改编自中的定义amsmath
。图片中的底线显示符号相互叠加;差异确实可以忽略不计。
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\makeatletter
\DeclareRobustCommand{\colorddot}[3]{%
% #1=color of first dot, #2=color of second dot, #3=accentee
{\mathop{\kern\z@#3}\limits^{%
\vbox to-1.55\ex@{%
\kern-\tw@\ex@
\hbox{\normalfont\kern0.05em\textcolor{#1}{.}\kern-0.085em\textcolor{#2}{.}}
\vss
}%
}}%
}
\makeatother
\begin{document}
$\ddot{x}$
$\colorddot{green}{blue}{x}$
$\ddot{x}$\llap{$\colorddot{green}{blue}{x}$}
$\colorddot{green}{blue}{x}$\llap{$\ddot{x}$}
\end{document}
请注意,不同的颜色会使点看起来不对齐。
答案3
人们可以只使用accents
为此目的而制作的包。
\documentclass{article}
\usepackage{amsmath}
\usepackage{accents}
\usepackage{pgffor}
\usepackage{xcolor}
\newcommand{\ColorDots}[2]{\accentset{\foreach \X in {#1}
{\textcolor{\X}{\boldsymbol{.}}}}{#2}}
\begin{document}
$\accentset{\boldsymbol{..}}{x}$ $\ColorDots{red,blue}{y}$ $\ColorDots{red}{z}$
$\ColorDots{red,orange,blue}{X}$
\end{document}