[Tex/LaTex] biber/biblatex: \printbibliography spits out section heading despite filters/checks

biberbiblatexsubdividing

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},%
  heading=subbibliography,%
  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.

I'd appreciate your help.

Best Answer

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},%
  heading=subbibliography,%
  keyword=authored,%
  keyword=recent,%
  sorting=ydnt,%
  filter=bookChapters]

\end{document}