ontarget-standardize.tex /size: 34 Kb    last modification: 2024-01-16 10:21
1% language=us runpath=texruns:manuals/ontarget
2
3\setupexternalfigures[directory=screendumps]
4
5\usebodyfont[antykwa]
6\usebodyfont[modern-nt]
7\usebodyfont[modern]
8\usebodyfont[bonum-nt]
9\usebodyfont[bonum]
10\usebodyfont[lucida-nt]
11\usebodyfont[lucida]
12\usebodyfont[erewhon-nt]
13\usebodyfont[erewhon]
14\usebodyfont[libertinus-nt]
15\usebodyfont[libertinus]
16\usebodyfont[stixtwo]
17\usebodyfont[cambria]
18
19\hyphenation{prime-shift-up-cramped}
20
21\startcomponent ontarget-standardize
22
23\environment ontarget-style
24
25\startchapter[title={Standardizing math fonts}]
26
27\startsection[title={Introduction}]
28
29\CONTEXT\ has always had a good support for the typesetting of mathematics.
30\CONTEXT\ \MKII\ uses the \PDFTEX\ engine and hence traditional (\TYPEONE) fonts.
31Several math fonts are available, specifically designed to work seamlessly with
32\TEX. \CONTEXT\ \MKIV, the successor version, utilizes the \LUATEX\ engine,
33providing support not only for traditional fonts but also for \OPENTYPE\
34\UNICODE\ math fonts. Unlike the \XETEX\ engine, which interpreted these new
35fonts in a manner similar to traditional \TEX\ fonts, \LUATEX\ adheres more
36closely to the (unfortunately somewhat vague) \OPENTYPE\ specification. \footnote
37{See \typ{https://learn.microsoft.com/en-us/typography/opentype/spec/math}} When
38new fonts appeared, some were more like the traditional fonts, others more like
39\OPENTYPE\ \UNICODE\ math fonts. This leads to difficulties in achieving
40consistent results across different fonts and might be one reason that the
41\UNICODE\ engines are not yet used as much as they probably should.
42
43In autumn 2021 we started to discuss how to improve the typesetting of \OPENTYPE\
44\UNICODE\ mathematics, and it was natural to go on and do this for the
45\LUAMETATEX\ engine, and hence for \CONTEXT\ \LMTX. Since then, we have been
46engaging in daily discussions covering finer details such as glyphs, kerning,
47accent placement, inter|-|atom spacing (what we refer to as math
48microtypography), as well as broader aspects like formula alignment and formula
49line breaking (math macrotypography). This article will primarily focus on the
50finer details. Specifically, we will explore the various choices we have made
51throughout the process. The \OPENTYPE\ \UNICODE\ math specification is
52incomplete; some aspects are missing, while others remain ambiguous. This issue
53is exacerbated by the varying behaviors of fonts.
54
55We make runtime changes to fonts, and add a few additional font parameters that
56we missed. As a result, we deviate from the standard set by Microsoft (or rather,
57we choose to interpret it in our own way) and exercise the freedom to make
58runtime changes to font parameters. Regarding this aspect, we firmly believe that
59our results often align more closely with the original intentions of the font
60designers. Indeed, the existence of \quotation{oddities} in these fonts may be
61attributed to the lack of an engine, during their creation, that supported all
62the various features, making testing difficult, if not essentially impossible.
63Within \CONTEXT\ \LMTX, we have the necessary support, and we can activate
64various helpers that allow us to closely examine formulas. Without them our work
65would not have been possible.
66
67Ultimately, we hope and believe that we have made straightforward yet effective
68choices, rendering the existing \OPENTYPE\ \UNICODE\ math fonts usable. We hope
69that this article might be inspiring and useful for others who aim to achieve
70well|-|designed, modern math typesetting.
71
72\stopsection
73
74\startsection[title={Traditional vs.\ \OPENTYPE\ math fonts}]
75
76There is a fundamental difference between traditional \TEX\ math fonts and
77\OPENTYPE\ \UNICODE\ fonts. In the traditional approach, a math setup consists of
78multiple independent fonts. There is no direct relationship between a math italic
79$x$ and an $\hat{\hphantom{x}}$ on top of it. The engine handles the positioning
80almost independently of the shapes involved. There can be a shift to the right of
81$\hat{x}$ triggered by kerning with a so|-|called skew character but that is it.
82
83A somewhat loose coupling between fonts is present when we go from a base
84character to a larger variant that itself can point to a larger one and
85eventually end up at an extensible recipe. But the base character and that
86sequence are normally from different fonts. The assumption is that they are
87designed as a combination. In an \OPENTYPE\ font, variants and extensibles more
88directly relate to a base character.
89
90Then there is the italic correction which adds kerns between a character and what
91follows depending on the situation. It is not, in fact, a true italic correction,
92but more a hack where an untrue width is compensated for. A traditional \TEX\
93engine defaults to adding these corrections and selectively removes or
94compensates for them. In traditional \TEX\ this fake width helps placing the
95subscript properly while the italic correction is added to the advance width when
96attaching subscripts and|/|or moving to the next atom.
97
98In an \OPENTYPE\ font we see these phenomena translated into features. Instead of
99many math fonts we have one font. This means that one can have relations between
100glyphs, although in practice little of that happens. One example is that a
101specific character can have script and scriptscript sizes with a somewhat
102different design. Another is that there can be alternate shapes for the same
103character, and yet another is substitution of (for instance) dotted characters by
104dotless ones. However, from the perspective of features a math font is rather
105simple and undemanding.
106
107Another property is that in an \OPENTYPE\ math font the real widths are used in
108combination with optional italic correction when a sequence of characters is
109considered text, with the exception of large operators where italic correction is
110used for positioning limits on top and below. Instead of abusing italic
111corrections this way, a system of staircase kerns in each corner of a shape is
112possible.
113
114Then there are top (but not bottom) anchor positions that, like marks in text
115fonts, can be used to position accents on top of base characters or boxes. And
116while we talk of accents: they can come with so|-|called flat substitutions for
117situations where we want less height.
118
119All this is driven by a bunch of font parameters that (supposedly) relate to the
120design of the font. Some of them concern rules that are being used in
121constructing, for instance, fractions and radicals but maybe also for making new
122glyphs like extensibles, which is essentially a traditional \TEX\ thing.
123
124So, when we now look back at the traditional approach we can say that there are
125differences in the way a font is set up: widths and italic corrections, staircase
126kerns, rules as elements for constructing glyphs, anchoring of accents,
127flattening of accents, replacement of dotted characters, selection of smaller
128sizes, and font parameters. These differences have been reflected in the way
129engines (seem to) deal with \OPENTYPE\ math: one can start with a traditional
130engine and map \OPENTYPE\ onto that; one can implement an \OPENTYPE\ engine and,
131if needed, map traditional fonts onto the way that works; and of course there can
132be some mix of these.
133
134In practice, when we look at existing fonts, there is only one reference and that
135is Cambria. When mapped onto a traditional engine, much can be made to work, but
136not all. Then there are fonts that originate in the \TEX\ community and these do
137not always work well with an \OPENTYPE\ engine. Other fonts are a mix and work
138more or less. The more one looks into details, the clearer it becomes that no
139font is perfect and that it is hard to make an engine work well with them. In
140\LUAMETATEX\ we can explicitly control many of the choices the math engine makes,
141and there are more such choices than with traditional \TEX\ machinery. And
142although we can adapt fonts at runtime to suit the possibilities, it is not
143pretty.
144
145This is why we gradually decided on a somewhat different approach: we use the
146advantage of having a single font, normalize fonts to what we can reliably
147support, and if needed, add to fonts and control the math engine, especially the
148various subsystems, with directives that tell it what we want to be done. Let us
149discuss a few things that we do when we load a math font.
150
151\stopsection
152
153\startsection[title={Getting rid of italic corrections}]
154
155\OPENTYPE\ math has italic corrections for using characters in text and large
156operators (for limits), staircase kerns for combining scripts, and top anchor for
157placement of accents. In \LUAMETATEX\ we have access to more features.
158
159Let's remind ourselves. In a bit more detail, \OPENTYPE\ has:
160
161\startitemize[packed]
162\startitem
163    \typ An \typ {italic correction} is injected between characters in running
164    text, but: a sequence of atoms is {\em not} text, they are individually
165    spaced.
166\stopitem
167\startitem
168    An \typ {italic correction} value in large operators that reflects where
169    limits are attached in display mode; in effect, using the italic
170    correction as an anchor.
171\stopitem
172\startitem
173    \typ {Top anchors} are used to position accents over characters, but
174    not so much over atoms that are composed from not only characters.
175\stopitem
176\startitem
177    \typ {Flat accents} as substitution feature for situations where the height
178    would become excessive.
179\stopitem
180\startitem
181    \typ {Script and scriptscript} as substitution feature for a selection of
182    characters that are sensitive for scaling down.
183\stopitem
184\stopitemize
185
186This somewhat limited view on math character positioning has been extended in
187\LUAMETATEX, and we remap the above onto what we consider a bit more reliable,
188especially because we can tweak these better. We have:
189
190\startitemize[packed]
191\startitem
192    \typ {Corner kerns} that make it possible to adjust the horizontal location
193    of sub- and superscripts and prescripts.
194\stopitem
195\startitem
196    Although \typ {flat accents} are an existing feature, we extended them by
197    providing additional scaling when they are not specified.
198\stopitem
199\startitem
200    In addition to script sizes we also have \typ {mirror} as a feature so that
201    we can provide right to left math typesetting. (This also relates to
202    dropping in characters from other fonts, like Arabic.)
203\stopitem
204\startitem
205    In addition to the \typ {top anchors} we also have \typ {bottom anchors}
206    in order to properly place bottom accents. These are often
207    missing, so we need to construct them from available snippets.
208\stopitem
209\startitem
210    An additional \typ {extensible italic correction} makes it possible to
211    better anchor scripts to sloped large operators. This is combined with
212    keeping track of \typ {corner kerns} that can be specified per character.
213\stopitem
214\startitem
215    Characters can have \typ {margins} which makes it possible to more precisely
216    position accents that would normally overflow the base character and clash
217    with scripts. These go in all four directions.
218\stopitem
219\startitem
220    In order to be able to place the degree in a radical more precisely (read:
221    not run into the shape when there is more than just a single degree atom) we
222    have \typ {radical offsets}.
223\stopitem
224\stopitemize
225
226There are plenty more tuning options but some are too obscure to mention here.
227All high level constructors, like fences, radicals, accents, operators,
228fractions, etc.\ can be tuned via optional keyword and key|/|values at the macro
229end.
230
231We eliminate the italic correction in math fonts, instead adding it to the width,
232and using a negative bottom right kern. If possible we also set a top and bottom
233accent anchor. This happens when we load the font. We also translate the italic
234correction on large operators into anchors. As a result, the engine can now
235completely ignore italic corrections in favor of proper widths, kerns and
236anchors. Let us look at a few examples.
237
238The italic $f$ is used a lot in mathematics and it is also one of the most
239problematic characters. In \TEXGYRE\ Bonum Math the italic f has a narrow
240bounding box; the character sticks out on both the left and right. To the right,
241this is compensated by a large amount of italic correction. This means that when
242one adds sub- and superscripts, it works well. We add italic correction to the
243width, and introducing a negative corner kern at the bottom right corner, and
244thus the placement of sub- and superscripts is not altered. Look carefully at the
245bounding boxes below.
246
247\startplacefloat
248  [intermezzo]
249  [location=nonumber]
250  \startcombination[nx=2,distance=1es]
251    \startcontent
252      \switchtobodyfont[bonum-nt]
253      \showglyphs
254      \dm{\setmscale{3}f_0^1}
255    \stopcontent
256    \startcaption
257      \hbox {original}
258    \stopcaption
259    \startcontent
260      \showglyphs
261      \dm{\setmscale{3}f_0^1}
262    \stopcontent
263    \startcaption
264      \hbox {tweaked}
265    \stopcaption
266  \stopcombination
267\stopplacefloat
268
269Compare with Lucida Bright Math, which comes with staircase kerns instead of
270italic correction. We convert these kerns into corner kerns.
271
272\startplacefloat
273  [intermezzo]
274  [location=nonumber]
275  \startcombination[nx=2,distance=5ts]
276    \startcontent
277      \switchtobodyfont[lucida-nt]
278      \showglyphs
279      \dm{\setmscale{3}f_0^1}
280    \stopcontent
281    \startcaption
282      \hbox {original}
283    \stopcaption
284    \startcontent
285      \switchtobodyfont[lucida]
286      \showglyphs
287      \dm{\setmscale{3}f_0^1}
288    \stopcontent
289    \startcaption
290      \hbox {tweaked}
291    \stopcaption
292  \stopcombination
293\stopplacefloat
294
295For characters that stick out to the left, we also increase the width and shift
296the glyph to ensure that it does not stick out on the left side. This prevents
297glyphs from clashing into each other.
298
299\startplacefloat
300  [intermezzo]
301  [location=nonumber]
302  \startcombination[nx=2,distance=5ts]
303    \startcontent
304      \switchtobodyfont[bonum-nt]
305      \showglyphs
306      \dm{\setmscale{3}(f)}
307    \stopcontent
308    \startcaption
309      \hbox {original}
310    \stopcaption
311    \startcontent
312      \showglyphs
313      \dm{\setmscale{3}(f)}
314    \stopcontent
315    \startcaption
316      \hbox {tweaked}
317    \stopcaption
318  \stopcombination
319\stopplacefloat
320
321As mentioned, for the integral, one of the most common big operators, the limits
322are also placed with help of the italic correction. When the limits go below and
323on top, proper bottom and top anchor points are introduced, calculated from the
324italic correction. (The difference in size of the integral signs is a side effect
325of the font parameter \typ {DisplayOperatorMinHeight} being tweaked, as we'll
326discuss more later. \OPENTYPE\ fonts can come with more than two sizes.)
327
328\startplacefloat
329  [intermezzo]
330  [location=nonumber]
331  \startcombination[nx=3,distance=5ts]
332    \startcontent
333      \switchtobodyfont[bonum-nt]
334      \showglyphs
335      \dm{\setmscale{1.5}\int_a^b f(x) \dd x}
336    \stopcontent
337    \startcaption
338      original
339    \stopcaption
340    \startcontent
341      \showglyphs
342      \dm{\setmscale{1.5}\int_a^b f(x) \dd x}
343    \stopcontent
344    \startcaption
345      \hbox {tweaked, nolimits}
346    \stopcaption
347    \startcontent
348      \setupmathematics
349        [integral=limits]
350      \showglyphs
351      \dm{\setmscale{1.5}\int_a^b f(x) \dd x}
352    \stopcontent
353    \startcaption
354      \hbox {tweaked, limits}
355    \stopcaption
356  \stopcombination
357\stopplacefloat
358
359Compare these integrals with the summation, that usually does not have any italic
360correction bound to it. This means that the new anchor points end up in the
361middle of the summation symbol.
362
363\startplacefloat
364  [intermezzo]
365  [location=nonumber]
366  \startcombination[nx=2,distance=5ts]
367    \startcontent
368      \switchtobodyfont[bonum-nt]
369      \showglyphs
370      \dm{\setmscale{1.5}\sum_{k=1}^{n}a_k}
371    \stopcontent
372    \startcaption
373      original
374    \stopcaption
375    \startcontent
376      \showglyphs
377      \dm{\setmscale{1.5}\sum_{k=1}^{n}a_k}
378    \stopcontent
379    \startcaption
380      tweaked
381    \stopcaption
382  \stopcombination
383\stopplacefloat
384
385We also introduce some corner kerns in cases where there were neither italic
386corrections nor staircase kerns. This is mainly done for delimiters, like
387parentheses. We can have a different amount of kerning for the various sizes.
388Often the original glyph does not benefit from any kerning, while the variants
389and extensibles do.
390
391\startplacefloat
392  [intermezzo]
393  [location=nonumber]
394  \startcombination[nx=2,distance=5ts]
395    \startcontent
396      \switchtobodyfont[bonum-nt]
397      \showglyphs
398      \dm{\setmscale{1.5}\left( \frac {1}{1 + x^2} \right)^2}
399    \stopcontent
400    \startcaption
401      original
402    \stopcaption
403    \startcontent
404      \showglyphs
405      \dm{\setmscale{1.5}\left( \frac {1}{1 + x^2} \right)^2}
406    \stopcontent
407    \startcaption
408      tweaked
409    \stopcaption
410  \stopcombination
411\stopplacefloat
412
413Note also the different sizes of the parentheses in the example above. Both
414examples are set with \typ {\left(} and \typ {\right)}, but the font parameters
415are chosen differently in the tweaked version. Font designers should have used
416the opportunity to have more granularity in sizes. Latin Modern Math has four,
417many others have steps in between, but there is a lack of consistency.
418
419\stopsection
420
421\startsection[title={Converting staircase kerns}]
422
423We simplify the staircase kerns, which are often somewhat sloppy and seldom
424complete (see figure below), into more reliable corner kerns. It's good enough
425and looks better on the whole. We also avoid bugs that way.
426
427\startplacefloat
428  [intermezzo]
429  [location=nonumber]
430  \startcombination[nx=2,ny=1,distance=5TS]
431    \startcontent
432      \clip[ny=3,y=2]
433      {\externalfigure[CambriaItalicV-bottomrightkern][height=3ES]}
434    \stopcontent
435    \startcaption
436      italic V
437    \stopcaption
438    \startcontent
439      \clip[ny=3,y=2]
440      {\externalfigure[CambriauprightV-bottomrightkern][height=3ES]}
441    \stopcontent
442    \startcaption
443      upright V
444    \stopcaption
445  \stopcombination
446\stopplacefloat
447
448
449\stopsection
450
451\startsection[title={Tweaking accents}]
452
453We ignore the zero dimensions of accents, simply assuming that one cannot know if
454the shape is centered or sticks out in a curious way, and therefore use proper
455widths with top and bottom anchors derived from the bounding box. We compensate
456for negative llx values being abused for positioning. We check for overflows in
457the engine. In case of multiple accents, we place the first one anchored over the
458character, and center the others on top of it.
459
460\startplacefloat
461  [intermezzo]
462  [location=nonumber]
463  \startcombination[nx=1,distance=5TS]
464    \startcontent
465      \switchtobodyfont[bonum]
466      \showglyphs
467      \dm{\setmscale{3} \hat{\hat{\hat{f}}}}
468    \stopcontent
469    \startcaption
470    \stopcaption
471  \stopcombination
472\stopplacefloat
473
474We mentioned in an earlier \TUGBOAT\ article that sometimes anchor points are
475just wrong. We have a tweak that resets them (to the middle) that we use for
476several fonts and alphabets.
477
478Some accents, like the hat, can benefit from being scaled. The fonts typically
479provide the base size and a few variants.
480
481\startplacefloat
482  [intermezzo]
483  [location=nonumber]
484  \startcombination[nx=2,ny=1,distance=5TS]
485    \startcontent
486      \switchtobodyfont[bonum-nt]
487      \showglyphs
488      \dm{\setmscale{3}\widehat[stretch=no]{f+g}}
489    \stopcontent
490    \startcaption
491      original
492    \stopcaption
493    \startcontent
494      \showglyphs
495      \dm{\setmscale{3}\widehat{f+g}}
496    \stopcontent
497    \startcaption
498      tweaked
499    \stopcaption
500  \stopcombination
501\stopplacefloat
502
503The only fonts we have seen that support flattened accents are Stix Two Math
504and Cambria Math.
505
506\startplacefloat
507  [intermezzo]
508  [location=nonumber]
509  \startcombination[nx=2,ny=1,distance=1es]
510    \startcontent
511      \switchtobodyfont[stixtwo]
512      \showglyphs
513      \dm{\setmscale{3}\hat{a}\hat{A}\hat{C}}
514    \stopcontent
515    \startcaption
516      stix two
517    \stopcaption
518    \startcontent
519      \switchtobodyfont[cambria]
520      \showglyphs
521      \dm{\setmscale{3}\hat{a}\hat{A}\hat{C}}
522    \stopcontent
523    \startcaption
524      cambria
525    \stopcaption
526  \stopcombination
527\stopplacefloat
528
529If you look carefully, you notice that the hats over the capital letters are not
530as tall as the one over the lowercase letter. There is a font parameter \typ
531{FlattenedAccentBaseHeight} that is supposed to specify when this effect is
532supposed to kick in. Even though other fonts do not use this feature, the
533parameter is set, sometimes to strange values (if they were to have the
534property). For example, in Garamond Math, the value is 420.
535
536We introduced a tweak that can fake the flattened accents, and therefore we need
537to alter the value of the font parameter to more reasonable values. We
538communicated to Daniel Flipo, who maintains several math fonts, that the
539parameter was not correctly set in Erewhon math. In fact, it was set such that
540the flattened accents were used for some capital letters (C in the example below)
541but not for others (A below). He quickly fixed that. The green rules in the
542picture have the height of \typ {FlattenedAccentBaseHeight}; it did not need to
543be decreased by much.
544
545\startplacefloat
546  [intermezzo]
547  [location=nonumber]
548  \startcombination[nx=2,distance=5TS]
549    \startcontent
550        \externalfigure[erewhonmath][page=1]
551    \stopcontent
552    \startcaption
553        \hbox{Erewhon, not fixed}
554    \stopcaption
555    \startcontent
556        \externalfigure[erewhonmath][page=2]
557    \stopcontent
558    \startcaption
559        \hbox{Erewhon, fixed}
560    \stopcaption
561  \stopcombination
562\stopplacefloat
563
564\stopsection
565
566\startsection[title={Getting rid of rules}]
567
568We get rid of rules as pseudo-glyphs in extensibles and bars. This also gives
569nicer visual integration because flat rules do not always fit in with the rest of
570the font. We also added support for this in the few (Polish) Type~1 math fonts
571that we still want to support, like Antykwa ToruƄska.
572
573\startplacefloat
574    [intermezzo]
575    [location=nonumber]
576\startcombination[nx=3,ny=1,distance=5TS]
577\startcontent
578\switchtobodyfont[modern-nt]%
579\setupmathfractions
580  [strut=no]%
581\dm{
582  \setmscale{3}
583  \sqrt{\frac{1+x}{1-x}}
584}
585\stopcontent
586\startcaption
587With rule
588\stopcaption
589
590\startcontent
591\switchtobodyfont[modern]%
592\setupmathfractions
593  [strut=no]%
594\dm{
595  \setmscale{3}
596  \sqrt{\frac{1+x}{1-x}}
597}
598\stopcontent
599\startcaption
600With glyph
601\stopcaption
602\startcontent
603\switchtobodyfont[antykwa]%
604\setupmathfractions
605  [strut=no]%
606\dm{
607  \setmscale{3}
608  \sqrt{\frac{1+x}{1-x}}
609}
610\stopcontent
611\startcaption
612Antykwa
613\stopcaption
614\stopcombination
615\stopplacefloat
616
617Here is an enlarged example of an Antykwa rule. Latin Modern has rounded corners,
618here we see a rather distinctive ending.
619
620\startlinecorrection
621\scale[height=2cm]{\switchtobodyfont[antykwa]\im{\overbar{x^2 + 2x + 2}}}
622\stoplinecorrection
623
624\stopsection
625
626\startsection[title={Tweaking primes}]
627
628We make it no secret that we consider primes in math fonts a mess. For some
629reason no one could convince the \UNICODE\ people that a \quote {prime} is not a
630\quote {minute} (that is, \acro{U+2032 PRIME} is also supposed to be used as the
631symbol for minutes); in case you'd like to argue that \quotation {they often look
632the same}, that is also true for the Latin and Greek capital \quote {A}. This
633lost opportunity means that, as with traditional \TEX\ fonts, we need to fight a
634bit with placement. The base character can or cannot be already anchored at some
635superscript|-|like position, so that makes it basically unusable. An alternative
636assumption might be that one should just use the script size variant as a
637superscript, but as we will see below, that assumes that they sit on the baseline
638so that we can move it up to the right spot. Add to that the fact that
639traditional \TEX\ has no concept of a prime, and we need some kind of juggling
640with successive scripts. This is what macro packages end up doing.
641
642But this is not what we want. In \CONTEXT\ \MKIV\ we already have special
643mechanisms for dealing with primes, which include mapping successive primes onto
644the multiple characters in \UNICODE, where we actually have individual triple and
645quadruple primes and three reverse (real) primes as well. However, primes are now
646a native feature, like super- and subscripts, as well as prescripts and indices.
647(All examples here are uniformly scaled.)
648
649\startplacefloat
650  [intermezzo]
651  [location=nonumber]
652  \startcombination[nx=3,ny=6]
653    \startcontent
654      \externalfigure[Latinmodernprime][scale=200]
655    \stopcontent
656    \startcaption
657      lm
658    \stopcaption
659    \startcontent
660      \externalfigure[Latinmodernprimest][scale=200]
661    \stopcontent
662    \startcaption
663      st
664    \stopcaption
665    \startcontent
666      \externalfigure[Latinmodernprimests][scale=200]
667    \stopcontent
668    \startcaption
669      sts
670    \stopcaption
671    \startcontent
672      \externalfigure[Lucidaprime][scale=200]
673    \stopcontent
674    \startcaption
675      lucida
676    \stopcaption
677    \startcontent
678    \stopcontent
679    \startcaption
680    \stopcaption
681    \startcontent
682      \externalfigure[Lucidaprimessty][scale=200]
683    \stopcontent
684    \startcaption
685      ssty
686    \stopcaption
687    \startcontent
688      \externalfigure[Erewhonprime][scale=200]
689    \stopcontent
690    \startcaption
691      erewhon
692    \stopcaption
693    \startcontent
694      \externalfigure[Erewhonprimest][scale=200]
695    \stopcontent
696    \startcaption
697      st
698    \stopcaption
699    \startcontent
700      \externalfigure[Erewhonprimesst][scale=200]
701    \stopcontent
702    \startcaption
703      sst
704    \stopcaption
705    \startcontent
706      \externalfigure[Libertinusprime][scale=200]
707    \stopcontent
708    \startcaption
709      libertinus
710    \stopcaption
711    \startcontent
712      \externalfigure[Libertinusprimessty1][scale=200]
713    \stopcontent
714    \startcaption
715      ssty1
716    \stopcaption
717    \startcontent
718    \stopcontent
719    \startcaption
720    \stopcaption
721  \stopcombination
722\stopplacefloat
723
724Because primes are now a native feature, we also have new font parameters \typ
725{PrimeShiftUp} and \typ {PrimeShiftUpCramped}, similar to \typ
726{SuperscriptShiftUp} and \typ {SuperscriptShiftUpCramped}, which add a horizontal
727axis where the primes are placed. There is also a \typ {fixprimes} tweak that we
728can use to scale and fix the glyph itself. Below, we see how very different the
729primes from different fonts look (all examples are uniformly scaled), and then
730examples comparing the original and tweaked primes.
731
732\startbuffer
733\dm{\setmscale{2}f'(x) + e^{f'(x)}}
734\stopbuffer
735
736\startplacefloat
737  [intermezzo]
738  [location=nonumber]
739  \startcombination[nx=2,ny=4,distance=2ts]
740    \startcontent
741      \switchtobodyfont[modern-nt]
742      \getbuffer
743    \stopcontent
744    \startcaption
745      lm original
746    \stopcaption
747    \startcontent
748      \switchtobodyfont[modern]
749      \getbuffer
750    \stopcontent
751    \startcaption
752      lm tweaked
753    \stopcaption
754    \startcontent
755      \switchtobodyfont[lucida-nt]
756      \getbuffer
757    \stopcontent
758    \startcaption
759      lucida original
760    \stopcaption
761    \startcontent
762      \switchtobodyfont[lucida]
763      \getbuffer
764    \stopcontent
765    \startcaption
766      lucida tweaked
767    \stopcaption
768    \startcontent
769      \switchtobodyfont[erewhon-nt]
770      \getbuffer
771    \stopcontent
772    \startcaption
773      erewhon original
774    \stopcaption
775    \startcontent
776      \switchtobodyfont[erewhon]
777      \getbuffer
778    \stopcontent
779    \startcaption
780      erewhon tweaked
781    \stopcaption
782    \startcontent
783      \switchtobodyfont[libertinus-nt]
784      \getbuffer
785    \stopcontent
786    \startcaption
787      libertinus original
788    \stopcaption
789    \startcontent
790      \switchtobodyfont[libertinus]
791      \getbuffer
792    \stopcontent
793    \startcaption
794      libertinus tweaked
795    \stopcaption
796  \stopcombination
797\stopplacefloat
798
799\stopsection
800
801\startsection[title={Font parameters}]
802
803We add some font parameters, ignore some existing ones, and fix at runtime those
804that look to be suboptimal. We have no better method than looking at examples, so
805parameters might be fine|-|tuned further in the future.
806
807We have already mentioned that we have a few new parameters, \typ {PrimeShiftUp}
808and \typ {PrimeShiftUpCramped}, to position primes on their own axis, independent
809of the superscripts. They are also chosen to always be placed outside
810superscripts, so the inputs \typ {$f'^2$} and \typ {$f^2'$} both result in
811$f^2'$. Authors should use parentheses in order to avoid confusion.
812
813\startplacefloat
814  [intermezzo]
815  [location=nonumber]
816  \startcombination[nx=1,ny=3]
817  \startcontent
818    \externalfigure[latex-pdfpowers-crop][scale=1.2*2400]
819  \stopcontent
820  \startcaption
821  \stopcaption
822  \startcontent
823    \externalfigure[latex-luapowers-crop][scale=1.2*2400]
824  \stopcontent
825  \startcaption
826  \stopcaption
827  \startcontent
828    \externalfigure[230430-3-crop][scale=1.2*2000]
829  \stopcontent
830  \startcaption
831  \stopcaption
832  \stopcombination
833\stopplacefloat
834
835Let us briefly mention the other parameters. These are the adapted parameters for
836\TeX\ Gyre Bonum:
837
838\starttyping
839AccentTopShiftUp                  =  -15
840FlattenedAccentTopShiftUp         =  -15
841AccentBaseDepth                   =   50
842DelimiterPercent                  =   90
843DelimiterShortfall                =  400
844DisplayOperatorMinHeight          = 1900
845SubscriptShiftDown                =  201
846SuperscriptShiftUp                =  364
847SubscriptShiftDownWithSuperscript = "1.4*SubscriptShiftDown"
848PrimeShiftUp                      = "1.25*SuperscriptShiftUp"
849PrimeShiftUpCramped               = "1.25*SuperscriptShiftUp"
850\stoptyping
851
852Some of these are not in \OPENTYPE. We can set up much more, but it depends on
853the font what is needed, and also on user demands.
854
855We have noticed that many font designers seem to have had problems setting some
856of the values; for example, \typ {DisplayOperatorMinHeight} seems to be off in
857many fonts.
858
859\stopsection
860
861\startsection[title={Profiling}]
862
863Let us end with profiling, which is only indirectly related to the tweaking of
864the fonts. Indeed, font parameters control the vertical positioning of sub- and
865superscripts. If not carefully set, they might force a non-negative \tex {
866lineskip} where not necessary. In the previous section we showed how these
867parameters were tweaked for Bonum.
868
869Sometimes formulas are too high (or have a too large depth) for the line, and so
870a \tex {lineskip} is added so that the lines do not clash. If the lowest part of
871the top line (typically caused by the depth) and the tallest part of the bottom
872line (caused by the height) are not close to each other on the line, one might
873argue that this \tex {lineskip} does not have to be added, or at least with
874reduced amount. This is possible to achieve by adding \typ
875{\setupalign[profile]}. Let us look at one example.
876
877\startbuffer[annals]
878So the question is: how good an approximation to \im {\sigma} is \im {\sigma * W
879\phi}? But the attentive reader will realize that we have already answered this
880question in the course of proving the sharp GĂ„rding inequality. Indeed, suppose
881\im{\phi \in \mathcal{S}} is even and \im {\fenced[doublebar]{\phi}_2 = 1}, and
882set \im {\phi^a(x) = a^{n/4} \phi (a^{1/2}x)}. Then we have shown (cf.\ Remark
883(2.89)) that \im {\sigma - \sigma * W\phi^a \in S_{\rho, \delta}^{m-(\rho-
884\delta)}} whenever \im {\sigma \in S_{\rho, \delta}^m} is supported in a set
885where \im {\langle \xi \rangle^{\rho + \delta} \approx a}.
886\stopbuffer
887
888\starttextdisplay
889\bgroup
890\switchtobodyfont[modern]%23cm
891\startcombination[nx=1,ny=2]
892\startcontent
893\vtop{\hsize 14cm\relax%
894\showmakeup[line]
895\getbuffer[annals]}
896\stopcontent
897\startcaption
898No profiling
899\stopcaption
900\startcontent
901\vtop{\hsize 14cm\relax%
902\setupalign[profile]
903\showmakeup[line]
904\enabletrackers[profiling.lines.show]
905\getbuffer[annals]}
906\stopcontent
907\startcaption
908Profiling
909\stopcaption
910\stopcombination
911\egroup
912\stoptextdisplay
913
914In the above paragraphs we enabled a helper that shows us where the profiling
915feature kicks in. We also show the lines (\typ {\showmakeup[line]}). Below we
916show the example without those helpers. You can judge for yourself which one you
917prefer.
918
919\starttextdisplay
920\bgroup
921\switchtobodyfont[modern]
922\startcombination[nx=1,ny=2]
923\startcontent
924\vtop{\hsize 14cm\relax%
925\getbuffer[annals]}
926\stopcontent
927\startcaption
928No profiling
929\stopcaption
930\startcontent
931\vtop{\hsize 14cm\relax%
932\setupalign[profile]
933\disabletrackers[profiling.lines.show]
934\getbuffer[annals]}
935\stopcontent
936\startcaption
937Profiling
938\stopcaption
939\stopcombination
940\egroup
941\stoptextdisplay
942
943It is worth emphasizing that, contrary to what one might believe at first, the
944profiling does not substantially affect the compilation time. On a 300-page math
945book we tried, which usually compiles in about 10 seconds, profiling did not add
946more than 0.5 seconds. The same observation holds for the other math tweaks we
947have mentioned: the overhead is negligible.
948
949\stopsection
950
951\startsection[title={Conclusions}]
952
953All these tweaks can be overloaded per glyph if needed; for some fonts, we indeed
954do this, in so|-|called goodie files. The good news is that by doing all this we
955present the engine with a font that is consistent, which also means that we can
956more easily control the typeset result in specific circumstances.
957
958The reader may wonder how we ended up with this somewhat confusing state of
959affairs in the font world. Here are some possible reasons. There is only one
960reference font, Cambria, and that uses its reference word processor renderer,
961Word. Then came \XETEX\ that as far as we know maps \OPENTYPE\ math onto a
962traditional \TEX\ engine, so when fonts started coming from the \TEX\ crowd,
963traditional dimensions and parameters sort of fit in. When \LUATEX\ showed up, it
964started from the other end: \OPENTYPE. That works well with the reference font
965but less so with that ones coming from \TEX. Eventually more fonts showed up, and
966it's not clear how these got tested because some lean towards the traditional and
967others towards the reference fonts. And, all in all, these fonts mostly seem to
968be rather untested in real (more complex) math.
969
970The more we looked into the specific properties of \OPENTYPE\ math fonts and
971rendering, the more we got the feeling that it was some hybrid of what \TEX\ does
972(with fonts) and ultimately desired behavior. That works well with Cambria and a
973more or less frozen approach in a word processor, but doesn't suit well with
974\TEX. Bits and pieces are missing, which could have been added from the
975perspective of generalization and imperfections in \TEX\ as well. Lessons learned
976from decades of dealing with math in macros and math fonts were not reflected in
977the \OPENTYPE\ fonts and approach, which is of course understandable as
978\OPENTYPE\ math never especially aimed at \TEX. But that also means that at some
979point one has to draw conclusions and make decisions, which is what we do in
980\CONTEXT, \LUAMETATEX\ and the runtime|-|adapted fonts. And it gives pretty good
981and reliable results.
982
983\stopsection
984
985\stopchapter
986
987\stopcomponent
988