1

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}{%
\printbibheading[title={Bibliographie}, heading=bibintoc]

\printbibliography[nottype = X, heading=subbibliography, title={Doctrine}]
\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)
{
    \printbibliography[title={Bibliographie}, heading=bibintoc]
}
else
{
\printbibheading[title={Bibliographie}, heading=bibintoc]
\printbibliography[nottype = X, heading=subbibliography, title={Doctrine}]
\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 ?

Accepted answer

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

And it worked hassle-free !

2

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}

\addbibresource{biblatex-examples.bib}

\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}
    {\printbibheading[title={Bibliographie}, heading=bibintoc]%
     \printbibliography[nottype = online, heading=subbibliography, title={Doctrine}]%
     \printbibliography[type = online, heading=subbibliography, title={Documents Officiels}]}
    {\printbibliography[title={Bibliographie}, heading=bibintoc]}}
\makeatother

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

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

enter image description here

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.