luatex-math.tex /size: 70 Kb    last modification: 2023-12-21 09:43
1% language=us engine=luatex runpath=texruns:manuals/luatex
2
3\environment luatex-style
4
5\startcomponent luatex-math
6
7\startchapter[reference=math,title={Math}]
8
9\startsection[title={Traditional alongside \OPENTYPE}]
10
11\topicindex {math}
12
13The handling of mathematics in \LUATEX\ differs quite a bit from how \TEX82 (and
14therefore \PDFTEX) handles math. First, \LUATEX\ adds primitives and extends some
15others so that \UNICODE\ input can be used easily. Second, all of \TEX82's
16internal special values (for example for operator spacing) have been made
17accessible and changeable via control sequences. Third, there are extensions that
18make it easier to use \OPENTYPE\ math fonts. And finally, there are some
19extensions that have been proposed or considered in the past that are now added
20to the engine.
21
22\stopsection
23
24\startsection[title={Unicode math characters}]
25
26\topicindex {math+\UNICODE}
27\topicindex {\UNICODE+math}
28
29Character handling is now extended up to the full \UNICODE\ range (the \type {\U}
30prefix), which is compatible with \XETEX.
31
32The math primitives from \TEX\ are kept as they are, except for the ones that
33convert from input to math commands: \type {mathcode}, and \type {delcode}. These
34two now allow for a 21-bit character argument on the left hand side of the equals
35sign.
36
37Some of the new \LUATEX\ primitives read more than one separate value. This is
38shown in the tables below by a plus sign.
39
40The input for such primitives would look like this:
41
42\starttyping
43\def\overbrace{\Umathaccent 0 1 "23DE }
44\stoptyping
45
46The altered \TEX82 primitives are:
47
48\starttabulate[|l|l|r|c|l|r|]
49\DB primitive       \BC min \BC max    \BC \kern 2em \BC min \BC max    \NC \NR
50\TB
51\NC \prm {mathcode} \NC 0   \NC 10FFFF \NC =         \NC 0   \NC 8000   \NC \NR
52\NC \prm {delcode}  \NC 0   \NC 10FFFF \NC =         \NC 0   \NC FFFFFF \NC \NR
53\LL
54\stoptabulate
55
56The unaltered ones are:
57
58\starttabulate[|l|l|r|]
59\DB primitive          \BC min \BC max     \NC \NR
60\TB
61\NC \prm {mathchardef} \NC 0   \NC    8000 \NC \NR
62\NC \prm {mathchar}    \NC 0   \NC    7FFF \NC \NR
63\NC \prm {mathaccent}  \NC 0   \NC    7FFF \NC \NR
64\NC \prm {delimiter}   \NC 0   \NC 7FFFFFF \NC \NR
65\NC \prm {radical}     \NC 0   \NC 7FFFFFF \NC \NR
66\LL
67\stoptabulate
68
69For practical reasons \prm {mathchardef} will silently accept values larger
70that \type {0x8000} and interpret it as \lpr {Umathcharnumdef}. This is needed
71to satisfy older macro packages.
72
73The following new primitives are compatible with \XETEX:
74
75% somewhat fuzzy:
76
77\starttabulate[|l|l|r|c|l|r|]
78\DB primitive                             \BC min       \BC max         \BC \kern 2em \BC min       \BC max         \NC \NR
79\TB
80\NC \lpr {Umathchardef}                   \NC 0+0+0     \NC 7+FF+10FFFF \NC           \NC           \NC             \NC \NR
81\NC \lpr {Umathcharnumdef}\rlap{\high{5}} \NC -80000000 \NC    7FFFFFFF \NC           \NC           \NC             \NC \NR
82\NC \lpr {Umathcode}                      \NC 0         \NC      10FFFF \NC =         \NC 0+0+0     \NC 7+FF+10FFFF \NC \NR
83\NC \lpr {Udelcode}                       \NC 0         \NC      10FFFF \NC =         \NC 0+0       \NC   FF+10FFFF \NC \NR
84\NC \lpr {Umathchar}                      \NC 0+0+0     \NC 7+FF+10FFFF \NC           \NC           \NC             \NC \NR
85\NC \lpr {Umathaccent}                    \NC 0+0+0     \NC 7+FF+10FFFF \NC           \NC           \NC             \NC \NR
86\NC \lpr {Udelimiter}                     \NC 0+0+0     \NC 7+FF+10FFFF \NC           \NC           \NC             \NC \NR
87\NC \lpr {Uradical}                       \NC 0+0       \NC   FF+10FFFF \NC           \NC           \NC             \NC \NR
88\NC \lpr {Umathcharnum}                   \NC -80000000 \NC    7FFFFFFF \NC           \NC           \NC             \NC \NR
89\NC \lpr {Umathcodenum}                   \NC 0         \NC      10FFFF \NC =         \NC -80000000 \NC    7FFFFFFF \NC \NR
90\NC \lpr {Udelcodenum}                    \NC 0         \NC      10FFFF \NC =         \NC -80000000 \NC    7FFFFFFF \NC \NR
91\LL
92\stoptabulate
93
94Specifications typically look like:
95
96\starttyping
97\Umathchardef\xx="1"0"456
98\Umathcode   123="1"0"789
99\stoptyping
100
101The new primitives that deal with delimiter|-|style objects do not set up a
102\quote {large family}. Selecting a suitable size for display purposes is expected
103to be dealt with by the font via the \lpr {Umathoperatorsize} parameter.
104
105For some of these primitives, all information is packed into a single signed
106integer. For the first two (\lpr {Umathcharnum} and \lpr {Umathcodenum}), the
107lowest 21 bits are the character code, the 3 bits above that represent the math
108class, and the family data is kept in the topmost bits. This means that the values
109for math families 128--255 are actually negative. For \lpr {Udelcodenum} there
110is no math class. The math family information is stored in the bits directly on
111top of the character code. Using these three commands is not as natural as using
112the two- and three|-|value commands, so unless you know exactly what you are
113doing and absolutely require the speedup resulting from the faster input
114scanning, it is better to use the verbose commands instead.
115
116The \lpr {Umathaccent} command accepts optional keywords to control various
117details regarding math accents. See \in {section} [mathacc] below for details.
118
119There are more new primitives and all of these will be explained in following
120sections:
121
122\starttabulate[|l|l|]
123\DB primitive                \BC value range (in hex) \NC \NR
124\TB
125\NC \lpr {Uroot}           \NC 0 + 0--FF + 10FFFF   \NC \NR
126\NC \lpr {Uoverdelimiter}  \NC 0 + 0--FF + 10FFFF   \NC \NR
127\NC \lpr {Uunderdelimiter} \NC 0 + 0--FF + 10FFFF   \NC \NR
128\NC \lpr {Udelimiterover}  \NC 0 + 0--FF + 10FFFF   \NC \NR
129\NC \lpr {Udelimiterunder} \NC 0 + 0--FF + 10FFFF   \NC \NR
130\LL
131\stoptabulate
132
133Instead of the pseudo class variable (7) you can use a family number as signal
134for using the current family. This permits classifying characters with a class
135and still let the family adapt. The trigger family is set with \lpr
136{variablefam}. So:
137
138\starttyping
139\variablefam"24
140\Umathchardef\foo "3 "24 123
141\foo \fam9
142\stoptyping
143
144Results in a curly left brace taken from family 9 with class \quote {relation}
145and spacing around it will be accordingly.
146
147\stopsection
148
149\startsection[title={Math styles}]
150
151\subsection{\lpr {mathstyle}}
152
153\topicindex {math+styles}
154
155It is possible to discover the math style that will be used for a formula in an
156expandable fashion (while the math list is still being read). To make this
157possible, \LUATEX\ adds the new primitive: \lpr {mathstyle}. This is a \quote
158{convert command} like e.g. \prm {romannumeral}: its value can only be read,
159not set.
160
161The returned value is between 0 and 7 (in math mode), or $-1$ (all other modes).
162For easy testing, the eight math style commands have been altered so that they can
163be used as numeric values, so you can write code like this:
164
165\starttyping
166\ifnum\mathstyle=\textstyle
167    \message{normal text style}
168\else \ifnum\mathstyle=\crampedtextstyle
169    \message{cramped text style}
170\fi \fi
171\stoptyping
172
173Sometimes you won't get what you expect so a bit of explanation might help to
174understand what happens. When math is parsed and expanded it gets turned into a
175linked list. In a second pass the formula will be build. This has to do with the
176fact that in order to determine the automatically chosen sizes (in for instance
177fractions) following content can influence preceding sizes. A side effect of this
178is for instance that one cannot change the definition of a font family (and
179thereby reusing numbers) because the number that got used is stored and used in
180the second pass (so changing \type {\fam 12} mid|-|formula spoils over to
181preceding use of that family).
182
183The style switching primitives like \prm {textstyle} are turned into nodes so the
184styles set there are frozen. The \prm {mathchoice} primitive results in four
185lists being constructed of which one is used in the second pass. The fact that
186some automatic styles are not yet known also means that the \lpr {mathstyle}
187primitive expands to the current style which can of course be different from the
188one really used. It's a snapshot of the first pass state. As a consequence in the
189following example you get a style number (first pass) typeset that can actually
190differ from the used style (second pass). In the case of a math choice used
191ungrouped, the chosen style is used after the choice too, unless you group.
192
193\startbuffer[1]
194    [a:\mathstyle]\quad
195    \bgroup
196    \mathchoice
197        {\bf \scriptstyle       (x:d :\mathstyle)}
198        {\bf \scriptscriptstyle (x:t :\mathstyle)}
199        {\bf \scriptscriptstyle (x:s :\mathstyle)}
200        {\bf \scriptscriptstyle (x:ss:\mathstyle)}
201    \egroup
202    \quad[b:\mathstyle]\quad
203    \mathchoice
204        {\bf \scriptstyle       (y:d :\mathstyle)}
205        {\bf \scriptscriptstyle (y:t :\mathstyle)}
206        {\bf \scriptscriptstyle (y:s :\mathstyle)}
207        {\bf \scriptscriptstyle (y:ss:\mathstyle)}
208    \quad[c:\mathstyle]\quad
209    \bgroup
210    \mathchoice
211        {\bf \scriptstyle       (z:d :\mathstyle)}
212        {\bf \scriptscriptstyle (z:t :\mathstyle)}
213        {\bf \scriptscriptstyle (z:s :\mathstyle)}
214        {\bf \scriptscriptstyle (z:ss:\mathstyle)}
215    \egroup
216    \quad[d:\mathstyle]
217\stopbuffer
218
219\startbuffer[2]
220    [a:\mathstyle]\quad
221    \begingroup
222    \mathchoice
223        {\bf \scriptstyle       (x:d :\mathstyle)}
224        {\bf \scriptscriptstyle (x:t :\mathstyle)}
225        {\bf \scriptscriptstyle (x:s :\mathstyle)}
226        {\bf \scriptscriptstyle (x:ss:\mathstyle)}
227    \endgroup
228    \quad[b:\mathstyle]\quad
229    \mathchoice
230        {\bf \scriptstyle       (y:d :\mathstyle)}
231        {\bf \scriptscriptstyle (y:t :\mathstyle)}
232        {\bf \scriptscriptstyle (y:s :\mathstyle)}
233        {\bf \scriptscriptstyle (y:ss:\mathstyle)}
234    \quad[c:\mathstyle]\quad
235    \begingroup
236    \mathchoice
237        {\bf \scriptstyle       (z:d :\mathstyle)}
238        {\bf \scriptscriptstyle (z:t :\mathstyle)}
239        {\bf \scriptscriptstyle (z:s :\mathstyle)}
240        {\bf \scriptscriptstyle (z:ss:\mathstyle)}
241    \endgroup
242    \quad[d:\mathstyle]
243\stopbuffer
244
245\typebuffer[1]
246
247% \typebuffer[2]
248
249This gives:
250
251\blank $\displaystyle \getbuffer[1]$ \blank
252\blank $\textstyle    \getbuffer[1]$ \blank
253
254Using \prm {begingroup} \unknown\ \prm {endgroup} instead gives:
255
256\blank $\displaystyle \getbuffer[2]$ \blank
257\blank $\textstyle    \getbuffer[2]$ \blank
258
259This might look wrong but it's just a side effect of \lpr {mathstyle} expanding
260to the current (first pass) style and the number being injected in the list that
261gets converted in the second pass. It all makes sense and it illustrates the
262importance of grouping. In fact, the math choice style being effective afterwards
263has advantages. It would be hard to get it otherwise.
264
265\subsection{\lpr {Ustack}}
266
267\topicindex {math+stacks}
268
269There are a few math commands in \TEX\ where the style that will be used is not
270known straight from the start. These commands (\prm {over}, \prm {atop},
271\prm {overwithdelims}, \prm {atopwithdelims}) would therefore normally return
272wrong values for \lpr {mathstyle}. To fix this, \LUATEX\ introduces a special
273prefix command: \lpr {Ustack}:
274
275\starttyping
276$\Ustack {a \over b}$
277\stoptyping
278
279The \lpr {Ustack} command will scan the next brace and start a new math group
280with the correct (numerator) math style.
281
282\subsection{Cramped math styles}
283
284\topicindex {math+styles}
285\topicindex {math+spacing}
286\topicindex {math+cramped}
287
288\LUATEX\ has four new primitives to set the cramped math styles directly:
289
290\starttyping
291\crampeddisplaystyle
292\crampedtextstyle
293\crampedscriptstyle
294\crampedscriptscriptstyle
295\stoptyping
296
297These additional commands are not all that valuable on their own, but they come
298in handy as arguments to the math parameter settings that will be added shortly.
299
300In Eijkhouts \quotation {\TEX\ by Topic} the rules for handling styles in scripts
301are described as follows:
302
303\startitemize
304\startitem
305    In any style superscripts and subscripts are taken from the next smaller style.
306    Exception: in display style they are in script style.
307\stopitem
308\startitem
309    Subscripts are always in the cramped variant of the style; superscripts are only
310    cramped if the original style was cramped.
311\stopitem
312\startitem
313    In an \type {..\over..} formula in any style the numerator and denominator are
314    taken from the next smaller style.
315\stopitem
316\startitem
317    The denominator is always in cramped style; the numerator is only in cramped
318    style if the original style was cramped.
319\stopitem
320\startitem
321    Formulas under a \type {\sqrt} or \prm {overline} are in cramped style.
322\stopitem
323\stopitemize
324
325In \LUATEX\ one can set the styles in more detail which means that you sometimes
326have to set both normal and cramped styles to get the effect you want. (Even) if
327we force styles in the script using \prm {scriptstyle} and \lpr
328{crampedscriptstyle} we get this:
329
330\startbuffer[demo]
331\starttabulate
332\DB style         \BC example \NC \NR
333\TB
334\NC default       \NC $b_{x=xx}^{x=xx}$ \NC \NR
335\NC script        \NC $b_{\scriptstyle x=xx}^{\scriptstyle x=xx}$ \NC \NR
336\NC crampedscript \NC $b_{\crampedscriptstyle x=xx}^{\crampedscriptstyle x=xx}$ \NC \NR
337\LL
338\stoptabulate
339\stopbuffer
340
341\getbuffer[demo]
342
343Now we set the following parameters
344
345\startbuffer[setup]
346\Umathordrelspacing\scriptstyle=30mu
347\Umathordordspacing\scriptstyle=30mu
348\stopbuffer
349
350\typebuffer[setup]
351
352This gives a different result:
353
354\start\getbuffer[setup,demo]\stop
355
356But, as this is not what is expected (visually) we should say:
357
358\startbuffer[setup]
359\Umathordrelspacing\scriptstyle=30mu
360\Umathordordspacing\scriptstyle=30mu
361\Umathordrelspacing\crampedscriptstyle=30mu
362\Umathordordspacing\crampedscriptstyle=30mu
363\stopbuffer
364
365\typebuffer[setup]
366
367Now we get:
368
369\start\getbuffer[setup,demo]\stop
370
371\stopsection
372
373\startsection[title={Math parameter settings}]
374
375\subsection {Many new \lpr {Umath*} primitives}
376
377\topicindex {math+parameters}
378
379In \LUATEX, the font dimension parameters that \TEX\ used in math typesetting are
380now accessible via primitive commands. In fact, refactoring of the math engine
381has resulted in many more parameters than were not accessible before.
382
383\starttabulate
384\DB primitive name                   \BC description \NC \NR
385\TB
386\NC \lpr {Umathquad}               \NC the width of 18 mu's \NC \NR
387\NC \lpr {Umathaxis}               \NC height of the vertical center axis of
388                                         the math formula above the baseline \NC \NR
389\NC \lpr {Umathoperatorsize}       \NC minimum size of large operators in display mode \NC \NR
390\NC \lpr {Umathoverbarkern}        \NC vertical clearance above the rule \NC \NR
391\NC \lpr {Umathoverbarrule}        \NC the width of the rule \NC \NR
392\NC \lpr {Umathoverbarvgap}        \NC vertical clearance below the rule \NC \NR
393\NC \lpr {Umathunderbarkern}       \NC vertical clearance below the rule \NC \NR
394\NC \lpr {Umathunderbarrule}       \NC the width of the rule \NC \NR
395\NC \lpr {Umathunderbarvgap}       \NC vertical clearance above the rule \NC \NR
396\NC \lpr {Umathradicalkern}        \NC vertical clearance above the rule \NC \NR
397\NC \lpr {Umathradicalrule}        \NC the width of the rule \NC \NR
398\NC \lpr {Umathradicalvgap}        \NC vertical clearance below the rule \NC \NR
399\NC \lpr {Umathradicaldegreebefore}\NC the forward kern that takes place before placement of
400                                       the radical degree \NC \NR
401\NC \lpr {Umathradicaldegreeafter} \NC the backward kern that takes place after placement of
402                                       the radical degree \NC \NR
403\NC \lpr {Umathradicaldegreeraise} \NC this is the percentage of the total height and depth of
404                                       the radical sign that the degree is raised by; it is
405                                       expressed in \type {percents}, so 60\% is expressed as the
406                                       integer $60$ \NC \NR
407\NC \lpr {Umathstackvgap}          \NC vertical clearance between the two
408                                       elements in a \prm {atop} stack \NC \NR
409\NC \lpr {Umathstacknumup}         \NC numerator shift upward in \prm {atop} stack \NC \NR
410\NC \lpr {Umathstackdenomdown}     \NC denominator shift downward in \prm {atop} stack \NC \NR
411\NC \lpr {Umathfractionrule}       \NC the width of the rule in a \prm {over} \NC \NR
412\NC \lpr {Umathfractionnumvgap}    \NC vertical clearance between the numerator and the rule \NC \NR
413\NC \lpr {Umathfractionnumup}      \NC numerator shift upward in \prm {over} \NC \NR
414\NC \lpr {Umathfractiondenomvgap}  \NC vertical clearance between the denominator and the rule \NC \NR
415\NC \lpr {Umathfractiondenomdown}  \NC denominator shift downward in \prm {over} \NC \NR
416\NC \lpr {Umathfractiondelsize}    \NC minimum delimiter size for \type {\...withdelims} \NC \NR
417\NC \lpr {Umathlimitabovevgap}     \NC vertical clearance for limits above operators \NC \NR
418\NC \lpr {Umathlimitabovebgap}     \NC vertical baseline clearance for limits above operators \NC \NR
419\NC \lpr {Umathlimitabovekern}     \NC space reserved at the top of the limit \NC \NR
420\NC \lpr {Umathlimitbelowvgap}     \NC vertical clearance for limits below operators \NC \NR
421\NC \lpr {Umathlimitbelowbgap}     \NC vertical baseline clearance for limits below operators \NC \NR
422\NC \lpr {Umathlimitbelowkern}     \NC space reserved at the bottom of the limit \NC \NR
423\NC \lpr {Umathoverdelimitervgap}  \NC vertical clearance for limits above delimiters \NC \NR
424\NC \lpr {Umathoverdelimiterbgap}  \NC vertical baseline clearance for limits above delimiters \NC \NR
425\NC \lpr {Umathunderdelimitervgap} \NC vertical clearance for limits below delimiters \NC \NR
426\NC \lpr {Umathunderdelimiterbgap} \NC vertical baseline clearance for limits below delimiters \NC \NR
427\NC \lpr {Umathsubshiftdrop}       \NC subscript drop for boxes and subformulas \NC \NR
428\NC \lpr {Umathsubshiftdown}       \NC subscript drop for characters \NC \NR
429\NC \lpr {Umathsupshiftdrop}       \NC superscript drop (raise, actually) for boxes and subformulas \NC \NR
430\NC \lpr {Umathsupshiftup}         \NC superscript raise for characters \NC \NR
431\NC \lpr {Umathsubsupshiftdown}    \NC subscript drop in the presence of a superscript \NC \NR
432\NC \lpr {Umathsubtopmax}          \NC the top of standalone subscripts cannot be higher than this
433                                       above the baseline \NC \NR
434\NC \lpr {Umathsupbottommin}       \NC the bottom of standalone superscripts cannot be less than
435                                       this above the baseline \NC \NR
436\NC \lpr {Umathsupsubbottommax}    \NC the bottom of the superscript of a combined super- and subscript
437                                       be at least as high as this above the baseline \NC \NR
438\NC \lpr {Umathsubsupvgap}         \NC vertical clearance between super- and subscript \NC \NR
439\NC \lpr {Umathspaceafterscript}   \NC additional space added after a super- or subscript \NC \NR
440\NC \lpr {Umathconnectoroverlapmin}\NC minimum overlap between parts in an extensible recipe \NC \NR
441\LL
442\stoptabulate
443
444Each of the parameters in this section can be set by a command like this:
445
446\starttyping
447\Umathquad\displaystyle=1em
448\stoptyping
449
450they obey grouping, and you can use \type {\the\Umathquad\displaystyle} if
451needed.
452
453\subsection{Font|-|based math parameters}
454
455\topicindex {math+parameters}
456
457While it is nice to have these math parameters available for tweaking, it would
458be tedious to have to set each of them by hand. For this reason, \LUATEX\
459initializes a bunch of these parameters whenever you assign a font identifier to
460a math family based on either the traditional math font dimensions in the font
461(for assignments to math family~2 and~3 using \TFM|-|based fonts like \type
462{cmsy} and \type {cmex}), or based on the named values in a potential \type
463{MathConstants} table when the font is loaded via Lua. If there is a \type
464{MathConstants} table, this takes precedence over font dimensions, and in that
465case no attention is paid to which family is being assigned to: the \type
466{MathConstants} tables in the last assigned family sets all parameters.
467
468In the table below, the one|-|letter style abbreviations and symbolic tfm font
469dimension names match those used in the \TeX book. Assignments to \prm
470{textfont} set the values for the cramped and uncramped display and text styles,
471\prm {scriptfont} sets the script styles, and \prm {scriptscriptfont} sets the
472scriptscript styles, so we have eight parameters for three font sizes. In the
473\TFM\ case, assignments only happen in family~2 and family~3 (and of course only
474for the parameters for which there are font dimensions).
475
476Besides the parameters below, \LUATEX\ also looks at the \quote {space} font
477dimension parameter. For math fonts, this should be set to zero.
478
479\def\MathLine#1#2#3#4#5%
480  {\TB
481   \NC \llap{\high{\tx #2\enspace}}\ttbf \string #1 \NC \tt #5 \NC \NR
482   \NC \tx #3 \NC \tt #4 \NC \NR}
483
484\starttabulate[|l|l|]
485\DB variable / style \BC tfm / opentype \NC \NR
486\MathLine{\Umathaxis}               {}   {}                     {AxisHeight}                              {axis_height}
487\MathLine{\Umathoperatorsize}       {6}  {D, D'}                {DisplayOperatorMinHeight}                {\emdash}
488\MathLine{\Umathfractiondelsize}    {9}  {D, D'}                {FractionDelimiterDisplayStyleSize}       {delim1}
489\MathLine{\Umathfractiondelsize}    {9}  {T, T', S, S', SS, SS'}{FractionDelimiterSize}                   {delim2}
490\MathLine{\Umathfractiondenomdown}  {}   {D, D'}                {FractionDenominatorDisplayStyleShiftDown}{denom1}
491\MathLine{\Umathfractiondenomdown}  {}   {T, T', S, S', SS, SS'}{FractionDenominatorShiftDown}            {denom2}
492\MathLine{\Umathfractiondenomvgap}  {}   {D, D'}                {FractionDenominatorDisplayStyleGapMin}   {3*default_rule_thickness}
493\MathLine{\Umathfractiondenomvgap}  {}   {T, T', S, S', SS, SS'}{FractionDenominatorGapMin}               {default_rule_thickness}
494\MathLine{\Umathfractionnumup}      {}   {D, D'}                {FractionNumeratorDisplayStyleShiftUp}    {num1}
495\MathLine{\Umathfractionnumup}      {}   {T, T', S, S', SS, SS'}{FractionNumeratorShiftUp}                {num2}
496\MathLine{\Umathfractionnumvgap}    {}   {D, D'}                {FractionNumeratorDisplayStyleGapMin}     {3*default_rule_thickness}
497\MathLine{\Umathfractionnumvgap}    {}   {T, T', S, S', SS, SS'}{FractionNumeratorGapMin}                 {default_rule_thickness}
498\MathLine{\Umathfractionrule}       {}   {}                     {FractionRuleThickness}                   {default_rule_thickness}
499\MathLine{\Umathskewedfractionhgap} {}   {}                     {SkewedFractionHorizontalGap}             {math_quad/2}
500\MathLine{\Umathskewedfractionvgap} {}   {}                     {SkewedFractionVerticalGap}               {math_x_height}
501\MathLine{\Umathlimitabovebgap}     {}   {}                     {UpperLimitBaselineRiseMin}               {big_op_spacing3}
502\MathLine{\Umathlimitabovekern}     {1}  {}                     {0}                                       {big_op_spacing5}
503\MathLine{\Umathlimitabovevgap}     {}   {}                     {UpperLimitGapMin}                        {big_op_spacing1}
504\MathLine{\Umathlimitbelowbgap}     {}   {}                     {LowerLimitBaselineDropMin}               {big_op_spacing4}
505\MathLine{\Umathlimitbelowkern}     {1}  {}                     {0}                                       {big_op_spacing5}
506\MathLine{\Umathlimitbelowvgap}     {}   {}                     {LowerLimitGapMin}                        {big_op_spacing2}
507\MathLine{\Umathoverdelimitervgap}  {}   {}                     {StretchStackGapBelowMin}                 {big_op_spacing1}
508\MathLine{\Umathoverdelimiterbgap}  {}   {}                     {StretchStackTopShiftUp}                  {big_op_spacing3}
509\MathLine{\Umathunderdelimitervgap} {}   {}                     {StretchStackGapAboveMin}                 {big_op_spacing2}
510\MathLine{\Umathunderdelimiterbgap} {}   {}                     {StretchStackBottomShiftDown}             {big_op_spacing4}
511\MathLine{\Umathoverbarkern}        {}   {}                     {OverbarExtraAscender}                    {default_rule_thickness}
512\MathLine{\Umathoverbarrule}        {}   {}                     {OverbarRuleThickness}                    {default_rule_thickness}
513\MathLine{\Umathoverbarvgap}        {}   {}                     {OverbarVerticalGap}                      {3*default_rule_thickness}
514\MathLine{\Umathquad}               {1}  {}                     {<font_size(f)>}                          {math_quad}
515\MathLine{\Umathradicalkern}        {}   {}                     {RadicalExtraAscender}                    {default_rule_thickness}
516\MathLine{\Umathradicalrule}        {2}  {}                     {RadicalRuleThickness}                    {<not set>}
517\MathLine{\Umathradicalvgap}        {3}  {D, D'}                {RadicalDisplayStyleVerticalGap}          {default_rule_thickness+abs(math_x_height)/4}
518\MathLine{\Umathradicalvgap}        {3}  {T, T', S, S', SS, SS'}{RadicalVerticalGap}                      {default_rule_thickness+abs(default_rule_thickness)/4}
519\MathLine{\Umathradicaldegreebefore}{2}  {}                     {RadicalKernBeforeDegree}                 {<not set>}
520\MathLine{\Umathradicaldegreeafter} {2}  {}                     {RadicalKernAfterDegree}                  {<not set>}
521\MathLine{\Umathradicaldegreeraise} {2,7}{}                     {RadicalDegreeBottomRaisePercent}         {<not set>}
522\MathLine{\Umathspaceafterscript}   {4}  {}                     {SpaceAfterScript}                        {script_space}
523\MathLine{\Umathstackdenomdown}     {}   {D, D'}                {StackBottomDisplayStyleShiftDown}        {denom1}
524\MathLine{\Umathstackdenomdown}     {}   {T, T', S, S', SS, SS'}{StackBottomShiftDown}                    {denom2}
525\MathLine{\Umathstacknumup}         {}   {D, D'}                {StackTopDisplayStyleShiftUp}             {num1}
526\MathLine{\Umathstacknumup}         {}   {T, T', S, S', SS, SS'}{StackTopShiftUp}                         {num3}
527\MathLine{\Umathstackvgap}          {}   {D, D'}                {StackDisplayStyleGapMin}                 {7*default_rule_thickness}
528\MathLine{\Umathstackvgap}          {}   {T, T', S, S', SS, SS'}{StackGapMin}                             {3*default_rule_thickness}
529\MathLine{\Umathsubshiftdown}       {}   {}                     {SubscriptShiftDown}                      {sub1}
530\MathLine{\Umathsubshiftdrop}       {}   {}                     {SubscriptBaselineDropMin}                {sub_drop}
531\MathLine{\Umathsubsupshiftdown}    {8}  {}                     {SubscriptShiftDownWithSuperscript}       {\emdash}
532\MathLine{\Umathsubtopmax}          {}   {}                     {SubscriptTopMax}                         {abs(math_x_height*4)/5}
533\MathLine{\Umathsubsupvgap}         {}   {}                     {SubSuperscriptGapMin}                    {4*default_rule_thickness}
534\MathLine{\Umathsupbottommin}       {}   {}                     {SuperscriptBottomMin}                    {abs(math_x_height/4)}
535\MathLine{\Umathsupshiftdrop}       {}   {}                     {SuperscriptBaselineDropMax}              {sup_drop}
536\MathLine{\Umathsupshiftup}         {}   {D}                    {SuperscriptShiftUp}                      {sup1}
537\MathLine{\Umathsupshiftup}         {}   {T, S, SS,}            {SuperscriptShiftUp}                      {sup2}
538\MathLine{\Umathsupshiftup}         {}   {D', T', S', SS'}      {SuperscriptShiftUpCramped}               {sup3}
539\MathLine{\Umathsupsubbottommax}    {}   {}                     {SuperscriptBottomMaxWithSubscript}       {abs(math_x_height*4)/5}
540\MathLine{\Umathunderbarkern}       {}   {}                     {UnderbarExtraDescender}                  {default_rule_thickness}
541\MathLine{\Umathunderbarrule}       {}   {}                     {UnderbarRuleThickness}                   {default_rule_thickness}
542\MathLine{\Umathunderbarvgap}       {}   {}                     {UnderbarVerticalGap}                     {3*default_rule_thickness}
543\MathLine{\Umathconnectoroverlapmin}{5}  {}                     {MinConnectorOverlap}                     {0}
544\LL
545\stoptabulate
546
547Note 1: \OPENTYPE\ fonts set \lpr {Umathlimitabovekern} and \lpr
548{Umathlimitbelowkern} to zero and set \lpr {Umathquad} to the font size of the
549used font, because these are not supported in the \type {MATH} table,
550
551Note 2: Traditional \TFM\ fonts do not set \lpr {Umathradicalrule} because
552\TEX82\ uses the height of the radical instead. When this parameter is indeed not
553set when \LUATEX\ has to typeset a radical, a backward compatibility mode will
554kick in that assumes that an oldstyle \TEX\ font is used. Also, they do not set
555\lpr {Umathradicaldegreebefore}, \lpr {Umathradicaldegreeafter}, and \lpr
556{Umathradicaldegreeraise}. These are then automatically initialized to
557$5/18$quad, $-10/18$quad, and 60.
558
559Note 3: If \TFM\ fonts are used, then the \lpr {Umathradicalvgap} is not set
560until the first time \LUATEX\ has to typeset a formula because this needs
561parameters from both family~2 and family~3. This provides a partial backward
562compatibility with \TEX82, but that compatibility is only partial: once the \lpr
563{Umathradicalvgap} is set, it will not be recalculated any more.
564
565Note 4: When \TFM\ fonts are used a similar situation arises with respect to \lpr
566{Umathspaceafterscript}: it is not set until the first time \LUATEX\ has to
567typeset a formula. This provides some backward compatibility with \TEX82. But
568once the \lpr {Umathspaceafterscript} is set, \prm {scriptspace} will never be
569looked at again.
570
571Note 5: Traditional \TFM\ fonts set \lpr {Umathconnectoroverlapmin} to zero
572because \TEX82\ always stacks extensibles without any overlap.
573
574Note 6: The \lpr {Umathoperatorsize} is only used in \prm {displaystyle}, and is
575only set in \OPENTYPE\ fonts. In \TFM\ font mode, it is artificially set to one
576scaled point more than the initial attempt's size, so that always the \quote
577{first next} will be tried, just like in \TEX82.
578
579Note 7: The \lpr {Umathradicaldegreeraise} is a special case because it is the
580only parameter that is expressed in a percentage instead of a number of scaled
581points.
582
583Note 8: \type {SubscriptShiftDownWithSuperscript} does not actually exist in the
584\quote {standard} \OPENTYPE\ math font Cambria, but it is useful enough to be
585added.
586
587Note 9: \type {FractionDelimiterDisplayStyleSize} and \type
588{FractionDelimiterSize} do not actually exist in the \quote {standard} \OPENTYPE\
589math font Cambria, but were useful enough to be added.
590
591\stopsection
592
593\startsection[title={Math spacing}]
594
595\subsection{Inline surrounding space}
596
597\topicindex {math+spacing}
598
599Inline math is surrounded by (optional) \prm {mathsurround} spacing but that is a fixed
600dimension. There is now an additional parameter \lpr {mathsurroundskip}. When set to a
601non|-|zero value (or zero with some stretch or shrink) this parameter will replace
602\prm {mathsurround}. By using an additional parameter instead of changing the nature
603of \prm {mathsurround}, we can remain compatible. In the meantime a bit more
604control has been added via \lpr {mathsurroundmode}. This directive can take 6 values
605with zero being the default behaviour.
606
607\start
608
609\def\OneLiner#1#2%
610  {\NC \type{#1}
611   \NC \dontleavehmode\inframed[align=normal,offset=0pt,frame=off]{\mathsurroundmode#1\relax\hsize 100pt   x$x$x}
612   \NC \dontleavehmode\inframed[align=normal,offset=0pt,frame=off]{\mathsurroundmode#1\relax\hsize 100pt x $x$ x}
613   \NC #2
614   \NC \NR}
615
616\startbuffer
617\mathsurround    10pt
618\mathsurroundskip20pt
619\stopbuffer
620
621\typebuffer \getbuffer
622
623\starttabulate[|c|c|c|pl|]
624\DB mode \BC x\$x\$x \BC x \$x\$ x \BC effect \NC \NR
625\TB
626\OneLiner{0}{obey \prm {mathsurround} when \lpr {mathsurroundskip} is 0pt}
627\OneLiner{1}{only add skip to the left}
628\OneLiner{2}{only add skip to the right}
629\OneLiner{3}{add skip to the left and right}
630\OneLiner{4}{ignore the skip setting, obey \prm {mathsurround}}
631\OneLiner{5}{disable all spacing around math}
632\OneLiner{6}{only apply \lpr {mathsurroundskip} when also spacing}
633\OneLiner{7}{only apply \lpr {mathsurroundskip} when no spacing}
634\LL
635\stoptabulate
636
637\stop
638
639Method six omits the surround glue when there is (x)spacing glue present while
640method seven does the opposite, the glue is only applied when there is (x)space
641glue present too. Anything more fancy, like checking the begining or end of a
642paragraph (or edges of a box) would not be robust anyway. If you want that you
643can write a callback that runs over a list and analyzes a paragraph. Actually, in
644that case you could also inject glue (or set the properties of a math node)
645explicitly. So, these modes are in practice mostly useful for special purposes
646and experiments (they originate in a tracker item). Keep in mind that this glue
647is part of the math node and not always treated as normal glue: it travels with
648the begin and end math nodes. Also, method 6 and 7 will zero the skip related
649fields in a node when applicable in the first occasion that checks them
650(linebreaking or packaging).
651
652\subsection{Pairwise spacing}
653
654\topicindex {math+spacing}
655
656Besides the parameters mentioned in the previous sections, there are also 64 new
657primitives to control the math spacing table (as explained in Chapter~18 of the
658\TEX book). The primitive names are a simple matter of combining two math atom
659types, but for completeness' sake, here is the whole list:
660
661\starttwocolumns
662\startlines
663\lpr {Umathordordspacing}
664\lpr {Umathordopspacing}
665\lpr {Umathordbinspacing}
666\lpr {Umathordrelspacing}
667\lpr {Umathordopenspacing}
668\lpr {Umathordclosespacing}
669\lpr {Umathordpunctspacing}
670\lpr {Umathordinnerspacing}
671\lpr {Umathopordspacing}
672\lpr {Umathopopspacing}
673\lpr {Umathopbinspacing}
674\lpr {Umathoprelspacing}
675\lpr {Umathopopenspacing}
676\lpr {Umathopclosespacing}
677\lpr {Umathoppunctspacing}
678\lpr {Umathopinnerspacing}
679\lpr {Umathbinordspacing}
680\lpr {Umathbinopspacing}
681\lpr {Umathbinbinspacing}
682\lpr {Umathbinrelspacing}
683\lpr {Umathbinopenspacing}
684\lpr {Umathbinclosespacing}
685\lpr {Umathbinpunctspacing}
686\lpr {Umathbininnerspacing}
687\lpr {Umathrelordspacing}
688\lpr {Umathrelopspacing}
689\lpr {Umathrelbinspacing}
690\lpr {Umathrelrelspacing}
691\lpr {Umathrelopenspacing}
692\lpr {Umathrelclosespacing}
693\lpr {Umathrelpunctspacing}
694\lpr {Umathrelinnerspacing}
695\lpr {Umathopenordspacing}
696\lpr {Umathopenopspacing}
697\lpr {Umathopenbinspacing}
698\lpr {Umathopenrelspacing}
699\lpr {Umathopenopenspacing}
700\lpr {Umathopenclosespacing}
701\lpr {Umathopenpunctspacing}
702\lpr {Umathopeninnerspacing}
703\lpr {Umathcloseordspacing}
704\lpr {Umathcloseopspacing}
705\lpr {Umathclosebinspacing}
706\lpr {Umathcloserelspacing}
707\lpr {Umathcloseopenspacing}
708\lpr {Umathcloseclosespacing}
709\lpr {Umathclosepunctspacing}
710\lpr {Umathcloseinnerspacing}
711\lpr {Umathpunctordspacing}
712\lpr {Umathpunctopspacing}
713\lpr {Umathpunctbinspacing}
714\lpr {Umathpunctrelspacing}
715\lpr {Umathpunctopenspacing}
716\lpr {Umathpunctclosespacing}
717\lpr {Umathpunctpunctspacing}
718\lpr {Umathpunctinnerspacing}
719\lpr {Umathinnerordspacing}
720\lpr {Umathinneropspacing}
721\lpr {Umathinnerbinspacing}
722\lpr {Umathinnerrelspacing}
723\lpr {Umathinneropenspacing}
724\lpr {Umathinnerclosespacing}
725\lpr {Umathinnerpunctspacing}
726\lpr {Umathinnerinnerspacing}
727\stoplines
728\stoptwocolumns
729
730These parameters are of type \prm {muskip}, so setting a parameter can be done
731like this:
732
733\starttyping
734\Umathopordspacing\displaystyle=4mu plus 2mu
735\stoptyping
736
737They are all initialized by \type {initex} to the values mentioned in the table
738in Chapter~18 of the \TEX book.
739
740Note 1: for ease of use as well as for backward compatibility, \prm {thinmuskip},
741\prm {medmuskip} and \prm {thickmuskip} are treated specially. In their case a
742pointer to the corresponding internal parameter is saved, not the actual \prm
743{muskip} value. This means that any later changes to one of these three
744parameters will be taken into account.
745
746Note 2: Careful readers will realise that there are also primitives for the items
747marked \type {*} in the \TEX book. These will not actually be used as those
748combinations of atoms cannot actually happen, but it seemed better not to break
749orthogonality. They are initialized to zero.
750
751\subsection{Skips around display math}
752
753\topicindex {math+spacing}
754
755The injection of \prm {abovedisplayskip} and \prm {belowdisplayskip} is not
756symmetrical. An above one is always inserted, also when zero, but the below is
757only inserted when larger than zero. Especially the latter makes it sometimes hard
758to fully control spacing. Therefore \LUATEX\ comes with a new directive: \lpr
759{mathdisplayskipmode}. The following values apply:
760
761\starttabulate[|c|l|]
762\DB value  \BC meaning \NC \NR
763\TB
764\NC 0 \NC normal \TEX\ behaviour \NC \NR
765\NC 1 \NC always (same as 0) \NC \NR
766\NC 2 \NC only when not zero \NC \NR
767\NC 3 \NC never, not even when not zero \NC \NR
768\LL
769\stoptabulate
770
771By default the short skip detection is not adapted to r2l typesetting and that
772hasn't been the case since the start of the project. Changing it could break
773hacks that users came up with but when you set \lpr {matheqdirmode} to a positive
774value direction will be taken into account.
775
776\subsection {Nolimit correction}
777
778\topicindex {math+limits}
779
780There are two extra math parameters \lpr {Umathnolimitsupfactor} and \lpr
781{Umathnolimitsubfactor} that were added to provide some control over how limits
782are spaced (for example the position of super and subscripts after integral
783operators). They relate to an extra parameter \lpr {mathnolimitsmode}. The half
784corrections are what happens when scripts are placed above and below. The
785problem with italic corrections is that officially that correction italic is used
786for above|/|below placement while advanced kerns are used for placement at the
787right end. The question is: how often is this implemented, and if so, do the
788kerns assume correction too. Anyway, with this parameter one can control it.
789
790\starttabulate[|l|ck1|ck1|ck1|ck1|ck1|ck1|]
791    \NC % probably not ok, we need a raw int here
792        \NC \mathnolimitsmode0    $\displaystyle\mathop{\normalint}\nolimits^0_1$
793        \NC \mathnolimitsmode1    $\displaystyle\mathop{\normalint}\nolimits^0_1$
794        \NC \mathnolimitsmode2    $\displaystyle\mathop{\normalint}\nolimits^0_1$
795        \NC \mathnolimitsmode3    $\displaystyle\mathop{\normalint}\nolimits^0_1$
796        \NC \mathnolimitsmode4    $\displaystyle\mathop{\normalint}\nolimits^0_1$
797        \NC \mathnolimitsmode8000 $\displaystyle\mathop{\normalint}\nolimits^0_1$
798    \NC \NR
799    \TB
800    \BC mode
801        \NC \tttf 0
802        \NC \tttf 1
803        \NC \tttf 2
804        \NC \tttf 3
805        \NC \tttf 4
806        \NC \tttf 8000
807    \NC \NR
808    \BC superscript
809        \NC 0
810        \NC font
811        \NC 0
812        \NC 0
813        \NC +ic/2
814        \NC 0
815    \NC \NR
816    \BC subscript
817        \NC -ic
818        \NC font
819        \NC 0
820        \NC -ic/2
821        \NC -ic/2
822        \NC 8000ic/1000
823    \NC \NR
824\stoptabulate
825
826When the mode is set to one, the math parameters are used. This way a macro
827package writer can decide what looks best. Given the current state of fonts in
828\CONTEXT\ we currently use mode 1 with factor 0 for the superscript and 750 for
829the subscripts. Positive values are used for both parameters but the subscript
830shifts to the left. A \lpr {mathnolimitsmode} larger that 15 is considered to
831be a factor for the subscript correction. This feature can be handy when
832experimenting.
833
834\subsection {Math italic mess}
835
836\topicindex {math+italics}
837
838The \lpr {mathitalicsmode} parameter can be set to~1 to force italic correction
839before noads that represent some more complex structure (read: everything that is
840not an ord, bin, rel, open, close, punct or inner). A value of~2 will enforce the
841old school font code path for all italics. We show a Cambria example.
842
843\starttexdefinition Whatever #1
844    \NC \type{\mathitalicsmode = #1}
845    \NC \mathitalicsmode#1\ruledhbox{$\left|T^1\right|$}
846    \NC \mathitalicsmode#1\ruledhbox{$\left|T\right|$}
847    \NC \mathitalicsmode#1\ruledhbox{$T+1$}
848    \NC \mathitalicsmode#1\ruledhbox{$T{1\over2}$}
849    \NC \mathitalicsmode#1\ruledhbox{$T\sqrt{1}$}
850    \NC \NR
851\stoptexdefinition
852
853\start
854    \switchtobodyfont[cambria]
855    \starttabulate[|c|c|c|c|c|c|]
856        \Whatever{0}%
857        \Whatever{1}%
858    \stoptabulate
859\stop
860
861This kind of parameters relate to the fact that italic correction in \OPENTYPE\
862math is bound to fuzzy rules. So, control is the solution.
863
864\subsection {Script and kerning}
865
866\topicindex {math+kerning}
867\topicindex {math+scripts}
868
869If you want to typeset text in math macro packages often provide something \type
870{\text} which obeys the script sizes. As the definition can be anything there is
871a good chance that the kerning doesn't come out well when used in a script. Given
872that the first glyph ends up in a \prm {hbox} we have some control over this.
873And, as a bonus we also added control over the normal sublist kerning. The \lpr
874{mathscriptboxmode} parameter defaults to~1.
875
876\starttabulate[|c|l|]
877\DB value     \BC meaning \NC \NR
878\TB
879\NC \type {0} \NC forget about kerning \NC \NR
880\NC \type {1} \NC kern math sub lists with a valid glyph \NC \NR
881\NC \type {2} \NC also kern math sub boxes that have a valid glyph \NC \NR
882\NC \type {2} \NC only kern math sub boxes with a boundary node present\NC \NR
883\LL
884\stoptabulate
885
886Here we show some examples. Of course this doesn't solve all our problems, if
887only because some fonts have characters with bounding boxes that compensate for
888italics, while other fonts can lack kerns.
889
890\startbuffer[1]
891    $T_{\tf fluff}$
892\stopbuffer
893
894\startbuffer[2]
895    $T_{\text{fluff}}$
896\stopbuffer
897
898\startbuffer[3]
899    $T_{\text{\boundary1 fluff}}$
900\stopbuffer
901
902\unexpanded\def\Show#1#2#3%
903  {\doifelsenothing{#3}
904     {\small\tx\typeinlinebuffer[#1]}
905     {\doifelse{#3}{-}
906        {\small\bf\tt mode #2}
907        {\switchtobodyfont[#3]\showfontkerns\showglyphs\mathscriptboxmode#2\relax\inlinebuffer[#1]}}}
908
909\starttabulate[|lBT|c|c|c|c|c|]
910    \NC          \NC \Show{1}{0}{}         \NC\Show{1}{1}{}         \NC \Show{2}{1}{}         \NC \Show{2}{2}{}         \NC \Show{3}{3}{}         \NC \NR
911    \NC          \NC \Show{1}{0}{-}        \NC\Show{1}{1}{-}        \NC \Show{2}{1}{-}        \NC \Show{2}{2}{-}        \NC \Show{3}{3}{-}        \NC \NR
912    \NC modern   \NC \Show{1}{0}{modern}   \NC\Show{1}{1}{modern}   \NC \Show{2}{1}{modern}   \NC \Show{2}{2}{modern}   \NC \Show{3}{3}{modern}   \NC \NR
913    \NC lucidaot \NC \Show{1}{0}{lucidaot} \NC\Show{1}{1}{lucidaot} \NC \Show{2}{1}{lucidaot} \NC \Show{2}{2}{lucidaot} \NC \Show{3}{3}{lucidaot} \NC \NR
914    \NC pagella  \NC \Show{1}{0}{pagella}  \NC\Show{1}{1}{pagella}  \NC \Show{2}{1}{pagella}  \NC \Show{2}{2}{pagella}  \NC \Show{3}{3}{pagella}  \NC \NR
915    \NC cambria  \NC \Show{1}{0}{cambria}  \NC\Show{1}{1}{cambria}  \NC \Show{2}{1}{cambria}  \NC \Show{2}{2}{cambria}  \NC \Show{3}{3}{cambria}  \NC \NR
916    \NC dejavu   \NC \Show{1}{0}{dejavu}   \NC\Show{1}{1}{dejavu}   \NC \Show{2}{1}{dejavu}   \NC \Show{2}{2}{dejavu}   \NC \Show{3}{3}{dejavu}   \NC \NR
917\stoptabulate
918
919Kerning between a character subscript is controlled by \lpr {mathscriptcharmode}
920which also defaults to~1.
921
922Here is another example. Internally we tag kerns as italic kerns or font kerns
923where font kerns result from the staircase kern tables. In 2018 fonts like Latin
924Modern and Pagella rely on cheats with the boundingbox, Cambria uses staircase
925kerns and Lucida a mixture. Depending on how fonts evolve we might add some more
926control over what one can turn on and off.
927
928\def\MathSample#1#2#3%
929  {\NC
930   #1 \NC
931   #2 \NC
932   \showglyphdata \switchtobodyfont[#2,17.3pt]$#3T_{f}$         \NC
933   \showglyphdata \switchtobodyfont[#2,17.3pt]$#3\gamma_{e}$    \NC
934   \showglyphdata \switchtobodyfont[#2,17.3pt]$#3\gamma_{ee}$   \NC
935   \showglyphdata \switchtobodyfont[#2,17.3pt]$#3T_{\tf fluff}$ \NC
936   \NR}
937
938\starttabulate[|Tl|Tl|l|l|l|l|]
939    \FL
940    \MathSample{normal}{modern}  {\mr}
941    \MathSample{}      {pagella} {\mr}
942    \MathSample{}      {cambria} {\mr}
943    \MathSample{}      {lucidaot}{\mr}
944    \ML
945    \MathSample{bold}  {modern}  {\mb}
946    \MathSample{}      {pagella} {\mb}
947    \MathSample{}      {cambria} {\mb}
948    \MathSample{}      {lucidaot}{\mb}
949    \LL
950\stoptabulate
951
952\subsection{Fixed scripts}
953
954We have three parameters that are used for this fixed anchoring:
955
956\starttabulate[|c|l|]
957\DB parameter \BC register \NC \NR
958\NC $d$ \NC \lpr {Umathsubshiftdown}    \NC \NR
959\NC $u$ \NC \lpr {Umathsupshiftup}      \NC \NR
960\NC $s$ \NC \lpr {Umathsubsupshiftdown} \NC \NR
961\LL
962\stoptabulate
963
964When we set \lpr {mathscriptsmode} to a value other than zero these are used
965for calculating fixed positions. This is something that is needed for instance
966for chemistry. You can manipulate the mentioned variables to achieve different
967effects.
968
969\def\SampleMath#1%
970  {$\mathscriptsmode#1\mathupright CH_2 + CH^+_2 + CH^2_2$}
971
972\starttabulate[|c|c|c|p|]
973\DB mode \BC down          \BC up            \BC example        \NC \NR
974\TB
975\NC 0    \NC dynamic       \NC dynamic       \NC \SampleMath{0} \NC \NR
976\NC 1    \NC $d$           \NC $u$           \NC \SampleMath{1} \NC \NR
977\NC 2    \NC $s$           \NC $u$           \NC \SampleMath{2} \NC \NR
978\NC 3    \NC $s$           \NC $u + s - d$   \NC \SampleMath{3} \NC \NR
979\NC 4    \NC $d + (s-d)/2$ \NC $u + (s-d)/2$ \NC \SampleMath{4} \NC \NR
980\NC 5    \NC $d$           \NC $u + s - d$   \NC \SampleMath{5} \NC \NR
981\LL
982\stoptabulate
983
984The value of this parameter obeys grouping but applies to the whole current
985formula.
986
987% if needed we can put the value in stylenodes but maybe more should go there
988
989\subsection{Penalties: \lpr {mathpenaltiesmode}}
990
991\topicindex {math+penalties}
992
993Only in inline math penalties will be added in a math list. You can force
994penalties (also in display math) by setting:
995
996\starttyping
997\mathpenaltiesmode = 1
998\stoptyping
999
1000This primnitive is not really needed in \LUATEX\ because you can use the callback
1001\cbk {mlist_to_hlist} to force penalties by just calling the regular routine
1002with forced penalties. However, as part of opening up and control this primitive
1003makes sense. As a bonus we also provide two extra penalties:
1004
1005\starttyping
1006\prebinoppenalty = -100 % example value
1007\prerelpenalty   =  900 % example value
1008\stoptyping
1009
1010They default to inifinite which signals that they don't need to be inserted. When
1011set they are injected before a binop or rel noad. This is an experimental feature.
1012
1013\subsection{Equation spacing: \lpr {matheqnogapstep}}
1014
1015By default \TEX\ will add one quad between the equation and the number. This is
1016hard coded. A new primitive can control this:
1017
1018\startsyntax
1019\matheqnogapstep = 1000
1020\stopsyntax
1021
1022Because a math quad from the math text font is used instead of a dimension, we
1023use a step to control the size. A value of zero will suppress the gap. The step
1024is divided by 1000 which is the usual way to mimmick floating point factors in
1025\TEX.
1026
1027\stopsection
1028
1029\startsection[title={Math constructs}]
1030
1031\subsection {Unscaled fences}
1032
1033\topicindex {math+fences}
1034
1035The \lpr {mathdelimitersmode} primitive is experimental and deals with the
1036following (potential) problems. Three bits can be set. The first bit prevents an
1037unwanted shift when the fence symbol is not scaled (a cambria side effect). The
1038second bit forces italic correction between a preceding character ordinal and the
1039fenced subformula, while the third bit turns that subformula into an ordinary so
1040that the same spacing applies as with unfenced variants. Here we show Cambria
1041(with \lpr {mathitalicsmode} enabled).
1042
1043\starttexdefinition Whatever #1
1044    \NC \type{\mathdelimitersmode = #1}
1045    \NC \mathitalicsmode1\mathdelimitersmode#1\ruledhbox{\showglyphs\showfontkerns\showfontitalics$f(x)$}
1046    \NC \mathitalicsmode1\mathdelimitersmode#1\ruledhbox{\showglyphs\showfontkerns\showfontitalics$f\left(x\right)$}
1047    \NC \NR
1048\stoptexdefinition
1049
1050\start
1051    \switchtobodyfont[cambria]
1052    \starttabulate[|l|l|l|]
1053        \Whatever{0}\Whatever{1}\Whatever{2}\Whatever{3}%
1054        \Whatever{4}\Whatever{5}\Whatever{6}\Whatever{7}%
1055    \stoptabulate
1056\stop
1057
1058So, when set to 7 fenced subformulas with unscaled delimiters come out the same
1059as unfenced ones. This can be handy for cases where one is forced to use \prm
1060{left} and \prm {right} always because of unpredictable content. As said, it's an
1061experimental feature (which somehow fits in the exceptional way fences are dealt
1062with in the engine). The full list of flags is given in the next table:
1063
1064\starttabulate[|c|l|]
1065\DB value  \BC meaning \NC \NR
1066\TB
1067\NC \type{"01} \NC don't apply the usual shift \NC \NR
1068\NC \type{"02} \NC apply italic correction when possible \NC \NR
1069\NC \type{"04} \NC force an ordinary subformula \NC \NR
1070\NC \type{"08} \NC no shift when a base character \NC \NR
1071\NC \type{"10} \NC only shift when an extensible \NC \NR
1072\LL
1073\stoptabulate
1074
1075The effect can depend on the font (and for Cambria one can use for instance \type {"16}).
1076
1077\subsection[mathacc]{Accent handling}
1078
1079\topicindex {math+accents}
1080
1081\LUATEX\ supports both top accents and bottom accents in math mode, and math
1082accents stretch automatically (if this is supported by the font the accent comes
1083from, of course). Bottom and combined accents as well as fixed-width math accents
1084are controlled by optional keywords following \lpr {Umathaccent}.
1085
1086The keyword \type {bottom} after \lpr {Umathaccent} signals that a bottom accent
1087is needed, and the keyword \type {both} signals that both a top and a bottom
1088accent are needed (in this case two accents need to be specified, of course).
1089
1090Then the set of three integers defining the accent is read. This set of integers
1091can be prefixed by the \type {fixed} keyword to indicate that a non-stretching
1092variant is requested (in case of both accents, this step is repeated).
1093
1094A simple example:
1095
1096\starttyping
1097\Umathaccent both fixed 0 0 "20D7 fixed 0 0 "20D7 {example}
1098\stoptyping
1099
1100If a math top accent has to be placed and the accentee is a character and has a
1101non-zero \type {top_accent} value, then this value will be used to place the
1102accent instead of the \prm {skewchar} kern used by \TEX82.
1103
1104The \type {top_accent} value represents a vertical line somewhere in the
1105accentee. The accent will be shifted horizontally such that its own \type
1106{top_accent} line coincides with the one from the accentee. If the \type
1107{top_accent} value of the accent is zero, then half the width of the accent
1108followed by its italic correction is used instead.
1109
1110The vertical placement of a top accent depends on the \type {x_height} of the
1111font of the accentee (as explained in the \TEX book), but if a value turns out
1112to be zero and the font had a \type {MathConstants} table, then \type
1113{AccentBaseHeight} is used instead.
1114
1115The vertical placement of a bottom accent is straight below the accentee, no
1116correction takes place.
1117
1118Possible locations are \type {top}, \type {bottom}, \type {both} and \type
1119{center}. When no location is given \type {top} is assumed. An additional
1120parameter \nod {fraction} can be specified followed by a number; a value of for
1121instance 1200 means that the criterium is 1.2 times the width of the nucleus. The
1122fraction only applies to the stepwise selected shapes and is mostly meant for the
1123\type {overlay} location. It also works for the other locations but then it
1124concerns the width.
1125
1126\subsection{Radical extensions}
1127
1128\topicindex {math+radicals}
1129
1130The new primitive \lpr {Uroot} allows the construction of a radical noad
1131including a degree field. Its syntax is an extension of \lpr {Uradical}:
1132
1133\starttyping
1134\Uradical <fam integer> <char integer> <radicand>
1135\Uroot    <fam integer> <char integer> <degree> <radicand>
1136\stoptyping
1137
1138The placement of the degree is controlled by the math parameters \lpr
1139{Umathradicaldegreebefore}, \lpr {Umathradicaldegreeafter}, and \lpr
1140{Umathradicaldegreeraise}. The degree will be typeset in \prm
1141{scriptscriptstyle}.
1142
1143\subsection{Super- and subscripts}
1144
1145The character fields in a \LUA|-|loaded \OPENTYPE\ math font can have a \quote
1146{mathkern} table. The format of this table is the same as the \quote {mathkern}
1147table that is returned by the \type {fontloader} library, except that all height
1148and kern values have to be specified in actual scaled points.
1149
1150When a super- or subscript has to be placed next to a math item, \LUATEX\ checks
1151whether the super- or subscript and the nucleus are both simple character items.
1152If they are, and if the fonts of both character items are \OPENTYPE\ fonts (as
1153opposed to legacy \TEX\ fonts), then \LUATEX\ will use the \OPENTYPE\ math
1154algorithm for deciding on the horizontal placement of the super- or subscript.
1155
1156This works as follows:
1157
1158\startitemize
1159    \startitem
1160        The vertical position of the script is calculated.
1161    \stopitem
1162    \startitem
1163        The default horizontal position is flat next to the base character.
1164    \stopitem
1165    \startitem
1166        For superscripts, the italic correction of the base character is added.
1167    \stopitem
1168    \startitem
1169        For a superscript, two vertical values are calculated: the bottom of the
1170        script (after shifting up), and the top of the base. For a subscript, the two
1171        values are the top of the (shifted down) script, and the bottom of the base.
1172    \stopitem
1173    \startitem
1174        For each of these two locations:
1175        \startitemize
1176            \startitem
1177                find the math kern value at this height for the base (for a subscript
1178                placement, this is the bottom_right corner, for a superscript
1179                placement the top_right corner)
1180            \stopitem
1181            \startitem
1182                find the math kern value at this height for the script (for a
1183                subscript placement, this is the top_left corner, for a superscript
1184                placement the bottom_left corner)
1185            \stopitem
1186            \startitem
1187                add the found values together to get a preliminary result.
1188            \stopitem
1189        \stopitemize
1190    \stopitem
1191    \startitem
1192        The horizontal kern to be applied is the smallest of the two results from
1193        previous step.
1194    \stopitem
1195\stopitemize
1196
1197The math kern value at a specific height is the kern value that is specified by the
1198next higher height and kern pair, or the highest one in the character (if there is no
1199value high enough in the character), or simply zero (if the character has no math kern
1200pairs at all).
1201
1202\subsection{Scripts on extensibles}
1203
1204\topicindex {math+scripts}
1205\topicindex {math+delimiters}
1206\topicindex {math+extensibles}
1207
1208The primitives \lpr {Uunderdelimiter} and \lpr {Uoverdelimiter} allow the
1209placement of a subscript or superscript on an automatically extensible item and
1210\lpr {Udelimiterunder} and \lpr {Udelimiterover} allow the placement of an
1211automatically extensible item as a subscript or superscript on a nucleus. The
1212input:
1213
1214% these produce radical noads .. in fact the code base has the numbers wrong for
1215% quite a while, so no one seems to use this
1216
1217\startbuffer
1218$\Uoverdelimiter  0 "2194 {\hbox{\strut  overdelimiter}}$
1219$\Uunderdelimiter 0 "2194 {\hbox{\strut underdelimiter}}$
1220$\Udelimiterover  0 "2194 {\hbox{\strut  delimiterover}}$
1221$\Udelimiterunder 0 "2194 {\hbox{\strut delimiterunder}}$
1222\stopbuffer
1223
1224\typebuffer will render this:
1225
1226\blank \startnarrower \getbuffer \stopnarrower \blank
1227
1228The vertical placements are controlled by \lpr {Umathunderdelimiterbgap}, \lpr
1229{Umathunderdelimitervgap}, \lpr {Umathoverdelimiterbgap}, and \lpr
1230{Umathoverdelimitervgap} in a similar way as limit placements on large operators.
1231The superscript in \lpr {Uoverdelimiter} is typeset in a suitable scripted style,
1232the subscript in \lpr {Uunderdelimiter} is cramped as well.
1233
1234These primitives accepts an option \type {width} specification. When used the
1235also optional keywords \type {left}, \type {middle} and \type {right} will
1236determine what happens when a requested size can't be met (which can happen when
1237we step to successive larger variants).
1238
1239An extra primitive \lpr {Uhextensible} is available that can be used like this:
1240
1241\startbuffer
1242$\Uhextensible width 10cm 0 "2194$
1243\stopbuffer
1244
1245\typebuffer This will render this:
1246
1247\blank \startnarrower \getbuffer \stopnarrower \blank
1248
1249Here you can also pass options, like:
1250
1251\startbuffer
1252$\Uhextensible width 1pt middle 0 "2194$
1253\stopbuffer
1254
1255\typebuffer This gives:
1256
1257\blank \startnarrower \getbuffer \stopnarrower \blank
1258
1259\LUATEX\ internally uses a structure that supports \OPENTYPE\ \quote
1260{MathVariants} as well as \TFM\ \quote {extensible recipes}. In most cases where
1261font metrics are involved we have a different code path for traditional fonts end
1262\OPENTYPE\ fonts.
1263
1264Sometimes you might want to act upon the size of a delimiter, something that is
1265not really possible because of the fact that they are calculated {\em after} most
1266has been typeset already. In the following example the all|-|zero specification
1267is the trigger to make a fake box with the last delimiter dimensions and shift.
1268It's an ugly hack but its relative simple and not intrusive implementation has no
1269side effects. Any other heuristic solution would not satisfy possible demands
1270anyway. Here is a rather low level example:
1271
1272\startbuffer
1273\startformula
1274\Uleft  \Udelimiter 5 0 "222B
1275\frac{\frac{a}{b}}{\frac{c}{d}}
1276\Uright \Udelimiter 5 0 "222B
1277\kern-2\fontcharwd\textfont0 "222B
1278\mathlimop{\Uvextensible \Udelimiter 0 0 0}_1^2 x
1279\stopformula
1280\stopbuffer
1281
1282\typebuffer
1283
1284The last line, by passing zero values, results in a fake operator that has the
1285dimensions of the previous delimiter. We can then backtrack over the (presumed)
1286width and the two numbers become limit operators. As said, it's not pretty but it
1287works.
1288
1289\subsection{Fractions}
1290
1291\topicindex {math+fractions}
1292
1293The \prm {abovewithdelims} command accepts a keyword \type {exact}. When issued
1294the extra space relative to the rule thickness is not added. One can of course
1295use the \type {\Umathfraction..gap} commands to influence the spacing. Also the
1296rule is still positioned around the math axis.
1297
1298\starttyping
1299$$ { {a} \abovewithdelims() exact 4pt {b} }$$
1300\stoptyping
1301
1302The math parameter table contains some parameters that specify a horizontal and
1303vertical gap for skewed fractions. Of course some guessing is needed in order to
1304implement something that uses them. And so we now provide a primitive similar to the
1305other fraction related ones but with a few options so that one can influence the
1306rendering. Of course a user can also mess around a bit with the parameters
1307\lpr {Umathskewedfractionhgap} and \lpr {Umathskewedfractionvgap}.
1308
1309The syntax used here is:
1310
1311\starttyping
1312{ {1} \Uskewed / <options> {2} }
1313{ {1} \Uskewedwithdelims / () <options> {2} }
1314\stoptyping
1315
1316where the options can be \type {noaxis} and \type {exact}. By default we add half
1317the axis to the shifts and by default we zero the width of the middle character.
1318For Latin Modern the result looks as follows:
1319
1320\def\ShowA#1#2#3{$x + { {#1} \Uskewed           /    #3 {#2} } + x$}
1321\def\ShowB#1#2#3{$x + { {#1} \Uskewedwithdelims / () #3 {#2} } + x$}
1322
1323\start
1324    \switchtobodyfont[modern]
1325    \starttabulate[||||||]
1326        \NC \NC
1327            \ShowA{a}{b}{} \NC
1328            \ShowA{1}{2}{} \NC
1329            \ShowB{a}{b}{} \NC
1330            \ShowB{1}{2}{} \NC
1331        \NR
1332        \NC \type{exact} \NC
1333            \ShowA{a}{b}{exact} \NC
1334            \ShowA{1}{2}{exact} \NC
1335            \ShowB{a}{b}{exact} \NC
1336            \ShowB{1}{2}{exact} \NC
1337        \NR
1338        \NC \type{noaxis} \NC
1339            \ShowA{a}{b}{noaxis} \NC
1340            \ShowA{1}{2}{noaxis} \NC
1341            \ShowB{a}{b}{noaxis} \NC
1342            \ShowB{1}{2}{noaxis} \NC
1343        \NR
1344        \NC \type{exact noaxis} \NC
1345            \ShowA{a}{b}{exact noaxis} \NC
1346            \ShowA{1}{2}{exact noaxis} \NC
1347            \ShowB{a}{b}{exact noaxis} \NC
1348            \ShowB{1}{2}{exact noaxis} \NC
1349        \NR
1350    \stoptabulate
1351\stop
1352
1353The keyword \type {norule} will hide the rule with the above variants while
1354keeping the rule related spacing.
1355
1356\subsection {Delimiters: \type{\Uleft}, \prm {Umiddle} and \prm {Uright}}
1357
1358\topicindex {math+delimiters}
1359
1360Normally you will force delimiters to certain sizes by putting an empty box or
1361rule next to it. The resulting delimiter will either be a character from the
1362stepwise size range or an extensible. The latter can be quite differently
1363positioned than the characters as it depends on the fit as well as the fact if
1364the used characters in the font have depth or height. Commands like (plain \TEX
1365s) \type {\big} need use this feature. In \LUATEX\ we provide a bit more control
1366by three variants that support optional parameters \type {height}, \type {depth}
1367and \type {axis}. The following example uses this:
1368
1369\startbuffer
1370\Uleft   height 30pt depth 10pt      \Udelimiter "0 "0 "000028
1371\quad x\quad
1372\Umiddle height 40pt depth 15pt      \Udelimiter "0 "0 "002016
1373\quad x\quad
1374\Uright  height 30pt depth 10pt      \Udelimiter "0 "0 "000029
1375\quad \quad \quad
1376\Uleft   height 30pt depth 10pt axis \Udelimiter "0 "0 "000028
1377\quad x\quad
1378\Umiddle height 40pt depth 15pt axis \Udelimiter "0 "0 "002016
1379\quad x\quad
1380\Uright  height 30pt depth 10pt axis \Udelimiter "0 "0 "000029
1381\stopbuffer
1382
1383\typebuffer
1384
1385\startlinecorrection
1386\ruledhbox{\mathematics{\getbuffer}}
1387\stoplinecorrection
1388
1389The keyword \type {exact} can be used as directive that the real dimensions
1390should be applied when the criteria can't be met which can happen when we're
1391still stepping through the successively larger variants. When no dimensions are
1392given the \type {noaxis} command can be used to prevent shifting over the axis.
1393
1394You can influence the final class with the keyword \type {class} which will
1395influence the spacing. The numbers are the same as for character classes.
1396
1397\stopsection
1398
1399\startsection[title={Extracting values}]
1400
1401\subsection{Codes}
1402
1403\topicindex {math+codes}
1404
1405You can extract the components of a math character. Say that we have defined:
1406
1407\starttyping
1408\Umathcode 1 2 3 4
1409\stoptyping
1410
1411then
1412
1413\starttyping
1414[\Umathcharclass1] [\Umathcharfam1] [\Umathcharslot1]
1415\stoptyping
1416
1417will return:
1418
1419\starttyping
1420[2] [3] [4]
1421\stoptyping
1422
1423These commands are provides as convenience. Before they come available you could
1424do the following:
1425
1426\starttyping
1427\def\Umathcharclass{\directlua{tex.print(tex.getmathcode(token.scan_int())[1])}}
1428\def\Umathcharfam  {\directlua{tex.print(tex.getmathcode(token.scan_int())[2])}}
1429\def\Umathcharslot {\directlua{tex.print(tex.getmathcode(token.scan_int())[3])}}
1430\stoptyping
1431
1432\subsection {Last lines}
1433
1434\topicindex {math+last line}
1435
1436There is a new primitive to control the overshoot in the calculation of the
1437previous line in mid|-|paragraph display math. The default value is 2 times
1438the em width of the current font:
1439
1440\starttyping
1441\predisplaygapfactor=2000
1442\stoptyping
1443
1444If you want to have the length of the last line independent of math i.e.\ you don't
1445want to revert to a hack where you insert a fake display math formula in order to
1446get the length of the last line, the following will often work too:
1447
1448\starttyping
1449\def\lastlinelength{\dimexpr
1450    \directlua {tex.sprint (
1451        (nodes.dimensions(node.tail(tex.lists.page_head).list))
1452    )}sp
1453\relax}
1454\stoptyping
1455
1456\stopsection
1457
1458\startsection[title={Math mode}]
1459
1460\subsection {Verbose versions of single|-|character math commands}
1461
1462\topicindex {math+styles}
1463
1464\LUATEX\ defines six new primitives that have the same function as
1465\type {^}, \type {_}, \type {$}, and \type {$$}:
1466
1467\starttabulate[|l|l|]
1468\DB primitive                  \BC explanation \NC \NR
1469\TB
1470\NC \lpr {Usuperscript}      \NC duplicates the functionality of \type {^} \NC \NR
1471\NC \lpr {Usubscript}        \NC duplicates the functionality of \type {_} \NC \NR
1472\NC \lpr {Ustartmath}        \NC duplicates the functionality of \type {$}, % $
1473                                   when used in non-math mode. \NC \NR
1474\NC \lpr {Ustopmath}         \NC duplicates the functionality of \type {$}, % $
1475                                   when used in inline math mode. \NC \NR
1476\NC \lpr {Ustartdisplaymath} \NC duplicates the functionality of \type {$$}, % $$
1477                                   when used in non-math mode. \NC \NR
1478\NC \lpr {Ustopdisplaymath}  \NC duplicates the functionality of \type {$$}, % $$
1479                                   when used in display math mode. \NC \NR
1480\LL
1481\stoptabulate
1482
1483The \lpr {Ustopmath} and \lpr {Ustopdisplaymath} primitives check if the current
1484math mode is the correct one (inline vs.\ displayed), but you can freely intermix
1485the four mathon|/|mathoff commands with explicit dollar sign(s).
1486
1487\subsection{Script commands \lpr {Unosuperscript} and \lpr {Unosubscript}}
1488
1489\topicindex {math+styles}
1490\topicindex {math+scripts}
1491
1492These two commands result in super- and subscripts but with the current style (at the
1493time of rendering). So,
1494
1495\startbuffer[script]
1496$
1497    x\Usuperscript  {1}\Usubscript  {2} =
1498    x\Unosuperscript{1}\Unosubscript{2} =
1499    x\Usuperscript  {1}\Unosubscript{2} =
1500    x\Unosuperscript{1}\Usubscript  {2}
1501$
1502\stopbuffer
1503
1504\typebuffer[script]
1505
1506results in \inlinebuffer[script].
1507
1508\subsection{Allowed math commands in non|-|math modes}
1509
1510\topicindex {math+text}
1511\topicindex {text+math}
1512
1513The commands \prm {mathchar}, and \lpr {Umathchar} and control sequences that are
1514the result of \prm {mathchardef} or \lpr {Umathchardef} are also acceptable in
1515the horizontal and vertical modes. In those cases, the \prm {textfont} from the
1516requested math family is used.
1517
1518% \startsection[title={Math todo}]
1519%
1520% The following items are still todo.
1521%
1522% \startitemize
1523% \startitem
1524%     Pre-scripts.
1525% \stopitem
1526% \startitem
1527%     Multi-story stacks.
1528% \stopitem
1529% \startitem
1530%     Flattened accents for high characters (maybe).
1531% \stopitem
1532% \startitem
1533%     Better control over the spacing around displays and handling of equation numbers.
1534% \stopitem
1535% \startitem
1536%     Support for multi|-|line displays using \MATHML\ style alignment points.
1537% \stopitem
1538% \stopitemize
1539%
1540% \stopsection
1541
1542\stopsection
1543
1544\startsection[title={Goodies}]
1545
1546\subsection {Flattening: \lpr {mathflattenmode}}
1547
1548\topicindex {math+flattening}
1549
1550The \TEX\ math engine collapses \type {ord} noads without sub- and superscripts
1551and a character as nucleus. and which has the side effect that in \OPENTYPE\ mode
1552italic corrections are applied (given that they are enabled).
1553
1554\startbuffer[sample]
1555\switchtobodyfont[modern]
1556$V \mathbin{\mathbin{v}} V$\par
1557$V \mathord{\mathord{v}} V$\par
1558\stopbuffer
1559
1560\typebuffer[sample]
1561
1562This renders as:
1563
1564\blank \start \mathflattenmode\plusone \getbuffer[sample] \stop \blank
1565
1566When we set \lpr {mathflattenmode} to 31 we get:
1567
1568\blank \start \mathflattenmode\numexpr1+2+4+8+16\relax \getbuffer[sample] \stop \blank
1569
1570When you see no difference, then the font probably has the proper character
1571dimensions and no italic correction is needed. For Latin Modern (at least till
15722018) there was a visual difference. In that respect this parameter is not always
1573needed unless of course you want efficient math lists anyway.
1574
1575You can influence flattening by adding the appropriate number to the value of the
1576mode parameter. The default value is~1.
1577
1578\starttabulate[|Tc|c|]
1579\DB mode \BC class \NC \NR
1580\TB
1581\NC  1   \NC ord   \NC \NR
1582\NC  2   \NC bin   \NC \NR
1583\NC  4   \NC rel   \NC \NR
1584\NC  8   \NC punct \NC \NR
1585\NC 16   \NC inner \NC \NR
1586\LL
1587\stoptabulate
1588
1589\subsection {Less Tracing}
1590
1591\topicindex {math+tracing}
1592
1593Because there are quite some math related parameters and values, it is possible
1594to limit tracing. Only when \type {tracingassigns} and|/|or \type
1595{tracingrestores} are set to~2 or more they will be traced.
1596
1597\subsection {Math options with \lpr {mathdefaultsmode}}
1598
1599This option has been introduced because \LATEX\ developers wanted some of the
1600defaults to be different from the ones that were set in stone when we froze
1601\LUATEX. The default values are:
1602
1603\starttabulate[|l|c|c|]
1604\DB                 \BC scanning \BC rendering \NC \NR
1605\TB
1606\NC radical/root    \NC cramped  \NC cramped   \NC \NR
1607\NC under delimiter \NC cramped  \NC supstyle  \NC \NR
1608\NC over delimiter  \NC cramped  \NC substyle  \NC \NR
1609\NC delimiter under \NC cramped  \NC current   \NC \NR
1610\NC delimiter over  \NC cramped  \NC current   \NC \NR
1611\LL
1612\stoptabulate
1613
1614When \type {\mathdefaultsmode} is larger than zero, we have:
1615
1616\starttabulate[|l|c|c|]
1617\DB                 \BC scanning \BC rendering \NC \NR
1618\TB
1619\NC radical/root    \NC cramped  \NC cramped   \NC \NR
1620\NC under delimiter \NC substyle \NC substyle  \NC \NR
1621\NC over delimiter  \NC supstyle \NC supstyle  \NC \NR
1622\NC delimiter under \NC current  \NC current   \NC \NR
1623\NC delimiter over  \NC cramped  \NC cramped   \NC \NR
1624\LL
1625\stoptabulate
1626
1627It is outside the scope of this manual to discuss the rationale behind these
1628defaults. The zero values date back from the early times. If needed you can
1629explicitly set the style in the content argument.
1630
1631\subsection {Math options with \lpr {mathoption}}
1632
1633The logic in the math engine is rather complex and there are often no universal
1634solutions (read: what works out well for one font, fails for another). Therefore
1635some variations in the implementation are driven by parameters (modes). In
1636addition there is a new primitive \lpr {mathoption} which will be used for
1637testing. Don't rely on any option to be there in a production version as they are
1638meant for development.
1639
1640This option was introduced for testing purposes when the math engine got split
1641code paths and it forces the engine to treat new fonts as old ones with respect
1642to italic correction etc. There are no guarantees given with respect to the final
1643result and unexpected side effects are not seen as bugs as they relate to font
1644properties. There is currently only one option:
1645
1646\startbuffer
1647\mathoption old 1
1648\stopbuffer
1649
1650The \type {oldmath} boolean flag in the \LUA\ font table is the official way to
1651force old treatment as it's bound to fonts. Like with all options we may
1652temporarily introduce with this command this feature is not meant for production.
1653
1654% % obsolete:
1655%
1656% \subsubsection {\type {\mathoption noitaliccompensation}}
1657%
1658% This option compensates placement for characters with a built|-|in italic
1659% correction.
1660%
1661% \startbuffer
1662% {\showboxes\int}\quad
1663% {\showboxes\int_{|}^{|}}\quad
1664% {\showboxes\int\limits_{|}^{|}}
1665% \stopbuffer
1666%
1667% \typebuffer
1668%
1669% Gives (with computer modern that has such italics):
1670%
1671% \startlinecorrection[blank]
1672%     \switchtobodyfont[modern]
1673%     \startcombination[nx=2,ny=2,distance=5em]
1674%         {\mathoption noitaliccompensation 0\relax \mathematics{\getbuffer}}
1675%             {\nohyphens\type{0:inline}}
1676%         {\mathoption noitaliccompensation 0\relax \mathematics{\displaymath\getbuffer}}
1677%             {\nohyphens\type{0:display}}
1678%         {\mathoption noitaliccompensation 1\relax \mathematics{\getbuffer}}
1679%             {\nohyphens\type{1:inline}}
1680%         {\mathoption noitaliccompensation 1\relax \mathematics{\displaymath\getbuffer}}
1681%             {\nohyphens\type{1:display}}
1682%     \stopcombination
1683% \stoplinecorrection
1684
1685% % obsolete:
1686%
1687% \subsubsection {\type {\mathoption nocharitalic}}
1688%
1689% When two characters follow each other italic correction can interfere. The
1690% following example shows what this option does:
1691%
1692% \startbuffer
1693% \catcode"1D443=11
1694% \catcode"1D444=11
1695% \catcode"1D445=11
1696% P( PP PQR
1697% \stopbuffer
1698%
1699% \typebuffer
1700%
1701% Gives (with computer modern that has such italics):
1702%
1703% \startlinecorrection[blank]
1704%     \switchtobodyfont[modern]
1705%     \startcombination[nx=2,ny=2,distance=5em]
1706%         {\mathoption nocharitalic 0\relax \mathematics{\getbuffer}}
1707%             {\nohyphens\type{0:inline}}
1708%         {\mathoption nocharitalic 0\relax \mathematics{\displaymath\getbuffer}}
1709%             {\nohyphens\type{0:display}}
1710%         {\mathoption nocharitalic 1\relax \mathematics{\getbuffer}}
1711%             {\nohyphens\type{1:inline}}
1712%         {\mathoption nocharitalic 1\relax \mathematics{\displaymath\getbuffer}}
1713%             {\nohyphens\type{1:display}}
1714%     \stopcombination
1715% \stoplinecorrection
1716
1717% % obsolete:
1718%
1719% \subsubsection {\type {\mathoption useoldfractionscaling}}
1720%
1721% This option has been introduced as solution for tracker item 604 for fuzzy cases
1722% around either or not present fraction related settings for new fonts.
1723
1724\stopsection
1725
1726\stopchapter
1727
1728\stopcomponent
1729