summaryrefslogtreecommitdiff
path: root/support/orderer/Orderer.pl
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/orderer/Orderer.pl
Initial commit
Diffstat (limited to 'support/orderer/Orderer.pl')
-rw-r--r--support/orderer/Orderer.pl32
1 files changed, 32 insertions, 0 deletions
diff --git a/support/orderer/Orderer.pl b/support/orderer/Orderer.pl
new file mode 100644
index 0000000000..2d529848f9
--- /dev/null
+++ b/support/orderer/Orderer.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+# The script is designated to order the references in the external .tex-file.
+# It is assumed that all the references are introduced using standard \bibitem{key}. M.S.
+if(!$ARGV[0])
+{print "Enter the external .tex-file name in which You want to order references:";
+$file=<STDIN>;chomp($file);$fileout="$file.tex";
+print "By default the output will be placed to the file $fileout\nYou can specify the output using option -o in the command line call: ./Orderer filename -o OutputName\n";}
+else {$file=$ARGV[0];if(($ARGV[1] eq '-o')and($ARGV[2])){$fileout=$ARGV[2]}else{$fileout="$file.tex"}};
+print "Opening file $file\n";
+open(SM,$file);@lines=<SM>;close(SM);
+# Now drop all the lines which start with %(comment)
+foreach $line(@lines){if($line!~/^[ ]*\%/){push(@Lines,"$line")}};
+foreach $line(@Lines){if($line=~ /\\cite\{[a-zA-Z:0-9\,\']+\}/g){&AddCite($&);
+while($'=~ /\\cite\{[a-zA-Z:0-9\,\']+\}/g) # Multiple citations on the same page
+ {&AddCite($&)}}};
+print "$#Cite citations found\n";
+foreach $line(@Lines){$x=$line;if($x=~s/(\\bibitem\{)([a-zA-Z:0-9\,\']+)(\}\s)$/\2/g){$hash=$x;chomp($hash)};
+if($hash){if($line!~/\\end/){@Y=("$BibItem{$hash}","$line");$BibItem{$hash}="@Y";}
+ else{push(@LastLines,$line)}}else{push(@FirstLines,$line)};};
+print "Printing out ordered list into file $fileout:\n";
+open(SM,">$fileout");print SM "@FirstLines";
+foreach $citation(@Cite){print SM $BibItem{$citation}};
+print SM "@LastLines";close(SM);&Check;
+sub AddCite
+# The subroutine extracts the citation and adds it to the specified array
+# Format of the call: (String)
+{$string=$_[0];$string=~ s/^(\\cite\{)([a-zA-Z:0-9\,\']+)(\})$/\2/g;@Values=split(/\,/,$string);
+foreach $value(@Values){if("@Cite"!~/$value/){push(@Cite,$value)};}};
+sub Check
+{@BibItemsList=keys %BibItem;
+foreach $citation(@Cite){if("@BibItemsList"!~/$citation/){print "Warning::Citation $citation is not found !\n "}};
+foreach $bib(@BibItemsList){if("@Cite"!~/$bib/){print "Warning::Bibitem", $BibItem{$bib}, " is not used !\n "}};}; \ No newline at end of file