[Tex/LaTex] biblatex and new line for DOI, URL and Eprint

biblatex

I've been playing around with biblatex a little and, since I am tired of broken DOIs, URLS and other eprint links, I would like to use a biblatex style which implements a new line for these fields. I started from the standard.bbx file and in the article style, I replaced

\newunit\newblock
\usebibmacro{doi+eprint+url}

by

\newline
\usebibmacro{doi+eprint+url}

There is something wrong since a dot (.) is added at the beginning of the DOI line in the final bibliography and a new line is added even though the doi field is empty. Is there a way to fix this?

Then, I wanted to go a bit further by having a new line for each of the DOI, URL, EPRINT, then something like:

\newline
\usebibmacro{doi}
\newline
\usebibmacro{url}
\newline
\usebibmacro{eprint}

by replacing \newbibmacro*{doi+eprint+url} by \newbibmacro*{doi}, \newbibmacro*{eprint} and \newbibmacro*{url} (copy-paste process of the last lines of standard.bbx) and by replacing \usebibmacro{doi+eprint+url} by the lines above but unfortunately, it does not work. I'd be happy to hear from you on this.

Best Answer

\setunit is an alternative to \newunit that allows you to set punctuation instead of \newunitpunct (which is typically a period plus a space). The really neat thing about \newunit and \setunit is that you don't need to worry about generating excessive punctuation, particularly when some fields are missing.

The code below defines a new bibliography macro bbx:parunit. It issues \setunit to generate line breaks only in the bibliography. With the option setting backref=true, bbx:parunit also prints the back reference immediately before the first line break. Edits are applied to generic bibliography macros from biblatex.def so that the solution should work with most styles.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage[american]{babel}
\usepackage[colorlinks]{hyperref}
\usepackage[style=verbose,backref=true]{biblatex}

\newbibmacro*{bbx:parunit}{%
  \ifbibliography
    {\setunit{\bibpagerefpunct}\newblock
     \usebibmacro{pageref}%
     \clearlist{pageref}%
     \setunit{\adddot\par\nobreak}}
    {}}

\renewbibmacro*{doi+eprint+url}{%
  \usebibmacro{bbx:parunit}% Added
  \iftoggle{bbx:doi}
    {\printfield{doi}}
    {}%
  \iftoggle{bbx:eprint}
    {\usebibmacro{eprint}}
    {}%
  \iftoggle{bbx:url}
    {\usebibmacro{url+urldate}}
    {}}

\renewbibmacro*{eprint}{%
  \usebibmacro{bbx:parunit}% Added
  \iffieldundef{eprinttype}
    {\printfield{eprint}}
    {\printfield[eprint:\strfield{eprinttype}]{eprint}}}

\renewbibmacro*{url+urldate}{%
  \usebibmacro{bbx:parunit}% Added
  \printfield{url}%
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addspace}%
     \printtext[urldate]{\printurldate}}}

\addbibresource{biblatex-examples.bib}

\begin{document}
\null\vfill\noindent
Filler text.\footcite{bertram,kastenholz,ctan,itzhaki}
\printbibliography
\end{document}

enter image description here