]> AND Private Git Repository - canny.git/blob - psfig.sty
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
retouche complexité
[canny.git] / psfig.sty
1 % Psfig/TeX 
2 \def\PsfigVersion{1.10}
3 \def\setDriver{\DvipsDriver} % \DvipsDriver or \OzTeXDriver
4 %
5 % All software, documentation, and related files in this distribution of
6 % psfig/tex are Copyright 1993 Trevor J. Darrell
7 %
8 % Permission is granted for use and non-profit distribution of psfig/tex 
9 % providing that this notice is clearly maintained. The right to
10 % distribute any portion of psfig/tex for profit or as part of any commercial
11 % product is specifically reserved for the author(s) of that portion.
12 %
13 % To use with LaTeX, use \documentstyle[psfig,...]{...}
14 % To use with TeX, use \input psfig.sty
15 %
16 % Bugs and improvements to trevor@media.mit.edu.
17 %
18 % Thanks to Ned Batchelder, Greg Hager (GDH), J. Daniel Smith (JDS),
19 % Tom Rokicki (TR), Robert Russell (RR), George V. Reilly (GVR),
20 % Ken McGlothlen (KHC), Baron Grey (BG), Gerhard Tobermann (GT).
21 % and all others who have contributed code and comments to this project!
22 %
23 % ======================================================================
24 % Modification History:
25 %
26 %  9 Oct 1990   JDS     used more robust bbox reading code from Tom Rokicki
27 % 29 Mar 1991   JDS     implemented rotation= option
28 % 25 Jun 1991   RR      if bb specified on cmd line don't check
29 %                       for .ps file.
30 %  3 Jul 1991   JDS     check if file already read in once
31 %  4 Sep 1991   JDS     fixed incorrect computation of rotated
32 %                       bounding box
33 % 25 Sep 1991   GVR     expanded synopsis of \psfig
34 % 14 Oct 1991   JDS     \fbox code from LaTeX so \psdraft works with TeX
35 %                       changed \typeout to \ps@typeout
36 % 17 Oct 1991   JDS     added \psscalefirst and \psrotatefirst
37 % 23 Jun 1993   KHC     ``doclip'' must appear before ``rotate''
38 % 27 Oct 1993   TJD     removed printing of filename to avoid 
39 %                       underscore problems. changed \frame to \fbox.
40 %                       Added OzTeX support from BG. Added new
41 %                       figure search path code from GT.
42 %
43 % ======================================================================
44 %
45 % Command synopsis:
46 %
47 % \psdraft      draws an outline box, but doesn't include the figure
48 %               in the DVI file.  Useful for previewing.
49 %
50 % \psfull       includes the figure in the DVI file (default).
51 %
52 % \psscalefirst width= or height= specifies the size of the figure
53 %               before rotation.
54 % \psrotatefirst (default) width= or height= specifies the size of the
55 %                figure after rotation.  Asymetric figures will
56 %                appear to shrink.
57 %
58 % \psfigurepath{dir:dir:...}  sets the path to search for the figure
59 %
60 % \psfig
61 % usage: \psfig{file=, figure=, height=, width=,
62 %                       bbllx=, bblly=, bburx=, bbury=,
63 %                       rheight=, rwidth=, clip=, angle=, silent=}
64 %
65 %       "file" is the filename.  If no path name is specified and the
66 %               file is not found in the current directory,
67 %               it will be looked for in directory \psfigurepath.
68 %       "figure" is a synonym for "file".
69 %       By default, the width and height of the figure are taken from
70 %               the BoundingBox of the figure.
71 %       If "width" is specified, the figure is scaled so that it has
72 %               the specified width.  Its height changes proportionately.
73 %       If "height" is specified, the figure is scaled so that it has
74 %               the specified height.  Its width changes proportionately.
75 %       If both "width" and "height" are specified, the figure is scaled
76 %               anamorphically.
77 %       "bbllx", "bblly", "bburx", and "bbury" control the PostScript
78 %               BoundingBox.  If these four values are specified
79 %               *before* the "file" option, the PSFIG will not try to
80 %               open the PostScript file.
81 %       "rheight" and "rwidth" are the reserved height and width
82 %               of the figure, i.e., how big TeX actually thinks
83 %               the figure is.  They default to "width" and "height".
84 %       The "clip" option ensures that no portion of the figure will
85 %               appear outside its BoundingBox.  "clip=" is a switch and
86 %               takes no value, but the `=' must be present.
87 %       The "angle" option specifies the angle of rotation (degrees, ccw).
88 %       The "silent" option makes \psfig work silently.
89 %
90 % ======================================================================
91 % check to see if macros already loaded in (maybe some other file says
92 % "\input psfig") ...
93 \ifx\undefined\psfig\else\endinput\fi
94 %
95 % from a suggestion by eijkhout@csrd.uiuc.edu to allow
96 % loading as a style file. Changed to avoid problems
97 % with amstex per suggestion by jbence@math.ucla.edu
98
99 \let\LaTeXAtSign=\@
100 \let\@=\relax
101 \edef\psfigRestoreAt{\catcode`\@=\number\catcode`@\relax}
102 %\edef\psfigRestoreAt{\catcode`@=\number\catcode`@\relax}
103 \catcode`\@=11\relax
104 \newwrite\@unused
105 \def\ps@typeout#1{{\let\protect\string\immediate\write\@unused{#1}}}
106
107 \def\DvipsDriver{
108         \ps@typeout{psfig/tex \PsfigVersion -dvips}
109 \def\PsfigSpecials{\DvipsSpecials}      \def\ps@dir{/}
110 \def\ps@predir{} }
111 \def\OzTeXDriver{
112         \ps@typeout{psfig/tex \PsfigVersion -oztex}
113         \def\PsfigSpecials{\OzTeXSpecials}
114         \def\ps@dir{:}
115         \def\ps@predir{:}
116         \catcode`\^^J=5
117 }
118
119 %% Here's how you define your figure path.  Should be set up with null
120 %% default and a user useable definition.
121
122 \def\figurepath{./:}
123 \def\psfigurepath#1{\edef\figurepath{#1:}}
124
125 %%% inserted for Searching Unixpaths
126 %%% (the path must end with :)
127 %%% (call: \DoPaths\figurepath )
128 %%%------------------------------------------------------
129 \def\DoPaths#1{\expandafter\EachPath#1\stoplist}
130 %
131 \def\leer{}
132 \def\EachPath#1:#2\stoplist{% #1 part of the list (delimiter :)
133   \ExistsFile{#1}{\SearchedFile}
134   \ifx#2\leer
135   \else
136     \expandafter\EachPath#2\stoplist
137   \fi}
138 %
139 % exists the file (does not work for directories!)
140 %
141 \def\ps@dir{/}
142 \def\ExistsFile#1#2{%
143    \openin1=\ps@predir#1\ps@dir#2
144    \ifeof1
145        \closein1
146        %\ps@typeout{...not: \ps@predir#1\ps@dir#2}
147    \else
148        \closein1
149        %\ps@typeout{...in:  \ps@predir#1\ps@dir#2}
150         \ifx\ps@founddir\leer
151           %\ps@typeout{set founddir #1}
152            \edef\ps@founddir{#1}
153         \fi
154    \fi}
155 %------------------------------------------------------
156 %
157 % Get dir in path or error
158 %
159 \def\get@dir#1{%
160   \def\ps@founddir{}
161   \def\SearchedFile{#1}
162   \DoPaths\figurepath
163 %  \fi
164 }
165 %------------------------------------------------------
166 %%% END of Searching Unixpaths
167
168
169 %
170 % @psdo control structure -- similar to Latex @for.
171 % I redefined these with different names so that psfig can
172 % be used with TeX as well as LaTeX, and so that it will not 
173 % be vunerable to future changes in LaTeX's internal
174 % control structure,
175 %
176 \def\@nnil{\@nil}
177 \def\@empty{}
178 \def\@psdonoop#1\@@#2#3{}
179 \def\@psdo#1:=#2\do#3{\edef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
180     \expandafter\@psdoloop#2,\@nil,\@nil\@@#1{#3}\fi}
181 \def\@psdoloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
182        #5\def#4{#2}\ifx #4\@nnil \else#5\@ipsdoloop #3\@@#4{#5}\fi\fi}
183 \def\@ipsdoloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
184        \let\@nextwhile=\@psdonoop \else
185       #4\relax\let\@nextwhile=\@ipsdoloop\fi\@nextwhile#2\@@#3{#4}}
186 \def\@tpsdo#1:=#2\do#3{\xdef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
187     \@tpsdoloop#2\@nil\@nil\@@#1{#3}\fi}
188 \def\@tpsdoloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
189        \let\@nextwhile=\@psdonoop \else
190       #4\relax\let\@nextwhile=\@tpsdoloop\fi\@nextwhile#2\@@#3{#4}}
191
192 % \fbox is defined in latex.tex; so if \fbox is undefined, assume that
193 % we are not in LaTeX.
194 % Perhaps this could be done better???
195 \ifx\undefined\fbox
196 % \fbox code from modified slightly from LaTeX
197 \newdimen\fboxrule
198 \newdimen\fboxsep
199 \newdimen\ps@tempdima
200 \newbox\ps@tempboxa
201 \fboxsep = 3pt
202 \fboxrule = .4pt
203 \long\def\fbox#1{\leavevmode\setbox\ps@tempboxa\hbox{#1}\ps@tempdima\fboxrule
204     \advance\ps@tempdima \fboxsep \advance\ps@tempdima \dp\ps@tempboxa
205    \hbox{\lower \ps@tempdima\hbox
206   {\vbox{\hrule height \fboxrule
207           \hbox{\vrule width \fboxrule \hskip\fboxsep
208           \vbox{\vskip\fboxsep \box\ps@tempboxa\vskip\fboxsep}\hskip 
209                  \fboxsep\vrule width \fboxrule}
210                  \hrule height \fboxrule}}}}
211 \fi
212 %
213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 % file reading stuff from epsf.tex
215 %   EPSF.TEX macro file:
216 %   Written by Tomas Rokicki of Radical Eye Software, 29 Mar 1989.
217 %   Revised by Don Knuth, 3 Jan 1990.
218 %   Revised by Tomas Rokicki to accept bounding boxes with no
219 %      space after the colon, 18 Jul 1990.
220 %   Portions modified/removed for use in PSFIG package by
221 %      J. Daniel Smith, 9 October 1990.
222 %
223 \newread\ps@stream
224 \newif\ifnot@eof       % continue looking for the bounding box?
225 \newif\if@noisy        % report what you're making?
226 \newif\if@atend        % %%BoundingBox: has (at end) specification
227 \newif\if@psfile       % does this look like a PostScript file?
228 %
229 % PostScript files should start with `%!'
230 %
231 {\catcode`\%=12\global\gdef\epsf@start{%!}}
232 \def\epsf@PS{PS}
233 %
234 \def\epsf@getbb#1{%
235 %
236 %   The first thing we need to do is to open the
237 %   PostScript file, if possible.
238 %
239 \openin\ps@stream=\ps@predir#1
240 \ifeof\ps@stream\ps@typeout{Error, File #1 not found}\else
241 %
242 %   Okay, we got it. Now we'll scan lines until we find one that doesn't
243 %   start with %. We're looking for the bounding box comment.
244 %
245    {\not@eoftrue \chardef\other=12
246     \def\do##1{\catcode`##1=\other}\dospecials \catcode`\ =10
247     \loop
248        \if@psfile
249           \read\ps@stream to \epsf@fileline
250        \else{
251           \obeyspaces
252           \read\ps@stream to \epsf@tmp\global\let\epsf@fileline\epsf@tmp}
253        \fi
254        \ifeof\ps@stream\not@eoffalse\else
255 %
256 %   Check the first line for `%!'.  Issue a warning message if its not
257 %   there, since the file might not be a PostScript file.
258 %
259        \if@psfile\else
260        \expandafter\epsf@test\epsf@fileline:. \\%
261        \fi
262 %
263 %   We check to see if the first character is a % sign;
264 %   if so, we look further and stop only if the line begins with
265 %   `%%BoundingBox:' and the `(atend)' specification was not found.
266 %   That is, the only way to stop is when the end of file is reached,
267 %   or a `%%BoundingBox: llx lly urx ury' line is found.
268 %
269           \expandafter\epsf@aux\epsf@fileline:. \\%
270        \fi
271    \ifnot@eof\repeat
272    }\closein\ps@stream\fi}%
273 %
274 % This tests if the file we are reading looks like a PostScript file.
275 %
276 \long\def\epsf@test#1#2#3:#4\\{\def\epsf@testit{#1#2}
277                         \ifx\epsf@testit\epsf@start\else
278 \ps@typeout{Warning! File does not start with `\epsf@start'.  It may not be a PostScript file.}
279                         \fi
280                         \@psfiletrue} % don't test after 1st line
281 %
282 %   We still need to define the tricky \epsf@aux macro. This requires
283 %   a couple of magic constants for comparison purposes.
284 %
285 {\catcode`\%=12\global\let\epsf@percent=%\global\def\epsf@bblit{%BoundingBox}}
286 %
287 %
288 %   So we're ready to check for `%BoundingBox:' and to grab the
289 %   values if they are found.  We continue searching if `(at end)'
290 %   was found after the `%BoundingBox:'.
291 %
292 \long\def\epsf@aux#1#2:#3\\{\ifx#1\epsf@percent
293    \def\epsf@testit{#2}\ifx\epsf@testit\epsf@bblit
294         \@atendfalse
295         \epsf@atend #3 . \\%
296         \if@atend       
297            \if@verbose{
298                 \ps@typeout{psfig: found `(atend)'; continuing search}
299            }\fi
300         \else
301         \epsf@grab #3 . . . \\%
302         \not@eoffalse
303         \global\no@bbfalse
304         \fi
305    \fi\fi}%
306 %
307 %   Here we grab the values and stuff them in the appropriate definitions.
308 %
309 \def\epsf@grab #1 #2 #3 #4 #5\\{%
310    \global\def\epsf@llx{#1}\ifx\epsf@llx\empty
311       \epsf@grab #2 #3 #4 #5 .\\\else
312    \global\def\epsf@lly{#2}%
313    \global\def\epsf@urx{#3}\global\def\epsf@ury{#4}\fi}%
314 %
315 % Determine if the stuff following the %%BoundingBox is `(atend)'
316 % J. Daniel Smith.  Copied from \epsf@grab above.
317 %
318 \def\epsf@atendlit{(atend)} 
319 \def\epsf@atend #1 #2 #3\\{%
320    \def\epsf@tmp{#1}\ifx\epsf@tmp\empty
321       \epsf@atend #2 #3 .\\\else
322    \ifx\epsf@tmp\epsf@atendlit\@atendtrue\fi\fi}
323
324
325 % End of file reading stuff from epsf.tex
326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
327
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 % trigonometry stuff from "trig.tex"
330 \chardef\psletter = 11 % won't conflict with \begin{letter} now...
331 \chardef\other = 12
332
333 \newif \ifdebug %%% turn me on to see TeX hard at work ...
334 \newif\ifc@mpute %%% don't need to compute some values
335 \c@mputetrue % but assume that we do
336
337 \let\then = \relax
338 \def\r@dian{pt }
339 \let\r@dians = \r@dian
340 \let\dimensionless@nit = \r@dian
341 \let\dimensionless@nits = \dimensionless@nit
342 \def\internal@nit{sp }
343 \let\internal@nits = \internal@nit
344 \newif\ifstillc@nverging
345 \def \Mess@ge #1{\ifdebug \then \message {#1} \fi}
346
347 { %%% Things that need abnormal catcodes %%%
348         \catcode `\@ = \psletter
349         \gdef \nodimen {\expandafter \n@dimen \the \dimen}
350         \gdef \term #1 #2 #3%
351                {\edef \t@ {\the #1}%%% freeze parameter 1 (count, by value)
352                 \edef \t@@ {\expandafter \n@dimen \the #2\r@dian}%
353                                    %%% freeze parameter 2 (dimen, by value)
354                 \t@rm {\t@} {\t@@} {#3}%
355                }
356         \gdef \t@rm #1 #2 #3%
357                {{%
358                 \count 0 = 0
359                 \dimen 0 = 1 \dimensionless@nit
360                 \dimen 2 = #2\relax
361                 \Mess@ge {Calculating term #1 of \nodimen 2}%
362                 \loop
363                 \ifnum  \count 0 < #1
364                 \then   \advance \count 0 by 1
365                         \Mess@ge {Iteration \the \count 0 \space}%
366                         \Multiply \dimen 0 by {\dimen 2}%
367                         \Mess@ge {After multiplication, term = \nodimen 0}%
368                         \Divide \dimen 0 by {\count 0}%
369                         \Mess@ge {After division, term = \nodimen 0}%
370                 \repeat
371                 \Mess@ge {Final value for term #1 of 
372                                 \nodimen 2 \space is \nodimen 0}%
373                 \xdef \Term {#3 = \nodimen 0 \r@dians}%
374                 \aftergroup \Term
375                }}
376         \catcode `\p = \other
377         \catcode `\t = \other
378         \gdef \n@dimen #1pt{#1} %%% throw away the ``pt''
379 }
380
381 \def \Divide #1by #2{\divide #1 by #2} %%% just a synonym
382
383 \def \Multiply #1by #2%%% allows division of a dimen by a dimen
384        {{%%% should really freeze parameter 2 (dimen, passed by value)
385         \count 0 = #1\relax
386         \count 2 = #2\relax
387         \count 4 = 65536
388         \Mess@ge {Before scaling, count 0 = \the \count 0 \space and
389                         count 2 = \the \count 2}%
390         \ifnum  \count 0 > 32767 %%% do our best to avoid overflow
391         \then   \divide \count 0 by 4
392                 \divide \count 4 by 4
393         \else   \ifnum  \count 0 < -32767
394                 \then   \divide \count 0 by 4
395                         \divide \count 4 by 4
396                 \else
397                 \fi
398         \fi
399         \ifnum  \count 2 > 32767 %%% while retaining reasonable accuracy
400         \then   \divide \count 2 by 4
401                 \divide \count 4 by 4
402         \else   \ifnum  \count 2 < -32767
403                 \then   \divide \count 2 by 4
404                         \divide \count 4 by 4
405                 \else
406                 \fi
407         \fi
408         \multiply \count 0 by \count 2
409         \divide \count 0 by \count 4
410         \xdef \product {#1 = \the \count 0 \internal@nits}%
411         \aftergroup \product
412        }}
413
414 \def\r@duce{\ifdim\dimen0 > 90\r@dian \then   % sin(x+90) = sin(180-x)
415                 \multiply\dimen0 by -1
416                 \advance\dimen0 by 180\r@dian
417                 \r@duce
418             \else \ifdim\dimen0 < -90\r@dian \then  % sin(-x) = sin(360+x)
419                 \advance\dimen0 by 360\r@dian
420                 \r@duce
421                 \fi
422             \fi}
423
424 \def\Sine#1%
425        {{%
426         \dimen 0 = #1 \r@dian
427         \r@duce
428         \ifdim\dimen0 = -90\r@dian \then
429            \dimen4 = -1\r@dian
430            \c@mputefalse
431         \fi
432         \ifdim\dimen0 = 90\r@dian \then
433            \dimen4 = 1\r@dian
434            \c@mputefalse
435         \fi
436         \ifdim\dimen0 = 0\r@dian \then
437            \dimen4 = 0\r@dian
438            \c@mputefalse
439         \fi
440 %
441         \ifc@mpute \then
442                 % convert degrees to radians
443                 \divide\dimen0 by 180
444                 \dimen0=3.141592654\dimen0
445 %
446                 \dimen 2 = 3.1415926535897963\r@dian %%% a well-known constant
447                 \divide\dimen 2 by 2 %%% we only deal with -pi/2 : pi/2
448                 \Mess@ge {Sin: calculating Sin of \nodimen 0}%
449                 \count 0 = 1 %%% see power-series expansion for sine
450                 \dimen 2 = 1 \r@dian %%% ditto
451                 \dimen 4 = 0 \r@dian %%% ditto
452                 \loop
453                         \ifnum  \dimen 2 = 0 %%% then we've done
454                         \then   \stillc@nvergingfalse 
455                         \else   \stillc@nvergingtrue
456                         \fi
457                         \ifstillc@nverging %%% then calculate next term
458                         \then   \term {\count 0} {\dimen 0} {\dimen 2}%
459                                 \advance \count 0 by 2
460                                 \count 2 = \count 0
461                                 \divide \count 2 by 2
462                                 \ifodd  \count 2 %%% signs alternate
463                                 \then   \advance \dimen 4 by \dimen 2
464                                 \else   \advance \dimen 4 by -\dimen 2
465                                 \fi
466                 \repeat
467         \fi             
468                         \xdef \sine {\nodimen 4}%
469        }}
470
471 % Now the Cosine can be calculated easily by calling \Sine
472 \def\Cosine#1{\ifx\sine\UnDefined\edef\Savesine{\relax}\else
473                              \edef\Savesine{\sine}\fi
474         {\dimen0=#1\r@dian\advance\dimen0 by 90\r@dian
475          \Sine{\nodimen 0}
476          \xdef\cosine{\sine}
477          \xdef\sine{\Savesine}}}              
478 % end of trig stuff
479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
480
481 \def\psdraft{
482         \def\@psdraft{0}
483         %\ps@typeout{draft level now is \@psdraft \space . }
484 }
485 \def\psfull{
486         \def\@psdraft{100}
487         %\ps@typeout{draft level now is \@psdraft \space . }
488 }
489
490 \psfull
491
492 \newif\if@scalefirst
493 \def\psscalefirst{\@scalefirsttrue}
494 \def\psrotatefirst{\@scalefirstfalse}
495 \psrotatefirst
496
497 \newif\if@draftbox
498 \def\psnodraftbox{
499         \@draftboxfalse
500 }
501 \def\psdraftbox{
502         \@draftboxtrue
503 }
504 \@draftboxtrue
505
506 \newif\if@prologfile
507 \newif\if@postlogfile
508 \def\pssilent{
509         \@noisyfalse
510 }
511 \def\psnoisy{
512         \@noisytrue
513 }
514 \psnoisy
515 %%% These are for the option list.
516 %%% A specification of the form a = b maps to calling \@p@@sa{b}
517 \newif\if@bbllx
518 \newif\if@bblly
519 \newif\if@bburx
520 \newif\if@bbury
521 \newif\if@height
522 \newif\if@width
523 \newif\if@rheight
524 \newif\if@rwidth
525 \newif\if@angle
526 \newif\if@clip
527 \newif\if@verbose
528 \def\@p@@sclip#1{\@cliptrue}
529 %
530 %
531 \newif\if@decmpr
532 %
533 \def\@p@@sfigure#1{\def\@p@sfile{null}\def\@p@sbbfile{null}\@decmprfalse
534    % look directly for file (e.g. absolute path)
535    \openin1=\ps@predir#1
536    \ifeof1
537         \closein1
538         % failed, search directories for file
539         \get@dir{#1}
540         \ifx\ps@founddir\leer
541                 % failed, search directly for file.bb
542                 \openin1=\ps@predir#1.bb
543                 \ifeof1
544                         \closein1
545                         % failed, search directories for file.bb
546                         \get@dir{#1.bb}
547                         \ifx\ps@founddir\leer
548                                 % failed, lose.
549                                 \ps@typeout{Can't find #1 in \figurepath}
550                         \else
551                                 % found file.bb in search dir
552                                 \@decmprtrue
553                                 \def\@p@sfile{\ps@founddir\ps@dir#1}
554                                 \def\@p@sbbfile{\ps@founddir\ps@dir#1.bb}
555                         \fi
556                 \else
557                         \closein1
558                         %found file.bb directly
559                         \@decmprtrue
560                         \def\@p@sfile{#1}
561                         \def\@p@sbbfile{#1.bb}
562                 \fi
563         \else
564                 % found file in search dir
565                 \def\@p@sfile{\ps@founddir\ps@dir#1}
566                 \def\@p@sbbfile{\ps@founddir\ps@dir#1}
567         \fi
568    \else
569         % found file directly
570         \closein1
571         \def\@p@sfile{#1}
572         \def\@p@sbbfile{#1}
573    \fi
574 }
575 %
576 %
577 %
578 \def\@p@@sfile#1{\@p@@sfigure{#1}}
579 %
580 \def\@p@@sbbllx#1{
581                 %\ps@typeout{bbllx is #1}
582                 \@bbllxtrue
583                 \dimen100=#1
584                 \edef\@p@sbbllx{\number\dimen100}
585 }
586 \def\@p@@sbblly#1{
587                 %\ps@typeout{bblly is #1}
588                 \@bbllytrue
589                 \dimen100=#1
590                 \edef\@p@sbblly{\number\dimen100}
591 }
592 \def\@p@@sbburx#1{
593                 %\ps@typeout{bburx is #1}
594                 \@bburxtrue
595                 \dimen100=#1
596                 \edef\@p@sbburx{\number\dimen100}
597 }
598 \def\@p@@sbbury#1{
599                 %\ps@typeout{bbury is #1}
600                 \@bburytrue
601                 \dimen100=#1
602                 \edef\@p@sbbury{\number\dimen100}
603 }
604 \def\@p@@sheight#1{
605                 \@heighttrue
606                 \dimen100=#1
607                 \edef\@p@sheight{\number\dimen100}
608                 %\ps@typeout{Height is \@p@sheight}
609 }
610 \def\@p@@swidth#1{
611                 %\ps@typeout{Width is #1}
612                 \@widthtrue
613                 \dimen100=#1
614                 \edef\@p@swidth{\number\dimen100}
615 }
616 \def\@p@@srheight#1{
617                 %\ps@typeout{Reserved height is #1}
618                 \@rheighttrue
619                 \dimen100=#1
620                 \edef\@p@srheight{\number\dimen100}
621 }
622 \def\@p@@srwidth#1{
623                 %\ps@typeout{Reserved width is #1}
624                 \@rwidthtrue
625                 \dimen100=#1
626                 \edef\@p@srwidth{\number\dimen100}
627 }
628 \def\@p@@sangle#1{
629                 %\ps@typeout{Rotation is #1}
630                 \@angletrue
631 %               \dimen100=#1
632                 \edef\@p@sangle{#1} %\number\dimen100}
633 }
634 \def\@p@@ssilent#1{ 
635                 \@verbosefalse
636 }
637 \def\@p@@sprolog#1{\@prologfiletrue\def\@prologfileval{#1}}
638 \def\@p@@spostlog#1{\@postlogfiletrue\def\@postlogfileval{#1}}
639 \def\@cs@name#1{\csname #1\endcsname}
640 \def\@setparms#1=#2,{\@cs@name{@p@@s#1}{#2}}
641 %
642 % initialize the defaults (size the size of the figure)
643 %
644 \def\ps@init@parms{
645                 \@bbllxfalse \@bbllyfalse
646                 \@bburxfalse \@bburyfalse
647                 \@heightfalse \@widthfalse
648                 \@rheightfalse \@rwidthfalse
649                 \def\@p@sbbllx{}\def\@p@sbblly{}
650                 \def\@p@sbburx{}\def\@p@sbbury{}
651                 \def\@p@sheight{}\def\@p@swidth{}
652                 \def\@p@srheight{}\def\@p@srwidth{}
653                 \def\@p@sangle{0}
654                 \def\@p@sfile{} \def\@p@sbbfile{}
655                 \def\@p@scost{10}
656                 \def\@sc{}
657                 \@prologfilefalse
658                 \@postlogfilefalse
659                 \@clipfalse
660                 \if@noisy
661                         \@verbosetrue
662                 \else
663                         \@verbosefalse
664                 \fi
665 }
666 %
667 % Go through the options setting things up.
668 %
669 \def\parse@ps@parms#1{
670                 \@psdo\@psfiga:=#1\do
671                    {\expandafter\@setparms\@psfiga,}}
672 %
673 % Compute bb height and width
674 %
675 \newif\ifno@bb
676 \def\bb@missing{
677         \if@verbose{
678                 \ps@typeout{psfig: searching \@p@sbbfile \space  for bounding box}
679         }\fi
680         \no@bbtrue
681         \epsf@getbb{\@p@sbbfile}
682         \ifno@bb \else \bb@cull\epsf@llx\epsf@lly\epsf@urx\epsf@ury\fi
683 }       
684 \def\bb@cull#1#2#3#4{
685         \dimen100=#1 bp\edef\@p@sbbllx{\number\dimen100}
686         \dimen100=#2 bp\edef\@p@sbblly{\number\dimen100}
687         \dimen100=#3 bp\edef\@p@sbburx{\number\dimen100}
688         \dimen100=#4 bp\edef\@p@sbbury{\number\dimen100}
689         \no@bbfalse
690 }
691 % rotate point (#1,#2) about (0,0).
692 % The sine and cosine of the angle are already stored in \sine and
693 % \cosine.  The result is placed in (\p@intvaluex, \p@intvaluey).
694 \newdimen\p@intvaluex
695 \newdimen\p@intvaluey
696 \def\rotate@#1#2{{\dimen0=#1 sp\dimen1=#2 sp
697 %               calculate x' = x \cos\theta - y \sin\theta
698                   \global\p@intvaluex=\cosine\dimen0
699                   \dimen3=\sine\dimen1
700                   \global\advance\p@intvaluex by -\dimen3
701 %               calculate y' = x \sin\theta + y \cos\theta
702                   \global\p@intvaluey=\sine\dimen0
703                   \dimen3=\cosine\dimen1
704                   \global\advance\p@intvaluey by \dimen3
705                   }}
706 \def\compute@bb{
707                 \no@bbfalse
708                 \if@bbllx \else \no@bbtrue \fi
709                 \if@bblly \else \no@bbtrue \fi
710                 \if@bburx \else \no@bbtrue \fi
711                 \if@bbury \else \no@bbtrue \fi
712                 \ifno@bb \bb@missing \fi
713                 \ifno@bb \ps@typeout{FATAL ERROR: no bb supplied or found}
714                         \no-bb-error
715                 \fi
716                 %
717 %\ps@typeout{BB: \@p@sbbllx, \@p@sbblly, \@p@sbburx, \@p@sbbury} 
718 %
719 % store height/width of original (unrotated) bounding box
720                 \count203=\@p@sbburx
721                 \count204=\@p@sbbury
722                 \advance\count203 by -\@p@sbbllx
723                 \advance\count204 by -\@p@sbblly
724                 \edef\ps@bbw{\number\count203}
725                 \edef\ps@bbh{\number\count204}
726                 %\ps@typeout{ psbbh = \ps@bbh, psbbw = \ps@bbw }
727                 \if@angle 
728                         \Sine{\@p@sangle}\Cosine{\@p@sangle}
729                         {\dimen100=\maxdimen\xdef\r@p@sbbllx{\number\dimen100}
730                                             \xdef\r@p@sbblly{\number\dimen100}
731                                             \xdef\r@p@sbburx{-\number\dimen100}
732                                             \xdef\r@p@sbbury{-\number\dimen100}}
733 %
734 % Need to rotate all four points and take the X-Y extremes of the new
735 % points as the new bounding box.
736                         \def\minmaxtest{
737                            \ifnum\number\p@intvaluex<\r@p@sbbllx
738                               \xdef\r@p@sbbllx{\number\p@intvaluex}\fi
739                            \ifnum\number\p@intvaluex>\r@p@sbburx
740                               \xdef\r@p@sbburx{\number\p@intvaluex}\fi
741                            \ifnum\number\p@intvaluey<\r@p@sbblly
742                               \xdef\r@p@sbblly{\number\p@intvaluey}\fi
743                            \ifnum\number\p@intvaluey>\r@p@sbbury
744                               \xdef\r@p@sbbury{\number\p@intvaluey}\fi
745                            }
746 %                       lower left
747                         \rotate@{\@p@sbbllx}{\@p@sbblly}
748                         \minmaxtest
749 %                       upper left
750                         \rotate@{\@p@sbbllx}{\@p@sbbury}
751                         \minmaxtest
752 %                       lower right
753                         \rotate@{\@p@sbburx}{\@p@sbblly}
754                         \minmaxtest
755 %                       upper right
756                         \rotate@{\@p@sbburx}{\@p@sbbury}
757                         \minmaxtest
758                         \edef\@p@sbbllx{\r@p@sbbllx}\edef\@p@sbblly{\r@p@sbblly}
759                         \edef\@p@sbburx{\r@p@sbburx}\edef\@p@sbbury{\r@p@sbbury}
760 %\ps@typeout{rotated BB: \r@p@sbbllx, \r@p@sbblly, \r@p@sbburx, \r@p@sbbury}
761                 \fi
762                 \count203=\@p@sbburx
763                 \count204=\@p@sbbury
764                 \advance\count203 by -\@p@sbbllx
765                 \advance\count204 by -\@p@sbblly
766                 \edef\@bbw{\number\count203}
767                 \edef\@bbh{\number\count204}
768                 %\ps@typeout{ bbh = \@bbh, bbw = \@bbw }
769 }
770 %
771 % \in@hundreds performs #1 * (#2 / #3) correct to the hundreds,
772 %       then leaves the result in @result
773 %
774 \def\in@hundreds#1#2#3{\count240=#2 \count241=#3
775                      \count100=\count240        % 100 is first digit #2/#3
776                      \divide\count100 by \count241
777                      \count101=\count100
778                      \multiply\count101 by \count241
779                      \advance\count240 by -\count101
780                      \multiply\count240 by 10
781                      \count101=\count240        %101 is second digit of #2/#3
782                      \divide\count101 by \count241
783                      \count102=\count101
784                      \multiply\count102 by \count241
785                      \advance\count240 by -\count102
786                      \multiply\count240 by 10
787                      \count102=\count240        % 102 is the third digit
788                      \divide\count102 by \count241
789                      \count200=#1\count205=0
790                      \count201=\count200
791                         \multiply\count201 by \count100
792                         \advance\count205 by \count201
793                      \count201=\count200
794                         \divide\count201 by 10
795                         \multiply\count201 by \count101
796                         \advance\count205 by \count201
797                         %
798                      \count201=\count200
799                         \divide\count201 by 100
800                         \multiply\count201 by \count102
801                         \advance\count205 by \count201
802                         %
803                      \edef\@result{\number\count205}
804 }
805 \def\compute@wfromh{
806                 % computing : width = height * (bbw / bbh)
807                 \in@hundreds{\@p@sheight}{\@bbw}{\@bbh}
808                 %\ps@typeout{ \@p@sheight * \@bbw / \@bbh, = \@result }
809                 \edef\@p@swidth{\@result}
810                 %\ps@typeout{w from h: width is \@p@swidth}
811 }
812 \def\compute@hfromw{
813                 % computing : height = width * (bbh / bbw)
814                 \in@hundreds{\@p@swidth}{\@bbh}{\@bbw}
815                 %\ps@typeout{ \@p@swidth * \@bbh / \@bbw = \@result }
816                 \edef\@p@sheight{\@result}
817                 %\ps@typeout{h from w : height is \@p@sheight}
818 }
819 \def\compute@handw{
820                 \if@height 
821                         \if@width
822                         \else
823                                 \compute@wfromh
824                         \fi
825                 \else 
826                         \if@width
827                                 \compute@hfromw
828                         \else
829                                 \edef\@p@sheight{\@bbh}
830                                 \edef\@p@swidth{\@bbw}
831                         \fi
832                 \fi
833 }
834 \def\compute@resv{
835                 \if@rheight \else \edef\@p@srheight{\@p@sheight} \fi
836                 \if@rwidth \else \edef\@p@srwidth{\@p@swidth} \fi
837                 %\ps@typeout{rheight = \@p@srheight, rwidth = \@p@srwidth}
838 }
839 %               
840 % Compute any missing values
841 \def\compute@sizes{
842         \compute@bb
843         \if@scalefirst\if@angle
844 % at this point the bounding box has been adjsuted correctly for
845 % rotation.  PSFIG does all of its scaling using \@bbh and \@bbw.  If
846 % a width= or height= was specified along with \psscalefirst, then the
847 % width=/height= value needs to be adjusted to match the new (rotated)
848 % bounding box size (specifed in \@bbw and \@bbh).
849 %    \ps@bbw       width=
850 %    -------  =  ---------- 
851 %    \@bbw       new width=
852 % so `new width=' = (width= * \@bbw) / \ps@bbw; where \ps@bbw is the
853 % width of the original (unrotated) bounding box.
854         \if@width
855            \in@hundreds{\@p@swidth}{\@bbw}{\ps@bbw}
856            \edef\@p@swidth{\@result}
857         \fi
858         \if@height
859            \in@hundreds{\@p@sheight}{\@bbh}{\ps@bbh}
860            \edef\@p@sheight{\@result}
861         \fi
862         \fi\fi
863         \compute@handw
864         \compute@resv}
865 %
866 %
867 %
868 \def\OzTeXSpecials{
869         \special{empty.ps /@isp {true} def}
870         \special{empty.ps \@p@swidth \space \@p@sheight \space
871                         \@p@sbbllx \space \@p@sbblly \space
872                         \@p@sbburx \space \@p@sbbury \space
873                         startTexFig \space }
874         \if@clip{
875                 \if@verbose{
876                         \ps@typeout{(clip)}
877                 }\fi
878                 \special{empty.ps doclip \space }
879         }\fi
880         \if@angle{
881                 \if@verbose{
882                         \ps@typeout{(rotate)}
883                 }\fi
884                 \special {empty.ps \@p@sangle \space rotate \space} 
885         }\fi
886         \if@prologfile
887             \special{\@prologfileval \space } \fi
888         \if@decmpr{
889                 \if@verbose{
890                         \ps@typeout{psfig: Compression not available
891                         in OzTeX version \space }
892                 }\fi
893         }\else{
894                 \if@verbose{
895                         \ps@typeout{psfig: including \@p@sfile \space }
896                 }\fi
897                 \special{epsf=\@p@sfile \space }
898         }\fi
899         \if@postlogfile
900             \special{\@postlogfileval \space } \fi
901         \special{empty.ps /@isp {false} def}
902 }
903 \def\DvipsSpecials{
904         %
905         \special{ps::[begin]    \@p@swidth \space \@p@sheight \space
906                         \@p@sbbllx \space \@p@sbblly \space
907                         \@p@sbburx \space \@p@sbbury \space
908                         startTexFig \space }
909         \if@clip{
910                 \if@verbose{
911                         \ps@typeout{(clip)}
912                 }\fi
913                 \special{ps:: doclip \space }
914         }\fi
915         \if@angle
916                 \if@verbose{
917                         \ps@typeout{(clip)}
918                 }\fi
919                 \special {ps:: \@p@sangle \space rotate \space} 
920         \fi
921         \if@prologfile
922             \special{ps: plotfile \@prologfileval \space } \fi
923         \if@decmpr{
924                 \if@verbose{
925                         \ps@typeout{psfig: including \@p@sfile.Z \space }
926                 }\fi
927                 \special{ps: plotfile "`zcat \@p@sfile.Z" \space }
928         }\else{
929                 \if@verbose{
930                         \ps@typeout{psfig: including \@p@sfile \space }
931                 }\fi
932                 \special{ps: plotfile \@p@sfile \space }
933         }\fi
934         \if@postlogfile
935             \special{ps: plotfile \@postlogfileval \space } \fi
936         \special{ps::[end] endTexFig \space }
937 }
938 %
939 % \psfig
940 % usage : \psfig{file=, height=, width=, bbllx=, bblly=, bburx=, bbury=,
941 %                       rheight=, rwidth=, clip=}
942 %
943 % "clip=" is a switch and takes no value, but the `=' must be present.
944 \def\psfig#1{\vbox {
945         % do a zero width hard space so that a single
946         % \psfig in a centering enviornment will behave nicely
947         %{\setbox0=\hbox{\ }\ \hskip-\wd0}
948         %
949         \ps@init@parms
950         \parse@ps@parms{#1}
951         \compute@sizes
952         %
953         \ifnum\@p@scost<\@psdraft{
954                 \PsfigSpecials 
955                 % Create the vbox to reserve the space for the figure.
956                 \vbox to \@p@srheight sp{
957                 % 1/92 TJD Changed from "true sp" to "sp" for magnification.
958                         \hbox to \@p@srwidth sp{
959                                 \hss
960                         }
961                 \vss
962                 }
963         }\else{
964                 % draft figure, just reserve the space and print the
965                 % path name.
966                 \if@draftbox{           
967                         % Verbose draft: print file name in box
968                         % 10/93 TJD changed to fbox from frame
969                         \hbox{\fbox{\vbox to \@p@srheight sp{
970                         \vss
971                         \hbox to \@p@srwidth sp{ \hss 
972                                 % 10/93 TJD deleted to avoid ``_'' problems
973                                 % \@p@sfile
974                          \hss }
975                         \vss
976                         }}}
977                 }\else{
978                         % Non-verbose draft
979                         \vbox to \@p@srheight sp{
980                         \vss
981                         \hbox to \@p@srwidth sp{\hss}
982                         \vss
983                         }
984                 }\fi    
985
986
987
988         }\fi
989 }}
990 \psfigRestoreAt
991 \setDriver
992 \let\@=\LaTeXAtSign
993
994
995