| 1 |
% FIGFLOW: plain TEX macro by Ian Hutchinson, 21 Oct 95. |
| 2 |
% Copyright 1995 Ian Hutchinson. |
| 3 |
% You may freely use, modify, and/or distribute this file, without limitation. |
| 4 |
% Make text flow round figure. |
| 5 |
% Usage: \figflow{<width>}{<height>}{<[Figure+][Caption]>} |
| 6 |
% at start of new paragraph. Figure top starts at insert. |
| 7 |
% #1 figure width dimen. If negative, fig on right, else left. |
| 8 |
% #2 figure height (including caption) dimen. (E.g.: 4 truein) |
| 9 |
% #3 \special for figure if desired, then \vfill caption. (Both optional). |
| 10 |
% Example: figflow{4 truein}{5 truein}{\epsfbox{figure.ps}\vfill Figure 1.} |
| 11 |
% User is responsible for the figure fitting within the space defined. |
| 12 |
% If figure won't fit on page, it is moved over the page break. |
| 13 |
% If a new figflow starts before the old one is finished, a message is given |
| 14 |
% and the second figure is skipped. Fix manually. |
| 15 |
% Does not work for Latex. |
| 16 |
|
| 17 |
\newdimen\pageremains\newdimen\pdepth |
| 18 |
\newdimen\figwidth |
| 19 |
\newdimen\figheight |
| 20 |
\newcount\figlines |
| 21 |
\newcount\flevel |
| 22 |
|
| 23 |
\def\figflow#1#2#3{ |
| 24 |
\ifnum\flevel>0 |
| 25 |
\message{******Figure collision. Ignoring second figure.******} |
| 26 |
\else |
| 27 |
\figwidth=#1 |
| 28 |
\figheight=#2 |
| 29 |
\def\contents{#3} |
| 30 |
% Put figure contents in an appropriate box. |
| 31 |
\def\figure{\let\temp=\par \let\par=\plainpar |
| 32 |
\line{\overfullrule=0pt% Avoid black box. |
| 33 |
\ifdim \figwidth<0pt \hsize=-\figwidth \hss\else \hsize=\figwidth\fi |
| 34 |
\advance \hsize by -10pt% Give a little extra hspace. |
| 35 |
\vbox to \figheight{\vfil\noindent\contents} |
| 36 |
\ifdim \figwidth>0pt \hss\fi |
| 37 |
} \vskip-\figheight |
| 38 |
\let\par=\temp% |
| 39 |
} |
| 40 |
\advance\figheight by \baselineskip |
| 41 |
\divide\figheight by \baselineskip% convert height to lines. |
| 42 |
\figlines=\figheight \multiply\figheight by \baselineskip |
| 43 |
\begingroup\overfullrule=0pt% Turn off black box outside fig |
| 44 |
\tolerance=1000% Allow more spaced out lines. |
| 45 |
\flevel=1 |
| 46 |
% Store \par |
| 47 |
\let\plainpar=\par |
| 48 |
% Define new \par to process figures each paragraph. |
| 49 |
\def\par{ |
| 50 |
\ifnum\flevel=1 |
| 51 |
% We are starting a new figure. Set to look for enough room. |
| 52 |
\plainpar |
| 53 |
% End the previous paragraph. |
| 54 |
\pageremains=\pagegoal \advance\pageremains by -\pagetotal |
| 55 |
\ifdim\pageremains<\figheight \message{Moving figure...}%keep looking |
| 56 |
\else |
| 57 |
% Found the starting place. Store prevdepth. Remove glue. Place the figure. |
| 58 |
\pdepth=\prevdepth |
| 59 |
\nointerlineskip |
| 60 |
\figure |
| 61 |
\hangindent \figwidth \hangafter -\figlines \hfuzz 5 pt |
| 62 |
\flevel=2 |
| 63 |
\prevgraf=0 |
| 64 |
\figheight=\baselineskip% Removed parskip adjust. |
| 65 |
\fi |
| 66 |
\else |
| 67 |
\ifnum\flevel=2%level 2, making the figure. |
| 68 |
\ifdim\figheight<\parskip |
| 69 |
\advance\figlines -1 \advance\hangafter 1 |
| 70 |
\advance\figheight\baselineskip |
| 71 |
\else |
| 72 |
\advance\figheight -\parskip%\message{else \the\figheight} |
| 73 |
\fi |
| 74 |
\hangcarrypar\relax% I don't know why, but this is needed. |
| 75 |
\fi |
| 76 |
\fi |
| 77 |
} |
| 78 |
\par |
| 79 |
\vskip-\pdepth%Restore the prevdepth from the previous paragraph. |
| 80 |
\fi |
| 81 |
} |
| 82 |
% Macros. |
| 83 |
\def\endflow{\global\let\par=\plainpar\endgroup}% terminate main group. |
| 84 |
\def\hangcarrypar{% Carry the hangindent to next par. |
| 85 |
\edef\next{\hangafter=\the\hangafter\hangindent=\the\hangindent} |
| 86 |
\plainpar\next |
| 87 |
\edef\next{\prevgraf=\the\prevgraf} |
| 88 |
\ifnum\prevgraf>0 |
| 89 |
\ifnum\prevgraf>\figlines \endflow \flevel=0 |
| 90 |
\else |
| 91 |
\message{FIGFLOW: line \the\prevgraf, of \the\figlines.} |
| 92 |
\leavevmode% Sets prevgraf to 0. So reset it using next. |
| 93 |
\next |
| 94 |
\fi |
| 95 |
\fi |
| 96 |
} |