1

I'm using hyperref and cleveref in my document. Now, for clarity to my readers I want the links (that will reference other documents so might not be clear) to have a different color than black. And, for my own sanity, I would prefer to just keep using the \cref{...} command. How would I achieve this? I can find this and this (along more), however; the first is not globally, and only works for that specific type. The second redefines the \cref{} command, which shouldn't be the solution to this basic problem.

What I want to achieve is this:

Colored chapter

This can be created using the following:

\textcolor{bluegray}{\cref{chap:lorem}}

However, when I try to get the \textcolor command to be used globally I can only come this far:

Not colored chapter

This can be created using the following in the preamble:

\crefdefaultlabelformat{\textcolor{bluegray}{#2#1}#3}

And just using \cref{chap:lorem} in the text. With this solution, chapter is not colored bluegray as well, which is what I want to achieve. This is logical, because this command only applies to the label counter as per the cleveref docs.

The solution mentioned here does what I want using \crefformat{<type>}{<format>}; however, the code there only works for that specific type. I don't want to go around and having to re-define this for every type I use in my document (though certainly possible, I feel like there has to be a cleaner way for this). I don't see a \crefdefaultformat{<format>} command or the alikes in the cleveref docs.

What would be the best approach? Am I basically forced to override the default \cref{} command?

2 Answers2

2

You can use the \crefname command to change the text "chapter" to whatever you want, including colored versions:

\crefname{chapter}{\textcolor{bluegray}{chapter}}{\textcolor{bluegray}{chapters}}

Use \Crefname with analogous syntax for the \Cref version.

ronno
  • 1,325
  • Thank you for your answer. That's another possible solution; however, I would have to redefine all the types that I want to use. This is of course less than ideal again, since this would cause a lot of code duplication :-) – MagicLegend Apr 16 '20 at 12:07
  • You could probably redefine \crefname and \Crefname themselves to include the \textcolor, though this would still require you to include \crefname{chapter}{chapter}{chapters} etc for each counter cleveref recognizes by default. I'll update the answer if I think of a better way. – ronno Apr 16 '20 at 14:27
  • For now I have simply defined two new commands; \ccref (colored cref) and \Ccref; which fits my needs. Simply just added this \newcommand{\ccref}[1]{\textcolor{bluegray}{\cref{#1}}} to the preamble, and use it like the regular \cref command. Feel free to add this to your answer; then I'll mark it as the solution :) – MagicLegend Apr 17 '20 at 07:51
  • I think that's sufficiently different from my solution that you should post it as a separate answer (and then feel free to mark it as accepted). – ronno Apr 17 '20 at 08:32
2

Because I didn't want to redefine the original command, I simply settled with adding a new command as follows:

\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}

\definecolor{bluegray}{rgb}{0.4, 0.6, 0.8}
\newcommand{\ccref}[1]{\textcolor{bluegray}{\cref{#1}}}
\newcommand{\Ccref}[1]{\textcolor{bluegray}{\Cref{#1}}}