%D \module
%D   [      file=s-mod-00,
%D        version=very-old,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Documentation Base Environment,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D This module looks like crap, is not documented, will
%D change, and used to be called modu-*.tex.

% todo:
%
% file inclusions -> hyperlinks

\mainlanguage[en] % better not here

\usemodule[units]

\enableactivediscretionaries
\newprettytrue

\unprotect

% beter:
%
% group    -> title
% title    -> category
% subtitle -> subtitle

% herzien ivm fonts

% nog eens \interface \\ \\ verder doorvoeren

\def\resetmoduledocumentation
  {\getrawparameters
     [Module]
     [       file=\jobname,
             type=,
          version={\currentdate[\v!year,{.},\v!month,{.},\v!day]},
           system=\CONTEXT,
            title=Unknown Title,
         subtitle=,
           author=Unknown Author,
             date=\currentdate,
        copyright=Unknown Copyright,
      suggestions=]}

\resetmoduledocumentation

\def\dostartmoduledocumentation[#1]%
  {\newcounter\ParagraphNumber
   \resetmoduledocumentation
   \getrawparameters[Module][type=tex,#1]}

\def\startmoduledocumentation
  {\starttext
   \dosingleempty\dostartmoduledocumentation}

\def\stopmoduledocumentation
  {\page
   \placeregister
     [\v!index]
     [\c!balance=\v!yes,
      \c!indicator=\v!no,
      \c!criterium=\v!text]
   \stoptext}

% \def\complexmodule[#1]%
%   {\startglobal % i.v.m. \bgroup in \startdocumentation
%    \getrawparameters[Module][#1]
%    \stopglobal  % i.v.m. \bgroup in \startdocumentation
%    \moduletitle}
%
% \def\simplemodule#1%
%   {\type{#1}}
%
% \definecomplexorsimple\module

% \startmode[atpragma]
%
%   \def\TitlePage#1% can be done more efficient
%     {\startMPrun
%         mpgraph := #1 ;
%         input mp-cont ;
%      \stopMPrun
%      \externalfigure
%        [\bufferprefix mprun.#1]
%        [\c!height=\vsize,
%         \c!width=\hsize]}
%
%   \defineoverlay[titlepage][\TitlePage{512}]
%
% \stopmode

\startuseMPgraphic{titlepage}

  width  := PaperWidth ;
  height := PaperHeight ;

  color local_red, local_white, local_blue ;

  local_white := white ;

  local_blue := local_white randomized (.6,.8) ;
  local_red  := local_white randomized (.3,.4) ;

  u := width/400 ;

  def a_module (expr dx, dy) =
    picture p ; p := image
      ( ddy := 0 ; sx := 60u ;
        for i=1 upto (4 randomized 2) :
          sy := 7u randomized 3u ;
          fill unitsquare xyscaled(sx,sy) shifted (0,ddy)
            withcolor local_red ;
          ddy := ddy + sy + 4u ;
        endfor ) ;
    p := p shifted (dx,dy) shifted - center p ;
    fill boundingbox p enlarged 8u withcolor local_white ;
    fill boundingbox p enlarged 4u withcolor local_blue ;
    draw p ;
  enddef ;

  set_grid(width, height, width/15, height/15) ;
  forever:
    if new_on_grid(uniformdeviate width,uniformdeviate height):
      a_module(dx,dy) ;
    fi ;
    exitif grid_full ;
  endfor ;

  clip currentpicture to unitsquare xyscaled(width,height) ;
\stopuseMPgraphic

\defineoverlay
  [titlepage]
  [\useMPgraphic{titlepage}]

\doifmode{atpragma}{\readfile{s-mod-04.tex}{}{}}

\defineframed
  [TitleFrame]
  [\c!background=\v!color,
   \c!backgroundcolor=white,
   \c!align=\v!right,
   \c!offset=12pt,
   \c!strut=\v!no,
   \c!frame=\v!off,
   \c!bottom=]

\definelayout
  [titlepage]
  [\c!backspace=0pt,
   \c!topspace=0pt,
   \c!header=0pt,
   \c!footer=0pt,
   \c!height=\v!middle,
   \c!width=\v!middle]

\def\moduletitle
  {\setuplayout[titlepage]
   \ifx\ModuleNumber\undefined \else
     \ifnum\ModuleNumber<10
       \edef\ModuleNumber{00\ModuleNumber}
     \else\ifnum\ModuleNumber<100
       \edef\ModuleNumber{0\ModuleNumber}
     \fi\fi
     \setupbackgrounds
       [\v!page]
       [\c!background=titlepage]
   \fi
   \startmakeup[\v!standard][\c!headerstate=\v!none,\c!footerstate=\v!none]
     \switchtobodyfont[14.4pt,ss]
     \bgroup
       \def\CONTEXT {Con\kern-.15em\TeX t}
       \def\TEXUTIL {\TeX Util}
       \def\PPCHTEX {PPCH\TeX}
       \def\METAPOST{MetaPost}
       \hfill
         {\definedfont[SansBold at 96pt]\setstrut
          \TitleFrame{\Modulesystem}}
       \vfill
       \definetabulate[temp][|l|l|]%
       \switchtobodyfont[17.3pt,ss]
       \hfill
         {\bf\setstrut
          \TitleFrame
            {\insidefloattrue\setuptabulate[\c!before=,\c!after=]%
             \starttemp
               \doifsomething{\Moduletitle}
                 {\NC title \EQ \Moduletitle \NC\NR}%
               \doifsomething{\Modulesubtitle}
                 {\NC subtitle \EQ \Modulesubtitle \NC\NR}%
               \doifsomething{\Moduleauthor}
                 {\NC author \EQ \Moduleauthor \NC\NR}%
                  \NC date \EQ \currentdate \NC\NR
              %\doifsomething{\Modulesuggestions} % todo: generates space
              %  {\NC suggestions \NC \Modulesuggestions \NC\NR}%
             \stoptemp}}
     \egroup
   \stopmakeup
   \ifx\ModuleNumber\undefined \else
     \setupbackgrounds
       [\v!page]
       [\c!background=]
   \fi
   \setuplayout}

\let\stopdocumentation=\relax

\def\startdocumentation
  {\bgroup
   \doglobal\newcounter\NOfMarginLines
   \def\stopdocumentation{\par\egroup}}

\newif\ifcompressdefinitions

\def\startcompressdefinitions {\global\compressdefinitionstrue}
\def\stopcompressdefinitions  {\global\compressdefinitionsfalse}

\gdef\CompressDefinitions%
  {\ifcompressdefinitions
     \switchtobodyfont[\v!small]%
   \fi}

\startnotmode[nocode]

  \definetyping
    [definition]

  \setuptyping
    [definition]
    [\c!before={\page[\v!preference]}\blank\PresetParagraphNumber\CompressDefinitions,
     \c!after=\ResetParagraphNumber\blank,
     \c!option=\Moduletype]

\stopnotmode

\startmode[nocode]

% \definieerbuffer[definition] % ignore

  \long\def\startdefinition#1\stopdefinition{}

\stopmode

\definetyping [PL]  [\c!option=PL, \c!margin=\v!standard]
\definetyping [JV]  [\c!option=JV, \c!margin=\v!standard]
\definetyping [MP]  [\c!option=MP, \c!margin=\v!standard]
\definetyping [TEX] [\c!option=TEX,\c!margin=\v!standard]

\setuptyping [\v!typing]  [\c!margin=\v!standard]
\setuptyping [\v!file]    [\c!margin=\v!standard]
\setuptyping [definition] [\c!margin=0pt]

\newcounter\NOfMarginLines
\newcounter\ParagraphNumber

\def\ResetParagraphNumber
  {\egroup}

\def\PresetParagraphNumber
  {\bgroup
   \xdef\NOfTextLines%
     {\the\prevgraf}%
   \doglobal\decrement\NOfMarginLines
   \doglobal\increment\ParagraphNumber
   \message{.}%
   \gdef\ShowParagraphNumber%
     {\llap{\slx\ParagraphNumber\hskip\leftmargindistance}}%
   \gdef\ShowParagraphNumberA%
     {\ifnum\NOfMarginLines>\NOfTextLines\relax
        \doglobal\increment\NOfTextLines
      \else
        \ShowParagraphNumber
        \global\let\ShowParagraphNumberA=\relax
        \global\let\ShowParagraphNumberB=\ShowParagraphNumber
        \doglobal\newcounter\NOfMarginLines
      \fi}%
   \gdef\ShowParagraphNumberB%
     {}%
   \EveryLine
     {\ShowParagraphNumberA}%
   \EveryPar
     {\vadjust{\nobreak}%
      \ShowParagraphNumberB}}

\EveryPar % skip one
  {\EveryPar
     {\doglobal\newcounter\NOfMarginLines}}

\def\dodomargeaanduidingen[#1]#2%
  {\def\docommand##1%
     {\indent\hbox
        {\ifx#2\relax
           \index{##1}%
         \else
           \index{#2{##1}}%
         \fi
         #2{\doboundtext{##1}{\leftmarginwidth}{..}}}%
       \doglobal\increment\NOfMarginLines
       \endgraf}%
   \processcommalist[#1]\docommand}

\def\margeaanduidingen#1[#2]%
  {\def\domargeaanduidingen##1##2%
     {\margintitle[#2]%
        {\switchtobodyfont[\v!small]%
         \doglobal\newcounter\NOfMarginLines
         \dodomargeaanduidingen[##1]#1%
         \scratchcounter=\NOfMarginLines
         \multiply\scratchcounter by 10
         \divide\scratchcounter by 12
         \advance\scratchcounter by 1
         \xdef\NOfMarginLines{\the\scratchcounter}%
         \processcommalist[##2]\index}}%
   \dodoublegroupempty\domargeaanduidingen}

\def\complexmacros{\margeaanduidingen\tex  }
\def\complexextras{\margeaanduidingen\relax}

\def\complexelements
  {\margeaanduidingen\someelement}

\def\someelement#1{\type{<#1>}}

\definecomplexorsimpleempty\macros
\definecomplexorsimpleempty\extras
\definecomplexorsimpleempty\elements

\def\showelements{\dodoubleempty\doshowelements}

\def\doshowelements[#1][#2]
  {\bgroup
   \processXMLbuffer
   \typebuffer
   \setupcolors[\c!state=\v!stop]
   \showXSDcomponent[#1][#2]
   \egroup}

% \macros{a,b}
% \macros{a,b}{b}
% \macros[a]{a,b}{b}

% weg ermee

\defineparagraphs [interface] [\c!n=2]
\setupparagraphs  [interface] [1] [\c!width=4cm]

\def\startexample{\par\startnarrower}  \let\startvoorbeeld\startexample
\def\stopexample {\stopnarrower}       \let\stopvoorbeeld \stopexample

\gdef\VisualizeLastSpace{\ifdim\lastskip>0pt\unskip\tttf\char32\fi}

\gdef\ShowHeadText #1{\tttf#1\VL\mainlanguage[\currentlanguage]\headtext {#1}\VisualizeLastSpace}
\gdef\ShowLabelText#1{\tttf#1\VL\mainlanguage[\currentlanguage]\labeltext{#1}\VisualizeLastSpace}

\startbuffer[lang-a]
\starttable[|l|l|]
  \HL
  \VL \bf head key  \VL \bf current value \VL\SR
  \HL
  \VL \ShowHeadText \v!abbreviations      \VL\FR
  \VL \ShowHeadText \v!units              \VL\MR
  \VL \ShowHeadText \v!figures            \VL\MR
  \VL \ShowHeadText \v!graphics           \VL\MR
  \VL \ShowHeadText \v!index              \VL\MR
  \VL \ShowHeadText \v!content            \VL\MR
  \VL \ShowHeadText \v!intermezzi         \VL\MR
  \VL \ShowHeadText \v!logos              \VL\MR
  \VL \ShowHeadText \v!tables             \VL\LR
  \HL
\stoptable
\stopbuffer

\startbuffer[lang-b]
\starttable[|l|l|]
  \HL
  \VL \bf label key  \VL \bf current value \VL\SR
  \HL
  \VL \ShowLabelText \v!table              \VL\FR
  \VL \ShowLabelText \v!figure             \VL\MR
  \VL \ShowLabelText \v!intermezzo         \VL\MR
  \VL \ShowLabelText \v!graphic            \VL\MR
  \VL \ShowLabelText \v!chapter            \VL\MR
  \VL \ShowLabelText \v!section            \VL\MR
  \VL \ShowLabelText \v!subsection         \VL\MR
  \VL \ShowLabelText \v!subsubsection      \VL\MR
  \VL \ShowLabelText \v!appendix           \VL\MR
  \VL \ShowLabelText \v!part               \VL\MR
  \VL \ShowLabelText \v!line               \VL\MR
  \VL \ShowLabelText \v!lines              \VL\LR
  \HL
\stoptable
\stopbuffer

\startbuffer[lang-c]
\starttable[|l|l|]
  \HL
  \VL \bf label key  \VL \bf current value \VL\SR
  \HL
  \VL \ShowLabelText \v!january            \VL\FR
  \VL \ShowLabelText \v!february           \VL\MR
  \VL \ShowLabelText \v!march              \VL\MR
  \VL \ShowLabelText \v!april              \VL\MR
  \VL \ShowLabelText \v!may                \VL\MR
  \VL \ShowLabelText \v!june               \VL\MR
  \VL \ShowLabelText \v!july               \VL\MR
  \VL \ShowLabelText \v!august             \VL\MR
  \VL \ShowLabelText \v!september          \VL\MR
  \VL \ShowLabelText \v!october            \VL\MR
  \VL \ShowLabelText \v!november           \VL\MR
  \VL \ShowLabelText \v!december           \VL\LR
  \HL
\stoptable
\stopbuffer

\startbuffer[lang-d]
\starttable[|l|l|]
  \HL
  \VL \bf label key  \VL \bf current value \VL\SR
  \HL
  \VL \ShowLabelText \v!sunday             \VL\FR
  \VL \ShowLabelText \v!monday             \VL\MR
  \VL \ShowLabelText \v!tuesday            \VL\MR
  \VL \ShowLabelText \v!wednesday          \VL\MR
  \VL \ShowLabelText \v!thursday           \VL\MR
  \VL \ShowLabelText \v!friday             \VL\MR
  \VL \ShowLabelText \v!saturday           \VL\LR
  \HL
\stoptable
\stopbuffer

\gdef\ShowTextsValues[#1][#2]%
  {\vbox\bgroup
   \language[#1]%
   \setbox\scratchbox\hbox to \hsize{\hss\bfb#2 language defaults\hss}
   \dp\scratchbox\zeropoint
   \box\scratchbox
   \vskip1em
   \hrule
   \vskip2em
   \halign
     {\hss##\hss&##\hskip1em&\hss##\hss\cr
      $\vcenter{\getbuffer[lang-a]}$&&$\vcenter{\getbuffer[lang-b]}$\cr
      \noalign{\vskip1em}
      $\vcenter{\getbuffer[lang-c]}$&&$\vcenter{\getbuffer[lang-d]}$\cr}%
   \egroup}

\gdef\ShowLanguageValues[#1][#2]#3#4%
  {\hbox to \hsize
     {\hss
      \vbox
        \bgroup
        \language[#1]%
        \let\normalbar=|
        \starttable[||||]
        \HL
        \VL \THREE{\bf subsentence symbol and quotes} \VL\SR
        \HL
        \VL \quotation{#3 #4} \VL \quote{#2} \VL \let|=\normalbar |<||<|#3|>|#4|>| \VL\FR
        \VL \quotation{#3 #4} \VL \quote{#2} \VL |<||<|#3|>|#4|>| \VL\LR
        \HL
        \stoptable
        \egroup
      \hss}}

\gdef\doShowAllLanguageValues[#1][#2]#3#4%
  {\vbox
     {\ShowTextsValues[#1][#2]
      \vskip2em
      \ShowLanguageValues[#1][#2]{#3}{#4}}
   \protect
   \page}

\gdef\ShowAllLanguageValues
  {\page
   \unprotect
   \dodoubleargument\doShowAllLanguageValues}

\protect

%D Command references:

% \input setupa
% \input setupb

\usemodule[int-load] \loadsetups

\unprotect

% \def\showsetup
%   {\doglobal\newcounter\CurrentArgument
%    \setup}

\def\showsetup#1%
  {{\def\y##1{\writestatus{setups}{warning: remove y! from #1}}%
    \setup{#1}}}

\setupframedtexts
  [setuptext]
  [\c!background=\v!screen,
   \c!frame=\v!off]

\protect \endinput
