%D \module
%D   [       file=core-des,
%D        version=1997.03.31,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Descriptions,
%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 / Descriptions}

\unprotect

% Dit kan en moet dus anders:
%
% \start... :  \vbox\bgroup
% \stop...  :  \egroup
% llap enz.
% geen indent!
%
% enz. enz.
%
% Op die manier is meer mogelijk en worden \par's geskipt.
%
% De macro \??dd#1\s!do\c!commando levert de koppeling tussen
% \@@descriptionnumberen en \doordefinieren. Deze constructie is nodig
% omdat doornummeren geen argument heeft en omdat subnummers
% niet worden genest binnen het hogere niveau. Het commando
% \??dd#1\s!do\c!state moet in dat geval \v!start zijn.
%
% herimplementeren met \nextbox en \unhbox\unvbox

\newbox\@@descriptionbox

\def\descriptionparameter#1{\csname\??dd\currentdescription#1\endcsname}

\def\@@descriptionhandler{\descriptionparameter{\s!do\c!command}}

\def\normal@@descriptionhandler[#1]#2#3%
  {\doattributes
     {\??dd\currentdescription}\c!headstyle\c!headcolor
     {\descriptionparameter\c!command{#3}}% NAAR BUITENSTE NIVEAU !
   \rawreference\s!def{#1}{#2}} % brrr moet in #4

\setvalue{@@description\v!left}%
  {\@@descriptionhang\@@descriptionleftpure\@@descriptionlefthang}

\setvalue{@@description\v!right}%
  {\@@descriptionhang\@@descriptionrightpure\@@descriptionrighthang}

\def\@@descriptionhang#1#2%
  {\processaction
     [\descriptionparameter\c!hang]
     [   \v!none=>\let\next#1,%
               0=>\let\next#1,%
      \s!unknown=>\let\next#2,%
      \s!default=>\let\next#1]%
   \next}

\def\@@descriptionleftpure[#1]#2%
  {\@@dostartdescription[#1]{#2}%
   \noindent\ignorespaces
   \leftskip\@@leftdescriptionskip
   \rightskip\@@rightdescriptionskip
   \advance\leftskip \!!widtha
   \@@makedescriptionpurebox\raggedright
   \advance\leftskip \!!widthb
   \llap
     {\hbox to \leftskip
        {\hskip\@@leftdescriptionskip
         \copy\@@descriptionbox\hss}}%
   \@@dodescription}

\def\@@descriptionrightpure[#1]#2%
  {\@@dostartdescription[#1]{#2}%
   \noindent\ignorespaces
   \leftskip\@@leftdescriptionskip
   \rightskip\@@rightdescriptionskip
   \advance\rightskip \!!widtha
   \@@makedescriptionpurebox\raggedleft
   \rlap
     {\hskip\hsize
      \hskip-\leftskip
      \hskip-\rightskip
      \copy\@@descriptionbox
      \hskip\@@rightdescriptionskip}%
   \advance\rightskip \!!widthb
   \@@dodescription}

\def\@@makedescriptionpurebox#1%
  {\setbox\@@descriptionbox\vtop
     {\dontcomplain
      \hsize\!!widtha
      \leftskip\zeropoint
      \rightskip\zeropoint
      #1\setupalign[\descriptionparameter\c!align]%
      \ifhbox\@@descriptionbox\unhcopy\else\copy\fi\@@descriptionbox}%
   \ht\@@descriptionbox\strutht
   \dp\@@descriptionbox\strutdp}

\def\@@descriptionlefthang[#1]#2%
  {\@@dostartdescription[#1]{#2}%
   \dontcomplain
   \advance\!!widtha \!!widthb
   \hangindent\!!widtha
   \@@makedescriptionhangbox\raggedright{\advance\rightskip \!!widthb}%
   \noindent\ignorespaces
   \llap
     {\dontshowcomposition
      \vtop to \zeropoint{\box\@@descriptionbox}}%
   \@@dodescription}

\def\@@descriptionrighthang[#1]#2%
  {\@@dostartdescription[#1]{#2}%
   \dontcomplain
   \advance\!!widtha \!!widthb
   \hangindent-\!!widtha
   \@@makedescriptionhangbox\raggedleft{\advance\leftskip \!!widthb}%
   \noindent\ignorespaces
   \rlap
     {\dontcomplain
      \dontshowcomposition
      \scratchdimen\hsize
      \advance\scratchdimen -\leftskip
      \advance\scratchdimen -\rightskip
      \hbox to \scratchdimen
        {\hss\vtop to \zeropoint{\box\@@descriptionbox}}}%
   \@@dodescription}

\def\@@makedescriptionhangbox#1#2%
  {\setbox\@@descriptionbox\vtop % \vbox gaat fout in hang
     {\forgetall
      \dontcomplain
      \hsize\!!widtha
      #1\setupalign[\descriptionparameter\c!align]#2%
      \ifhbox\@@descriptionbox\unhcopy\else\copy\fi\@@descriptionbox}%
   \ht\@@descriptionbox\strutht
   \dp\@@descriptionbox\strutdp
   \doifsomething{\descriptionparameter\c!hang}
     {\doifinsetelse{\descriptionparameter\c!hang}{\v!fit,\v!broad}
        {\scratchdimen\ht\@@descriptionbox
         \advance\scratchdimen \dp\@@descriptionbox
         \doif{\descriptionparameter\c!hang}\v!broad
           {\advance\scratchdimen .5\strutht}%
         \getnoflines\scratchdimen
         \hangafter-\noflines}
        {\hangafter-\descriptionparameter\c!hang}}}

\setvalue{@@description\v!top}[#1]#2%
  {%\page[\v!preference]%       % Weg ermee!
   %\dosomebreak{\goodbreak}%   % Dit is beter en nodig!
   \dohandlepagebreakX\plusone   % En dit moet het maar worden.
   \@@dostartdescription[#1]{\let\\=\space#2}%
   \noindent\ignorespaces
   \copy\@@descriptionbox\par
   \nobreak
   \descriptionparameter\c!inbetween
   \nobreak
   \@@dodescription}

\def\do@@description#1[#2]#3%
  {\@@dostartdescription[#2]{#3}%
   \noindent\ignorespaces % not needed this ignore
   #1{\ifhbox\@@descriptionbox\unhcopy\else\copy\fi\@@descriptionbox}%
   \@@dodescription}

\setvalue{@@description\v!inmargin    }{\do@@description\inmargin}
\setvalue{@@description\v!inleft      }{\do@@description\inleft  }
\setvalue{@@description\v!inright     }{\do@@description\inright }
\setvalue{@@description\v!margin      }{\do@@description\inmargin}
\setvalue{@@description\v!leftmargin  }{\do@@description\inleft  }
\setvalue{@@description\v!rightmargin }{\do@@description\inright }
\setvalue{@@description\v!innermargin }{\do@@description\ininner }
\setvalue{@@description\v!outermargin }{\do@@description\inouter }

\setvalue{@@description\v!serried\v!fit}[#1]#2%
  {\@@dostartdescription[#1]{#2}%
   \noindent\ignorespaces
   \ifhbox\@@descriptionbox\unhcopy\else\copy\fi\@@descriptionbox
   \hskip\!!widthb % toegevoegd
   \@@dodescription}

\setvalue{@@description\v!serried\v!broad}[#1]#2%
  {\@@dostartdescription[#1]{#2}%
   \noindent\ignorespaces
   \ifhbox\@@descriptionbox\unhcopy\else\copy\fi\@@descriptionbox
   \hskip\!!widthb \!!plus .5\!!widthb \!!minus .25\!!widthb
   \@@dodescription}

\setvalue{@@description\v!serried\v!wide}[#1]#2%
  {\@@dostartdescription[#1]{#2}%
   \noindent\ignorespaces
   \hbox to \!!widtha
     {\ifhbox\@@descriptionbox\unhcopy\else\copy\fi\@@descriptionbox\hss}%
   \hskip\!!widthb
   \ignorespaces
   \@@dodescription}

\setvalue{@@description\v!serried}[#1]#2%
  {\processaction
      [\descriptionparameter\c!width]
      [     \v!fit=>\let\next\v!fit,
          \v!broad=>\let\next\v!broad,
        \s!unknown=>\let\next\v!wide,
        \s!default=>\let\next\v!broad]%
   \getvalue{@@description\v!serried\next}[#1]{#2}}

\setvalue{@@description\v!hanging}[#1]#2%
  {\@@dostartdescription[#1]{#2}% % adds \c!margin to \leftskip
   \noindent\ignorespaces
   \advance\leftskip -\leftskipadaption \relax
   \ifdim\leftskipadaption=\zeropoint
     \leftskipadaption1.5em % just some default
     \ifnum\insidedefinition=\plusone
       \ifdim\leftskip>\zeropoint \relax
         \leftskipadaption\leftskip
       \fi
     \fi
   \fi
   \ifnum\insidedefinition=\plusone
     \advance\leftskip \leftskipadaption
   \fi
   \hskip-\leftskipadaption
   \ifhbox\@@descriptionbox\unhcopy\else\copy\fi\@@descriptionbox
   \kern\ifdim\!!widthb=\zeropoint .75em\else\!!widthb\fi
   \ignorespaces
   \@@dodescription}

%D A bonus definition
%D
%D \starttyping
%D \setupfootnotedefinition[location=command,headcommand=\llap]
%D \stoptyping

\setvalue{@@description\v!command}#1%
  {\do@@description{\executeifdefined{\??dd#1\c!headcommand}\framed}{#1}}

%D A new key 'headalign' in definitions.

\chardef\insidedefinition=0

\let\@@leftdescriptionskip \!!zeropoint
\let\@@rightdescriptionskip\!!zeropoint

\def\@@dostartdescription[#1]#2%
  {\descriptionparameter\c!before
   \begingroup
   \doadaptleftskip{\descriptionparameter\c!margin}%
   \showcomposition
   \!!widthb\descriptionparameter\c!distance\relax
   \ifdim\!!widthb=\zeropoint\relax
     \doif{\descriptionparameter\c!width}\v!broad{\!!widthb=1em}%
   \fi
   % temp hack, we need to avoid this kind of preprocessing
   \setbox\@@descriptionbox\hbox % preroll
     {\forgetall
      \trialtypesettingtrue
      \dontcomplain
      \def\\{\crlf}%
      \@@descriptionhandler[#1]{#2}%
        {\begstrut\descriptionparameter\c!text\ignorespaces#2\endstrut}}%
   % so far
   \assignwidth
     \!!widtha
     {\descriptionparameter\c!width}%
     {\doifelsenothing{\descriptionparameter\c!sample}%
        {% preroll can move here (test first)
         \ifhbox\@@descriptionbox\unhcopy\else\copy\fi \@@descriptionbox}%
        {\@@descriptionhandler[#1]{#2}%
           {\descriptionparameter\c!text\descriptionparameter\c!sample}}}
     \!!widthb
   \setbox\@@descriptionbox\hbox
     {\forgetall
      \dontcomplain
      \let\\\endgraf
      \doifelse{\descriptionparameter\c!location}\v!serried
        {\@@descriptionhandler[#1]{#2}%
           {\begstrut\descriptionparameter\c!text#2\endstrut}}
        {\@@descriptionhandler[#1]{#2}%
           {\vtop{\hsize\!!widtha\advance\hsize-\!!widthb
            \begstrut\descriptionparameter\c!text\ignorespaces#2\endstrut}}}}%
   \doifelse{\descriptionparameter\c!aligntitle}\v!no
     {\edef\@@leftdescriptionskip {\the\leftskip }%
      \edef\@@rightdescriptionskip{\the\rightskip}}
     {\ifcase\insidedefinition
        \edef\@@leftdescriptionskip {\the\leftskip }%
        \edef\@@rightdescriptionskip{\the\rightskip}%
      \fi}%
   \expanded{\indenting[\descriptionparameter\c!indenting]}%
   % better a system mode
   \ifcase\insidedefinition
     \chardef\insidedefinition\plusone
   \or
     \chardef\insidedefinition\plustwo
   \fi} % now happens elsewhere : \noindent\ignorespaces

\def\@@stopdescription#1%
  {\def\currentdescription{#1}%
   \dostopattributes
   \par % maybe better after \dostopattributes
   \endgroup
   \descriptionparameter\c!after
   \egroup % temporary hack
   \dochecknextindentation{\??dd#1}}% \currentdescription}}

\def\@@dodescription
  {\dostartattributes{\??dd\currentdescription}\c!style\c!color\empty
   \ignorespaces}

% starters:

\def\@@startdescription[#1][#2]%
  {\def\currentdescription{#1}%
   \doifelse{\descriptionparameter{\s!do\c!state}}\v!start
     {\@@startsomedescription{#1}[#2]{}}
     {\dowithwargument{\@@startsomedescription{#1}[#2]}}}

\def\@@description[#1][#2]%
  {\def\currentdescription{#1}%
   \doifelse{\descriptionparameter{\s!do\c!state}}\v!start
     {\@@somedescription{#1}[#2]{}}
     {\dowithwargument{\@@somedescription{#1}[#2]}}}

% these call:

\def\@@somedescription#1[#2]#3%
  {\dowithpar
     {\bgroup\@@makedescription{#1}[#2]{#3}}%
     {\@@stopdescription{#1}}}

\def\@@startsomedescription#1[#2]#3%
  {\bgroup % temporary hack
   \BeforePar{\@@makedescription{#1}[#2]{#3}}%
   \GotoPar}

% which calls:

\def\@@makedescription#1%
  {\def\currentdescription{#1}%
   \executeifdefined
     {@@description\descriptionparameter\c!location}
     {\getvalue{@@description\v!left}}}

% \def\@@makedescription#1%
%   {\def\currentdescription{#1}%
%    \ifundefined{@@description\descriptionparameter\c!location}%
%      \letvalue{\??dd#1\c!location}\v!left
%    \fi
%    \getvalue{@@description\descriptionparameter\c!location}}

% definitions

\def\setupdescriptions
  {\dodoubleempty\dosetupdescriptions}

\def\dosetupdescriptions[#1][#2]% % beter: \iffirstargument
  {\ConvertToConstant\doifelse{#2}{}
     {\dodosetupdescriptions[][#1]}
     {\dodoubleargumentwithset\dodosetupdescriptions[#1][#2]}}

\def\dodosetupdescriptions[#1]% [#2]%
  {\getparameters[\??dd#1]}   % [#2]}

\def\dodefinedescription[#1][#2]%
  {\copyparameters[\??dd#1][\??dd]
     [\c!location,\c!headstyle,\c!style,\c!color,\c!headcolor,
      \c!width,\c!hang,\c!sample,\c!before,\c!inbetween,\c!after,\c!margin,
      \c!indenting,\c!indentnext,\c!align,\c!text,\c!distance,\c!command]%
   \getparameters[\??dd#1]
     [\s!do\c!state=\v!stop,\s!do\c!command=\normal@@descriptionhandler,#2]%
   \doifvalue{\??dd#1\c!location}\v!top{\doassign[\??dd#1][\c!inbetween=\blank]}%
   \setvalue        {#1}{\dodoubleempty\@@description[#1]}%
   \setvalue{\e!start#1}{\dodoubleempty\@@startdescription[#1]}%
   \setvalue{\e!stop #1}{\@@stopdescription{#1}}}%

\def\definedescription
  {\dodoubleemptywithset\dodefinedescription}

\def\showdnpuretext#1%
  {\strut\getvalue{\??dd#1\c!text}} % geen spatie

\def\showdntext#1%
  {\doifelsevaluenothing{\??dd#1\c!text}
     {\ignorespaces}
     {\strut
      \getvalue{\??dd#1\c!text}%
      \removeunwantedspaces\fixedspace}}

\def\showdnnumber#1%
  {\preparednumber
   \convertednumber[\getvalue{\??dd#1\??dd\c!number}]}

\def\showdnsubnumber#1%
  {\showdnnumber{#1}%
   \getvalue{\??dd#1\c!separator}%
   \convertednumber[\v!sub\getvalue{\??dd#1\??dd\c!number}]}

\def\showdnsubsubnumber#1%
  {\showdnsubnumber{#1}%
   \getvalue{\??dd#1\c!separator}%
   \convertednumber[\v!sub\v!sub\getvalue{\??dd#1\??dd\c!number}]}

\def\showdnsubsubsubnumber#1%
  {\showdnsubsubnumber{#1}%
   \getvalue{\??dd#1\c!separator}%
   \convertednumber[\v!sub\v!sub\v!sub\getvalue{\??dd#1\??dd\c!number}]}

\def\domakednnumber#1#2#3%
  {\getvalue{\??dd#2#1\c!left}%
   \strut#3{#1}%
   \getvalue{\??dd#2#1\c!stopper}%
   \getvalue{\??dd#2#1\c!right}}

% #1=name  #2=level #3=\show  #4[#5]#6#7=#1[#2]#3#4 van description

\def\special@@descriptionhandler#1#2#3#4[#5]#6#7%
  {\strut
   \doifelsevalue{\??dd#1\c!number}\v!no
     \!!doneafalse{\doifelse{#5}{-}\!!doneafalse\!!doneatrue}%
   \chardef\descriptioncoupling\zerocount
   \iflocation
     \doifvaluesomething{\??dd#1\c!coupling}
       {\processaction % genereert > of <
          [\getvalue{\??dd#1\c!couplingway}]
          [ \v!local=>\chardef\descriptioncoupling1, % old: default
           \v!global=>\chardef\descriptioncoupling2]}% new: global crosslinking
   \fi
   \setupnumber % the number is called indirectly
     [\getvalue{\??dd#1\??dd\c!number}]
     [\c!sectionnumber=\getvalue{\??dd#1\c!sectionnumber}]%
   \if!!donea
     \iftrialtypesetting\startlocal\fi
     \getvalue{\e!next#2#1}% tricky but we need the preroll
     \iftrialtypesetting\stoplocal\fi
     % \getvalue{\e!next#2#1}%
     \iflocation
       \bgroup
       \letvalue{\??dd#1\c!sectionnumber}\v!yes
       \protectconversion
       \maakvoorafgaandenummer[\getvalue{\??dd#1\??dd\c!number}]%
       \preparethenumber{\??dd#1}\voorafgaandenummer\preparednumber
       \ifcase\descriptioncoupling \or
         \xdef\@@internalenumber{#3{#1}}%
         \rawreference\s!num{#1:\@@internalenumber}{}%
       \or
         \xdef\@@internalenumber{\countervalue{\??dd\c!coupling#1}}%
         \rawreference\s!num{#1:\@@internalenumber}{}%
       \fi
       \egroup
     \fi
     \maakvoorafgaandenummer[\getvalue{\??dd#1\??dd\c!number}]%
     \preparethenumber{\??dd#1}\voorafgaandenummer\preparednumber
     \disablepseudocaps      % sorry, uppercase causes troubles
     \doattributes        % \nocase primitive needed
       {\??dd#1}\c!headstyle\c!headcolor
       {\getvalue{\??dd#1\c!command}% hook for taco
          {\showdntext{#2#1}%
           \domakednnumber{#1}{#2}{#3}}}%
     \iflocation\ifcase\descriptioncoupling \else
       \edef\localconnection{\getvalue{\??dd#1\c!coupling}:\@@internalenumber}%
       \doifreferencefoundelse\localconnection
         {\in[\localconnection]}\donothing % genereert > of <
     \fi\fi
     \doifnot{#5}{-}{\rawreference\s!num{#5}{#3{#1}}}%
   \else % Why was this strange expansion needed?
     \edef\!!stringa{\showdnpuretext{#2#1}}% nog eens testen binnen \expanded
     \expanded{\doattributes{\??dd#1}\noexpand\c!headstyle\noexpand\c!headcolor
       {\noexpand\getvalue{\??dd#1\c!command}{\!!stringa}}}%
     \doifnot{#5}{-}{\rawreference\s!num{#5}{}}%
   \fi}

\setvalue{\??dd\s!set\v!sub\s!sub\s!sub\c!number}#1%
  {\edef\@@descriptionnumber{\getvalue{\??dd#1\??dd\c!number}}%
   \setnumber[\v!sub\v!sub\v!sub\@@descriptionnumber]}

\setvalue{\??dd\s!set\v!sub\s!sub\c!number}#1%
  {\@@ddresetsubsubsubnumber{#1}%
   \setnumber[\v!sub\v!sub\@@descriptionnumber]}

\setvalue{\??dd\s!set\v!sub\c!number}#1%
  {\@@ddresetsubsubnumber{#1}%
   \setnumber[\v!sub\@@descriptionnumber]}

\setvalue{\??dd\s!set\c!number}#1%
  {\@@ddresetsubnumber{#1}%
   \setnumber[\@@descriptionnumber]}

\setvalue{\??dd\s!reset\v!sub\v!sub\v!sub\c!number}#1%
  {\edef\@@descriptionnumber{\getvalue{\??dd#1\??dd\c!number}}%
   \resetnumber[\v!sub\v!sub\v!sub\@@descriptionnumber]}

\setvalue{\??dd\s!reset\v!sub\v!sub\c!number}#1%
  {\@@ddresetsubsubsubnumber{#1}%
   \resetnumber[\v!sub\v!sub\@@descriptionnumber]}

\setvalue{\??dd\s!reset\v!sub\c!number}#1%
  {\@@ddresetsubsubnumber{#1}%
   \resetnumber[\v!sub\@@descriptionnumber]}

\setvalue{\??dd\s!reset\c!number}#1%
  {\@@ddresetsubnumber{#1}%
   \resetnumber[\@@descriptionnumber]}

\setvalue{\??dd\e!next\v!sub\v!sub\v!sub\c!number}#1[#2]%
  {\edef\@@descriptionnumber{\getvalue{\??dd#1\??dd\c!number}}%
   \incrementnumber[\v!sub\v!sub\v!sub\@@descriptionnumber]%
   \rawreference\s!num{#2}{\showdnsubsubsubnumber{\@@descriptionnumber}}}%

\setvalue{\??dd\e!next\v!sub\v!sub\c!number}#1[#2]%
  {\@@ddresetsubsubsubnumber{#1}%
   \incrementnumber[\v!sub\v!sub\@@descriptionnumber]%
   \rawreference\s!num{#2}{\showdnsubsubnumber{\@@descriptionnumber}}}

\setvalue{\??dd\e!next\v!sub\c!number}#1[#2]%
  {\@@ddresetsubsubnumber{#1}%
   \incrementnumber[\v!sub\@@descriptionnumber]%
   \rawreference\s!num{#2}{\showdnsubnumber{\@@descriptionnumber}}}

\setvalue{\??dd\e!next\c!number}#1[#2]%
  {\@@ddresetsubnumber{#1}%
   \incrementnumber[\@@descriptionnumber]%
   \rawreference\s!num{#2}{\showdnnumber{\@@descriptionnumber}}}

\def\dodosetupenumerations[#1][#2]%
  {\getparameters[\??dd#1][#2]%
   \doifdefined{\??dd#1\c!start}
     {\setupnumber[#1][\c!start=\getvalue{\??dd#1\c!start}]}%
   \setupnumber[#1][\c!conversion=\getvalue{\??dd#1\c!conversion}]}

\def\dosetupenumerations[#1][#2]%
  {\ConvertToConstant\doifelse{#2}{}
     {\getparameters[\??dn][#1]}
     {\dodoubleargumentwithset\dodosetupenumerations[#1][#2]}}

\def\setupenumerations
  {\dodoubleempty\dosetupenumerations}

\def\dododefineenumeration#1#2#3[#4][#5]#6%
  {\makecounter{\??dd\c!coupling#1}% new: global cross linking
   \dodefinedescription[#3#1]%
     [\s!do\c!state=\v!start,
      \s!do\c!command=\special@@descriptionhandler{#1}{#3}{#6}]%
   \copyparameters[\??dd#3#1][\??dn]
     [\c!location,\c!headstyle,\c!style,\c!color,\c!headcolor,
      \c!width,\c!number,\c!distance,\c!command,
      \c!sample,\c!hang,\c!align,\c!before,\c!inbetween,\c!after,
      \c!levels,\c!way,\c!blockway,\c!separator,\c!margin,
      \c!indenting,\c!indentnext,\c!stopper,\c!sectionnumber,
      \c!number]%
   \doifassignmentelse{#4}
     {\getparameters[\??dd#3#1]%
        [\c!text=#1,\??dd\c!number=#1,\c!conversion=,
         \c!left=,\c!right=,\c!coupling=,\c!couplingway=\v!local,#4]}%
     {\doifelsenothing{#4}
        {\getparameters[\??dd#3#1]%
           [\c!text=#1,\??dd\c!number=#1,\c!conversion=,
            \c!stopper=,
            \c!left=,\c!right=,\c!coupling=,\c!couplingway=,#4]}%
        {\copyparameters[\??dd#3#1][\??dd#3#4]
           [\c!location,\c!headstyle,\c!style,\c!color,\c!headcolor,
            \c!width,\c!number,\c!distance,\c!command,\c!margin,
            \c!sample,\c!hang,\c!align,\c!before,\c!inbetween,\c!after,
            \c!stopper,\c!indenting,\c!indentnext,\c!left,\c!right,
            \c!coupling,\c!couplingway]%
         \getparameters[\??dd#3#1]
           [\c!text=#1,\??dd\c!number=#4,\c!conversion=,#5]}}%
   \doifvalue{\??dd#3#1\??dd\c!number}{#1}
     {\definenumber
        [#3#1]
        [\c!way=\getvalue{\??dd#1\c!way},
         \c!blockway=\getvalue{\??dd#1\c!blockway},
         \c!sectionnumber=\getvalue{\??dd#1\c!sectionnumber}]%
      \doifvalue{\??dd#1\c!levels}{#2}%                           % for
        {\doifsomething{\getvalue{\??dd#1\c!conversion}}%         % old
           {\setupnumber[#3#1]                                    % times
              [\c!conversion=\getvalue{\??dd#1\c!conversion}]}}}% % sake
   \setvalue{\s!set  #3#1}{\dosetenumerationnumber[#1][#3]}%
   \setvalue{\s!reset#3#1}{\doresetenumerationnumber[#1][#3]}%
   \setvalue{\e!next #3#1}{\dotripleempty\donextenumerationnumber[#1][#3]}}

\def\doresetenumerationnumber[#1][#2]%
  {\getvalue{\??dd\s!reset#2\c!number}{#1}}%

\def\dosetenumerationnumber[#1][#2]%
  {\getvalue{\??dd\s!set#2\c!number}{#1}}%

\def\donextenumerationnumber[#1][#2]%
  {\pluscounter{\??dd\c!coupling#1}% new: global crosslinking
   \getvalue{\??dd\c!next#2\c!number}{#1}}%

\def\dodefineenumeration[#1][#2][#3]%
  {\dododefineenumeration{#1}{1}{}[#2][#3]\showdnnumber
   \dododefineenumeration{#1}{2}{\v!sub}[#2][#3]\showdnsubnumber
   \dododefineenumeration{#1}{3}{\v!sub\v!sub}[#2][#3]\showdnsubsubnumber
   \dododefineenumeration{#1}{4}{\v!sub\v!sub\v!sub}[#2][#3]\showdnsubsubsubnumber}

\def\defineenumeration
  {\dotripleemptywithset\dodefineenumeration}

%  Het default-mechanisme kan mooier: leegtest, enz.
%
%  Werkprocedure buiten description

\def\dodosetupindentations[#1][#2]%
  {\getparameters[\??ds#1][#2]}

\def\dosetupindentations[#1][#2]%
  {\ConvertToConstant\doifelse{#2}{}
     {\dodosetupindentations[][#1]}
     {\dodoubleargumentwithset\dodosetupindentations[#1][#2]}}

\def\setupindentations
  {\dodoubleempty\dosetupindentations}

% what to do with this

\def\startdoorspringen
  {\whitespace
   \@@dsbefore
   \dosomebreak\goodbreak % \page[\v!preference]
   \begingroup
   \parskip\zeropoint\relax}

\def\stopdoorspringen
  {\endgroup
   \@@dsafter}

%

\def\dododefineindenting#1#2#3%
  {\par
   \getvalue{\??ds#1\c!before}%
   \begingroup
   \doifvaluenothing{\??ds#1\c!sample}
     {\setvalue{\??ds#1\c!sample}%
        {\getvalue{\??ds#1\c!text}}}%
   \assignwidth
     {\!!widtha}
     {\getvalue{\??ds#1\c!width}}
     {\doattributes
        {\??ds#1}\c!headstyle\c!headcolor
        {\getvalue{\??ds#1\c!sample}\getvalue{\??ds#1\c!separator}}}
     {\getvalue{\??ds#1\c!distance}}%
   \advance\!!widtha \getvalue{\??ds#1\c!distance}%
   \setbox2\hbox to \!!widtha
     {\doattributes
        {\??ds#1}\c!headstyle\c!headcolor
        {\strut
         \getvalue{\??ds#1\c!text}%
         \hss
         \getvalue{\??ds#1\c!separator}%
         \hskip\getvalue{\??ds#1\c!distance}}}%
   \parindent\zeropoint
   \hskip#2\!!widtha\indent\box2%
   \hangindent#3\!!widtha
   \doattributes{\??ds#1}\c!style\c!color\empty
   \AfterPar{\endgroup\getvalue{\??ds#1\c!after}}% must be redone
   \GetPar}

\def\dodefineindenting[#1][#2]%
  {\copyparameters[\??ds#1][\??ds]
      [\c!text,\c!separator,\c!width,\c!style,\c!color,
       \c!headstyle,\c!sample,\c!before,\c!after,\c!distance]%
   \getparameters[\??ds#1][#2]%
   \setvalue            {#1}{\dododefineindenting{#1}{0}{1}}%
   \setvalue      {\v!sub#1}{\dododefineindenting{#1}{1}{2}}%
   \setvalue{\v!sub\v!sub#1}{\dododefineindenting{#1}{2}{3}}}

\def\defineindenting
  {\dodoubleargumentwithset\dodefineindenting}

\def\definelabel
  {\dodoubleargumentwithset\dodefinelabel}

\def\dodefinelabel[#1][#2]%
  {\definenumber
     [#1]
     [\c!command=,\c!location=,#2]%
   % downward compatible
   \processaction
     [\numberparameter{#1}\c!location]
     [  \v!inmargin=>{\setupnumber[#1][\c!command=\inmargin]},
          \v!inleft=>{\setupnumber[#1][\c!command=\inleft  ]},
         \v!inright=>{\setupnumber[#1][\c!command=\inright ]},
          \v!margin=>{\setupnumber[#1][\c!command=\inmargin]}]%
   % generated commands (in addition to the number ones)
   \setvalue            {#1}{\dodoubleempty\do@@label[#1]}%
   \setvalue{\s!reset    #1}{\resetnumber[#1]}%
   \setvalue{\e!increment#1}{\incrementnumber[#1]}%
   \setvalue{\e!next     #1}{\dodoubleempty\do@@nextlabel[#1]}%
   \setvalue{\c!current  #1}{\currentnumber[#1]}}

\def\do@@label[#1][#2]%
  {\numberparameter{#1}\c!before
   \numberparameter{#1}\c!command
     {\doattributes{\@@thenumber{#1}}\c!headstyle\c!headcolor
        {\dotextprefix{\numberparameter{#1}\c!text}%
         \getvalue{\e!next#1}[#2]}}%
   \numberparameter{#1}\c!after}%

\def\do@@nextlabel[#1][#2]%
  {\nextnumber[#1][\s!lab][#2]}

\setupdescriptions
  [\c!location=\v!left,
   \c!headstyle=\v!bold,
   \c!style=\v!normal,
   \c!color=,
   \c!headcolor=,
   \c!width=8em,
   \c!distance=0pt,
   \c!hang=,
   \c!sample=,
   \c!align=,
   \c!margin=\v!no,
   \c!before=\blank,
   \c!inbetween=\blank,
   \c!after=\blank,
   \c!indentnext=\v!yes,
   \c!indenting=\v!never,
   \c!command=]

\setupenumerations
  [\c!location=\v!top,
   \c!headstyle=\v!bold,
   \c!headcolor=,
   \c!style=\v!normal,
   \c!color=,
   \c!width=8em,
   \c!distance=0pt,
   \c!hang=,
   \c!sample=,
   \c!align=,
   \c!margin=\v!no,
   \c!before=\blank,
   \c!inbetween=\blank,
   \c!after=\blank,
   \c!indentnext=\v!yes,
   \c!indenting=\v!never,
   \c!text=,
   \c!levels=3,                % to be upward compatible
   \c!conversion=,             % to be upward compatible
   \c!way=\v!by\v!text,
   \c!sectionnumber=\v!yes,
   \c!separator=.,
   \c!stopper=,
   \c!number=,
   \c!command=]

\setupindentations
  [\c!style=\v!normal,
   \c!headstyle=\v!normal,
   \c!color=,
   \c!headcolor=,
   \c!width=\v!fit,
   \c!text=\unknown,
   \c!sample=,
   \c!before=\blank,
   \c!after=\blank,
   \c!distance=1em,
   \c!separator={ :}]

\protect \endinput
