Difference between revisions of "TypeScripts - Old Content"

From Wiki
Jump to navigation Jump to search
(link to font install page)
(16 intermediate revisions by 9 users not shown)
Line 1: Line 1:
< [[Fonts]] >
+
Typescripts are the ConTeXt way of using fonts and defining font families.
  
Typescripts are the ConTeXt way of using fonts and defining font families.
+
Beware, the examples on this page work only with MkII / pdfTeX (i.e. neither XeTeX nor LuaTeX).
  
 
==Basics==
 
==Basics==
  
Sample typescript for the free text font [http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&item_id=Gentium Gentium]. Installation instructions are at [[Installing_a_TrueType_font,_step_by_step]].
+
Sample typescript for the free text font [http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&item_id=Gentium Gentium]. Installation instructions are at [[Installing a TrueType font, step by step - Old Content]].
A typescript must live in your project folder to be found, even if I'd prefer <tt>(texmf)/fonts/typescripts</tt>...
+
A typescript must live in your project folder or in another folder in your ConTeXt path (e.g., <tt>(texmf)/tex/context/user</tt>)
  
 
<texcode>
 
<texcode>
Line 13: Line 13:
  
 
% load mapfile
 
% load mapfile
\starttypescript [map] [\defaultencoding]
+
 
\loadmapfile [\defaultencoding-sil-gentium.map]
+
\starttypescript [map] [gentium] [\defaultencoding]
 +
    \loadmapfile [\defaultencoding-sil-gentium.map]
 
\stoptypescript
 
\stoptypescript
  
 
% mapping from PostScript name (or visible font name, if it's a TrueType font) to TFM file name
 
% mapping from PostScript name (or visible font name, if it's a TrueType font) to TFM file name
\starttypescript [serif] [gentium] [\defaultencoding]
+
% The second argument means that these names are loaded with either the 'gentium'
\definefontsynonym [GentiumAlt-Italic] [\defaultencoding-genai101][encoding=\defaultencoding]
+
% or 'gentium-alt' names.
\definefontsynonym [GentiumAlt] [\defaultencoding-genar101][encoding=\defaultencoding]
+
 
\definefontsynonym [Gentium-Italic] [\defaultencoding-geni101][encoding=\defaultencoding]
+
\starttypescript [serif] [gentium,gentium-alt] [\defaultencoding] % mapping is used by two "name" typescripts
\definefontsynonym [Gentium] [\defaultencoding-genr101][encoding=\defaultencoding]
+
    \definefontsynonym [Gentium]           [\defaultencoding-genr101] [encoding=\defaultencoding]
 +
    \definefontsynonym [Gentium-Italic]   [\defaultencoding-geni101] [encoding=\defaultencoding]
 +
    \definefontsynonym [GentiumAlt]       [\defaultencoding-genar101] [encoding=\defaultencoding]
 +
    \definefontsynonym [GentiumAlt-Italic] [\defaultencoding-genai101] [encoding=\defaultencoding]
 
\stoptypescript
 
\stoptypescript
  
 
% mapping from generic family name to PostScript name
 
% mapping from generic family name to PostScript name
\starttypescript [serif] [gentium] [name]
+
 
\definefontsynonym [Serif] [Gentium]
+
\starttypescript [serif] [gentium] [name]
\definefontsynonym [SerifItalic] [Gentium-Italic]
+
    \definefontsynonym [Serif]       [Gentium]
 +
    \definefontsynonym [SerifItalic] [Gentium-Italic]
 
\stoptypescript
 
\stoptypescript
  
 
% additional mapping to alternate glyphs, not further used
 
% additional mapping to alternate glyphs, not further used
\starttypescript [serif] [gentium-alt] [name]
+
 
\usetypescript [serif] [gentium] [\defaultencoding] % use font name mapping
+
\starttypescript [serif] [gentium-alt] [name]
\definefontsynonym [Serif] [GentiumAlt]
+
    \definefontsynonym [Serif]       [GentiumAlt]
\definefontsynonym [SerifItalic] [GentiumAlt-Italic]
+
    \definefontsynonym [SerifItalic] [GentiumAlt-Italic]
 
\stoptypescript
 
\stoptypescript
  
 
% sample family definition
 
% sample family definition
 
% here we define only the serif (rm) version.
 
% here we define only the serif (rm) version.
\starttypescript [my] [sil-gentium]
+
 
\definetypeface [sil-gentium] [rm] [serif] [gentium] [default][encoding=\defaultencoding]
+
\starttypescript [sil-gentium]
% \definetypeface [sil-gentium] [ss] [sans] [default] [default][encoding=\defaultencoding]
+
    \definetypeface [sil-gentium] [rm] [serif] [gentium] [default] [encoding=\defaultencoding]
% \definetypeface [sil-gentium] [tt] [mono] [default] [default][encoding=\defaultencoding]
+
%   \definetypeface [sil-gentium] [ss] [sans] [default] [default] [encoding=\defaultencoding]
% \definetypeface [sil-gentium] [mm] [math] [default] [default][encoding=\defaultencoding]
+
%   \definetypeface [sil-gentium] [tt] [mono] [default] [default] [encoding=\defaultencoding]
 +
%   \definetypeface [sil-gentium] [mm] [math] [default] [default] [encoding=\defaultencoding]
 
\stoptypescript
 
\stoptypescript
 
</texcode>
 
</texcode>
Line 54: Line 60:
 
<texcode>
 
<texcode>
 
\setupencoding[default=ec] % defines \defaultencoding
 
\setupencoding[default=ec] % defines \defaultencoding
 +
 
\usetypescriptfile[type-sil-gentium]
 
\usetypescriptfile[type-sil-gentium]
\usetypescript[my][sil-gentium]
 
\setupbodyfont [sil-gentium, rm, 12pt]
 
  
\setupbodyfontenvironment[default] [em=italic] % slanted is default emphasize in ConTeXt
+
\usetypescript[sil-gentium]
 +
\setupbodyfont[sil-gentium,rm,12pt]
 +
 
 +
\setupbodyfontenvironment [default] [em=italic] % slanted is default emphasize in ConTeXt
 
</texcode>
 
</texcode>
  
Line 80: Line 88:
 
% This is the first change we need to make: we list all the encodings it can match,
 
% This is the first change we need to make: we list all the encodings it can match,
 
% and then use that data within the typescript:
 
% and then use that data within the typescript:
\starttypescript [map]   [ec,texnansi,8r,t5,t2a,t2b,qx]
+
 
  \loadmapfile   [\typescripttwo-sil-gentium.map]
+
\starttypescript [map] [gentium] [ec,texnansi,8r,t5,t2a,t2b,qx]
 +
    \loadmapfile [\typescriptthree-sil-gentium.map]
 
\stoptypescript
 
\stoptypescript
  
 
% We use the same technique. As the encoding variable shows up in the third
 
% We use the same technique. As the encoding variable shows up in the third
 
% argument, we use \typescriptthree.
 
% argument, we use \typescriptthree.
% The second argument means that these names are loaded with either the 'gentium'
+
 
% or 'gentium-alt' names.
+
\starttypescript [serif] [gentium] [ec,texnansi,8r,t5,t2a,t2b,qx]
\starttypescript [serif] [gentium,gentium-alt] [ec,texnansi,8r,t5,t2a,t2b,qx]
+
    \definefontsynonym [Gentium]           [\typescriptthree-genr101] [encoding=\typescriptthree]
  \definefontsynonym [GentiumAlt-Italic] [\typescriptthree-genai101][encoding=\typescriptthree]
+
    \definefontsynonym [Gentium-Italic]   [\typescriptthree-geni101] [encoding=\typescriptthree]
  \definefontsynonym [GentiumAlt]       [\typescriptthree-genar101][encoding=\typescriptthree]
+
    \definefontsynonym [GentiumAlt]       [\typescriptthree-genar101][encoding=\typescriptthree]
  \definefontsynonym [Gentium-Italic]   [\typescriptthree-geni101] [encoding=\typescriptthree]
+
    \definefontsynonym [GentiumAlt-Italic] [\typescriptthree-genai101][encoding=\typescriptthree]
  \definefontsynonym [Gentium]           [\typescriptthree-genr101] [encoding=\typescriptthree]
 
 
\stoptypescript
 
\stoptypescript
  
% We use the new (and fast loading) font fallbacks to cover bold markup.
+
% Getting fancy: occasionally you want to access alternates from the main font:
\starttypescript  [serif] [gentium]      [name]
 
  \setups            [font:fallback:serif]
 
  \definefontsynonym  [Serif]            [Gentium]
 
  \definefontsynonym  [SerifItalic]      [Gentium-Italic]
 
\stoptypescript
 
  
% The 'gentium-alt' script differs from its brother above in the fonts it points to.
+
\starttypescript [serif] [gentium] [name]
\starttypescript [serif] [gentium-alt] [name]
+
    \setups [font:fallback:serif] % We use the new (and fast loading) font fallbacks to cover bold markup.
  \setups             [font:fallback:serif]
+
    \definefontsynonym [Serif]               [Gentium]
  \definefontsynonym [Serif]           [GentiumAlt]
+
    \definefontsynonym [SerifItalic]        [Gentium-Italic]
  \definefontsynonym  [SerifItalic]     [GentiumAlt-Italic]
+
    % Gentium contains only two faces, so we map everything else on Italic
 +
    \definefontsynonym [SerifSlanted]        [SerifItalic]
 +
    \definefontsynonym [SerifBoldItalic]    [SerifItalic]
 +
    \definefontsynonym [SerifCaps]          [SerifItalic]
 +
    \definefontsynonym [SerifBoldCaps]      [SerifItalic]
 +
    % markup of \Var[alt] results in a (subtle) font switch (Gentium's alternate glyphs change only some diacritics):
 +
    \definefontvariant [Serif] [alt] [Alt]
 +
    % unfortunately you need to define eight synonyms to handle the fallback cases:
 +
    \definefontsynonym [SerifRegular]        [Serif]
 +
    \definefontsynonym [SerifRegularAlt]    [GentiumAlt] % you must define "Regular" for every additional variant
 +
    \definefontsynonym [SerifBoldAlt]        [GentiumAlt]
 +
    \definefontsynonym [SerifCapsAlt]        [GentiumAlt]
 +
    \definefontsynonym [SerifItalicAlt]      [GentiumAlt-Italic]
 +
    \definefontsynonym [SerifSlantedAlt]    [GentiumAlt-Italic]
 +
    \definefontsynonym [SerifBoldItalicAlt] [GentiumAlt-Italic]
 +
    \definefontsynonym [SerifBoldSlantedAlt] [GentiumAlt-Italic]
 
\stoptypescript
 
\stoptypescript
  
 
% sample family definition
 
% sample family definition
 
% here we define only the serif (rm) version.
 
% here we define only the serif (rm) version.
\starttypescript  [sil-gentium] [ec,texnansi,8r,t5,t2a,t2b,qx]
 
  \definetypeface  [sil-gentium] [rm] [serif] [gentium] [default] [encoding=\typescripttwo]
 
% \definetypeface  [sil-gentium] [ss] [sans]  [default] [default] [encoding=\typescripttwo]
 
% \definetypeface  [sil-gentium] [tt] [mono]  [default] [default] [encoding=\typescripttwo]
 
% \definetypeface  [sil-gentium] [mm] [math]  [default] [default] [encoding=\typescripttwo]
 
\stoptypescript
 
  
% Getting fancy: occasionally you want to access alternates from the main font:
+
\starttypescript [sil-gentium] [ec,texnansi,8r,t5,t2a,t2b,qx]
\starttypescript [serif] [gentium]     [name]
+
    \definetypeface [sil-gentium] [rm] [serif] [gentium] [default] [encoding=\typescripttwo]
% unfortunately you need to define eight synonyms to handle the fallback cases:
+
%   \definetypeface [sil-gentium] [ss] [sans] [default] [default] [encoding=\typescripttwo]
  \definefontsynonym [SerifRegular]       [Serif]
+
%   \definetypeface [sil-gentium] [tt] [mono]  [default] [default] [encoding=\typescripttwo]
  \definefontsynonym [SerifRegularAlt]     [GentiumAlt]
+
%   \definetypeface [sil-gentium] [mm] [math] [default] [default] [encoding=\typescripttwo]
   \definefontsynonym [SerifBoldAlt]       [GentiumAlt]
 
  \definefontsynonym [SerifCapsAlt]       [GentiumAlt]
 
  \definefontsynonym [SerifItalicAlt]     [GentiumAlt-Italic]
 
   \definefontsynonym [SerifSlantedAlt]     [GentiumAlt-Italic]
 
  \definefontsynonym [SerifBoldItalicAlt]  [GentiumAlt-Italic]
 
   \definefontsynonym [SerifBoldSlantedAlt] [GentiumAlt-Italic]
 
 
 
% markup of \Var[alt] results in a (subtle) font switch:
 
  \definefontvariant [Serif] [alt] [Alt]
 
 
\stoptypescript
 
\stoptypescript
  
Line 138: Line 141:
 
==Links==
 
==Links==
 
* [http://www.pragma-ade.com/general/manuals/showfont.pdf examples of using typescripts] by Pragma
 
* [http://www.pragma-ade.com/general/manuals/showfont.pdf examples of using typescripts] by Pragma
* [http://www.ramm.ch/fiee/texnique/?menu=0-1-4&amp;lang=en example typescripts] for free and commercial fonts, by Hraban (partly outdated)
+
* Sample of [http://wiki.contextgarden.net/exljbris_typescript MkIV  typescripts for exljbris fonts]
 
* typescripts for some fonts from the FontSite500 CD on the [[Font Site]] page, by Holger Schöner
 
* typescripts for some fonts from the FontSite500 CD on the [[Font Site]] page, by Holger Schöner
 
* typescripts for lazy font combinations on the [[Flexi Face]] page
 
* typescripts for lazy font combinations on the [[Flexi Face]] page
 
* some pointers on extending typescripts to accommodate access to &ldquo;variants,&rdquo; like old-style figures, are on the [[Font Variants]] page
 
* some pointers on extending typescripts to accommodate access to &ldquo;variants,&rdquo; like old-style figures, are on the [[Font Variants]] page
* [[Fonts in XeTeX]] gives some details about the [[XeTeX]]-specific typescripts in <tt>type-xtx</tt>
+
* [[Fonts in XeTeX - Old Content]] gives some details about the [[XeTeX]]-specific typescripts in <tt>type-xtx</tt>
 +
 
 +
[[Category:Old Content]]

Revision as of 19:55, 3 June 2020

Typescripts are the ConTeXt way of using fonts and defining font families.

Beware, the examples on this page work only with MkII / pdfTeX (i.e. neither XeTeX nor LuaTeX).

Basics

Sample typescript for the free text font Gentium. Installation instructions are at Installing a TrueType font, step by step - Old Content. A typescript must live in your project folder or in another folder in your ConTeXt path (e.g., (texmf)/tex/context/user)

% type-sil-gentium.tex
% Typescript for serif family SIL Gentium

% load mapfile

\starttypescript [map] [gentium] [\defaultencoding]
    \loadmapfile [\defaultencoding-sil-gentium.map]
\stoptypescript

% mapping from PostScript name (or visible font name, if it's a TrueType font) to TFM file name
% The second argument means that these names are loaded with either the 'gentium'
% or 'gentium-alt' names.

\starttypescript [serif] [gentium,gentium-alt] [\defaultencoding] % mapping is used by two "name" typescripts
    \definefontsynonym [Gentium]           [\defaultencoding-genr101]  [encoding=\defaultencoding]
    \definefontsynonym [Gentium-Italic]    [\defaultencoding-geni101]  [encoding=\defaultencoding]
    \definefontsynonym [GentiumAlt]        [\defaultencoding-genar101] [encoding=\defaultencoding]
    \definefontsynonym [GentiumAlt-Italic] [\defaultencoding-genai101] [encoding=\defaultencoding]
\stoptypescript

% mapping from generic family name to PostScript name

\starttypescript [serif] [gentium] [name]
    \definefontsynonym [Serif]       [Gentium]
    \definefontsynonym [SerifItalic] [Gentium-Italic]
\stoptypescript

% additional mapping to alternate glyphs, not further used

\starttypescript [serif] [gentium-alt] [name]
    \definefontsynonym [Serif]       [GentiumAlt]
    \definefontsynonym [SerifItalic] [GentiumAlt-Italic]
\stoptypescript

% sample family definition
% here we define only the serif (rm) version.

\starttypescript [sil-gentium]
    \definetypeface [sil-gentium] [rm] [serif] [gentium] [default] [encoding=\defaultencoding]
%   \definetypeface [sil-gentium] [ss] [sans]  [default] [default] [encoding=\defaultencoding]
%   \definetypeface [sil-gentium] [tt] [mono]  [default] [default] [encoding=\defaultencoding]
%   \definetypeface [sil-gentium] [mm] [math]  [default] [default] [encoding=\defaultencoding]
\stoptypescript

The multiple mapping is not strictly needed, but increases flexibility.

To use your new typescript, write the following in your environment file (or single TeX file):

\setupencoding[default=ec] % defines \defaultencoding

\usetypescriptfile[type-sil-gentium]

\usetypescript[sil-gentium]
\setupbodyfont[sil-gentium,rm,12pt]

\setupbodyfontenvironment [default] [em=italic] % slanted is default emphasize in ConTeXt

The map file was written by texfont and lives in (texmf)/fonts/map/pdftex/context. It combines raw TFM (metrics), PostScript name, font file and encoding

% ec-sil-gentium.map
ec-raw-genai101 GentiumAlt-Italic 4 < genai101.pfb ec.enc
ec-raw-genar101 GentiumAlt 4 < genar101.pfb ec.enc
ec-raw-geni101 Gentium-Italic 4 < geni101.pfb ec.enc
ec-raw-genr101 Gentium 4 < genr101.pfb ec.enc

The next step: making it more generic

If you'd like to write a typescript that handles many more encodings, somewhat more generically, here is one model to build upon:

% type-sil-gentium.tex
% Typescript for serif family SIL Gentium

% This is the first change we need to make: we list all the encodings it can match,
% and then use that data within the typescript:

\starttypescript [map] [gentium] [ec,texnansi,8r,t5,t2a,t2b,qx]
    \loadmapfile [\typescriptthree-sil-gentium.map]
\stoptypescript

% We use the same technique. As the encoding variable shows up in the third
% argument, we use \typescriptthree.

\starttypescript [serif] [gentium] [ec,texnansi,8r,t5,t2a,t2b,qx]
    \definefontsynonym [Gentium]           [\typescriptthree-genr101] [encoding=\typescriptthree]
    \definefontsynonym [Gentium-Italic]    [\typescriptthree-geni101] [encoding=\typescriptthree]
    \definefontsynonym [GentiumAlt]        [\typescriptthree-genar101][encoding=\typescriptthree]
    \definefontsynonym [GentiumAlt-Italic] [\typescriptthree-genai101][encoding=\typescriptthree]
\stoptypescript

% Getting fancy: occasionally you want to access alternates from the main font:

\starttypescript [serif] [gentium] [name]
    \setups [font:fallback:serif] % We use the new (and fast loading) font fallbacks to cover bold markup.
    \definefontsynonym [Serif]               [Gentium]
    \definefontsynonym [SerifItalic]         [Gentium-Italic]
    % Gentium contains only two faces, so we map everything else on Italic
    \definefontsynonym [SerifSlanted]        [SerifItalic]
    \definefontsynonym [SerifBoldItalic]     [SerifItalic]
    \definefontsynonym [SerifCaps]           [SerifItalic]
    \definefontsynonym [SerifBoldCaps]       [SerifItalic]
    % markup of \Var[alt] results in a (subtle) font switch (Gentium's alternate glyphs change only some diacritics):
    \definefontvariant [Serif] [alt] [Alt]
    % unfortunately you need to define eight synonyms to handle the fallback cases:
    \definefontsynonym [SerifRegular]        [Serif]
    \definefontsynonym [SerifRegularAlt]     [GentiumAlt] % you must define "Regular" for every additional variant
    \definefontsynonym [SerifBoldAlt]        [GentiumAlt]
    \definefontsynonym [SerifCapsAlt]        [GentiumAlt]
    \definefontsynonym [SerifItalicAlt]      [GentiumAlt-Italic]
    \definefontsynonym [SerifSlantedAlt]     [GentiumAlt-Italic]
    \definefontsynonym [SerifBoldItalicAlt]  [GentiumAlt-Italic]
    \definefontsynonym [SerifBoldSlantedAlt] [GentiumAlt-Italic]
\stoptypescript

% sample family definition
% here we define only the serif (rm) version.

\starttypescript [sil-gentium] [ec,texnansi,8r,t5,t2a,t2b,qx]
    \definetypeface [sil-gentium] [rm] [serif] [gentium] [default] [encoding=\typescripttwo]
%   \definetypeface [sil-gentium] [ss] [sans]  [default] [default] [encoding=\typescripttwo]
%   \definetypeface [sil-gentium] [tt] [mono]  [default] [default] [encoding=\typescripttwo]
%   \definetypeface [sil-gentium] [mm] [math]  [default] [default] [encoding=\typescripttwo]
\stoptypescript

Links