hybrid-fontnames.tex /size: 19 Kb    last modification: 2023-12-21 09:43
1% language=us
2
3\startcomponent hybrid-fontnames
4
5\environment hybrid-environment
6
7\startchapter[title={The font name mess}]
8
9\startsection [title={Introduction}]
10
11When \TEX\ came around it shipped with its own fonts. At that moment the \TEX\
12font universe was a small and well known territory. The \quote {only} hassle was
13that one needed to make sure that the right kind of bitmap was available for the
14printer.
15
16When other languages than English came into the picture things became more
17complex as now fonts instances in specific encodings showed up. After a couple of
18years the by then standardised \TEX\ distributions carried tens of thousands of
19font files. The reason for this was simple: \TEX\ fonts could only have 256
20characters and therefore there were quite some encodings. Also, large \CJK\ fonts
21could easily have hundreds of metric files per font. Distributions also provide
22metrics for commercial fonts although I could never use them and as a result have
23many extra metric files in my personal trees (generated by \TEXFONT). \footnote
24{Distributions like \TEX Live have between 50.000 and 100.000 files, but
25derivatives like the \CONTEXT\ minimals are much smaller.}
26
27At the input side many problems related to encodings were solved by \UNICODE. So,
28when the more \UNICODE\ aware fonts showed up, it looked like things would become
29easier. For instance, no longer were choices for encodings needed. Instead one
30had to choose features and enable languages and scripts and so the problem of the
31multitude of files was replaced by the necessity to know what some font actually
32provides. But still, for the average user it can be seen as an improvement.
33
34A rather persistent problem remained, especially for those who want to use
35different fonts and or need to install fonts on the system that come from
36elsewhere (either free or commercial): the names used for fonts. You may argue
37that modern \TEX\ engines and macro packages can make things easier, especially
38as one can call up fonts by their names instead of their filenames, but actually
39the problem has worsened. With traditional \TEX\ you definitely get an error when
40you mistype a filename or call for a font that is not on your system. The more
41modern \TEX's macro packages can provide fallback mechanisms and you can end up
42with something you didn't ask for.
43
44For years one of the good things of \TEX\ was its stability. If we forget about
45changes in content, macro packages and|/|or hyphenation patterns, documents could
46render more or less the same for years. This is because fonts didn't change.
47However, now that fonts are more complex, bugs gets fixed and thereby results can
48differ. Or, if you use platform fonts, your updated operating system might have
49new or even different variants. Or, if you access your fonts by fontname, a
50lookup can resolve differently.
51
52The main reason for this is that fontnames as well as filenames of fonts are
53highly inconsistent across vendors, within vendors and platforms. As we have to
54deal with this matter, in \MKIV\ we have several ways to address a font: by
55filename, by fontname, and by specification. In the next sections I will describe
56all three.
57
58\stopsection
59
60\startsection [title={Method 1: file}]
61
62The most robust way to specify what fonts is to be used is the filename. This is
63done as follows:
64
65\starttyping
66\definefont[SomeFont][file:lmmono10-regular]
67\stoptyping
68
69A filename lookup is case insensitive and the name you pass is exact. Of course
70the \type {file:} prefix (as with any prefix) can be used in font synonyms as
71well. You may add a suffix, so this is also valid:
72
73\starttyping
74\definefont[SomeFont][file:lmmono10-regular.otf]
75\stoptyping
76
77By default \CONTEXT\ will first look for an \OPENTYPE\ font so in both cases you
78will get such a font. But how do you know what the filename is? You can for
79instance check it out with:
80
81\starttyping
82mtxrun --script font --list --file --pattern="lm*mono"
83\stoptyping
84
85This reports some information about the file, like the weight, style, width,
86fontname, filename and optionally the subfont id and a mismatch between the
87analysed weight and the one mentioned by the font.
88
89\startntyping
90latinmodernmonolight       light    normal   normal      lmmonolt10regular           lmmonolt10-regular.otf
91latinmodernmonoproplight   light    italic   normal      lmmonoproplt10oblique       lmmonoproplt10-oblique.otf
92latinmodernmono            normal   normal   normal      lmmono9regular              lmmono9-regular.otf
93latinmodernmonoprop        normal   italic   normal      lmmonoprop10oblique         lmmonoprop10-oblique.otf
94latinmodernmono            normal   italic   normal      lmmono10italic              lmmono10-italic.otf
95latinmodernmono            normal   normal   normal      lmmono8regular              lmmono8-regular.otf
96latinmodernmonolightcond   light    italic   condensed   lmmonoltcond10oblique       lmmonoltcond10-oblique.otf
97latinmodernmonolight       light    italic   normal      lmmonolt10oblique           lmmonolt10-oblique.otf
98latinmodernmonolightcond   light    normal   condensed   lmmonoltcond10regular       lmmonoltcond10-regular.otf
99latinmodernmonolight       bold     italic   normal      lmmonolt10boldoblique       lmmonolt10-boldoblique.otf
100latinmodernmonocaps        normal   italic   normal      lmmonocaps10oblique         lmmonocaps10-oblique.otf
101latinmodernmonoproplight   bold     italic   normal      lmmonoproplt10boldoblique   lmmonoproplt10-boldoblique.otf
102latinmodernmonolight       bold     normal   normal      lmmonolt10bold              lmmonolt10-bold.otf
103latinmodernmonoproplight   bold     normal   normal      lmmonoproplt10bold          lmmonoproplt10-bold.otf
104latinmodernmonoslanted     normal   normal   normal      lmmonoslant10regular        lmmonoslant10-regular.otf
105latinmodernmono            normal   normal   normal      lmmono12regular             lmmono12-regular.otf
106latinmodernmonocaps        normal   normal   normal      lmmonocaps10regular         lmmonocaps10-regular.otf
107latinmodernmonoprop        normal   normal   normal      lmmonoprop10regular         lmmonoprop10-regular.otf
108latinmodernmono            normal   normal   normal      lmmono10regular             lmmono10-regular.otf
109latinmodernmonoproplight   light    normal   normal      lmmonoproplt10regular       lmmonoproplt10-regular.otf
110\stopntyping
111
112\stopsection
113
114\startsection [title={Method 1: name}]
115
116Instead of lookup by file, you can also use names. In the font database we store
117references to the fontname and fullname as well as some composed names from
118information that comes with the font. This permits rather liberal naming and the
119main reason is that we can more easily look up fonts. In practice you will use
120names that are as close to the filename as possible.
121
122\starttyping
123mtxrun --script font --list --name --pattern="lmmono*regular" --all
124\stoptyping
125
126This gives on my machine:
127
128\startntyping
129lmmono10regular         lmmono10regular         lmmono10-regular.otf
130lmmono12regular         lmmono12regular         lmmono12-regular.otf
131lmmono8regular          lmmono8regular          lmmono8-regular.otf
132lmmono9regular          lmmono9regular          lmmono9-regular.otf
133lmmonocaps10regular     lmmonocaps10regular     lmmonocaps10-regular.otf
134lmmonolt10regular       lmmonolt10regular       lmmonolt10-regular.otf
135lmmonoltcond10regular   lmmonoltcond10regular   lmmonoltcond10-regular.otf
136lmmonoprop10regular     lmmonoprop10regular     lmmonoprop10-regular.otf
137lmmonoproplt10regular   lmmonoproplt10regular   lmmonoproplt10-regular.otf
138lmmonoslant10regular    lmmonoslant10regular    lmmonoslant10-regular.otf
139\stopntyping
140
141It does not show from this list but with name lookups first \OPENTYPE\ fonts are
142checked and then \TYPEONE. In this case there are \TYPEONE\ variants as well but
143they are ignored. Fonts are registered under all names that make sense and can be
144derived from its description. So:
145
146\starttyping
147mtxrun --script font --list --name --pattern="latinmodern*mono" --all
148\stoptyping
149
150will give:
151
152\startntyping
153latinmodernmono                      lmmono9regular              lmmono9-regular.otf
154latinmodernmonocaps                  lmmonocaps10oblique         lmmonocaps10-oblique.otf
155latinmodernmonocapsitalic            lmmonocaps10oblique         lmmonocaps10-oblique.otf
156latinmodernmonocapsnormal            lmmonocaps10oblique         lmmonocaps10-oblique.otf
157latinmodernmonolight                 lmmonolt10regular           lmmonolt10-regular.otf
158latinmodernmonolightbold             lmmonolt10boldoblique       lmmonolt10-boldoblique.otf
159latinmodernmonolightbolditalic       lmmonolt10boldoblique       lmmonolt10-boldoblique.otf
160latinmodernmonolightcond             lmmonoltcond10oblique       lmmonoltcond10-oblique.otf
161latinmodernmonolightconditalic       lmmonoltcond10oblique       lmmonoltcond10-oblique.otf
162latinmodernmonolightcondlight        lmmonoltcond10oblique       lmmonoltcond10-oblique.otf
163latinmodernmonolightitalic           lmmonolt10oblique           lmmonolt10-oblique.otf
164latinmodernmonolightlight            lmmonolt10regular           lmmonolt10-regular.otf
165latinmodernmononormal                lmmono9regular              lmmono9-regular.otf
166latinmodernmonoprop                  lmmonoprop10oblique         lmmonoprop10-oblique.otf
167latinmodernmonopropitalic            lmmonoprop10oblique         lmmonoprop10-oblique.otf
168latinmodernmonoproplight             lmmonoproplt10oblique       lmmonoproplt10-oblique.otf
169latinmodernmonoproplightbold         lmmonoproplt10boldoblique   lmmonoproplt10-boldoblique.otf
170latinmodernmonoproplightbolditalic   lmmonoproplt10boldoblique   lmmonoproplt10-boldoblique.otf
171latinmodernmonoproplightitalic       lmmonoproplt10oblique       lmmonoproplt10-oblique.otf
172latinmodernmonoproplightlight        lmmonoproplt10oblique       lmmonoproplt10-oblique.otf
173latinmodernmonopropnormal            lmmonoprop10oblique         lmmonoprop10-oblique.otf
174latinmodernmonoslanted               lmmonoslant10regular        lmmonoslant10-regular.otf
175latinmodernmonoslantednormal         lmmonoslant10regular        lmmonoslant10-regular.otf
176\stopntyping
177
178Watch the 9 point version in this list. It happens that there are 9, 10 and 12
179point regular variants but all those extras come in 10 point only. So we get a
180mix and if you want a specific design size you really have to be more specific.
181Because one font can be registered with its fontname, fullname etc.\ it can show
182up more than once in the list. You get what you ask for.
183
184With this obscurity you might wonder why names make sense as lookups. One
185advantage is that you can forget about special characters. Also, Latin Modern
186with its design sizes is probably the worst case. So, although for most fonts a
187name like the following will work, for Latin Modern it gives one of the design
188sizes:
189
190\starttyping
191\definefont[SomeFont][name:latinmodernmonolightbolditalic]
192\stoptyping
193
194But this is quite okay:
195
196\starttyping
197\definefont[SomeFont][name:lmmonolt10boldoblique]
198\stoptyping
199
200So, in practice this method will work out as well as the file method but
201you can best check if you get what you want.
202
203\stopsection
204
205\startsection [title={Method 1: spec}]
206
207We have now arrived at the third method, selecting by means of a specification.
208This time we take the familyname as starting point (although we have some
209fallback mechanisms):
210
211\starttyping
212\definefont[SomeSerif]          [spec:times]
213\definefont[SomeSerifBold]      [spec:times-bold]
214\definefont[SomeSerifItalic]    [spec:times-italic]
215\definefont[SomeSerifBoldItalic][spec:times-bold-italic]
216\stoptyping
217
218The patterns are of the form:
219
220\starttyping
221spec:name-weight-style-width
222spec:name-weight-style
223spec:name-style
224\stoptyping
225
226When only the name is used, it actually boils down to:
227
228\starttyping
229spec:name-normal-normal-normal
230\stoptyping
231
232So, this is also valid:
233
234\starttyping
235spec:name-normal-italic-normal
236spec:name-normal-normal-condensed
237\stoptyping
238
239Again we can consult the database:
240
241\starttyping
242mtxrun --script font --list --spec lmmono-normal-italic
243\stoptyping
244
245This prints the following list. The first column is the familyname, the fifth
246column the fontname:
247
248\startntyping
249latinmodernmono       normal   italic   normal   lmmono10italic        lmmono10-italic.otf
250latinmodernmonoprop   normal   italic   normal   lmmonoprop10oblique   lmmonoprop10-oblique.otf
251lmmono10              normal   italic   normal   lmmono10italic        lmtti10.afm
252lmmonoprop10          normal   italic   normal   lmmonoprop10oblique   lmvtto10.afm
253lmmonocaps10          normal   italic   normal   lmmonocaps10oblique   lmtcso10.afm
254latinmodernmonocaps   normal   italic   normal   lmmonocaps10oblique   lmmonocaps10-oblique.otf
255\stopntyping
256
257Watch the \OPENTYPE\ and \TYPEONE\ mix. As we're just investigating here, the
258lookup looks at the fontname and not at the familyname. At the \TEX\ end you use
259the familyname:
260
261\starttyping
262\definefont[SomeFont][spec:latinmodernmono-normal-italic-normal]
263\stoptyping
264
265So, we have the following ways to access this font:
266
267\starttyping
268\definefont[SomeFont][file:lmmono10-italic]
269\definefont[SomeFont][file:lmmono10-italic.otf]
270\definefont[SomeFont][name:lmmono10italic]
271\definefont[SomeFont][spec:latinmodernmono-normal-italic-normal]
272\stoptyping
273
274As \OPENTYPE\ fonts are prefered over \TYPEONE\ there is not much chance of a
275mixup.
276
277As mentioned in the introduction, qualifications are somewhat inconsistent. Among
278the weight we find: black, bol, bold, demi, demibold, extrabold, heavy, light,
279medium, mediumbold, regular, semi, semibold, ultra, ultrabold and ultralight.
280Styles are: ita, ital, italic, roman, regular, reverseoblique, oblique and
281slanted. Examples of width are: book, cond, condensed, expanded, normal and thin.
282Finally we have alternatives which can be anything.
283
284When doing a lookup, some normalizations takes place, with the default always
285being \quote {normal}. But still the repertoire is large:
286
287\startntyping
288helveticaneue medium     normal normal    helveticaneuemedium           HelveticaNeue.ttc index:  0
289helveticaneue bold       normal condensed helveticaneuecondensedbold    HelveticaNeue.ttc index:  1
290helveticaneue black      normal condensed helveticaneuecondensedblack   HelveticaNeue.ttc index:  2
291helveticaneue ultralight italic thin      helveticaneueultralightitalic HelveticaNeue.ttc index:  3
292helveticaneue ultralight normal thin      helveticaneueultralight       HelveticaNeue.ttc index:  4
293helveticaneue light      italic normal    helveticaneuelightitalic      HelveticaNeue.ttc index:  5
294helveticaneue light      normal normal    helveticaneuelight            HelveticaNeue.ttc index:  6
295helveticaneue bold       italic normal    helveticaneuebolditalic       HelveticaNeue.ttc index:  7
296helveticaneue normal     italic normal    helveticaneueitalic           HelveticaNeue.ttc index:  8
297helveticaneue bold       normal normal    helveticaneuebold             HelveticaNeue.ttc index:  9
298helveticaneue normal     normal normal    helveticaneue                 HelveticaNeue.ttc index: 10
299helveticaneue normal     normal condensed helveticaneuecondensed        hlc_____.afm   conflict: roman
300helveticaneue bold       normal condensed helveticaneueboldcond         hlbc____.afm
301helveticaneue black      normal normal    helveticaneueblackcond        hlzc____.afm   conflict: normal
302helveticaneue black      normal normal    helveticaneueblack            hlbl____.afm   conflict: normal
303helveticaneue normal     normal normal    helveticaneueroman            lt_50259.afm   conflict: regular
304\stopntyping
305
306\stopsection
307
308\startsection[title={The font database}]
309
310In \MKIV\ we use a rather extensive font database which in addition to bare
311information also contains a couple of hashes. When you use \CONTEXT\ \MKIV\ and
312install a new font, you have to regenerate the file database. In a next \TEX\ run
313this will trigger a reload of the font database. Of course you can also force a
314reload with:
315
316\starttyping
317mtxrun --script font --reload
318\stoptyping
319
320As a summary we mention a few of the discussed calls of this script:
321
322\startntyping
323mtxrun --script font --list somename (== --pattern=*somename*)
324
325mtxrun --script font --list --name somename
326mtxrun --script font --list --name --pattern=*somename*
327
328mtxrun --script font --list --spec somename
329mtxrun --script font --list --spec somename-bold-italic
330mtxrun --script font --list --spec --pattern=*somename*
331mtxrun --script font --list --spec --filter="fontname=somename"
332mtxrun --script font --list --spec --filter="familyname=somename,weight=bold,style=italic,width=condensed"
333
334mtxrun --script font --list --file somename
335mtxrun --script font --list --file --pattern=*somename*
336\stopntyping
337
338The lists shown in before depend on what fonts are installed and
339their version. They might not reflect reality at the time you read
340this.
341
342\stopsection
343
344\startsection[title={Interfacing}]
345
346Regular users never deal with the font database directly. However, if you write
347font loading macros yourself, you can access the database from the \TEX\ end.
348First we show an example of an entry in the database, in this case TeXGyreTermes
349Regular.
350
351\starttyping
352{
353    designsize = 100,
354    familyname = "texgyretermes",
355    filename = "texgyretermes-regular.otf",
356    fontname = "texgyretermesregular",
357    fontweight = "regular",
358    format = "otf",
359    fullname = "texgyretermesregular",
360    maxsize = 200,
361    minsize = 50,
362    rawname = "TeXGyreTermes-Regular",
363    style = "normal",
364    variant = "",
365    weight = "normal",
366    width = "normal",
367}
368\stoptyping
369
370Another example is Helvetica Neue Italic:
371
372\starttyping
373{
374    designsize = 0,
375    familyname = "helveticaneue",
376    filename = "HelveticaNeue.ttc",
377    fontname = "helveticaneueitalic",
378    fontweight = "book",
379    format = "ttc",
380    fullname = "helveticaneueitalic",
381    maxsize = 0,
382    minsize = 0,
383    rawname = "Helvetica Neue Italic",
384    style = "italic",
385    subfont = 8,
386    variant = "",
387    weight = "normal",
388    width = "normal",
389}
390\stoptyping
391
392As you can see, some fields can be meaningless, like the sizes. As using the low
393level \TEX\ interface assumes some knowledge, we stick here to an example:
394
395\starttyping
396\def\TestLookup#1%
397  {\dolookupfontbyspec{#1}
398   pattern: #1, found: \dolookupnoffound
399   \blank
400   \dorecurse {\dolookupnoffound} {%
401     \recurselevel:~\dolookupgetkeyofindex{fontname}{\recurselevel}%
402     \quad
403   }%
404   \blank}
405
406\TestLookup{familyname=helveticaneue}
407\TestLookup{familyname=helveticaneue,weight=bold}
408\TestLookup{familyname=helveticaneue,weight=bold,style=italic}
409\stoptyping
410
411You can use the following commands:
412
413\starttyping
414\dolookupfontbyspec    {key=value list}
415\dolookupnoffound
416\dolookupgetkeyofindex {key}{index}
417\dolookupgetkey        {key}
418\stoptyping
419
420First you do a lookup. After that there can be one or more matches and you can
421access the fields of each match. What you do with the information is up to
422yourself.
423
424\stopsection
425
426\startsection[title={A few remarks}]
427
428The fact that modern \TEX\ engines can access system fonts is promoted as a
429virtue. The previous sections demonstrated that in practice this does not really
430free us from a name mess. Of course, when we use a really small \TEX\ tree, and
431system fonts only, there is not much that can go wrong, but when you have extra
432fonts installed there can be clashes.
433
434We're better off with filenames than we were in former times when operating
435systems and media forced distributors to stick to 8 characters in filenames. But
436that does not guarantee that today's shipments are more consistent. And as there
437are still some limitations in the length of fontnames, obscure names will be with
438us for a long time to come.
439
440\stopsection
441
442\stopchapter
443
444\stopcomponent
445