我正在尋找一種方法,biblatex
在沒有指定 DOI 的情況下僅列印 URL(在我的情況下,DOI 無論如何都會導致引用中的鏈接,從而使 URL 變得多餘)。
我想出了這個(但它似乎會導致無限循環,因為編譯未完成...):
\renewbibmacro*{url+urldate}{%
\iffieldundef{doi}
{\usebibmacro{url+urldate}}
{}%
}
似乎保存巨集\let
不起作用,因為+
...
知道如何正確執行此操作嗎?
M(N)網頁:
\documentclass{article}
\usepackage[style=authoryear-comp]{biblatex}
\usepackage{hyperref}
%\renewbibmacro*{url+urldate}{%
% \iffieldundef{doi}
% {\usebibmacro{url+urldate}}
% {}%
%
\addbibresource{\jobname.bib}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{key,
author = {Author, A.},
year = {2001},
title = {Title},
publisher = {Publisher},
archivePrefix = {arXiv},
arxivId = {1607.07249},
doi = {10.1007/978-3-319-49004-5_22},
eprint = {1607.07249},
url = {http://link.springer.com/10.1007/978-3-319-49004-5_22},
}
\end{filecontents}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
答案1
沒有\letbibmacro
(您可能會提出功能請求),但創建一個並不困難:
\documentclass{article}
\usepackage[style=authoryear-comp]{biblatex}
\usepackage{hyperref}
\newcommand{\letbibmacro}[2]{%
\csletcs{abx@macro@#1}{abx@macro@#2}%
}
\letbibmacro{orig-url+urldate}{url+urldate}
\renewbibmacro*{url+urldate}{%
\iffieldundef{doi}
{\usebibmacro{orig-url+urldate}}
{}%
}
\addbibresource{\jobname.bib}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{key,
author = {Author, A.},
year = {2001},
title = {Title},
publisher = {Publisher},
archivePrefix = {arXiv},
arxivId = {1607.07249},
doi = {10.1007/978-3-319-49004-5_22},
eprint = {1607.07249},
url = {http://link.springer.com/10.1007/978-3-319-49004-5{\_}22},
}
@book{key2,
author = {Author, A.},
year = {2001},
title = {Title},
publisher = {Publisher},
archivePrefix = {arXiv},
arxivId = {1607.07249},
eprint = {1607.07249},
url = {http://link.springer.com/10.1007/978-3-319-49004-5{\_}22},
}
\end{filecontents}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
答案2
對於您提出的問題,您已經得到了很好的答案,因此我想為您想要解決的問題添加兩個解決方案。
您可以使用
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=doi, final]
\step[fieldset=url, null]
\step[fieldset=urldate, null]
}
}
}
或者
\AtEveryBibitem{%
\iffieldundef{doi}
{}
{\clearfield{url}\clearfield{urlyear}}%
}
如果存在 DOI,則不列印 URL。
答案3
要有條件地列印 url,您可以將其包裝在\iffieldundef{doi}{}{}
\documentclass{article}
\usepackage[style=authoryear-comp]{biblatex}
\usepackage{hyperref}
% print url if no doi
\renewbibmacro*{doi+eprint+url}{%
\printfield{doi}
\newunit\newblock
\iftoggle{bbx:eprint}{
\usebibmacro{eprint}
}{}%
\newunit\newblock
\iffieldundef{doi}{
\usebibmacro{url+urldate}}
{}
}
\addbibresource{\jobname.bib}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{key,
author = {Author, A.},
year = {2001},
title = {Title},
publisher = {Publisher},
archivePrefix = {arXiv},
arxivId = {1607.07249},
doi = {10.1007/978-3-319-49004-5_22},
eprint = {1607.07249},
url = {http://link.springer.com/10.1007/978-3-319-49004-5{\_}22},
}
@book{keyx,
author = {Author, A.},
year = {2001},
title = {Title},
publisher = {Publisher},
archivePrefix = {arXiv},
arxivId = {1607.07249},
url = {http://link.springer.com/10.1007/978-3-319-49004-5{\_}22},
}
\end{filecontents*}
\begin{document}
\nocite{*}
\printbibliography
\end{document}