
%\hoffset=-0.1in
\voffset=-2pc
\raggedbottom
%\hsize=39pc  %\vsize=59pc  
%\maxdepth=2.2pt  \parindent=1pc
\vsize=720pt
\hsize=6.5in
\baselineskip12pt
\parskip0pt
\parindent1em
\hfuzz1.5pt
\tolerance2000

\hyphenation{Post-Script}
% Page layout
\newdimen\pagewidth \newdimen\pageheight \newdimen\ruleht
\newdimen\colwidth \newdimen\bigcolheight
\colwidth=3.1in%19pc 
\bigcolheight=1450pt%120pc
\pagewidth=\hsize \pageheight=\vsize \ruleht=.5pt
\abovedisplayskip=6pt plus 3pt minus 1pt
\belowdisplayskip=6pt plus 3pt minus 1pt
\abovedisplayshortskip=0pt plus 3pt
\belowdisplayshortskip=4pt plus 3pt
 
\newinsert\botins
\def\afoot{\strut\egroup}
\def\botpic#1{\par
      \insert\botins\bgroup\hsize=\pagewidth
      \offinterlineskip
      \interlinepenalty100 \let\par=\endgraf
        \leftskip=0pt     \rightskip=0pt      
        \splittopskip=10pt plus 1pt minus 1pt \floatingpenalty=20000
        \medskip{#1}\medskip\egroup}
\skip\botins=12pt plus 2pt minus 4pt % space added when footnote is present
\count\botins=2000 % footnote magnification factor (1 to 1)
\dimen\botins=36pc % maximum footnotes per page
 
\def\toppic#1{\par
      \insert\topins\bgroup\hsize=\pagewidth
      \interlinepenalty100 \let\par=\endgraf
      \offinterlineskip
        \leftskip=0pt     \rightskip=0pt      
        \splittopskip=10pt plus 1pt minus 1pt \floatingpenalty=20000
        \medskip{#1}\medskip\egroup}
\skip\topins=12pt plus 2pt minus 4pt % space added when footnote is present
\count\topins=2000 % footnote magnification factor (1 to 1)
\dimen\topins=36pc % maximum footnotes per page
 
\newinsert\margin
\dimen\margin=\maxdimen
%\count\margin=0 \skip\margin=0pt % marginal inserts take up no space
 
\newif\iftitle
\def\titlepage{\global\titletrue} % for pages without headlines
\def\rhead{{\sl \TeX\kern-0.1em line 7}}                           
 
\def\leftheadline{\hbox to \pagewidth{%
    \vbox to 10pt{}% strut to position the baseline
    \sl\rhead\hfil\folio         % running head flush left
    }}
\def\rightheadline{\hbox to \pagewidth{%
    \vbox to 10pt{}% strut to position the baseline
    \sl\rhead\hfil      % running head flush left  
    \folio                     % folio to right of text
    }}
 
\def\onepageout#1{\shipout\vbox{ % here we define one page of output
    \offinterlineskip % butt the boxes together
    \vbox to 2pc{ % this part goes on top of the 44pc pages
      \iftitle % the next is used for title pages
        \global\titlefalse % reset the titlepage switch
        \setcornerrules % for camera alignment
      \else\ifodd\pageno \rightheadline\else\leftheadline\fi\fi
      \vfill} % this completes the \vbox to 3pc
    \vbox to \pageheight{
      \ifvoid\margin\else % marginal info is present
        \rlap{\kern31pc\vbox to 0pt{\kern4pt\box\margin \vss}}\fi
      \ifvoid\topins\else % top note info is present
        \hrule height\ruleht width\pagewidth \kern-\ruleht \kern3pt
        \unvbox\topins
        \vskip\skip\topins \kern-3pt
        \hrule height\ruleht width\pagewidth \kern-\ruleht \kern3pt
        \vskip\skip\topins \kern-3pt
        \fi
      #1 % now insert the main information
      \vfill
      \ifvoid\botins\else % bot note info is present
        \vskip\skip\botins \kern-3pt
        \hrule height\ruleht width\pagewidth \kern-\ruleht \kern3pt
        \unvbox\botins
        \vskip\skip\botins \kern-3pt
        \hrule height\ruleht width\pagewidth \kern-\ruleht \kern3pt
        \fi
      \boxmaxdepth=\maxdepth
      } % this completes the \vbox to \pageheight
    }
  \advancepageno}
 
\def\setcornerrules{\hbox to \pagewidth{\vrule width 1pc height\ruleht
    \hfil \vrule width 1pc}
  \hbox to \pagewidth{\llap{\sevenrm(page \folio)\kern1pc}%
    \vrule height1pc width\ruleht depth 0pt
    \hfil \vrule width\ruleht depth 0pt}}
 
\output{\onepageout{\unvbox255}}
 
\newbox\partialpage
\newdimen\savesize
\def\begindoublecolumns{\begingroup
  \savesize=\vsize
  \output={\global\setbox\partialpage=\vbox{\unvbox255\bigskip}}\eject
  \output={\doublecolumnout} \hsize=\colwidth \vsize=\bigcolheight
  \advance\vsize by -2\ht\partialpage
  \advance\vsize by -2\ht\botins
  \advance\vsize by -2\ht\topins
  \pagegoal=\vsize}
\def\enddoublecolumns{\output={\balancecolumns}\eject
  \global\output={\onepageout{\unvbox255}}
  \global\vsize=\savesize
  \endgroup \pagegoal=\vsize}
 
\def\doublecolumnout{%
% \splitmaxdepth=\maxdepth
  \dimen0=\pageheight
  \advance\dimen0 by-\ht\partialpage
  \advance\dimen0 by-\ht\botins
  \advance\dimen0 by-\ht\topins
  \splittopskip=\topskip
  \setbox0=\vsplit255 to\dimen0
  \setbox2=\vsplit255 to\dimen0
  \onepageout\pagesofar
  \global\vsize=\bigcolheight
  \unvbox255 \penalty\outputpenalty}
\def\pagesofar{\unvbox\partialpage
  \wd0=\hsize \wd2=\hsize \hbox to\pagewidth{\box0\hfil\box2}}
\def\balancecolumns{\setbox0=\vbox{\unvbox255} \dimen0=\ht0
  \advance\dimen0 by\topskip \advance\dimen0 by-\baselineskip
  \divide\dimen0 by2 \splittopskip=\topskip
  {\vbadness=10000 \loop \global\setbox3=\copy0
    \global\setbox1=\vsplit3 to\dimen0
    \ifdim\ht3>\dimen0 \global\advance\dimen0 by1pt \repeat}
  \setbox0=\vbox to\dimen0{\unvbox1}
  \setbox2=\vbox to\dimen0
% {\unvbox3}
  {\dimen2=\dp3 \unvbox3 \kern-\dimen2 \vfil}
  \global\output={\balancingerror}
  \pagesofar}
\newhelp\balerrhelp{Please change the page into one that works.}
\def\balancingerror{\errhelp=\balerrhelp
  \errmessage{Page can't be balanced}
  \onepageout{\unvbox255}}
 
 
 
 
 
 
 
 
\newbox\caption
\setbox\caption=\vbox{
\hsize=3in
\tolerance=2000
\leftline{{\bf Portrait of the author on a windy day}}
\medskip
\noindent The picture at left originates from the 
following PostScript fragment.
It is 6 inches square.\par
\medskip
{\tt\frenchspacing\parskip=0pt\parindent=0pt\obeyspaces
\def\pc{\char"25}\def\lb{\char"7B}\def\rb{\char"7D}\obeylines %
\pc\pc BoundingBox: 72 216 504 648
72 72 scale
/picstr 64 string def
/imageshow \lb image showpage\rb def
1 3 translate 6 6 scale
128 128 8
[128 0 0 128 0 0]
\lb currentfile picstr readhexstring pop\rb 
imageshow
967B8D9AA3A7B9B9B9B077614B343027
27303D42463D3D343434343434302C2C
 
\pc\ 1020 lines of hex digits omitted
 
534B5358585358585353585861535861
5858615C5C535C585C61655C5C61615C
}}
\count0=4
\font\sc=cmcsc10
%\psdraft
\def\PS{{\sc PostScript}}
\def\PSF{{\it psfig\/}}
\def\Special{{\tt\char"5C special}}
\def\Vbox{{\tt\char"5C vbox}}
\def\input{{\tt\char"5C input}}
\def\Psfig{{\tt\char"5C psfig}}
\def\LaTeX{{\sc L\kern-.36em\raise.3ex\hbox{a}\kern-.15em
    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
\def\bslash{\char"5C}
\def\blob{$\star$}
\def\lb{\char"7B}
\def\rb{\char"7D}
\hrule height 0pt
\botpic{\hbox to \pagewidth {\vbox to 3 in {\vss}\hss
\vbox to 3in {\vss\box\caption\vss}}} 
\begindoublecolumns
\centerline{{\bf \TeX\ and graphics --- the {\it psfig\/} package}}
\medskip
\noindent How do you include figures and diagrams in \TeX\ documents?
In traditional publishing you'd probably reserve some space with
a \Vbox\ and paste in a carefully hand\-drawn, photo\-reduced,
cropped illustration.
But this is 1988 and Desktop Publishing is all the rage, so you 
want to do everything electronically.
And you can't help feeling rather envious of those people with
{\it Pagemaker\/} and its friends who seem to be able to do
this sort of thing at the click of a mouse button.
After all, aren't we \TeX\ users supposed to be at the leading edge
of electronic publishing?
How come the Macintosh people can do it and we can't?
Well, the simple answer is just one word --- \PS.         
(Wake up, Malcolm!)
If you have a \PS\ device all the software you need for scaling, 
translating, and clipping your graphics is actually present in the
printer --- all you have to do is to invoke these functions with
the right parameters.
This is what the \PSF\ package achieves automatically.
If you don't have a \PS\ printer or typesetter for your \TeX\ output --- get
one!
 
\PSF\ originates from the University of Pennsylvania and was advertised in
\TeX hax early last year.
It consists of a set of \TeX\ macros that you can \input\ at the start of
a Plain \TeX\ job or declare as a \LaTeX\ style option.
\PSF\ assumes that your diagrams exist as separate \PS\ files on the
system you use for \TeX ing.
This lets you prepare your figures using whatever software you might care
to use, provided that the end result is a file of \PS. 
At Daresbury there is widespread use of the {\sc ghost-}{\oldstyle 80} graphics package from
{\sc ukaea} Culham, and also {\sc sas}-graph, which can
both generate \PS, and there are tricks for capturing \PS\
output from {\it MacDraw\/} and other graphics programs
running on PCs. \PSF\ also likes your \PS\  file to have a
``bounding box'' comment near the beginning. 
This tells \PSF\ the `natural' size of the \PS\ figure --- i.e. the coordinates
of the bottom left and upper right corners of the figure in the initial \PS\
coordinate frame.
If the software used to create the figure does not generate a suitable 
bounding box comment  you can edit one  in by hand or supply the information
when you tell \TeX\ to place the figure. 
 
Suppose you have an picture in the file {\tt mypic.ps} and you want
it centred horizontally and scaled to be just 3 inches high.
A simple way to achieve this is to say
\vskip 0.2ex
\centerline{\tt\bslash centerline\lb\bslash psfig\lb figure=mypic.ps,%
height=3in\rb\rb}
\vskip 0.2ex
\noindent The \Psfig\ macro reads and parses the lines of the {\tt mypic.ps} file
looking for its bounding box comment.
This enables it to compute the desired width of the figure (keeping its
aspect ratio constant) and to reserve a \Vbox\ of exactly the right size.
Within the \Vbox\ \PSF\ inserts \Special\ control sequences which
propagate scaling information and the name of the included \PS\ file
to the  {\tt dvi} file.
 
More sophisticated effects can be achieved with further arguments in the
\Psfig\ call.
These include:\par
{\parindent=1em\parskip=0pt
\item{\blob}overriding the figure's bounding box comment;
\item{\blob}anamorphic scaling of the figure by giving both   
a {\tt width=} and a {\tt height=} argument;
\item{\blob}specifying explicitly the size of the \Vbox\ that \TeX\
reserves for the figure.
This can be used to overlap figures and text, for example;
\item{\blob}clipping the figure to an explicit bounding box. This
could be used to extract just a part of a larger figure;
\item{\blob}a draft mode where space is reserved for figures but
the figures are suppressed from the output;
\item{\blob}inclusion of a \PS\ prologue file such as the notorious
{\it LaserPrep\/} procedures needed for the correct interpretation
of {\it MacDraw}, {\it MacChart}, etc., output.
\par}
\PSF\ requires surprisingly little support from a  {\tt dvi} to \PS\ device
driver.
Essentially just two \Special s are needed:
one assumes that its argument is a fragment of \PS\ to be propagated
unchanged to the output, and the second assumes that its argument is the
name of a file of \PS\ which is to be included, also unmodified, in the
output.
The first type of \Special\ is used to establish the \PS\ environment
(principally the current transformation matrix) in which the \PS\
included by the second \Special\ is executed.
The work of transforming the original figure is done by the
graphic transformation machinery in the %\PS\ 
printer when the output is
printed.
This is in distinct contrast to the code needed in, say, a  {\tt dvi} to LN03
device driver to achieve the same effect, and exemplifies the power
and generality of the \PS\ language.
 
To sum up, the \PSF\ package is a practical way of integrating figures
with \TeX\ documents.
Figures can be originated using any software package that can output \PS.
It requires only elementary device driver support for \Special s.
We have found it quite adequate for scientific papers and technical manuals
requiring, for example, graphs of experimental data or schematic
diagrams.
It's tolerably simple to use and works quite nicely with the \LaTeX\ 
{\tt figure} environment.
Of course, \PSF\ is firmly in the \PS\ world.
The \LaTeX\ {\tt picture} environment and the Pic\TeX\ package are
device independent but the former supports only a limited range of   vector 
orientations and circle diameters and the latter, though general, is restricted
to relatively simple line graphics if \TeX's memory capacity is not to be
exceeded.
Under {\sc unix}, {\tt tpic} does for \TeX\ what {\tt pic} and its friends do
for {\tt troff}, but appears to be available only to licencees of {\sc at\&t'}s
{\tt ditroff} typesetting software.
The \TeX tyl system avoids overloading \TeX\ by passing graphics primitives
transparently in {\tt\bslash special}s and relying on a  {\tt dvi} postprocessor
to expand them into a (large) {\tt\bslash special}-free  {\tt dvi} file.
But for my money 
\PS\ is really the only choice today if you must have integrated
text and graphics.\par
%(Sorry, Malcolm!)

\rightline{\sl David Brightly}
%\leftline{Daresbury Laboratory, SERC}
%\leftline{Warrington, WA4 4AD}
%\leftline{0925 603574}
%\leftline{Janet: {\tt brightly @ daresbury}}
\enddoublecolumns
\toppic{\vbox{\centerline{\vbox to 4.7 in {\vss}}\medskip
\centerline{\bf Mapping the original picture {\it(left)\/} into the 
\TeX\ page {\it(right)\/}}}}
 
\end
