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 have to set globally the color of every math to blue. However, if I need to annotate an expression by using \underbrace, the curly brace must be in black (for example).

The following are my MWE and its corresponding output in which I failed to accomplish my objective.

enter image description here

\documentclass[preview,border=12pt]{standalone}
\usepackage{amsmath}
\usepackage{xcolor}
\everymath{\color{blue}}
\newcommand\HighlightedTerm[2]{%
        \color{black}%
        \underbrace{#1}_{\color{red}\text{#2 term}}%
}
\begin{document}
Consider an expression $2a^3b^2cd^7e-ab^2cde^3$. It has 2 terms as shown in the following,
\[
\HighlightedTerm{2a^3b^2cd^7e}{1st}\HighlightedTerm{-ab^2cde^3}{2nd}
\]
Do you understand?
\end{document}

Could you help me to realize my objective? Please don't advice me to use TikZ or PSTricks. :-)

share|improve this question
1  
Note: making every equation in blue is my strategy to prevent someone from photocopying my book. –  I am who I say I am Feb 16 '13 at 14:41
    
How exactly do you expect that strategy to prevent anyone from photocopying your book? –  trav1s Jun 5 '13 at 7:23
    
@trav1s: Text in blue is difficult to be copied. It is my experience. –  I am who I say I am Jun 7 '13 at 13:47
add comment

1 Answer

up vote 7 down vote accepted

The definition of \underbrace uses the definition of \upbracefill. Both commands are defined in the file fontmath.ltx

The command \upbracefill is defined as follows and you can see it opens a new math-environment.

\def\upbracefill{$\m@th \setbox\z@\hbox{$\braceld$}%
  \bracelu\leaders\vrule \@height\ht\z@ \@depth\z@\hfill\bracerd
  \braceld\leaders\vrule \@height\ht\z@ \@depth\z@\hfill\braceru$}

So the easiest way will be the adding of a simple \color{black} to the default definition:

\def\upbracefill{$\color{black}\m@th \setbox\z@\hbox{$\braceld$}%
  \bracelu\leaders\vrule \@height\ht\z@ \@depth\z@\hfill\bracerd
  \braceld\leaders\vrule \@height\ht\z@ \@depth\z@\hfill\braceru$}

Here your MWE using \makeatletter and \makeatother.

\documentclass[preview,border=12pt]{standalone}
\usepackage{amsmath}
\usepackage{xcolor}
\everymath{\color{blue}}
\newcommand\HighlightedTerm[2]{%
        \color{black}%
        \underbrace{#1}_{\color{red}\text{#2 term}}%
}

\makeatletter
\def\upbracefill{$\color{black}\m@th \setbox\z@\hbox{$\braceld$}%
  \bracelu\leaders\vrule \@height\ht\z@ \@depth\z@\hfill\bracerd
  \braceld\leaders\vrule \@height\ht\z@ \@depth\z@\hfill\braceru$}
\makeatother
\begin{document}   
Consider an expression $2a^3b^2cd^7e-ab^2cde^3$. It has 2 terms as shown in the following,
\[
\HighlightedTerm{2a^3b^2cd^7e}{1st}\HighlightedTerm{-ab^2cde^3}{2nd}
\]
Do you understand?
\end{document}

enter image description here

share|improve this answer
add comment

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.