\doifnotmode{mkiv}{\endinput}

\setupxml[method=mkiv,default=hidden]

\usemodule[x][mathml]

\xmlregisterdocumentsetup{ldx}{xml:mml:define}
\xmlregisterdocumentsetup{ldx}{xml:ldx:define}

\xmlregisterns{ldx}{ldx}

\startxmlsetups xml:ldx:define
%     \xmlgrab {\xmldocument} {ldx:*} {*}
    \xmlsetsetup {#1} {ldx:*} {ldx:*}
\stopxmlsetups

% % %

\startxmlsetups ldx:p
    \xmlflush{#1}\par
\stopxmlsetups

\startxmlsetups ldx:source
    \source{\xmlflush{#1}}
\stopxmlsetups

\startxmlsetups ldx:key
    \dontleavehmode{\bf\xmlflush{#1}}
\stopxmlsetups

\startxmlsetups ldx:variable
    \xmlflush{#1}
%     \expanded{\variable{\xmlflush{#1}}}
\stopxmlsetups

\startxmlsetups ldx:function
    \dontleavehmode{\bf function}\space\xmlflush{#1}
%     \expanded{\function{\xmlflush{#1}}}
\stopxmlsetups

\startxmlsetups ldx:com
    \dontleavehmode{\tt--\xmlflush{#1}}
\stopxmlsetups

\startxmlsetups ldx:document
    \page
    \xmlflush{#1}
    \determineregistercharacteristics[function]
    \startmode[*register]
        \testpage[4]
        \extra{Functions}
        \placeregister[function]
    \stopmode
    \determineregistercharacteristics[variable]
    \startmode[*register]
        \testpage[4]
        \extra{Variables}
        \placeregister[variable]
    \stopmode
\stopxmlsetups

\newcounter\CommentCounter

\startxmlsetups ldx:comment
    \blank
    \doglobal\increment\CommentCounter
    \margintitle{\bf\CommentCounter}
    \xmlflush{#1}
    \blank
\stopxmlsetups

\startxmlsetups ldx:dqs
    \dontleavehmode\bgroup\tt"\xmlflush{#1}"\egroup
\stopxmlsetups

\startxmlsetups ldx:sqs
    \dontleavehmode\bgroup\tt'\xmlflush{#1}'\egroup
\stopxmlsetups

\startxmlsetups ldx:code
    \startpacked
    \xmlflush{#1}\relax
    \stoppacked
\stopxmlsetups

\startxmlsetups ldx:lines
    \startpacked
    \xmlflush{#1}
    \stoppacked
\stopxmlsetups

\startxmlsetups ldx:line
    \doifelsenothing {\xmlflush{#1}} {
        \xmlflush{#1}\crlf
    } {
        \dontleavehmode \hbox to \hsize \bgroup
            \strut
            \hskip.25\dimexpr\xmlattdef{#1}{n}{0}em\relax\relax % extra relax needed !
            \doif {\xmlatt{#1}{comment}} {yes} {\tt}
            \xmlflush{#1}
            \hss
       \egroup
       \endgraf
    }
\stopxmlsetups

\startxmlsetups ldx:logo
    \uppercasestring\xmlatt{#1}{label}\xmlatt{#1}{name}\to\ascii
    \ifx\ascii\empty\else\getvalue{\ascii}\fi
\stopxmlsetups

\startxmlsetups ldx:l
    \uppercasestring\xmlatt{#1}{l}\xmlatt{#1}{n}\to\ascii
    \ifx\ascii\empty\else\getvalue{\ascii}\fi
\stopxmlsetups

\startxmlsetups ldx:typing
    \blank
    \startpacked \tt
    \xmlverbatim{#1}
    \stoppacked
    \blank
\stopxmlsetups

\startxmlsetups ldx:type
    \dontleavehmode{\tt\xmlflush{#1}}
\stopxmlsetups

\startxmlsetups ldx:t
    \dontleavehmode{\tt\xmlflush{#1}}
\stopxmlsetups

%

\def\xmldocument{ldx}

\usemodule[abr-02]

% key -> kw
% dqs -> dq
% sqs -> sq
% line -> ln
% code -> cd
% comment -> tx (text)

\definetypeface[mainfacenormal]  [ss][sans] [iwona]       [default]
\definetypeface[mainfacenormal]  [rm][serif][palatino]    [default]
\definetypeface[mainfacenormal]  [tt][mono] [modern]      [default][rscale=1] % 1.1
\definetypeface[mainfacenormal]  [mm][math] [iwona]       [default][encoding=default]

\definetypeface[mainfacemedium]  [ss][sans] [iwona-medium][default]
\definetypeface[mainfacenormal]  [rm][serif][palatino]    [default]
\definetypeface[mainfacemedium]  [tt][mono] [modern]      [default][rscale=1] % 1.1
\definetypeface[mainfacemedium]  [mm][math] [iwona-medium][default][encoding=default]

\definetypeface[mainfacenarrowtt][tt][mono] [modern-cond] [default][rscale=1] % 1.1

\setupbodyfont
  [mainfacenormal,11pt]

\setupwhitespace
  [big]

\defineregister[function][functions]
\defineregister[variable][variables]

\definehead[source][subject]
\definehead[extra] [subsubject]
\definehead[topic] [subsubsubject]

\setuphead
  [source]
  [style=\bfb]

\setuphead
  [extra]
  [style=\bfa]

\setuphead
  [topic]
  [style=\bf]

\setuplayout
  [width=middle,
   height=middle,
   backspace=2cm,
   topspace=2cm]

% \usemodule[inf-02]

\endinput
