4

The following example works well:

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[parent=section]{theorem}
\usepackage{hyperref}


\begin{document}
\section{Section}
\begin{theorem}\label{true}
  True.
\end{theorem}
According to \autoref{true}, this is true.

\subsection{Proof of Theorem \ref{true}}
Proof.
\end{document}

But the following example fails:

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[parent=section]{theorem}
\usepackage{hyperref}


\begin{document}
\section{Section}
\begin{theorem}\label{true}
  True.
\end{theorem}
According to \autoref{true}, this is true.

\subsection{Proof of \autoref{true}}
Proof.
\end{document}

With the error:

Argument of \@sect has an extra } \subsection{Proof of \autoref{true}}
Paragraph ended before \@sect was complete \subsection{Proof of \autoref{true}}
Paragraph ended before \HyPsd@@ProtectSpacesFi was complete \subsection{Proof of \autoref{true}}
Extra }, or forgotten \endgroup \subsection{Proof of \autoref{true}}
Use of \HyPsd@RemoveMask doesn't match its definition \subsection{Proof of \autoref{true}}
Undefined control sequence \subsection{Proof of \autoref{true}}
Paragraph ended before \HyPsd@RemoveBraces was complete \subsection{Proof of \autoref{true}}
Extra }, or forgotten \endgroup \subsection{Proof of \autoref{true}}
Argument of \HyPsd@CheckCatcodes has an extra } \subsection{Proof of \autoref{true}}
Paragraph ended before \HyPsd@CheckCatcodes was complete \subsection{Proof of \autoref{true}}
File ended while scanning use of \HyPsd@RemoveMask

Any idea why, or how to overcome this?

2 Answers 2

1

\autoref chokes when the text for making the bookmark is being processed. Use \texorpdfstring:

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[parent=section]{theorem}
\usepackage{hyperref}

\begin{document}
\section{Section}
\begin{theorem}\label{true}
  True.
\end{theorem}
According to \autoref{true}, this is true.

\subsection{Proof of \texorpdfstring{\autoref{true}}{"true"}}
Proof.
\end{document}

enter image description here

Alternatively, use cleveref:

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[parent=section]{theorem}
\usepackage{hyperref}
\usepackage[capitalize]{cleveref}


% remove a spurious warning
\makeatletter
\pdfstringdefDisableCommands{\let\cref\@firstofone}
\makeatother

\begin{document}
\section{Section}
\begin{theorem}\label{true}
  True.
\end{theorem}
According to \cref{true}, this is true.

\subsection{Proof of \cref{true}}
Proof.
\end{document}
5
  • Do you have a recommendation, which solution should I use?
    – Bach
    Mar 28, 2016 at 16:17
  • @Bach I'd go for cleveref, which is much more powerful.
    – egreg
    Mar 28, 2016 at 16:22
  • This works, thanks! One thing to note is that the Theorem string is not clickable with \cref, but is clickable with \autoref, so I wouldn't recommend combining the two.
    – Bach
    Mar 28, 2016 at 16:28
  • 1
    @Bach \usepackage[capitalize,nameinlink]{cleveref}
    – egreg
    Mar 28, 2016 at 16:32
  • 1
    The warning caused by the usage of cleveref is actually not spurious: The PDF bookmark in the example says "Proof of true", instead of "Proof of Theorem 1.1". It therefore seems that \texorpdfstring is also necessary with cleveref. Feb 2, 2017 at 21:25
0

Bizarrely, the following solution also seems to work: add title={Theorem} to the theorem declaration.

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[parent=section,title={Theorem}]{theorem} % added title={Theorem}
\usepackage{hyperref}


\begin{document}
\section{Section}
\begin{theorem}\label{true}
  True.
\end{theorem}
According to \autoref{true}, this is true.

\subsection{Proof of \autoref{true}}
Proof.
\end{document}

I have no idea why this works; I stumbled upon this solution by lucky chance. Presumably the problematic code is somewhere in the automatic title generation?

Setting the title manually for every theorem style could be an alternative solution if for some reason you're unable (or unwilling) to use the package cleveref. So far, this seems to be the only solution that also generates the right PDF bookmark (though that might not matter to some).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .