Total number of citations

I am trying find an easy way to get the total number of citations in my thesis (in the final document - not in my Libary.bib file!). I know that I can use \citenum{last_entry} to get the number of the last entry, but in case there is a new entry added later, this doesn't give me the total number of citations anymore. I found the package \usepackage{totcount} helpful, because it give you a super easy way to get the total number of figures, tables, etc.

My questions is: Is there a similar command for the total number of citations? I searched quite a bit, but didn't find anything helpful.

Just in case this info is needed - I use a numeric output such as:

[1] P. Drude, Physikal. Zeitschr. 1, 161 (1900)

Example of how I currently use the package totcount for the total number of figures, tables:

\documentclass{book}
\usepackage{totcount}
\newtotcounter{bibitems}
\newtotcounter{figure}
\regtotcounter{table}

\begin{document}
The total number of figures is \total{figure}, and the total number of tables is \total{table}.

\begin{figure}
[...]
\end{figure}

\begin{figure}
[...]
\end{figure}

\begin{table}
[...]
\end{end}

\begin{table}
[...]
\end{end}

\end{document}

-
I assume references, say you refer three time to the same thing, does this count as one or as three? – CommuSoft Mar 3 '14 at 14:02

You can do this using the totcount package.

\documentclass{article}
\usepackage{totcount}

\newtotcounter{citnum} %From the package documentation
\def\oldbibitem{} \let\oldbibitem=\bibitem
\def\bibitem{\stepcounter{citnum}\oldbibitem}

\begin{document}
This document contains \total{citnum}\ references.

\cite{Martin06} \cite{Fortran2008}

\begin{thebibliography}{1}

\bibitem{Martin06}
P.~A. Martin.
\newblock {\em Multiple Scattering. {Interaction} of Time-Harmonic Waves with
{$N$} Obstacles}.
\newblock Cambridge University Press, 2006.

\bibitem{Fortran2008}
Fortran standards technical~committee (J3).
\newblock Fortran 2008 language standard.
\newblock Technical Report J3/10-007, International Committee for Information
Technology Standards (INCITS), 2010.

\end{thebibliography}
\end{document}


Note that this works for bibtex bibliographies as well; I included the bibliography environment to make the example as simple as possible.

-
Does this work for a BibTeX bibliography as well? – Torbjørn T. Mar 3 '14 at 14:27
@TorbjørnT. --- Yes. I just included the bibliography environment to make the example as simple as possible. I'll edit the answer. – Ian Thompson Mar 3 '14 at 14:43
Aha! @IanThompson I was a that point already. But the number returned was always "0". Turned out that I adding \newtotcounter{citnum} etc. to the style file is not a good idea! Added to the header works great! Thx though! – Philipp Mar 3 '14 at 15:36

If you are allowed to perform a shell-escape, when LaTeX uses bibliography, a document.blg file is produced. In this file the following line appears:

...
You've used 8 entries,
...


So you can run

grep -P "You've used [0-9]+ entries," -m 1 "Document.blg" | grep -P "[0-9]+" -o


By using the following document, this number will be printed:

\documentclass{article}
\usepackage{bashful}
\begin{document}
Foo...

\bash[script,stdout]
grep -P "You've used [0-9]+ entries," -m 1 "Document.blg" | grep -P "[0-9]+" -o
\END
\end{document}

-

an alternative with biblatex for simply counting the number of entries in a bibliography is to use \AtEveryBibitem.

\usepackage{totcount}
\newtotcounter{citenum}
\AtEveryBibitem{\stepcounter{citenum}}


for multiple \printbibliography calls the counter can be reset with \AtNextBibliography.

-