我使用的参考资料在字段中有地址url
。它们在我的.bib
文件中使用以下模板:ssrn.com/abstract=1234567
。
但是,生成的超链接也是ssrn.com/abstract=1234567
。这使得 pdf 阅读器不想打开链接,因为没有http://
前缀。为每个 URL 添加后者会(很繁琐,并且)在参考列表中占用太多空间。
问题:如何使 biblatex 生成类似\href{http://<url-field-content>}{<url-field-content>}
参考文献中的超链接?
(文件<url-field-content>
提供的信息在哪里.bib
)
\documentclass{article}
\usepackage[style=authoryear-comp]{biblatex}
\addbibresource{\jobname.bib}
\begin{filecontents}{\jobname.bib}
@book{key,
author = {Author, A.},
year = {2001},
title = {Title},
publisher = {Publisher},
url = {ssrn.com/abstract=1234567},
}
\end{filecontents}
\usepackage{filecontents}
\usepackage{hyperref}
\begin{document}
\nocite{key}
\printbibliography
\end{document}
答案1
您可以通过重新定义该url
字段来做到这一点。
% arara: pdflatex
% arara: biber
% arara: pdflatex
% arara: pdflatex
\begin{filecontents}{\jobname.bib}
@book{key,
author = {Author, A.},
year = {2001},
title = {Title},
publisher = {Publisher},
url = {ssrn.com/abstract=1234567},
}
\end{filecontents}
\documentclass{article}
\usepackage[style=authoryear-comp]{biblatex}
\DeclareFieldFormat{url}{%
\mkbibacro{URL}\addcolon\space
\href{http://#1}{\UrlFont#1}%
}
\addbibresource{\jobname.bib}
\usepackage{hyperref}
\begin{document}
\nocite{key}
\printbibliography
\end{document}
答案2
使用 Biber 的源映射。这样您就不必修改已经正确的 URL 字段。以下内容添加到http://
不url
以ftp://
、http://
或开头的字段https://
。
\documentclass{article}
\usepackage[style=authoryear-comp]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@online{bronto,
author = {Anne Elk},
title = {Towards a Unified Theory on Brontosauruses},
date = {1972-11-16},
url = {example.edu/~elk/bronto.pdf},
urldate = {2015-09-07},
}
@online{tric,
title = {A Theory on Triceratops},
author = {Anne Elk},
date = {1972-11-16},
url = {https://example.edu/~elk/tric.html#page11},
urldate = {2015-09-07},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\usepackage{hyperref}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=url, notmatch=\regexp{\A(ftp|https?)://}, final]
\step[fieldsource=url, match=\regexp{\A(.*)\Z}, replace=\regexp{http://$1}]
}
}
}
\begin{document}
\nocite{*}
\printbibliography
\end{document}