Changes

Jump to navigation Jump to search
5,687 bytes added ,  18:53, 31 May 2009
This page is beeing regorganized
'''Please, someone, fill this page !'''
'''This page is beeing regorganized'''
 
==== Good ol' typescripts ====
 
Of course, Mark IV allows you to use typescripts as you've always done; for example:
 
<texcode>
\usetypescript[palatino]
\setupbodyfont[palatino,12pt]
effe fietsen 2: \input tufte $\sqrt{2}$ \eogonek
 
\sc effe fietsen 2: \input tufte $\sqrt{2}$ \eogonek
</texcode>
 
That's as simple as using a traditional ConTeXt typescript!
 
But ... how is it any different, then? Well, the difference is that in Mark IV, we can use an Opentype font directly, so that what is done here: when we want to use Palatino, the [[TeX Gyre]] equivalent (“Pagella”) is called and we can use its Opentype “features”; read on.
 
==== Opentype features ====
 
A “feature”, in the Opentype jargon, is a set of rules describing changes in the appearance of the text. Hmm, that's not very precise. Let's show some examples. First of all, you have to know that features are referred to by 4-letter tags, and you will see this a lot. One of them is ‘smcp‘, for “small caps“. Let's consider the following Mark IV-only code:
 
<texcode>
\definefontfeature[smallcaps][language=DFLT,script=latn,smcp=yes]
\font\palasmallcaps=texgyrepagella-regular*smallcaps
\palasmallcaps This is a text in small capitals.
</texcode>
 
Here you basically define a (Mark IV) feature with the name ”smallcaps”, and associate it with the (Opentype) feature “smcp”. You have to specify which script you want to use it with; scripts in Opentype are also tagged with four letters, and “latn” is of course Latin.
 
Then you define a TeX font with that feature.
 
You can see what features are defined in a particular font with the following bit of code
 
<texcode>
\ctxlua
{
fontname = 'texgyrepagella-regular.otf'
 
--[[ First read the font data.
This makes heavy use of some of the Mark IV code]]
tfmdata = fonts.tfm.read_and_define("file:" .. fontname, 655360)
font = tfmdata.shared.otfdata
if font
then
gsubfeatures = fonts.otf.analyze_features(font.gsub)
gposfeatures = fonts.otf.analyze_features(font.gpos)
end
 
if gsubfeatures then
table.sort(gsubfeatures) % We want our list sorted alphabetically!
tex.sprint("\\rm GSUB features: \\tt ") % Beware: you don't want \rm to be interpreted by lua (\rm would yield carriage return + letter m)!
for _, feat in ipairs(gsubfeatures)
do tex.sprint(feat) tex.sprint(' ')
end
else tex.sprint("\\rm No GSUB features")
end
tex.sprint("\\par")
 
if gposfeatures then
tex.sprint("\\rm GPOS features: \\tt ")
table.sort(gposfeatures)
for _, feat in ipairs(gposfeatures)
do tex.sprint(feat) tex.sprint(' ')
end
else tex.sprint("\\rm No GPOS features")
end
}
</texcode>
 
It prints the list on the page. You'll notice there are two sets of features, each one of them defined in a different table of the Opentype font: the <code>GSUB</code> table (for Glyph SUBstitution) gives rules for replacing glyphs in certains circumstances (think of ligatures: f + i -> fi); the <code>GPOS</code> table (Glyph POSititioning) gives rules for moving glyphs (think of kerning: A + V -> A <kerning> V).
 
Incidentally, the above code gives some basic examples of LuaTeX programming, a mixture of both Lua and TeX programming with some special features (features in the general sense, not the Opentype one :-).
 
==== A (Complete) Typescript Example ====
 
<texcode>
\starttypescript [sans] [franklin]
 
\definefontsynonym [FranklinBookRegular] [name:FranklinGothicBookITC-Regular] [features=default]
\definefontsynonym [FranklinMediumRegular] [name:FranklinGothicMediumITC-Regular] [features=default]
\definefontsynonym [FranklinDemiRegular] [name:FranklinGothicDemiITC-Regular] [features=default]
\definefontsynonym [FranklinHeavyRegular] [name:FranklinGothicHeavyITC-Regular] [features=default]
\definefontsynonym [FranklinBookItalic] [name:FranklinGothicBookITC-Italic] [features=default]
\definefontsynonym [FranklinDemiItalic] [name:FranklinGothicMediumITC-Italic] [features=default]
\definefontsynonym [FranklinHeavyItalic] [name:FranklinGothicDemiITC-Italic] [features=default]
\definefontsynonym [FranklinMediumItalic] [name:FranklinGothicHeavyITC-Italic] [features=default]
 
\stoptypescript
 
\starttypescript [sans] [franklin]
 
\definefontsynonym [Sans] [FranklinBookRegular] [features=default]
\definefontsynonym [SansItalic] [FranklinBookItalic] [features=default]
\definefontsynonym [SansBold] [FranklinDemiRegular] [features=default]
\definefontsynonym [SansBoldItalic] [FranklinDemiItalic] [features=default]
\definefontsynonym [SansSlanted] [SansItalic] [features=default]
\definefontsynonym [SansBoldSlanted] [SansBoldItalic] [features=default]
\definefontsynonym [SansCaps] [Sans] [features=smallcaps]
 
\stoptypescript
 
\definetypeface[franklin][rm][sans][franklin][default]
\definetypeface[franklin][ss][sans][franklin][default]
\definetypeface[franklin][tt][mono][modern] [default][rscale=1.12]
\definetypeface[franklin][mm][math][iwona] [default][rscale=1.02]
 
\setupbodyfont[franklin,ss,10pt]
</texcode>
 
==== Using System Fonts ====
 
LuaTeX can see system fonts if you set the <code>OSFONTDIR</code> variable, for instance
set OSFONTDIR=c:/windows/fonts//
OSFONTDIR can contain a list of directories separated by semicolons, such as
export OSFONTDIR="/usr/local/share/fonts;$HOME/.fonts"
 
After installing new fonts or changing the value of OSFONTDIR, you must regenerate the font name database:
mtxrun --script font --reload
 
= Old contents =
Just the simplest way to use an otf font — or any font that does appear in <tt>mtxrun --script font --list</tt> — in all the document.
[[Category:Fonts]]
[[Category:International]]

Navigation menu