[Tex/LaTex] Is it possible to give colors to big (automatic) parenthesis in math mode

bracketscolormath-mode

In the following code I can't make the right parenthesis to have arbitrary colors.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\begin{document}
\begin{equation}
\left(\frac{44}{55}{\color{blue}\right)}
\end{equation}
\end{document}

As soon as I add color around \right) (or \left() I get an error: ! Missing } inserted.

Is there a work around for this? (I prefer not to touch other parts of the equation).

Best Answer

It's really easier: \left and \right form a group, so setting the color immediately before \right will do.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\begin{document}
\begin{equation}
\left(\frac{44}{55}\color{red}\right)+2
\end{equation}
\end{document}

enter image description here

For coloring also the left delimiter, you can save the color before changing it:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\begin{document}
\begin{equation}
\begingroup
\colorlet{savedleftcolor}{.}
\color{blue}\left(\color{savedleftcolor}
  \frac{44}{55}\color{red}\right)
\endgroup
+2
\end{equation}
\end{document}

enter image description here

A generalized version:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\newcommand{\cleft}[2][.]{%
  \begingroup\colorlet{savedleftcolor}{.}%
  \color{#1}\left#2\color{savedleftcolor}%
}
\newcommand{\cright}[2][.]{%
  \color{#1}\right#2\endgroup
}


\begin{document}
\begin{equation}
\cleft[blue](\frac{44}{55}\cright[red])
+
\cleft[red](\frac{44}{55}\cright)
\end{equation}
\end{document}

Note that \cleft{[} is needed for having the bracket, if no color is specified, or \cleft\lbrack.

Don't try closing \cleft with \right or \left with \cright.

enter image description here