summaryrefslogtreecommitdiff
path: root/systems/tex-extensions/clasen/math/fraction.ch
blob: ab27046166400d21886b0ebe93fd2db4c3b11f95 (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
% idea: keep track of math style in integer parameter
% \mathstyle *while scanning the formula*. To be able 
% to do this, we need to keep track of
%
% \overline
% ^
% _
% \mathaccent
% style atoms
% \fraction{...\over...}
%
% Change necessary: \mathstyle is *not* an ordinary
% integer parameter, since math style doesn't obey
% grouping. Try ${\scriptscriptstyle 1}2$.
% Therefore it should be a special readonly parameter and
% a \cramp primitive should be separately added.

@x l.8392
@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 l.8420
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 l.8435
  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

%
% \mathstyle returns -1 if used outside math mode. 
%

@x l.8504
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 l.14108
@!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 l.21649
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 l.21700
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 l.21798
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

%
% we change scan_math to expect one additional parameter, 
% the mathstyle for the next math atom. There are two
% cases here:
% - simple atom: use local var stack to hold old style
%                and restore it from there
% - subformula:  use save stack to hold old style and
%                restore it when reading `}' 
%

@x l.21810
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 l.21848
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 l.21944
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 l.21999
%scan_delimiter(left_delimiter(tail),true); 
%if t=1 then scan_delimiter(right_delimiter(tail),true)
%else mem[right_delimiter(tail)].qqqq:=null_delimiter;
%scan_math(nucleus(tail));
%end;
%@y
%scan_delimiter(left_delimiter(tail),true); 
%if t=1 then scan_delimiter(right_delimiter(tail),true)
%else mem[right_delimiter(tail)].qqqq:=null_delimiter;
%scan_math(nucleus(tail),cramped_style(mathstyle));
%end;
%@z

@x
{before |scan_math| in |math_radical|}
scan_math(nucleus(tail)); 
@y
{before |scan_math| in |math_radical|}
scan_math(nucleus(tail),cramped_style(mathstyle));
@z

@x l.22012
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 l.22066
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 l.22076
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 l.22094
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 l.22109
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 l.22149
@d delimited_code=3 { `\.{\\abovewithdelims}', etc.}
@y
@d delimited_code=3 { `\.{\\abovewithdelims}', etc.}
@d fraction_code=6 { `\.{\\fraction}', etc.}
@z

@x l.22162
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 l.22171
  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

% We handle \fraction{...\over...} here, by scanning away
% the left brace and then doing the same as for 
% mmode+left_brace
% The point is that we have a handle to update the
% math_style variable properly here.
% We do scan_left_brace followed by back_input to
% force the left brace to be there

@x l.22176
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 l.22258
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