4

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

\documentclass{amsart}
\usepackage[dvipsnames]{xcolor}
\usepackage[breaklinks,colorlinks,pagebackref]{hyperref} 
\hypersetup{linkcolor=Red , citecolor=Green}
\usepackage[capitalise,nameinlink]{cleveref}
\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

1
  • 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, 2018 at 1:06

2 Answers 2

3

\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):

enter image description here

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

\usepackage[dvipsnames]{xcolor}
\usepackage[colorlinks,linkcolor=Red]{hyperref} 
\usepackage[capitalise,nameinlink]{cleveref}

\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}
6
  • 1
    @MOB Mico is very excellent user. He will surely solve your problem.
    – Sebastiano
    Apr 17, 2018 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, 2018 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, 2018 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, 2018 at 5:35
  • @MOB - I've updated my answer.
    – Mico
    Apr 18, 2018 at 5:42
4

You have to remove the color specification for \cref:

\documentclass{amsart}
\usepackage[dvipsnames]{xcolor}
\usepackage[colorlinks,pagebackref]{hyperref} 
\usepackage[capitalise,nameinlink]{cleveref}

\hypersetup{linkcolor=Red , citecolor=Green}

\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}

enter image description here

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

\documentclass{amsart}
\usepackage[dvipsnames]{xcolor}
\usepackage[colorlinks,pagebackref]{hyperref} 
\usepackage[capitalise,nameinlink]{cleveref}

\hypersetup{linkcolor=Red , citecolor=Green}

% 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)
  {\color{Blue}\bfseries} % HEADFONT
  {.}         % HEADPUNCT
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {}          % CUSTOM-HEAD-SPEC
\newtheoremstyle{colordefinition}
  {\topsep}   % ABOVESPACE
  {\topsep}   % BELOWSPACE
  {\normalfont}  % BODYFONT
  {0pt}       % INDENT (empty value is the same as 0pt)
  {\color{Blue}\bfseries} % HEADFONT
  {.}         % HEADPUNCT
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {}          % CUSTOM-HEAD-SPEC

\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}

enter image description here

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

You must log in to answer this question.

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