Wrapping existing bibmacro

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


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.


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}

Tags:

Biblatex