# Reference to proof prints section instead

I have several theorems in a document with the proofs in the appendix. After some theorem, I want to refer to the proof and, using the hyperref package, I want to make the reference clickable to avoid scrolling.

However, adding a label to the proof and then referring to it (I am also using the cleveref package) refers and links to the respective section which holds the proof instead, in my example to the appendix.

MWE:

\documentclass{article}
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{cleveref}
\newtheorem{theorem}{Theorem}

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

For an initution, see the proof.

For an intiution, see \cref{proof:some-theorem}.

\appendix
\section{Proofs}
\begin{proof}[Proof of \Cref{thm:some-theorem}]
\label{proof:some-theorem}
This is a proof.
\end{proof}
\end{document}


How can I get the reference to print "proof" (or "proof of Theorem 1") instead, with the hyperlink also linking to the proof?

• My mistake seems to be that I am trying to label/reference an unnumbered item/environment. Using \hypertarget and \hyperlink works as a solution, though I still have to set the caption "proof" manually. – Bernd Sep 11 '18 at 8:30
• I am now using (apologies for the formatting): \documentclass{article} \usepackage{amsthm} \usepackage{hyperref} \usepackage{cleveref} \newtheorem{theorem}{Theorem} \begin{document} \section{Theorems} \begin{theorem}\label{thm:some-theorem} This is a theorem. \end{theorem} For an initution, see the proof. For an intiution, see the \hyperlink{proof:some-theorem}{proof}. \appendix \section{Proofs} \begin{proof}[Proof of \Cref{thm:some-theorem}] \hypertarget{proof:some-theorem} This is a proof. \end{proof} \end{document} – Bernd Sep 11 '18 at 8:31
• You don't have to add comments, you can edit your question. – Ulrike Fischer Sep 11 '18 at 8:39

The problem was indicated by the O.P. already:

proof is a counterless environment, i.e. there is no counter connected to it, as such \label inside proof will grab the last \@currentlabel, this has been modified by \refstepcounter{section} in \section{Proofs}, so \cref reports section or appendix for this.

My approach adds a \prooflabel that connects to the counter value of the theorem counter from the relevant label that is involved, such that Theorem 147 will provide Proof 147.

In order to simplify this, \crtcrefcountervalue (a new addition to crossreftools package) is applied and injected into the proofcntr counter.

I added cleveref names for the proofcntr as well.

\documentclass{article}
\usepackage{etoolbox}

\usepackage{xparse}

\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{cleveref}

\usepackage{crossreftools}

%%% The following lines are not necessary with crossreftools v.0.8
\makeatletter
\@ifundefined{crtcrefcountervalue}{%
\newcommand{\crt@crefundefinedcountervalue}{1977}

\newcommand{\crtcrefcountervalue}[1]{%
\crtcrefifundefinedlabel{#1}{%
\crt@crefundefinedcountervalue%
}{%
\crtcrefnumber{#1}%
}%
}
}{}

\makeatother

\newtheorem{theorem}{Theorem}

\newcounter{proofcntr}
\crefname{proofcntr}{proof}{proofs}
\Crefname{proofcntr}{Proof}{Proofs}

\NewDocumentCommand{\prooflabel}{+m+m}{%
\setcounter{proofcntr}{\numexpr\crtcrefcountervalue{#1}-1}%
\refstepcounter{proofcntr}%
\label{#2}%
}

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

For an intuition, see the proof.

For an intuition, see \cref{proof:some-theorem}, but with respect to \cref{thm:some-really-important-theorem} see the best proof ever: \cref{proof:some-really-important-theorem}

\begin{theorem}\label{thm:some-really-important-theorem}
Brontosaurs are thin at one end, thick in the middle and thin at the other end.

Source: Anne Elk (Misses).
\end{theorem}

\appendix
\section{Proofs}
\begin{proof}[Proof of \Cref{thm:some-theorem}]
\prooflabel{thm:some-theorem}{proof:some-theorem}
This is a proof.
\end{proof}

\begin{proof}[Proof of \Cref{thm:some-really-important-theorem}]
\prooflabel{thm:some-really-important-theorem}{proof:some-really-important-theorem}

The source is Anne Elk (Misses), that's enough ;-)
\end{proof}

\end{document}


You can make bidirectional links using the same label.

\documentclass{article}
\usepackage{amsthm}
\usepackage{cleveref}

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

\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}


The picture shows that the link “proof” refers to the correct proof. Raising the \hypertarget is needed or the link would point to the baseline of the proof's first line.