Characters words and fonts/Tutorials
Contents
- 1 Font styles, style alternatives, and switch commands
- 2 Mnemonic font switches
- 3 Emphasizing text
- 4 Quotes
- 5 Font sizes
- 6 Typeface selection from those distributed with ConTeXt
- 7 Capitalizing or small-capitalizing words
- 8 Underlining, striking through, and overlining
- 9 Subscripting and superscripting
- 10 Framing
- 11 Coloring
- 12 Customize your highlighting commands
- 13 The style= and color= parameters
- 14 Summary
- 15 Further
- 16 TODO
Font styles, style alternatives, and switch commands
Here are 6 font styles, and their associated switch command, the most commonly used being the first 4:
- serif \rm (roman), sans serif \ss, teletype \tt, math \mr (math regular)
- calligraphy \cg, handwriting \hw
Each of these styles comes in different alternatives:
- normal \tf (typeface), bold \bf, italic \it, slanted \sl, bold-italic \bi, bold-slanted \bs, small-capped \sc.
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
This is serif text \par {\bf switched to bold} \par {\ss switched to sans serif} \par This is normal serif again \par {\tt switched to typewriter \par {\it switched to typewriter and italic}}
You can generally combine font styles with alternatives, so if you want to
switch to bold sans serif, you can use either \bf\ss
or
\ss\bf
. The various combinations look like the following.
Mnemonic font switches
While learning a document markup language like ConTeXt, it can be hard to remember all the commands. ConTeXt provides other, easy-to-remember font switches. So for bold you can use \bold, for italic you can use \italic, for slanted you can use \slanted, and so on.
In addition, the commands \smallbodyfont and
\bigbodyfont can be used to change the font size. The relative size depends on the value of big
and small
in \definebodyfontenvironment.
You can probably guess what the following do:
These mnemonic font switches 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,
This is {\bold bold} and so is \bold{this}. But this is not.
Emphasizing text
There is a font switch \em to emphasize text. This is somewhat special: it does automatic italic correction and changes the alternative depending on the current alternative. For example, if the current font alternative is normal (i.e. upright), \em switches to slanted; and if the current font alternative is slanted, \em switches to normal.
Quotes
Don't try to type quotation marks, but use logical markup! Quotation marks and formatting are language dependent.
- single quotes
- \quote{some text} or \startquote
- double quotes
- \quotation{some text}
You'll be hearing more and more: \quote{This document is typeset with ConTeXt}, and \quotation{that's cool}.
Font sizes
Occasionally one needs to use a font size different from the bodyfont. ConTeXt provides two series of commands for that. For a larger font size, you can use
- \tfa to scale the font size by a factor of
1.2
, - \tfb to scale by
(1.2)^2 = 1.440
, - \tfc to scale by
(1.2)^3 = 1.728
, and - \tfd to scale by
(1.2)^4 = 2.074
.
The scale is relative to the current bodyfont size.
To decrease the font size, you can use
{\tfxx T}, {\tfx T}, {\tf T}, {\tfa T}, {\tfb T}, {\tfc T}, {\tfd T}
Font size can be combined with font styles alternatives
{\tfxx T}, {\tfx T}, {\tf T}, {\tfa T}, {\tfb T}, {\tfc T}, {\tfd T} \par {\bfxx T}, {\bfx T}, {\bf T}, {\bfa T}, {\bfb T}, {\bfc T}, {\bfd T} \par {\itxx T}, {\itx T}, {\it T}, {\ita T}, {\itb T}, {\itc T}, {\itd T} \par {\slxx T}, {\slx T}, {\sl T}, {\sla T}, {\slb T}, {\slc T}, {\sld T} \par {\bixx T}, {\bix T}, {\bi T}, {\bia T}, {\bib T}, {\bic T}, {\bid T} \par {\bsxx T}, {\bsx T}, {\bs T}, {\bsa T}, {\bsb T}, {\bsc T}, {\bsd T}
These quick font switches are meant for changing the font style, alternative, or size of a few words: they do not change the bodyfont, so they don't affect interline spacing or math font sizes. So, if you want to change the font size of an entire paragraph, use \switchtobodyfont described below.
Typeface selection from those distributed with ConTeXt
By default, the typeface used is latin modern (now named latin modern) in serif style at 11pt. To change the typeface used in the entire document (including headers and footers), use \setupbodyfont and the associated typescript name from 21 fonts distributed with ConTeXt.
\setupbodyfont[thetypescriptname,style, size]
For example
Let's use the Tex Gyre Pagella Serif font:
\setupbodyfont[pagella,serif,12pt] \normal{Upright: The quick brown fox…}\par \bold{Bold: The quick brown fox…}\par \italic{Italic: The quick brown fox…}\par \bolditalic{Bolditalic: The quick brown fox…}
And DejaVu Condensed Sans font:
\setupbodyfont[dejavu-condensed,sans,10pt] \normal{Upright: The quick brown fox…}\par \bold{Bold: The quick brown fox…}\par \italic{Italic: The quick brown fox…}\par \bolditalic{Bolditalic: The quick brown fox…}
If you want to switch to a different font and take care of the interline spacing, you can use the \switchtobodyfont command. It accepts all the same arguments as \setupbodyfont. The difference between the two is that \setupbodyfont also changes the font for headers, footers and other page markings, while \switchtobodyfont does not.
So \setupbodyfont is used in the setup area of the input file
for global font definitions to apply to the whole document,
whereas \switchtobodyfont is used anywhere else for local font changes (i.e. changes to the running text only).
The effect of \switchtobodyfont can be localized within a group as usual (delimited by {}
). If not localized, its action is maintained until next \switchtobodyfont.
\setupbodyfont[pagella,serif,12pt] The quick brown fox jumps {\switchtobodyfont[dejavu-condensed,sans,8pt] over the lazy} dog. The quick brown fox jumps \switchtobodyfont[dejavu-condensed,sans,8pt] over the lazy dog. \startsection[title=test] The quick brown fox jumps {\switchtobodyfont[gentium,12pt] over the lazy} dog. \stopsection
ConTeXt provides two relative sizes, called big and small. So, to increase the bodyfont size, use \switchtobodyfont[big]
(or \setbigbodyfont
), and to decrease the bodyfont size, use \switchtobodyfont[small]
(or \setsmallbodyfont
). The exact
size used for big and small can be set using
\definebodyfontenvironment.
\setupbodyfont[pagella,serif,12pt] The {\switchtobodyfont[big] quick brown} fox jumps over the {\switchtobodyfont[small] black lazy} dog.
Capitalizing or small-capitalizing words
\Word{hello world}\par \WORD{hello world}\par \Words{hello world}\par {\sc hello world} \par \cap{hello world} \par \Cap{hello world} \par
Note that \WORD, \Word and all following macros aren't switches, but commands (brackets behind, not around: {\bf switch} vs \Word{macro}.
Underlining, striking through, and overlining
Underlined, struck, and overlined text can be achieved with \overbar , \overbars, \overstrike, \overstrikes, \underbar, and \underbars.
\overbar{hello world}\par \overbars{hello world}\par \overstrike{hello world}\par \overstrikes{hello world}\par \underbar{hello world} \par \underbars{hello world} \par
Subscripting and superscripting
2 commands here : \low , \high.
hello\low{world}\par hello\high{world}
Framing
The command \inframed is used for adding frames, backgrounds and styling to a segment of text
Hello \inframed{ConTeXt} world ! Hello \inframed[background=color, backgroundcolor=cyan, frame=off]{ConTeXt} world !
To apply at block text level see \framed or \startframed.
Coloring
See the Color page, but just to give you a quick illustration of the command \color[thecolorname]{the text}:
\color[darkred]{I love} \color[darkyellow]{ConTeXt}
Customize your highlighting commands
It can be appropriate to define a semantic command that takes care of the font switching. For example, instead of using {\bf important text}
\definehighlight[important][style=\bold] This is the \important{important part} of the text.
The style= and color= parameters
Many ConTeXt commands accept a style
and a color
parameter. These in turn accept a name as defined by \definehighlight, \definealternativestyle, \definefont for fonts, etc., respectively \definecolor or \startstandardmakeup for colors:
\definefont[MyFont][Arial at 28pt] \startmakeup[standard][style=MyFont] Lorem ipsum dolor sit amet consectetur. \stopmakeup
Alternatively, instead of pre-defining a font or color name, one can hand the definition over directly:
\startmakeup[standard][style={\setupinterlinespace[line=5em]}] Lorem ipsum dolor sit amet consectetur. \stopmakeup
Summary
You have learned
- to use switches commands to set up
- to use mnemonics commands when you prefer \serif, \bold, \sansbold
- to use \setupbodyfont to select the typeface among those distributed with ConTeXt, and to switch to another one in the running text with \switchtobodyfont.
- to mix typefaces and to build a family of fonts with \definefontfamily.
- to change the appearance like
- capitalizing or small-capitalizing words \Word ,\WORD ,\Words ,\cap ,\Cap.
- underlining, striking through, and overlining, with \overbar , \overbars, \overstrike, \overstrikes, \underbar, and \underbars.
- subscripting and superscripting, with \low , \high.
- to define your own highlighting commands , with \definehighlight
Further
TODO
- Check that nothing has been lost during the reallocation of Characters words and fonts/Font Switching between tutorials and how-to guides.