%D \module
%D   [       file=cont-new,
%D        version=1995.10.10,
%D          title=\CONTEXT\ Miscellaneous Macros,
%D       subtitle=New Macros,
%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.

%D This file is loaded at runtime, thereby providing an
%D excellent place for hacks, patches, extensions and new 
%D features. 

\unprotect

\def\showexternalfigured
  {\bgroup
   \immediate\openout\scratchwrite=mpfigs.mp
   \def\presetfigure[##1][##2]%
     {\getfiguredimensionsonly[##1]% \pagefigure[##1]%
      \immediate\write\scratchwrite
         {registerfigure("##1",\figurewidth,\figureheight)}}
   \pushendofline
   \readjobfile\@@exfile\donothing\donothing
   \popendofline
   \immediate\closeout\scratchwrite
   \egroup}

\def\setsidefloatparagraph
  {%\advance\sidefloatprogress \sidefloatbottomskip
   %\!!counta\sidefloatprogress
\scratchdimen\sidefloatprogress
\advance\scratchdimen \ht\strutbox
\advance\scratchdimen -10sp % new, needed in prikkels, prevent rounding errors 
\!!counta\scratchdimen
   \divide\!!counta \baselineskip
   \ifnum\!!counta>0
     \hangindent \ifrightfloat-\fi\sidefloatwidth
     \hangafter-\!!counta
   \fi
   \global\advance\sidefloatparagraph \plusone
   \iftracesidefloats
     \hskip-\sidefloatwidth
     \color[darkgray]%
       {\vrule\!!height.5\s!pt\!!depth.5\s!pt\!!width\sidefloatwidth
       %\hskip-.25\bodyfontsize\showstruts\strut\hskip.25\bodyfontsize}%
        \llap{\showstruts\strut\hskip.25\bodyfontsize}}%
   \fi}




\writestatus{\m!systems}{beware: some patches loaded from cont-new.tex!}

\def\ejectinsert
  {\flushnotes
   \bgroup
   \noftopfloats\plusthousand
   \nofbotfloats\zerocount
   % this is needed in case a float that has been stored 
   % ends up at the current page; this border case occurs when 
   % the calculated room is 'eps' smaller that the room available
   % when just flushing; so now we have (maybe optional):  
   \pagebaselinecorrection
   % alas, this is tricky but needed (first surfaced in prikkels)
   \doflushfloats
   \egroup}

\def\overloaded#1#2%
  {\appendtoks
     \writestatus\m!systems{overloaded: \string#2}%
   \to \everybye
   #1#2}

\def\toplinebox
  {\dowithnextbox
     {\ifdim\nextboxdp>\strutdepth
        \scratchdimen\nextboxdp
        \advance\scratchdimen-\strutdepth
        \getnoflines\scratchdimen
        \struttedbox{\flushnextbox}%
        \dorecurse\noflines{\vbox{\hsize\zeropoint\strut}}%
      \else
        \flushnextbox
      \fi}%
   \tbox}

\def\expandifnonempty#1%
  {\@EA\ifx\csname#1\endcsname\empty
     \expandafter\secondoftwoarguments
   \else
     \expandafter\firstoftwoarguments
   \fi
   {\csname#1\endcsname}}

\def\@@sectiekoppeling#1%
  {\expandifnonempty{\??ko#1\c!koppeling}{#1}}

\def\@@sectiesectie#1%
  {\expandifnonempty{\??ko#1\c!sectie}{\@@sectiekoppeling{#1}}}

\def\sectioncountervalue#1%
  {\@@sectionvalue{\@@sectiesectie{#1}}}

% todo namespace \@@meta:#1:... ! ! ! ! ! !

\def\presetMPvariable
  {\dodoubleargument\dopresetMPvariable}

\def\dopresetMPvariable[#1][#2=#3]%
  {\doifundefined{#1:#2}{\setvalue{#1:#2}{#3}}}

% experiment, not yet to be used

\def\displaybreak
  {\ifhmode
     \removeunwantedspaces
     \ifcase\raggedstatus\hfill\fi
     \strut\penalty-9999 % \break fails on case (3)
   \fi}

\def\startdisplay{\displaybreak\ignorespaces\startopelkaar}
\def\stopdisplay {\stopopelkaar\displaybreak\ignorespaces}

\def\tightvbox
  {\dowithnextbox{\nextboxdp\zeropoint\flushnextbox}\vbox}

\def\tightvtop
  {\dowithnextbox{\nextboxht\zeropoint\flushnextbox}\vtop}

\def\startpagefigure
  {\dodoubleempty\dostartpagefigure}

\def\dostartpagefigure[#1][#2]%
  {\bgroup
   \getparameters[\??ex][\c!offset=\!!zeropoint,#2]%
   \startTEXpage[\c!offset=\@@exoffset]%
     \externalfigure[#1][#2]\ignorespaces}

\def\stoppagefigure
  {\stopTEXpage
   \egroup}

\def\pagefigure
  {\dodoubleempty\dopagefigure}

\def\dopagefigure[#1][#2]%
  {\dostartpagefigure[#1][#2]\stoppagefigure}

% pretty important (esp since we now ignore shipouts)
%
% actually we should nil all writes, marks, specials

\appendtoks \globallet\popcolor\relax \to \everylastshipout

\def\incrementvalue#1{\expandafter\increment\csname#1\endcsname}
\def\decrementvalue#1{\expandafter\decrement\csname#1\endcsname}

% \translateMPinput{il2-pl}
%
% \startMPenvironment[global]
%   \setupbodyfont[plr]
% \stopMPenvironment
%
% \TeX: � �
%
% \startMPcode
% draw btex MetaPost: � � etex scaled 5 ;
% \stopMPcode

% \startcolumnset[two] \input tufte
% \startcolumnsetspan[two] \input tufte \stopcolumnsetspan
% \input tufte \stopcolumnset

% now in cont-loc.tex, for the sake of testing.
%
% %D When \type {\somecolor} is issued, we can savely assume
% %D grouping. Using \type {\groupedcommand} here (i.e.\ the
% %D definition of \type {\color}) is unsafe because in
% %D interferes with for instance switching attributes.
%
% \def\switchtocolor[#1]%
%   {\bgroup\startcolor[#1]
%    \aftergroup\stopcolor
%    \aftergroup\egroup}

% test this for a long time, esp since from now on, by default
% \commands are not expanded

\setupreferencing
  [\c!expansie=\v!nee]

\def\dotextreference[#1]#2%
  {\bgroup
   \def\asciia{#1}%
   \convertexpanded\??rf{#2}\asciib
   \@EA\rawtextreference\@EA\s!txt\@EA\asciia\@EA{\asciib}%
   \egroup}

\def\dopagereference[#1]%
  {\rawpagereference\s!pag{#1}}

\def\doreference[#1]#2%
  {\bgroup
   \def\asciia{#1}%
   \convertexpanded\??rf{#2}\asciib
   \@EA\rawreference\@EA\s!ref\@EA\asciia\@EA{\asciib}%
   \egroup}

% what is this stupid macro meant for:

\def\hyphenationpoint
  {\hskip\zeropoint}

\def\hyphenated#1%
  {\bgroup
   \!!counta\zerocount
   \def\hyphenated##1{\advance\!!counta\plusone}%
   \handletokens#1\with\hyphenated
   \!!countb\plusone
   \def\hyphenated##1%
     {##1%
      \advance\!!countb\plusone\relax
      \ifnum\!!countb>2 \ifnum\!!countb<\!!counta
        \hyphenationpoint
      \fi\fi}%
   \handletokens#1\with\hyphenated
   \egroup}

\def\obeysupersubletters
  {\let\super\normalsuper
   \let\suber\normalsuber
   \let\normalsuper\letterhat
   \let\normalsuber\letterunderscore
   \enablesupersub}

\def\obeysupersubmath
  {\let\normalsuper\letterhat
   \let\normalsuber\letterunderscore
   \enablesupersub}

%\let\normaltype\type
%
%\def\type#1%
%  {\expanded{\normaltype{\detokenize{#1}}}}

% {x123 \os x123} {\tfa x123 \os x123} {x123 \tx x123 \os x123}
% \definefontsynonym[OldStyle][Serif]
% {x123 \os x123} {\tfa x123 \os x123} {x123 \tx x123 \os x123}

% testen :
%
% \appendtoks
%   \let\registerparoptions\relax
% \to \everyforgetall

\def\startgridcorrection
  {\dosingleempty\dostartgridcorrection}

\def\dostartgridcorrection[#1]%
  {\ifgridsnapping
     \iffirstargument\doifsomething{#1}{\verplaatsopgrid[#1]}\fi
     \snaptogrid\vbox\bgroup
   \else
     \startbaselinecorrection
   \fi}

\def\stopgridcorrection
  {\ifgridsnapping
     \egroup
   \else
     \stopbaselinecorrection
   \fi}

\def\checkgridsnapping
  {\lineskip\ifgridsnapping\zeropoint\else\normallineskip\fi}

\def\startplaatsen
  {\dosingleempty\dostartplaatsen}

\def\dostartplaatsen[#1]% tzt n*links etc
  {\endgraf
   \noindent\bgroup
   \setlocalhsize
   \hbox to \localhsize\bgroup
     \doifnot{#1}\v!links\hss
     \def\stopplaatsen
       {\unskip\unskip\unskip
        \doifnot{#1}\v!rechts\hss
        \egroup
        \egroup
        \endgraf}%
     \gobblespacetokens}

% \startplaatsen[links] bla \stopplaatsen

% we don't register the paragraph characteristics, only the
% width

\appendtoks
  \setinnerparpositions % see "techniek" for application
\to \everytabulate

\appendtoks \checkcurrentlayout \to \everystarttext

\def\flushfootnotes  {\flushnotes}
\def\doflushfootnotes{\doflushnotes}

%D This alternative is slower, since it works on top of the
%D color (stack) mechanism, but it does provide nesting.

\def\dosetrastercolor#1%
  {\edef\@@cl@@s{#1}%
   \ifx\@@cl@@s\empty
     \let\@@cl@@s\@@rsraster
   \fi
   \setevalue{\??cr\??rs}{\colorSpattern}}

% beware, don't add extra grouping, else color in tables
% fails

\def\localstartraster[#1]%
  {\ifincolor\dosetrastercolor{#1}\localstartcolor[\??rs]\fi}

\def\startraster[#1]%
  {\ifincolor\dosetrastercolor{#1}\startcolor[\??rs]\fi}

\def\localstopraster{\ifincolor\localstopcolor\fi}
\def\stopraster     {\ifincolor\stopcolor\fi}

\def\fontclassname#1#2%
  {\ifcsname\??ff#1#2\endcsname
     \fontclassname{#1}{\csname\??ff#1#2\endcsname}%
   \else\ifcsname\??ff#2\endcsname
     \fontclassname{#1}{\csname\??ff#2\endcsname}%
   \else
     #2%
   \fi\fi}

\def\defineclassfontsynonym
  {\dotripleargument\dodefineclassfontsynonym}

\def\dodefineclassfontsynonym[#1][#2][#3]%
  {\definefontsynonym[#1][\fontclassname{#2}{#3}]}

%\definefontsynonym [KopFont] [\fontclassname{officina}{SerifBold}]
%
%\defineclassfontsynonym [KopFont] [officina] [SerifBold]

\def\startkolomopmaak % don't change
  {\bgroup
   \getrawnoflines\teksthoogte % teksthoogte kan topskip hebben, dus raw
   \scratchdimen\noflines\lineheight
   \advance\scratchdimen-\lineheight
   \advance\scratchdimen\topskip
   \setbox\scratchbox
   \ifcase\showgridstate\vbox\else\ruledvbox\fi to \scratchdimen\bgroup
   \forgetall} % ! don't change 

\def\stopkolomopmaak
  {\egroup
   \dp\scratchbox\zeropoint
   \wd\scratchbox\tekstbreedte
   \box\scratchbox
   \egroup}

% todo : hoe komt box er uit

\long\def\startexternalfigure
  {\dotripleempty\dostartexternalfigure}

\long\def\dostartexternalfigure[#1][#2][#3]#4\stopexternalfigure
  {\gdef\figuredescription{#4}%
   \externalfigure[#1][#2][#3]%
   \globallet\figuredescription\empty}

\let\figuredescription\empty

\newtoks\everyfirstparagraphintro
\newtoks\everynextparagraphintro

\chardef\everyparagraphintro=0

\def\setupparagraphintro
  {\dodoubleempty\dosetupparagraphintro}

\def\dosetupparagraphintro[#1][#2]%
  {\processallactionsinset
     [#1]
     [   \v!reset=>\global\chardef\everyparagraphintro0
                   \global\everyfirstparagraphintro\emptytoks
                   \global\everynextparagraphintro \emptytoks,
        \v!eerste=>\global\chardef\everyparagraphintro1
                   \doglobal\appendtoks#2\to\everyfirstparagraphintro,
      \v!volgende=>\ifcase\everyparagraphintro\global\chardef\everyparagraphintro=2\fi
                   \doglobal\appendtoks#2\to\everynextparagraphintro,
           \v!elk=>\ifcase\everyparagraphintro\global\chardef\everyparagraphintro=2\fi
                   \doglobal\appendtoks#2\to\everyfirstparagraphintro
                   \doglobal\appendtoks#2\to\everynextparagraphintro]}

\def\doinsertparagraphintro
  {\ifcase\everyparagraphintro\relax
     % no data
   \or
     % first data
     \global\chardef\everyparagraphintro2
     \scratchtoks\everyfirstparagraphintro
     \global\everyfirstparagraphintro\emptytoks
   \or
     % next data
     \scratchtoks\everynextparagraphintro
   \fi
   \the\scratchtoks}

\def\insertparagraphintro
  {\ifcase\everyparagraphintro\else\@EA\doinsertparagraphintro\fi}

\appendtoks\insertparagraphintro\to\everypar

%D \starttypen
%D \setupparagraphintro[first][\hbox to 3.5em{\tt FIRST \hss}]
%D \setupparagraphintro[first][\hbox to 3.5em{\tt TSRIF \hss}]
%D \setupparagraphintro[next] [\hbox to 3.5em{\tt NEXT  \hss}]
%D \setupparagraphintro[next] [\hbox to 3.5em{\tt TXEN  \hss}]
%D \setupparagraphintro[each] [\hbox to 3.0em{\tt EACH  \hss}]
%D \setupparagraphintro[each] [\hbox to 3.0em{\tt HCEA  \hss}]
%D
%D some paragraph \par
%D some paragraph \par
%D some paragraph \par
%D
%D \definelabel[parnumber]
%D
%D \setupparagraphintro[reset,each][\inleft{\slxx\parnumber}]
%D
%D some paragraph \par
%D some paragraph \par
%D some paragraph \par
%D \stoptypen

% wrong names

\newif\ifpagechanged \let\lastchangedpage\empty

\def\checkpagechange#1%
  {\gettwopassdata\s!paragraph
   \pagechangedfalse
   \iftwopassdatafound
     \ifnum\twopassdata>0\getvalue{\s!paragraph:p:#1}\relax
       \pagechangedtrue
     \fi
   \fi
   \ifpagechanged
     \letgvalue{\s!paragraph:p:#1}\twopassdata
     \globallet\lastchangedpage\twopassdata
   \else
     \globallet\lastchangedpage\realfolio
   \fi
   \doparagraphreference}

\def\changedpage#1%
  {\getvalue{\s!paragraph:p:#1}}

% incomplete, will be a special case of float placement 

\def\startfixed{\dosingleempty\dostartfixed}

\long\def\dostartfixed[#1]%
  {\expanded{\dowithnextbox{\noexpand\dodofixed{\ifhmode0\else1\fi}{#1}}}%
   \vbox\bgroup
   \setlocalhsize}

\def\stopfixed
  {\egroup}

\def\dodofixed#1#2%
  {\ifcase#1\relax
     \processaction
       [#2]
       [   \v!hoog=>\bbox   {\flushnextbox},
           \v!laag=>\tbox   {\flushnextbox},
         \v!midden=>\vcenter{\flushnextbox},
           \v!laho=>\vcenter{\flushnextbox},
        \s!unknown=>\tbox   {\flushnextbox},
        \s!default=>\tbox   {\flushnextbox}]%
   \else
     \startbaselinecorrection
     \noindent\flushnextbox
     \stopbaselinecorrection
   \fi}

% \startitemize
%
% \item \externalfigure[koe][height=2cm]
% \item \externalfigure[koe][height=2cm]
% \item \externalfigure[koe][height=2cm]
% \item \externalfigure[koe][height=2cm]
%
% \page
%
% \item \startfixed      \externalfigure[koe][height=2cm]\stopfixed
% \item \startfixed[high]\externalfigure[koe][height=2cm]\stopfixed
% \item \startfixed[low] \externalfigure[koe][height=2cm]\stopfixed
% \item \startfixed[lohi]\externalfigure[koe][height=2cm]\stopfixed
%
% \page
%
% \item test \startfixed      \externalfigure[koe][height=2cm]\stopfixed
% \item test \startfixed[high]\externalfigure[koe][height=2cm]\stopfixed
% \item test \startfixed[low] \externalfigure[koe][height=2cm]\stopfixed
% \item test \startfixed[lohi]\externalfigure[koe][height=2cm]\stopfixed
%
% \page
%
% \item test \par \startfixed      \externalfigure[koe][height=2cm]\stopfixed
% \item test \par \startfixed[high]\externalfigure[koe][height=2cm]\stopfixed
% \item test \par \startfixed[low] \externalfigure[koe][height=2cm]\stopfixed
% \item test \par \startfixed[lohi]\externalfigure[koe][height=2cm]\stopfixed
%
% \stopitemize

% \def\docalculatefigurenorm#1#2%
%   {\dodocalculatefigurenorm{#1}[#2\empty\empty]}
%
% \def\dodocalculatefigurenorm#1[#2#3#4]#5#6#7%
%   {\ExpandFirstAfter\processaction
%       [#2#3#4]
%       [     \v!max=>\global#1=#6\relax,
%           \v!kolom=>\global#1=#6\relax,
%           \v!tekst=>\global#1=#6\relax,
%         \v!passend=>\global#1=#7\relax,
%            \v!ruim=>\global#1=#7\relax
%                     \global\advance #1 -4\@@exkorps\relax,
%        #2*\v!kolom=>\global#1=#6\relax
%                     \ifbinnenkolommen
%                       \global\advance#1 \intercolumnwidth
%                       \global\multiply#1 #2\relax
%                       \global\advance#1 -\intercolumnwidth
%                     \fi,
%        #2*\v!tekst=>\global#1=\zetbreedte
%                     \global\advance#1 \papierbreedte,
%         \s!default=>\doifsomething{#5}{\global#1=#5\relax},
%         \s!unknown=>\global#1=\@@exkorps\relax
%                     \global\divide#1 \!!ten\relax
%                     \global\multiply#1 #2#3#4\relax]}

\def\complexTableTB[#1]{\TABLEnoalign{\blanko[#1]}}
\def\simpleTableTB     {\TABLEnoalign{\blanko}}

\def\TabulateTB
  {\complexorsimpleTable{TB}}

\def\doTableinterline% #1
  {\ifnum\currentTABLEcolumn>\maxTABLEcolumn
     \chuckTABLEautorow
   \else\ifnum\currentTABLEcolumn=\zerocount
     \TABLEnoalign
       {\globalletempty\checkTABLEautorow
        \globalletempty\chuckTABLEautorow}%
   \else
     \setTABLEerror\TABLEmissingcolumn
     \handleTABLEerror
   \fi\fi
   \complexorsimpleTable} % {#1}

\def\TableHL{\doTableinterline{HL}}
\def\TableTB{\doTableinterline{TB}}

\appendtoks\let\TB\TableTB   \to\everytable
\appendtoks\let\TB\TabulateTB\to\everytabulate

% \starttabulate
% \NC text \NC text \NC \NR
% \TB[small]
% \NC text \NC text \NC \NR
% \TB[4*big]
% \NC text \NC text \NC \NR
% \stoptabulate
%
% \starttable[|||]
% \VL text \VL text \VL \AR
% \TB[small]
% \VL text \VL text \VL \AR
% \TB[4*big]
% \VL text \VL text \VL \AR
% \stoptable

% still needed for uguide

\let\placefloatlabel          \placefloatcaption
\let\placefloatlabeltext      \placefloatcaptiontext
\let\placefloatlabelreference \placefloatcaptionreference

\def\obeyfollowingtoken{{}}  % end \cs scanning

\def\gobbleparameters{\doquadrupleempty\dogobbleparameters}
\def\dogobbleparameters[#1][#2][#3][#4]{}

\def\defineTABLEdivisions
  {\global\TABLEdivisionfalse % in start
   \let\DL\TableDL
   \let\DC\TableDC
   \let\DV\TableDV
   \let\DR\TableDR}

\def\defineTABLErules
  {\let\VL\TableVL
   \let\VC\TableVC
   \let\HL\TableHL
   \let\HC\TableHC
   \let\VS\TableVS
   \let\VD\TableVD
   \let\VT\TableVT}

\def\TableVS{\gdef\@VLn{1}\VL}
\def\TableVD{\gdef\@VLn{2}\VL}
\def\TableVT{\gdef\@VLn{3}\VL}

\def\@VLn{1}
\def\@VLd{.125em}

\def\do!ttInsertVrule % will be merged in 2005
  {\vrule \!thWidth
   \ifnum\!tgCode=1
     \ifx\!tgValue\empty
       \LineThicknessFactor
     \else
       \!tgValue
     \fi
     \LineThicknessUnit
   \else
     \!tgValue
   \fi
   \hskip\@VLd}

\def\!ttInsertVrule%
  {\hfil
   \TABLEbeforebar % added
   \startglobalTABLEcolor % added
   % we could do without this speedup, some day merge 'm
   \ifcase\@VLn\or
     \do!ttInsertVrule
     \unskip
   \else
     \dorecurse\@VLn\do!ttInsertVrule
     \gdef\@VLn{1}%
     \unskip
   \fi
   \stopglobalTABLEcolor % added
   \TABLEafterbar % added
   \hfil
   &}

% \starttable[|||]
% \HL
% \VL test \VS test \VL \FR
% \VL test \VD test \VL \MR
% \VL test \VT test \VL \LR
% \HL
% \stoptable

%D To be documented, \type {\includemenu[menu]}.
%D To be documented, \type {\emphbf} cum suis.

%D A prelude to strategies. Note for myself: overloads
%D previous stuff from local pragma test files.

\def\s!strategy{strategy}

\def\currentstrategypass    {1}
\def\currentstrategyvariable{0}
\def\maximumstrategypass    {8}

\newconditional\strategypassneeded
\newconditional\strategypassforced

\definetwopasslist{\s!strategy}

\def\registerstrategypass%
  {\ifnum\currentstrategypass>\maximumstrategypass \else
     \ifconditional\strategypassforced
       \doglobal\increment\currentstrategypass
     \else%\ifconditional\strategypassneeded
       %\doglobal\increment\currentstrategypass
     \fi%\fi
   \fi
   \savecurrentvalue\currentstrategypass{\currentstrategypass}}

\appendtoks \registerstrategypass \to \everybye % \everylastshipout

\def\setstrategyvariable#1#2% key value
  {%\doifnotstrategyvariable{#1}{\global\settrue\strategypassneeded}%
   \doglobal\increment\currentstrategyvariable
   \expanded{\immediatewriteutilitycommand{\noexpand
     \twopassentry{\s!strategy}{\currentstrategyvariable}{#1::#2}}}}

\def\doifstrategyvariableelse#1#2#3%
  {\getstrategyvariable{#1}\iftwopassdatafound#2\else#3\fi}

\def\getstrategyvariable#1% key
  {\findtwopassdata{\s!strategy}{#1::}%
   \setxvalue{\s!strategy:#1}{\twopassdata}}

\def\retainstrategyvariable#1% key
  {\expanded{\setstrategyvariable{#1}{\strategyvariable{#1}}}}

\def\strategyvariable#1% key
  {\csname\s!strategy:#1\endcsname}

\let\stratvar\strategyvariable

\def\forcestrategy{\global\settrue \strategypassforced}
\def\abortstrategy{\global\setfalse\strategypassforced}

\def\doifstrategyvariableelse#1#2#3%
  {\getstrategyvariable{#1}\iftwopassdatafound#2\else#3\fi}

\def\doifstrategyvariable   #1#2{\doifstrategyvariableelse{#1}{#2}{}}
\def\doifnotstrategyvariable#1#2{\doifstrategyvariableelse{#1}{}{#2}}

%D New: only at start of columns; may change ! Rather
%D interwoven and therefore to be integrated when the multi
%D column modules are merged.

%  already taken care of: \definesystemvariable{ks}

% is buggy now and does not work any longer

\def\setupcolumnspan[#1]%
  {\getparameters[\??ks][#1]}

\presetlocalframed
  [\??ks]

\setupcolumnspan
  [\c!n=2,
   \c!offset=\v!overlay,
   \c!kader=\v!uit]

\newbox\columnspanbox \let\postprocesscolumnspanbox\gobbleoneargument

\def\dostartcolumnspan[#1]%
  {\bgroup
   \setupcolumnspan[#1]%
   \forgetall
   \ifbinnenkolommen
     \advance\hsize \intercolumnwidth
     \hsize\@@ksn\hsize
     \advance\hsize -\intercolumnwidth
   \fi
   \dowithnextbox
     {\setbox\columnspanbox\flushnextbox
      \ifbinnenkolommen\wd\columnspanbox\hsize\fi
      \postprocesscolumnspanbox\columnspanbox
      \scratchdimen\ht\columnspanbox
      \setbox\columnspanbox\hbox % depth to be checked, probably option!
        {\localframed[\??ks][\c!offset=\v!overlay]{\box\columnspanbox}}%
      \ht\columnspanbox\scratchdimen
      \dp\columnspanbox\dp\strutbox
      \wd\columnspanbox\hsize
      \ifbinnenkolommen
        \ifnum\@@ksn>1
          \setvsize
          \dohandleallcolumns
            {\ifnum\currentcolumn>\@@ksn\else
               \global\setbox\currenttopcolumnbox=\vbox
                 {\ifnum\currentcolumn=1
                    \snaptogrid\vbox{\copy\columnspanbox}
                  \else
                    \snaptogrid\vbox{\vphantom{\copy\columnspanbox}}
                  \fi}%
               \wd\currenttopcolumnbox\hsize
               \global\advance\vsize -\ht\currenttopcolumnbox
             \fi}
          \global\pagegoal\vsize
        \else
          \snaptogrid\vbox{\box\columnspanbox}
        \fi
      \else
        \snaptogrid\vbox{\box\columnspanbox}
      \fi
      \endgraf
      \prevdepth\dp\strutbox
      \egroup}
     \vbox\bgroup
      %\topskipcorrection % becomes an option !
       \EveryPar{\begstrut\EveryPar{}}} % also !

\def\startcolumnspan
  {\dosingleempty\dostartcolumnspan}

\def\stopcolumnspan
  {\egroup}

%D For Ton. To be documented.

\def\plaatsexterndocument[#1]%
  {\def\doexternaldocument[##1][##2][##3]%
     {\readlocfile{##2}\donothing\donothing}%
   \getvalue{\v!file:::#1}}

%D Far from complete.

\def\startgeheel
  {\startregelcorrectie
   \insidefloattrue}

\def\stopgeheel
  {\stopregelcorrectie}

%D No more news.

\protect

%D A few local optimizations and new features, if defined:

\readfile {cont-loc} {} {}

\endinput
