Simple Typescript Example

From Wiki
Revision as of 02:16, 30 January 2014 by Thangalin (talk | contribs)
Jump to navigation Jump to search


This page describes how to map a Sans Serif font to the \ss command and a Serif font to the \rm command.


This example uses Nimbus, which is a GPL font. Check to see if Nimbus is available by running the following command:

mtxrun --script fonts --list --all --pattern=nimbus*

This should reveal a list similar to the following:

nimbusromno9lmedi          nimbusromno9lmedi        utmb8a.afm
nimbusromno9lmedibold      nimbusromno9lmedi        utmb8a.afm
nimbusromno9lmediital      nimbusromno9lmediital    utmbi8a.afm
nimbusromno9lregu          nimbusromno9lregu        utmr8a.afm
nimbusromno9lreguital      nimbusromno9lreguital    utmri8a.afm
nimbusromno9lregunormal    nimbusromno9lregu        utmr8a.afm
nimbussanlbold             nimbussanlbold           uhvb8a.afm
nimbussanlboldital         nimbussanlboldital       uhvbo8a.afm
nimbussanlregu             nimbussanlregu           uhvr8a.afm
nimbussanlreguital         nimbussanlreguital       uhvro8a.afm
nimbussanlregunormal       nimbussanlregu           uhvr8a.afm

If the font is not shown, you might have to install the font, which can be found on some systems at:


You may use a different font; please see how to install fonts to MkIV for details.


The ConTeXt code to configure the font follows:


\starttypescript [serif] [nimbus]
  \definefontsynonym [Serif]             [name:nimbusromno9lregu]
  \definefontsynonym [SerifBold]         [name:nimbusromno9lbold]
  \definefontsynonym [SerifItalic]       [name:nimbusromno9lreguital]
  \definefontsynonym [SerifSlanted]      [name:nimbusromno9lreguital]
  \definefontsynonym [SerifBoldItalic]   [name:nimbusromno9lboldital]
  \definefontsynonym [SerifBoldSlanted]  [name:nimbusromno9lboldital]
  \definefontsynonym [SerifCaps]         [name:nimbusromno9lregu]

\starttypescript [sans] [nimbus]
  \definefontsynonym [Sans]             [name:nimbussanlregu]
  \definefontsynonym [SansBold]         [name:nimbussanlbold]
  \definefontsynonym [SansItalic]       [name:nimbussanlreguital]
  \definefontsynonym [SansSlanted]      [name:nimbussanlreguital]
  \definefontsynonym [SansBoldItalic]   [name:nimbussanlboldital]
  \definefontsynonym [SansBoldSlanted]  [name:nimbussanlboldital]
  \definefontsynonym [SansCaps]         [name:nimbussanlregu]

\definetypeface [nimbus]  [rm]  [serif] [nimbus]
\definetypeface [nimbus]  [ss]  [sans]  [nimbus]



Regular, {\it Italic}, {\bf Bold}, {\bi Bold-Italic}, {\sc KaPiTaLe}




  • The first two lines say:
    • We only enter unicode
    • We only use unicode fonts
  • Thirds line (setupcapitals) say ConTeXt to use the Capital Letters defined in the fonts
  • Two scripts are defined:
    1. the scripts named [serif][nimbus] and
    2. the script named [sans][nimbus]
  • Both scripts map the fonts names to the different (existing) font style.
  • Both definetypeface-lines define the typeface nimbus. The first defines the rm-fonts and the second the ss-fonts.
  • setupbodyfont says to ConTeXt witch typeface to use with which parameters.

The chain starts with setupbodyfont: it calls the typeface nimbus. Then the typeface nimbus

  1. calls the typescript [serif][nimbus] for the rm-fonts
  2. calls the typescript [sans][nimbus] for the ss-fonts.

And inside these scripts the fonts are mapped to the different font styles.

Small extension

To show how to call a typescript directly we extend the script a little:

\definefontsynonym [SansCaps]           [name:nimbusromno9lregu]

\starttypescript [nimbus]
  \definetypeface [nimbus]	[rm]	[serif]	[nimbus]
  \definetypeface [nimbus]	[ss]	[sans]	[nimbus]




  • A third typescript is defined named [nimbus]
  • usetypescript calls the typescript [nimbus] in which the typeface [nimbus] is defined
  • typeface [nimbus] and typescript [nimbus] are two totally different things
  • if the typescript [nimbus] would not be called via usetypescript then the typeface [nimbus] would not be defined


  • setupbodyfont
  • showbodyfont
  • definetypeface (not found in the references)
  • starttypescript / stoptypescript (not found in the references)
  • definefontsynonym (not found in the references)