\setuppapersize[S5]

\setuplayout[
                   width=middle,
                  height=middle,
                %location=middle,
                topspace=0in,
             bottomspace=0in,
          bottomdistance=.25in,
                  bottom=.25in,
               backspace=.5in,
                cutspace=0.5in,
              leftmargin=0.25in,
             rightmargin=0.25in,
      leftmargindistance=0.1in,
     rightmargindistance=0.1in,
                  header=0.25in,
                  footer=0.5in,
           headerdistace=0.25in,
          footerdistance=0.25in,
                 marking=on,
%                   grid=yes,
    ]

\setuppagenumbering [location=none]


\setupbodyfontenvironment[default][em=italic]
\setupbodyfont[dejavu,10pt]


\definetype[command][color=darkred, style=type]
\definetype[options][color=darkblue, style=type]
\definetype[comment][color=orange, style=italic]

\definestartstop
    [TexSnippetComment]
    [color=orange,
     style=italic]
 
\setuptyping[option=tex, before=\startEXAMPLE, after=\stopEXAMPLE, indentnext=no, escape={[[,]]}]
\setuptype[option=tex]

\setupindenting[medium,yes]
\setupwhitespace[medium]

\setuphead[title][alternative=middle, textstyle=\sansbold] 
\setuphead[section,subject,subsubject,subsection]
          [numberstyle=\sansbold,textstyle=\sansbold, page=yes]

\setupitemize[1][autointro]
\setupitemize[indenting=no]

%% Frames and Backgrounds : <<<

\definetextbackground
    [EXAMPLE]
    [           mp=background:random,
          location=paragraph,
     rulethickness=1pt,
        framecolor=darkred,
             width=\textwidth,
            height=fit,
        leftoffset=5em,
       rightoffset=0mm,
            before={\testpage[3]\blank[2*big]},
             after={\blank},
    ]

\startuseMPgraphic{background:random}
   path p;
   for i = 1 upto nofmultipars :
    p = (multipars[i]
     topenlarged 8pt
     bottomenlarged 4pt
     leftenlarged -4EmWidth
     rightenlarged 0EmWidth ) randomized 4pt ;
   fill p withcolor lightgray ;
   draw p withcolor \MPvar{linecolor}
    withpen pencircle scaled \MPvar{linewidth};
   endfor;
   setbounds currentpicture to boundingbox OverlayBox ;
\stopuseMPgraphic

\defineframedtext
    [EXAMPLEframe]
    [rulethickness=1pt,
        framecolor=darkred,
            height=6.55cm,
             width=broad,
        background=color,
   backgroundcolor=gray,
    ]

\definehighlight[emph][style=em]

\setupcombination[distance=4em]

\setupinteraction[state=start]
