edit · print · PDF

Please note that all the SIEpedia's articles address specific issues or questions raised by IAC users, so they do not attempt to be rigorous or exhaustive, and may or may not be useful or applicable in different or more general contexts.

Check for unused references in Latex manuscript

Papers to be submitted to the Astrophysical Journal or the Astronomical Journals use the LaTeX AASTEX package, and the preferred method for reference management is to use the thebibliography environment. Citations in the body are marked with the \cite command (and its variants as \citep, \citealp etc.), while bibliography references are listed with the \bibitem command.

While it is straightforward to identify citations missing the associated reference, as Latex will print a warning message whenever it encounters one, there is no easy way to check what references in the bibliography list are never used (cited) in the text.

To this end, we have written a simple perl script that operates on the .aux file and lists all unused references:

#!/usr/bin/perl
#
# File name: citations.cl
# Written by: SIEi+e, IAC - sinfin [at] iac.es.
# Script to check whether, in a latex file using the bibitem-\cite reference
# management technique, there are bibliography references that are never cited
# in the text.
# Run this script on the .aux file, for example:
# citations.pl ms.aux

$file = @ARGV[0];

open(LATEX, "$file") || die "cannot open $file";
@lines = <LATEX>;
close(LATEX) || die "cannot close $file";

print "Bibliography items not referenced: \n";
print "================================== \n";

foreach $line (@lines) {
    if ($line =~ /^\\bibcite{(.*?)}.* /) {
        $match = $1;
        $found = 0;
        foreach $li (@lines) {
            if ($li =~ /$match/ && $li !~ /\\bibcite/) {
                $found = 1;
            }
        }
        if ($found == 0) {
            print "$match \n";
        }
    }
}

After you have removed the extra references from the .tex file, run Latex again twice.

edit · print · PDF
Page last modified on October 02, 2012, at 02:07 PM