%D \module
%D   [       file=core-mis,
%D        version=1998.01.29,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Miscelaneous,
%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 Core Macros / Misc Commands}

\startmessages  dutch  library: systems
  title: systeem
      3: probeer LaTeX eens
\stopmessages

\startmessages  english  library: systems
  title: system
      3: try LaTeX
\stopmessages

\startmessages  german  library: systems
  title: system
      3: Versuche LaTeX
\stopmessages

\startmessages  czech  library: systems
  title: system
      3: zkuste LaTeX
\stopmessages

\startmessages  italian  library: systems
  title: sistema
      3: provare LaTeX
\stopmessages

\startmessages  norwegian  library: systems
  title: system
      3: forsøker LaTeX
\stopmessages

\startmessages  romanian  library: systems
  title: sistem
      3: incercati LaTeX
\stopmessages

\unprotect

%D \macros
%D   {simplifiedcommands, simplifycommands}
%D
%D I first needed this simplification in bookmarks. Users can
%D add their own if needed.

\ifx\simplifiedcommands\undefined \newtoks\simplifiedcommands \fi

\def\simplifycommands{\the\simplifiedcommands}

%D A possibly growing list:

\appendtoks        \def\executesynonym#1#2#3#4{#3}\to\simplifiedcommands
\appendtoks                              \def\ { }\to\simplifiedcommands
\appendtoks\def\type#1{\string\\\strippedcsname#1}\to\simplifiedcommands
\appendtoks                          \def\TeX{TeX}\to\simplifiedcommands
\appendtoks                  \def\ConTeXt{ConTeXt}\to\simplifiedcommands
\appendtoks                \def\MetaPost{MetaPost}\to\simplifiedcommands
\appendtoks                \def\MetaPost{MetaFont}\to\simplifiedcommands
\appendtoks                 \def\MetaPost{MetaFun}\to\simplifiedcommands
\appendtoks                              \def||{-}\to\simplifiedcommands

%D You would not expect the next macro in \CONTEXT,
%D wouldn't you? It's there to warn \LATEX\ users that
%D something is wrong.

\def\documentstyle
  {\showmessage\m!systems3\empty\stoptekst}

\let\documentclass=\documentstyle

% THIS WAS MAIN-002.TEX

%\def\checkinterlineskip
%  {\ifvmode
%     \ifdim\lastskip>\zeropoint
%       \nointerlineskip
%     \else\ifdim\lastkern>\zeropoint
%       \nointerlineskip
%     \fi\fi
%   \fi}

\def\horitems#1#2% #1=breedte #2=commandos
  {\scratchdimen#1%
   \divide\scratchdimen \nofitems
   \!!counta\zerocount
   \def\docommando##1%
     {\advance\!!counta \plusone
      \processaction
        [\@@isuitlijnen]
        [  \v!links=>\hbox to \scratchdimen{\strut##1\hss},
          \v!rechts=>\hbox to \scratchdimen{\hss\strut##1},
          \v!midden=>\hbox to \scratchdimen{\hss\strut##1\hss},
           \v!marge=>\ifnum\!!counta=\plusone\hss\else\hfill\fi
                     \strut##1%
                     \ifnum\!!counta=\nofitems\hss\else\hfill\fi,
         \s!default=>\hbox to \scratchdimen{\hss\strut##1\hss}, % midden
         \s!unknown=>\hbox to \scratchdimen{\strut##1\hss}]}%   % links
   \hbox to #1{\hss#2\hss}}

\def\veritems#1#2% #1=breedte #2=commandos
  {\scratchdimen#1%
   \def\docommando##1%
     {\ifdim\scratchdimen<\zeropoint % the - was a signal
        \hbox to -\scratchdimen{\hss\strut##1}%
      \else\ifdim\scratchdimen>\zeropoint
        \hbox to \scratchdimen{\strut##1\hss}%
      \else
        \hbox{\strut##1}%
      \fi\fi}%
   \vbox{#2}}

\def\dostelitemsin[#1]%
  {\getparameters[\??is][#1]%
   \doif\@@isbreedte\v!onbekend
     {\def\@@isbreedte{\hsize}}%
   \doifconversiondefinedelse\@@issymbool
     {\def\doitembullet##1{\convertnumber{\@@issymbool}{##1}}}
     {\doifsymboldefinedelse\@@issymbool
        {\def\doitembullet##1{\symbol[\@@issymbool]}}{}}}

\def\makeitemsandbullets#1%
  {\doifelse\@@isn\v!onbekend
     {\getcommalistsize[#1]%
      \edef\nofitems{\commalistsize}}
     {\edef\nofitems{\@@isn}}%
   \setbox0\hbox
     {\doitems \@@isbreedte
        {\processcommalist[#1]\docommando}}%
   \setbox2\hbox
     {\doitems \@@isbulletbreedte
        {\dorecurse\nofitems
           {\docommando{\strut\doitembullet\recurselevel}}}}}

\def\dostartitems#1#2#3%
  {\let\doitems#2%
   \def\@@isbulletbreedte{#3}%
   \makeitemsandbullets{#1}%
   \@@isvoor}

\def\dostopitems
  {\@@isna
   \egroup}

\setvalue{doitems\v!boven}#1%
  {\dostartitems{#1}\horitems\@@isbreedte
   \noindent\vbox
     {\forgetall
      \doifsomething\@@issymbool
        {\doifnot\@@issymbool\v!geen
           {\box2
            \@@istussen
            \nointerlineskip}}%
      \box0}%
   \dostopitems}

\setvalue{doitems\v!onder}#1%
  {\dostartitems{#1}\horitems\@@isbreedte
   \noindent\vbox
     {\forgetall
      \box0
      \doifsomething\@@issymbool
        {\@@istussen
         \nointerlineskip
         \box2}}%
   \dostopitems}

\setvalue{doitems\v!inmarge}#1%
  {\dostartitems{#1}\veritems{-1.5em}%  - is a signal
   \noindent\hbox{\llap{\box2\hskip\linkermargeafstand}\box0}%
   \dostopitems}

\setvalue{doitems\v!links}#1%
  {\advance\hsize -1.5em%
   \dostartitems{#1}\veritems{1.5em}%
   \noindent\hbox{\box2\box0}%
   \dostopitems}

\setvalue{doitems\v!rechts}#1%
  {\dostartitems{#1}\veritems{0em}%
   \noindent\hbox{\box0\hskip-\wd2\box2}%
   \dostopitems}

\def\stelitemsin
  {\dosingleargument\dostelitemsin}

\def\complexitems[#1]%
  {\bgroup
   \stelitemsin[#1]%
   \parindent\zeropoint
   \setlocalhsize
   \hsize\localhsize
   \mindermeldingen
  %\doifundefined{doitems\@@isplaats}%
  %  {\let\@@isplaats\v!links}%
  %\getvalue{doitems\@@isplaats}}
   \executeifdefined{doitems\@@isplaats}{\let\@@isplaats\v!links}}

\definecomplexorsimpleempty\items

\stelitemsin
  [\c!plaats=\v!links,
   \c!symbool=5,
   \c!breedte=\hsize,
   \c!uitlijnen=\v!midden,
   \c!n=\v!onbekend,
   \c!voor=\blanko,
   \c!tussen={\blanko[\v!middel]},
   \c!na=\blanko]

% Te zijner tijd [plaats=boven,onder,midden] implementeren,
% in dat geval moet eerst de maximale hoogte worden bepaald.
%
% Overigens kan een en ander mooier met \halign.

\def\dodefinieeralineas[#1][#2]%
  {\setvalue{\s!do\s!next#1}%
     {\def\\{\getvalue{#1}}}%
   \setvalue{#1}%
     {\getvalue{\s!do\s!next#1}%
      \dostartalineas{#1}}%
   \setvalue{\e!volgende#1}%
     {\getvalue{#1}}%
   \setvalue{\e!start#1}%
     {\bgroup
      \letvalue{\s!do\s!next#1}\empty
      \setvalue{\e!stop#1}%
        {\getvalue{#1}%
         \egroup}%
      \getvalue{#1}}%
   \getparameters[\??al#1]%
     [\c!n=3,
      \c!voor=\blanko,
      \c!na=\blanko,
      \c!afstand=1em,
      \c!hoogte=\v!passend,
      \c!lijn=\v!uit,
      \c!commando=,
      \c!uitlijnen=,
      \c!tolerantie=\v!soepel,
      \c!letter=,
      \c!kleur=,
      \c!boven=,
      \c!boven=\vss,
      \c!onder=\vfill,
      #2]%
   \setvalue{\e!stel#1\e!in}%
     {\stelalineasin[#1]}%
   \dorecurse
      {\getvalue{\??al#1\c!n}}
      {\stelalineasin[#1][\recurselevel]
         [\c!breedte=,
          \c!onder=\getvalue{\??al#1\c!onder},
          \c!boven=\getvalue{\??al#1\c!boven},
          \c!hoogte=\getvalue{\??al#1\c!hoogte},
          \c!letter=\getvalue{\??al#1\c!letter},
          \c!kleur=\getvalue{\??al#1\c!kleur},
          \c!lijn=\getvalue{\??al#1\c!lijn},
          \c!uitlijnen=\getvalue{\??al#1\c!uitlijnen},
          \c!tolerantie=\getvalue{\??al#1\c!tolerantie},
          \c!afstand=\getvalue{\??al#1\c!afstand}]}%
   \stelalineasin[#1][1][\c!afstand=0em]}

% nog monster
%
%\assignwidth
%  {\!!widtha}
%  {\getvalue{\??dd#1\c!breedte}}
%  {\doifelsevaluenothing{\??dd#1\c!monster}
%     {\hskip
%     {\doattributes
%        {\??al#1}\c!letter\c!kleur
%        {\getvalue{\??dd#1\c!monster}}}}
%  {0pt}

\def\definieeralineas%
  {\dodoubleargument\dodefinieeralineas}

\def\dostelalineasin[#1][#2][#3]%
  {\doifelse{#2}\v!elk
     {\dorecurse
        {\getvalue{\??al#1\c!n}}
        {\getparameters[\??al#1\recurselevel][#3]}}
     {\ConvertToConstant\doifelse{#3}{}
        {\getparameters[\??al#1][#2]}
        {\def\docommando##1%
           {\getparameters[\??al#1##1][#3]}%
         \processcommalist[#2]\docommando}}}

\def\stelalineasin
  {\dotripleempty\dostelalineasin}

\newcount\alteller
\newcount\alnsize
\newdimen\alhsize

\def\doalinealijn#1#2%
  {\doifelsevalue{\??al#2\the\alteller\c!lijn}\v!aan
     {\dimen2=#1\relax
      \hskip.5\dimen2
      \hskip-\linewidth
      \vrule\!!width\linewidth
      \hskip.5\dimen2}
     {\hskip#1}}

\def\dostartalinea#1%
  {\doifelsevaluenothing{\??al#1\the\alteller\c!breedte}
     {\!!widtha\alhsize
      \divide\!!widtha \alnsize}
     {\!!widtha\getvalue{\??al#1\the\alteller\c!breedte}}%
   \dostartattributes
     {\??al#1\the\alteller}\c!letter\c!kleur
     \empty
   \doifelsevalue{\??al#1\the\alteller\c!hoogte}\v!passend
     {\setbox0\vtop}
     {\setbox0\vtop to \getvalue{\??al#1\the\alteller\c!hoogte}}%
   \bgroup
   \blanko[\v!blokkeer]%
   \forgetall
   \getvalue{\??al#1\the\alteller\c!boven}%
   \getvalue{\??al#1\c!binnen}%
   \hsize\!!widtha  % setting \wd afterwards removed
   \getvalue{\??al#1\the\alteller\c!binnen}%
   \edef\!!stringa{\getvalue{\??al#1\the\alteller\c!uitlijnen}}%  nodig?
   \expandafter\steluitlijnenin\expandafter[\!!stringa]%
   \edef\!!stringa{\getvalue{\??al#1\the\alteller\c!tolerantie}}% nodig?
   \expandafter\steltolerantiein\expandafter[\!!stringa]%
   \ignorespaces
   \endgraf
   \ignorespaces
   %
   % Nadeel van de onderstaande constructie is dat \everypar
   % binnen een groep kan staan en zo steeds \begstruts
   % worden geplaatst. Mooi is anders dus moet het anders!
   %
   % Hier is \Everypar niet nodig.
   %
   \everypar{\begstrut\everypar\emptytoks}%
   %
   \ignorespaces\geenspatie % dubbel: \ignorespaces
   \getvalue{\??al#1\the\alteller\c!commando}}

\def\dostopalinea#1%
  {\ifvmode
     \removelastskip
   \else
     \unskip\endstrut\endgraf
   \fi
   \getvalue{\??al#1\the\alteller\c!onder}%
   \egroup
   \ifdim\wd0=\zeropoint % no data
     \wd0\!!widtha
   \fi
   \box0
   \dostopattributes
   %\ifnum\alteller<\getvalue{\??al#1\c!n}\relax
   %  \def\next{\doalinea{#1}}%
   %\else
   %  \def\next{\dostopalineas{#1}}%
   %\fi
   %\next}
   \ifnum\alteller<\getvalue{\??al#1\c!n}\relax
     \@EA\doalinea
   \else
     \@EA\dostopalineas
   \fi{#1}}

\def\doalinea#1%
  {\global\advance\alteller \plusone
   \doifelsevaluenothing{\??al#1\the\alteller\c!afstand}
     {\doifnot{\the\alteller}{1}
        {\hskip\getvalue{\??al#1\c!afstand}}}
     {\doifelse{\the\alteller}{1}%
        {\hskip\getvalue{\??al#1\the\alteller\c!afstand}}
        {\doalinealijn{\getvalue{\??al#1\the\alteller\c!afstand}}{#1}}}%
   \setvalue{#1}{\dostopalinea{#1}}%
   \dostartalinea{#1}}

\def\dostartalineas#1%
  {\global\alteller\zerocount
   \parindent\zeropoint
   \setlocalhsize
   \alhsize\localhsize
   \alnsize\getvalue{\??al#1\c!n}\relax
   \dorecurse
     {\getvalue{\??al#1\c!n}}
     {\doifelsevaluenothing{\??al#1\recurselevel\c!afstand}
        {\doifnot{\recurselevel}{1}
           {\global\advance\alhsize -\getvalue{\??al#1\c!afstand}\relax}}
        {\global\advance\alhsize -\getvalue{\??al#1\recurselevel\c!afstand}\relax}%
      \doifvaluesomething{\??al#1\recurselevel\c!breedte}
        {\global\advance\alnsize \minusone
         \global\advance\alhsize -\getvalue{\??al#1\recurselevel\c!breedte}\relax}}%
   %\witruimte                 % gaat fout bij \framed
   \getvalue{\??al#1\c!voor}%
   \leavevmode                 % gaat wel goed bij \framed
   \vbox\bgroup\hbox\bgroup\doalinea{#1}}

\def\dostopalineas#1%
  {\egroup
   \egroup
   \par
   \getvalue{\??al#1\c!na}}%

\def\dosteltabin[#1]%
  {\getparameters[\??ta]
     [\c!kopletter=\v!normaal,
      \c!kopkleur=,
      \c!letter=\v!normaal,
      \c!kleur=,
      \c!breedte=\v!ruim,
      \c!monster={\hskip4em},
      \c!voor=,
      \c!na=,
      #1]%
   \doordefinieren
     [tab]
     [\c!kopletter=\@@takopletter,
      \c!kopkleur=\@@takleur,
      \c!monster=\@@tamonster,
      \c!breedte=\@@tabreedte,
      \c!voor=\@@tavoor,
      \c!na=\@@tana]}

\def\steltabin
  {\dosingleargument\dosteltabin}

\steltabin
  [\c!plaats=\v!links]

% The following macro's are derived from PPCHTEX and
% therefore take some LaTeX font-switching into account.

\newif\ifloweredsubscripts

% Due to some upward incompatibality of LaTeX to LaTeX2.09
% and/or LaTeX2e we had to force \@@chemieletter. Otherwise
% some weird \nullfont error comes up.

\doifundefined{@@chemieletter}{\def\@@chemieletter{\rm}}

\def\beginlatexmathmodehack
  {\ifmmode
     \let\endlatexmathmodehack\relax
   \else
     \def\endlatexmathmodehack{$}$\@@chemieletter
   \fi}

\def\setsubscripts
  {\beginlatexmathmodehack
   \def\dosetsubscript##1##2##3%
     {\dimen0=##3\fontdimen5##2%
      \setxvalue{@@\string##1\string##2}{\the##1##2\relax}%
      ##1##2=\dimen0\relax}%
   \def\dodosetsubscript##1##2%
     {\dosetsubscript{##1}{\textfont2}{##2}%
      \dosetsubscript{##1}{\scriptfont2}{##2}%
      \dosetsubscript{##1}{\scriptscriptfont2}{##2}}%
  %\dodosetsubscript{\fontdimen14}{?}%
   \dodosetsubscript{\fontdimen16}{.7}%
   \dodosetsubscript{\fontdimen17}{.7}%
   \global\loweredsubscriptstrue
   \endlatexmathmodehack}

\def\resetsubscripts
  {\ifloweredsubscripts
     \beginlatexmathmodehack
     \def\doresetsubscript##1##2%
       {\dimen0=\getvalue{@@\string##1\string##2}\relax
        ##1##2=\dimen0}%
     \def\dodoresetsubscript##1%
       {\doresetsubscript{##1}{\textfont2}%
        \doresetsubscript{##1}{\scriptfont2}%
        \doresetsubscript{##1}{\scriptscriptfont2}}%
    %\dodoresetsubscript{\fontdimen14}%
     \dodoresetsubscript{\fontdimen16}%
     \dodoresetsubscript{\fontdimen17}%
     \global\loweredsubscriptsfalse
     \endlatexmathmodehack
   \fi}

\let\beginlatexmathmodehack = \relax
\let\endlatexmathmodehack   = \relax

\def\chem#1#2#3%
  {\bgroup
   \setsubscripts
   \mathematics{\hbox{#1}_{#2}^{#3}}%
   \resetsubscripts
   \egroup}

\def\celsius#1{#1\mathematics{^\circ}C}
\def\graden   {\mathematics{^\circ}}
\def\inch     {\hbox{\rm\char125\relax}}
\def\breuk#1#2{\mathematics{#1\over#2}}

\def\bedragprefix {\euro\normalfixedspace}
\def\bedragsuffix {}
\def\bedragempty  {\euro}

\unexpanded\def\bedrag#1%
  {\strut\hbox\bgroup
   \let\normalfixedspace~%
   \doifelsenothing{#1}
     {\bedragempty}
     {\bedragprefix\digits{#1}\bedragsuffix}%
   \egroup}

% \definieeralineas[test][n=3]
%
% \stelalineasin[test][3][breedte=4cm,uitlijnen=links]
%
% \startopelkaar
% \test hans \\ ton \\ \bedrag{1.000,--} \\
% \test hans \\ ton \\ \bedrag{~.~~1,--} \\
% \test hans \\ ton \\ \bedrag{~.~~1,~~} \\
% \test hans \\ ton \\ \bedrag{~.100,--} \\
% \test hans \\ ton \\ \subtot{1.000,--} \\
% \test hans \\ ton \\ \bedrag{1.000,--} \\
% \test hans \\ ton \\ \bedrag{1.000,--} \\
% \test hans \\ ton \\ \totaal{1.000,--} \\
% \test hans \\ ton \\ \bedrag{nihil,--} \\
% \test hans \\ ton \\ \totaal{nihil,--} \\
% \test hans \\ ton \\ \subtot{nihil,--} \\
% \stopopelkaar

\def\doorsnede
  {\hbox{\rlap/$\circ$} }

\def\punten
  {\dosingleempty\dopunten}

\def\dopunten[#1]%
  {\scratchdimen.5em%
   \hbox to \iffirstargument#1\else5\fi \scratchdimen
     {\leaders\hbox to \scratchdimen{\hss.\hss}\hss}}

\def\ongeveer
  {\mathematics\pm}

% for compatibility

\def\unknown
  {\dontleavehmode\punten[3]}

\def\leftboundarycharacter#1#2%
  {\languageparameter#1%
   \nobreak
   \hskip\hspaceamount\currentlanguage{#2}}

\def\rightboundarycharacter#1#2%
  {\nobreak
   \hskip\hspaceamount\currentlanguage{#2}%
   \languageparameter#1}

% actually this is pretty old, but temporary moved here

\def\stelkoppeltekenin
  {\dodoubleargument\getparameters[\??kp]}

\stelkoppeltekenin
  [\c!teken=\compoundhyphen]
 
\definehspace [sentence]      [\zeropoint]
\definehspace [intersentence] [.250em]

\definesymbol
  [\c!leftsentence]
  [\leftboundarycharacter\c!leftsentence{sentence}]

\definesymbol
  [\c!rightsentence]
  [\rightboundarycharacter\c!rightsentence{sentence}]

\definesymbol
  [\c!leftsubsentence]
  [\leftboundarycharacter\c!leftsubsentence{sentence}]

\definesymbol
  [\c!rightsubsentence]
  [\rightboundarycharacter\c!rightsubsentence{sentence}]

\installdiscretionaries || \@@kpteken

\newsignal \subsentencesignal
\newcounter\subsentencelevel

\def\beginofsubsentence
  {\ifdim\lastkern=\subsentencesignal
     \unskip
     \kern\hspaceamount\currentlanguage{intersentence}%
   \fi
   \doglobal\increment\subsentencelevel
   \ifnum\subsentencelevel=\plusone
     \leaveoutervmode
   \fi
   \symbol[\ifodd\subsentencelevel\c!leftsentence   \else
                                  \c!leftsubsentence\fi]%
   \ignorespaces}

\def\beginofsubsentencespacing
  {\kern\subsentencesignal\ignorespaces}

\def\endofsubsentence
  {\symbol[\ifodd\subsentencelevel\c!rightsentence   \else
                                  \c!rightsubsentence\fi]%
   \doglobal\decrement\subsentencelevel
   \unskip
   \kern\subsentencesignal}

\def\endofsubsentencespacing
  {\ifdim\lastkern=\subsentencesignal
     \unskip
     \hskip\hspaceamount\currentlanguage{intersentence}%
     \ignorespaces
   \else
     \unskip
   \fi}

% test |<|test |<|test|>| test|>| test \par
% test|<|test|<|test|>|test|>|test     \par
% test |<||<|test|>||>| test           \par

\enableactivediscretionaries

\definehspace [quotation]      [\zeropoint]
\definehspace [interquotation] [.125em]

%definehspace [quote]  [\zeropoint]
%definehspace [speech] [\zeropoint]

\definehspace [quote]  [\hspaceamount\currentlanguage{quotation}]
\definehspace [speech] [\hspaceamount\currentlanguage{quotation}]

\definesymbol
  [\c!leftquotation] 
  [\leftboundarycharacter\c!leftquotation{quotation}]

\definesymbol
  [\c!rightquotation] 
  [\rightboundarycharacter\c!rightquotation{quotation}]

\definesymbol
  [\c!leftquote]      
  [\leftboundarycharacter\c!leftquote{quote}]

\definesymbol
  [\c!rightquote]     
  [\rightboundarycharacter\c!rightquote{quote}]

\definesymbol
  [\c!leftspeech]   
  [\leftboundarycharacter\c!leftspeech{speech}]

\definesymbol
  [\c!rightspeech]  
  [\rightboundarycharacter\c!rightspeech{speech}]

\definesymbol
  [\c!middlespeech] 
  [\leftboundarycharacter\c!middlespeech{speech}]

%%%%% will be replaced by delimitedtext %%%%%

\def\leftquotationmark
  {\setbox\scratchbox\hbox{\symbol[\c!leftquotation]}%
   \doif\@@ciplaats\v!marge{\hskip-\wd\scratchbox}%
   \box\scratchbox}

\def\rightquotationmark
  {\hsmash{\symbol[\c!rightquotation]}}

\newsignal\quotationsignal

\def\stelciterenin
  {\dodoubleargument\getparameters[\??ci]}

\def\stelcitatenin
  {\stelciterenin}

\def\startcitaat
  {\bgroup\dosingleempty\dostartcitaat}

\def\dostartcitaat[#1]%
  {\@@civoor
   \doifelsenothing{#1}
     {\let\dostopcitaat\relax}
     {\startsmaller[#1]%
      \let\dostopcitaat\stopsmaller}%
   \dostartattributes\??ci\c!letter\c!kleur\empty
   \leftquotationmark
   \ignorespaces}

\def\stopcitaat
  {\removeunwantedspaces
   \removelastskip
   \rightquotationmark
   \dostopattributes
   \dostopcitaat
   \@@cina
   \egroup}

\def\dohandlequotation#1#2%
  {\ifdim\lastskip=\quotationsignal
     \unskip\hskip\hspaceamount\currentlanguage{interquotation}%
   \else
     #2%
   \fi
   \ifhmode % else funny pagebeaks
     \penalty\!!tenthousand\hskip\zeropoint      % == \prewordbreak
   \fi
   \strut % new, needed below
   \symbol[#1]%
   \penalty\!!tenthousand\hskip\quotationsignal} % +- \prewordbreak

\def\handlequotation#1%
  {\dohandlequotation{#1}\relax}

\unexpanded\def\citaat
  {\groupedcommand
     {\dohandlequotation\c!leftquotation \relax}
     {\dohandlequotation\c!rightquotation\removelastskip}}

\unexpanded\def\citeer
  {\doifelse\@@ciletter\v!normaal\doquotedcite\doattributedcite}

\def\doquotedcite
  {\groupedcommand
     {\dohandlequotation\c!leftquote \relax}
     {\dohandlequotation\c!rightquote\removelastskip}}

\def\doattributedcite
  {\groupedcommand
     {\dostartattributes\??ci\c!letter\c!kleur}
     {\dostopattributes}}

%D The previous one fails in \placefloat[left]{}{}, so instead
%D we use the next alternative, where the first one is handled
%D outside group. Watch the strut.

\unexpanded\def\citaat
  {\dohandlequotation\c!leftquotation\relax
   \groupedcommand \donothing 
     {\dohandlequotation\c!rightquotation\removelastskip}}

\def\doquotedcite
  {\dohandlequotation\c!leftquote\relax
   \groupedcommand \donothing
     {\dohandlequotation\c!rightquote\removelastskip}}

\stelciterenin
  [\c!plaats=\v!marge,
   \c!letter=\v!normaal,
   \c!kleur=,
   \c!voor=\startsmaller,
   \c!na=\stopsmaller]

%D The next features was so desperately needed by Giuseppe
%D Bilotta that he made a module for it. Since this is a
%D typical example of core functionality, I decided to extend
%D the low level quotation macros in such a way that a speech
%D feature could be build on top of it. The speech opening and
%D closing symbols are defined per language. Italian is an
%D example of a language that has them set.

%%%%% will be replaced by delimitedtext %%%%%

\newcounter\speechlevel \newconditional\insidespeech

\def\startspeech
  {\doglobal\increment\speechlevel\relax
   \dohandlequotation\c!leftspeech\relax
   \global\settrue\insidespeech
   \ignorespaces}

\def\stopspeech
  {\dohandlequotation\c!rightspeech\removelastskip
   \doglobal\decrement\speechlevel\relax
   \ifcase\speechlevel\relax \global\setfalse\insidespeech \fi}

\def\dohandlespeech % indirect since called in everypar
  {\relax % still needed?
   \ifcase\speechlevel\or\dodohandlespeech\fi}

\def\dodohandlespeech
  {\ifconditional\insidespeech
     \dohandlequotation\c!middlespeech\relax
   \else
     \global\settrue\insidespeech
   \fi}

\unexpanded\def\speech
  {\doglobal\increment\speechlevel\relax
   \dohandlequotation\c!leftspeech\relax
   \groupedcommand \ignorespaces
     {\dohandlequotation\c!rightspeech\removelastskip
      \doglobal\decrement\speechlevel\relax}}

\appendtoks \dohandlespeech \to \everypar

% this will replace the quotation and speed definitions 

\newsignal\delimitedtextignal

\def\delimitedtextparameter#1%
  {\csname\??ci
     \ifundefined{\??ci\currentdelimitedtext#1}\else\currentdelimitedtext\fi
   #1\endcsname}

\def\definedelimitedtext
  {\dodoubleempty\dodefinedelimitedtext}

\def\dodefinedelimitedtext[#1][#2]%
  {\doifassignmentelse{#2}
     {\getparameters
        [\??ci#1]
        [\c!plaats=\v!marge, % \v!tekst \v!alinea 
         \c!voorwit=,
         \c!nawit=\delimitedtextparameter\c!voorwit,
         \c!letter=\v!normaal,
         \c!kleur=,
         \c!linkermarge=\zeropoint,
         \c!rechtermarge=\delimitedtextparameter\c!linkermarge,
         \c!springvolgendein=\v!ja,
         \c!voor=,
         \c!na=,
         \c!links=,
         \c!rechts=,
         \c!niveau=0,
         \c!herhaal=\v!nee,
        #2]}%
     {\doifdefined{#2} 
        {\copyparameters[\??ci#1][\??ci#2]
           [\c!plaats,\c!voorwit,\c!nawit,\c!letter,\c!kleur,
            \c!linkermarge,\c!rechtermarge,\c!springvolgendein,
            \c!voor,\c!na,\c!links,\c!rechts]}}%
   \doifsomething{#1}
     {\unexpanded\setvalue{#1}{\delimitedtext[#1]}%
      \setvalue{\e!start#1}{\startdelimitedtext[#1]}%
      \setvalue{\e!stop#1}{\stopdelimitedtext}}}

\def\setupdelimitedtext
  {\dodoubleargument\dosetupdelimitedtext}

\def\dosetupdelimitedtext[#1][#2]%
  {\ifsecondargument
     \getparameters[\??ci#1][#2]%
   \else
     \getparameters[\??ci][#1]%
   \fi}

\def\dorepeatdelimitedtext
  {\relax\ifcase\delimitedtextparameter\c!niveau\else
     \dohandledelimitedtext\c!midden
   \fi}

\def\startdelimitedtext[#1]%
  {\bgroup
   \def\currentdelimitedtext{#1}%
   \doif{\delimitedtextparameter\c!herhaal}\v!ja
     {\appendtoks \dorepeatdelimitedtext \to \everypar}%
   \doifinsetelse{\delimitedtextparameter\c!plaats}{\v!alinea,\v!marge}%
     {\dosingleempty\dostartdelimitedtextpar}\dostartdelimitedtexttxt}

\def\dostartdelimitedtextpar[#1]%                                     
  {\let\dostopdelimitedtext\dostopdelimitedtextpar
   \doifsomething{\delimitedtextparameter\c!voorwit}
     {\blanko[\delimitedtextparameter\c!voorwit]}%
   \delimitedtextparameter\c!voor
   % nicer: 
   % \doadaptleftskip {\delimitedtextparameter\c!linkermarge}%
   % \doadaptrightskip{\delimitedtextparameter\c!rechtermarge}%
   % backward compatible: 
   \doifelsenothing{#1}
     {\doadaptleftskip {\delimitedtextparameter\c!linkermarge}%
      \doadaptrightskip{\delimitedtextparameter\c!rechtermarge}%
      \let\dodostopdelimitedtextpar\endgraf}
     {\startsmaller[#1]\let\dodostopdelimitedtextpar\stopsmaller}%
   % so far 
   \doif{\delimitedtextparameter\c!springvolgendein}\v!nee\noindentation
   \dostartattributes{\??ci\currentdelimitedtext}\c!letter\c!kleur\empty
   \leftdelimitedtextmark
   \doglobal\incrementvalue{\??ci\currentdelimitedtext\c!niveau}%
   \ignorespaces}

\def\dostopdelimitedtextpar
  {\removeunwantedspaces
   \removelastskip
   \rightdelimitedtextmark
   \dostopattributes
   \dodostopdelimitedtextpar
   \delimitedtextparameter\c!na
   \doifsomething{\delimitedtextparameter\c!nawit}
     {\blanko[\delimitedtextparameter\c!nawit]}}

\def\dostartdelimitedtexttxt
  {\let\dostopdelimitedtext\dostopdelimitedtexttxt
   \dostartattributes{\??ci\currentdelimitedtext}\c!letter\c!kleur\empty
   \dohandledelimitedtext\c!links
   \ignorespaces}

\def\dostopdelimitedtexttxt
  {\removeunwantedspaces
   \dohandledelimitedtext\c!rechts
   \dostopattributes}

\def\stopdelimitedtext 
  {\dostopdelimitedtext
   \doglobal\decrementvalue{\??ci\currentdelimitedtext\c!niveau}%
   \egroup}

\def\delimitedtext[#1]%
  {\pushmacro\currentdelimitedtext 
   \def\currentdelimitedtext{#1}%
   \doifinsetelse{\delimitedtextparameter\c!plaats}{\v!alinea,\v!marge}%
     \dodelimitedtextpar\dodelimitedtexttxt}

% shortcuts 

\def\startdelimited{\startdelimitedtext}
\def\stopdelimited {\stopdelimitedtext}  % no let, dynamically assigned
\def\delimited     {\delimitedtext}

\def\leftdelimitedtextmark
  {\dontleavehmode 
   \setbox\scratchbox\hbox{\delimitedtextparameter\c!links}%
   \doif{\delimitedtextparameter\c!plaats}\v!marge{\hskip-\wd\scratchbox}%
   \box\scratchbox}

\def\rightdelimitedtextmark
  {\hsmash{\delimitedtextparameter\c!rechts}}

\def\dohandledelimitedtext#1#2%
  {\bgroup
   \setbox\scratchbox\hbox{#1}%
   \ifdim\wd\scratchbox>\zeropoint
     \ifdim\lastskip=\delimitedtextignal
       \unskip\hskip\hspaceamount\currentlanguage{interquotation}%
     \else
       #2%
     \fi
     \ifhmode % else funny pagebeaks
       \penalty\!!tenthousand\hskip\zeropoint % == \prewordbreak
     \fi
     \strut % new, needed below
     \delimitedtextparameter#1%
     \penalty\!!tenthousand\hskip\delimitedtextignal % +- \prewordbreak
   \fi
   \egroup}

\def\handledelimitedtext#1%
  {\dohandledelimitedtext{#1}\relax}

\unexpanded\def\dodelimitedtextpar
  {\dohandledelimitedtext\c!links\relax
   \groupedcommand
     \donothing
     {\dohandledelimitedtext\c!rechts\removelastskip}}

\unexpanded\def\dodelimitedtexttxt
  {\doifelse{\delimitedtextparameter\c!letter}\v!normaal
     \doquoteddelimited\doattributeddelimited}

\def\doquoteddelimited
  {\dohandledelimitedtext\c!links\relax
   \groupedcommand 
     \donothing
     {\dohandledelimitedtext\c!rechts
      \removelastskip
      \popmacro\currentdelimitedtext}}

\def\doattributeddelimited
  {\groupedcommand
     {\dostartattributes{\??ci\currentdelimitedtext}\c!letter\c!kleur}
     {\dostopattributes
      \popmacro\currentdelimitedtext}}

% \definedelimitedtext
%   [\v!citaat]
%   [\c!links={\symbol[\c!leftquotation]},
%    \c!rechts={\symbol[\c!rightquotation]},
%    \c!linkermarge=\v!standaard]
% 
% \definedelimitedtext
%   [\v!citeer][\v!citaat]
% 
% \setupdelimitedtext
%   [\v!citeer]
%   [\c!plaats=\v!tekst, 
%    \c!links={\symbol[\c!leftquote]},
%    \c!rechts={\symbol[\c!rightquote]}]
% 
% \definedelimitedtext
%   [\v!spraak][\v!citaat]
% 
% \setupdelimitedtext
%   [\v!spraak]
%   [\c!herhaal=\v!ja,
%    \c!links={\symbol[\c!leftspeech]},
%    \c!midden={\symbol[\c!middlespeech]},
%    \c!rechts={\symbol[\c!rightspeech]}]
% 
% % how do we call an tight quote 
% %
% % \definedelimitedtext
% %    [x\v!citaat][\v!citaat]
% %
% % \setupdelimitedtext
% %   [x\v!citaat]
% %   [\c!springvolgendein=\v!nee,
% %    \c!voorwit=\v!geenwit]
% 
% \def\stelciterenin{\setupdelimitedtext[\v!citaat]}
% \def\stelcitatenin{\setupdelimitedtext[\v!citeer]}

% seldom used, move from kernel to run time module 

% Tijden horen hier niet thuis en zullen in een aparte
% module worden ondergebracht. voorlopig handhaven we ze nog
% even. Een implementatie met \doordefinieren zou beter voldoen
% omdat een en ander dan instelbaar wordt. Het is trouwens
% zowieso beter het commando \tijd te reserveren voor de
% systeemtijd.

\def\tijd#1%
  {\setbox0=\hbox{00.00}%
   \hbox to \wd0{\hfill#1}}

\def\tijdspan#1#2%
  {\hbox{\tijd{#1}~---~\tijd{#2}}}

\def\activiteit#1#2%
  {\activity{\tijdspan{#1}{#2}}}

\def\activiteit#1#2%
  {\sym{\tijdspan{#1}{#2}}}

% seldom used, move from kernel to run time module 

\def\dotoevoegen#1%
  {\def\next{#1}%
   \dorecurse{#1}{\inlinker{\next~+}\let\next\empty\crlf}}

\def\complextoevoegen[#1]%
  {\blanko
   \processaction
     [#1]
     [  \v!klein=>\dotoevoegen{3},
       \v!middel=>\dotoevoegen{6},
        \v!groot=>\dotoevoegen{9},
      \s!default=>\dotoevoegen{6},
      \s!unknown=>\dotoevoegen{#1}]
   \blanko}

\definecomplexorsimpleempty\toevoegen

% seldom used, move from kernel to run time module 

\def\basegrid 
  {\dosingleempty\dobasegrid} 

\def\dobasegrid[#1]%
  {\begingroup
   \getparameters[\??rt]
     [\c!x=0,\c!y=0,
      \c!nx=10,\c!ny=10,
      \c!dx=.5,\c!dy=.5,
      \c!xstap=0,\c!ystap=0,
      \c!eenheid=\s!cm,
      \c!schaal=1,
      \c!factor=1,
      \c!offset=\v!ja,
      \c!plaats=\v!links,
      #1]%
   \startpositioning
     \dimen0=\@@rtdx\@@rteenheid\relax
     \dimen0=\@@rtschaal\dimen0\relax
     \dimen0=\@@rtfactor\dimen0\relax
     \multiply\dimen0 \@@rtnx\relax
     \dimen2=\@@rtdy\@@rteenheid\relax
     \dimen2=\@@rtschaal\dimen2\relax
     \dimen2=\@@rtfactor\dimen2\relax
     \multiply\dimen2 \@@rtny\relax
     \def\horline
       {\vbox
          {\hrule
             \!!width \dimen0
             \!!height \linewidth
             \!!depth \!!zeropoint}}%
     \def\verline%
       {\vrule
          \!!width \linewidth
          \!!height \dimen2
          \!!depth \!!zeropoint}%
     \doglobal\newcounter\@@gridc
     \doglobal\newcounter\@@gridd
     \doglobal\newcounter\@@gride
     \def\setlegend##1##2##3%
       {\gdef\@@gridc{0}%
        \dimen0=2em\relax
        \dimen2=##2\@@rteenheid\relax
        \dimen2=\@@rtschaal\dimen2\relax
        \dimen2=\@@rtfactor\dimen2\relax
        \divide\dimen0 \dimen2\relax
        \xdef\@@gride{\number\dimen0}%
        \ifnum\@@gride>50
          \gdef\@@gride{100}%
        \else\ifnum\@@gride>10
          \gdef\@@gride{50}%
        \else\ifnum\@@gride>5
          \gdef\@@gride{10}%
        \else\ifnum\@@gride>1
          \gdef\@@gride{5}%
        \else
          \gdef\@@gride{1}%
        \fi\fi\fi\fi
        \gdef\@@gridd{0}%
        \def\legend
          {\ifnum\@@gridd=\zerocount
             \vbox
               {\increment(\@@gridc,##1)%
                \hbox to 2em{\hss\@@gridc\hss}}%
             \global\let\@@gridd=\@@gride
           \fi
             \doglobal\decrement\@@gridd
             \doglobal\increment(\@@gridc,##1)}}%
     \def\draw##1##2##3##4##5##6##7##8##9%
       {\setuppositioning
          [\c!status=##8,
           \c!xstap=\v!absoluut,
           \c!ystap=\v!absoluut,
           \c!eenheid=\@@rteenheid,
           \c!schaal=\@@rtschaal,
           \c!factor=\@@rtfactor,
           \c!offset=\@@rtoffset,
           \c!xoffset=##6,
           \c!yoffset=##7]%
        \doifelse{##9}\v!midden
          {\scratchdimen##3pt\scratchdimen.5\scratchdimen
           \edef\@@psxx{\withoutpt\the\scratchdimen}%
           \scratchdimen##4pt\scratchdimen.5\scratchdimen
           \edef\@@psyy{\withoutpt\the\scratchdimen}%
           \scratchcounter##2\advance\scratchcounter -1
           \edef\@@pszz{\the\scratchcounter}}
          {\edef\@@psxx{0}\edef\@@psyy{0}\edef\@@pszz{##2}}%
        \position(\@@psxx,\@@psyy){##1}%
        \setuppositioning
          [\c!status=##8,
           \c!xstap=\v!relatief,
           \c!ystap=\v!relatief,
           \c!schaal=\@@rtschaal,
           \c!factor=\@@rtfactor,
           \c!offset=\@@rtoffset,
           \c!eenheid=\@@rteenheid]%
        \dorecurse\@@pszz{\position(##3,##4){##5}}}%
     \draw
       \verline\@@rtnx\@@rtdx0\verline\!!zeropoint\!!zeropoint\v!start\empty
     \draw
       \horline\@@rtny0\@@rtdy\horline\!!zeropoint\!!zeropoint\v!start\empty
     \tfx
     \doifnot\@@rtxstap{0}
       {\setlegend\@@rtxstap\@@rtdx\@@rtx
        \draw\legend\@@rtnx\@@rtdx0\legend{-1em}{-1.5em}\v!overlay\@@rtplaats}%
     \doifnot\@@rtystap{0}
       {\setlegend\@@rtystap\@@rtdy\@@rty
        \draw\legend\@@rtny0\@@rtdy\legend{-2em}{-.75ex}\v!overlay\@@rtplaats}%
  \stoppositioning
  \endgroup}

\let\grid\basegrid

% Dit wordt:
%
%   \doorverwijzen[naam][instellingen] enz.
%
% waarbij <naam> bijvoorbeeld publicatie is. Dit levert:
%
%   \start<naam>
%   \stop<naam>
%
%   \beginvan<naam>
%   \eindvan<naam>
%
%   \publicatie
%
%   \volledigelijstmetpublicaties
%
% eigenlijk kan ook door... zo worden uitgebreid!

\doornummeren
  [@publicatie]
  [\c!plaats=\v!links,
   \c!breedte=\@@pbbreedte,\c!hang=,\c!monster=,
   \c!voor=\@@pbvoor,\c!na=\@@pbna,\c!tussen=,
   \c!kopletter=\@@pbkopletter,\c!letter=,
   \c!kopkleur=\@@pbkopkleur,\c!kleur=,
   \c!wijze=\@@pbwijze,\c!blokwijze=\@@pbblokwijze,
   \c!tekst=,\c!links=\@@pblinks,\c!rechts=\@@pbrechts]

\def\dostelpublicatiesin[#1]%
  {\getparameters[\??pb][#1]}

\def\stelpublicatiesin%
  {\dosingleargument\dostelpublicatiesin}

\def\apa@publicatie
  {\doifsomething\@@pb@naam    {\@@pb@naam,\space}%
   \doifsomething\@@pb@titel   {{\sl\@@pb@titel}.\space}%
   \doifsomething\@@pb@jaar    {(\@@pb@jaar).\space}%
   \doifsomething\@@pb@plaats  {\@@pb@plaats\doifelsenothing\@@pb@uitgever{.}{:\space}}%
   \doifsomething\@@pb@uitgever{\@@pb@uitgever.}}

\def\normaal@publicatie
  {\@@pb@naam, \@@pb@titel, \@@pb@jaar, \@@pb@pagina, \@@pb@plaats, \@@pb@uitgever.}

\def\complexstartpublicatie[#1]#2\stoppublicatie
  {\bgroup
   \def\dosetpublicatie
     {\processcommalist
        [naam,titel,jaar,plaats,pagina,uitgever]
        \setpublicatie
      \ignorespaces}%
   \def\setpublicatie##1%
      {\letvalue{\??pb @##1}\empty
       \setvalue{##1}####1{\setvalue{\??pb @##1}{####1}\ignorespaces}}%
   \def\getpublicatie%
     {\doifsomething\@@pbvariant{\getvalue{\@@pbvariant @publicatie}}}%
   \doifelse\@@pbnummeren\v!ja
      {\@publicatie[#1]\dosetpublicatie#2\getpublicatie\par}%
      {\@@pbvoor
       \dosetpublicatie\ignorespaces#2\getpublicatie
       \@@pbna}%
   \egroup}

\definecomplexorsimpleempty\startpublicatie

\def\publicatie#1[#2]%
  {\@@pblinks\in{#1}[#2]\@@pbrechts}

\stelpublicatiesin
  [\c!nummeren=\v!ja,
   \c!variant=\c!apa,
   \c!breedte=2em,
   \c!hang=,
   \c!monster=,
   \c!voor=,
   \c!na=,
   \c!tussen=,
   \c!kopletter=,
   \c!kopkleur=,
   \c!letter=,
   \c!kleur=,
   \c!blokwijze=\v!per\v!tekst,
   \c!wijze=\v!per\v!tekst,
   \c!tekst=,
   \c!links={[},
   \c!rechts={]}]

% only used at pragma, move from kernel to run time module 

\def\kenmerkdatum
  {\currentdate[\v!kenmerk]}

\def\dokenmerk[#1]%
   {\noheaderandfooterlines
    \bgroup
    \getparameters
      [\??km]
      [\c!bet=\unknown,\c!dat=\unknown,\c!ken=\unknown,
       \c!van=,\c!aan=,\c!ref=,#1]%
    % moet anders, hoort niet in 01b
    \assigntranslation[\s!nl=referentie,\s!en=reference,\s!de=Referenz,\s!sp=referencia]\to\@@@kmref
    \assigntranslation[\s!nl=van,\s!en=from,\s!de=Von,\s!sp=de]\to\@@@kmvan
    \assigntranslation[\s!nl=aan,\s!en=to,\s!de=An,\s!sp=a]\to\@@@kmaan
    \assigntranslation[\s!nl=betreft,\s!en=concerns,\s!de=Betreff,\s!sp=]\to\@@@kmbet
    \assigntranslation[\s!nl=datum,\s!en=date,\s!de=Datum,\s!sp=fecha]\to\@@@kmdat
    \assigntranslation[\s!nl=kenmerk,\s!en=mark,\s!de=Kennzeichen,\s!sp=]\to\@@@kmken
    %
    \definetabulate[\s!dummy][|l|p|]
    \startdummy
      \NC\@@@kmbet\EQ\@@kmbet\NC\NR
      \NC\@@@kmdat\EQ\@@kmdat\NC\NR
      \NC\@@@kmken\EQ\expanded{\kap{\@@kmken}}\NC\NR
      \doifsomething{\@@kmvan\@@kmaan}{\NC\NC\NC\NR}%
      \doifsomething \@@kmvan         {\NC\@@@kmvan\EQ\@@kmvan\NC\NR}%
      \doifsomething \@@kmaan         {\NC\@@@kmaan\EQ\@@kmaan\NC\NR}%
      \doifsomething \@@kmref         {\NC\NC\NC\NR\NC\@@@kmref\EQ\@@kmref\NC\NR}%
    \stopdummy
    \egroup}

\def\kenmerk
  {\dosingleargument\dokenmerk}

% NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW
% NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW NIEUW

\def\??ri{@@ri}

\def\stelrijenin
  {\dodoubleargument\getparameters[\??ri]}

\def\complexstartrijen[#1]%
  {\bgroup
   \stelrijenin[#1]%
   \let\do@@rionder\relax
   \def\rij
     {\do@@rionder
      \egroup
      \dimen0\vsize
      \divide\dimen0 \@@rin
      \advance\dimen0 -\lineskip
      \vbox to \dimen0
        \bgroup
        \@@riboven
        \let\do@@rionder\@@rionder
        \ignorespaces}%
   \bgroup
   \rij}

\definecomplexorsimpleempty\startrijen

\def\stoprijen
  {\do@@rionder
   \egroup
   \egroup}

\stelrijenin
  [\c!n=2,
   \c!boven=,
   \c!onder=\vfill]

% THIS WAS MAIN-003.TEX

\startmessages  dutch  library: systems
     41: externe file -- in groep -- bestaat niet
\stopmessages

\startmessages  english  library: systems
     41: external file -- in group -- does not exist
\stopmessages

\startmessages  german  library: systems
     41: Externe Datei -- in Gruppe -- existiert nicht
\stopmessages

\startmessages  czech  library: systems
     41: externi soubor -- ve skupine -- neexistuje
\stopmessages

\startmessages  italian  library: systems
     41: il file esterno -- del gruppo -- non esiste
\stopmessages

\startmessages  norwegian  library: systems
     41: ekstern fil -- i gruppe -- eksisterer ikke
\stopmessages

\startmessages  romanian  library: systems
     41: fisierul extern -- din grupul -- nu exista
\stopmessages

\definetabulate
  [\e!legenda]
  [|emj1|i1|mR|]

\setuptabulate
  [\e!legenda]
  [\c!eenheid=.75em,\c!binnen=\setquicktabulate\leg,EQ={=}]

\definetabulate
  [\e!legenda][\v!twee]
  [|emj1|emk1|i1|mR|]

\definetabulate
  [\e!gegeven]
  [|R|ecmj1|i1mR|]

\setuptabulate
  [\e!gegeven]
  [\c!eenheid=.75em,\c!binnen=\setquicktabulate\geg,EQ={=}]

\unexpanded\def\xbox
  {\bgroup\aftergroup\egroup\hbox\bgroup\tx\let\next=}

\unexpanded\def\xxbox
  {\bgroup\aftergroup\egroup\hbox\bgroup\txx\let\next=}

% \def\mrm#1%
%   {$\rm#1$}

%D \macros
%D   {definepairedbox, setuppairedbox, placepairedbox}
%D
%D Paired boxes, formally called legends, but from now on a
%D legend is just an instance, are primarily meant for
%D typesetting some text alongside an illustration. Although
%D there is quite some variation possible, the functionality is
%D kept simple, if only because in most cases such pairs are
%D typeset sober.
%D
%D The location specification accepts a pair, where the first
%D keyword specifies the arrangement, and the second one the
%D alignment. The first key of the location pair is one of
%D \type {left}, \type {right}, \type {top} or \type {bottom},
%D while the second key can also be \type {middle}.
%D
%D The first box is just collected in an horizontal box, but
%D the second one is a vertical box that gets passed the
%D bodyfont and alignment settings.

%  \startbuffer[test]
%  \test left   \test left,top    \test left,bottom  \test left,middle
%  \test right  \test right,top   \test right,bottom \test right,middle
%  \test top    \test top,left    \test top,right    \test top,middle
%  \test bottom \test bottom,left \test bottom,right \test bottom,middle
%  \stopbuffer
%
%  \def\showtest#1%
%    {\pagina
%     \typebuffer[demo]
%     \def\test##1
%       {\startlinecorrection[blank]
%        \getbuffer[demo]%
%        \ruledhbox\placelegend
%          [bodyfont=6pt,location={##1}]
%          {\framed[width=.25\textwidth]{\tttf##1}}
%          {#1}
%        \stoplinecorrection}
%     \getbuffer[test]}
%
%  \startbuffer[demo]
%  \setuplegend
%    [width=\hsize,maxwidth=\makeupwidth,
%     height=\vsize,maxheight=\makeupheight]
%  \stopbuffer
%
%  \showtest{These examples demonstrate the default settings.}
%
%  \startbuffer[demo]
%  \setuplegend
%    [width=\textwidth,
%     maxwidth=\textwidth]
%  \stopbuffer
%
%  \showtest{\input tufte }
%
%  \startbuffer[demo]
%  \setuplegend
%    [width=.65\textwidth]
%  \stopbuffer
%
%  \showtest{\input knuth }
%
%  \startbuffer[demo]
%  \setuplegend
%    [height=2cm]
%  \stopbuffer
%
%  \showtest{These examples demonstrate some other settings.}
%
%  \startbuffer[demo]
%  \setuplegend
%    [width=.65\textwidth,
%     height=2cm]
%  \stopbuffer
%
%  \showtest{These examples demonstrate some other settings.}
%
%  \startbuffer[demo]
%  \setuplegend
%    [n=2,align=right,width=.5\textwidth]
%  \stopbuffer
%
%  \showtest{\input zapf }

%D \macros
%D   {setuplegend, placelegend}
%D
%D It makes sense to typeset a legend to a figure in \TEX\
%D and not in a drawing package. The macro \type {\placelegend}
%D combines a figure (or something else) and its legend. This
%D command is just a paired box.
%D
%D The legend is placed according to \type {location}, being
%D \type {bottom} or \type {right}. The macro macro is used as
%D follows.
%D
%D \starttypen
%D \placefigure
%D   {whow}
%D   {\placelegend
%D      {\externalfigure[cow]}
%D      {\starttabulation
%D       \NC 1 \NC head \NC \NR
%D       \NC 2 \NC legs \NC \NR
%D       \NC 3 \NC tail \NC \NR
%D       \stoptabulation}}
%D
%D \placefigure
%D   {whow}
%D   {\placelegend
%D      {\externalfigure[cow]}
%D      {\starttabulation[|l|l|l|l|]
%D       \NC 1 \NC head \NC 3 \NC tail \NC \NR
%D       \NC 2 \NC legs \NC   \NC      \NC \NR
%D       \stoptabulation}}
%D
%D \placefigure
%D   {whow}
%D   {\placelegend[n=2]
%D      {\externalfigure[cow]}
%D      {\starttabulation
%D       \NC 1 \NC head \NC \NR
%D       \NC 2 \NC legs \NC \NR
%D       \NC 3 \NC tail \NC \NR
%D       \stoptabulation}}
%D
%D \placefigure
%D   {whow}
%D   {\placelegend[n=2]
%D      {\externalfigure[cow]}
%D      {head \par legs \par tail}}
%D
%D \placefigure
%D   {whow}
%D   {\placelegend[n=2]
%D      {\externalfigure[cow]}
%D      {\startitemize[packed]
%D       \item head \item legs \item  tail \item belly \item horns
%D       \stopitemize}}
%D
%D \placefigure
%D   {whow}
%D   {\placelegend[n=2,width=.8\hsize]
%D      {\externalfigure[cow]}
%D      {\startitemize[packed]
%D       \item head \item legs \item  tail \item belly \item horns
%D       \stopitemize}}
%D \stoptypen

\newbox\firstpairedbox
\newbox\secondpairedbox

\def\definepairedbox
  {\dodoubleempty\dodefinepairedbox}

\def\dodefinepairedbox[#1][#2]%
  {\getparameters
     [\??ld#1]
     [\c!n=1,
      \c!afstand=\bodyfontsize,
      \c!voor=,
      \c!na=,
      \c!tussen={\blanko[\v!middel]},
      \c!breedte=\hsize,
      \c!hoogte=\vsize,
      \c!maxbreedte=\zetbreedte,
      \c!maxhoogte=\zethoogte,
      \c!korps=,
      \c!uitlijnen=,
      \c!plaats=\v!onder,
      #2]%
   \setvalue{\e!stel#1\e!in}{\setuppairedbox[#1]}%
   \setvalue{\e!plaats#1}{\placepairedbox[#1]}}

\def\setuppairedbox
  {\dodoubleempty\dosetuppairedbox}

\def\dosetuppairedbox[#1]%
  {\getparameters[\??ld#1]}

\def\placepairedbox
  {\bgroup\dodoubleempty\doplacepairedbox}

\def\doplacepairedbox[#1][#2]% watch the hsize/vsize tricks
  {\setuppairedbox[#1][#2]%     % and don't change them
   \copyparameters
     [\??ld][\??ld#1]
     [\c!n,\c!afstand,\c!tussen,\c!voor,\c!na,
      \c!breedte,\c!hoogte,\c!maxbreedte,\c!maxhoogte,
      \c!korps,\c!uitlijnen,\c!plaats]%
   \@@ldvoor\bgroup
   \beforefirstpairedbox
   \dowithnextbox
     {\betweenbothpairedboxes
      \dowithnextbox
        {\afterbothpairedboxes
         \egroup\@@ldna
         \egroup}
      \vbox\bgroup
        \insidesecondpairedbox
        \let\next=}
   \hbox}

\def\beforefirstpairedbox
  {\chardef\pairedlocationa1 % left
   \chardef\pairedlocationb4 % middle
   \getfromcommacommand[\@@ldplaats][1]%
   \processaction
     [\commalistelement]
     [ \v!links=>\chardef\pairedlocationa0,
      \v!rechts=>\chardef\pairedlocationa1,
       \v!boven=>\chardef\pairedlocationa2,
       \v!onder=>\chardef\pairedlocationa3]%
   \getfromcommacommand[\@@ldplaats][2]%
   \processaction
     [\commalistelement]
     [ \v!links=>\chardef\pairedlocationb0,
      \v!rechts=>\chardef\pairedlocationb1,
        \v!hoog=>\chardef\pairedlocationb2,
       \v!boven=>\chardef\pairedlocationb2,
        \v!laag=>\chardef\pairedlocationb3,
       \v!onder=>\chardef\pairedlocationb3,
      \v!midden=>\chardef\pairedlocationb4]}

\def\betweenbothpairedboxes
  {\switchtobodyfont[\@@ldkorps]% split under same regime
   \setbox\firstpairedbox\box\nextbox
   \ifnum\pairedlocationa<2
     \hsize\wd\firstpairedbox % trick
     \hsize\@@ldbreedte
     \scratchdimen\wd\firstpairedbox
     \advance\scratchdimen \@@ldafstand
     \bgroup\advance\scratchdimen \hsize
     \ifdim\scratchdimen>\@@ldmaxbreedte\relax
       \egroup
       \hsize\@@ldmaxbreedte
       \advance\hsize -\scratchdimen
     \else
       \egroup
     \fi
   \else
     \hsize\wd\firstpairedbox
     \hsize\@@ldbreedte % can be \hsize
     \ifdim\hsize>\@@ldmaxbreedte\relax \hsize\@@ldmaxbreedte \fi % can be \hsize
   \fi
   \ifnum\@@ldn>\plusone
     \setrigidcolumnhsize\hsize\@@ldafstand\@@ldn
   \fi}

\def\afterbothpairedboxes
  {\setbox\secondpairedbox\vbox
     {\ifnum\@@ldn>1 \rigidcolumnbalance\nextbox \else \box\nextbox \fi}%
   \ifnum\pairedlocationa<2\hbox\else\vbox\fi\bgroup % hide vsize
   \forgetall
   \ifnum\pairedlocationa<2
     \scratchdimen\maxoftwoboxdimens\ht\firstpairedbox\secondpairedbox
     \vsize\scratchdimen
     \ifdim\scratchdimen<\@@ldhoogte\relax % can be \vsize
       \scratchdimen\@@ldhoogte
     \fi
     \ifdim\scratchdimen>\@@ldmaxhoogte\relax
       \scratchdimen\@@ldmaxhoogte
     \fi
     \valignpairedbox\firstpairedbox \scratchdimen
     \valignpairedbox\secondpairedbox\scratchdimen
   \else
     \scratchdimen\maxoftwoboxdimens\wd\firstpairedbox\secondpairedbox
     \halignpairedbox\firstpairedbox \scratchdimen
     \halignpairedbox\secondpairedbox\scratchdimen
     \scratchdimen\ht\secondpairedbox
     \vsize\scratchdimen
     \ifdim\ht\secondpairedbox<\@@ldhoogte\relax % can be \vsize
       \scratchdimen\@@ldhoogte\relax % \relax needed
     \fi
     \ifdim\scratchdimen>\@@ldmaxhoogte\relax % todo: totale hoogte
       \scratchdimen\@@ldmaxhoogte\relax % \relax needed
     \fi
     \ifdim\scratchdimen>\ht\secondpairedbox
       \setbox\secondpairedbox\vbox to \scratchdimen
         {\ifnum\pairedlocationa=3 \vss\fi % 
          \box\secondpairedbox
          \ifnum\pairedlocationa=2 \vss\fi}% \kern\zeropoint
     \fi
   \fi
   \ifcase\pairedlocationa
     \box\secondpairedbox\hskip\@@ldafstand\box\firstpairedbox \or
     \box\firstpairedbox \hskip\@@ldafstand\box\secondpairedbox\or
     \box\secondpairedbox\par  \@@ldtussen \box\firstpairedbox \or
     \box\firstpairedbox \par  \@@ldtussen \box\secondpairedbox\else
   \fi
   \egroup}

\def\insidesecondpairedbox
  {\forgetall
   \steluitlijnenin[\@@lduitlijnen]%
   \tolerantTABLEbreaktrue % hm.
   \blanko[\v!blokkeer]%
   \everypar{\begstrut}}

\def\maxoftwoboxdimens#1#2#3%
  {#1\ifdim#1#2>#1#3 #2\else#3\fi}

\def\valignpairedbox#1#2%
  {\setbox#1\vbox to #2
     {\ifcase\pairedlocationb\or\or\or\vss\or\vss\fi
      \box#1\relax
      \ifcase\pairedlocationb\or\or\vss\or\or\vss\fi}}

\def\halignpairedbox#1#2%
  {\setbox#1\hbox to #2
     {\ifcase\pairedlocationb\or\hss\or\or\or\hss\fi
      \box#1\relax
      \ifcase\pairedlocationb\hss\or\or\or\or\hss\fi}}

\definepairedbox[\e!legenda]

\newcount\horcombination  % counter
\newcount\totcombination

\def\definecombination
  {\dodoubleempty\dodefinecombination}

\def\definecombination[#1][#2]%
  {\copyparameters
     [\??co#1][\??co]
     [\c!breedte,\c!hoogte,\c!afstand,\c!plaats,%
      \c!voor,\c!tussen,\c!na,\c!uitlijnen,%
      \c!letter,\c!kleur]%
   \getparameters
     [\??co#1][#2]}

\def\setupcombinations
  {\dodoubleargument\getparameters[\??co]}

\def\startcombination
  {\dodoubleempty\dostartcombination}

\def\combinationparameter#1%
  {\csname\??co\currentcombination#1\endcsname}%

\def\dostartcombination[#1][#2]%
  {\bgroup
   \ifsecondargument
     \def\currentcombination{#1}%
   \else
     \let\currentcombination\empty
   \fi
   \forgetall
   \doifelse{\combinationparameter\c!hoogte}\v!passend
     {\vbox}{\vbox to \combinationparameter\c!hoogte}%
   \bgroup
  %\doifelsenothing{#1}
  %  {\dodostartcombination[2*1*]}
  %  {\doifelsenothing{#2}
  %     {\dodostartcombination[#1*1*]}
  %     {\dodostartcombination[#2*1*]}}}
   \expanded{\dodostartcombination
     [\ifsecondargument#2\else\iffirstargument#1\else2\fi\fi*1*]}}

\long\def\dodostartcombination[#1*#2*#3]%
  {\stelfractiesin
     [\c!n=\v!passend,\c!afstand=\combinationparameter\c!afstand]%
   \global\horcombination#1%
   \global\totcombination#2%
   \global\setbox\combinationstack\emptybox
   \xdef\maxhorcombination{\the\horcombination}%
   \multiply\totcombination\horcombination
   \tabskip\zeropoint
   \doifelse{\combinationparameter\c!breedte}\v!passend
     {\halign}{\halign to \combinationparameter\c!breedte}%
   \bgroup&%
   %\hfil##\hfil% now : location={left,top}
   \ExpandBothAfter\doifnotinset\v!links{\combinationparameter\c!plaats}\hfil
   ##%
   \ExpandBothAfter\doifnotinset\v!rechts{\combinationparameter\c!plaats}\hfil
   &\tabskip\zeropoint \!!plus 1fill##\cr
   \docombination}

\def\docombination % we want to add struts but still ignore an empty box
  {\dowithnextbox
     {\setbox0\box\nextbox
      \dowithnextbox
        {\setbox2\box\nextbox
         \dodocombination}%
      \vtop\bgroup
        \def\next
          {\futurelet\nexttoken\nextnext}%
        \def\nextnext
          {\ifx\nexttoken\egroup \else % the next box is empty
             \hsize\wd0
             \steluitlijnenin[\combinationparameter\c!uitlijnen]%
\dostartattributes{\??co\currentcombination}\c!letter\c!kleur\empty
             \bgroup
             \aftergroup\endstrut
\aftergroup\dostopattributes
             \aftergroup\egroup
             \begstrut
           \fi}%
        \afterassignment\next\let\nexttoken=}
  \hbox}

% stupid version, does not align top stuff when captions, 
% keep as example
% 
% \def\dodocombination
%   {\vbox
%      {\forgetall % \stelwitruimtein[\v!geen]%
%       \let\next\vbox
%       \ExpandFirstAfter\processallactionsinset
%         [\combinationparameter\c!plaats]
%         [  \v!boven=>\let\next\tbox,
%           \v!midden=>\let\next\halfwaybox]%
%       \next{\copy0}% 
%       \ifdim\ht2>\zeropoint % beter dan \wd2, nu \strut mogelijk
%         \@@cotussen
%         %\vtop % wrong code 
%         %  {\nointerlineskip  % recently added
%         %   \hsize\wd0
%         %   \steluitlijnenin[\combinationparameter\c!uitlijnen]%  % \raggedcenter
%         %   \begstrut\unhbox2\endstrut}%
%         \box2
%       \fi}%
%    \ifnum\totcombination>\plusone
%      \global\advance\totcombination\minusone
%      \global\advance\horcombination\minusone
%      \ifnum\horcombination=\zerocount
%        \def\next
%          {\cr\noalign
%             {\forgetall % \stelwitruimtein[\v!geen]% no 
%              \nointerlineskip
%              \combinationparameter\c!na
%              \combinationparameter\c!voor
%              \vss
%              \nointerlineskip}%
%           \global\horcombination\maxhorcombination\relax
%           \docombination}%
%      \else
%        \def\next
%          {&&&\hskip\combinationparameter\c!afstand&\docombination}%
%      \fi
%    \else
%      \def\next
%        {\cr\egroup}%
%    \fi
%    \next}

\def\dodocombination
  {\vbox
     {\forgetall % \stelwitruimtein[\v!geen]%
      \let\next\vbox
      \ExpandFirstAfter\processallactionsinset
        [\combinationparameter\c!plaats]
        [  \v!boven=>\let\next\tbox,
          \v!midden=>\let\next\halfwaybox]%
      \next{\copy0}%
      % we need to save the caption for a next alignment line
      \saveoncombinationstack2}%
   \ifnum\totcombination>\plusone
     \global\advance\totcombination\minusone
     \global\advance\horcombination\minusone
     \ifnum\horcombination=\zerocount
       \def\next
         {\cr
          \flushcombinationstack
          \noalign
            {\forgetall % \stelwitruimtein[\v!geen]% no
             \global\setbox\combinationstack\emptybox
             \nointerlineskip
             \combinationparameter\c!na
             \combinationparameter\c!voor
             \vss
             \nointerlineskip}%
          \global\horcombination\maxhorcombination\relax
          \docombination}%
     \else
       \def\next
         {&&&\hskip\combinationparameter\c!afstand&\docombination}%
     \fi
   \else
     \def\next
       {\cr
        \flushcombinationstack
        \egroup}%
   \fi
   \next}

\def\stopcombination
  {\egroup
   \egroup}

\newbox\combinationstack

\def\saveoncombinationstack#1% 
  {\global\setbox\combinationstack\hbox
     {\hbox{\box#1}\unhbox\combinationstack}}

\def\flushcombinationstack
  {\noalign
     {\ifdim\ht\combinationstack>\zeropoint
        \@@cotussen
        \global\horcombination\maxhorcombination
        \globallet\doflushcombinationstack\dodoflushcombinationstack
      \else
        \global\setbox\combinationstack\emptybox
        \globallet\doflushcombinationstack\donothing
      \fi}%
   \doflushcombinationstack\crcr}

\gdef\dodoflushcombinationstack
  {\global\setbox\combinationstack\hbox
     {\unhbox\combinationstack
      \global\setbox1\lastbox}%
   \box1% \ruledhbox{\box1}%
   \global\advance\horcombination\minusone\relax
   \ifnum\horcombination>\zerocount
     \def\next{&&&&\doflushcombinationstack}%
   \else
     \global\setbox\combinationstack\emptybox
    %\let\next\relax
     \@EA\gobbleoneargument
   \fi
   \next}

\setupcombinations
  [\c!breedte=\v!passend,
   \c!hoogte=\v!passend,
   \c!afstand=1em,
   \c!plaats=\v!onder, % can be something {top,left} 
   \c!voor=\blanko,
   \c!tussen={\blanko[\v!middel]},
   \c!letter=,
   \c!kleur=,
   \c!na=,
   \c!uitlijnen=\v!midden]

\def\plaatsondernaastelkaar#1#2%
  {\bgroup
   \def\doplaatsondernaastelkaar%
     {#2\cr\omit\bgroup#2%
      \aftergroup#2%
      \aftergroup\cr
      \aftergroup\egroup
      \aftergroup\egroup
      \let\next=}%
   #1\bgroup##\cr
   \omit\bgroup#2%
   \aftergroup\doplaatsondernaastelkaar
   \let\next=}

\def\plaatsonderelkaar
  {\plaatsondernaastelkaar\halign\hss}

\def\plaatsnaastelkaar
  {\plaatsondernaastelkaar\valign\vss}

\def\dogebruikexternefiles[#1][#2]%
  {\getparameters
     [\??fi#1]
     [\c!file=,
      \c!korps=,
      \c!optie=,
      #2]}

\def\gebruikexternefiles
  {\dodoubleargument\dogebruikexternefiles}

\def\dostelexternefilesin[#1][#2]%
  {\doifundefinedelse{\??fi#1\c!file}
     {\gebruikexternefiles[#1][#2]}
     {\getparameters[\??fi#1][#2]}}

\def\stelexternefilesin
  {\dodoubleargument\dostelexternefilesin}

\def\verwerkexternefile#1#2#3%
  {\bgroup
   \getparameters[\??fi#1][\c!file=,#3]%
   \doinputonce{\getvalue{\??fi#1\c!file}}%
   \ExpandFirstAfter\switchtobodyfont[\getvalue{\??fi#1\c!korps}]%
   \readsysfile{#2}  % beter: loc of fix gebied
     \donothing
     {\showmessage\m!systems{41}{#2,#1}}%
   \egroup}

\def\dogebruikexternefile[#1][#2][#3][#4]%
  {\stelexternefilesin[#1][]%
   \doinputonce{\getvalue{\??fi#1\c!file}}%
   \doifelsenothing{#2}
     {\setvalue{#3}{\verwerkexternefile{#1}{#3}{#4}}}
     {\setvalue{#2}{\verwerkexternefile{#1}{#3}{#4}}}}

\def\gebruikexternefile
  {\doquadrupleargument\dogebruikexternefile}

\gebruikexternefiles
  [pictex]
  [\c!korps=\v!klein,
   \c!file=pictex]

\gebruikexternefiles
  [table]
  [\c!file=table]

\presetlocalframed[\??ro]

\def\setuprotate
  {\dodoubleargument\getparameters[\??ro]}

% \ht, \vfillvoor, \vfillna, \wd, \hfillvoor, \hfillna

% \def\dodostoprotate#1#2#3#4#5#6%
%   {\dontshowcomposition
%    \vbox to #1\nextbox
%      {#2\relax
%       \hbox to #4\nextbox
%         {#5\relax % \number removes leading spaces too
%          \edef\@@rorotatie{\number\@@rorotatie}%
%          \doifelsenothing{\@@rorotatie}
%            {\dostartrotation{90}}
%            {\dostartrotation{\@@rorotatie}}%
%          \wd\nextbox\zeropoint
%          \ht\nextbox\zeropoint
%          \box\nextbox
%          \dostoprotation
%          #6}
%       #3}%
%    \egroup}
% 
% \def\dostoprotate%
%   {\!!counta=\@@rorotatie
%    \divide\!!counta by 90
%    \ifcase\!!counta
%      \dodostoprotate\ht\relax\vfill\wd\relax\hfill
%    \or
%      \dodostoprotate\wd\vfill\relax\ht\relax\hfill
%    \or
%      \dodostoprotate\ht\vfill\relax\wd\hfill\relax
%    \or
%      \dodostoprotate\wd\relax\vfill\ht\hfill\relax
%    \or
%      \dodostoprotate\ht\relax\vfill\wd\relax\hfill
%    \else
%      \def\@@rotatie{90}%
%      \dodostoprotate\ht\relax\vfill\wd\relax\hfill
%    \fi}
% 
% \def\dorotatebox#1% {angle} \hbox/\vbox/\vtop
%   {\bgroup
%    \hbox\bgroup % compatibility hack
%    \dowithnextbox
%      {\edef\@@rorotatie{#1}%
%       \setbox\nextbox=\vbox{\box\nextbox}%
%       \dostoprotate
%       \egroup}}

\def\dorotatebox#1% {angle} \hbox/\vbox/\vtop
  {\bgroup
   \hbox\bgroup % compatibility hack
   \dowithnextbox
     {\edef\@@rorotatie{#1}%
      \setbox\nextbox=\vbox{\box\nextbox}%
      \dostoprotate
      \egroup}}

\def\dodostoprotate#1#2#3#4#5#6%
  {\dontshowcomposition
   \scratchdimen\nextboxht\advance\scratchdimen\nextboxdp
   \doif\@@roplaats\v!hoog
     {\setbox\nextbox\vbox{\hbox{\raise\nextboxdp\box\nextbox}}}%
   \setbox\nextbox\vbox to #1
     {#2\relax
      \hbox to #4
        {#5\relax % \number removes leading spaces too
         \edef\@@rorotatie{\number\@@rorotatie}%
         \doifelsenothing\@@rorotatie
           {\dostartrotation{90}}
           {\dostartrotation{\@@rorotatie}}%
         \nextboxwd\zeropoint
         \nextboxht\zeropoint
        %\nextboxdp\zeropoint
         \box\nextbox
         \dostoprotation
         #6}
      #3}%
\nextboxdp\zeropoint
\box\nextbox
   \egroup}

\def\dostoprotate
  {\!!counta\@@rorotatie
   \divide\!!counta 90
   \ifcase\!!counta
     \dodostoprotate\nextboxht\relax\vfill\nextboxwd\relax\hfill
   \or
    %\dodostoprotate\nextboxwd\vfill\relax\nextboxht\relax\hfill
     \dodostoprotate\nextboxwd\vfill\relax\scratchdimen\relax\hfill
   \or
     \dodostoprotate\nextboxht\vfill\relax\nextboxwd\hfill\relax
   \or
    %\dodostoprotate\nextboxwd\relax\vfill\nextboxht\hfill\relax
     \dodostoprotate\nextboxwd\relax\vfill\scratchdimen\hfill\relax
   \or
     \dodostoprotate\nextboxht\relax\vfill\nextboxwd\relax\hfill
   \else
     \def\@@rotatie{90}%
     \dodostoprotate\nextboxht\relax\vfill\nextboxwd\relax\hfill
   \fi}

%D A couple of examples, demonstrating how the depth ios 
%D taken care of: 
%D
%D \startbuffer
%D test\rotate[frame=on, rotation=0]  {gans}%
%D test\rotate[frame=on, rotation=90] {gans}%
%D test\rotate[frame=on, rotation=180]{gans}%
%D test\rotate[frame=on, rotation=270]{gans}%
%D test
%D \stopbuffer
%D 
%D \typebuffer \getbuffer

\def\complexrotate[#1]%
  {\dowithnextbox
     {\getparameters[\??ro][#1]%
      \dostoprotate}%
   \vbox\localframed[\??ro][#1]}

\unexpanded\def\rotate % \bgroup: \rotate kan argument zijn
  {\bgroup\complexorsimpleempty\rotate}

\setuprotate
  [\c!rotatie=90,
   \c!breedte=\v!passend,
   \c!hoogte=\v!passend,
   \c!offset=\v!overlay,
   \c!kader=\v!uit]

% schaal

% \def\doscalelikeafigure
%   {\doifsomething{\@@xyfactor\@@xyhfactor\@@xybfactor\@@xyschaal
%                   \@@xybreedte\@@xyhoogte\@@xyregels}
%      {\let \@@efschaal \@@xyschaal
%       \let \@@effactor \@@xyfactor
%       \let \@@efbfactor\@@xybfactor
%       \let \@@efhfactor\@@xyhfactor
%       \let \@@efbreedte\@@xybreedte
%       \let \@@efhoogte \@@xyhoogte
%       \let \@@efregels \@@xyregels
%       \let \@@epx      \!!zeropoint
%       \let \@@epy      \!!zeropoint
%       \edef\@@epw     {\the\wd\nextbox}%
%       \edef\@@eph     {\the\ht\nextbox}%
%       \checkfiguresettings
%       \setfactorfiguresize
%       \setscalefiguresize
%       \setdimensionfiguresize
%       \convertfigureinsertscale\@@epx\figx\figxsca\scax
%       \convertfigureinsertscale\@@epy\figy\figysca\scay
%       \scratchdimen\scax\s!pt \divide\scratchdimen 100
%       \edef\@@xysx{\withoutpt\the\scratchdimen}%
%       \scratchdimen\scay\s!pt \divide\scratchdimen 100
%       \edef\@@xysy{\withoutpt\the\scratchdimen}}}

% \def\doschaal[#1]%
%   {\bgroup
%    \forgetall
%    \getparameters
%      [\??xy]
%      [\c!schaal=,\c!breedte=,\c!hoogte=,\c!regels=,
%       \c!factor=,\c!hfactor=,\c!bfactor=,
%       \c!sx=1,\c!sy=1,#1]%
%    \dowithnextbox
%      {\dontshowcomposition
%       \ifdim\ht\nextbox>\zeropoint \ifdim\wd\nextbox>\zeropoint
%         \doscalelikeafigure
%         \dimen0=\@@xysy\ht\nextbox
%         \dimen2=\@@xysy\dp\nextbox
%         \dimen4=\@@xysx\wd\nextbox
%         \dimen6=\dimen0\advance\dimen6 \dimen2
%         \setbox\nextbox\vbox to \dimen6
%           {\ht\nextbox\zeropoint
%            \dp\nextbox\zeropoint
%            \vfill % erbij
%            \dostartscaling\@@xysx\@@xysy\box\nextbox\dostopscaling}%
%         \ht\nextbox\dimen0
%         \dp\nextbox\dimen2
%         \wd\nextbox\dimen4
%       \fi \fi
%       \box\nextbox
%       \egroup}
%    \hbox}

\def\doscalelikeafigure % quite dirty and potential interference possible
  {\doifsomething{\@@xyfactor\@@xyhfactor\@@xybfactor\@@xyschaal
                  \@@xybreedte\@@xyhoogte\@@xyregels}
     {\let \@@efschaal \@@xyschaal
      \let \@@effactor \@@xyfactor
      \let \@@efbfactor\@@xybfactor
      \let \@@efhfactor\@@xyhfactor
      \let \@@efbreedte\@@xybreedte
      \let \@@efhoogte \@@xyhoogte
      \let \@@efregels \@@xyregels
      \let \@@epx      \!!zeropoint
      \let \@@epy      \!!zeropoint
      \edef\@@epw     {\the\wd\nextbox}%
      \edef\@@eph     {\the\ht\nextbox}%
      \figwid\zeropoint \figxsca\plusone % see note * (core-fig)
      \fighei\zeropoint \figysca\plusone % see note * (core-fig)
      \checkfiguresettings
      \setfactorfiguresize
      \setscalefiguresize
      \setdimensionfiguresize
      \convertfigureinsertscale\@@epx\figx\figxsca\scax
      \convertfigureinsertscale\@@epy\figy\figysca\scay
      \scratchdimen\scax\s!pt \divide\scratchdimen 100
      \edef\@@xysx{\withoutpt\the\scratchdimen}%
      \scratchdimen\scay\s!pt \divide\scratchdimen 100
      \edef\@@xysy{\withoutpt\the\scratchdimen}}}

\def\doschaal[#1]%
  {\bgroup
   \forgetall
   \getparameters
     [\??xy]
     [\c!schaal=,\c!breedte=,\c!hoogte=,\c!regels=,
      \c!factor=,\c!hfactor=,\c!bfactor=,
      \c!sx=1,\c!sy=1,#1]%
   \dowithnextbox
     {\dontshowcomposition
      \ifdim\ht\nextbox>\zeropoint \ifdim\wd\nextbox>\zeropoint
        \doscalelikeafigure
        \dimen0=\@@xysy\ht\nextbox
        \dimen2=\@@xysy\dp\nextbox
        \dimen4=\@@xysx\wd\nextbox
        \dimen6=\dimen0\advance\dimen6 \dimen2
%        \setbox\nextbox\vbox to \dimen6
%          {\ht\nextbox\zeropoint
%           \dp\nextbox\zeropoint
%           \vfill % erbij
%           \dostartscaling\@@xysx\@@xysy\box\nextbox\dostopscaling}%
        \setbox\nextbox\hbox
          {\smashbox\nextbox
           \dostartscaling\@@xysx\@@xysy\box\nextbox\dostopscaling}%
        \ht\nextbox\dimen0
        \dp\nextbox\dimen2
        \wd\nextbox\dimen4
      \fi \fi
      \box\nextbox
      \egroup}
   \hbox}

\def\schaal
  {\dosingleempty\doschaal}

% mirror

\def\domirrorbox % \hbox/\vbox/\vtop
  {\bgroup
   \dowithnextbox
     {\dontshowcomposition
      \scratchdimen\wd\nextbox
      \setbox\nextbox\vbox
        {\dostartmirroring\hskip-\wd\nextbox\box\nextbox\dostopmirroring}%
      \wd\nextbox\scratchdimen
      \box\nextbox
      \egroup}}

\def\spiegel
  {\domirrorbox\hbox}

%\setbox0=\hbox{gans}
%
%\ruledhbox{\copy0 \schaal[sx=2,sy=2]{\copy0}}
%
%\spiegel{\ruledhbox{\copy0 \schaal{\box0}}}

% to be used in some other places! todo!
%
% verdelen \hsize in fracties, wordt nog wat algemener,
% beetje vaag nu
%
% \fractie[n/m,elementen,afstand]
%
% \fractie[2/5,3,1em]
% \fractie[2/5,3,1em]
% \fractie[1/5,3,1em]
%
% \stelfractiesin[afstand=,aantal=]  (passend,passend)

\def\??fr{@@fr}

\def\stelfractiesin
  {\dodoubleargument\getparameters[\??fr]}

\def\dodofractie[#1/#2,#3,#4,#5]%
  {\doifelsenothing{#3}
     {\doifelse\@@frn\v!passend
        {\!!counta#2\relax}
        {\!!counta\@@frn\relax}}
     {\!!counta#3\relax}%
   \doifelsenothing{#4}
     {\doifelse\@@frafstand\v!passend
        {\!!widtha\zeropoint}
        {\!!widtha\@@frafstand}}
     {\!!widtha#4}%
   \advance\!!counta \minusone
   \multiply\!!widtha \!!counta
   \advance\hsize -\!!widtha
   \divide\hsize #2\relax
   \hsize#1\hsize}

\def\dofractie[#1]%
  {\dodofractie[#1,,,,,,]}

\def\fractie
  {\dosingleargument\dofractie}

\stelfractiesin
  [\c!afstand=\tfskipsize,
   \c!n=\v!passend]

%D This one is for Daniel Pittman, who wanted tight
%D fractions. We show three versions. First the simple
%D one using \type {\low} and \type {high}:
%D
%D \startbuffer
%D \def\vfrac#1#2%
%D   {\hbox{\high{\tx#1\kern-.25em}/\low{\kern-.25em\tx#2}}}
%D
%D test \vfrac{1}{2} test \vfrac{123}{456} test
%D \stopbuffer
%D
%D \typebuffer {\showmakeup\haalbuffer}
%D
%D A better way to handle the kerning is the following, here
%D we kind of assume that tye slash is symmetrical and has
%D nearly zero width.
%D
%D \startbuffer
%D \def\vfract#1#2%
%D   {\hbox{\high{\tx#1}\hbox to \zeropoint{\hss/\hss}\low{\tx#2}}}
%D \stopbuffer
%D
%D \typebuffer {\showmakeup\haalbuffer}
%D
%D The third and best alternative is the following:
%D
%D {\showmakeup\haalbuffer}\crlf\haalbuffer
%D
%D This time we measure the height of the \type {/} and
%D shift over the maximum height and depths of this
%D character and the fractional digits (we use 57 as
%D sample). Here we combine all methods in one macros.

\chardef\vulgarfractionmethod=3

\definehspace[vulgarfraction][.25em] % [.15em]
\definesymbol[vulgarfraction][/]     % [\raise.2ex\hbox{/}]

\def\vulgarfraction#1#2%
  {\dontleavehmode
   \hbox
     {\def\vulgarfraction{vulgarfraction}%
      \ifcase\vulgarfractionmethod
        #1\symbol[\vulgarfraction]#2%
      \or
        \high{\tx#1\kern-\hspaceamount\empty\vulgarfraction}%
        \symbol[\vulgarfraction]%
        \low {\kern-\hspaceamount\empty\vulgarfraction\tx#2}%
      \or
        \high{\tx#1}%
        \hbox to \zeropoint{\hss\symbol[\vulgarfraction]\hss}%
        \low{\tx#2}%
      \or
        \setbox0\hbox{\symbol[\vulgarfraction]}%
        \setbox2\hbox{\txx57}%
        \raise\ht0\hbox{\lower\ht2\hbox{\txx#1}}%
        \hbox to \zeropoint{\hss\symbol[\vulgarfraction]\hss}%
        \lower\dp0\hbox{\raise\dp2\hbox{\txx#2}}%
      \fi}}

\ifx\vfrac\undefined \let\vfrac\vulgarfraction \fi

%D \starttabulate
%D \HL
%D \NC \bf method \NC \bf visualization \NC\NR
%D \HL
%D \NC 0 \NC \chardef\vulgarfractionmethod0\vulgarfraction{1}{2} \NC\NR
%D \NC 1 \NC \chardef\vulgarfractionmethod1\vulgarfraction{1}{2} \NC\NR
%D \NC 2 \NC \chardef\vulgarfractionmethod2\vulgarfraction{1}{2} \NC\NR
%D \NC 3 \NC \chardef\vulgarfractionmethod3\vulgarfraction{1}{2} \NC\NR
%D \HL
%D \stoptabulate

%D Under construction: 
%D
%D \starttypen 
%D \commalistsentence[aap,noot,mies]
%D \commalistsentence[aap,noot]
%D \commalistsentence[aap]
%D \stoptypen 

\let\handlecommalistsentence\firstofoneargument

\def\commalistsentence[#1]%
  {\bgroup 
   \getcommalistsize[#1]%
   \ifcase\commalistsize\relax
     \def\serializedcommalist{#1}%
   \else
     \let\serializedcommalist\empty
     \scratchcounter\zerocount
     \def\docommando##1%
       {\advance\scratchcounter \plusone 
        \ifnum\scratchcounter=\plusone
          \scratchtoks{\handlecommalistsentence{##1}}%
        \else
          \ifnum\scratchcounter=\commalistsize
            \appendtoks\labeltext{and-2}\handlecommalistsentence{##1}\to\scratchtoks
          \else
            \appendtoks\labeltext{and-1}\handlecommalistsentence{##1}\to\scratchtoks
          \fi
        \fi}%
     \processcommacommand[#1]\docommando
     \edef\serializedcommalist{\the\scratchtoks}%
   \fi
   \serializedcommalist
   \egroup}

\ifx\textcomma\undefined \def\textcomma{,} \fi 

\setuplabeltext [\s!nl] [and-1=\textcomma\ , and-2= en ]
\setuplabeltext [\s!en] [and-1=\textcomma\ , and-2=\textcomma\ and ]
\setuplabeltext [\s!de] [and-1=\textcomma\ , and-2= und ]

\protect \endinput
