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.

regarding this documentation

ftp://ftp.dante.de/pub/tex/info/math/voss/mathCol/mathCol.pdf

it should be easy to change the color of an align environment like this:

\documentclass{article}
\usepackage{color,amsmath}
\begin{document}
\begin{align}\color{red}
x &= 1\\
y &= 2
\end{align}
\end{document}

But all that changes to red is the first entry, i.e. the x. I use MiKTeX 2.8 on Windows XP.

Any ideas?

share|improve this question

migrated from stackoverflow.com Jan 31 '13 at 14:58

This question came from our site for professional and enthusiast programmers.

    
@PeterGrill I was not aware of TeX.SE and I don't have an account there. Since I found quit a few questions about LaTeX here on Stackoverflow I thoungt I can ask LaTeX stuff here too?! If this questions really shouldn't be here how can I migrate it? –  Florian Mans Jan 30 '13 at 16:07
    
I'd recommend you post future questions at TeX.SE. This should get migrated as I have flagged it. You should create an account there -- I think it is only one click to get the same account to be able to access both sites. –  Peter Grill Jan 30 '13 at 18:20
    
Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Jan 31 '13 at 15:24
add comment

1 Answer 1

up vote 4 down vote accepted

Each cell within the align environment forms a group, localizing the extent of the colour change. If you wrap the colour change around the outside of align, it spans across the internal cells:

enter image description here

\documentclass{article}
\usepackage{xcolor,amsmath}% http://ctan.org/pkg/{xcolor,amsmath}
\begin{document}
{\color{red}\begin{align}
x &= 1\\
y &= 2
\end{align}}
\end{document}

You'll notice that this sets even the equation numbers in \color{red}. This is easily fixed by adding the following to your preamble:

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\math@cr@@@align}% <cmd>
  {\place@tag}% <search>
  {\bgroup\color{black}\place@tag\egroup}% <replace>
  {}{}% <success><failure>
\makeatother

The above etoolbox-patch inserts a black colour-change around the number-printing mechanism \place@tag:

enter image description here

For individual colour modifications to each cell/component of the line, insert \color{<colour>} in the respective cells you want to use colour <colour>.

share|improve this answer
    
Thanks for your help. Problem solved. But I'm still curious if the manual I linked is wrong and always has been or if at the time it was written things with align and color worked differently... –  Florian Mans Jan 30 '13 at 16:02
    
@FlorianMans: Which of the equations in the document are you referring to? If it is the equation marked (7) (p 4), then the code is exactly correct and corresponds to the output. Note that even though the author uses align, he uses the CD environment rather than align internals. As such, \color{blue} spans the entire equation. –  Werner Jan 30 '13 at 16:27
    
Yes I was referring to equation (7). I didn't consider the `CD' environment as the important difference. Thanks again for your help and further clarification. –  Florian Mans Jan 31 '13 at 9:13
add comment

Your Answer

 
discard

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