Debian Codegraph @

texmf-dist/source/latex/float/float.dtx

raw
1 % \iffalse
2 %% Package `float' to use with LaTeX 2e
3 %% Copyright (C) 1991-2000 Anselm Lingnau, all rights reserved
4 %%
5 % This program can be redistributed and/or modified under the terms
6 % of the LaTeX Project Public License distributed from CTAN archives
7 % in the directory macros/latex/base/lppl.txt; either version 1 of
8 % the License, or (at your option) any later version.
9 %
10 % $Id: float.dtx,v 1.8 2001/11/07 23:46:25 anselm Exp $
11 %
12 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
13 %<package>\ProvidesPackage{float}
14 %<package> [2001/11/08 v1.3d Float enhancements (AL)]
15 %
16 %<*driver>
17 \documentclass{ltxdoc}
18 \usepackage{float}
19 \GetFileInfo{float.sty}
20 \EnableCrossrefs
21 %\DisableCrossrefs % Say \DisableCrossrefs if index is ready
22 \RecordChanges % Gather update information
23 \CodelineIndex % Index code by line number
24 \title{An Improved Environment for Floats\thanks{This file
25 has version number \fileversion.
26 Part of this style option is based on the \textsf{here} option
27 by David P. Carlisle (\texttt{[email protected]}),
28 who also provided helpful criticism.}}
29 \author{Anselm Lingnau\\\texttt{[email protected]}}%
30 \date{\filedate}
31 \floatstyle{ruled}
32 \newfloat{Program}{tbp}{lop}[section]
33 \floatstyle{plain}
34 \newfloat{Example}{t}{lox}[section]
35 \floatstyle{boxed}
36 \restylefloat{table}
37 \begin{document}
38 \maketitle
39 \DocInput{float.dtx}
40 \end{document}
41 %</driver>
42 % \fi
43 %
44 % \CheckSum{495}
45 %
46 % \changes{v1.3}{18 Jul 2001}{Changed some names to reduce namespace pollution}
47 % \changes{v1.2d}{29 May 99}{License changed to LPPL}
48 % \changes{v1.2}{20 Jun 94}{Adapted for LaTeX2e}
49 % \changes{v1.1d}{17 Dec 92}{Fixed documentation}
50 %
51 % \DoNotIndex{\@Mii,\@Miv,\@cons,\@currlist,\@dblarg,\@dbldeferlist}
52 % \DoNotIndex{\@dblfloat,\@dottedtocline,\@eha,\@ehd,\@Esphack,\@float}
53 % \DoNotIndex{\@floatpenalty,\@gobble,\@ifnextchar,\@ifundefined,\@ifstar}
54 % \DoNotIndex{\@latexerr,\@latex@error,\@minipagefalse,\@mkboth,\@namedef}
55 % \DoNotIndex{\@nameuse,\@parboxrestore,\@setminipage,\@setnobreak,\@spaces}
56 % \DoNotIndex{\@starttoc,\@tempa,\@tempboxa,\@tempdima,\@tempf,\@undefined}
57 % \DoNotIndex{\@warning}
58 % \DoNotIndex{\addcontentsline,\addtocontents,\addtocounter,\advance,\arabic}
59 % \DoNotIndex{\begingroup,\bfseries,\bgroup,\begin,\box,\chapter}
60 % \DoNotIndex{\color@endbox,\color@vbox,\columnwidth,\csname,\def,\dimen}
61 % \DoNotIndex{\docdate,\edef,\egroup,\else,\end,\end@dblfloat,\end@float}
62 % \DoNotIndex{\endcsname,\endgroup,\endinput,\expandafter,\fi}
63 % \DoNotIndex{\filedate,\fileversion,\global,\hbadness,\hbox,\hfil,\hrule}
64 % \DoNotIndex{\hsize,\ht,\if@twocolumn,\ifdim,\iffalse,\ifnum,\iftrue,\ifvoid}
65 % \DoNotIndex{\ifx,\ignorespaces,\intextsep,\kern,\let,\long}
66 % \DoNotIndex{\MakeUppercase,\moveleft,\newbox,\newcommand,\newcounter,\newif}
67 % \DoNotIndex{\newsavebox,\newtoks,\noexpand,\normalcolor,\normalsize}
68 % \DoNotIndex{\numberline,\outer@nobreak,\PackageError,\PackageWarning}
69 % \DoNotIndex{\par,\parindent,\parskip,\penalty,\prevdepth,\protect}
70 % \DoNotIndex{\providecommand,\refstepcounter,\relax,\renewcommand,\reset@font}
71 % \DoNotIndex{\rmfamily,\section,\setbox,\setcounter,\setlength,\space}
72 % \DoNotIndex{\textheight,\textwidth,\the,\typeout,\unvbox,\uppercase}
73 % \DoNotIndex{\vadjust,\value,\vbox,\vrule,\vskip,\vspace,\wd,\xdef}
74 % \DoNotIndex{\z@skip,\z@}
75 %
76 % \begin{abstract}
77 % This style option improves the interface for defining floating
78 % objects such as figures and tables in \LaTeX{}.
79 % It adds the notion of a `float style' that governs appearance
80 % of floats.
81 % New kinds of floats may be defined using a |\newfloat| command
82 % analogous to |\newtheorem|.
83 % This style option also incorporates the functionality
84 % of David Carlisle's style option \textsf{here},
85 % giving floating environments a \texttt{[H]} option
86 % which means `PUT IT HERE'
87 % (as opposed to the standard \texttt{[h]} option which means
88 % `You may put it here if you like').
89 % \end{abstract}
90 %
91 % \section{Introduction}
92 %
93 % Among the features of \LaTeX\ are `floating' figures and tables
94 % that drift from where they appear in the input text to, say, the top
95 % of a page. The contents and formatting of floats is pretty much up
96 % to the user, except that there is a |\caption| command that
97 % governs formatting of the caption --- it is centered if it is short,
98 % and formatted as a paragraph if it is longer than a single line of text.
99 % Sometimes other types of floating objects, e.g., algorithms or programs,
100 % are desirable, but they must be defined by analogy to the existing
101 % floats since there is no simple command for doing this. This goes
102 % beyond the knowledge or inclination of the average \LaTeX\ user.
103 %
104 % In this style option, I present an interface to floating objects
105 % that attempts to fix some of these shortcomings.
106 % First of all, I introduce the notion of a `float style'.
107 % A float style governs the appearance of a class of floats like a page style
108 % governs the appearance of a page (\LaTeX\ has page styles \texttt{plain},
109 % \texttt{empty} and \texttt{headings}, among others). This style option
110 % provides some exemplary float styles:
111 % \begin{description}
112 % \item[plain] This is the float style that \LaTeX\ normally applies to
113 % its floats, i.e., nothing in particular. The only difference is
114 % that the caption comes out \emph{below} the body of the float,
115 % regardless of where it is given in the text.
116 % \item[plaintop] This is similar to `plain' but the caption always
117 % comes out \emph{above} the body of the float.
118 % \item[boxed] The body of the float is printed inside a box. The caption
119 % goes below that box.
120 % \item[ruled] This float style is patterned on the table style of
121 % {\sl Concrete Mathematics}. The caption is printed at the top of the
122 % float, surrounded by rules; another rule finishes off the float.
123 % \end{description}
124 %
125 % \begin{Program}
126 % \begin{verbatim}
127 % #include <stdio.h>
128 %
129 % int main(int argc, char **argv)
130 % {
131 % int i;
132 % for (i = 0; i < argc; ++i)
133 % printf("argv[%d] = %s\n", i, argv[i]);
134 % return 0;
135 % }
136 % \end{verbatim}
137 % \caption{The first program. This hasn't got anything to do with the package
138 % but is included as an example. Note the \texttt{ruled} float style.%
139 % \label{prog1.1}}
140 % \end{Program}
141 % To facilitate the definition of new floating objects, \textsf{float}
142 % supports the |\newfloat| command. This command is comparable to
143 % |\newtheorem| in that it allows the user to add a new class of floats
144 % at the document level. No style option hacking is necessary.
145 % There's also a |\listof| command that prints a listing of all the
146 % floats of a given type, like |\listoffigures| and |\listoftables|
147 % in vanilla \LaTeX.
148 %
149 % \section{The User Interface --- New Floats}
150 %
151 % \DescribeMacro{\newfloat}
152 % The most important command in \textsf{float} is the |\newfloat|
153 % command. As mentioned above, it is patterned on |\newtheorem|.
154 % The |\newfloat| command takes three required and one optional
155 % argument; it is of the form\\[2pt]
156 % \hspace*{\MacroIndent}|\newfloat{|\meta{type}|}{|^^A
157 % \meta{placement}|}{|\meta{ext}|}[|\meta{within}{\tt]}\\[2pt]
158 % \meta{type} is the `type' of the new class of floats, like \texttt{program}
159 % or \texttt{algorithm}. After the appropriate |\newfloat|, commands
160 % like |\begin{program}| or |\end{algorithm*}| will be available.
161 % \meta{placement} gives the default placement parameters for this class
162 % of floats. The placement parameters are the same as in standard \LaTeX,
163 % i.e., \texttt{t}, \texttt{b}, \texttt{p} and \texttt{h} for `top', `bottom',
164 % `page' and `here', respectively.
165 % When \LaTeX\ writes the captions to an auxiliary file for the list
166 % of figures (or whatever), it'll use the job name followed by \meta{ext}
167 % as a file name.
168 % Finally, the optional argument \meta{within} determines whether floats
169 % of this class will be numbered within some sectional unit of the document.
170 % For example, if \meta{within}$=$\texttt{chapter}, the floats will be numbered
171 % within chapters. (In standard \LaTeX, this happens with figures and tables
172 % in the \textsf{report} and \textsf{book} document styles.)
173 % As an example, Program~\ref{prog1.1} above was created by a command
174 % sequence similar to that shown in the following Example.
175 % \begin{Example}[H]
176 % \begin{verse}
177 % |\floatstyle{ruled}|\\
178 % |\newfloat{Program}{tbp}{lop}[section]|\\
179 % \dots\ loads o' stuff \dots\\
180 % |\begin{Program}|\\
181 % |\begin{verbatim}|\\
182 % \dots\ program text \dots\\
183 % |\end{verbatim}|\\
184 % |\caption{|\dots\ caption \dots|}|\\
185 % |\end{Program}|
186 % \end{verse}
187 % \caption{This is another silly floating Example. Except that this one
188 % doesn't actually float because it uses the {\tt[H]} optional parameter
189 % to appear \textbf{Here}. (Gotcha.)}
190 % \end{Example}
191 %
192 % \DescribeMacro{\floatstyle}
193 % The |\floatstyle| command sets a default float style. This float style
194 % will be used for all the floats that are subsequently defined using
195 % |\newfloat|, until another |\floatstyle| command appears.
196 % The |\floatstyle| command takes one argument, the name of a float
197 % style. For instance, |\floatstyle{ruled}|. Specifying a string that
198 % does not name a valid float style is an error.
199 %
200 % \DescribeMacro{\floatname}
201 % The |\floatname| command lets you define the \emph{float name} that
202 % \LaTeX\ uses in the caption of a float, i.e., `Figure' for a figure
203 % and so on. For example, |\floatname{program}{Program}|.
204 % The |\newfloat| command sets the float name to its argument
205 % \meta{type} if no other name has been specified before.
206 %
207 % \DescribeMacro{\floatplacement}
208 % The |\floatplacement| command resets the default placement specifier
209 % of a class of floats. E.g., |\floatplacement{figure}{tp}|.
210 %
211 % \DescribeMacro{\restylefloat}
212 % The |\restylefloat| command is necessary to change styles for the
213 % standard float types \texttt{figure} and \texttt{table}. Since these aren't
214 % usually defined via |\newfloat|, they don't have a style associated
215 % with them. Thus you have to say, for example,\\[2pt]
216 % \hspace*{\MacroIndent}|\floatstyle{ruled}|\\
217 % \hspace*{\MacroIndent}|\restylefloat{table}|\\[2pt]
218 % to have tables come out \texttt{ruled}. The command also lets you change
219 % style for floats that you define via |\newfloat|, although this
220 % is, typographically speaking, not a good idea.
221 % See table~\ref{table1} for an example.
222 % There is a |\restylefloat*| command which will restyle an existing
223 % float type but will keep the new float style from taking over the
224 % |\caption| command. In this case the user is responsible for
225 % handling their own captions.
226 % \DeleteShortVerb{\|}
227 % \begin{table} \def\B#1{$\displaystyle{n\choose#1}$}
228 % \begin{center} \begin{tabular}{c|cccccccc}
229 % $n$&\B0&\B1&\B2&\B3&\B4&\B5&\B6&\B7\\ \hline
230 % 0 & 1\\
231 % 1 & 1&1\\
232 % 2 & 1&2&1\\
233 % 3 & 1&3&3&1\\
234 % 4 & 1&4&6&4&1\\
235 % 5 & 1&5&10&10&5&1\\
236 % 6 & 1&6&15&20&15&6&1\\
237 % 7 & 1&7&21&35&35&21&7&1
238 % \end{tabular} \end{center}
239 % \caption{Pascal's triangle. This is a re-styled \LaTeX\ \texttt{table}.%
240 % \label{table1}}
241 % \end{table}
242 % \MakeShortVerb{\|}
243 %
244 % \DescribeMacro{\listof}
245 % The |\listof| command produces a list of all the floats of a given
246 % class. Its syntax is\\[2pt]
247 % \hspace*{\MacroIndent}|\listof{|\meta{type}|}{|\meta{title}^^A
248 % |}|\\[2pt]
249 % \meta{type} is the float type given in the |\newfloat| command.
250 % \meta{title} is used for the title of the list as well as the headings
251 % if the current page style includes them. Otherwise, the |\listof|
252 % command is analogous to the built-in \LaTeX\ commands
253 % |\listoffigures| and |\listoftables|.
254 %
255 % \section{The User Interface --- \texttt{[H]} Placement Specifier}
256 %
257 % Many people find \LaTeX's float placement specifiers too restrictive.
258 % A Commonly Uttered Complaint (CUC) calls for a way to place a float
259 % exactly at the spot where it occurs in the input file, i.e., to \emph{not}
260 % have it float at all.
261 % It seems that the \texttt{[h]} specifier should do that, but in fact it
262 % only suggests to \LaTeX\ something along the lines of ``put the float
263 % here if it's OK with you''. As it turns out, \LaTeX\ hardly ever feels
264 % inclined to actually do that. This situation can be improved by
265 % judicious manipulation of float style parameters.
266 %
267 % The same effect can be achieved by changing the actual method of
268 % placing floats. David Carlisle's \textsf{here} option introduces a new float
269 % placement specifier, namely \texttt{[H]}, which, when added to a float,
270 % tells \LaTeX\ to ``put it HERE, period''. If there isn't enough space
271 % left on the page, the float is carried over to the next page together
272 % with whatever follows, even though there might still be room left for
273 % some of that.
274 % This style option provides the \texttt{[H]} specifier for newly defined
275 % classes of floats as well as the predefined \texttt{figure}s and
276 % \texttt{table}s, thereby superseding \textsf{here}. David suggests
277 % that the \textsf{here} option be withdrawn from the archives in due course.
278 %
279 % The {\tt[H]} specifier may simply be added to the float as an optional
280 % argument, like all the other specifiers.
281 % It may \emph{not} be used in conjunction with any other placement
282 % specifiers, so {\tt[Hhtbp]} is illegal.
283 % Neither may it be used as the default placement specifier for a whole
284 % class of floats.
285 % The following table is
286 % defined like this:
287 % \begin{verse}
288 % |\begin{table}[H]|\\
289 % |\begin{tabular}{cl}|\\
290 % |\tt t & Top of the page\\|\\
291 % \dots\ more stuff \dots\\
292 % \end{verse}
293 % (It seems that I have to add some extraneous chatter here just so that
294 % the float actually comes out right in the middle of a printed page.
295 % When I \LaTeX ed the documentation just now it turned out that there
296 % was a page break that fell exactly between the ``So now'' line and the
297 % float. This wouldn't Prove Anything. Bother.)
298 % So now we have the following float placement specifiers:
299 % \begin{table}[H]
300 % \begin{tabular}{cl}
301 % \tt t & Top of the page\\
302 % \tt b & Bottom of the page\\
303 % \tt p & Page of floats\\
304 % \tt h & Here, if possible\\
305 % \tt H & Here, definitely
306 % \end{tabular}
307 % ^^A\caption{Could it be that this just needs a caption?}
308 % \end{table}
309 %
310 % \StopEventually{\PrintIndex}
311 %
312 % \section{Implementation}
313 %
314 % \subsection{Basics}
315 %
316 % \begin{macrocode}
317 %<*package>
318 % \end{macrocode}
319 %
320 % In \LaTeX, floats are assigned `type numbers' that are powers of~$2$.
321 % Since there are only two classes of floats, their type numbers are
322 % hardwired into the document styles. We need to be somewhat more flexible,
323 % and thus we initialize a counter to hold the next type number to be
324 % assigned. This counter will be incremented appropriately later.
325 % \begin{macrocode}
326 \newcounter{float@type}
327 \@ifundefined{c@figure}%
328 {\setcounter{float@type}{1}}%
329 {\setcounter{float@type}{4}}
330 % \end{macrocode}
331 % To warm up, we'll look at some of the simpler commands first.
332 % \begin{macro}{\floatstyle}
333 % The |\floatstyle| command puts its argument into the
334 % |\float@style| macro as the name of the new float style.
335 % But if the argument doesn't denote a float style, an error message
336 % is output instead: Each float style \meta{style} has a corresponding command
337 % |\fs@|\meta{style} that contains the appropriate declarations.
338 % If the control sequence |\fs@|\meta{arg} (which goes with the
339 % argument \meta{arg} to |\floatstyle|) is undefined, i.e.,
340 % equals |\relax| under |\ifx|, then the float style \meta{arg}
341 % is unknown, and we call |\float@error{|\meta{arg}|}| for the
342 % error message.
343 % \begin{macrocode}
344 \newcommand\floatstyle[1]{\@ifundefined{fs@#1}%
345 {\float@error{#1}}%
346 {\def\float@style{#1}}}
347 % \end{macrocode}
348 % \end{macro}
349 % \begin{macro}{\float@error}
350 % Here's the error message. |\@eha| is the help message that says
351 % `Your command was ignored.'
352 % \begin{macrocode}
353 \newcommand\float@error[1]{\PackageError{float}{%
354 Unknown float style `#1'
355 }{\@eha}}
356 % \end{macrocode}
357 % \end{macro}
358 %
359 % The next two commands are even simpler. \LaTeX\ says that
360 % |\fps@|\meta{float} contains the default placement specifier for
361 % the class of floats \meta{float}. |\fname@|\meta{float} expands
362 % to the name that appears in \meta{float} captions, e.g., `Figure'.
363 % (This is our own definition.)
364 % \begin{macrocode}
365 \newcommand\floatname[2]{\@namedef{fname@#1}{#2}}
366 \newcommand\floatplacement[2]{\@namedef{fps@#1}{#2}}
367 % \end{macrocode}
368 %
369 % \begin{macrocode}
370 \newcommand\floatevery[2]{\csname @float@every@#1\endcsname={#2}}
371 % \end{macrocode}
372 % \begin{macro}{\restylefloat}
373 % The |\restylefloat| command sets up everything so that subsequent
374 % commands like |\begin{|\meta{float}|}| use the appropriate
375 % float style. It defines |\fst@|\meta{float} to expand to a command
376 % that sets up the currently selected float style (|\fs@|\meta{style}).
377 % Then it defines the commands |\begin{|\meta{float}|}|,
378 % |\end{|\meta{float}|}|, |\begin{|\meta{float}|*}| and
379 % |\end{|\meta{float}|*}|. The |\restylefloat*| command is like
380 % |\restylefloat| but will leave the captions of that float type
381 % alone.
382 % \changes{v1.3c}{17 Aug 2001}{Remove token register leak}
383 % \changes{v1.3a}{15 Aug 2001}{Introduce star form of `restylefloat}
384 % \begin{macrocode}
385 \newcommand\restylefloat{\@ifstar\float@restyle@\float@restyle}
386 \newcommand\float@restyle@[1]{\float@restyle{#1}%
387 \expandafter\let\csname @float@c@#1\endcsname=\@caption}
388 \newcommand\float@restyle[1]{\expandafter\edef\csname
389 fst@#1\endcsname{\expandafter\noexpand\csname
390 fs@\float@style\endcsname}%
391 \@namedef{#1}{\@nameuse{fst@#1}%
392 \@float@setevery{#1}\@float{#1}}%
393 \@namedef{#1*}{\@nameuse{fst@#1}%
394 \@float@setevery{#1}\@dblfloat{#1}}%
395 \expandafter\let\csname end#1\endcsname\float@end
396 \expandafter\let\csname end#1*\endcsname\float@dblend
397 \expandafter\let\csname @float@c@#1\endcsname=\float@caption
398 \@ifundefined{@float@every@#1}{%
399 \expandafter\newtoks\csname @float@every@#1\endcsname}{}%
400 \@nameuse{@float@every@#1}={}}
401 % \end{macrocode}
402 % \end{macro}
403 %
404 % \begin{macro}{\newfloat}
405 % Now we can explain how to define a new class of floats. Recall that
406 % the three required arguments to |\newfloat| are \meta{type},
407 % \meta{placement} and \meta{ext}, respectively. First we save the
408 % latter two; we also maintain a list of active \meta{ext}s so we can
409 % later iterate over all currently-open lists of floats.
410 % \begin{macrocode}
411 \newtoks\float@exts
412 \newcommand\newfloat[3]{\@namedef{ext@#1}{#3}
413 \let\float@do=\relax
414 \xdef\@tempa{\noexpand\float@exts{\the\float@exts \float@do{#3}}}%
415 \@tempa
416 \floatplacement{#1}{#2}%
417 % \end{macrocode}
418 % Then we figure out a default value for the `caption name' of this
419 % class of floats. If the |\fname@|\meta{type} isn't already defined,
420 % we tentatively use \meta{type} as the name. This is convenient if
421 % \meta{type} is, say, \texttt{Program}, since no |\floatname| command
422 % is necessary at all.
423 % \begin{macrocode}
424 \@ifundefined{fname@#1}{\floatname{#1}{#1}}{}
425 % \end{macrocode}
426 % Then we set up the type number for \LaTeX\ in |\ftype@|\meta{type}.
427 % Afterwards we have to set the |float@type| to the next greater power
428 % of two, so that it is ready for the next |\newfloat|. Fortunately,
429 % we just have to double it by adding. We don't bother checking for overflow
430 % since it is pretty unlikely that somebody will define 25 different classes
431 % of floats. Finally, we call |\restylefloat| to define the style and
432 % commands for this class of floats.
433 % \begin{macrocode}
434 \expandafter\edef\csname ftype@#1\endcsname{\value{float@type}}%
435 \addtocounter{float@type}{\value{float@type}}
436 \restylefloat{#1}%
437 % \end{macrocode}
438 % Now all that's left is to assemble the |\fnum@|\meta{type} macro
439 % that \LaTeX\ wants to use in its captions. Basically it is just
440 % `caption name'${}+{}$`counter value', disguised so that the command
441 % \emph{names} appear in the definition instead of their expansions.
442 % \begin{macrocode}
443 \expandafter\edef\csname fnum@#1\endcsname%
444 {\expandafter\noexpand\csname fname@#1\endcsname{}
445 \expandafter\noexpand\csname the#1\endcsname}
446 % \end{macrocode}
447 % Finally, we have to take care of the optional argument, \meta{within}.
448 % If the optional argument is present, we pass control to |\float@newx|.
449 % Otherwise, we just define the counter for this class of floats.
450 % By default, the numbers come out |\arabic|.
451 % \begin{macrocode}
452 \@ifnextchar[{\float@newx{#1}}%
453 {\@ifundefined{c@#1}{\newcounter{#1}\@namedef{the#1}{\arabic{#1}}}%
454 {}}}
455 % \end{macrocode}
456 % \end{macro}
457 %
458 % \begin{macro}{\float@newx}
459 % Here we deal with the optional argument to |\newfloat|. We have
460 % to create a new counter as per |\newcounter{|\meta{type}|}|
461 % and add that counter to the list of counters to be reset whenever
462 % counter \meta{within} is stepped. The standard command
463 % |\newcounter{|\meta{type}|}[|\meta{within}{\tt]} takes care of that.
464 % However, we can't define the \meta{type} counter if it's already defined.
465 % While this case is simply ignored when \meta{within} is not present,
466 % we issue a warning here since what comes out is probably not what the user
467 % expects.
468 % \begin{macrocode}
469 \def\float@newx#1[#2]{\@ifundefined{c@#1}{\newcounter{#1}[#2]%
470 \expandafter\edef\csname the#1\endcsname{%
471 \expandafter\noexpand\csname
472 the#2\endcsname.\noexpand\arabic{#1}}}%
473 {\PackageWarning{float}{Can't redefine counter variable for #1.}}}
474 % \end{macrocode}
475 % \end{macro}
476 %
477 % \subsection{Adapting \LaTeX\ internals}
478 %
479 % We have to adapt some of \LaTeX's internal macros to our needs.
480 % There are several things that have to be changed around
481 % in order to provide the functionality of David Carlisle's \textsf{here}.
482 % The following is thus lifted from \textsf{here}, with changes and with
483 % David's permission:
484 %
485 % \begin{macro}{\@float@Hx}
486 % We save the original version of |\@xfloat|. (This macro is called from
487 % |\@float|, which we used above to define the environment commands for a
488 % new class of floats.)
489 % \begin{macrocode}
490 \let\@float@Hx\@xfloat
491 % \end{macrocode}
492 % \end{macro}
493 % \begin{macro}{\@xfloat}
494 % The new version of |\@xfloat| looks for a |[H]| argument.
495 % If it is present |\@float@HH| is called, otherwise the original macro
496 % (renamed to |\@float@Hx|) is called.
497 % \begin{macrocode}
498 \def\@xfloat#1[{\@ifnextchar{H}{\@float@HH{#1}[}{\@float@Hx{#1}[}}
499 % \end{macrocode}
500 % \end{macro}
501 % Later on we'll need a box to save a |[H]| float.
502 % \begin{macrocode}
503 \newsavebox\float@box
504 \newif\if@flstyle
505 % \end{macrocode}
506 % \begin{macro}{\@float@HH}
507 % First gobble the |[H]|. Note that \texttt{H} should not be used in
508 % conjunction with the other placement options, nor as the value of the
509 % default placement, as set in |\fps@|{\it type}.
510 % \begin{macrocode}
511 \def\@float@HH#1[H]{%
512 % \end{macrocode}
513 % Locally redefine the end of the environment.
514 % \begin{macrocode}
515 \expandafter\let\csname end#1\endcsname\float@endH
516 % \end{macrocode}
517 % We don't get a |\@currbox| if we don't actually use the float mechanism.
518 % Therefore we fake one using the |\float@box| defined above.
519 % \begin{macrocode}
520 \let\@currbox\float@box
521 % \end{macrocode}
522 % Now we save the current float class name for use in constructing the
523 % |\caption|. The caption box (defined below) is initialised to an empty
524 % box to avoid trouble with floats not having a caption. Then we start the
525 % box that'll hold the float itself.
526 % |\parindent| is set to zero for compatibility with the standard \texttt{[h]}
527 % option.
528 % \changes{v1.2c}{29 Mar 95}{Bring H floats more in line with normal floats}
529 % \begin{macrocode}
530 \def\@captype{#1}\setbox\@floatcapt=\vbox{}%
531 \expandafter\ifx\csname fst@#1\endcsname\relax
532 \@flstylefalse\else\@flstyletrue\fi
533 \setbox\@currbox\color@vbox\normalcolor
534 \vbox\bgroup \hsize\columnwidth \@parboxrestore
535 \@floatboxreset \@setnobreak
536 % \end{macrocode}
537 % The final |\ignorespaces| is needed to gobble any spaces or newlines
538 % after the {\tt[H]} tokens.
539 % \begin{macrocode}
540 \ignorespaces}
541 % \end{macrocode}
542 % \end{macro}
543 %
544 % \begin{macrocode}
545 \newtoks\@float@everytoks
546 \let\@float@boxreset=\@floatboxreset
547 \def\@floatboxreset{\@float@boxreset\the\@float@everytoks}
548 \def\@float@setevery#1{\@float@everytoks=\@nameuse{@float@every@#1}}
549 % \end{macrocode}
550 %
551 % \begin{macro}{\float@makebox}
552 % Basically, we must arrange for `style commands' to be executed
553 % at certain points during the generation of the float.
554 % \LaTeX\ puts a float into a vertical box |\@currbox| which it takes
555 % off a list of empty boxes for insertions. When the |\float@makebox| macro
556 % is called, |\@currbox| contains the complete float, minus the caption
557 % --- we'll see later that we use our own |\caption| command to
558 % put the caption into a |\vbox| of its own. This is the only way
559 % we can control the position of the caption by the float style,
560 % regardless of where the caption appears in the float's input text itself.
561 % So the `style commands' are |\@fs@pre|, which is inserted at the
562 % very beginning of the float, |\@fs@mid|, which comes between the
563 % float and the caption (or the caption and the float, if captions are put
564 % at the top), and |\@fs@post|, which finishes off the float.
565 % The caption may appear at the top or at the bottom of the float,
566 % as defined by |\@fs@iftopcapt|. Therefore, before we hand the
567 % float to \LaTeX\ for positioning, it is taken apart and reassembled
568 % using the style commands.
569 % \changes{v1.3a}{15 Aug 2001}{Changed `ifvbox to `ifvoid}
570 % \begin{macrocode}
571 \newcommand\float@makebox[1]{%
572 \vbox{\hsize=#1 \@parboxrestore
573 \@fs@pre\@fs@iftopcapt
574 \ifvoid\@floatcapt\else\unvbox\@floatcapt\par\@fs@mid\fi
575 \unvbox\@currbox
576 \else\unvbox\@currbox
577 \ifvoid\@floatcapt\else\par\@fs@mid\unvbox\@floatcapt\fi
578 \fi\par\@fs@post\vskip\z@}}
579 % \end{macrocode}
580 % \end{macro}
581 % \begin{macro}{\float@end}
582 % The internal macro |\end@float| appears here under the name of |\float@end|.
583 % The main thing which is changed is that we call |\float@makebox| to
584 % reconstruct the float according to the float style.
585 % We want to do exactly what the \LaTeX\ kernel does without copying
586 % actual kernel code if we can help it; therefore we finish off the
587 % float using the kernel |\@endfloatbox|, then replace \LaTeX's
588 % contents of the |\@currbox| with our own processed version, and then
589 % hand the thing off to \LaTeX again. Of course we have already done
590 % |\@endfloatbox|, which comes at the beginning of |\end@float|, ourselves;
591 % therefore we neutralize it before calling |\end@float|. This doesn't
592 % matter since we're in a group anyway (we wanted to keep the style
593 % commands local), so everything is undone at the end of the environment.
594 % \changes{v1.3d}{08 Nov 2001}{Removed an extraneous level of grouping}
595 % \changes{v1.3b}{17 Aug 2001}{Still another new method}
596 % \changes{v1.3}{18 Jul 2001}{Simplified according to H. A. Sommerfeldt}
597 % \changes{v1.2a}{29 Mar 95}{Fixed float end handling for LaTeX2e of Dec94}
598 % \begin{macrocode}
599 \newcommand\float@end{\@endfloatbox
600 \global\setbox\@currbox\float@makebox\columnwidth
601 \let\@endfloatbox\relax\end@float}
602 % \end{macrocode}
603 % \end{macro}
604 %
605 % \begin{macro}{\float@endH}
606 % The |\float@endH| command is, again, derived from \textsf{here}. It'll
607 % deal correctly with a non-floating float, inserting the proper amounts
608 % of white space above and below.
609 % \changes{v1.3b}{18 Aug 2001}{Move more processing to LaTeX kernel}
610 % \changes{v1.2c}{29 Mar 95}{Bring H floats more in line with normal floats}
611 % \begin{macrocode}
612 \newcommand\float@endH{\@endfloatbox\vskip\intextsep
613 \if@flstyle\setbox\@currbox\float@makebox\columnwidth\fi
614 \box\@currbox\vskip\intextsep\relax}
615 % \end{macrocode}
616 % \end{macro}
617 %
618 % \begin{macro}{\float@dblend}
619 % The |\float@dblend| command finishes up double-column floats. This
620 % uses the same approach as |\float@end| above. It seems to work.
621 % \changes{v1.3b}{17 Aug 2001}{Still another new method}
622 % \changes{v1.3}{18 Jul 2001}{Rewritten after H. A. Sommerfeldt}
623 % \changes{v1.2e}{09 Mar 2000}{Fixed bug in double-column floats}
624 % \changes{v1.2a}{29 Mar 95}{Fixed float end handling for LaTeX2e of Dec94}
625 % \begin{macrocode}
626 \newcommand\float@dblend{\@endfloatbox
627 \global\setbox\@currbox\float@makebox\textwidth
628 \let\@endfloatbox\relax\end@dblfloat}
629 % \end{macrocode}
630 % \end{macro}
631 %
632 % \subsection{Captions and lists of floats}
633 %
634 % Now for the caption routines.
635 % We use a box, |\@floatcapt|, to hold the caption while the float
636 % is assembled.
637 % \begin{macrocode}
638 \newsavebox\@floatcapt
639 % \end{macrocode}
640 %
641 % \begin{macro}{\caption}
642 % This is the only \LaTeX\ macro that this document style supersedes.
643 % Our |\caption| command checks whether there is a custom style
644 % defined for the current float (whose type can be found in |\@captype|).
645 % If so, the caption routines from \textsf{float} are used, otherwise
646 % (or when the float style has been applied via |\restylefloat*| so
647 % that captions aren't handled by this package)
648 % we call the vanilla \LaTeX\ routines.
649 % \begin{macrocode}
650 \renewcommand\caption{%
651 \ifx\@captype\@undefined
652 \@latex@error{\noexpand\caption outside float}\@ehd
653 \expandafter\@gobble
654 \else
655 \refstepcounter\@captype
656 \let\@tempf\@caption
657 \expandafter\ifx\csname @float@c@\@captype\endcsname\relax\else
658 \expandafter\expandafter\let
659 \expandafter\@tempf\csname @float@c@\@captype\endcsname\fi\fi
660 \@dblarg{\@tempf\@captype}}
661 % \end{macrocode}
662 % \end{macro}
663 %
664 % \begin{macro}{\float@caption}
665 % The |\float@caption| macro takes care of entering the caption into
666 % the appropriate listing. It also controls the typesetting of the caption
667 % itself, although a style-dependent macro |\@fs@capt| is called
668 % to handle the specifics. Note that because the caption is saved in a box
669 % instead of being output to the float right away, you cannot simply put
670 % a legend after the caption proper; it has to follow the |\caption|
671 % command in an optional argument.
672 %
673 % First of all, we call |\addcontentsline| to update the list of
674 % floats of this class. Note that |\float@caption| is |\long|
675 % to allow for paragraph breaks in its arguments.
676 % \begin{macrocode}
677 \long\def\float@caption#1[#2]#3{\addcontentsline{\@nameuse{ext@#1}}{#1}%
678 {\protect\numberline{\@nameuse{the#1}}{\ignorespaces #2}}
679 % \end{macrocode}
680 % Now we collect the caption proper. The caption name and number are
681 % taken from |\fnum@|\meta{float}, where \meta{float} is the class
682 % of float we're currently handling.
683 % \begin{macrocode}
684 \global\setbox\@floatcapt\vbox\bgroup\@parboxrestore
685 \normalsize\@fs@capt{\@nameuse{fnum@#1}}{\ignorespaces #3}%
686 % \end{macrocode}
687 % Finally we check for the presence of the optional argument. If there is
688 % one, we call |\float@ccon| to pick it up; otherwise, the |\egroup|
689 % finishes off the box.
690 % \begin{macrocode}
691 \@ifnextchar[{\float@ccon}{\egroup}}
692 % \end{macrocode}
693 % \end{macro}
694 %
695 % \begin{macro}{\float@ccon}
696 % The |\float@ccon| macro expands to the optional argument of a
697 % |\caption| command, followed by |\par\egroup|. Note that this
698 % precludes using |\verb| \& Co.\ in the optional argument; the
699 % interested reader is urged to fix this problem as an exercise.
700 % \begin{macrocode}
701 \long\def\float@ccon[#1]{#1\par\egroup}
702 % \end{macrocode}
703 % \end{macro}
704 %
705 % \begin{macro}{\listof}
706 % The |\listof| command reads the desired list of floats from the
707 % appropriate auxiliary file. The file is then restarted.
708 % First of all, we check whether the float style that's supposed to be
709 % listed is actually defined. If not, we output a |\float@error|.
710 % \begin{macrocode}
711 \newcommand*{\listof}[2]{%
712 \@ifundefined{ext@#1}{\float@error{#1}}{%
713 % \end{macrocode}
714 % All's well until now. We define the |\l@|\meta{float} command
715 % that \LaTeX\ needs for formatting the list, and then typeset the
716 % appropriate list header.
717 % \begin{macrocode}
718 \@namedef{l@#1}{\@dottedtocline{1}{1.5em}{2.3em}}%
719 \float@listhead{#2}%
720 % \end{macrocode}
721 % Next we call |\@starttoc| with the correct file extension
722 % to do the actual work.
723 % If |\parskip| is non-zero, vertical space would be added between
724 % the individual list entries. To avoid this, we zero |\parskip|
725 % locally. This should be done after the |\float@listhead| above since
726 % |\parskip| also influences the spacing of headings, and the listings
727 % would look different from other chapters otherwise. (Suggested by
728 % Markus Kohm.)
729 % \changes{v1.3c}{17 Aug 2001}{Set parskip to zero for listing}
730 % \begin{macrocode}
731 \begingroup\setlength{\parskip}{\z@}%
732 \@starttoc{\@nameuse{ext@#1}}%
733 \endgroup}}
734 % \end{macrocode}
735 % \end{macro}
736 %
737 % \begin{macro}{\float@listhead}
738 % This command generates the beginning of a list of floats.
739 % Currently the list appears at the chapter or the section level, depending
740 % on whether chapters are supported in the document class. According to
741 % a suggestion from Markus Kohm, this is now in a separate command so it
742 % can be overridden by other packages. We also use |\MakeUppercase| instead
743 % of |\uppercase|; when this piece of code was first written |\MakeUppercase|
744 % hadn't been invented yet, and for some reason this never got updated.
745 % \changes{v1.3}{18 Jul 2001}{Factored out list-of-float starting code}
746 % \begin{macrocode}
747 \providecommand*{\float@listhead}[1]{%
748 \@ifundefined{chapter}{\def\@tempa{\section*}}%
749 {\def\@tempa{\chapter*}}%
750 \@tempa{#1\@mkboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}}}%
751 % \end{macrocode}
752 % \end{macro}
753 %
754 % \begin{macro}{\float@addtolists}
755 % This command allows \LaTeX\ programmers to add something to all
756 % currently-defined lists of floats, such as some extra vertical
757 % space at the beginning of a new chapter in the main text
758 % (|\float@addtolists{\protect\addvspace{10pt}}|), without knowing
759 % exactly which lists of floats are currently being constructed.
760 % This command currently does \emph{not} operate on the |lot| and |lof|
761 % lists.
762 % \changes{v1.3}{18 Jul 2001}{Added command}
763 % \begin{macrocode}
764 \newcommand\float@addtolists[1]{%
765 \def\float@do##1{\addtocontents{##1}{#1}} \the\float@exts}
766 % \end{macrocode}
767 % \end{macro}
768 %
769 % \section{The Float Styles}
770 %
771 % Finally, we define the standard float styles that were outlined
772 % in the Introduction. Every float style \meta{style} corresponds to a
773 % command |\fs@|\meta{style} which contains the definitions of the
774 % style commands, namely
775 % \begin{center}\begin{tabular}{rl}
776 % |\@fs@pre|&top of the float\\
777 % |\@fs@mid|&between float and caption\\
778 % |\@fs@post|&bottom of the float\\
779 % |\@fs@capt|&formatting routine for caption\\
780 % |\@fs@cfont|&font for caption name \& number
781 % \end{tabular}\end{center}
782 %
783 % \begin{macro}{\floatc@plain}
784 % The |\floatc@plain| macro formats a caption the way \LaTeX\ does
785 % it: if the caption is fairly short, it is centered, otherwise it is
786 % formatted as a paragraph. The only difference is that the portion
787 % containing the caption name and number uses the |\@fs@captfont|.
788 % \begin{macrocode}
789 \newcommand\floatc@plain[2]{\setbox\@tempboxa\hbox{{\@fs@cfont #1:} #2}%
790 \ifdim\wd\@tempboxa>\hsize {\@fs@cfont #1:} #2\par
791 \else\hbox to\hsize{\hfil\box\@tempboxa\hfil}\fi}
792 % \end{macrocode}
793 % \end{macro}
794 % \begin{macro}{\fs@plain}
795 % The \texttt{plain} float style is similar to what \LaTeX\ does of its
796 % own accord; the only difference is that the caption is guaranteed
797 % to come out at the bottom of the float.
798 % \changes{v1.3a}{15 Aug 2001}{Use `abovecaptionskip rather than
799 % hard-coded value}
800 % \begin{macrocode}
801 \newcommand\fs@plain{\def\@fs@cfont{\rmfamily}\let\@fs@capt\floatc@plain
802 \def\@fs@pre{}\def\@fs@post{}%
803 \def\@fs@mid{\vspace\abovecaptionskip\relax}%
804 \let\@fs@iftopcapt\iffalse}
805 % \end{macrocode}
806 % \end{macro}
807 %
808 % \begin{macro}{\fs@plaintop}
809 % The \texttt{plaintop} float style is similar to the \texttt{plain}
810 % float style except that the caption comes out at the top.
811 % \changes{v1.3}{18 Jul 2001}{Added plaintop float style}
812 % \changes{v1.3a}{15 Aug 2001}{Use `belowcaptionskip rather than
813 % hard-coded value}
814 % \begin{macrocode}
815 \newcommand\fs@plaintop{\fs@plain
816 \def\@fs@mid{\vspace\belowcaptionskip\relax}%
817 \let\@fs@iftopcapt\iftrue}
818 \let\floatc@plaintop=\floatc@plain
819 % \end{macrocode}
820 % \end{macro}
821 %
822 % \begin{macro}{\floatc@ruled}
823 % The |\floatc@ruled| command is even simpler than the
824 % |\floatc@plain| macro. The caption is simply printed `as is'.
825 % \begin{macrocode}
826 \newcommand\floatc@ruled[2]{{\@fs@cfont #1} #2\par}
827 % \end{macrocode}
828 % \end{macro}
829 %
830 % \begin{macro}{\fs@ruled}
831 % In the \texttt{ruled} float style, the caption appears at the top of the
832 % float, preceded and followed by horizontal rules.
833 % Another rule followes the whole of the float.
834 % \begin{macrocode}
835 \newcommand\fs@ruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
836 \def\@fs@pre{\hrule height.8pt depth0pt \kern2pt}%
837 \def\@fs@post{\kern2pt\hrule\relax}%
838 \def\@fs@mid{\kern2pt\hrule\kern2pt}%
839 \let\@fs@iftopcapt\iftrue}
840 % \end{macrocode}
841 % \end{macro}
842 %
843 % \begin{macro}{\fs@boxed}
844 % The \texttt{boxed} float style puts the float into a box (which is slightly
845 % larger than the usual |\textwidth|). The caption appears below
846 % the box.
847 % \changes{v1.2b}{29 Mar 95}{Fixed bug in boxed floatstyle}
848 % \begin{macrocode}
849 \newcommand\fs@boxed{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@plain
850 \def\@fs@pre{\setbox\@currbox\vbox{\hbadness10000
851 \moveleft3.4pt\vbox{\advance\hsize by6.8pt
852 \hrule \hbox to\hsize{\vrule\kern3pt
853 \vbox{\kern3pt\box\@currbox\kern3pt}\kern3pt\vrule}\hrule}}}%
854 \def\@fs@mid{\kern2pt}%
855 \def\@fs@post{}\let\@fs@iftopcapt\iffalse}
856 % \end{macrocode}
857 % \end{macro}
858 %
859 % Before we finish, we set the float style to \texttt{plain}.
860 % \begin{macrocode}
861 \floatstyle{plain}
862 % \end{macrocode}
863 % Other float styles can be added without much ado.
864 % If there are many more float styles, it should be worthwhile
865 % to invent a scheme similar to that used in Frank Mittelbach's
866 % \textsf{theorem} option in order to conserve space, i.e., put the
867 % float styles into individual files that can be loaded on demand.
868 % I would like to hear from people who define interesting
869 % float styles.
870 % \PrintChanges
871 % \Finale
872 % \end{document}
873 \endinput