# biber/biblatex: \printbibliography spits out section heading despite filters/checks

With a setup as reproduced below, I end up with a section heading "Book Chapters" being produced although there is no bib entry to be printed. This leaves me (in my complete setting) with a bunch of empty headings for empty bib sections.

A sample document:

\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

\usepackage{textcomp}
\usepackage[autostyle]{csquotes}

\usepackage{filecontents}
\usepackage[style=alphabetic,%
backend=biber,%
language=english,%
isbn=false,%
url=true,%
maxbibnames=99%
]{biblatex}

\begin{filecontents*}{test.bib}
@inbook{my:key,
author    = {AAA BBB and CCC DDD},
title     = {An Introduction},
year      = {2012},
booktitle = {YYY},
pages     = {111-222},
publisher = {LePub},
series    = {The Series},
keywords   = {authored}
}
\end{filecontents*}

\defbibfilter{bookChapters}{%
type=inbook or type=incollection
}

\defbibcheck{byYear}{%
\iffieldint{year}
{\ifnumless{\thefield{year}}{2013}
{\skipentry}
{}}
{\skipentry}
}

\bibliography{test}

\begin{document}
\nocite{*}

\printbibliography[title={Book Chapters},%
check=byYear,%
keyword=authored,%
sorting=ydnt,%
filter=bookChapters]

\end{document}


I crawled the biblatex reference, but it did not come up with a solution for me. I am running biber 1.1 and biblatex 2.1.

-
biblatex doesn't know your bibliography is empty at the time the heading is printed. Filtering is done on a per-item basis; empty bibliographies are detected once the last item is processed. –  Audrey Sep 27 '12 at 14:47
Thx for your response. Maybe I must clarify: My bibliography (*.bib) is not empty. In the above scenario, the filter "byYear" does not leave a single entry to be printed. How should I determine upfront whether there will be any matching entries in a given bib? That defeats the purpose of filtering, doesn't it? –  sts Sep 27 '12 at 14:59
I should add: I apply the biblatex filtering in an automated manner to a series of *.bib resources that I cannot change/control upfront. –  sts Sep 27 '12 at 15:09
The purpose of filtering is to omit some entries, not all of them. You can filter by category instead. Entries can be counted and added to categories in \AtDataInput. –  Audrey Sep 27 '12 at 15:18
Mmmh. Is \AtDataInput the recommended way to exclude (and to omit) all entries which date prior to a certain year so that \printbibliography does not print, actually, in case of an empty bib? So, to clarify, I create a helper category which stores all entries passing the year check in \AtDataInput ... and then I pass category=... to \printbibliography= –  sts Sep 27 '12 at 16:09

I came up with a solution based on \DeclareSourcemap and an auxiliary keyword. I observed that keyword= constraints will have \printbibliography, well, not printing (including the section heading) if a required keyword is not present in any of the entries. Exactly the behavior, I was looking for.

Therefore, I refactored my initial year check ("byYear" above) into a \map statement:

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite=true]{
\step[fieldsource=year,
match=\regexp{^20(0[8-9]|[1-9][0-9])$}, final] \step[fieldsource=keywords, match=\regexp{^}, replace=\regexp{recent,}] } } }  (which, here, inserts a keyword "recent" for all entries having a year value between 2008-2099) The rewritten example of above is: \documentclass[a4paper]{article} \pagestyle{empty} \usepackage[english]{babel} \usepackage[utf8]{inputenc} \usepackage{textcomp} \usepackage[autostyle]{csquotes} \usepackage{filecontents} \usepackage[style=alphabetic,% backend=biber,% language=english,% isbn=false,% url=true,% maxbibnames=99% ]{biblatex} \begin{filecontents*}{test.bib} @inbook{my:key, author = {AAA BBB and CCC DDD}, title = {An Introduction}, year = {2007}, booktitle = {YYY}, pages = {111-222}, publisher = {LePub}, series = {The Series}, keywords = {authored} } \end{filecontents*} \DeclareSourcemap{ \maps[datatype=bibtex]{ \map[overwrite=true]{ \step[fieldsource=year, match=\regexp{^20(0[8-9]|[1-9][0-9])$},
final]
\step[fieldsource=keywords, match=\regexp{^}, replace=\regexp{recent,}]
}
}
}

\defbibfilter{bookChapters}{%
type=inbook or type=incollection
}

\bibliography{test}

\begin{document}
\nocite{*}

\printbibliography[title={Book Chapters since 2008},%

Thanks for this. Could you please tell me how I write a \regexp that will give me the range 1912--2099? Thanks a million! –  Mårten Dec 16 '14 at 20:31