#!/usr/bin/env perl
# $Id: fixtexindexpost 615 2010-09-30 15:49:42Z florenz@TU-BERLIN.DE $

# this script is called with the same arguments as texindex and 
# tries to fix some bugs and flaws wrp to the dosfop generated indices

# Flaw 2) -> (represented as -{\tt\gtr}) is frequently hyphenated for 
# linebreaks; this is now remedied by inserting \penalty 10000 after the 
# minus sign

# Bug 2) \initial{_} causes TeX errors changed to \initial{\_}

# note one could also use this place for generating more mathematical 
# printing of functionalities, but dosfop is not a pretty printer

print "fixtexindexpost v 1.0\n";

while (<@ARGV>) 
{  $indexfile = $_ . "s";
   print "now fixing(post) $indexfile ...";
   $oldindexfile = $indexfile . ".out";

   rename($indexfile, $oldindexfile) || die "backup of $indexfile failed";
   open(IN, $oldindexfile) || die "cannot open $oldindexfile";
   open(OUT, ">" . $indexfile)  || die "cannot open file $indexfile";
   
   while(<IN>)
   { # insert \penalty 10000 between ->
     s/-({\\tt\\gtr})/-\\penalty 10000\1/g;
     # change \initial{_}
     s/\\initial {_}/\\initial {\\_}/;
     print OUT;
     };
   
   close IN || die "trouble closing $oldindexfile";
   close OUT || die "trouble closing $indexfile";
   unlink $oldindexfile;
   print "done\n";
 
}

