#!/usr/bin/perl -s use File::Copy; ## Options: ### -s = skip prel ### -Q = Quiet ### -clear = clear temporary files after build ### -fast = do not check if redo is needed: ### - pdflatex once, bibtex or index if needed, but not pdflatex again our ($s,$f,$clear,$fast,$o,$Q,$debug); $clear = 1; $clear = 0 if $debug; my $preloption = ""; $preloption .= "-f" if $f; my $base = "__ppdflatex__$$"; $Q = "-Q" if $Q; my $a = shift or die("usage $0 file.pre\n"); if (!-f $a) { $a =~ s/\.$//; for my $e (qw.tlpp ptex pre tex.) { if (-f "$a.$e") { $a = "$a.$e"; last; } } } my $b = $a; $b =~ s/\.(tlpp|ptex|pre|tex)$//; my $teximporter=`grep -E '[(\\|begin)\{](import_|inline_|_(html|camila|dot|abc|pod|makefile|gnuplot))' $a`; $teximporter=" | teximporter $Q " if $teximporter; my $c; if ($s) { copy($a, "$base.tex"); } else { $c=`grep '^=\\.' $a`; if($c){ syst("brev2s $a $teximporter > $base.tex"); } else { syst("prel -a $preloption < $a $teximporter > $base.tex"); } } syst("pdflatex $base"); $c=`grep '\\\\bibliography{' $a`; $c =~ s/\%.*//s; $ind=`grep '\\\\printindex' $a`; $ind =~ s/\%.*//s; my $toc=`grep '\\\\tableofcontents' $a`; $toc =~ s/\%.*//s; ##print "bibtex? = $c\n"; ##print "makeindex? = $ind\n"; $toc && ($redo = 1); if ($ind) { syst("makeindex $base"); $redo=1} if ($c) { syst("bibtex $base") ; $redo=1;} if ($redo && !$fast) { syst("pdflatex $base"); syst("pdflatex $base"); } if($o) { rename("$base.pdf" , $o );} else { rename("$base.pdf" , "$b.pdf");} ##warn("\nOutput written to $b.pdf\n"); unlink("$base.tex"); cleartmp(); sub cleartmp { if ($clear && !$fast) { ## As caution, do not clear in fast mode rename("$base.pdf","__ppdflatex__.pdf"); for my $file (<$base.*>) { unlink $file; } } } sub syst{ my $a=shift; # print STDERR "debug: $a\n"; if(system($a) != 0){ cleartmp() ; die "system $a failed:\n\t $? $!"; } } __END__ =head1 NAME ppdflatex - preprocessor for LaTeX =head1 SYNOPSIS =head1 Options -s = skip prel -Q = Quiet -clear = clear temporary files after build =head1 DESCRIPTION C may use C C and C. In order to make beamer slides, if brev2s sintax is found (^.= title) brev2s preprocessor is executed too. In order to easilly importer external formats, if teximporter sintax is found (C<\\import_graphviz{file}>) teximporter preprocessor is executed too. In order to make bibliography if C<\\bibliography> is found BibTeX is executed too. In order to make conceptual indexes, if C<\\printindex> is found makeindex is executed too. =head1 AUTHOR J.Joao Almeida, jj@di.uminho.pt =head1 SEE ALSO teximport brev2s LaTeX, BibTeX makeindex perl(1). =cut