# problem with cleveref

I would like to colorize my theorems and questions. I use the following code:

\documentclass{amsart}
\usepackage[dvipsnames]{xcolor}
\newtheorem{theorem}{\color{Blue} Theorem}[section]
\theoremstyle{definition}
\newtheorem{question}[theorem]{\color{Blue} Question }
\begin{document}
\begin{question}\label{qu1}  Question 1
\end{question}

\begin{theorem}\label{thm1} Theorem 1
\end{theorem}
Now we reference to ~\cref{thm1} and ~\cref{qu1}.

\end{document}


By running this, I get the following Error massage:

Argument of \@declaredcolor has an extra }."

I don't know what the problem is. Can you see the problem?

Thanks

• Please advise whether the color Blue should apply to just the environment's "label" ("Theorem", "Question", etc) or to the associated numbers ("0.1", "0.2", etc) as well. – Mico Apr 18 '18 at 1:06

\color is a "fragile" (in the LaTeX-specific sense of the word) command. You need to change

\newtheorem{theorem}{\color{Blue} Theorem}[section]
\theoremstyle{definition}
\newtheorem{question}[theorem]{\color{Blue} Question }


to

\newtheorem{theorem}{\protect\color{Blue} Theorem}[section]
\theoremstyle{definition}
\newtheorem{question}[theorem]{\protect\color{Blue} Question }


Even better though, as shown in egreg's answer, is to (re)run \crefname on the theorem and question counters. Here's an MWE (minimum working example):

\documentclass{amsart} % loads 'amsthm' package automatically

\usepackage[dvipsnames]{xcolor}

\newtheorem{theorem}{\color{Blue}Theorem}[section]
\theoremstyle{definition}
\newtheorem{question}[theorem]{\color{Blue}Question}
\crefname{theorem}{Theorem}{Theorems} % thanks, @egreg!
\crefname{question}{Question}{Questions}

\begin{document}
\setcounter{section}{2} % just for this example

\begin{question}\label{qu1}Question 1\end{question}
\begin{theorem}\label{thm1}Theorem 1\end{theorem}
\noindent
Now we cross-reference~\cref{thm1,qu1}.
\end{document}

• @MOB Mico is very excellent user. He will surely solve your problem. – Sebastiano Apr 17 '18 at 22:20
• Dear @Mico: Thanks for you answer. I have added \protect. But when I run it the Question will be in Blue and the link to it is also in Blue. But the linkcolor=Red is not Blue. Can you see the problem? – MO B Apr 17 '18 at 22:23
• Yes, it compiles fine, but doesn't do what's expected. Besides, \textcolor is the right command instead of \color. – egreg Apr 17 '18 at 22:45
• @egreg - with \textcolor, only the "label" ("Theorem", "Question", etc) gets colorized, but not the associated number. That's why I kept the OP's \color directive (while adding \protect). However, your solution (run \crefname) does away with the need for \protection. – Mico Apr 18 '18 at 5:35
• @MOB - I've updated my answer. – Mico Apr 18 '18 at 5:42

You have to remove the color specification for \cref:

\documentclass{amsart}
\usepackage[dvipsnames]{xcolor}

\newtheorem{theorem}{\textcolor{Blue}{Theorem}}[section]
\theoremstyle{definition}
\newtheorem{question}[theorem]{\textcolor{Blue}{Question}}

\crefname{theorem}{Theorem}{Theorems}
\crefname{question}{Question}{Questions}

\begin{document}

\begin{question}\label{qu1}
Question 1
\end{question}

\begin{theorem}\label{thm1}
Theorem 1
\end{theorem}

Now we reference to~\cref{thm1} and~\cref{qu1}.

\end{document}


OK, this doesn't color the number. Since Mico stole my code, here's a better one.

\documentclass{amsart}
\usepackage[dvipsnames]{xcolor}

% see https://tex.stackexchange.com/a/17555/4427
\newtheoremstyle{colorplain}
{\topsep}   % ABOVESPACE
{\topsep}   % BELOWSPACE
{\itshape}  % BODYFONT
{0pt}       % INDENT (empty value is the same as 0pt)
{5pt plus 1pt minus 1pt} % HEADSPACE
\newtheoremstyle{colordefinition}
{\topsep}   % ABOVESPACE
{\topsep}   % BELOWSPACE
{\normalfont}  % BODYFONT
{0pt}       % INDENT (empty value is the same as 0pt)
{5pt plus 1pt minus 1pt} % HEADSPACE

\theoremstyle{colorplain}
\newtheorem{theorem}{Theorem}[section]
\theoremstyle{colordefinition}
\newtheorem{question}[theorem]{Question}

\begin{document}

\begin{question}\label{qu1}
Question 1
\end{question}

\begin{theorem}\label{thm1}
Theorem 1
\end{theorem}

Now we reference to~\cref{thm1} and~\cref{qu1}.

\end{document}


• Now I am very fast to upvote also for you :-). – Sebastiano Apr 17 '18 at 22:44