#!/usr/bin/perl use strict; use File::Copy; sub create_tmp_dir ($) { # Create a temp directory, it will be removed when the script exits. my $base = shift; my $template = $base . ".XXXXXXXXXX"; use File::Temp qw (tempdir); my $tmpdir = tempdir ($template, TMPDIR => 1, CLEANUP => 1); return $tmpdir; } my $arg=shift(@ARGV); my $file; if ($arg =~ m/\\input{([^\}]*)}/){ $file=$1; } else { $file=$arg; } my $stem=$file; $stem =~ s/\.lhs$//; print STDERR "using $stem as stem\n"; my $tmpdir= create_tmp_dir ("lhslatex"); my $old_dir=$ENV{PWD}; open (IN,"<$file") || die "$!"; chdir $tmpdir || die "$!"; # the aux file, and any other included files will be read from the original # directory $ENV{TEXINPUTS}= $old_dir.':'.$ENV{TEXINPUTS}; print STDERR "TEXINPUTS=$ENV{TEXINPUTS}\n"; open (OUT,"|lhs2TeX - > $stem.tex") || die "$!"; while(){ print OUT; } close OUT || die "$!"; my $command= $arg; print STDERR "command = $command"; $command=~ s/\.lhs/.tex/; print STDERR "command = $command"; system('pdflatex \''.$command.'\''); move( $stem.".pdf", $old_dir) || die "$!"; move( $stem.".aux", $old_dir) || die "$!";