#!/bin/sh # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # latex2ps version 4.1 : produce postscript files from latex sources # # Copyright (C) 2000-2006 Glad Deschrijver, Fri March 25 2002, # # Mon Apr 22 2002, Thu Jul 03 2003, Tue Aug 12 2003, Mon Oct 6 2003, # # Fri May 07 2004, Fri May 13 2005, Fri 01 Jul 2005, Wed Nov 22 2006, # # Wed Nov 29 2006 # # Can handle filenames containing spaces, if you encounter problems # # with other symbols in filenames, please contact me at # # Glad.Deschrijver@UGent.be # # # # This program is free software; you can redistribute it and/or # # modify it under the terms of the GNU General Public License # # as published by the Free Software Foundation; either version 2 # # of the License, or (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # # USA. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 4.1 : - you can give absolute paths to the executables now # - you can change the command used for bibtex and makeindex # - usage shows the default previewcommand depending on the # default mode # 4.0 : - introduction of --sequence flag which allows for better # customization of the typesetting process; e.g. # --sequence=llbil runs latex, latex, bibtex, makeindex, latex # - group handling of different options # - latex2ps v3.2 only worked in bash, the current version works # in other shells (tested in dash, ksh) again # - added mode 4 which converts a dvi file to pdf # - added compression of the output file (currently only gzip and # bzip2 are supported) # 3.2 : moved the default values of some variables to a .latex2psrc file # so that the user can change the defaults without editing the script; # added the environment variable LATEX2PSRC and the flag --norcfile # 3.1 : - if the tex-file contains errors, then it will not be typesetted # a second time, unless --forcecontinue=yes is specified # - some minor bugs removed # 3.0 : - added support for hidden files (i.e. filenames with a leading dot) # - changed the usage of the flags in order to allow changing # the defaults below # - introduced the notion of typesetting modes (so pdflatex is back; # the current modes are dvi, ps, dvips+ps2pdf and pdflatex) # 2.4 : replaced pdflatex by dvips -Ppdf followed by ps2pdf # 2.3 : - options for latex, bibtex and dvips can now be given using the # options --latexoptions, --bibtexoptions and --dvipsoptions, # - added support for makeindex # 2.2 : passing arguments not recognized by latex2ps to latex itself # 2.1 : added support for pdflatex # 2.0 : complete rewrite of latex2ps progname=`echo "$0" | sed -e 's/[^\/]*\///g'` version=4.1 copyright="Copyright (C) 2000-2006 Glad Deschrijver" if `test ! "$LATEX2PSRC" = ""` then latex2psrcfile=$LATEX2PSRC else latex2psrcfile=$HOME/.latex2psrc fi usercfile=yes bq='`' eq="'" file="" previewcmdchanged=0 outputfile="" usage=no exitcode=0 sequence="" usage() { if `test $previewcmdchanged = 0` then case $mode in 0) previewcmd=$previewdvicmd;; 1) previewcmd=$previewpscmd;; *) previewcmd=$previewpdfcmd;; esac fi cat << EOF Usage: $progname [OPTIONS] file[.tex] Options: [defaults in brackets after descriptions] Configuration: --mode=MODE typeset using MODE [$mode], where MODE is one of 0: run latex to produce dvi 1: run latex and dvips to produce ps 2: run latex, dvips, ps2pdf to produce pdf 3: run pdflatex to produce pdf 4: convert dvi file to pdf via dvips+ps2pdf --typeset=CMD use CMD for typesetting [$typeset] --bib=yes/no use bibtex [$bib] (note: if you have a .bbl file which you don't want to be overwritten, then use --bib=no) -b short for --bib=yes --bibtexcommand=CMD use CMD as your bibtex command [$bibtex] --index=yes/no use makeindex [$index] (note: if you have a .ind file which you don't want to be overwritten, then use --index=no) -i short for --index=yes --makeindexcommand=CMD use CMD as your makeindex command [$makeindex] --sequence=SEQ run latex, bibtex and makeindex according to the sequence SEQ (which consists of the letters b, i, l) e.g. --sequence=llbil runs latex, latex, bibtex, makeindex, latex --preview=yes/no preview using program defined by --previewcommand [$preview] -p short for --preview=yes --previewcommand=CMD use CMD to preview the output file [$previewcmd] --delete=yes/no delete auxiliary files produced by tex/latex [$delete] --latexoptions=OPTIONS options passed to tex/latex (e.g. ${bq}latex2ps --latexoptions="-fmt=amstex"${eq} runs ${bq}latex -fmt=amstex${eq}) --bibtexoptions=OPTIONS options passed to bibtex --makeindexoptions=OPTIONS options passed to makeindex --dvipsoptions=OPTIONS options passed to dvips --ps2pdfoptions=OPTIONS options passed to ps2pdf --forcecontinue=yes/no force to continue typesetting when errors are encountered -f short for --forcecontinue=yes --compress=yes/no compress the output file [$compress] -c short for --compress=yes --compresscommand=CMD use CMD for compressing [$compresscmd] --rcfile=FILE get the defaults from the file FILE instead of from .latex2psrc --norcfile don't use a configuration file (all information must be given by the above options then) -h, --help display this help and exit -v, --version output version information and exit EOF } parsercfile() { if `test ! -f $latex2psrcfile` then if `test $usercfile = "yes"` then echo "$progname: The configuration file $bq$latex2psrcfile$eq does not exist." echo "$progname: Please specify a valid configuration file with the option --rcfile." echo "$progname: Alternatively you can run with --norcfile and specify all the options" echo "$progname: on the command line." echo "$progname: Run with --help for more information." exit 1 else return fi fi # the next command removes lines beginning with # and empty lines #+ and replaces all spaces and tabs by ^ defaultvalues=`sed -e "/^\#.*/d" -e "/^$/d" -e "s/[\ \t]/\^/g" $latex2psrcfile` for defaultvalue in $defaultvalues do defaultvalue=`echo $defaultvalue | sed -e "s/\^/\ /g"` # the name of the variable is equal to the left hand side of the first = varname=`echo $defaultvalue | sed -e "s/=.*//"` # the value of the variable is everything else, but without #+ surrounding hyphens value=`echo $defaultvalue | sed -e "s/[^=]*=//" -e "s/^\"//" -e "s/\"$//"` eval varname2=\$$varname # $varname2 contains the current value of $varname if `test "${varname2}" = ""` # if the option is not given by the user then export $varname="$value" fi done } parsefilename() { if `test -z "$file"` then echo "$progname: At least one file name is required as an argument." echo "$progname: Try $bq-h$eq or $bq--help$eq for more information." exit 1 elif `test -f "$file"` then filebasename=`echo $file | sed -e "s/\.[^\.]*$//"` ext=`echo $file | sed -e "s/.*\.//g"` file=$filebasename else if test $mode != 4 then filetest="$file.tex" ext="tex" else filetest="$file.dvi" ext="dvi" fi if `test ! -f "$filetest"` then if test $mode != 4 then filetest="$file.TEX" ext="TEX" else filetest="$file.DVI" ext="DVI" fi if `test ! -f "$filetest"` then echo "File does not exist: $file" exit 1 fi fi fi path=`echo $file | sed -e "s/[^\/]*$//g"` file=`echo $file | sed -e "s/.*\///g"` if `test ! "$path" = ""` then cd "$path" fi # filetmp is the filename in which all spaces and dots are replaced #+ by the string $latex2pstmp filetmp=`echo "$file" | sed -e "s/\ /${latex2pstmp}/g"` filetmp=`echo "$filetmp" | sed -e "s/^\./${latex2pstmp}/g"` } parse_sequence() { testsequence=`echo $sequence | sed -e "s/[bil]*//g"` if test ! -z $testsequence then usage exit 1 fi spacedsequence=`echo $sequence | sed -r "s/(.)/\1\ /g"` spacedsequence2=`echo $spacedsequence | sed -e "s/\ $//"` for item in $spacedsequence2 do case $item in l) $typeset $typesetargs "$filetmp.$ext" # if the tex-file contains errors, then do not typeset again latexreturn=$? if test $latexreturn -ne 0 -a $forcecontinue != "yes" then exit 1 fi ;; b) $bibtex $bibtexargs "$filetmp.aux" bib=yes ;; i) $makeindex $makeindexargs "$filetmp.idx" index=yes ;; *) usage; exit 1;; # should never get here esac done } typeset_latex() { if `test ! "$file" = "$filetmp"` # if the filename contains spaces or dots then cp "$file.$ext" "$filetmp.$ext" 2>/dev/null mv "$file.bbl" "$filetmp.bbl" 2>/dev/null mv "$file.ind" "$filetmp.ind" 2>/dev/null fi # if bib: latex; bibtex; latex; latex # if index: latex; makeindex; latex # if bib and index: latex; bibtex; latex; makeindex; latex # if none: latex; latex if test -z $sequence then if test $bib = "yes" then bibsequence="bl" fi if test $index = "yes" then indexsequence="i" fi sequence="l${bibsequence}${indexsequence}l" fi parse_sequence renameauxfiles typesetbase=`echo $typeset | sed -e "s/\s.*//" -e "s/.*\///"` if `test "$typesetbase" = "pdflatex"` then mv "$filetmp.pdf" "$file.pdf" 2>/dev/null outputfile="$file.pdf" else mv "$filetmp.dvi" "$file.dvi" 2>/dev/null outputfile="$file.dvi" fi if `test ! "$file" = "$filetmp"` then rm "$filetmp.$ext" 2>/dev/null fi if `test "$delete" = "yes"` then deleteauxfiles fi } typeset_dvips() { if test $mode != 4 then mv "$file.dvi" "$filetmp.dvi" 2>/dev/null else mv "$file.$ext" "$filetmp.dvi" 2>/dev/null fi dvips $dvipsargs "$filetmp.dvi" -o "$filetmp.ps" if `test ! "$filetmp" = "$file"` then sed -e "s/${filetmp}\.dvi -o ${filetmp}\.ps/\"$file\.dvi\" -o \"$file\.ps\"/g" \ -e "s/${filetmp}\.dvi/$file\.dvi/g" $filetmp.ps > "$file.ps" rm $filetmp.ps fi outputfile="$file.ps" if test $mode != 4 then if `test "$delete" = "yes"` then rm $filetmp.dvi else mv $filetmp.dvi "$file.dvi" 2>/dev/null fi else mv $filetmp.dvi "$file.$ext" 2>/dev/null fi } typeset_dvips_ps2pdf() { dvipsargs="$dvipsargs $dvipspdfargs" typeset_dvips mv "$file.ps" "$filetmp.ps" 2>/dev/null ps2pdf $ps2pdfargs "$filetmp.ps" mv $filetmp.pdf "$file.pdf" 2>/dev/null outputfile="$file.pdf" if `test "$delete" = "yes"` then rm $filetmp.ps else mv $filetmp.ps "$file.ps" 2>/dev/null fi } deleteauxfiles() { rm "$file.aux" 2>/dev/null rm "$file.log" 2>/dev/null rm "$file.toc" 2>/dev/null rm "$file.lof" 2>/dev/null rm "$file.lot" 2>/dev/null if `test "$bib" = "yes"` then rm "$file.bbl" 2>/dev/null fi rm "$file.blg" 2>/dev/null rm "$file.idx" 2>/dev/null rm "$file.ilg" 2>/dev/null if `test "$index" = "yes"` then rm "$file.ind" 2>/dev/null fi } renameauxfiles() { mv $filetmp.aux "$file.aux" 2>/dev/null mv $filetmp.log "$file.log" 2>/dev/null mv $filetmp.toc "$file.toc" 2>/dev/null mv $filetmp.lof "$file.lof" 2>/dev/null mv $filetmp.lot "$file.lot" 2>/dev/null mv $filetmp.bbl "$file.bbl" 2>/dev/null mv $filetmp.blg "$file.blg" 2>/dev/null mv $filetmp.idx "$file.idx" 2>/dev/null mv $filetmp.ilg "$file.ilg" 2>/dev/null mv $filetmp.ind "$file.ind" 2>/dev/null } while test x"$1" != x do case $1 in -h|--help) usage=yes; shift;; --mode=*|--typeset=*|--sequence=*|--forcecontinue=*|--delete=*| \ --bib=*|--index=*|--preview=*|--compress=*|--compresscommand=*| \ --bibtexcommand=*|--makeindexcommand=*) var=`echo $1 | sed -r 's/^--([^=]*)=.*/\1/'` vartransform="s/--${var}=//" export $var=`echo $1 | sed -e $vartransform` shift ;; -f) forcecontinue=yes; shift;; -b) bib=yes; shift;; -i) index=yes; shift;; -p) preview=yes; shift;; -c) compress=yes; shift;; --previewcommand=*) tmp=`echo $1 | sed -e 's/--previewcommand=//'` if test $tmp; then previewcmd=$tmp; previewcmdchanged=1; fi shift ;; --latexoptions=*) tmp=`echo $1 | sed -e 's/--latexoptions=//'` if `test ! "$tmp" = ""`; then typesetargs="$typesetargs $tmp"; fi shift ;; --bibtexoptions=*|--makeindexoptions=*|--dvipsoptions=*| \ --ps2pdfoptions=*) var=`echo $1 | sed -r 's/^--([^=]*)=.*/\1/'` vartransform="s/--${var}=//" tmp=`echo $1 | sed -e $vartransform` if `test ! "$tmp" = ""` then tmp2=`echo $var | sed -e "s/options//"` tmp2="${tmp2}args" # eval tmp3=\$${tmp2} # if $tmp2 = "dvipsargs" then # #+ $tmp3 contains the value of $dvipsargs # export $tmp2="${tmp3} $tmp" export $tmp2="$(eval echo \$$tmp2) $tmp" fi shift ;; --rcfile=*) latex2psrcfile=`echo $1 | sed -e 's/--rcfile=//'` shift ;; --norcfile) usercfile=no shift ;; -v|--version) echo "$progname $version" echo "$copyright" echo "This program comes with ABSOLUTELY NO WARRANTY. This is free" echo "software, and you are welcome to redistribute it under" echo "the terms of the GNU General Public License." exit 0 ;; -*) usage=yes; exitcode=1; shift;; *) file=$1; shift;; esac done if `test "$usage" = "yes"` then usercfile=no fi parsercfile if `test "$usage" = "yes"` then usage exit $exitcode fi parsefilename case $mode in 0) typeset_latex;; 1) typeset_latex; typeset_dvips;; 2) typeset_latex; typeset_dvips_ps2pdf;; 3) typeset=pdflatex; typeset_latex;; 4) typeset_dvips_ps2pdf;; *) echo "$progname: The typesetting mode should be an integer" \ "between 0 and 3." echo "$progname: Try $bq-h$eq or $bq--help$eq for more information." exit 1;; esac if `test "$compress" = "yes"` then $compresscmd "$outputfile" compresscmdbase=`echo $compresscmd | sed -e "s/\s.*//" -e "s/.*\///"` case $compresscmdbase in bzip2) outputfile="${outputfile}.bz2";; gzip) outputfile="${outputfile}.gz";; esac fi if `test "$preview" = "yes"` then if `test $previewcmdchanged = 0` then case $mode in 0) previewcmd=$previewdvicmd;; 1) previewcmd=$previewpscmd;; *) previewcmd=$previewpdfcmd;; esac fi $previewcmd "$outputfile" & fi exit 0