Sometimes when writing maths documents, I want to have the name of a theorem in a section heading. This works fine in the text of the document, but it runs into trouble in the PDF outline. Specifically, the name of the section in the outline contains the label of the theorem, rather than its actual printed number in the text. How can I get around this?
In the MWE below, the offending section heading will print as "Proof of Theorem 1.1" in the text, but as "Proof of thmName" in the outline. I want it to also say "Proof of Theorem 1.1" in the outline.
\documentclass{amsart}
\usepackage{hyperref}
\usepackage{cleveref}
\newtheorem{thm}{Theorem}[section]
\begin{document}
\section{Introduction}
In this paper we prove the following result, which requires a bunch of lemmas to be given first.
\begin{thm}\label{thmName}
Some result.
\end{thm}
\section{Required Results}
Here we give a bunch of lemmas.
\section{Proof of \cref{thmName}} % The offending section heading
We draw the lemmas together into a proof of \cref{thmName}.
\end{document}
I compile this with PDFLaTeX, and it seems this is a problem with hyperref. The warning I get from it is
Token not allowed in a PDF string (PDFDocEncoding):(hyperref) removing `\new@ifnextchar' on input line 22
Update
By following Jakob's answer here, I've been able to get this working as follows:
\documentclass{amsart}
\usepackage{hyperref}
\usepackage{cleveref}
\newtheorem{theorem}{Theorem}[section] % Note that the environment is now named 'theorem' rather than 'thm'.
\usepackage{crossreftools}
\pdfstringdefDisableCommands{%
\let\Cref\crtCref
\let\cref\crtcref
}
\begin{document}
\section{Introduction}
In this paper we prove the following result, which requires a bunch of lemmas to be given first.
\begin{theorem}\label{thmName}
Some result.
\end{theorem}
\section{Required Results}
Here we give a bunch of lemmas.
\section{Proof of \cref{thmName}}
We draw the lemmas together into a proof of \cref{thmName}.
\end{document}
However, it absolutely requires me to name the theorem environment 'theorem' rather than 'thm'. If I do the above with \newtheorem{thm}{Theorem}[section] instead, all sorts of errors are thrown. Why would this be?
\newcommand\mythmref[1]{Theorem~\ref{#1}}in the preamble and then use\mythmref{thmName}. – Ulrike Fischer Jan 14 '21 at 16:23