如何强制 hyperref 仅引用 \cite 而不引用 \citeauthor 或 \citeyear?

如何强制 hyperref 仅引用 \cite 而不引用 \citeauthor 或 \citeyear?

我只想hyperref在使用 and 时建立链接\cite,而不是使用\citeyearand \citeauthor。以下是示例:

\documentclass{article}
\usepackage[numbers]{natbib}
\usepackage{hyperref}

\begin{document}

\citeauthor{Wysocki1960} has shown something interesting in \citeyear{Wysocki1960} \cite{Wysocki1960}.

\bibliographystyle{plainnat}
\bibliography{test}
\end{document}

使用.bib 文件:

@article{Wysocki1960,
annote = {cited By (since 1996) 27},
author = {Wysocki, J.J.},
journal = {Journal of Applied Physics},
number = {3},
pages = {571--578},
title = {{Effect of temperature on photovoltaic solar energy conversion}},
volume = {31},
year = {1960}
}

在输出中,我只希望 [1] 作为链接出现。

答案1

\NAT@hyper@#1超链接由中定义的宏设置natbib.sty。使用etoolbox可以挂接到低级引用命令,\NAT@citexnum以使\NAT@hyper@非数字引用不执行任何操作。以下是示例。

\documentclass{article}
\usepackage[numbers]{natbib}
\usepackage[colorlinks]{hyperref}
\usepackage{etoolbox}

\makeatletter
\pretocmd{\NAT@citexnum}{\@ifnum{\NAT@ctype>\z@}{\let\NAT@hyper@\relax}{}}{}{}
\makeatother

\begin{filecontents}{\jobname.bib}
@Book{companion,
  author = {Goossens, Michel and Mittelbach, Frank and Samarin, Alexander},
  title = {The LaTeX Companion},
  edition = {1},
  publisher = {Addison-Wesley},
  location = {Reading, Mass.},
  year = {1994}}
@Book{adams,
  title = {The Restaurant at the End of the Universe},
  author = {Douglas Adams},
  series = {The Hitchhiker's Guide to the Galaxy},
  publisher = {Pan Macmillan},
  year = {1980}}
\end{filecontents}

\newcommand{\cmd}[1]{\texttt{\textbackslash #1}}

\begin{document}
\noindent
\cmd{citeauthor}: \citeauthor{adams}, \citeauthor{companion} \\
\cmd{cite}: \cite{adams}, \cite{companion} \\
\cmd{citeyear}: \citeyear{adams}, \citeyear{companion} \\
\cmd{citet}: \citet{adams}, \citet[see][p. 20]{adams} \\
multi-\cmd{citet}: \citet{companion,adams} \\
\cmd{citep}: \citep{adams}, \citep[see][p. 20]{companion} \\
multi-\cmd{citep}: \citep{companion,adams} \\
\cmd{citetext}, \cmd{citealp}: \citetext{see \citealp{companion}, or even better \citealp{adams}}
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}

在此处输入图片描述

相关内容