以下是一个例子:
\documentclass{article}
\begin{filecontents}{example.bib}
@article{doe-2015,
Author = {J. Doe and M. Mouse and D. Duck and W. Disney},
Doi = {ija.foo/bar},
Journal = {International Journal of Articles},
Title = {Title of the article},
Year = {2015}}
\end{filecontents}
\usepackage[ backend=biber, style=authoryear-comp, natbib ]{biblatex}
\bibliography{example.bib}
\usepackage[ colorlinks, citecolor=red ]{hyperref}
\begin{document}
\citep{doe-2015}
\printbibliography
\end{document}
在输出 pdf(我使用的是 XeLaTeX)中,文本引用有指向参考部分页面的链接。我想更改这些文本内链接,使它们指向 DOI url(如果存在)。欢迎提出任何建议。
答案1
我们可以重新定义bibhyperref
格式(产生引文的链接位)以优先链接到 DOI、URL 电子印本等。
\DeclareFieldFormat{bibhyperreforig}{\bibhyperref{#1}}
\DeclareFieldFormat{bibhyperref}{%
\ifhyperref
{\iffieldundef{doi}
{\iffieldundef{eprint}
{\iffieldundef{url}
{\printtext[bibhyperreforig]{#1}}
{\href{\thefield{url}}{#1}}}
{\mkhrefeprint{#1}}}
{\href{http://dx.doi.org/\thefield{doi}}{#1}}}
{\printtext[bibhyperreforig]{#1}}}
链接到电子版印刷品相当棘手,所以我们需要一个辅助函数(这完全是由于奥黛丽)。
\makeatletter
\newrobustcmd*{\mkhrefeprint}[1]{%
\iffieldequalstr{eprinttype}{arxiv}
{\href{http://arxiv.org/\abx@arxivpath/\thefield{eprint}}{#1}}
{\iffieldequalstr{eprinttype}{hdl}
{\href{http://hdl.handle.net/\thefield{eprint}}{#1}}
{\iffieldequalstr{eprinttype}{jstor}
{\href{http://www.jstor.org/stable/\thefield{eprint}}{#1}}
{\iffieldequalstr{eprinttype}{pubmed}
{\href{http://www.ncbi.nlm.nih.gov/pubmed/\thefield{eprint}}{#1}}
{\iffieldequalstr{eprinttype}{googlebooks}
{\href{http://books.google.com/books?id=\thefield{eprint}}{#1}}
{#1}}}}}}
\makeatother
现在引用链接指向 DOI、电子印刷本、URL 或参考书目(按此顺序)。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[backend=biber, style=authoryear-comp, natbib]{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage[colorlinks, citecolor=red ]{hyperref}
\DeclareFieldFormat{bibhyperreforig}{\bibhyperref{#1}}
\DeclareFieldFormat{bibhyperref}{%
\ifhyperref
{\iffieldundef{doi}
{\iffieldundef{eprint}
{\iffieldundef{url}
{\printtext[bibhyperreforig]{#1}}
{\href{\thefield{url}}{#1}}}
{\mkhrefeprint{#1}}}
{\href{http://dx.doi.org/\thefield{doi}}{#1}}}
{\printtext[bibhyperreforig]{#1}}}
\makeatletter
\newrobustcmd*{\mkhrefeprint}[1]{%
\iffieldequalstr{eprinttype}{arxiv}
{\href{http://arxiv.org/\abx@arxivpath/\thefield{eprint}}{#1}}
{\iffieldequalstr{eprinttype}{hdl}
{\href{http://hdl.handle.net/\thefield{eprint}}{#1}}
{\iffieldequalstr{eprinttype}{jstor}
{\href{http://www.jstor.org/stable/\thefield{eprint}}{#1}}
{\iffieldequalstr{eprinttype}{pubmed}
{\href{http://www.ncbi.nlm.nih.gov/pubmed/\thefield{eprint}}{#1}}
{\iffieldequalstr{eprinttype}{googlebooks}
{\href{http://books.google.com/books?id=\thefield{eprint}}{#1}}
{#1}}}}}}
\makeatother
\begin{document}
\citep{kastenholz,cicero,baez/article,ctan}
\printbibliography
\end{document}