I am creating an annotated bibliography. Is there a way of obtaining a count of the number of references in a bibliography meeting certain criteria and inserting that into a document?

For example using biblatex I create one section using:

\nocite{*} ;; include all references in .bib file
\printbibliography[keyword=MyProject,type=report,title=My project reports]

and another using:

\printbibliography[keyword=AnotherProject,type=report,title=Another project's reports]

Somewhere else in the document I would like to be able to put a table with counts of number of number of reports by project, or include these counts in text. So for example:

"This year, My Project produced XX reports, while Another Project produced YY reports."

Any ideas on how to get started on that?


Based on Maieul's excellent and quick answer, I have the following MWE:

My project produced \thearticles peer-reviewed articles and Another Project produced \theotherarticles peer-reviewed articles. \par 
Note - no numbers here.

\printbibliography[keyword=MyProject,title=My project peer-reviewed articles,type=article]
\printbibliography[keyword=AnotherProject,title=Another project peer-reviewed articles,type=article]
My project produced \thearticles peer-reviewed articles and Another Project produced \theotherarticles peer-reviewed articles. \par

This works


Where mybiblio.bib looks like:

author = { Other, A N},
title = { my article},
journal = { Some journal },
keywords = {MyProject},
year = {2000},
volume = {343},
pages = {230-8}
author = {Author, E and Author, M},
journal = {Some Journal},
keywords = {MyProject},
number = {4},
pages = {424--428},
title = {{Another article}},
volume = {6},
year = {1993}
author = {Author, F and Author, T },
journal = {Another journal},
keywords = {AnotherProject},
title = {{A third article}},
year = {1997}

However, as you will see I cannot refer to the counters earlier in the document than the \printbibliography commands. Is there any way to be able to refer to the counters early on?

3 Answers 3


Ok, so in your preamble, put

  {We have \therefs references}

And use \printbibliography[env=counter,options for selection]

Explanation: you create a new type of bibliography, called "counter". It defined by \defbibenvironment.

  1. Type of bibliography, here "counter"
  2. Secund argument : what is doing at the beginning of bibliography. In your case it's: a. Reset counter b. Say to print nothing when a entry is tested.
  3. What is printing at the end of bibliography.
  4. What is printing / executed at each entry.

Sorry for English. If ok, say to me. I will write a french article in my weblog.

  • And you also must write \defbibheading{counter}{} to have no heading in \printbibliography[heading=counter,env=counter,options for selection].
    – Maïeul
    Commented Aug 12, 2012 at 16:23
  • This works thanks - does what I need. Does take a LONG time to compile though once you have several combinations of categories and a big bibliography.
    – user8786
    Commented Aug 12, 2012 at 21:04
  • ok, cool. I publish in my weblog geekographie.maieul.net/…
    – Maïeul
    Commented Aug 12, 2012 at 21:24

You can count references in \AtDataInput. To avoid specifying the counting/filtering criteria twice, you can create categories.


\defbibheading{primary}{\subsection*{Primary sources}}
\defbibheading{secondary}{\subsection*{Secondary sources}}

  \ifboolexpr{ test {\ifkeyword{primary}} and not test {\ifentrytype{misc}} }
  \ifboolexpr{ test {\ifkeyword{secondary}} and not test {\iffieldundef{year}}
               and test {\ifnumless{\thefield{year}+0}{1980}} }

In this document, I cite \arabic{primary} primary works and \arabic{secondary}
secondary works.
% Filler text \parencite{aristotle:poetics,aristotle:rhetoric,nussbaum,hyman,pines}.
% \bibbycategory is a shorthand for:
% \printbibliography[heading=primary,category=primary]
% \printbibliography[heading=secondary,category=secondary]

This approach also works with BibTeX as the backend. \ifboolexpr provides a flexible way to combine individual tests. Further details can be found in the biblatex manual.

A limitation is that \AtDataInput doesn't distinguish between reference sections. If your document uses these (via the refsection option or the refsection environment), you can make the counters section-specific using some commands from etoolbox.



  \ifboolexpr{ test {\ifkeyword{primary}} and not test {\ifentrytype{misc}} }
  \ifboolexpr{ test {\ifkeyword{secondary}} and not test {\iffieldundef{year}}
               and test {\ifnumless{\thefield{year}+0}{1980}} }

Here you should only access the counter values with \theprimary and \thesecondary.

  • This looks interesting. Does it work with \nocite{*} or does it depend on explicit citation of each item in the bibliography? Can it be generalised to multiple criteria/keywords (eg type=report AND keyword=MyProject AND notkeyword=ProgressReport)? Thanks.
    – user8786
    Commented Aug 12, 2012 at 21:06
  • oh, it's a better way ! no problem of time for running. It's working with nocite. And you can make a lot of test : for exemple :\ifkeyword{toto}{\ifkeyword{titi}{}{\stepcounter{toto}}}{}. You should read the manual of biblatex : theres is a lot of test.
    – Maïeul
    Commented Aug 12, 2012 at 21:30
  • but the manual say Note that, if there are any refsection environments in the document and an entry is cited in more than one of them, the ⟨code⟩ may be executed multiple times for an entry. I don't know in your case. But why not.
    – Maïeul
    Commented Aug 12, 2012 at 21:35
  • @Audrey yes, that is why it could be a problem, in some context. But I think you suggestion is better than mine, for time processing.
    – Maïeul
    Commented Aug 12, 2012 at 22:18
  • This works well, and is fast. However I prefer Maieul's method since it uses the same selection criteria as \printbibligraphy. This allows me to set say \myprojectreports to "keyword=myproject,type=report" once and refer to it when counting and when generating the bibliography. Some of my selection criteria are quite complicated, so keeping a single copy is much easier. Thanks though - I'm sure this will come in useful someday.
    – user8786
    Commented Aug 13, 2012 at 12:11

I think, you could try this :

\printbibliography[keyword=MyProject,type=report,title=My project reports]
\printbibliography[keyword=MyProject,type=report,title=My project reports]
This year, My Project produced \thereports reports, while Another Project produced \thereports2 reports.

L.1 and L. 4 : creating counters L.2 and L. 6 : increments counters at each entry of bibliography. L. 7 : prints counter

see also http://geekographie.maieul.net/Une-bibliographie-commentee

  • Merci infiniment. Works very well. One question though - with this I can refer to the counter (\thereports) after the \printbibliography command, but not in a preceeding chapter or page. Is there anyway to set the scope of the counter so I can refer to it earlier on in the document. Or is there a "\printphantombibliography" command I can use early on to count but not print the number of citations?
    – user8786
    Commented Aug 12, 2012 at 11:05
  • sorry, I don't understand what do you want to do. Could you reformulate ? Maybe you could try in french ?
    – Maïeul
    Commented Aug 12, 2012 at 11:21
  • Salut. J'ai ajouté un MWE qui explique un peu. En fait la bibliographie aura plusieurs chapitres - un par projet - et je souhaite avoir au début du doc un chaptire de synthèse qui va presenter le nombre d'articles publié par chaque projet, le nombre de rapports techniques etc.
    – user8786
    Commented Aug 12, 2012 at 13:21
  • @user8786: Just move the \newcounter{...} lines to the preamble. As usual in such situation, you need to compile twice to get correct values.
    – Daniel
    Commented Aug 12, 2012 at 13:58
  • @Daniel: That gives me zeros in the main text, and the correct numbers in the bibliography, presumably since the value really is zero at that stage. I guess I somehow need to stop latex expanding the counters until after the bibliography has been printed?
    – user8786
    Commented Aug 12, 2012 at 14:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .