You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
5.2 KiB

25 years ago
  1. % EPSF.TEX macro file:
  2. % Written by Tomas Rokicki of Radical Eye Software, 29 Mar 1989.
  3. % Revised by Don Knuth, 3 Jan 1990.
  4. %
  5. % TeX macros to include an Encapsulated PostScript graphic.
  6. % Works by finding the bounding box comment,
  7. % calculating the correct scale values, and inserting a vbox
  8. % of the appropriate size at the current position in the TeX document.
  9. %
  10. % To use, simply say
  11. % \input epsf % somewhere early on in your TeX file
  12. % \epsfbox{filename.ps} % where you want to insert a vbox for a figure
  13. %
  14. % The effect will be to typeset the figure as a TeX box, at the
  15. % point of your \epsfbox command. By default, the graphic will have its
  16. % `natural' width (namely the width of its bounding box, as described
  17. % in filename.ps). The TeX box will have depth zero.
  18. % You can enlarge or reduce the figure by saying
  19. % \epsfxsize=<dimen> \epsfille{filename.ps}
  20. % instead. Then the width of the TeX box will be \epsfxsize, and its
  21. % height will be scaled proportionately.
  22. % (The \epsfbox macro resets \epsfxsize to zero after each use.)
  23. % If you want TeX to report the size of the figure (as a message
  24. % on your terminal when it processes each figure), say `\epsfverbosetrue'.
  25. %
  26. \newread\epsffilein % file to \read
  27. \newif\ifepsffileok % continue looking for the bounding box?
  28. \newif\ifepsfbbfound % success?
  29. \newif\ifepsfverbose % report what you're making?
  30. \newdimen\epsfxsize % horizontal size after scaling
  31. \newdimen\epsfysize % vertical size after scaling
  32. \newdimen\epsftsize % horizontal size before scaling
  33. \newdimen\epsfrsize % vertical size before scaling
  34. \newdimen\epsftmp % register for arithmetic manipulation
  35. \newdimen\pspoints % conversion factor
  36. \pspoints=1truebp % Adobe points are `big'
  37. \epsfxsize=0pt % Default value, means `use natural size'
  38. %
  39. \def\epsfbox#1{%
  40. %
  41. % The first thing we need to do is to open the
  42. % PostScript file, if possible.
  43. %
  44. \openin\epsffilein=#1
  45. \ifeof\epsffilein\errmessage{I couldn't open #1, will ignore it}\else
  46. %
  47. % Okay, we got it. Now we'll scan lines until we find one that doesn't
  48. % start with %. We're looking for the bounding box comment.
  49. %
  50. {\epsffileoktrue \chardef\other=12
  51. \def\do##1{\catcode`##1=\other}\dospecials \catcode`\ =10
  52. \loop
  53. \read\epsffilein to \epsffileline
  54. \ifeof\epsffilein\epsffileokfalse\else
  55. %
  56. % We check to see if the first character is a % sign;
  57. % if not, we stop reading (unless the line was entirely blank);
  58. % if so, we look further and stop only if the line begins with
  59. % `%%BoundingBox: '.
  60. %
  61. \expandafter\epsfaux\epsffileline. \\%
  62. \fi
  63. \ifepsffileok\repeat
  64. \ifepsfbbfound\else
  65. \ifepsfverbose\message{No bounding box comment in #1; using defaults}\fi
  66. \global\def\epsfllx{72}%
  67. \global\def\epsflly{72}%
  68. \global\def\epsfurx{540}%
  69. \global\def\epsfury{720}\fi
  70. }\closein\epsffilein
  71. %
  72. % Now we have to calculate the scale and offset values to use.
  73. % First we compute the natural sizes.
  74. %
  75. \epsfrsize=\epsfury\pspoints
  76. \advance\epsfrsize by-\epsflly\pspoints
  77. \epsftsize=\epsfurx\pspoints
  78. \advance\epsftsize by-\epsfllx\pspoints
  79. %
  80. % If `epsfxsize' is 0, we default to the natural size of the picture.
  81. % Otherwise we scale the graph to be \epsfxsize wide.
  82. %
  83. \ifnum\epsfxsize=0 \epsfxsize=\epsftsize \epsfysize=\epsfrsize
  84. %
  85. % We have a sticky problem here: TeX doesn't do floating point arithmetic!
  86. % Our goal is to compute y = rx/t. The following loop does this reasonably
  87. % fast, with an error of at most about 16 sp (about 1/4000 pt).
  88. %
  89. \else\epsftmp=\epsfrsize \divide\epsftmp\epsftsize
  90. \epsfysize=\epsfxsize \multiply\epsfysize\epsftmp
  91. \multiply\epsftmp\epsftsize \advance\epsfrsize-\epsftmp
  92. \epsftmp=\epsfxsize
  93. \loop \advance\epsfrsize\epsfrsize \divide\epsftmp 2
  94. \ifnum\epsftmp>0
  95. \ifnum\epsfrsize<\epsftsize\else
  96. \advance\epsfrsize-\epsftsize \advance\epsfysize\epsftmp \fi
  97. \repeat
  98. \fi
  99. %
  100. % Finally, we make the vbox and stick in a \special that dvips can parse.
  101. %
  102. \ifepsfverbose\message{#1: width=\the\epsfxsize, height=\the\epsfysize}\fi
  103. \epsftmp=10\epsfxsize \divide\epsftmp\pspoints
  104. \vbox to\epsfysize{\vfil\hbox to\epsfxsize{%
  105. \special{psfile=#1 llx=\epsfllx\space lly=\epsflly\space
  106. urx=\epsfurx\space ury=\epsfury\space rwi=\number\epsftmp}%
  107. \hfil}}%
  108. \fi\epsfxsize=0pt}%
  109. %
  110. % We still need to define the tricky \epsfaux macro. This requires
  111. % a couple of magic constants for comparison purposes.
  112. %
  113. {\catcode`\%=12 \global\let\epsfpercent=%\global\def\epsfbblit{%BoundingBox:}}%
  114. %
  115. % So we're ready to check for `%BoundingBox:' and to grab the
  116. % values if they are found.
  117. %
  118. \long\def\epsfaux#1#2 #3\\{\ifx#1\epsfpercent
  119. \def\testit{#2}\ifx\testit\epsfbblit
  120. \epsfgrab #3 . . . \\%
  121. \epsffileokfalse
  122. \global\epsfbbfoundtrue
  123. \fi\else\ifx#1\par\else\epsffileokfalse\fi\fi}%
  124. %
  125. % Here we grab the values and stuff them in the appropriate definitions.
  126. %
  127. \def\epsfgrab#1 #2 #3 #4 #5\\{\global\def\epsfllx{#1}\global\def\epsflly{#2}%
  128. \global\def\epsfurx{#3}\global\def\epsfury{#4}}%
  129. %
  130. % Finally, another definition for compatibility with older macros.
  131. %
  132. \let\epsffile=\epsfbox