[comp.text.tex] psfilt - a filter for including Frame Maker files, etc in LaTeX

jay@ctr.columbia.edu (Jay Hyman) (02/26/91)

I recently posted a filter called "psfilt" to prepare various graphics
files for inclusion in LaTeX documents using Trevor Darrell's psfig.
I received several complaints about the use of Sun's nawk filter,
so here it is again, using standard awk instead.

The files treated here are single-page PostScript documents produced by:
 - Frame Maker 2.0 in either portrait or landscape mode, 
 - Splus 2.3 in landscape mode (you can try it with other versions...)
 - Mathematica

Simple editing of the Postscript files is used to create EPS files of
the type expected by psfig.   Good luck.

-jay

--------------------------cut here------------------------
#!/bin/sh
#
# psfilt: filter to translate various PostScript files to EPSF
#
# Copyright (c) 1991, Giovanni Pacifici, giovanni@ctr.columbia.edu
#
# Permission is granted to copy and distribute this file in modified
# or unmodified form, for noncommercial use, provided (a) this copyright
# notice is preserved, (b) no attempt is made to restrict redistribution
# of this file, and (c) this file is not distributed as part of any
# collection whose redistribution is restricted by a compilation copyright.
#
trap 'echo interrupt; exit' 1 2 3 9 15
if test $# -ne 3
	 then 
		echo "This Program Translates Frame Maker, Mathematica and Splus"
		echo "PostScript Files into Encapsulated PostScript Files."
		echo "You can include these files directly into Latex Documents."
		echo "To Run The Filter use:"
		echo " "
		echo $0 "filetype InputFile OutputFile"
		echo " "
		echo "filetype can be one of the following:"
		echo "	fmland: Specifies that the input file is a Frame Maker"
		echo "		PostScript in Landscape Format"
		echo "	fmport: Specifies that the input file is a Frame Maker"
		echo "		PostScript in Portrait Format"
		echo "	Splus:	Specifies that the input file is a Splus"
		echo "		PostScript in Landscape Format"
		echo "	Math:	Specifies that the input file is Mathematica"
		echo "		PostScript"
		echo " "
		exit
 fi
case $1 in
fml*)
	echo "PostScript To EPSF Filter"
	echo "Converting Landscape Frame Maker File:" $2
	echo "Output to File:" $3
	cat $2 | \
	awk '
	BEGIN { }
	{
		if ($0 ~ /^%%BoundingBox/)
		{
			print $1 " 180 180 612 792"
		}
		if ($0 ~ / FMDOCUMENT/)
		{
			print $1, $2 " 2 2 " $5, $6, $7, $8
		}
		if ($0 ~ / 1 FMBEGINPAGE/)
			{
			print $1, $2 " 0 " $4
		}
		if ($0 !~ / 1 FMBEGINPAGE/ && $0 !~ / FMDOCUMENT/ && $0 !~ /^%%BoundingBox/)
		{
			print $0
		} 
	}
		END {
		}
		' > $3 ;;
fmp*)
	echo "PostScript To EPSF Filter"
	echo "Converting Portrait Frame Maker File:" $2
	echo "Output to File:" $3
	cat $2 | \
	awk '
	BEGIN { }
	{
		if ($0 ~ /^%%BoundingBox/)
		{
			print $1 " 0 0 612 792"
		}
		if ($0 ~ / FMDOCUMENT/)
		{
			print $1, $2 " 2 2 " $5, $6, $7, $8
		}
		if ($0 !~ / FMDOCUMENT/ && $0 !~ /^%%BoundingBox/)
		{
			print $0
		} 
	}
		END {
		}
		' > $3 ;;
Sp*)
	echo "PostScript To EPSF Filter"
	echo "Converting Landscape Splus File:" $2
	echo "Output to File:" $3
	cat $2 | \
	awk '
	BEGIN { }
	{
		if ($0 ~ /^%%BoundingBox/)
		{
			print $1 " 20 150 792 792"
		}
		if ($0 ~ /Landscape true def/)
		{
			print $1, "false",  $3
		}
		if ($0 ~ /^\/Region /)
		{
			print "/Region [20 150 792 792] def"
		}
		if ($0 !~ /Landscape true def/&& $0 !~ /^\/Region / && $0 !~ /^%%BoundingBox/)
		{
			print $0
		} 
	}
		END {
		}
		' > $3 ;;
ma*)
	echo "PostScript To EPSF Filter"
	echo "Converting Mathematica File:" $2
	echo "Output to File:" $3
	cat $2 | \
	awk '
	BEGIN { }
	{
		if ($0 ~ /^%!/)
		{
			print $0
			print "%%BoundingBox: 0 100 612 632"
		}
		else
		{
			print $0
		} 
	}
		END {
		}
		' > $3 ;;
*)
	echo 'unexpected name:' $1 ;;
esac
	

-- 
Jay Hyman                                            jay@ctr.columbia.edu  
Center for Telecommunications Research                Columbia University