Difference between revisions of "Font Switching"

From Wiki
Jump to navigation Jump to search
m
m
Line 4: Line 4:
 
In ConTeXt there are four ways to switch fonts:
 
In ConTeXt there are four ways to switch fonts:
  
* font style (<cmd>rm</cmd>, <cmd>ss</cmd>, etc.),
+
* font style ({{cmd|rm}}, {{cmd|ss}}, etc.),
* font size  (<cmd>tfa</cmd>, <cmd>tfb</cmd>, etc.),
+
* font size  ({{cmd|tfa}}, {{cmd|tfb}}, etc.),
* alternative font style (<cmd>bold</cmd>, <cmd>sans</cmd>, etc.),
+
* alternative font style ({{cmd|bold}}, {{cmd|sans}}, etc.),
* a complete font change (<cmd>setupbodyfont</cmd>, <cmd>switchtobodyfont</cmd>).
+
* a complete font change ({{cmd|setupbodyfont}}, {{cmd|switchtobodyfont}}).
  
 
==  Font styles ==
 
==  Font styles ==
  
 
There are three types of font families: serif, sans serif, and teletype.  To
 
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
+
switch between these families, use {{cmd|rm}} for serif, {{cmd|ss}} for
sans serif, and <cmd>tt</cmd> for teletype.
+
sans serif, and {{cmd|tt}} for teletype.
  
 
Each of these families come in different styles: upright, bold, italic,
 
Each of these families come in different styles: upright, bold, italic,
 
slanted, bold-italic, bold-slanted, and small-capped. To switch to a different
 
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>
+
style, use {{cmd|tf}} for upright, {{cmd|bf}} for bold, {{cmd|it}}
for italic, <cmd>sl</cmd> for slanted, <cmd>bi</cmd> for bold-italic,
+
for italic, {{cmd|sl}} for slanted, {{cmd|bi}} for bold-italic,
<cmd>bs</cmd> for bold-slanted, and <cmd>sc</cmd> for small-capped.
+
{{cmd|bs}} for bold-slanted, and {{cmd|sc}} for small-capped.
  
 
You can generally combine font families and font styles, so if you want to
 
You can generally combine font families and font styles, so if you want to
Line 25: Line 25:
 
<code>\ss\bf</code>.  
 
<code>\ss\bf</code>.  
  
There is a font switch <cmd>em</cmd> to ''emphasize'' text. This is somewhat
+
There is a font switch {{cmd|em}} to ''emphasize'' text. This is somewhat
 
special: it does automatic italic correction and changes the style depending
 
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,
 
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}} switches to slanted; and if the current font style is slanted,
<cmd>em</cmd> switches to upright.
+
{{cmd|em}} switches to upright.
  
 
ConTeXt uses the Latin Modern fonts by default; these fonts look
 
ConTeXt uses the Latin Modern fonts by default; these fonts look
Line 63: Line 63:
  
 
Occasionally one needs to change the font size. ConTeXt provides two series
 
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
+
of commands for that. To increase the font you can use {{cmd|tfa}} to scale
the font size by a factor of <code>1.2</code>, <cmd>tfb</cmd> to scale by a factor of
+
the font size by a factor of <code>1.2</code>, {{cmd|tfb}} to scale by a factor of
<code>(1.2)^2 = 1.44</code>, <cmd>tfc</cmd> to scale by <code>(1.2)^3 = 1.728</code> and <cmd>tfd</cmd> to
+
<code>(1.2)^2 = 1.44</code>, {{cmd|tfc}} to scale by <code>(1.2)^3 = 1.728</code> and {{cmd|tfd}} to
 
scale by <code>(1.2)^4 = 2.074</code>.
 
scale by <code>(1.2)^4 = 2.074</code>.
  
To decrease the font size, you can use <cmd>tfx</cmd>
+
To decrease the font size, you can use {{cmd|tfx}}
to scale the font by a factor of <code>0.8</code> and <cmd>tfxx</cmd> to scale by a factor
+
to scale the font by a factor of <code>0.8</code> and {{cmd|tfxx}} to scale by a factor
 
of <code>0.6</code>. The scale factors can be a function of the current font size and can
 
of <code>0.6</code>. The scale factors can be a function of the current font size and can
be changed by <cmd>definebodyfontenvironment</cmd>.
+
be changed by {{cmd|definebodyfontenvironment}}.
  
 
For example, if you want
 
For example, if you want
<cmd>tfa</cmd> to be equal to 12pt when you are using 10pt font, and be equal to
+
{{cmd|tfa}} to be equal to 12pt when you are using 10pt font, and be equal to
 
14pt when you are using 11pt font, then add
 
14pt when you are using 11pt font, then add
 
<texcode>
 
<texcode>
Line 80: Line 80:
 
\definebodyfontenvironment [11pt] [a=14pt]
 
\definebodyfontenvironment [11pt] [a=14pt]
 
</texcode>
 
</texcode>
<cmd>definebodyfontenvironment</cmd> is described in detail in  
+
{{cmd|definebodyfontenvironment}} is described in detail in  
 
the ConTeXt manual and the [[source:font-ini.tex|font-ini.tex]] source file.
 
the ConTeXt manual and the [[source:font-ini.tex|font-ini.tex]] source file.
  
 
Font size can be combined with font styles. As a shortcut, you can use
 
Font size can be combined with font styles. As a shortcut, you can use
<cmd>bfa</cmd> to get bold font scaled by <code>1.2</code>, <cmd>bfx</cmd> to get a bold font
+
{{cmd|bfa}} to get bold font scaled by <code>1.2</code>, {{cmd|bfx}} to get a bold font
 
scaled by <code>0.8</code> and similar commands for other font styles.
 
scaled by <code>0.8</code> and similar commands for other font styles.
  
Line 90: Line 90:
 
words: they do not change the interline spacing and math font sizes. So, if
 
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
 
you want to change the font size of an entire paragraph, use
<cmd>switchtobodyfont</cmd> described below in [[Font_Switching#Complete_font_change|Complete Font Change]]. However, it
+
{{cmd|switchtobodyfont}} described below in [[Font_Switching#Complete_font_change|Complete Font Change]]. However, it
 
is fine to use them as style directives in setup commands, that is, using them
 
is fine to use them as style directives in setup commands, that is, using them
 
as an option for <code>[[Style_and_Color_Parameters|style=]]...</code> in any setup command that accepts
 
as an option for <code>[[Style_and_Color_Parameters|style=]]...</code> in any setup command that accepts
Line 99: Line 99:
 
While learning a document markup language like ConTeXt, it can be hard to
 
While learning a document markup language like ConTeXt, it can be hard to
 
remember all the commands. ConTeXt provides easy to remember alternative
 
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
+
font styles. So for bold you can use {{cmd|bold}}, for italic you can use
<cmd>italic</cmd>, for slanted you can use <cmd>slanted</cmd>, and so on. You can
+
{{cmd|italic}}, for slanted you can use {{cmd|slanted}}, and so on. You can
 
probably guess what the following do:
 
probably guess what the following do:
  
 
{|
 
{|
  |  <cmd>normal</cmd>
+
  |  {{cmd|normal}}
  |  <cmd>slanted</cmd>
+
  |  {{cmd|slanted}}
 
  |-
 
  |-
  |  <cmd>boldslanted</cmd>
+
  |  {{cmd|boldslanted}}
  |  <cmd>slantedbold</cmd>
+
  |  {{cmd|slantedbold}}
 
  |-
 
  |-
  |  <cmd>bolditalic</cmd>
+
  |  {{cmd|bolditalic}}
  |  <cmd>italicbold</cmd>
+
  |  {{cmd|italicbold}}
 
  |-
 
  |-
  |  <cmd>small</cmd>
+
  |  {{cmd|small}}
  |  <cmd>smallnormal</cmd>
+
  |  {{cmd|smallnormal}}
 
  |-
 
  |-
  |  <cmd>smallbold</cmd>
+
  |  {{cmd|smallbold}}
  |  <cmd>smallslanted</cmd>
+
  |  {{cmd|smallslanted}}
 
  |-
 
  |-
  |  <cmd>smallboldslanted</cmd>
+
  |  {{cmd|smallboldslanted}}
  |  <cmd>smallslantedbold</cmd>
+
  |  {{cmd|smallslantedbold}}
 
  |-
 
  |-
  |  <cmd>smallbolditalic</cmd>
+
  |  {{cmd|smallbolditalic}}
  |  <cmd>smallitalicbold</cmd>
+
  |  {{cmd|smallitalicbold}}
 
  |-
 
  |-
  |  <cmd>sans</cmd>
+
  |  {{cmd|sans}}
  |  <cmd>sansserif</cmd>
+
  |  {{cmd|sansserif}}
 
  |-
 
  |-
  |  <cmd>sansbold</cmd>
+
  |  {{cmd|sansbold}}
  |  <cmd>smallcaps</cmd>
+
  |  {{cmd|smallcaps}}
 
  |}
 
  |}
  
In addition, the commands <cmd>smallbodyfont</cmd> and
+
In addition, the commands {{cmd|smallbodyfont}} and
<cmd>bigbodyfont</cmd> can be used to change the font size.
+
{{cmd|bigbodyfont}} can be used to change the font size.
  
 
These alternative font styles are pretty smart. You can either use them as
 
These alternative font styles are pretty smart. You can either use them as
Line 153: Line 153:
  
 
If you need to change to a different font size and take care of interline
 
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
+
spacing, you can use {{cmd|switchtobodyfont}}. For example, to switch to 12pt
 
you can use <code>\switchtobodyfont[12pt]</code>.
 
you can use <code>\switchtobodyfont[12pt]</code>.
  
Line 161: Line 161:
 
smaller font size use  <code>\switchtobodyfont[small]</code>. The exact
 
smaller font size use  <code>\switchtobodyfont[small]</code>. The exact
 
size used for big and small can be set using  
 
size used for big and small can be set using  
<cmd>definebodyfontenvironment</cmd>.
+
{{cmd|definebodyfontenvironment}}.
  
The <cmd>setupbodyfont</cmd> command accepts all the same arguments as
+
The {{cmd|setupbodyfont}} command accepts all the same arguments as
<cmd>switchtobodyfont</cmd>. The difference between the two is that
+
{{cmd|switchtobodyfont}}. The difference between the two is that
<cmd>setupbodyfont</cmd> also changes the font for headers, footers and other
+
{{cmd|setupbodyfont}} also changes the font for headers, footers and other
page markings, while <cmd>switchtobodyfont</cmd> does not. So you should use
+
page markings, while {{cmd|switchtobodyfont}} does not. So you should use
<cmd>setupbodyfont</cmd> for global font definitions to apply to the whole document, and
+
{{cmd|setupbodyfont}} for global font definitions to apply to the whole document, and
<cmd>switchtobodyfont</cmd> for local font changes. The effect of
+
{{cmd|switchtobodyfont}} for local font changes. The effect of
<cmd>switchtobodyfont</cmd> can be localized within a group as usual.
+
{{cmd|switchtobodyfont}} can be localized within a group as usual.
  
 
== Different typefaces ==
 
== Different typefaces ==

Revision as of 23:39, 22 September 2013

< Basic Text Formatting | Fonts | Font Sizes >


In ConTeXt there are four ways to switch fonts:

Font styles

There are three types of font families: serif, sans serif, and teletype. To switch between these families, use \rm for serif, \ss for sans serif, and \tt 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 \tf for upright, \bf for bold, \it for italic, \sl for slanted, \bi for bold-italic, \bs for bold-slanted, and \sc 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 \bf\ss or \ss\bf.

There is a font switch \em 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, \em switches to slanted; and if the current font style is slanted, \em 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

\definebodyfontenvironment[default][em=italic]

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
{\ss This is sans serif}
{\tt and this is typewriter}

which gives (notice the braces in the above lines)

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 \tfa to scale the font size by a factor of 1.2, \tfb to scale by a factor of (1.2)^2 = 1.44, \tfc to scale by (1.2)^3 = 1.728 and \tfd to scale by (1.2)^4 = 2.074.

To decrease the font size, you can use \tfx to scale the font by a factor of 0.8 and \tfxx 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 \definebodyfontenvironment.

For example, if you want \tfa to be equal to 12pt when you are using 10pt font, and be equal to 14pt when you are using 11pt font, then add

\definebodyfontenvironment [10pt] [a=12pt]
\definebodyfontenvironment [11pt] [a=14pt]

\definebodyfontenvironment is described in detail in the ConTeXt manual and the font-ini.tex source file.

Font size can be combined with font styles. As a shortcut, you can use \bfa to get bold font scaled by 1.2, \bfx 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 \switchtobodyfont described below in Complete Font Change. However, it is fine to use them as style directives in setup commands, that is, using them as an option for style=... in any setup command that accepts style 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 \bold, for italic you can use \italic, for slanted you can use \slanted, and so on. You can probably guess what the following do:

\normal \slanted
\boldslanted \slantedbold
\bolditalic \italicbold
\small \smallnormal
\smallbold \smallslanted
\smallboldslanted \smallslantedbold
\smallbolditalic \smallitalicbold
\sans \sansserif
\sansbold \smallcaps

In addition, the commands \smallbodyfont and \bigbodyfont 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,

This is {\bold bold} and so is \bold{this}.

These alternative font styles can also be used for all style=... options, and while using them as style options, you can just give the command name, for example:

\setuphead[section][style=bold] 

Complete font change

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


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

The \setupbodyfont command accepts all the same arguments as \switchtobodyfont. The difference between the two is that \setupbodyfont also changes the font for headers, footers and other page markings, while \switchtobodyfont does not. So you should use \setupbodyfont for global font definitions to apply to the whole document, and \switchtobodyfont for local font changes. The effect of \switchtobodyfont 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 [1], while a separate manual describes how to write support for new typefaces [2].

The recipes as given work with the standalone ConTeXt distribution, but not with TeX Live et al. [3] 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 \usetypescript[berry][ec] or \usetypescript[adobekb][ec].

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 manuals, or ask on the ConTeXt Mailing Lists.