summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/fonts/fonts/fonts-lookups.tex
blob: e9448b88456e49c265f41c29fe09534d7c635871 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
% language=uk

\startcomponent fonts-lookups

\environment fonts-environment

\startchapter[title=Lookups][color=darkblue]

\startsection[title=Introduction]

In traditional \TEX\ a font is defined by referring to its filename. A
definition looks like this:

\starttyping
\font \MyFontA = lmr10
\font \MyFontB = lmr10 at 20pt
\font \MyFontC = lmr10 scaled 1500
\stoptyping

The first definition defines the command \type {MyFontA} as a reference to the
font stored in the file \type {lmx10}. No scaling takes place so the natural size
is taken. This so called designsize is in no way standardized. Just look at these
three specimen:

\startlines
{\definedfont[file:dejavuserif*default]Design Size (Dejavu)}
{\definedfont[file:cambria*default]Design Size (Cambria)}
{\definedfont[file:lmroman10-regular*default]Design Size (Latin Modern)}
\stoplines

The designsize is normally 10 point, but as there is no real reference for this a
designer decides how to translate this into a visual representation. As a
consequence the \type {20pt} in the second line of the example definitions only
means that the font is scaled to (normally) twice the designsize. The third line
scaled by a factor \type {1.5} and the reason for using a value thousand times
larger is that \TEX's numbers are integers.

The next three lines are typical for Latin Modern (derived from Computer Modern)
because this family comes in different design sizes.

\starttyping
\font \MyFontD = lmr12
\font \MyFontE = lmr12 at 20pt
\font \MyFontF = lmr12 scaled 1500
\stoptyping

Because the designsize is part of the font metrics the second line (\type
{\MyFontE}) is of similar size as \type {\MyFontB} although the 12~point variant
is visually better suited for scaling up.

These definitions refer to files, but what file? What gets loaded is the file
with name \type {name.tfm}. Eventually for embedding in the (let's assume \PDF)
file the outlines are taken from \type {name.pfb}. At that stage, when present, a
\type {name.vf} is consulted in order to resolve characters that are combinations
of others (potentially from other \type {pfb} files). The mapping from \type
{name.tfm} to \type {name.pfb} filename happens in the so called map file. This
means that one can also refer to another file, for instance \type {name.ttf}.

All this logic is hard coded in the engine and because the virtual font mechanism
was introduced later without extending the \type {tfm} format, it can be hard at
times to figure out issues when a (maybe obsolete) virtual file is present (this
can be the case if you have generated the \type {tfm} file from an \type {afm}
file that comes with the \type {pfb} file when you buy one.

But, in \LUATEX\ we no longer use traditional fonts and as a consequence we have
more options open. Before we move on to them, we mention yet another definition:

\starttyping
\font \MyFontG = lmr12 sa 1.2
\stoptyping

This method is not part of \TEX\ but is provided by \CONTEXT, \MKII\ as well as
\MKIV. It means as much as \quotation {scale this font to 1.2 times the
bodyfontsize}. As this involves parsing the specification, it does not work
as advertised here, but the next definition works okay:

\starttyping
\definefont[MyFontG][lmr12 sa 1.2]
\stoptyping

This indicates that we already had a parser for font specifications on board
which in turn made it relatively easy to do even more parsing, for instance for
font features as introduced in \XETEX\ and \LUATEX.

\stopsection

\startsection[title=Specifications]

In \LUATEX\ we intercept the font loader. We do so for several reasons.

\startitemize[packed]

\startitem We want to make decisions on what file to load, this is needed when
for instance there are files with the same name but different properties. \stopitem

\startitem We want to be able to lookup by file, by name, and by more abstract specification.
In doing so, we want to be as tolerant as possible. \stopitem

\startitem We want to support several scaling methods, as discussed in the previous section. \stopitem

\startitem We want to implement several strategies for passing features and defining non
standard approaches. \stopitem

\stopitemize

The formal specification of a font is as follows:

\starttyping
\definefont[PublicReference][filename]
\definefont[PublicReference][filename at dimension]
\definefont[PublicReference][filename scaled number]
\stoptyping

We already had that extended to:

\starttyping
\definefont[PublicReference][filename]
\definefont[PublicReference][filename at dimension]
\definefont[PublicReference][filename scaled number]
\definefont[PublicReference][filename sa number]
\stoptyping

So let's generalize that to:

\starttyping
\definefont[PublicReference][filename scaling]
\stoptyping

And in \MKIV\ we now have:

\starttyping
\definefont[PublicReference][filename*featurenames scaling]
\definefont[PublicReference][filename:featurespecication scaling]
\definefont[PublicReference][filename@virtualconstructor scaling]
\stoptyping

The second variant is seldom used and is only provided because some users
have fonts defined in the \XETEX\ way. Users are advised not to use this
method. The last method is special in the sense that it's used to define
fonts that are constructed using the built in virtual font constructors. This
method is for instance used for defining virtual math fonts.

The first method is what we use most. It is really important not to forget the
feature specification. A rather safe bet is \type {*default}. In a next chapter
we will discuss the difference between these two; here we focus on the name part.

The \type {filename} is in fact a symbolic name. In \CONTEXT\ we have always used
an indirect reference to fonts. Look at this:

\starttyping
\definefont[TitleFont][SerifBold*default sa 2]
\stoptyping

A reference like \type {SerifBold} makes it possible to define styles independent
of the chosen font family. This reference eventually gets resolved to a real
name and there can be a chain of references.

Font definitions can be grouped into a larger setup using typescripts. In that
case, we can set the features for a regular, italic, bold and bolditalic for the
whole set but when a fontname has a specific feature associated (as in the
previous examples) that one takes precedence.

so far we talked about fonts being files, but in practice a lookup happens by
file as well as by name as known to the system. In the next section this will be
explained in more detail.

\stopsection

\startsection[title=File]

You can force a file lookup with:

\starttyping
\definefont[TitleFont][file:somefilename*default sa 2]
\stoptyping

If you use more symbolic names you can use the \type {file:} prefix in the
mapping:

\starttyping
\definefontsynonym[SerifBold][file:somefile]
\definefont[TitleFont][SerifBold*default sa 2]
\stoptyping

In projects that are supposed to run for a long time I always use the file based
lookup, because filenames tend to be rather stable. Also, as the lookup happens
in the \TEX\ directory structure, file lookups will rely on the general file
search routines. This has the benefit that case is ignored. When no match is found
the lookup will also use the font name database. Spaces and special characters are
ignored.

The name alone is not enough as there can be similar filenames with different
suffixes. Therefore the lookup will happen in the order \ctxcommand {
concatcommalist { list = fonts.readers.sequence, separator = ", ", last = " and
", command = "type" } }. You can force a lookup by being more explicit, like:

\starttyping
\definefont[TitleFont][file:somefilename.ttf*default sa 1]
\stoptyping

\stopsection

\startsection[title=Name]

Say that we want to use a Dejavu font and that instead of filenames we want to
use its given name. The best way to find out what is available is to call for a
list:

\starttyping
mtxrun --script font --list --all dejavu
\stoptyping

This produces the following list:

\startnarrowtyping
dejavusans                     dejavusans                     dejavusans.ttf
dejavusansbold                 dejavusansbold                 dejavusans-bold.ttf
dejavusansboldoblique          dejavusansboldoblique          dejavusans-boldoblique.ttf
dejavusanscondensed            dejavusanscondensed            dejavusanscondensed.ttf
dejavusanscondensedbold        dejavusanscondensedbold        dejavusanscondensed-bold.ttf
dejavusanscondensedboldoblique dejavusanscondensedboldoblique dejavusanscondensed-boldoblique.ttf
dejavusanscondensednormal      dejavusanscondensed            dejavusanscondensed.ttf
dejavusanscondensedoblique     dejavusanscondensedoblique     dejavusanscondensed-oblique.ttf
dejavusansextralight           dejavusansextralight           dejavusans-extralight.ttf
dejavusanslight                dejavusansextralight           dejavusans-extralight.ttf
dejavusansmono                 dejavusansmono                 dejavusansmono.ttf
dejavusansmonobold             dejavusansmonobold             dejavusansmono-bold.ttf
dejavusansmonoboldoblique      dejavusansmonoboldoblique      dejavusansmono-boldoblique.ttf
dejavusansmononormal           dejavusansmonooblique          dejavusansmono-oblique.ttf
dejavusansmonooblique          dejavusansmonooblique          dejavusansmono-oblique.ttf
dejavusansnormal               dejavusans                     dejavusans.ttf
dejavusansoblique              dejavusansoblique              dejavusans-oblique.ttf
dejavuserif                    dejavuserif                    dejavuserif.ttf
dejavuserifbold                dejavuserifbold                dejavuserif-bold.ttf
dejavuserifbolditalic          dejavuserifbolditalic          dejavuserif-bolditalic.ttf
dejavuserifcondensed           dejavuserifcondensed           dejavuserifcondensed.ttf
dejavuserifcondensedbold       dejavuserifcondensedbold       dejavuserifcondensed-bold.ttf
dejavuserifcondensedbolditalic dejavuserifcondensedbolditalic dejavuserifcondensed-bolditalic.ttf
dejavuserifcondenseditalic     dejavuserifcondenseditalic     dejavuserifcondensed-italic.ttf
dejavuserifcondensednormal     dejavuserifcondensed           dejavuserifcondensed.ttf
dejavuserifitalic              dejavuserifitalic              dejavuserif-italic.ttf
dejavuserifnormal              dejavuserif                    dejavuserif.ttf
\stopnarrowtyping

The first two columns mention the names that we can use to access a font. These
are normalized names in the sense that we only kept letters and numbers. The next three
definitions are equivalent:

\starttyping
\definefont[TitleFont][name:dejavuserif*default sa 1]
\definefont[TitleFont][name:dejavuserifnormal*default sa 1]
\definefont[TitleFont][name:dejavuserif.ttf*default sa 1]
\stoptyping

In the list you see two names that all point to \type {dejavusans-extralight.ttf}:

\starttyping
dejavusansextralight
dejavusanslight
\stoptyping

There are some heuristics built into \CONTEXT\ and we do some cleanup as well.
For instance we interpret \type {ital} as \type {italic}. In a font there is
sometimes information about the weight and we look at those properties as well.
Unfortunately font names (even within a collection) are often rather inconsistent
so you still need to know what you're looking for. The more explicit you are, the
less change of problems.

\stopsection

\startsection[title=Spec]

There is often some logic in naming fonts but it's not robust and really depends on
how consistent a font designer or typefoundry has been. In \CONTEXT\ we can
access names by using a normalized scheme.

\starttyping
name-weight-style-width-variant
\stoptyping

The following values are valid:

\starttabulate[|Bl|Tp|]
\NC weight  \NC \ctxcommand { concatcommalist { list = fonts.names.knownweights  } } \NC \NR
\NC style   \NC \ctxcommand { concatcommalist { list = fonts.names.knownstyles   } } \NC \NR
\NC width   \NC \ctxcommand { concatcommalist { list = fonts.names.knownwidths   } } \NC \NR
\NC variant \NC \ctxcommand { concatcommalist { list = fonts.names.knownvariants } } \NC \NR
\stoptabulate

The four specifiers are optional but the more you provide, the better the match. Let's
give an example:

\starttyping
mtxrun --script fonts --list --spec dejavu
\stoptyping

This reports:

\startnarrowtyping
dejavuserifcondensed normal normal normal normal dejavuserifcondensed dejavuserifcondensed.ttf
dejavuserif          normal normal normal normal dejavuserif          dejavuserif.ttf
dejavusansmono       normal normal normal normal dejavusansmono       dejavusansmono.ttf
dejavusanscondensed  normal normal normal normal dejavusanscondensed  dejavusanscondensed.ttf
dejavusans           normal normal normal normal dejavusans           dejavusans.ttf
\stopnarrowtyping

We can be more specific, for instance:

\starttyping
mtxrun --script fonts --list --spec dejavu-bold
\stoptyping

\startnarrowtyping
dejavuserif    bold normal normal normal dejavuserifbold    dejavuserif-bold.ttf
dejavusansmono bold normal normal normal dejavusansmonobold dejavusansmono-bold.ttf
dejavusans     bold normal normal normal dejavusansbold     dejavusans-bold.ttf
\stopnarrowtyping

We add another specifier:

\starttyping
mtxrun --script fonts --list --spec dejavu-bold-italic
\stoptyping

\startnarrowtyping
dejavuserif    bold italic normal normal dejavuserifbolditalic     dejavuserif-bolditalic.ttf
dejavusansmono bold italic normal normal dejavusansmonoboldoblique dejavusansmono-boldoblique.ttf
dejavusans     bold italic normal normal dejavusansboldoblique     dejavusans-boldoblique.ttf
\stopnarrowtyping

As the first hit is used we need to be more specific with respect to the
name, so lets do that in an example definition:

\starttyping
\definefont[TitleFont][spec:dejavuserif-bold-italic*default sa 1]
\stoptyping

Watch the prefix \type {spec}. Wolfgang Schusters \type {simplefonts} module
nowadays uses this method to define sets of fonts based on a name only
specification. Of course that works best if a fontset has well defined
properties.

\stopsection

\startsection[title=Selectfont]

The selectfont interface by Wolfgang Schuster can be used to define fonts
by name. For a long term project workflow you probably want to use filenames
but for average use names do well:

\starttyping
\definefontfamily [mainface] [serif] [DejaVu Serif]
\definefontfamily [mainface] [sans]  [DejaVu Sans]
\definefontfamily [mainface] [mono]  [DejaVu Sans Mono] [features=none]
\definefontfamily [mainface] [math]  [Dejavu Math]
\stoptyping

This setup is triggered in the usual way:

\starttyping
\setupbodyfont[mainface]
\stoptyping

When you combine different designs you may need to apply a relative scale:

\starttyping
\definefontfamily [mainface] [math]  [XITS Math] [rscale=1.1]
\stoptyping

Some fonts come in designsizes, like Latin Modern:

\starttyping
\definefontfamily
  [mainface]
  [serif]
  [Latin Modern Roman]
  [designsize=auto]
\stoptyping

You can define fallbacks, for example:

\starttyping
\definefallbackfamily
  [mainface]
  [serif]
  [DejaVu Serif]
  [range=cyrillic]

\definefontfamily [mainface] [serif] [TeX Gyre Pagella]
\stoptyping

Here Pagella is used with missing characters taken from Dejavu. The ranges
are defined with:

\starttyping
\definefontfamilypreset
  [range:cyrillic]
  [range={cyrillic,
          cyrillicextendeda,
          cyrillicextendedb,
          cyrillicsupplement}]
\stoptyping

For more details you can consult the wiki and the source file \type {font-sel.mkvi}.

\stopsection

\stopchapter

\stopcomponent