Difference between revisions of "Simple Typescript Example"

From ConTeXt wiki
m
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
[[Category:Fonts]]
 
[[Category:Fonts]]
==Task==
 
  
To map Nimbus Sans on rm-fonts and Nimbus Serif on ss-fonts.
+
==Overview==
 +
 
 +
This page describes how to map a Sans Serif font to the {{cmd|ss}} command and a Serif font to the {{cmd|rm}} command. This page also describes how typefaces differ from typescripts.
  
 
==Requirements==
 
==Requirements==
  
The Nimbus Sans and Nimbus Serif fonts are installed at your System and also recognized by ConTeXt. If
+
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*
 
  mtxrun --script fonts --list --all --pattern=nimbus*
  
does not shows you minimum:
+
This should reveal a list similar to the following:
  
 
  nimbusromno9lmedi          nimbusromno9lmedi        utmb8a.afm
 
  nimbusromno9lmedi          nimbusromno9lmedi        utmb8a.afm
Line 24: Line 25:
 
  nimbussanlregunormal      nimbussanlregu          uhvr8a.afm
 
  nimbussanlregunormal      nimbussanlregu          uhvr8a.afm
  
please visit the instruction [[Fonts_in_LuaTeX#Building_the_font_database|how to install fonts to MkIV]].
+
If the font is not shown, you might have to install the font, which can be found on some systems at:
  
You do not have to use this Nimbus fonts. For this example you can use any Unicode font you like. If you use different fonts do not forget to exchange the font names in the example script below.
+
/usr/share/fonts/type1/gsfonts
 +
 
 +
You may use a different font; please see [[Fonts_in_LuaTeX#Building_the_font_database|how to install fonts to MkIV]] for details.
  
 
==Script==
 
==Script==
 +
 +
Configure a font follows:
  
 
<texcode>
 
<texcode>
 +
% Enable Unicode fonts
 
\enableregime[utf]
 
\enableregime[utf]
\setupencoding[default=uc]
 
  
 +
% Enable Capital Letter use
 
\setupcapitals[sc=yes]
 
\setupcapitals[sc=yes]
  
\starttypescript [serif] [nimbus]  
+
% Define a script named [serif][nimbus]
   \definefontsynonym [Serif]         [name:nimbussanlregu]
+
\starttypescript [serif] [nimbus]
   \definefontsynonym [SerifBold]   [name:nimbussanlbold]
+
   \definefontsynonym [Serif]             [name:nimbusromno9lregu]
   \definefontsynonym [SerifItalic]         [name:nimbussanlreguital]
+
   \definefontsynonym [SerifBold]         [name:nimbusromno9lbold]
   \definefontsynonym [SerifSlanted]       [name:nimbussanlreguital]
+
   \definefontsynonym [SerifItalic]       [name:nimbusromno9lreguital]
   \definefontsynonym [SerifBoldItalic]     [name:nimbussanlboldital]
+
   \definefontsynonym [SerifSlanted]     [name:nimbusromno9lreguital]
   \definefontsynonym [SerifBoldSlanted]   [name:nimbussanlboldital]
+
   \definefontsynonym [SerifBoldItalic]   [name:nimbusromno9lboldital]
   \definefontsynonym [SerifCaps]           [name:nimbussanlregu]
+
   \definefontsynonym [SerifBoldSlanted] [name:nimbusromno9lboldital]
 +
   \definefontsynonym [SerifCaps]         [name:nimbusromno9lregu]
 
\stoptypescript
 
\stoptypescript
  
\starttypescript [sans] [nimbus]  
+
% Define a second script named [sans][nimbus]
   \definefontsynonym [Sans]         [name:nimbusromno9lregu]
+
\starttypescript [sans] [nimbus]
   \definefontsynonym [SansBold]   [name:nimbusromno9lbold]
+
   \definefontsynonym [Sans]             [name:nimbussanlregu]
   \definefontsynonym [SansItalic]         [name:nimbusromno9lreguital]
+
   \definefontsynonym [SansBold]         [name:nimbussanlbold]
   \definefontsynonym [SansSlanted]       [name:nimbusromno9lreguital]
+
   \definefontsynonym [SansItalic]       [name:nimbussanlreguital]
   \definefontsynonym [SansBoldItalic]     [name:nimbusromno9lboldital]
+
   \definefontsynonym [SansSlanted]     [name:nimbussanlreguital]
   \definefontsynonym [SansBoldSlanted]   [name:nimbusromno9lboldital]
+
   \definefontsynonym [SansBoldItalic]   [name:nimbussanlboldital]
   \definefontsynonym [SansCaps]           [name:nimbusromno9lregu]
+
   \definefontsynonym [SansBoldSlanted] [name:nimbussanlboldital]
 +
   \definefontsynonym [SansCaps]         [name:nimbussanlregu]
 
\stoptypescript
 
\stoptypescript
  
\definetypeface [nimbus] [rm] [serif] [nimbus]
+
% Define the typeface nimbus; use serif for rm-fonts, sans serif for ss-fonts.
\definetypeface [nimbus] [ss] [sans] [nimbus]
+
\definetypeface [nimbus] [rm] [serif] [nimbus]
 +
\definetypeface [nimbus] [ss] [sans] [nimbus]
  
 +
% Indicate the typeface to use.
 +
\usetypescript[nimbus][uc]
 
\setupbodyfont[nimbus,rm,10pt]
 
\setupbodyfont[nimbus,rm,10pt]
  
 
\starttext
 
\starttext
  
Regular
+
Regular, {\it Italic}, {\bf Bold}, {\bi Bold-Italic}, {\sc KaPiTaLe}
 
 
{\it Italic}
 
 
 
{\bf Bold}
 
 
 
{\bi Bold-Italic}
 
 
 
{\sc KaPiTaLe}
 
  
 
\showbodyfont
 
\showbodyfont
Line 78: Line 81:
 
</texcode>
 
</texcode>
  
Annotations:
+
Both scripts (serif and sans nimbus) map the fonts names to the different (existing) font style. Usage is implemented as follows:
* 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:
 
*# the scripts named ''[serif][nimbus]'' and
 
*# 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''
+
* The {{cmd|setupbodyfont}} command calls the ''typeface nimbus''.
# calls the ''typescript [serif][nimbus]'' for the rm-fonts
+
* The ''typeface nimbus'' calls the ''typescript [serif][nimbus]'' for {{cmd|rm}} fonts, or  ''typescript [sans][nimbus]'' for the {{cmd|ss}} fonts.
# calls the ''typescript [sans][nimbus]'' for the ss-fonts.
 
And inside these scripts the fonts are mapped to the different font styles.
 
  
==Small extension==
+
The scripts then map the fonts to different font styles.
  
To show how to call a typescript directly we extend the script a litte:
+
==Extension==
 +
 
 +
The fonts can be changed by extending the script:
  
 
<texcode>
 
<texcode>
Line 104: Line 97:
 
\stoptypescript
 
\stoptypescript
  
 +
% Define a typescript named nimbus.
 
\starttypescript [nimbus]
 
\starttypescript [nimbus]
 
   \definetypeface [nimbus] [rm] [serif] [nimbus]
 
   \definetypeface [nimbus] [rm] [serif] [nimbus]
Line 109: Line 103:
 
\stoptypescript
 
\stoptypescript
  
 +
% Use the nimbus typescript, which defines the nimbus typeface.
 
\usetypescript[nimbus]
 
\usetypescript[nimbus]
 
\setupbodyfont[nimbus,rm,10pt]
 
\setupbodyfont[nimbus,rm,10pt]
Line 116: Line 111:
 
</texcode>
 
</texcode>
  
Annotations:
+
Note that ''typeface [nimbus]'' and ''typescript [nimbus]'' are different.
* A thrid typescript is defined named ''[nimbus]''
+
 
* usetypescript calls the ''typescript [nimbus]'' in which the ''typeface [nimbus]'' is defined
+
Calling {{cmd|usetypescript}}[nimbus] ensures that the two {{cmd|definetypeface}} commands, embedded within {{cmd|starttypescript}}, as shown above, are called:
* ''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
+
  \definetypeface [nimbus] [rm]  [serif]  [nimbus]
 +
  \definetypeface [nimbus] [ss]  [sans]  [nimbus]
  
 
==References==
 
==References==
  
* [[Reference/en/setupbodyfont|setupbodyfont]]
+
* [[Command/setupbodyfont|setupbodyfont]]
* [[Reference/en/showbodyfont|showbodyfont]]
+
* [[Command/showbodyfont|showbodyfont]]
 
* definetypeface (not found in the references)
 
* definetypeface (not found in the references)
 
* starttypescript / stoptypescript (not found in the references)
 
* starttypescript / stoptypescript (not found in the references)
 
* definefontsynonym (not found in the references)
 
* definefontsynonym (not found in the references)

Latest revision as of 07:42, 30 January 2014


Overview

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.

Requirements

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:

/usr/share/fonts/type1/gsfonts

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

Script

Configure a font follows:

% Enable Unicode fonts
\enableregime[utf]

% Enable Capital Letter use
\setupcapitals[sc=yes]

% 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]
\stoptypescript

% 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]
\stoptypescript

% 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.
\usetypescript[nimbus][uc]
\setupbodyfont[nimbus,rm,10pt]

\starttext

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

\showbodyfont

\stoptext

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.

Extension

The fonts can be changed by extending the script:

...
\definefontsynonym [SansCaps]           [name:nimbusromno9lregu]
\stoptypescript

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

% Use the nimbus typescript, which defines the nimbus typeface.
\usetypescript[nimbus]
\setupbodyfont[nimbus,rm,10pt]

\starttext
...

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]

References

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