%%% ==================================================================== %%% @LaTeX-style-file{ %%% filename = "float.sty", %%% version = "1.1c", %%% date = "18 December 1992", %%% time = "10:00:00 CET", %%% author = "Anselm Lingnau", %%% address = "Hochschulrechenzentrum/FB Mathematik %%% Johann Wolfgang Goethe-Universit\"at %%% Postfach 11 19 32 %%% DW-6000 Frankfurt am Main %%% Germany", %%% telephone = "+49 798 2554", %%% checksum = "56253 815 4764 35676" %%% email = "lingnau@math.uni-frankfurt.de (Internet)", %%% codetable = "ISO/ASCII", %%% keywords = "LaTeX, figure, table, floats", %%% supported = "yes", %%% docstring = " %%% %%% float.sty %%% %%% A LaTeX style option which defines a \newfloat command %%% to define new classes of floats in the spirit of \newtheorem. %%% Floats can be defined to use any of various 'float styles'. %%% float.sty also incorporates the functionality of David Carlisle's %%% here.sty, giving floats a [H] option, meaning 'do not float', %%% or 'PUT IT HERE'. %%% %%% Documentation requires Frank Mittelbach's doc.sty.", %%% } %%% ======================================================================== % % Beware of file version and date in banner at top of implementation below. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % * Version 1.1a, added here.sty functionality. % * Version 1.1b, \@Esphack in place of \@esphack. Removed spurious % * whitespace. Fixed documentation. Thanks to David Carlisle. % * Version 1.1c, \@Esphack hack for compatibility with old LaTeXes. Fixed % * checksums. Removed spurious blank line at end of file. Thanks again. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %<*x> % This file may be used without modification as a style (.sty) file. % % If you have Mittelbach's doc.sty, this file may be formatted with a % command like: % latex float.sty % % If you have the Mittelbach/Duchier/Braams docstrip utility, you may % produce a faster loading .sty file. Rename this file to: float.doc % Then run this file through *plain* TeX: % tex float.doc % This should produce the file float.sty. % If you do not have plain TeX on your system, you can trick LaTeX into % doing the work as follows: % latex \def\fmtname{plain} \input float.doc % Note that you may need to quote the arguments here to stop your % operating system treating the \ characters incorrectly. % % latex float.doc % will produce a typeset version of the documentation, as above. % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \def\plain{plain}\ifx\fmtname\plain\csname fi\endcsname \def\batchfile{float.doc} \input docstrip \preamble Do not distribute the stripped version of this file. \endpreamble \generateFile{float.sty}{t}{\from{float.doc}{}} \endinput \fi % \ifcat a\noexpand @\let\next\relax\else\def\next{% \documentstyle[float,doc]{article}\MakePercentIgnore}\fi\next % %\def\eatmodule<#1>{}\eatmodule % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % \textwidth=355pt ^^A Allow macrocode text with 72 columns % \CodelineIndex ^^A Code lines numbered % \EnableCrossrefs ^^A No Cross References % \MakeShortVerb{\|} ^^A |\foo| works like \verb+|\foo| % \CheckSum{467} % % \DoNotIndex{\@Esphack,\@Mii,\@Miv,\@cons,\@currlist,\@dblarg,\@dbldeferlist} % \DoNotIndex{\@dblfloat,\@dottedtocline,\@eha,\@esphack,\@float} % \DoNotIndex{\@floatpenalty,\@ifnextchar,\@ifundefined,\@latexerr} % \DoNotIndex{\@mkboth,\@namedef,\@nameuse,\@parboxrestore,\@spaces} % \DoNotIndex{\@starttoc,\@tempa,\@tempboxa,\@tempdima,\@warning} % \DoNotIndex{\addcontentsline,\advance,\arabic,\bf,\bgroup,\box,\chapter} % \DoNotIndex{\columnwidth,\csname,\def,\dimen,\docdate,\edef,\egroup,\else} % \DoNotIndex{\endcsname,\endinput,\expandafter,\fi,\filedate,\fileversion} % \DoNotIndex{\global,\hbadness,\hbox,\hfil,\hrule,\hsize,\ht,\if@twocolumn} % \DoNotIndex{\ifdim,\iffalse,\ifnum,\iftrue,\ifvbox,\ifx,\ignorespaces} % \DoNotIndex{\intextsep,\kern,\let,\long,\moveleft,\newbox,\newcount} % \DoNotIndex{\newcounter,\newif,\noexpand,\normalsize,\numberline,\par} % \DoNotIndex{\parindent,\penalty,\prevdepth,\protect,\refstepcounter,\relax} % \DoNotIndex{\rm,\section,\setbox,\space,\textheight,\the,\typeout,\unvbox} % \DoNotIndex{\uppercase,\vadjust,\vbox,\vrule,\vskip,\wd,\wlog,\z@} % % \title{An Improved Environment for Floats} % \author{Anselm Lingnau\thanks{Hochschulrechenzentrum/Fachbereich Mathematik, % Johann Wolfgang Goethe-Universit\"at, Postfach 11\,19\,32, % DW-6000 Frankfurt am Main. % E-Mail: {\tt lingnau@math.uni-frankfurt.de}}% % \thanks{Part of this style option is based on % {\tt here.sty} by David Carlisle ({\tt carlisle@cs.man.ac.uk}), % who also provided helpful criticism.}} % \date{8 October 1992} % \floatstyle{ruled} % \newfloat{Program}{tbp}{lop}[section] % \floatstyle{plain} % \newfloat{Example}{t}{lox}[section] % \floatstyle{boxed} % \restylefloat{table} % \begin{document} % \maketitle % % \begin{abstract} % This style option improves the interface for defining floating % objects such as figures and tables in \LaTeX{}. % It adds the notion of a `float style' that governs appearance % of floats. % New kinds of floats may be defined using a |\newfloat| command % analogous to |\newtheorem|. % This style option also incorporates the functionality % of David Carlisle's {\tt here.sty}, % giving floating environments a {\tt [H]} option which means `PUT IT HERE' % (as opposed to the standard {\tt [h]} option which means % `You may put it here if you like'). % \end{abstract} % % \section{Introduction} % % Among the features of \LaTeX\ are `floating' figures and tables % that drift from where they appear in the input text to, say, the top % of a page. The contents and formatting of floats is pretty much up % to the user, except that there is a |\caption| command that % governs formatting of the caption --- it is centered if it is short, % and formatted as a paragraph if it is longer than a single line of text. % Sometimes other types of floating objects, e.g., algorithms or programs, % are desirable, but they must be defined by analogy to the existing % floats since there is no simple command for doing this. This goes % beyond the knowledge or inclination of the average \LaTeX\ user. % % In this style option, I present an interface to floating objects % that attempts to fix some of these shortcomings. % First of all, I introduce the notion of a `float style'. % A float style governs the appearance of a class of floats like a page style % governs the appearance of a page (\LaTeX\ has page styles {\tt plain}, % {\tt empty} and {\tt headings}, among others). This style option % provides some exemplary float styles: % \begin{description} % \item[plain] This is the float style that \LaTeX\ normally applies to % its floats, i.e., nothing in particular. The only difference is % that the caption comes out {\em below\/} the body of the float, % regardless of where it is given in the text. % \item[boxed] The body of the float is printed inside a box. The caption % goes below that box. % \item[ruled] This float style is patterned on the table style of % {\sl Concrete Mathematics}. The caption is printed at the top of the % float, surrounded by rules; another rule finishes off the float. % \end{description} % % \begin{Program} % \begin{verbatim} % #include % % int main(int argc, char **argv) % { % int i; % for (i = 0; i < argc; ++i) % printf("argv[%d] = %s\n", i, argv[i]); % return 0; % } % \end{verbatim} % \caption{The first program. This hasn't got anything to do with the style % but is included as an example. Note the {\tt ruled} float style.% % \label{prog1.1}} % \end{Program} % To facilitate the definition of new floating objects, {\tt float.sty} % supports the |\newfloat| command. This command is comparable to % |\newtheorem| in that it allows the user to add a new class of floats % at the document level. No style option hacking is necessary. % There's also a |\listof| command that prints a listing of all the % floats of a given type, like |\listoffigures| and |\listoftables| % in vanilla \LaTeX. % % \section{The User Interface --- New Floats} % % \DescribeMacro{\newfloat} % The most important command in {\tt float.sty} is the |\newfloat| % command. As mentioned above, it is patterned on |\newtheorem|. % The |\newfloat| command takes three required and one optional % argument; it is of the form\\[2pt] % \hspace*{\MacroIndent}|\newfloat{|\meta{type}|}{|^^A % \meta{placement}|}{|\meta{ext}|}[|\meta{within}{\tt]}\\[2pt] % \meta{type} is the `type' of the new class of floats, like {\tt program} % or {\tt algorithm}. After the appropriate |\newfloat|, commands % like |\begin{program}| or |\end{algorithm*}| will be available. % \meta{placement} gives the default placement parameters for this class % of floats. The placement parameters are the same as in standard \LaTeX, % i.e., {\tt t}, {\tt b}, {\tt p} and {\tt h} for `top', `bottom', % `page' and `here', respectively. % When \LaTeX\ writes the captions to an auxiliary file for the list % of figures (or whatever), it'll use the job name followed by \meta{ext} % as a file name. % Finally, the optional argument \meta{within} determines whether floats % of this class will be numbered within some sectional unit of the document. % For example, if \meta{within}$=${\tt chapter}, the floats will be numbered % within chapters. (In standard \LaTeX, this happens with figures and tables % in the {\tt report} and {\tt book} document styles.) % As an example, Program~\ref{prog1.1} above was created by a command % sequence similar to that shown in the following Example. % \begin{Example}[H] % \begin{verse} % |\floatstyle{ruled}|\\ % |\newfloat{Program}{tbp}{lop}[section]|\\ % \dots\ loads o' stuff \dots\\ % |\begin{Program}|\\ % |\begin{verbatim}|\\ % \dots\ program text \dots\\ % |\end{verbatim}|\\ % |\caption{|\dots\ caption \dots|}|\\ % |\end{Program}| % \end{verse} % \caption{This is another silly floating Example. Except that this one % doesn't actually float because it uses the {\tt[H]} optional parameter % to appear {\bf Here}. (Gotcha.)} % \end{Example} % % \DescribeMacro{\floatstyle} % The |\floatstyle| command sets a default float style. This float style % will be used for all the floats that are subsequently defined using % |\newfloat|, until another |\floatstyle| command appears. % The |\floatstyle| command takes one argument, the name of a float % style. For instance, |\floatstyle{ruled}|. Specifying a string that % does not name a valid float style is an error. % % \DescribeMacro{\floatname} % The |\floatname| command lets you define the {\em float name\/} that % \LaTeX\ uses in the caption of a float, i.e., `Figure' for a figure % and so on. For example, |\floatname{program}{Program}|. % The |\newfloat| command sets the float name to its argument % \meta{type} if no other name has been specified before. % % \DescribeMacro{\floatplacement} % The |\floatplacement| command resets the default placement specifier % of a class of floats. E.g., |\floatplacement{figure}{tp}|. % % \DescribeMacro{\restylefloat} % The |\restylefloat| command is necessary to change styles for the % standard float types {\tt figure} and {\tt table}. Since these aren't % usually defined via |\newfloat|, they don't have a style associated % with them. Thus you have to say, for example,\\[2pt] % \hspace*{\MacroIndent}|\floatstyle{ruled}|\\ % \hspace*{\MacroIndent}|\restylefloat{table}|\\[2pt] % to have tables come out {\tt ruled}. The command also lets you change % style for floats that you define via |\newfloat|, although this % is, typographically speaking, not a good idea. % See table~\ref{table1} for an example. % \DeleteShortVerb{\|} % \begin{table} \def\B#1{$\displaystyle{n\choose#1}$} % \begin{center} \begin{tabular}{c|ccccc} % $n$&\B0&\B1&\B2&\B3&\B4\\ \hline % 0 & 1\\ % 1 & 1&1\\ % 2 & 1&2&1\\ % 3 & 1&3&3&1\\ % 4 & 1&4&6&4&1 % \end{tabular} \end{center} % \caption{Pascal's triangle. This is a re-styled \LaTeX\ {\tt table}.% % \label{table1}} % \end{table} % \MakeShortVerb{\|} % % \DescribeMacro{\listof} % The |\listof| command produces a list of all the floats of a given % class. Its syntax is\\[2pt] % \hspace*{\MacroIndent}|\listof{|\meta{type}|}{|\meta{title}^^A % |}|\\[2pt] % \meta{type} is the float type given in the |\newfloat| command. % \meta{title} is used for the title of the list as well as the headings % if the current page style includes them. Otherwise, the |\listof| % command is analogous to the built-in \LaTeX\ commands % |\listoffigures| and |\listoftables|. % % \section{The User Interface --- {\tt[H]} Placement Specifier} % % Many people find \LaTeX's float placement specifiers too restrictive. % A Commonly Uttered Complaint (CUC) calls for a way to place a float % exactly at the spot where it occurs in the input file, i.e., to {\em not\/} % have it float at all. % It seems that the {\tt[h]} specifier should do that, but in fact it % only suggests to \LaTeX\ something along the lines of ``put the float % here if it's OK with you''. As it turns out, \LaTeX\ hardly ever feels % inclined to actually do that. This situation can be improved by % judicious manipulation of float style parameters. % % The same effect can be achieved by changing the actual method of % placing floats. David Carlisle's {\tt here.sty} introduces a new float % placement specifier, namely {\tt[H]}, which, when added to a float, % tells \LaTeX\ to ``put it HERE, period''. If there isn't enough space % left on the page, the float is carried over to the next page together % with whatever follows, even though there might still be room left for % some of that. % This style option provides the {\tt[H]} specifier for newly defined % classes of floats as well as the predefined {\tt figure}s and % {\tt table}s, thereby superseding {\tt here.sty}. David suggests % that the {\tt here.sty} be withdrawn from the archives in due course. % % The {\tt[H]} specifier may simply be added to the float as an optional % argument, like all the other specifiers. % It may {\em not\/} be used in conjunction with any other placement % specifiers, so {\tt[Hhtbp]} is illegal. % Neither may it be used as the default placement specifier for a whole % class of floats. % The following table is % defined like this: % \begin{verse} % |\begin{table}[H]|\\ % |\begin{tabular}{cl}|\\ % |\tt t & Top of the page\\|\\ % \dots\ more stuff \dots\\ % \end{verse} % (It seems that I have to add some extraneous chatter here just so that % the float actually comes out right in the middle of a printed page. % When I \LaTeX ed the documentation just now it turned out that there % was a page break that fell exactly between the ``So now'' line and the % float. This wouldn't Prove Anything. Bother.) % So now we have the following float placement specifiers: % \begin{table}[H] % \begin{tabular}{cl} % \tt t & Top of the page\\ % \tt b & Bottom of the page\\ % \tt p & Page of floats\\ % \tt h & Here, if possible\\ % \tt H & Here, definitely % \end{tabular} % ^^A\caption{Could it be that this just needs a caption?} % \end{table} % % \typeout{End of the Introduction.} % \typein[\answer]% % {Do you want an annotated listing of the macro definitions (y/n) ?} % \def\next{y}\ifx\answer\next\else\expandafter\stop\fi % \StopEventually{\PrintIndex} % % \section{Implementation} % % As usual, the file identifies itself in the log file. % But only if this file's macros aren't yet defined. % `Old' versions of \LaTeX\ (those before March 1992) don't have |\@Esphack|. % We do an |\@esphack| hack to get around that. % \begin{macrocode} \@ifundefined{newfloat}{}{\endinput} \wlog{Style-Option: `float' 1.1c 18 Dec 92 (AL)} \@ifundefined{@Esphack}{\let\@Esphack\@esphack}{} % \end{macrocode} % In \LaTeX, floats are assigned `type numbers' that are powers of two. % Since there are only two classes of floats, their type numbers are % hardwired into the document styles. We need to be somewhat more flexible, % and thus we initialize a counter to hold the next type number to be % assigned. This counter will be incremented appropriately later. % \begin{macrocode} \newcount\float@type \@ifundefined{c@figure}{\float@type=1}{\float@type=4} % \end{macrocode} % To warm up, we'll look at some of the simpler commands first. % \begin{macro}{\floatstyle} % The |\floatstyle| command puts its argument into the % |\float@style| macro as the name of the new float style. % But if the argument doesn't denote a float style, an error message % is output instead: Each float style \meta{style} has a corresponding command % |\fs@|\meta{style} that contains the appropriate declarations. % If the control sequence |\fs@|\meta{arg} (which goes with the % argument \meta{arg} to |\floatstyle|) is undefined, i.e., % equals |\relax| under |\ifx|, then the float style \meta{arg} % is unknown, and we call |\float@error{|\meta{arg}|}| for the % error message. % \begin{macrocode} \def\floatstyle#1{\expandafter\ifx\csname fs@#1\endcsname\relax \float@error{#1}\else\def\float@style{#1}\fi} % \end{macrocode} % \end{macro} % \begin{macro}{\float@error} % Here's the error message. |\@eha| is the help message that says % `Your command was ignored.' % \begin{macrocode} \def\float@error#1{\@latexerr{Unknown float style `#1'}\@eha} % \end{macrocode} % \end{macro} % % The next two commands are even simpler. \LaTeX\ says that % |\fps@|\meta{float} contains the default placement specifier for % the class of floats \meta{float}. |\fname@|\meta{float} expands % to the name that appears in \meta{float} captions, e.g., `Figure'. % (This is our own definition.) % \begin{macrocode} \def\floatname#1#2{\@namedef{fname@#1}{#2}} \def\floatplacement#1#2{\@namedef{fps@#1}{#2}} % \end{macrocode} % % \begin{macro}{\restylefloat} % The |\restylefloat| command sets up everything so that subsequent % commands like |\begin{|\meta{float}|}| use the appropriate % float style. It defines |\fst@|\meta{float} to expand to a command % that sets up the currently selected float style (|\fs@|\meta{style}). % Then it defines the commands |\begin{|\meta{float}|}|, % |\end{|\meta{float}|}|, |\begin{|\meta{float}|*}| and % |\end{|\meta{float}|*}|. % \begin{macrocode} \def\restylefloat#1{\expandafter\edef\csname fst@#1\endcsname{\expandafter\noexpand\csname fs@\float@style\endcsname}% \@namedef{#1}{\bgroup\@nameuse{fst@#1}\@float{#1}}% \@namedef{#1*}{\bgroup\@nameuse{fst@#1}\@dblfloat{#1}}% \expandafter\let\csname end#1\endcsname\float@end \expandafter\let\csname end#1*\endcsname\float@dblend} % \end{macrocode} % \end{macro} % % \begin{macro}{\newfloat} % Now we can explain how to define a new class of floats. Recall that % the three required arguments to |\newfloat| are \meta{type}, % \meta{placement} and \meta{ext}, respectively. First we save the % latter two. % \begin{macrocode} \def\newfloat#1#2#3{\@namedef{ext@#1}{#3} \floatplacement{#1}{#2}% % \end{macrocode} % Then we figure out a default value for the `caption name' of this % class of floats. If the |\fname@|\meta{type} isn't already defined, % we tentatively use \meta{type} as the name. This is convenient if % \meta{type} is, say, {\tt Program}, since no |\floatname| command % is necessary at all. % \begin{macrocode} \expandafter\ifx\csname fname@#1\endcsname\relax \floatname{#1}{#1}\fi % \end{macrocode} % Then we set up the type number for \LaTeX\ in |\ftype@|\meta{type}. % Afterwards we have to set the |\float@type| to the next greater power % of two, so that it is ready for the next |\newfloat|. Fortunately, % we just have to double it by adding. We don't bother to check for overflow % since it is pretty unlikely that somebody will define 25 different classes % of floats. Finally, we call |\restylefloat| to define the style and % commands for this class of floats. % \begin{macrocode} \expandafter\edef\csname ftype@#1\endcsname{\the\float@type}% \advance\float@type by\float@type \restylefloat{#1}% % \end{macrocode} % Now all that's left is to assemble the |\fnum@|\meta{type} macro % that \LaTeX\ wants to use in its captions. Basically it is just % `caption name'${}+{}$`counter value', disguised so that the command % {\em names\/} appear in the definition instead of their expansions. % \begin{macrocode} \expandafter\edef\csname fnum@#1\endcsname% {\expandafter\noexpand\csname fname@#1\endcsname{} \expandafter\noexpand\csname the#1\endcsname} % \end{macrocode} % Finally, we have to take care of the optional argument, \meta{within}. % If the optional argument is present, we pass control to |\@xnewfloat|. % Otherwise, we just define the counter for this class of floats. % By default, the numbers come out |\arabic|. % \begin{macrocode} \@ifnextchar[{\@xnewfloat{#1}}% {\@ifundefined{c@#1}{\newcounter{#1}\@namedef{the#1}{\arabic{#1}}}% {}}} % \end{macrocode} % \end{macro} % % \begin{macro}{\@xnewfloat} % Here we deal with the optional argument to |\newfloat|. We have % to create a new counter as per |\newcounter{|\meta{type}|}| % and add that counter to the list of counters to be reset whenever % counter \meta{within} is stepped. The standard command % |\newcounter{|\meta{type}|}[|\meta{within}{\tt]} takes care of that. % However, we can't define the \meta{type} counter if it's already defined. % While this case is simply ignored when \meta{within} is not present, % we issue a warning here since what comes out is probably not what the user % expects. % \begin{macrocode} \def\@xnewfloat#1[#2]{\@ifundefined{c@#1}{\newcounter{#1}[#2]% \expandafter\edef\csname the#1\endcsname{% \expandafter\noexpand\csname the#2\endcsname.\noexpand\arabic{#1}}}% {\@warning{Can't redefine counter variable for #1.}}} % \end{macrocode} % \end{macro} % % We have to adapt some of \LaTeX's internal macros to our needs. % There are several things that have to be changed around % in order to provide the functionality of David Carlisle's {\tt here.sty}. % The following is thus lifted from {\tt here.sty}, with changes and with % David's permission: % % \begin{macro}{\@Hxfloat} % We save the original version of |\@xfloat|. (This macro is called from % |\@float|, which we used above to define the environment commands for a % new class of floats.) % \begin{macrocode} \let\@Hxfloat\@xfloat % \end{macrocode} % \end{macro} % \begin{macro}{\@xfloat} % The new version of |\@xfloat| looks for a |[H]| argument. % If it is present |\@HHfloat| is called, otherwise the original macro % (renamed to |\@Hxfloat|) is called. % \begin{macrocode} \def\@xfloat#1[{\@ifnextchar{H}{\@HHfloat{#1}[}{\@Hxfloat{#1}[}} % \end{macrocode} % \end{macro} % Later on we'll need a box to save a |[H]| float. % \begin{macrocode} \newbox\float@box \newif\if@flstyle % \end{macrocode} % \begin{macro}{\@HHfloat} % First gobble the |[H]|. Note that {\tt H} should not be used in % conjunction with the other placement options, nor as the value of the % default placement, as set in |\fps@|{\it type}. % \begin{macrocode} \def\@HHfloat#1[H]{% % \end{macrocode} % Locally redefine the end of the environment. % \begin{macrocode} \expandafter\let\csname end#1\endcsname\float@endH % \end{macrocode} % We don't get a |\@currbox| if we don't actually use the float mechanism. % Therefore we fake one using the |\float@box| defined above. % \begin{macrocode} \let\@currbox\float@box % \end{macrocode} % Now we save the current float class name for use in constructing the % |\caption|. The caption box (defined below) is initialised to an empty % box to avoid trouble with floats not having a caption. Then we start the % box that'll hold the float itself. % |\parindent| is set to zero for compatibility with the standard {\tt [h]} % option. % \begin{macrocode} \def\@captype{#1}\setbox\@floatcapt=\vbox{}% \expandafter\ifx\csname fst@#1\endcsname\relax \@flstylefalse\else\@flstyletrue\fi \setbox\@currbox=\vbox\bgroup\parindent\z@ % \end{macrocode} % The final |\ignorespaces| is needed to gobble any spaces or newlines % after the {\tt[H]} tokens. % \begin{macrocode} \ignorespaces} % \end{macrocode} % \end{macro} % % \begin{macro}{\float@makebox} % Basically, we must arrange for `style commands' to be executed % at certain points during the generation of the float. % \LaTeX\ puts a float into a vertical box |\@currbox| which it takes % off a list of empty boxes for insertions. When the |\float@makebox| macro % is called, |\@currbox| contains the complete float, minus the caption % --- we'll see later that we use our own |\caption| command to % put the caption into a |\vbox| of its own. This is the only way % we can control the position of the caption by the float style, % regardless of where the caption appears in the float's input text itself. % So the `style commands' are |\@fs@pre|, which is inserted at the % very beginning of the float, |\@fs@mid|, which comes between the % float and the caption (or the caption and the float, if captions are put % at the top), and |\@fs@post|, which finishes off the float. % The caption may appear at the top or at the bottom of the float, % as defined by |\@fs@iftopcapt|. Therefore, before we hand the % float to \LaTeX\ for positioning, it is taken apart and reassembled % using the style commands. % \begin{macrocode} \def\float@makebox{% \vbox{\hsize\columnwidth \@parboxrestore \@fs@pre\@fs@iftopcapt \ifvbox\@floatcapt\unvbox\@floatcapt\par\@fs@mid\fi \unvbox\@currbox \else\unvbox\@currbox \ifvbox\@floatcapt\par\@fs@mid\unvbox\@floatcapt\fi \fi\par\@fs@post\vskip\z@}} % \end{macrocode} % \end{macro} % \begin{macro}{\float@end} % The internal macro |\end@float| appears here under the name of |\float@end|. % The main thing which is changed is that we call |\float@makebox| to % reconstruct the float according to the float style. % \begin{macrocode} \def\float@end{\egroup \global\setbox\@currbox\float@makebox % \end{macrocode} % Now \LaTeX\ takes over again. % \begin{macrocode} \ifnum\@floatpenalty <\z@ \@cons\@currlist\@currbox \ifdim \ht\@currbox >\textheight \ht\@currbox\textheight \fi \ifnum\@floatpenalty < -\@Mii \penalty -\@Miv \@tempdima\prevdepth \vbox{}\prevdepth \@tempdima \penalty\@floatpenalty \else \vadjust{\penalty -\@Miv \vbox{}\penalty\@floatpenalty}\@Esphack \fi\fi\egroup} % \end{macrocode} % (The final |\egroup| is not present in the original definition; % we need it to finish off the |\bgroup| that precedes the % |\@nameuse| in the |\begin{|\meta{float}|}| commands. % This is to keep the style commands local.) % \end{macro} % % \begin{macro}{\float@endH} % The |\float@endH| command is, again, derived from {\tt here.sty}. It'll % deal correctly with a non-floating float, inserting the proper amounts % of white space above and below. % \begin{macrocode} \def\float@endH{\egroup \vskip\intextsep \if@flstyle\float@makebox\else\box\@currbox\fi \vskip\intextsep\egroup} % \end{macrocode} % \end{macro} % % \begin{macro}{\float@dblend} % The |\float@dblend| macro is an almost-verbatim copy of % |\end@dblfloat| but for the last part, from |\fi\egroup| on. % The |\egroup| is, of course, necessary because of the |\bgroup| % at the very beginning of the float. And we have to call |\float@end| % instead of |\end@float|, naturally. % \begin{macrocode} \def\float@dblend{\if@twocolumn \par\vskip\z@\egroup \ifnum\@floatpenalty <\z@ \@cons\@dbldeferlist\@currbox\fi \ifnum \@floatpenalty =-\@Mii \@Esphack\fi\egroup\else\float@end\fi} % \end{macrocode} % \end{macro} % % Now for the caption routines. % We use a box, |\@floatcapt|, to hold the caption while the float % is assembled. % \begin{macrocode} \newbox\@floatcapt % \end{macrocode} % % \begin{macro}{\caption} % This is the only \LaTeX\ macro that this document style supersedes. % Our |\caption| command checks whether there is a custom style % defined for the current float (whose type can be found in |\@captype|). % If so, the caption routines from {\tt float.sty} are used, otherwise % we call the vanilla \LaTeX\ routines. % The |\@flcapt| conditional is used to tell the float-assembly routines % that there actually {\em is\/} a caption. We need this to properly handle % {\tt figure}s and {\tt table}s that have been restyled. % \begin{macrocode} \def\caption{\refstepcounter\@captype \expandafter\ifx\csname fst@\@captype\endcsname\relax \let\@tempf\@caption \else\let\@tempf\float@caption\fi \@dblarg{\@tempf\@captype}} % \end{macrocode} % \end{macro} % % \begin{macro}{\float@caption} % The |\float@caption| macro takes care of entering the caption into % the appropriate listing. It also controls the typesetting of the caption % itself, although a style-dependent macro |\@fs@capt| is called % to handle the specifics. Note that because the caption is saved in a box % instead of being output to the float right away, you cannot simply put % a legend after the caption proper; it has to follow the |\caption| % command in an optional argument. % % First of all, we call |\addcontentsline| to update the list of % floats of this class. Note that |\float@caption| is |\long| % to allow for paragraph breaks in its arguments. % \begin{macrocode} \long\def\float@caption#1[#2]#3{\addcontentsline{\csname ext@#1\endcsname}{#1}{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}} % \end{macrocode} % Now we collect the caption proper. The caption name and number are % taken from |\fnum@|\meta{float}, where \meta{float} is the class % of float we're currently handling. % \begin{macrocode} \global\setbox\@floatcapt\vbox\bgroup\@parboxrestore \normalsize\@fs@capt{\csname fnum@#1\endcsname}{\ignorespaces #3}% % \end{macrocode} % Finally we check for the presence of the optional argument. If there is % one, we call |\float@ccon| to pick it up; otherwise, the |\egroup| % finishes off the box. % \begin{macrocode} \@ifnextchar[{\float@ccon}{\egroup}} % \end{macrocode} % \end{macro} % % \begin{macro}{\float@ccon} % The |\float@ccon| macro expands to the optional argument of a % |\caption| command, followed by |\par\egroup|. Note that this % precludes using |\verb| \& Co.\ in the optional argument; the % interested reader is urged to fix this problem as an exercise. % \begin{macrocode} \long\def\float@ccon[#1]{#1\par\egroup} % \end{macrocode} % \end{macro} % % \begin{macro}{\listof} % The |\listof| command reads the desired list of floats from the % appropriate auxiliary file. The file is then restarted. % Currently the list appears at the chapter or the section level, depending % on whether chapters are supported in the document style at all. % First of all, we check whether the float style that's supposed to be % listed is actually defined. If not, we output a |\float@error|. % \begin{macrocode} \def\listof#1#2{\expandafter\ifx\csname ext@#1\endcsname\relax\float@error{#1}% % \end{macrocode} % All's well until now. We determine whether the list is going to be a % chapter or a section, and we define the |\l@|\meta{float} command % that \LaTeX\ needs for formatting the list. % After that, we call |\@starttoc| with the correct file extension % to do the actual work. % \begin{macrocode} \else \@ifundefined{chapter}{\def\@tempa{\section*}}% {\def\@tempa{\chapter*}}% \@tempa{#2\@mkboth{\uppercase{#2}}{\uppercase{#2}}}% \expandafter\def\csname l@#1\endcsname{\@dottedtocline{1}{1.5em}{2.3em}}% \@starttoc{\csname ext@#1\endcsname}\fi} % \end{macrocode} % \end{macro} % % \section{The Float Styles} % % Finally, we define the three standard float styles that were outlined % in the Introduction. Every float style \meta{style} corresponds to a % command |\fs@|\meta{style} which contains the definitions of the % style commands, namely % \begin{center}\begin{tabular}{rl} % |\@fs@pre|&top of the float\\ % |\@fs@mid|&between float and caption\\ % |\@fs@post|&bottom of the float\\ % |\@fs@capt|&formatting routine for caption\\ % |\@fs@cfont|&font for caption name \& number % \end{tabular}\end{center} % % \begin{macro}{\floatc@plain} % The |\floatc@plain| macro formats a caption the way \LaTeX\ does % it: if the caption is fairly short, it is centered, otherwise it is % formatted as a paragraph. The only difference is that the portion % containing the caption name and number uses the |\@fs@captfont|. % \begin{macrocode} \def\floatc@plain#1#2{\setbox\@tempboxa\hbox{{\@fs@cfont #1:} #2}% \ifdim\wd\@tempboxa>\hsize {\@fs@cfont #1:} #2\par \else\hbox to\hsize{\hfil\box\@tempboxa\hfil}\fi} % \end{macrocode} % \end{macro} % \begin{macro}{\fs@plain} % The {\tt plain} float style is similar to what \LaTeX\ does of its % own accord; the only difference is that the caption is guaranteed % to come out at the bottom of the float. % \begin{macrocode} \def\fs@plain{\def\@fs@cfont{\rm}\let\@fs@capt\floatc@plain \def\@fs@pre{}\def\@fs@post{}\def\@fs@mid{\vskip10pt\relax}% \let\@fs@iftopcapt\iffalse} % \end{macrocode} % \end{macro} % % \begin{macro}{\floatc@ruled} % The |\floatc@ruled| command is even simpler than the % |\floatc@plain| macro. The caption is simply printed `as is'. % \begin{macrocode} \def\floatc@ruled#1#2{{\@fs@cfont #1} #2\par} % \end{macrocode} % \end{macro} % % \begin{macro}{\fs@ruled} % In the {\tt ruled} float style, the caption appears at the top of the % float, preceded and followed by horizontal rules. % Another rule followes the whole of the float. % \begin{macrocode} \def\fs@ruled{\def\@fs@cfont{\bf}\let\@fs@capt\floatc@ruled \def\@fs@pre{\hrule height.8pt depth0pt \kern2pt}% \def\@fs@post{\kern2pt\hrule\relax}% \def\@fs@mid{\kern2pt\hrule\kern2pt}% \let\@fs@iftopcapt\iftrue} % \end{macrocode} % \end{macro} % % \begin{macro}{\fs@boxed} % The {\tt boxed} float style puts the float into a box (which is slightly % larger than the usual |\textwidth|). The caption appears below % the box. % \begin{macrocode} \@namedef{fs@boxed}{\def\@fs@cfont{\bf}\let\@fs@capt\floatc@plain \def\@fs@pre{\dimen0=\hsize \advance\dimen0 by6.8pt \hbadness10000 \moveleft3.4pt\vbox\bgroup\hsize=\dimen0\hrule \hbox to\dimen0\bgroup\vrule\kern3pt\vbox\bgroup\kern3pt}% \def\@fs@mid{\kern3pt\egroup\kern3pt\vrule\egroup \hrule\egroup\kern2pt}% \def\@fs@post{}\let\@fs@iftopcapt\iffalse} % \end{macrocode} % \end{macro} % % Before we finish, we set the float style to {\tt plain}. % \begin{macrocode} \floatstyle{plain} % \end{macrocode} % Other float styles can be added without much ado. % If there are many more float styles, it should be worthwhile % to invent a scheme similar to that used in Frank Mittelbach's % {\tt theorem} option in order to conserve space, i.e., put the % float styles into individual files that can be loaded on demand. % I would like to hear from people who define interesting % float styles. % \Finale % \end{document} \endinput