将定理标题链接至 url

将定理标题链接至 url

在回答另一个问题时(这里),定理很好地链接到另一个文件。然而,当我尝试使用它链接到网站时(通过填写 \url{www. ... .com} 而不是 ./file.pdf),会出现错误消息(超出 Tex 容量)。有没有办法解决这个问题?

答案1

你必须将新的定理样式定义为

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

linkthm然后使用

\begin{linkthm}{http://tex.stackexchange.com}

MWE(借用该答案)

\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{\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}{http://tex.stackexchange.com}
This has a link.
\end{linkthm}

\begin{linkthm}{http://tex.stackexchange.com}[Attribution]
This has the same link.
\end{linkthm}

\end{document} 

输出

在此处输入图片描述

相关内容