首页 > 解决方案 > 将内联引文链接到 doi(而不是参考书目项目)?

问题描述

一个朋友给了我一个解决方案,可以在我的书目项目中添加指向 doi(或 url)的链接,这是通过修改 apa.bst 中的 format.title 宏来完成的:

FUNCTION {format.title}
{ title empty$
    { "" }
    { title "t" change.case$
      doi empty$
        {url empty$
            { }
            { "\href{" url * "}{" * swap$ * "}" * }
         if$}
        { "\href{http://dx.doi.org/" doi * "}{" * swap$ * "}" * }
      if$
    }
  if$
}

这很好用,但现在我想这样做,以便当我单击内联引文(由 \cite 或 \citep 生成)时,它链接到与参考书目项目相同的 url(或 doi)(能够做“文本->浏览器中的doi”而不是“文本->参考书目->浏览器中的doi”,每次我想查看参考文献时都会在pdf中丢失位置......)

任何人都知道 natbib/hyperref 交互发生在哪里以及如何“破解”它以链接到我的 url/doi 而不是围兜项目标签?

标签: latex

解决方案


正如评论中已经说过的,如果 bibtex 样式不能恰好产生您正在寻找的结果,那么使用 biblatex 会更好 - 事情更容易定制。

这是一个快速示例,如何将指向 doi 的链接包装在引文周围。年份仍将指向参考书目,因此您可以选择您想去的地方:

\documentclass{article}

\usepackage[style=apa]{biblatex}
\usepackage{hyperref}

\addbibresource{biblatex-examples.bib}

\makeatletter
\renewbibmacro*{cite}{%
  \iffieldequals{fullhash}{\cbx@lasthash}
% Multiple cites in one command
   {\setunit{\compcitedelim}%
    \usebibmacro{cite:plabelyear+extradate}}%
% Single cite
   {\ifnameundef{labelname}
% No author/editor
     {\usebibmacro{cite:noname}%
       \setunit{\printdelim{nameyeardelim}}%
       \usebibmacro{cite:plabelyear+extradate}%
       \savefield{fullhash}{\cbx@lasthash}}
% Normal cite
     {  \href{http://dx.doi.org/\thefield{doi}}{\ifnameundef{shortauthor}
       {\printnames{labelname}}%
       {\cbx@apa@ifnamesaved
         {\printnames{shortauthor}}
         {\ifnameundef{groupauthor}
           {\printnames[labelname]{author}}
           {\printnames[labelname]{groupauthor}}%
          \addspace\printnames[sabrackets]{shortauthor}}}%
       \setunit{\printdelim{nameyeardelim}}%
      \usebibmacro{cite:plabelyear+extradate}%
      \savefield{fullhash}{\cbx@lasthash}}}}%
   \setunit{\multicitedelim}}
\makeatother

\begin{document}

\cite{kastenholz,sigfridsson}

\printbibliography

\end{document}

在此处输入图像描述


推荐阅读