epsf.tex 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. %%% -*-TeX-*-
  2. %%% ====================================================================
  3. %%% @TeX-file{
  4. %%% author = "Tom Rokicki",
  5. %%% version = "2.7.4",
  6. %%% date = "14 February 2011",
  7. %%% time = "15:44:06 MST",
  8. %%% filename = "epsf.tex",
  9. %%% address = "Tom Rokicki
  10. %%% Box 2081
  11. %%% Stanford, CA 94309
  12. %%% USA",
  13. %%% telephone = "+1 415 855 9989",
  14. %%% checksum = "29223 653 3100 27123",
  15. %%% email = "rokicki@cs.stanford.edu (Internet)",
  16. %%% codetable = "ISO/ASCII",
  17. %%% copyright = "This file is freely redistributable and
  18. %%% placed into the public domain by Tomas
  19. %%% Rokicki.",
  20. %%% keywords = "PostScript, TeX",
  21. %%% license = "public domain",
  22. %%% supported = "yes",
  23. %%% abstract = "This file contains macros to support the
  24. %%% inclusion of Encapsulated PostScript files
  25. %%% in TeX documents.",
  26. %%% docstring = "This file contains TeX macros to include an
  27. %%% Encapsulated PostScript graphic. It works
  28. %%% by finding the bounding box comment,
  29. %%% calculating the correct scale values, and
  30. %%% inserting a vbox of the appropriate size at
  31. %%% the current position in the TeX document.
  32. %%%
  33. %%% To use, simply use
  34. %%%
  35. %%% \input epsf % somewhere early on in your TeX file
  36. %%%
  37. %%% % then where you want to insert a vbox for a figure:
  38. %%% \epsfbox{filename.ps}
  39. %%%
  40. %%% Alternatively, you can supply your own
  41. %%% bounding box by
  42. %%%
  43. %%% \epsfbox[0 0 30 50]{filename.ps}
  44. %%%
  45. %%% This will not read in the file, and will
  46. %%% instead use the bounding box you specify.
  47. %%%
  48. %%% The effect will be to typeset the figure as
  49. %%% a TeX box, at the point of your \epsfbox
  50. %%% command. By default, the graphic will have
  51. %%% its `natural' width (namely the width of
  52. %%% its bounding box, as described in
  53. %%% filename.ps). The TeX box will have depth
  54. %%% zero.
  55. %%%
  56. %%% You can enlarge or reduce the figure by
  57. %%% using
  58. %%%
  59. %%% \epsfxsize = <dimen> \epsfbox{filename.ps}
  60. %%% or
  61. %%% \epsfysize = <dimen> \epsfbox{filename.ps}
  62. %%%
  63. %%% instead. Then the width of the TeX box will
  64. %%% be \epsfxsize and its height will be scaled
  65. %%% proportionately (or the height will be
  66. %%% \epsfysize and its width will be scaled
  67. %%% proportionately).
  68. %%%
  69. %%% The width (and height) is restored to zero
  70. %%% after each use, so \epsfxsize or \epsfysize
  71. %%% must be specified before EACH use of
  72. %%% \epsfbox.
  73. %%%
  74. %%% A more general facility for sizing is
  75. %%% available by defining the \epsfsize macro.
  76. %%% Normally you can redefine this macro to do
  77. %%% almost anything. The first parameter is
  78. %%% the natural x size of the PostScript
  79. %%% graphic, the second parameter is the
  80. %%% natural y size of the PostScript graphic.
  81. %%% It must return the xsize to use, or 0 if
  82. %%% natural scaling is to be used. Common uses
  83. %%% include:
  84. %%%
  85. %%% \epsfxsize % just leave the old value alone
  86. %%% 0pt % use the natural sizes
  87. %%% #1 % use the natural sizes
  88. %%% \hsize % scale to full width
  89. %%% 0.5#1 % scale to 50% of natural size
  90. %%% \ifnum #1 > \hsize \hsize \else #1\fi
  91. %%% % smaller of natural, hsize
  92. %%%
  93. %%% If you want TeX to report the size of the
  94. %%% figure (as a message on your terminal when
  95. %%% it processes each figure), use
  96. %%% `\epsfverbosetrue'.
  97. %%%
  98. %%% If you only want to get the bounding box
  99. %%% extents, without producing any output boxes
  100. %%% or \special{}, then use \epsfgetbb{filename}.
  101. %%% The bounding box corner coordinates are saved
  102. %%% in the macros \epsfllx, \epsflly, \epsfurx,
  103. %%% and \epsfury in PostScript units of big
  104. %%% points.
  105. %%%
  106. %%% Revision history:
  107. %%%
  108. %%% ---------------------------------------------
  109. %%% epsf.tex macro file:
  110. %%% Originally written by Tomas Rokicki of
  111. %%% Radical Eye Software, 29 Mar 1989.
  112. %%%
  113. %%% ---------------------------------------------
  114. %%% Revised by Don Knuth, 3 Jan 1990.
  115. %%%
  116. %%% ---------------------------------------------
  117. %%% Revised by Tomas Rokicki, 18 Jul 1990.
  118. %%% Accept bounding boxes with no space after
  119. %%% the colon.
  120. %%%
  121. %%% ---------------------------------------------
  122. %%% Revised by Nelson H. F. Beebe
  123. %%% <beebe@math.utah.edu>, 03 Dec 1991 [2.0].
  124. %%% Add version number and date typeout.
  125. %%%
  126. %%% Use \immediate\write16 instead of \message
  127. %%% to ensure output on new line.
  128. %%%
  129. %%% Handle nested EPS files.
  130. %%%
  131. %%% Handle %%BoundingBox: (atend) lines.
  132. %%%
  133. %%% Do not quit when blank lines are found.
  134. %%%
  135. %%% Add a few percents to remove generation of
  136. %%% spurious blank space.
  137. %%%
  138. %%% Move \special output to
  139. %%% \epsfspecial{filename} so that other macro
  140. %%% packages can input this one, then change
  141. %%% the definition of \epsfspecial to match
  142. %%% another DVI driver.
  143. %%%
  144. %%% Move size computation to \epsfsetsize which
  145. %%% can be called by the user; the verbose
  146. %%% output of the bounding box and scaled width
  147. %%% and height happens here.
  148. %%%
  149. %%% ---------------------------------------------
  150. %%% Revised by Nelson H. F. Beebe
  151. %%% <beebe@math.utah.edu>, 05 May 1992 [2.1].
  152. %%% Wrap \leavevmode\hbox{} around \vbox{} with
  153. %%% the \special so that \epsffile{} can be
  154. %%% used inside \begin{center}...\end{center}
  155. %%%
  156. %%% ---------------------------------------------
  157. %%% Revised by Nelson H. F. Beebe
  158. %%% <beebe@math.utah.edu>, 09 Dec 1992 [2.2].
  159. %%% Introduce \epsfshow{true,false} and
  160. %%% \epsfframe{true,false} macros; the latter
  161. %%% suppresses the insertion of the PostScript,
  162. %%% and instead just creates an empty box,
  163. %%% which may be handy for rapid prototyping.
  164. %%%
  165. %%% ---------------------------------------------
  166. %%% Revised by Nelson H. F. Beebe
  167. %%% <beebe@math.utah.edu>, 14 Dec 1992 [2.3].
  168. %%% Add \epsfshowfilename{true,false}. When
  169. %%% true, and \epsfshowfalse is specified, the
  170. %%% PostScript file name will be displayed
  171. %%% centered in the figure box.
  172. %%%
  173. %%% ---------------------------------------------
  174. %%% Revised by Nelson H. F. Beebe
  175. %%% <beebe@math.utah.edu>, 20 June 1993 [2.4].
  176. %%% Remove non-zero debug setting of \epsfframemargin,
  177. %%% and change margin handling to preserve EPS image
  178. %%% size and aspect ratio, so that the actual
  179. %%% box is \epsfxsize+\epsfframemargin wide by
  180. %%% \epsfysize+\epsfframemargin high.
  181. %%% Reduce output of \epsfshowfilenametrue to
  182. %%% just the bare file name.
  183. %%%
  184. %%% ---------------------------------------------
  185. %%% Revised by Nelson H. F. Beebe
  186. %%% <beebe@math.utah.edu>, 13 July 1993 [2.5].
  187. %%% Add \epsfframethickness for control of
  188. %%% \epsfframe frame lines.
  189. %%%
  190. %%% ---------------------------------------------
  191. %%% Revised by Nelson H. F. Beebe
  192. %%% <beebe@math.utah.edu>, 02 July 1996 [2.6]
  193. %%% Add missing initialization \epsfatendfalse;
  194. %%% the lack of this resulted in the wrong
  195. %%% BoundingBox being picked up, mea culpa, sigh...
  196. %%%
  197. %%% ---------------------------------------------
  198. %%% Revised by Nelson H. F. Beebe
  199. %%% <beebe@math.utah.edu>, 25 October 1996 [2.7]
  200. %%% Update to match changes in from dvips 5-600
  201. %%% distribution: new user-accessible macros:
  202. %%% \epsfclipon, \epsfclipoff, \epsfdrafton,
  203. %%% \epsfdraftoff, change \empty to \epsfempty.
  204. %%%
  205. %%% ---------------------------------------------
  206. %%% Revised by Nelson H. F. Beebe
  207. %%% <beebe@math.utah.edu>, 18 May 2002 [2.7.1]
  208. %%% Add write statements to echo input file
  209. %%% names. Prior to that change, an error in
  210. %%% such a file could be quite hard to track
  211. %%% down: a long list of TeX page numbers could
  212. %%% suddenly be followed by ``TeX buffer
  213. %%% capacity'' exceeded, without any indication
  214. %%% of the file that was responsible.
  215. %%%
  216. %%% ---------------------------------------------
  217. %%% Revised by Nelson H. F. Beebe
  218. %%% <beebe@math.utah.edu>, 16 May 2003 [2.7.2]
  219. %%% Supply two critical percent characters that
  220. %%% were mistakenly omitted in version 2.7.1,
  221. %%% and resulted in a small amount of spurious
  222. %%% horizontal space.
  223. %%%
  224. %%% ---------------------------------------------
  225. %%% Revised by Nelson H. F. Beebe
  226. %%% <beebe@math.utah.edu>, 14 Feb 2011 [2.7.3]
  227. %%% Add previously-missing \space in rwi
  228. %%% assignments (bug reported 14-Feb-2011 by
  229. %%% Stefan Rueger <s.rueger@open.ac.uk>).
  230. %%%
  231. %%% ---------------------------------------------
  232. %%% Revised by Nelson H. F. Beebe
  233. %%% <beebe@math.utah.edu>, Karl Berry
  234. %%% <karl@freefriends.org>, and Robin Fairbairns
  235. %%% <Robin.Fairbairns@cl.cam.ac.uk>,
  236. %%% 23 July 2005 [2.7.3]
  237. %%% Add critical \hbox{} wrapper in \epsfsetgraph
  238. %%% so that \epsfbox{} does not conflict with
  239. %%% LaTeX center environment when \epsfbox{} is
  240. %%% surrounded by other horizonal objects.
  241. %%% Improve macro readability by adding legal,
  242. %%% but invisible-in-typeset-output, spaces.
  243. %%% Ensure that verbose status reports come
  244. %%% inside (filename ...) list.
  245. %%%
  246. %%% ---------------------------------------------
  247. %%% The checksum field above contains a CRC-16
  248. %%% checksum as the first value, followed by
  249. %%% the equivalent of the standard UNIX wc
  250. %%% (word count) utility output of lines,
  251. %%% words, and characters. This is produced by
  252. %%% Robert Solovay's checksum utility.",
  253. %%% }
  254. %%% ====================================================================
  255. %\immediate \write16 {This is `epsf.tex' v2.0 <02 Dec 1991>}%
  256. %\immediate \write16 {This is `epsf.tex' v2.1 <05 May 1992>}%
  257. %\immediate \write16 {This is `epsf.tex' v2.2 <09 Dec 1992>}%
  258. %\immediate \write16 {This is `epsf.tex' v2.3 <14 Dec 1992>}%
  259. %\immediate \write16 {This is `epsf.tex' v2.4 <20 June 1993>}%
  260. %\immediate \write16 {This is `epsf.tex' v2.5 <13 July 1993>}%
  261. %\immediate \write16 {This is `epsf.tex' v2.6 <02 July 1996>}%
  262. %\immediate \write16 {This is `epsf.tex' v2.7 <25 October 1996>}%
  263. %\immediate \write16 {This is `epsf.tex' v2.7.1 <18 May 2002>}%
  264. %\immediate \write16 {This is `epsf.tex' v2.7.2 <16 May 2003>}%
  265. %\immediate \write16 {This is `epsf.tex' v2.7.3 <23 July 2005>}%
  266. \immediate \write16 {This is `epsf.tex' v2.7.4 <14 February 2011>}%
  267. %
  268. \newread \epsffilein % file to \read
  269. \newif \ifepsfatend % need to scan to LAST %%BoundingBox comment?
  270. \newif \ifepsfbbfound % success?
  271. \newif \ifepsfdraft % use draft mode?
  272. \newif \ifepsffileok % continue looking for the bounding box?
  273. \newif \ifepsfframe % frame the bounding box?
  274. \newif \ifepsfshow % show PostScript file, or just bounding box?
  275. \epsfshowtrue % default is to display PostScript file
  276. \newif \ifepsfshowfilename % show the file name if \epsfshowfalse specified?
  277. \newif \ifepsfverbose % report what you're making?
  278. \newdimen \epsfframemargin % margin between box and frame
  279. \newdimen \epsfframethickness % thickness of frame rules
  280. \newdimen \epsfrsize % vertical size before scaling
  281. \newdimen \epsftmp % register for arithmetic manipulation
  282. \newdimen \epsftsize % horizontal size before scaling
  283. \newdimen \epsfxsize % horizontal size after scaling
  284. \newdimen \epsfysize % vertical size after scaling
  285. \newdimen \pspoints % conversion factor
  286. %
  287. \pspoints = 1bp % Adobe points are `big'
  288. \epsfxsize = 0pt % default value, means `use natural size'
  289. \epsfysize = 0pt % ditto
  290. \epsfframemargin = 0pt % default value: frame box flush around picture
  291. \epsfframethickness = 0.4pt % TeX's default rule thickness
  292. %
  293. \def \epsfbox #1{%
  294. \global \def \epsfllx {72}%
  295. \global \def \epsflly {72}%
  296. \global \def \epsfurx {540}%
  297. \global \def \epsfury {720}%
  298. \def \lbracket {[}%
  299. \def \testit {#1}%
  300. \ifx \testit \lbracket
  301. \let \next = \epsfgetlitbb
  302. \else
  303. \let \next = \epsfnormal
  304. \fi
  305. \next{#1}%
  306. }%
  307. %
  308. % We use \epsfgetlitbb if the user specified an explicit bounding box,
  309. % and \epsfnormal otherwise. Because \epsfgetbb can be called
  310. % separately to retrieve the bounding box, we move the verbose
  311. % printing the bounding box extents and size on the terminal to
  312. % \epsfstatus. Therefore, when the user provided the bounding box,
  313. % \epsfgetbb will not be called, so we must call \epsfsetsize and
  314. % \epsfstatus ourselves.
  315. %
  316. \def \epsfgetlitbb #1#2 #3 #4 #5]#6{%
  317. \epsfgrab #2 #3 #4 #5 .\\%
  318. \epsfsetsize
  319. \epsfstatus{#6}%
  320. \epsfsetgraph{#6}%
  321. }%
  322. %
  323. \def \epsfnormal #1{%
  324. \epsfgetbb{#1}%
  325. \epsfsetgraph{#1}%
  326. }%
  327. %
  328. \def \epsfgetbb #1{%
  329. %
  330. % The first thing we need to do is to open the
  331. % PostScript file, if possible.
  332. %
  333. \openin\epsffilein=#1
  334. \immediate \write16 {(#1}%
  335. \ifeof \epsffilein
  336. \errmessage{Could not open file #1, ignoring it}%
  337. \else %process the file
  338. {% %start a group to contain catcode changes
  339. % Make all special characters, except space, to be of type
  340. % `other' so we process the file in almost verbatim mode
  341. % (TeXbook, p. 344).
  342. \chardef \other = 12%
  343. \def \do ##1{\catcode`##1=\other}%
  344. \dospecials
  345. \catcode `\ = 10%
  346. \epsffileoktrue %true while we are looping
  347. \epsfatendfalse %[02-Jul-1996]: add forgotten initialization
  348. \loop %reading lines from the EPS file
  349. \read \epsffilein to \epsffileline
  350. \ifeof \epsffilein %then no more input
  351. \epsffileokfalse %so set completion flag
  352. \else %otherwise process one line
  353. \expandafter \epsfaux \epsffileline :. \\%
  354. \fi
  355. \ifepsffileok
  356. \repeat
  357. \ifepsfbbfound
  358. \else
  359. \ifepsfverbose
  360. \immediate \write16 {No BoundingBox comment found in %
  361. file #1; using defaults}%
  362. \fi
  363. \fi
  364. }% %end catcode changes
  365. \closein\epsffilein
  366. \fi %end of file processing
  367. \epsfsetsize %compute size parameters
  368. \epsfstatus{#1}%
  369. \immediate \write16 {)}%
  370. }%
  371. %
  372. % Clipping control:
  373. \def \epsfclipon {\def \epsfclipstring { clip}}%
  374. \def \epsfclipoff {\def \epsfclipstring {\ifepsfdraft \space clip\fi}}%
  375. \epsfclipoff % default for dvips is OFF
  376. %
  377. % The special that is emitted by \epsfsetgraph comes from this macro.
  378. % It is defined separately to allow easy customization by other
  379. % packages that first \input epsf.tex, then redefine \epsfspecial.
  380. % This macro is invoked in the lower-left corner of a box of the
  381. % width and height determined from the arguments to \epsffile, or
  382. % from the %%BoundingBox in the EPS file itself.
  383. %
  384. % This version is for dvips:
  385. \def \epsfspecial #1{%
  386. \epsftmp=10\epsfxsize
  387. \divide \epsftmp by \pspoints
  388. \ifnum \epsfrsize = 0%
  389. \relax
  390. \special{PSfile=\ifepsfdraft psdraft.ps\else#1\fi\space
  391. llx=\epsfllx\space
  392. lly=\epsflly\space
  393. urx=\epsfurx\space
  394. ury=\epsfury\space
  395. rwi=\number\epsftmp\space
  396. \epsfclipstring
  397. }%
  398. \else
  399. \epsfrsize=10\epsfysize
  400. \divide \epsfrsize by \pspoints
  401. \special{PSfile=\ifepsfdraft psdraft.ps\else#1\fi\space
  402. llx=\epsfllx\space
  403. lly=\epsflly\space
  404. urx=\epsfurx\space
  405. ury=\epsfury\space
  406. rwi=\number\epsftmp\space
  407. rhi=\number\epsfrsize
  408. \epsfclipstring
  409. }%
  410. \fi
  411. }%
  412. %
  413. % \epsfframe macro adapted from the TeXbook, exercise 21.3, p. 223, 331.
  414. % but modified to set the box width to the natural width, rather
  415. % than the line width, and to include space for margins and rules
  416. \def \epsfframe #1%
  417. {%
  418. % method for detecting latex suggested by Robin Fairbairns, May 2005.
  419. \ifx \documentstyle \epsfundefined
  420. \relax
  421. \else
  422. % \leavevmode % so we can put this inside
  423. % a latex centered environment
  424. % The \leavevmode breaks under plain when this is inside a box,
  425. % because it forces the figure to be the entire \hsize. On the
  426. % other hand, we need the \leavevmode for it to work in LaTeX,
  427. % because the {center} environment works by adjusting TeX's
  428. % paragraph parameters.
  429. %
  430. % Compare the LaTeX sequence
  431. % \begin{center}
  432. % \epsfbox{tip.eps}q
  433. % \end{center}
  434. % (needs the \leavevmode to put the q right next to the image)
  435. %
  436. % with the plain TeX sequence:
  437. % \leftline{\vbox{\epsfbox{tip.eps}}q}
  438. % (had the q all the way over to the right, when \leavevmode was used)
  439. \fi
  440. %
  441. \setbox0 = \hbox{#1}%
  442. \dimen0 = \wd0 % natural width of argument
  443. \advance \dimen0 by 2\epsfframemargin % plus width of 2 margins
  444. \advance \dimen0 by 2\epsfframethickness % plus width of 2 rule lines
  445. \relax
  446. \hbox{%
  447. \vbox
  448. {%
  449. \hrule height \epsfframethickness depth 0pt
  450. \hbox to \dimen0
  451. {%
  452. \hss
  453. \vrule width \epsfframethickness
  454. \kern \epsfframemargin
  455. \vbox {\kern \epsfframemargin \box0 \kern \epsfframemargin }%
  456. \kern \epsfframemargin
  457. \vrule width \epsfframethickness
  458. \hss
  459. }% end hbox
  460. \hrule height 0pt depth \epsfframethickness
  461. }% end vbox
  462. }% end hbox
  463. \relax
  464. }%
  465. %
  466. \def \epsfsetgraph #1%
  467. {%
  468. %
  469. % Make the vbox and stick in a \special that the DVI driver can
  470. % parse. \vfil and \hfil are used to place the \special origin at
  471. % the lower-left corner of the vbox. \epsfspecial can be redefined
  472. % to produce alternate \special syntaxes.
  473. %
  474. \ifvmode \leavevmode \fi
  475. \relax
  476. \hbox{% so we can put this in \begin{center}...\end{center}
  477. \ifepsfframe \expandafter \epsfframe \fi
  478. {\vbox to\epsfysize
  479. {%
  480. \ifepsfshow
  481. % output \special{} at lower-left corner of figure box
  482. \vfil
  483. \hbox to \epsfxsize{\epsfspecial{#1}\hfil}%
  484. \else
  485. \vfil
  486. \hbox to\epsfxsize{%
  487. \hss
  488. \ifepsfshowfilename
  489. {%
  490. \epsfframemargin=3pt % local change of margin
  491. \epsfframe{{\tt #1}}%
  492. }%
  493. \fi
  494. \hss
  495. }%
  496. \vfil
  497. \fi
  498. }%
  499. }}%
  500. \relax
  501. %
  502. % Reset \epsfxsize and \epsfysize, as documented above.
  503. %
  504. \global \epsfxsize = 0pt
  505. \global \epsfysize = 0pt
  506. }%
  507. %
  508. % Now we have to calculate the scale and offset values to use.
  509. % First we compute the natural sizes.
  510. %
  511. \def \epsfsetsize
  512. {%
  513. \epsfrsize = \epsfury \pspoints
  514. \advance \epsfrsize by -\epsflly \pspoints
  515. \epsftsize = \epsfurx \pspoints
  516. \advance \epsftsize by -\epsfllx \pspoints
  517. %
  518. % If `epsfxsize' is 0, we default to the natural size of the picture.
  519. % Otherwise we scale the graph to be \epsfxsize wide.
  520. %
  521. \epsfxsize = \epsfsize{\epsftsize}{\epsfrsize}%
  522. \ifnum \epsfxsize = 0
  523. \ifnum \epsfysize = 0
  524. \epsfxsize = \epsftsize
  525. \epsfysize = \epsfrsize
  526. \epsfrsize = 0pt
  527. %
  528. % We have a sticky problem here: TeX doesn't do floating point arithmetic!
  529. % Our goal is to compute y = rx/t. The following loop does this reasonably
  530. % fast, with an error of at most about 16 sp (about 1/4000 pt).
  531. %
  532. \else
  533. \epsftmp = \epsftsize
  534. \divide \epsftmp by \epsfrsize
  535. \epsfxsize = \epsfysize
  536. \multiply \epsfxsize by \epsftmp
  537. \multiply \epsftmp by \epsfrsize
  538. \advance \epsftsize by -\epsftmp
  539. \epsftmp = \epsfysize
  540. \loop
  541. \advance \epsftsize by \epsftsize
  542. \divide \epsftmp by 2
  543. \ifnum \epsftmp > 0
  544. \ifnum \epsftsize < \epsfrsize
  545. \else
  546. \advance \epsftsize -\epsfrsize
  547. \advance \epsfxsize \epsftmp
  548. \fi
  549. \repeat
  550. \epsfrsize = 0pt
  551. \fi
  552. \else
  553. \ifnum \epsfysize = 0
  554. \epsftmp = \epsfrsize
  555. \divide \epsftmp by \epsftsize
  556. \epsfysize = \epsfxsize
  557. \multiply \epsfysize by \epsftmp
  558. \multiply \epsftmp by \epsftsize
  559. \advance \epsfrsize by -\epsftmp
  560. \epsftmp = \epsfxsize
  561. \loop
  562. \advance \epsfrsize by \epsfrsize
  563. \divide \epsftmp by 2
  564. \ifnum \epsftmp > 0
  565. \ifnum \epsfrsize < \epsftsize
  566. \else
  567. \advance \epsfrsize by -\epsftsize
  568. \advance \epsfysize by \epsftmp
  569. \fi
  570. \repeat
  571. \epsfrsize = 0pt
  572. \else
  573. \epsfrsize = \epsfysize
  574. \fi
  575. \fi
  576. }%
  577. %
  578. % Issue some status messages if the user requested them
  579. %
  580. \def \epsfstatus #1{% arg = filename
  581. \ifepsfverbose
  582. \immediate \write16 {#1: BoundingBox:
  583. llx = \epsfllx \space lly = \epsflly \space
  584. urx = \epsfurx \space ury = \epsfury \space}%
  585. \immediate \write16 {#1: scaled width = \the\epsfxsize \space
  586. scaled height = \the\epsfysize}%
  587. \fi
  588. }%
  589. %
  590. % We still need to define the tricky \epsfaux macro. This requires
  591. % a couple of magic constants for comparison purposes.
  592. %
  593. {\catcode`\%=12 \global \let \epsfpercent=%\global \def \epsfbblit {%BoundingBox}}%
  594. \global \def \epsfatend{(atend)}%
  595. %
  596. % So we're ready to check for `%BoundingBox:' and to grab the
  597. % values if they are found.
  598. %
  599. % If we find a line
  600. %
  601. % %%BoundingBox: (atend)
  602. %
  603. % then we ignore it, but set a flag to force parsing all of the
  604. % file, so the last %%BoundingBox parsed will be the one used. This
  605. % is necessary, because EPS files can themselves contain other EPS
  606. % files with their own %%BoundingBox comments.
  607. %
  608. % If we find a line
  609. %
  610. % %%BoundingBox: llx lly urx ury
  611. %
  612. % then we save the 4 values in \epsfllx, \epsflly, \epsfurx, \epsfury.
  613. % Then, if we have not previously parsed an (atend), we flag completion
  614. % and can stop reading the file. Otherwise, we must keep on reading
  615. % to end of file so that we find the values on the LAST %%BoundingBox.
  616. \long \def \epsfaux#1#2:#3\\%
  617. {%
  618. \def \testit {#2}% % save second character up to just before colon
  619. \ifx#1\epsfpercent % then first char is percent (quick test)
  620. \ifx \testit \epsfbblit % then (slow test) we have %%BoundingBox
  621. \epsfgrab #3 . . . \\%
  622. \ifx \epsfllx\epsfatend % then ignore %%BoundingBox: (atend)
  623. \global \epsfatendtrue
  624. \else % else found %%BoundingBox: llx lly urx ury
  625. \ifepsfatend % then keep parsing ALL %%BoundingBox lines
  626. \else % else stop after first one parsed
  627. \epsffileokfalse
  628. \fi
  629. \global \epsfbbfoundtrue
  630. \fi
  631. \fi
  632. \fi
  633. }%
  634. %
  635. % Here we grab the values and stuff them in the appropriate definitions.
  636. %
  637. \def \epsfempty {}%
  638. \def \epsfgrab #1 #2 #3 #4 #5\\{%
  639. \global \def \epsfllx {#1}\ifx \epsfllx\epsfempty
  640. \epsfgrab #2 #3 #4 #5 .\\\else
  641. \global \def \epsflly {#2}%
  642. \global \def \epsfurx {#3}\global \def \epsfury {#4}\fi
  643. }%
  644. %
  645. % We default the epsfsize macro.
  646. %
  647. \def \epsfsize #1#2{\epsfxsize}%
  648. %
  649. % Finally, another definition for compatibility with older macros.
  650. %
  651. \let \epsffile = \epsfbox
  652. \endinput