1226584Sdim%%% ====================================================================
2226584Sdim%%%   This file is freely redistributable and placed into the
3226584Sdim%%%   public domain by Tomas Rokicki.
4226584Sdim%%%  @TeX-file{
5226584Sdim%%%     author          = "Tom Rokicki",
6226584Sdim%%%     version         = "2.7k",
7226584Sdim%%%     date            = "19 July 1997",
8226584Sdim%%%     time            = "10:00:05 MDT",
9226584Sdim%%%     filename        = "epsf.tex",
10226584Sdim%%%     address         = "Tom Rokicki
11226584Sdim%%%                        Box 2081
12226584Sdim%%%                        Stanford, CA 94309
13226584Sdim%%%                        USA",
14226584Sdim%%%     telephone       = "+1 415 855 9989",
15226584Sdim%%%     email           = "rokicki@cs.stanford.edu (Internet)",
16226584Sdim%%%     codetable       = "ISO/ASCII",
17226584Sdim%%%     keywords        = "PostScript, TeX",
18226584Sdim%%%     supported       = "yes",
19226584Sdim%%%     abstract        = "This file contains macros to support the inclusion
20226584Sdim%%%                        of Encapsulated PostScript files in TeX documents.",
21226584Sdim%%%     docstring       = "This file contains TeX macros to include an
22226584Sdim%%%                        Encapsulated PostScript graphic.  It works
23226584Sdim%%%                        by finding the bounding box comment,
24226584Sdim%%%                        calculating the correct scale values, and
25234353Sdim%%%                        inserting a vbox of the appropriate size at
26226584Sdim%%%                        the current position in the TeX document.
27226584Sdim%%%
28234353Sdim%%%                        To use, simply say
29226584Sdim%%%
30226584Sdim%%%                        \input epsf % somewhere early on in your TeX file
31226584Sdim%%%
32226584Sdim%%%                        % then where you want to insert a vbox for a figure:
33226584Sdim%%%                        \epsfbox{filename.ps}
34226584Sdim%%%
35234353Sdim%%%                        Alternatively, you can supply your own
36243830Sdim%%%                        bounding box by
37243830Sdim%%%
38234353Sdim%%%                        \epsfbox[0 0 30 50]{filename.ps}
39234982Sdim%%%
40243830Sdim%%%                        This will not read in the file, and will
41243830Sdim%%%                        instead use the bounding box you specify.
42243830Sdim%%%
43234982Sdim%%%                        The effect will be to typeset the figure as
44234982Sdim%%%                        a TeX box, at the point of your \epsfbox
45234982Sdim%%%                        command. By default, the graphic will have
46234982Sdim%%%                        its `natural' width (namely the width of
47243830Sdim%%%                        its bounding box, as described in
48243830Sdim%%%                        filename.ps). The TeX box will have depth
49243830Sdim%%%                        zero.
50243830Sdim%%%
51226584Sdim%%%                        You can enlarge or reduce the figure by
52226584Sdim%%%                        saying
53226584Sdim%%%
54226584Sdim%%%                          \epsfxsize=<dimen> \epsfbox{filename.ps}
55226584Sdim%%%                        or
56226584Sdim%%%                          \epsfysize=<dimen> \epsfbox{filename.ps}
57226584Sdim%%%
58226584Sdim%%%                        instead. Then the width of the TeX box will
59243830Sdim%%%                        be \epsfxsize and its height will be scaled
60243830Sdim%%%                        proportionately (or the height will be
61226584Sdim%%%                        \epsfysize and its width will be scaled
62226584Sdim%%%                        proportionately).
63226584Sdim%%%
64226584Sdim%%%                        The width (and height) is restored to zero
65226584Sdim%%%                        after each use, so \epsfxsize or \epsfysize
66226584Sdim%%%                        must be specified before EACH use of
67226584Sdim%%%                        \epsfbox.
68226584Sdim%%%
69226584Sdim%%%                        A more general facility for sizing is
70226584Sdim%%%                        available by defining the \epsfsize macro.
71226584Sdim%%%                        Normally you can redefine this macro to do
72226584Sdim%%%                        almost anything.  The first parameter is
73226584Sdim%%%                        the natural x size of the PostScript
74226584Sdim%%%                        graphic, the second parameter is the
75226584Sdim%%%                        natural y size of the PostScript graphic.
76226584Sdim%%%                        It must return the xsize to use, or 0 if
77226584Sdim%%%                        natural scaling is to be used.  Common uses
78226584Sdim%%%                        include:
79226584Sdim%%%
80226584Sdim%%%                           \epsfxsize  % just leave the old value alone
81226584Sdim%%%                           0pt         % use the natural sizes
82226584Sdim%%%                           #1          % use the natural sizes
83226584Sdim%%%                           \hsize      % scale to full width
84226584Sdim%%%                           0.5#1       % scale to 50% of natural size
85226584Sdim%%%                           \ifnum #1>\hsize\hsize\else#1\fi
86226584Sdim%%%                                       % smaller of natural, hsize
87226584Sdim%%%
88226584Sdim%%%                        If you want TeX to report the size of the
89226584Sdim%%%                        figure (as a message on your terminal when
90226584Sdim%%%                        it processes each figure), say
91226584Sdim%%%                        `\epsfverbosetrue'.
92226584Sdim%%%
93226584Sdim%%%                        If you only want to get the bounding box
94226584Sdim%%%                        extents, without producing any output boxes
95226584Sdim%%%                        or \special{}, then say
96226584Sdim%%%                        \epsfgetbb{filename}.  The extents will be
97226584Sdim%%%                        saved in the macros \epsfllx \epsflly
98226584Sdim%%%                        \epsfurx \epsfury in PostScript units of
99226584Sdim%%%                        big points.
100226584Sdim%%%
101226584Sdim%%%                        Revision history:
102226584Sdim%%%
103226584Sdim%%%                        ---------------------------------------------
104226584Sdim%%%                        epsf.tex macro file:
105226584Sdim%%%                        Originally written by Tomas Rokicki of
106226584Sdim%%%                        Radical Eye Software, 29 Mar 1989.
107226584Sdim%%%
108226584Sdim%%%                        ---------------------------------------------
109226584Sdim%%%                        Revised by Don Knuth, 3 Jan 1990.
110226584Sdim%%%
111226584Sdim%%%                        ---------------------------------------------
112243830Sdim%%%                        Revised by Tomas Rokicki, 18 Jul 1990.
113243830Sdim%%%                        Accept bounding boxes with no space after
114243830Sdim%%%                        the colon.
115243830Sdim%%%
116226584Sdim%%%                        ---------------------------------------------
117226584Sdim%%%                        Revised by Nelson H. F. Beebe
118226584Sdim%%%                        <beebe@math.utah.edu>, 03 Dec 1991 [2.0].
119226584Sdim%%%                        Add version number and date typeout.
120226584Sdim%%%
121226584Sdim%%%                        Use \immediate\write16 instead of \message
122226584Sdim%%%                        to ensure output on new line.
123226584Sdim%%%
124226584Sdim%%%                        Handle nested EPS files.
125226584Sdim%%%
126226584Sdim%%%                        Handle %%BoundingBox: (atend) lines.
127243830Sdim%%%
128243830Sdim%%%                        Do not quit when blank lines are found.
129243830Sdim%%%
130243830Sdim%%%                        Add a few percents to remove generation of
131243830Sdim%%%                        spurious blank space.
132243830Sdim%%%
133243830Sdim%%%                        Move \special output to
134243830Sdim%%%                        \epsfspecial{filename} so that other macro
135234353Sdim%%%                        packages can input this one, then change
136226584Sdim%%%                        the definition of \epsfspecial to match
137226584Sdim%%%                        another DVI driver.
138226584Sdim%%%
139226584Sdim%%%                        Move size computation to \epsfsetsize which
140226584Sdim%%%                        can be called by the user; the verbose
141226584Sdim%%%                        output of the bounding box and scaled width
142226584Sdim%%%                        and height happens here.
143226584Sdim%%%
144226584Sdim%%%                        ---------------------------------------------
145234353Sdim%%%                        Revised by Nelson H. F. Beebe
146234353Sdim%%%                        <beebe@math.utah.edu>, 05 May 1992 [2.1].
147226584Sdim%%%                        Wrap \leavevmode\hbox{} around \vbox{} with
148226584Sdim%%%                        the \special so that \epsffile{} can be
149226584Sdim%%%                        used inside \begin{center}...\end{center}
150226584Sdim%%%
151226584Sdim%%%                        ---------------------------------------------
152226584Sdim%%%                        Revised by Nelson H. F. Beebe
153226584Sdim%%%                        <beebe@math.utah.edu>, 09 Dec 1992 [2.2].
154226584Sdim%%%                        Introduce \epsfshow{true,false} and
155226584Sdim%%%                        \epsfframe{true,false} macros; the latter
156226584Sdim%%%                        suppresses the insertion of the PostScript,
157226584Sdim%%%                        and instead just creates an empty box,
158226584Sdim%%%                        which may be handy for rapid prototyping.
159226584Sdim%%%
160226584Sdim%%%                        ---------------------------------------------
161226584Sdim%%%                        Revised by Nelson H. F. Beebe
162226584Sdim%%%                        <beebe@math.utah.edu>, 14 Dec 1992 [2.3].
163226584Sdim%%%                        Add \epsfshowfilename{true,false}.  When
164226584Sdim%%%                        true, and \epsfshowfalse is specified, the
165226584Sdim%%%                        PostScript file name will be displayed
166226584Sdim%%%                        centered in the figure box.
167226584Sdim%%%
168226584Sdim%%%                        ---------------------------------------------
169226584Sdim%%%                        Revised by Nelson H. F. Beebe
170243830Sdim%%%                        <beebe@math.utah.edu>, 20 June 1993 [2.4].
171243830Sdim%%%                        Remove non-zero debug setting of \epsfframemargin,
172243830Sdim%%%                        and change margin handling to preserve EPS image
173243830Sdim%%%                        size and aspect ratio, so that the actual
174226584Sdim%%%                        box is \epsfxsize+\epsfframemargin wide by
175226584Sdim%%%                        \epsfysize+\epsfframemargin high.
176226584Sdim%%%                        Reduce output of \epsfshowfilenametrue to
177226584Sdim%%%                        just the bare file name.
178226584Sdim%%%
179226584Sdim%%%                        ---------------------------------------------
180226584Sdim%%%                        Revised by Nelson H. F. Beebe
181226584Sdim%%%                        <beebe@math.utah.edu>, 13 July 1993 [2.5].
182226584Sdim%%%                        Add \epsfframethickness for control of
183226584Sdim%%%                        \epsfframe frame lines.
184226584Sdim%%%
185226584Sdim%%%                        ---------------------------------------------
186226584Sdim%%%                        Revised by Nelson H. F. Beebe
187226584Sdim%%%                        <beebe@math.utah.edu>, 02 July 1996 [2.6]
188226584Sdim%%%                        Add missing initialization \epsfatendfalse;
189226584Sdim%%%                        the lack of this resulted in the wrong
190226584Sdim%%%                        BoundingBox being picked up, mea culpa, sigh...
191226584Sdim%%%                        ---------------------------------------------
192243830Sdim%%%
193243830Sdim%%%                        ---------------------------------------------
194243830Sdim%%%                        Revised by Nelson H. F. Beebe
195243830Sdim%%%                        <beebe@math.utah.edu>, 25 October 1996 [2.7]
196243830Sdim%%%                        Update to match changes in from dvips 5-600
197243830Sdim%%%                        distribution: new user-accessible macros:
198226584Sdim%%%                        \epsfclipon, \epsfclipoff, \epsfdrafton,
199226584Sdim%%%                        \epsfdraftoff, change \empty to \epsfempty.
200226584Sdim%%%                        ---------------------------------------------
201226584Sdim%%%                        
202226584Sdim%%%                        Modified to avoid verbosity, give help.
203226584Sdim%%%                        --kb@cs.umb.edu, for Texinfo.
204226584Sdim%%%  }
205226584Sdim%%% ====================================================================
206226584Sdim%
207226584Sdim\ifx\epsfannounce\undefined \def\epsfannounce{\immediate\write16}\fi
208226584Sdim \epsfannounce{This is `epsf.tex' v2.7k <10 July 1997>}%
209226584Sdim%
210226584Sdim\newread\epsffilein    % file to \read
211226584Sdim\newif\ifepsfatend     % need to scan to LAST %%BoundingBox comment?
212226584Sdim\newif\ifepsfbbfound   % success?
213226584Sdim\newif\ifepsfdraft     % use draft mode?
214226584Sdim\newif\ifepsffileok    % continue looking for the bounding box?
215226584Sdim\newif\ifepsfframe     % frame the bounding box?
216234353Sdim\newif\ifepsfshow      % show PostScript file, or just bounding box?
217234353Sdim\epsfshowtrue          % default is to display PostScript file
218234353Sdim\newif\ifepsfshowfilename % show the file name if \epsfshowfalse specified?
219234982Sdim\newif\ifepsfverbose   % report what you're making?
220234982Sdim\newdimen\epsfframemargin % margin between box and frame
221234982Sdim\newdimen\epsfframethickness % thickness of frame rules
222234982Sdim\newdimen\epsfrsize    % vertical size before scaling
223234353Sdim\newdimen\epsftmp      % register for arithmetic manipulation
224234353Sdim\newdimen\epsftsize    % horizontal size before scaling
225226584Sdim\newdimen\epsfxsize    % horizontal size after scaling
226226584Sdim\newdimen\epsfysize    % vertical size after scaling
227226584Sdim\newdimen\pspoints     % conversion factor
228226584Sdim%
229226584Sdim\pspoints = 1bp        % Adobe points are `big'
230226584Sdim\epsfxsize = 0pt       % default value, means `use natural size'
231226584Sdim\epsfysize = 0pt       % ditto
232226584Sdim\epsfframemargin = 0pt % default value: frame box flush around picture
233243830Sdim\epsfframethickness = 0.4pt % TeX's default rule thickness
234226584Sdim%
235243830Sdim\def\epsfbox#1{\global\def\epsfllx{72}\global\def\epsflly{72}%
236226584Sdim   \global\def\epsfurx{540}\global\def\epsfury{720}%
237226584Sdim   \def\lbracket{[}\def\testit{#1}\ifx\testit\lbracket
238243830Sdim   \let\next=\epsfgetlitbb\else\let\next=\epsfnormal\fi\next{#1}}%
239226584Sdim%
240234353Sdim% We use \epsfgetlitbb if the user specified an explicit bounding box,
241226584Sdim% and \epsfnormal otherwise.  Because \epsfgetbb can be called
242226584Sdim% separately to retrieve the bounding box, we move the verbose
243226584Sdim% printing the bounding box extents and size on the terminal to
244226584Sdim% \epsfstatus.  Therefore, when the user provided the bounding box,
245234353Sdim% \epsfgetbb will not be called, so we must call \epsfsetsize and
246234353Sdim% \epsfstatus ourselves.
247226584Sdim%
248226584Sdim\def\epsfgetlitbb#1#2 #3 #4 #5]#6{%
249226584Sdim   \epsfgrab #2 #3 #4 #5 .\\%
250226584Sdim   \epsfsetsize
251226584Sdim   \epsfstatus{#6}%
252226584Sdim   \epsfsetgraph{#6}%
253243830Sdim}%
254243830Sdim%
255243830Sdim\def\epsfnormal#1{%
256243830Sdim    \epsfgetbb{#1}%
257243830Sdim    \epsfsetgraph{#1}%
258226584Sdim}%
259226584Sdim%
260226584Sdim\newhelp\epsfnoopenhelp{The PostScript image file must be findable by
261226584SdimTeX, i.e., somewhere in the TEXINPUTS (or equivalent) path.}%
262226584Sdim%
263226584Sdim\def\epsfgetbb#1{%
264226584Sdim%
265226584Sdim%   The first thing we need to do is to open the
266226584Sdim%   PostScript file, if possible.
267226584Sdim%
268226584Sdim    \openin\epsffilein=#1
269226584Sdim    \ifeof\epsffilein
270226584Sdim        \errhelp = \epsfnoopenhelp
271226584Sdim        \errmessage{Could not open file #1, ignoring it}%
272226584Sdim    \else                       %process the file
273226584Sdim        {%                      %start a group to contain catcode changes
274226584Sdim            % Make all special characters, except space, to be of type
275226584Sdim            % `other' so we process the file in almost verbatim mode
276226584Sdim            % (TeXbook, p. 344).
277226584Sdim            \chardef\other=12
278226584Sdim            \def\do##1{\catcode`##1=\other}%
279226584Sdim            \dospecials
280226584Sdim            \catcode`\ =10
281226584Sdim            \epsffileoktrue         %true while we are looping
282226584Sdim            \epsfatendfalse     %[02-Jul-1996]: add forgotten initialization
283226584Sdim            \loop               %reading lines from the EPS file
284226584Sdim                \read\epsffilein to \epsffileline
285226584Sdim                \ifeof\epsffilein %then no more input
286226584Sdim                \epsffileokfalse %so set completion flag
287226584Sdim            \else                %otherwise process one line
288226584Sdim                \expandafter\epsfaux\epsffileline:. \\%
289226584Sdim            \fi
290226584Sdim            \ifepsffileok
291226584Sdim            \repeat
292226584Sdim            \ifepsfbbfound
293226584Sdim            \else
294226584Sdim                \ifepsfverbose
295226584Sdim                    \immediate\write16{No BoundingBox comment found in %
296226584Sdim                                    file #1; using defaults}%
297226584Sdim                \fi
298226584Sdim            \fi
299243830Sdim        }%                      %end catcode changes
300243830Sdim        \closein\epsffilein
301243830Sdim    \fi                         %end of file processing
302243830Sdim    \epsfsetsize                %compute size parameters
303226584Sdim    \epsfstatus{#1}%
304226584Sdim}%
305226584Sdim%
306226584Sdim% Clipping control:
307226584Sdim\def\epsfclipon{\def\epsfclipstring{ clip}}%
308234353Sdim\def\epsfclipoff{\def\epsfclipstring{\ifepsfdraft\space clip\fi}}%
309234353Sdim\epsfclipoff % default for dvips is OFF
310234353Sdim%
311226584Sdim% The special that is emitted by \epsfsetgraph comes from this macro.
312226584Sdim% It is defined separately to allow easy customization by other
313226584Sdim% packages that first \input epsf.tex, then redefine \epsfspecial.
314226584Sdim% This macro is invoked in the lower-left corner of a box of the
315226584Sdim% width and height determined from the arguments to \epsffile, or
316226584Sdim% from the %%BoundingBox in the EPS file itself.
317226584Sdim%
318226584Sdim% This version is for dvips:
319226584Sdim\def\epsfspecial#1{%
320226584Sdim     \epsftmp=10\epsfxsize
321226584Sdim     \divide\epsftmp\pspoints
322226584Sdim     \ifnum\epsfrsize=0\relax
323226584Sdim       \special{PSfile=\ifepsfdraft psdraft.ps\else#1\fi\space
324226584Sdim                llx=\epsfllx\space
325226584Sdim                lly=\epsflly\space
326226584Sdim                urx=\epsfurx\space
327226584Sdim                ury=\epsfury\space
328226584Sdim                rwi=\number\epsftmp
329226584Sdim                \epsfclipstring
330226584Sdim               }%
331226584Sdim     \else
332226584Sdim       \epsfrsize=10\epsfysize
333226584Sdim       \divide\epsfrsize\pspoints
334226584Sdim       \special{PSfile=\ifepsfdraft psdraft.ps\else#1\fi\space
335226584Sdim                llx=\epsfllx\space
336226584Sdim                lly=\epsflly\space
337226584Sdim                urx=\epsfurx\space
338226584Sdim                ury=\epsfury\space
339226584Sdim                rwi=\number\epsftmp\space
340226584Sdim                rhi=\number\epsfrsize
341226584Sdim                \epsfclipstring
342226584Sdim               }%
343226584Sdim     \fi
344226584Sdim}%
345226584Sdim%
346226584Sdim% \epsfframe macro adapted from the TeXbook, exercise 21.3, p. 223, 331.
347226584Sdim% but modified to set the box width to the natural width, rather
348226584Sdim% than the line width, and to include space for margins and rules
349226584Sdim\def\epsfframe#1%
350226584Sdim{%
351226584Sdim  \leavevmode                   % so we can put this inside
352226584Sdim                                % a centered environment
353226584Sdim  \setbox0 = \hbox{#1}%
354226584Sdim  \dimen0 = \wd0                                % natural width of argument
355226584Sdim  \advance \dimen0 by 2\epsfframemargin         % plus width of 2 margins
356226584Sdim  \advance \dimen0 by 2\epsfframethickness      % plus width of 2 rule lines
357226584Sdim  \vbox
358226584Sdim  {%
359226584Sdim    \hrule height \epsfframethickness depth 0pt
360226584Sdim    \hbox to \dimen0
361226584Sdim    {%
362226584Sdim      \hss
363226584Sdim      \vrule width \epsfframethickness
364226584Sdim      \kern \epsfframemargin
365226584Sdim      \vbox {\kern \epsfframemargin \box0 \kern \epsfframemargin }%
366226584Sdim      \kern \epsfframemargin
367226584Sdim      \vrule width \epsfframethickness
368226584Sdim      \hss
369226584Sdim    }% end hbox
370226584Sdim    \hrule height 0pt depth \epsfframethickness
371226584Sdim  }% end vbox
372226584Sdim}%
373226584Sdim%
374226584Sdim\def\epsfsetgraph#1%
375226584Sdim{%
376226584Sdim   %
377226584Sdim   % Make the vbox and stick in a \special that the DVI driver can
378226584Sdim   % parse.  \vfil and \hfil are used to place the \special origin at
379226584Sdim   % the lower-left corner of the vbox.  \epsfspecial can be redefined
380226584Sdim   % to produce alternate \special syntaxes.
381226584Sdim   %
382226584Sdim   \leavevmode
383226584Sdim   \hbox{% so we can put this in \begin{center}...\end{center}
384226584Sdim     \ifepsfframe\expandafter\epsfframe\fi
385226584Sdim     {\vbox to\epsfysize
386226584Sdim     {%
387226584Sdim        \ifepsfshow
388226584Sdim            % output \special{} at lower-left corner of figure box
389226584Sdim            \vfil
390226584Sdim            \hbox to \epsfxsize{\epsfspecial{#1}\hfil}%
391226584Sdim        \else
392226584Sdim            \vfil
393226584Sdim            \hbox to\epsfxsize{%
394226584Sdim               \hss
395226584Sdim               \ifepsfshowfilename
396226584Sdim               {%
397226584Sdim                  \epsfframemargin=3pt % local change of margin
398226584Sdim                  \epsfframe{{\tt #1}}%
399226584Sdim               }%
400226584Sdim               \fi
401226584Sdim               \hss
402            }%
403            \vfil
404        \fi
405     }%
406   }}%
407   %
408   % Reset \epsfxsize and \epsfysize, as documented above.
409   %
410   \global\epsfxsize=0pt
411   \global\epsfysize=0pt
412}%
413%
414%   Now we have to calculate the scale and offset values to use.
415%   First we compute the natural sizes.
416%
417\def\epsfsetsize
418{%
419   \epsfrsize=\epsfury\pspoints
420   \advance\epsfrsize by-\epsflly\pspoints
421   \epsftsize=\epsfurx\pspoints
422   \advance\epsftsize by-\epsfllx\pspoints
423%
424%   If `epsfxsize' is 0, we default to the natural size of the picture.
425%   Otherwise we scale the graph to be \epsfxsize wide.
426%
427   \epsfxsize=\epsfsize{\epsftsize}{\epsfrsize}%
428   \ifnum \epsfxsize=0
429      \ifnum \epsfysize=0
430        \epsfxsize=\epsftsize
431        \epsfysize=\epsfrsize
432        \epsfrsize=0pt
433%
434%   We have a sticky problem here:  TeX doesn't do floating point arithmetic!
435%   Our goal is to compute y = rx/t. The following loop does this reasonably
436%   fast, with an error of at most about 16 sp (about 1/4000 pt).
437%
438      \else
439        \epsftmp=\epsftsize \divide\epsftmp\epsfrsize
440        \epsfxsize=\epsfysize \multiply\epsfxsize\epsftmp
441        \multiply\epsftmp\epsfrsize \advance\epsftsize-\epsftmp
442        \epsftmp=\epsfysize
443        \loop \advance\epsftsize\epsftsize \divide\epsftmp 2
444        \ifnum \epsftmp>0
445           \ifnum \epsftsize<\epsfrsize
446           \else
447              \advance\epsftsize-\epsfrsize \advance\epsfxsize\epsftmp
448           \fi
449        \repeat
450        \epsfrsize=0pt
451      \fi
452   \else
453     \ifnum \epsfysize=0
454       \epsftmp=\epsfrsize \divide\epsftmp\epsftsize
455       \epsfysize=\epsfxsize \multiply\epsfysize\epsftmp
456       \multiply\epsftmp\epsftsize \advance\epsfrsize-\epsftmp
457       \epsftmp=\epsfxsize
458       \loop \advance\epsfrsize\epsfrsize \divide\epsftmp 2
459       \ifnum \epsftmp>0
460          \ifnum \epsfrsize<\epsftsize
461          \else
462             \advance\epsfrsize-\epsftsize \advance\epsfysize\epsftmp
463          \fi
464       \repeat
465       \epsfrsize=0pt
466     \else
467       \epsfrsize=\epsfysize
468     \fi
469   \fi
470}%
471%
472% Issue some status messages if the user requested them
473%
474\def\epsfstatus#1{% arg = filename
475   \ifepsfverbose
476     \immediate\write16{#1: BoundingBox:
477                  llx = \epsfllx\space lly = \epsflly\space
478                  urx = \epsfurx\space ury = \epsfury\space}%
479     \immediate\write16{#1: scaled width = \the\epsfxsize\space
480                  scaled height = \the\epsfysize}%
481   \fi
482}%
483%
484%   We still need to define the tricky \epsfaux macro. This requires
485%   a couple of magic constants for comparison purposes.
486%
487{\catcode`\%=12 \global\let\epsfpercent=%\global\def\epsfbblit{%BoundingBox}}%
488\global\def\epsfatend{(atend)}%
489%
490%   So we're ready to check for `%BoundingBox:' and to grab the
491%   values if they are found.
492%
493%   If we find a line
494%
495%   %%BoundingBox: (atend)
496%
497%   then we ignore it, but set a flag to force parsing all of the
498%   file, so the last %%BoundingBox parsed will be the one used.  This
499%   is necessary, because EPS files can themselves contain other EPS
500%   files with their own %%BoundingBox comments.
501%
502%   If we find a line
503%
504%   %%BoundingBox: llx lly urx ury
505%
506%   then we save the 4 values in \epsfllx, \epsflly, \epsfurx, \epsfury.
507%   Then, if we have not previously parsed an (atend), we flag completion
508%   and can stop reading the file.  Otherwise, we must keep on reading
509%   to end of file so that we find the values on the LAST %%BoundingBox.
510\long\def\epsfaux#1#2:#3\\%
511{%
512   \def\testit{#2}%             % save second character up to just before colon
513   \ifx#1\epsfpercent           % then first char is percent (quick test)
514       \ifx\testit\epsfbblit    % then (slow test) we have %%BoundingBox
515            \epsfgrab #3 . . . \\%
516            \ifx\epsfllx\epsfatend % then ignore %%BoundingBox: (atend)
517                \global\epsfatendtrue
518            \else               % else found %%BoundingBox: llx lly urx ury
519                \ifepsfatend    % then keep parsing ALL %%BoundingBox lines
520                \else           % else stop after first one parsed
521                    \epsffileokfalse
522                \fi
523                \global\epsfbbfoundtrue
524            \fi
525       \fi
526   \fi
527}%
528%
529%   Here we grab the values and stuff them in the appropriate definitions.
530%
531\def\epsfempty{}%
532\def\epsfgrab #1 #2 #3 #4 #5\\{%
533   \global\def\epsfllx{#1}\ifx\epsfllx\epsfempty
534      \epsfgrab #2 #3 #4 #5 .\\\else
535   \global\def\epsflly{#2}%
536   \global\def\epsfurx{#3}\global\def\epsfury{#4}\fi
537}%
538%
539%   We default the epsfsize macro.
540%
541\def\epsfsize#1#2{\epsfxsize}%
542%
543%   Finally, another definition for compatibility with older macros.
544%
545\let\epsffile=\epsfbox
546\endinput
547
548