7

I'm searching for a way to make biblatex only print URLs if there's no DOI specified (in my case the DOIs lead to a links in the refs anyhow, making the URL sort of redundant).

I came up with this (but it seems to cause an endless loop as compilation doesn't finish...):

\renewbibmacro*{url+urldate}{%
  \iffieldundef{doi}
    {\usebibmacro{url+urldate}}
    {}%
}

it seems saving the macro with \let doesn't work due to the +...

any idea how to do this properly?

M(N)WEB:

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

example

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. In particular, please add a complete minimal working example with bibliography (MWEB)! – CarLaTeX Apr 24 '17 at 15:17
  • done... is there some "inline preview" on tex.sx? – Jörn Hees Apr 24 '17 at 15:37
  • No, there isn't. You have to load your own image... – CarLaTeX Apr 24 '17 at 15:41
  • 3
    Note that your URL field should read url = {http://link.springer.com/10.1007/978-3-319-49004-5_22}. There is no need to escape special characters in URLs, indeed it has adverse effects to do so. – moewe Apr 24 '17 at 16:32
  • comes form mendeley bibtex export like that... fixed nevertheless... – Jörn Hees Apr 25 '17 at 16:24
8

There is no \letbibmacro (and you might file a feature request), but it's not difficult to create one:

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

enter image description here

5

You have already gotten great answers to the question you asked, so I thought I'd add two solutions for the problem that you want to solve.

You can use

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

or

\AtEveryBibitem{%
  \iffieldundef{doi}
    {}
    {\clearfield{url}\clearfield{urlyear}}%
}

to not print the URL if a DOI is present.

  • this is indeed nice to know and upvoted, but as i was in general after properly wrapping, the accept goes to egreg – Jörn Hees Apr 25 '17 at 16:28
4

To conditionally print the url, you could wrap it in \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}
  • hmm, my idea was not to create a code copy of the standards that might get outdated, upvote anyhow ;) – Jörn Hees Apr 24 '17 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.