# Undefined color error in Section after defining the color

In the following MWE,

\documentclass[twocolumn,showpacs,preprintnumbers,amsmath,amssymb,superscriptaddress]{revtex4}
\usepackage[dvips]{graphicx}
\usepackage[usenames,dvipsnames]{xcolor} % in order to use color names
\usepackage{color}
\definecolor{ngreen}{rgb}{0.2,0.7,0.2}%161
\newcommand{\grn}{\color{ngreen}}

\begin{document}

\title{\grn Title}% Force line breaks with \\
\maketitle

\section{\grn Section} % compilation error in this line!
Some Text.

\end{document}


I get the compilation error "Package xcolor Error: Undefined color 'NGREEN' ", but it seems to me that I have correctly defined the color ngreen. What's the problem? Note that if you comment the line, I got the correct compilation for the title.

PS I get the same error compiling with latex and pdflatex.

PPS probably some of the packages are redundant.

• I suppose the problem comes with section capitalization: add \colorlet{NGREEN}{ngreen} for a workaround. – Claudio Fiandrino Dec 4 '13 at 9:32
• With article it works just fine. This must be related to revtex4. I've never used it, so I've no clue... – nickie Dec 4 '13 at 9:34
• You are right @ClaudioFiandrino, adding \colorlet{NGREEN}{ngreen} it works. So the capitalization of the section title reflects to the commands? – Nicola Dec 4 '13 at 9:46
• @nickie The guy who has sent me the .tex file used \grn to highlight his changing to the text. Probably it works fine on his laptop. I wonder why it doesn't on mine without \colorlet{NGREEN}{ngreen} – Nicola Dec 4 '13 at 9:46

You need to use \protect\grn or else \grn is expanded to \color{NGREEN} when the section heading is converted to upper case.

\documentclass{revtex4}
\usepackage{color}
\definecolor{ngreen}{rgb}{0.2,0.7,0.2}%161
\newcommand{\grn}{\color{ngreen}}
\begin{document}
\section{\protect\grn This is a section}
\end{document}


This is not specific to revtex except in that revtex capitalises section headings. To cause the same problem in any document class you can use

\MakeUppercase{\grn abc}


and the solution (\protect) is the same.