\usemodule [letterspace]

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

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

\defineletterspace [smallcaps]
\setupletterspace  [smallcaps] [
  spacefactor=.05,
  spaceskip=.25em,
]

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

\let\te\textemph
\unexpanded\def\name#1{\smallcaps{\sc#1}}

\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]

\def\quote#1{\bgroup\italic#1\egroup}
\def\uprightslash{\bgroup\rm/\egroup}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Bibliography                                                  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Bib: Setups                                                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setuppublications [
  alternative=ssa,
  refcommand=authoryear,
  %sorttype=bbl,
  sort=author,
  numbering=yes,
  autohang=yes,
]

\setuppublicationlist [
  artauthor=\invertedauthor,
]

\setupcite [authoryear] [compress=no]

%%% Used in bibliography formatting.
\definestartstop [bibindent] [
  before={\startnarrower[left]%
          \setupindenting[-\leftskip,yes,first]%
          \clubpenalty-9000%
          \widowpenalty-9000%
          },  
  after=\stopnarrower,
]

\unexpanded\def\ctay#1{\cite[authoryear][#1]}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Bib: Entries                                                  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\startpublication [
  k=lt,
  t=book,
  a={{Willberg/Forssman}},
  y=1997,
  %n=1,
  s={Lesetypographie},
]
  \author[]{Hans Peter}[]{}{Willberg}
  \author[]{Friedrich}[]{}{Forssmann}
  \pubyear{1997}
  \title{Lesetypographie}
  \city{Mainz}
\stoppublication

\startpublication [
  k=mt,
  t=book,
  a={Bodoni},
  y=1818,
  %n=1,
  s={Manuale},
]
  \author[]{Giambattista}[]{}{Bodoni}
  \pubyear{1818}
  \title{Manuale Tipografico, 2~vols}
  \city{Parma}
\stoppublication

\startpublication [
  k=bh,
  t=book,
  a={Bringhurst},
  y=2008,
  %n=1,
  s={Elements},
]
  \author[]{Robert}[]{}{Bringhurst}
  \pubyear{2008}
  \title{The Elements of Typographic Style}
  \edition{3.2}
  \city{Point Roberts WA, Vancouver}
\stoppublication

\startpublication[
  k=roemer,
  t=article,
  a={Roemer},
  y=2011,
  %n=3,
  s={Gewichten},
]
  \artauthor[]{Christine}[]{}{Roemer}
  \pubyear{2011}
  \arttitle{Gewichten -- Wichtiges und Unwichtiges mit \LATEX\ markieren}
  \journal{Die \TEX nische Komödie}
  \volume{2011:1}
  \pages{6--16}
\stoppublication

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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{Introduction}

Robert \name{Bringhurst} quotes Frederick \name{Goudy}’s famous
dictum on the topic of letterspacing: \quote{A man who would
letterspace lowercase would steal sheep.}\footnote{\ctay{bh},
S.~31.}

\chapter{Commands}

\section{Default Letterspace Command}

\showsetup{letterspace}
\showsetup{startletterspace}

\section{Defining and Customizing Letterspace Commands}

\showsetup{setupletterspace}
\showsetup{defineletterspace}

\chapter{Applications}

\section{Precautions}

\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
highlighted text, the paragraph, and possibly the whole page will
certainly be spoilt.
Granted, from this perspective letterspacing might appear to be
too dangerous a tool, only begging for misuse.
But this judgement is premature as letterspacing has in fact a
long tradition and was employed in many outstanding examples of
typography.
Apart from its seductive versatility there are no objections
against letterspacing on a general level, as long as it is
carefully utilized.

Letterspacing has two prevailing uses: ({\it1}) for emphases and
({\it2}) for spacing capital letters, which is especially
valuable in display situations like for instance the front matter
of books or section headings.
Both come with a set of peculiarities that the typesetter must
consider in order to figure out the appropriate values for the
interword and letter spacings.

\section{Emphasis}
Documents that require many levels of different emphases are
among the primary targets of letterspacing.
For example, in linguistics an author might wish to distinguish
({\it1}) names of cited authors, ({\it2}) ordinary text emphasis,
({\it3}) inline quoted passages, and ({\it4}) word forms or
etymological roots.
To be sure, this can be accomplished with a mapping like
  {\it1}: small capitals,
  {\it2}: italics,
  {\it3}: quotation marks, and
  {\it4}: a slanted face.
But \te{quotation marks} are hard to keep track of, if the enveloped
text exceeds a certain length; also, they disencourage skimming
because the reader always has to check whether the point that
caught his eye might belong to a quotation instead of the main
text.
In various fonts -- mainly sans serif -- \te{slant} cannot easily
be told apart from italics, thus defeating the very purpose of
emphasis, in other fonts it might not be available at all.
\te{Bold face} might seem to be an obvious alternative but even
semi bold weights cause text to stand out from the surrounding
paragraph, diverting the readers attention away from its normal
trail along successive lines.
Besides, the more a text is intermingled with different weights,
the closer it resembles the look of a dictionary.

After these deliberations the validity of \te{letterspacing,}
including lower case, as a means of emphasis is already half
established.
It beats slant with respect to availability and differentiating
effect.
It is preferable over quotation marks because the emphasized
passage clearly differs from the main font style.
Finally, it triumphs over weight switching as the result is very
close to the mean overall distribution of ink within the text
body.
In the previous graduation of emphasis levels an alternative
involving letter spacing could be as follows:
  {\it1}: small caps,
  {\it2}: letterspaced text font,
  {\it3}: italics, and
  {\it4}: letterspaced italics or slants.
Here another convenient feature of letterspacing becomes
apparent: as it is basically a different method of typesetting
the same font it can theoretically be applied on any typeface and
weight.
It follows, that in the foregoing mapping, parts of longer
(italic) quotations may be emphasized as well:
  \quote{%
    regum timendorum in proprios greges {\uprightslash}
    reges in ipsos imperium est \te{Iouis} {\uprightslash}
    \te{clari} Giganteo triumpho {\uprightslash}
    cuncta supercilio \te{mouentis.}%
  }
However, substituting rule {\it2} for {\it3}, the resulting
mapping will be less satisfactory.
As quotations are prone to extending over multiple lines, whereas
normal emphasis rarely spans more than two words, letter spacing
the former might lead to the unbalanced appearance of paragraphs.
So best avoid letterspacing in cases where the object possibly
encompasses entire sentences.

Caution is necessary concerning \te{punctuation} adjacient to the
letterspaced passage.
In contrast to italicized or bold emphasis where an immediately
succeeding punctuation sign is best typeset in the surrounding
main face (e.g. „et {\it tu}, Brute?“), letter spacing may
require the sign to be typeset as part of the emphasis.
The reason for this consists partly in the larger interword
spacing that extends to the surrounding spaces, and partly also
on the letterspacing itself which would be disrupted by a
tighter-spaced character.
(Bad: \te{O Tite}, tute, \te{Tati}, tibi tanta, \te{tyranne}, tulisti;
good: \te{O Tite,} tute, \te{Tati,} tibi tanta, \te{tyranne,} tulisti.)

\section{Capital Spacing}

\section{Don’t’s}
-- different letterspace widths for the same meaning


\title{References}

\startbibindent
  \placepublications[criterium=all]
\stopbibindent

\stopbodymatter
\stoptext
