# Making a theorem into a link

A link to another file can be created using the code

\href{run:/path/to/my/file.ext}{text displayed}


Now I'm use the amsthm package. What I'd like is for the phrase 'Theorem X' to be a link to another file (where the proof is written). Is this achievable?

• Have you looked into using the xr ("eXternal References) package? – Mico May 19 '13 at 13:01

## 1 Answer

Yes, it is. Just define a suitable theorem style:

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

\newtheoremstyle{linked}
{}%      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
{\href{run:\thislink}{\thmname{#1} \thmnumber{#2}}\thmnote{ (#3)}}% Thm head spec

\newtheorem{thm}{Theorem}[section] % normal theorems

\theoremstyle{linked}
\newtheorem{innlinkthm}[thm]{Theorem} % theorems with link
\newenvironment{linkthm}[1]
{\def\thislink{#1}\innlinkthm}
{\endinnlinkthm}

\begin{document}
\section{Theorems}

\begin{thm}
This is a normal theorem.
\end{thm}

\begin{linkthm}{./somefile.pdf}
This has a link.
\end{linkthm}

\begin{linkthm}{./somefile.pdf}[Attribution]
This has the same link.
\end{linkthm}

\end{document}


• Thank you. I'm actually having difficulty getting the standard \href command to work in general, and this applies to your code. When I click the link, nothing happens. Is this is standard issue? I'm running Linux, Ubuntu. – goblin GONE May 19 '13 at 14:11
• So just to clarify, I am running your code exactly, and I have put somefile.pdf in the same directory. – goblin GONE May 19 '13 at 14:16
• @user18921 You may try file: instead of run:` – egreg May 19 '13 at 14:26
• Hmm still not working. Anyway, I don't want to burden you with mere troubleshooting. If I can't solve it on my own, I'll just ask another question. – goblin GONE May 19 '13 at 14:27
• @user18921 This may depend on the PDF viewer and on OS settings. On Mac OS X it works out of the box. – egreg May 19 '13 at 14:29