% 11-Nov-88 17:29   Allan.Heydon@HOKUSAI.THEORY.CS.CMU.EDU   macros
% for centering PS figures 

% Below is a LaTeX file containing macro definitions to include
% PostScript figures in a document and automatically center them. The
% macros are enhancements to a macro written by Brad White. Basically,
% the enhancements allow either Macintosh-generated or "normal"
% PostScript files (such as those produced by xfig(1) to be included.
% The PostScript files can also be scaled horizontally and vertically. 

% psfigure.tex -- macro definitions for including PostScript files in
%		  pictures. Based on code by Brad White.
%
% Macros Defined:
%   \macpsfigure, \normalpsfigure
%   \macpsfigureScaled, \normalpsfigureScaled
%   \psfigure
%
% To Use in a LaTeX \figure:
% \begin{figure}[hbt] % options: h=here, b=bottom, t=top, p=page of floats
%    \macpsfigureScaled{\figplain}{5in}{3.5in}{0.6}{0.6}{example.ps}
%    \caption{A Centered 5 x 3.5 inch Picture Scaled by 6/10 in
%	      Both Directions.
%	      \label{fig:example-figure}}
% \end{figure}
%
% ---------------------------------------------------------------------------
%
% \macpsfigure{style}{width}{height}{file}
% \normalpsfigure{style}{width}{height}{file}
%
% where:
%  style	is one of \figplain (plain figure), \figboxed (boxed
%		figure), or \figomit (omit the figure alltogether)
%  width	is the width of the picture (a dimension)
%  height	is the height of the picture (a dimension)
%  file		is the name of the postscript file to include inside
%		the \special command
%
% Dimensions (for 'width' and 'height') in TeX must have units such as
% ``in'' for inches, ``cm'' for centimeter, ``pt'' for points. The
% units for the 'width' and 'height' dimensions need not be the same.
%
% These macros produce the PostScript figure in file 'file' centered
% on the page.  The only difference between the ``mac'' and ``normal''
% macros is how the origin of the included PostScript file is
% considered to be situated in the picture. Use \macpsfigure for
% PostScript files generated by a Macintosh; use \normalpsfigure for
% PostScript files generated by programs like xfig(1).
%
% EXAMPLES:
%
% \macpsfigure{\figplain}{5in}{3in}{foo.ps}
%    Centers the picture ``foo.ps'' which is 5 inches across and 3
%    inches high.
%
% \normalpsfigure{\figomit}{3.2cm}{4.3in}{Figures/example-1.ps}
%    Centers (in a box) the picture in the file
%    ``Figures/example-1.ps'' which is 3.2 centimeters wide and
%    4.3 inches high.
%
% ---------------------------------------------------------------------------
%
% \macpsfigureScaled{style}{width}{height}{width-scale}{height-scale}{file}
% \normalpsfigureScaled{style}{width}{height}{width-scale}{height-scale}{file}
%
% where:
%  style, width, height, file are as above
%  width-scale	is a factor representing how much the picture should
%		be scaled in the horizontal direction
%  height-scale is a factor representing how much the picture should
%		be scaled in the vertical direction
%
% These macros are like their couterparts \macpsfigure and
% \normalpsfigure, but they allow the user to specify that the picture
% should be scaled in either or both directions. The dimensions 'width'
% and 'height' should be the dimensions of the picture *before
% scaling*.
%
% ---------------------------------------------------------------------------
%
% \psfigure{style}{x}{y}{x-scale}{y-scale}{file}{invert-origin-p}
%
% where:
%  x		is the width of the picture
%  y		is the height of the picture
%  x-scale	is the amount to scale the picture in the x direction
%  y-scale	is the amount to scale the picture in the y direction
%  file		is the name of the input file (extension required)
%  invert-origin-p	is either \iftrue or \iffalse depending on
%			whether or not the origin is at the top or
%			bottom of the picture, respectively.
%
% ---------------------------------------------------------------------------
%
\newcommand{\macpsfigure}[4]{%
\psfigure{#1}{#2}{#3}{1.0}{1.0}{#4}{\iftrue}}
%
\newcommand{\normalpsfigure}[4]{%
\psfigure{#1}{#2}{#3}{1.0}{1.0}{#4}{\iffalse}}
%
% ---------------------------------------------------------------------------
%
\newcommand{\macpsfigureScaled}[6]{%
\psfigure{#1}{#2}{#3}{#4}{#5}{#6}{\iftrue}}
%
\newcommand{\normalpsfigureScaled}[6]{%
\psfigure{#1}{#2}{#3}{#4}{#5}{#6}{\iffalse}}
%
% ---------------------------------------------------------------------------
%
% Define \figplain, \figboxed, \figomit to be integers 0, 1, 2
%
\def\figplain{0}
\def\figboxed{1}
\def\figomit{2}
%
% ---------------------------------------------------------------------------
%
\newcommand{\psfigure}[7]{
    \begingroup
	\countdef\width=127 \countdef\height=126
	\countdef\offset=125 \countdef\pagewidth=124
	\dimen255=#2 \dimen255=#4\dimen255 \width=\dimen255
	\dimen255=#3 \dimen255=#5\dimen255 \height=\dimen255
	\offset=-\textwidth \advance\offset\width \divide\offset 2
	\pagewidth=\textwidth
	\setlength{\unitlength}{1sp}
	\begin{picture}(\pagewidth,\height)(\offset,{#7-\height\else 0\fi})
	\ifcase #1
%	  Case: \figplain
	    \put(0,0){\special{psfile=#6 hscale=#4 vscale=#5}} \or
%	  Case: \figboxed
	    \put(0,0){\special{psfile=#6 hscale=#4 vscale=#5}}
	    \put(0,0){\framebox(\width,\height){}} \or
%	  Case: \figomit
	    \put(0,0){\framebox(\width,\height){#6}}
%	  Default:
	    \else\typeout{Bad style for \psfigure}
	\fi
	\end{picture}\hfill
    \endgroup
}

