5

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}

enter image description here

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

3
  • 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, 2018 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, 2018 at 8:31
  • You don't have to add comments, you can edit your question. Sep 11, 2018 at 8:39

3 Answers 3

3

You can make bidirectional links using the same label.

\documentclass{article}
\usepackage{amsthm}
\usepackage[colorlinks]{hyperref}
\usepackage{cleveref}

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

enter image description here

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.

3

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{\crtrefundefinedcountervalue}[1]{\renewcommand{\crt@refundefinedcountervalue}{#1}}


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

enter image description here

2
  • This seems to work well unless you mix proofs of Lemmas and Theorems that have different counters.
    – Paul Wintz
    Aug 12 at 9:39
  • There's a pretty easy fix to my previous comment: Define a separate counter for each type of result: \newcounter{theoremproofcntr} \newcounter{lemmaproofcntr} Modify \prooflabel as \NewDocumentCommand{\prooflabel}{o +m+m}{% \setcounter{#1proofcntr}{\numexpr\crtcrefcountervalue{#2}-1}% \refstepcounter{#1proofcntr}% \label{#3}% } And label a proof of a theorem like \prooflabel[theorem]{result:pythagorean theorem}{proof:pythagorean theorem}
    – Paul Wintz
    Aug 12 at 9:54
0

How about this?

\documentclass{article}
\usepackage{amsthm}
\usepackage{hyperref}

\newtheorem*{theorem}{Theorem}

\begin{document}

\begin{theorem}
  \phantomsection\label{theorem:main}
  This is true.
\end{theorem}

\begin{proof}
  \phantomsection\label{proof:main-theorem}
  Obvious.
\end{proof}

The \hyperref[proof:main-theorem]{proof} of
the \hyperref[theorem:main]{theorem} is obvious.

\end{document}

You must log in to answer this question.

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