Debian Codegraph @

texmf-dist/tex/generic/tex-ps/epsfx.tex

raw
1 %--------------------------------------------------------------------------
2 % This is small extension of T. Rokicki's EPSF.TEX (from DVIPS 5.58):
3 % -- allows safe including of EPS files generated by DVIPS
4 % -- can also display bounding boxes.
5 %--------------------------------------------------------------------------
6 % AUTHORS: Bogus\l{}aw Jackowski and Piotr Pianowski
7 % BOP s.c.
8 % ul. Piastowska 70, 80-363 Gda\'nsk, Poland
9 % email: [email protected]
10 % USAGE:
11 % \eps{file.eps} % instead of \epsffile{file.eps}
12 % The following settings of the parameter \tracingeps are recognized:
13 % \tracingeps=0 % default, no extra information displayed
14 % \tracingeps=1 % displays bounding boxes and file names
15 % \tracingeps>1 % displays graphics, bounding boxes and file names
16 % HISTORY:
17 % ver. 0.5 19 VIII 1994
18 % ver. 0.51 25 VIII 1994
19 % * \epsnamecolor added
20 % ver. 0.52 31 VIII 1994
21 % * \eps renamed to \epsraw
22 % * \tps renamed to \eps
23 % ver. 0.53 9 I 1995
24 % * `\isls false N' added to \eps
25 % * virtually active slash neutralized
26 % ver. 0.54 9 III 1995
27 % * \eps clears bop-hook
28 % ver. 0.55 27 III 1995
29 % * a patch neutralizing unnecessary rounding added
30 % ver. 0.56 3 X 1995
31 % * \special commands surrounding EPS box are to be nested in the \vbox
32 % ver. 0.57 31 VIII 1996
33 % * odd characters in names enabled
34 % ver. 0.58 21 III 1997
35 % * setpageparams and setpage neutralized
36 % ver. 0.585 25 III 1997
37 % * comments touched
38 % ver. 0.59 7 VI 1998
39 % * EPSF.TEX included
40 % ver. 0.60 10 I 1999
41 % * safe multiplication of eps dimensions by 10 (expected to be
42 % included in the newest version of Rokicki's package)
43 % ver. 0.61 29 III 2000
44 % * \eps expands to \hbox
45 % ver. 0.62 13 (Friday) VII 2001
46 % * setpagedevice neutralized (why only now?) along with a bundle of
47 % commands specifying paper size (a0, a1, ... , b0, b1, ... , etc.)
48 %--------------------------------------------------------------------------
49 \edef\slashcatcode{\the\catcode`\/}
50 \catcode`\/12
51 %
52 %%%%%%%%%%%%%%%%%%%%%%%%%%% \input epsf -- inserted below %%%%%%%%%%%%%%%%%
53 % EPSF.TEX macro file:
54 % Written by Tomas Rokicki of Radical Eye Software, 29 Mar 1989.
55 % Revised by Don Knuth, 3 Jan 1990.
56 % Revised by Tomas Rokicki to accept bounding boxes with no
57 % space after the colon, 18 Jul 1990.
58 %
59 % TeX macros to include an Encapsulated PostScript graphic.
60 % Works by finding the bounding box comment,
61 % calculating the correct scale values, and inserting a vbox
62 % of the appropriate size at the current position in the TeX document.
63 %
64 % To use with the center environment of LaTeX, preface the \epsffile
65 % call with a \leavevmode. (LaTeX should probably supply this itself
66 % for the center environment.)
67 %
68 % To use, simply say
69 % \input epsf % somewhere early on in your TeX file
70 % \epsfbox{filename.ps} % where you want to insert a vbox for a figure
71 %
72 % Alternatively, you can type
73 %
74 % \epsfbox[0 0 30 50]{filename.ps} % to supply your own BB
75 %
76 % which will not read in the file, and will instead use the bounding
77 % box you specify.
78 %
79 % The effect will be to typeset the figure as a TeX box, at the
80 % point of your \epsfbox command. By default, the graphic will have its
81 % `natural' width (namely the width of its bounding box, as described
82 % in filename.ps). The TeX box will have depth zero.
83 %
84 % You can enlarge or reduce the figure by saying
85 % \epsfxsize=<dimen> \epsfbox{filename.ps}
86 % (or
87 % \epsfysize=<dimen> \epsfbox{filename.ps})
88 % instead. Then the width of the TeX box will be \epsfxsize and its
89 % height will be scaled proportionately (or the height will be
90 % \epsfysize and its width will be scaled proportiontally). The
91 % width (and height) is restored to zero after each use.
92 %
93 % A more general facility for sizing is available by defining the
94 % \epsfsize macro. Normally you can redefine this macro
95 % to do almost anything. The first parameter is the natural x size of
96 % the PostScript graphic, the second parameter is the natural y size
97 % of the PostScript graphic. It must return the xsize to use, or 0 if
98 % natural scaling is to be used. Common uses include:
99 %
100 % \epsfxsize % just leave the old value alone
101 % 0pt % use the natural sizes
102 % #1 % use the natural sizes
103 % \hsize % scale to full width
104 % 0.5#1 % scale to 50% of natural size
105 % \ifnum#1>\hsize\hsize\else#1\fi % smaller of natural, hsize
106 %
107 % If you want TeX to report the size of the figure (as a message
108 % on your terminal when it processes each figure), say `\epsfverbosetrue'.
109 %
110 \newread\epsffilein % file to \read
111 \newif\ifepsffileok % continue looking for the bounding box?
112 \newif\ifepsfbbfound % success?
113 \newif\ifepsfverbose % report what you're making?
114 \newif\ifepsfdraft % use draft mode?
115 \newdimen\epsfxsize % horizontal size after scaling
116 \newdimen\epsfysize % vertical size after scaling
117 \newdimen\epsftsize % horizontal size before scaling
118 \newdimen\epsfrsize % vertical size before scaling
119 \newdimen\epsftmp % register for arithmetic manipulation
120 \newdimen\pspoints % conversion factor
121 %
122 \pspoints=1bp % Adobe points are `big'
123 \epsfxsize=0pt % Default value, means `use natural size'
124 \epsfysize=0pt % ditto
125 %
126 \def\epsfbox#1{\global\def\epsfllx{72}\global\def\epsflly{72}%
127 \global\def\epsfurx{540}\global\def\epsfury{720}%
128 \def\lbracket{[}\def\testit{#1}\ifx\testit\lbracket
129 \let\next=\epsfgetlitbb\else\let\next=\epsfnormal\fi\next{#1}}%
130 %
131 \def\epsfgetlitbb#1#2 #3 #4 #5]#6{\epsfgrab #2 #3 #4 #5 .\\%
132 \epsfsetgraph{#6}}%
133 %
134 \def\epsfnormal#1{\epsfgetbb{#1}\epsfsetgraph{#1}}%
135 %
136 \def\epsfgetbb#1{%
137 %
138 % The first thing we need to do is to open the
139 % PostScript file, if possible.
140 %
141 \openin\epsffilein=#1
142 \ifeof\epsffilein\errmessage{I couldn't open #1, will ignore it}\else
143 %
144 % Okay, we got it. Now we'll scan lines until we find one that doesn't
145 % start with %. We're looking for the bounding box comment.
146 %
147 {\epsffileoktrue \chardef\other=12
148 \def\do##1{\catcode`##1=\other}\dospecials \catcode`\ =10
149 \loop
150 \read\epsffilein to \epsffileline
151 \ifeof\epsffilein\epsffileokfalse\else
152 %
153 % We check to see if the first character is a % sign;
154 % if not, we stop reading (unless the line was entirely blank);
155 % if so, we look further and stop only if the line begins with
156 % `%%BoundingBox:'.
157 %
158 \expandafter\epsfaux\epsffileline:. \\%
159 \fi
160 \ifepsffileok\repeat
161 \ifepsfbbfound\else
162 \ifepsfverbose\message{No bounding box comment in #1; using defaults}\fi\fi
163 }\closein\epsffilein\fi}%
164 %
165 % Now we have to calculate the scale and offset values to use.
166 % First we compute the natural sizes.
167 %
168 \def\epsfclipon{\def\epsfclipstring{ clip}}%
169 \def\epsfclipoff{\def\epsfclipstring{\ifepsfdraft\space clip\fi}}%
170 \epsfclipoff
171 %
172 \def\epsfsetgraph#1{%
173 \epsfrsize=\epsfury\pspoints
174 \advance\epsfrsize by-\epsflly\pspoints
175 \epsftsize=\epsfurx\pspoints
176 \advance\epsftsize by-\epsfllx\pspoints
177 %
178 % If `epsfxsize' is 0, we default to the natural size of the picture.
179 % Otherwise we scale the graph to be \epsfxsize wide.
180 %
181 \epsfxsize\epsfsize\epsftsize\epsfrsize
182 \ifnum\epsfxsize=0 \ifnum\epsfysize=0
183 \epsfxsize=\epsftsize \epsfysize=\epsfrsize
184 \epsfrsize=0pt
185 %
186 % We have a sticky problem here: TeX doesn't do floating point arithmetic!
187 % Our goal is to compute y = rx/t. The following loop does this reasonably
188 % fast, with an error of at most about 16 sp (about 1/4000 pt).
189 %
190 \else\epsftmp=\epsftsize \divide\epsftmp\epsfrsize
191 \epsfxsize=\epsfysize \multiply\epsfxsize\epsftmp
192 \multiply\epsftmp\epsfrsize \advance\epsftsize-\epsftmp
193 \epsftmp=\epsfysize
194 \loop \advance\epsftsize\epsftsize \divide\epsftmp 2
195 \ifnum\epsftmp>0
196 \ifnum\epsftsize<\epsfrsize\else
197 \advance\epsftsize-\epsfrsize \advance\epsfxsize\epsftmp \fi
198 \repeat
199 \epsfrsize=0pt
200 \fi
201 \else \ifnum\epsfysize=0
202 \epsftmp=\epsfrsize \divide\epsftmp\epsftsize
203 \epsfysize=\epsfxsize \multiply\epsfysize\epsftmp
204 \multiply\epsftmp\epsftsize \advance\epsfrsize-\epsftmp
205 \epsftmp=\epsfxsize
206 \loop \advance\epsfrsize\epsfrsize \divide\epsftmp 2
207 \ifnum\epsftmp>0
208 \ifnum\epsfrsize<\epsftsize\else
209 \advance\epsfrsize-\epsftsize \advance\epsfysize\epsftmp \fi
210 \repeat
211 \epsfrsize=0pt
212 \else
213 \epsfrsize=\epsfysize
214 \fi
215 \fi
216 %
217 % Finally, we make the vbox and stick in a \special that dvips can parse.
218 %
219 \ifepsfverbose\message{#1: width=\the\epsfxsize, height=\the\epsfysize}\fi
220 \epsftmp=10\epsfxsize \divide\epsftmp\pspoints
221 \vbox to\epsfysize{\vfil\hbox to\epsfxsize{%
222 \ifnum\epsfrsize=0\relax
223 \special{PSfile=\ifepsfdraft psdraft.ps\else#1\fi\space
224 llx=\epsfllx\space lly=\epsflly\space
225 urx=\epsfurx\space ury=\epsfury\space rwi=\number\epsftmp
226 \epsfclipstring}%
227 \else
228 \epsfrsize=10\epsfysize \divide\epsfrsize\pspoints
229 \special{PSfile=\ifepsfdraft psdraft.ps\else#1\fi\space
230 llx=\epsfllx\space lly=\epsflly\space
231 urx=\epsfurx\space ury=\epsfury\space rwi=\number\epsftmp\space
232 rhi=\number\epsfrsize \epsfclipstring}%
233 \fi
234 \hfil}}%
235 \global\epsfxsize=0pt\global\epsfysize=0pt}%
236 %
237 % We still need to define the tricky \epsfaux macro. This requires
238 % a couple of magic constants for comparison purposes.
239 %
240 {\catcode`\%=12 \global\let\epsfpercent=%\global\def\epsfbblit{%BoundingBox}}%
241 %
242 % So we're ready to check for `%BoundingBox:' and to grab the
243 % values if they are found.
244 %
245 \long\def\epsfaux#1#2:#3\\{\ifx#1\epsfpercent
246 \def\testit{#2}\ifx\testit\epsfbblit
247 \epsfgrab #3 . . . \\%
248 \epsffileokfalse
249 \global\epsfbbfoundtrue
250 \fi\else\ifx#1\par\else\epsffileokfalse\fi\fi}%
251 %
252 % Here we grab the values and stuff them in the appropriate definitions.
253 %
254 \def\epsfempty{}%
255 \def\epsfgrab #1 #2 #3 #4 #5\\{%
256 \global\def\epsfllx{#1}\ifx\epsfllx\epsfempty
257 \epsfgrab #2 #3 #4 #5 .\\\else
258 \global\def\epsflly{#2}%
259 \global\def\epsfurx{#3}\global\def\epsfury{#4}\fi}%
260 %
261 % We default the epsfsize macro.
262 %
263 \def\epsfsize#1#2{\epsfxsize}
264 %
265 % Finally, another definition for compatibility with older macros.
266 %
267 \let\epsffile=\epsfbox
268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% End of EPSF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 % ---
270 \newcount\tracingeps \tracingeps0
271 % ---
272 \newbox\tmpepsbox
273 % ---
274 \ifx\epsdirundefined\epsdir\def\epsdir{}\fi
275 \def\epsnamecolor{1 0 0}
276 % ---
277 % BOTH \eps and \epsraw ``normalize'' the eps name, as one may wish
278 % to use \epsraw separately
279 % ---
280 \def\epsraw{\begingroup\escapechar-1\catcode`\%12\def~{\string~}\epsrawcont}
281 \def\epsrawcont#1{%
282 \xdef\theepsname{\expandafter\string\csname#1\endcsname}\endgroup
283 \ifnum\tracingeps=0 \hbox{\epsffile{\epsdir\theepsname}}\fi
284 \ifnum\tracingeps>0
285 \hbox{\setbox\tmpepsbox\hbox{\epsffile{\epsdir\theepsname}}%
286 \ifnum\tracingeps>1 \rlap{\copy\tmpepsbox}\fi
287 \vbox{\offinterlineskip
288 \hrule\vskip-.4pt
289 \hbox to\wd\tmpepsbox{\vrule\hss\vbox to\ht\tmpepsbox{
290 \vss\hbox{\tt \special{ps:gsave \epsnamecolor\space setrgbcolor}%
291 \theepsname\special{ps:grestore}}\vss}\hss\vrule}
292 \vskip-.4pt\hrule
293 }}\fi}
294 % ---
295 \def\eps{\hbox\bgroup
296 \begingroup \escapechar-1 \catcode`\%12 \def~{\string~}\epscont}
297 \def\epscont#1{%
298 \xdef\theepsname{\expandafter\string\csname#1\endcsname}\endgroup
299 \vbox{\special{ps: /SItps save N /isls false N
300 statusdict begin
301 /setpageparams {pop pop pop pop} def /setpage {pop pop pop} def
302 end
303 userdict begin
304 /bop-hook {} def /setpagedevice {pop} def
305 /a0 {} def /a1 {} def /a2 {} def /a3 {} def /a4 {} def /a5 {} def
306 /a6 {} def /a7 {} def /a8 {} def /a9 {} def /a10 {} def
307 /b0 {} def /b1 {} def /b2 {} def /b3 {} def /b4 {} def /b5 {} def
308 /letter {} def /note {} def /legal {} def
309 /halfletter {} def /11x17 {} def /ledger {} def
310 /flsa {} def /flse {} def
311 end }%
312 \epsraw\theepsname\special{ps: SItps restore }}\egroup}
313 % ---
314 % Redefinition of epsf macros:
315 %
316 % The values of `rwi' and `rhi' parameters are to be given in tenths
317 % of big point; the older version of the epsf package used to multiply
318 % a dimen register by 10, which put severe limitations on the
319 % available EPS size.
320 %
321 % The macro `\decimalshift' multiplies a given value by 10 ``syntactically,''
322 % i.e., accomplishes ``decimal shifting''; the following conditions
323 % are assumed to hold:
324 % * leading zeros are meaningless;
325 % * <digit>+<period><dimen unit> is a proper form of a dimen value;
326 % * the command `\the' applied to a dimen register yields a canonical form:
327 % [<minus>]<digit>+[<period><digit>+]<pt unit>
328 % where <pt unit> are `p' and `t' characters having category code 12.
329 %
330 \def\decimalshift#1{% #1 -- a dimen register
331 \expandafter\expandafter\expandafter
332 \decimalsplit\expandafter\gobblePT\the#1.\relax
333 }%
334 \def\decimalsplit#1.#2\relax{%
335 \ifnum#1=0 \ifdim#11sp=-1sp -\fi \else #1\fi
336 \ifdim0#2sp=0sp 0\else \fractionshift#2\fi
337 }%
338 \def\fractionshift#1#2.{\ifnum0#2=0 #1\else #1.#2\fi}%
339 {\catcode`\p12 \catcode`\t12 \gdef\gobblePT#1pt{#1}}%
340 \def\pttobp{0.99626401}% = 72/72.27
341 % ---
342 \def\epsfsetgraph#1{%
343 \epsfrsize=\epsfury\pspoints
344 \advance\epsfrsize by-\epsflly\pspoints
345 \epsftsize=\epsfurx\pspoints
346 \advance\epsftsize by-\epsfllx\pspoints
347 %
348 % If `epsfxsize' is 0, we default to the natural size of the picture.
349 % Otherwise we scale the graph to be \epsfxsize wide.
350 %
351 \epsfxsize\epsfsize\epsftsize\epsfrsize
352 \ifnum\epsfxsize=0 \ifnum\epsfysize=0
353 \epsfxsize=\epsftsize \epsfysize=\epsfrsize
354 \epsfrsize=0pt
355 %
356 % We have a sticky problem here: TeX doesn't do floating point arithmetic!
357 % Our goal is to compute y = rx/t. The following loop does this reasonably
358 % fast, with an error of at most about 16 sp (about 1/4000 pt).
359 %
360 \else\epsftmp=\epsftsize \divide\epsftmp\epsfrsize
361 \epsfxsize=\epsfysize \multiply\epsfxsize\epsftmp
362 \multiply\epsftmp\epsfrsize \advance\epsftsize-\epsftmp
363 \epsftmp=\epsfysize
364 \loop \advance\epsftsize\epsftsize \divide\epsftmp 2
365 \ifnum\epsftmp>0
366 \ifnum\epsftsize<\epsfrsize\else
367 \advance\epsftsize-\epsfrsize \advance\epsfxsize\epsftmp \fi
368 \repeat
369 \epsfrsize=0pt
370 \fi
371 \else \ifnum\epsfysize=0
372 \epsftmp=\epsfrsize \divide\epsftmp\epsftsize
373 \epsfysize=\epsfxsize \multiply\epsfysize\epsftmp
374 \multiply\epsftmp\epsftsize \advance\epsfrsize-\epsftmp
375 \epsftmp=\epsfxsize
376 \loop \advance\epsfrsize\epsfrsize \divide\epsftmp 2
377 \ifnum\epsftmp>0
378 \ifnum\epsfrsize<\epsftsize\else
379 \advance\epsfrsize-\epsftsize \advance\epsfysize\epsftmp \fi
380 \repeat
381 \epsfrsize=0pt
382 \else
383 \epsfrsize=\epsfysize
384 \fi
385 \fi
386 %
387 % Finally, we make the vbox and stick in a \special that dvips can parse.
388 %
389 \ifepsfverbose\message{#1: width=\the\epsfxsize, height=\the\epsfysize}\fi
390 \epsftmp=\pttobp\epsfxsize
391 \vbox to\epsfysize{\vfil\hbox to\epsfxsize{%
392 \ifnum\epsfrsize=0\relax
393 \special{PSfile=\ifepsfdraft psdraft.ps\else#1\fi\space
394 llx=\epsfllx\space lly=\epsflly\space
395 urx=\epsfurx\space ury=\epsfury\space
396 rwi=\decimalshift\epsftmp
397 \epsfclipstring}%
398 \else
399 \epsfrsize=\pttobp\epsfysize
400 \special{PSfile=\ifepsfdraft psdraft.ps\else#1\fi\space
401 llx=\epsfllx\space lly=\epsflly\space
402 urx=\epsfurx\space ury=\epsfury\space
403 rwi=\decimalshift\epsftmp\space
404 rhi=\decimalshift\epsfrsize
405 \epsfclipstring}%
406 \fi
407 \hfil}}%
408 \global\epsfxsize=0pt\global\epsfysize=0pt}%
409 % ---
410 \catcode`\/\slashcatcode
411 % ---
412 \endinput