# Script to replace ordinary references with citealias ones.

@text = ();

while (<>) { push @text, $_; }

for ($i = 0; $i < scalar @text; ++$i) {
	$l = $text[$i];
	print $l;
	next unless $l =~ m/^\\begin_inset CommandInset citation/;
	for ($j = 0; $j < 5; ++$j) {
		$key = $text[$i + $j]; 
		if ($key =~ m/^key "Chalmers:CTW"/) {
			$lc = $text[$i + 1];
			if ($lc =~m/^LatexCommand citep/) { 
				$text[$i + 1] = "LatexCommand citepalias\n";
			} elsif ($lc =~m/^LatexCommand citealp/) { 
				$text[$i + 1] = "LatexCommand citetalias\n";
			} elsif ($lc =~m/^LatexCommand citeyearpar/) { 
				$text[$i + 1] = "LatexCommand citepalias\n";
			} else { die($lc); }
			last;
		}
	}
}
