# Cleveref and pdf Bookmark

I'm making pdf bookmarks with hyperref and cleveref packages. However, the pdf bookmarks show the label I defined, rather than the theorem name the label refers to. Here's the code:

\documentclass{article}

\usepackage{hyperref}
\usepackage{cleveref}

\newtheorem{theorem}{Theorem}

\begin{document}

\section{Section 1}
\begin{theorem}\label{some label}
This is a theorem.
\end{theorem}

\section{Proof to \Cref{some label}}

\end{document}


And here's the pdf:

Any idea how to change the label to "Proof to Theorem 1" instead of "Proof to some label"?

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – karlkoeller Mar 28 '15 at 6:40
• \Cref is not really expandable, I fear, since it's defined to be a robust command – user31729 Mar 28 '15 at 6:47

I'm afraid there is no solution for this, apart from using the command \texorpdfstring, that is you have to specify what has to go in the text and what has to go in the bookmarks.

Hence, substitute

\section{Proof to \Cref{some label}}


with

\section{Proof to \texorpdfstring{\Cref{some_label}}{Theorem \ref{some_label}}}


Note that it isn't a good idea to have label names with spaces, so I've substituted some label with some_label.

MWE:

\documentclass{article}

\usepackage{hyperref}
\usepackage{cleveref}

\newtheorem{theorem}{Theorem}

\begin{document}

\section{Section 1}
\begin{theorem}\label{some_label}
This is a theorem.
\end{theorem}

\section{Proof to \texorpdfstring{\Cref{some_label}}{Theorem \ref{some_label}}}

\end{document}


Output:

• That solves the problem (with a bit more work), thank you! – Erika L Mar 28 '15 at 16:01

The \Cref command cannot be used in \section when bookmarks are being produced; however, \autoref works (it's less powerful, though). For a simple application like this you can do as follows:

\documentclass{article}

\usepackage{hyperref}
\usepackage{cleveref}

\pdfstringdefDisableCommands{\let\Cref\autoref}

\newtheorem{theorem}{Theorem}

\begin{document}

\section{Section 1}

\begin{theorem}\label{some_label}
This is a theorem.
\end{theorem}

\section{Proof to \Cref{some_label}}

\end{document}


• Thanks. I did try autoref, but I do have a bunch of lemmas/propositions/corollaries which makes cleveref more suitable. – Erika L Mar 28 '15 at 20:43
• @ErikaL Yes, but as you see, I let \Cref to \autoref only in bookmarks where super precision is not really necessary. – egreg Mar 28 '15 at 20:44
• It does work for the MWE. However I found another strange behavior using this method, see [tex.stackexchange.com/questions/235634/… – Erika L Mar 28 '15 at 21:12
• This answer deserves to be upvoted more. It is an automatic solution relative to the manual solution that the accepted answer proposes. The virtues are obvious. If a figure number being referred to in the bookmark/section heading changes, then hand-coding a string quickly becomes dangerously out of date & misleading. – Krishna Jan 8 at 20:37