summaryrefslogtreecommitdiffstats
path: root/check-ciation-order.pl
blob: 55046ad85f435dff8a0b7f166b103e3f12296b20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env perl
use strict;
use warnings;

=head1 DESCRIPTION

Look for \cite commands that are not preceeded by a \citea command. This means
that there is no text cite before a numbered cite.

=cut

my %seen;
my %output;

while (<<>>) {
	next if m/^\s*%/;
	while (m/\\(?<cmd>citea?)\{(?<keys>.*?)\}/g) {
		my $keys = $+{keys};
		my $cmd = $+{cmd};

		for my $key (split /,/, $keys) {
			$key = trim($key);
			$seen{$key}++ if $cmd eq "citea";
			print "incorrect order: $cmd - $key\n" if !defined $seen{$key} and $output{$key}++==0;
		}
	}
}

sub trim {
	my $str = shift;
	$str =~ s/\s*$//;
	$str =~ s/^\s*//;
	return $str;
}