仅当 doi 不存在时才打印 url

仅当 doi 不存在时才打印 url

这个问题启发我让打印UrlEprint字段成为条件,这样只有当没有Doi字段时才会打印。任何指点都会很感激,

如果我使用下面发布的代码,我希望它删除我在这里用红色划掉的内容, url 和 Eprint 仅在没有 doi 时

\documentclass{article}

\usepackage[backend=bibtex, style=authoryear-comp, natbib=true]{biblatex} %for digital version 
\bibliography{\jobname}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Holland1986,
    Author = {Paul W. Holland},
    Doi = {10.1080/01621459.1986.10478354},
    Eprint = {http://www.tandfonline.com/doi/pdf/10.1080/01621459.1986.10478354},
    Journal = {Journal of the American Statistical Association},
    Keywords = {Applied_Economics},
    Number = {396},
    Pages = {945-960},
    Title = {Statistics and Causal Inference},
    Url = {http://www.tandfonline.com/doi/abs/10.1080/01621459.1986.10478354},
    Volume = {81},
    Year = {1986}}
@article{Heckman1990,
    Author = {James Heckman},
    Issn = {00028282},
    Journal = {The American Economic Review},
    Keywords = {_MSc},
    Number = {2},
    Pages = {313-318},
    Publisher = {American Economic Association},
    Title = {Varieties of Selection Bias},
    Url = {http://www.jstor.org/stable/2006591},
    Volume = {80},
    Year = {1990}}  
\end{filecontents}

\begin{document}

\citet{Holland1986} and \citet{Heckman1990} went for a swim. 
\printbibliography
\end{document}

答案1

要有条件地打印 URL,可以使用以下命令:

\documentclass{article}

\usepackage[backend=bibtex, style=authoryear-comp, natbib=true,url=false]{biblatex} %for digital version 
\bibliography{\jobname}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Holland1986,
    Author = {Paul W. Holland},
    Doi = {10.1080/01621459.1986.10478354},
    Journal = {Journal of the American Statistical Association},
    Keywords = {Applied_Economics},
    Number = {396},
    Pages = {945-960},
    Title = {Statistics and Causal Inference},
    Url = {http://www.tandfonline.com/doi/abs/10.1080/01621459.1986.10478354},
    Volume = {81},
    Year = {1986}}
@article{Heckman1990,
    Author = {James Heckman},
    Issn = {00028282},
    Journal = {The American Economic Review},
    Keywords = {_MSc},
    Number = {2},
    Pages = {313-318},
    Publisher = {American Economic Association},
    Title = {Varieties of Selection Bias},
    Url = {http://www.jstor.org/stable/2006591},
    Volume = {80},
    Year = {1990}}  
\end{filecontents}

% 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}}%
        {}%
    }

\begin{document}

\citet{Holland1986} and \citet{Heckman1990} went for a swim. 
\printbibliography
\end{document}

在此处输入图片描述

答案2

您的 MWE 使用 BibTeX,但如果您愿意切换到 Biber(您真的应该研究一下,Biber 提供更多功能并且 BibTeX 现在正式被视为遗留后端),您可以使用 Biber 的 sourcemap 功能。

\documentclass{article}

\usepackage[backend=biber, style=authoryear-comp]{biblatex} 

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=doi, final]
      \step[fieldset=url, null]
      \step[fieldset=eprint, null]
    }  
  }
}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Holland1986,
    Author = {Paul W. Holland},
    Doi = {10.1080/01621459.1986.10478354},
    Eprint = {http://www.tandfonline.com/doi/pdf/10.1080/01621459.1986.10478354},
    Journal = {Journal of the American Statistical Association},
    Keywords = {Applied_Economics},
    Number = {396},
    Pages = {945-960},
    Title = {Statistics and Causal Inference},
    Url = {http://www.tandfonline.com/doi/abs/10.1080/01621459.1986.10478354},
    Volume = {81},
    Year = {1986}}
@article{Heckman1990,
    Author = {James Heckman},
    Issn = {00028282},
    Journal = {The American Economic Review},
    Keywords = {_MSc},
    Number = {2},
    Pages = {313-318},
    Publisher = {American Economic Association},
    Title = {Varieties of Selection Bias},
    Url = {http://www.jstor.org/stable/2006591},
    Volume = {80},
    Year = {1990}}
\end{filecontents}

\begin{document}
\addbibresource{\jobname.bib}

\textcite{Holland1986} and \textcite{Heckman1990} went for a swim. 
\printbibliography
\end{document}

Heckman, James (1990)。“选择偏差的种类”。《美国经济评论》80.2,第 313-318 页。网址:http://www.jstor.org/stable/2006591.//Holland, Paul W. (1986)。“统计与因果推断”。《美国统计协会杂志》81.396,第 945-960 页。doi:10.1080/01621459.1986.10478354。

答案3

这不是一个真正的tex解决方案,但如果你正在使用佐特罗更好的 BibTex您可以打开Preferences>Better BibTeX并且只导出一个

当参考文献同时具有 DOI 和 URL 时,导出

相关内容