1

I added the solution by @egreg to the question Reference to proof prints section instead to my document and it did not work throwing the error: Undefined control sequence. \@hyper@@anchor ...r@spot {#2#3}\let \put@me@back

The culprit as it turns out is thmtools:

\documentclass{article}
\usepackage{amsthm}
\usepackage[colorlinks]{hyperref}
\usepackage{cleveref}
\usepackage{thmtools}   %Only addition compared to the used solution

\newtheorem{theorem}{Theorem}
\newenvironment{delayedproof}[1]
 {\begin{proof}[\raisedtarget{#1}Proof of \Cref{#1}]}
 {\end{proof}}
\newcommand{\raisedtarget}[1]{%
  \raisebox{\fontcharht\font`P}[0pt][0pt]{\hypertarget{#1}{}}%
}
\newcommand{\proofref}[1]{\hyperlink{#1}{proof}}

\begin{document}
\section{Theorems}
\begin{theorem}\label{thm:some-theorem}
This is a theorem.
\end{theorem}

For an intuition, see the \proofref{thm:some-theorem}.

\appendix
\section{Proofs}
\begin{delayedproof}{thm:some-theorem}
This is a proof.
\end{delayedproof}
\end{document}

I am now interested in answering what exactly breaks and if there is a better, i.e. the hyperlink does the right thing, fix that what I have come up with:

\newenvironment{delayedproof}[1]
 {\raisedtarget{#1}\begin{proof}[Proof of \Cref{#1}]}
 {\end{proof}}
\newcommand{\raisedtarget}[1]{%
  \raisebox{\fontcharht\font`P}[0pt][0pt]{\hypertarget{#1}{}}%
}
0

1 Answer 1

2

The \raisedtarget is fragile. I would use \MakeLinkTarget instead. It will also take care to raise the target a bit.

\documentclass{article}
\usepackage{amsthm}
\usepackage[colorlinks]{hyperref}
\usepackage{cleveref}
\usepackage{thmtools}   %Only addition compared to the used solution

\newtheorem{theorem}{Theorem}
\newenvironment{delayedproof}[1]
 {\begin{proof}[\raisedtarget{#1}Proof of \Cref{#1}]}
 {\end{proof}}
\newcommand{\raisedtarget}[1]{\MakeLinkTarget*{#1}}%

\newcommand{\proofref}[1]{\hyperlink{#1}{proof}}

\begin{document}
\section{Theorems}
\begin{theorem}\label{thm:some-theorem}
This is a theorem.
\end{theorem}

For an intuition, see the \proofref{thm:some-theorem}.

\appendix
\section{Proofs}
\begin{delayedproof}{thm:some-theorem}
This is a proof.
\end{delayedproof}
\end{document}
1
  • Thank you very much! You might want to think about whether to add this answer also to the original question Commented Nov 25 at 15:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.