summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/still/still-opentypemath.tex
blob: 43a34086644822fd5cd70cf7896b7e4c3ef6e6f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
% language=uk

\environment still-environment

\starttext

\startchapter[title=Opentype math]

\startsection[title=Introduction]

When \TEX\ typesets mathematics it makes some assumptions about the properties of
fonts and dimensions of glyphs. Due to practical limitations in the traditional
eight|-|bit fonts, such as the number of available characters in a font and a
limited number of heights and depths, some juggling takes place. For instance,
\TEX\ sometimes uses dimensions as a signal to treat some characters as special.
This is not a problem as long as one knows how to make a font and in practice
that was done by looking at the properties of Computer Modern to implement
similar shapes. After all, there are not that many math fonts around and
basically there is only one engine that can deal with them properly.

However, when Microsoft set the standard for \OPENTYPE\ math fonts it also
steered the direction of their use in rendering mathematics. This means that the
\LUATEX\ engine, which handles \OPENTYPE\ fonts, has to implement some
alternative code paths. At the start, this involved a bit of gambling because
there was no real specification; since then we now have a better picture. One of
the more complex changes that took place is in the way italic correction is
applied. A dirty way out of this dilemma would be to turn the math fonts into
virtual ones that match traditional \TEX\ properties, but this would not be a
nice solution.

It must be noted that in the process of implementing support for the new fonts,
Taco (Hoekwater) turned some noad types (see below) into a generic noad with a subtype. This
simplified the transition. At the same time, a lot of detailed control was added
in the way successive characters are spaced.

In \LUATEX\ before 0.85, the italic correction was always added when a character got
boxed (a frequently used preparation in the math builder). Now this is only done
for the traditional fonts because, concerning italic correction, the \OPENTYPE\
standard states: \footnote {Recently version 1.8 has been published on the Microsoft
website.}

\startitemize[n]
    \startitem
        When a run of slanted characters is followed by a straight character
        (such as an operator or a delimiter), the italics correction of the last
        glyph is added to its advance width.
    \stopitem
    \startitem
        When positioning limits on an N-ary operator (e.g., integral sign), the
        horizontal position of the upper limit is moved to the right by half of the
        italics correction, while the position of the lower limit is moved to the
        left by the same distance.
    \stopitem
    \startitem
        When positioning superscripts and subscripts, their default horizontal
        positions are also different by the amount of the italics correction of
        the preceding glyph.
    \stopitem
\stopitemize

And, with respect to kerning:

\startitemize[continue]
    \startitem
        Set the default horizontal position for the superscript as shifted
        relative to the position of the subscript by the italics correction of
        the base glyph.
    \stopitem
\stopitemize

I must admit that when the first implementation showed up, my natural reaction to
unexpected behaviour was just to compensate for it. One such solution was simply not
to pass the italic correction to the engine and deal with it in \LUA. In
practice, that didn't work well for all cases; one reason was that the engine
saw the combination of old fonts as a new one and followed a mixed code path.
\footnote {\CONTEXT\ employed \UNICODE\ math right from the start of \LUATEX.}
Another approach I tried was a mix of manipulated italic values and \LUA, but
finally, as specifications settled I decided to leave it to the engine completely,
if only because successive versions of \LUATEX\ behaved much better.

So, as we were closing in on the first stable release of \LUATEX\ (1.0.0
was released on September~27, 2016; this note was mostly written in the
early part of 2016), I decided to fix the
pending issues and sat down to look at the math|-|related code. I must admit that I
had never looked in depth into that part of the machinery. In the next sections I
will discuss some of the outcomes of this exercise.

I will also discuss some extensions that have been on the agenda for years. They
are rather generic and handy, but I must also admit that the \MKIV\ code related
to math has so many options to control rendering that I'm not sure if they will
ever be used in \CONTEXT. Nevertheless, these generic extensions fit well into
the set of basic features of \LUATEX.

\stopsection

\startsection[title=Italic correction]

As stated above, the normal code path included italic correction in all the math
boxes made. This meant that, in some places, the correction had to be
removed and/or moved to another place in the chain. This is a natural side effect
of the fact that \TEX\ runs over the intermediate list of math nodes (noads) and
turns them into regular nodes, mostly glyphs, kerns, glue and boxes.

The complication is not so much the italic corrections themselves, because we
could just continue to do the same, but the fact that these corrections are to be
interpreted differently in case of integrals. There, the problem is that we have
to (kind of) look backward at what is done in order to determine what italic
corrections are to be applied.

The original solution was to keep track of the applied correction via variables
but that still made some analysis necessary. In the new implementation, more
information is stored in the processed noads. This is a logical choice given that
we have already added other information. It also makes it possible to fix cases
that will (for sure) show up in the future.

\startbuffer[ic-1]
\ruledhbox\bgroup
    \showglyphs\showboxes
    \hbox{$\int ^2  $}\quad
    \hbox{$\int   _2$}\quad
    \hbox{$\int ^2_2$}\quad
    \hbox{$f    ^2  $}\quad
    \hbox{$f      _2$}\quad
    \hbox{$f    ^2_2$}%
\egroup
\stopbuffer

\startbuffer[ic-2]
\ruledhbox\bgroup
    \showglyphs\showboxes
    \hbox{$\normalint ^2  $}\quad
    \hbox{$\normalint   _2$}\quad
    \hbox{$\normalint ^2_2$}\quad
    \hbox{$\int       ^2  $}\quad
    \hbox{$\int         _2$}\quad
    \hbox{$\int       ^2_2$}%
\egroup
\stopbuffer

\placefigure
  [here]
  [fig:italic-correction-1]
  {Italic correction examples (1): superscripts shifted right and subscripts left.}
  {\scale[width=\textwidth]{\getbuffer[ic-1]}}

In \in {figure} [fig:italic-correction-1] we show two examples of inline italic
correction. The superscripts are shifted to the right and the subscripts to the
left. In the case of an integral sign, we need to move half the correction. This
is triggered by the \type {\nolimits} primitive. In \in {figure}
[fig:italic-correction-2] we show the difference between just an integral
character and one tagged as having limits. \footnote {We show some boxes so that
you can get an idea what \TEX\ is doing. Essentially, \TEX\ puts superscripts and
subscripts on top of each other with some kern in between and then corrects the
dimensions.}

\placefigure
  [here]
  [fig:italic-correction-2]
  {Italic correction examples (2): plain integral vs.\ integral with limits}
  {\scale[width=\textwidth]{\getbuffer[ic-2]}}

The amount of correction, if present at all, depends on the font, and in this
document we use DejaVu math. \in {Figure} [fig:italic-correction-3] shows a few
variants. As you can see, the amount of correction is highly font dependent.

\placefigure
  [here]
  [fig:italic-correction-3]
  {Italic correction examples (3): correction amounts are font-dependent.}
  {\startcombination[1*4]
     {\switchtobodyfont [pagella]\scale[width=\textwidth]{\getbuffer[ic-1]}} {cambria}
     {\switchtobodyfont [cambria]\scale[width=\textwidth]{\getbuffer[ic-1]}} {pagella}
     {\switchtobodyfont  [modern]\scale[width=\textwidth]{\getbuffer[ic-1]}} {latin modern}
     {\switchtobodyfont[lucidaot]\scale[width=\textwidth]{\getbuffer[ic-1]}} {lucida ot}
   \stopcombination}

\startsection[title=Vertical delimiters]

When we go into display math, there is a good chance that an integral has to be
enlarged. The integral sign in \UNICODE\ has slot \type {0x222B}, so we can
define a bigger one as follows:

\startbuffer[nocontext]
\let\int\normalint
\stopbuffer

\startbuffer[cambria]
\switchtobodyfont[cambria]%
\stopbuffer

\startbuffer[pagella]
\switchtobodyfont[pagella]%
\stopbuffer

\startbuffer[modern]
\switchtobodyfont[modern]%
\stopbuffer

\startbuffer[lucidaot]
\switchtobodyfont[lucidaot]%
\stopbuffer

\startbuffer[xits]
\switchtobodyfont[xits]%
\stopbuffer

\startbuffer[largerint]
\def\standardint{
    \Umathchar "1 "0 "222B
}
\def\wrappedint{\mathop{
    \Umathchar "1 "0 "222B
}}
\def\biggerint{\mathop{
    \Uleft  height 3ex depth 3ex axis \Udelimiter "0 "0 "222B
    \Uright .
}}
\def\evenbiggerint{\mathop{
    \Uleft  height 6ex depth 6ex axis \Udelimiter "0 "0 "222B
    \Uright .
}}
\stopbuffer

\typebuffer[largerint]

\startbuffer[demoint]
$
\displaystyle\standardint  ^a_b\enspace
\displaystyle\wrappedint   ^a_b\enspace
\displaystyle\biggerint    ^a_b\enspace
\displaystyle\evenbiggerint^a_b\enspace
$
\stopbuffer

The \type {axis} keyword will apply a shift up over the size of the current
styles math axis. We use this in some examples as:

\typebuffer[demoint]

In \in {figure} [fig:demoint] you can see some subtle differences. The wrapped
version doesn't shift the superscript and subscript. The reason is that the
operator is hidden in its own wrapper and the scripts attach at an outer level.
So, unless we start analyzing the innermost noad and apply that to the outer, we
cannot know the shift. Such analyzing is asking for problems: where do we stop
and what slight variations do we take into account? It's better to be
predictable.

\startbuffer
    \ruledhbox \bgroup
        \showglyphs \showboxes
        \getbuffer[nocontext,pagella, largerint,demoint]
        \getbuffer[nocontext,cambria, largerint,demoint]
        \getbuffer[nocontext,modern,  largerint,demoint]
        \getbuffer[nocontext,lucidaot,largerint,demoint]
    \egroup
\stopbuffer

\placefigure
  [here]
  [fig:demoint]
  {Comparison of integral variants (standard, wrapped, bigger, even
   bigger) among fonts: \TeX\ Gyre Pagella, Cambria, Latin Modern, and
   Lucida OT.}
  {\scale[width=\textwidth]{\getbuffer}}

Another observation is that Latin Modern does not provide (at least not yet)
large integrals at all.

The following four cases are equivalent:

\starttyping
\Uleft   height 3ex depth 3ex axis \Udelimiter "0 "0 "222B
\Uright .

\Uleft  .
\Uright  height 3ex depth 3ex axis \Udelimiter "0 "0 "222B

\Uleft   .
\Umiddle height 3ex depth 3ex axis \Udelimiter "0 "0 "222B
\Uright  .

\Uleft   .
\Umiddle height 3ex depth 3ex axis \Udelimiter "0 "0 "222B
\Uright  .
\stoptyping

However, because this all looks a bit clumsy, we now provide a new
primitive:

\starttyping
\Uvextensible
    height <dimension>
    depth <dimension>
    axis
    exact
    <delimiter>
\stoptyping

The symbol to be constructed will have size \type {height} plus \type {depth}.
When an \type {axis} is specified, the symbol will be shifted up, which is
normally the case for such symbols. The keyword \type {exact} will correct the
dimensions when no exact match is made, and this can be the case as long as we
use the stepwise larger glyphs and before we end up using the composed shapes.
When no dimensions are specified, the normal construction takes place and the
only keyword that can be used then is \type {noaxis} which keeps the axis out of
the calculations. After about a week of experimenting and exploring options, this
combination made most sense, read: no fuzzy heuristics but predictable behaviour.
After all, one might need different solutions for different fonts or
circumstances and the applied logic (and expectations) can (and will, for sure)
differ per macro package.

\def\SampleRule#1#2%
  {\blackrule[height=#1,depth=#2,width=1mm,color=maincolor]}

% \def\SampleDelimiterSpec#1#2%
%   {\ruledhbox \bgroup
%       \SampleRule{20mm}{20mm}\enspace
%       \ruledhbox{$\maincolor\char"#1$}\enspace
%       \ruledhbox{$\Uleft height  1mm depth  1mm #2 \Udelimiter 0 0 "#1\Uright .$}\enspace
%       \ruledhbox{$\Uleft height  2mm depth  2mm #2 \Udelimiter 0 0 "#1\Uright .$}\enspace
%       \ruledhbox{$\Uleft height  5mm depth  5mm #2 \Udelimiter 0 0 "#1\Uright .$}\enspace
%       \ruledhbox{$\Uleft height 20mm depth 20mm #2 \Udelimiter 0 0 "#1\Uright .$}\enspace
%       \ruledhbox{$\Uleft height 20mm depth 10mm #2 \Udelimiter 0 0 "#1\Uright .$}%
%    \egroup}

\def\SampleDelimiterSpec#1#2%
  {\ruledhbox \bgroup
      \SampleRule{20mm}{20mm}\enspace
      \ruledhbox{$\maincolor\char"#1$}\enspace
      \ruledhbox{$\Uvextensible height  1mm depth  1mm #2 \Udelimiter 0 0 "#1$}\enspace
      \ruledhbox{$\Uvextensible height  2mm depth  2mm #2 \Udelimiter 0 0 "#1$}\enspace
      \ruledhbox{$\Uvextensible height  5mm depth  5mm #2 \Udelimiter 0 0 "#1$}\enspace
      \ruledhbox{$\Uvextensible height 20mm depth 20mm #2 \Udelimiter 0 0 "#1$}\enspace
      \ruledhbox{$\Uvextensible height 20mm depth 10mm #2 \Udelimiter 0 0 "#1$}%
   \egroup}

\startbuffer[delimiter-integral-spec]
\startcombination[4*1]
    {\SampleDelimiterSpec{222B}{}}           {}
    {\SampleDelimiterSpec{222B}{axis}}       {axis}
    {\SampleDelimiterSpec{222B}{exact}}      {exact}
    {\SampleDelimiterSpec{222B}{axis exact}} {axis exact}
\stopcombination
\stopbuffer

\startbuffer[delimiter-leftparent-spec]
\startcombination[4*1]
    {\SampleDelimiterSpec{0028}{}}           {}
    {\SampleDelimiterSpec{0028}{axis}}       {axis}
    {\SampleDelimiterSpec{0028}{exact}}      {exact}
    {\SampleDelimiterSpec{0028}{axis exact}} {axis exact}
\stopcombination
\stopbuffer

\placefigure
  [here]
  [fig:integral-spec]
  {Cambria integrals, with dimensions.}
  {\getbuffer[nocontext,cambria,delimiter-integral-spec]}

\placefigure
  [here]
  [fig:leftparent-spec]
  {Cambria left parenthesis, with dimensions.}
  {\getbuffer[nocontext,cambria,delimiter-leftparent-spec]}

\def\SampleDelimiterAuto#1#2%
  {\ruledhbox \bgroup
      \ruledhbox{$\maincolor\char"#1$}\enspace
      \ruledhbox{$\Uleft #2 \Udelimiter 0 0 "#1\SampleRule{ 1mm}{ 1mm}\Uright .$}\enspace
      \ruledhbox{$\Uleft #2 \Udelimiter 0 0 "#1\SampleRule{ 2mm}{ 2mm}\Uright .$}\enspace
      \ruledhbox{$\Uleft #2 \Udelimiter 0 0 "#1\SampleRule{ 5mm}{ 5mm}\Uright .$}\enspace
      \ruledhbox{$\Uleft #2 \Udelimiter 0 0 "#1\SampleRule{10mm}{10mm}\Uright .$}\enspace
      \ruledhbox{$\Uleft #2 \Udelimiter 0 0 "#1\SampleRule{15mm}{15mm}\Uright .$}\enspace
      \ruledhbox{$\Uleft #2 \Udelimiter 0 0 "#1\SampleRule{20mm}{20mm}\Uright .$}\enspace
      \ruledhbox{$\Uleft #2 \Udelimiter 0 0 "#1\SampleRule{20mm}{10mm}\Uright .$}%
   \egroup}

\startbuffer[delimiter-integral-auto]
\startcombination[2*1]
    {\SampleDelimiterAuto{222B}{}}       {}
    {\SampleDelimiterAuto{222B}{noaxis}} {noaxis}
\stopcombination
\stopbuffer

\startbuffer[delimiter-leftparent-auto]
\startcombination[4*1]
    {\SampleDelimiterAuto{0028}{}}       {}
    {\SampleDelimiterAuto{0028}{noaxis}} {noaxis}
\stopcombination
\stopbuffer

\placefigure
  [here]
  [fig:integral]
  {Cambria integrals, adaptive: \type {axis} left and \type {noaxis} right.}
  {\getbuffer[nocontext,cambria,delimiter-integral-auto]}

\placefigure
  [here]
  [fig:leftparent]
  {Cambria left parenthesis, adaptive: \type {axis} left and \type {noaxis} right.}
  {\getbuffer[nocontext,cambria,delimiter-leftparent-auto]}
\stopsection

\startsection[title=Horizontal delimiters]

Horizontal extenders also have some new options. Although one can achieve similar
results with macros, the following might look a bit more natural. Also, some
properties are lost once the delimiter is constructed, so macros can become
complex when trying to determine the original dimensions involved.

We start with the new \type {\Uhextensible} primitive that accepts a dimension.
It's just a variant of the over and under delimiters with no content part.

\starttyping
\Uhextensible
    height <dimension>
    depth <dimension>
    left | middle | right
    <family>
    <slot>
\stoptyping

So for example you can say:

\starttyping
$\Uhextensible width 30pt 0 "2194$
\stoptyping

The \type {left}, \type {middle} and \type {right} keywords are only interpreted
when the requested size can't be met due to stepwise larger glyph selection
(i.e., before we start using arbitrary sizes made of snippets). \in {Figure}
[fig:hextensible] shows what we get when we step from 2--20 points by
increments of 2 points in Cambria.

\unexpanded\def\ExtensibleFunA#1%
  {\switchtobodyfont[cambria,17.3pt]%
   \hbox\bgroup
     \dostepwiserecurse{2}{20}{2}
       {\backgroundline
          [maincolor]
          {\white$\Uhextensible width \recurselevel pt #1 0 "2194$}%
        \quad}%
     \unskip
   \egroup}

\unexpanded\def\ExtensibleFunB#1%
  {\switchtobodyfont[cambria,17.3pt]%
   \hbox\bgroup
     \dostepwiserecurse{2}{20}{2}
       {\ruledhbox
          {$\Uhextensible width \recurselevel pt #1 0 "2194$}%
        \quad}%
     \unskip
   \egroup}

\startbuffer
\starttabulate[|l|p|]
    \NC (default)     \NC \ExtensibleFunA{}       \par \ExtensibleFunB{}       \NC \NR
    \NC \type{left}   \NC \ExtensibleFunA{left}   \par \ExtensibleFunB{left}   \NC \NR
    \NC \type{middle} \NC \ExtensibleFunA{middle} \par \ExtensibleFunB{middle} \NC \NR
    \NC \type{right}  \NC \ExtensibleFunA{right}  \par \ExtensibleFunB{right}  \NC \NR
\stoptabulate
\stopbuffer

\placefigure
    [here]
    [fig:hextensible]
    {Stepwise wider \type {\Uhextensible} with options (cambria).}
    {\getbuffer}

The dimensions and options can also be given to the four primitives \type {\Uoverdelimiter},
\type {\Uunderdelimiter}, \type {\Udelimiterover} and \type {\Udelimiterunder}. \in {Figure} [fig:delimiterunder] shows what happens when the
delimiter is smaller than requested. The samples look like this:

\starttyping
$\Udelimiterunder width 1pt 0 "2194 {\hbox{\strut !}}
\stoptyping

When no dimension is given the keywords are ignored as it makes no sense to
mess with the extensible in that case.

\unexpanded\def\DelimiterFunA#1%
  {\switchtobodyfont[cambria,20.7pt]%
   \hbox\bgroup
     \dostepwiserecurse{1}{10}{1}
        {\backgroundline
           [maincolor]
           {\white$\Udelimiterunder width ##1pt #1 0 "2194 {\hbox{\strut !}}$}%
         \quad}%
     \unskip
   \egroup}

\unexpanded\def\DelimiterFunB#1%
  {\switchtobodyfont[cambria,20.7pt]%
   \hbox\bgroup
     \dostepwiserecurse{1}{10}{1}
        {\ruledhbox
           {$\Udelimiterunder width ##1pt #1 0 "2194 {\hbox{\strut !}}$}%
          \quad}%
     \unskip
   \egroup}

\startbuffer
\starttabulate[|l|p|]
    \NC (default)     \NC \DelimiterFunA{}       \par \DelimiterFunB{}       \NC \NR
    \NC \type{left}   \NC \DelimiterFunA{left}   \par \DelimiterFunB{left}   \NC \NR
    \NC \type{middle} \NC \DelimiterFunA{middle} \par \DelimiterFunB{middle} \NC \NR
    \NC \type{right}  \NC \DelimiterFunA{right}  \par \DelimiterFunB{right}  \NC \NR
    \NC \NR
\stoptabulate
\stopbuffer

\placefigure
    [here]
    [fig:delimiterunder]
    {Stepwise wider \type {\Udelimiterunder} with options (cambria).}
    {\getbuffer}

\stopsection

\startsection[title=Accents]

Many years ago, I observed that overlaying characters (which happens when
we negate an operator which has no composed negation glyph) didn't always give nice results
and, therefore, a tracker item was created. When going over the todo list, I ran
across a suggested patch by Khaled Hosny that added an overlay accent type. As
the suggested solution fits in with the other extensions, a variant has been
implemented.

The results definitely depend on the quality and completeness of the font, so here we
will show \type {xits}. The placement of an \type {overlay} also depends on the top
accent shift as specified in the font for the used glyph. Instead of a fixed
criterion for trying to find the best match, an additional \type {fraction}
(numerator) parameter can be specified. A value of $800$ means that the target
width is $800/1000$.

The \type {\Umathaccent} command now has the following syntax:

\starttyping
\Umathaccent
    [top|bottom|overlay]
    [fixed]
    [fraction <number>]
    <delimiter>
    {content}
\stoptyping

When we have an overlay, the fraction concerns the height; otherwise it concerns
the width of the nucleus. In both cases, it is only applied when searching for
stepwise larger glyphs, as extensibles are not influenced. An example of a
specification is:

\starttyping
\Umathaccent
    overlay "0 "0 "0338
    fraction 950
    {\Umathchar"1"0"2211}
\stoptyping

\in {Figure} [fig:accent-1] shows what we get when we use different fractions
(from 800 up to 1500 with a step of 100). We see that \type {\overlay} is not
always useful.

\startbuffer[accents-1]
\dostepwiserecurse{800}{1500}{100}{%
$\Umathaccent
    overlay "0 "0 "0338
    fraction #1
    {\Umathchar"1"0"2211} #1
$\quad
}\unskip
\stopbuffer

\startbuffer
\startcombination[1*3]
    {\getbuffer[xits,accents-1]}    {xits    \endash\ has   variants}
    {\getbuffer[cambria,accents-1]} {cambria \endash\ lacks variants}
    {\getbuffer[pagella,accents-1]} {pagella \endash\ lacks variants}
\stopcombination
\stopbuffer

\placefigure
    [here]
    [fig:accent-1]
    {Using \type {overlay} in \type {\Umathaccent}.}
    {\getbuffer}

\startbuffer[accents-2]
$\Umathaccent overlay "0 "0 "0338 {x}$
$\Umathaccent overlay "0 "0 "0338 {\tf x}$
$\Umathaccent overlay "0 "0 "0338 {\tf xxx}$
\stopbuffer

Normally you can forget about the factor because overlays make most sense for
inline math, which uses relatively small glyphs, so we can get \getbuffer
[accents-2] with the following code:

\typebuffer[accents-2]

A normal accent can also be influenced by \type {fraction}:

\startbuffer[accents-4]
\dostepwiserecurse{500}{1500}{250}{%
$
    \Umathaccent
        top "0 "0 "23DE
        fraction #1
        {a\times b}
$\quad
}\unskip
\stopbuffer

\blank \start \getbuffer[accents-4] \stop \blank

\stopsection

\startsection[title=Fractions]

A normal fraction has a reasonable thick rule but as soon as you make it bigger you
will notice a peculiar effect:

\startlinecorrection
\startcombination[5*1]
   {$\displaystyle x + {{a} \abovewithdelims() 1pt {b}}$} {1pt}
   {$\displaystyle x + {{a} \abovewithdelims() 2pt {b}}$} {2pt}
   {$\displaystyle x + {{a} \abovewithdelims() 3pt {b}}$} {3pt}
   {$\displaystyle x + {{a} \abovewithdelims() 4pt {b}}$} {4pt}
   {$\displaystyle x + {{a} \abovewithdelims() 5pt {b}}$} {5pt}
\stopcombination
\stoplinecorrection

Such a fraction is specified as:

\starttyping
x + { {a} \abovewithdelims () 5pt {b} }
\stoptyping

A new keyword \type {exact} avoids the excessive spacing:

\starttyping
x + { {a} \abovewithdelims () exact 5pt {b} }
\stoptyping

Now we get:

\startlinecorrection
\startcombination[5*1]
   {$\displaystyle x + {{a} \abovewithdelims() exact 1pt {b}}$} {1pt}
   {$\displaystyle x + {{a} \abovewithdelims() exact 2pt {b}}$} {2pt}
   {$\displaystyle x + {{a} \abovewithdelims() exact 3pt {b}}$} {3pt}
   {$\displaystyle x + {{a} \abovewithdelims() exact 4pt {b}}$} {4pt}
   {$\displaystyle x + {{a} \abovewithdelims() exact 5pt {b}}$} {5pt}
\stopcombination
\stoplinecorrection

One way to get consistent spacing in such fractions is to use struts:

\starttyping
x + { {\strut a} \abovewithdelims () exact 5pt {\strut b} }
\stoptyping

Now we get:

\startlinecorrection
\startcombination[5*1]
   {$\displaystyle x + {{\strut a} \abovewithdelims() exact 1pt {\strut b}}$} {1pt}
   {$\displaystyle x + {{\strut a} \abovewithdelims() exact 2pt {\strut b}}$} {2pt}
   {$\displaystyle x + {{\strut a} \abovewithdelims() exact 3pt {\strut b}}$} {3pt}
   {$\displaystyle x + {{\strut a} \abovewithdelims() exact 4pt {\strut b}}$} {4pt}
   {$\displaystyle x + {{\strut a} \abovewithdelims() exact 5pt {\strut b}}$} {5pt}
\stopcombination
\stoplinecorrection

Yet another way to increase the distance between the rule and text a bit is:

\starttyping
\Umathfractionnumvgap  \displaystyle4pt
\Umathfractiondenomvgap\displaystyle4pt
\stoptyping

This looks quite consistent:

\startlinecorrection
\Umathfractionnumvgap  \displaystyle4pt
\Umathfractiondenomvgap\displaystyle4pt
\startcombination[5*1]
   {$\displaystyle x + {{a} \abovewithdelims() exact 1pt {b}}$} {1pt}
   {$\displaystyle x + {{a} \abovewithdelims() exact 2pt {b}}$} {2pt}
   {$\displaystyle x + {{a} \abovewithdelims() exact 3pt {b}}$} {3pt}
   {$\displaystyle x + {{a} \abovewithdelims() exact 4pt {b}}$} {4pt}
   {$\displaystyle x + {{a} \abovewithdelims() exact 5pt {b}}$} {5pt}
\stopcombination
\stoplinecorrection

Here we use code like:

\starttyping
$\displaystyle x + {{a} \abovewithdelims() exact 2pt {b}}$
\stoptyping

Using struts, it is best to zero the gap:

\startlinecorrection
\Umathfractionnumvgap  \displaystyle0pt
\Umathfractiondenomvgap\displaystyle0pt
\startcombination[5*1]
   {$\displaystyle x + {{\strut a} \abovewithdelims() exact 1pt {\strut b}}$} {1pt}
   {$\displaystyle x + {{\strut a} \abovewithdelims() exact 2pt {\strut b}}$} {2pt}
   {$\displaystyle x + {{\strut a} \abovewithdelims() exact 3pt {\strut b}}$} {3pt}
   {$\displaystyle x + {{\strut a} \abovewithdelims() exact 4pt {\strut b}}$} {4pt}
   {$\displaystyle x + {{\strut a} \abovewithdelims() exact 5pt {\strut b}}$} {5pt}
\stopcombination
\stoplinecorrection

Here we use code like:

\starttyping
$\displaystyle x + {{\strut a} \abovewithdelims() exact 2pt {\strut b}}$
\stoptyping

\stopsection

\startsection[title=Skewed fractions]

The math parameter table contains values specifying horizontal and
vertical gaps for skewed fractions. Some guessing is needed in order to implement
something that uses them, so we now provide a primitive similar to the other
fraction related ones but with a few options that one can use to influence the
rendering. Of course, a user can mess around directly with the parameters \type
{\Umathskewedfractionhgap} and \type {\Umathskewedfractionvgap}.

The syntax used here is:

\starttyping
{ {1} \Uskewed / <options> {2} }
{ {1} \Uskewedwithdelims / () <options> {2} }
\stoptyping

The options can be \type {noaxis} and \type {exact}, a combination of them or
just nothing. By default we add half the axis to the shifts and also by default
we zero the width of the middle character. For Latin Modern, the result looks as
follows:

\def\ShowA#1#2#3{$x + { {#1} \Uskewed           /    #3 {#2} } + x$}
\def\ShowB#1#2#3{$x + { {#1} \Uskewedwithdelims / () #3 {#2} } + x$}

\start
    \switchtobodyfont[modern]
    \starttabulate[||||||]
        \NC \NC
            \ShowA{a}{b}{} \NC
            \ShowA{1}{2}{} \NC
            \ShowB{a}{b}{} \NC
            \ShowB{1}{2}{} \NC
        \NR
        \NC \type{exact} \NC
            \ShowA{a}{b}{exact} \NC
            \ShowA{1}{2}{exact} \NC
            \ShowB{a}{b}{exact} \NC
            \ShowB{1}{2}{exact} \NC
        \NR
        \NC \type{noaxis} \NC
            \ShowA{a}{b}{noaxis} \NC
            \ShowA{1}{2}{noaxis} \NC
            \ShowB{a}{b}{noaxis} \NC
            \ShowB{1}{2}{noaxis} \NC
        \NR
        \NC \type{exact noaxis} \NC
            \ShowA{a}{b}{exact noaxis} \NC
            \ShowA{1}{2}{exact noaxis} \NC
            \ShowB{a}{b}{exact noaxis} \NC
            \ShowB{1}{2}{exact noaxis} \NC
        \NR
    \stoptabulate
\stop

\stopsection

\startsection[title=Side effects]

Not all bugs reported as such are really bugs. Here is one that came from a
misunderstanding: In Eijkhout's \quotation {\TEX\ by Topic}, the rules for
handling styles in scripts are described as follows:

\startitemize
\startitem
    In any style superscripts and subscripts are taken from the next smaller
    style. Exception: in display style they are taken in script style.
\stopitem
\startitem
    Subscripts are always in the cramped variant of the style; superscripts are
    only cramped if the original style was cramped.
\stopitem
\startitem
    In an \type {..\over..} formula in any style the numerator and denominator
    are taken from the next smaller style.
\stopitem
\startitem
    The denominator is always in cramped style; the numerator is only in cramped
    style if the original style was cramped.
\stopitem
\startitem
    Formulas under a \type {\sqrt} or \type {\overline} are in cramped style.
\stopitem
\stopitemize

In \LUATEX, one can set the styles in more detail, which means that you sometimes
have to set both normal and cramped styles to get the effect you want. If we
force styles in the script using \type {\scriptstyle} and \type
{\crampedscriptstyle} we get the following (all render the same):

\startbuffer[demo]
\starttabulate
\NC default       \NC $b_{x=xx}^{x=xx}$ \NC \NR
\NC script        \NC $b_{\scriptstyle x=xx}^{\scriptstyle x=xx}$ \NC \NR
\NC crampedscript \NC $b_{\crampedscriptstyle x=xx}^{\crampedscriptstyle x=xx}$ \NC \NR
\stoptabulate
\stopbuffer

\getbuffer[demo]

This is coded like:

\starttyping
$b_{x=xx}^{x=xx}$
$b_{\scriptstyle x=xx}^{\scriptstyle x=xx}$
$b_{\crampedscriptstyle x=xx}^{\crampedscriptstyle x=xx}$
\stoptyping

Now we set the following parameters:

\startbuffer[setup]
\Umathordrelspacing\scriptstyle=30mu
\Umathordordspacing\scriptstyle=30mu
\stopbuffer

\typebuffer[setup]

This gives:

\start\getbuffer[setup,demo]\stop

Since the result is not what is expected (visually), we should say:

\startbuffer[setup]
\Umathordrelspacing\scriptstyle=30mu
\Umathordordspacing\scriptstyle=30mu
\Umathordrelspacing\crampedscriptstyle=30mu
\Umathordordspacing\crampedscriptstyle=30mu
\stopbuffer

\typebuffer[setup]

Now we get:

\start\getbuffer[setup,demo]\stop

\stopsection

\startsection[title=Fixed scripts]

We have three parameters that are used for anchoring superscripts and subscripts,
alone or in combinations.

\starttabulate[|l|l|]
\NC $d$ \NC \type {\Umathsubshiftdown}    \NC \NR
\NC $u$ \NC \type {\Umathsupshiftup}      \NC \NR
\NC $s$ \NC \type {\Umathsubsupshiftdown} \NC \NR
\stoptabulate

When we set \type {\mathscriptsmode} to a value other than zero, these are used
for calculating fixed positions. This is something that is needed in, for
instance, chemical equations. You can manipulate the mentioned variables to
achieve different effects, and the specifications are shown in the following table. In
order to see the differences in more detail, they are enlarged in \in {figure}
[fig:mathscriptsmode].

\def\SampleMath#1%
  {\ruledhbox{$\mathscriptsmode#1\mathupright CH_2 + CH^+_2 + CH^2_2$}}

\starttabulate[|c|c|c|l|]
    \NC \bf mode \NC \bf down      \NC \bf up        \NC                \NC \NR
    \NC 0        \NC dynamic       \NC dynamic       \NC \SampleMath{0} \NC \NR
    \NC 1        \NC $d$           \NC $u$           \NC \SampleMath{1} \NC \NR
    \NC 2        \NC $s$           \NC $u$           \NC \SampleMath{2} \NC \NR
    \NC 3        \NC $s$           \NC $u + s - d$   \NC \SampleMath{3} \NC \NR
    \NC 4        \NC $d + (s-d)/2$ \NC $u + (s-d)/2$ \NC \SampleMath{4} \NC \NR
    \NC 5        \NC $d$           \NC $u + s - d$   \NC \SampleMath{5} \NC \NR
\stoptabulate

\placefigure
  [here]
  [fig:mathscriptsmode]
  {The effect of setting \type {\mathscriptsmode}.}
  {\startcombination[nx=3,ny=2,distance=1em]
     {\scale[width=\dimexpr(\textwidth-2em)/3\relax]{\SampleMath{0}}} {0}
     {\scale[width=\dimexpr(\textwidth-2em)/3\relax]{\SampleMath{1}}} {1}
     {\scale[width=\dimexpr(\textwidth-2em)/3\relax]{\SampleMath{2}}} {2}
     {\scale[width=\dimexpr(\textwidth-2em)/3\relax]{\SampleMath{3}}} {3}
     {\scale[width=\dimexpr(\textwidth-2em)/3\relax]{\SampleMath{4}}} {4}
     {\scale[width=\dimexpr(\textwidth-2em)/3\relax]{\SampleMath{5}}} {5}
   \stopcombination}

\stopsection

\startsection[title=Remark]

The changes that we have made are hopefully not too intrusive. Instead of
extending existing commands, new ones were introduced so that compatibility
should not be a significant problem. To some extent, these extensions violate the
principle that extensions should be done in \LUA, but \TEX\ being a math renderer
and \OPENTYPE\ replacing old font technology, we felt that we should make an
exception here. Hopefully, not too many bugs were introduced.

\stopsection

\stopchapter

\stoptext