wrapfig.sty 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. % W R A P F I G . S T Y ver 3.6 (Jan 31, 2003)
  2. %
  3. % Copyright (C) 1991-2003 by Donald Arseneau <asnd@triumf.ca>
  4. % This software is released under the terms of the LaTeX Project
  5. % public license.
  6. %
  7. % Environments "wrapfigure" and "wraptable" place a figure or table
  8. % at the side of the page and wrap text around it.
  9. %
  10. % \begin{wrapfigure}[12]{r}[34pt]{5cm} <figure> \end{wrapfigure}
  11. % -- - ---- ---
  12. % [number of narrow lines] {placement} [overhang] {width of figure}
  13. %
  14. % Placement is one of r, l, i, o, R, L, I, O, for right, left,
  15. % inside, outside, (here / FLOAT).
  16. % The figure sticks into the margin by `overhang', if given, or by the
  17. % length \wrapoverhang, which is normally zero.
  18. % The number of wrapped text lines is normally calculated from the height
  19. % of the figure, but may be specified manually ("12" above).
  20. %
  21. % Environments similar to "wrapfigure" and "wraptable" may be easily added,
  22. % or invoked by "\begin{wrapfloat}{float_name}"
  23. %
  24. % More detailed instructions are given below, following the definitions.
  25. % Please direct any problem reports to asnd@triumf.ca
  26. %%%%% ----- Begin definitions ----- %%%%%
  27. \@ifundefined{c@WF@wrappedlines}{}{\endinput}
  28. \newdimen\wrapoverhang \wrapoverhang\z@
  29. \newdimen\WF@size
  30. \newcount\c@WF@wrappedlines % used globally
  31. \newbox\WF@box
  32. \newtoks\WF@everypar
  33. \newif\ifWF@float
  34. \let\@@parshape\parshape
  35. \let\WF@@everypar\everypar
  36. \def\wrapfloat#1{\def\@captype{#1}\@ifnextchar[\WF@wr{\WF@wr[]}}
  37. \def\wrapfigure{\wrapfloat{figure}}
  38. \def\wraptable{\wrapfloat{table}}
  39. \def\WF@wr[#1]#2{% first two args: #1=num lines, #2=placement
  40. \xdef\WF@wfname{wrap\@captype\space}%
  41. \ifvoid\WF@box\else \WFclear \WF@collision \fi
  42. \xdef\WF@place{\string`\@car#2r\@nil}%
  43. \ifnum\lccode\WF@place=\WF@place \global\WF@floatfalse
  44. \else \global\WF@floattrue \fi
  45. \ifx\parshape\WF@fudgeparshape \ifWF@float\else\WF@collision\fi \else
  46. \ifx\par\@@par \ifnum\@@parshape>\z@\WF@conflict\fi \else \WF@conflict\fi
  47. \fi \gdef\WF@wli{#1}%
  48. \@ifnextchar[\WF@rapt{\WF@rapt[\wrapoverhang]}}
  49. \def\WF@rapt[#1]#2{% final two args: #1 = overhang, #2 = width,
  50. \gdef\WF@ovh{#1}% hold overhang for later, when \width is known
  51. \global\setbox\WF@box\vtop\bgroup \setlength\hsize{#2}%
  52. \ifdim\hsize>\z@ \@parboxrestore \else
  53. \setbox\z@\hbox\bgroup \let\wf@@caption\caption \let\caption\wf@caption
  54. \ignorespaces \fi}
  55. \def\wf@caption{\relax
  56. \ifdim\hsize>\z@ \let\caption\wf@@caption \else
  57. \unskip \egroup \hsize\wd\z@ \@parboxrestore \box\z@ \fi \caption}
  58. \def\endwrapfloat{%
  59. \ifdim\hsize>\z@ \par\hrule\@width\hsize\@height\z@ % force width
  60. \else \unskip \egroup \box\z@ \fi % or end hbox
  61. \egroup % end the \vtop; width is known so now is "later"
  62. \WF@floatstyhook % support float.sty
  63. \def\width{\wd\WF@box}\setlength\wrapoverhang{\WF@ovh}%
  64. \xdef\WF@ovh{\the\wrapoverhang}% save until wrapping
  65. \ifdim\ht\WF@box>\topskip \ht\WF@box\z@ \fi % too much height, set flag.
  66. \ifdim\ht\WF@box<.5\p@ % too tall (starts with \vbox) or too short
  67. \global\setbox\WF@box\vtop{\vskip-1.4ex\unvbox\WF@box}\fi
  68. \global\WF@size\dp\WF@box % box is guaranteed to have little height.
  69. \global\advance\WF@size1.5\baselineskip \global\advance\WF@size\tw@\intextsep
  70. \aftergroup\WF@startfloating % even when not really floating!
  71. \ifWF@float\else \ifhmode
  72. {\unskip \parfillskip\z@skip \par \vskip-\parskip}\aftergroup\noindent
  73. \fi\fi \global\@ignoretrue}
  74. \let\endwrapfigure\endwrapfloat
  75. \let\endwraptable\endwrapfloat
  76. % Subvert \everypar to float fig and do wrapping. Also for non-float.
  77. \def\WF@startfloating{%
  78. \WF@everypar\expandafter{\the\everypar}\let\everypar\WF@everypar
  79. \WF@@everypar{\ifvoid\WF@box\else\WF@floathand\fi \the\everypar
  80. \WF@wraphand
  81. }}
  82. \def\WF@floathand{%
  83. \ifx\parshape\WF@fudgeparshape \WF@fltmes\else
  84. \ifx\par\@@par\ifnum\@@parshape=\z@\ifdim\hangindent=\z@
  85. \setbox\z@\lastbox \begingroup
  86. \@@par \WF@@everypar{}\WF@putfigmaybe
  87. \endgroup % start wrapping
  88. \ifvoid\z@\else\box\z@\fi % replace indentation
  89. \else\WF@fltmes\fi\else\WF@fltmes\fi\else\WF@fltmes\fi\fi}
  90. % Put fig here if it fits or if it can't float
  91. \def\WF@putfigmaybe{%
  92. \ifinner
  93. \vskip-\parskip \global\WF@floatfalse
  94. \let\pagetotal\maxdimen % kludge flag for "not top of page"
  95. \else % outer page
  96. \@tempdima\pagedepth % save page depth
  97. {\advance\parskip\@tempdima\vskip-\parskip}% back up to baseline
  98. \penalty\interlinepenalty % update pg. parameters
  99. \@tempdimb\pagegoal \advance\@tempdimb-\pagetotal % room left on page
  100. \ifdim\@tempdimb<\z@ % \WF@info{Page overfull already;}%
  101. \global\WF@floatfalse
  102. \ifdim-\@tempdimb>\pageshrink \else \pagebreak \fi
  103. \else
  104. \ifdim\WF@size>\@tempdimb
  105. % \WF@info{Size \the\WF@size\space does not fit in \the\@tempdimb}%
  106. \ifWF@float \dimen@.5\baselineskip \else \dimen@ 2\baselineskip\fi
  107. \ifdim\pagestretch>\dimen@ \dimen@\pagestretch \fi
  108. \ifdim\pagefilstretch>\z@ \dimen@\@tempdimb \fi
  109. \ifdim\pagefillstretch>\z@ \dimen@\@tempdimb \fi
  110. \advance\dimen@.5\baselineskip
  111. \ifdim\dimen@>\@tempdimb % \WF@info{Page nearly full; can stretch}%
  112. \global\WF@floatfalse \pagebreak
  113. \fi
  114. \else % \WF@info{Fits in \the\@tempdimb;}%
  115. \global\WF@floatfalse
  116. \fi\fi
  117. \vskip\@tempdima\relax % (return erased page depth)
  118. \fi
  119. \noindent
  120. \ifWF@float
  121. \WF@fltmes
  122. \else % putting here;
  123. \WF@info{Put \WF@wfname here:}%
  124. {\ifodd\if@twoside\c@page\else\@ne\fi % assign l/r to i/o placement
  125. \lccode`i`l\lccode`o`r\else \lccode`i`r\lccode`o`l\fi
  126. \xdef\WF@place{\the\lccode\lccode\WF@place}}% twice to get only l or r
  127. \hbox to\z@{% llap or rlap depending on {l} or {r}; calc effective width
  128. \@tempdima\wd\WF@box \@tempdimb\WF@ovh
  129. \advance\@tempdima-\@tempdimb \advance\@tempdima\columnsep
  130. \@tempdimb\hsize \advance\@tempdimb-\@tempdima
  131. \xdef\WF@adjlw{\the\@tempdima}%
  132. \ifnum `l=\WF@place % fig on left
  133. \hss % figure overlaps space to the left
  134. \def\@tempa{\kern\columnsep}% position to left of the gap
  135. \else % fig on right
  136. \@tempdima\z@ % no left indentation
  137. \kern\@tempdimb \kern\columnsep
  138. \def\@tempa{\hss}% figure overlaps space to the right
  139. \fi
  140. \ifdim\@tempdimb<\hsize
  141. \xdef\WF@wrapil{\the\@tempdima \the\@tempdimb}% indentation and length
  142. \xdef\WF@adjtlm{\the\@tempdima}%
  143. \else
  144. \xdef\WF@wrapil{\z@ \the\hsize}%
  145. \xdef\WF@adjlw{\z@}\xdef\WF@adjtlm{\z@}%
  146. \fi
  147. \ifdim\pagetotal=\z@ % \WF@info{Put \WF@wfname at top of p.\thepage}%
  148. \global\advance\WF@size-\intextsep
  149. \else % \WF@info{Putting \WF@wfname in middle of page}%
  150. \setbox\WF@box\hbox{\lower\intextsep\box\WF@box}%
  151. \fi \dp\WF@box\z@ \box\WF@box \@tempa
  152. }% end \hbox to 0pt
  153. \aftergroup\WF@startwrapping % after the \endgroup which immediately follows
  154. \fi}
  155. \def\WF@startwrapping{%
  156. \ifx\WF@wli\@empty
  157. {\advance\WF@size1.1\baselineskip
  158. \divide\WF@size\baselineskip \global\c@WF@wrappedlines\WF@size}%
  159. \else
  160. \setcounter{WF@wrappedlines}{\WF@wli}\global\advance\c@WF@wrappedlines\@ne
  161. \fi
  162. \ifnum\c@WF@wrappedlines>\@ne
  163. \let\parshape\WF@fudgeparshape \let\WF@pspars\@empty \let\WF@@par\par
  164. \def\@setpar##1{\def\WF@@par{##1}}\def\par{\@par}\let\@par\WF@mypar
  165. \xdef\WF@restoretol{\tolerance\the\tolerance}\tolerance9999
  166. \advance\linewidth-\WF@adjlw \advance\@totalleftmargin\WF@adjtlm
  167. \fi}
  168. \def\WF@wraphand{%
  169. \ifnum\c@WF@wrappedlines<\tw@ \WF@finale
  170. \else \begingroup % Create \parshape command:
  171. \@tempcnta\@ne \let\WF@wrapil\relax \gdef\WF@ps{}%
  172. \@whilenum \@tempcnta<\c@WF@wrappedlines\do{% repeated indentation, length
  173. \xdef\WF@ps{\WF@ps\WF@wrapil}\advance\@tempcnta\@ne
  174. }\endgroup
  175. \ifx\WF@pspars\@empty
  176. \@@parshape\c@WF@wrappedlines \WF@ps \WF@noil
  177. \else % use external `parshape' values to modify my parshape
  178. \WF@modps
  179. \fi\fi}
  180. \def\WF@mypar{\relax
  181. \WF@@par % what the rest of LaTeX expects \par to be (usually \@@par)
  182. \ifnum\@@parshape=\z@ \let\WF@pspars\@empty \fi % reset `parshape'
  183. \global\advance\c@WF@wrappedlines-\prevgraf \prevgraf\z@
  184. \ifnum\c@WF@wrappedlines<\tw@ \WF@finale \fi}
  185. \def\WF@modps{\begingroup
  186. \afterassignment\@tempdimb \@tempdima\WF@pspars % a=ind, b=wid
  187. \advance\@tempdima-\WF@adjtlm \advance\@tempdimb\WF@adjlw
  188. % \afterassignment\dimen@\advance\@tempdima\WF@wrapil
  189. % \advance\@tempdimb\dimen@ \advance\@tempdimb-\hsize
  190. \let\WF@wrapil\WF@pspars%{\the\@tempdima \the\@tempdimb}%
  191. \edef\@tempb{\@@parshape\c@WF@wrappedlines \WF@ps \the\@tempdima \the\@tempdimb}%
  192. \expandafter\endgroup\@tempb}
  193. \let\@@setpar\@setpar
  194. \def\WF@noil{\z@ \hsize}
  195. \let\WF@pspars\@empty
  196. \def\WF@fudgeparshape{\relax \ifnum\c@WF@wrappedlines<\tw@ \WF@finale
  197. \else \afterassignment\WF@fudgeparshapee \fam \fi}
  198. \def\WF@fudgeparshapee{\ifnum\fam=\@ne \expandafter \WF@parshapeee \else
  199. \WF@conflict \@@parshape\fam \fi}
  200. \def\WF@parshapeee#1#2{\begingroup\delimitershortfall#1%
  201. \nulldelimiterspace#2%\advance\nulldelimiterspace\WF@adjlw
  202. \edef\@tempa{\def\noexpand\WF@pspars{%
  203. \the\delimitershortfall \the\nulldelimiterspace}}%
  204. \expandafter\endgroup\@tempa \WF@wraphand}
  205. \def\WF@finale{\ifx\parshape\WF@fudgeparshape
  206. \WF@restoretol \let\@setpar\@@setpar \let\par\WF@@par
  207. \advance\linewidth\WF@adjlw \advance\@totalleftmargin-\WF@adjtlm
  208. \WF@info{Finish wrapping text}%
  209. \ifx\par\@@par \def\@par{\let\par\@@par\par}\else \let\@par\WF@@par \fi
  210. \let\parshape\@@parshape
  211. \parshape\ifx\WF@pspars\@empty \z@ \else \@ne \WF@pspars\fi \fi
  212. \ifvoid\WF@box \ifx\everypar\WF@everypar
  213. \let\everypar\WF@@everypar \everypar\expandafter{\the\WF@everypar}%
  214. \fi\fi}
  215. \newcommand{\WFclear}{\par
  216. \ifvoid\WF@box\else \vskip\bigskipamount \box\WF@box
  217. \let\everypar\WF@@everypar \everypar\expandafter{\the\WF@everypar}%
  218. \fi \global\c@WF@wrappedlines\z@ \WF@finale}
  219. \begingroup
  220. \toks0={\let\everypar\WF@@everypar \everypar\expandafter{\the\WF@everypar}%
  221. \let\parshape\@@parshape \let\@setpar\@@setpar }
  222. \toks1=\expandafter{\@arrayparboxrestore}
  223. \toks2=\expandafter{\clearpage}
  224. \edef\@tempa{\def\noexpand\@arrayparboxrestore{\the\toks0 \the\toks1}%
  225. \def\noexpand\clearpage{\noexpand\protect\noexpand\WFclear \the\toks2}}
  226. \expandafter
  227. \endgroup\@tempa
  228. \@ifundefined{@capwidth}{\let\@capwidth\hsize}{}% Pamper RevTeX's Stupidity
  229. \def\WF@conflict{\WF@warning
  230. {\WF@wfname used inside a conflicting environment}}
  231. \def\WF@collision{\WF@warning{Collision between wrapping environments}}
  232. \def\WF@fltmes{\ifWF@float \WF@info{\WF@wfname floats}%
  233. \else \WF@warning{Stationary \WF@wfname forced to float}\fi}
  234. \let\WF@warning\@warning
  235. \let\WF@info\@gobble
  236. % Support float.sty: float styles and \newfloat. Make \newfloat{foo}
  237. % define the `wrapfoo' environment. Support \newfloat from memoir.cls
  238. % and \newfloatlist from ccaption.sty.
  239. %
  240. \let\WF@floatstyhook\relax
  241. \@ifundefined{newfloat}{}{% There is a \newfloat command
  242. %
  243. \@ifundefined{restylefloat}{
  244. % \newfloat comes from somewhere besides float.sty
  245. \@ifclassloaded{memoir}{
  246. \toks@=\expandafter\expandafter\expandafter
  247. {\csname\string\newfloat\endcsname [{#1}]{#2}{#3}{#4}%
  248. \newenvironment{wrap#2}{\wrapfloat{#2}}{\endwrapfloat}%
  249. }
  250. \edef\@tempa{\def\expandafter\noexpand\csname\string\newfloat\endcsname
  251. [##1]##2##3##4{\the\toks@}}
  252. \@tempa
  253. }% end memoir support
  254. {}% Other origins of \newfloat here??
  255. }{
  256. % float.sty handler. Ooops: Two versions for different versions
  257. % Changing \float@restyle (or \restylefloat) changes \newfloat too.
  258. \@ifundefined{float@restyle}{% older float.sty
  259. \toks@=\expandafter{\restylefloat{#1}% (env may or may not be defined)
  260. \@namedef{wrap#1}{\def\@captype{#1}\@nameuse{fst@#1}%
  261. \def\WF@floatstyhook{\let\@currbox\WF@box \columnwidth\wd\WF@box
  262. \global\setbox\WF@box\float@makebox}%
  263. \@ifnextchar[\WF@wr{\WF@wr[]}}%
  264. \expandafter\let\csname endwrap#1\endcsname \endwrapfigure
  265. }\edef\@tempa{\def\noexpand\restylefloat##1{\the\toks@}}
  266. }{% newer float.sty: use \float@restyle, and \float@makebox takes width arg
  267. \toks@=\expandafter{\float@restyle{#1}% (env may or may not be defined)
  268. \@namedef{wrap#1}{\def\@captype{#1}\@nameuse{fst@#1}%
  269. \def\WF@floatstyhook{\let\@currbox\WF@box
  270. \global\setbox\WF@box\float@makebox{\wd\WF@box}}%
  271. \@ifnextchar[\WF@wr{\WF@wr[]}}%
  272. \expandafter\let\csname endwrap#1\endcsname \endwrapfigure
  273. }\edef\@tempa{\def\noexpand\float@restyle##1{\the\toks@}}
  274. }
  275. \@tempa % perform redefinitions
  276. %
  277. }% End float.sty handler
  278. }% End redefinitions of \newfloat
  279. % Support ccaption.sty
  280. \@ifundefined{\string\newfloatlist}{}{
  281. \toks@=\expandafter\expandafter\expandafter
  282. {\csname\string\newfloatlist\endcsname [{#1}]{#2}{#3}{#4}{#5}%
  283. \@namedef{wrap#2}{\wrapfloat{#2}}%
  284. \expandafter\let\csname endwrap#2\endcsname \endwrapfloat
  285. }
  286. \edef\@tempa{\def\expandafter\noexpand\csname\string\newfloatlist\endcsname
  287. [##1]##2##3##4##5{\the\toks@}}
  288. \@tempa
  289. }
  290. % Process package options.
  291. \@ifundefined{DeclareOption}{\endinput}{}
  292. \def\WF@warning{\PackageWarning{wrapfig}}
  293. \ProvidesPackage{wrapfig}[2003/01/31 \space v 3.6]
  294. \DeclareOption{verbose}{\def\WF@info{\PackageInfo{wrapfig}}}
  295. \ProcessOptions
  296. \AtEndDocument{\WFclear}
  297. \endinput
  298. %%%%% ----- End definitions ----- %%%%%
  299. %%%%% ----- Begin Instructions ----- %%%%%
  300. W R A P F I G . S T Y \ \ ver 3.6 \ \ (Jan 31, 2003)
  301. Copyright (C) 1991-2003 by Donald Arseneau (asnd@triumf.ca)
  302. Wrapfig.sty provides the environments "wrapfigure" and "wraptable" for
  303. typesetting a narrow float at the edge of the text, and making the text
  304. wrap around it. The "wrapfigure" and "wraptable" environments interact
  305. properly with the "\caption" command to produce proper numbering, but
  306. they are not regular floats like "figure" and "table", so (beware!) they
  307. may be printed out of sequence with the regular floats. There are four
  308. parameters for "\begin{wrapfigure}", two optional and two required, plus
  309. the text of the figure, with a caption perhaps:
  310. \begin{wrapfigure}[12]{r}[34pt]{5cm} <figure> \end{wrapfigure}
  311. == = ==== ===
  312. [number of narrow lines] {placement} [overhang] {width}
  313. Some idiosyncrasies:
  314. - You must not specify a wrapfigure in any type of list environment or
  315. or immediately before or immediately after one. It is OK to follow
  316. a list if there is a blank line ("\par") in between.
  317. - If you put a wrapfigure in a parbox or a minipage, or any other type
  318. of grouping, the text wrapping should end before the group does.
  319. - It does work in two-column format, but are your figures that small?
  320. - It may be out of sequence with regular floats.
  321. - The hlines that may be printed above and below floats are ignored;
  322. you must insert them manually if desired.
  323. - "\linewidth" is now adjusted within the wrapped text, but since it
  324. can only be set for whole paragraphs at a time, it will persist with
  325. the wrong value after the wrapping, until the paragraph is finished.
  326. New wrapping environments may be added when new float types are defined
  327. (using memoir.cls, float.sty, or ccaption.sty). Any wrapping environment,
  328. "wrapfigure", "wraptable", or something else may be invoked using the
  329. "wrapfloat" environment, as in "\begin{wrapfloat}{figure}{O}{5cm}".
  330. To use float.sty properly, load package "float" before "wrapfig",
  331. and declare any new float types after loading both. Likewise for
  332. ccaption.sty and "\newfloatlist" and memoir.cls and its "\newfloat".
  333. \section{Placement and Floating}
  334. Parameter "#2" (required) is the figure placement code, but the valid
  335. codes are different from regular figures. They come in pairs: an
  336. uppercase version which allows the figure to float, and a lowercase
  337. version that puts the figure ``exactly here''.
  338. r R - the right side of the text
  339. l L - the left side of the text
  340. i I - the inside edge--near the binding (if "[twoside]" document)
  341. o O - the outside edge--far from the binding
  342. You should specify one code only, not a list. The figure or table must
  343. be on one side or the other; it cannot be in the middle with text on
  344. both sides. The "i" and "o" options refer to the inside and outside of
  345. the whole page, not individual columns.
  346. The ability to float is somewhat restricted, and you will get best results
  347. by giving exact manual placement, but floating is more convenient while
  348. revising the document. Any changes to the formatting can ruin your manual
  349. positioning so you should adjust the placement just before printing a
  350. final copy. Here are some tips for good placement:
  351. - The environment should be placed so as to not run over a page break.
  352. - The environment must not be placed in special places like lists.
  353. - For esthetic reasons, only plain text should wrap around the figure.
  354. Section titles and big equations look bad; lists are bad if the figure
  355. is on the left. (All these function properly, they just don't look
  356. very good.) Small equations look fine.
  357. - It is convenient to begin the environment between paragraphs, but if
  358. you want placement in the middle of a paragraph, you must put the
  359. environment between two words where there is a natural line break.
  360. When floating, \LaTeX\ tries to apply these rules. More specifically,
  361. a floated wrapping environment will only begin...
  362. - at the beginning of a paragraph,
  363. - when there is enough room on the page, or it is possible to go on
  364. the next page,
  365. - if the `paragraph' is not in a section title or a list,
  366. - if the paragraph is not wrapping around another figure,
  367. - in the main text (not in a minipage etc.)
  368. It is possible that a non-floating wrapfigure will be forced to float
  369. when an earlier one is still being processed. A warning will be written
  370. in that case. You can have more information about the floating process
  371. written to the log file by specifying "\usepackage[verbose]{wrapfig}".
  372. If there is a lot of flexibility on a page, a floating wrapfigure may
  373. be placed badly; you must turn to manual placement. A rare problem is
  374. that floats and footnotes specified within the wrapping text can also
  375. cause poor placement and bad formatting.
  376. \section {Sizing and optional overhang}
  377. Parameter "#4" (the second required parameter) is the width of the figure
  378. or table. Given the way that \LaTeX\ puts just about everything into boxes
  379. with the current line-width, the width parameter will take precedence over
  380. whatever natural width the figure has. In particular, the caption is always
  381. typeset with the specified width. If the figure is wider than the space
  382. allotted, you will get an ``overfull box'' warning.
  383. However, if you specify a width of *zero* ("0pt"), the actual width of
  384. the figure will determine the wrapping width. A following "\caption"
  385. should have the same width as the figure, but it might fail badly; it
  386. is safer to specify a width when you use a caption.
  387. \LaTeX\ will wrap surrounding text around the figure, leaving a gap of
  388. "\intextsep" at the top and bottom, and "\columsep" at the side, by
  389. producing a series of shortened text lines beside the figure. The
  390. indentation (shortening) of the text is the figure width plus "\columnsep"
  391. minus overhang (if any; see below).
  392. \LaTeX\ calculates the number of short lines needed based on the height
  393. of the figure and the length "\intextsep". You can override this guess
  394. by giving the first optional argument (parameter "#1") specifying the
  395. number of shortened lines (counting each displayed equation as 3 lines).
  396. This is particularly useful when the surrounding text contains extra
  397. vertical spacing that is not accounted for automatically.
  398. The second optional parameter ("#3") tells how much the figure should
  399. hang out into the margin. The default overhang is given by the length
  400. "\wrapoverhang", which is "0pt" normally but can be changed using
  401. "\setlength". For example, to have all wrapfigures use the space
  402. reserved for marginal notes,
  403. \setlength{\wrapoverhang}{\marginparwidth}
  404. \addtolength{\wrapoverhang}{\marginparsep}
  405. When you do specify the overhang explicitly for a particular figure, you
  406. can use a special unit called "\width" meaning the width of the figure.
  407. For example, "[0.5\width]" makes the center of the figure sit on the
  408. edge of the text, and "[\width]" puts the figure entirely in the margin
  409. (and the adjacent text is indented by just "\columnsep"). This "\width"
  410. is the actual width of the wrapfigure, which may be greater than the
  411. declared width.
  412. \section{Some Random Implementation Notes}
  413. Unfortunately, \LaTeX's system of setting "\everypar" and "\par" is
  414. unable to coexist peacefully with a wrapping environment, so I was
  415. forced to subvert the "\@setpar" mechanism and "\everypar". ("\everypar"
  416. is already subverted once by NFSS.)
  417. When checking the room left on the page, remember that if there is less
  418. than "\baselineskip" the new paragraph will begin on the next page, even
  419. if there is no page stretch. If non-floating, I force a bad page break
  420. rather than have the figure hang into the bottom margin.
  421. Here are notes on various variables and some macros; what info they
  422. store and how they are used.
  423. \WF@wli - number-of-wrapped-lines parameter, saved for start of wrapping.
  424. Set globally by "\WF@wr" (set empty if no optional parameter given).
  425. The floating mechanism ignores this and uses the real size.
  426. \WF@ovh - margin overhang set globally by "\WF@rapt", saved until placing
  427. figure (but not reset). Actually, the setting is very tricky so that
  428. the expected values are used when a figure floats. First, the expression
  429. is saved without evaluation by "\WF@rapt" ("\begin{wrapfigure}") because
  430. "\width" is still unknown. Soon after that, "\endwrapfigure" executes
  431. "\WF@ovh" to evaluate the overhang and save the result (so that changes
  432. to "\wrapoverhang" while this figure is floating won't affect this
  433. figure). Finally, it is used by "\WF@putfigmaybe" when printing the fig.
  434. \WF@place - a macro that is used as a number, giving the placement code.
  435. It might start out as "`I" and later be converted to "114" (r).
  436. \WF@box - tested for void at "\begin{wrapfigure}", to avoid collisions,
  437. by "\everypar" to do floating, and by "\WF@finale" before resetting
  438. "\everypar". Voided globally when used by "\WF@putfigmaybe" (or by
  439. "\WF@wr" if an old figure must be dumped prematurely).
  440. \par - test if it is "\@@par" by "\begin{wrapfigure}" and "\WF@floathand"
  441. to float past special environments. It is set to "\@par" ("\WF@mypar")
  442. by "\WF@startwrapping", and restored by an end-group (bad!) or by
  443. "\WF@finale" (good). It is protected from change by redefining
  444. "\@setpar".
  445. \parshape - let to "\WF@fudgeparshape" by "\WF@startwrapping", so lists
  446. will continue wrapping; "\@@parshape" preserves the real "\parshape"
  447. command, and it is restored by "\WF@finale" or "\@parboxrestore".
  448. "\WF@floathand" and "\WF@wr" test if old wrapping is still in progress
  449. with "\ifx\parshape\WF@fudgeparshape". The value of "\@@parshape" is
  450. also tested to float past lists and other wrapping environments.
  451. \hangindent - tested to float past section titles etc.
  452. \c@WF@wrappedlines - the number of shortened lines + 1; set globally by
  453. "\WF@startwrapping" and decremented by "\par" ("\WF@mypar"). It is > 1
  454. only when wrapping is incomplete. "\WF@wraphand", "\WF@fudgeparshape",
  455. and "\WF@mypar" test the number for calling "\WF@finale". It may get
  456. stuck at some high value if "\par" is restored by an end-group, (and
  457. wrapping is terminated prematurely) so it is unwise to use this as a
  458. test for wrapping-complete.
  459. \pagetotal - one of many parameters used to compute floating. When
  460. putting a wrapfigure in a parbox, I assign "\let\pagetotal\maxdimen"
  461. (locally!) to signal not-top-of-page and no floating.
  462. \WF@pspars - the "\parshape" parameters as LaTeX sets them for lists
  463. ("\WF@fudgeparshape"); when wrapping I test it and use it to modify my
  464. own real params for the paragraph. They are also used when "\parshape"
  465. is restored after wrapping.
  466. \WF@finale - is performed by "\par" when wrapping should end. However,
  467. that might happen inside a group (a list especially), so the subverted
  468. versions of "\par", "\parshape" etc. will be reinstated when the group
  469. ends. Thus, they must themselves test "\c@WF@wrappedlines" < 2 to see
  470. when wrapping is over, and if so, they should just do "\WF@finale" again.
  471. These are the tests to see if a floating wrapfigure will fit at a particular
  472. spot. These tests are performed at the beginning of every paragraph after
  473. the figure, except in lists etc. ("\pagegoal" - "\pagetotal" is the room
  474. left on the page.)
  475. >
  476. room_left := \pagegoal - \pagetotal
  477. if room_left < 0 then page overfull already: put figure (on next page)
  478. else
  479. if figure_size > room_left then does not fit
  480. if max(min_stretch, \pagestretch) + extra > room_left
  481. then page can stretch until full: put figure (at top of next page)
  482. fi
  483. else figure fits: put figure
  484. fi fi
  485. <
  486. Even if a wrapfigure is not floating, it will go through the same logic
  487. to generate a "\pagebreak", and maybe an underfull page, when the current
  488. page can stretch until full. The "min_stretch" depends on whether it is
  489. floating or not: ".5\baselineskip" (floating) "2\baselineskip" (not). The
  490. "extra" is ".5\baselineskip" in either case. These values can be adjusted.
  491. There are some other `magic numbers' for floating that aren't really so
  492. special, but you must change them together if you change them at all.
  493. To make floating wrapfigures float less and fit on pages more frequently,
  494. but not change the number of wrapped lines, decrease the "1.5" in
  495. "\global\advance\WF@size1.5\baselineskip" and increase the "1.1" in
  496. "\advance\WF@size1.1\baselineskip" by the same amount (and vice versa).
  497. To make more (or fewer) wrapped lines for the same size figure, without
  498. changing the floating, change "1.1" in "\advance\WF@size1.1\baselineskip"
  499. unilaterally.
  500. %%%%% ----- End Instructions ----- %%%%%
  501. Test file integrity: ASCII 32-57, 58-126: !"#$%&'()*+,-./0123456789
  502. :;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~