\usemodule [letterspace]

\defineletterspace [largecaps]
\setupletterspace  [largecaps] [
  spacefactor=.2,
  spaceskip=.3em,
]

\defineletterspace [mediumcaps]
\setupletterspace  [mediumcaps] [
  spacefactor=.25,
  spaceskip=.5em,
]

\defineletterspace [textemph]
\setupletterspace  [textemph] [
  spacefactor=.125,
  spaceskip=.33em,
]

\let\te\textemph

\defineletterspace [ugly]
\setupletterspace  [ugly] [
  spacefactor=.4,
  spaceskip=1em,
]


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Font Setups                                                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\definefontfeature [default] [default] [
  protrusion=quality,
  expansion=quality,
  mode=node,
  script=latn,
  onum=yes,
  dlig=yes,
  liga=yes,
]

\usetypescript [antykwa-poltawskiego]
\setupbodyfont [antykwa-poltawskiego,10pt]

\usetypescript [serif] [hz] [highquality]
\setupalign    [hanging,hz]

\setupbodyfontenvironment [default] [12pt] [interlinespace=15pt]
\setupbodyfontenvironment [default] [11pt] [interlinespace=13pt]
\setupbodyfontenvironment [default] [10pt] [interlinespace=12pt]
\setupbodyfontenvironment [default] [9pt]  [interlinespace=11pt]
\setupbodyfontenvironment [default] [8pt]  [interlinespace=10pt]

\setupbodyfontenvironment [default] [em=italic]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Presenting the Interface                                      %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usemodule  [int-load]
\loadsetups [t-letterspace.xml]

\define\beautifyshowsetups{%
  \unexpanded\def\setupnumfont  {\rm}%
  \unexpanded\def\setuptxtfont  {\rm}%
  \unexpanded\def\setupintfont  {\rm\sc\Word}%
  \unexpanded\def\setupvarfont  {\rm\it}%
  \unexpanded\def\setupoptfont  {\rm\it}%
  \unexpanded\def\setupalwcolor {gutenred}%
  \unexpanded\def\setupoptcolor {gutenred}%
  \defineframedtext [setuptext] [
    frame=off,
    background=color,
    backgroundcolor=gray:2,
    width=\hsize,
    height=fit,
    align=right,
    offset=0.75em,
  ]%
}

\let\Oldshowsetup\showsetup

\define[1]\showsetup{% hurray for diversity
  \bgroup\beautifyshowsetups%
    \Oldshowsetup{#1}%
  \egroup%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Paper                                                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\definepapersize[LHS][
  width=160mm,
  height=239mm,
]

\setuppapersize[LHS][LHS]

\showframe
\setuplayout [
    width=122mm,
    %textheight=199mm, % ca. 47 rows * 12pt
    height=224mm, % text height should end up at ca. 47 rows * 12pt
    %height=fit,
    %  
    topspace=14mm,
    header=12pt,
    headerdistance=4mm,
    top=00mm,
    %  
    bottomspace=0mm,
    footer=23mm,
    bottom=0mm,
    footerdistance=0mm,
    %  
    backspace=16mm,
    leftedge=0mm,
    leftedgedistance=0mm,
    leftmargin=16mm,
    leftmargindistance=1em,
    %  
    rightmargin=20mm,
    rightmargindistance=2mm,
    rightedge=0mm,
    rightedgedistance=0mm,
]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Interaction                                                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\definecolor [gutenred] [x=bf221f] % rubrication from digitized_Göttingen Gutenberg bible

\setupinteraction[%
  state=start,
  color=gutenred,
  contrastcolor=gutenred,
  %color=,
  %contrastcolor=,
  style=,
  focus=standard,
  title={Letterspace Module},
  subtitle={Bringing Flow into Horizontal Spacing},
  author={Philipp Gesang},
  keyword={ConTeXt, LuaTeX, letterspacing, horizontal glue},
]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Headings                                                      %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\defineletterspace [LSchapter]
\defineletterspace [LSsection]
\defineletterspace [LSsubsection]
\setupletterspace  [LSchapter]    [spacefactor=.1,  spaceskip=.33em]
\setupletterspace  [LSsection]    [spacefactor=.15, spaceskip=.40em]
\setupletterspace  [LSsubsection] [spacefactor=.125,spaceskip=.33em]

\def   \fontchapter#1{\setupbodyfont[11pt]\WORD\LSchapter{#1}}
\def   \fontsection#1{\setupbodyfont[11pt]\word\sc\LSsection{#1}}
\def\fontsubsection#1{\setupbodyfont[11pt]\LSsubsection{#1}}

\def   \Chapterheadfontcmd{\fontchapter}
\def   \Sectionheadfontcmd{\fontsection}
\def\Subsectionheadfontcmd{\fontsubsection}

\setuphead [chapter] [
  align=middle,
  footer=text,
  grid=yes,
  header=empty,
  number=no,
  page=yes,
  style=,
  textcommand=\Chapterheadfontcmd,
  before={\startlinecorrection\blank[3*line,force]},
  after={\stoplinecorrection\blank[line,force]},
]

\definetext [text] [footer] [pagenumber]

\setuphead [section] [
  align=middle,
  number=no,
  page=no,
  style=,
  textcommand=\Sectionheadfontcmd,
  before={\blank[line]},
  after={\blank[line]},
]

\setuphead [subsection] [
  align=middle,
  number=no,
  page=no,
  style=,
  textcommand=\Subsectionheadfontcmd,
  before={\blank[line]},
  after={\blank[line]},
]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ToC                                                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def   \tocfontchapter#1{\WORD\LSchapter{#1}}
\def   \tocfontsection#1{\word\sc\LSsection{#1}}
\def\tocfontsubsection#1{\LSsubsection{#1}}

\setuplist [chapter] [
  alternative=b,
  textcommand=\tocfontchapter,
]

\setuplist [section] [
  alternative=c,
  interaction=text,
  margin=2em,
  numberstyle=,
  textcommand=\tocfontsection,
  textstyle=,
]

\setuplist [subsection] [
  %after=2.5em,    % from the hack
  alternative=d,
  interaction=text,
  margin=3em,     % hanging
  textcommand=\tocfontsubsection,
]

\setuplistalternative[c] [
  %distance=0em,
  %width=0pt,
  stretch=.5em,
  command=\hskip.5em\phglistdots\hskip.5em\relax,
]

\def\phglistdots{\gleaders\hbox to 1em{\hss.\hss}\hfill}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Misc                                                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\clubpenalty  -7000
\widowpenalty -7000

\def\etc{{\italic\letterampersand}c}

\setupindenting [yes,next,medium]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Makeup for Front Matter                                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\definemakeup [FM] [standard]
\setupmakeup [FM] [
  width=125mm,
  height=172.506mm,
  location=middle,
]

\setupheadertexts [] [] [] []
\setuppagenumbering [state=stop,location=]

\starttext

\startfrontmatter
\setuplayout [width=middle]
\startFMmakeup
  \raggedcenter
  \vfill
  {\tfc\italic The}\par
  \vfill
  {\tfd\WORD \largecaps{Letterspace Module}}\par
  \vfill
  {\tfc\italic for {\CONTEXT} MkIV}\par
  \vfill
  {\tfa\sc \mediumcaps{A Contribution to Horizontal Movement}}\par
  \vfill
\stopFMmakeup
\stopfrontmatter

\page

\useURL [phg-mail] [megas.kapaneus@gmail.com]   [] []
\useURL [phg-bibu] [https://bitbucket.org/phg/] [] []
\startstandardmakeup
  \vfill\raggedright\tfx
  © 2011-03-16 {\italic Philipp Gesang}, Heidelberg\par
  The latest Version can be found at \from [phg-bibu].\par
  Mail bugs and fixes or complaints and suggestions to \from
  [phg-mail].\par
\stopstandardmakeup

\page [odd]
\startbodymatter

\setuppagenumber [number=1]
\setuppagenumbering [
  state=start,
  alternative=doublesided,
  location={right,header},
]

\setupheadertexts
  [{\tfx\getmarking[title]}]    [{\pagenumber}]
  [{\pagenumber}]        [{\tfx\getmarking[title]}]

\title{Content}

\placelist[chapter,section][criterium=all]

\chapter{Commands}

\section{Default Letterspace Command}

\showsetup{letterspace}
\showsetup{startletterspace}

\section{Defining and Customizing Letterspace Commands}

\showsetup{setupletterspace}
\showsetup{defineletterspace}

\chapter{Applications}

\section{Things to Avoid}

\te{Letterspacing} is a dynamic property of a string of text, as
opposed to static font properties that are e.g. italics or slant.
In principle, when applying a letterspacing to text, the current
font is not merely pushed back in favor of another font.
Instead, the way of typesetting the same font is modified by
certain parameters; in the case of the \te{Letterspace} module
these are the \te{kerning} and the \te{interword space}.
Therefore it exclusively depends on the correct adjustment of said
parameters whether the letterspacing will achieve its purpose or
not.
On the other hand, external factors like harmonizing different
typefaces, the font’s design size \etc. are ruled out as possible
influences, which can be a great advantage if for example a font
happens to lack a matching italic face for emphasizing.

Due to its flexibility and because it poses relatively small
demands on the typesetting environment, thoughtless letterspacing
may easily ruin a product.
Moderate values don’t express how important a particular emphasis
is to the author? Just \ugly{widen the spacing} and no reader
will ever skip over your message \dots.
Sure, everybody will get the cue, though the appearance of the
paragraph, possibly the whole page will certainly be spoilt.


\section{Emphasis}

\section{Capital Spacing}


\stopbodymatter
\stoptext
