2

Is there a way to define a label within \printbibliography in order to automatically get the number of references.

I would typically like to do:

\section{Articles (\ref{no_articles})}

\printbibliography[heading=none, keyword=my_article]\label{no_articles}

But unfortunately, \ref{no_articles} points to the section number and not to the total number of references.

Many thanks!

leparc
  • 163
  • The label will never return the number of references. If you really need to know how many refs you have, just choose a numbered style, run your file again, find out how many there are, and undo the style -- of course if you're already using a numeric style you always know how many there are. – user574859 Jul 20 '22 at 10:37
  • 1
    I think https://tex.stackexchange.com/questions/163451/total-number-of-citations can be used here as well. – Marijn Jul 20 '22 at 20:50
  • 1
    See for example https://tex.stackexchange.com/q/404238/35864 and https://tex.stackexchange.com/q/454182/35864. – moewe Jul 21 '22 at 04:56

1 Answers1

4

Many thanks to @Marijn and @moewe, indeed the following did the trick:

In the preamble:

\usepackage{totcount}
\newtotcounter{no_refs}
\AtEveryBibitem{\ifkeyword{my_keyword}{\stepcounter{no_refs}}{}}

And later in the document:


\subsection{References (\the\totvalue{no_refs})}
\printbibliography[heading=none, keyword=my_keyword]

NB: I have read that \AtNextBibliographycan be used to reset all counters after a previous printbibliography statetment, but this did not work here, the counter kept accumulating.

Pertinax
  • 260
leparc
  • 163