#!/usr/local/bin/perl # # David MacKay 4 June 94 # # DELATEX.p - master program that # (1) causes other programs to read .tex and .aux file # and create extra perl programs # # (2) causes these perl programs to be run in a big pipe # to de-tex-ify the .tex file # # usage # DELATEX.p [options] file # # expects to find file.tex and file.aux # creates file.nc.p and file.ref.p # writes result to file.detex # # depends on the existence of these executables in path: # # tex_2_p.p aux_2_p.p delatex1.p delatex2.p delatex3.p delatex0.p # # delatex0.p by itself turns a latex file into a flat file # # options: # clean=1 causes temporary perl scripts to be removed. # newcom=0 don't bother interpreting newcommands # # This is free software. It is full of bugs but I hope it is found # useful. No support is provided by the author. # # To add new features, edit the files as follows: # # to kill strings that are not killed, add lines to delatex2.p # to modify the newcommand substitutions, edit tex_2_p.p # to modify handling of equation, section and table references, # and citations, edit aux_2_p.p $clean=1; $newcom=1; $dobbl = 1 ; # # process options on command line # eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; # $file = $ARGV[0] ; $filetex = $file.".tex"; $fileaux = $file.".aux"; $filebbl = $file.".bbl"; $filencp = $file.".nc.p"; $filerefp = $file.".ref.p"; $filede = $file.".detex" ; $command1 = "tex_2_p.p $filetex > $filencp "; $command2 = "aux_2_p.p $fileaux > $filerefp " ; $commandfinal = ( $newcom ) ? "delatex0.p $filetex | delatex1.p | $filerefp | $filencp | delatex2.p | delatex4.p > $filede" : "delatex0.p $filetex | delatex1.p | $filerefp | delatex2.p | delatex4.p > $filede" ; # Ken mode: # "delatex1.p $filetex | delatex1a.p | $filerefp | $filencp | delatex2.p > $filede" : # "delatex1.p $filetex | delatex1a.p | $filerefp | delatex2.p > $filede" ; if ( $newcom ) { print $command1 , "\n" ; system $command1 ; } print $command2 , "\n" ; system $command2 ; chmod 0755, $filencp, $filerefp ; print $commandfinal , "\n" ; system $commandfinal ; if ( $dobbl == 1 ) { # should add a check for existence of filebbl $bblcommand = "delatex3.p $filebbl >> $filede" ; print $bblcommand , "\n" ; system $bblcommand ; } if ( $clean == 1 ) { system "rm $filencp $filerefp" ; } # make public thus: # tar cvf /home/ftp/pub/mackay/perl/delatex.tar DELATEX.p delatex1.p delatex2.p delatex3.p delatex4.p tex_2_p.p aux_2_p.p