# Isolated coloring of math symbols and boxes in equations

I know that by using a package like xcolor I can use $\color{<color>} <math symbols>$ to typeset math symbols in my preferred color. But how can I isolate the color to specific symbols only?

Say for instance the illustrations of commented equations in Howard Anton's Calculus book have colors for underbraces and the bounding text boxes but have none for the included text.

Consider the following MWE

\documentclass[]{article}

\usepackage{amsmath}
\usepackage{xcolor}

\begin{document}

$$\dfrac{d}{dx}[\sin(3x^2+2)]=\underbrace{\cos(3x^2+2)}_{\text{ \fbox{\parbox[b][]{2cm}{ Derivative of the outise evaluated at the inside} }}} \cdot \underbrace{6x}_{\text{ \color{blue}{\fbox{\parbox[b][]{1.25cm}{ Derivative of the inside} }}}}$$
\end{document}


which outputs

How can I isolate the coloring to the underbraces and the bounding box to blue without affecting the other symbols/text?

-

## 2 Answers

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

\makeatletter
\renewcommand\underbrace[2][olive]{%
\mathop{\vtop{\m@th\ialign{##\crcr
$\hfil\displaystyle{#2}\hfil$\crcr
\noalign{\kern3\p@\nointerlineskip}%
\textcolor{#1}{\upbracefill}\crcr\noalign{\kern3\p@}}}}\limits}
\makeatother
\newcommand\ColorBox[3][olive]{\text{\fcolorbox{#1}{white}{\parbox[b][]{#2}{\raggedright#3}}}}

\begin{document}

$$\frac{d}{dx}[\sin(3x^2+2)]=\underbrace{\cos(3x^2+2)}_{\ColorBox{2cm}{Derivative of the outise evaluated at the inside}} \cdot \underbrace[red!60!black]{6x}_{\ColorBox[red!60!black]{1.25cm}{Derivative of the inside}}$$

\end{document}


The syntax:

\underbrace[<color>]{<text>}
\ColorBox[<color>]{<width>}{<text>}


The default color: olive.

-
That was fast. Where can I find the definition for \underbraces and other such commands? –  hpesoj626 Sep 27 '12 at 8:27
@hpesoj626 For LaTeX kernel commands, such as \underbrace, you can open a terminal a run texdox source2e or in CTAN: source2e. –  Gonzalo Medina Sep 27 '12 at 12:57

Here are some minor alternatives to Gonzalo's answer, provided by the abraces package. More specifically, it allows for inserting arbitrary code within the brace construction using @{<stuff>}:

\documentclass{article}
\usepackage[overload]{abraces}% http://ctan.org/pkg/abraces
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\begin{document}
$$\dfrac{\mathrm{d}}{\mathrm{d}x}\big[\sin(3x^2+2)\big]= \underbrace[@{\color{olive}}l1D1r]{\cos(3x^2+2)}_{\color{olive} \text{\fbox{\parbox[b]{2cm}{\raggedright% \color{black}Derivative of the outside evaluated at the inside} }}} \cdot \underbrace[@{\color{red!60!black}}l1D1r]{\vphantom{()}6x}_{\color{red!60!black} \text{\fbox{\parbox[b]{1.25cm}{\raggedright% \color{black}Derivative of the inside} }}}$$
\end{document}


Other modifications include:

• Using \mathrm{d} for d/dx;
• Enlarging the brackets around the LHS using \big[ and \big]; and
• Inserting \vphantom to lower the \underbrace for both components of the chain rule to the same depth.
-