使用 hyperref 使 URL 不可点击

使用 hyperref 使 URL 不可点击

有人告诉我,我必须将本文档参考书目中的所有 URL 设为不可点击。但是,我正在使用hyperref在文档内进行内部链接(参见引文)。

我查看了包选项,hyperref但找不到使 URL 不可点击的选项。有秘诀吗?

更新 1: 这是一个 MWE,表明修改href似乎不起作用。

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

\begin{document}

\renewcommand\href[3][\relax]{#3}

Here's a cite:~\cite{ChaudhuriMS:11pperm}.


\bibliographystyle{IEEEtran}
\bibliography{example}
\end{document}

例如.bib:

@article{ChaudhuriMS:11pperm,
    Author = {Kamalika Chaudhuri and Claire Monteleoni and Anand Dilip Sarwate},
    Date-Added = {2014-07-15 22:54:03 +0000},
    Date-Modified = {2014-07-15 22:54:03 +0000},
    Journal = {Journal of Machine Learning Research},
    Local-Url = {pdfs/ChaudhuriMS11erm.pdf},
    Month = {March},
    Pages = {1069--1109},
    Title = {Differentially private empirical risk minimization},
    Url = {http://jmlr.csail.mit.edu/papers/v12/chaudhuri11a.html},
    Volume = {12},
    Year = {2011},
    Bdsk-Url-1 = {http://jmlr.csail.mit.edu/papers/v12/chaudhuri11a.html}}

我收到一条警告: Package hyperref Message: Driver (autodetected): hpdftex.这是否正在撤消 href 重新定义?请注意,我在 MacOS 上使用 pdflatex。

更新 2: 这是一个新的 MWE——似乎如果我在\newpage引用前面加上一个,它会使所有 URL 都可点击,如果不能,那么修复就有效了……我可以在我的文档中破解它,但我发现这种行为有点……出乎意料?是否\newpage清除了一些设置?

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{ChaudhuriMS:11pperm,
    Author = {Kamalika Chaudhuri and Claire Monteleoni and Anand Dilip Sarwate},
    Journal = {Journal of Machine Learning Research},
    Month = {March},
    Pages = {1069--1109},
    Title = {Differentially private empirical risk minimization},
    Url = {http://jmlr.csail.mit.edu/papers/v12/chaudhuri11a.html},
    Volume = {12},
    Year = {2011}}
\end{filecontents*}

\usepackage[colorlinks]{hyperref}

\begin{document}

Here is a cite: \cite{ChaudhuriMS:11pperm}.

\newpage % comment to make URL not clickable

\let\url\nolinkurl% Make \url be equivalent to \nolinkurl
\bibliographystyle{IEEEtran}
\bibliography{\jobname}
\end{document}

更新 3: 这是 TeXShop 生成的 .bbl 文件(也许我应该返回命令行?)。我仍然认为,当且仅当注释掉 时,链接才不可点击\newpage。.bbl 文件是完全相同的无论我是否评论该\newpage命令。

% Generated by IEEEtran.bst, version: 1.13 (2008/09/30)
\begin{thebibliography}{1}
\providecommand{\url}[1]{#1}
\csname url@samestyle\endcsname
\providecommand{\newblock}{\relax}
\providecommand{\bibinfo}[2]{#2}
\providecommand{\BIBentrySTDinterwordspacing}{\spaceskip=0pt\relax}
\providecommand{\BIBentryALTinterwordstretchfactor}{4}
\providecommand{\BIBentryALTinterwordspacing}{\spaceskip=\fontdimen2\font plus
\BIBentryALTinterwordstretchfactor\fontdimen3\font minus
  \fontdimen4\font\relax}
\providecommand{\BIBforeignlanguage}[2]{{%
\expandafter\ifx\csname l@#1\endcsname\relax
\typeout{** WARNING: IEEEtran.bst: No hyphenation pattern has been}%
\typeout{** loaded for the language `#1'. Using the pattern for}%
\typeout{** the default language instead.}%
\else
\language=\csname l@#1\endcsname
\fi
#2}}
\providecommand{\BIBdecl}{\relax}
\BIBdecl

\bibitem{ChaudhuriMS:11pperm}
\BIBentryALTinterwordspacing
K.~Chaudhuri, C.~Monteleoni, and A.~D. Sarwate, ``Differentially private
  empirical risk minimization,'' \emph{Journal of Machine Learning Research},
  vol.~12, pp. 1069--1109, March 2011. [Online]. Available:
  \url{http://jmlr.csail.mit.edu/papers/v12/chaudhuri11a.html}
\BIBentrySTDinterwordspacing

\end{the bibliography}

更新 4: 这种现象似乎只出现在苹果的 Preview PDF 阅读器中(解决方案由沃纳如果您在 Adob​​e 中查看 PDF,效果会很好。我仍然不知道为什么\newpage会造成这种差异,但至少我现在对 URL 有了合理的否认。谢谢!

答案1

要停用参考书目中的 URL 功能,请设置\url为相当于\nolinkurl(也由hyperref;参见章节4 附加用户宏hyperrefHTML 文档):

在此处输入图片描述

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{ChaudhuriMS:11pperm,
    Author = {Kamalika Chaudhuri and Claire Monteleoni and Anand Dilip Sarwate},
    Date-Added = {2014-07-15 22:54:03 +0000},
    Date-Modified = {2014-07-15 22:54:03 +0000},
    Journal = {Journal of Machine Learning Research},
    Local-Url = {pdfs/ChaudhuriMS11erm.pdf},
    Month = {March},
    Pages = {1069--1109},
    Title = {Differentially private empirical risk minimization},
    Url = {http://jmlr.csail.mit.edu/papers/v12/chaudhuri11a.html},
    Volume = {12},
    Year = {2011},
    Bdsk-Url-1 = {http://jmlr.csail.mit.edu/papers/v12/chaudhuri11a.html}}
\end{filecontents*}

\usepackage[colorlinks]{hyperref}

\begin{document}

Here's a cite:~\cite{ChaudhuriMS:11pperm}.

\let\url\nolinkurl% Make \url be equivalent to \nolinkurl
\bibliographystyle{IEEEtran}
\bibliography{\jobname}
\end{document}

答案2

假设您使用hyperref标准方式,则参考书目中的链接是使用创建的\href。您可以\href在参考书目开始之前重新定义命令来禁用这些链接。语法\href如下

\href[optional arguments]{url}{text}

您希望拾取第三个参数\href并丢弃其余参数(#1是可选参数)。因此,您需要类似以下内容:

\documentclass{article}
\cite{one_paper}
\cite{another_paper}
\begin{document}

\renewcommand\href[3][\relax]{#3}     % this is the crucial line

\bibliographystyle{alpha}
\bibliography{mypapers}
\end{\document}

如果您在参考书目之后出现了使用 hyperref 创建的链接,那么您应该“保存”原始\href命令,然后再恢复它:

\let\orighref=\href
\renewcommand\href[3][\relax]{#3}  
\bibliography{mypapers}
\let\href=\orighref

相关内容