# Print url only if doi not present

this question inspired me to make the printing of the Url and the Eprint field conditional, so that it only prints if there's no Doi field. Any pointers would be appreciated,

If I use the code posted below, I would like it to remove what I've striked out with red here,

\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}

• The inverse problem is over at tex.stackexchange.com/q/154864/35864 Apr 4, 2018 at 12:17
• I don't think Eprint = {http://www.tandfonline.com/doi/pdf/10.1080/01621459.1986.10478354}, is an eprint field. eprint is normally used for online repositories such as arXiv, JSTOR, Google Books where the URL can be shortened using some kind of unique identifier. Apr 4, 2018 at 12:48
• For example you may replace Url = {http://www.jstor.org/stable/2006591}, with eprint = {2006591}, eprinttype = {jstor}, Apr 4, 2018 at 12:49
• @moewe, thanks for linking that thread. I did see it, but I'm not really any good at writing functions in LaTeX/TeX. What do you use as the authoritative source in regard to what bibtex fields is meant for what? Like what is actually suppose to go in eprint and what about translators etc? Thanks. Apr 5, 2018 at 13:56
• The biblatex documentation has a short explanation about what each field does and what it means. The file biblatex-examples.bib contains good example usages of many fields. Apr 5, 2018 at 13:58

To conditionally print the URL you could use the following:

\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}


• You may want to protect a few line-ends there with % to avoid unwanted space. You could also add an answer using soucemaps similar to tex.stackexchange.com/a/154875/35864 Apr 4, 2018 at 12:17
• @moewe Thanks for your suggestion about the %! I'll leave the the sourcemap for you, our biblatex expert! Apr 4, 2018 at 12:30
• +1: This is a great answer and I would love to see this as a package option :). (@moewe) Jul 9, 2021 at 19:54

Your MWE uses BibTeX, but if you are willing to switch to Biber (you really should look into it, Biber offers more features and BibTeX is officially considered a legacy backend now), you can use Biber's sourcemap feature.

\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}

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


• Thanks. Did not know BibTeX is considered a legacy backend. Could you recommend any sources on the BibTeX versus Biber question? Apr 5, 2018 at 13:50
• @EricFail See §3.15 Using the fallback BibTeX backend of the biblatex docs: "To utilise all of the features described here, biblatex must be used with the Biber program as a backend. Indeed, the documentation in general assumes this. However, for a limited subset of use cases it is possible to use the long-established BibTeX program [...] as the supporting backend. This works in much the same way as for Biber with the only proviso being that BibTeX is much more limited as a backend." Apr 5, 2018 at 14:02
• This works well for plain entries like articles. However, for an inproceedings entry with a crossref to a proceedings entry this causes the bibliography to instead include the (even less desirable) URL of the proceedings entry. Is there an easy way to avoid this? May 27, 2021 at 8:52
• @bnord There is probably a way around that. But I expect the solution will be longer than is convenient to discuss in the comments, so I suggest you ask a new question (with an MWE for testing). May 27, 2021 at 13:57
• @Dr.ManuelKuehner The code already clears both URL and eprint fields if a DOI is present. (arXiv counts as eprint.) If that is not what you want and you can't find a way to extend this answer to do what you want, please ask a new question with an example and a detailed description of the desired result. Jul 10, 2021 at 12:04

This is not really a tex solution, but if you are using Zotero with Better BibTex you can open Preferences>Better BibTeX and only export one

• although not answering the original question, this helped me a lot. Thanks! Sep 30, 2021 at 13:42