0

I am trying to learn how to customize biblatex bibliographies using \defbibenvironment; in particular, trying to make a bibliography as compact as possible.

One specific tweak I'm interested in is removing the eprint field, but only for those entries that are also published in a journal, that is, those with a non-empty journaltitle field.

Is there a way to use \clearfield in the fourth argument of \defbibenvironment conditional on the value (or existence) of another field?

P.S.: I suggest \defbinenvironment only because that has worked for me in the past when I've had multiple bibliographies in a document with different styles. I would be happy with answers not using \defbinenvironment as long as they would allow for that.

2

1 Answer 1

1

You can test for the existence of fields with \iffieldundef{<field name>}{<true>}{<false>}. Do keep in mind that biblatex knows three different kinds of fields: plain fields, lists and name lists. Those are tested for with \iffieldundef, \iflistundef and \ifnameundef, respectively. You can find out the "type" of each field in the biblatex documentation.

Usually people don't get rid of fields in \defbibenvironment (even though that is technically possible), the more common idiom is

\AtEveryBibitem{%
  \iffieldundef{journaltitle}
    {}
    {\clearfield{eprint}}%
}

Note that \AtEveryBibitem applies only to the bibliography. If you also need to affect citations (including \fullcite) you need to duplicate the code in \AtEveryCitekey as well.

If you want to get rid of a field it is usually more elegant to use a Biber sourcemap instead of \clearfield. This clears out the field at the input stage, which means that the field is completely ignored and not just "forgotten about" very late in the game.

For your use case I would make the assumption that an entry has a non-empty journaltitle if and only if it is an @article so that we can go for

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[backend=biber, style=authoryear]{biblatex}

\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
      \pertype{article}
      \step[fieldset=eprint, null]
    }
  }
}

\addbibresource{biblatex-examples.bib}

\begin{document}
Lorem \autocite{sigfridsson,baez/article,baez/online,wassenberg}

\printbibliography
\end{document}

If you have @articles without journal/journaltitle (I personally think that this is wrong: @article is only the right choice if the article is actually published in a journal), then you can also explicitly test for journal/journaltitle (recall that the former is a legacy alias for the latter, that we need to resolve first)

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[backend=biber, style=authoryear]{biblatex}

\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
      \step[fieldsource=journal, fieldtarget=journaltitle]
      \step[fieldsource=journaltitle, final]
      \step[fieldset=eprint, null]
    }
  }
}

\addbibresource{biblatex-examples.bib}

\begin{document}
Lorem \autocite{sigfridsson,baez/article,baez/online,wassenberg}

\printbibliography
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .