Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

\begin{equation}
\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{equation}
\end{document}

which outputs

enter image description here

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

share|improve this question

2 Answers 2

up vote 7 down vote accepted
\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}

\begin{equation}
\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{equation}

\end{document}

enter image description here

The syntax:

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

The default color: olive.

share|improve this answer
    
That was fast. Where can I find the definition for \underbraces and other such commands? –  hpesoj626 Sep 27 '12 at 8:27
1  
@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>}:

enter image description here

\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}
\begin{equation}
  \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{equation}
\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.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.