# Format cleveref labels including names

I'm trying to emphasize my figure references with bold text. When referencing a labeled figure with \cref{fig:mylabel} I get the correct text Abbildung 1, however I'm having trouble formatting it.

I'm using the packages hyperref and cleveref with a German document setting. As per documentation there is the option \crefdefaultlabelformat, however when I try to make the entire label bold (so including the name) with \crefdefaultlabelformat{\bfseries#2#1#3} only the number reference will get emphasized. Same is true for \creflabelformat{figure}....

There is also the option to format the links provided by hyperref, but I was unable to find something that only targets these specific links.

\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage[labelfont=bf]{caption}
\crefdefaultlabelformat{\bfseries#2#1#3}

\begin{document}
\begin{figure}[h]
\caption{Some image}
\label{fig:mylabel}
\end{figure}

This should all be bold $$\rightarrow$$ \cref{fig:mylabel}
\end{document}


If the aim is to have just figure references bold, you can do

\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage[labelfont=bf]{caption}

\crefformat{figure}{#2\bfseries\figurename~#1#3}

\begin{document}

\begin{figure}[htp]
\caption{Some image}
\label{fig:mylabel}
\end{figure}

This should all be bold \cref{fig:mylabel} and this shouldn't.

\end{document}


If you really want all \cref produced text to be in boldface, you can patch \@cref.

\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage{xpatch}
\usepackage[labelfont=bf]{caption}

\makeatletter
\xpatchcmd{\@cref}{\begingroup}{\begingroup\bfseries}{}{}
\makeatother

\begin{document}

\begin{figure}[htp]
\caption{Some image}
\label{fig:mylabel}
\end{figure}

This should all be bold \cref{fig:mylabel} and this shouldn't.

\end{document}


Perhaps someone has a more cref/hyperref native solution.

But in the meanwhile what works is to just wrap cref with bfseries. Inspired by Werner's answer to make it a bit less cumbersome, we can automatize this wrapping by first saving the cref under another name e.g. oldcref:

\usepackage{letltxmacro}
\LetLtxMacro\oldcref\cref


And then redefining the cref with the wrapped one:

\usepackage{xparse}
\RenewDocumentCommand{\cref}{m}{\bfseries\oldcref{#1}} % m here means one mandatory argument


\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage[labelfont=bf]{caption}

% simply wrap cref by bfseries
\usepackage{letltxmacro,xparse}
\LetLtxMacro\oldcref\cref
\RenewDocumentCommand{\cref}{m}{\bfseries\oldcref{#1}}

\begin{document}
\begin{figure}[h]
\caption{Some image}
\label{fig:mylabel}
\end{figure}

This should all be bold $$\rightarrow$$ \cref{fig:mylabel}
\end{document}