diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/orderer |
Initial commit
Diffstat (limited to 'support/orderer')
-rw-r--r-- | support/orderer/Orderer.pl | 32 | ||||
-rw-r--r-- | support/orderer/README | 6 |
2 files changed, 38 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 diff --git a/support/orderer/README b/support/orderer/README new file mode 100644 index 0000000000..34af3e7d2e --- /dev/null +++ b/support/orderer/README @@ -0,0 +1,6 @@ +The script re-orders references in the .tex file (in the order as they +appear in the text). This is REQUIRED by most of the journals, this is +TEDIOUS to do manually (in average each article contains ~50 citations) +and unfortunately none of the LateXs which I know can do this job. +The script is written in Perl (pre-installed on most Linux OS), but can +be easily rewritten in other languages. |