#!/bin/sh # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # pstex2eps version 3.1 : produce postscript files from pstex sources # # Copyright (C) 2000-2006 Glad Deschrijver, Mon Apr 22 2002, # # Tue Aug 12 2003, Tue Aug 21 2003, Fri Nov 24 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. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 3.1 : - check whether the temporary tex file created by the script # does not exist yet # - removed some small bugs # 3.0 : added support for style files, changed the usage of the flags # --preview and --delete in order to allow changing the defaults # below # 2.1 : enhancement of --help; output now to .eps instead of .ps # 2.0 : complete rewrite of pstex2eps # Change defaults below preview=no # Don't open output-image previewcmd=gv # Open output-image with this command delete=yes # Delete .pstex and .pstex_t created by xfig typeset=latex # Use this command to typeset LaTeX documents stylefile="" # default style file (empty string if using # pstex2eps default) stylereplace="\$f" # The regexp "\$f" in the style file will be # replaced by the filename (without extension) tmpfile=pstex2epstmp # Name used for temporary files (change only # when the file pstex2epstmp.tex already exists) # Below this line you shouldn't change anything progname=`echo "$0" | sed -e 's/[^\/]*\///g'` version=3.1 copyright="Copyright (C) 2000-2003 Glad Deschrijver" bq='`' eq="'" file="" tmpfile2=$tmpfile.tex usage() { cat << EOF Usage: $progname [OPTIONS] file[.pstex|.pstex_t] Options: [defaults in brackets after descriptions] Configuration: --preview=yes/no preview using program defined by --previewcommand [$preview] -p short for --preview=yes --previewcommand=CMD use CMD to preview postscript files [$previewcmd] --style=FILE use user-defined style file FILE instead of standard style --delete=yes/no delete file.pstex and file.pstex_t [$delete] -h, --help display this help and exit -v, --version output version information and exit EOF } 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 else F=`echo $file | sed -e "s/\.[^\.]*$//"` ext=`echo $file | sed -e "s/.*\.//g"` if `test "$ext" = "pstex"` || `test "$ext" = "pstex_t"` then file=$F fi if `test ! -r "$file.pstex"` || `test ! -r "$file.pstex_t"` then echo "$progname: $file.pstex or $file.pstex_t not found or not readable." exit 1 fi fi path=`echo $file | sed -e "s/[^\/]*$//g"` file=`echo $file | sed -e "s/.*\///g"` if `test ! "$path" = ""` then cd "$path" fi } createtexfile() { if test -f "$tmpfile2" then echo "The file $tmpfile2 already exists. Please rename or move this file to another directory." exit 1 fi if test "$stylefile" = "" then echo "\documentclass{report}" > $tmpfile2 echo "\usepackage{amssymb}" >> $tmpfile2 echo "\usepackage{amsmath}" >> $tmpfile2 echo "\usepackage{epsfig}" >> $tmpfile2 echo "\usepackage{color}" >> $tmpfile2 printf "\\" >> $tmpfile2 echo "begin{document}" >> $tmpfile2 echo "\pagestyle{empty}" >> $tmpfile2 echo "\input{$file2.pstex_t}" >> $tmpfile2 echo "\end{document}" >> $tmpfile2 else cat $stylefile | sed -e "s/$stylereplace/$file2/g" > $tmpfile2 fi } typesetfile() { file2=`echo "$file" | sed -e "s/\ /_pstex2epstmp_/g"` if `test "$file" != "$file2"` then sed -e "s/$file\.pstex/$file2\.pstex/g" "$file.pstex" > $file2.pstex sed -e "s/$file\.pstex/$file2\.pstex/g" "$file.pstex_t" > $file2.pstex_t fi createtexfile $typeset $tmpfile2 dvips -E $tmpfile.dvi -o $tmpfile.eps sed -e "s/$tmpfile\.dvi -o $tmpfile\.eps/\"$file\.dvi\" -o \"$file\.eps\"/g" \ -e "s/$tmpfile\.dvi/$file\.dvi/g" $tmpfile.eps > "$file.eps" # cp "$file.eps" $tmpfile.eps # epstopdf $tmpfile.eps # mv $tmpfile.pdf "$file.pdf" rm $tmpfile.* if `test "$file" != "$file2"` then rm $file2.pstex rm $file2.pstex_t fi } deleteauxfiles() { rm "$file.pstex" 2>/dev/null rm "$file.pstex_t" 2>/dev/null } while test x"$1" != x do case $1 in -h|--help) usage; exit 0;; --preview=*) preview=`echo $1 | sed -e 's/--preview=//'` shift ;; -p) preview=yes shift ;; --previewcommand=*) tmp=`echo $1 | sed -e 's/--previewcommand=//'` if test $tmp; then previewcmd=$tmp; fi shift ;; --style=*) tmp=`echo $1 | sed -e 's/--style=//'` if test $tmp; then stylefile=$tmp; fi shift ;; --delete=*) delete=`echo $1 | sed -e 's/--delete=//'` 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; exit 1;; *) file=$1; shift;; esac done parsefilename typesetfile if `test "$preview" = "yes"` then $previewcmd "$file.eps" & fi if `test "$delete" = "yes"` then deleteauxfiles fi exit 0