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