# Is it possible to automatically generate a rank of the citations?

I would like to know which papers or books I am citing the most. So, is it possible to automatically generate a rank of the citations? (i.e. automatically count the number of times all references are cited and then generate an ordered list)? I know I could use my editor to find the number of times a specific reference is cited, but I would need to do this for all citations, and this is quite painful.

I am currently using the package natbib and citep to cite. I am using a custom document class that I think inherits from the book class.

• biblatex has the citecounter option to count the number of citations of a particular entry. It should also be possible to cook something similar up for BibTeX-based solutions, but at least the idea I have in mind could potentially depend on the bibliography/citation packages you use, so more details about your setup (do you use cite, natbib, biblatex, ... which document class do you use?) would be appreciated. ... – moewe Jul 14 at 5:56
• That then only gives you the number of times an item was cited, you'd still need to make a sorted list of that. I don't have a concrete plan how that would be done, but I'm guessing some expl3 tools will come in handy. – moewe Jul 14 at 5:57
• Not what you are asking, but (maybe) what you want is make back references. This will not count nor sort the references, but you will see easily how much and where exactly each reference is cited. With biblatex is smply backref =true but it is possible make also back references with bibtex. – Fran Jul 14 at 8:28
• @moewe See my last edit. – nbro Jul 14 at 11:56

Every \cite command writes a cite request of the form \citation{<key_1>,...,<key_n>} to the .aux file. So if you want to find out how often an entry was cited, you can redefine \citation to calculate that data for you. Just grab the list loop through it and increase a counter associated to every key you find.

Here is a expl3 solution that also sorts the cited entry keys by the number of citations in the end.

\documentclass[british]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{natbib}

\usepackage{expl3}
\usepackage{xparse}

\ExplSyntaxOn
\seq_new:N \l__nbro_citedkeys_seq

\cs_new_protected:Npn \__nbro_count_entrykey:n #1
{
\seq_if_in:NnF \l__nbro_citedkeys_seq {#1}
{
\seq_gput_right:Nn \l__nbro_citedkeys_seq {#1}
\int_new:c {l__nbro_citecounter_#1}
}
\int_gincr:c {l__nbro_citecounter_#1}
}

\NewDocumentCommand \entrykeycitecount { >{ \SplitList{,}}m }
{
\ProcessList {#1} { \__nbro_count_entrykey:n }
}

\cs_new_protected:Npn \__nbro_sort_by_citecount:N #1
{
\seq_sort:Nn #1
{
\int_compare:nNnTF
{ \int_use:c {l__nbro_citecounter_##1} }
>
{ \int_use:c {l__nbro_citecounter_##2} }
{ \sort_return_same: }
{ \sort_return_swapped: }
}
}

\cs_generate_variant:Nn \int_to_arabic:n { v }

\cs_new:Npn \__nbro_print_entrykey_citecount:n #1
{
#1:~\int_to_arabic:v {l__nbro_citecounter_#1} \par
}

\NewDocumentCommand \printcitecounts {}
{
\__nbro_sort_by_citecount:N \l__nbro_citedkeys_seq
\seq_map_function:NN \l__nbro_citedkeys_seq \__nbro_print_entrykey_citecount:n
}
\ExplSyntaxOff

\renewcommand{\citation}[1]{%
\entrykeycitecount{#1}}

\begin{document}
\printcitecounts

\citep{article-full,incollection-full,misc-full}

\citep{incollection-full}

\citep{article-full}

\citep{incollection-full}

\bibliographystyle{plainnat}
\bibliography{xampl}
\end{document}


Note that I just redefined \citation and didn't try to append \entrykeycitecount to the original definition. This is usually not an issue since the LaTeX kernel, the standard classes and natbib have \citation defined as doing nothing, but you should probably check that this doesn't clash with anything other you use.