% \iffalse
%%
%% (C) Copyright 1999-2000 Frank Mittelbach, David Carlisle, Chris Rowley
%% All rights reserved.
%%
%% Not for general distribution. In its present form it is not allowed
%% to put this package onto CD or an archive without consulting the
%% the authors.
%% 
% \fi
%
%
%    \begin{macrocode}
\def\@tempa#1: #2.dtx,v #3 #4 #5 #6 #7${
  \ProvidesPackage{#2}[#4 #3 #5 #6]}
\@tempa$Id: xo-final.dtx,v 1.20 2000/08/11 07:14:09 latex3 Exp $
%    \end{macrocode}
%
%    \begin{macrocode}
\IgnoreWhiteSpace
%    \end{macrocode}
%
%    Update: as of April 3 this now does something reasonable with
%    top and bottom floats.  The text in between still needs lots of
%    attention.  No headers/footers/margins/overlays etc etc yet.
%
%    There is still a lot of inefficient indirection; this shows where we
%    may be able to support more general page-makeup systems.
%
%    And not much tracing yet.
%
%    \subsection{Text columns}
%    
% \begin{macro}{\produce@final@column}
% \begin{macro}{\final@column@with@floats}
% \begin{macro}{\final@column}
%
% This version puts column floats in columns; see below for
% an alternative.  It simulates current \LaTeX{} so should not be
% taken as a model for anything useful.
%
% When we remove or modernise this a lot more code from below can go
% too. 
% 
%    \begin{macrocode}
\def\final@column@with@floats {
%<*trace>
  \@tracepush{produce@final@column}
%</trace>
   \setbox\@outputbox \box\@cclv

   \expandafter
   \add@floats@top
      \csname area@t1\the\curr@col@count\endcsname

   \ifvoid\footins
   \else
     \setbox\@outputbox \vbox {
       \boxmaxdepth \@maxdepth
       \dimen@\dp\@outputbox
       \unvbox \@outputbox
       \vskip-\dimen@
       \vskip \skip\footins
       \color@begingroup
         \normalcolor
         \footnoterule
         \unvbox \footins
       \color@endgroup
      }
   \fi

   \expandafter
   \add@floats@bottom 
      \csname area@b1\the\curr@col@count\endcsname

   \global\setbox\csname col@box@\the\curr@col@count\endcsname
          % \vbox { % this should one day become \@colht
          \vbox { % this should one day become \@colht
                                % or else
           \@texttop
           \dimen@ \dp\@outputbox
           \unvbox \@outputbox
           \vskip -\dimen@
           \@textbottom
           }%
   \global \maxdepth \@maxdepth
%<*trace>
  \@tracepop{produce@final@column}
%</trace>
}
%    \end{macrocode}
%   This version does not give special treatment to column floats; it
%   simply attachs footnotes and tops/tails.
%
%   Probably this should just stuff the main text and footnotes into
%   boxes (or a box?) with no extra formatting; all aesthetic handling would
%   be done later, when the page is being made-up.  
%
%   The formatting details are clearly temporary.
%   
%    \begin{macrocode}
\def\final@column {
%<*trace>
  \@tracepush{produce@final@column}
%</trace>
   \setbox\@outputbox \box\@cclv

   \ifvoid\footins
   \else
     \setbox\@outputbox \vbox {
       \boxmaxdepth \@maxdepth
       \dimen@\dp\@outputbox
       \unvbox \@outputbox
       \vskip-\dimen@
       \vskip \skip\footins
       \color@begingroup
         \normalcolor
         \footnoterule
         \unvbox \footins
       \color@endgroup
      }
   \fi

%    \end{macrocode}
%
%   I am not sure if texttop/bottom should survive for long: something
%   more spohisictaed is needed these days.  This may mean that
%   footnotes need better handling too: what makes a complex column
%   look good?
%
%    \begin{macrocode}
   \global\setbox\csname col@box@\the\curr@col@count\endcsname
          \vbox { % this should one day become \@colht
                                % or else
           \@texttop
           \dimen@ \dp\@outputbox
           \unvbox \@outputbox
           \vskip -\dimen@
           \@textbottom
           }%
   \global \maxdepth \@maxdepth
%<*trace>
  \@tracepop{produce@final@column}
%</trace>
}
\let \produce@final@column \final@column
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\add@floats@top}
% \begin{macro}{\add@floats@bottom}
%  These are now used (if at all)
%  only within columns (maybe not best even there).
%  
%    \begin{macrocode}
\def\add@floats@top #1{
  \ifx#1\@empty
  \else
    \setbox\@tempboxa \vbox{}
    \let \@elt \@comflelt #1
    \setbox\@outputbox \vbox{
                             \boxmaxdepth \maxdepth
                             \unvbox\@tempboxa
                             \vskip -\pagesetup@float@float@sep
                             \topfigrule
                             \vskip \pagesetup@float@text@sep
                             \unvbox\@outputbox
                             }
    \let\@elt\relax
    \release@floats#1
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\add@floats@bottom#1{
  \ifx#1\@empty
  \else
    \setbox\@tempboxa \vbox{}
    \let\@elt\@comflelt
      #1
    \setbox\@outputbox \vbox{
                             \unvbox\@outputbox
                             \vskip \pagesetup@float@text@sep
                             \botfigrule
                             \unvbox\@tempboxa
                             \vskip -\pagesetup@float@float@sep
                             }
    \let\@elt\relax
    \release@floats#1
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
%
%    \subsection{Shipout and housekeeping}
%
%
% \begin{macro}{\absolute@page@number}
%    \begin{macrocode}
\mathchardef\absolute@page@number\c@page
%    \end{macrocode}
% \end{macro}
% 
%    \begin{macrocode}

%    \end{macrocode}
%    
% \begin{macro}{\produce@final@page}
% 
%    This puts everything to be shipped out into the hbox
%    |\page@box| and then ships this out (not quite, see below!).
%
%    Probably these two processes should be separated.
%    
%    At present it does the page-makeup within the shipped out box;
%    this should proably be done earlier.
%
%    Should the box (or the box-name) be a global
%    fixed object (bad;-) or a local parameter (good;-)?
%    
%    The shipping out is surrounded by considerable housekeeping:
%    this version sets up to do the writes and fixes the
%    numbering.
%
%    \begin{macrocode}
\def\produce@final@page{
%<*trace>
  \@tracepush{produce@final@page}
  \tr@ce{final~ page~ output:~ Chris'~ version}
%</trace>
  \begingroup           % the \endgroup is put in by \aftergroup
%    \end{macrocode}
%    
%    \begin{macrocode}
    \@resetactivechars
    \@parboxrestore
    \let \protect \noexpand
%    \end{macrocode}%    
%    Temp: just puts stuff into lists (which could have been built up
%    as floats are placed?).
%    \begin{macrocode}
    \do@floats  
    \shipout \hbox {        % NOTE: an hbox now!  
%    \end{macrocode}
%    
%    \begin{macrocode}
      \set@typeset@protect
      \aftergroup \endgroup
      \aftergroup \set@typeset@protect
%    \end{macrocode}
%    Making the box can be done outside the shipout.
%    \begin{macrocode}
       \make@page@box
       \box \page@box
    }
% \endgroup  %% This is _implicitly_ here.
%    \end{macrocode}
%    
%    \begin{macrocode}
  \count@\absolute@page@number
%<*trace>
  \tr@ce{absolute~page:~\the\absolute@page@number}
%</trace>
  \advance\count@\@ne
  \global\advance\c@page\@ne
  \global\mathchardef\absolute@page@number\count@
%<*trace>
  \@tracepop{produce@final@page}
%</trace>
}

%    \end{macrocode}
% \end{macro}
%
%    \subsection{The page box}
%    
% \begin{macro}{\mbox@addtopage}
% \begin{macro}{\box@addtopage}
% \begin{macro}{\page@box}
%  This should be generalised to add a box to any box (without overcrowding).
%    \begin{macrocode}
\newbox \page@box
\def\mbox@addtopage (#1,#2)#3{%
%<*trace>
  \tr@ce{box~being~added~to~page:~at~(#1,~#2)
        }
%</trace>
  \global \setbox\page@box
    \hbox {
      \unhbox \page@box
      \mbox@put  (#1,#2) {#3}
    }
}
\def\box@addtopage (#1,#2)#3{%
  \mbox@addtopage (#1,#2){\box #3}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\make@page@box}
%
% This adds stuff to a globallly named box; maybe it should be more
% generic.
% 
% This is some kind of default example.
% It should be templated. 
% 
%    \begin{macrocode}
\def \make@page@box {
%<*trace>
  \@tracepush{make@page@box}
  \tr@ce{new style page nake-up}
%</trace>
%    \end{macrocode}
%    Temp for current header:
%    \begin{macrocode}
    \mbox@addtopage (\pagebodylefthpos, \headheight)
       {page:~\thepage}
%    \end{macrocode}
%    Then add the float areas, using a list of boxes and positions.
%    Probably, the whole thing should be done this way but this may
%    not be sensible for simple cases.
%
%    Also, some alignments (eg text) may be better handled by the
%    use of coffins (which are a very similar, but more complex,
%    technology).
%
%    First set-up starting point for main text body.
%    \begin{macrocode}
  \forall@columns {
    \expandafter \xdef
      \csname stack@level@\the\curr@col@count \endcsname
        {\pagebodytopvpos}
  }
  \stack@top@areas
  \add@columns
  \stack@bot@areas
%<*trace>
  \@tracepop{make@page@box}
%</trace>
}
%    \end{macrocode}
% \end{macro}
%
%    
%    \subsection{The page box: text columns}
%
%    This needs to be a lot more sophisticated in order to make these
%    look anything but dreadful.
%    
% \begin{macro}{\add@columns}
% \begin{macro}{\add@columns@topstacked}
% \begin{macro}{\add@columns@botaligned}
% 
%    Several possibilities here: choose one.
% 
%    One way to do bottom-aligned columns (probably will not
%    generalise well):
%    \begin{macrocode}
\def \add@columns@botaligned {
%<*trace>
  \@tracepush{add@columns@botaligned}
%</trace>
  \setlength \@tempdima {\pagebodylefthpos} 
  \forall@columns {
%<*trace>
  \tr@ce{bot~aligned~column~\the\curr@col@count :~%
             ht=\expandafter\the\expandafter\ht
                \csname col@box@\the\curr@col@count \endcsname,~
             dp=\expandafter\the\expandafter\dp
                \csname col@box@\the\curr@col@count \endcsname}
%</trace>
%    \end{macrocode}
%    Rules will need to be handled separately: where do they go in
%    general with spanning floats?
%    \begin{macrocode}
%          \vrule
    \box@addtopage ( \@tempdima, \pagebodybotvpos )
          {\csname col@box@\the\curr@col@count \endcsname}
        \setlength \@tempdima {\@tempdima + \columnwidth + \columnsep} 
%          \vrule
  }
%<*trace>
  \@tracepop{add@columns@botaligned}
%</trace>
}
%    \end{macrocode}
%
%    Stacking them at the top: this must be dome immediately after
%    stacking the top areas.  They are aligned, if possible, at the
%    top (the actual top, not necessarily the top text line).
%    
%    \begin{macrocode}
\def \add@columns@topstacked {
%<*trace>
  \@tracepush{add@columns@topstacked}
%</trace>
  \gsetmlength \cuur@col@pos {\pagebodylefthpos} 
  \forall@columns {
%<*trace>
  \tr@ce{top~stacked~column~\the\curr@col@count :~%
             ht=\expandafter\the\expandafter\ht
                \csname col@box@\the\curr@col@count \endcsname,~
             dp=\expandafter\the\expandafter\dp
                \csname col@box@\the\curr@col@count \endcsname}
  \tr@ce{vsize~for~column~\the\curr@col@count~was:~%
                \csname col@ht@ \the\curr@col@count\endcsname}
  \tr@ce{lowered~column~\the\curr@col@count~:~%
                      \csname stack@level@\the\curr@col@count \endcsname
                      }
%</trace>
  \gsetmlength@c {stack@level@\the\curr@col@count}
    { \csname stack@level@\the\curr@col@count \endcsname
      + \expandafter
        \ht \csname col@box@\the\curr@col@count \endcsname
    }
%    \end{macrocode}
%    Vertical rules will need to be handled differentlyy:
%    where do they go in general with spanning floats?
%    \begin{macrocode}
%          \vrule
    \box@addtopage (  \cuur@col@pos,
                     \csname stack@level@\the\curr@col@count \endcsname )
          {\csname col@box@\the\curr@col@count \endcsname}
        \gsetmlength  \cuur@col@pos { \cuur@col@pos + \columnwidth + \columnsep} 
%          \vrule
    }
%<*trace>
  \@tracepop{add@columns@topstacked}
%</trace>
}
\let \add@columns \add@columns@topstacked
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% 
%    \subsection{The page box: float areas}
%    
% \begin{macro}{\t@stack@area}
% \begin{macro}{\b@stack@area}
%
%  The 4th argument must be a procedure that fills a box whose number
%  is its last argument.  This rather bizarre code merely avoids
%  a box-register-per-area.
%
%    \begin{macrocode}
\def\t@stack@area #1#2#3#4{
%<*trace>
  \@tracepush{t@stack@area}
%</trace>
  #4 \@tempboxa
%    \end{macrocode}
%    First update stacking position for these columns.
%    \begin{macrocode}
 \@tempcnta #2 
 \@tempcntb #3 \relax
  \setlength \@tempdimb {\ht\@tempboxa + \dp\@tempboxa}
  \loop
    \@tempdima \csname stack@level@\the\@tempcntb \endcsname 
    \advance \@tempdima \@tempdimb
    \expandafter
    \xdef \csname stack@level@\the\@tempcntb \endcsname 
      { \the\@tempdima }
  \advance \@tempcntb \@ne
  \advance \@tempcnta \m@ne
  \ifnum \@tempcnta  > \z@
  \repeat
%    \end{macrocode}
% Calculate horizontal displacement.
%    \begin{macrocode}
  \setlength \@tempdima
    {\pagebodylefthpos - \columndisplacement + \columndisplacement * #3}
%    \end{macrocode}
% Add box.
%    \begin{macrocode}
%<*trace>
  \tr@ce{float~area~box~#1#2#3~~lowered~:~%
                      \csname stack@level@#3 \endcsname
                      }
%</trace>
  \box@addtopage (\@tempdima,\csname stack@level@#3\endcsname)
                 \@tempboxa
%<*trace>
  \@tracepop{t@stack@area}
%</trace>
}
%    \end{macrocode}
%    Different order for co-stacking.
%    \begin{macrocode}
\def\b@stack@area #1#2#3#4{
%<*trace>
  \@tracepush{b@stack@area}
%</trace>
  #4 \@tempboxa
%    \end{macrocode}
% Calculate horizontal displacement.
%    \begin{macrocode}
  \setlength \@tempdima
    {\pagebodylefthpos - \columndisplacement + \columndisplacement * #3}
%    \end{macrocode}
% Add box.
%    \begin{macrocode}
  \box@addtopage (\@tempdima,\csname stack@level@#3\endcsname)
                 \@tempboxa
%    \end{macrocode}
%    Then update stacking position for these columns.
%    \begin{macrocode}
 \@tempcnta #2
 \@tempcntb #3 \relax
  \setlength \@tempdimb {\ht\@tempboxa + \dp\@tempboxa}
  \loop
    \@tempdima \csname stack@level@\the\@tempcntb \endcsname 
    \advance \@tempdima -\@tempdimb
    \expandafter
    \xdef \csname stack@level@\the\@tempcntb \endcsname 
      { \the\@tempdima }
  \advance \@tempcntb \@ne
  \advance \@tempcnta \m@ne
  \ifnum \@tempcnta > \@ne
  \repeat
%<*trace>
  \@tracepop{b@stack@area}
%</trace>
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\stack@top@areas}
% \begin{macro}{\stack@bot@areas}
%
% Use of these is all a bit ad hoc for a particular stacking system.
%
%    \begin{macrocode}
\def \stack@bot@areas {
  \stack@areas@list b \pagebodybotvpos \pagebox@list@b
}
\def \stack@top@areas {
  \stack@areas@list t \pagebodytopvpos \pagebox@list@t
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\stack@areas@list}
% 
%    |#1| : stacking type (t, b or c at present)\\
%    |#2| : starting position\\
%    |#3| : list name
%    
%    \begin{macrocode}
\def \stack@areas@list #1#2#3 {
%<*trace>
  \@tracepush{stack@areas@list}
%</trace>
  \ifx #3 \@empty
  \else
    \forall@columns {
%    \end{macrocode}
%    Starting point:
%    \begin{macrocode}
%          \vrule
    \expandafter \xdef
      \csname stack@level@\the\curr@col@count \endcsname
        {#2}
    }
%    \end{macrocode}
%    Stacking or co-stacking: bottom-up or top-down.
%    \begin{macrocode}
  \expandafter
  \let \expandafter
      \p@elt \csname #1@stack@area \endcsname
        #3
  \fi
%<*trace>
  \@tracepop{stack@areas@list}
%</trace>
}
%    \end{macrocode}
% \end{macro}
%
% 
% \begin{macro}{\make@area@floats@box}
%
% Format all the floats in a list and store the result in a box register.
% This should be templated.
%
% This could do the file-writing too.
% 
%    |#1| : area-name\\
%    |#2| : box to be filled
%    
%    \begin{macrocode}
\def\make@area@floats@box #1#2 {
%<*trace>
  \@tracepush{make@area@floats@box}
%</trace>
  \setbox #2 \vbox{}
%  \let \@elt \@comflelt  % Big aaah!
  \def \@elt { \typeset@float@in@box {#2} }
    \csname area@#1\endcsname
%    \end{macrocode}
%    Not very pretty yet!  But better when decoration
%    stuff is used.
%    \begin{macrocode}
  \let \@elt \relax
  \expandafter
  \release@floats
    \csname area@#1\endcsname
%<*trace>
  \@tracepop{make@area@floats@box}
%</trace>
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{DECORATIONS}
%  Not used at present but something like this is probably needed.
%  
%    \begin{macrocode}
    
\def \box@decorate@bot #1 {
    \setbox #1 \vbox{
                             \vskip \pagesetup@float@text@sep
                             \botfigrule
                             \unvbox #1
                             \vskip -\pagesetup@float@float@sep
    }
}
\def \box@decorate@top #1 {
    \setbox #1 \vbox{
                             \unvbox #1
                             \vskip -\pagesetup@float@float@sep
                             \topfigrule
                             \vskip \pagesetup@float@text@sep
    }
}


%    \end{macrocode}
% \end{macro}
%
%    
%    \subsection{The page box: margins}
%
%    Needed?
% 
%    \subsection{The page box: headers and footers}
%
%    Nothing worth puting here yet.
%    
%    \subsection{The page box: other}
%
%    Maybe should be many subsections: eg overlays.
%    
% \subsection{Typesetting captions and float boxes}
%
% All more or less temporary.
% 
% \begin{macro}{\@comflelt}
% \begin{macro}{\typeset@float@in@box}
% 
% Maybe a bad name but this is probably as generic as it can be at
% present (and one would hate to see the name's demise).
% 
%    \begin{macrocode}
\def\@comflelt #1 {
  \global \let \this@float@box #1
  \expandafter
  \extract@this@float@actual@structure \the\toks #1
  \setbox\@tempboxa \vbox {
    \unvbox\@tempboxa
    \typeset@this@float@and@caption
    }
  }
%    \end{macrocode}
%
%    Thus sadly we maybe should move to this, avoiding the use of a
%    global variable for parameter passing.
%    
%    \begin{macrocode}
\def\typeset@float@in@box #1 #2 {
  \global \let \this@float@box #2
  \expandafter
  \extract@this@float@actual@structure \the\toks #2
  \setbox #1 \vbox {
    \unvbox #1
    \typeset@this@float@and@caption
    }
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%    
% \begin{macro}{\typeset@this@float@and@caption}
% 
% This should really be a template instance.
%
% It must be integrated with the generic version of
% |\append@caption@to@float| since they must both do the same thing.
% 
% May use |\this@area|, |\this@area@col@number| and other information,
% to be determined \ldots even |\this@caption@action|.
%
% First we disable premature captioning (fascist or what?).
% 
%    \begin{macrocode}
%<*obsolete>
\let\add@caption@to@float@box \relax
%</obsolete>

%<*obsolete>
\def \typeset@this@float@and@caption {
  \box\this@float@box
  \nobreak
  \smallskip
  \hsize\columnwidth
  \this@caption \par
  \bigskip
  \hrule
  \vskip\pagesetup@float@float@sep
  }
% Reminder ABOVE ONLY WORKS WITH THIS:
% \def\append@caption@to@float{
%   \global\setbox\this@captioned@float\vbox{
%   \copy\this@float@box
%   \smallskip
%   \hsize\columnwidth
%   \this@caption
%   \par\bigskip\hrule}
% }
%</obsolete>
%    \end{macrocode}
% \end{macro}
%
%    \subsection{Page box lists}
%    
% \begin{macro}{\pagebox@area}
% \begin{macro}{\@addto@pagebox@list}
%
%  Bad names?
% 
%  Add the float areas to a page-box list, and specify how to
%  process them.  This should be templated. The columns could be added
%  to this list.
%
%  The 2nd argument must at present be a procedure that has two
%  arguments and it is expected to fill a box whose number
%  is its last argument.  This rather bizarre code merely avoids
%  a box-register-per-area.
%
%    |#1| : area-name
%    |#2| : action for each float in area
%    |#3| : area-position
%    
%    \begin{macrocode}
\def\pagebox@area #1#2#3 {
%<*trace>
  \@tracepush {pagebox@area}
%</trace>
  \expandafter
  \let \expandafter
    \this@list \csname area@#1\endcsname
%<*trace>
  \tr@ce{adding~ floats~ (if any)~ #1~  ==~ `\this@list'~
         to~page~list:~#3 }
%</trace>
  \ifx \this@list \@empty
  \else
    \let \p@elt \relax    
    \@addto@pagebox@list {#3}
      { \p@elt #1 { #2 {#1}} }
  \fi
%<*trace>
  \@tracepop {pagebox@area}
%</trace>
}
%    \end{macrocode}
% Ugh!!  Improve?
%    \begin{macrocode}
\def \@addto@pagebox@list #1#2 {
  \@temptokena \expandafter\expandafter\expandafter
    { \csname pagebox@list@#1 \endcsname
      #2
    }
 \expandafter
  \xdef
    \csname pagebox@list@#1 \endcsname
      { \the\@temptokena }
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% 
%
%    \subsection{Magic boxes}
%    
% \begin{macro}{\mbox@put}
% \begin{macro}{\box@put}
% \begin{macro}{\copy@put}
%
% Probably move sometime.\footnote{Move?}
% 
% These add boxes with the specified visual relative position
% but all-zero dimensions (unlike picture mode where the inner
% boxes have non-zero vertical size).  A highly generalised lap-box!
% 
% At present these use Don Knuth's left-handed DVI co-ordinate
% system.  They could (should?) be changed to a saner system as used
% by \LaTeX{}, Postscript and the rest of the known civilised world
% since Descartes.
% 
%    \begin{macrocode}
\def\mbox@put (#1,#2)#3{%
  \setbox\@tempboxa \hbox {
%   \raise #2                              % Ugh!  Zany y-direction---
      \lower #2                            %   thanks Don!
        \hbox {\kern#1 #3\hss}
      }
%    \end{macrocode}
% For this application we must zero everything. 
%    \begin{macrocode}
  \wd \@tempboxa \z@
  \ht \@tempboxa \z@
  \dp \@tempboxa \z@
  \box\@tempboxa
  }
%    \end{macrocode}
%    
%    \begin{macrocode}
\def\box@put (#1,#2)#3{%
  \mbox@put (#1,#2) {\box #3}
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\copy@put (#1,#2)#3{
  \mbox@put (#1,#2) {\copy #3}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Move me!}
% 
% Stuff for elsewhere; maybe to xo-new right now?
% 
% \begin{macro}{\forall@areas}
% \begin{macro}{\def \make@useful@list@aux}
% \begin{macro}{\def \make@useful@list}
% Area list stuff\footnote{Probably move.}.
% 
% These should be more generally used/available whatever area lists,
%  however impemnted, we end up with.
%
%  This list manipulation stuff works only for lists whose elements are
%   unexpandable; this could be extended.
%    \begin{macrocode}
\def \forall@areas #1 {
  \def \area@elt ##1##2##3 {
  \def \curr@area {##1##2##3}
  \def \curr@pos {##1}
  \def \curr@col {##3}
  \def \curr@span {##2}
  #1
  }
  \used@areas@exec
}

\def \make@useful@list@aux #1#2#3 {
  \ifx #1 \relax
  \else
    \expandafter
    \xdef \csname \temp@list@name @exec \endcsname
      {\csname \temp@list@name @exec \endcsname \temp@list@elt #1#2#3 }
  \expandafter
       \make@useful@list@aux 
  \fi
}
\def \make@useful@list #1 #2 {
  \edef \temp@list@name
    {\expandafter \@gobble \string #1}
  \def \temp@list@elt {#2}
  \let #2 \relax
  \expandafter
  \let \csname \temp@list@name @exec \endcsname \@empty
  \expandafter
  \make@useful@list@aux #1\relax\relax\relax
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    
% \begin{macro}{\release@floats}
%
%    \begin{macrocode}
\def\release@floats#1{
% \show #1
   \xdef \@freelist {\@freelist#1}
   \global\let#1\@empty
}
%    \end{macrocode}
% \end{macro}
%
% More helper functions (some not yet used)\footnote{To be moved}.
%
% Lettings.
% 
% \begin{macro}{\let@nc}
% \begin{macro}{\let@cn}
% \begin{macro}{\let@cc}
%    \begin{macrocode}
\def \let@nc #1 #2 {
  \expandafter
  \let \expandafter
      #1 \csname #2\endcsname
}    
\def \let@cn #1 {
  \expandafter
  \let \csname #1\endcsname
}    
\def \let@cc #1 {
  \expandafter
  \let@nc \csname #1\endcsname
}    
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% Macrised lengths etc.
% 
% \begin{macro}{\setmlength}
% \begin{macro}{\gsetmlength}
%    \begin{macrocode}
\def \gsetmlength #1#2  {
    \setlength \@tempdima {#2}  
  \xdef #1 {\the\@tempdima}
} 
\def \gsetmlength@c #1#2  {
    \setlength \@tempdima {#2}
    \expandafter
    \xdef \csname #1\endcsname
      {\the\@tempdima}
}
\def \setmlength #1#2  {
    \setlength \@tempdima {#2}  
  \edef #1 {\the\@tempdima}
} 
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Really temp stuff}
% 
% \begin{macro}{TEMP@KLUDGES}
% Some very temporary (very bad) examples and kludges:
%    \begin{macrocode}
\def \do@floats {
%<*trace>
  \@tracepush{do@floats}
%</trace>
  \make@useful@list \used@areas \area@elt 
  \let  \pagebox@list@t \@empty
  \let  \pagebox@list@b \@empty
  \forall@areas {
    \expandafter
    \pagebox@area
      \expandafter
      {\curr@area} \make@area@floats@box  {\curr@pos}
  }
%<*trace>
  \tr@ce{
    pagebox~list:~t~ is~\meaning \pagebox@list@t}
  \tr@ce{
    pagebox~list:~b~ is~\meaning \pagebox@list@t}
  \@tracepop{do@floats}
%</trace>
}

%    \end{macrocode}
%    
%  Temp place for these calcs. They should be part of the page layout
%  set-up.\footnote{Move?}  
%  Temp positioning stuff:
%    \begin{macrocode}
\AtBeginDocument {
%% vert
  \setlength \@tempdima {\headheight + \headsep}  
  \xdef \pagebodytopvpos {\the\@tempdima}

  \setlength \@tempdima {\@tempdima + \textheight}  
  \xdef \pagebodybotvpos {\the\@tempdima}

%% horiz
  \setlength \@tempdima {\columnwidth + \columnsep}
  \xdef \columndisplacement {\the\@tempdima}

  \def \pagebodylefthpos {\z@}  % or whatever?)

%  \show \pagebodytopvpos
%  \show \pagebodybotvpos
% 
%  \showthe \headheight
%  \showthe \headsep
%  \showthe \textheight
%  \showthe \textwidth
%  \showthe \columnwidth
}

%    \end{macrocode}
%    \end{macro}
%
% \endinput
\endinput
%
% $Log: xo-final.dtx,v $
% Revision 1.20  2000/08/11 07:14:09  latex3
% added header
%
% Revision 1.19  2000/07/19 15:56:46  latex3
% removed \extract@this@float@actual@structure (is now in xo-or awaiting
% normalisation with similar commands)
%
% Revision 1.18  2000/07/10 18:46:11  latex3
% mainly macro renamings
%
% Revision 1.17  2000/06/16 11:20:40  latex3
% rename \construct@and@test@col@height to \construct@and@test@col@ht
% rename \construct@and@test@col@heights to \construct@and@test@col@hts
% rename \cl@height1 to \@col@ht@1 (etc)
%
% Revision 1.16  2000/06/13 21:17:32  latex3
% move setting of \protect so that it works
%
% Revision 1.15  2000/04/12 20:52:39  car2
% Much tidyng: farewell comflelt!
%
% Revision 1.14  2000/04/06 22:14:00  car2
% added caption setting
%
% Revision 1.13  2000/04/03  12:09:28  car2
% alpha version
%
% Revision 1.12  2000/04/03 10:59:31  car2
% Untidy alpha
%
% Revision 1.11  2000/03/30 21:06:28  car2
% Chris' alpha-minus version
%
% Revision 1.10  2000/03/24 15:34:27  latex3
% version that starts supporting spans (still a hack yet)
%
% Revision 1.9  2000/03/22 15:29:42  latex3
% some normalisations of names
%
% Revision 1.8  2000/03/09 14:44:31  latex3
% *** empty log message ***
%
% Revision 1.7  2000/03/05 19:38:12  latex3
% support multiple columns (6 max right now)
%
% Revision 1.6  2000/02/26 18:25:10  david
% release floats changes
%
% Revision 1.5  2000/02/16  17:34:31  latex3
% bit of extra tracing to find why columns do not align (no good :-)
%
% Revision 1.4  2000/02/16  13:39:47  latex3
% added 3col support
%
% Revision 1.3  2000/02/16  10:19:03  latex3
% better code for adding floats to column (using \pagesetup@float@text@sep and friends)
%
% Revision 1.2  2000/02/13  22:28:10  latex3
% moved some stuff from xo-or.sty to this file
%
