6

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: enter image description here

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
7

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:

enter image description here

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

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}

enter image description here

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.