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 @article
s 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}