Difference between revisions of "Use fonts distributed with ConTeXt"

From Wiki
Jump to navigation Jump to search
m (minor adjustments, nothing new)
 
(11 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
First, have a look at the [[ConTeXt distribution's Fonts|21 provided fonts]] and the associated typescript name:
 
First, have a look at the [[ConTeXt distribution's Fonts|21 provided fonts]] and the associated typescript name:
  
= Use one the provided fonts, out of the box =
+
= Change the font used in the document =
 +
 
 +
To change the font used in the entire document (including headers and footers), use  {{cmd|setupbodyfont}} and the associated [[ConTeXt distribution's Fonts|typescript name]].
 +
 
 +
: <texcode>\setupbodyfont[thetypescriptname]</texcode>
 +
 
 +
By default, the font is used at 11pt. To change the font size, specify the font size with the the typescript name. For example, to switch to 10pt, use:
 +
 
 +
: <texcode>\setupbodyfont[typescriptname, 10pt]</texcode>
 +
 
 +
By default, the serif (or roman) style of the font is used. To switch to sans serif style, add <code>ss</code> to {{cmd|setupbodyfont}}:
 +
 
 +
: <texcode>\setupbodyfont[typescriptname, ss]</texcode>
 +
 
 +
These options can be combined. So, to get sans serif font at 12pt, use:
 +
 
 +
: <texcode>\setupbodyfont[typescriptname, ss, 12pt]</texcode>
  
; #1. Declare the font you want to use for your document with {{cmd|setupbodyfont}} and the associated [[ConTeXt distribution's Fonts|typescript name]].
 
:* <texcode>\setupbodyfont[thetypescriptname]</texcode>
 
; #2. Specify the font size
 
:* <texcode>\setupbodyfont[xxpt]</texcode>
 
  
 
To learn how to use different alternative styles of a given font, like regular / bold / italic, see the [[Font_Switching]] in the [[Basics]].
 
To learn how to use different alternative styles of a given font, like regular / bold / italic, see the [[Font_Switching]] in the [[Basics]].
Line 17: Line 29:
 
Let see what give the defaults:
 
Let see what give the defaults:
 
<context source=yes>
 
<context source=yes>
\setupbodyfont[12pt]
+
\setupbodyfont[10pt]
  
{\rm The quick brown fox jumps over the lazy dog}\\
+
\startlines
{\it The quick brown fox jumps over the lazy dog}\\
+
\normal{Upright: The quick brown fox \unknown}
{\bf The quick brown fox jumps over the lazy dog}\\
+
\bold{Bold: The quick brown fox \unknown}
{\bi The quick brown fox jumps over the lazy dog}\\
+
\italic{Italic: The quick brown fox \unknown}
 +
\bolditalic{Bolditalic: The quick brown fox \unknown}
 +
\stoplines
 
</context>
 
</context>
 
|
 
|
 
And let's view the difference with Tex Gyre Pagella Serif font:
 
And let's view the difference with Tex Gyre Pagella Serif font:
 
<context source=yes>
 
<context source=yes>
\setupbodyfont[12pt]
+
\setupbodyfont[pagella,10pt]
\setupbodyfont[pagella]
+
 
{\rm The quick brown fox jumps over the lazy dog}\\
+
\startlines
{\it The quick brown fox jumps over the lazy dog}\\
+
\normal{Upright: The quick brown fox \unknown}
{\bf The quick brown fox jumps over the lazy dog}\\
+
\bold{Bold: The quick brown fox \unknown}
{\bi The quick brown fox jumps over the lazy dog}\\
+
\italic{Italic: The quick brown fox \unknown}
 +
\bolditalic{Bolditalic: The quick brown fox \unknown}
 +
\stoplines
 
</context>
 
</context>
 
}}
 
}}
Line 62: Line 78:
  
 
== Example ==
 
== Example ==
 +
 
{{TwoColumnsUnderLevel1
 
{{TwoColumnsUnderLevel1
 
|
 
|
 
This basic input is typeset with the default font, Latin Modern:
 
This basic input is typeset with the default font, Latin Modern:
 
<context source=yes>
 
<context source=yes>
\setupbodyfont[12pt]
 
  
  
Line 72: Line 88:
  
  
{\rm    The quick brown fox jumps over the lazy dog}\\
+
 
{\rm\bf The quick brown fox jumps over the lazy dog}\\
+
 
{\rm\it The quick brown fox jumps over the lazy dog}\\
+
 
\\
+
\setupbodyfont[7pt]
{\ss    The quick brown fox jumps over the lazy dog}\\
+
\startbuffer[line]
{\ss\bf The quick brown fox jumps over the lazy dog}\\
+
The quick brown fox jumps over
{\ss\it The quick brown fox jumps over the lazy dog}\\
+
\stopbuffer
\\
+
 
{\tt    The quick brown fox jumps over the lazy dog}\\
+
\startbuffer[sample]
{\tt\bf The quick brown fox jumps over the lazy dog}\\
+
\startTABLE
{\tt\it The quick brown fox jumps over the lazy dog}\\
+
  \NC \type{\normal}   
\\
+
  \NC \normal{\getbuffer[line]}  
Inline math: $x = \frac{y}{2z} + x_{\text{center}}$\\
+
  \NC \NR
 +
  \NC \type{\italic}   
 +
  \NC \italic{\getbuffer[line]}  
 +
  \NC \NR
 +
  \NC \type{\bold}     
 +
  \NC \bold{\getbuffer[line]}  
 +
  \NC \NR
 +
  \NC \type{\bolditalic}
 +
  \NC \bolditalic{\getbuffer[line]}
 +
  \NC \NR
 +
\stopTABLE
 +
\stopbuffer
 +
 
 +
\startlines
 +
\type{\serif}
 +
\serif{\getbuffer[sample]}
 +
 
 +
\type{\sans}
 +
\sans{\getbuffer[sample]}
 +
 
 +
\type{\mono}
 +
\mono{\getbuffer[sample]}
 +
 
 +
\type{\math}
 +
\math{x = \frac{y}{2z} + x_{\text{center}}}
 +
\stoplines
 
</context>
 
</context>
 
|
 
|
 
And let's view the difference with our new set of fonts:  
 
And let's view the difference with our new set of fonts:  
 
<context source=yes>
 
<context source=yes>
\setupbodyfont[12pt]
+
\definefontfamily [MyFontIdentifier]  
\definefontfamily [MyFontIdentifier] [rm] [texgyrepagella]
+
                  [rm] [texgyrepagella]
\definefontfamily [MyFontIdentifier] [ss] [texgyreadventor]
+
\definefontfamily [MyFontIdentifier]
\definefontfamily [MyFontIdentifier] [tt] [texgyrecursor]
+
                  [ss] [texgyreadventor]
\definefontfamily [MyFontIdentifier] [mm] [stixtwomath]
+
\definefontfamily [MyFontIdentifier]  
\setupbodyfont[MyFontIdentifier]
+
                  [tt] [texgyrecursor]
{\rm    The quick brown fox jumps over the lazy dog}\\
+
\definefontfamily [MyFontIdentifier]
{\rm\bf The quick brown fox jumps over the lazy dog}\\
+
                  [mm] [stixtwomath]
{\rm\it The quick brown fox jumps over the lazy dog}\\
+
\setupbodyfont[MyFontIdentifier, 7pt]
\\
+
\startbuffer[line]
{\ss    The quick brown fox jumps over the lazy dog}\\
+
The quick brown fox jumps over
{\ss\bf The quick brown fox jumps over the lazy dog}\\
+
\stopbuffer
{\ss\it The quick brown fox jumps over the lazy dog}\\
+
 
\\
+
\startbuffer[sample]
{\tt    The quick brown fox jumps over the lazy dog}\\
+
\startTABLE
{\tt\bf The quick brown fox jumps over the lazy dog}\\
+
  \NC \type{\normal}   
{\tt\it The quick brown fox jumps over the lazy dog}\\
+
  \NC \normal{\getbuffer[line]}  
\\
+
  \NC \NR
Inline math: $x = \frac{y}{2z} + x_{\text{center}}$\\
+
  \NC \type{\italic}
 +
  \NC \italic{\getbuffer[line]}  
 +
  \NC \NR
 +
  \NC \type{\bold}     
 +
  \NC \bold{\getbuffer[line]}
 +
  \NC \NR
 +
  \NC \type{\bolditalic}  
 +
  \NC \bolditalic{\getbuffer[line]}
 +
  \NC \NR
 +
\stopTABLE
 +
\stopbuffer
 +
 
 +
\startlines
 +
\type{\serif}
 +
\serif{\getbuffer[sample]}
 +
 
 +
\type{\sans}
 +
\sans{\getbuffer[sample]}
 +
 
 +
\type{\mono}
 +
\mono{\getbuffer[sample]}
 +
 
 +
\type{\math}
 +
\math{x = \frac{y}{2z} + x_{\text{center}}}
 +
\stoplines
 
</context>
 
</context>
 
}}
 
}}
 +
 +
 +
[[Category:Fonts]]

Latest revision as of 08:35, 7 June 2020


First, have a look at the 21 provided fonts and the associated typescript name:

Change the font used in the document

To change the font used in the entire document (including headers and footers), use \setupbodyfont and the associated typescript name.

\setupbodyfont[thetypescriptname]

By default, the font is used at 11pt. To change the font size, specify the font size with the the typescript name. For example, to switch to 10pt, use:

\setupbodyfont[typescriptname, 10pt]

By default, the serif (or roman) style of the font is used. To switch to sans serif style, add ss to \setupbodyfont:

\setupbodyfont[typescriptname, ss]

These options can be combined. So, to get sans serif font at 12pt, use:

\setupbodyfont[typescriptname, ss, 12pt]


To learn how to use different alternative styles of a given font, like regular / bold / italic, see the Font_Switching in the Basics.

Example

  • Let see what give the defaults:
    \setupbodyfont[10pt]
    
    \startlines
    \normal{Upright: The quick brown fox \unknown}
    \bold{Bold: The quick brown fox \unknown}
    \italic{Italic: The quick brown fox \unknown}
    \bolditalic{Bolditalic: The quick brown fox \unknown}
    \stoplines
    
  • And let's view the difference with Tex Gyre Pagella Serif font:
    \setupbodyfont[pagella,10pt]
    
    \startlines
    \normal{Upright: The quick brown fox \unknown}
    \bold{Bold: The quick brown fox \unknown}
    \italic{Italic: The quick brown fox \unknown}
    \bolditalic{Bolditalic: The quick brown fox \unknown}
    \stoplines
    

You can switch to any other font with \switchtobodyfont.

How to mix the provided fonts

#1. With \definefontfamily, give a name to the set of fonts you want to use, and indicate a first font.
  • Let's start with a Serif font, for which TeX practice is to refer to them as rm for Roman
\definefontfamily[MyFontIdentifier][rm][familynameoftheseriffont]
  • !!! WARNING !!!, , it's not the typescript name that we have to use, but the family name of the font
    • see under each preview in the overview table
    • or use mtxrun --script font --list --file -pattern=*typescriptname* like mtxrun --script font --list --file -pattern=*pagella*
#2. For the other fonts, just continue to add them to your font family.
  • ss for Sans Serif, tt for TypewriTer, mm for MatheMatics.
\definefontfamily[MyFontIdentifier][ss][familynameofthesansseriffont]
\definefontfamily[MyFontIdentifier][tt][familynameofthemonospacedfont]
\definefontfamily[MyFontIdentifier][mm][familynameofthemathfont]
  • As you see, a limit here is that in TeX practice, we only have one roman, one sans serif... per font family.
  • in order to use more fonts, like width variation ("condensed",...), and weight variation ("light",...), we have to define other font family (MyFontIdentifier-condensed, MyFontIdentifier-light), and to switch between them along the document, with \switchtobodyfont.
#3. Declare your font family as the default for your document with \setupbodyfont, as you would do for a typescript.
\setupbodyfont[MyFontIdentifier]


Example

  • This basic input is typeset with the default font, Latin Modern:
    
    
    
    
    
    
    
    
    \setupbodyfont[7pt]
    \startbuffer[line]
    The quick brown fox jumps over
    \stopbuffer
    
    \startbuffer[sample]
    \startTABLE
      \NC \type{\normal}     
      \NC \normal{\getbuffer[line]} 
      \NC \NR
      \NC \type{\italic}     
      \NC \italic{\getbuffer[line]} 
      \NC \NR
      \NC \type{\bold}       
      \NC \bold{\getbuffer[line]} 
      \NC \NR
      \NC \type{\bolditalic}
      \NC \bolditalic{\getbuffer[line]}
      \NC \NR
    \stopTABLE
    \stopbuffer
    
    \startlines
    \type{\serif}
    \serif{\getbuffer[sample]}
    
    \type{\sans}
    \sans{\getbuffer[sample]}
    
    \type{\mono}
    \mono{\getbuffer[sample]}
    
    \type{\math}
    \math{x = \frac{y}{2z} + x_{\text{center}}}
    \stoplines
    
  • And let's view the difference with our new set of fonts:
    \definefontfamily [MyFontIdentifier] 
                      [rm] [texgyrepagella]
    \definefontfamily [MyFontIdentifier]
                      [ss] [texgyreadventor]
    \definefontfamily [MyFontIdentifier] 
                      [tt] [texgyrecursor]
    \definefontfamily [MyFontIdentifier]
                      [mm] [stixtwomath]
    \setupbodyfont[MyFontIdentifier, 7pt]
    \startbuffer[line]
    The quick brown fox jumps over
    \stopbuffer
    
    \startbuffer[sample]
    \startTABLE
      \NC \type{\normal}     
      \NC \normal{\getbuffer[line]} 
      \NC \NR
      \NC \type{\italic}
      \NC \italic{\getbuffer[line]} 
      \NC \NR
      \NC \type{\bold}      
      \NC \bold{\getbuffer[line]}
      \NC \NR
      \NC \type{\bolditalic} 
      \NC \bolditalic{\getbuffer[line]} 
      \NC \NR
    \stopTABLE
    \stopbuffer
    
    \startlines
    \type{\serif}
    \serif{\getbuffer[sample]}
    
    \type{\sans}
    \sans{\getbuffer[sample]}
    
    \type{\mono}
    \mono{\getbuffer[sample]}
    
    \type{\math}
    \math{x = \frac{y}{2z} + x_{\text{center}}}
    \stoplines