# Issue with cref and color names, generally and in theorem environments

I am trying to use \cref from the cleveref package with in a theorem environment. I also want my theorem names colored, say red. Now if one tries to use \cref within a colored environment, e.g.

\documentclass{article}
\usepackage{amsthm}
\usepackage[usenames,dvipsnames]{color}

\newtheorem{redthm}{{\color{red}Theorem}}

\begin{document}

\begin{redthm} \label{thm1} Assume ABC.  Then D.
\end{redthm}

{\color{red} \ref{thm1}}

\end{document}


I get the error

./tmp.tex:13: LaTeX Error: Undefined color 'RED'.


I might like a solution, but I could live with that: what I really want to do is use \cref with my "red theorem" environments. E.g., replace the above \cref line with:

\begin{redthm} Under assumptions of \cref{thm1}, E.
\end{redthm}


This gives the same error, even though the body of the theorem is not actually colored. So can someone give me a solution to one or both of the following?

1. How can we use \cref in a colored environment?
2. How can we make a theorem environment so the word "Theorem" is colored but there is no conflict with \cref within the body of the theorem.

(I would also be to happy to hear an explanation of why these errors happen, bearing in mind I don't know anything about the internals of tex or these packages.)

• this is just a guess, as i'm not really familiar with the internals of some of these packages. the option capitalize for cleveref looks suspicious. there's no uppercasing in amsthm, but when something you think should be lowercase is reported as not working and the unrecognized string is showing in uppercase, something is changing it. try defining a color RED (equivalent to red) and using that. – barbara beeton Sep 11 '15 at 19:24
• @barbarabeeton Hmm, it does seem to be capitalize that is causing problems, although I don't know why it's capitalizing this (or every letter, as it usually just capitalizes the first letter). – Kimball Sep 11 '15 at 19:55
• @Kimball: I assume, that the capitalizing breaks here due to \color, due to various expansions etc, such that the capitalizing is applied to the argument of \color, i.e. redRED, which is then fed into \color, leading to the error – user31729 Sep 11 '15 at 20:28

It's better to use \protect\color{red}Theorem here, since the capitalize option of cleveref sees \color{red} first, wrongly transforming it into RED colour, which isn't defined here. \color is a fragile command, so \protect prevents the 'breaking apart' here.

\documentclass{article}
\usepackage{amsthm}
\usepackage[usenames,dvipsnames]{xcolor}

\newtheorem{redthm}{\protect\color{red}Theorem}

\begin{document}

\begin{redthm} \label{thm1}  Under assumptions of \cref{thm1}
Assume ABC.  Then D.
\end{redthm}

{\color{red} \ref{thm1}}

\end{document}


• Thanks, that works. I didn't know about \protect. But I'll wait a bit to accept in case some other interesting answers pop up. – Kimball Sep 11 '15 at 19:57