%D \module
%D   [       file=page-flt,
%D        version=2000.10.20,
%D          title=\CONTEXT\ OTR Macros,
%D       subtitle=Floating Bodies, 
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{Context OTR Macros / Floating Bodies} 

\unprotect

% naar supp-box.tex

\def\voidbox{\box\voidb@x}

\def\spreadhbox#1% rebuilds \hbox{<box><hss><box><hss><box>}  
  {\bgroup
   \ifhbox#1\relax
     \setbox2=\voidbox
     \unhbox#1% 
     \doloop
       {\unpenalty\unskip\unpenalty\unskip\unpenalty\unskip
        \setbox0=\lastbox
        \ifvoid0
          \exitloop
        \else
          \setbox2=\hbox
            {\ifhbox0 \spreadhbox0\else\box0\fi
             \ifvoid2 \else\hss\unhbox2\fi}%
        \fi}%
     \ifvoid2\else\unhbox2\fi
   \else
     \box#1%
   \fi
   \egroup}

\def\placefloats{\doflushfloats}  % keep this one 

\startmessages  dutch  library: floatblocks
  title: plaatsblokken
      1: -- hernummerd / -- => --
      2: -- bewaard
      3: -- verplaatst
      4: -- geplaatst
      5: volgorde aangepast
      6: maximaal -- boven
      7: maximaal -- onder
      8: minder dan -- regels
      9: volgorde verstoord
     10: -- begrensd
     11: geen blok opgegeven
     12: niet gedefinieerd
\stopmessages

\startmessages  english  library: floatblocks
 title: floatblocks
      1: -- renumbered / -- => --
      2: -- saved
      3: -- moved
      4: -- placed
      5: order adapted
      6: n of top floats limited to --
      7: n of bottom floats limited to --
      8: less than -- lines
      9: order disturbed
     10: -- limited
     11: no block given
     12: undefined
\stopmessages

\startmessages  german  library: floatblocks
 title: Gleitobjektbloecke
      1: -- neu nummeriert / -- => --
      2: -- gespeichert
      3: -- verschoben
      4: -- plaziert
      5: Reihenfolge angepasst
      6: Anz. der oberen Gleitobjekte beschraengt auf --
      7: Anz. der unteren Gleitobjekte beschraengt auf  --
      8: weniger als -- zeilen
      9: Reigenfolge gestoert
     10: -- begrenzt
     11: kein Block gegeben
     12: undefiniert
\stopmessages

\startmessages  czech  library: floatblocks
 title: plovouciobjekty
      1: -- precislovano / -- => --
      2: -- ulozeno
      3: -- presunuto
      4: -- umisteno
      5: poradi prizpusobeno
      6: pocet hornich plovoucich objektu je omezen na --
      7: pocet spodnich plovoucich objektu je omezen na --
      8: radku je mene nez --
      9: poradi naruseno
     10: -- omezeno
     11: nedan zadny blok
     12: nedefinovano
\stopmessages

\startmessages  italian  library: floatblocks
 title: oggetti mobili
      1: -- rinumerato / -- => --
      2: -- salavto
      3: -- mosso
      4: -- sistemato
      5: ordine aggiustato
      6: n di top floats limitato a --
      7: n di bottom floats limitato a --
      8: meno di -- righe
      9: ordine disturbato
     10: -- limitato
     11: nessun oggetto specificato
     12: non definito
\stopmessages

\startmessages  norwegian  library: floatblocks
 title: flytblokker
      1: -- renummerert / -- => --
      2: -- lagret
      3: -- flyttet
      4: -- plassert
      5: rekkef�lge tilpasset
      6: maksimalt -- flytblokker �verst
      7: maksimalt -- flytblokker nederst
      8: mindre enn -- linjer
      9: rekkef�lge endret
     10: -- begrenset
     11: ingen blokk oppgitt
     12: udefinert
\stopmessages

\startmessages  romanian  library: floatblocks
 title: Blocuri
      1: -- renumerotat / -- => --
      2: -- salvat
      3: -- mutat
      4: -- plasat
      5: ordinea adaptata
      6: nr. cadrelor de sus limitat la  --
      7: nr. blocurilor de jos limitat la --
      8: mai putin de -- linii
      9: ordinea deranjata
     10: -- limitat
     11: nu este dat nici un bloc
     12: nedefinit
\stopmessages

\def\stelplaatsblokkenin%
  {\dodoubleargument\getparameters[\??bk]}

\def\stelblokkopjesin%
  {\dodoubleargument\getparameters[\??kj]}%

\def\dostelplaatsblokin[#1][#2]%
  {\getparameters[\??fl#1][#2]}

\def\stelplaatsblokin%
  {\dodoubleargument\dostelplaatsblokin}

\def\dostelblokkopjein[#1][#2]%
  {\getparameters[\??kj#1][#2]}

\def\stelblokkopjein%
  {\dodoubleargument\dostelblokkopjein}

\def\doleegblok#1%
  {\localframed
      [\??fl#1][\c!kader=\v!aan]%
      {\getmessage{\m!floatblocks}{12}}}

\def\docomplexplaatsblok[#1][#2][#3]#4%
  {\flushfootnotes
   \ifmargeblokken
     \doifinset{\v!marge}{#2}
       {\bgroup
        \everypar{\egroup\the\everypar}%
        \hsize=\@@mbbreedte}%
   \fi
   \global\insidefloattrue
   \dowithnextboxcontent
     {\postponefootnotes} % new 
     {\docompletefloat
        {#1}{#3}{#1}{#2}{#1}{#4}
        {\box\nextbox}}%
   \vbox}

\def\docomplexstarttekstblok[#1][#2][#3]%
  {\flushfootnotes
   \flushsidefloats % hoort eigenlijk niet hier
   \docomplexplaatsblok[#1][\v!tekst,#2,\v!links][#3]}

\def\docomplexreserveerblok[#1][#2][#3][#4]#5%
  {\getvalue{\e!plaats#1}[#3][#4]{#5}{\localframed[\??fl#1][#2]{#1}}}

\def\docomplexstartreserveertekstblok[#1][#2][#3][#4]%
  {\flushsidefloats % hoort eigenlijk niet hier
   \docomplexreserveerblok[#1][#2][\v!tekst,#3,\v!links][#4]}

\def\dodefinieerplaatsblok[#1][#2]%        #1=naam  #2=meervoud
  {\presetlocalframed[\??fl#1]%
   \stelplaatsblokin
     [#1]
     [\c!breedte=15\korpsgrootte,
      \c!hoogte=10\korpsgrootte,
      \c!kader=\@@bkkader,
      \c!straal=\@@bkstraal,
      \c!hoek=\@@bkhoek,
      \c!plaats=\@@bkplaats,
      \c!achtergrond=\@@bkachtergrond,
      \c!achtergrondraster=\@@bkachtergrondraster,
      \c!achtergrondkleur=\@@bkachtergrondkleur,
      \c!achtergrondoffset=\@@bkachtergrondoffset,
      \c!bovenkader=\@@bkbovenkader,
      \c!onderkader=\@@bkonderkader,
      \c!linkerkader=\@@bklinkerkader,
      \c!rechterkader=\@@bkrechterkader,
      \c!kaderoffset=\@@bkkaderoffset,
      \c!paginaovergangen=]%
   \stelblokkopjein
     [#1]
     [\c!plaats=\@@kjplaats,
      %\c!voor=\@@kjvoor,
      \c!tussen=\@@kjtussen,
      %\c!na=\@@kjna,
      \c!breedte=\@@kjbreedte,
      \c!kopletter=\@@kjkopletter,
      \c!letter=\@@kjletter,
      \c!kleur=\@@kjkleur,
      \c!uitlijnen=\@@kjuitlijnen,
      \c!nummer=\@@kjnummer,
      \c!wijze=\@@kjwijze,
      \c!blokwijze=\@@kjblokwijze,
      \c!sectienummer=\@@kjsectienummer,
      \c!conversie=\@@kjconversie]%
   \doorlabelen
     [#1]
     [\c!tekst=#1,
      \c!plaats=\v!intekst,
      \c!wijze=\getvalue{\??kj#1\c!wijze},
      \c!blokwijze=\getvalue{\??kj#1\c!blokwijze},
      \c!sectienummer=\getvalue{\??kj#1\c!sectienummer},
      \c!conversie=\getvalue{\??kj#1\c!conversie}]%
   \presetlabeltext[#1=\Word{#1}~]%
   \presetheadtext[#2=\Word{#2}]%
   \definieerlijst[#1]%
   \setvalue{\e!plaats\e!lijstmet#2}%
     {\dodoubleempty\doplaatslijst[#1]}%
   \setvalue{\e!volledige\e!lijstmet#2}%
     {\dotripleempty\dodovolledigelijst[#1][#2]}%
   \setvalue{\e!plaats#1}%
     {\dotripleempty\docomplexplaatsblok[#1]}%
   \setvalue{\e!reserveer#1}%
     {\doquadrupleempty\docomplexreserveerblok[#1]}%
   \setvalue{\e!start#1\e!tekst}%
     {\dotripleempty\docomplexstarttekstblok[#1]}%
   \setvalue{\e!stop#1\e!tekst}%
     {\dostoptextfloat}%
   \setvalue{\e!start\e!reserveer#1\e!tekst}%
     {\doquadrupleempty\docomplexstartreserveertekstblok[#1]}%
   \setvalue{\e!stop\e!reserveer#1\e!tekst}%
     {\dostoptextfloat}%
   \setvalue{\e!lege#1}%
     {\doleegblok{#1}}%
   \setvalue{\e!leeg#1}%
     {\doleegblok{#1}}}

\def\definieerplaatsblok%
  {\dodoubleargument\dodefinieerplaatsblok}

% De onderstaande macro's zijn verantwoordelijk voor het plaatsen
% van floats. De macro's moeten nog worden aangepast en
% uitgebreid:
%
% -  nofloatpermitted : top, bot en mid counters en geen topins
%    als reeds midfloat of botfloat
%
% -  links, rechts, midden als niet hangend

\newif\ifsomefloatwaiting     \somefloatwaitingfalse
\newif\ifroomforfloat         \roomforfloattrue
\newif\ifnofloatpermitted     \nofloatpermittedfalse

\newcount\totalnoffloats      \totalnoffloats =0
\newcount\savednoffloats      \savednoffloats =0
\newcount\noffloatinserts     \noffloatinserts=0

\newbox\floatlist
\newbox\savedfloatlist

%newinsert\topins 
\newinsert\botins  
\newinsert\lowins % below footnotes  

\skip \botins=\zeropoint    \skip \lowins=\zeropoint
\count\botins=\!!thousand   \count\lowins=\!!thousand
\dimen\botins=\maxdimen     \dimen\lowins=\maxdimen

\newdimen\topinserted \topinserted=\zeropoint
\newdimen\botinserted \botinserted=\zeropoint

\newif\ifflushingfloats \flushingfloatsfalse

\newbox\floattext

\newdimen\floattextwidth
\newdimen\floattextheight

\newbox\floatbox
\newbox\savedfloatbox

\newdimen\floatwidth
\newdimen\floatheight

% Er wordt bij \v!altijd als dat nodig is hernummerd.
% Daarbij wordt gebruik gemaakt van de opgeslagen nummers en
% volgorde.

\definetwopasslist{\s!float}

\def\dofloatreference%
  {\doglobal\increment\numberedfloat
   \edef\dodofloatreference%
     {\writeutilitycommand%
        {\twopassentry%
           {\s!float}%
           {\numberedfloat}%
           {\hetnummer}}}%
   \dodofloatreference}

\def\redofloatorder#1%
  {\doglobal\increment\nofplacedfloats\relax
   \gettwopassdata{\s!float}%
   \iftwopassdatafound
     \doifnot{\hetnummer}{\twopassdata}
       {\edef\oldhetnummer{\hetnummer}%
        \xdef\hetnummer{\twopassdata}%
        \showmessage
          {\m!floatblocks}{1}
          {\nofplacedfloats,#1 \oldhetnummer,\hetnummer}}%
   \fi}

% In \dofloatinfomessage wordt {{ }} gebruikt omdat anders
% binnen \startuitstellen...\stopuitstellen geen goede
% melding in de marge volgt: \ifinner is dan namelijk true.

\def\dofloatinfomessage#1#2#3%
  {\bgroup
   \showmessage{\m!floatblocks}{#2}{#3}%
   \@EA\floatinfo\@EA#1\@EA{\currentmessagetext}%
   \egroup}

\def\dosavefloatinfo%
  {\dofloatinfomessage{>}{2}{\the\totalnoffloats}}

\def\dofloatflushedinfo%
  {\bgroup
   \!!counta=\totalnoffloats
   \advance\!!counta by -\savednoffloats
   \dofloatinfomessage{<}{3}{\the\!!counta}%
   \egroup}

\def\doinsertfloatinfo%
  {\dofloatinfomessage{<}{4}{\the\totalnoffloats}}

% ook voetnoten saven

% \def\dogetfloat%
%   {\ifsomefloatwaiting
%      \global\setbox\floatlist=\vbox
%        {\unvbox\floatlist
%         \global\setbox\globalscratchbox=\lastbox}%
%      \setbox\floatbox=\box\globalscratchbox % local !
%      \global\advance\savednoffloats by -1\relax
%      \ifnum\savednoffloats=0
%        \global\somefloatwaitingfalse
%      \fi
%    \else
%      \global\savednoffloats=0
%      \global\setbox\floatbox=\box\voidb@x
%    \fi}
% 
% \def\dosavefloat%
%   {\global\setbox\floatlist=\vbox
%      {\nointerlineskip
%       \box\floatbox
%       \unvbox\floatlist}%
%    \global\advance\savednoffloats by 1
%    \global\somefloatwaitingtrue
%    \dosavefloatinfo
%    \nonoindentation}
% 
% \def\doresavefloat%
%   {\global\setbox\floatlist=\vbox
%      {\nointerlineskip
%       \unvbox\floatlist
%       \box\floatbox}%
%    \global\advance\savednoffloats by 1
%    \global\somefloatwaitingtrue}
% 
% \def\doreversesavefloat%
%   {\global\setbox\floatlist=\vbox
%      {\nointerlineskip
%       \unvbox\floatlist
%       \box\floatbox}%
%    \global\advance\savednoffloats by 1
%    \global\somefloatwaitingtrue
%    \dosavefloatinfo}

% \def\Xdogetfloat%
%   {\ifcase\savednoffloats\global\somefloatwaitingfalse\fi 
%    \ifsomefloatwaiting
%      \global\setbox\floatlist=\vbox
%        {\unvbox\floatlist
%         \global\setbox\globalscratchbox=\lastbox}%
%      \global\advance\savednoffloats by -1
%      \global\setbox\floatbox=\box\globalscratchbox
% %     \ifnum\savednoffloats=0
% %       \global\somefloatwaitingfalse
% %     \fi
%    \else
%      \global\savednoffloats=0
%      \global\setbox\floatbox=\box\voidb@x
%    \fi}

\def\dogetfloat%
  {\ifsomefloatwaiting
     \global\setbox\floatlist=\vbox
       {\unvbox\floatlist
        \global\setbox\globalscratchbox=\lastbox}%
     \ifcenterfloatbox
       \ifdim\wd\globalscratchbox<\hsize
         \setbox\floatbox=\hbox to \hsize{\hss\box\globalscratchbox\hss}%
       \else
         \setbox\floatbox=\box\globalscratchbox % local !
       \fi
     \else
       \setbox\floatbox=\box\globalscratchbox % local !
     \fi
     \global\advance\savednoffloats by -1\relax
     \ifnum\savednoffloats=0
       \global\somefloatwaitingfalse
     \fi
   \else
     \global\savednoffloats=0
     \global\setbox\floatbox=\box\voidb@x
   \fi}

\def\uncenteredfloatbox%
  {\ifcenterfloatbox
     \ifhbox\floatbox\relax % remove centering 
       \ifdim\wd\floatbox=\hsize
         \ifhbox\floatbox
           \setbox\scratchbox=\hbox
             {\unhbox\floatbox
              \unskip\unskip
              \global\setbox\globalscratchbox=\lastbox}%
           \box\globalscratchbox
         \else
           \box\floatbox
         \fi
       \else
         \box\floatbox
       \fi
     \else
       \box\floatbox
     \fi
   \else
     \box\floatbox
   \fi}

\def\dosavefloat%
  {\global\setbox\floatlist=\vbox
     {\nointerlineskip
      \uncenteredfloatbox
      \unvbox\floatlist}%
   \global\advance\savednoffloats by 1
   \global\somefloatwaitingtrue
   \dosavefloatinfo
   \nonoindentation}

\def\doresavefloat%
  {\global\setbox\floatlist=\vbox
     {\nointerlineskip
      \unvbox\floatlist
      \uncenteredfloatbox}%
   \global\advance\savednoffloats by 1
   \global\somefloatwaitingtrue}

\def\doreversesavefloat%
  {\global\setbox\floatlist=\vbox
     {\nointerlineskip
      \unvbox\floatlist
      \uncenteredfloatbox}%
   \global\advance\savednoffloats by 1
   \global\somefloatwaitingtrue
   \dosavefloatinfo}

\def\dosavefloatstatus%
  {\global\setbox\savedfloatlist=\copy\floatlist
   \global\setbox\savedfloatbox =\copy\floatbox
   \xdef\dorestorefloatstatus%
     {\global\setbox\floatlist=\box\savedfloatlist
      \global\setbox\floatbox =\box\savedfloatbox
      \savednoffloats=\the\savednoffloats}}
 
\let\dorestorefloatstatus\relax

\def\checkwaitingfloats#1%
  {\ifsomefloatwaiting
     \doifinsetelse{\v!altijd}{#1}
       {\showmessage{\m!floatblocks}{5}{}}
       {\doflushfloats}%
   \fi}

\ifx\doflushfloats\undefined \let\doflushfloats\relax \fi
\ifx\flushfloatbox\undefined \let\flushfloatbox\relax \fi

\newif\iftopofinsert 
\newif\iftestfloatbox 
\newif\ifcenterfloatbox \centerfloatboxtrue

% beter de laatste skip buiten de \insert uitvoeren,
% bovendien bij volle flush onder baseline.

\def\betweenfloatblanko% assumes that \@@bknawit is present
  {\bgroup
   \setbox0=\vbox{\strut\blanko[\@@bkvoorwit]\strut}%
   \setbox2=\vbox{\strut\blanko[\@@bknawit]\strut}%
   \ifdim\ht0>\ht2
     \blanko[-\@@bknawit,\@@bkvoorwit]
   \fi
   \egroup}

\def\doplacefloatbox%
  {%\forgetall % NJET!
   \witruimte
   \blanko[\@@bkvoorwit]
   \flushfloatbox
   \blanko[\@@bknawit]}

\ifx\someherefloat\undefined \let\someherefloat\doplacefloatbox \fi
\ifx\somefixdfloat\undefined \let\somefixdfloat\doplacefloatbox \fi
\ifx\somepagefloat\undefined \let\somepagefloat\doplacefloatbox \fi
\ifx\sometopsfloat\undefined \let\sometopsfloat\doplacefloatbox \fi
\ifx\somebotsfloat\undefined \let\somebotsfloat\doplacefloatbox \fi

\ifx\somesidefloat\undefined \let\somesidefloat\doplacefloatbox \fi
\ifx\somefacefloat\undefined \let\somefacefloat\doplacefloatbox \fi
\ifx\sometextfloat\undefined \let\sometextfloat\doplacefloatbox \fi

\def\somepagefloat[#1]%  links, rechts, midden, hoog, midden, laag
  {\checkwaitingfloats{#1}%
   \global\setbox\collectedpagefloats=\vbox
     {\unvbox\collectedpagefloats
      \vbox to \teksthoogte
        {\doifnotinset{\v!hoog}{#1}{\vfill}
         \box\floatbox
         \doifnotinset{\v!laag}{#1}{\vfill}}
      \goodbreak}%
   \doinsertfloatinfo}

\def\sometextfloat[#1]%  lang, links, rechts, hoog, midden, laag, offset
  {\checkwaitingfloats{#1}%
   \def\dostoptextfloat{\dodostoptextfloat[#1]}%
   \global\floattextwidth=\hsize
   \global\floatwidth=\wd\floatbox
   \global\floatheight=\ht\floatbox % forget about the depth
   \global\advance\floattextwidth by -\floatwidth
   \global\advance\floattextwidth by -\@@bkmarge\relax % was \tfskipsize
   \doifinsetelse{\v!lang}{#1}
     {\floattextheight=\pagegoal
      \advance\floattextheight by -\pagetotal
      \advance\floattextheight by -\bigskipamount     % lelijk
      \ifdim\floattextheight>\teksthoogte
        \floattextheight=\teksthoogte
      \fi
      \boxmaxdepth=\zeropoint \relax            % toegevoegd
      \ifdim\floattextheight<\floatheight
        \floattextheight=\floatheight
      \fi
      \setbox\floattext=\vbox to \floattextheight}
     {\setbox\floattext=\vbox}%
   \bgroup
   \forgetall\stelblankoin\stelwitruimtein % new, also needed for footnotes
   \blanko[\v!blokkeer]
   \hsize\floattextwidth
   \ignorespaces}

\def\dodostoptextfloat[#1]%
  {\egroup
   \doifnotinset{\v!lang}{#1}%
     {\ifdim\ht\floattext<\floatheight
        \floattextheight=\floatheight
      \else
        \floattextheight=\ht\floattext
      \fi}%
   \setbox\floatbox=\vbox to \floattextheight
     {\hsize\floatwidth
      \doifinsetelse{\v!beide}{#1}%
        {\doifinsetelse{\v!laag}{#1}
           {\vfill\box\floatbox}
           {\doifinsetelse{\v!midden}{#1}
              {\vfill\box\floatbox\vfill}
              {\box\floatbox\vfill}}}
        {\box\floatbox\vfill}}%
    \setbox\floattext=\vbox to \floattextheight
     {\hsize\floattextwidth
      \doifinsetelse{\v!laag}{#1}
        {\vfill
         \box\floattext
         \doifinset{\c!offset}{#1}{\witruimte\blanko}}
        {\doifinsetelse{\v!midden}{#1}
           {\vfill
            \box\floattext
            \vfill}
           {\doifinset{\v!offset}{#1}{\witruimte\blanko}%
            \box\floattext
            \vfill}}}%
   \doifinsetelse{\v!rechts}{#1}%
     {\setbox\floatbox=\hbox to \hsize
        {\box\floattext
         \hfill
         \box\floatbox}}
     {\setbox\floatbox=\hbox to \hsize
        {\box\floatbox
         \hfill
         \box\floattext}}%
   \baselinecorrection
   \witruimte
   \blanko[\@@bkvoorwit]%
   \doifnotinset{\v!lang}{#1}%
     {\dp\floatbox=\openstrutdepth}% dp\strutbox}%      % toegevoegd
   \box\floatbox
   \blanko[\@@bknawit]%
   \doinsertfloatinfo}

\def\somefacefloat[#1]%  links, rechts, midden, hoog, midden, laag
  {\checkwaitingfloats{#1}%
   \startnaast\box\floatbox\stopnaast
   \doinsertfloatinfo}

\def\someelsefloat[#1]%
  {\doifinsetelse{\v!hier}{#1}
     {\doifinsetelse{\v!altijd}{#1}
        {\pagina[\v!voorkeur]%
         \docheckiffloatfits
         \ifroomforfloat
           \placesomeherefloat[#1]%
         \else
           \showmessage{\m!floatblocks}{9}{}%
           \doreversesavefloat
         \fi}
        {\ifsomefloatwaiting
           \dosavefloat
         \else
           \pagina[\v!voorkeur]%
           \docheckiffloatfits
           \ifroomforfloat
             \placesomeherefloat[#1]%
           \else
             \dosavefloat
           \fi
         \fi}}
     {\doifinsetelse{\v!altijd}{#1}
        {\docheckiffloatfits
         \ifroomforfloat
           \processallactionsinset
             [#1]
             [   \v!boven=>{\placesometopsfloat[#1]},
                 \v!onder=>{\placesomebotsfloat[#1]},
               \s!unknown=>{\placesomeherefloat[#1]},
               \s!default=>{\placesomeherefloat[#1]}]%
         \else
           \showmessage{\m!floatblocks}{9}{}%
           \doreversesavefloat
         \fi}
        {\docheckiffloatfits
         \ifroomforfloat
           \processallactionsinset
             [#1]
             [  \v!boven=>{\placesometopsfloat[#1]},
                \v!onder=>{\placesomebotsfloat[#1]},
              \s!unknown=>{\placesomeherefloat[#1]},
              \s!default=>{\placesomeherefloat[#1]}]%
         \else
           \dosavefloat
         \fi}}}

% De onderstaande macro wordt gebruikt bij de macros
% voor het plaatsen van tabellen en figuren (klopt niet
% meer).
%
% \dofloat         {plaats} {label1} {label2} {kader}
%
% \docompletefloat {nummer} {referentie} {lijst}
%                  {plaats} {label1} {label2} {inhoud}
%
% \box\floatbox    inhoud+referentie
%
% \do???float#1    #1 = boxnummer
%
% \ifinsidefloat   wordt \true gezet voor \docompletefloat en \false
%                  na float plaatsen; kan worden gebruikt om in
%                  andere commando's witruimte te onderdrukken

\newdimen\floattopskip          \floattopskip=12pt
\newdimen\floatbottomskip       \floatbottomskip=12pt
\newdimen\floatsideskip         \floatsideskip=12pt

\newdimen\sidefloattopskip      \sidefloattopskip=\floattopskip
\newdimen\sidefloatbottomskip   \sidefloatbottomskip=\floatbottomskip
\def\sidefloattopoffset         {\openstrutdepth} % {\dp\strutbox}

\newcount\noftopfloats          \noftopfloats=2
\newcount\nofbotfloats          \nofbotfloats=0

\def\calculatefloatskips%
  {{\def\calculatefloatskips##1##2%
      {\doifelsenothing{##2}
         {\global##1=\zeropoint}
         {\doifelse{##2}{\v!geen}
            {\global##1=\zeropoint}
            {\setbox0=\vbox{\witruimte\@EA\blanko\@EA[##2]}%
             \global##1=\ht0}}}%
    \calculatefloatskips\floattopskip\@@bkvoorwit
    \calculatefloatskips\floatbottomskip\@@bknawit
    \calculatefloatskips\sidefloattopskip\@@bkzijvoorwit
    \calculatefloatskips\sidefloatbottomskip\@@bkzijnawit
    \def\sidefloattopoffset{\openstrutdepth}% {\dp\strutbox}%
    \global\floatsideskip=\@@bkmarge\relax
    \global\noftopfloats=\@@bknboven\relax
    \global\nofbotfloats=\@@bknonder\relax}}

\newif\ifinsidefloat

\def\floatcaptionsuffix{} % an optional suffix
\def\floatcaptionnumber{} % a logical counter

\def\dosetfloatcaption#1#2#3%
  {\def\dofloattekst%
     {{\doattributes{\??kj#1}\c!letter\c!kleur{#3}}}%
   \doifelsevalue{\??kj#1\c!nummer}{\v!ja}
     {\def\dofloatnummer%
        {{\xdef\floatcaptionnumber{#1}%
          \hbox{\doattributes{\??kj#1}\c!kopletter\c!kopkleur
             {\strut#2\floatcaptionsuffix}}}%
          \ConvertToConstant\doifnot{#3}{}
            {\tfskip
             \emergencystretch=.5em}}}
     {\let\dofloatnummer=\empty}}

\def\putborderedfloat#1\in#2\\%
  {\setbox#2=\vbox
     {\localframed
        [\??fl#1]
        [\c!breedte=\@@bkbreedte,
         \c!hoogte=\@@bkhoogte,
         \c!plaats=\v!normaal,
         \c!offset=\@@bkoffset]%
        {\box\floatbox}}}

\newbox\captionbox

\def\putcompletecaption#1#2#3#4%
  {\noindent
   \xdef\floatcaptionnumber{#1}%
   \doattributes{\??kj#1}\c!letter\c!kleur
     {\doifvalue{\??kj#1\c!nummer}{\v!ja}
        {\hbox{\doattributes{\??kj#1}\c!kopletter\c!kopkleur{\strut#2\floatcaptionsuffix}}%
         \ConvertToConstant\doifnot{#3}{}
           {\ifcase#4\relax
              \tfskip\emergencystretch=.5em
            \else
              \ifx\@@kjkjtussen\empty\else\unskip\@@kjkjtussen\fi
            \fi}}%
      \begstrut#3\endstrut\endgraf}}

% \def\dosetpagfloat#1#2#3#4% \copy wegwerken 
%   {\bgroup
%    \forgetall
%    \postponefootnotes
%    \mindermeldingen
%   %\showcomposition
%    \putborderedfloat#4\in4\\%
%    \def\locatefloat%
%      {\doregelplaats\@@flflplaats}%
%    \ConvertToConstant\doifelse{#3}{\v!geen}
%      {\global\setbox\floatbox=\vbox % pas op als wd groter dan hsize
%         {\ifbinnenkolommen\ifdim\wd4>\hsize  
%            \let\locatefloat\relax            
%          \fi\fi                              
%          \locatefloat{\copy4}}}  % we need \wd4 later 
%      {\setbox2=\hbox  
%         {\footnotesenabledfalse\putcompletecaption{#4}{#2}{#3}{0}}%
%       \doifinsetelse{\@@kjkjplaats}{\v!hoog,\v!midden,\v!laag}
%         {\dimen0=\hsize
%          \advance\dimen0 by -\wd4\relax
%          \advance\dimen0 by -\@@bkmarge\relax % \was tfskipsize\relax
%          \ifdim\wd2>\dimen0\relax
%            \dimen2=1.3\dimen0\relax
%            \ifdim\wd2<\dimen2\relax
%              \dimen0=0.8\dimen0\relax
%            \fi
%          \fi
%          \setbox2=\vbox
%            {\forgetall
%             \hsize=\dimen0\relax
%             \raggedright
%             \putcompletecaption{#4}{#2}{#3}{1}}}
%         {\doifelse{\@@kjkjbreedte}{\v!max}
%            {\dosetraggedvbox{\@@kjkjuitlijnen}%
%             \setbox2=\raggedbox
%               {\hsize\wd4\relax
%                \putcompletecaption{#4}{#2}{#3}{0}}}
%            {\ifdim\wd2>\wd4\relax
%               \doifelse{\@@kjkjbreedte}{\v!passend}
%                 {\ifdim\wd4<15\korpsgrootte\relax
%                    \dimen0=15\korpsgrootte\relax
%                  \else
%                    \dimen0=\wd4\relax
%                  \fi
%                  \ifdim\wd4>\hsize
%                    \setbox0=\vbox
%                      {\forgetall
%                       \hsize=1.0\wd4
%                       \footnotesenabledfalse
%                       \putcompletecaption{#4}{#2}{#3}{0}}%
%                    \ifdim\ht0>\lineheight\relax
%                      \setbox2=\vbox
%                        {\forgetall
%                         \hsize=0.9\wd4
%                         \putcompletecaption{#4}{#2}{#3}{0}}%
%                    \else
%                     %\setbox2=\vbox % was 0, bug
%                     %  {\forgetall
%                     %   \hsize=1.0\wd4
%                     %   \putcompletecaption{#4}{#2}{#3}{0}}%
%                      \setbox2=\hbox{\putcompletecaption{#4}{#2}{#3}{0}}% 
%                    \fi
%                  \else
%                    \setbox0=\vbox
%                      {\forgetall
%                       \dimen2=1.5\dimen0\relax
%                       \ifdim\dimen2<\hsize
%                         \hsize=\dimen2\relax
%                       \fi
%                       \footnotesenabledfalse
%                       \putcompletecaption{#4}{#2}{#3}{0}}%
%                    \ifdim\ht0>\lineheight\relax
%                      \setbox2=\vbox
%                        {\forgetall
%                         \dimen2=1.2\dimen0\relax
%                         \ifdim\dimen2<\hsize
%                           \hsize=\dimen2\relax
%                         \fi
%                         \putcompletecaption{#4}{#2}{#3}{0}}%
%                    \else
%                     %\setbox2=\vbox % was 0, bug
%                     %  {\forgetall
%                     %   \dimen2=1.5\dimen0\relax
%                     %   \ifdim\dimen2<\hsize
%                     %     \hsize=\dimen2\relax
%                     %   \fi
%                     %   \putcompletecaption{#4}{#2}{#3}{0}}%
%                      \setbox2=\hbox{\putcompletecaption{#4}{#2}{#3}{0}}% 
%                    \fi
%                  \fi}
%                 {\dosetraggedvbox{\@@kjkjuitlijnen}%
%                  \setbox2=\raggedbox
%                    {\hsize\@@kjkjbreedte
%                     \putcompletecaption{#4}{#2}{#3}{0}}}%
%             \else
% %              \setbox2=\hbox % we want footnotes ! 
% %                {\putcompletecaption{#4}{#2}{#3}{0}}%
%                \dosetraggedvbox{\@@kjkjuitlijnen}%
%                \setbox2=\raggedbox
%                  {\hsize\wd4
%                   \putcompletecaption{#4}{#2}{#3}{0}}%
%             \fi}}%
%       \global\setbox\floatbox=\vbox
%         {\forgetall
%          \processaction
%            [\@@kjkjplaats]
%            [ \v!boven=>\locatefloat{\copy2}%
%                        \endgraf\@@kjkjtussen
%                        \locatefloat{\copy4},
%              \v!onder=>\locatefloat{\copy4}%
%                        \endgraf\@@kjkjtussen
%                        \locatefloat{\copy2},
%               \v!hoog=>\locatefloat
%                          {\doifelse{\@@flflplaats}{\v!links}
%                             {\copy4
%                              \tfskip
%                              \vbox to\ht4{\@@kjkjtussen\copy2\vfill}}
%                             {\vbox to\ht4{\@@kjkjtussen\copy2\vfill}%
%                              \tfskip
%                              \copy4}},
%               \v!laag=>\locatefloat
%                          {\doifelse{\@@flflplaats}{\v!links}
%                             {\copy4
%                              \tfskip
%                              \vbox to\ht4
%                                {\vfill\copy2\@@kjkjtussen}}
%                             {\vbox to\ht4
%                                {\vfill\copy2\@@kjkjtussen}%
%                              \tfskip
%                              \copy4}},
%             \v!midden=>\locatefloat
%                          {\doifelse{\@@flflplaats}{\v!links}
%                             {\copy4
%                              \tfskip
%                              \vbox to\ht4{\vfill\copy2\vfill}}
%                             {\vbox to\ht4{\vfill\copy2\vfill}%
%                              \tfskip
%                              \copy4}},
%               \v!geen=>\locatefloat{\copy4}]}}%
%   % extended: 
%    \postcenterfloatbox{\wd4}%
%   %\ifdim\wd4>\hsize
%   %  \global\setbox\floatbox=
%   %    \hbox to \ifbinnenkolommen\wd4\else\hsize\fi
%   %      {\hss\box\floatbox\hss}%
%   %\fi
%    \egroup}

% new 

\newbox\tempfloatbox
\newbox\tempcaptionbox

%\stelblokkopjesin[\c!breedte=5cm]
%\stelblokkopjesin[\c!uitlijnen=\v!links]
%\stelblokkopjesin[\c!uitlijnen=\v!rechts]

\def\dosetpagfloat#1#2#3#4% \copy wegwerken 
  {\bgroup
   \forgetall
   \postponefootnotes
   \mindermeldingen
   \putborderedfloat#4\in\tempfloatbox\\%
   \def\locatefloat%
     {\doregelplaats\@@flflplaats}%
   \ConvertToConstant\doifelse{#3}{\v!geen}
     {\dopreparenocaption{#1}{#2}{#3}{#4}
      \edef\width{\the\wd\floatbox}}
     {\setbox\tempcaptionbox=\hbox  
        {\footnotesenabledfalse\putcompletecaption{#4}{#2}{#3}{0}}%
      \doifinsetelse{\@@kjkjplaats}{\v!hoog,\v!midden,\v!laag}
        {\dopreparesidecaption{#1}{#2}{#3}{#4}}
        {\doifelse{\@@kjkjbreedte}{\v!max}
           {\dopreparestackcaptionmax{#1}{#2}{#3}{#4}}
           {\ifdim\wd\tempcaptionbox>\wd\tempfloatbox % wider caption
              \doifelse{\@@kjkjbreedte}{\v!passend}
                {\dopreparestackcaptionaut{#1}{#2}{#3}{#4}}
                {\dopreparestackcaptionwid{#1}{#2}{#3}{#4}}%
            \else
              \dopreparestackcaptionmin{#1}{#2}{#3}{#4}%
            \fi}}
      \edef\width{\the\wd\tempfloatbox}%
      \buildfloatbox}%
   \postcenterfloatbox\width
   \egroup}

\def\dopreparenocaption#1#2#3#4%
  {\global\setbox\floatbox=\vbox % pas op als wd groter dan hsize
     {\ifbinnenkolommen\ifdim\wd\tempfloatbox>\hsize  
        \let\locatefloat\relax            
      \fi\fi                              
      \locatefloat{\copy\tempfloatbox}}} 

\def\dopreparestackcaptionmax#1#2#3#4%
  {\dosetraggedvbox{\@@kjkjuitlijnen}%
   \setbox\tempcaptionbox=\raggedbox
     {\hsize\wd\tempfloatbox
      \putcompletecaption{#4}{#2}{#3}{0}}}

\def\captionminwidth  {15\korpsgrootte}
\def\captionovershoot {2em}

\def\dopreparestackcaptionaut#1#2#3#4%
  {\doifsomething{\@@kjkjuitlijnen}
     {\ExpandBothAfter\doifnotinset{\v!midden}{\@@kjkjuitlijnen}
        {\let\captionovershoot\!!zeropoint}}% 
   \ifdim\wd\tempfloatbox>\hsize
     % float is wider than \hsize 
     \dosetraggedvbox\@@kjkjuitlijnen
     \setbox\scratchbox=\raggedbox % trial run 
       {\hsize=\wd\tempfloatbox
        \footnotesenabledfalse
        \putcompletecaption{#4}{#2}{#3}{0}}%
     \ifdim\ht\scratchbox>\lineheight % more lines 
       \dosetraggedvbox\@@kjkjuitlijnen
       \setbox\tempcaptionbox=\raggedbox
         {\hsize=\wd\tempfloatbox
          \advance\hsize -\captionovershoot\relax
          \ifdim\hsize<\captionminwidth\relax
            \hsize=\wd\tempfloatbox
          \fi
          \putcompletecaption{#4}{#2}{#3}{0}}%
     \else
       \setbox\tempcaptionbox=\raggedbox
         {\hsize=\wd\tempfloatbox
          \putcompletecaption{#4}{#2}{#3}{0}}%
     \fi
   \else
     % float is smaller of equal to \hsize 
     \ifdim\wd\tempfloatbox<\captionminwidth\relax
       \scratchdimen\captionminwidth % float smaller than min width 
     \else 
       \scratchdimen\wd\tempfloatbox % float width 
     \fi 
     \setbox\scratchbox=\vbox     % test with overshoot 
       {\advance\scratchdimen \captionovershoot
        \advance\scratchdimen 3em % an average word length 
        \ifdim\scratchdimen<\hsize \hsize=\scratchdimen \fi
        \footnotesenabledfalse
        \putcompletecaption{#4}{#2}{#3}{0}}%
     \ifdim\ht\scratchbox>\lineheight 
       % at least an average word longer than a line 
       \dosetraggedvbox\@@kjkjuitlijnen
       \setbox\tempcaptionbox\raggedbox
         {\advance\scratchdimen \captionovershoot
          \ifdim\scratchdimen<\hsize \hsize=\scratchdimen \fi
          \putcompletecaption{#4}{#2}{#3}{0}}%
     \else
       % just over a line, don't use an overshoot
       \dosetraggedvbox\@@kjkjuitlijnen
       \setbox\tempcaptionbox=\raggedbox
         {\hsize\scratchdimen
          \putcompletecaption{#4}{#2}{#3}{0}}%
     \fi
   \fi}

\def\dopreparestackcaptionwid#1#2#3#4%
  {\dosetraggedvbox\@@kjkjuitlijnen
   \setbox\tempcaptionbox=\raggedbox
     {\hsize\@@kjkjbreedte
      \putcompletecaption{#4}{#2}{#3}{0}}}

\def\dopreparestackcaptionmin#1#2#3#4%
  {\raggedcenter                     % the default 
   \dosetraggedvbox\@@kjkjuitlijnen  % when given 
   \setbox\tempcaptionbox=\raggedbox % vbox, keeps footnotes 
     {\hsize\wd\tempfloatbox
      \putcompletecaption{#4}{#2}{#3}{0}}}

\def\dopreparesidecaption#1#2#3#4%
  {\dimen0=\hsize
   \advance\dimen0 by -\wd\tempfloatbox
   \advance\dimen0 by -\@@bkmarge\relax % was \tfskipsize\relax
   \ifdim\wd\tempcaptionbox>\dimen0
     \dimen2=1.3\dimen0
     \ifdim\wd\tempcaptionbox<\dimen2
       \dimen0=0.8\dimen0
     \fi
   \fi
   \setbox\tempcaptionbox=\vbox
     {\hsize=\dimen0
      \raggedright
      \putcompletecaption{#4}{#2}{#3}{1}}}

\def\buildfloatbox%
  {\global\setbox\floatbox=\vbox
     {\forgetall
      \processaction
        [\@@kjkjplaats]
        [ \v!boven=>\locatefloat{\box\tempcaptionbox}%
                    \endgraf\@@kjkjtussen
                    \locatefloat{\box\tempfloatbox},
          \v!onder=>\locatefloat{\box\tempfloatbox}%
                    \endgraf\@@kjkjtussen
                    \locatefloat{\box\tempcaptionbox},
           \v!hoog=>\locatefloat
                      {\doifelse{\@@flflplaats}{\v!links}
                         {\box\tempfloatbox
                          \tfskip
                          \vbox to\ht\tempfloatbox{\@@kjkjtussen\box\tempcaptionbox\vfill}}
                         {\vbox to\ht\tempfloatbox{\@@kjkjtussen\box\tempcaptionbox\vfill}%
                          \tfskip
                          \box\tempfloatbox}},
           \v!laag=>\locatefloat
                      {\doifelse{\@@flflplaats}{\v!links}
                         {\box\tempfloatbox
                          \tfskip
                          \vbox to\ht\tempfloatbox
                            {\vfill\box\tempcaptionbox\@@kjkjtussen}}
                         {\vbox to\ht\tempfloatbox
                            {\vfill\box\tempcaptionbox\@@kjkjtussen}%
                          \tfskip
                          \box\tempfloatbox}},
         \v!midden=>\locatefloat
                      {\doifelse{\@@flflplaats}{\v!links}
                         {\box\tempfloatbox
                          \tfskip
                          \vbox to\ht\tempfloatbox{\vfill\box\tempcaptionbox\vfill}}
                         {\vbox to\ht\tempfloatbox{\vfill\box\tempcaptionbox\vfill}%
                          \tfskip
                          \box\tempfloatbox}},
           \v!geen=>\locatefloat{\box\tempfloatbox}]}}

\newif\ifpostponecolumnfloats \postponecolumnfloatsfalse % don't change 

%\def\postcenterfloatbox#1%
%  {\ifbinnenkolommen
%     \ifpostponecolumnfloats
%       \scratchdimen=\zetbreedte
%     \else
%       \scratchdimen=#1\relax
%     \fi
%   \else\ifdim#1>\hsize
%     \scratchdimen=\hsize
%   \else
%     \scratchdimen=\wd\floatbox
%   \fi\fi
%   \global\setbox\floatbox=\hbox to \scratchdimen
%     {\hfill\box\floatbox\hfill}} % geen \hss, gaat mis in kolommen ! 

% \def\postcenterfloatbox#1% 2 of 4
%   {\global\floatwidth\wd\ifdim\wd2>\wd4 2 \else 4 \fi
%    \ifdim\floatwidth>\zetbreedte
%      \global\floatwidth\zetbreedte
%    \else\ifdim\floatwidth<\hsize
%      \global\floatwidth\hsize
%    \fi\fi
%    \global\setbox\floatbox=\hbox to \floatwidth
%      {\hss\box\floatbox\hss}}

% \def\postcenterfloatbox#1% 2 of 4
%   {\global\setbox\floatbox=\hbox to \width % \wd\ifdim\wd2>\wd4 2\else4\fi
%        {\hss\box\floatbox\hss}%
%    \ifdim\wd\floatbox>\zetbreedte
%      \global\setbox\floatbox=\hbox to \zetbreedte
%        {\hss\box\floatbox\hss}%
%    \else\ifcenterfloatbox\ifdim\wd\floatbox<\hsize
% %     \global\setbox\floatbox=\hbox to \hsize
% %       {\hss\box\floatbox\hss}%
%    \fi\fi\fi
%    \global\floatwidth\wd\floatbox}

\def\postcenterfloatbox#1%
  {\ifbinnenkolommen
     \ifpostponecolumnfloats
       \scratchdimen=\zetbreedte
     \else
       \scratchdimen=#1\relax
     \fi
   \else\ifdim#1>\hsize
     \scratchdimen=\hsize
   \else
     \scratchdimen=\wd\floatbox
   \fi\fi
   \global\setbox\floatbox=\hbox to \scratchdimen
%     {\hfill\box\floatbox\hfill}} % geen \hss, gaat mis in kolommen ! 
     {\hss\box\floatbox\hss}} % wel \hss, anders mis in colset 

\def\dosetparfloat#1#2#3#4%
  {\bgroup
   \forgetall
   \postponefootnotes
   \mindermeldingen
   %\showcomposition
   \putborderedfloat#4\in4\\
   \ConvertToConstant\doifelse{#3}{\v!geen}
     {\global\setbox\floatbox=\vbox{\box4}}
     {\setbox2=\hbox
        {\forgetall\putcompletecaption{#4}{#2}{#3}{0}}%
      \doifelse{\@@kjkjbreedte}{\v!max}
        {\dosetraggedvbox{\@@kjkjuitlijnen}%
         \setbox2=\raggedbox
           {\hsize\wd4\putcompletecaption{#4}{#2}{#3}{0}}}%
        {\doifelse{\@@kjkjbreedte}{\v!passend}
           {\ifdim\wd2>\wd4\relax
              \setbox2=\vbox
                {\forgetall\hsize\wd4\putcompletecaption{#4}{#2}{#3}{0}}%
            \else
              \setbox2=\hbox to \wd4
                {\hss\box2\hss}%
            \fi}
           {\dosetraggedvbox{\@@kjkjuitlijnen}%
            \setbox2=\raggedbox
              {\hsize\wd4\putcompletecaption{#4}{#2}{#3}{0}}}}%
      \global\setbox\floatbox=\vbox
        {\processaction
           [\@@kjkjplaats]
           [ \v!boven=>\box2\endgraf\@@kjkjtussen\box4,
             \v!onder=>\box4\endgraf\@@kjkjtussen\box2,
              \v!geen=>\box4,
           \s!unknown=>\box4\endgraf\@@kjkjtussen\box2]}}%
   \egroup}

\newif\ifparfloat

\long\def\dosetfloatbox#1#2#3#4%
  {\ifvisible
     \par
     \doifcommonelse
        {#1}{\v!links,\v!rechts,\v!inlinker,\v!inrechter,\v!inmarge}
        {\global\parfloattrue}
        {\global\parfloatfalse}%
     \ifbinnenkolommen
       \global\parfloatfalse
     \fi
     \edef\@@kjkjbreedte  {\getvalue{\??kj#4\c!breedte}}%
     \def \@@kjkjtussen   {\getvalue{\??kj#4\c!tussen}}%  geen \edef
     \edef\@@kjkjplaats   {\getvalue{\??kj#4\c!plaats}}%
     \edef\@@kjkjuitlijnen{\getvalue{\??kj#4\c!uitlijnen}}%
     \edef\@@flflplaats   {\getvalue{\??fl#4\c!plaats}}%
     \ifparfloat
       \dosetparfloat{#1}{#2}{#3}{#4}%
     \else
       \dosetpagfloat{#1}{#2}{#3}{#4}%
     \fi
     \setbox\floatbox=\hbox{\black\box\floatbox}%
     \global\floatheight=\ht\floatbox
     \global\advance\floatheight by \dp\floatbox
     \global\floatwidth=\wd\floatbox
     \global\advance\totalnoffloats by 1
     \doifnotinset{\v!marge}{#1} % gaat namelijk nog fout
       {\setbox\floatbox=\vbox
          {\parindent\zeropoint
           \ifvoorlopig
             \inleftmargin{\framed{\infofont\the\totalnoffloats}}%
           \fi
           \box\floatbox}}%
     \wd\floatbox=\floatwidth
     \dimen0=\floatheight
     \advance\dimen0 by \lineheight
     \ifdim\dimen0<\teksthoogte
     \else
       \global\floatheight=\teksthoogte
       \global\advance\floatheight by -\lineheight
       \ht\floatbox=\floatheight
       \dp\floatbox=\zeropoint
       \showmessage{\m!floatblocks}{10}{\the\totalnoffloats}%
     \fi
   \fi}

\newcounter\noxfloatlocations

\def\dogetfloatbox#1%
  {\ifvisible
     \let\next\relax % ivm eetex
     \processfirstactioninset
       [#1]
       [    \v!hier=>\def\next{\someelsefloat[#1]},
         \v!forceer=>\def\next{\somefixdfloat[#1]},
           \v!links=>\def\next{\somesidefloat[#1]\presetindentation},
          \v!rechts=>\def\next{\somesidefloat[#1]},
           \v!tekst=>\def\next{\sometextfloat[#1]},
           \v!boven=>\def\next{\someelsefloat[#1]\nonoindentation}, % !
           \v!onder=>\def\next{\someelsefloat[#1]},
           \v!marge=>\def\next{\somenextfloat[#1]\nonoindentation}, % !
          \v!pagina=>\def\next{\somepagefloat[#1]},
           \v!naast=>\def\next{\somefacefloat[#1]},
         \v!inmarge=>\def\next{\somesidefloat[#1]},
        \v!inlinker=>\def\next{\somesidefloat[#1]},
       \v!inrechter=>\def\next{\somesidefloat[#1]},
         \s!default=>\def\next{\someelsefloat[\v!hier,#1]},
         \s!unknown=>\def\next{\someelsefloat[\v!hier,#1]}]%
     \next
   \fi}

\long\def\dofloat#1#2#3#4%
  {\dosetfloatbox{#1}{#2}{#3}{#4}%
   \dogetfloatbox{#1}}%

\long\def\docompletefloat#1#2#3#4#5#6#7%
  {\flushsidefloats
   \calculatefloatskips
   \bgroup
   \global\setbox\floatbox=\vbox{#7}%
   \dimen0=\ht\floatbox
   \advance\dimen0 by \dp\floatbox
   \ifdim\dimen0=\zeropoint
     \showmessage{\m!floatblocks}{11}{}%
     \global\setbox\floatbox=\vbox{\getvalue{\e!lege#3}}%
   \fi
   \ConvertToConstant\doifelse{#6}{\v!geen}
     {\global\setbox\floatbox=\vbox
        {\unvbox\floatbox
         \vss % gets rid of the depth
         \rawpagereference{\s!flt}{#2}}%
      \egroup\dofloat{#4}{}{#6}{#1}}
     {\doglobal\convertargument#6\to\asciititle % \asciititle is global 
      \doifelsevalue{\??kj#1\c!nummer}{\v!ja}
        {\verhoognummer[#1]%
         \maakhetnummer[#1]%
         \global\setbox\floatbox=\vbox
            {\unvbox\floatbox % no \vss, keep the depth
             \dofloatreference
             \redofloatorder{#1}%
             \rawreference{\s!flt}{#2}{{\hetnummer}{\asciititle}}%
             \doschrijfnaarlijst{#3}{\hetnummer}{#6}{#3}}%
         \egroup\dofloat{#4}{\labeltexts{#5}{\hetnummer}}{#6}{#1}}
        {\global\setbox\floatbox=\vbox
           {\unvbox\floatbox % no \vss, keep the depth
            \rawreference{\s!flt}{#2}{{}{\asciititle}}}%
         \egroup\dofloat{#4}{}{#6}{#1}}}%
   \global\insidefloatfalse}


\newif\ifmargeblokken

\def\dostelmargeblokkenin[#1]%
  {\getparameters[\??mb][#1]%
   \doifelse{\@@mbstatus}{\v!start}%
     {\showmessage{\m!layouts}{4}{}%
      \margeblokkentrue
      \let\somenextfloat=\dosomenextfloat
      \let\startmargeblok=\dostartmargeblok
      \let\stopmargeblok=\dostopmargeblok}%
     {\showmessage{\m!layouts}{5}{}%
      \margeblokkenfalse
      \def\somenextfloat[##1]%
        {\someelsefloat[##1,\v!hier]}%
      \let\startmargeblok=\dontstartmargeblok
      \let\stopmargeblok=\dontstopmargeblok}}

\def\stelmargeblokkenin%
  {\dosingleargument\dostelmargeblokkenin}

\newbox\marginbox

\def\dosomenextfloat[#1]%
  {\global\setbox\marginbox=\vbox
     {\hsize\@@mbbreedte
      \unvcopy\marginbox
      \ifvoid\marginbox\else\expandafter\@@mbtussen\fi
      \box\floatbox\filbreak}%
   \ifdim\ht\marginbox>\teksthoogte
     \dosavefloatinfo
   \else
     \doinsertfloatinfo
   \fi}

\newbox\preparedmarginbox

\def\reshapemargin%
  {\ifdim\ht\preparedmarginbox>\zeropoint
     \beginofshapebox
     \unvbox\preparedmarginbox
     \endofshapebox
     \reshapebox
       {\box\shapebox}%
     \setbox\preparedmarginbox=\vbox to \teksthoogte
       {\@@mbboven
        \flushshapebox
        \@@mbonder}%
   \fi}

\def\plaatsrechtermargeblok%
  {\hskip\rechtermargebreedte}

\def\plaatslinkermargeblok%
  {\hskip\linkermargebreedte}

\def\checkmargeblokken%  
  {\ifvoid\marginbox\else\docheckmargeblokken\fi}

\def\docheckmargeblokken% erg inefficient 
  {\setbox\preparedmarginbox=\vbox
     {\forgetall
      \splittopskip\topskip
      \ifvoid\marginbox\else
        \ifdim\ht\marginbox>\teksthoogte
          \vsplit\marginbox to \teksthoogte
        \else
          \unvbox\marginbox
        \fi
      \fi}%
   \reshapemargin
   \setbox\preparedmarginbox=\vbox
      {\@@mbvoor\box\preparedmarginbox\@@mbna}%
   \def\rightmarginbox%
     {\def\plaatsrechtermargeblok%
        {\setbox\preparedmarginbox=\hbox to \rechtermargebreedte
           {\@@mblinks\box\preparedmarginbox\@@mbrechts}%
         \vsmashbox\preparedmarginbox
         \box\preparedmarginbox}}%
   \def\leftmarginbox%
     {\def\plaatslinkermargeblok%
        {\setbox\preparedmarginbox=\hbox to \linkermargebreedte
           {\@@mbrechts\box\preparedmarginbox\@@mblinks}%
         \vsmashbox\preparedmarginbox
         \box\preparedmarginbox}}%
   \processaction % traag 
     [\@@mbplaats]
     [ \v!inmarge=>\doifbothsidesoverruled
                     \rightmarginbox
                   \orsideone
                     \rightmarginbox
                   \orsidetwo
                     \leftmarginbox
                   \od,
        \v!midden=>\doifbothsidesoverruled
                     \rightmarginbox
                   \orsideone
                     \leftmarginbox
                   \orsidetwo
                     \rightmarginbox
                   \od,
         \v!links=>\leftmarginbox,
        \v!rechts=>\rightmarginbox,
       \s!unknown=>\setbox\preparedmarginbox=\hbox{}]}

\def\dostartmargeblok%  % 2 maal \vbox ivm \unvbox elders
  {\global\setbox\marginbox=\vtop\bgroup\vbox\bgroup
     \hsize\@@mbbreedte
     \ifvoid\marginbox\else
       \unvbox\marginbox
       \@@mbtussen
     \fi
     \steluitlijnenin[\@@mbuitlijnen]%
     \dostartattributes\??mb\c!letter\c!kleur{}%
     \begstrut\ignorespaces}

\def\dostopmargeblok%
  {\unskip\endstrut
   \dostopattributes
   \egroup
   \egroup}

\def\dontstartmargeblok%
  {\@@mbvoor
   \bgroup
   \dostartattributes\??mb\c!letter\c!kleur{}}

\def\dontstopmargeblok%
  {\dostopattributes
   \egroup
   \@@mbna}

\newcounter\nofpostponedblocks

\newif\ifinuitstellen

\newevery\everytopofpage\relax

\appendtoks\the\everytopofpage     \to\everystarttext
\appendtoks\global\everytopofpage{}\to\everystoptext

%\def\douitstellen%
%  {\the\everytopofpage
%   \ifinuitstellen\else\ifcase\nofpostponedblocks\else % The \nof-test is
%     \global\pagetotal\zeropoint % recently added 
%     \global\inuitstellentrue                          % definitely needed
%     \dorecurse{\nofpostponedblocks}                   % else we can loose
%       {\haalbuffer[buf-\recurselevel]}                % or disorder floats
%     \doflushfloats % new but potential dangerous      % and that is something
%     \doglobal\newcounter\nofpostponedblocks           % we don't want, do we?
%     \global\inuitstellenfalse                         % Anyhow, 'uitstellen'
%   \fi\fi}                                             % is still suboptimal.

\def\douitstellen%
  {\the\everytopofpage
   \ifvoid\collectedpagefloats\else
     % message
     \unvbox\collectedpagefloats
   \fi
   \ifinuitstellen\else\ifcase\nofpostponedblocks\else % The \nof-test is
\bgroup
\black % else problems inside split verbatim 
\restoreglobalbodyfont % else problems inside split verbatim 
     % message
     \global\pagetotal\zeropoint % recently added
     \global\inuitstellentrue                          % definitely needed
     \dorecurse{\nofpostponedblocks}                   % else we can loose
       {\haalbuffer[buf-\recurselevel]}                % or disorder floats
     \doflushfloats % new but potential dangerous      % and that is something
     \doglobal\newcounter\nofpostponedblocks           % we don't want, do we?
     \global\inuitstellenfalse                         % Anyhow, 'uitstellen'
\egroup
   \fi\fi}                                             % is still suboptimal.

\setvalue{\e!start\e!uitstellen}%
  {\doglobal\increment\nofpostponedblocks
   \showmessage{\m!layouts}{3}{\nofpostponedblocks}%
   \dostartbuffer[buf-\nofpostponedblocks]
     [\e!start\e!uitstellen][\e!stop\e!uitstellen]}

\definieernummer
  [\??si]
  [\c!wijze=\v!per\v!tekst,
   \c!conversie=\@@siconversie]

\def\stelplaatsbloksplitsenin%
  {\dodoubleargument\getparameters[\??si]}

% ook (continued)

\def\dosplitsplaatsblok[#1]#2% nog dubbele refs
  {\ifbinnenkolommen         % tzt ook nog figuren splitten
     % not yet supported
   \else
     \bgroup
     \insidefloattrue
     \getparameters[\??si][#1]%
     \resetnummer[\??si]%
     \def\floatcaptionsuffix{\nummer[\??si]}%
     \TABLEcaptionheight=\@@siregels\lineheight
\def\docomplexpagina[##1]{\goodbreak}%
     \dowithnextbox
       {\forgetall
        \mindermeldingen
        \doloop
          {\setbox2\vsplit\nextbox to \lineheight
           \setbox2=\vbox{\unvbox2}
           \ifdim\ht2>\lineheight
             \verhoognummer[\??si]%
             \ifnum\ruwenummer[\??si]=1 \ifdim\ht\nextbox=\zeropoint
               \let\floatcaptionsuffix=\empty
             \fi\fi
             \bgroup
             #2{\unvbox2}
             \egroup
             \ifdim\ht\nextbox>\zeropoint
               \pagina
               \verlaagnummer[\floatcaptionnumber]%
             \fi
           \fi
           \ifdim\ht\nextbox>\zeropoint\else
             \expandafter\exitloop
           \fi}%
        \egroup}
     \vbox
   \fi}

\def\splitsplaatsblok%
  {\dosingleempty\dosplitsplaatsblok}

\def\dooutput{\sidefloatoutput}           % redefinition of \dooutput

\stelmargeblokkenin
  [\c!status=\v!start,
   \c!plaats=\v!inmarge,
   \c!breedte=\rechtermargebreedte,
   \c!letter=,
   \c!kleur=,
   \c!uitlijnen=,
   \c!links=,
   \c!rechts=,
   \c!boven=,
   \c!tussen=\blanko,
   \c!onder=\vfill,
   \c!voor=,
   \c!na=]

\definieerplaatsblok
  [\v!figuur]
  [\v!figuren]

\definieerplaatsblok
  [\v!tabel]
  [\v!tabellen]

\stelplaatsblokin
  [\v!tabel]
  [\c!kader=\v!uit]

\definieerplaatsblok
  [\v!intermezzo]
  [\v!intermezzos]

\definieerplaatsblok
  [\v!grafiek]
  [\v!grafieken]

\stelblokkopjesin
  [\c!plaats=\v!onder,
   \c!voor=\blanko,
   \c!tussen={\blanko[\v!middel]},
   \c!na=\blanko,
   \c!breedte=\v!passend,
   \c!kopletter=\v!vet,
   \c!letter=\v!normaal,
   \c!kleur=,
   \c!uitlijnen=,
   \c!nummer=\v!ja,
   \c!wijze=\@@nrwijze,
   \c!blokwijze=\@@nrblokwijze,
   \c!sectienummer=\@@nrsectienummer,
   \c!conversie=\v!cijfers]

\stelplaatsblokkenin
  [\c!plaats=\v!midden,
   \c!breedte=\v!passend,
   \c!hoogte=\v!passend,
   \c!offset=\v!overlay,
   \c!kader=\v!uit,
   \c!straal=.5\korpsgrootte,
   \c!hoek=\v!recht,
   \c!achtergrond=,
   \c!achtergrondraster=\@@rsraster,
   \c!achtergrondkleur=,
   \c!achtergrondoffset=\!!zeropoint,
   \c!bovenkader=,
   \c!onderkader=,
   \c!linkerkader=,
   \c!rechterkader=,
   \c!kaderoffset=\!!zeropoint,
   \c!voor=,
   \c!na=,
   \c!voorwit=\v!groot,
   \c!nawit=\v!groot,
   \c!zijvoorwit=\@@bkvoorwit,
   \c!zijnawit=\@@bknawit,
   \c!springvolgendein=\v!nee,
   \c!marge=1em,
   \c!nboven=2,
   \c!nonder=0,
   \c!nregels=4]

\stelplaatsbloksplitsenin
  [\c!conversie=\v!letter, % \v!romeins
   \c!regels=3]

% float strategy

\let\floatmethod\empty

\def\dogetfloatbox#1%
  {\ifvisible
     \getfromcommalist[#1][1]%
     \@EA\beforesplitstring\commalistelement\at:\to\floatmethod
     \@EA\aftersplitstring \commalistelement\at:\to\floatcolumn
% nog algemeen otr 
\ifx\OTRSETsetpreferedcolumnslot\undefined\else
     \OTRSETsetpreferedcolumnslot\floatcolumn 
\fi 
% commando van maken 
     \doifundefined{\string\floatmethod\floatmethod}
       {\let\floatmethod\v!hier}%
     \getvalue{\string\floatmethod\floatmethod}[#1]%
   \fi}

\def\installfloathandler#1#2% #1=keyword #2=handler
  {\setvalue{\string\floatmethod#1}{#2}}

\installfloathandler \v!hier      \someherefloat 
\installfloathandler \v!forceer   \somefixdfloat 
\installfloathandler \v!links     \someleftsidefloat 
\installfloathandler \v!rechts    \somerightsidefloat 
\installfloathandler \v!tekst     \sometextfloat 
\installfloathandler \v!boven     \sometopfloat 
\installfloathandler \v!onder     \somebottomfloat 
\installfloathandler \v!marge     \somemarginfloat 
\installfloathandler \v!pagina    \somepagefloat 
\installfloathandler \v!naast     \somefacefloat 
\installfloathandler \v!inmarge   \someinmarginfloat 
\installfloathandler \v!inlinker  \someinleftmarginfloat 
\installfloathandler \v!inrechter \someinrightmarginfloat 

\installfloathandler {tblr} \someslotfloat 
\installfloathandler {lrtb} \someslotfloat 
\installfloathandler {tbrl} \someslotfloat 
\installfloathandler {rltb} \someslotfloat 
\installfloathandler {btlr} \someslotfloat 
\installfloathandler {lrbt} \someslotfloat 
\installfloathandler {btrl} \someslotfloat 
\installfloathandler {rlbt} \someslotfloat 
\installfloathandler {fxtb} \someslotfloat 
\installfloathandler {fxbt} \someslotfloat 

\def\placesomeslotfloat {\OTRcommand\someslotfloat}
\def\placesomeherefloat {\OTRcommand\someherefloat}
\def\placesomefixdfloat {\OTRcommand\somefixdfloat}
\def\placesomepagefloat {\OTRcommand\somepagefloat}
\def\placesometopsfloat {\OTRcommand\sometopsfloat}
\def\placesomebotsfloat {\OTRcommand\somebotsfloat}
\def\placesomesidefloat {\OTRcommand\somesidefloat}
\def\placesomefacefloat {\OTRcommand\somefacefloat}

\def\someleftsidefloat     [#1]{\somesidefloat[#1]\presetindentation}
\def\somerightsidefloat    [#1]{\somesidefloat[#1]}
\def\sometopfloat          [#1]{\someelsefloat[#1]\nonoindentation}
\def\somebottomfloat       [#1]{\someelsefloat[#1]}
\def\somemarginfloat       [#1]{\somenextfloat[#1]\nonoindentation}
\def\someinleftmarginfloat [#1]{\somesidefloat[#1]}
\def\someinrightmarginfloat[#1]{\somesidefloat[#1]}
\def\someinmarginfloat     [#1]{\somesidefloat[#1]}
\def\someherefloat         [#1]{\someelsefloat[\v!hier,#1]}

\def\somefixdfloat {\placesomefixdfloat}
\def\somepagefloat {\placesomepagefloat}
\def\somefacefloat {\placesomefacefloat}
\def\someslotfloat {\placesomeslotfloat}

\protect \endinput 
