latex - 将内联引文链接到 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 而不是围兜项目标签?
解决方案
正如评论中已经说过的,如果 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}
推荐阅读
- jhipster - jhipster 的分离前端和 API
- javascript - 当我尝试切换时,Else 语句在“单击”事件中不起作用
- java - JPA 坚持的 OffsetDateTime 相差 2 小时
- wso2 - Wso2 身份服务器版本 5.3.0 OAuth 客户端密钥
- javascript - 使用NodeJS在数组中搜索关键字,只获取MongoDB中匹配的元素
- django - 使用电话和密码注册 Django 用户
- wpf - WPF 组合框不显示所选值
- angular - *ngFor 在模板上显示时无法使用我的数组
- ios - CoreData iOS 崩溃:_coordinator_you_never_successfully_opened_the_database_missing_directory
- c# - C# Selenium 使用带有用户名和密码的代理