summaryrefslogtreecommitdiff
path: root/systems/tex-extensions/clasen/math/math.ch
blob: 2fbe62230e744b8445b7604a7db18d2b6f696d19 (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
@x
@d normal=0 {the most common case when several cases are named}
@y
@d normal=0 {the most common case when several cases are named}
@d under_accent=2 {|subtype| of under math accents}
@d nesting=1 {add this to an accent |subtype| to make it nesting}
@z

@x
primitive("mathaccent",math_accent,0);@/
@!@:math_accent_}{\.{\\mathaccent} primitive@>
@y
primitive("mathaccent",math_accent,normal);@/
@!@:math_accent_}{\.{\\mathaccent} primitive@>
primitive("nestingmathaccent",math_accent,normal+nesting);@/
@!@:nesting_math_accent_}{\.{\\nestingmathaccent} primitive@>
primitive("mathunderaccent",math_accent,under_accent);@/
@!@:math_under_accent_}{\.{\\mathunderaccent} primitive@>
primitive("nestingmathunderaccent",math_accent,under_accent+nesting);@/
@!@:nesting_math_under_accent_}{\.{\\nestingmathunderaccent} primitive@>
@z

@x
primitive("radical",radical,0);@/
@!@:radical_}{\.{\\radical} primitive@>
@y
primitive("radical",radical,0);@/
@!@:radical_}{\.{\\radical} primitive@>
primitive("genradical",radical,1);@/
@!@:genradical_}{\.{\\genradical} primitive@>
@z

@x
math_accent: print_esc("mathaccent");
@y
math_accent: case chr_code of
  normal:              print_esc("mathaccent");
  normal+nesting:      print_esc("nestingmathaccent");
  under_accent:        print_esc("mathunderaccent");
  under_accent+nesting:print_esc("nestingmathunderaccent");
  othercases           print("Unknown accent!")
endcases;
@z

@x
radical: print_esc("radical");
@y
radical: if chr_code=0 then print_esc("radical") else print_esc("genradical");
@z

@x
@d input_line_no_code=glue_val+1 {code for \.{\\inputlineno}}
@d badness_code=glue_val+2 {code for \.{\\badness}}
@y
@d input_line_no_code=glue_val+1 {code for \.{\\inputlineno}}
@d badness_code=glue_val+2 {code for \.{\\badness}}
@d math_style_code=glue_val+3 {code for \.{\\mathstyle}}
@z

@x
primitive("badness",last_item,badness_code);
@!@:badness_}{\.{\\badness} primitive@>
@y
primitive("badness",last_item,badness_code);
@!@:badness_}{\.{\\badness} primitive@>
primitive("mathstyle",last_item,math_style_code);
@!@:mathstyle_}{\.{\\mathstyle} primitive@>
@z

@x
  input_line_no_code: print_esc("inputlineno");
  othercases print_esc("badness")
@y
  input_line_no_code: print_esc("inputlineno");
  badness_code: print_esc("badness");
  math_style_code: print_esc("mathstyle");
  othercases confusion("last_item")
@:this can't happen last_item}{\quad last_item@>
@z

@x
if cur_chr>glue_val then
  begin if cur_chr=input_line_no_code then cur_val:=line
  else cur_val:=last_badness; {|cur_chr=badness_code|}
  cur_val_level:=int_val;
  end
@y
if cur_chr>glue_val then
  begin if cur_chr=input_line_no_code then cur_val:=line
  else if cur_chr=math_style_code then begin
    if abs(mode)=mmode then cur_val:=mathstyle
    else cur_val:=-1;
  end else cur_val:=last_badness;
  cur_val_level:=int_val;
  end
@z

@x
@d radical_noad_size=5 {number of |mem| words in a radical noad}
@y
@d radical_noad_size=6 {number of |mem| words in a radical noad}
@d is_null_delimiter(#) ==
  ((mem[#].qqqq.b0=0) and (mem[#].qqqq.b1=min_quarterword) and
   (mem[#].qqqq.b2=0) and (mem[#].qqqq.b3=min_quarterword))
@z

@x
begin case c div 2 of
0: print_esc("displaystyle"); {|display_style=0|}
1: print_esc("textstyle"); {|text_style=2|}
2: print_esc("scriptstyle"); {|script_style=4|}
3: print_esc("scriptscriptstyle"); {|script_script_style=6|}
othercases print("Unknown style!")
@y
begin case c of
display_style:               print_esc("displaystyle");
display_style+cramped:       print_esc("crampeddisplaystyle");
text_style:                  print_esc("textstyle");
text_style+cramped:          print_esc("crampedtextstyle");
script_style:                print_esc("scriptstyle");
script_style+cramped:        print_esc("crampedscriptstyle");
script_script_style:         print_esc("scriptscriptstyle");
script_script_style+cramped: print_esc("crampedscriptscriptstyle");
othercases                   print("Unknown style!")
@z

@x
radical_noad: begin print_esc("radical"); print_delimiter(left_delimiter(p));
  end;
@y
radical_noad: if subtype(p)=normal then begin
    print_esc("radical"); print_delimiter(left_delimiter(p));
  end else begin
    print_esc("genradical"); print_delimiter(left_delimiter(p));
    print_delimiter(right_delimiter(p));
  end;
@z

@x
@!cur_style:small_number; {style code at current place in the list}
@y
@!cur_style,mathstyle:small_number; {style code at current place in the list}
@z

@x
accent_noad: make_math_accent(q);
@y
accent_noad: if subtype(q)<under_accent then make_math_accent(q)
             else make_math_under_accent(q);
@z

@x
procedure make_radical(@!q:pointer);
var x,@!y:pointer; {temporary registers for box construction}
@!delta,@!clr:scaled; {dimensions involved in the calculation}
begin x:=clean_box(nucleus(q),cramped_style(cur_style));
if cur_style<text_style then {display style}
  clr:=default_rule_thickness+(abs(math_x_height(cur_size)) div 4)
else  begin clr:=default_rule_thickness; clr:=clr + (abs(clr) div 4);
  end;
y:=var_delimiter(left_delimiter(q),cur_size,height(x)+depth(x)+clr+
  default_rule_thickness);
delta:=depth(y)-(height(x)+depth(x)+clr);
if delta>0 then clr:=clr+half(delta); {increase the actual clearance}
shift_amount(y):=-(height(x)+clr);
link(y):=overbar(x,clr,height(y));
info(nucleus(q)):=hpack(y,natural); math_type(nucleus(q)):=sub_box;
end;
@y
procedure make_radical(@!q:pointer);
var x,@!y,z:pointer; {temporary registers for box construction}
@!delta,@!clr,ht:scaled; {dimensions involved in the calculation}
begin x:=clean_box(nucleus(q),cramped_style(cur_style));
if cur_style<text_style then {display style}
  clr:=default_rule_thickness+(abs(math_x_height(cur_size)) div 4)
else  begin clr:=default_rule_thickness; clr:=clr + (abs(clr) div 4);
  end;
y:=var_delimiter(left_delimiter(q),cur_size,height(x)+depth(x)+clr+
  default_rule_thickness);
delta:=depth(y)-(height(x)+depth(x)+clr);
if delta>0 then clr:=clr+half(delta); {increase the actual clearance}
shift_amount(y):=-(height(x)+clr);
ht:=height(y);
if subtype(q)=normal then link(y):=overbar(x,clr,ht)
else begin
  z:=var_delimiter(right_delimiter(q),cur_size,height(x)+depth(x)+clr+
    default_rule_thickness);
  shift_amount(z):=-(height(x)+clr);
  if height(z)>ht then ht:=height(z);
  link(y):=overbar(x,clr,ht);
  link(link(y)):=z;
end;
info(nucleus(q)):=hpack(y,natural); math_type(nucleus(q)):=sub_box;
end;
@z

@x
procedure make_math_accent(@!q:pointer);
label done,done1;
var p,@!x,@!y:pointer; {temporary registers for box construction}
@y
procedure horizontally_stack_into_box(@!b:pointer;@!f:internal_font_number;@!c:quarterword);
var p:pointer; {new node placed into |b|}
begin
 p:=char_box(f,c); link(p):=list_ptr(b); list_ptr(b):=p;
 width(b):=width(b)+width(p);
end;

procedure make_math_under_accent(@!q:pointer);
label done,done1,done2,done3;
var p,qq,@!x,@!y:pointer; {temporary registers for box construction}
@!a:integer; {address of lig/kern instruction}
@!c:quarterword; {accent character}
@!f:internal_font_number; {its font}
@!i,ii:four_quarters; {its |char_info|}
@!s:scaled; {amount to skew the accent to the right}
@!h:scaled; {height of character being accented}
@!delta,sep:scaled; {space to insert between accentee and accent}
@!w,v,u:scaled; {width of the accentee, not including sub/superscripts}
@!t:four_quarters;
@!m,n:integer;
@!hd:eight_bits;
begin fetch(accent_chr(q));
if char_exists(cur_i) then
  begin i:=cur_i; c:=cur_c; f:=cur_f;@/
  @<Compute under accent skew@>;
  @<Compute separation for under accent@>;
   x:=clean_box(nucleus(q),cur_style); w:=width(x); h:=height(x);
  @<Switch to a larger accent if available and appropriate@>;
  if (math_type(supscr(q))<>empty)or(math_type(subscr(q))<>empty) then
    if math_type(nucleus(q))=math_char then
      @<Swap the subscript and superscript into box |x|@>;
  shift_amount(y):=half(w-width(y))-s; width(y):=0;
  p:=new_kern(sep); link(x):=p; link(p):=y;
  p:=new_kern(-sep-x_height(f)); link(y):=p;
  y:=vpack(x,natural); width(y):=w;
  depth(y):=depth(y)+height(y)-h; height(y):=h;
  info(nucleus(q)):=y; math_type(nucleus(q)):=sub_box;
  end;
end;

procedure make_math_accent(@!q:pointer);
label done,done1,done2;
var p,qq,@!x,@!y:pointer; {temporary registers for box construction}
@z

@x
@!w:scaled; {width of the accentee, not including sub/superscripts}
@y
@!w,v,u:scaled; {width of the accentee, not including sub/superscripts}
@!t:four_quarters;
@!m,n:integer;
@!hd:eight_bits;
@z

@x
  y:=char_box(f,c);
@y
@z

@x
@ @<Switch to a larger accent if available and appropriate@>=
loop@+  begin if char_tag(i)<>list_tag then goto done;
  y:=rem_byte(i);
  i:=char_info(f)(y);
  if not char_exists(i) then goto done;
  if char_width(f)(i)>w then goto done;
  c:=y;
  end;
done:
@y
@ @<Switch to a larger accent if available and appropriate@>=
loop@+  begin
  if char_tag(i)=ext_tag then begin
    y:=new_null_box;
    type(y):=hlist_node;
    i:=font_info[exten_base[f]+rem_byte(i)].qqqq;@/
    c:=ext_rep(i); t:=char_info(f)(c); u:=char_width(f)(t); v:=0;
    hd:=height_depth(t); height(y):=char_height(f)(hd); depth(y):=char_depth(f)(hd);
    c:=ext_bot(i); t:=char_info(f)(c); @+if c<>min_quarterword then v:=v+char_width(f)(t);
    c:=ext_mid(i); t:=char_info(f)(c); @+if c<>min_quarterword then v:=v+char_width(f)(t);
    c:=ext_top(i); t:=char_info(f)(c); @+if c<>min_quarterword then v:=v+char_width(f)(t);
    n:=0;
    if u>0 then while v<w do begin
      v:=v+u; incr(n);
      if ext_mid(i)<>min_quarterword then v:=v+u;
    end;
    c:=ext_bot(i);
    if c<>min_quarterword then horizontally_stack_into_box(y,f,c);
    c:=ext_rep(i);
    for m:=1 to n do horizontally_stack_into_box(y,f,c);
    c:=ext_mid(i);
    if c<>min_quarterword then begin
      horizontally_stack_into_box(y,f,c);
      c:=ext_rep(i);
      for m:=1 to n do horizontally_stack_into_box(y,f,c);
    end;
    c:=ext_top(i);
    if c<>min_quarterword then horizontally_stack_into_box(y,f,c);
    goto done2;
  end;
  if char_tag(i)<>list_tag then goto done;
  y:=rem_byte(i);
  i:=char_info(f)(y);
  if not char_exists(i) then goto done;
  if char_width(f)(i)>w then goto done;
  c:=y;
end;
done:
  y:=char_box(f,c);
done2:
@z

@x
@ @<Compute the amount of skew@>=
s:=0;
if math_type(nucleus(q))=math_char then
  begin fetch(nucleus(q));
@y
@ @<Compute under accent skew@>=
s:=0;
qq:=q;
if odd(subtype(q)) then
  while (math_type(nucleus(qq))=sub_mlist)and
        (type(info(nucleus(qq)))=accent_noad)and
        ((subtype(qq)=subtype(q))or(subtype(qq) div 2<>subtype(q) div 2)) do
    qq:=info(nucleus(qq));
if math_type(nucleus(qq))=math_char then
  begin fetch(nucleus(qq));
  ii:=char_info(cur_f)(skew_char[cur_f]);
  if char_tag(ii)=lig_tag then
    begin a:=lig_kern_start(cur_f)(ii);
    ii:=font_info[a].qqqq;
    if skip_byte(ii)>stop_flag then
      begin a:=lig_kern_restart(cur_f)(ii);
      ii:=font_info[a].qqqq;
      end;
    loop@+ begin if qo(next_char(ii))=cur_c then
        begin if op_byte(ii)>=kern_flag then
          if skip_byte(ii)<=stop_flag then s:=char_kern(cur_f)(ii);
        goto done1;
        end;
      if skip_byte(ii)>=stop_flag then goto done1;
      a:=a+qo(skip_byte(ii))+1;
      ii:=font_info[a].qqqq;
      end;
    end;
  end;
done1:

@ @<Compute separation for under accent@>=
  sep:=0;
  ii:=i;
  if char_tag(ii)=lig_tag then
    begin a:=lig_kern_start(f)(ii);
    ii:=font_info[a].qqqq;
    if skip_byte(ii)>stop_flag then
      begin a:=lig_kern_restart(f)(ii);
      ii:=font_info[a].qqqq;
      end;
    loop@+ begin if qo(next_char(ii))=c then
        begin if op_byte(ii)>=kern_flag then
          if skip_byte(ii)<=stop_flag then sep:=char_kern(f)(ii);
        goto done3;
        end;
      if skip_byte(ii)>=stop_flag then goto done3;
      a:=a+qo(skip_byte(ii))+1;
      ii:=font_info[a].qqqq;
      end;
    end;
done3:

@ @<Compute the amount of skew@>=
s:=0;
qq:=q;
{while odd(subtype(qq))and(math_type(nucleus(qq))=sub_mlist)and
   (type(info(nucleus(qq)))=accent_noad) do}
if odd(subtype(q)) then
  while (math_type(nucleus(qq))=sub_mlist)and
        (type(info(nucleus(qq)))=accent_noad)and
        ((subtype(qq)=subtype(q))or(subtype(qq) div 2<>subtype(q) div 2)) do
  qq:=info(nucleus(qq));
if math_type(nucleus(qq))=math_char then
  begin fetch(nucleus(qq));
@z

@x
begin push_math(math_shift_group); eq_word_define(int_base+cur_fam_code,-1);
if every_math<>null then begin_token_list(every_math,every_math_text);
@y
begin mathstyle:=text_style;
push_math(math_shift_group); eq_word_define(int_base+cur_fam_code,-1);
if every_math<>null then begin_token_list(every_math,every_math_text);
@z

@x
push_math(math_shift_group); mode:=mmode;
eq_word_define(int_base+cur_fam_code,-1);@/
@y
mathstyle:=display_style;
push_math(math_shift_group); mode:=mmode;
eq_word_define(int_base+cur_fam_code,-1);@/
@z

@x
mmode+left_brace: begin tail_append(new_noad);
  back_input; scan_math(nucleus(tail));
@y
mmode+left_brace: begin tail_append(new_noad);
  back_input; scan_math(nucleus(tail),mathstyle);
@z

@x
procedure scan_math(@!p:pointer);
label restart,reswitch,exit;
var c:integer; {math character code}
begin restart:@<Get the next non-blank non-relax...@>;
reswitch:case cur_cmd of
letter,other_char,char_given: begin c:=ho(math_code(cur_chr));
    if c=@'100000 then
      begin @<Treat |cur_chr| as an active character@>;
      goto restart;
      end;
    end;
char_num: begin scan_char_num; cur_chr:=cur_val; cur_cmd:=char_given;
  goto reswitch;
  end;
math_char_num: begin scan_fifteen_bit_int; c:=cur_val;
  end;
math_given: c:=cur_chr;
delim_num: begin scan_twenty_seven_bit_int; c:=cur_val div @'10000;
  end;
othercases @<Scan a subformula enclosed in braces and |return|@>
endcases;@/
math_type(p):=math_char; character(p):=qi(c mod 256);
if (c>=var_code)and fam_in_range then fam(p):=cur_fam
else fam(p):=(c div 256) mod 16;
exit:end;
@y
procedure scan_math(@!p:pointer;s:small_number);
label restart,reswitch,exit;
var c:integer; {math character code}
  savedstyle:small_number;
begin
savedstyle:=mathstyle; mathstyle:=s;
restart:@<Get the next non-blank non-relax...@>;
reswitch:case cur_cmd of
letter,other_char,char_given: begin c:=ho(math_code(cur_chr));
    if c=@'100000 then
      begin @<Treat |cur_chr| as an active character@>;
      goto restart;
      end;
    end;
char_num: begin scan_char_num; cur_chr:=cur_val; cur_cmd:=char_given;
  goto reswitch;
  end;
math_char_num: begin scan_fifteen_bit_int; c:=cur_val;
  end;
math_given: c:=cur_chr;
delim_num: begin scan_twenty_seven_bit_int; c:=cur_val div @'10000;
  end;
othercases @<Scan a subformula enclosed in braces and |return|@>
endcases;@/
math_type(p):=math_char; character(p):=qi(c mod 256);
if (c>=var_code)and fam_in_range then fam(p):=cur_fam
else fam(p):=(c div 256) mod 16;
mathstyle:=savedstyle;
exit:
end;
@z

@x
begin back_input; scan_left_brace;@/
saved(0):=p; incr(save_ptr); push_math(math_group); return;
@y
begin back_input; scan_left_brace;@/
saved(0):=p; incr(save_ptr); saved(0):=savedstyle; incr(save_ptr);
push_math(math_group); return;
@z

@x
mmode+math_comp: begin tail_append(new_noad);
  type(tail):=cur_chr; scan_math(nucleus(tail));
@y
mmode+math_comp: begin tail_append(new_noad);
  type(tail):=cur_chr;
  case type(tail) of
  over_noad: scan_math(nucleus(tail),cramped_style(mathstyle));
  othercases scan_math(nucleus(tail),mathstyle);
  endcases;
@z

@x
type(tail):=radical_noad; subtype(tail):=normal;
@y
type(tail):=radical_noad; subtype(tail):=cur_chr;
@z

@x
{before |scan_math| in |math_radical|}
scan_math(nucleus(tail));
@y
if subtype(tail)=normal then mem[right_delimiter(tail)].qqqq:=null_delimiter
else scan_delimiter(right_delimiter(tail),true);
{before |scan_math| in |math_radical|}
scan_math(nucleus(tail),cramped_style(mathstyle));
@z

@x
procedure math_ac;
begin if cur_cmd=accent then
  @<Complain that the user should have said \.{\\mathaccent}@>;
tail_append(get_node(accent_noad_size));
type(tail):=accent_noad; subtype(tail):=normal;
@y
procedure math_ac;
begin if cur_cmd=accent then
  @<Complain that the user should have said \.{\\mathaccent}@>;
tail_append(get_node(accent_noad_size));
type(tail):=accent_noad; subtype(tail):=cur_chr;
@z

@x
if (cur_val>=var_code)and fam_in_range then fam(accent_chr(tail)):=cur_fam
else fam(accent_chr(tail)):=(cur_val div 256) mod 16;
scan_math(nucleus(tail));
end;
@y
if (cur_val>=var_code)and fam_in_range then fam(accent_chr(tail)):=cur_fam
else fam(accent_chr(tail)):=(cur_val div 256) mod 16;
scan_math(nucleus(tail),cramped_style(mathstyle));
end;
@z

@x
primitive("displaystyle",math_style,display_style);
@!@:display_style_}{\.{\\displaystyle} primitive@>
primitive("textstyle",math_style,text_style);
@!@:text_style_}{\.{\\textstyle} primitive@>
primitive("scriptstyle",math_style,script_style);
@!@:script_style_}{\.{\\scriptstyle} primitive@>
primitive("scriptscriptstyle",math_style,script_script_style);
@!@:script_script_style_}{\.{\\scriptscriptstyle} primitive@>
@y
primitive("displaystyle",math_style,display_style);
@!@:display_style_}{\.{\\displaystyle} primitive@>
primitive("crampeddisplaystyle",math_style,display_style+cramped);
@!@:cramped_display_style_}{\.{\\crampeddisplaystyle} primitive@>
primitive("textstyle",math_style,text_style);
@!@:text_style_}{\.{\\textstyle} primitive@>
primitive("crampedtextstyle",math_style,text_style+cramped);
@!@:cramped_text_style_}{\.{\\crampedtextstyle} primitive@>
primitive("scriptstyle",math_style,script_style);
@!@:script_style_}{\.{\\scriptstyle} primitive@>
primitive("crampedscriptstyle",math_style,script_style+cramped);
@!@:cramped_script_style_}{\.{\\crampedscriptstyle} primitive@>
primitive("scriptscriptstyle",math_style,script_script_style);
@!@:script_script_style_}{\.{\\scriptscriptstyle} primitive@>
primitive("crampedscriptscriptstyle",math_style,script_script_style+cramped);
@!@:cramped_script_script_style_}{\.{\\crampedscriptscriptstyle} primitive@>
@z

@x
mmode+math_style: tail_append(new_style(cur_chr));
@y
mmode+math_style: begin tail_append(new_style(cur_chr));
  mathstyle:=cur_chr;
end;
@z

@x
procedure append_choices;
begin tail_append(new_choice); incr(save_ptr); saved(-1):=0;
push_math(math_choice_group); scan_left_brace;
@y
procedure append_choices;
begin tail_append(new_choice);
incr(save_ptr); saved(-1):=mathstyle;
incr(save_ptr); saved(-1):=0;
push_math(math_choice_group); scan_left_brace;
mathstyle:=display_style;
@z

@x
3:begin script_script_mlist(tail):=p; decr(save_ptr); return;
  end;
end; {there are no other cases}
incr(saved(-1)); push_math(math_choice_group); scan_left_brace;
@y
3:begin script_script_mlist(tail):=p; decr(save_ptr);
    mathstyle:=saved(-1); decr(save_ptr);
    return;
  end;
end; {there are no other cases}
incr(saved(-1)); push_math(math_choice_group); scan_left_brace;
mathstyle:=2*saved(-1);
@z

@x
procedure sub_sup;
var t:small_number; {type of previous sub/superscript}
@!p:pointer; {field to be filled by |scan_math|}
begin t:=empty; p:=null;
if tail<>head then if scripts_allowed(tail) then
  begin p:=supscr(tail)+cur_cmd-sup_mark; {|supscr| or |subscr|}
  t:=math_type(p);
  end;
if (p=null)or(t<>empty) then @<Insert a dummy noad to be sub/superscripted@>;
scan_math(p);
end;
@y
procedure sub_sup;
var t:small_number; {type of previous sub/superscript}
@!p:pointer; {field to be filled by |scan_math|}
begin t:=empty; p:=null;
if tail<>head then if scripts_allowed(tail) then
  begin p:=supscr(tail)+cur_cmd-sup_mark; {|supscr| or |subscr|}
  t:=math_type(p);
  end;
if (p=null)or(t<>empty) then @<Insert a dummy noad to be sub/superscripted@>;
if cur_cmd=sup_mark then scan_math(p,sup_style(mathstyle))
else scan_math(p,sub_style(mathstyle));
end;
@z

@x
@d delimited_code=3 { `\.{\\abovewithdelims}', etc.}
@y
@d delimited_code=3 { `\.{\\abovewithdelims}', etc.}
@d fraction_code=6 { `\.{\\fraction}', etc.}
@z

@x
primitive("atopwithdelims",above,delimited_code+atop_code);
@!@:atop_with_delims_}{\.{\\atopwithdelims} primitive@>
@y
primitive("atopwithdelims",above,delimited_code+atop_code);
@!@:atop_with_delims_}{\.{\\atopwithdelims} primitive@>
primitive("fraction",above,fraction_code);
@!@:fraction_}{\.{\\fraction} primitive@>
@z

@x
  delimited_code+atop_code:print_esc("atopwithdelims");
  othercases print_esc("above")
@y
  delimited_code+atop_code:print_esc("atopwithdelims");
  fraction_code:print_esc("fraction");
  othercases print_esc("above")
@z

@x
mmode+above: math_fraction;
@y
mmode+above: if cur_chr=fraction_code then begin
  scan_left_brace; tail_append(new_noad);
  back_input;
  scan_math(nucleus(tail),num_style(mathstyle));
end else begin
  math_fraction;
end;
@z

@x
procedure math_fraction;
var c:small_number; {the type of generalized fraction we are scanning}
begin c:=cur_chr;
@y
procedure math_fraction;
var c:small_number; {the type of generalized fraction we are scanning}
begin c:=cur_chr;
mathstyle:=denom_style(save_stack[cur_boundary-1].int);
@z

@x
math_group: begin unsave; decr(save_ptr);@/
  math_type(saved(0)):=sub_mlist; p:=fin_mlist(null); info(saved(0)):=p;
@y
math_group: begin unsave; decr(save_ptr);@/
  mathstyle:=saved(0); decr(save_ptr);
  math_type(saved(0)):=sub_mlist; p:=fin_mlist(null); info(saved(0)):=p;
@z