该hyperref
手册似乎没有记录独立打开/关闭不同类型链接(引用、url、交叉引用、文件、目录、脚注)的方法。
一种可能的情况是启用所有使用\href
(url 链接) 创建的链接,但禁用所有其他类型的链接。另一种情况是启用所有引用链接,但禁用所有其他类型的链接。
怎样才能做到这一点?
一个相关的问题是选择性关闭超链接,但它只涉及如何关闭交叉引用链接。
答案1
该软件包hyperref
仅支持关闭“超级功能”的可能选项的子集:
bookmarks=false
:书签/大纲pdfpagelabels=false
:PDF 页面标签hyperfootnotes=false
:脚注hyperindex=false
: 指数pageanchor=false
:页面锚点- ...
还hyperref
提供环境NoHyper
。
仅限 URL 链接
修改后的版本NoHyper
可用于禁用除 URI 链接之外的所有链接。
例如:
\documentclass[12pt]{article}
\usepackage[a5paper,landscape]{geometry}% smaller test image for TeX.sx
\usepackage[
bookmarks=false,
pdfpagelabels=false,
hyperfootnotes=false,
hyperindex=false,
pageanchor=false,
colorlinks,
]{hyperref}
\makeatletter
\let\saved@hyper@linkurl\hyper@linkurl
%\let\saved@hyper@linkfile\hyper@linkfile
\let\saved@hyper@link@\hyper@link@
\AtBeginDocument{%
% Since the whole document is affected, only the \begin part of
% environment `NoHyper' is needed.
\NoHyper
\let\hyper@linkurl\saved@hyper@linkurl % needed by \url
%\let\hyper@linkfile\saved@hyper@linkfile % needed by \href{<file>}
\let\hyper@link@\saved@hyper@link@ % needed by \href{<url>}
}
\makeatother
\begin{document}
\tableofcontents
\section{Hello World}
\label{sec:hello}
This is section \ref{sec:hello} on page \pageref{sec:hello}.%
\footnote{This is a footnote}\\
\url{http://tex.stackexchange.com/}\\
\href{http://tex.stackexchange.com/}{\TeX\ Stack Exchange}\\
\IfFileExists{t.pdf}{\href{t.pdf}{Local PDF file}}{(No local file.)}\\
\cite{abc} is a good book.
\begin{thebibliography}{9}
\bibitem{abc} A good book.
\end{thebibliography}
\end{document}
仅引用链接
以下示例尝试启用引文链接(未使用 测试natbib
)。还需要启用锚点以获取引文的链接目标。
\documentclass[12pt]{article}
\usepackage[a5paper,landscape]{geometry}% smaller test image for TeX.sx
\usepackage[
bookmarks=false,
pdfpagelabels=false,
hyperfootnotes=false,
hyperindex=false,
pageanchor=false,
colorlinks,
]{hyperref}
\makeatletter
\let\saved@hyper@link@\hyper@link@
\let\saved@hyper@link\hyper@link
% anchors are needed for the citations
\let\saved@hyper@anchorstart\hyper@anchorstart
\let\saved@hyper@anchorend\hyper@anchorend
\def\textstring@cite{cite}
\def\new@hyper@link@[#1]{%
\def\@temp{#1}%
\ifx\@temp\textstring@cite
\expandafter\saved@hyper@link@
\else
\expandafter\disabled@hyper@link@
\fi
[{#1}]%
}
\def\new@hyper@link#1{%
\def\@temp{#1}%
\ifx\@temp\textstring@cite
\expandafter\saved@hyper@link
\else
\expandafter\disabled@hyper@link
\fi
{#1}%
}
\AtBeginDocument{%
\NoHyper
\let\disabled@hyper@link@\hyper@link@
\let\disabled@hyper@link\hyper@link
\let\hyper@link@\new@hyper@link@
\let\hyper@link\new@hyper@link
\let\hyper@anchorstart\saved@hyper@anchorstart
\let\hyper@anchorend\saved@hyper@anchorend
}
\makeatother
\begin{document}
\tableofcontents
\section{Hello World}
\label{sec:hello}
This is section \ref{sec:hello} on page \pageref{sec:hello}.%
\footnote{This is a footnote}\\
\url{http://tex.stackexchange.com/}\\
\href{http://tex.stackexchange.com/}{\TeX\ Stack Exchange}\\
\IfFileExists{t.pdf}{\href{t.pdf}{Local PDF file}}{(No local file.)}\\
\cite{abc} is a good book.
\begin{thebibliography}{9}
\bibitem{abc} A good book.
\end{thebibliography}
\end{document}