3

I have theorems, e.g., a lemma below whose proof is provided in the appendix. How to make the lemma clickable and directed to its restatable (or proof) in the appendix?

Here is the illustration.

enter image description here

Here is the minimal code for the figure above.

\documentclass{article}
\usepackage{amsmath, amsthm, thm-restate}
\newtheorem{lemma}{Lemma}

\begin{document}

\begin{restatable}[Ni]{lemma}{mylemma}\label{thm:mylemma}
    Given us be the knight, we say Ni. 
\end{restatable}


\appendix 
\section{Appendix: proofs}

\mylemma*
\begin{proof}
It is true, Ni!
\end{proof}

\end{document}

1 Answer 1

0

Here is an option that uses thmtools' internal \ifthmt@thisistheone to test if we're in the original or restated theorem. The idea is to define a theorem style, taking inspiration from egreg's answer here, where the heading checks whether or not the theorem is restated, then links appropriately. Use \NewLinkedTheorem exactly as you would \newtheorem.

\documentclass{article}
\usepackage{amsthm,thmtools,kantlipsum}
\usepackage[colorlinks]{hyperref}

\makeatletter
\newtheoremstyle{linkedrestate}
  {}%      Space above, empty = `usual value'
  {}%      Space below
  {\itshape}% Body font
  {}%         Indent amount (empty = no indent, \parindent = para indent)
  {\bfseries}% Thm head font
  {.}%        Punctuation after thm head
  { }%     Space after thm head: " " = normal interword space;
     %     \newline = linebreak
  {%
    \ifthmt@thisistheone
    \hyperlink{restated:\thisthm}{\thmname{#1} \thmnumber{#2}\unskip}%
    \thmnote{ (#3)}%
    \hypertarget{orig:\thisthm}{}%
    \else
    \hyperlink{orig:\thisthm}{\thmname{#1} \thmnumber{#2}\unskip}%
    \thmnote{ (#3)}%
    \hypertarget{restated:\thisthm}{}%
    \fi
    }% Thm head spec

\NewDocumentCommand{\NewLinkedTheorem}{s m o m o}{
    \edef\current@thmstyle{\thmt@outerstyle} % store current theorem style
    \IfBooleanTF{#1}{
        \newtheorem*{#2}{#4}
        \theoremstyle{linkedrestate}
        \newtheorem*{linked-#2}{#4}
        \ExpandArgs{e}\theoremstyle{\current@thmstyle} % reset theorem style
        }{
        \IfNoValueTF{#3}{
            \IfNoValueTF{#5}{
                \newtheorem{#2}{#4}
                }{
                \newtheorem{#2}{#4}[#5]
                }
            }{
            \newtheorem{#2}[#3]{#4}
            }
        \theoremstyle{linkedrestate}
        \newtheorem{linked-#2}[#2]{#4}
        \ExpandArgs{e}\theoremstyle{\current@thmstyle} % reset theorem style
        }
    }
\makeatother

\NewDocumentEnvironment{linkrestatable}{O{} m m +b}{%
    \def\thisthm{#3}%
    \begin{restatable}[#1]{linked-#2}{#3}
    #4
    \end{restatable}
    \AddToHook{cmd/#3/before}{\def\thisthm{#3}}%
    }{}

\NewLinkedTheorem{theorem}{Theorem}[section]
\NewLinkedTheorem*{KL}{Klein's Lemma}

\begin{document}

\section{Theorems}

\begin{linkrestatable}{theorem}{mytag}
\kant[2][1]
\end{linkrestatable}

\begin{theorem}
\kant[3][1]
\end{theorem}

\mytag*

\begin{linkrestatable}{KL}{anothertag}
\kant[4][1]
\end{linkrestatable}

\begin{KL}
\kant[5][1]
\end{KL}

\anothertag*

\end{document}

thms

You must log in to answer this question.

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