#!/usr/bin/perl ############################################################################## # pssq: the postscript squeeze routine for latex # Usage pssq file num # where "file" is the name of the latex file without the .tex extension and # "num" is the number of pages you want to squish it into. # You need to insert the line # "\input scale" # immediately before \begin{document} in your latex file... # When pssq is finished you need to execute the either of the # scripts dps600, dpdf600 or dpdfm600 it creates in the # directory it is run in (depending on whether you need a postscript or a # PDF both under standard and MikTex systems. # # Authors: JMLG Extreme Programming Team # No warranty is provided whatsoever and no liability is accepted for the use # of this program. If your paper gets rejected because you squished it too much # then you you work shorter hours, produce less and write genuinely shorter # papers. You have been warned. ############################################################################# $res=600 ; $scale_tex="scale.tex" ; $fname=$ARGV[0] ; $target_pages=$ARGV[1]; $logfile="logfile" ; $ds=dps.$res ; $dp=dpdf.$res ; $dpm=dpdfm.$res ; $flog=$fname.".log" ; $lower_bound=0.5 ; $upper_bound=2 ; $current=1.03 ; $not_done=1 ; die "usage: pssq file num\n " unless @ARGV ; $latex="latex ".$fname.".tex" ; $reportpages= "(tail -1 $flog | sed -e 's/.*(\\([0-9]*\\).*/\\1/')" ; while ($not_done) { open(fd,">".$scale_tex); print fd "\\textwidth=".$current."\\textwidth\n" ; print fd "\\textheight=".$current."\\textheight\n" ; close(fd) ; print "pspt: Scale = ".$current." " ; system(" $latex > /dev/null") ; $number_of_pages=`$reportpages` ; print "=> Page count=".$number_of_pages ; if (($upper_bound-$lower_bound<1e-3) & ($number_of_pages==$target_pages)) { print "DONE\n" ; $not_done=0 ; } else { if ($number_of_pages>$target_pages) { $lower_bound=$current ; } ; if ($number_of_pages<=$target_pages) { $upper_bound=$current ; } ; $current=($lower_bound+$upper_bound)/2 ; #print $lower_bound." <= ".$current." <= ".$upper_bound ; } } open(fd,">".$ds); $iscale=1000/$current ; print fd "#!/bin/sh\n" ; print fd "dvips -D$res -t a4 -Z -x $iscale $fname -o \n" ; close(fd); $chmod="chmod +x $ds" ; system($chmod) ; open(fd,">".$dp); $fscale=1/$current ; print fd "#!/bin/sh\n" ; print fd "dvipdf -r $res -z 9 -m $fscale $fname \n" ; print fd "echo \"%PDF-1.2 ($fscale)\" > $fname.tmp; tail +2 $fname.pdf >> $fname.tmp; rm $fname.pdf; mv $fname.tmp $fname.pdf" ; close(fd); $chmod="chmod +x $dp" ; system($chmod) ; open(fd,">".$dpm); $fscale=1/$current ; print fd "#!/bin/sh\n" ; print fd "dvipdfm -r $res -z 9 -m $fscale $fname \n" ; print fd "echo \"%PDF-1.2 ($fscale)\" > $fname.tmp; tail +2 $fname.pdf >> $fname.tmp; rm $fname.pdf; mv $fname.tmp $fname.pdf" ; close(fd); $chmod="chmod +x $dpm" ; system($chmod) ; $call_ds="./".$ds ; print "Now run \"./".$ds."\", \"./".$dp."\" or \"./".$dpm."\"\n" ; if ($current > 1.1) { print "Warning, a scaling of ".$current." is likely to be obvious!\n" }