No meu documento, preciso que alguns colchetes sejam destacados em cores, para isso tentei o código abaixo:
\documentclass{book}
\usepackage{xcolor}
\usepackage{mhchem}
\begin{document}
\definecolor{bracketcolor}{cmyk}{0,1,1,0}%red
\newcommand{\colorbkt}[1]{\color{bracketcolor}#1\color{black}}%
\[
\left\lvert
p-p_{\mathcal{C}}\right\rvert^{-1}\quad\colorbkt{\left\lvert} p-p_{\mathcal{C}}\colorbkt{\right\rvert}^{-1}
\]
\[
\left( p-p_{\mathcal{C}}\right)^{-1}\quad\colorbkt{\left(} p-p_{\mathcal{C}}\colorbkt{\right)}^{-1}
\]
\[
\left[ p-p_{\mathcal{C}}\right]^{-1}\quad\colorbkt{\left[} p-p_{\mathcal{C}}\colorbkt{\right]}^{-1}
\]
\end{document}
Ele produziu a saída como:
Funciona, mas há algum espaço adicional após os colchetes de fechamento, consulte a captura de tela destacada, por favor, sugira como eu corrigi?
Responder1
Utilize \mathcolor:
\documentclass{book}
\usepackage{xcolor}
\usepackage{mhchem}
\begin{document}
\definecolor{bracketcolor}{cmyk}{0,1,1,0}%red
\newcommand{\colorbkt}[1]{\color{bracketcolor}#1\color{black}}%
\[
\left\lvert
p-p_{\mathcal{C}}\right\rvert^{-1}\quad\colorbkt{\left\lvert} p-p_{\mathcal{C}}\colorbkt{\right\rvert}^{-1}
\]
\[
\left( p-p_{\mathcal{C}}\right)^{-1}\quad\colorbkt{\left(} p-p_{\mathcal{C}}\colorbkt{\right)}^{-1}
\]
\[
\left[ p-p_{\mathcal{C}}\right]^{-1}\quad\colorbkt{\left[} p-p_{\mathcal{C}}\colorbkt{\right]}^{-1}
\]
\renewcommand{\colorbkt}[1]{\mathcolor{bracketcolor}{#1}}% with \mathcolor it works
\[
\left\lvert
p-p_{\mathcal{C}}\right\rvert^{-1}\quad\colorbkt{\left\lvert} p-p_{\mathcal{C}}\colorbkt{\right\rvert}^{-1}
\]
\[
\left( p-p_{\mathcal{C}}\right)^{-1}\quad\colorbkt{\left(} p-p_{\mathcal{C}}\colorbkt{\right)}^{-1}
\]
\[
\left[ p-p_{\mathcal{C}}\right]^{-1}\quad\colorbkt{\left[} p-p_{\mathcal{C}}\colorbkt{\right]}^{-1}
\]
\end{document}