Simple Typescript Example

From Wiki
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 page also describes how typefaces differ from typescripts.


This example uses Nimbus, which is a GPL font. Check whether 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.


Configure a font follows:

% Enable Unicode fonts

% Enable Capital Letter use

% Define a script named [serif][nimbus]
\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]

% Define a second script named [sans][nimbus]
\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]

% Define the typeface nimbus; use serif for rm-fonts, sans serif for ss-fonts.
\definetypeface [nimbus]  [rm]  [serif] [nimbus]
\definetypeface [nimbus]  [ss]  [sans]  [nimbus]

% Indicate the typeface to use.


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



Both scripts (serif and sans nimbus) map the fonts names to the different (existing) font style. Usage is implemented as follows:

  • The \setupbodyfont command calls the typeface nimbus.
  • The typeface nimbus calls the typescript [serif][nimbus] for \rm fonts, or typescript [sans][nimbus] for the \ss fonts.

The scripts then map the fonts to different font styles.


The fonts can be changed by extending the script:

\definefontsynonym [SansCaps]           [name:nimbusromno9lregu]

% Define a typescript named nimbus.
\starttypescript [nimbus]
  \definetypeface [nimbus]	[rm]	[serif]	[nimbus]
  \definetypeface [nimbus]	[ss]	[sans]	[nimbus]

% Use the nimbus typescript, which defines the nimbus typeface.


Note that typeface [nimbus] and typescript [nimbus] are different.

Calling \usetypescript[nimbus] ensures that the two \definetypeface commands, embedded within \starttypescript, as shown above, are called:

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