8

I am getting an Package xcolor Error: Undefined color 'RED' if I use a red symbol in the Chapter title. In the MWE below, commenting the last \chapter results in an error. There seems to be no problem with the Second Chapter title containing the red symbol, as the example as is below produces correct results. Problem only shows up in the subsequent chapter.

\documentclass{book}

\usepackage{xcolor}
\newcommand{\SymbolInRed}{$\textcolor{red}{\times}$}

\begin{document}
\chapter{First Chapter}
\chapter{Second Chapter\SymbolInRed}
%\chapter{Third Chapter}% Undefined color 'RED' if uncomment this.
\end{document}

I have been using this for a while now and have had not problems. I recently changed the header/footer to contain the chapter title using \leftmark and started having this problem so thought it was related to that. But with this example I can reproduce the problem without that.

1

2 Answers 2

5

As Lev Bishop already stated this is caused by the header mark which is converted to uppercase which also turns red into RED and is also a problem with e.g. \label. This can also be avoided by declaring \SymbolInRed as a robust command or of course using \protect\SymbolInRed inside the \chapter{..}. This way the symbol macro isn't expanded and the header mark code never sees the red. This also helps you with the ToC file which then will only hold \SymbolInRed and not its expanded version.

\documentclass{book}

\usepackage{xcolor}
\DeclareRobustCommand{\SymbolInRed}{$\textcolor{red}{\times}$}

\begin{document}
\chapter{First Chapter}
\chapter{Second Chapter\SymbolInRed}
\chapter{Third Chapter}% works now
\end{document}

Also this related question on How to add a tikz/pgf command to section command for more info.

1
  • Thanks for the explanation. I was not able to connect the problem with the color and the upper case/lower case otherwise. This solution also does not require another package to be loaded. Jun 30, 2011 at 8:35
3

Problem is with the header mark (page 4). Fix with \usepackage[overload]{textcase}

3
  • Thanks, that fixes it. But can you elaborate a bit as to what the problem and the fix is. The documentation on the overload option for textcase doesn't seem to be related to this at all. Jun 30, 2011 at 4:50
  • 1
    This fixes the problem just because the color change is inside a math formula; it won't do any good in other cases. If the definition had been \textcolor{red}{$\times$}, the problem with RED would have been the same also with textcolor, for example.
    – egreg
    Jun 30, 2011 at 9:55
  • Martin beat me to the explanation :)
    – Lev Bishop
    Jun 30, 2011 at 14:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .