# User-defined printbibliography with conditional formatting on count of entry-type

Now that I got most of my pieces in place, I'm trying to work my custom "\printbibliography" command. I'm using the "article" class, but I take the.

In short, I need to create a custom command which create 2 types of bilbigraphy, depending on the presence of cited material of custom type "message". But the same would apply to any bibliography type, so I slightly change my code so that the "message" type is any kind of "X" entry type.

I need the following :

• A bibliograhphy heading, appearing in the Table of content
• A conditional test on the existence of a type of entries.
• If no element of type "X" is present, then I print the bibliography
• If at least 1 element of type "X" is present I need to split the bibliography into 2 subheadings, with different title. These titles must not be in the table of content.

This code works for me, in the case "with X entry" :

\newcommand{\printlegalbibliography}{%

\printbibliography[type = X, heading=subbibliography, title={Documents Officiels}]
}


I'd like to change it to something like this :

if(bibliography not contains any X entry type)
{
}
else
{
\printbibliography[type = X, heading=subbibliography, title={Documents Officiels}]
}


Questions:

1. Is there a command to code this part "bibliography not contains any X entry type" ?
2. What is the correct code for and if-else form in this type of context ?

I simply copy-pasted the code of @moewe Then I replaced with the relevant custom type (@message)

And it worked hassle-free !

Let's for the moment assume your "type X" is @online.

First we need to count the number of entries for each type, this is done in \AtDataInput. In \printlegalbibliography we only need to check if there were any @online entries

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

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

\makeatletter
\AtDataInput{%
\ifltxcounter{blx@typecount@\thefield{entrytype}@\the\c@refsection}
{}
{\newcounter{blx@typecount@\thefield{entrytype}@\the\c@refsection}}%
\stepcounter{blx@typecount@\thefield{entrytype}@\the\c@refsection}}

\newcommand{\printlegalbibliography}{%
\ifltxcounter{blx@typecount@online@\the\c@refsection}
{}
{\newcounter{blx@typecount@online@\the\c@refsection}}%
\ifnumgreater{\value{blx@typecount@online@\the\c@refsection}}{0}
\printbibliography[type = online, heading=subbibliography, title={Documents Officiels}]}
\makeatother

\begin{document}
\section{Two online sources}
\cite{sigfridsson,markey,ctan}
\printlegalbibliography

\newrefsection
\section{No online sources}
\cite{sigfridsson}
\printlegalbibliography
\end{document}


• Hi, this is perfect. At the moment, I only plan to use a single bibliography for my document, hence the first proposition is working just fine, thanks ! Edit: actually, there is only a single version of the code now, so I'll test it again tomorrow with your version. – XaWin Apr 23 '18 at 21:00