\definecolor [chap_frame] [black]
\definecolor [textcolor]  [white]

\startuseMPgraphic{chapter-thumb}
    path chap_frame ;
    pair pos,a,b ;
    picture Chap ;

    if \somenamedheadnumber{chapter}{current} > 0 :
        curr_chap := \somenamedheadnumber{chapter}{current} ;
    else :
        curr_chap := 1 ;
    fi;
    if \somenamedheadnumber{chapter}{last} > 0 :
        last_chap := \somenamedheadnumber{chapter}{last} ;
    else :
        last_chap := 1 ;
    fi;
    if \somenamedheadnumber{section}{current} > 0 :
        curr_sect := \somenamedheadnumber{section}{current} ;
    else:
        curr_sect := 1 ;
    fi;
    if \somenamedheadnumber{section}{last} > 0 :
        last_sect := \somenamedheadnumber{section}{last} ;
    else:
        last_sect := 1;
    fi;
    if curr_chap < 11 :
        skip := TextHeight * (curr_chap-1)/11 ;
    elseif curr_chap < 21 :
        skip := TextHeight * (curr_chap-11)/11 ;
    else:
        skip := TextHeight * (curr_chap-21)/11 ;
    fi;

    Chap := textext("\bfa\textcolor\getmarking[chapter]") ;

    StartPage ;
        chap_frame := lcircle xscaled (2*RightMarginWidth) yscaled (1.5*RightMarginWidth) ;

        a := ulcorner chap_frame ;
        b := urcorner chap_frame ;

        pos := urcorner Field[Text][RightMarginSeparator] - ulcorner chap_frame - (-1mm,skip) ;

        fill chap_frame shifted pos withcolor "chap_frame" ;
        draw Chap rotated 90 shifted (xpart pos-4mm,ypart pos) ;
    StopPage ;
\stopuseMPgraphic

\defineoverlay[chapter-thumb][\useMPgraphic{chapter-thumb}]

\startsectionblockenvironment[bodypart]
    \setupbackgrounds[rightpage][background=chapter-thumb]
\stopsectionblockenvironment

\showframe

\starttext

\startfrontmatter

\startchapter[title=Test A]
	\samplefile{ward}
\stopchapter

\stopfrontmatter

\startbodymatter

\startchapter[title=Test C]
	\samplefile{ward}
\stopchapter

\stopbodymatter

\stoptext























% Global settings for all chapters
\setuphead[chapter][style=\ssc]

% Local settings for chapter in the bodymatter block
\startsectionblockenvironment[bodypart]
\setuphead[chapter][color=blue]
\stopsectionblockenvironment

\starttext

\startfrontmatter

\title{Table of content}

\placecontent

\stopfrontmatter

\startbodymatter

\chapter{Knuth}

\input knuth

\chapter{Zapf}

\input zapf

\stopbodymatter

\stoptext





\starttext

a\texttilde b\lettertilde c\textasciitilde d

\stoptext




\definepageinjectionalternative
  [chapter:image]
  [renderingsetup=pageinjection:chapter:image]

\startsetups [pageinjection:chapter:image]
  \centerbox{\externalfigure[\dummyparameter{name}]}
\stopsetups

\definepageinjection
  [chapter:start]
  [empty]
  [page=left]

\definepageinjection
  [chapter:insert]
  [previouspage]
  [alternative=chapter:image,
   offset=1cm,
   pagestate=stop]

\setuphead
  [chapter]
  [beforesection={\pageinjection[chapter:start]},
   insidesection={\pageinjection[chapter:insert][name={chapter-\namedheadnumber{chapter}}]}]

\setuppagenumbering
  [alternative=doublesided]

\setupexternalfigures
  [location=default]

\useexternalfigure [chapter-1] [mill]   [factor=max]
\useexternalfigure [chapter-2] [hacker] [orientation=90,scale=2000]
\useexternalfigure [chapter-3] [cow]    [orientation=90,height=\framedwidth]

\starttext

\startchapter [title={Mill}]
\dorecurse{7}{\samplefile{lorem}}
\stopchapter

\startchapter [title={Hacker}]
\dorecurse{11}{\samplefile{lorem}}
\stopchapter

\startchapter [title={cow}]
\dorecurse{7}{\samplefile{lorem}}
\stopchapter

\stoptext




\setupbodyfont[termes]

\starttext

plays \m{\frac{2}{3} A}, \m{\frac{1}{3} D}.

\stoptext






\definefallbackfamily[story][serif][notoserif][range={greekandcoptic,greekextended},force=yes]
\definefontfamily[story][serif][TeX Gyre Schola]

\definefontfamily [story] [sans] [Latin Modern Sans]
\definefontfamily [story] [mono] [Latin Modern Mono] [features=none]

\definetypeface [story] [ss] [sans] [modern] [default]
\definetypeface [story] [ss] [mono] [modern] [default]

\definetypeface [story] [ss] [sans] [modern-designsize] [default]
\definetypeface [story] [ss] [mono] [modern-designsize] [default]

\definefontfamily[story][mm][TeX Gyre Pagella Math]

\definetypeface [story] [mm] [math] [pagella] [default]

\setupbodyfont[story,11pt]

\usebodyfont[termes]

\showframe

\startsetups [blockquote:style]
    \switchtobodyfont[termes]
    \setupwhitespace[2pt]
\stopsetups

\setupdelimitedtext
  [blockquote]
  [spacebefore=big,
         style=\directsetup{blockquote:style},
     indenting=none,
    indentnext=yes]

\starttext
\chapter{Testing}
\input ward

\startblockquote
\input knuth

\stopblockquote

\input zapf

{\it This is what Italic letters look like.} {\bf And these are bold.}


\startblockquote
This is what it said, in {\it Italic} and {\bf bold} letters:

\bgroup
\it This is what Italic letters look like here.
\egroup

\bgroup
\bf This is what Bold letters look like here.
\egroup
\stopblockquote

\stoptext











\definelayer [testlayer]

\setupbackgrounds [text] [text] [background=testlayer]

%\setupbackgrounds[state=repeat]

\starttext

\setlayer [testlayer] [x=1cm,y=1cm] {Text background}

\dorecurse{4}{xxx\page}

\stoptext






\starttext

text {\italicface text {\boldface text} text} text

text {\it text {\bf text} text} text: here the third instance of text is in boldface, but not in italic boldface.

text {\it text {\bi text} text} text

\stoptext


\unprotect

\def\pack_layers_positioned_box_nop
  {\vpack
     {\writestatus{WOLF}{\getboxlly\b_layers}%
      \writestatus{WOLF}{\getboxllx\b_layers}%
      \vskip-\getboxlly\b_layers
      \hskip-\getboxllx\b_layers
      \hsize-\dimexpr\getboxllx\b_layers-\wd\b_layers\relax
      \ifconditional\c_pack_layers_repeated\copy\else\box\fi\b_layers}}

\protect

\setuppapersize[A4][A3]

\setuplayout[location=middle]

\definelayer
  [test]
  [%option=test,
   %method=fit,
   position=yes]

\setupbackgrounds [text] [text] [background=test]

\setupbackgrounds[state=repeat]

\starttext

text \setlayer[test]{layer} text

\page

text

\stoptext






\starttext

\startitemize[columns,three]
\startitem One \stopitem
\startitem Two\par Three \stopitem
\stopitemize


\stoptext










\starttext

text {\italicface text {\boldface text} text} text

\stoptext




\unprotect

\def\page_backgrounds_set_boxes
  {\ifconditional\c_page_backgrounds_new
     \page_backgrounds_set_boxes_r
   \fi
   \doifbothsides
     \page_backgrounds_set_boxes_a
     \page_backgrounds_set_boxes_b
     \page_backgrounds_set_boxes_c
   \ifx\p_page_backgrounds_state\v!repeat\else
     \global\setfalse\c_page_backgrounds_new
   \fi}

\protect

%\definelayer [l_page]
\definelayer [l_text]

%\setupbackgrounds [page] [background=l_page]
\setupbackgrounds [text] [text] [background=l_text]

\setupbackgrounds[state=repeat]

\starttext

%\setlayer [l_page] [x=1cm,y=1cm] {Page background}
\setlayer [l_text] [x=1cm,y=1cm] {Text background}

\tracingmacros1
\dorecurse{4}{xxx\page}
\tracingmacros0

\stoptext







\showgrid

\starttext

\samplefile{lorem}

\page

\start \setupinterlinespace[2]% 2 lines, also possible: 1.5, 3, ...
\samplefile{lorem}\par
\stop

\page

\start \setupinterlinespace[line=5.6ex]% also possible: \setupinterlinespace[5.6ex]
\samplefile{lorem}\par
\stop

\stoptext



\starttexdefinition RemovePreceding #1
    \removeunwantedspaces
    #1
\stoptexdefinition

\starttexdefinition RemoveFollowing #1
    #1
    \ignorespaces
\stoptexdefinition

\starttext

Bla \RemovePreceding{Bla} Bla

Bla \RemoveFollowing{Bla} Bla

\stoptext



\starttexdefinition Italic #1
    \emphasized{#1}
    \autoinsertnextspace
\stoptexdefinition

\starttexdefinition Underbar #1
    \underbar{#1}
\stoptexdefinition

\starttext

Bla Bla Bla

\Underbar{\Italic{Bla} , Bla Bla.}

\stoptext





\startxmlsetups xml:test
    \xmlsetsetup{#1}{*}{-}
    \xmlsetsetup{#1}{article|p|italic|underline}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:test}

\startxmlsetups xml:article
\starttext
    \xmlflush{#1}
\stoptext
\stopxmlsetups

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

\startxmlsetups xml:italic
    \emph{\xmlflush{#1}}
\stopxmlsetups

\startxmlsetups xml:underline
    \underbar{\xmlflush{#1}}
\stopxmlsetups

\startbuffer[test]
<?xml version="1.0" encoding="UTF-8"?>
<article>
    <p>Bla Bla Bla</p>
    <p>
        <underline>
        <italic>Bla</italic>
        </underline>, Bla Bla.</p>
</article>
\stopbuffer

\starttext
\xmlprocessbuffer{test}{test}{}
\stoptext
