Commit | Line | Data |
---|---|---|
3e5dbc70 BA |
1 | % |
2 | % W R A P F I G . S T Y | |
3 | % | |
4 | % Copyright (C) 1991,1992 by Donald Arseneau | |
5 | % These macros may be freely transmitted, reproduced, or modified for | |
6 | % non-commercial purposes provided that this notice is left intact. | |
7 | % | |
8 | % Environment "wrapfigure" to manually place a figure at the side | |
9 | % of the page and wrap text around it. | |
10 | % | |
11 | % \begin{wrapfigure}[36]{r}{3in} <figure> <\caption> etc. \end{wrapfigure} | |
12 | % -- - --- | |
13 | % [number of narrow lines] {left or right} {width of figure} | |
14 | % | |
15 | % Usage: | |
16 | % This is a different type of *non-floating* figure environment for LaTeX. | |
17 | % A figure of the specified width appears on the left or right (as specified) | |
18 | % of the page. LaTeX will try to wrap text around the figure leaving a gap of | |
19 | % \columsep by producing a number of short lines of text. LaTeX calculates | |
20 | % the number of short lines needed based on the height of the figure plus | |
21 | % the length \intextsep. You can override this guess by giving the optional | |
22 | % argument specifying the number of shortened lines (counting each displayed | |
23 | % equation as 3 lines). Cautions: | |
24 | % o Wrapfigure should not be used inside another environment (e.g., list) | |
25 | % o It does work in two-column format, but that would be silly. | |
26 | % o Since it does not float, it may be out of sequence with floated figures. | |
27 | % o The automatic rules (lines) that may be placed above or below floats | |
28 | % are ignored here. You must insert the rules manually. | |
29 | % | |
30 | % Placement: | |
31 | % LaTeX will not move a wrapfigure to the best place, so it is up to YOU | |
32 | % to position it well. Any changes to the document can ruin your careful | |
33 | % positioning so wrapfigures should be positioned just before printing a | |
34 | % final copy. Here are the rules for good placement: | |
35 | % o The environment should be placed so as to not run over a page boundary. | |
36 | % o Only ordinary text should have to flow past the figure; no section | |
37 | % titles please. Equations are acceptable if they fit. | |
38 | % o It is convenient to give \begin{wrapfigure} just after a paragraph has | |
39 | % ended. But if you want to start in the middle of a paragraph, you must | |
40 | % put the environment between two words where there is a natural linebreak | |
41 | % (like "must" and "put" above). | |
42 | % | |
43 | \newcount \WF@wrappedlines % used globally | |
44 | ||
45 | \def\wrapfigure{\@ifnextchar[{\WF@raptfig}{\WF@raptfig[-1]}} | |
46 | ||
47 | \def\WF@raptfig[#1]#2#3{\relax\ifx\par\@@par\else\typeout | |
48 | {WARNING: wrapfigure used inside another environment.}\fi | |
49 | \ifnum#10>\z@ % 10*num. lines specified (0 if blank) | |
50 | \global\WF@wrappedlines#1\global\advance\WF@wrappedlines\@ne | |
51 | \else % calc num. lines later | |
52 | \global\WF@wrappedlines\z@ | |
53 | \fi | |
54 | \ifvmode % Between paragraphs: Start new one. Text will be indented... | |
55 | \noindent \aftergroup\indent % after the \endgroup of \end{wrapfigure} | |
56 | \else % In paragraph: End this one so it doesn't look ended; start new one. | |
57 | {\unskip\parfillskip\z@skip\par\penalty\interlinepenalty | |
58 | \parskip\z@skip\noindent}% text will start with no indentation | |
59 | \fi \hbox to \z@\bgroup % llap or rlap depending on {l} or {r} parameter. | |
60 | \@tempdimb\hsize \advance\@tempdimb-#3 \advance\@tempdimb-\columnsep | |
61 | \if r#2\relax% fig on right | |
62 | \@tempdima\z@ % no hanging indentation | |
63 | \kern-#3\kern\hsize % position to the right of the text, past gutter | |
64 | \def\@tempa{\hss}% figure overlaps space to the right | |
65 | \else % fig on left | |
66 | \@tempdima#3\advance\@tempdima\columnsep % indent past figure | |
67 | \hss % figure overlaps space to the left | |
68 | \def\@tempa{\kern\columnsep}% position to left of the gap | |
69 | \fi | |
70 | \xdef\WF@wrapil{\the\@tempdima \the\@tempdimb}% indentation and length | |
71 | \setbox\z@\vtop\bgroup \hsize=#3\relax \hrule \@height\z@ | |
72 | \@parboxrestore | |
73 | \def\@captype{figure}% set up figure | |
74 | } | |
75 | ||
76 | \def\endwrapfigure{\leftline{}\egroup % ensure \hsize wide | |
77 | \ifnum \WF@wrappedlines=\z@ % measure figure box to count lines | |
78 | \@tempdima\dp\z@ \advance\@tempdima\intextsep | |
79 | \divide\@tempdima\baselineskip | |
80 | \global\WF@wrappedlines\@tempdima \global\advance\WF@wrappedlines\tw@ | |
81 | \fi \dp\z@\z@ \box\z@ % smash the vtop | |
82 | \@tempa\egroup \aftergroup\WF@startwrapping \global\@ignoretrue} | |
83 | ||
84 | \def\WF@startwrapping{\everypar{\WF@setwrapping}\WF@setwrapping | |
85 | \def\WF@savedclubp{\the\clubpenalty}\clubpenalty\@M % prevent bad pagebreak | |
86 | \def\WF@restoretol{\tolerance\the\tolerance}\tolerance\@M | |
87 | \def\par{\@@par \clubpenalty\WF@savedclubp % will wrap more than one | |
88 | \global\advance\WF@wrappedlines-\prevgraf % paragraph if necessary | |
89 | \ifnum\WF@wrappedlines<\tw@ \everypar{}\let\par\@@par\WF@restoretol\fi | |
90 | }} | |
91 | % Create \parshape command | |
92 | \def\WF@setwrapping{\@tempcnta\@ne \let\@tempb\relax \def\@tempc{}% | |
93 | \@whilenum \@tempcnta<\WF@wrappedlines\do{% repeated indentation, length | |
94 | \edef\@tempc{\@tempc\@tempb}\advance\@tempcnta\@ne | |
95 | }\let\@tempb\WF@wrapil \parshape \WF@wrappedlines \@tempc \z@ \hsize} | |
96 | % | |
97 | % 1992: change boxing so there is no height. | |
98 | % interim version: added \@parboxrestore | |
99 | % | |
100 | % Send problem reports to asnd@Reg.TRIUMF.CA | |
101 | % | |
102 | % test integrity: | |
103 | % brackets: round, square, curly, angle: () [] {} <> | |
104 | % backslash, slash, vertical, at, dollar, and: \ / | @ $ & | |
105 | % hat, grave, acute (apostrophe), quote, tilde, under: ^ ` ' " ~ _ | |
106 | ||
107 |