20

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.

pluton
  • 16,421

2 Answers2

23

\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

Audrey
  • 28,881
  • That's very nice but now, \footcite is a bit too long. I think that \footcite with the author, the year and the title + a numeric link to the full biblio at the end of the document (the way numeric style works now but the link [1] would be embedded in the \footcite) would be the best compromise. – pluton Sep 28 '11 at 22:20
  • Nice again and clearly usable. You think it is possible to control/reduce what is in the footnotes by keeping what is in the main references? Something like: Initials and family names for the authors; title; year; journal and no more? That'd be great ! – pluton Sep 28 '11 at 23:33
  • @pluton It is definitely possible, but I'd open that up as a new question as that problem is very style-specific and separate from your original question. – Audrey Sep 28 '11 at 23:39
  • I do not know now since your solution is very nice. I was thinking of the usual style=numeric and \footcite{ref1} (your first reference) would provide as a footnote : A. Bertram & R. Wentworth, "Gromov invariants for holomorphic maps on Riemann surfaces", J. Amer. Math. Soc (1996) [1] and the [1] would be linked to the full citation at the end organised by the usual numeric style, but that's just an idea. – pluton Sep 28 '11 at 23:41
  • about your very last comment, I'll open a new question as soon as possible. Many thanks! – pluton Sep 28 '11 at 23:44
  • One little more thing here is that the backref page will be indicated after the last of the doi, eprint and url fields and it looks odd. Also, redefining \DefineBibliographyStrings{english}{page = {p\adddot},pages = {p\adddot}} has no effect. – pluton Sep 29 '11 at 18:04
  • @pluton I've updated to solution to print back references before doi/eprint/url. This solution should not change the behaviour of any bibliography strings. Inserting your string redefinition has the expected result on my end - the page reference for Bertram & Wentworth changes from pp. to p.. – Audrey Sep 29 '11 at 18:44
  • Thanks. Maybe you could write a user guide : Biblatex by example :) Strange, I do not get the p. and pp. I'll try to figure out why. – pluton Sep 29 '11 at 19:08
  • Got it. The abbreviate=false option does not like the pp. and p. redefinition, that's unfortunate. – pluton Sep 29 '11 at 19:18
  • @pluton Good to hear you've figured out the problem. I'm actually not convinced a user guide on top of the biblatex documentation is necessary. The manual has many examples and there are sample tex files to get you started. Style files are well-organized so it easy to look under the hood to see how everything works. If the documentation isn't enough (or is maybe too much?), lockstep's posts on this site are pretty good at flattening that initial learning curve. – Audrey Sep 29 '11 at 19:37
  • Hmm, it prints (visited on [visited on 03/24/2012]). for me – letmaik Oct 10 '12 at 11:16
  • Got it... instead of \printtext[urldate]{\printurldate} use \printtext{\printurldate} – letmaik Oct 10 '12 at 11:25
9

You can't directly include \newline in the .bbx file as it is 'text' and will be out of position in the biblatex tracker. Instead, you need to use the \printtext macro

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

I'd probably make this a bit more sophisticated, and use \iffieldundef to conditionally include these new lines

\iffieldundef{doi}
  {}
  {%
    \printtext{\newline}%
    \usebibmacro{doi}%
  }%
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • Thanks. Sounds promising. And the {doi+eprint+url} environment could be redefined separately as \newbibmacro*{doi}{\iftoggle{bbx:doi}{\printfield{doi}}{}} plus the same for eprint and url? – pluton Sep 28 '11 at 17:15
  • I am not sure why Audrey removed the provided answer? – pluton Sep 28 '11 at 17:22
  • @pluton It had bug I wanted to fix. The post is back now. – Audrey Sep 28 '11 at 17:34