Changes

Jump to navigation Jump to search
8,362 bytes added ,  18:08, 16 August 2007
Wikified version of TUGboat article
== Introduction ==

This is a wikified version of this
[http://www.tug.org/TUGboat/Articles/tb28-2/tb89mahajan.pdf Tugboat article].

In this article I will discuss how to use the various font styles in
ConTeXt. Fonts are one of the most complicated parts of TeX. Fortunately,
the macro developers take care of the dirty stuff, and most of the user
interface is clean. Nevertheless, understanding the various options of the
user interface can be intimidating. As a beginner, one does not want to know
all the nitty-gritty details, but just the basic features. We hope to
present these in this article.

In ConTeXt there are four ways to switch fonts:

* font style (<cmd>rm</cmd>, <cmd>ss</cmd>, etc.),
* font size (<cmd>tfa</cmd>, <cmd>tfb</cmd>, etc.),
* alternative font style (<cmd>bold</cmd>, <cmd>sans</cmd>, etc.),
* a complete font change (<cmd>setupbodyfont</cmd>, <cmd>switchtobodyfont</cmd>).

I will briefly explain each of these.

== Font styles ==

There are three types of font families: serif, sans serif, and teletype. To
switch between these families, use <cmd>rm</cmd> for serif, <cmd>ss</cmd> for
sans serif, and <cmd>tt</cmd> for teletype.

Each of these families come in different styles: upright, bold, italic,
slanted, bold-italic, bold-slanted, and small-capped. To switch to a different
style, use <cmd>tf</cmd> for upright, <cmd>bf</cmd> for bold, <cmd>it</cmd>
for italic, <cmd>sl</cmd> for slanted, <cmd>bi</cmd> for bold-italic,
<cmd>bs</cmd> for bold-slanted, and <cmd>sc</cmd> for small-capped.

You can generally combine font families and font styles, so if you want to
switch to bold sans serif, you can use either <code>\bf\ss</code> or
<code>\ss\bf</code>.

There is a font switch <cmd>em</cmd> to 'emphasize' text. This is somewhat
special: it does automatic italic correction and changes the style depending
on the current font style. For example, if the current font style is upright,
<cmd>em</cmd> switches to slanted; and if the current font style is slanted,
<cmd>em</cmd> switches to upright.

ConTeXt uses the Latin Modern fonts by default; these fonts look
similar to the original Computer Modern fonts, but have a much larger
character repertoire. As it happens, in the Latin Modern (and Computer
Modern) fonts, the slanted font does not stand out from the
upright font enough for some tastes; so, many people prefer to use the
italic font for emphasis. To do that use
<texcode>
\definebodyfontenvironment[default][em=italic]
</texcode>

A font switch remains valid for the rest of the group. So, if you want to
temporarily switch to a different font, use the font style command inside a
group. The easiest way to start a group is to enclose the text within braces
(also called curly brackets), for example

<texcode>
This is serif text
{\ss This is sans serif}
{\tt and this is typewriter}
</texcode>

which gives (notice the braces in the above lines)

<context>
This is serif text \crlf
{\ss This is sans serif} \crlf
{\tt and this is typewriter}
</context>

== Font sizes ==

Occasionally one needs to change the font size. ConTeXt provides two series
of commands for that. To increase the font you can use <cmd>tfa</cmd> to scale
the font size by a factor of $1.2$, <cmd>tfb</cmd> to scale by a factor of
$(1.2)^2 = 1.44$, <cmd>tfc</cmd> to scale by <code>(1.2)^3 = 1.728</code> and <cmd>tfd</cmd> to
scale by <code>(1.2)^4 = 2.074</code>.

To decrease the font size, you can use <cmd>tfx</cmd>
to scale the font by a factor of $0.8$ and <cmd>tfxx</cmd> to scale by a factor
of $0.6$. The scale factors can be a function of the current font size and can
be changed by <cmd>definebodyfontenvironment</cmd>.

For example, if you want
<cmd>tfa</cmd> to be equal to 12pt when you are using 10pt font, and be equal to
14pt when you are using 11pt font, then add
<texcode>
\definebodyfontenvironment [10pt] [a=12pt]
\definebodyfontenvironment [11pt] [a=14pt]
</texcode>
<cmd>definebodyfontenvironment</cmd> is described in detail in
the ConTeXt manual and the \filename{font-ini.tex} source file.

Font size can be combined with font styles. As a shortcut, you can use
<cmd>bfa</cmd> to get bold font scaled by 1.2, <cmd>bfx</cmd> to get a bold font
scaled by 0.8 and similar commands for other font styles.

These font size switches are meant for changing the font size of a few
words: they do not change the interline spacing and math font sizes. So, if
you want to change the font size of an entire paragraph, use
<cmd>switchtobodyfont</cmd> described below in \in Section[setupbodyfont]. However, it
is fine to use them as style directives in setup commands, that is, using them
as an option for \type{style=...} in any setup command that accepts
<code>style</code> option.

== Alternative font styles ==

While learning a document markup language like ConTeXt, it can be hard to
remember all the commands. ConTeXt provides easy to remember alternative
font styles. So for bold you can use <cmd>bold</cmd>, for italic you can use
<cmd>italic</cmd>, for slanted you can use <cmd>slanted</cmd>, and so on. You can
probably guess what the following do:

{|
| <cmd>normal</cmd>
| <cmd>slanted</cmd>
|-
| <cmd>boldslanted</cmd>
| <cmd>slantedbold</cmd>
|-
| <cmd>bolditalic</cmd>
| <cmd>italicbold</cmd>
|-
| <cmd>small</cmd>
| <cmd>smallnormal</cmd>
|-
| <cmd>smallbold</cmd>
| <cmd>smallslanted</cmd>
|-
| <cmd>smallboldslanted</cmd>
| <cmd>smallslantedbold</cmd>
|-
| <cmd>smallbolditalic</cmd>
| <cmd>smallitalicbold</cmd>
|-
| <cmd>sans</cmd>
| <cmd>sansserif</cmd>
|-
| <cmd>sansbold</cmd>
| <cmd>smallcaps</cmd>
|}

In addition, the commands <cmd>smallbodyfont</cmd> and
<cmd>bigbodyfont</cmd> can be used to change the font size.

These alternative font styles are pretty smart. You can either use them as
font style switches inside a group, or as a font changing command that takes an
argument. For example,
<cotext source="yes">
This is {\bold bold} and so is \bold{this}.
</context>

These alternative font styles can also be used for all \type{style=...}
options, and while using them as style options, you can just give the command
name, for example:
<texcode>
\setuphead[section][style=bold]
</texcode>

== Complete font change ==

If you need to change to a different font size and take care of interline
spacing, you can use <cmd>switchtobodyfont</cmd>. For example, to switch to 12pt
you can use <code>\switchtobodyfont[12pt]</code>.


ConTeXt provides two relative sizes, called 'big' and 'small'. So, to go to a
bigger font size use <code>\switchtobodyfont[big]</code> and to use a
smaller font size use <code>\switchtobodyfont[small]</code>. The exact
size used for big and small can be set using
<code>\definebodyfontenvironment</code>.

The <cmd>setupbodyfont</cmd> command accepts all the same arguments as
<cmd>switchtobodyfont</cmd>. The difference between the two is that
<cmd>setupbodyfont</cmd> also changes the font for headers, footers and other
page markings, while <cmd>switchtobodyfont</cmd> does not. So you should use
<cmd>setupbodyfont</cmd> for global font definitions to apply to the whole document, and
<cmd>switchtobodyfont</cmd> for local font changes. The effect of
<cmd>switchtobodyfont</cmd> can be localized within a group as usual.

== Different typefaces ==

So far we have discussed style and size changes within a given typeface
family. If you want to use a different typeface altogether, such as Times or
Palatino, the Pragma web site has recipes covering all the commonly available
typefaces, ([http://pragma-ade.com/general/manuals/showfont.pdf]) while a
separate manual describes how to write support for new typefaces
([http://pragma-ade.com/general/manuals/mfonts.pdf])

The recipes as given work with the standalone ConTeXt distribution, but not
with TeX Live et al. [http://pragma-ade.com/general/technotes/tfmetrics.pdf]
explains why CONTEXT uses separate font metrics, and gives some differences
between the sets. To use the recipes with other distributions,
try adding one of <code>\usetypescript[berry][ec]</code> or
<code>\usetypescript[adobekb][ec]</code>.

== Conclusion ==

There are many other ways of choosing font styles in ConTeXt. If these
basic styles do not satisfy your needs, have a look at the [[Official ConTeXt Documentation| manual]],
or ask on the [[ConTeXt Mailing Lists]].

Navigation menu