6 #pragma warning(disable:4115) // kill rpcasync.h complaint
8 #define MYLIBAPI __declspec(dllexport)
13 #pragma warning(disable:4131) // old style declarator
14 #pragma warning(disable:4135) // conversion between different integral types
15 #pragma warning(disable:4127) // conditional expression is constant
23 #pragma warning(disable:4244) /* 96/Jan/10 */
25 /* rebox_ used to be in tex4.c */
27 halfword rebox_(halfword b, scaled w)
30 internal_font_number f;
33 if ((width(b) != w) && (list_ptr(b) != 0))
35 if (type(b) == vlist_node)
40 if (((p >= hi_mem_min)) && (link(p) == 0))
43 v = char_width(f, char_info(f, character(p)));
46 link(p) = new_kern(width(b) - v);
49 free_node(b, box_node_size);
50 b = new_glue(ss_glue);
56 link(p) = new_glue(ss_glue);
57 return hpack(b, w, exactly);
65 /* This is to be the start of tex5.c */
67 halfword math_glue_(halfword g, scaled m)
73 n = x_over_n(m, 65536L);
82 p = get_node(glue_spec_size);
83 width(p) = mult_and_add(n, width(g), xn_over_d(width(g), f, 65536L), 1073741823L); /* 2^30 - 1 */
84 stretch_order(p) = stretch_order(g);
86 if (stretch_order(p) == normal)
87 stretch(p) = mult_and_add(n, stretch(g), xn_over_d(stretch(g), f, 65536L), 1073741823L); /* 2^30 - 1 */
89 stretch(p) = stretch(g);
91 shrink_order(p) = shrink_order(g);
93 if (shrink_order(p) == normal)
94 shrink(p) = mult_and_add(n, shrink(g), xn_over_d(shrink(g), f, 65536L), 1073741823L); /* 2^30 - 1 */
96 shrink(p) = shrink(g);
101 void math_kern_ (halfword p, scaled m)
106 if (subtype(p) == mu_glue)
108 n = x_over_n(m, 65536L);
117 width(p) = mult_and_add(n, width(p), xn_over_d(width(p), f, 65536L), 1073741823L); /* 2^30 - 1 */
118 subtype(p) = explicit;
122 void flush_math (void)
124 flush_node_list(link(head));
125 flush_node_list(incompleat_noad);
131 halfword clean_box_(halfword p, small_number s)
134 small_number save_style;
142 cur_mlist = new_noad();
143 mem[nucleus(cur_mlist)] = mem[p];
166 save_style = cur_style;
168 mlist_penalties = false;
171 cur_style = save_style;
174 if (cur_style < script_style)
175 cur_size = text_size;
177 cur_size = 16 * ((cur_style - text_style) / 2);
179 cur_mu = x_over_n(math_quad(cur_size), 18);
182 if ((q >= hi_mem_min) || (q == 0))
184 else if ((link(q) == 0) && (type(q) <= vlist_node) && (shift_amount(q) == 0))
191 if ((q >= hi_mem_min))
197 if (!(r >= hi_mem_min))
198 if (type(r) == kern_node)
200 free_node(r, small_node_size);
208 void fetch_(halfword a)
210 cur_c = mem[a].hh.b1;
211 cur_f = eqtb[(hash_size + 1835) + mem[a].hh.b0 + cur_size].hh.v.RH;
216 print_size(cur_size);
218 print_int(mem[a].hh.b0);
219 print_string(" is undefined (character ");
222 help4("Somewhere in the math formula just ended, you used the",
223 "stated character from an undefined font family. For example,",
224 "plain TeX doesn't allow \\it or \\sl in subscripts. Proceed,",
225 "and I'll try to forget that I needed that character.");
227 cur_i = null_character;
232 if ((cur_c >= font_bc[cur_f]) && (cur_c <= font_ec[cur_f]))
233 cur_i = font_info[char_base[cur_f]+ cur_c].qqqq;
235 cur_i = null_character;
236 if (!((cur_i.b0 > 0)))
238 char_warning(cur_f, cur_c);
244 void make_over_(halfword q)
246 mem[q + 1].hh.v.LH = overbar(clean_box(q + 1, 2 * (cur_style / 2) + 1),
247 3 * font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint,
248 font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint);
249 mem[q + 1].hh.v.RH = 2;
252 void make_under_(halfword q)
256 x = clean_box(q + 1, cur_style);
257 p = new_kern(3 * font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint);
259 mem[p].hh.v.RH = fraction_rule(font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint);
260 y = vpackage(x, 0, 1, 1073741823L); /* 2^30 - 1 */
261 delta = mem[y + 3].cint + mem[y + 2].cint + font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint;
262 mem[y + 3].cint = mem[x + 3].cint;
263 mem[y + 2].cint = delta - mem[y + 3].cint;
264 mem[q + 1].hh.v.LH = y;
265 mem[q + 1].hh.v.RH = 2;
268 void make_vcenter_(halfword q)
272 v = mem[q + 1].hh.v.LH;
273 if (mem[v].hh.b0 != 1)
275 confusion("vcenter");
276 return; // abort_flag set
278 delta = mem[v + 3].cint + mem[v + 2].cint;
279 mem[v + 3].cint = font_info[22 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint + half(delta);
280 mem[v + 2].cint = delta - mem[v + 3].cint;
283 void make_radical_(halfword q)
287 x = clean_box(q + 1, 2 *(cur_style / 2)+ 1);
289 clr = font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint +
290 (abs(font_info[5 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint)/ 4);
293 clr = font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint;
294 clr = clr + (abs(clr) / 4);
296 y = var_delimiter(q + 4,
297 cur_size, mem[x + 3].cint + mem[x + 2].cint + clr + font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint);
298 delta = mem[y + 2].cint -(mem[x + 3].cint + mem[x + 2].cint + clr);
300 clr = clr + half(delta);
301 mem[y + 4].cint = - (integer) (mem[x + 3].cint + clr);
302 mem[y].hh.v.RH = overbar(x, clr, mem[y + 3].cint);
303 mem[q + 1].hh.v.LH = hpack(y, 0, 1);
304 mem[q + 1].hh.v.RH = 2;
307 void make_math_accent_(halfword q)
312 internal_font_number f;
325 if (mem[q + 1].hh.v.RH == 1)
328 if (((cur_i.b2)% 4)== 1)
330 a = lig_kern_base[cur_f]+ cur_i.b3;
331 cur_i = font_info[a].qqqq;
334 a = lig_kern_base[cur_f]+ 256 * cur_i.b2 + cur_i.b3 + 32768L - 256 * (128);
335 cur_i = font_info[a].qqqq;
339 if (cur_i.b1 == skew_char[cur_f])
343 s = font_info[kern_base[cur_f]+ 256 * cur_i.b2 + cur_i.b3].cint;
348 a = a + cur_i.b0 + 1;
349 cur_i = font_info[a].qqqq;
354 x = clean_box(q + 1, 2 * (cur_style / 2) + 1);
359 if (((i.b2)% 4) != 2)
362 i = font_info[char_base[f]+ y].qqqq;
365 if (font_info[width_base[f]+ i.b0].cint > w)
367 /* long to unsigned short ... */
371 if (h < font_info[5 + param_base[f]].cint)
374 delta = font_info[5 + param_base[f]].cint;
375 if ((mem[q + 2].hh.v.RH != 0) || (mem[q + 3].hh.v.RH != 0))
376 if (mem[q + 1].hh.v.RH == 1)
380 mem[x + 1]= mem[q + 1];
381 mem[x + 2]= mem[q + 2];
382 mem[x + 3]= mem[q + 3];
383 mem[q + 2].hh = empty_field;
384 mem[q + 3].hh = empty_field;
385 mem[q + 1].hh.v.RH = 3;
386 mem[q + 1].hh.v.LH = x;
387 x = clean_box(q + 1, cur_style);
388 delta = delta + mem[x + 3].cint - h;
392 mem[y + 4].cint = s + half(w - mem[y + 1].cint);
394 p = new_kern(- (integer) delta);
397 y = vpackage(y, 0, 1, 1073741823L); /* 2^30 - 1 */
398 mem[y + 1].cint = mem[x + 1].cint;
399 if (mem[y + 3].cint < h)
401 p = new_kern(h - mem[y + 3].cint);
402 mem[p].hh.v.RH = mem[y + 5].hh.v.RH;
403 mem[y + 5].hh.v.RH = p;
406 mem[q + 1].hh.v.LH = y;
407 mem[q + 1].hh.v.RH = 2;
411 void make_fraction_(halfword q)
413 halfword p, v, x, y, z;
414 scaled delta, delta1, delta2, shiftup, shiftdown, clr;
416 if (mem[q + 1].cint == 1073741824L) /* 2^30 */
417 mem[q + 1].cint = font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint;
418 x = clean_box(q + 2, cur_style + 2 - 2 * (cur_style / 6));
419 z = clean_box(q + 3, 2 * (cur_style / 2) + 3 - 2 * (cur_style / 6));
420 if (mem[x + 1].cint < mem[z + 1].cint)
421 x = rebox(x, mem[z + 1].cint);
423 z = rebox(z, mem[x + 1].cint);
426 shiftup = font_info[8 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
427 shiftdown = font_info[11 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
431 shiftdown = font_info[12 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
432 if (mem[q + 1].cint != 0)
433 shiftup = font_info[9 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
435 shiftup = font_info[10 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
437 if (mem[q + 1].cint == 0)
440 clr = 7 * font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint;
442 clr = 3 * font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint;
443 delta = half(clr - ((shiftup - mem[x + 2].cint) - (mem[z + 3].cint - shiftdown)));
446 shiftup = shiftup + delta;
447 shiftdown = shiftdown + delta;
453 clr = 3 * mem[q + 1].cint;
455 clr = mem[q + 1].cint;
456 delta = half(mem[q + 1].cint);
457 delta1 = clr - ((shiftup - mem[x + 2].cint) - (font_info[22 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint + delta));
458 delta2 = clr -((font_info[22 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint - delta) - (mem[z + 3].cint - shiftdown));
460 shiftup = shiftup + delta1;
462 shiftdown = shiftdown + delta2;
466 mem[v + 3].cint = shiftup + mem[x + 3].cint;
467 mem[v + 2].cint = mem[z + 2].cint + shiftdown;
468 mem[v + 1].cint = mem[x + 1].cint;
469 if (mem[q + 1].cint == 0)
471 p = new_kern((shiftup - mem[x + 2].cint)-(mem[z + 3].cint - shiftdown));
476 y = fraction_rule(mem[q + 1].cint);
477 p = new_kern((font_info[22 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint - delta) - (mem[z + 3].cint - shiftdown));
480 p = new_kern((shiftup - mem[x + 2].cint) - (font_info[22 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint + delta));
484 mem[v + 5].hh.v.RH = x;
486 delta = font_info[20 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
488 delta = font_info[21 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
489 x = var_delimiter(q + 4, cur_size, delta);
491 z = var_delimiter(q + 5, cur_size, delta);
493 mem[q + 1].cint = hpack(x, 0, 1);
495 /***************************************************************************/
496 /* moved to end to avoid questions about pragma optimize 96/Sep/12 */
497 scaled make_op_ (halfword);
498 /***************************************************************************/
500 void make_ord_(halfword q)
505 if (mem[q + 3].hh.v.RH == 0)
506 if (mem[q + 2].hh.v.RH == 0)
507 if (mem[q + 1].hh.v.RH == 1)
511 if ((mem[p].hh.b0 >= 16) && (mem[p].hh.b0 <= 22))
512 if (mem[p + 1].hh.v.RH == 1)
513 if (mem[p + 1].hh.b0 == mem[q + 1].hh.b0)
515 mem[q + 1].hh.v.RH = 4;
517 if (((cur_i.b2) % 4) == 1)
519 a = lig_kern_base[cur_f]+ cur_i.b3;
520 cur_c = mem[p + 1].hh.b1;
521 cur_i = font_info[a].qqqq;
524 a = lig_kern_base[cur_f] + 256 * cur_i.b2 + cur_i.b3 + 32768L - 256 * (128);
525 cur_i = font_info[a].qqqq;
529 if (cur_i.b1 == cur_c)
533 p = new_kern(font_info[kern_base[cur_f] + 256 * cur_i.b2 + cur_i.b3].cint);
534 mem[p].hh.v.RH = mem[q].hh.v.RH;
543 pause_for_instructions();
550 mem[q + 1].hh.b1 = cur_i.b3;
554 mem[p + 1].hh.b1 = cur_i.b3;
561 mem[r + 1].hh.b1 = cur_i.b3;
562 mem[r + 1].hh.b0 = mem[q + 1].hh.b0;
566 mem[r + 1].hh.v.RH = 1;
568 mem[r + 1].hh.v.RH = 4;
573 mem[q].hh.v.RH = mem[p].hh.v.RH;
574 mem[q + 1].hh.b1 = cur_i.b3;
575 mem[q + 3]= mem[p + 3];
576 mem[q + 2]= mem[p + 2];
583 mem[q + 1].hh.v.RH = 1;
588 a = a + cur_i.b0 + 1;
589 cur_i = font_info[a].qqqq;
595 /***************************************************************************/
596 /* moved to end to avoid questions about pragma optimize 96/Sep/12 */
597 void make_scripts_ (halfword, scaled);
598 /***************************************************************************/
600 small_number make_left_right_(halfword q, small_number style, scaled maxd, scaled max_h)
602 register small_number Result;
603 scaled delta, delta1, delta2;
608 cur_size = 16 * ((style - 2) / 2);
609 delta2 = maxd + font_info[22 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
610 delta1 = max_h + maxd - delta2;
613 delta = (delta1 / 500) * delimiter_factor;
614 delta2 = delta1 + delta1 - delimiter_shortfall;
617 mem[q + 1].cint = var_delimiter(q + 1, cur_size, delta);
618 Result = mem[q].hh.b0 - (10);
622 void mlist_to_hlist (void)
627 small_number savestyle;
630 /* small_number rtype; */
631 int rtype; /* 95/Jan/7 */
632 /* small_number t; */
633 int t; /* 95/Jan/7 */
640 penalties = mlist_penalties;
651 cur_size = 16 * ((cur_style - 2) / 2);
652 cur_mu = x_over_n(font_info[6 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint, 18);
658 switch (mem[q].hh.b0)
686 if (mem[q].hh.b0 == 31)
702 if (mem[q].hh.b1 == 1)
730 cur_style = mem[q].hh.b1;
735 cur_size = 16 * ((cur_style - 2) / 2);
736 cur_mu = x_over_n(font_info[6 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint, 18);
743 switch (cur_style / 2)
747 p = mem[q + 1].hh.v.LH;
748 mem[q + 1].hh.v.LH = 0;
753 p = mem[q + 1].hh.v.RH;
754 mem[q + 1].hh.v.RH = 0;
759 p = mem[q + 2].hh.v.LH;
760 mem[q + 2].hh.v.LH = 0;
765 p = mem[q + 2].hh.v.RH;
766 mem[q + 2].hh.v.RH = 0;
770 flush_node_list(mem[q + 1].hh.v.LH);
771 flush_node_list(mem[q + 1].hh.v.RH);
772 flush_node_list(mem[q + 2].hh.v.LH);
773 flush_node_list(mem[q + 2].hh.v.RH);
775 mem[q].hh.b1 = cur_style;
778 if (p != 0)/* if p<>null then l.14317 */
782 /* while link(p)<>null do p:=link(p); */
783 while (mem[p].hh.v.RH != 0)
800 if (mem[q + 3].cint > max_h)
801 max_h = mem[q + 3].cint;
802 if (mem[q + 2].cint > maxd)
803 maxd = mem[q + 2].cint;
809 if (mem[q].hh.b1 == 99)
811 x = mem[q + 1].hh.v.LH;
812 y = math_glue(x, cur_mu);
814 mem[q + 1].hh.v.LH = y;
817 else if ((cur_size != 0) && (mem[q].hh.b1 == 98))
820 /* if p<>null then if (type(p)=glue_node)or(type(p)=kern_node) then */
822 if ((mem[p].hh.b0 == 10) || (mem[p].hh.b0 == 11))
824 mem[q].hh.v.RH = mem[p].hh.v.RH;
834 math_kern(q, cur_mu);
841 return; // abort_flag set
844 } /* end of switch */
845 switch (mem[q + 1].hh.v.RH)
853 delta = font_info[italic_base[cur_f]+(cur_i.b2)/ 4].cint;
854 p = new_character(cur_f, cur_c);
855 if ((mem[q + 1].hh.v.RH == 4) && (font_info[2 + param_base[cur_f]].cint != 0))
857 if ((mem[q + 3].hh.v.RH == 0) && (delta != 0))
859 mem[p].hh.v.RH = new_kern(delta);
871 p = mem[q + 1].hh.v.LH;
875 cur_mlist = mem[q + 1].hh.v.LH;
876 savestyle = cur_style;
877 mlist_penalties = false;
879 cur_style = savestyle;
884 cur_size = 16 * ((cur_style - 2) / 2);
885 cur_mu = x_over_n(font_info[6 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint, 18);
887 p = hpack(mem[temp_head].hh.v.RH, 0, 1);
893 return; // abort_flag set
896 } /* end of switch */
898 mem[q + 1].cint = p; /* p may be used without ... */
899 if ((mem[q + 3].hh.v.RH == 0) && (mem[q + 2].hh.v.RH == 0))
901 make_scripts(q, delta);
903 z = hpack(mem[q + 1].cint, 0, 1);
904 if (mem[z + 3].cint > max_h)
905 max_h = mem[z + 3].cint;
906 if (mem[z + 2].cint > maxd)
907 maxd = mem[z + 2].cint;
911 rtype = mem[r].hh.b0;
926 cur_size = 16 *((cur_style - 2) / 2);
927 cur_mu = x_over_n(font_info[6 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint, 18);
934 switch (mem[q].hh.b0)
946 pen = bin_op_penalty;
975 t = make_left_right(q, style, maxd, max_h);
979 cur_style = mem[q].hh.b1;
985 cur_size = 16 *((cur_style - 2) / 2);
986 cur_mu = x_over_n(font_info[6 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint, 18);
1010 confusion("mlist3");
1011 return; // abort_flag set
1017 switch (str_pool[rtype * 8 + t + magic_offset])
1045 confusion("mlist4");
1046 return; // abort_flag set
1052 y = math_glue(eqtb[(hash_size + 782) + x].hh.v.RH, cur_mu); /* gluebase + x */
1057 mem[z].hh.b1 = x + 1; /* x may be used without ... */
1060 if (mem[q + 1].cint != 0)
1062 mem[p].hh.v.RH = mem[q + 1].cint;
1067 while (!(mem[p].hh.v.RH == 0));
1070 if (mem[q].hh.v.RH != 0)
1073 rtype = mem[mem[q].hh.v.RH].hh.b0;
1077 z = new_penalty(pen);
1091 void push_alignment (void)
1095 mem[p].hh.v.RH = align_ptr;
1096 mem[p].hh.v.LH = cur_align;
1097 mem[p + 1].hh.v.LH = mem[align_head].hh.v.RH;
1098 mem[p + 1].hh.v.RH = cur_span;
1099 mem[p + 2].cint = cur_loop;
1100 mem[p + 3].cint = align_state;
1101 mem[p + 4].hh.v.LH = cur_head;
1102 mem[p + 4].hh.v.RH = cur_tail;
1104 cur_head = get_avail();
1107 void pop_alignment (void)
1111 mem[cur_head].hh.v.RH = avail;
1118 cur_tail = mem[p + 4].hh.v.RH;
1119 cur_head = mem[p + 4].hh.v.LH;
1120 align_state = mem[p + 3].cint;
1121 cur_loop = mem[p + 2].cint;
1122 cur_span = mem[p + 1].hh.v.RH;
1123 mem[align_head].hh.v.RH = mem[p + 1].hh.v.LH;
1124 cur_align = mem[p].hh.v.LH;
1125 align_ptr = mem[p].hh.v.RH;
1129 void get_preamble_token (void)
1133 while ((cur_chr == 256) && (cur_cmd == 4))
1144 fatal_error("(interwoven alignment preambles are not allowed)");
1145 return; // abort_flag set
1147 if ((cur_cmd == 75) && (cur_chr == (hash_size + 793)))
1149 scan_optional_equals();
1151 if (global_defs > 0)
1152 geq_define((hash_size + 793), 117, cur_val);
1154 eq_define((hash_size + 793), 117, cur_val);
1159 void init_align (void)
1166 align_state = -1000000L;
1168 if ((mode == 203) && ((tail != cur_list.head_field) || (cur_list.aux_field.cint != 0)))
1170 print_err("Improper ");
1171 print_esc("halign");
1172 print_string(" inside $$'s");
1173 help3("Displays can use special alignments (like \\eqalignno)",
1174 "only if nothing but the alignment itself is between $$'s.",
1175 "So I've deleted the formulas that preceded this alignment.");
1183 cur_list.aux_field.cint = nest[nest_ptr - 2].aux_field.cint;
1186 /* long to short ... */
1187 mode = - (integer) mode;
1188 scan_spec(6, false);
1189 mem[align_head].hh.v.RH = 0;
1190 cur_align = align_head;
1193 warning_index = savecsptr;
1194 align_state = -1000000L;
1197 mem[cur_align].hh.v.RH = new_param_glue(11);
1198 cur_align = mem[cur_align].hh.v.RH;
1205 get_preamble_token();
1208 if ((cur_cmd <= 5) && (cur_cmd >= 4) && (align_state == -1000000L))
1209 if ((p == hold_head) && (cur_loop == 0) && (cur_cmd == 4))
1210 cur_loop = cur_align;
1213 print_err("Missing # inserted in alignment preamble");
1214 help3("There should be exactly one # between &'s, when an",
1215 "\\halign or \\valign is being set up. In this case you had",
1216 "none, so I've put one in; maybe that will work.");
1220 else if ((cur_cmd != 10) || (p != hold_head))
1222 mem[p].hh.v.RH = get_avail();
1224 mem[p].hh.v.LH = cur_tok;
1228 mem[cur_align].hh.v.RH = new_null_box();
1229 cur_align = mem[cur_align].hh.v.RH;
1230 mem[cur_align].hh.v.LH = end_span;
1231 mem[cur_align + 1].cint = -1073741824L; /* - 2^30 */
1232 mem[cur_align + 3].cint = mem[hold_head].hh.v.RH;
1238 get_preamble_token();
1239 if ((cur_cmd <= 5) && (cur_cmd >= 4) && (align_state == -1000000L))
1243 print_err("Only one # is allowed per tab");
1244 help3("There should be exactly one # between &'s, when an",
1245 "\\halign or \\valign is being set up. In this case you had",
1246 "more than one, so I'm ignoring all but the first.");
1250 mem[p].hh.v.RH = get_avail();
1252 mem[p].hh.v.LH = cur_tok;
1255 mem[p].hh.v.RH = get_avail();
1257 /* mem[p].hh.v.LH = (hash_size + 4614); */
1258 /* mem[p].hh.v.LH = (hash_size + 4095 + 519); */
1259 mem[p].hh.v.LH = (hash_size + hash_extra + 4095 + 519); /* 96/Jan/10 */
1260 mem[cur_align + 2].cint = mem[hold_head].hh.v.RH;
1265 /* if every_cr<>null then begin_token_list(every_cr,every_cr_text); l.15665 */
1266 if (every_cr != 0) /* everycr */
1267 begin_token_list(every_cr, 13);
1271 void init_span_ (halfword p)
1275 space_factor = 1000;
1278 cur_list.aux_field.cint = ignore_depth;
1284 void init_row (void)
1287 mode = (-103) - mode;
1291 cur_list.aux_field.cint = 0;
1293 tail_append(new_glue(mem[mem[align_head].hh.v.RH + 1].hh.v.LH));
1294 mem[tail].hh.b1 = 12;
1295 cur_align = mem[mem[align_head].hh.v.RH].hh.v.RH;
1296 cur_tail = cur_head;
1297 init_span(cur_align);
1300 void init_col (void)
1302 mem[cur_align + 5].hh.v.LH = cur_cmd;
1308 begin_token_list(mem[cur_align + 3].cint, 1);
1311 /* fin_col() moved to end to hide in pragma (g, "off") */
1312 /* may need to move more ? everything calling new_null_box() ? */
1319 p = hpack(mem[head].hh.v.RH, 0, 1);
1322 if (cur_head != cur_tail)
1324 mem[tail].hh.v.RH = mem[cur_head].hh.v.RH;
1330 p = vpackage(mem[head].hh.v.RH, 0, 1, 1073741823L); /* 2^30 - 1 */
1332 mem[tail].hh.v.RH = p;
1334 space_factor = 1000;
1337 mem[p + 6].cint = 0;
1338 if (every_cr != 0) /* everycr */
1339 begin_token_list(every_cr, 13);
1343 void fin_align (void)
1345 halfword p, q, r, s, u, v;
1350 memory_word auxsave;
1354 confusion("align1");
1355 return; // abort_flag set
1360 confusion("align0");
1361 return; // abort_flag set
1364 if (nest[nest_ptr - 1].mode_field == 203)
1368 q = mem[mem[align_head].hh.v.RH].hh.v.RH;
1371 flush_list(mem[q + 3].cint);
1372 flush_list(mem[q + 2].cint);
1373 p = mem[mem[q].hh.v.RH].hh.v.RH;
1374 if (mem[q + 1].cint == -1073741824L) /* - 2^30 */
1376 mem[q + 1].cint = 0;
1378 s = mem[r + 1].hh.v.LH;
1381 incr(mem[0].hh.v.RH); /* mem[mem_bot]? mem[null]? */
1383 mem[r + 1].hh.v.LH = 0;
1386 if (mem[q].hh.v.LH != end_span)
1388 t = mem[q + 1].cint + mem[mem[mem[q].hh.v.RH + 1].hh.v.LH + 1].cint;
1395 mem[r + 1].cint = mem[r + 1].cint - t;
1397 while (mem[r].hh.v.RH > n)
1400 n = mem[mem[s].hh.v.LH].hh.v.RH + 1;
1402 if (mem[r].hh.v.RH < n)
1404 mem[r].hh.v.LH = mem[s].hh.v.LH;
1406 decr(mem[r].hh.v.RH);
1411 if (mem[r + 1].cint > mem[mem[s].hh.v.LH + 1].cint)
1412 mem[mem[s].hh.v.LH + 1].cint = mem[r + 1].cint;
1417 while (!(r == end_span));
1421 mem[q + 3].cint = 0;
1422 mem[q + 2].cint = 0;
1423 mem[q + 5].hh.b1 = 0;
1424 mem[q + 5].hh.b0 = 0;
1425 mem[q + 6].cint = 0;
1426 mem[q + 4].cint = 0;
1430 save_ptr = save_ptr - 2;
1431 pack_begin_line = - (integer) mode_line;
1434 rulesave = overfull_rule;
1436 p = hpack(mem[align_head].hh.v.RH, save_stack[save_ptr + 1].cint, save_stack[save_ptr + 0].cint);
1437 overfull_rule = rulesave;
1441 q = mem[mem[align_head].hh.v.RH].hh.v.RH;
1444 mem[q + 3].cint = mem[q + 1].cint;
1445 mem[q + 1].cint = 0;
1446 q = mem[mem[q].hh.v.RH].hh.v.RH;
1449 p = vpackage(mem[align_head].hh.v.RH, save_stack[save_ptr + 1].cint, save_stack[save_ptr + 0].cint, 1073741823L); /* 2^30 - 1 */
1450 q = mem[mem[align_head].hh.v.RH].hh.v.RH;
1453 mem[q + 1].cint = mem[q + 3].cint;
1454 mem[q + 3].cint = 0;
1455 q = mem[mem[q].hh.v.RH].hh.v.RH;
1459 pack_begin_line = 0;
1460 q = mem[head].hh.v.RH;
1463 {/* while q<>null l.15794 OK */
1464 if (!(q >= hi_mem_min)) /* begin if not is_char_node(q) then */
1465 if (mem[q].hh.b0 == 13)
1470 mem[q + 1].cint = mem[p + 1].cint;
1475 mem[q + 3].cint = mem[p + 3].cint;
1477 mem[q + 5].hh.b1 = mem[p + 5].hh.b1;
1478 mem[q + 5].hh.b0 = mem[p + 5].hh.b0;
1479 mem[q + 6].gr = mem[p + 6].gr;
1480 mem[q + 4].cint = o;
1481 r = mem[mem[q + 5].hh.v.RH].hh.v.RH;
1482 s = mem[mem[p + 5].hh.v.RH].hh.v.RH;
1486 t = mem[s + 1].cint;
1493 v = mem[s + 1].hh.v.LH;
1494 mem[u].hh.v.RH = new_glue(v);
1497 t = t + mem[v + 1].cint;
1498 if (mem[p + 5].hh.b0 == 1)
1500 if (mem[v].hh.b0 == mem[p + 5].hh.b1)
1501 t = t + round(mem[p + 6].gr * mem[v + 2].cint);
1503 else if (mem[p + 5].hh.b0 == 2)
1505 if (mem[v].hh.b1 == mem[p + 5].hh.b1)
1506 t = t - round(mem[p + 6].gr * mem[v + 3].cint);
1509 mem[u].hh.v.RH = new_null_box();
1511 t = t + mem[s + 1].cint;
1513 mem[u + 1].cint = mem[s + 1].cint;
1517 mem[u + 3].cint = mem[s + 1].cint;
1522 mem[r + 3].cint = mem[q + 3].cint;
1523 mem[r + 2].cint = mem[q + 2].cint;
1524 if (t == mem[r + 1].cint)
1526 mem[r + 5].hh.b0 = 0;
1527 mem[r + 5].hh.b1 = 0;
1528 mem[r + 6].gr = 0.0;
1530 else if (t > mem[r + 1].cint)
1532 mem[r + 5].hh.b0 = 1;
1533 if (mem[r + 6].cint == 0)
1534 mem[r + 6].gr = 0.0;
1536 mem[r + 6].gr =(t - mem[r + 1].cint)/ ((double) mem[r + 6].cint);
1540 mem[r + 5].hh.b1 = mem[r + 5].hh.b0;
1541 mem[r + 5].hh.b0 = 2;
1542 if (mem[r + 4].cint == 0)
1543 mem[r + 6].gr = 0.0;
1544 else if ((mem[r + 5].hh.b1 == 0) && (mem[r + 1].cint - t > mem[r + 4].cint))
1545 mem[r + 6].gr = 1.0;
1547 mem[r + 6].gr =(mem[r + 1].cint - t)/ ((double) mem[r + 4].cint);
1549 mem[r + 1].cint = w;
1554 mem[r + 1].cint = mem[q + 1].cint;
1555 if (t == mem[r + 3].cint)
1557 mem[r + 5].hh.b0 = 0;
1558 mem[r + 5].hh.b1 = 0;
1559 mem[r + 6].gr = 0.0;
1561 else if (t > mem[r + 3].cint)
1563 mem[r + 5].hh.b0 = 1;
1564 if (mem[r + 6].cint == 0)
1565 mem[r + 6].gr = 0.0;
1566 else mem[r + 6].gr = (t - mem[r + 3].cint) / ((double) mem[r + 6].cint);
1570 mem[r + 5].hh.b1 = mem[r + 5].hh.b0;
1571 mem[r + 5].hh.b0 = 2;
1572 if (mem[r + 4].cint == 0)
1573 mem[r + 6].gr = 0.0;
1574 else if ((mem[r + 5].hh.b1 == 0) && (mem[r + 3].cint - t > mem[r + 4].cint))
1575 mem[r + 6].gr = 1.0;
1577 mem[r + 6].gr =(mem[r + 3].cint - t)/ ((double) mem[r + 4].cint);
1579 mem[r + 3].cint = w;
1582 mem[r + 4].cint = 0;
1585 mem[u].hh.v.RH = mem[r].hh.v.RH;
1586 mem[r].hh.v.RH = mem[hold_head].hh.v.RH;
1589 r = mem[mem[r].hh.v.RH].hh.v.RH;
1590 s = mem[mem[s].hh.v.RH].hh.v.RH;
1594 else if (mem[q].hh.b0 == 2)
1596 if ((mem[q + 1].cint == -1073741824L)) /* 2^30 */
1597 mem[q + 1].cint = mem[p + 1].cint;
1598 if ((mem[q + 3].cint == -1073741824L)) /* 2^30 */
1599 mem[q + 3].cint = mem[p + 3].cint;
1600 if ((mem[q + 2].cint == -1073741824L)) /* 2^30 */
1601 mem[q + 2].cint = mem[p + 2].cint;
1607 mem[q + 4].cint = o;
1617 auxsave = cur_list.aux_field;
1618 p = mem[head].hh.v.RH;
1626 print_err("Missing $$ inserted");
1627 help2("Displays can use special alignments (like \\eqalignno)",
1628 "only if nothing but the alignment itself is between $$'s.");
1636 print_err("Display math should end with $$");
1637 help2("The `$' that I just saw supposedly matches a previous `$$'.",
1638 "So I shall assume that you typed `$$' both times.");
1643 tail_append(new_penalty(pre_display_penalty));
1644 tail_append(new_param_glue(3));
1645 mem[tail].hh.v.RH = p;
1648 tail_append(new_penalty(post_display_penalty));
1649 tail_append(new_param_glue(4));
1650 cur_list.aux_field.cint = auxsave.cint;
1651 resume_after_display();
1655 cur_list.aux_field = auxsave;
1656 mem[tail].hh.v.RH = p;
1657 if (p != 0) /* if p<>null then tail:=q; l.15926 */
1665 /* used to be align_peek, zfintieshrink, etc in old tex5.c */
1666 /************************************************************************/
1667 /* moved down here to avoid questions about pragma optimize */
1668 #pragma optimize("g", off)
1669 /* for MC VS compiler */
1670 /* Moved down here 96/Oct/12 in response to problem with texerror.tex */
1671 /* pragma optimize("a", off) not strong enough - this may slow things */
1675 register bool Result;
1687 return 0; // abort_flag set
1689 q = mem[cur_align].hh.v.RH;
1694 return 0; // abort_flag set
1697 if (align_state < 500000L)
1699 fatal_error("(interwoven alignment preambles are not allowed)"); /* */
1700 return 0; // abort_flag set
1703 p = mem[q].hh.v.RH; /* p <- link(q) p.791 */
1704 /* if (p = null) ^ (extra_info(cur_align) < cr_code) then p.792 */
1705 if ((p == 0) && (mem[cur_align + 5].hh.v.LH < 257))
1708 /* potential problem here if new_null_box causes memory reallocation ??? */
1709 /* compiler optimization does not refresh `mem' loaded in registers ? */
1710 mem[q].hh.v.RH = new_null_box();
1712 mem[p].hh.v.LH = end_span;
1713 mem[p + 1].cint = -1073741824L; /* - 2^30 */
1714 cur_loop = mem[cur_loop].hh.v.RH;
1716 r = mem[cur_loop + 3].cint;
1719 mem[q].hh.v.RH = get_avail();
1721 mem[q].hh.v.LH = mem[r].hh.v.LH;
1725 mem[p + 3].cint = mem[hold_head].hh.v.RH;
1727 r = mem[cur_loop + 2].cint;
1730 mem[q].hh.v.RH = get_avail();
1732 mem[q].hh.v.LH = mem[r].hh.v.LH;
1736 mem[p + 2].cint = mem[hold_head].hh.v.RH;
1737 cur_loop = mem[cur_loop].hh.v.RH;
1738 mem[p].hh.v.RH = new_glue(mem[cur_loop + 1].hh.v.LH);
1742 print_err("Extra alignment tab has been changed to ");
1744 help3("You have given more \\span or & marks than there were",
1745 "in the preamble to the \\halign or \\valign now in progress.",
1746 "So I'll assume that you meant to type \\cr instead.");
1747 /* extra_info(cur_align) < cr_code) ? */
1748 mem[cur_align + 5].hh.v.LH = 257;
1751 if (mem[cur_align + 5].hh.v.LH != 256)
1758 adjust_tail = cur_tail;
1759 u = hpack(mem[head].hh.v.RH, 0, 1);
1760 w = mem[u + 1].cint;
1761 cur_tail = adjust_tail;
1766 u = vpackage(mem[head].hh.v.RH, 0, 1, 0);
1767 w = mem[u + 3].cint;
1770 if (cur_span != cur_align)
1776 q = mem[mem[q].hh.v.RH].hh.v.RH;
1778 while (!(q == cur_align));
1779 /* if n > max_quarterword then confusion("256 spans"); p.798 */
1780 /* if (n > 255) */ /* 94/Apr/4 ? */
1781 if (n > max_quarterword)
1782 { /* 96/Oct/12 ??? */
1783 confusion("256 spans"); /* 256 spans --- message wrong now, but ... */
1784 return 0; // abort_flag set
1787 while (mem[mem[q].hh.v.LH].hh.v.RH < n)
1789 if (mem[mem[q].hh.v.LH].hh.v.RH > n)
1792 mem[s].hh.v.LH = mem[q].hh.v.LH;
1795 mem[s + 1].cint = w;
1797 else if (mem[mem[q].hh.v.LH + 1].cint < w)
1798 mem[mem[q].hh.v.LH + 1].cint = w;
1800 else if (w > mem[cur_align + 1].cint)
1801 mem[cur_align + 1].cint = w;
1804 if (total_stretch[3] != 0)
1806 else if (total_stretch[2] != 0)
1808 else if (total_stretch[1] != 0)
1812 mem[u + 5].hh.b1 = o;
1813 mem[u + 6].cint = total_stretch[o];
1814 if (total_shrink[3] != 0)
1816 else if (total_shrink[2] != 0)
1818 else if (total_shrink[1] != 0)
1822 mem[u + 5].hh.b0 = o;
1823 mem[u + 4].cint = total_shrink[o];
1825 mem[tail].hh.v.RH = u;
1829 tail_append(new_glue(mem[mem[cur_align].hh.v.RH + 1].hh.v.LH));
1830 mem[tail].hh.b1 = 12;
1831 /* if (extra_info(cur_align) >= cr_code) then p.792 */
1832 if (mem[cur_align + 5].hh.v.LH >= 257)
1839 align_state = 1000000L;
1844 while (!(cur_cmd != 10));
1850 /* #pragma optimize ("g", on) */ /* for MC VS compiler */
1851 /* #pragma optimize ("g",) */ /* 94/Jan/25 */
1852 /* #pragma optimize ("", on) */ /* 96/Sep/12 */
1853 /* #pragma optimize("g", off) */ /* for MC VS compiler */
1855 scaled make_op_(halfword q)
1857 register scaled Result;
1859 halfword p, v, x, y, z;
1862 scaled shiftup, shiftdown;
1864 if ((mem[q].hh.b1 == 0) && (cur_style < 2))
1866 if (mem[q + 1].hh.v.RH == 1)
1869 if ((cur_style < 2) && (((cur_i.b2)% 4)== 2))
1872 i = font_info[char_base[cur_f]+ c].qqqq;
1877 mem[q + 1].hh.b1 = c;
1880 delta = font_info[italic_base[cur_f] + (cur_i.b2) / 4].cint;
1881 x = clean_box(q + 1, cur_style);
1882 if ((mem[q + 3].hh.v.RH != 0) && (mem[q].hh.b1 != 1))
1883 mem[x + 1].cint = mem[x + 1].cint - delta;
1884 mem[x + 4].cint = half(mem[x + 3].cint - mem[x + 2].cint) - font_info[22 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
1885 mem[q + 1].hh.v.RH = 2;
1886 mem[q + 1].hh.v.LH = x;
1890 if (mem[q].hh.b1 == 1)
1892 x = clean_box(q + 2, 2 * (cur_style / 4) + 4 + (cur_style % 2));
1893 y = clean_box(q + 1, cur_style);
1894 z = clean_box(q + 3, 2 * (cur_style / 4) + 5);
1897 mem[v + 1].cint = mem[y + 1].cint;
1898 if (mem[x + 1].cint > mem[v + 1].cint)
1899 mem[v + 1].cint = mem[x + 1].cint;
1900 if (mem[z + 1].cint > mem[v + 1].cint)
1901 mem[v + 1].cint = mem[z + 1].cint;
1902 x = rebox(x, mem[v + 1].cint);
1903 y = rebox(y, mem[v + 1].cint);
1904 z = rebox(z, mem[v + 1].cint);
1905 mem[x + 4].cint = half(delta);
1906 mem[z + 4].cint = - (integer) mem[x + 4].cint;
1907 mem[v + 3].cint = mem[y + 3].cint;
1908 mem[v + 2].cint = mem[y + 2].cint;
1909 if (mem[q + 2].hh.v.RH == 0)
1912 mem[v + 5].hh.v.RH = y;
1916 shiftup = font_info[11 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint - mem[x + 2].cint;
1917 if (shiftup < font_info[9 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint)
1918 shiftup = font_info[9 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint;
1919 p = new_kern(shiftup);
1922 p = new_kern(font_info[13 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint);
1924 mem[v + 5].hh.v.RH = p;
1925 mem[v + 3].cint = mem[v + 3].cint + font_info[13 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint + mem[x + 3].cint + mem[x + 2].cint + shiftup;
1927 if (mem[q + 3].hh.v.RH == 0)
1931 shiftdown = font_info[12 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint - mem[z + 3].cint;
1932 if (shiftdown < font_info[10 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint)
1933 shiftdown = font_info[10 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint;
1934 p = new_kern(shiftdown);
1937 p = new_kern(font_info[13 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint);
1939 mem[v + 2].cint = mem[v + 2].cint + font_info[13 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint + mem[z + 3].cint + mem[z + 2].cint + shiftdown;
1941 mem[q + 1].cint = v;
1946 /* #pragma optimize ("g", on) */ /* for MC VS compiler */
1947 /* #pragma optimize ("g",) */ /* 94/Jan/25 */
1948 /* #pragma optimize ("", on) */ /* 96/Sep/12 */
1949 /* #pragma optimize ("g", off) */
1951 void make_scripts_(halfword q, scaled delta)
1953 halfword p, x, y, z;
1954 scaled shiftup, shiftdown, clr;
1957 p = mem[q + 1].cint;
1958 if ((p >= hi_mem_min))
1970 shiftup = mem[z + 3].cint - font_info[18 + param_base[eqtb[(hash_size + 1837) + t].hh.v.RH]].cint;
1971 shiftdown = mem[z + 2].cint + font_info[19 + param_base[eqtb[(hash_size + 1837) + t].hh.v.RH]].cint;
1974 if (mem[q + 2].hh.v.RH == 0)
1976 x = clean_box(q + 3, 2 *(cur_style / 4)+ 5);
1977 mem[x + 1].cint = mem[x + 1].cint + script_space;
1978 if (shiftdown < font_info[16 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint)
1979 shiftdown = font_info[16 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
1980 clr = mem[x + 3].cint -(abs(font_info[5 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint * 4) / 5);
1981 if (shiftdown < clr)
1983 mem[x + 4].cint = shiftdown;
1988 x = clean_box(q + 2, 2 *(cur_style / 4)+ 4 +(cur_style % 2));
1989 mem[x + 1].cint = mem[x + 1].cint + script_space;
1991 clr = font_info[15 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
1992 else if (cur_style < 2)
1993 clr = font_info[13 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
1995 clr = font_info[14 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
1998 clr = mem[x + 2].cint +(abs(font_info[5 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint) / 4);
2002 if (mem[q + 3].hh.v.RH == 0)
2003 mem[x + 4].cint = - (integer) shiftup;
2006 y = clean_box(q + 3, 2 * (cur_style / 4)+ 5);
2007 mem[y + 1].cint = mem[y + 1].cint + script_space;
2008 if (shiftdown < font_info[17 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint)
2009 shiftdown = font_info[17 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint;
2010 clr = 4 * font_info[8 + param_base[eqtb[(hash_size + 1838) + cur_size].hh.v.RH]].cint - ((shiftup - mem[x + 2].cint) - (mem[y + 3].cint - shiftdown));
2013 shiftdown = shiftdown + clr;
2014 clr =(abs(font_info[5 + param_base[eqtb[(hash_size + 1837) + cur_size].hh.v.RH]].cint * 4) / 5) - (shiftup - mem[x + 2].cint);
2017 shiftup = shiftup + clr;
2018 shiftdown = shiftdown - clr;
2021 mem[x + 4].cint = delta;
2022 p = new_kern((shiftup - mem[x + 2].cint) - (mem[y + 3].cint - shiftdown));
2025 x = vpackage(x, 0, 1, 1073741823L); /* 2^30 - 1 */
2026 mem[x + 4].cint = shiftdown;
2029 if (mem[q + 1].cint == 0)
2030 mem[q + 1].cint = x;
2033 p = mem[q + 1].cint;
2034 while (mem[p].hh.v.RH != 0)
2039 /* #pragma optimize ("g", on) */ /* 96/Sep/12 */
2040 /* #pragma optimize ("g") */ /* 94/Jan/25 */
2041 #pragma optimize ("", on) /* 96/Sep/12 */