[comp.text] Postscript within TeX/LaTeX

charlie@mica.stat.washington.edu (Charlie Geyer) (03/19/89)

Several people have asked lately how to include PostScript in TeX.  The
following is the way I have worked out after playing with it for about a
year.

It uses the LaTeX figure environment to get the exact placement on the
page of the \special command.  There are two macros \psinc (for PostScript
INClude) and \framepsinc.  The usage is \psinc(arg1,arg2){arg3} where arg1
is the width of the included figure in inches, arg2 the height, and arg3
the arguments to the \special command.  The usage for \framepsinc is the
same (it just puts the figure in a framebox).

When the files "woof.inc" and "woof.tex" are cut out

  latex woof
  dvi2ps woof.dvi | lpr

does the example.

Note the comment about the PostScript showpage command in "woof.inc." 
Dvi2ps does not disable page ejects.  If you are producing PostScript with
a driver that is expecting its output to be printed directly, you have
to remove the "showpage" commands with an editor before the file can
be included.

  sed 's/showpage//g' file1 > file2

does the trick.

Cut this out as the file "woof.inc"
-------------- cut here ----------------------
%! Magic comment indicates PostScript to UNIX
gsave
/Helvetica findfont 14 scalefont setfont
newpath
0 0 moveto
(This is a test include file.) dup stringwidth pop 2 div 144 exch sub
28 moveto show
grestore
% showpage %%% comment out "showpage" commands, they upset TeX.
-------------- cut here ----------------------
Cut this out as the file "woof.tex"
-------------- cut here ----------------------
%
% macros
%
\def\psinc(#1,#2)#3{
\setlength{\unitlength}{1in}
\centering\begin{picture}(#1,#2)
\put(0,0){\special{#3}}
\end{picture}}
%
\def\framepsinc(#1,#2)#3{
\setlength{\unitlength}{1in}
\centering\begin{picture}(#1,#2)
\put(0,0){\framebox(#1,#2)[bl]{\special{#3}}}
\end{picture}}
%
\def\postscript{{\sc PostScript}}
%
\documentstyle[12pt]{article}
\begin{document}
This is a test of including \postscript\ in \TeX\ (\LaTeX\ actually).
The text up to here is set by \TeX.  The large type in the Helvetica
font is produced by the included \postscript\ file ``woof.inc.''
\begin{figure}[h]
\psinc(4,1){psfile=woof.inc}
\caption[]{A figure made by an included \postscript\ file.}
\end{figure}

Sometimes it is useful to put a frame around the area left for the
included figure so that one can see how much of the alloted space the
figure takes up, the margins \LaTeX\ leaves around the figure, and so
forth.
\begin{figure}[h]
\framepsinc(4,1){psfile=woof.inc}
\caption[]{The same figure in a framebox.}
\end{figure}
\end{document}
-------------- cut here ----------------------