Blame doc/pmi/epsf.sty

Packit Service c5cf8c
%   EPSF.TEX macro file:
Packit Service c5cf8c
%   Written by Tomas Rokicki of Radical Eye Software, 29 Mar 1989.
Packit Service c5cf8c
%   Revised by Don Knuth, 3 Jan 1990.
Packit Service c5cf8c
%   Revised by Tomas Rokicki to accept bounding boxes with no
Packit Service c5cf8c
%      space after the colon, 18 Jul 1990.
Packit Service c5cf8c
%
Packit Service c5cf8c
%   TeX macros to include an Encapsulated PostScript graphic.
Packit Service c5cf8c
%   Works by finding the bounding box comment,
Packit Service c5cf8c
%   calculating the correct scale values, and inserting a vbox
Packit Service c5cf8c
%   of the appropriate size at the current position in the TeX document.
Packit Service c5cf8c
%
Packit Service c5cf8c
%   To use with the center environment of LaTeX, preface the \epsffile
Packit Service c5cf8c
%   call with a \leavevmode.  (LaTeX should probably supply this itself
Packit Service c5cf8c
%   for the center environment.)
Packit Service c5cf8c
%
Packit Service c5cf8c
%   To use, simply say
Packit Service c5cf8c
%   \input epsf           % somewhere early on in your TeX file
Packit Service c5cf8c
%   \epsfbox{filename.ps} % where you want to insert a vbox for a figure
Packit Service c5cf8c
%
Packit Service c5cf8c
%   Alternatively, you can type
Packit Service c5cf8c
%
Packit Service c5cf8c
%   \epsfbox[0 0 30 50]{filename.ps} % to supply your own BB
Packit Service c5cf8c
%
Packit Service c5cf8c
%   which will not read in the file, and will instead use the bounding
Packit Service c5cf8c
%   box you specify.
Packit Service c5cf8c
%
Packit Service c5cf8c
%   The effect will be to typeset the figure as a TeX box, at the
Packit Service c5cf8c
%   point of your \epsfbox command. By default, the graphic will have its
Packit Service c5cf8c
%   `natural' width (namely the width of its bounding box, as described
Packit Service c5cf8c
%   in filename.ps). The TeX box will have depth zero.
Packit Service c5cf8c
%
Packit Service c5cf8c
%   You can enlarge or reduce the figure by saying
Packit Service c5cf8c
%     \epsfxsize=<dimen> \epsfbox{filename.ps}
Packit Service c5cf8c
%   (or
Packit Service c5cf8c
%     \epsfysize=<dimen> \epsfbox{filename.ps})
Packit Service c5cf8c
%   instead. Then the width of the TeX box will be \epsfxsize and its
Packit Service c5cf8c
%   height will be scaled proportionately (or the height will be
Packit Service c5cf8c
%   \epsfysize and its width will be scaled proportiontally).  The
Packit Service c5cf8c
%   width (and height) is restored to zero after each use.
Packit Service c5cf8c
%
Packit Service c5cf8c
%   A more general facility for sizing is available by defining the
Packit Service c5cf8c
%   \epsfsize macro.    Normally you can redefine this macro
Packit Service c5cf8c
%   to do almost anything.  The first parameter is the natural x size of
Packit Service c5cf8c
%   the PostScript graphic, the second parameter is the natural y size
Packit Service c5cf8c
%   of the PostScript graphic.  It must return the xsize to use, or 0 if
Packit Service c5cf8c
%   natural scaling is to be used.  Common uses include:
Packit Service c5cf8c
%
Packit Service c5cf8c
%      \epsfxsize  % just leave the old value alone
Packit Service c5cf8c
%      0pt         % use the natural sizes
Packit Service c5cf8c
%      #1          % use the natural sizes
Packit Service c5cf8c
%      \hsize      % scale to full width
Packit Service c5cf8c
%      0.5#1       % scale to 50% of natural size
Packit Service c5cf8c
%      \ifnum#1>\hsize\hsize\else#1\fi  % smaller of natural, hsize
Packit Service c5cf8c
%
Packit Service c5cf8c
%   If you want TeX to report the size of the figure (as a message
Packit Service c5cf8c
%   on your terminal when it processes each figure), say `\epsfverbosetrue'.
Packit Service c5cf8c
%
Packit Service c5cf8c
\newread\epsffilein    % file to \read
Packit Service c5cf8c
\newif\ifepsffileok    % continue looking for the bounding box?
Packit Service c5cf8c
\newif\ifepsfbbfound   % success?
Packit Service c5cf8c
\newif\ifepsfverbose   % report what you're making?
Packit Service c5cf8c
\newdimen\epsfxsize    % horizontal size after scaling
Packit Service c5cf8c
\newdimen\epsfysize    % vertical size after scaling
Packit Service c5cf8c
\newdimen\epsftsize    % horizontal size before scaling
Packit Service c5cf8c
\newdimen\epsfrsize    % vertical size before scaling
Packit Service c5cf8c
\newdimen\epsftmp      % register for arithmetic manipulation
Packit Service c5cf8c
\newdimen\pspoints     % conversion factor
Packit Service c5cf8c
%
Packit Service c5cf8c
\pspoints=1bp          % Adobe points are `big'
Packit Service c5cf8c
\epsfxsize=0pt         % Default value, means `use natural size'
Packit Service c5cf8c
\epsfysize=0pt         % ditto
Packit Service c5cf8c
%
Packit Service c5cf8c
\def\epsfbox#1{\global\def\epsfllx{72}\global\def\epsflly{72}%
Packit Service c5cf8c
   \global\def\epsfurx{540}\global\def\epsfury{720}%
Packit Service c5cf8c
   \def\lbracket{[}\def\testit{#1}\ifx\testit\lbracket
Packit Service c5cf8c
   \let\next=\epsfgetlitbb\else\let\next=\epsfnormal\fi\next{#1}}%
Packit Service c5cf8c
%
Packit Service c5cf8c
\def\epsfgetlitbb#1#2 #3 #4 #5]#6{\epsfgrab #2 #3 #4 #5 .\\%
Packit Service c5cf8c
   \epsfsetgraph{#6}}%
Packit Service c5cf8c
%
Packit Service c5cf8c
\def\epsfnormal#1{\epsfgetbb{#1}\epsfsetgraph{#1}}%
Packit Service c5cf8c
%
Packit Service c5cf8c
\def\epsfgetbb#1{%
Packit Service c5cf8c
%
Packit Service c5cf8c
%   The first thing we need to do is to open the
Packit Service c5cf8c
%   PostScript file, if possible.
Packit Service c5cf8c
%
Packit Service c5cf8c
\openin\epsffilein=#1
Packit Service c5cf8c
\ifeof\epsffilein\errmessage{I couldn't open #1, will ignore it}\else
Packit Service c5cf8c
%
Packit Service c5cf8c
%   Okay, we got it. Now we'll scan lines until we find one that doesn't
Packit Service c5cf8c
%   start with %. We're looking for the bounding box comment.
Packit Service c5cf8c
%
Packit Service c5cf8c
   {\epsffileoktrue \chardef\other=12
Packit Service c5cf8c
    \def\do##1{\catcode`##1=\other}\dospecials \catcode`\ =10
Packit Service c5cf8c
    \loop
Packit Service c5cf8c
       \read\epsffilein to \epsffileline
Packit Service c5cf8c
       \ifeof\epsffilein\epsffileokfalse\else
Packit Service c5cf8c
%
Packit Service c5cf8c
%   We check to see if the first character is a % sign;
Packit Service c5cf8c
%   if not, we stop reading (unless the line was entirely blank);
Packit Service c5cf8c
%   if so, we look further and stop only if the line begins with
Packit Service c5cf8c
%   `%%BoundingBox:'.
Packit Service c5cf8c
%
Packit Service c5cf8c
          \expandafter\epsfaux\epsffileline:. \\%
Packit Service c5cf8c
       \fi
Packit Service c5cf8c
   \ifepsffileok\repeat
Packit Service c5cf8c
   \ifepsfbbfound\else
Packit Service c5cf8c
    \ifepsfverbose\message{No bounding box comment in #1; using defaults}\fi\fi
Packit Service c5cf8c
   }\closein\epsffilein\fi}%
Packit Service c5cf8c
%
Packit Service c5cf8c
%   Now we have to calculate the scale and offset values to use.
Packit Service c5cf8c
%   First we compute the natural sizes.
Packit Service c5cf8c
%
Packit Service c5cf8c
\def\epsfsetgraph#1{%
Packit Service c5cf8c
   \epsfrsize=\epsfury\pspoints
Packit Service c5cf8c
   \advance\epsfrsize by-\epsflly\pspoints
Packit Service c5cf8c
   \epsftsize=\epsfurx\pspoints
Packit Service c5cf8c
   \advance\epsftsize by-\epsfllx\pspoints
Packit Service c5cf8c
%
Packit Service c5cf8c
%   If `epsfxsize' is 0, we default to the natural size of the picture.
Packit Service c5cf8c
%   Otherwise we scale the graph to be \epsfxsize wide.
Packit Service c5cf8c
%
Packit Service c5cf8c
   \epsfxsize\epsfsize\epsftsize\epsfrsize
Packit Service c5cf8c
   \ifnum\epsfxsize=0 \ifnum\epsfysize=0
Packit Service c5cf8c
      \epsfxsize=\epsftsize \epsfysize=\epsfrsize
Packit Service c5cf8c
%
Packit Service c5cf8c
%   We have a sticky problem here:  TeX doesn't do floating point arithmetic!
Packit Service c5cf8c
%   Our goal is to compute y = rx/t. The following loop does this reasonably
Packit Service c5cf8c
%   fast, with an error of at most about 16 sp (about 1/4000 pt).
Packit Service c5cf8c
% 
Packit Service c5cf8c
     \else\epsftmp=\epsftsize \divide\epsftmp\epsfrsize
Packit Service c5cf8c
       \epsfxsize=\epsfysize \multiply\epsfxsize\epsftmp
Packit Service c5cf8c
       \multiply\epsftmp\epsfrsize \advance\epsftsize-\epsftmp
Packit Service c5cf8c
       \epsftmp=\epsfysize
Packit Service c5cf8c
       \loop \advance\epsftsize\epsftsize \divide\epsftmp 2
Packit Service c5cf8c
       \ifnum\epsftmp>0
Packit Service c5cf8c
          \ifnum\epsftsize<\epsfrsize\else
Packit Service c5cf8c
             \advance\epsftsize-\epsfrsize \advance\epsfxsize\epsftmp \fi
Packit Service c5cf8c
       \repeat
Packit Service c5cf8c
     \fi
Packit Service c5cf8c
   \else\epsftmp=\epsfrsize \divide\epsftmp\epsftsize
Packit Service c5cf8c
     \epsfysize=\epsfxsize \multiply\epsfysize\epsftmp   
Packit Service c5cf8c
     \multiply\epsftmp\epsftsize \advance\epsfrsize-\epsftmp
Packit Service c5cf8c
     \epsftmp=\epsfxsize
Packit Service c5cf8c
     \loop \advance\epsfrsize\epsfrsize \divide\epsftmp 2
Packit Service c5cf8c
     \ifnum\epsftmp>0
Packit Service c5cf8c
        \ifnum\epsfrsize<\epsftsize\else
Packit Service c5cf8c
           \advance\epsfrsize-\epsftsize \advance\epsfysize\epsftmp \fi
Packit Service c5cf8c
     \repeat     
Packit Service c5cf8c
   \fi
Packit Service c5cf8c
%
Packit Service c5cf8c
%  Finally, we make the vbox and stick in a \special that dvips can parse.
Packit Service c5cf8c
%
Packit Service c5cf8c
   \ifepsfverbose\message{#1: width=\the\epsfxsize, height=\the\epsfysize}\fi
Packit Service c5cf8c
   \epsftmp=10\epsfxsize \divide\epsftmp\pspoints
Packit Service c5cf8c
   \vbox to\epsfysize{\vfil\hbox to\epsfxsize{%
Packit Service c5cf8c
      \special{PSfile=#1 llx=\epsfllx\space lly=\epsflly\space
Packit Service c5cf8c
          urx=\epsfurx\space ury=\epsfury\space rwi=\number\epsftmp}%
Packit Service c5cf8c
      \hfil}}%
Packit Service c5cf8c
\epsfxsize=0pt\epsfysize=0pt}%
Packit Service c5cf8c
Packit Service c5cf8c
%
Packit Service c5cf8c
%   We still need to define the tricky \epsfaux macro. This requires
Packit Service c5cf8c
%   a couple of magic constants for comparison purposes.
Packit Service c5cf8c
%
Packit Service c5cf8c
{\catcode`\%=12 \global\let\epsfpercent=%\global\def\epsfbblit{%BoundingBox}}%
Packit Service c5cf8c
%
Packit Service c5cf8c
%   So we're ready to check for `%BoundingBox:' and to grab the
Packit Service c5cf8c
%   values if they are found.
Packit Service c5cf8c
%
Packit Service c5cf8c
\long\def\epsfaux#1#2:#3\\{\ifx#1\epsfpercent
Packit Service c5cf8c
   \def\testit{#2}\ifx\testit\epsfbblit
Packit Service c5cf8c
      \epsfgrab #3 . . . \\%
Packit Service c5cf8c
      \epsffileokfalse
Packit Service c5cf8c
      \global\epsfbbfoundtrue
Packit Service c5cf8c
   \fi\else\ifx#1\par\else\epsffileokfalse\fi\fi}%
Packit Service c5cf8c
%
Packit Service c5cf8c
%   Here we grab the values and stuff them in the appropriate definitions.
Packit Service c5cf8c
%
Packit Service c5cf8c
\def\epsfgrab #1 #2 #3 #4 #5\\{%
Packit Service c5cf8c
   \global\def\epsfllx{#1}\ifx\epsfllx\empty
Packit Service c5cf8c
      \epsfgrab #2 #3 #4 #5 .\\\else
Packit Service c5cf8c
   \global\def\epsflly{#2}%
Packit Service c5cf8c
   \global\def\epsfurx{#3}\global\def\epsfury{#4}\fi}%
Packit Service c5cf8c
%
Packit Service c5cf8c
%   We default the epsfsize macro.
Packit Service c5cf8c
%
Packit Service c5cf8c
\def\epsfsize#1#2{\epsfxsize}
Packit Service c5cf8c
%
Packit Service c5cf8c
%   Finally, another definition for compatibility with older macros.
Packit Service c5cf8c
%
Packit Service c5cf8c
\let\epsffile=\epsfbox