math-fonts.tex /size: 9 Kb    last modification: 2024-01-16 10:21
1% language=us runpath=texruns:manuals/math
2
3\environment math-layout
4\environment math-fonts-helpers
5
6% todo: use "keep-latin-modern-math.otf" and "keep-texgyre-pagella-math.otf"
7
8\startcomponent math-fonts
9
10\startchapter[title=Fonts]
11
12\startsection[title=Introduction]
13
14In this document we will discuss how we deal with \OPENTYPE\ math fonts. There is
15a set of samples that are used for testing. One problem is that these fonts
16evolve so what we discuss and fix today might not be applicable tomorrow in which
17case this document can also be seen from a historic perspective. We will mostly
18use \CONTEXT\ speak.
19
20The examples that we show use test files and normally they should render okay. If
21not, we need to fix something. They are part of a set of test files by Mikael
22Sundqvist and Hans Hagen made in the perspective of defining proper goodie files
23and this chapter summarizes our journey.
24
25{\em This chapter is uncorrected work in progress.}
26
27\stopsection
28
29\startsection[title=Italics]
30
31First of all we need to mention some fundamental differences between a
32traditional setup and one for \OPENTYPE\ \UNICODE\ fonts. When \TEX\ showed up,
33fonts had at most 256 characters. Sets of characters are organized in so called
34families of which there are 16: family zero is the one used for what is called
35roman (upright), family one for so called math italic characters, family two for
36all kind of symbols and family three for extensible characters. The \TEX\
37distribution comes with matching fonts. Now, when one enters a formula like this:
38
39\starttyping
40y = \sqrt{x^2 + 4}
41\stoptyping
42
43the \type {x} and \type {y} are math italics (family 1), \type {1} and \type {2}
44are upright (family 0), the \type {+} is a symbol (family 2) and the radical
45comes from family 3 as it can differ in size. The letters are actually from the
46math {\it italic} alphabet and there can be other alphabets: bold, bold italic,
47blackboard, script, etc. For these one defines additional families or when one
48runs out of families symbolic names can be used to map to the non alphabetic
49\ASCII\ slots.
50
51In \CONTEXT\ right from when we started with \LUATEX\ the multiple families were
52dropped in favor of just one. \footnote {This is not entirely true because we
53also have one for bold, and two for r2l regular and bold, but these are dealt
54with in a special way: all definitions use family zero.} Because \UNICODE\ has a
55concept of math alphabets (unfortunately with holes) we use \UNICODE\ \OPENTYPE\
56fonts as well as (certainly before there was anything else than Cambria) virtual
57(runtime) assemblies of traditional \TYPEONE\ fonts.
58
59In this and following chapters we only discuss the \OPENTYPE\ fonts because that
60is what we normally deal with. One complication there is that, although Cambria
61set a clear standard, the fonts that evolved in the \TEX\ ecosystem are to a
62large extend modelled after the traditional \TEX\ fonts. Fonts that originate
63from elsewhere are a mix of both models. And it is this curious mix of approaches
64that forces us to adapt the machinery and|/|or the fonts to our needs. For a long
65time \CONTEXT\ assumed some consistency and although there were mechanisms in
66place to deal with these (often not) subtle differences, in the long run that was
67not what we wanted. So, when these fonts became more and more frozen we decided
68to go for a more individual long term \quote {fix them runtime} solution.
69
70A result is that in \LMTX\ we use a similar approach as in \MKIV\ but instead of
71trying to fix the fonts automatically (driven by pseudo features), we now
72delegate that to the font goodie mechanism where we can also fine tune more
73easily per font: runtime tweaks. The basics are the same but it is a bit easier
74that way, also because in the worst case one can program a specific tweak without
75side effects for the rest.
76
77\startplacefigure[title={Italics Sample 2}]
78    \externalfigure
79        [math-fonts-italics-002.tex]
80        [width=\textwidth]
81\stopplacefigure
82
83The tweak that deals with italics (and other shapes) is:
84
85\starttabulate[|T|||]
86\NC tweak \NC \type {dimensions} \NC \NC \NR
87\NC list  \NC table \NC a hash with treatments \NC \NR
88\stoptabulate
89
90\stopsection
91
92\startsection[title={Primes}]
93
94% \ctxlua{nodes.tasks.disableaction("math","noads.handlers.fixscripts")}
95% \ctxlua{nodes.tasks.enableaction("math","noads.handlers.fixscripts")}
96
97Primes are implemented in a curious way. In traditional \TEX\ they are treated as
98superscripts which is often achieved by making the single quote into an active
99character (in math mode) that takes care of this. The dimensions of a prime are
100such that it comes at the right spot (according to the designers wish). However,
101in \UNICODE\ the same symbol is used for minutes in text mode and because there
102are no duplicates in \UNICODE, it is that already superscripted symbol that we
103see show up in fonts. There is (for some reason) no dedicated single prime slot
104(and one can argue that minutes and primes are really different things and if
105not, why then does greek and latin don't share more).
106
107In \CONTEXT\ we don't want to mess with active characters and even more, we want
108proper symbols for the multiple primes. At the same time we need to handle
109following superscripts as well as cases where a subscript is used as index to a
110nucleus where the whole is then primed. This is implemented in a combination of
111\TEX, \LUA\ and normalized prime symbols.
112
113\startplacefigure[title={Primes Sample 1}]
114    \externalfigure
115        [math-fonts-primes-001.tex]
116        [width=\textwidth]
117\stopplacefigure
118
119Fixing primes boils down to fixing dimensions and repositioning the shape.
120Optionally the multiples can be emulated and a smaller size can be chosen. It's
121also a matter of taste and primes are often not the best designed symbols.
122
123The specification is:
124
125\starttabulate[|T|||]
126\NC tweak   \NC \type {fixprimes} \NC \NC \NR
127\NC factor  \NC number  \NC fraction of the accent base height that the prime shifts up \NC \NR
128\NC smaller \NC boolean \NC when \type {true}, replace multiples \NC \NR
129\NC scale   \NC number  \NC the glyph scale \NC \NR
130\NC fake    \NC number  \NC when set, fake multiples and use this width 0.75 \NC \NR
131\NC keep    \NC boolean \NC keep text size prime as it is \NC \NR
132\stoptabulate
133
134In \MKIV\ we remap primes but in \LMTX\ we adapt the regular slots. As a
135consequence we sacrifice the text size minutes. The \type {keep} option will
136leave the text size variant as it is.
137
138Keep in mind that primes are processed depending on what precedes and follows so
139you cannot really test a character by just calling it: when there is something in
140front it will become a superscripted prime.
141
142\stopsection
143
144\startsection[title={Scripts}]
145
146This tweak will add superscript characters for plus and minus. The main reason
147for them being supplied is that we need them to indicate an explicit (minus)
148sign in calculator math examples.
149
150\startplacefigure[title={Scripts Sample 1}]
151    \externalfigure
152        [math-fonts-scripts-001.tex]
153        [width=\textwidth]
154\stopplacefigure
155
156The specification is:
157
158\starttabulate[|T|||]
159\NC tweak \NC \type {addscripts} \NC \NC \NR
160\NC scale \NC number \NC the scale of the scripted character \NC \NR
161\stoptabulate
162
163Keep in mind that these scripts are processed depending on what precedes so you
164cannot really test a character by just calling it.
165
166\stopsection
167
168\startsection[title={Radicals}]
169
170The traditional \TEX\ engine is made in conjunction with the Computer Modern
171Fonts and there the radical symbol sits below the baseline so that the height
172indicates the rule thickness. In \OPENTYPE\ fonts this is a variable. The Latin
173Modern Math font inherits this somewhat strange position property but we can fix
174that with this tweak:
175
176\startplacefigure[title={Radicals Sample 1}]
177    \externalfigure
178        [math-fonts-radicals-001.tex]
179        [width=\textwidth]
180\stopplacefigure
181
182There are no options:
183
184\starttabulate[|T|||]
185\NC tweak \NC \type {fixradicals} \NC \NC \NR
186\stoptabulate
187
188\stopsection
189
190\startsection[title={Accents}]
191
192We cannot yet tweak accents, but here is an example:
193
194\startplacefigure[title={Accents Sample 1}]
195    \externalfigure
196        [math-fonts-accents-001.tex]
197        [width=\textwidth]
198\stopplacefigure
199
200\stopsection
201
202\startsection[title={Spacing}]
203
204There are \UNICODE\ characters for various spaces and this option defines them
205when they are not present. It is up to the macro package to make sure that the
206non breakable spaces are treated as such. In this document we get:
207
208\def\ShowSpacing#1#2%
209  {\NC \ruledhbox{\showmakeup[glue]\showstruts\strut\char"#1\strut}\NC#2\NC\NR}
210
211\starttabulate[|w(1.5em)|T|]
212    \ShowSpacing{00A0}{nbsp}
213    \ShowSpacing{2000}{enquad}
214    \ShowSpacing{2001}{emquad}
215    \ShowSpacing{2002}{enspace}
216    \ShowSpacing{2003}{emspace}
217    \ShowSpacing{2004}{threeperemspace}
218    \ShowSpacing{2005}{fourperemspace}
219    \ShowSpacing{2006}{sixperemspace}
220    \ShowSpacing{2007}{figurespace}
221    \ShowSpacing{2008}{punctuationspace}
222    \ShowSpacing{2009}{breakablethinspace}
223    \ShowSpacing{200A}{hairspace}
224    \ShowSpacing{200B}{zerowidthspace}
225    \ShowSpacing{202F}{narrownobreakspace}
226    \ShowSpacing{205F}{maththinspace}
227\stoptabulate
228
229There are no options:
230
231\starttabulate[|T|||]
232\NC tweak \NC \type {checkspacing} \NC \NC \NR
233\stoptabulate
234
235\stopsection
236
237\startsection[title=Parameters]
238
239An \OPENTYPE\ math fonts has a lot of parameters and because the engine let you
240set them for every style (regular and cramped) you can exercise a lot of control.
241A difference with traditional math is that we only have one cramped parameter:
242\typ {SuperscriptShiftUpCramped}.
243
244\startbuffer
245\startoverlay
246    {\ruledhbox{$\strut \red  \displaystyle        x^2_1 x^2 x_1$}}
247    {\ruledhbox{$\strut \blue \crampeddisplaystyle x^2_1 x^2 x_1$}}
248\stopoverlay
249\stopbuffer
250
251\typebuffer
252
253Only the superscript is affected (in some miraculous way):
254
255\startlinecorrection
256    \scale[height=3cm]{\switchtobodyfont[pagella]\getbuffer}
257\stoplinecorrection
258
259\stopsection
260
261\stopchapter
262
263\stopcomponent
264