ontarget-jmn.tex /size: 10 Kb    last modification: 2024-01-16 10:21
1% language=us runpath=texruns:manuals/ontarget
2
3% \profilemacro\scaledfontdimen
4
5\usebodyfont[antykwa]
6\usebodyfont[iwona]
7\usebodyfont[kurier]
8
9\startcomponent ontarget-jmn
10
11\environment ontarget-style
12
13\startchapter[title={Supporting math in the JMN collection}]
14
15\startlines
16Hans Hagen, Hasselt NL
17Mikael Sundqvist, Lund SV
18\stoplines
19
20\startsubject[title=Introduction]
21
22In 2022 we overhauled math font support in \CONTEXT, using new functionality in
23the \LUAMETATEX\ engine. By that time it had become clear that the \OPENTYPE\
24math font landscape had more or less settled. The Latin Modern fonts as well as
25the \TEX gyre fonts don't evolve, so we consider them being frozen. It is also
26unlikely that the reference Cambria font will change or become more complete.
27More recent math font are modelled as a mixture of Cambria and Latin Modern.
28
29When we started with \LUATEX\ in \CONTEXT\ we immediately started using \UNICODE\
30math but the lack of proper \UNICODE\ fonts, with the exception of Cambria,
31resulted in creating virtual \UNICODE\ math fonts on the fly using the virtual
32font features of the \LUATEX. But when the \OPENTYPE\ math fonts came available
33that kind of trickery was no longer needed (or at least less preferred).
34
35That is why we considered dropping the virtual math font mechanism from \LMTX. We
36had already dropped \type {tx} (we can use Termes) and \type {px} (better use
37Pagella) fonts as well as \TYPEONE\ based Latin Modern. Dropping the commercial
38Math Times was a logical next step, also because it has never been tested. The
39mixtures of Pagella and Euler were already replaced by using the upgraded tweak
40mechanism.
41
42That left us with Antykwa, Iwona and Kurier, the fonts that the late Janusz
43Nowacky vectorized and that came with plenty \OPENTYPE\ text fonts but also with
44\TYPEONE\ math companions. And, as we like these fonts, it meant that we had to
45come up with a solution. One option was to create proper \OPENTYPE\ math fonts, but
46another was to strip down the virtual math font mechanism to just support these
47fonts. There is some charm in keeping the \TYPEONE\ fonts, also because it is a
48test case for (by now sort of obsolete) \TFM\ metric, \PFB\ outline, encoding and
49map files, for which we have code embedded so having a proper test case makes
50sense.
51
52In the end we opted for the second solution so this is what the next sections are
53about: supporting \OPENTYPE\ math using \TYPEONE\ fonts. We admit that it took
54way more time than a conversion to \OPENTYPE\ math fonts would have, but that is
55partly due to the fact that these fonts, and especially Antykwa, have some
56characteristic features that we wanted to use. So, in a sense it was also an
57esthetics challenge. It also helped that the font was used in realistic and
58moderately complex math rendering. We also note that rendering in \LMTX\ is
59different (and hopefully better) than in \MKIV\ because we try to benefit from
60the upgraded math engine in \LUAMETATEX.
61
62This exploration is dedicated to Janusz who was one of the characteristic
63presenters of fonts at Bacho\TEX\ meetings, who contributed these fonts, and
64who in some sense was thereby kick starting the Polish \TEX\ related font
65projects.
66
67\stopsubject
68
69\startsubject[title=Virtual math]
70
71We keep this expose simple and only tell what we did, you can look at the \type
72{lfg} files and source code to see what magick is done. For the standard Antykwa
73we load \typ {LatinModern-Math} first, so we cover all symbols that matter. Next
74we stepwise load \typ {rm-anttr.tfm}, \typ {mi-anttri.tfm}, \typ {mi-anttbi.tfm},
75\typ {rm-anttb.tfm}, \typ {sy-anttrz.tfm}, \typ {ex-anttr.tfm}. For each we
76specify an encoding vector. Some are loaded multiple times with different
77vectors. Because we don't like the slanted curly braces we even load \typ
78{AntykwaTorunska-Regular} in order to get the upright ones. This method is not that
79different from what we do in \MKIV.
80
81The specification of a loaded font also can contain a list of (named) characters
82that should be ignored, That was one of the new features in the virtual
83constructor. We take the math parameters from the fonts where these are
84specified, here in the symbols and extension fonts.
85
86The fonts contain extra snippets of extensibles that one can use to construct
87some of these vertical and horizontal stretched symbols on the fly in addition to
88what the font metrics already define. Unfortunately some snippets are missing,
89like the six pieces that could make up horizontal and vertical bars, for which we
90now need to cheat. We considered making a companion font but for now we are in
91\quote {as good as we can} emulation mode.
92
93\stopsubject
94
95\startsubject[title=The fonts]
96
97We start out with a skeleton font and in the past we used the \OPENTYPE\ text
98font for that. On top of that we overlay a bunch of \TYPEONE\ fonts, and as was
99common in those days, the \AMS\ math symbol fonts \type {msa} and \type {msb}
100were overlayed last in order to fill in remaining gaps. However, now that we have
101a Latin Modern \OPENTYPE\ math font it made more sense to use that as starting
102point because it already has all these symbols.
103
104If we forget about the additional weights and condensed variants, the JMN math
105collection has actually not that many fonts. One reason for that is that the
106upright roman font, the ones that have an \type {r} near the end of the file
107name, in traditional \TEX\ speak \type {rm}, have way more than 255 characters:
108it not only has all kind of composed characters, it also has all the extensible
109shapes. All is (as usual with \TYPEONE\ fonts) driven by encoding and mapping
110files. Fortunately the glyphs names (that we use for filtering) are the same for
111the three fonts but there are some more in Antykwa.
112
113\stopsubject
114
115\startsubject[title=Challenges]
116
117The real challenge was Antykwa. This is because it has a distinctive curvature at
118the end of sticky parts (like rules and such). The \TEX\ machinery as well as
119\OPENTYPE\ math assume rules being used in for instance radicals, fractions,
120overbars, underbars and vertical bar fences.
121
122\startlinecorrection
123\scale[width=\textwidth]{\switchtobodyfont[antykwa]\im {
124    \showglyphs
125    \mathbin{-}
126    \mathbin{+}
127    \mathbin{=}
128    \mathbin{<}
129    \mathbin{>}
130}}
131\stoplinecorrection
132
133The last three come in not only sizes (aka variants) but also can stretch (aka
134extensible). And, them being just rules it is assumes that the \TEX\ engine deals
135with that, and as it cannot really do that without characters, the traditional
136approach is to use commands that use \TEX\ rules. However, in \CONTEXT\ (\MKIV\
137and \LMTX) we can provide the proper variants and extensible using virtual
138shapes, and in \LMTX\ we can even scale as last resort.
139
140The first two are special. We already could support fractions using dedicated
141characters because we played with the fraction builder using for instance arrows
142as separator and these are not rules but characters. It was not that much work to
143also make that possible for the rule in a radical. The main adaptation was that
144we need to center the numerator and denominator of a fraction and the body of a
145radical when the character used is wider than requested.
146
147\startlinecorrection
148\scale[height=2cm]{\switchtobodyfont[antykwa]\im {
149    \showglyphs
150    \sqrt{x+1} -
151    \fenced[bar]{
152        \frac{1}{x+1}
153    }
154}}
155\stoplinecorrection
156
157Because we have two font models in \CONTEXT, normal and compact, we had to be careful
158in defining the virtual shapes and extensibles so that they work in both models. This
159has to do with scaling and sharing.
160
161\stopsubject
162
163\startsubject[title=Implementation]
164
165The original virtual math font mechanism worked closely with the math fall back
166features, but these have been replaced by tweaks, which means that we lost some
167of that. Also, heuristics worked fine on the average but for Antykwa we wanted
168more. Therefore some of the built in logic has been moved to the goodie file that
169controls the composition. After all, we don't want to hard code specific
170solutions in the core.
171
172Another addition was the use of so called setups bound to a font class so that we
173can set up some math machinery features for e.g.\ Antykwa in the goodie file. We
174need to bind to a class because we mix a dozen math fonts in one test file and
175therefore we need to separate these setups.
176
177As in regular \OPENTYPE\ math support we ignore the italic correction and translate
178it in combinations of proper width and specific kerning. That way we avoid all kind
179of issues that we otherwise need to compensate for.
180
181Because we need to hook extensible characters into the machine for Antykwa its
182font typescript file also defines a font class specific setup (of a few lines) to
183be applied. This might evolve into a more granular mechanism but for now it works
184fine and adds little overhead.
185
186\stopsubject
187
188\startsubject[title=Examples]
189
190We end by showing a few \quotation{real} examples.
191
192\bgroup\switchtobodyfont[antykwa]
193\startformula
194\binom{n}{k} = \frac{n!}{k!(n-k)!}\mtp{,} 0 \leq k \leq n\mtp{.}
195\stopformula
196\egroup
197
198The parentheses are unchanged, and we believe that using rotation symmetry
199instead of mirror symmetry is a brave but interesting choice, and the new
200fraction bar fits well with it. The fraction bar also fits well with the equal
201sign.
202
203\bgroup
204\switchtobodyfont[antykwa]
205\startformula
2061 + x + x^2 + \ldots + x^n = \frac{1 - x^{n+1}}{1 - x}
207\stopformula
208\egroup
209
210The new vertical bars go well with the brackets, the integral and the solidus.
211
212\bgroup
213\switchtobodyfont[antykwa]
214\startformula
215\fenced[doublebar]{f}_p = \F3\left[ \int_0^1 \fenced[bar]{f(x)}^p \dd x \right]^{1/p}
216\stopformula
217\egroup
218
219The fancy fraction bar and the radical bar have made the arithmetic|-|geometric
220mean inequality look more appealing than ever, hasn't it?
221
222\bgroup
223\switchtobodyfont[antykwa]
224\startformula
225    \frac{a_1 + a_2 + \ldots + a_n}{n} \geq \root[n=n]{a_1 a_2 \ldots a_n}
226\stopformula
227\egroup
228
229Primes are usually a bit of a challenge:
230
231\bgroup
232\switchtobodyfont[antykwa]
233\startformula
234f(k+1)-f(k) \alignhere = f'(k)+f''(k)\frac{1}{2}+f'''(\xi_k)\frac{1}{6}
235            \breakhere = k^p+\frac{p}{2}k^{p-1}+\frac{p(p-1)}{6}\xi_k^{p-2}
236\stopformula
237\egroup
238
239And, as expected, multi|-|line formulas also look fine.
240
241\stopsubject
242
243\stopchapter
244
245\stopcomponent
246