[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Tex related utility



Hi 
	The utility 2ps attached will call latex and then dvips and then
if gv is not already running on the file, open gv. For best results, ask
gv to watch file.

Usage: 2ps latex_source [-c | --clean | -q | --quiet | -cq] 

Hope all tex users find it useful. Comments are welcome. Also if any
probs, please let us know.

This is developed by Srinathan and Krishnaram of Theoretical Computer
Science lab at IIT Madras. email :  {srinath,kngk}@meenakshi.iitm.ernet.in


regards,
Sudhakar


-- 
--------------------------------------------------------------------------
G Sudhakar 		
cs97194
#362, Godavari Hostel 		 
IIT Madras - 600036			
India		
sudhakarg79@xxxxxxxxxxx ,  sudha@xxxxxxxxxxxxxxxxxxxxxxx
Phone 91-44-445-9075
---------------Linux - the choice of the NEW generation ------------------
Fortune says :
What one believes to be true either is true or becomes true.
		-- John Lilly
#!/usr/bin/perl

$MIN_LOG_SIZE = 2;
# At least $MIN_LOG_SIZE lines in the log file expected.

if ((@ARGV == 0) || ((@ARGV == 2) && ($ARGV[1] ne "-q") && ($ARGV[1] ne "--quiet")  && ($ARGV[1] ne "-c") && ($ARGV[1] ne "--clean") && ($ARGV[1] ne "-cq")) || (@ARGV >= 3)) {
# Either 1 argument or 2 arguments, with 2nd argument == -q or --quiet or -c or --clean or -cq (clean and quiet)
    print "Usage: 2ps latex_source [-c | --clean | -q | --quiet | -cq]\n";
    print "Developed by Srinathan and Krishnaram!\n";
    print " {srinath,kngk}\@meenakshi.iitm.ernet.in\n";
    exit;
} else {
   if (@ARGV == 2) {
      if (($ARGV[1] eq "-q") || ($ARGV[1] eq "--quiet") || ($ARGV[1] eq "-cq")) { 
         $STD_OUT = "1> /dev/null";
         $STD_ERR = "2> /dev/null";
         # These flags are null strings otherwise.
      }
      if (($ARGV[1] eq "-c") || ($ARGV[1] eq "--clean") || ($ARGV[1] eq "-cq")) {
         $CLEAN = 1;
      }  
   }
} 

#Working code starts here.
@temp = split (/['\.']+/,$ARGV[0]);

open(BIB,"< $temp[0].tex");
while ($line = <BIB>) {
    if ($line =~ /\\bibliography/) {
       $BIB_PRESENT = 1;
    }
}
close BIB;

if ($BIB_PRESENT == 1) {
   open(INP, "< $temp[0].log");
   $count = 0;
   while ($line = <INP>) {
       if ($line =~ /There were undefined references/) {
#         print "bibtex $temp[0] && latex $ARGV[0]";
         system("bibtex $temp[0] $STD_OUT && latex $ARGV[0] $STD_OUT");
       } 
       $count++;
   }
   close INP;

   if ($count < $MIN_LOG_SIZE) {
   # At least $MIN_LOG_SIZE lines in the log file expected.
   #   print "inside if $count \n";
      system("latex $ARGV[0] $STD_OUT && bibtex $temp[0] $STD_OUT && latex $ARGV[0] $STD_OUT");
   #   print "latex $ARGV[0] && bibtex $temp[0] && latex $ARGV[0]";
   }
} 
# End of if BIB_PRESENT ...

system("latex $ARGV[0] $STD_OUT && dvips $temp[0].dvi -o $STD_ERR");
#print "latex $ARGV[0] $STD_OUT && dvips $temp[0].dvi -o $STD_ERR";
open(GV, "ps x|grep \"gv $temp[0].ps\"|");
$flag = 1;
while ($line = <GV>) {
#   print $line;
   if ($line =~ /gv $temp[0].ps/) {
       if (!($line =~ /grep/)) {
           $flag = 0;
       }
   }
} 
if ($flag == 1) {
#       print "gv $temp[0].ps &";
       system("gv $temp[0].ps &");

}
close GV;

if ($CLEAN == 1) {
   system("rm -fv $temp[0].aux $temp[0].blg $temp[0].log $temp[0].dvi texput.log core");
}