\startcomponent co-typography

\environment contextref-env
\product contextref

% this chapter runs in mkii and mkiv modes now, but the output 
% is not always the same.

% needed for mkiv:

\startmode[mkiv]

\definefontfeature[default][default]
     [protrusion=pure,expansion=quality,mode=node,script=latn]
\usetypescript[modern][ec]

% the next hack shortens the font name (in mkiv, the \fontname is the
% full path to the disk file)

\input enco-run
\unexpanded\gdef\visualizecharacterslegend
  {\hbox
     {\edef\banner{\currentencoding\space\ctxlua{tex.sprint(file.basename('\fontname\font'))}}%
      \tttf\banner:\space
      {\blue composed}\space{\red bottom}\space{\green char}\space raw}}

\stopmode
% needed for mkii:

\loadmapfile[lm-texnansi.map]
\loadmapfile[lm-qx.map]
\loadmapfile[lm-t5.map]

\def\definition#1{{\it #1}}

% this doesnt work properly in mkiv ? lines are black instead of gray

\def\FakeLine#1%
  {\hbox to \hsize
     {\strut
      \hbox to \hsize
        {\startcolor[AltColor]%
         \leaders
         \hrule height .8\ht\strutbox depth  .6\dp\strutbox
         \hfil
         \stopcolor
         #1}%
      \hskip-\hsize
      \hbox to \hsize
        {\startcolor[white]%
         \leaders
         \hrule height .25pt depth .25pt
         \hfil
         \stopcolor
         \hphantom{#1}}%
      \hss}%
   \par}

\def\FakeParagraph#1#2%
 {\startlinecorrection[blank]
  \FakeLine{}\FakeLine{#1{#2{-}}}
  \FakeLine{}\FakeLine{#1{#2{,}}}
  \FakeLine{}\FakeLine{#1{#2{.}}}
  \stoplinecorrection}

% this chapter needs lots of typescripts

\usetypescript
   [map,sans,mono,handwriting,calligraphy,serif]
   [helvetica,schoolbook,times,antykwa-torunska,modern]

\chapter[typography]{Typography}

\section{Introduction}
\index{typography}

Throughout the millennia humans have developed and adapted methods for
storing facts and thoughts on a variety of different media. A very
efficient way of doing this is using logograms, as the Chinese have done
for ages. Another method is to represent each syllable in a word by a
symbol, as the Japanese do when writing telegrams. However, the most
common way of storing characters is by using a limited set of shapes
representing basic sounds (a.k.a. phonemes). Such a collection is
called an \definition{alphabet}, and the shapes are called
\definition{letters}.

\TEX\ is primarily meant for typesetting languages that 
use this third method. The other two methods can also be dealt
with, but some extra effort is needed. In this chapter we will focus
on languages that use alphabets, the other methods will be
explained in later chapters.

The shapes representing the characters that make up an alphabet are
more or less standardized, and thereby can be recognized by readers
even if their details differ.  A collection of pictures representing
character shapes is called a \definition{font}, and the pictures in a
font are called \definition{glyphs}.

The example below shows (from left to right) a Computer Modern font, a Helvetica lookalike, a Times Roman lookalike and the Antiqua Torunska font, all scaled to 48pt.

\startlinecorrection
\externalfigure[typography/glyphs.pdf][page=1]
\stoplinecorrection

As you can see, quite some design variation is possible. It follows that when fonts from different sources (designers) are intermixed, the result is not always pleasing to look at. The term \definition{font collection} refers to a set of fonts combined together in such a way that the overall appearance on a page looks good and reading is as comfortable as possible.  

The next example shows an attempt at such a font collection:  the fonts were picked such that the glyph sizes and the line thicknesses are roughly the same.

\startlinecorrection
\externalfigure[typography/glyphs.pdf][page=3]
\stoplinecorrection

Fonts from a single source often already come in a few variations that are 
intended to be used together.  Such a set of fonts with  the same basic design is known as a \definition{font family}. In the example below there are a normal, a bold, an italic, and a bold italic \definition{alternative} of a font. 

\startlinecorrection
\externalfigure[typography/glyphs.pdf][page=2]
\stoplinecorrection



The distance between the individual glyphs in a word and the actual
glyphs that are used depends on the combinations of these glyphs.  In
the top line of the next sample, the gap between the~b and the~o as
well as the distance between the~o and the~x is slightly altered.
This is called kerning. Further, the separate glyphs for the~f and
the~i have been combined into a single one. This is called ligaturing.

\startlinecorrection
\hbox to \hsize{\hss\vbox
  {\forgetall \hsize=5cm
   \vfill
   \definefont[test][ComputerModern at 48pt]\test
   \hbox{box}
   \vskip-36pt
   \def\\#1%
     {\toprulefalse
      \bottomrulefalse
      \ruledhbox{\vrule width 0pt height 72pt#1}}
   \hbox{\\b\\o\\x}}
\kern 2cm
\vbox
  {\forgetall  \hsize=5cm
   \vfill
   \definefont[test][ComputerModern at 48pt]\test
   \hbox{file}
   \vskip-36pt
   \def\\#1%
     {%\toprulefalse
      %\bottomrulefalse
      \hbox{\vrule width 0pt height 72pt#1}}
   \hbox{\\f\\i\\l\\e}}
\hss}
\stoplinecorrection

The font shown here is Computer Modern, the default \TEX\ font. This
font is designed by Donald Knuth. The Computer Modern has many
kerning pairs, while the Palatino||like font that is used for most of
the text in this manual has only a few, while both have essentially
the same list of ligatures.


Micro||typography like kerning pairs and ligatures are not to be altered 
by the user, but are part of the font design and the required data is stored
inside the font file, together with the drawing routines for the
actual pictures. It {\em is\/} possible for the user to alter fonts
and interline spacing and some more aspects on the level of
macro||typography. The choice of font is the main topic of this
chapter.

There are many different methods that can be used to classify
fonts. There are classification systems based on the period in which
the style was first developed; on the characteristics of the font; or
the font application, like a newspaper or a book. Often, classification
systems mix these characteristics to a certain point.

For example, the Computer Modern family can be classified as a
\quote{modern} font. This is a classification that primarily indicates
a period (late 18\high{th} century), but it also implies a particular
shape: \quote{modern} fonts have a high contrast between thick and
thin strokes, and their stress axis is perfectly vertical.

At the same time, specific fonts in the Computer Modern family can be
classified as \quote{serif} (glyphs strokes have embellishments at the
end), \quote{sans serif} (shapes end abruptly), or \quote{monospaced}
(all glyphs have the same width). 

The Computer Modern family is in fact inspired by one font in particular:
\quote{Modern 8a} by the Monotype corporation. Knuth implemented
Computer Modern in \METAFONT\ using parameters so that he could
generate a whole collection of fonts all closely matching each other in
style. In \CONTEXT\ you will normally use a reimplementation of
Computer Modern using a more modern file format (Type~1 or OpenType).
This new version is called \quote{Latin Modern}, and also features an
extended glyph set making it usable for languages that could not be
typeset with Knuth's original fonts.

\startlinecorrection
\ruledhbox to \hsize
  {\hss
   \definefont[test][LMRoman-Regular           at 48pt]\test ok\setstrut\strut\hss
   \definefont[test][LMSans-Regular            at 48pt]\test ok\hss
   \definefont[test][LMTypewriter-Regular      at 48pt]\test ok\hss
   \definefont[test][LMRoman-CapsRegular       at 48pt]\test ok\hss
   \definefont[test][LMTypewriterVarWd-Regular at 48pt]\test ok\hss}
\stoplinecorrection

In this example you see five font styles of Latin Modern: the Roman,
Sans, Typewriter, Smallcaps and Variable Typewriter. Computer Modern
is one of the few font families that comes with dedicated design
sizes.  The example below shows the differences of a 5, 7, 9, 12 and
17~point design scaled up to 48 points. Such nuances in font size are
seldom seen these days.

\startlinecorrection
\ruledhbox to \hsize
  {\hss
   \definefont[test][cmr5  at 48pt]\test ok\setstrut\strut\hss
   \definefont[test][cmr7  at 48pt]\test ok\hss
   \definefont[test][cmr9  at 48pt]\test ok\hss
   \definefont[test][cmr12 at 48pt]\test ok\hss
   \definefont[test][cmr17 at 48pt]\test ok\hss}
\stoplinecorrection

As explained earlier, the general appearance of a font style can be
classified according to many schemes, and the exact terminology used
depends on the background of the user.  In \in {table}[tab:font
triplets] you can see some examples of the terms that are used by
various people to identify the three font styles that are most often
found together within a single book design (such as for a software manual).

\startbuffer[styles]
\vskip1ex
\starttabulate[|l|l|l|]
\NC \bf \rlap{terms}  \NC \qquad \NC \bf intented usage        \NC \NR
\NC regular, serif, roman   \NC            \NC \rmtf main text          \NC \NR
\NC support, sans            \NC             \NC \sstf section headings   \NC \NR
\NC teletype, mono, type \NC          \NC \tttf code examples      \NC \NR
\stoptabulate
\vskip1ex
\stopbuffer

\placetable
  [here][tab:font triplets]
  {Some ways of identifying the font styles in a document design.}
  {\getbuffer[styles]}

Within the lists of terms, the earlier names are normally used by
typographers and book designers, the later ones are commonly used in
\TEX. In \CONTEXT\ all of these terms can be used intermixed
because they are all remapped to the same set of internal commands. As
will be explained later, the command \type {\rm} is used to switch to
the style used for the main text (this is usually a font style with
serifs), \type{\ss} to switch to the support style (usually a style
without serifs) and \type {\tt} to switch to the code example style
(for which usually monospaced fonts are used).

Text can be typeset in different font sizes. The unit \type {pt},
short for \quote{printer's point}, is normally used to specify the
size of a font. There are a little over 72 points per inch (or a
little under 2.85 points per millimeter, if you prefer metric
units). Traditionally, font designers used to design a glyph
collection for each point size, but nowadays most fonts have only a
single design size of 10 points, or at most a small set of sizes with
names indicating their proposed use, like {\em caption}, {\em text},
and {\em display}.

The next sections will go into the details of switching of font styles and
fonts in your documents. Be warned that the font switching mechanism
is rather complex. This is due to the different modes like math
mode and text mode in \CONTEXT. If you want to understand the
mechanism fully, you will have to acquaint yourself with the concept
of encoding vectors and obtain some knowledge on fonts and their
peculiarities.  See the next chapter for more information.

\section[bodyfont]{The mechanism}
\index{roman}
\index{sans serif}
\index{typewriter}

Font switching is one of the oldest features of \CONTEXT\ because font
switching is indispensable in a macro package.  During the years
extensions to the font switching mechanism were inevitable. The
following starting points have been chosen during the development of this
mechanism:

\startitemize[packed]
\item It must be easy to change font {\em styles}, e.g., switching 
      between roman (serif, regular), sans serif
      (support), teletype (monospaced) etc. (\type {\rm},
      \type {\ss}, \type {\tt} etc.)
\item More than one {\em alternative} set of glyphs shapes must be
      available like italic and bold (\type {\it} and \type {\bf}).
\item Different font {\em families} like Latin Modern Roman 
      and Lucida Bright must be supported.
\item It must be possible to combine different families into font
      {\em collections}.
\item Different sub|| and super||scripts must be
      available. These script sizes have to be consistent across the
      switching of family, style and alternative.
\item It should be possible to combine all of these requirements
      into a single definition unit called a {\em body font}.
\item Changing the global font collection as well as the size must 
      also be easy, and so sizes between 8pt and 14.4pt must be
      available by default.
\stopitemize

Before reading further, please stop for a moment to make sure you
thoroughly comprehend the above paragraphs. \CONTEXT's terminology
probably differs from what you are accustomed to, especially if you
were previously a \LATEX\ user.

\section[font switching]{Font switching}
\index{fonts}
\index{roman}
\index{slanted}
\index{boldface}
\index{italic}
\index{typewriter}
\index{sans serif}
\index{old style}
\index{medaeval numbers}

The mechanism to switch from one style to another is somewhat complex,
not in the least because the terminology is a bit fuzzy.  A quick
recap: we call a collection of fonts, like Lucida or Computer Modern
Roman, a {\em family}.  Within such a family, the members can be
grouped according to characteristics. Such a group is called a {\em
style}. Examples of styles within a family are: \quote{roman},
\quote{sans serif} and \quote{teletype}. We saw already that there can
be alternative classifications, but they all refer to the presence of
serifs and the glyphs having equal widths. Within a style there
can be {\em alternatives}, like \quote{boldface} and \quote{italic}.

There are different ways to change into a new a style or
alternative. You can use \type {\ss} to switch to a sans
serif font style and \type {\bf} to get a bold alternative.
When a different style is chosen, the alternatives adapt
themselves to this style. Often a document will be mostly typeset 
using just one combination of family and style. 
This is called the bodyfont.

Consistent use of commands like \type {\bf} and \type
{\it} in the text will automatically result in the desired
bold and italic alternatives when you change the family or
style in the setup area of your input file. 

\subsection[font style switching]{Font style switching}

Switching to another font style is done by one of five 
two-letter commands that are listed in~\in{table}[tab:style switches].

\startbuffer[styleswitch]
\vskip 1ex
\starttabulate[|l|l|]
%\NC \bf style  \NC \bf Long names and aliases    \NC\NR
\NC \type{\rm} \NC serif, regular, roman, rm     \NC\NR
\NC \type{\ss} \NC sans, support, sansserif, ss  \NC\NR
\NC \type{\tt} \NC mono, type, teletype, tt      \NC\NR
\NC \type{\hw} \NC handwritten, hw               \NC\NR
\NC \type{\cg} \NC calligraphic, cg              \NC\NR
\NC --         \NC mm                            \NC\NR
\stoptabulate
\vskip 1ex
\stopbuffer

\placetable
  [here]
  [tab:style switches]
  {Font style switching commands}
{\getbuffer[styleswitch]}

The \quote{handwritten} and \quote{calligraphic} font styles are
sometimes useful when dealing with very elaborate document layout
definitions. In the \CONTEXT\ distribution only the Lucida font
family uses these styles; in any other font set they are simply
ignored. You could use them in your own font setups if you so desire.
See the next chapter for font setup definitions.

There is a sixth internal style that is only ever referred to as
\quote{mm}. This style handles math fonts. It does not make sense to
use this style directly so there is no command attached to it, but it
is quite important internally so it makes sense to introduce it right
away.

\subsection[font alternative switching]{Font alternative switching}

The alternatives within a style are given in~\in{table}[tab:alternative switches]. 
Not all fonts have both italic and slanted or the bold alternatives of
each. Some other fonts do not have small caps or have only one set of
digits.  When an alternative is not known, \CONTEXT\ will attempt to
choose a suitable replacement automatically. For instance, the italic
alternative may be used for if slanted is not available or vice versa.


\startbuffer[alternativeswitch]
\vskip 1ex
\starttabulate[|l|l|]
\NC \type{\bf} \NC bold                                \NC\NR
\NC \type{\it} \NC italic                              \NC\NR
\NC \type{\bi} \NC bolditalic, italicbold              \NC\NR
\NC \type{\sl} \NC slanted                             \NC\NR
\NC \type{\bs} \NC boldslanted, slantedbold            \NC\NR
\NC \type{\sc} \NC smallcaps                           \NC\NR
\NC \type{\os} \NC mediaeval (from {\em oldstyle}) \NC\NR
\NC \type{\tf} \NC normal (from {\em typeface})    \NC\NR
\stoptabulate
\vskip 1ex
\stopbuffer

\placetable
  [here]
  [tab:alternative switches]
  {Font alternative switching commands and their keyword equivalents.
   With \type {\os} you tell \CONTEXT\ that you prefer mediaeval or
   old||style numbers as in {\os 139} over~{\rm 139}.}
{\getbuffer[alternativeswitch]}

Besides these two-letter commands, there is a series of font selector
commands with a suffix attached. Some examples of that are:

\startexample
\starttyping
\tfx \bfx \slx \itx
\tfa \tfb \tfc \tfd \tfxx
\stoptyping
\stopexample

Each of the ordered alphabetic suffixes \type{a}, \type{b}, \dots\
select a somewhat larger actual font than the previous one. The
\type{x} and \type{xx} suffixes select smaller and yet smaller 
versions.


\startbuffer[xalternativeswitch]
\vskip 1ex
\starttabulate[|l|l|]
\NC \type{\bfx} \NC smallbold                           \NC\NR
\NC \type{\itx} \NC smallitalic                         \NC\NR
\NC \type{\bix} \NC smallbolditalic, smallitalicbold    \NC\NR
\NC \type{\slx} \NC smallslanted                        \NC\NR
\NC \type{\bsx} \NC smallboldslanted, smallslantedbold  \NC\NR
\NC \type{\tfx} \NC small, smallnormal                  \NC\NR
\stoptabulate
\vskip 1ex
\stopbuffer

\placetable
  [here]
  [tab:small alternative switches]
  {Small alternative switching commands and their keyword equivalents.}
{\getbuffer[xalternativeswitch]}


The \quote{small} switches mentioned 
in~\in{table}[tab:small alternative switches] are always available. 
The availability of other
commands like \type {\ita}, \type {\bfxx}, \type {\bfc}, etc.
depends on the completeness of the font definition files. 
For the core \CONTEXT\ fonts, you can count on at least
\type{\tfa}, \type{\tfb}, \type{\tfc}, \type{\tfd}, and \type{\tfxx} 
being defined. For the others, just try and see what happens.

When you have chosen a larger character size,
for example \type {\tfb}, then \type {\tf} equals \type {\tfb},
\type {\bf} equals \type {\bfb}, etc. This method is almost always
preferable over returning to the original character size, but it 
may catch you off-guard.

More generic font scaling commands are also available:

\startexample
\starttyping
\tx \txx
\setsmallbodyfont \setbigbodyfont
\stoptyping
\stopexample

The command \type {\tx} adapts itself to both the style and the
alternative. This command is rather handy when one wants to write
macros that act like a chameleon. Going one more step smaller, is
possible too: \type {\txx}. Using \type {\tx} when \type {\tx} is
already given, is equivalent to \type {\txx}.

The commands \type{\setsmallbodyfont} and \type{\setbigbodyfont} switch 
to the \quote{small} and \quote{big} body font sizes. These relative 
sizes are defined via the \quote{body font environment}, 
see~\in{section}[sec:body font environment]. 

The various commands will adapt themselves to the actual
setup of font and size. For example:

\startbuffer
{\rm test {\sl test} {\bf test} \tfc test {\tx test} {\bf test}}
{\ss test {\sl test \tx test} {\bf test \tx test}}
\stopbuffer

\startexample
\typebuffer
\stopexample

will result in:

\startreality
\startlines
\getbuffer
\stoplines
\stopreality

When the \type {\rm} style is active, \CONTEXT\ will interpret the
command \type {\tfd} as if it was \type {\rmd}, when the style
\type{\ss} is active, \type {\tfd} as is treated as \type {\ssd}. 
All default font setups use \type {tf}||setups so they will
automatically adapt to the current font style.

The remainder of this section is for the sake of completeness.
Use of the following commands in new documents is discouraged.

Frequent font switching leads to longer processing times.
When no sub- or superscripts are used and you are very
certain what font you want to use, you can perform fast font
switches with: \type {\rmsl}, \type {\ssbf}, \type {\tttf},
etc.

The plain \TeX\ compatible font switches 
\type {\vi}, \type {\vii}, \type {\viii}, \type {\ix}, \type {\x}, and 
\type {\xii} are also defined, these have local effects 
like \type{\tfx} and \type{\tfa}. 

\subsection{Switching font styles in setup commands}

A number of \CONTEXT\ commands use the parameter \type {style} to set
the used font.  The parameter mechanism is rather flexible so that 
within the parameter \type {style} you can use any of the font switching 
commands like \type {\bf} or \type {bf} or \type{\switchtobodyfont}, 
but also a number of keywords like
\startexample
\starttyping
normal  bold  italic  bolditalic  slanted  boldslanted  type
small  smallbold  smallitalic  ...  smallslanted  ...  smalltype
capital
\stoptyping
\stopexample

Most of these keywords have already been listed in the tables \in{}[tab:alternative switches]
and \in{} [tab:small alternative switches], but a few predefined ones have not
been mentioned yet.
These are displayed in~\in{table}[tab:last alternative switches], together with the commands
they execute. As is normal in \CONTEXT, you can extend the list of accepted keywords by 
defining your own. This will be  explained in\in~{section}[sec:definealternativestyle] 
in the next chapter.

\startbuffer[lastalternativeswitch]
\vskip 1ex
\starttabulate[|l|l|]
\NC \type{\tt}               \NC type, mono      \NC\NR
\NC \type{\ttx}              \NC smalltype       \NC\NR
\NC \type{\ss}               \NC sans, sansserif \NC\NR
\NC \type{\ss\bf}            \NC sansbold        \NC\NR
\NC \type{\setsmallbodyfont} \NC smallbodyfont   \NC\NR
\NC \type{\setbigbodyfont}   \NC bigbodyfont     \NC\NR
\NC \type{\smallcapped}      \NC cap, capital    \NC\NR
\NC \type{\WORD}             \NC WORD            \NC\NR
\stoptabulate
\vskip 1ex
\stopbuffer

\placetable
  [here]
  [tab:last alternative switches]
  {Remaining font alternative keywords.}
{\getbuffer[lastalternativeswitch]}

\section[emphasize]{Emphasize}
\index{emphasize}
\index{slanted}
\index{italic}
\macro{\tex{em}}

Within most macro||packages the command \type {\em} is
available. This command behaves like a chameleon which means
that it will adapt to the actual typeface. In \CONTEXT\
\type {\em} has the following characteristics:

\startitemize[packed]
\item a switch to {\it italic} or {\sl slanted} is possible
\item a switch within \type {\bf} results in {\bi bold italic}  or 
      {\bs bold slanted} (when available)
\item a so called {\em italic correction} is performed
      automatically (\type {\/})
\stopitemize

The bold italic or bold slanted characters are supported only
when \type {\bs} and \type {\bi} are available.

\startbuffer
The mnemonic {\em em} means {\em emphasis}.
{\em The mnemonic {\em em} means {\em emphasis}.}
{\bf The mnemonic {\em em} means {\em emphasis}.}
{\em \bf The mnemonic {\em em} means {\em emphasis}.}
{\it The mnemonic em {\em means \bf emphasis}.}
{\sl The mnemonic em {\em means \bf emphasis}.}
\stopbuffer

\startexample
\typebuffer
\stopexample

This results in:

\startlines
\getbuffer
\stoplines

The advantage of the use of \type {\em} over \type {\it}
and|/|or \type {\sl} is that consistent typesetting is
enforced.

By default emphasis is set at {\em slanted}, but in this text
it is set at {\em italic}. This setting is made via 
\type{\setupbodyfontenvironment}, 
see~\in{section}[sec:body font environment] for more details:

\startexample
\starttyping
\setupbodyfontenvironment
   [default]
   [em=italic]
\stoptyping
\stopexample


\section[linespacing]{Line spacing}
\index{linespacing}
\index{baselines}
\index{whitespacing}
\index{spacing}
\macro{\tex{setupinterlinespace}}

In \TEX\ linespacing is determined by a number of variable
dimensions like \type {\topskip}, \type {\parskip} and \type
{\baselineskip}. However, in \CONTEXT\ these variables are
related to the bodyfont size.

A line has a height and a depth. The distance between two
lines is normally equal to the sum of the maximum height and
maximum depth:

\leavevmode
\blackrule[height=max,depth=0pt] +
\blackrule[height=0pt,depth=max] =
\blackrule[height=max,depth=max]

This sum is in \CONTEXT\ equal to 2.8ex, so almost three
times the height of an~x. This is about $1.2$ times the
bodyfont height. The proportion between maximum height and
depth is .72~:~.28 by default. Linespacing alters when a new
bodyfont is used or when linespacing is defined explicitly
by \type {\setupinterlinespace} (which is explained later):

Sometimes a line does not have the maximum height or depth.
The next example illustrates this:

\def\somecharacter#1%
  {\setbox0=\hbox{#1}%
   \blackrule[width=\wd0,height=\ht0,depth=\dp0]}

\def\someline%
  {\noindent \processtokens\somecharacter\somecharacter\relax\space
     {The height and depth of lines differs.}}

\someline

It says:

\startbaselinecorrection
\ruledhbox{The height and depth of lines differs.}
\stopbaselinecorrection

When we put two of these lines above each other we will get:

\someline \crlf \someline

You can see that the distance is somewhat bigger that the
sum of the height and depth of each separate line. This
distance is called the baseline distance (\type
{\baselineskip}) and is in this document \the \baselineskip.
If we add some extra height to the line we see this:

\someline \blackrule[height=2ex,depth=2ex] \crlf \someline

To prevent the lines from touching \TEX\ adds a \type
{\lineskip}, in our example {\the\lineskip}. In a similar
way \TEX\ is taking care of the first line of a page to have
at least a height of \type {\topskip} (here \the\topskip).

Linespacing is set up by:

\showsetup{setupinterlinespace}

Linespacing adapts to the size of the actual bodyfont
automatically. This means that the user can leave this
command untouched, unless a different linespacing is wanted.
Instead of a factor one of the predetermined values \type
{small} (1.0), \type {medium} (1.25) or \type {big} (1.5)
can be given. Below an example is given of a text with a
linespacing of 1.25: \type{\setupinterlinespace[medium]}.

\startreality
\startnarrower
\setupinterlinespace[1.25]
Whenever it comes to my mind that \quotation {everything that comes in
quantities, will somehow survive}, I also got the feeling that in a few
hundred years people will draw the saddening conclusion that all those
top||ten hits produced by computers represent the some of todays
musical and instrumental abilities. Isn't it true that archaeologists can
spend a lifetime on speculating about some old coins from the first century?
On the other hand, the mere fact that one can have success with this type
of non||music success of some top||hit musicians demonstrates both the
listeners inability to rate the product and the lack of self criticism of
the performers. In principle the future archaeologist will therefore draw
the right conclusion. \par
\stopnarrower
\stopreality

When you make a font switch the linespacing is adapted when you give
the command \hbox{\type {\setupinterlinespace}} without any setup
parameters and also when you add the key \type {reset}, for example

\startexample
\starttyping
\setupinterlinespace[reset,medium]
\stoptyping
\stopexample

The text below is typeset in the fontsize \type {\tfa}, using
the following input:

\startexample
\starttyping
  \start \tfa \setupinterlinespace 
  In books meant for children we often find
  a somewhat ... when needed. \par \stop
\stoptyping
\stopexample

In this example the \type {\par} is necessary because \TEX\
operates on whole paragraphs.  Within a group one has to 
close the paragraph explicitly with an empty line or \type {\par}
otherwise \TEX\ will have forgotten the linespacing before
the paragraph is finished (as in that case, the paragraph is
ended by the empty line after the \type {\stop}). 

The word \type{height} is typeset inside a bare \type{\tfd} 
group, to illustrate why \type{\setupinterlinespace} is required.
 
\start 
\startnarrower
\tfa \setupinterlinespace In books meant for children
we often find a somewhat bigger typeface, for instance
because we are convinced that this enables them to read the
book themselves. On the other hand, I can also imagine that
it is a cheap way to increase the number of pages.
Unfortunately scaling up will also uncover the lack of
quality of the typesetting used and|/|or the lack of
typographic knowledge of the user of such a system. The
interline space sometimes differs on a line by line basis,
and depends on the {\tfd height} of the current line.
Therefore, when changing the style, something that should
only be done on purpose, also change the baseline distance
when needed. \par 
\stopnarrower 
\stop

Instead of a keyword, one can pass a key||value pair to
define the characteristics of a line. 

\showsetup{setupinterlinespace:2}

The default settings are:

\starttyping
\setupinterlinespace
  [height=.72,
   depth=.28,
   top=1.0,
   bottom=0.4,
   line=2.8ex]
\stoptyping

The \type {height} and \type {depth} determine the ratio
between the height and depth of a line. The baseline
distance is set to 2.8ex. The parameters \type {top} and
\type {bottom} specify the relation between the bodyfont
size and the height of the first line and the depth of the
last line on a page. They are related to
\TEX's \type {\topskip} and \type {\maxdepth}.

We will see later that instead of setting the spacing at the document
level, i.e.\ for each font, you can set the spacing per body font
environment:

\starttyping
\setupbodyfontenvironment
  [modern] [12pt]
  [interlinespace=14pt]
\stoptyping


\section[capitals]{Capitals}
\index{capital characters}
\index{capitals}
\index{small capitals}
\index{small||caps}
\macro{\tex{setupcapitals}}
\macro{\tex{CAP}}
\macro{\tex{Cap}}
\macro{\tex{cap}}
\macro{\tex{smallcapped}}
\macro{\tex{nocap}}
\macro{\tex{Caps}}
\macro{\tex{Words}}
\macro{\tex{WORDS}}
\macro{\tex{Word}}
\macro{\tex{characters}}

Some words and abbreviations are typeset in capitals (uppercase). \CONTEXT\
provides the following commands for changing both upper|| and lowercase
characters into capitals.

\showsetup{cap}

\showsetup{Cap}

\showsetup{CAP}

\showsetup{Caps}

The command \type {\cap} converts all letters to capitals at
the size of \type {\tx}. If you switch to italic (\type
{\it}), bold (\type {\bf}), etc. the capital letter will
also change. Since \type {\cap} has a specific meaning in
math mode, the formal implementation is called \type
{\smallcapped}. However in text mode one can use \type
{\cap}.


% You are advised not to type capital letters in your source
% file because real small caps distinguishes between small
% and big letters.

\startbuffer
Capitals for \cap {UK} are \cap {OK} and capitals for \cap {USA} are
okay. But what about capitals in \cap {Y2K}.
\stopbuffer

\startexample
\typebuffer
\stopexample

this results in:

\startreality
\getbuffer
\stopreality

A \type {\cap} within a \type {\cap} will not lead to any
problems:

\startbuffer
\cap {People that have gathered their \cap {capital} at the cost of other
people are not seldom \nocap {decapitated} in revolutionary times.}
\stopbuffer

\startexample
\typebuffer
\stopexample

or:

\startreality
\getbuffer
\stopreality

In this example you can see that \type {\cap} can be temporarily
revoked by \type {\nocap}.

\showsetup{nocap}

The command \type {\Cap} changes the first character of a
word into a capital and \type {\CAP} changes letters that
are preceded by \type {\\} into capital letters. With \type
{\Caps} you can change the first character of several words
into a capital letter.

\showsetup{setupcapitals}

With this command the capital mechanism can be set up. The
key \type {sc=yes} switches to real {\sc Small Caps}. The key
\type {title} determines whether capitals in titles are changed.

Next to the former \type {\cap}||commands there are also:

\showsetup{Word}

and

\showsetup{Words}

These commands switch the first characters of a word or words into
capitals. All characters in a word are changed with:

\showsetup{WORD}

Let's end this section with real small capitals. When these are
available the real small caps \type {\sc} are preferred over
the pseudo||capital in abbreviations and logos.

\startbuffer
In a manual on \TeX\ and Con\TeX t there is always the question whether 
to type \cap{\TeX} and \cap{Con\TeX t} or {\sc \TeX} and {\sc Con\TeX t}. 
Both are defined as a logo in the style definition so we type \type {\TEX} 
and \type {\CONTEXT}, which come out as \TEX\ and \CONTEXT.
\stopbuffer

\startexample
\typebuffer
\stopexample

Results in:

\startreality
\getbuffer
\stopreality

{\sc It is always possible to typeset text in small
capitals. However, realize that lower case characters
discriminate more and make for an easier read.}

An important difference between \type {\cap} and \type {\sc}
is that the latter command is used for a specific designed
font type. The command \type {\cap} on the other hand adapts
itself to the actual typeface: {\sl \cap {kap}}, {\bf \cap
{kap}}, {\bs \cap {kap}}, etc.


\section[stretching]{Character spacing}
\index{inter character spacing}
\index{character spacing}
\index{stretching}
\macro{\tex{stretched}}


Some typesetting packages stretch words (inter character
spacing) to reach an acceptable alignment. In \CONTEXT\
this not supported. On purpose! Words in titles can be
stretched by:

\showsetup{stretched}

\startbuffer
\hbox to \hsize {\stretched{there\\is\\much\\stretch\\in ...}}
\hbox to 20em   {\stretched{... and\\here\\somewhat\\less}}
\stopbuffer

\startexample
\typebuffer
\stopexample

With \type {\\} you can enforce a space (\type {{}} is also
allowed).

\startreality
\leavevmode\getbuffer
\stopreality

These typographically non permitted actions are only allowed
in heads. The macros that take care of stretching do this
by processing the text character by character.


This chapter will not go into the details of underlining because
using underlining for typographical purposes is a bad practice.
Instead, the commands related to under- and over-lining are discussed
in \in {section} [underline] (\over [underline]).

\section[bodyfontswitch]{Selecting bodyfonts}
\index{bodyfont}
\index{font size}
\macro{\tex{setupbodyfont}}
\macro{\tex{switchtobodyfont}}

The bodyfont (main font), font style and size is set up with:

\showsetup{setupbodyfont}

In a running text a temporary font switch is done with the
command:

\showsetup{switchtobodyfont}

This command doesn't change the bodyfont in headers and
footers. With \type {small} and \type {big} you switch to a
smaller or larger font.

In most cases, the command \type {\setupbodyfont} is only used once:
in the style definition, and font switching inside the document is
done with \type {\switchtobodyfont}. Don't confuse these two because
that may lead to some rather strange but legitimate effects. 

\subsection{Body font sizes}

Body font sizes actually consist of two components: the
font size and a number of indirect parameters.
Think of things like the font size used in headers, footers,
footnotes, sub|| and superscripts, as well as the interline space and
a few others. 

This is why in \CONTEXT\ there is the concept of a {\em body font
environment} (expressed as a dimension), and that is what you pass as
an argument to \type{\setupbodyfont} or \type{\switchtobodyfont}. The
definitions as presented above indicate \type{5pt ... 12pt}
for the body font environment, but actually any dimension is
acceptable. 

The most frequently used sizes are predefined as body font
environments: 4pt \dots\ 12pt, 14.4pt, and 17.3pt. But when you use a
different, not-yet-defined size specification |<|for example in a
title page|>| \CONTEXT\ will define a body font environment for that
size automatically.  While doing so, \CONTEXT\ normally works with a
precision of 1~decimal to prevent unnecessary loading of fontsizes
with only small size differences.

Be warned that in this case, the results may be a less than ideal. The
reason is that \CONTEXT\ not just has to load the actual font, but it
also has to guess at the various other settings like the relative font
sizes and the interline space.  It does so by using the values from
the nearest smaller body font environment is that is already defined.

You can extend the list of predefined body font environments and even
alter the precision in body font matching. 
See~\in{section}[sec:body font environment] for detailed information about how to
tweak or define your own body font sizes.

\blank

To end this section, the example below demonstrates how the interline
space is adapted automatically, when changing the size of the
bodyfont. Consider this input:

\startbuffer
{\switchtobodyfont[14.4pt] with these commands \par}
{\switchtobodyfont[12pt]   for font switching  \par}
{\switchtobodyfont[10pt]   it is possible to   \par}
{\switchtobodyfont[8pt]    produce an eye test: \par}
{\switchtobodyfont[6pt]    a x c e u i w m q p \par}
\stopbuffer

\startexample
\typebuffer
\stopexample

The actual \CONTEXT\ behaviour is shown below on the left. On the
right you can see what would have happened if the interline space
were not automatically adapted.

\startlinecorrection
\startcombination
  {\vtop{\forgetall\hsize.4\textwidth                \getbuffer}} {}
  {\vtop{\forgetall\hsize.4\textwidth\everybodyfont{}\getbuffer}} {}
\stopcombination
\stoplinecorrection

\subsection{Body font identifiers}

\macro{\tex{usetypescript}}

In the definition block of \type{setupbodyfont} there was a list of
words given besides the special marker \type{IDENTIFIER}. These words
are the symbolic \CONTEXT\ names for the font styles that we ran into
earlier, with a few aliases so that you do not have to worry about the
actual naming convention used. The symbolic names are mapped to
two-letter internal style abbreviations that are used internally.
See~\in{table}[tab:style switches] for an overview.

Although the macro syntax does not say so, you can use two-letter
internal style abbreviations (\type{ss}, \type{rm}) as well as the
longer names, if you prefer.

\blank 

We have seen already that there are other and easier ways to switch the
font style, so if \type{\setupbodyfont} could only be used for this
purpose it would not be all that useful. But luckily there is more:
the optional \type{IDENTIFIER} can be a \quote{body font name} (aka
\quote{typeface}). Such names have to be predefined, perhaps in a font
support file, or simply on earlier lines in the style definition.

A \quote{typeface} is a symbolic name that links a single font style
to actual font families. Such symbolic names are typically grouped
together in a definition block that sets up values that link the four
styles \type{\rm}, \type{\ss}, \type{\tt} and \type{\mm} to fonts in a
\quote{font collection}, and such definition blocks are called
\quote{typescripts}.

\CONTEXT\ expects you to define your own font setups, but there 
are quite a few examples predefined in various typescript files. Not
all of those are perpetually loaded, so you usually have to execute a
typescript explicitly to get the typeface names predefined. To this
end, typescripts {\em themselves\/} also have names. 

Executing a typescript is done by \type{\usetypescript}. We will get
back to \type{\usetypescript} later because it is in fact a very
flexible command, but let's discuss simple usage first.

\showsetup{usetypescript}

A typical input sequence for selecting the predefined \quote{palatino}
set of typefaces in \MKII\ will look like this:

\startexample
\starttyping
\usetypescript[palatino][ec]
\setupbodyfont[palatino,12pt]
\stoptyping
\stopexample

In this example the typescript named \type{palatino} is asked for in
the \type{ec} font encoding, and that defines a set of typefaces under
the name \type{palatino}. These are then used by \type{\setupbodyfont}
and eventually this makes \PDFTEX\ load the free Type~1 font URW Palladio
in the correct encoding.  URW Palladio is a font that looks a lot like the
commercial font Linotype Palatino by Hermann Zapf, which explains the
name of the typescript and typefaces.

Font encodings will be handled fully in the~\in{section}[sec:encodings]. 
For now, please take for granted the fact that \PDFTEX\ needs a second 
argument to \type{\usetypescript} that specifies an encoding name, and
that there is a fixed set of acceptable names that depends on the typescript
that is being requested.

In \XETEX\ and \MKIV\ the situation is a little bit different because
fonts are reencoded to match Unicode whenever that is possible. That
in turn means that \XETEX\ and \MKIV\ prefer to use OpenType fonts
over Type~1 fonts, so different typescript definitions are used behind
the scenes, and the second argument to \type{\usetypescript} becomes
optional. 

For example,

\startexample
\starttyping
\usetypescript[palatino]
\setupbodyfont[palatino,12pt]
\stoptyping
\stopexample

will make \XETEX\ and \LUATEX\ load the OpenType font Pagella. This is
a free font from the \TeX\ Gyre project, that also looks just like the
commercial font Linotype Palatino. You may as well leave the second
argument in place: while it will always be ignored by \LUATEX,
\XETEX\ will actually use that encoding if the typescript uses Type~1
fonts instead of the more modern OpenType or TrueType font formats. 

All predefined typescripts attach meaning to (at least) the three basic
text font styles(serif, sans, and mono), so you can e.g. do this:

\startexample
\starttyping
\usetypescript[times][ec]
\setupbodyfont[times,sans,12pt]
\stoptyping
\stopexample

and end up using the OpenType font \TeX\ Gyre Heros or the Type~1 font
URW Nimbus Sans~L. Both fonts are very similar in appearance to
Linotype Helvetica, by the way.

The typescripts that come with the \CONTEXT\ distribution are placed
in source files that have names that start with \type{type-}. Some of
these files are automatically loaded when needed, but most have to be loaded
explicitly. There is a list in~\in{table}[tab:typescript files]

\macro{\tex{preloadtypescripts}}

Some of the internal building blocks for typescripts are themselves located in
yet other files (font size and font map file information, for example).
Normally, when \CONTEXT\ has to load typescript information from files, it will
try to save memory by only executing the typescript it needs at that moment and
discarding all other information. If you have enough memory at your disposal, 
you can speed up typescript use considerably by adding 

\startexample
\starttyping
\preloadtypescripts
\stoptyping
\stopexample

in your preamble or your \type{cont-usr.tex}. This will make \CONTEXT\ store
all the typescript information in internal token registers the first (and
therefore only) time it loads the actual files.

\startbuffer[typefiles]
\begingroup
\switchtobodyfont[9pt]
\vskip 1ex
\starttabulate[|l|l|l|l|l|]
\NC \bf File   \NC \bf Loaded     \NC \bf Loaded    \NC \bf Loaded   \NC \bf Description \NC \NR
\NC            \NC \bf by \PDFTEX \NC \bf by \XETEX \NC \bf by \MKIV \NC                 \NC \FR
\NC type-akb   \NC no             \NC no            \NC no           \NC PostScript fonts using psnfss names (Type~1)\NC \NR
\NC type-buy   \NC no             \NC no            \NC no           \NC Various commercial fonts (Type~1)\NC \NR
\NC type-cbg   \NC no             \NC no            \NC no           \NC Greek free fonts (Type~1)\NC \NR
\NC type-cow   \NC no             \NC no            \NC no           \NC The \CONTEXT\ cow font (Type~1)\NC \NR
\NC type-exp   \NC no             \NC no            \NC no           \NC Commercial Zapf fonts (OpenType)\NC \NR
\NC type-fsf   \NC no             \NC no            \NC no           \NC Commercial Fontsite 500 fonts (Type~1)\NC \NR
\NC type-ghz   \NC no             \NC no            \NC no           \NC Commercial Zapf fonts (Type~1)\NC \NR
\NC type-gyr   \NC no             \NC no            \NC no           \NC The \TeX\ Gyre project fonts (Type~1)\NC \NR
\NC type-hgz   \NC no             \NC no            \NC no           \NC Commercial Zapf fonts (OpenType)\NC \NR
\NC type-msw   \NC no             \NC no            \NC no           \NC Fonts that come with Microsoft Windows (Type~1)\NC \NR
\NC type-omg   \NC no             \NC no            \NC no           \NC Omega free fonts (Type~1)\NC \NR
\NC type-one   \NC yes            \NC no            \NC no           \NC Various free fonts (Type~1)\NC \NR
\NC type-otf   \NC no             \NC yes           \NC yes          \NC Various free fonts (OpenType)\NC \NR
\NC type-xtx   \NC no             \NC yes           \NC no           \NC Fonts that come with MacOSX (OpenType)\NC \NR
\stoptabulate
\vskip 1ex
\endgroup
\stopbuffer

\placetable
  [here]
  [tab:typescript files]
  {The typescript source files that are part of \CONTEXT.}
  {\getbuffer[typefiles]}

Explicit loading one of those files is done via the macro \type{\usetypescriptfile}.
\macro{\tex{usetypescriptfile}}

\startbuffer[typescripts]
\begingroup
\switchtobodyfont[9pt]
\def\*#1{{\bf#1}}
\vskip 1ex
\starttabulate[|l|l|l|l|]
\NC \bf Typescript        \NC \bf Typeface      \NC \bf File           \NC \bf Encodings                     \NC \FR
\NC antykwa-torunska      \NC antykwa           \NC type-one, type-otf \NC texnansi,ec,8r,t2a                \NC \NR
\NC fourier               \NC fourier           \NC type-one           \NC ec                                \NC \NR
\NC iwona                 \NC iwona             \NC type-one, type-otf \NC texnansi,ec,8r,t2a                \NC \NR
\NC iwona-heavy           \NC iwona-heavy       \NC type-one, type-otf \NC texnansi,ec,8r,t2a                \NC \NR
\NC iwona-light           \NC iwona-light       \NC type-one, type-otf \NC texnansi,ec,8r,t2a                \NC \NR
\NC iwona-medium          \NC iwona-medium      \NC type-one, type-otf \NC texnansi,ec,8r,t2a                \NC \NR
\NC modern                \NC modern            \NC type-one, type-otf \NC texnansi,ec,qx,t5,default         \NC \NR
\NC modern-base           \NC modern            \NC type-one, type-otf \NC texnansi,ec,qx,t5,default,t2a/b/c \NC \NR
\NC modernvariable        \NC modernvariable    \NC type-one, type-otf \NC texnansi,ec,qx,8r,t5              \NC \NR
\NC palatino              \NC palatino          \NC type-one, type-otf \NC texnansi,ec,qx,8r,t5              \NC \NR
\NC postscript            \NC postscript        \NC type-one, type-otf \NC texnansi,ec,qx,8r,t5              \NC \NR
\NC times                 \NC times             \NC type-one, type-otf \NC texnansi,ec,qx,8r,t5              \NC \NR
\HL
\NC OmegaLGC              \NC omlgc             \NC type-omg           \NC (unspecified)                     \NC \NR
\NC cbgreek               \NC cbgreek           \NC type-cbg           \NC (unspecified)                     \NC \NR
\NC cbgreek-all           \NC cbgreek-all       \NC type-cbg           \NC (unspecified)                     \NC \NR
\NC cbgreek-medium        \NC cbgreek-medium    \NC type-cbg           \NC (unspecified)                     \NC \NR
\NC cow                   \NC cow               \NC type-cow           \NC default                           \NC \NR
\NC sheep                 \NC sheep             \NC type-cow           \NC default                           \NC \NR
\NC \*{lucida}            \NC lucida            \NC type-buy           \NC texnansi,ec,8r                    \NC \NR
\NC \*{lucidabfm}         \NC lucida            \NC type-buy           \NC texnansi,ec,8r                    \NC \NR
\NC \*{lucidabfm}         \NC lucidabfm         \NC type-buy           \NC texnansi,ec,8r                    \NC \NR
\NC \*{lucidaboldmath}    \NC lucida            \NC type-buy           \NC texnansi,ec,8r                    \NC \NR
\NC \*{lucidaboldmath}    \NC lucidaboldmath    \NC type-buy           \NC texnansi,ec,8r                    \NC \NR
\NC \*{optima}            \NC optima            \NC type-one           \NC texnansi,ec,qx                    \NC \NR
\NC \*{optima}            \NC optima            \NC type-ghz           \NC texnansi,ec,qx                    \NC \NR
\NC \*{optima-nova}       \NC optima            \NC type-ghz, type-hgz \NC texnansi,ec                       \NC \NR
\NC \*{optima-nova-os}    \NC optima-os         \NC type-ghz, type-hgz \NC texnansi,ec                       \NC \NR
\NC \*{palatino}          \NC palatino          \NC type-hgz           \NC (cannot be used in \MKII)         \NC \NR
\NC \*{palatino-informal} \NC palatino-informal \NC type-hgz           \NC (cannot be used in \MKII)         \NC \NR
\NC \*{palatino-light}    \NC palatino-light    \NC type-exp           \NC (cannot be used in \MKII)         \NC \NR
\NC \*{palatino-medium}   \NC palatino-medium   \NC type-exp           \NC (cannot be used in \MKII)         \NC \NR
\NC \*{palatino-normal}   \NC palatino-normal   \NC type-exp           \NC (cannot be used in \MKII)         \NC \NR
\NC \*{palatino-nova}     \NC palatino          \NC type-hgz           \NC (cannot be used in \MKII)         \NC \NR
\NC \*{palatino-sans}     \NC palatino          \NC type-hgz           \NC (cannot be used in \MKII)         \NC \NR
\stoptabulate
\vskip 1ex
\endgroup
\stopbuffer

\placetable
  [here]
  [tab:typescripts and typefaces]
  {The typescripts. Typescripts that use commercial fonts are typeset in bold. Typescripts above the horizontal line are preloaded.}
  {\getbuffer[typescripts]}

The predefined typescripts, the typefaces they define, the files
in which they are contained in the \CONTEXT\ distribution, and the
encodings they support in \MKII\ mode are listed in~\in {table}
[tab:typescripts and typefaces]. In the following section there is a 
table (\in {}[tab:typeface names]) that explains 
what font set each typescript attaches to each of the font styles.

\showsetup{usetypescriptfile}

For example, the following 

\startexample
\starttyping
\usetypescriptfile[type-buy]
\usetypescript[lucida][texnansi]
\setupbodyfont[lucida,12pt]
\stoptyping
\stopexample

will make \PDFTEX\ use the Lucida Bright font family. Because this is a commercial 
font, this only works correctly if you have actually bought and installed the fonts. 
This uses the \type{texnansi} encoding because that is the preferred encoding of the 
actual fonts.

This is a good moment to explain a little trick: because the various \type{type-xxx}
files define the building blocks for typescripts as well as the actual typescripts, 
it is sometimes possible to alter the effect of a typescript by
loading an extra typescript file. For example,

\starttyping
\usetypescriptfile[type-gyr]
\usetypescript[palatino][ec]
\setupbodyfont[palatino,12pt]
\stoptyping

will result in \PDFTEX\ using the Type~1 font Pagella from the \TeX\ Gyre project instead 
of the older and less complete URW Palladio, because the definition of the building blocks
for the \type{palatino} typescript that is in the \type{type-gyr} file overwrites the 
preloaded definition from the \type{type-one} file.

Two of the files in the \CONTEXT\ distribution exist precisely for this reason: 
\startitemize[packed]
\sym {\type{type-gyr.tex}} 

maps the typical PostScript font names for the free URW fonts 
to the \TeX\ Gyre set;
\sym {\type{type-akb.tex}} 

maps the same names to the commercial Adobe fonts. 
\stopitemize
For the definitions in the second file to work, you also need to execute an extra typescript:

\startexample
\starttyping
\usetypescriptfile [type-akb]
\usetypescript [adobekb] [ec]

\usetypescript [palatino] [ec]
\setupbodyfont[palatino,12pt]
\stoptyping
\stopexample

\subsection{Typeface definitions}

\macro{\tex{starttypescript}}
\macro{\tex{definetypeface}}

Defining a typeface goes like this:

\startexample
\starttyping
\starttypescript [palatino] [texnansi,ec,qx,t5,default]

\definetypeface[palatino] [rm] [serif][palatino] [default]
\definetypeface[palatino] [ss] [sans] [modern]   [default] [rscale=1.075]
\definetypeface[palatino] [tt] [mono] [modern]   [default] [rscale=1.075]
\definetypeface[palatino] [mm] [math] [palatino] [default]

\stoptypescript
\stoptyping
\stopexample

This defines a typescript named \type{palatino} in five different encodings.
When this typescript is executed via \type{\usetypescript}, it will define
four typefaces, one of each of the four basic styles \type{rm}, \type{ss}, \type{tt}, and \type{mm}. 

\showsetup{definetypeface} % empty at the moment

The third and fourth arguments to \type{\definetypeface} are pointers to already
declared font sets; these are defined elsewhere. \in{Table}[tab:typeface names] 
gives the full list of predefined typescripts (the first argument of \type{\starttypescript}) 
and font sets  that are attached to the styles (the third and fourth argument of 
each \type{\definetypeface}). 

The names in the third argument (like \type{serif} and \type{sans}) do {\em not\/} have the
same meaning as the names used in \type{\setupbodyfont}. Inside \type{\setupbodyfont}, they
were keywords that were internally remapped to one of the two-letter internal styles. Inside
\type{\definetypeface}, they are nothing more than convenience names that are  attached to a 
group of fonts by the person that wrote the font definition. They only reflect a grouping
that the person believed that could be a single font style.  Oftentimes, these names are
identical to the official style keywords, just as the typescript and typeface names are often 
the same, but there can be (and sometimes are) different names altogether.

\startbuffer[simpletypescripts]
\vskip 1ex
\begingroup
\switchtobodyfont[9pt]
\starttabulate[|l||l|l|l|l|]
\NC {\bf Typescript  }\NC {\bf Style rm    }  \NC {\bf Style ss }      \NC {\bf Style tt}     \NC  {\bf Style mm }  \NC \FR
\NC OmegaLGC          \NC omega               \NC --                   \NC omega              \NC --                \NC \NR
\NC antykwa-torunska  \NC antykwa-torunska    \NC modern               \NC modern             \NC antykwa-torunska  \NC \NR
\NC cbgreek           \NC cbgreek             \NC cbgreek              \NC cbgreek            \NC --                \NC \NR
\NC cbgreek-all       \NC cbgreek             \NC cbgreek              \NC cbgreek            \NC --                \NC \NR
\NC cbgreek-medium    \NC cbgreek             \NC cbgreek              \NC cbgreek            \NC --                \NC \NR
\NC cow               \NC cow                 \NC cow serif            \NC modern             \NC cow               \NC \NR
\NC fallback          \NC modern              \NC modern               \NC modern             \NC modern            \NC \NR
\NC fourier           \NC fourier             \NC modern               \NC modern             \NC fourier           \NC \NR
\NC iwona             \NC modern              \NC iwona                \NC modern             \NC iwona             \NC \NR
\NC iwona-heavy       \NC modern              \NC iwona-heavy          \NC modern             \NC iwona-heavy       \NC \NR
\NC iwona-light       \NC modern              \NC iwona-light          \NC modern             \NC iwona-light       \NC \NR
\NC iwona-medium      \NC modern              \NC iwona-medium         \NC modern             \NC iwona-medium      \NC \NR
\NC lucida            \NC lucida              \NC lucida               \NC lucida             \NC lucida            \NC \NR
\NC lucidabfm         \NC lucida              \NC lucida               \NC lucida             \NC lucida bfmath     \NC \NR
\NC lucidaboldmath    \NC lucida              \NC lucida               \NC lucida             \NC lucida boldmath   \NC \NR
\NC modern            \NC modern              \NC modern               \NC modern             \NC modern            \NC \NR
\NC modern-base       \NC (computer-)modern   \NC (computer-)modern    \NC (computer-)modern  \NC (computer-)modern \NC \NR
\NC modernvariable    \NC simple              \NC modern               \NC modern             \NC modern            \NC \NR
\NC optima            \NC palatino            \NC optima-nova          \NC modern             \NC palatino          \NC \NR
\NC optima-nova       \NC optima-nova sans    \NC optima-nova          \NC latin-modern       \NC latin-modern      \NC \NR
\NC optima-nova-os    \NC optima-nova-os sans \NC optima-nova-os       \NC latin-modern       \NC latin-modern      \NC \NR
\NC palatino          \NC palatino-nova       \NC palatino-sans        \NC latin-modern       \NC latin-modern      \NC \NR
\NC palatino          \NC palatino            \NC modern               \NC modern             \NC palatino          \NC \NR
\NC palatino-informal \NC palatino-nova       \NC palatino-informal    \NC latin-modern       \NC latin-modern      \NC \NR
\NC palatino-light    \NC palatino-nova       \NC palatino-sans-light  \NC latin-modern       \NC latin-modern      \NC \NR
\NC palatino-medium   \NC palatino-nova       \NC palatino-sans-medium \NC latin-modern       \NC latin-modern      \NC \NR
\NC palatino-normal   \NC palatino-nova       \NC palatino-sans-normal \NC latin-modern       \NC latin-modern      \NC \NR
\NC palatino-nova     \NC palatino-nova       \NC palatino-sans        \NC latin-modern       \NC latin-modern      \NC \NR
\NC palatino-sans     \NC palatino-nova       \NC palatino-sans        \NC latin-modern       \NC latin-modern      \NC \NR
\NC postscript        \NC times               \NC helvetica            \NC courier            \NC times             \NC \NR
\NC sheep             \NC sheep               \NC sheep serif          \NC modern             \NC sheep             \NC \NR
\NC times             \NC times               \NC helvetica            \NC modern             \NC times             \NC \NR
\stoptabulate
\endgroup
\vskip 1ex
\stopbuffer

\placetable
  [here]
  [tab:typeface names]
  {The typescripts.\crlf 
   Unless stated otherwise, style {\bf rm} uses a group named serif, style {\bf ss} uses sans, style {\bf tt} uses
   mono, and style {\bf mm} uses math.
   A single dash in a cell means that the typescript does not define that style; you should refrain from using the style.
   The lucida, lucidabfm, and lucidaboldmath typescripts also define {\bf hw} and {\bf cg} as \quote{lucida handwring} 
   and \quote{lucida calligraphy}.
   The modern-base typescript switches back to computer-modern for a few legacy encodings: t2a, t2b, and t2c.}
  {\getbuffer[simpletypescripts]}

How to define your own font sets will be explained in the next chapter,
but there are quite a few predefined font sets that come with \CONTEXT;
these are all listed in the four tables~\in{}[tab:body font names 1],
\in{}[tab:body font names 2], \in{}[tab:body font names 3], 
and \in{}[tab:body font names 4]. 

For everything to work properly in \MKII, the predefined font sets also have to have an
encoding attached, you can look those up in the relevant tables as well. 

The fifth argument to \type{\definetypeface} specifies specific font size setups (if any), 
these will be covered in~\in{section}[typefacesizes] in the next chapter. Almost always,
specifying \type{default} will suffice.

\startbuffer[bodyfontst1free]
\switchtobodyfont[9pt]
\starttabulate[|l|l|l|p(3.5cm)|]
\NC \bf Identifier             \NC \bf file  \NC \bf Encodings               \NC \bf Supported styles \NC \FR
\NC modern                     \NC type-one  \NC ec, qx, texnansi, t5        \NC serif, sans, mono, math, \crlf
                                                                                 boldmath, bfmath \NC \NR 
\NC latin-modern               \NC type-one  \NC ec, qx, texnansi, t5        \NC serif, sans, mono, math, \crlf 
                                                                                 boldmath, bfmath \NC \NR 
\NC computer-modern            \NC type-one  \NC t2a/b/c                     \NC serif, sans, mono, math, \crlf %removed lcy,cyr,x2
                                                                                 boldmath, bfmath \NC \NR 
\NC simple                     \NC type-one  \NC -- synonyms only --         \NC serif \NC \NR 
\NC concrete                   \NC type-one  \NC -- hardcoded --             \NC serif \NC \NR
\NC euler                      \NC type-one  \NC -- hardcoded --             \NC math, boldmath, bfmath\NC \NR
\NC ams                        \NC type-one  \NC -- hardcoded --             \NC math\NC \NR
\NC fourier                    \NC type-one  \NC ec                          \NC math, serif \NC \NR
\NC courier                    \NC type-one  \NC 8r, ec, qx, texnansi, t5    \NC mono \NC \NR
\NC helvetica                  \NC type-one  \NC 8r, ec, qx, texnansi, t5    \NC sans \NC \NR
\NC times                      \NC type-one  \NC 8r, ec, qx, texnansi, t5    \NC serif, math \NC \NR
\NC palatino                   \NC type-one  \NC 8r, ec, qx, texnansi, t5    \NC serif, math \NC \NR
\NC bookman                    \NC type-one  \NC 8r, ec, qx, texnansi, t5    \NC serif \NC \NR
\NC schoolbook                 \NC type-one  \NC 8r, ec, texnansi, t5        \NC serif \NC \NR
\NC chancery                   \NC type-one  \NC 8r, ec, qx, texnansi        \NC calligraphy \NC \NR
\NC charter                    \NC type-one  \NC 8r, ec, texnansi            \NC serif \NC \NR
\NC utopia                     \NC type-one  \NC ec, texnansi                \NC serif \NC \NR
\NC antykwa-torunska           \NC type-one  \NC ec, qx, texnansi, t5, t2a/b/c, greek \NC serif, math \NR
\NC antykwa-torunska-light     \NC type-one  \NC ec, qx, texnansi, t5, t2a/b/c, greek \NC serif, math \NR
\NC antykwa-torunska-cond      \NC type-one  \NC ec, qx, texnansi, t5, t2a/b/c, greek \NC serif, math \NR
\NC antykwa-torunska-lightcond \NC type-one  \NC ec, qx, texnansi, t5, t2a/b/c, greek \NC serif, math \NR
\NC antykwa-poltawskiego       \NC type-one  \NC 8r, ec, texnansi                   \NC serif \NR
\NC iwona                      \NC type-one  \NC ec, qx, texnansi, t5               \NC sans, math \NC \NR
\NC iwona-light                \NC type-one  \NC ec, qx, texnansi, t5               \NC sans, math \NC \NR
\NC iwona-medium               \NC type-one  \NC ec, qx, texnansi, t5               \NC sans, math \NC \NR
\NC iwona-heavy                \NC type-one  \NC ec, qx, texnansi, t5               \NC sans, math \NC \NR
\NC iwona-cond                 \NC type-one  \NC ec, qx, texnansi, t5               \NC sans \NC \NR
\NC iwona-light-cond           \NC type-one  \NC ec, qx, texnansi, t5               \NC sans \NC \NR
\NC iwona-medium-cond          \NC type-one  \NC ec, qx, texnansi, t5               \NC sans \NC \NR
\NC iwona-heavy-cond           \NC type-one  \NC ec, qx, texnansi, t5               \NC sans \NC \NR
\NC kurier                     \NC type-one  \NC ec, qx, texnansi, t5               \NC sans, math \NC \NR
\NC kurier-light               \NC type-one  \NC ec, qx, texnansi, t5               \NC sans, math \NC \NR
\NC kurier-medium              \NC type-one  \NC ec, qx, texnansi, t5               \NC sans, math \NC \NR
\NC pagella                    \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC serif\NC \NR % removed encs: rm,el, ec, cs, l7x
\NC palatino                   \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC serif\NC \NR
\NC termes                     \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC serif\NC \NR
\NC times                      \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC serif\NC \NR
\NC bonum                      \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC serif\NC \NR
\NC bookman                    \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC serif\NC \NR
\NC schola                     \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC serif\NC \NR
\NC schoolbook                 \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC serif\NC \NR
\NC heros                      \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC sans\NC \NR
\NC helvetica                  \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC sans\NC \NR
\NC adventor                   \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC sans\NC \NR
\NC cursor                     \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC mono\NC \NR
\NC courier                    \NC type-gyr  \NC ec, qx, texnansi, t5, t2a/b/c      \NC mono\NC \NR
\NC omega                      \NC type-omg  \NC -- hardcoded --                    \NC naskh, serif, mono\NC \NR
\NC cbgreek                    \NC type-cbg  \NC -- hardcoded --                    \NC serif, sans, mono \NC \NR
\NC cbgreek-medium             \NC type-cbg  \NC -- hardcoded --                    \NC serif, sans, mono \NC \NR
\NC cbgreek-all                \NC type-cbg  \NC -- hardcoded --                    \NC serif, sans, mono \NC \NR
\NC cow                        \NC type-cow  \NC -- hardcoded --                    \NC math, serif \NC \NR
\NC sheep                      \NC type-cow  \NC -- hardcoded --                    \NC math, serif \NC \NR

\stoptabulate
\stopbuffer

%\NC Identifier           \NC Needed font package              
%\NC modern               \NC Latin Modern              \NC \NR 
%\NC latin-modern         \NC Latin Modern              \NC \NR 
%\NC computer-modern      \NC Latin Modern              \NC \NR 
%\NC simple               \NC Latin Modern              \NC \NR 
%\NC concrete             \NC -- MF bitmaps --          \NC \NR
%\NC euler                \NC Euler                     \NC \NR
%\NC ams                  \NC AMS Symbols               \NC \NR
%\NC fourier              \NC Fourier                   \NC \NR
%\NC courier              \NC URW PostScript (or Adobe) \NC \NR
%\NC helvetica            \NC URW PostScript (or Adobe) \NC \NR
%\NC times                \NC URW PostScript (or Adobe) \NC \NR
%\NC palatino             \NC URW PostScript (or Adobe) \NC \NR
%\NC bookman              \NC URW PostScript (or Adobe) \NC \NR
%\NC schoolbook           \NC URW PostScript (or Adobe) \NC \NR
%\NC chancery             \NC URW PostScript (or Adobe) \NC \NR
%\NC charter              \NC Bitstream Charter         \NC \NR
%\NC utopia               \NC Adobe Utopia              \NC \NR
%\NC antykwa-torunska-xx  \NC Antykwa Torunska          \NC \NR
%\NC antykwa-poltawskiego \NC Antykwa Poltawskiego      \NC \NR
%\NC iwona-xx             \NC Iwona                     \NC \NR
%\NC kurier-xx            \NC Kurier                    \NC \NR
%\NC pagella              \NC TeX Gyre                  \NC \NR
%\NC palatino             \NC TeX Gyre                  \NC \NR
%\NC termes               \NC TeX Gyre                  \NC \NR
%\NC times                \NC TeX Gyre                  \NC \NR
%\NC bonum                \NC TeX Gyre                  \NC \NR
%\NC bookman              \NC TeX Gyre                  \NC \NR
%\NC schola               \NC TeX Gyre                  \NC \NR
%\NC schoolbook           \NC TeX Gyre                  \NC \NR
%\NC heros                \NC TeX Gyre                  \NC \NR
%\NC helvetica            \NC TeX Gyre                  \NC \NR
%\NC adventor             \NC TeX Gyre                  \NC \NR
%\NC cursor               \NC TeX Gyre                  \NC \NR
%\NC courier              \NC TeX Gyre                  \NC \NR
%\NC omega                \NC Omega fonts               \NC \NR
%\NC cbgreek-xx           \NC cbgreek                   \NC \NR
%\NC cow                  \NC \CONTEXT\ cow font        \NC \NR
%\NC sheep                \NC \CONTEXT\ cow font        \NC \NR


\startbuffer[bodyfontst1buy]
\switchtobodyfont[9pt]
\starttabulate[|l|l|l|p(4.5cm)|]
\NC \bf Identifier       \NC \bf file  \NC \bf Encodings      \NC \bf Supported styles \NC \FR
\NC lucida               \NC type-buy  \NC 8r, ec, texnansi   \NC serif, sans, mono, handwriting,\crlf 
                                                                  calligraphy, math, boldmath, \crlf
                                                                  bfmath, casual, fax \NC \NR
\NC informal             \NC type-buy \NC -- hardcoded --     \NC casual, math\NC \NR
\NC officina             \NC type-buy \NC 8r, ec, texnansi    \NC serif, sans\NC \NR
\NC meta                 \NC type-buy \NC 8r, ec, texnansi    \NC serif, sans, expert \NC \NR
\NC meta-medium          \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC meta-lf              \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC meta-book            \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC meta-book-lf         \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC meta-bold            \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC meta-bold-lf         \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC meta-normal          \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC meta-normal-lf       \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC meta-medium          \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC meta-medium-lf       \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC meta-black           \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC meta-black-lf        \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC univers              \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC univers-light        \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC univers-black        \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC mendoza              \NC type-buy \NC 8r, ec, texnansi    \NC serif \NC \NR
\NC frutiger             \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC kabel                \NC type-buy \NC 8r, ec, texnansi    \NC sans \NC \NR
\NC thesans              \NC type-buy \NC 8r, ec, texnansi    \NC sans, mono, expert \NC \NR
\NC sabon                \NC type-buy \NC 8r, ec, texnansi    \NC serif \NC \NR
\NC stone                \NC type-buy \NC ec, texnansi        \NC serif, sans \NC \NR
\NC stone-oldstyle       \NC type-buy \NC -- synonyms only -- \NC serif, sans \NC \NR
\NC industria            \NC type-buy \NC ec, texnansi        \NC sans \NC \NR
\NC bauhaus              \NC type-buy \NC ec, texnansi        \NC sans \NC \NR
\NC swift                \NC type-buy \NC ec, texnansi        \NC serif \NC \NR
\NC swift-light          \NC type-buy \NC -- synonyms only -- \NC serif \NC \NR
\NC syntax               \NC type-buy \NC ec, texnansi        \NC sans \NC \NR
\NC linoletter           \NC type-buy \NC ec, texnansi        \NC serif \NC \NR
\NC zapfino              \NC type-ghz \NC 8r, ec, texnansi    \NC serif, handwriting\NC \NR
\NC palatino-sans-light  \NC type-exp \NC texnansi, ec        \NC sans\NC \NR
\NC palatino-sans-normal \NC type-exp \NC texnansi, ec        \NC sans\NC \NR
\NC palatino-sans-medium \NC type-exp \NC texnansi, ec        \NC sans\NC \NR
\NC opus                 \NC type-fsf \NC 8r, ec, texnansi    \NC sans\NC \NR
\NC typewriter           \NC type-fsf \NC 8r, ec, texnansi    \NC mono\NC \NR
\NC garamond             \NC type-fsf \NC 8r, ec, texnansi    \NC serif\NC \NR
\NC optima               \NC type-ghz \NC 8r, ec, texnansi    \NC sans\NC \NR
\NC optima-nova          \NC type-ghz \NC 8r, ec, texnansi    \NC sans\NC \NR
\NC optima-nova-os       \NC type-ghz \NC 8r, ec, texnansi    \NC sans\NC \NR
\NC optima-nova-light    \NC type-ghz \NC 8r, ec, texnansi    \NC sans\NC \NR
\NC optima-nova-medium   \NC type-ghz \NC 8r, ec, texnansi    \NC sans\NC \NR
\NC palatino             \NC type-ghz \NC 8r, ec, texnansi    \NC serif\NC \NR
\NC palatino-nova        \NC type-ghz \NC 8r, ec, texnansi    \NC serif\NC \NR
\NC palatino-nova-os     \NC type-ghz \NC 8r, ec, texnansi    \NC serif\NC \NR
\NC palatino-nova-light  \NC type-ghz \NC 8r, ec, texnansi    \NC serif\NC \NR
\NC palatino-nova-medium \NC type-ghz \NC 8r, ec, texnansi    \NC serif\NC \NR
\NC aldus-nova           \NC type-ghz \NC 8r, ec, texnansi    \NC serif\NC \NR
\NC melior               \NC type-ghz \NC 8r, ec, texnansi    \NC serif\NC \NR
\NC verdana              \NC type-msw \NC texnansi            \NC sans\NC \NR
\NC arial                \NC type-msw \NC texnansi            \NC sans\NC \NR
\stoptabulate									         
\stopbuffer									         

%\NC Identifier           \NC Needed font package    \NC \NR
%\NC lucida               \NC Lucida (Y\&Y, TUG)     \NC \NR
%\NC informal             \NC Micropress Informal    \NC \NR
%\NC officina             \NC ITC Officina           \NC \NR
%\NC meta-xx              \NC FF Meta                \NC \NR
%\NC univers-xx           \NC Linotype Univers       \NC \NR
%\NC mendoza              \NC Mendoza                \NC \NR
%\NC frutiger             \NC Frutiger               \NC \NR
%\NC kabel                \NC ITC Kabel              \NC \NR
%\NC thesans              \NC FF The Sans            \NC \NR
%\NC sabon                \NC Monotype Sabon         \NC \NR
%\NC stone-xx             \NC ITC Stone              \NC \NR
%\NC industria            \NC Linotype Industria     \NC \NR
%\NC bauhaus              \NC ITC Bauhaus            \NC \NR
%\NC swift                \NC EF Swift               \NC \NR
%\NC swift-light          \NC EF Swift               \NC \NR
%\NC syntax               \NC Linotype Syntax        \NC \NR
%\NC linoletter           \NC Linotype Linoletter    \NC \NR
%\NC zapfino              \NC ZapfinoT1              \NC \NR
%\NC palatino-sans-xx     \NC Palatino Sans Nova T1  \NC \NR
%\NC opus                 \NC Fontsite 500 Opus      \NC \NR
%\NC typewriter           \NC Fontsite 500 Typewriter\NC \NR
%\NC garamond             \NC Fontsite 500 Garamond  \NC \NR
%\NC optima-xx            \NC Optima Nova T1         \NC \NR
%\NC palatino-xx          \NC Palatino Nova T1       \NC \NR
%\NC aldus-nova           \NC Aldus Nova T1          \NC \NR
%\NC melior               \NC Melior T1              \NC \NR
%\NC verdana              \NC Microsoft Windows      \NC \NR
%\NC arial                \NC Microsoft Windows      \NC \NR


\startbuffer[bodyfontsotffree]
\startsimplecolumns
\switchtobodyfont[9pt]
\starttabulate[|l|l|p|]
\NC \bf Identifier             \NC \bf file \NC \bf Supported styles \NC \FR
\NC modern                     \NC type-otf \NC serif, sans, mono, math, boldmath, bfmath \NC \NR 
\NC latin-modern               \NC type-otf \NC serif, sans, mono, math, boldmath, bfmath \NC \NR 
\NC modern-vari                \NC type-otf \NC mono \NC \NR 
\NC latin-modern-vari          \NC type-otf \NC mono \NC \NR 
\NC modern-cond                \NC type-otf \NC mono \NC \NR 
\NC latin-modern-cond          \NC type-otf \NC mono \NC \NR 
\NC computer-modern            \NC type-otf \NC serif, sans, mono, math, boldmath, bfmath \NC \NR 
\NC concrete                   \NC type-otf \NC serif \NC \NR
\NC euler                      \NC type-otf \NC math, boldmath, bfmath\NC \NR
\NC ams                        \NC type-otf \NC math \NC \NR
\NC pagella                    \NC type-otf \NC serif \NC \NR
\NC termes                     \NC type-otf \NC serif \NC \NR
\NC bonum                      \NC type-otf \NC serif \NC \NR
\NC schola                     \NC type-otf \NC serif \NC \NR
\NC chorus                     \NC type-otf \NC serif \NC \NR
\NC heros                      \NC type-otf \NC sans \NC \NR
\NC adventor                   \NC type-otf \NC sans \NC \NR
\NC \rlap{cursor}\hphantom{antykwa-torunska-lightcond}\NC type-otf \NC sans \NC \NR
\stoptabulate
\starttabulate[|l|l|p|]
\NC \bf Identifier             \NC \bf file \NC \bf Supported styles \NC \FR
\NC palatino                   \NC type-otf \NC serif, math \NC \NR
\NC times                      \NC type-otf \NC serif, math \NC \NR
\NC bookman                    \NC type-otf \NC serif \NC \NR
\NC schoolbook                 \NC type-otf \NC serif \NC \NR
\NC chancery                   \NC type-otf \NC calligraphy \NC \NR
\NC helvetica                  \NC type-otf \NC sans \NC \NR
\NC courier                    \NC type-otf \NC mono \NC \NR
\NC antykwa-torunska           \NC type-otf \NC serif, math \NC \NR
\NC antykwa-torunska-light     \NC type-otf \NC serif, math \NC \NR
\NC antykwa-torunska-cond      \NC type-otf \NC serif, math \NC \NR
\NC antykwa-torunska-lightcond \NC type-otf \NC serif, math \NC \NR
\NC antykwa-poltawskiego       \NC type-otf \NC serif \NC \NR
\NC iwona-light                \NC type-otf \NC sans, math \NC \NR
\NC iwona                      \NC type-otf \NC sans, math \NC \NR
\NC iwona-medium               \NC type-otf \NC sans, math \NC \NR
\NC iwona-heavy                \NC type-otf \NC sans, math \NC \NR
\NC iwona-cond                 \NC type-otf \NC sans \NC \NR
\NC iwona-light-cond           \NC type-otf \NC sans \NC \NR
\NC iwona-medium-cond          \NC type-otf \NC sans \NC \NR
\NC iwona-heavy-cond           \NC type-otf \NC sans \NC \NR
\NC kurier                     \NC type-otf \NC sans, math \NC \NR
\NC kurier-light               \NC type-otf \NC sans, math \NC \NR
\NC kurier-medium              \NC type-otf \NC sans, math \NC \NR
\NC charter                    \NC type-otf \NC serif \NC \NR
\NC gentium                    \NC type-xtx \NC serif \NC \NR
\stoptabulate
\stopsimplecolumns
\stopbuffer

%\NC Identifier                 \NC Needed font package    \NC \NR
%\NC modern                     \NC Latin Modern           \NC \NR
%\NC latin-modern               \NC Latin Modern           \NC \NR
%\NC modern-vari                \NC Latin Modern           \NC \NR
%\NC latin-modern-vari          \NC Latin Modern           \NC \NR
%\NC modern-cond                \NC Latin Modern           \NC \NR
%\NC latin-modern-cond          \NC Latin Modern           \NC \NR
%\NC computer-modern            \NC Latin Modern           \NC \NR
%\NC concrete                   \NC -- MF bitmaps --       \NC \NR
%\NC euler                      \NC Euler                  \NC \NR
%\NC ams                        \NC AMS                    \NC \NR
%\NC pagella                    \NC TeX Gyre               \NC \NR
%\NC termes                     \NC TeX Gyre               \NC \NR
%\NC bonum                      \NC TeX Gyre               \NC \NR
%\NC schola                     \NC TeX Gyre               \NC \NR
%\NC chorus                     \NC TeX Gyre               \NC \NR
%\NC heros                      \NC TeX Gyre               \NC \NR
%\NC adventor                   \NC TeX Gyre               \NC \NR
%\NC cursor                     \NC TeX Gyre               \NC \NR
%\NC palatino                   \NC TeX Gyre               \NC \NR
%\NC times                      \NC TeX Gyre               \NC \NR
%\NC bookman                    \NC TeX Gyre               \NC \NR
%\NC schoolbook                 \NC TeX Gyre               \NC \NR
%\NC chancery                   \NC TeX Gyre               \NC \NR
%\NC helvetica                  \NC TeX Gyre               \NC \NR
%\NC courier                    \NC TeX Gyre               \NC \NR
%\NC antykwa-torunska           \NC Antykwa Torunska       \NC \NR
%\NC antykwa-torunska-light     \NC Antykwa Torunska       \NC \NR
%\NC antykwa-torunska-cond      \NC Antykwa Torunska       \NC \NR
%\NC antykwa-torunska-lightcond \NC Antykwa Torunska       \NC \NR
%\NC antykwa-poltawskiego       \NC Antykwa Poltawskiego   \NC \NR
%\NC iwona-xx                   \NC Iwona                  \NC \NR
%\NC kurier-xx                  \NC Kurier                 \NC \NR
%\NC charter                    \NC Bitstream Charter      \NC \NR
%\NC gentium                    \NC SIL Gentium            \NC \NR

\startbuffer[bodyfontsotfbuy]
\startsimplecolumns
\switchtobodyfont[9pt]
\starttabulate[|l|l|l|]
\NC \bf Identifier                 \NC \bf file \NC \bf Supported styles \NC \FR
\NC zapfino                        \NC type-hgz \NC serif, handwriting\NC \NR
\NC optima-nova                    \NC type-hgz \NC sans\NC \NR
\NC optima-nova-os                 \NC type-hgz \NC sans\NC \NR
\NC optima-nova-light              \NC type-hgz \NC sans\NC \NR
\NC optima-nova-medium             \NC type-hgz \NC sans\NC \NR
\NC palatino-nova                  \NC type-hgz \NC serif\NC \NR
\NC palatino-nova-os               \NC type-hgz \NC serif\NC \NR
\NC palatino-nova-light            \NC type-hgz \NC serif\NC \NR
\NC palatino-nova-medium           \NC type-hgz \NC serif\NC \NR
\NC palatino-sans                  \NC type-hgz \NC sans\NC \NR
\NC palatino-informal              \NC type-hgz \NC sans\NC \NR
\NC melior                         \NC type-hgz \NC serif\NC \NR
\NC -- all four-variant fonts --   \NC type-xtx \NC Xserif \NC \NR
\NC -- all four-variant fonts --   \NC type-xtx \NC Xsans \NC \NR
\NC -- all four-variant fonts --   \NC type-xtx \NC Xmono \NC \NR
\stoptabulate
\starttabulate[|l|l|l|]
\NC \bf Identifier                 \NC \bf file \NC \bf Supported styles \NC \FR
\NC \rlap{times}\hphantom{-- all four-variant fonts --}\NC type-xtx \NC serif \NC \NR
\NC palatino                       \NC type-xtx \NC serif \NC \NR
\NC helvetica                      \NC type-xtx \NC sans \NC \NR
\NC courier                        \NC type-xtx \NC mono \NC \NR
\NC hoefler                        \NC type-xtx \NC serif \NC \NR
\NC lucidagrande                   \NC type-xtx \NC sans \NC \NR
\NC optima                         \NC type-xtx \NC sans \NC \NR
\NC gillsans                       \NC type-xtx \NC sans \NC \NR
\NC gillsanslt                     \NC type-xtx \NC sans \NC \NR
\NC zapfino                        \NC type-xtx \NC handwriting, serif \NC \NR
\NC applechancery                  \NC type-xtx \NC calligraphy, serif \NC \NR
\NC timesnewroman                  \NC type-xtx \NC serif \NC \NR
\NC arial                          \NC type-xtx \NC sans \NC \NR
\NC lucida                         \NC type-xtx \NC serif, sans, mono,\NC \NR
\NC                                \NC          \NC handwriting, fax, \NC \NR
\NC                                \NC          \NC calligraphy       \NC \NR
\stoptabulate
\stopsimplecolumns
\stopbuffer

%\NC Identifier                 \NC Needed font package    \NC \NR
%\NC zapfino                    \NC Zapfino Pro OTF        \NC \NR
%\NC optima-nova-xx             \NC Optima Nova OTF        \NC \NR
%\NC palatino-nova-xx           \NC Palatino Nova OTF      \NC \NR
%\NC melior                     \NC Melior OTF             \NC \NR
%\NC times                      \NC MacOSX                 \NC \NR
%\NC palatino                   \NC MacOSX (Book Antiqua)  \NC \NR
%\NC helvetica                  \NC MacOSX (Helvetica Neue)\NC \NR
%\NC courier                    \NC MacOSX                 \NC \NR
%\NC hoefler                    \NC MacOSX                 \NC \NR
%\NC lucidagrande               \NC MacOSX                 \NC \NR
%\NC optima                     \NC MacOSX                 \NC \NR
%\NC gillsans                   \NC MacOSX                 \NC \NR
%\NC gillsanslt                 \NC MacOSX                 \NC \NR
%\NC zapfino                    \NC MacOSX                 \NC \NR
%\NC applechancery              \NC MacOSX                 \NC \NR
%\NC timesnewroman              \NC MS Office              \NC \NR
%\NC arial                      \NC MS Office              \NC \NR
%\NC lucida                     \NC MS Office              \NC \NR

\placetable
  [here]
  [tab:body font names 1]
  {The predefined body font identifiers for free Type~1 and \METAFONT\ fonts}
  {\getbuffer[bodyfontst1free]}


\placetable
  [here]
  [tab:body font names 2]
  {The predefined body font identifiers for commercial Type~1 fonts}
  {\getbuffer[bodyfontst1buy]}

\placetable
  [here]
  [tab:body font names 3]
  {The predefined body font identifiers for free Opentype fonts}
  {\getbuffer[bodyfontsotffree]}


\placetable
  [here]
  [tab:body font names 4]
  {The predefined body font identifiers for commercial Opentype fonts}
  {\getbuffer[bodyfontsotfbuy]}

The optional sixth argument is used for tweaking font settings like the specification of
font features or adjusting parameters. In this case, the two \type{modern} font sets are
loaded with a small magnification, this evens out the visual heights of the font styles.

A note for the lazy: if the sixth argument is not given and the fifth argument happens
to be \type{default}, then the fifth argument can be omitted as well.

\startbuffer
\starttabulate[|lT|l|p|]
\NC \rm\bf key \NC \bf default value        \NC explanation                             \NC \FR
\NC rscale   \NC 1                       \NC a scaling factor for this typescript
                                             relative to the selected body font size \NC \NR
\NC encoding \NC \type{\defaultencoding} \NC the encoding for the typeface, normally
                                             inherited from the typescript
                                             automatically                           \NC \NR
\NC features \NC                         \NC this applies a predefined font feature set 
                                             (see~\in{section}[sec:font features])   \NC \NR
\NC text     \NC                         \NC sets up the forced math text style      \NC \NR
\stoptabulate 
\stopbuffer

There are four possible keys in the sixth argument:

\getbuffer

If you look closely, in~\in{table}[tab:body font names 4] you will
notice three very special items: \type{Xserif}, \type{Xsans} and
\type{Xmono}. These belong to a special \XETEX-only trick called
\quote{wildcard typescripts}.

\XETEX\ offers some nice features in terms of automatically finding 
related fonts in a family, namely the italic, bold, and
bolditalic alternatives. To take advantage of that, there's a set of
wildcard typescripts that take an arbitrary Macintosh font name as
input, and provide as many of the alternatives it can find. To set
these typescripts (and the calling conventions) apart from the
familiar ones, the typescripts are identified with \type{Xserif},
\type{Xsans}, and \type{Xmono}.

To call these special typescripts, it's most convenient to define a
typeface that uses these features. The named font slot should contain
the display name of the Regular alternative (not the family name) of
the font in question.  For example, you could have the following mix:

\startexample
\starttyping
\starttypescript[myface]
\definetypeface[myface][rm][Xserif][Baskerville]   [default]
\definetypeface[myface][tt][Xmono] [Courier]       [default][rscale=.87]
\definetypeface[myface][ss][Xsans] [Optima Regular][default]
\stoptypescript
\stoptyping
\stopexample

As you can see, you can activate relative scaling of face sizes. The above definitions look very much like any other typeface
definition, except that the serif/sans/mono identifier is preceded with X, and that there is no underlying "Optima Regular" defined
anywhere. Those missing bits of the definitions are handled by typescript and \XETEX\ magic.

\section[sec:body font environment]{Body font environments}

\macro{\tex{setupbodyfontenvironment}}
\macro{\tex{definebodyfontenvironment}}

Earlier we saw that within a single body font there are in fact
different font sizes such as super|-| and subscripts. The
relations between these sizes are defined by {\em body font
environments}.

For all regular font sizes, environments are predefined
that fulfill their purpose adequately. However when you want
to do some extra defining yourself there is:

\showsetup{definebodyfontenvironment}


The first argument is optional, and specifier the typeface identifier 
that this particular body font environment setup is for.
It defaults to the current typeface.

The second argument is the size of the body font environment that is being defined.  This
argument is not really optional, the macro syntax description is a little misleading.

The third argument once again is optional, and contains the actual settings
as key-value pairs. If it is missing, defaults will be guessed at
by \CONTEXT\ itself. Although the macro syntax says the type is
\type{DIMENSION},  floating point numbers are also acceptable. Such numbers are
multipliers that are applied to the font size when the body font environment is
applied.

\starttabulate[|lT|p|]
\NC text           \NC Math text size or multiplier (default is \type{1.0})\NC \NR
\NC script         \NC Math script size (default is \type{0.7})\NC \NR
\NC scriptscript   \NC Math scriptscript size (default  is \type{0.5})\NC \NR
\NC x              \NC The size used for commands like \type{\tfx} (default is \type{0.8})\NC \NR
\NC xx             \NC The size used for the \type{\tfxx} command (default is \type{0.6})\NC\NR
\NC a              \NC The size for commands like \type{\tfa}  (default is \type{1.200})\NC \NR
\NC b              \NC The size for commands like \type{\tfb}  (default is \type{1.440})\NC \NR
\NC c              \NC The size for commands like \type{\tfa}  (default is \type{1.728})\NC \NR
\NC d              \NC The size for commands like \type{\tfd}  (default is \type{2.074})\NC \NR
\NC big            \NC The \quote{larger} font size (default is \type{1.2})\NC \NR
\NC small          \NC The \quote{smaller} font size (default is \type{0.8})\NC \NR
\NC interlinespace \NC Distance between lines in a paragraph (default is \type{2.8ex})\NC \NR
\NC em             \NC The style to use for emphasis (default is \type{slanted})\NC \NR
\stoptabulate 

So, when you want to have a somewhat bigger fontsize for just a few words
(e.g. for a book title) you can type:

\startexample
\starttyping
\definebodyfontenvironment [24pt]
\switchtobodyfont[24pt]
\stoptyping
\stopexample

For longer stretches of text you will probably want to set up most of the
values explicitly, using something like this

\startexample
\starttyping
\definebodyfontenvironment
  [22pt]
  [        text=22pt,
         script=17.3pt,
   scriptscript=14.4pt,
              x=17.3pt,
             xx=14.4pt,
            big=28pt,
          small=17.3pt]
\stoptyping
\stopexample

To tweak already defined sizes, there is an accompanying setup command with the same
parameter conventions:

\showsetup{setupbodyfontenvironment}

\section[sec:font features]{Font feature sets}

\macro{\tex{definefontfeature}}

As mentioned already, some fonts contain extra information besides the actual glyph
shapes. In traditional \TEX\ fonts, the extra information is roughly limited to kerning
pairs and ligature information, and both of these \quote{features} are automatically
applied to the text that is being typeset.  In the odd case where one of the two needs to
be suppressed, a little bit of macro trickery can do the job without too many
complicating factors.

But with the new OpenType font format that is used by \XETEX\ and \LUATEX, the list of
possible features has increased enormously. OpenType fonts have not just kerning
information and ligature information, but there can also be other features like optional
oldstyle figures, caps and smallcaps glyphs, decorative swashes, etc.  all inside a 
single font file. 

Not only that, but some of these features are not even supposed to be active all the
time. Certain features should only be activated if the user asks for it, while other features
depend on the script and language that is in use for the text that is being typeset.

This is a big step forward in that there are now far fewer fonts needed to achieve the
same level of quality than before, all that extra font information also poses a big
challenge for macro writers. And add to that the fact that at the core, the two engines 
(\XETEX\ and  \LUATEX) handle OpenType fonts completely different from each other.

\CONTEXT\ has a new subsystem called \quote{font features} to create order in this forest
of features. The most important command is \type{\definefontfeature}. This command can be
used to group various font features under a single symbolic name, that can then be used
as e.g. the argument to the \type{features} key of \type{\definetypeface}.

\showsetup{definefontfeature}

\startexample
\starttyping
\definefontfeature
   [default-base]
   [script=latn,language=dflt,liga=yes,kern=yes,tlig=yes,trep=yes]
\stoptyping
\stopexample

As you can probably guess, the first argument is the symbolic name that is being
defined. The second argument is a mix of a-hoc settings and OpenType font features.

\starttabulate[|lT|p|]
\NC compose   \NC Use fallback composition in \MKIV\ 
                  (experimental, undocumented) \NC \NR
\NC protrusion\NC Character protrusion in \MKIV\
                  (see~\in{section}[sec:font handling]) \NC \NR
\NC expansion \NC Character expansion in \MKIV\
                  (see~\in{section}[sec:font handling]) \NC \NR
\NC script    \NC An OpenType script identifier \NC \NR
\NC language  \NC An OpenType script language identifier \NC \NR
\NC tlig      \NC A virtual feature for legacy (\TEX-style) automatic ligatures 
                 (for compatibility, there is an alias for this key called
                  \type{texligatures})\NC \NR
\NC trep      \NC A virtual feature for legacy (\TEX-style) automatic ligatures
                  (for compatibility, there is an alias for this key called \type{texquotes})
                  (only works in \MKIV) \NC \NR
\NC mode      \NC Processing mode for \MKIV. 
                  \type{node} and \type{base} allowed, \type{base} is default\NC \NR
\NC <tag>     \NC Any OpenType feature tag is acceptable, but in \MKIV\
                  only a \quote{known} subset actually has any effect, and then
                  only in \type{node} mode. 
                  This list is given in~\in{table}[tab:mkivfeatures].
                  In \XETEX, processing depends on the internal subengine that
                  is used by \XETEX, and that is outside of \CONTEXT's control. \NC \NR
\stoptabulate

A few fontfeatures are predefined by context:

\startbuffer[predeffeatures]
\vskip 1ex
\starttabulate[|lT|lT|]
\NC  default  \NC liga=yes,kern=yes,tlig=yes,trep=yes          \NC \NR
\NC smallcaps \NC liga=yes,kern=yes,tlig=yes,trep=yes,smcp=yes \NC \NR
\NC oldstyle  \NC liga=yes,kern=yes,tlig=yes,trep=yes,onum=yes \NC \NR
\stoptabulate
\vskip 1ex
\stopbuffer

\getbuffer[predeffeatures]

At the moment, \type {smallcaps} and \type{oldstyle} only work in \XETEX\ 
(in \MKIV, it would need an extra \type{mode=node} pair).

\startbuffer[mkivfeatures]
% rough \TEX\ source generated by:
% \startluacode
%  for k,v in pairs(fonts.otf.tables.features) do
%    print (string.format('\\NC %s \\NC %s \\NC \\NR', k, v))
%  end
% \stopluacode
\begingroup
\startsimplecolumns[n=3]
\switchtobodyfont[9pt]
\starttabulate[|lT|p|]
\NC aalt \NC Access All Alternates \NC \NR
\NC abvf \NC Above-Base Forms \NC \NR
\NC abvm \NC Above-Base Mark Positioning \NC \NR
\NC abvs \NC Above-Base Substitutions \NC \NR
\NC afrc \NC Alternative Fractions \NC \NR
\NC akhn \NC Akhands \NC \NR
\NC blwf \NC Below-Base Forms \NC \NR
\NC blwm \NC Below-Base Mark Positioning \NC \NR
\NC blws \NC Below-Base Substitutions \NC \NR
\NC c2pc \NC Petite Capitals From Capitals \NC \NR
\NC c2sc \NC Small Capitals From Capitals \NC \NR
\NC calt \NC Contextual Alternates \NC \NR
\NC case \NC Case-Sensitive Forms \NC \NR
\NC ccmp \NC Glyph Composition/Decomposition \NC \NR
\NC cjct \NC Conjunct Forms \NC \NR
\NC clig \NC Contextual Ligatures \NC \NR
\NC cpsp \NC Capital Spacing \NC \NR
\NC cswh \NC Contextual Swash \NC \NR
\NC curs \NC Cursive Positioning \NC \NR
\NC dflt \NC Default Processing \NC \NR
\NC dist \NC Distances \NC \NR
\NC dlig \NC Discretionary Ligatures \NC \NR
\NC dnom \NC Denominators \NC \NR
\NC expt \NC Expert Forms \NC \NR
\NC falt \NC Final glyph Alternates \NC \NR
\NC fina \NC Terminal Forms \NC \NR
\NC fin2 \NC Terminal Forms \#2 \NC \NR
\NC fin3 \NC Terminal Forms \#3 \NC \NR
\NC frac \NC Fractions \NC \NR
\NC fwid \NC Full Width \NC \NR
\NC half \NC Half Forms \NC \NR
\NC haln \NC Halant Forms \NC \NR
\NC halt \NC Alternate Half Width \NC \NR
\NC hist \NC Historical Forms \NC \NR
\NC hkna \NC Horizontal Kana Alternates \NC \NR
\NC hlig \NC Historical Ligatures \NC \NR
\NC hngl \NC Hangul \NC \NR
\NC hojo \NC Hojo Kanji Forms \NC \NR
\NC hwid \NC Half Width \NC \NR
\NC init \NC Initial Forms \NC \NR
\NC isol \NC Isolated Forms \NC \NR
\NC ital \NC Italics \NC \NR
\NC jalt \NC Justification Alternatives \NC \NR
\NC jp04 \NC JIS2004 Forms \NC \NR
\NC jp78 \NC JIS78 Forms \NC \NR
\NC jp83 \NC JIS83 Forms \NC \NR
\NC jp90 \NC JIS90 Forms \NC \NR
\NC kern \NC Kerning \NC \NR
\NC lfbd \NC Left Bounds \NC \NR
\NC liga \NC Standard Ligatures \NC \NR
\NC ljmo \NC Leading Jamo Forms \NC \NR
\NC lnum \NC Lining Figures \NC \NR
\NC locl \NC Localized Forms \NC \NR
\NC mark \NC Mark Positioning \NC \NR
\NC medi \NC Medial Forms \NC \NR
\NC med2 \NC Medial Forms \#2 \NC \NR
\NC mgrk \NC Mathematical Greek \NC \NR
\NC mkmk \NC Mark to Mark Positioning \NC \NR
\NC mset \NC Mark Positioning via Substitution \NC \NR
\NC nalt \NC Alternate Annotation Forms \NC \NR
\NC nlck \NC NLC Kanji Forms \NC \NR
\NC nukt \NC Nukta Forms \NC \NR
\NC numr \NC Numerators \NC \NR
\NC onum \NC Old Style Figures \NC \NR
\NC opbd \NC Optical Bounds \NC \NR
\NC ordn \NC Ordinals \NC \NR
\NC ornm \NC Ornaments \NC \NR
\NC palt \NC Proportional Alternate Width \NC \NR
\NC pcap \NC Petite Capitals \NC \NR
\NC pnum \NC Proportional Figures \NC \NR
\NC pref \NC Pre-base Forms \NC \NR
\NC pres \NC Pre-base Substitutions \NC \NR
\NC pstf \NC Post-base Forms \NC \NR
\NC psts \NC Post-base Substitutions \NC \NR
\NC pwid \NC Proportional Widths \NC \NR
\NC qwid \NC Quarter Widths \NC \NR
\NC rand \NC Randomize \NC \NR
\NC rkrf \NC Rakar Forms \NC \NR
\NC rlig \NC Required Ligatures \NC \NR
\NC rphf \NC Reph Form \NC \NR
\NC rtbd \NC Right Bounds \NC \NR
\NC rtla \NC Right-To-Left Alternates \NC \NR
\NC ruby \NC Ruby Notation Forms \NC \NR
\NC salt \NC Stylistic Alternates \NC \NR
\NC sinf \NC Scientific Inferiors \NC \NR
\NC size \NC Optical Size \NC \NR
\NC smcp \NC Small Capitals \NC \NR
\NC smpl \NC Simplified Forms \NC \NR
\NC ss01 \NC Stylistic Set 1 \NC \NR
\NC ss02 \NC Stylistic Set 2 \NC \NR
\NC ss03 \NC Stylistic Set 3 \NC \NR
\NC ss04 \NC Stylistic Set 4 \NC \NR
\NC ss05 \NC Stylistic Set 5 \NC \NR
\NC ss06 \NC Stylistic Set 6 \NC \NR
\NC ss07 \NC Stylistic Set 7 \NC \NR
\NC ss08 \NC Stylistic Set 8 \NC \NR
\NC ss09 \NC Stylistic Set 9 \NC \NR
\NC ss10 \NC Stylistic Set 10 \NC \NR
\NC ss11 \NC Stylistic Set 11 \NC \NR
\NC ss12 \NC Stylistic Set 12 \NC \NR
\NC ss13 \NC Stylistic Set 13 \NC \NR
\NC ss14 \NC Stylistic Set 14 \NC \NR
\NC ss15 \NC Stylistic Set 15 \NC \NR
\NC ss16 \NC Stylistic Set 16 \NC \NR
\NC ss17 \NC Stylistic Set 17 \NC \NR
\NC ss18 \NC Stylistic Set 18 \NC \NR
\NC ss19 \NC Stylistic Set 19 \NC \NR
\NC ss20 \NC Stylistic Set 20 \NC \NR
\NC subs \NC Subscript \NC \NR
\NC sups \NC Superscript \NC \NR
\NC swsh \NC Swash \NC \NR
\NC titl \NC Titling \NC \NR
\NC tjmo \NC Trailing Jamo Forms \NC \NR
%\NC tlig \NC TeX Ligatures \NC \NR
\NC tnam \NC Traditional Name Forms \NC \NR
\NC tnum \NC Tabular Figures \NC \NR
\NC trad \NC Traditional Forms \NC \NR
%\NC trep \NC TeX Replacements \NC \NR
\NC twid \NC Third Widths \NC \NR
\NC unic \NC Unicase \NC \NR
\NC valt \NC Alternate Vertical Metrics \NC \NR
\NC vatu \NC Vattu Variants \NC \NR
\NC vert \NC Vertical Writing \NC \NR
\NC vhal \NC Alternate Vertical Half Metrics \NC \NR
\NC vjmo \NC Vowel Jamo Forms \NC \NR
\NC vkna \NC Vertical Kana Alternates \NC \NR
\NC vkrn \NC Vertical Kerning \NC \NR
\NC vpal \NC Proportional Alternate Vertical Metrics \NC \NR
\NC vrt2 \NC Vertical Rotation \NC \NR
\NC zero \NC Slashed Zero \NC \NR
\stoptabulate
\stopsimplecolumns
\endgroup
\stopbuffer

\placetable
  [page]
  [tab:mkivfeatures]
  {The OpenType features that are understood by \MKIV\ in \type{mode=node} processing mode}
  {\getbuffer[mkivfeatures]}


\section{Displaying the current font setup}

\macro{\tex{showbodyfont}}
\macro{\tex{showbodyfontenvironment}}

With the command \type {\showbodyfont} an overview is generated of the available 
characters, and an overview of the different fontsizes within a family can be
summoned with \type{\showbodyfontenvironment}.

\showsetup{showbodyfont}

\showsetup{showbodyfontenvironment}


Specifying actual \type{IDENTIFIER}s to these commands is currently unreliable 
because they internally are still counting on an older system of body font 
definitions, but you can safely use a size argument to get the information 
for the current font set.

Below an example of the possible output is shown, for \type{\showbodyfont[12pt]}  

\showbodyfont[12pt]

And the output of \type{\showbodyfontenvironment[12pt]} is:

\showbodyfontenvironment[12pt]


\section{Math fonts}
\index{math fonts}
\macro{\tex{mf}}

\startbuffer[math-1]
$\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+ \bi x^2 =\rm 6x^2$
$\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+ \bi x^2 =\tf 6x^2$
$\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+ \bi x^2 =\bf 6x^2$
$\tf x^2+\bf x^2+\sl x^2+\it x^2+\bs x^2+ \bi x^2 =\sl 6x^2$
\stopbuffer

\startbuffer[math-2]
$\tf\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
$\bf\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
$\sl\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
$\bs\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
$\it\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
$\bi\mf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = 6x^2$
\stopbuffer

\startbuffer[math-3]
$\bf x^2 + x^2 + x^2 + x^2 + x^2 + x^2 = \mf 6x^2$
\stopbuffer

There are only a few font families in existence that can handle math
properly because such fonts have to carry a complete set of characters and
symbols for mathematical typesetting.  Among these, the Computer
Modern Roman distinguishes itself by its many design sizes; that
really pays off when typesetting complicated math formulas. 


Many \TEX\ users have chosen \TEX\ for its superb math typesetting. 

This chapter will not go into any details but in math mode, the
central concept is the {\em math family} (not to be confused with the
{\em font families} discussed earlier). There are math families for
\type {\bf}, \type {\it}, etc. as well as for the special math
symbols. Within each family, there are always exactly three member
fonts: \type{text}, \type{script} and \type{scriptscript}, or a
normal, smaller and smallest font. The normal font size is used for
running text and the smaller ones for sub and superscripts. The next
example will show what the members of a math family can do.

\typebuffer[math-1]

When this is typeset you see this:

\startlines
\getbuffer[math-1]
\stoplines

As you can see, the alphabetic characters adapt to the selected font
family but the symbols are all typeset in the same font
regardless. Technically this means that the symbols are set in the
fixed font family~0 whereas the alphabetic characters are typeset
using variable family numbers.

Typesetting math formulas can also be done somewhat differently, as we
will see in the next example.

\typebuffer[math-2]

A new command is used: \type {\mf}, which stands for {\em math
font}. This command takes care of the symbols in such a way that they
are also set in the actually selected font, just like the characters.

\startlines
\getbuffer[math-2]
\stoplines

You should take into account that \TEX\ typesets a formula as a
whole. In some cases this means that setups at the end of the formula
have an effect that starts already at the beginning of the formula.

For example, the exact location of \type {\mf} is not that important.
We also could have typed:

\typebuffer[math-3]

There is much more to be said about math, but it is better to do that
in~\in{chapter}[chap:math], about math.

\section{Em and Ex}
\index[em]{\type{em}}
\index[ex]{\type{ex}}

In specifying dimensions we can distinguish physical units
like \type {pt} and \type {cm} and internal units like \type
{em} and \type {ex}. These last units are related to the
actual fontsize. When you use these internal units in
specifying for example horizontal and vertical spacing you
don't have to do any recalculating when fonts are switched
in the style definition.

Some insight in these units does not hurt. The width of an
\type {em} is not the with of an M, but that of an --- (an
em||dash). When this glyph is not available in the font
another value is used. \in {Table} [ems] shows some
examples. We see that the width of a digit is about \type
{.5em}. In Computer Modern Roman a digit is exactly half
an em wide.

\startbuffer[em-ex-1]

\def\jump{\vl\hskip1em\vl}%
\def\mmmm{\vl M\vl}%
\def\dash{\vl---\vl}%
\def\numb{\vl12\vl}%

\starttable[|c|c|c|c|c|c|]
\HL
\VL \type{\tf} \VL \type{\bf} \VL \type{\sl}  \VL
    \type{\tt} \VL \type{\ss} \VL \type{\tfx} \VL\SR
\HL
\VL \tf\numb   \VL \bf\numb   \VL \sl \numb   \VL
    \tt\numb   \VL \ss\numb   \VL \tfx\numb   \VL\FR
\VL \tf\mmmm   \VL \bf\mmmm   \VL \sl \mmmm   \VL
    \tt\mmmm   \VL \ss\mmmm   \VL \tfx\mmmm   \VL\MR
\VL \tf\jump   \VL \bf\jump   \VL \sl \jump   \VL
    \tt\jump   \VL \ss\jump   \VL \tfx\jump   \VL\MR
\VL \tf\dash   \VL \bf\dash   \VL \sl \dash   \VL
    \tt\dash   \VL \ss\dash   \VL \tfx\dash   \VL\LR
\HL
\stoptable

\stopbuffer

\placetable
  [here][ems]
  {The width of an \type{em}.}
  {\getbuffer[em-ex-1]}

In most cases we use \type{em} for specifying width and
\type {ex} for height. An \type {ex} equals the height of 
a lowercase~x. \in {Table} [exes] shows some examples. 

\startbuffer[em-ex-2]

\def\show
  {\hbox
    {\forgetall
     \offinterlineskip
     \vbox
       {\hsize1em\hl[1]\endgraf\vskip1ex\hl[1]}%
     \hskip.25em
     \vbox
       {\hsize.5em \vskip\linewidth x\vskip\linewidth}}}%

\starttable[|c|c|c|c|c|c|]
\HL
\VL \type{\tf} \VL \type{\bf} \VL \type{\sl}  \VL
    \type{\tt} \VL \type{\ss} \VL \type{\tfx} \VL\SR
\HL
\VL \tf\show   \VL \bf\show   \VL \sl\show    \VL
    \tt\show   \VL \ss\show   \VL \tfx\show   \VL\SR
\HL
\stoptable

\stopbuffer

\placetable
  [here][exes]
  {The height of an \type{ex}.}
  {\getbuffer[em-ex-2]}


\section [sec:font handling]{Font handling}


Almost all users of typesetting systems based on \TEX\ do so because
of the quality of the output it produces. \PDFTEX\ (and through
inheritance \LUATEX\ as well) contains a few extensions to the
typesetting engine that make the output even better than the results
achieved by Knuth's original \TEX.  Although the extensions are made
available by \PDFTEX, they are not limited to the \PDF\ output, they
will work with the \DVI\ backend just as well. And when the
extensions are defined but not enabled, then the typeset output is
100\% identical to when the feature is not present at all.

\subsection [sec:protrusion]{Character protrusion}


In the following fake paragraph, you can see a hyphenation point, a
secondary sentence, separated by a comma, and a last sentence, ending
with a period. Miraculously, this paragraph fits into lines. Although
exaggerated, these lines demonstrate that visually the hyphen and
punctuation characters make the margin look ragged.

\FakeParagraph\hbox\relax

Before computers started to take over the traditional
typesetter's job, it was common practice to move hyphens and
punctuation into the margin, like in:

\FakeParagraph\rlap\relax

In this alternative, the margin looks less ragged, and this
becomes more noticeable once you get aware of this phenomenon.

Sometimes, shifting the characters completely into the
margin is too much for the sensitive eye, for instance with
an italic font, where the characters already hang to the
right. In such cases, we need to compromise.

\FakeParagraph{\hbox to .2ex}\rlap

\PDFTEX\ (and \LUATEX, that has inherited this feature) has provisions 
to move characters into the margin when they end up at the end of a
line. Such characters are called protruding characters. \PDFTEX\
takes protruding into account when breaking a paragraph.

We will demonstrate protruding using a quote from Hermann Zapf's
article \quotation {About micro||typography and the {\sl
hz}||program} in Electronic Publishing, vol~6~(3), 1993.

\startnarrower
\switchtobodyfont[9pt] 
\typefile{zapf}
\stopnarrower

After \TEX\ has typeset this paragraph (using a specific font size
and line width) it may have constructed the following lines.

\blank

\beginofshapebox
\switchtobodyfont[modern,9pt] \noindent \input zapf \par
\endofshapebox
\reshapebox{\hbox{\AltColor\ruledhbox{\black\box\shapebox}}}
\flushshapebox

\blank

As you can see, the height and depth of the lines depend on
the characters, but their width equals what \TEX\ calls
\type {\hsize}. However, the natural width of the lines may
differ from \type {\hsize}.

\blank

\beginofshapebox
\switchtobodyfont[modern,9pt] \noindent \input zapf \par
\endofshapebox
\reshapebox{\hbox{\AltColor\ruledhbox{\black\unhbox\shapebox}}}
\flushshapebox

\blank

Here the inter||word space is fixed to what \TEX\ considers
to be a space. This example also demonstrates that \TEX\
does not have spaces, but stretches the white area between
words to suit its demands. When breaking lines, \TEX's mind
is occupied by boxes, glue and penalties, or in more common
language: (parts of) words, stretchable white space, and more
or less preferred breakpoints.

\blank

%TH Source note:
% I left the \setupfontsynonyms in because they are 
% needed in mkii mode.

\bgroup
\def\postprocesscolumnbox#1{\hbox{\AltColor\ruledhbox{\black\box#1}}}
\startcolumns[n=3]
\setupfontsynonym [Serif] [handling=normal] 
\switchtobodyfont[modern,9pt] 
\setupalign[verytolerant,stretch,hanging]
\noindent \input zapf \par
\stopcolumns
\egroup

\blank

This time we have enabled \PDFTEX's protruding mechanism.
The characters that stick into the margin are taken into
account when breaking the paragraph into lines, but in the
final result, they do not count in the width. Here we used
an ugly three column layout so that we got a few more
hyphens to illustrate the principle.


When that same text is typeset in the traditional way in two columns,
it looks like this: 

\blank

\startsimplecolumns[n=2]
\setupalign[verytolerant,stretch]
\switchtobodyfont[modern,9pt] \noindent \input zapf \par
\stopsimplecolumns

\blank

As you can see, the hyphens and punctuation fit snugly into the line
and as a result the line endings look a bit ragged.
With protrusion turned on, it looks like this: 

\blank

\startsimplecolumns[n=2]
\setupfontsynonym [Serif] [handling=pure]
\setupalign[verytolerant,stretch,hanging]
\switchtobodyfont[modern,9pt] \noindent \input zapf \par
\stopsimplecolumns

\blank

Now the punctuation protrudes a little into the margin.  Although the margin 
is now geometrically uneven it looks straighter to the human eye because 
not so much whitespace \quote{pushes into} the text.

\subsection [sec:hz]{Font expansion}

In typesetting the two characters hz are tightly connected to Hermann
Zapf and the next couple of pages we will discuss a method for
optimizing the look and feel of a paragraph using a mechanism that is
inspired by his work. Although official qualified in \PDFTEX\ as
font adjusting, we will use the short qualification hz since this is
how it is called in the \PDFTEX\ community.

First, here is again the same example text that was used in the
previous section, typeset using normal \TEX||comptibale font settings:

\blank

\startsimplecolumns[n=2]
\setupalign[verytolerant,stretch]
\switchtobodyfont[modern,9pt] \noindent \input zapf \par
\stopsimplecolumns

\blank

The example below shows hz in action. This paragraph is typeset with
hz enabled and has a more even spacing than the text above.

\blank

\startsimplecolumns[n=2]
\setupfontsynonym [Serif] [handling=hz]
% the next line can't be used, or the font encoding tables at the end of
% the chapter will fail with a `was expanded with different values'-error
% in mkii.
% \setupfonthandling [hz] [min=50,max=50,step=10]
\setupalign[hanging,hz]
\switchtobodyfont[modern,9pt] \noindent \input zapf \par
\stopsimplecolumns

\blank

The average reader will not notice the trick, but those sensitive to
character shapes will see that some glyphs are widened slightly and
others are narrowed slightly.  Ideally the programs that built the
glyph should be defined in such a way that this goes unnoticed, but
in practice glyph programs are not that clever and so a brute force
horizontal scaling is applied. As long as the used percentage is
small, the distortion will go unnoticed and the paragraph will look
slightly better because the whitespace distribution is more even.

\subsection [sec:otherhandling]{Other font handlings}

In addition to the two handlings documented in the previous
paragraphs (protruding and hz), \CONTEXT\ also provides the \type
{noligs} handling (handy when one processes \XML), \type
{flexspacing} and \type {prespacing} (meant for languages like French
that need spacing around for instance \type {:} and~\type {;}). These
handlings are experimental.


\subsection{How to use font handlings}

Before we go into the details of the actual extensions, let's see
what is provided by \CONTEXT\ as the user||level interface.  The
\CONTEXT\ interface to those new features is through a subsystem
called \quote{font handling}, and at the top that subsystem is
seamlessly integrated into the normal alignment macros.

For example, assuming the system is set up already to support
protrusion, you can simply say

\startexample
\starttyping
\setupalign[hanging]
\stoptyping
\stopexample

to turn protrusion on. However, this will only work correctly if a
number of special setups have taken place internally. The command
\type{\setupalign} only toggles a switch, and the required setups
have to be done elsewhere. 

The list of font handling||related keys for \type{\setupalign} is:

\starttabulate[|lT|l|]
\NC hanging    \NC turns on character protrusion\NC \NR
\NC nohanging  \NC turns off character protrusion\NC \NR
\NC hz         \NC turns on font expansion\NC \NR
\NC nohz       \NC turns off font expansion\NC \NR
\NC spacing    \NC turns on special spacing rules\NC \NR
\NC nospacing  \NC turns off special spacing\NC \NR
\stoptabulate

Largely because of the tight connection with the font itself, the
method of defining and setting font handling is a little different
between \PDFTEX\ and \MKIV.

\subsection{Setting up font handlings in \MKII}

Now, let's move on to how to set up the system for font handling
properly. Most of the underlying features of \PDFTEX\ cannot be turned 
{\em merely} on or off, it is possible to tweak the machinery on
the font as well as on the individual glyph level. You can define
those settings all on your own, but \CONTEXT\ comes with a handy set
of predefined values.

\starttabulate[|lT|lT|p|]
\NC \rm\bf name \NC \bf \tex{setupalign}\NC \bf description \NC \NR
\NC pure 	\NC hanging         \NC full protrusion of only selected punctuation \NC \NR
\NC normal 	\NC hanging         \NC partial protrusion of punctuation and some asymmetrical letters \NC \NR
\NC hz 	        \NC hz              \NC variable correction of character widths\NC \NR
\NC quality 	\NC hanging,hz      \NC combination of hz and pure \NC \NR
\NC highquality \NC hanging,hz      \NC combination of hz and normal \NC \NR
\NC flexspacing \NC spacing         \NC automatic extra spacing around various punctuation characters \NC \NR
\NC prespacing  \NC spacing         \NC like flexspacing, but ignoring . and , and with smaller effects\NC \NR
\NC noligs      \NC --              \NC suppresses ligatures; because this is irreversible it is not 
                                        controlled via \type{\setupalign}\NC \NR
\stoptabulate

You need to be aware of the fact that at the moment that you actually
define a font, you need to tell what handling you want to apply. 

Note: setting up font handling involves a few low-level font definition
commands, so you may want to read the chapter about font definitions
first.

Say that we want to hang only the serif fonts and say that we use
Palatino as main typeface.

\startexample
\starttyping
\setupfontsynonym [Serif] [handling=pure]
\definetypeface [palatino] [rm] [serif] [palatino] [default]
\stoptyping
\stopexample

In the above example, the font loader is instructed to treat fonts
with the virtual name \type{Serif} in a special way by applying the
font handling named \type {pure}. After that, the typeface collection
\type {palatino} is (re)defined and by that process the font tagged
as \type {Serif} will get the \quote{hanging} settings attached it.

Now enable this typeface collection can be enabled by:

\startexample
\starttyping
\setupbodyfont [palatino]
\stoptyping
\stopexample

and finally, don't forget to turn on hanging by:

\startexample
\starttyping
\setupalign [hanging]
\stoptyping
\stopexample

However, this only takes care of the \type{Serif} font. Normally, that
is the virtual name for the combination \type {\rm\tf}. If you also want the
bold variants to hang, you have to add an extra line:

\startexample
\starttyping
\setupfontsynonym [SerifBold] [handling=pure]
\stoptyping
\stopexample

And so on for all the alternatives. This is tedious, so \CONTEXT\
provides a shortcut. If you want to set all serif weights at once, you
can call on a predefined typescript component before defining the
typeface:

\startexample
\starttyping
\usetypescript [serif] [handling] [pure]
\stoptyping
\stopexample

for hanging punctuation, or for all characters:

\starttyping
\usetypescript [serif] [handling] [normal]
\stoptyping

The full example then becomes:

\startexample
\starttyping
\usetypescript [serif] [handling] [pure]
\definetypeface [palatino] [rm] [serif] [palatino] [default]
\setupbodyfont [palatino]
\setupalign [hanging]
\stoptyping
\stopexample

The first argument can be one of three named typescript groups:
\type{serif} (for the virtual font synonyms whose names begin with \type{Serif}), 
\type{sans} (for \type{Sans}), or \type{mono}  (for \type{Mono}). The second 
argument should always be \type{handling}. The third argument has to
be one of named font handlings that are listed in the table at the
start of this section.

The typescripts that are used in these examples work by altering the
font synonyms for virtual symbolic font names like \type{Serif}
and \type{SerifBold} en bloc. They will even work with your own
typescripts if (but only if) these typescripts use the same font
naming conventions as the \CONTEXT\ core.

\blank

The definition of font handlings is actually a two-step process.  A
named font handling consists of one or more handling vectors that have
to be defined first, those are then combined under a single name.

This is not the right place to describe how to define the low-level
vector definitions in detail, for that you are referred to the
documented source of the main handling definition file \type
{hand-def.tex}. But to give you an idea of what it looks like, here is
a small excerpt of that file. The \type{pure} handling vector is
defined as:

\starttyping
\startfonthandling [pure]

  \defineprotrudefactor , 0 1
  \defineprotrudefactor . 0 1
  \defineprotrudefactor : 0 1
  \defineprotrudefactor ; 0 1
  \defineprotrudefactor - 0 1

  \defineprotrudefactor hyphen 0 1
  \defineprotrudefactor endash 0 .5
  \defineprotrudefactor emdash 0 .33 % .5

\stopfonthandling
\stoptyping

The \type{pure} font handling itself is then defined as follows:

\starttyping
\definefonthandling [pure] [pure] [type=hanging]
\stoptyping

The \type{hz} setup runs along the same lines. First here is a vector:

\starttyping
\startfonthandling [hz]

  \defineadjustfactor A .5
  \defineadjustfactor B .7
  \defineadjustfactor C .7
  ...

\stopfonthandling
\stoptyping

And then the definition of the hz handling is as follows:

\starttyping
\definefonthandling [hz] [hz,extended] [type=hz]
\stoptyping

To wrap this up, here is the macro syntax for the font handling
definition and setup.

\showsetup{definefonthandling}

As you can see, the \type{\definefonthandling} command accepts three
arguments.  The first is the handling to be defined, the second is a
list of handling vectors to be used, and the third sets up a number of
settings. 

\starttabulate[|lT|p|]
\NC type    \NC the type of this font handling feature, for use by \type{\setupalign} \NC \NR
\NC right   \NC used by \type{type=hanging}, default 1  \NC \NR
\NC left    \NC used by \type{type=hanging}, default 1  \NC \NR
\NC factor  \NC used by \type{type=spacing}, default 1  \NC \NR
\NC min     \NC used by \type{type=hz}, default 20      \NC \NR
\NC max     \NC used by \type{type=hz}, default 20      \NC \NR
\NC step    \NC used by \type{type=hz}, default 5       \NC \NR
\stoptabulate

On top of the list at the beginning of this paragraph, a few
more elaborate font handlings are also predefined:

\starttyping
\definefonthandling [purebold]        [pure] [type=hanging]
\definefonthandling [pureitalic]      [pure] [type=hanging,right=1.5]
\definefonthandling [pureslanted]     [pure] [type=hanging,right=1.5]
\definefonthandling [purebolditalic]  [pure] [type=hanging,right=1.5]
\definefonthandling [pureboldslanted] [pure] [type=hanging,right=1.5]
\stoptyping

The \type {right} parameter (there is also \type {left}) is a
multiplication factor that is applied to the values in the associated
vector. Such definitions can be more extensive, like:

\starttyping
\definefonthandling
  [normalitalic]
  [punctuation,alpha,extended]
  [type=hanging,right=1.5]
\stoptyping

Here we have combined three vectors into one handling. For these
extended font handlings, there are no predefined typescripts, so you
either have to use the font synonyms directly, or define your own
typescripts.  Now, if you think this is overly complicated, you are
probably right. Normally you will just invoke protruding handlings
defined previously, but the mechanisms are there to fine||tune the
handlings to your precise wishes.

In case you want to alter some of the settings of an already defined
font handling, there is

\showsetup{setupfonthandling}

The first argument is the handling to be altered, the second sets up 
the settings.

\subsection{Setting up font handlings in \MKIV}

In \MKIV, font handling is merged with the font features (because
these already have a low-level connection to the font), so you can
set up the font-side of things with the sixth argument 
of \type{\definetypeface}, like so:

\startexample
\starttyping
\definefontfeature
    [hz] [default]
    [protrusion=pure, mode=node, script=latn]
\definetypeface [palatino] [rm] [serif] [palatino] [default] [features=hz]
\setupbodyfont [palatino]
\setupalign [hanging]
\stoptyping
\stopexample

or by redefining the feature set that is used by the typescript you
are using and then (re-)executing the typescript, like so:

\startexample
\starttyping
\definefontfeature
    [default] [default]
    [protrusion=pure, expansion=quality, mode=node, script=latn]
\usetypescript[palatino]
\setupbodyfont [palatino]
\setupalign [hanging]
\stoptyping
\stopexample

There is a list of predefined font handling feature values that you can use:

For protrusion, there is:

\starttabulate[|lT|lT|p|]
\NC \rm\bf name \NC \bf \tex{setupalign}\NC \bf description \NC \NR
\NC pure 	\NC hanging         \NC full protrusion of only selected punctuation \NC \NR
\NC punctuation \NC hanging         \NC partial protrusion of punctuation \NC \NR
\NC alpha       \NC hanging         \NC partial of some asymmetrical letters \NC \NR
\NC quality     \NC hanging         \NC the combination of \type{punctuation} and \type{alpha}\NC \NR
\stoptabulate

For expansion, there is:

\starttabulate[|lT|lT|p|]
\NC \rm\bf name \NC \bf \tex{setupalign}\NC \bf description \NC \NR
\NC quality     \NC hz              \NC variable correction of character widths\NC \NR
\stoptabulate

These are defined in the file \type{font-ext.lua}. The low||level definitions look like

\startLUA
fonts.protrusions.vectors['pure'] = {
    [0x002C] = { 0, 1    }, -- comma
    [0x002E] = { 0, 1    }, -- period
    [0x003A] = { 0, 1    }, -- colon
    [0x003B] = { 0, 1    }, -- semicolon
    [0x002D] = { 0, 1    }, -- hyphen
    [0x2013] = { 0, 0.50 }, -- endash
    [0x2014] = { 0, 0.33 }, -- emdash
}
fonts.protrusions.classes['pure'] = {
    vector = 'pure', factor = 1
}
\stopLUA

That was the complete definition of \type{protrusion=pure}.  The key
\type{classes} has the same function as the macro call
\type{\definefonthandling} in \MKII.  It references the named vector 
\type{pure} and sets up a parameter.  

For \type{protrusion}, there is only the one parameter \type{factor},
but for \type{expansion} there are a few more:


\starttyping
\startLUA
fonts.expansions.classes['quality'] = {
    stretch = 2, shrink = 2, step = .5, vector = 'default', factor = 1
}
fonts.expansions.vectors['default'] = {
    [byte('A')] = 0.5, 
    [byte('B')] = 0.7, 
    ... -- many more characters follow
}
\stopLUA
\stoptyping

As you can see, the definition order of vector vs.\ class is not
important, and the format of the vector is a little different. The use of 
\type{byte()} is just so that that keying in hex numbers can be avoided. 
The values are bare numbers instead of hashes because there is only
one per-character parameter involved with character expansion. 

Also note that the values for the parameters \type{stretch},
\type{shrink} and \type{step} are divided by a factor 10 compared to
the \MKII\ definition.

In \MKIV, there is no support for the \type{spacing} key to
\type{\setupalign} yet. That is because the low||level features in
\PDFTEX\ are not present in \LUATEX, and there is no replacement yet.
The font handling \type{noligs} is, of course, replaced by the
OpenType font feature tags for ligatures: simply leave all of the
relevant font features turned off.

\section [sec:encodings]{Encodings and mappings}

This section only applies to \PDFTEX. If you are exclusively using
\XETEX\ or \MKIV, you can safely ignore the following text.

Not every language uses the (western) Latin alphabet. Although
in most languages the basic 26 characters are somehow used,
they can be combined with a broad range of accents placed in
any place.

In order to get a character representation, also called
glyph, in the resulting output, you have to encode
it in the input. This is no problem for \type {a..z}, but
other characters are accessed by name, for instance \type
{\eacute}. The glyph \eacute\ can be present in the font but when
it's not there, \TEX\ has to compose the character from a
letter~e and an accent~\textacute.

In practice this means that the meaning of \type {\eacute}
depends on the font and font encoding used. There are many
such encodings, each suited for a subset of languages.

\vskip 1ex
\starttabulate [|lT|p|l|]
\HL
\NC \rm\bf encoding \NC \bf usage \NC \bf status \NC \NR
\HL
\NC 8r        \NC a (strange) mixture of encodings                            \NC useless  \NC \NR
\NC default   \NC the 7 bit \ASCII\ encoding as used by plain \TEX            \NC obsolete \NC \NR
\NC ec        \NC the prefered encoding of \TEX\ distributions                \NC okay     \NC \NR
\NC greek     \NC an encoding for modern greek                                \NC okay     \NC \NR
\NC qx        \NC an encoding that covers most eastern european languages     \NC okay     \NC \NR
\NC t2a       \NC a cyrillic \TEX\ font encoding                              \NC ?        \NC \NR
\NC t2b       \NC another cyrillic \TEX\ font encoding                        \NC ?        \NC \NR
\NC t2c       \NC another another cyrillic \TEX\ font encoding                \NC ?        \NC \NR
\NC t5        \NC an encoding dedicated to vietnamese (many (double) accents) \NC okay     \NC \NR
\NC texnansi  \NC a combination of \TEX\ and Adobe standard encoding          \NC okay     \NC \NR
\HL
\stoptabulate
\vskip 1ex

These encodings are font related as is demonstrated in \in
{figure} [fig:font a], \in{}[fig:font b],  \in{}[fig:font c], \in
{and} [fig:font d]. Here we used the \type {\showfont} command.

\placefigure
  [here][fig:font a]
  {The Latin Modern Roman font in ec encoding.}
  {\externalfigure[typography/encodings.pdf][page=1]}

\placefigure
  [here][fig:font b]
  {The Latin Modern Roman font in texnansi encoding.}
  {\externalfigure[typography/encodings.pdf][page=2]}

\placefigure
  [here][fig:font c]
  {The Latin Modern Roman font in qx encoding.}
  {\externalfigure[typography/encodings.pdf][page=3]}

\placefigure
  [here][fig:font d]
  {The Latin Modern Roman font in t5 encoding.}
  {\externalfigure[typography/encodings.pdf][page=4]}

The situation is even more complicated than it looks, since
the font may be virtual, that is, built from several fonts.

The advantage of using specific encodings is that you can
let \TEX\ hyphenate words in the appropriate way. The
hyphenation patterns are applied to the internal
data structures that represent the sequence of glyphs. In
spite of what you may expect, they are font||dependent! Even
more confusing: they not only depend on the font encoding,
but also on the mapping from lower to uppercase characters,
or more precise, on the existence of such a mapping.

Unless you want to play with these encodings and mappings,
in most cases you can forget their details and rely on what
other \TEX\ experts tell you to do. Normally switching from
one to another encoding and|/|or mapping takes place with the
change in fonts or when some special output encoding is
needed, for instance in \PDF\ annotations and|/|or unicode
vectors that enable searching in documents. So, to summarize
this: encodings and mappings depend on the fonts used as well
have consequences for the language specific hyphenation
patterns. Fortunately \CONTEXT\ handles this for you
automatically.

\doflushfloats
\page

If you want to know to what extent a font is complete and
characters need to be composed on the fly, you can typeset a
a couple of tables. The (current) composition is shown by
\type {\showaccents}, as shown in~\in{figure}[fig:show accents]

\placefigure
  [here][fig:show accents]
  {Output of \type{\showaccents} for the current (palatino) font in \PDFTEX}
  {\externalfigure[typography/encodings.pdf][page=5]}

\page

With \type {\showcharacters}, you get a list of named characters (and
glyphs) as known to the system. Note: the following table will look
different in each of the three typesetting engines. 

\showcharacters

\stopcomponent
