Fonts in LuaTeX
NOTE: This page is not finished yet |
Please, someone, fill this page !
This page is beeing regorganized
Contents
Good ol' typescripts
Of course, Mark IV allows you to use typescripts as you've always done; for example:
\usetypescript[palatino] \setupbodyfont[palatino,12pt] effe fietsen 2: \input tufte $\sqrt{2}$ \eogonek \sc effe fietsen 2: \input tufte $\sqrt{2}$ \eogonek
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:
\definefontfeature[smallcaps][language=DFLT,script=latn,smcp=yes] \font\palasmallcaps=texgyrepagella-regular*smallcaps \palasmallcaps This is a text in small capitals.
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
\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 }
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 GSUB
table (for Glyph SUBstitution) gives rules for replacing glyphs in certains circumstances (think of ligatures: f + i -> fi); the GPOS
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
\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]
Using System Fonts
LuaTeX can see system fonts if you set the OSFONTDIR
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 mtxrun --script font --list — in all the document.
I’m stick here :
\definefontfeature [myfontfeature] [method=node, kern=yes, OTHER_FEATURE_COMMA_SEPERATED] \definefontsynonym [MyFontRegular] [name:TheFontName-Regular][features=myfontfeature] \definedfont [MyFontRegular at 16pt]
This doesn’t run for my title which use « \tfc », only for the body of the text.
- \definefontfeature
- [myfontfeature] : you can use the name you want. It will be use at the next line ;
- the fonts feature can be found with otfinfo -f TheFontFile.otf.
- \definefontsynonym :
- [MyFontRegular] : you can use the name you want. It will be use at the next line ;
- The name after name: is the name given by mtxrun --script font --list
- The « name: » part can be replaced by file:TheFontFile.otf
Example
First run
$ mtxrun --script fonts --list --pattern=*warnock*
You'll get a list of fonts containing the string warnock
warnockprobold WarnockPro-Bold E:/Fonts/Warnock Pro/WarnockPro-Bold.otf warnockproboldcapt WarnockPro-BoldCapt E:/Fonts/Warnock Pro/WarnockPro-BoldCapt.otf warnockprobolddisp WarnockPro-BoldDisp E:/Fonts/Warnock Pro/WarnockPro-BoldDisp.otf warnockproboldit WarnockPro-BoldIt E:/Fonts/Warnock Pro/WarnockPro-BoldIt.otf warnockprobolditcapt WarnockPro-BoldItCapt E:/Fonts/Warnock Pro/WarnockPro-BoldItCapt.otf warnockprobolditdisp WarnockPro-BoldItDisp E:/Fonts/Warnock Pro/WarnockPro-BoldItDisp.otf warnockprobolditsubh WarnockPro-BoldItSubh E:/Fonts/Warnock Pro/WarnockPro-BoldItSubh.otf warnockproboldsubh WarnockPro-BoldSubh E:/Fonts/Warnock Pro/WarnockPro-BoldSubh.otf warnockprobook WarnockPro-Regular E:/Fonts/Warnock Pro/WarnockPro-Regular.otf warnockprocapt WarnockPro-Capt E:/Fonts/Warnock Pro/WarnockPro-Capt.otf warnockprocaptionbold WarnockPro-BoldCapt E:/Fonts/Warnock Pro/WarnockPro-BoldCapt.otf warnockprocaptionbook WarnockPro-Capt E:/Fonts/Warnock Pro/WarnockPro-Capt.otf warnockprodisp WarnockPro-Disp E:/Fonts/Warnock Pro/WarnockPro-Disp.otf warnockprodisplaybold WarnockPro-BoldDisp E:/Fonts/Warnock Pro/WarnockPro-BoldDisp.otf warnockprodisplaybook WarnockPro-Disp E:/Fonts/Warnock Pro/WarnockPro-Disp.otf warnockproit WarnockPro-It E:/Fonts/Warnock Pro/WarnockPro-It.otf warnockproitcapt WarnockPro-ItCapt E:/Fonts/Warnock Pro/WarnockPro-ItCapt.otf warnockproitdisp WarnockPro-ItDisp E:/Fonts/Warnock Pro/WarnockPro-ItDisp.otf warnockproitsubh WarnockPro-ItSubh E:/Fonts/Warnock Pro/WarnockPro-ItSubh.otf warnockprolight WarnockPro-Light E:/Fonts/Warnock Pro/WarnockPro-Light.otf warnockprolightcapt WarnockPro-LightCapt E:/Fonts/Warnock Pro/WarnockPro-LightCapt.otf warnockprolightcaptionlight WarnockPro-LightCapt E:/Fonts/Warnock Pro/WarnockPro-LightCapt.otf warnockprolightdisp WarnockPro-LightDisp E:/Fonts/Warnock Pro/WarnockPro-LightDisp.otf warnockprolightdisplaylight WarnockPro-LightDisp E:/Fonts/Warnock Pro/WarnockPro-LightDisp.otf warnockprolightit WarnockPro-LightIt E:/Fonts/Warnock Pro/WarnockPro-LightIt.otf warnockprolightitcapt WarnockPro-LightItCapt E:/Fonts/Warnock Pro/WarnockPro-LightItCapt.otf warnockprolightitdisp WarnockPro-LightItDisp E:/Fonts/Warnock Pro/WarnockPro-LightItDisp.otf warnockprolightitsubh WarnockPro-LightItSubh E:/Fonts/Warnock Pro/WarnockPro-LightItSubh.otf warnockprolightlight WarnockPro-Light E:/Fonts/Warnock Pro/WarnockPro-Light.otf warnockprolightsubh WarnockPro-LightSubh E:/Fonts/Warnock Pro/WarnockPro-LightSubh.otf warnockprolightsubheadlight WarnockPro-LightSubh E:/Fonts/Warnock Pro/WarnockPro-LightSubh.otf warnockproregular WarnockPro-Regular E:/Fonts/Warnock Pro/WarnockPro-Regular.otf warnockprosemibold WarnockPro-Semibold E:/Fonts/Warnock Pro/WarnockPro-Semibold.otf warnockprosemiboldcapt WarnockPro-SemiboldCapt E:/Fonts/Warnock Pro/WarnockPro-SemiboldCapt.otf warnockprosemibolddisp WarnockPro-SemiboldDisp E:/Fonts/Warnock Pro/WarnockPro-SemiboldDisp.otf warnockprosemiboldit WarnockPro-SemiboldIt E:/Fonts/Warnock Pro/WarnockPro-SemiboldIt.otf warnockprosemibolditcapt WarnockPro-SemiboldItCapt E:/Fonts/Warnock Pro/WarnockPro-SemiboldItCapt.otf warnockprosemibolditdisp WarnockPro-SemiboldItDisp E:/Fonts/Warnock Pro/WarnockPro-SemiboldItDisp.otf warnockprosemibolditsubh WarnockPro-SemiboldItSubh E:/Fonts/Warnock Pro/WarnockPro-SemiboldItSubh.otf warnockprosemiboldsubh WarnockPro-SemiboldSubh E:/Fonts/Warnock Pro/WarnockPro-SemiboldSubh.otf warnockprosmbdcaptiondemi WarnockPro-SemiboldCapt E:/Fonts/Warnock Pro/WarnockPro-SemiboldCapt.otf warnockprosmbddemi WarnockPro-Semibold E:/Fonts/Warnock Pro/WarnockPro-Semibold.otf warnockprosmbddisplaydemi WarnockPro-SemiboldDisp E:/Fonts/Warnock Pro/WarnockPro-SemiboldDisp.otf warnockprosmbdsubheaddemi WarnockPro-SemiboldSubh E:/Fonts/Warnock Pro/WarnockPro-SemiboldSubh.otf warnockprosubh WarnockPro-Subh E:/Fonts/Warnock Pro/WarnockPro-Subh.otf warnockprosubheadbold WarnockPro-BoldSubh E:/Fonts/Warnock Pro/WarnockPro-BoldSubh.otf warnockprosubheadbook WarnockPro-Subh E:/Fonts/Warnock Pro/WarnockPro-Subh.otf
Now to access, say the regular warnock font, the following are valid. And I ought to mention that Hans recommends the first http://article.gmane.org/gmane.comp.tex.context/43685.
% Hans recommends this format; \definefontsynonym [WarnockPro-Regular] [name:warnockproregular]
and
\definefontsynonym [WarnockPro-Regular] [name:WarnockPro-Regular]
An entire typescript would be defined as;
\definefontfeature[latin-smallcaps][smallcaps][script=latn] \starttypescript [serif] [warnockpro] \setups[font:fallback:sans] \definefontsynonym [WarnockPro-Regular] [name:WarnockPro-Regular] \definefontsynonym [WarnockPro-Bold] [name:WarnockPro-Bold] \definefontsynonym [WarnockPro-Italic] [name:WarnockPro-It] \definefontsynonym [WarnockPro-BoldItalic] [name:WarnockPro-BoldIt] \stoptypescript \starttypescript [serif] [warnockpro] \definefontsynonym [Serif] [WarnockPro-Regular] [features=default] \definefontsynonym [SerifBold] [WarnockPro-Bold] [features=default] \definefontsynonym [SerifItalic] [WarnockPro-Italic] [features=default] \definefontsynonym [SerifBoldItalic] [WarnockPro-BoldItalic] [features=default] \definefontsynonym [SerifCaps] [Serif] [features=latin-smallcaps] \stoptypescript \definetypeface[adobe][rm][serif][warnockpro][default] \setupbodyfont[adobe,11pt]