-#ifdef _WINDOWS
- #define NOCOMM
- #define NOSOUND
- #define NODRIVERS
- #define STRICT
- #pragma warning(disable:4115) // kill rpcasync.h complaint
- #include <windows.h>
- #define MYLIBAPI __declspec(dllexport)
-#endif
-
-#include "texwin.h"
-
-#pragma warning(disable:4131) // old style declarator
-#pragma warning(disable:4135) // conversion between different integral types
-#pragma warning(disable:4127) // conditional expression is constant
-
-#include <setjmp.h>
-
-#define EXTERN extern
-
-#include "texd.h"
-
-#pragma warning(disable:4244) /* 96/Jan/10 */
-
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-/* sec 0944 */
-void build_page (void)
-{
- halfword p;
- halfword q, r;
- integer b, c;
- integer pi;
-/* unsigned char n; */
- unsigned int n; /* 95/Jan/7 */
- scaled delta, h, w;
-
-/* begin if (link(contrib_head)=null)or output_active then return; l.19351 */
- if ((mem[contrib_head].hh.v.RH == 0)|| output_active)
- return;
- do {
-lab22:
- p = mem[contrib_head].hh.v.RH;
-/* if (last_glue != 262143L) */
- if (last_glue != empty_flag)
- delete_glue_ref(last_glue);
- last_penalty = 0;
- last_kern = 0;
- if (mem[p].hh.b0 == 10) {
- last_glue = mem[p + 1].hh.v.LH;
- incr(mem[last_glue].hh.v.RH);
- } else {
-/* last_glue = 262143L; */
- last_glue = empty_flag;
- if (mem[p].hh.b0 == 12)
- last_penalty = mem[p + 1].cint;
- else if (mem[p].hh.b0 == 11)
- last_kern = mem[p + 1].cint;
- }
- switch (mem[p].hh.b0)
- {
- case 0:
- case 1:
- case 2:
- if (page_contents < 2) {
- if (page_contents == 0)
- freeze_page_specs(2);
- else
- page_contents = 2;
- q = new_skip_param(9);
- if (mem[temp_ptr + 1].cint > mem[p + 3].cint)
- mem[temp_ptr + 1].cint = mem[temp_ptr + 1].cint - mem[p + 3].cint;
- else
- mem[temp_ptr + 1].cint = 0;
- mem[q].hh.v.RH = p;
- mem[contrib_head].hh.v.RH = q;
- goto lab22;
- } else {
- page_so_far[1]= page_so_far[1]+ page_so_far[7]+ mem[p + 3].cint;
- page_so_far[7]= mem[p + 2].cint;
- goto lab80;
- }
- break;
- case 8:
- goto lab80;
- break;
- case 10:
- if (page_contents < 2)
- goto lab31;
- else if ((mem[page_tail].hh.b0 < 9))
- pi = 0;
- else
- goto lab90;
- break;
- case 11:
- if (page_contents < 2)
- goto lab31;
- else if (mem[p].hh.v.RH == 0)
- return;
- else if (mem[mem[p].hh.v.RH].hh.b0 == 10)
- pi = 0;
- else
- goto lab90;
- break;
- case 12:
- if (page_contents < 2)
- goto lab31;
- else
- pi = mem[p + 1].cint;
- break;
- case 4:
- goto lab80;
- break;
- case 3:
- {
- if (page_contents == 0)
- freeze_page_specs(1);
- n = mem[p].hh.b1;
- r = mem_top;
- while(n >= mem[mem[r].hh.v.RH].hh.b1)
- r = mem[r].hh.v.RH;
- n = n;
- if (mem[r].hh.b1 != n)
- {
- q = get_node(4);
- mem[q].hh.v.RH = mem[r].hh.v.RH;
- mem[r].hh.v.RH = q;
- r = q;
- mem[r].hh.b1 = n;
- mem[r].hh.b0 = 0;
- ensure_vbox(n);
- if (eqtb[(hash_size + 1578) + n].hh.v.RH == 0)
- mem[r + 3].cint = 0;
- else
- mem[r + 3].cint = mem[eqtb[(hash_size + 1578) + n].hh.v.RH + 3].cint + mem[eqtb[(hash_size + 1578) + n].hh.v.RH + 2].cint;
- mem[r + 2].hh.v.LH = 0;
- q = eqtb[(hash_size + 800) + n].hh.v.RH;
- if (eqtb[(hash_size + 3218) + n].cint == 1000)
- h = mem[r + 3].cint;
- else
- h = x_over_n(mem[r + 3].cint, 1000)* eqtb[(hash_size + 3218) + n].cint;
- page_so_far[0]= page_so_far[0]- h - mem[q + 1].cint;
- page_so_far[2 + mem[q].hh.b0]= page_so_far[2 + mem[q].hh.b0]+ mem[q + 2].cint;
- page_so_far[6]= page_so_far[6]+ mem[q + 3].cint;
- if ((mem[q].hh.b1 != 0)&&(mem[q + 3].cint != 0)) {
- print_err("Infinite glue shrinkage inserted from");
- print_esc("skip");
- print_int(n);
- help3("The correction glue for page breaking with insertions",
- "must have finite shrinkability. But you may proceed,",
- "since the offensive shrinkability has been made finite.");
- error();
- }
- }
- if (mem[r].hh.b0 == 1)
- insert_penalties = insert_penalties + mem[p + 1].cint;
- else {
- mem[r + 2].hh.v.RH = p;
- delta = page_so_far[0]- page_so_far[1]- page_so_far[7] + page_so_far[6];
- if (eqtb[(hash_size + 3218) + n].cint == 1000)
- h = mem[p + 3].cint;
- else
- h = x_over_n(mem[p + 3].cint, 1000)* eqtb[(hash_size + 3218) + n].cint;
- if (((h <= 0)||(h <= delta)) &&(mem[p + 3].cint + mem[r + 3].cint <= eqtb[(hash_size + 3751) + n].cint))
- {
- page_so_far[0]= page_so_far[0]- h;
- mem[r + 3].cint = mem[r + 3].cint + mem[p + 3].cint;
- } else {
- if (eqtb[(hash_size + 3218) + n].cint <= 0)
- w = 1073741823L; /* 2^30 - 1 */
- else {
- w = page_so_far[0]- page_so_far[1]- page_so_far[7];
- if (eqtb[(hash_size + 3218) + n].cint != 1000)
- w = x_over_n(w, eqtb[(hash_size + 3218) + n].cint)* 1000;
- }
- if (w > eqtb[(hash_size + 3751) + n].cint - mem[r + 3].cint)
- w = eqtb[(hash_size + 3751) + n].cint - mem[r + 3].cint;
- q = vert_break(mem[p + 4].hh.v.LH, w, mem[p + 2].cint);
- mem[r + 3].cint = mem[r + 3].cint + best_height_plus_depth;
- ;
-#ifdef STAT
- if (tracing_pages > 0)
- {
- begin_diagnostic();
- print_nl("% split");
- print_int(n);
- print_string(" to");
- print_scaled(w);
- print_char(',');
- print_scaled(best_height_plus_depth);
- print_string(" p=");
- if (q == 0) /* if q=null l.19614 */
- print_int(-10000);
- else if (mem[q].hh.b0 == 12)
- print_int(mem[q + 1].cint);
- else print_char('0');
- end_diagnostic(false);
- }
-#endif /* STAT */
- if (eqtb[(hash_size + 3218) + n].cint != 1000)
- best_height_plus_depth = x_over_n(best_height_plus_depth, 1000) * eqtb[(hash_size + 3218) + n].cint;
- page_so_far[0]= page_so_far[0]- best_height_plus_depth;
- mem[r].hh.b0 = 1;
- mem[r + 1].hh.v.RH = q;
- mem[r + 1].hh.v.LH = p;
- if (q == 0)
- insert_penalties = insert_penalties - 10000;
- else if (mem[q].hh.b0 == 12)
- insert_penalties = insert_penalties + mem[q + 1].cint;
- }
- }
- goto lab80;
- }
- break;
- default:
- {
- confusion("page");
- return; // abort_flag set
- }
- break;
- }
- if (pi < 10000)/* pi may be used ... */
- {
- if (page_so_far[1]< page_so_far[0])
- if ((page_so_far[3]!= 0)||(page_so_far[4]!= 0)||(page_so_far[5]!= 0))
- b = 0;
- else
- b = badness(page_so_far[0]- page_so_far[1], page_so_far[2]);
- else if (page_so_far[1]- page_so_far[0]> page_so_far[6])
- b = 1073741823L; /* 2^30 - 1 */
- else
- b = badness(page_so_far[1]- page_so_far[0], page_so_far[6]);
- if (b < 1073741823L) /* 2^30 - 1 */
- if (pi <= -10000)
- c = pi;
- else if (b < 10000)
- c = b + pi + insert_penalties;
- else
- c = 100000L;
- else
- c = b;
- if (insert_penalties >= 10000)
- c = 1073741823L; /* 2^30 - 1 */
- ;
-#ifdef STAT
- if (tracing_pages > 0)
- {
- begin_diagnostic();
- print_nl("%");
- print_string(" t=");
- print_totals();
- print_string(" g=");
- print_scaled(page_so_far[0]);
- print_string(" b=");
- if (b == 1073741823L) /* 2^30 - 1 */
- print_char('*');
- else
- print_int(b);
- print_string(" p=");
- print_int(pi);
- print_string(" c=");
- if (c == 1073741823L) /* 2^30 - 1 */
- print_char('*');
- else print_int(c);
- if (c <= least_page_cost)
- print_char('#');
- end_diagnostic(false);
- }
-#endif /* STAT */
- if (c <= least_page_cost)
- {
- best_page_break = p;
- best_size = page_so_far[0];
- least_page_cost = c;
- r = mem[mem_top].hh.v.RH;
- while (r != mem_top) {
- mem[r + 2].hh.v.LH = mem[r + 2].hh.v.RH;
- r = mem[r].hh.v.RH;
- }
- }
- if ((c == 1073741823L)||(pi <= -10000)) /* 2^30 - 1 */
- {
- fire_up(p);
- if (output_active)
- return;
- goto lab30;
- }
- }
- if ((mem[p].hh.b0 < 10)||(mem[p].hh.b0 > 11))
- goto lab80;
-lab90:
- if (mem[p].hh.b0 == 11)
- q = p;
- else {
- q = mem[p + 1].hh.v.LH;
- page_so_far[2 + mem[q].hh.b0] = page_so_far[2 + mem[q].hh.b0] + mem[q + 2].cint;
- page_so_far[6]= page_so_far[6]+ mem[q + 3].cint;
- if ((mem[q].hh.b1 != 0)&&(mem[q + 3].cint != 0)) {
- print_err("Infinite glue shrinkage found on current page");
- help4("The page about to be output contains some infinitely",
- "shrinkable glue, e.g., `\\vss' or `\\vskip 0pt minus 1fil'.",
- "Such glue doesn't belong there; but you can safely proceed,",
- "since the offensive shrinkability has been made finite.");
- error();
- r = new_spec(q);
- mem[r].hh.b1 = 0;
- delete_glue_ref(q);
- mem[p + 1].hh.v.LH = r;
- q = r;
- }
- }
- page_so_far[1]= page_so_far[1]+ page_so_far[7]+ mem[q + 1].cint;
- page_so_far[7]= 0;
-lab80:
- if (page_so_far[7]> page_max_depth) {
- page_so_far[1] = page_so_far[1] + page_so_far[7] - page_max_depth;
- page_so_far[7] = page_max_depth;
- }
- mem[page_tail].hh.v.RH = p;
- page_tail = p;
- mem[contrib_head].hh.v.RH = mem[p].hh.v.RH;
- mem[p].hh.v.RH = 0;
- goto lab30;
-lab31:
- mem[contrib_head].hh.v.RH = mem[p].hh.v.RH;
- mem[p].hh.v.RH = 0;
- flush_node_list(p);
-lab30:;
- } while (!(mem[contrib_head].hh.v.RH == 0));
- if (nest_ptr == 0)
- tail = contrib_head;
- else
- nest[0].tail_field = contrib_head;
-}
-/* sec 1043 */
-void app_space (void)
-{
- halfword q;
- if ((space_factor >= 2000) && (eqtb[(hash_size + 795)].hh.v.RH != 0))
- q = new_param_glue(13);
- else {
- if (eqtb[(hash_size + 794)].hh.v.RH != 0)
- main_p = eqtb[(hash_size + 794)].hh.v.RH;
- else {
- main_p = font_glue[eqtb[(hash_size + 1834)].hh.v.RH];
- if (main_p == 0) {
- main_p = new_spec(0);
- main_k = param_base[eqtb[(hash_size + 1834)].hh.v.RH]+ 2;
- mem[main_p + 1].cint = font_info[main_k].cint;
- mem[main_p + 2].cint = font_info[main_k + 1].cint;
- mem[main_p + 3].cint = font_info[main_k + 2].cint;
- font_glue[eqtb[(hash_size + 1834)].hh.v.RH]= main_p;
- }
- }
- main_p = new_spec(main_p);
- if (space_factor >= 2000)
- mem[main_p + 1].cint = mem[main_p + 1].cint + font_info[7 + param_base[eqtb[(hash_size + 1834)].hh.v.RH]].cint;
- mem[main_p + 2].cint = xn_over_d(mem[main_p + 2].cint, cur_list.aux_field.hh.v.LH, 1000);
- mem[main_p + 3].cint = xn_over_d(mem[main_p + 3].cint, 1000, space_factor);
- q = new_glue(main_p);
- mem[main_p].hh.v.RH = 0;
- }
- mem[tail].hh.v.RH = q;
- tail = q;
-}
-/* called from tex8.c only */
-/* sec 1047 */
-void insert_dollar_sign (void)
-{
- back_input();
- cur_tok = 804;
- print_err("Missing $ inserted");
- help2("I've inserted a begin-math/end-math symbol since I think",
- "you left one out. Proceed, with fingers crossed.");
- ins_error();
-}
-/* sec 1049 */
-void you_cant (void)
-{
- print_err("You can't use `");
- print_cmd_chr(cur_cmd, cur_chr);
- print_string("' in ");
- print_mode(mode);
-}
-/* sec 1050 */
-void report_illegal_case (void)
-{
- you_cant();
- help4("Sorry, but I'm not programmed to handle this case;",
- "I'll just pretend that you didn't ask for it.",
- "If you're in the wrong mode, you might be able to",
- "return to the right one by typing `I}' or `I$' or `I\\par'.");
- error();
-}
-/* sec 1051 */
-bool privileged (void)
-{
- register bool Result;
- if (mode > 0)
- Result = true;
- else {
- report_illegal_case();
- Result = false;
- }
- return Result;
-}
-/* sec 1054 */
-bool its_all_over (void)
-{/* 10 */
- register bool Result;
- if (privileged ())
- {
- if ((page_head == page_tail) && (head == cur_list.tail_field) && (dead_cycles == 0))
- {
- Result = true;
- return(Result);
- }
- back_input();
- {
- mem[tail].hh.v.RH = new_null_box();
- tail = mem[tail].hh.v.RH;
- }
- mem[tail + 1].cint = hsize;
- {
- mem[tail].hh.v.RH = new_glue(8);
- tail = mem[tail].hh.v.RH;
- }
- {
- mem[tail].hh.v.RH = new_penalty(-1073741824L);
- /* - 2^30 */
- tail = mem[tail].hh.v.RH;
- }
- build_page();
- }
- Result = false;
- return Result;
-}
-/* sec 1060 */
-void append_glue (void)
-{
- small_number s;
- s = cur_chr;
- switch(s)
- {
- case 0:
- cur_val = 4;
- break;
- case 1:
- cur_val = 8;
- break;
- case 2:
- cur_val = 12;
- break;
- case 3:
- cur_val = 16;
- break;
- case 4:
- scan_glue(2);
- break;
- case 5:
- scan_glue(3);
- break;
- }
- {
- mem[tail].hh.v.RH = new_glue(cur_val);
- tail = mem[tail].hh.v.RH;
- }
- if (s >= 4) {
- decr(mem[cur_val].hh.v.RH);
- if (s > 4)
- mem[tail].hh.b1 = 99;
- }
-}
-/* sec 1161 */
-void append_kern (void)
-{
- quarterword s;
- s = cur_chr;
- scan_dimen(s == 99, false, false);
- {
- mem[tail].hh.v.RH = new_kern(cur_val);
- tail = mem[tail].hh.v.RH;
- }
- mem[tail].hh.b1 = s;
-}
-/* sec 1054 */
-void off_save (void)
-{
- halfword p;
- if (cur_group == 0) {
- print_err("Extra ");
- print_cmd_chr(cur_cmd, cur_chr);
- help1("Things are pretty mixed up, but I think the worst is over.");
- error();
- } else {
- back_input();
- p = get_avail();
- mem[temp_head].hh.v.RH = p;
- print_err("Missing ");
- switch (cur_group)
- {
- case 14:
- {
-/* mem[p].hh.v.LH = (hash_size + 4611); */
-/* mem[p].hh.v.LH = (hash_size + 4095 + 516); */
- mem[p].hh.v.LH = (hash_size + hash_extra + 4095 + 516); /* 96/Jan/10 */
- print_esc("endgroup");
- }
- break;
- case 15:
- {
- mem[p].hh.v.LH = 804;
- print_char('$');
- }
- break;
- case 16:
- {
-/* mem[p].hh.v.LH = (hash_size + 4612); */
-/* mem[p].hh.v.LH = (hash_size + 4095 + 517); */
- mem[p].hh.v.LH = (hash_size + hash_extra + 4095 + 517); /* 96/Jan/10 */
- mem[p].hh.v.RH = get_avail();
- p = mem[p].hh.v.RH;
- mem[p].hh.v.LH = 3118;
- print_esc("right.");
- }
- break;
- default:
- {
- mem[p].hh.v.LH = 637;
- print_char('}');
- }
- break;
- }
- print_string(" inserted");
- begin_token_list(mem[temp_head].hh.v.RH, 4);
- help5("I've inserted something that you may have forgotten.",
- "(See the <inserted text> above.)",
- "With luck, this will get me unwedged. But if you",
- "really didn't forget anything, try typing `2' now; then",
- "my insertion and my current dilemma will both disappear.");
- error();
- }
-}
-/* only called from tex8.c */
-/* sec 1069 */
-void extra_right_brace (void)
-{
- print_err("Extra }, or forgotten");
- switch(cur_group)
- {
- case 14:
- print_esc("endgroup");
- break;
- case 15 :
- print_char('$');
- break;
- case 16 :
- print_esc("right");
- break;
- }
- help5("I've deleted a group-closing symbol because it seems to be",
- "spurious, as in `$x}$'. But perhaps the } is legitimate and",
- "you forgot something else, as in `\\hbox{$x}'. In such cases",
- "the way to recover is to insert both the forgotten and the",
- "deleted material, e.g., by typing `I$}'.");
- error();
- incr(align_state);
-}
-/* sec 1070 */
-void normal_paragraph (void)
-{
-/* if looseness<>0 then eq_word_define(int_base+looseness_code,0); */
- if (looseness != 0)
- eq_word_define((hash_size + 3182), 0);
- if (hang_indent != 0)
- eq_word_define((hash_size + 3747), 0);
- if (hang_after != 1)
- eq_word_define((hash_size + 3204), 1);
- if (par_shape_ptr != 0)
- eq_define((hash_size + 1312), 118, 0);
-}
-/* sec 1075 */
-void box_end_(integer boxcontext)
-{
- halfword p;
-/* if box_context<box_flag then ... 1073741824 2^30 */
- if (boxcontext < 1073741824L) {
- if (cur_box != 0) {
- mem[cur_box + 4].cint = boxcontext;
- if (abs(mode)== 1) {
- append_to_vlist(cur_box);
- if (adjust_tail != 0) {
- if (adjust_head != adjust_tail) {
- mem[tail].hh.v.RH = mem[adjust_head].hh.v.RH;
- tail = adjust_tail;
- }
- adjust_tail = 0;
- }
- if (mode > 0) {
- build_page();
- }
- } else {
- if (abs(mode)== 102)
- space_factor = 1000;
- else {
- p = new_noad();
- mem[p + 1].hh.v.RH = 2;
- mem[p + 1].hh.v.LH = cur_box;
- cur_box = p;
- }
- mem[tail].hh.v.RH = cur_box;
- tail = cur_box;
- }
- }
- }
-
-/* following fixed 1994/Apr/5 1 day anno Yang --- moby sigh ... */
-
-/* else if box_context<box_flag+512 then ... */
-/* else if (boxcontext < 1073742336L)*/ /* 2^30 + 512 */
- else if (boxcontext < (1073741824L + 512)) /* 2^30 + 512 */
-/* else if box_context<box_flag+256 then ... */
-/* if (boxcontext < 1073742080L)*/ /* 2^30 + 256 */
- if (boxcontext < (1073741824L + 256))/* 2^30 + 256 */
-/* eq_define(box_base-box_flag+box_context,box_ref,cur_box) */
-/* eq_define((hash_size - 1073740246L) + boxcontext, 119, cur_box); */
- eq_define((hash_size + 1578 - 1073741824L) + boxcontext, 119, cur_box);
-/* else geq_define(box_base-box_flag-256+box_context,box_ref,cur_box) */
-/* else geq_define((hash_size - 1073740502L) + boxcontext, 119, cur_box); */
- else geq_define((hash_size + 1322 - 1073741824L) + boxcontext, 119, cur_box);
- else if (cur_box != 0)
-/* if (boxcontext > 1073742336L)*/ /* 2^30 + 512 */
- if (boxcontext > (1073741824L + 512)) /* 2^30 + 512 */
- {
- do {
- get_x_token();
- } while(!((cur_cmd != 10)&&(cur_cmd != 0)));
-/* 424 in tex82.bug */
- if (((cur_cmd == 26) && (abs(mode)!= 1)) ||
- ((cur_cmd == 27) && (abs(mode)== 1)))
- {
-/* begin append_glue; subtype(tail):=box_context-(leader_flag-a_leaders); */
- append_glue();
-/* -(2^30 + 513 - 100) */
- mem[tail].hh.b1 = boxcontext -(1073742237L);
- mem[tail + 1].hh.v.RH = cur_box;
- }
- else {
- print_err("Leaders not followed by proper glue");
- help3("You should say `\\leaders <box or rule><hskip or vskip>'.",
- "I found the <box or rule>, but there's no suitable",
- "<hskip or vskip>, so I'm ignoring these leaders.");
- back_error();
- flush_node_list(cur_box);
- }
- }
- else ship_out(cur_box);
-}
-/* called only from tex8.c */
-/* sec 1079 */
-void begin_box_(integer boxcontext)
-{/* 10 30 */
- halfword p, q;
- quarterword m;
- halfword k;
- eight_bits n;
- switch(cur_chr){
- case 0 :
- {
- scan_eight_bit_int();
- cur_box = eqtb[(hash_size + 1578) + cur_val].hh.v.RH;
- eqtb[(hash_size + 1578) + cur_val].hh.v.RH = 0;
- }
- break;
- case 1 :
- {
- scan_eight_bit_int();
- cur_box = copy_node_list(eqtb[(hash_size + 1578) + cur_val].hh.v.RH);
- }
- break;
- case 2 :
- {
- cur_box = 0;
- if (abs(mode)== 203)
- {
- you_cant();
- help1("Sorry; this \\lastbox will be void.");
- error();
- } else if ((mode == 1)&&(head == cur_list.tail_field)) {
- you_cant();
- help2("Sorry...I usually can't take things from the current page.",
- "This \\lastbox will therefore be void.");
- error();
- } else {
- if (!(tail >= hi_mem_min))
- if ((mem[tail].hh.b0 == 0) || (mem[cur_list.tail_field].hh.b0 == 1)) {
- q = head;
- do {
- p = q;
- if (!(q >= hi_mem_min))
- if (mem[q].hh.b0 == 7)
- {
- {
- register integer for_end;
- m = 1;
- for_end = mem[q].hh.b1;
- if (m <= for_end) do
- p = mem[p].hh.v.RH;
- while(m++ < for_end);
- }
- if (p == tail)
- goto lab30;
- }
- q = mem[p].hh.v.RH;
- } while (!(q == tail));
- cur_box = tail;
- mem[cur_box + 4].cint = 0;
- tail = p;
- mem[p].hh.v.RH = 0;
-lab30:;
- }
- }
- }
- break;
- case 3:
- {
- scan_eight_bit_int();
- n = cur_val;
- if (!scan_keyword("to")) /* to */
- {
- print_err("Missing `to' inserted");
- help2("I'm working on `\\vsplit<box number> to <dimen>';",
- "will look for the <dimen> next.");
- error();
- }
- scan_dimen(false, false, false);
- cur_box = vsplit(n, cur_val);
- }
- break;
- default:
- {
- k = cur_chr - 4;
- save_stack[save_ptr + 0].cint = boxcontext;
- if (k == 102)
- if ((boxcontext < 1073741824L) && /* 2^30 */
- (abs(mode)== 1))
- scan_spec(3, true);
- else
- scan_spec(2, true);
- else {
- if (k == 1)
- scan_spec(4, true);
- else {
- scan_spec(5, true);
- k = 1;
- }
- normal_paragraph();
- }
- push_nest();
- mode = - (integer) k;
- if (k == 1)
- {
- cur_list.aux_field.cint = ignore_depth;
- if (every_vbox != 0)
- begin_token_list(every_vbox, 11);
- } else {
- space_factor = 1000;
- if (every_hbox != 0)
- begin_token_list(every_hbox, 10);
- }
- return;
- }
- break;
- }
- box_end(boxcontext);
-}
-/* sec 1084 */
-void scan_box_(integer boxcontext)
-{
- do {
- get_x_token();
- } while(!((cur_cmd != 10) && (cur_cmd != 0)));
- if (cur_cmd == 20){
- begin_box(boxcontext);
- }
- else if ((boxcontext >= 1073742337L)&& /* (2^30 + 512 + 1) */
- ((cur_cmd == 36)||(cur_cmd == 35)))
- {
- cur_box = scan_rule_spec();
- box_end(boxcontext);
- }
- else {
- print_err("A <box> was supposed to be here");
- help3("I was expecting to see \\hbox or \\vbox or \\copy or \\box or",
- "something like that. So you might find something missing in",
- "your output. But keep trying; you can fix this later.");
- back_error();
- }
-}
-/****************************************************************************/
-void package_ (small_number);
-/****************************************************************************/
-/* sec 1091 */
-small_number norm_min_ (integer h)
-{register
-/* small_number Result; */
- int Result; /* 95/Jan/7 */
- if (h <= 0)
- Result = 1;
- else if (h >= 63)
- Result = 63;
- else
- Result = h;
- return Result;
-}
-/* sec 1091 */
-void new_graf_(bool indented)
-{
- prev_graf = 0;
- if ((mode == 1)||(head != cur_list.tail_field))
- {
- mem[tail].hh.v.RH = new_param_glue(2);
- tail = mem[tail].hh.v.RH;
- }
-/* used to be followingin 3.141 */
-/* cur_list .lhmfield = norm_min(eqtb[(hash_size + 3214)].cint); */
-/* cur_list .rhmfield = norm_min(eqtb[(hash_size + 3215)].cint); */
- push_nest();
- mode = 102;
- space_factor = 1000;
-/* changes here since 3.141 */
- if (language <= 0)
- cur_lang = 0;
- else if (language > 255)
- cur_lang = 0;
- else cur_lang = language;
- clang = cur_lang;
- prev_graf =(norm_min(left_hyphen_min)* 64 +
- norm_min(right_hyphen_min)) * 65536L + cur_lang;
-/* eqtb ??? hash_size ? hash_size + hash_extra ? norm_min etc */
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
- if (indented)
- {
- tail = new_null_box();
- mem[head].hh.v.RH = tail;
- mem[tail + 1].cint = par_indent;
- }
- if (every_par != 0)
- begin_token_list(every_par, 7);
- if (nest_ptr == 1){
- build_page();
- }
-}
-/* procedure indent_in_hmode; l.21058 */
-/* sec 1093 */
-void indent_in_hmode (void)
-{
- halfword p, q;
- if (cur_chr > 0)
- {
- p = new_null_box();
- mem[p + 1].cint = par_indent;
- if (abs(mode)== 102)
- space_factor = 1000;
- else {
- q = new_noad();
- mem[q + 1].hh.v.RH = 2;
- mem[q + 1].hh.v.LH = p;
- p = q;
- }
- {
- mem[tail].hh.v.RH = p;
- tail = mem[tail].hh.v.RH;
- }
- }
-}
-/* only called from tex8.c */
-/* sec 1095 */
-void head_for_vmode (void)
-{
- if (mode < 0)
- if (cur_cmd != 36){
- off_save();
- } else {
- print_err("You can't use `");
- print_esc("hrule");
- print_string("' here except with leaders");
- help2("To put a horizontal rule in an hbox or an alignment,",
- "you should use \\leaders or \\hrulefill (see The TeXbook).");
- error();
- } else {
- back_input();
- cur_tok = par_token;
- back_input();
- cur_input.index_field = 4;
- }
-}
-/* sec 1096 */
-void end_graf (void)
-{
- if (mode == 102)
- {
- if (head == tail)
- pop_nest();
- else line_break(widow_penalty);
- normal_paragraph();
- error_count = 0;
- }
-}
-/* only called form tex8.c */
-/* sec 1099 */
-void begin_insert_or_adjust (void)
-{
- if (cur_cmd == 38)
- cur_val = 255;
- else {
- scan_eight_bit_int();
- if (cur_val == 255)
- {
- print_err("You can't ");
- print_esc("insert");
- print_int(255);
- help1("I'm changing to \\insert0; box 255 is special.");
- error();
- cur_val = 0;
- }
- }
- save_stack[save_ptr + 0].cint = cur_val;
- incr(save_ptr);
- new_save_level(11);
- scan_left_brace();
- normal_paragraph();
- push_nest();
- mode = -1;
- cur_list.aux_field.cint = ignore_depth;
-}
-/* sec 1101 */
-void make_mark (void)
-{
- halfword p;
- p = scan_toks(false, true);
- p = get_node(2);
- mem[p].hh.b0 = 4;
- mem[p].hh.b1 = 0;
- mem[p + 1].cint = def_ref;
- mem[tail].hh.v.RH = p;
- tail = p;
-}
-/* sec 1103 */
-void append_penalty (void)
-{
- scan_int();
- {
- mem[tail].hh.v.RH = new_penalty(cur_val);
- tail = mem[tail].hh.v.RH;
- }
- if (mode == 1){
- build_page();
- }
-}
-/* only called from tex8.c */
-/* sec 1105 */
-void delete_last (void)
-{/* 10 */
- halfword p, q;
- quarterword m;
- if ((mode == 1) && (tail == cur_list.head_field))
- {
-/* if ((cur_chr != 10)||(last_glue != 262143L)) */
- if ((cur_chr != 10) || (last_glue != empty_flag)) {
- you_cant();
- help2("Sorry...I usually can't take things from the current page.",
- "Try `I\\vskip-\\lastskip' instead.");
- if (cur_chr == 11)
- help_line[0] = "Try `I\\kern-\\last_kern' instead.";
- else if (cur_chr != 10)
- help_line[0] = "Perhaps you can make the output routine do it.";
- error();
- }
- } else {
- if (!(tail >= hi_mem_min))
- if (mem[tail].hh.b0 == cur_chr)
- {
- q = head;
- do {
- p = q;
- if (!(q >= hi_mem_min))
- if (mem[q].hh.b0 == 7)
- {
- {
- register integer for_end;
- m = 1;
- for_end = mem[q].hh.b1;
- if (m <= for_end) do
- p = mem[p].hh.v.RH;
- while(m++ < for_end);
- }
- if (p == tail)
- return;
- }
- q = mem[p].hh.v.RH;
- } while (!(q == tail));
- mem[p].hh.v.RH = 0;
- flush_node_list(tail);
- tail = p;
- }
- }
-}
-/* only called from tex8.c */
-/* procedure unpackage; l.21256 */
-/* sec 1110 */
-void unpackage (void)
-{
- halfword p;
- char c;
- c = cur_chr;
- scan_eight_bit_int();
- p = eqtb[(hash_size + 1578) + cur_val].hh.v.RH;
- if (p == 0)/* if p=null then return; l.21261 */
- return;
- if ((abs(mode)== 203) ||
- ((abs(mode) == 1) && (mem[p].hh.b0 != 1)) ||
- ((abs(mode) == 102) && (mem[p].hh.b0 != 0)))
- {
- print_err("Incompatible list can't be unboxed");
- help3("Sorry, Pandora. (You sneaky devil.)",
- "I refuse to unbox an \\hbox in vertical mode or vice versa.",
- "And I can't open any boxes in math mode.");
- error();
- return;
- }
- if (c == 1)
- mem[tail].hh.v.RH = copy_node_list(mem[p + 5].hh.v.RH);
- else {
- mem[tail].hh.v.RH = mem[p + 5].hh.v.RH;
- eqtb[(hash_size + 1578) + cur_val].hh.v.RH = 0;
- free_node(p, 7);
- }
- while (mem[tail].hh.v.RH != 0)
- tail = mem[tail].hh.v.RH;
-}
-/* sec 1113 */
-void append_italic_correction (void)
-{
- halfword p;
- internal_font_number f;
- if (tail != head)
- {
- if ((tail >= hi_mem_min))
- p = tail;
- else if (mem[tail].hh.b0 == 6)
- p = tail + 1;
- else return;
- f = mem[p].hh.b0;
- {
- mem[tail].hh.v.RH = new_kern(font_info[italic_base[f] + (font_info[char_base[f] + mem[p].hh.b1].qqqq.b2) / 4].cint);
- tail = mem[tail].hh.v.RH;
- }
- mem[tail].hh.b1 = 1;
- }
-}
-/* sec 1117 */
-void append_discretionary (void)
-{
- integer c;
- {
- mem[tail].hh.v.RH = new_disc();
- tail = mem[tail].hh.v.RH;
- }
- if (cur_chr == 1) {
- c = hyphen_char[eqtb[(hash_size + 1834)].hh.v.RH];
- if (c >= 0)
- if (c < 256)
- mem[tail + 1].hh.v.LH = new_character(eqtb[(hash_size + 1834)].hh.v.RH, c);
- } else {
- incr(save_ptr);
- save_stack[save_ptr - 1].cint = 0;
- new_save_level(10);
- scan_left_brace();
- push_nest();
- mode = -102;
- space_factor = 1000;
- }
-}
-/* only called form tex8.c */
-/* sec 1119 */
-void build_discretionary (void)
-{/* 30 10 */
- halfword p, q;
- integer n;
- unsave();
- q = head;
- p = mem[q].hh.v.RH;
- n = 0;
- while (p != 0) {
- if (!(p >= hi_mem_min))
- if (mem[p].hh.b0 > 2)
- if (mem[p].hh.b0 != 11)
- if (mem[p].hh.b0 != 6)
- {
- print_err("Improper discretionary list");
- help1("Discretionary lists must contain only boxes and kerns.");
- error();
- begin_diagnostic();
- print_nl("The following discretionary sublist has been deleted:");
- show_box(p);
- end_diagnostic(true);
- flush_node_list(p);
- mem[q].hh.v.RH = 0;
- goto lab30;
- }
- q = p;
- p = mem[q].hh.v.RH;
- incr(n);
- }
-lab30:;
- p = mem[head].hh.v.RH;
- pop_nest();
- switch (save_stack[save_ptr - 1].cint)
- {
- case 0:
- mem[tail + 1].hh.v.LH = p;
- break;
- case 1:
- mem[tail + 1].hh.v.RH = p;
- break;
- case 2:
- {
- if ((n > 0) && (abs(mode)== 203))
- {
- print_err("Illegal math ");
- print_esc("discretionary");
- help2("Sorry: The third part of a discretionary break must be",
- "empty, in math formulas. I had to delete your third part.");
- flush_node_list(p);
- n = 0;
- error();
- } else mem[tail].hh.v.RH = p;
-/* if n <= max_quarterword then replace_count(tail) <- n; p.1120 */
-/* if (n <= 255) */ /* 94/Apr/4 ? */
- if (n <= max_quarterword) /* 96/Oct/12 ??? */
- mem[tail].hh.b1 = n;
- else {
- print_err("Discretionary list is too long");
- help2("Wow---I never thought anybody would tweak me here.",
- "You can't seriously need such a huge discretionary list?");
- error();
- }
- if (n > 0)
- tail = q;
- decr(save_ptr);
- return;
- }
- break;
- }
- incr(save_stack[save_ptr - 1].cint);
- new_save_level(10);
- scan_left_brace();
- push_nest();
- mode = -102;
- space_factor = 1000;
-}
-/* called only from tex8.c */
-/* sec 1123 */
-void make_accent (void)
-{
- real s, t;
- halfword p, q, r;
- internal_font_number f;
- scaled a, h, x, w, delta;
- ffourquarters i;
- scan_char_num();
- f = eqtb[(hash_size + 1834)].hh.v.RH;
- p = new_character(f, cur_val);
- if (p != 0)
- {
- x = font_info[5 + param_base[f]].cint;
- s = font_info[1 + param_base[f]].cint / ((double) 65536.0);
- a = font_info[width_base[f]+ font_info[char_base[f]+ mem[p]
- .hh.b1].qqqq.b0].cint;
- do_assignments();
- q = 0;
- f = eqtb[(hash_size + 1834)].hh.v.RH;
- if ((cur_cmd == 11)||(cur_cmd == 12)||(cur_cmd == 68))
- q = new_character(f, cur_chr);
- else if (cur_cmd == 16)
- {
- scan_char_num();
- q = new_character(f, cur_val);
- }
- else back_input();
- if (q != 0)
- {
- t = font_info[1 + param_base[f]].cint / ((double) 65536.0);
- i = font_info[char_base[f]+ mem[q].hh.b1].qqqq;
- w = font_info[width_base[f]+ i.b0].cint;
- h = font_info[height_base[f]+(i.b1)/ 16].cint;
- if (h != x)
- {
- p = hpack(p, 0, 1);
- mem[p + 4].cint = x - h;
- }
- delta = round((w - a)/ ((double) 2.0)+ h * t - x * s);
- r = new_kern(delta);
- mem[r].hh.b1 = 2;
- mem[tail].hh.v.RH = r;
- mem[r].hh.v.RH = p;
- tail = new_kern(- (integer) a - delta);
- mem[tail].hh.b1 = 2;
- mem[p].hh.v.RH = tail;
- p = q;
- }
- mem[tail].hh.v.RH = p;
- tail = p;
- space_factor = 1000;
- }
-}
-/* sec 1127 */
-void align_error (void)
-{
- if (abs(align_state) > 2) {
- print_err("Misplaced ");
- print_cmd_chr(cur_cmd, cur_chr);
- if (cur_tok == 1062) {
- help6("I can't figure out why you would want to use a tab mark",
- "here. If you just want an ampersand, the remedy is",
- "simple: Just type `I\\&' now. But if some right brace",
- "up above has ended a previous alignment prematurely,",
- "you're probably due for more error messages, and you",
- "might try typing `S' now just to see what is salvageable.");
- } else {
- help5("I can't figure out why you would want to use a tab mark",
- "or \\cr or \\span just now. If something like a right brace",
- "up above has ended a previous alignment prematurely,",
- "you're probably due for more error messages, and you",
- "might try typing `S' now just to see what is salvageable.");
- }
- error();
- } else {
- back_input();
- if (align_state < 0) {
- print_err("Missing { inserted");
- incr(align_state);
- cur_tok = 379; /* belowdisplayshortskip ? */
- } else {
- print_err("Missing } inserted");
- decr(align_state);
- cur_tok = 637;
- }
- help3("I've put in what seems to be necessary to fix",
- "the current column of the current alignment.",
- "Try to go on, since this might almost work.");
- ins_error();
- }
-}
-/* sec 1129 */
-void noalign_error (void)
-{
- print_err("Misplaced ");
- print_esc("noalign");
- help2("I expect to see \\noalign only after the \\cr of",
- "an alignment. Proceed, and I'll ignore this case.");
- error();
-}
-/* only called from tex8.c */
-/* sec 1129 */
-void omit_error (void)
-{
- print_err("Misplaced ");
- print_esc("omit");
- help2("I expect to see \\omit only after tab marks or the \\cr of",
- "an alignment. Proceed, and I'll ignore this case.");
- error();
-}
-/* sec 1131 */
-void do_endv (void)
-{
- if (cur_group == 6) {
- end_graf();
- if (fin_col ())
- fin_row();
- } else off_save();
-}
-/* only called form tex8.c */
-/* sec 1135 */
-void cs_error (void)
-{
- print_err("Extra ");
- print_esc("endcsname");
- help1("I'm ignoring this, since I wasn't doing a \\csname.");
- error();
-}
-/* sec 1136 */
-void push_math_(group_code c)
-{
- push_nest();
- mode = -203;
- cur_list.aux_field.cint = 0;
- new_save_level(c);
-}
-/* sec 1138 */
-void init_math (void)
-{
- scaled w;
- scaled l;
- scaled s;
- halfword p;
- halfword q;
- internal_font_number f;
- integer n;
- scaled v;
- scaled d;
- get_token();
- if ((cur_cmd == 3) && (mode > 0)) {
- if (head == tail) {
- pop_nest();
- w = -1073741823L; /* - (2^30 - 1) */
- } else {
- line_break(display_widow_penalty);
- v = mem[just_box + 4].cint + 2 * font_info[6 + param_base[eqtb[(hash_size + 1834)].hh.v.RH]].cint;
- w = -1073741823L; /* - (2^30 - 1) */
- p = mem[just_box + 5].hh.v.RH;
- while (p != 0) {
-lab21:
- if ((p >= hi_mem_min)) {
- f = mem[p].hh.b0;
- d = font_info[width_base[f]+ font_info[char_base[f]+ mem[p].hh.b1].qqqq.b0].cint;
- goto lab40;
- }
- switch (mem[p].hh.b0)
- {
- case 0:
- case 1:
- case 2:
- {
- d = mem[p + 1].cint;
- goto lab40;
- }
- break;
- case 6:
- {
- mem[lig_trick]= mem[p + 1];
- mem[lig_trick].hh.v.RH = mem[p].hh.v.RH;
- p = lig_trick;
- goto lab21;
- }
- break;
- case 11:
- case 9:
- d = mem[p + 1].cint;
- break;
- case 10:
- {
- q = mem[p + 1].hh.v.LH;
- d = mem[q + 1].cint;
- if (mem[just_box + 5].hh.b0 == 1) {
- if ((mem[just_box + 5].hh.b1 == mem[q].hh.b0) && (mem[q + 2].cint != 0))
- v = 1073741823L; /* - (2^30 - 1) */
- } else if (mem[just_box + 5].hh.b0 == 2) {
- if ((mem[just_box + 5].hh.b1 == mem[q].hh.b1) && (mem[q + 3].cint != 0))
- v = 1073741823L; /* - (2^30 - 1) */
- }
- if (mem[p].hh.b1 >= 100)
- goto lab40;
- }
- break;
- case 8:
- d = 0;
- break;
- default:
- d = 0;
- break;
- }
- if (v < 1073741823L) /* - (2^30 - 1) */
- v = v + d;
- goto lab45;
-lab40:
- if (v < 1073741823L) /* - (2^30 - 1) */
- {
- v = v + d;
- w = v;
- } else {
- w = 1073741823L; /* - (2^30 - 1) */
- goto lab30;
- }
-lab45:
- p = mem[p].hh.v.RH;
- }
-lab30:;
- }
- if (par_shape_ptr == 0)
- if ((hang_indent != 0) &&
- (((hang_after >= 0) &&
- (prev_graf + 2 > hang_after)) ||(prev_graf + 1 < - (integer) hang_after))) {
- l = hsize - abs(hang_indent);
- if (hang_indent > 0)
- s = hang_indent;
- else
- s = 0;
- } else {
- l = hsize;
- s = 0;
- }
- else {
- n = mem[par_shape_ptr].hh.v.LH;
- if (prev_graf + 2 >= n)
- p = par_shape_ptr + 2 * n;
- else
- p = par_shape_ptr + 2 *(prev_graf + 2);
- s = mem[p - 1].cint;
- l = mem[p].cint;
- }
- push_math(15);
- mode = 203;
- eq_word_define((hash_size + 3207), -1);
- eq_word_define((hash_size + 3743), w);
- eq_word_define((hash_size + 3744), l);
- eq_word_define((hash_size + 3745), s);
- if (every_display != 0)/* everydisplay */
- begin_token_list(every_display, 9);
- if (nest_ptr == 1) {
- build_page();
- }
- } else {
- back_input();
- {
- push_math(15);
- eq_word_define((hash_size + 3207), -1);
- if (every_math != 0)/* everymath */
- begin_token_list(every_math, 8);
- }
- }
-}
-/* sec 1142 */
-void start_eq_no (void)
-{
- save_stack[save_ptr + 0].cint = cur_chr;
- incr(save_ptr);
- {
- push_math(15);
- eq_word_define((hash_size + 3207), -1);
- if (every_math != 0)/* everymath */
- begin_token_list(every_math, 8);
- }
-}
-/* sec 1151 */
-void scan_math_(halfword p)
-{
- integer c;
-lab20:
- do {
- get_x_token();
- } while(!((cur_cmd != 10) && (cur_cmd != 0)));
-lab21:
- switch (cur_cmd)
- {
- case 11:
- case 12:
- case 68:
- {
- c = eqtb[(hash_size + 2907) + cur_chr].hh.v.RH;
- if (c == 32768L) {
- {
- cur_cs = cur_chr + 1;
- cur_cmd = eqtb[cur_cs].hh.b0;
- cur_chr = eqtb[cur_cs].hh.v.RH;
- x_token();
- back_input();
- }
- goto lab20;
- }
- }
- break;
- case 16:
- {
- scan_char_num();
- cur_chr = cur_val;
- cur_cmd = 68;
- goto lab21;
- }
- break;
- case 17:
- {
- scan_fifteen_bit_int();
- c = cur_val;
- }
- break;
- case 69:
- c = cur_chr;
- break;
- case 15:
- {
- scan_twenty_seven_bit_int();
- c = cur_val / 4096;
-/* c = cur_val >> 12; */
- }
- break;
- default:
- {
- back_input();
- scan_left_brace();
- save_stack[save_ptr + 0].cint = p;
- incr(save_ptr);
- push_math(9);
- return;
- }
- break;
- }
- mem[p].hh.v.RH = 1;
- mem[p].hh.b1 = c % 256;
-/* mem[p].hh.b1 = c & 255; */ /* last 8 bits */
- if ((c >= 28672) && /* 32768 - 4096 ??? if (c>=var_code) and ... */
- ((cur_fam >= 0) && (cur_fam < 16)))
- mem[p].hh.b0 = cur_fam;
- else
- mem[p].hh.b0 =(c / 256)% 16;
-/* else mem[p].hh.b0 =(c >> 8)& 15; */ /* 4 bits to left */
-}
-/* sec 1155 */
-void set_math_char_(integer c)
-{
- halfword p;
- if (c >= 32768L) {
- cur_cs = cur_chr + 1; /* ??? */
-/* cur_cmd = eqtb[eqtbextra + cur_cs].hh.b0; */ /* was wrong ??? */
- cur_cmd = eqtb[cur_cs].hh.b0;
-/* cur_chr = eqtb[cur_cs].hh.v.RH; */ /* should have been eqtbextra ? */
- cur_chr = eqtb[cur_cs].hh.v.RH;
- x_token();
- back_input();
- } else {
- p = new_noad();
- mem[p + 1].hh.v.RH = 1;
- mem[p + 1].hh.b1 = c % 256;
-/* mem[p + 1].hh.b1 = c & 255; */ /* last 8 bits */
- mem[p + 1].hh.b0 =(c / 256)% 16;
-/* mem[p + 1].hh.b0 =(c >> 8)& 15; */ /* 4 bits to left */
- if (c >= 28672) /* 32768 - 4096 ? */
- {
- if (((cur_fam >= 0) && (cur_fam < 16)))
- mem[p + 1].hh.b0 = cur_fam;
- mem[p].hh.b0 = 16;
- } else
- mem[p].hh.b0 = 16 +(c / 4096);
-/* else mem[p].hh.b0 = 16 +(c >> 12); */
- mem[tail].hh.v.RH = p;
- tail = p;
- }
-}
-/* sec 1159 */
-void math_limit_switch (void)
-{
- if (head != tail)
- if (mem[tail].hh.b0 == 17) {
- mem[tail].hh.b1 = cur_chr;
- return;
- }
- print_err("Limit controls must follow a math operator");
- help1("I'm ignoring this misplaced \\limits or \\nolimits command.");
- error();
-}
-/* sec 1160 */
-void scan_delimiter_(halfword p, bool r)
-{
- if (r) {
- scan_twenty_seven_bit_int();
- } else {
- do {
- get_x_token();
- } while (!((cur_cmd != 10) && (cur_cmd != 0)));
- switch (cur_cmd)
- {
- case 11:
- case 12:
- cur_val = eqtb[(hash_size + 3474) + cur_chr].cint;
- break;
- case 15:
- scan_twenty_seven_bit_int();
- break;
- default:
- cur_val = -1;
- break;
- }
- }
- if (cur_val < 0) {
- print_err("Missing delimiter (. inserted)");
- help6("I was expecting to see something like `(' or `\\{' or",
- "`\\}' here. If you typed, e.g., `{' instead of `\\{', you",
- "should probably delete the `{' by typing `1' now, so that",
- "braces don't get unbalanced. Otherwise just proceed.",
- "Acceptable delimiters are characters whose \\delcode is",
- "nonnegative, or you can use `\\delimiter <delimiter code>'.");
- back_error();
- cur_val = 0;
- }
-/* attempt to speed up - bkph */ /* is compiler smart enough already ? */
- mem[p].qqqq.b0 =(cur_val / 1048576L) % 16; /* 2^20 */
-/* mem[p].qqqq.b0 =(cur_val >> 20)& 15; */
- mem[p].qqqq.b1 =(cur_val / 4096) % 256;
-/* mem[p].qqqq.b1 =(cur_val >> 12)& 255; */
- mem[p].qqqq.b2 =(cur_val / 256) % 16;
-/* mem[p].qqqq.b2 =(cur_val >> 8)& 15; */
- mem[p].qqqq.b3 = cur_val % 256;
-/* mem[p].qqqq.b3 = cur_val & 255; */
-}
-/* sec 1163 */
-void math_radical (void)
-{
- {
- mem[tail].hh.v.RH = get_node(5);
- tail = mem[tail].hh.v.RH;
- }
- mem[tail].hh.b0 = 24;
- mem[tail].hh.b1 = 0;
- mem[tail + 1].hh = empty_field;
- mem[tail + 3].hh = empty_field;
- mem[tail + 2].hh = empty_field;
- scan_delimiter(tail + 4, true);
- scan_math(tail + 1);
-}
-/* sec 1165 */
-void math_ac (void)
-{
- if (cur_cmd == 45) {
- print_err("Please use ");
- print_esc("mathaccent");
- print_string(" for accents in math mode");
- help2("I'm changing \\accent to \\mathaccent here; wish me luck.",
- "(Accents are not the same in formulas as they are in text.)");
- error();
- }
- {
- mem[tail].hh.v.RH = get_node(5);
- tail = mem[tail].hh.v.RH;
- }
- mem[tail].hh.b0 = 28;
- mem[tail].hh.b1 = 0;
- mem[tail + 1].hh = empty_field;
- mem[tail + 3].hh = empty_field;
- mem[tail + 2].hh = empty_field;
- mem[tail + 4].hh.v.RH = 1;
- scan_fifteen_bit_int();
- mem[tail + 4].hh.b1 = cur_val % 256;
-/* mem[tail + 4].hh.b1 = cur_val & 255; */
- if ((cur_val >= 28672) && /* 32768 - 4096 ? */
- ((cur_fam >= 0) &&
- (cur_fam < 16)))
- mem[tail + 4].hh.b0 = cur_fam;
- else
- mem[tail + 4].hh.b0 =(cur_val / 256) % 16;
-/* else mem[tail + 4].hh.b0 =(cur_val >> 8)& 15; */
- scan_math(tail + 1);
-}
-/* sec 1172 */
-void append_choices (void)
-{
- {
- mem[tail].hh.v.RH = new_choice();
- tail = mem[tail].hh.v.RH;
- }
- incr(save_ptr);
- save_stack[save_ptr - 1].cint = 0;
- push_math(13);
- scan_left_brace();
-}
-/* sec 1184 */
-halfword fin_mlist_(halfword p)
-{
- register halfword Result;
- halfword q;
- if (cur_list.aux_field.cint != 0) {
- mem[cur_list.aux_field.cint + 3].hh.v.RH = 3;
- mem[cur_list.aux_field.cint + 3].hh.v.LH = mem[head].hh.v.RH;
- if (p == 0)
- q = cur_list.aux_field.cint;
- else {
- q = mem[cur_list.aux_field.cint + 2].hh.v.LH;
- if (mem[q].hh.b0 != 30) {
- confusion("right");
- return 0; // abort_flag set
- }
- mem[cur_list.aux_field.cint + 2].hh.v.LH = mem[q].hh.v.RH;
- mem[q].hh.v.RH = cur_list.aux_field.cint;
- mem[cur_list.aux_field.cint].hh.v.RH = p;
- }
- } else {
- mem[tail].hh.v.RH = p;
- q = mem[head].hh.v.RH;
- }
- pop_nest();
- Result = q;
- return Result;
-}
-/* sec 1174 */
-void build_choices (void)
-{
- halfword p;
- unsave();
- p = fin_mlist(0);
- switch (save_stack[save_ptr - 1].cint)
- {
- case 0:
- mem[tail + 1].hh.v.LH = p;
- break;
- case 1:
- mem[tail + 1].hh.v.RH = p;
- break;
- case 2:
- mem[tail + 2].hh.v.LH = p;
- break;
- case 3:
- {
- mem[tail + 2].hh.v.RH = p;
- decr(save_ptr);
- return;
- }
- break;
- }
- incr(save_stack[save_ptr - 1].cint);
- push_math(13);
- scan_left_brace();
-}
-/* sec 1176 */
-void sub_sup (void)
-{
-/* small_number t; */
- int t; /* 95/Jan/7 */
- halfword p;
- t = 0;
- p = 0;
- if (tail != head)
- if ((mem[tail].hh.b0 >= 16) && (mem[tail].hh.b0 < 30)) {
- p = tail + 2 + cur_cmd - 7;
- t = mem[p].hh.v.RH;
- }
- if ((p == 0)||(t != 0)) {
- {
- mem[tail].hh.v.RH = new_noad();
- tail = mem[tail].hh.v.RH;
- }
- p = tail + 2 + cur_cmd - 7;
- if (t != 0) {
- if (cur_cmd == 7) {
- print_err("Double superscript");
- help1("I treat `x^1^2' essentially like `x^1{}^2'.");
- } else {
- print_err("Double subscript");
- help1("I treat `x_1_2' essentially like `x_1{}_2'.");
- }
- error();
- }
- }
- scan_math(p);
-}
-/* used to continue here with math_fraction etc in tex7.c */
-/*****************************************************************************/
-/* moved down here to avoid pragma optimize questions 96/Sep/12 */
-/* sec 1086 */
-void package_(small_number c)
-{
- scaled h;
- halfword p;
- scaled d;
- d = box_max_depth;
- unsave();
- save_ptr = save_ptr - 3;
- if (mode == -102)
- cur_box = hpack(mem[head].hh.v.RH, save_stack[save_ptr + 2].cint, save_stack[save_ptr + 1].cint);
- else {
- cur_box = vpackage(mem[head].hh.v.RH, save_stack[save_ptr + 2].cint, save_stack[save_ptr + 1].cint, d);
- if (c == 4) {
- h = 0;
- p = mem[cur_box + 5].hh.v.RH;
- if (p != 0)
- if (mem[p].hh.b0 <= 2)
- h = mem[p + 3].cint;
- mem[cur_box + 2].cint = mem[cur_box + 2].cint - h + mem[cur_box + 3].cint;
- mem[cur_box + 3].cint = h;
- }
- }
- pop_nest();
- box_end(save_stack[save_ptr + 0].cint);
-}
-#pragma optimize ("", on) /* 96/Sep/12 */
-/****************************************************************************/
+/* Copyright 2014 Clerk Ma\r
+\r
+ This program is free software; you can redistribute it and/or modify\r
+ it under the terms of the GNU General Public License as published by\r
+ the Free Software Foundation; either version 2 of the License, or\r
+ (at your option) any later version.\r
+\r
+ This program is distributed in the hope that it will be useful, but\r
+ WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ General Public License for more details.\r
+\r
+ You should have received a copy of the GNU General Public License\r
+ along with this program; if not, write to the Free Software\r
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\r
+ 02110-1301 USA. */\r
+\r
+#define EXTERN extern\r
+\r
+#include "yandytex.h"\r
+\r
+/* sec 0994 */\r
+void build_page (void)\r
+{\r
+ pointer p;\r
+ pointer q, r;\r
+ integer b, c;\r
+ integer pi;\r
+ /* unsigned char n; */\r
+ unsigned int n;\r
+ scaled delta, h, w;\r
+\r
+ if ((link(contrib_head) == 0) || output_active)\r
+ return;\r
+\r
+ do\r
+ {\r
+continu:\r
+ p = link(contrib_head);\r
+\r
+ if (last_glue != max_halfword)\r
+ delete_glue_ref(last_glue);\r
+\r
+ last_penalty = 0;\r
+ last_kern = 0;\r
+\r
+ if (type(p) == glue_node)\r
+ {\r
+ last_glue = glue_ptr(p);\r
+ add_glue_ref(last_glue);\r
+ }\r
+ else\r
+ {\r
+ last_glue = max_halfword;\r
+\r
+ if (type(p) == penalty_node)\r
+ last_penalty = penalty(p);\r
+ else if (type(p) == kern_node)\r
+ last_kern = width(p);\r
+ }\r
+\r
+ switch (type(p))\r
+ {\r
+ case hlist_node:\r
+ case vlist_node:\r
+ case rule_node:\r
+ if (page_contents < box_there)\r
+ {\r
+ if (page_contents == 0)\r
+ freeze_page_specs(box_there);\r
+ else\r
+ page_contents = box_there;\r
+\r
+ q = new_skip_param(top_skip_code);\r
+\r
+ if (width(temp_ptr) > height(p))\r
+ width(temp_ptr) = width(temp_ptr) - height(p);\r
+ else\r
+ width(temp_ptr) = 0;\r
+\r
+ link(q) = p;\r
+ link(contrib_head) = q;\r
+ goto continu;\r
+ }\r
+ else\r
+ {\r
+ page_total = page_total + page_depth + height(p);\r
+ page_depth = depth(p);\r
+ goto contribute;\r
+ }\r
+ break;\r
+\r
+ case whatsit_node:\r
+ goto contribute;\r
+ break;\r
+\r
+ case glue_node:\r
+ if (page_contents < box_there)\r
+ goto done1;\r
+ else if (precedes_break(page_tail))\r
+ pi = 0;\r
+ else\r
+ goto update_heights;\r
+ break;\r
+\r
+ case kern_node:\r
+ if (page_contents < box_there)\r
+ goto done1;\r
+ else if (link(p) == 0)\r
+ return;\r
+ else if (type(link(p)) == glue_node)\r
+ pi = 0;\r
+ else\r
+ goto update_heights;\r
+ break;\r
+\r
+ case penalty_node:\r
+ if (page_contents < box_there)\r
+ goto done1;\r
+ else\r
+ pi = penalty(p);\r
+ break;\r
+\r
+ case mark_node:\r
+ goto contribute;\r
+ break;\r
+\r
+ case ins_node:\r
+ {\r
+ if (page_contents == 0)\r
+ freeze_page_specs(inserts_only);\r
+\r
+ n = subtype(p);\r
+ r = page_ins_head;\r
+\r
+ while (n >= subtype(link(r)))\r
+ r = link(r);\r
+\r
+ n = n;\r
+\r
+ if (subtype(r) != n)\r
+ {\r
+ q = get_node(page_ins_node_size);\r
+ link(q) = link(r);\r
+ link(r) = q;\r
+ r = q;\r
+ subtype(r) = n;\r
+ type(r) = inserting;\r
+ ensure_vbox(n);\r
+\r
+ if (box(n) == 0)\r
+ height(r) = 0;\r
+ else\r
+ height(r) = height(box(n)) + depth(box(n));\r
+\r
+ best_ins_ptr(r) = 0;\r
+ q = skip(n);\r
+\r
+ if (count(n) == 1000)\r
+ h = height(r);\r
+ else\r
+ h = x_over_n(height(r), 1000) * count(n);\r
+\r
+ page_goal = page_goal - h - width(q);\r
+ page_so_far[2 + stretch_order(q)] = page_so_far[2 + stretch_order(q)] + stretch(q);\r
+ page_shrink = page_shrink + shrink(q);\r
+\r
+ if ((shrink_order(q) != normal) && (shrink(q) != 0))\r
+ {\r
+ print_err("Infinite glue shrinkage inserted from ");\r
+ print_esc("skip");\r
+ print_int(n);\r
+ help3("The correction glue for page breaking with insertions",\r
+ "must have finite shrinkability. But you may proceed,",\r
+ "since the offensive shrinkability has been made finite.");\r
+ error();\r
+ }\r
+ }\r
+\r
+ if (type(r) == split_up)\r
+ insert_penalties = insert_penalties + float_cost(p);\r
+ else\r
+ {\r
+ last_ins_ptr(r) = p;\r
+ delta = page_goal - page_total - page_depth + page_shrink;\r
+\r
+ if (count(n) == 1000)\r
+ h = height(p);\r
+ else\r
+ h = x_over_n(height(p), 1000) * count(n);\r
+\r
+ if (((h <= 0) || (h <= delta)) && (height(p) + height(r) <= dimen(n)))\r
+ {\r
+ page_goal = page_goal - h;\r
+ height(r) = height(r) + height(p);\r
+ }\r
+ else\r
+ {\r
+ if (count(n) <= 0)\r
+ w = max_dimen;\r
+ else\r
+ {\r
+ w = page_goal - page_total - page_depth;\r
+\r
+ if (count(n) != 1000)\r
+ w = x_over_n(w, count(n)) * 1000;\r
+ }\r
+\r
+ if (w > dimen(n) - height(r))\r
+ w = dimen(n) - height(r);\r
+\r
+ q = vert_break(ins_ptr(p), w, depth(p));\r
+ height(r) = height(r) + best_height_plus_depth;\r
+\r
+#ifdef STAT\r
+ if (tracing_pages > 0)\r
+ {\r
+ begin_diagnostic();\r
+ print_nl("% split");\r
+ print_int(n);\r
+ prints(" to");\r
+ print_scaled(w);\r
+ print_char(',');\r
+ print_scaled(best_height_plus_depth);\r
+ prints(" p=");\r
+\r
+ if (q == 0)\r
+ print_int(eject_penalty);\r
+ else if (type(q) == penalty_node)\r
+ print_int(penalty(q));\r
+ else\r
+ print_char('0');\r
+\r
+ end_diagnostic(false);\r
+ }\r
+#endif\r
+ if (count(n) != 1000)\r
+ best_height_plus_depth = x_over_n(best_height_plus_depth, 1000) * count(n);\r
+\r
+ page_goal = page_goal - best_height_plus_depth;\r
+ type(r) = split_up;\r
+ broken_ptr(r) = q;\r
+ broken_ins(r) = p;\r
+\r
+ if (q == 0)\r
+ insert_penalties = insert_penalties + (eject_penalty);\r
+ else if (type(q) == penalty_node)\r
+ insert_penalties = insert_penalties + penalty(q);\r
+ }\r
+ }\r
+ goto contribute;\r
+ }\r
+ break;\r
+\r
+ default:\r
+ {\r
+ confusion("page");\r
+ return;\r
+ }\r
+ break;\r
+ }\r
+\r
+ if (pi < inf_penalty)\r
+ {\r
+ if (page_total < page_goal)\r
+ if ((page_so_far[3] != 0) || (page_so_far[4] != 0) || (page_so_far[5] != 0))\r
+ b = 0;\r
+ else\r
+ b = badness(page_goal - page_total, page_so_far[2]);\r
+ else if (page_total - page_goal > page_shrink)\r
+ b = awful_bad;\r
+ else\r
+ b = badness(page_total - page_goal, page_shrink);\r
+ \r
+ if (b < awful_bad)\r
+ if (pi <= eject_penalty)\r
+ c = pi; \r
+ else if (b < inf_bad)\r
+ c = b + pi + insert_penalties;\r
+ else\r
+ c = deplorable;\r
+ else\r
+ c = b;\r
+\r
+ if (insert_penalties >= 10000)\r
+ c = awful_bad;\r
+\r
+#ifdef STAT\r
+ if (tracing_pages > 0)\r
+ {\r
+ begin_diagnostic();\r
+ print_nl("%");\r
+ prints(" t=");\r
+ print_totals();\r
+ prints(" g=");\r
+ print_scaled(page_goal);\r
+ prints(" b=");\r
+\r
+ if (b == awful_bad)\r
+ print_char('*');\r
+ else\r
+ print_int(b);\r
+\r
+ prints(" p=");\r
+ print_int(pi);\r
+ prints(" c=");\r
+\r
+ if (c == awful_bad)\r
+ print_char('*');\r
+ else\r
+ print_int(c);\r
+\r
+ if (c <= least_page_cost)\r
+ print_char('#');\r
+\r
+ end_diagnostic(false);\r
+ }\r
+#endif\r
+\r
+ if (c <= least_page_cost)\r
+ {\r
+ best_page_break = p;\r
+ best_size = page_goal;\r
+ least_page_cost = c;\r
+ r = link(page_ins_head);\r
+\r
+ while (r != page_ins_head)\r
+ {\r
+ best_ins_ptr(r) = last_ins_ptr(r);\r
+ r = link(r);\r
+ }\r
+ }\r
+\r
+ if ((c == awful_bad) || (pi <= eject_penalty))\r
+ {\r
+ fire_up(p);\r
+\r
+ if (output_active)\r
+ return;\r
+\r
+ goto done;\r
+ }\r
+ }\r
+\r
+ if ((type(p) < glue_node) || (type(p) > kern_node))\r
+ goto contribute;\r
+\r
+update_heights:\r
+ if (type(p) == kern_node)\r
+ q = p;\r
+ else\r
+ {\r
+ q = glue_ptr(p);\r
+ page_so_far[2 + stretch_order(q)] = page_so_far[2 + stretch_order(q)] + stretch(q);\r
+ page_shrink = page_shrink + shrink(q);\r
+\r
+ if ((shrink_order(q) != normal) && (shrink(q) != 0))\r
+ {\r
+ print_err("Infinite glue shrinkage found on current page");\r
+ help4("The page about to be output contains some infinitely",\r
+ "shrinkable glue, e.g., `\\vss' or `\\vskip 0pt minus 1fil'.",\r
+ "Such glue doesn't belong there; but you can safely proceed,",\r
+ "since the offensive shrinkability has been made finite.");\r
+ error();\r
+ r = new_spec(q);\r
+ shrink_order(r) = normal;\r
+ delete_glue_ref(q);\r
+ glue_ptr(p) = r;\r
+ q = r;\r
+ }\r
+ }\r
+\r
+ page_total = page_total + page_depth + width(q);\r
+ page_depth = 0;\r
+\r
+contribute:\r
+ if (page_depth > page_max_depth)\r
+ {\r
+ page_total = page_total + page_depth - page_max_depth;\r
+ page_depth = page_max_depth;\r
+ }\r
+\r
+ link(page_tail) = p;\r
+ page_tail = p;\r
+ link(contrib_head) = link(p);\r
+ link(p) = 0;\r
+ goto done;\r
+\r
+done1:\r
+ link(contrib_head) = link(p);\r
+ link(p) = 0;\r
+ flush_node_list(p);\r
+done:;\r
+ }\r
+ while (!(link(contrib_head) == 0));\r
+\r
+ if (nest_ptr == 0)\r
+ tail = contrib_head;\r
+ else\r
+ nest[0].tail_field = contrib_head;\r
+} \r
+/* sec 1043 */\r
+void app_space (void)\r
+{\r
+ pointer q;\r
+\r
+ if ((space_factor >= 2000) && (xspace_skip != zero_glue))\r
+ q = new_param_glue(xspace_skip_code);\r
+ else\r
+ {\r
+ if (space_skip != zero_glue)\r
+ main_p = space_skip;\r
+ else\r
+ {\r
+ main_p = font_glue[cur_font];\r
+\r
+ if (main_p == 0)\r
+ {\r
+ main_p = new_spec(zero_glue);\r
+ main_k = param_base[cur_font] + space_code;\r
+ width(main_p) = font_info[main_k].cint;\r
+ stretch(main_p) = font_info[main_k + 1].cint;\r
+ shrink(main_p) = font_info[main_k + 2].cint;\r
+ font_glue[cur_font] = main_p;\r
+ }\r
+ }\r
+\r
+ main_p = new_spec(main_p);\r
+\r
+ if (space_factor >= 2000)\r
+ width(main_p) = width(main_p) + extra_space(cur_font);\r
+\r
+ stretch(main_p) = xn_over_d(stretch(main_p), space_factor, 1000);\r
+ shrink(main_p) = xn_over_d(shrink(main_p), 1000, space_factor);\r
+ q = new_glue(main_p);\r
+ glue_ref_count(main_p) = 0;\r
+ }\r
+\r
+ link(tail) = q;\r
+ tail = q;\r
+}\r
+/* sec 1047 */\r
+void insert_dollar_sign (void)\r
+{\r
+ back_input();\r
+ cur_tok = math_shift_token + '$';\r
+ print_err("Missing $ inserted");\r
+ help2("I've inserted a begin-math/end-math symbol since I think",\r
+ "you left one out. Proceed, with fingers crossed.");\r
+ ins_error();\r
+}\r
+/* sec 1049 */\r
+void you_cant (void)\r
+{\r
+ print_err("You can't use `");\r
+ print_cmd_chr(cur_cmd, cur_chr);\r
+ prints("' in ");\r
+ print_mode(mode);\r
+}\r
+/* sec 1050 */\r
+void report_illegal_case (void)\r
+{\r
+ you_cant();\r
+ help4("Sorry, but I'm not programmed to handle this case;",\r
+ "I'll just pretend that you didn't ask for it.",\r
+ "If you're in the wrong mode, you might be able to",\r
+ "return to the right one by typing `I}' or `I$' or `I\\par'.");\r
+ error();\r
+}\r
+/* sec 1051 */\r
+boolean privileged (void)\r
+{\r
+ if (mode > 0)\r
+ return true;\r
+ else\r
+ {\r
+ report_illegal_case();\r
+ return false;\r
+ }\r
+}\r
+/* sec 1054 */\r
+boolean its_all_over (void)\r
+{\r
+ if (privileged())\r
+ {\r
+ if ((page_head == page_tail) && (head == tail) && (dead_cycles == 0))\r
+ {\r
+ return true;\r
+ }\r
+\r
+ back_input();\r
+ tail_append(new_null_box());\r
+ width(tail) = hsize;\r
+ tail_append(new_glue(fill_glue));\r
+ tail_append(new_penalty(-1073741824L));\r
+ build_page();\r
+ }\r
+\r
+ return false;\r
+}\r
+/* sec 1060 */\r
+void append_glue (void)\r
+{\r
+ small_number s;\r
+\r
+ s = cur_chr;\r
+\r
+ switch (s)\r
+ {\r
+ case fil_code:\r
+ cur_val = fil_glue;\r
+ break;\r
+\r
+ case fill_code:\r
+ cur_val = fill_glue;\r
+ break;\r
+\r
+ case ss_code:\r
+ cur_val = ss_glue;\r
+ break;\r
+\r
+ case fil_neg_code:\r
+ cur_val = fil_neg_glue;\r
+ break;\r
+\r
+ case skip_code:\r
+ scan_glue(glue_val);\r
+ break;\r
+\r
+ case mskip_code:\r
+ scan_glue(mu_val);\r
+ break;\r
+ }\r
+\r
+ tail_append(new_glue(cur_val));\r
+\r
+ if (s >= skip_code)\r
+ {\r
+ decr(glue_ref_count(cur_val));\r
+\r
+ if (s > skip_code)\r
+ subtype(tail) = mu_glue;\r
+ }\r
+}\r
+/* sec 1061 */\r
+void append_kern (void)\r
+{ \r
+ quarterword s;\r
+\r
+ s = cur_chr;\r
+\r
+ scan_dimen((s == mu_glue), false, false);\r
+ tail_append(new_kern(cur_val));\r
+ subtype(tail) = s;\r
+}\r
+/* sec 1064 */\r
+void off_save (void)\r
+{\r
+ pointer p;\r
+\r
+ if (cur_group == bottom_level)\r
+ {\r
+ print_err("Extra ");\r
+ print_cmd_chr(cur_cmd, cur_chr);\r
+ help1("Things are pretty mixed up, but I think the worst is over.");\r
+ error();\r
+ }\r
+ else\r
+ {\r
+ back_input();\r
+ p = get_avail();\r
+ link(temp_head) = p;\r
+ print_err("Missing ");\r
+\r
+ switch (cur_group)\r
+ {\r
+ case semi_simple_group:\r
+ {\r
+ info(p) = cs_token_flag + frozen_end_group;\r
+ print_esc("endgroup");\r
+ }\r
+ break;\r
+\r
+ case math_shift_group:\r
+ {\r
+ info(p) = math_shift_token + '$';\r
+ print_char('$');\r
+ }\r
+ break;\r
+\r
+ case math_left_group:\r
+ {\r
+ info(p) = cs_token_flag + frozen_right;\r
+ link(p) = get_avail();\r
+ p = link(p);\r
+ info(p) = other_token + '.';\r
+ print_esc("right.");\r
+ }\r
+ break;\r
+\r
+ default:\r
+ {\r
+ info(p) = right_brace_token + '}';\r
+ print_char('}');\r
+ }\r
+ break;\r
+ }\r
+\r
+ prints(" inserted");\r
+ ins_list(link(temp_head));\r
+ help5("I've inserted something that you may have forgotten.",\r
+ "(See the <inserted text> above.)",\r
+ "With luck, this will get me unwedged. But if you",\r
+ "really didn't forget anything, try typing `2' now; then",\r
+ "my insertion and my current dilemma will both disappear.");\r
+ error();\r
+ }\r
+}\r
+/* sec 1069 */\r
+void extra_right_brace (void)\r
+{\r
+ print_err("Extra }, or forgotten ");\r
+\r
+ switch (cur_group)\r
+ {\r
+ case semi_simple_group:\r
+ print_esc("endgroup");\r
+ break;\r
+\r
+ case math_shift_group:\r
+ print_char('$');\r
+ break;\r
+\r
+ case math_left_group:\r
+ print_esc("right");\r
+ break;\r
+ }\r
+\r
+ help5("I've deleted a group-closing symbol because it seems to be",\r
+ "spurious, as in `$x}$'. But perhaps the } is legitimate and",\r
+ "you forgot something else, as in `\\hbox{$x}'. In such cases",\r
+ "the way to recover is to insert both the forgotten and the",\r
+ "deleted material, e.g., by typing `I$}'.");\r
+ error();\r
+ incr(align_state);\r
+}\r
+/* sec 1070 */\r
+void normal_paragraph (void)\r
+{\r
+ if (looseness != 0)\r
+ eq_word_define(int_base + looseness_code, 0);\r
+\r
+ if (hang_indent != 0)\r
+ eq_word_define(dimen_base + hang_indent_code, 0);\r
+\r
+ if (hang_after != 1)\r
+ eq_word_define(int_base + hang_after_code, 1);\r
+\r
+ if (par_shape_ptr != 0)\r
+ eq_define(par_shape_loc, shape_ref, 0);\r
+}\r
+/* sec 1075 */\r
+void box_end (integer box_context)\r
+{\r
+ pointer p;\r
+\r
+ if (box_context < box_flag)\r
+ {\r
+ if (cur_box != 0)\r
+ {\r
+ shift_amount(cur_box) = box_context;\r
+\r
+ if (abs(mode) == vmode)\r
+ {\r
+ append_to_vlist(cur_box);\r
+\r
+ if (adjust_tail != 0)\r
+ {\r
+ if (adjust_head != adjust_tail)\r
+ {\r
+ link(tail) = link(adjust_head);\r
+ tail = adjust_tail;\r
+ }\r
+\r
+ adjust_tail = 0;\r
+ }\r
+\r
+ if (mode > 0)\r
+ build_page();\r
+ }\r
+ else\r
+ {\r
+ if (abs(mode) == hmode)\r
+ space_factor = 1000;\r
+ else\r
+ {\r
+ p = new_noad();\r
+ math_type(nucleus(p)) = sub_box;\r
+ info(nucleus(p)) = cur_box;\r
+ cur_box = p;\r
+ }\r
+\r
+ link(tail) = cur_box;\r
+ tail = cur_box;\r
+ }\r
+ }\r
+ }\r
+ else if (box_context < ship_out_flag)\r
+ if (box_context < (box_flag + 256))\r
+ eq_define((box_base - box_flag) + box_context, box_ref, cur_box);\r
+ else\r
+ geq_define((box_base - box_flag - 256) + box_context, box_ref, cur_box);\r
+ else if (cur_box != 0)\r
+ if (box_context > ship_out_flag)\r
+ {\r
+ do\r
+ {\r
+ get_x_token();\r
+ }\r
+ while (!((cur_cmd != spacer) && (cur_cmd != relax)));\r
+\r
+ if (((cur_cmd == hskip) && (abs(mode) != vmode)) || ((cur_cmd == vskip) && (abs(mode) == vmode)))\r
+ {\r
+ append_glue();\r
+ subtype(tail) = box_context - (leader_flag - a_leaders);\r
+ leader_ptr(tail) = cur_box;\r
+ }\r
+ else\r
+ {\r
+ print_err("Leaders not followed by proper glue");\r
+ help3("You should say `\\leaders <box or rule><hskip or vskip>'.",\r
+ "I found the <box or rule>, but there's no suitable",\r
+ "<hskip or vskip>, so I'm ignoring these leaders.");\r
+ back_error();\r
+ flush_node_list(cur_box);\r
+ }\r
+ }\r
+ else\r
+ ship_out(cur_box);\r
+}\r
+/* sec 1079 */\r
+void begin_box (integer box_context)\r
+{\r
+ pointer p, q;\r
+ quarterword m;\r
+ halfword k;\r
+ eight_bits n;\r
+\r
+ switch (cur_chr)\r
+ {\r
+ case box_code:\r
+ {\r
+ scan_eight_bit_int();\r
+ cur_box = box(cur_val);\r
+ box(cur_val) = 0;\r
+ }\r
+ break;\r
+\r
+ case copy_code:\r
+ {\r
+ scan_eight_bit_int();\r
+ cur_box = copy_node_list(box(cur_val));\r
+ }\r
+ break;\r
+\r
+ case last_box_code:\r
+ {\r
+ cur_box = 0;\r
+\r
+ if (abs(mode) == mmode)\r
+ {\r
+ you_cant();\r
+ help1("Sorry; this \\lastbox will be void.");\r
+ error();\r
+ }\r
+ else if ((mode == vmode) && (head == cur_list.tail_field))\r
+ {\r
+ you_cant();\r
+ help2("Sorry...I usually can't take things from the current page.",\r
+ "This \\lastbox will therefore be void.");\r
+ error();\r
+ }\r
+ else\r
+ {\r
+ if (!is_char_node(tail))\r
+ if ((type(tail) == hlist_node) || (type(tail) == vlist_node))\r
+ {\r
+ q = head;\r
+\r
+ do\r
+ {\r
+ p = q;\r
+\r
+ if (!is_char_node(q))\r
+ if (type(q) == disc_node)\r
+ {\r
+ for (m = 1; m <= replace_count(q); m++)\r
+ p = link(p);\r
+\r
+ if (p == tail)\r
+ goto done;\r
+ }\r
+\r
+ q = link(p);\r
+ }\r
+ while (!(q == tail));\r
+\r
+ cur_box = tail;\r
+ shift_amount(cur_box) = 0;\r
+ tail = p;\r
+ link(p) = 0;\r
+done:;\r
+ }\r
+ }\r
+ }\r
+ break;\r
+\r
+ case vsplit_code:\r
+ {\r
+ scan_eight_bit_int();\r
+ n = cur_val;\r
+\r
+ if (!scan_keyword("to"))\r
+ {\r
+ print_err("Missing `to' inserted");\r
+ help2("I'm working on `\\vsplit<box number> to <dimen>';",\r
+ "will look for the <dimen> next.");\r
+ error();\r
+ }\r
+\r
+ scan_dimen(false, false, false);\r
+ cur_box = vsplit(n, cur_val);\r
+ }\r
+ break;\r
+\r
+ default:\r
+ {\r
+ k = cur_chr - vtop_code;\r
+ saved(0) = box_context;\r
+\r
+ if (k == hmode)\r
+ if ((box_context < box_flag) && (abs(mode) == vmode))\r
+ scan_spec(adjust_hbox_group, true);\r
+ else\r
+ scan_spec(hbox_group, true);\r
+ else\r
+ {\r
+ if (k == vmode)\r
+ scan_spec(vbox_group, true);\r
+ else\r
+ {\r
+ scan_spec(vtop_group, true);\r
+ k = vmode;\r
+ }\r
+\r
+ normal_paragraph();\r
+ }\r
+\r
+ push_nest();\r
+ mode = - (integer) k;\r
+\r
+ if (k == vmode)\r
+ {\r
+ prev_depth = ignore_depth;\r
+\r
+ if (every_vbox != 0)\r
+ begin_token_list(every_vbox, every_vbox_text);\r
+ }\r
+ else\r
+ {\r
+ space_factor = 1000;\r
+\r
+ if (every_hbox != 0)\r
+ begin_token_list(every_hbox, every_vbox_text);\r
+ }\r
+\r
+ return;\r
+ }\r
+ break;\r
+ }\r
+\r
+ box_end(box_context);\r
+}\r
+/* sec 1084 */\r
+void scan_box_(integer box_context)\r
+{\r
+ do\r
+ {\r
+ get_x_token(); \r
+ }\r
+ while (!((cur_cmd != spacer) && (cur_cmd != relax)));\r
+\r
+ if (cur_cmd == make_box)\r
+ {\r
+ begin_box(box_context);\r
+ }\r
+ else if ((box_context >= leader_flag) && ((cur_cmd == hrule) || (cur_cmd == vrule)))\r
+ {\r
+ cur_box = scan_rule_spec();\r
+ box_end(box_context);\r
+ }\r
+ else\r
+ {\r
+ print_err("A <box> was supposed to be here");\r
+ help3("I was expecting to see \\hbox or \\vbox or \\copy or \\box or",\r
+ "something like that. So you might find something missing in",\r
+ "your output. But keep trying; you can fix this later.");\r
+ back_error();\r
+ }\r
+}\r
+/* sec 1091 */\r
+small_number norm_min (integer h)\r
+{\r
+ if (h <= 0)\r
+ return 1;\r
+ else if (h >= 63)\r
+ return 63;\r
+ else\r
+ return h;\r
+}\r
+/* sec 1091 */\r
+void new_graf (boolean indented)\r
+{\r
+ prev_graf = 0;\r
+\r
+ if ((mode == vmode) || (head != tail))\r
+ tail_append(new_param_glue(par_skip_code));\r
+\r
+ push_nest();\r
+ mode = hmode;\r
+ space_factor = 1000;\r
+ set_cur_lang();\r
+ clang = cur_lang;\r
+ prev_graf = (norm_min(left_hyphen_min) * 64 + norm_min(right_hyphen_min)) * 65536L + cur_lang;\r
+\r
+ if (indented)\r
+ {\r
+ tail = new_null_box();\r
+ link(head) = tail;\r
+ width(tail) = par_indent;\r
+ }\r
+\r
+ if (every_par != 0)\r
+ begin_token_list(every_par, every_par_text);\r
+\r
+ if (nest_ptr == 1)\r
+ build_page();\r
+}\r
+/* sec 1093 */\r
+void indent_in_hmode (void)\r
+{\r
+ pointer p, q;\r
+\r
+ if (cur_chr > 0)\r
+ {\r
+ p = new_null_box();\r
+ width(p) = par_indent;\r
+\r
+ if (abs(mode) == hmode)\r
+ space_factor = 1000;\r
+ else\r
+ {\r
+ q = new_noad();\r
+ math_type(nucleus(q)) = sub_box;\r
+ info(nucleus(q)) = p;\r
+ p = q;\r
+ }\r
+\r
+ tail_append(p);\r
+ }\r
+}\r
+/* sec 1095 */\r
+void head_for_vmode (void)\r
+{\r
+ if (mode < 0)\r
+ {\r
+ if (cur_cmd != hrule)\r
+ off_save();\r
+ else\r
+ {\r
+ print_err("You can't use `");\r
+ print_esc("hrule");\r
+ prints("' here except with leaders");\r
+ help2("To put a horizontal rule in an hbox or an alignment,",\r
+ "you should use \\leaders or \\hrulefill (see The TeXbook).");\r
+ error();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ back_input();\r
+ cur_tok = par_token;\r
+ back_input();\r
+ index = inserted;\r
+ }\r
+}\r
+/* sec 1096 */\r
+void end_graf (void)\r
+{\r
+ if (mode == hmode)\r
+ {\r
+ if (head == tail)\r
+ pop_nest();\r
+ else\r
+ line_break(widow_penalty);\r
+\r
+ normal_paragraph();\r
+ error_count = 0;\r
+ }\r
+}\r
+/* sec 1099 */\r
+void begin_insert_or_adjust (void)\r
+{\r
+ if (cur_cmd == vadjust)\r
+ cur_val = 255;\r
+ else\r
+ {\r
+ scan_eight_bit_int();\r
+\r
+ if (cur_val == 255)\r
+ {\r
+ print_err("You can't ");\r
+ print_esc("insert");\r
+ print_int(255);\r
+ help1("I'm changing to \\insert0; box 255 is special.");\r
+ error();\r
+ cur_val = 0;\r
+ }\r
+ }\r
+\r
+ saved(0) = cur_val;\r
+ incr(save_ptr);\r
+ new_save_level(insert_group);\r
+ scan_left_brace();\r
+ normal_paragraph();\r
+ push_nest();\r
+ mode = -vmode;\r
+ prev_depth = ignore_depth;\r
+}\r
+/* sec 1101 */\r
+void make_mark (void)\r
+{\r
+ pointer p;\r
+\r
+ p = scan_toks(false, true);\r
+ p = get_node(small_node_size);\r
+ type(p) = mark_node;\r
+ subtype(p) = 0;\r
+ mark_ptr(p) = def_ref;\r
+ link(tail) = p;\r
+ tail = p;\r
+}\r
+/* sec 1103 */\r
+void append_penalty (void)\r
+{\r
+ scan_int();\r
+ tail_append(new_penalty(cur_val));\r
+\r
+ if (mode == vmode)\r
+ build_page();\r
+}\r
+/* sec 1105 */\r
+void delete_last (void)\r
+{\r
+ pointer p, q;\r
+ quarterword m;\r
+\r
+ if ((mode == vmode) && (tail == head))\r
+ {\r
+ if ((cur_chr != glue_node) || (last_glue != max_halfword))\r
+ {\r
+ you_cant();\r
+ help2("Sorry...I usually can't take things from the current page.",\r
+ "Try `I\\vskip-\\lastskip' instead.");\r
+\r
+ if (cur_chr == kern_node)\r
+ help_line[0] = "Try `I\\kern-\\last_kern' instead.";\r
+ else if (cur_chr != glue_node)\r
+ help_line[0] = "Perhaps you can make the output routine do it.";\r
+ error();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if (!is_char_node(tail))\r
+ if (type(tail) == cur_chr)\r
+ {\r
+ q = head;\r
+\r
+ do\r
+ {\r
+ p = q;\r
+\r
+ if (!is_char_node(q))\r
+ if (type(q) == disc_node)\r
+ {\r
+ for (m = 1; m <= replace_count(q); m++)\r
+ p = link(p);\r
+\r
+ if (p == tail)\r
+ return;\r
+ }\r
+\r
+ q = link(p);\r
+ }\r
+ while (!(q == tail));\r
+\r
+ link(p) = 0;\r
+ flush_node_list(tail);\r
+ tail = p;\r
+ }\r
+ }\r
+}\r
+/* sec 1110 */\r
+void unpackage (void)\r
+{\r
+ pointer p;\r
+ char c;\r
+\r
+ c = cur_chr;\r
+ scan_eight_bit_int();\r
+ p = box(cur_val);\r
+\r
+ if (p == 0)\r
+ return;\r
+\r
+ if ((abs(mode) == mmode) || ((abs(mode) == vmode) && (type(p) != vlist_node)) ||\r
+ ((abs(mode) == hmode) && (type(p) != hlist_node)))\r
+ {\r
+ print_err("Incompatible list can't be unboxed");\r
+ help3("Sorry, Pandora. (You sneaky devil.)",\r
+ "I refuse to unbox an \\hbox in vertical mode or vice versa.",\r
+ "And I can't open any boxes in math mode.");\r
+ error();\r
+ return;\r
+ }\r
+\r
+ if (c == copy_code)\r
+ link(tail) = copy_node_list(list_ptr(p));\r
+ else\r
+ {\r
+ link(tail) = list_ptr(p);\r
+ box(cur_val) = 0;\r
+ free_node(p, box_node_size);\r
+ }\r
+\r
+ while (link(tail) != 0)\r
+ tail = link(tail);\r
+}\r
+/* sec 1113 */\r
+void append_italic_correction (void)\r
+{\r
+ pointer p;\r
+ internal_font_number f;\r
+\r
+ if (tail != head)\r
+ {\r
+ if (is_char_node(tail))\r
+ p = tail;\r
+ else if (type(tail) == ligature_node)\r
+ p = tail + 1;\r
+ else\r
+ return;\r
+\r
+ f = font(p);\r
+ tail_append(new_kern(char_italic(f, char_info(f, character(p)))));\r
+ subtype(tail) = explicit;\r
+ }\r
+}\r
+/* sec 1117 */\r
+void append_discretionary (void)\r
+{\r
+ integer c;\r
+\r
+ tail_append(new_disc());\r
+\r
+ if (cur_chr == 1)\r
+ {\r
+ c = hyphen_char[cur_font];\r
+\r
+ if (c >= 0)\r
+ if (c < 256)\r
+ pre_break(tail) = new_character(cur_font, c);\r
+ }\r
+ else\r
+ {\r
+ incr(save_ptr);\r
+ saved(-1) = 0;\r
+ new_save_level(disc_group);\r
+ scan_left_brace();\r
+ push_nest();\r
+ mode = -hmode;\r
+ space_factor = 1000;\r
+ }\r
+}\r
+/* sec 1119 */\r
+void build_discretionary (void)\r
+{\r
+ pointer p, q;\r
+ integer n;\r
+\r
+ unsave();\r
+ q = head;\r
+ p = link(q);\r
+ n = 0;\r
+\r
+ while (p != 0)\r
+ {\r
+ if (!is_char_node(p))\r
+ if (type(p) > rule_node)\r
+ if (type(p) != kern_node)\r
+ if (type(p) != ligature_node)\r
+ {\r
+ print_err("Improper discretionary list");\r
+ help1("Discretionary lists must contain only boxes and kerns.");\r
+ error();\r
+ begin_diagnostic();\r
+ print_nl("The following discretionary sublist has been deleted:");\r
+ show_box(p);\r
+ end_diagnostic(true);\r
+ flush_node_list(p);\r
+ link(q) = 0;\r
+ goto done;\r
+ }\r
+\r
+ q = p;\r
+ p = link(q);\r
+ incr(n);\r
+ }\r
+\r
+done:\r
+ p = link(head);\r
+ pop_nest();\r
+\r
+ switch (saved(-1))\r
+ {\r
+ case 0:\r
+ pre_break(tail) = p;\r
+ break;\r
+\r
+ case 1:\r
+ post_break(tail) = p;\r
+ break;\r
+\r
+ case 2:\r
+ {\r
+ if ((n > 0) && (abs(mode) == mmode))\r
+ {\r
+ print_err("Illegal math ");\r
+ print_esc("discretionary");\r
+ help2("Sorry: The third part of a discretionary break must be",\r
+ "empty, in math formulas. I had to delete your third part.");\r
+ flush_node_list(p);\r
+ n = 0;\r
+ error();\r
+ }\r
+ else\r
+ link(tail) = p;\r
+\r
+ if (n <= max_quarterword)\r
+ replace_count(tail) = n;\r
+ else\r
+ {\r
+ print_err("Discretionary list is too long");\r
+ help2("Wow---I never thought anybody would tweak me here.",\r
+ "You can't seriously need such a huge discretionary list?");\r
+ error();\r
+ }\r
+\r
+ if (n > 0)\r
+ tail = q;\r
+\r
+ decr(save_ptr);\r
+ return;\r
+ }\r
+ break;\r
+ }\r
+\r
+ incr(saved(-1));\r
+ new_save_level(disc_group);\r
+ scan_left_brace();\r
+ push_nest();\r
+ mode = -hmode;\r
+ space_factor = 1000;\r
+}\r
+/* sec 1123 */\r
+void make_accent (void)\r
+{\r
+ real s, t;\r
+ pointer p, q, r;\r
+ internal_font_number f;\r
+ scaled a, h, x, w, delta;\r
+ four_quarters i;\r
+\r
+ scan_char_num();\r
+ f = cur_font;\r
+ p = new_character(f, cur_val);\r
+\r
+ if (p != 0)\r
+ {\r
+ x = x_height(f);\r
+ s = slant(f) / ((double) 65536.0);\r
+ a = char_width(f, char_info(f, character(p)));\r
+ do_assignments();\r
+ q = 0;\r
+ f = cur_font;\r
+\r
+ if ((cur_cmd == letter) || (cur_cmd == other_char) || (cur_cmd == char_given))\r
+ q = new_character(f, cur_chr);\r
+ else if (cur_cmd == char_num)\r
+ {\r
+ scan_char_num();\r
+ q = new_character(f, cur_val);\r
+ }\r
+ else\r
+ back_input();\r
+\r
+ if (q != 0)\r
+ {\r
+ t = slant(f) / ((double) 65536.0);\r
+ i = char_info(f, character(q));\r
+ w = char_width(f, i);\r
+ h = char_height(f, height_depth(i));\r
+\r
+ if (h != x)\r
+ {\r
+ p = hpack(p, 0, 1);\r
+ shift_amount(p) = x - h;\r
+ }\r
+\r
+ delta = round((w - a) / ((double) 2.0) + h * t - x * s);\r
+ r = new_kern(delta);\r
+ subtype(r) = acc_kern;\r
+ link(tail) = r;\r
+ link(r) = p;\r
+ tail = new_kern(- (integer) a - delta);\r
+ subtype(tail) = acc_kern;\r
+ link(p) = tail;\r
+ p = q;\r
+ }\r
+\r
+ link(tail) = p;\r
+ tail = p;\r
+ space_factor = 1000;\r
+ }\r
+}\r
+/* sec 1127 */\r
+void align_error (void)\r
+{\r
+ if (abs(align_state) > 2)\r
+ {\r
+ print_err("Misplaced ");\r
+ print_cmd_chr(cur_cmd, cur_chr);\r
+\r
+ if (cur_tok == tab_token + '&')\r
+ {\r
+ help6("I can't figure out why you would want to use a tab mark",\r
+ "here. If you just want an ampersand, the remedy is",\r
+ "simple: Just type `I\\&' now. But if some right brace",\r
+ "up above has ended a previous alignment prematurely,",\r
+ "you're probably due for more error messages, and you",\r
+ "might try typing `S' now just to see what is salvageable.");\r
+ }\r
+ else\r
+ {\r
+ help5("I can't figure out why you would want to use a tab mark",\r
+ "or \\cr or \\span just now. If something like a right brace",\r
+ "up above has ended a previous alignment prematurely,",\r
+ "you're probably due for more error messages, and you",\r
+ "might try typing `S' now just to see what is salvageable.");\r
+ }\r
+\r
+ error();\r
+ }\r
+ else\r
+ {\r
+ back_input();\r
+\r
+ if (align_state < 0)\r
+ {\r
+ print_err("Missing { inserted");\r
+ incr(align_state);\r
+ cur_tok = left_brace_token + '{';\r
+ }\r
+ else\r
+ {\r
+ print_err("Missing } inserted");\r
+ decr(align_state);\r
+ cur_tok = right_brace_token + '}';\r
+ }\r
+\r
+ help3("I've put in what seems to be necessary to fix",\r
+ "the current column of the current alignment.",\r
+ "Try to go on, since this might almost work.");\r
+ ins_error();\r
+ }\r
+}\r
+/* sec 1129 */\r
+void noalign_error (void)\r
+{\r
+ print_err("Misplaced ");\r
+ print_esc("noalign");\r
+ help2("I expect to see \\noalign only after the \\cr of",\r
+ "an alignment. Proceed, and I'll ignore this case.");\r
+ error();\r
+}\r
+/* sec 1129 */\r
+void omit_error (void)\r
+{\r
+ print_err("Misplaced ");\r
+ print_esc("omit");\r
+ help2("I expect to see \\omit only after tab marks or the \\cr of",\r
+ "an alignment. Proceed, and I'll ignore this case.");\r
+ error();\r
+}\r
+/* sec 1131 */\r
+void do_endv (void)\r
+{\r
+ base_ptr = input_ptr;\r
+ input_stack[base_ptr] = cur_input;\r
+\r
+ while ((input_stack[base_ptr].index_field != v_template) &&\r
+ (input_stack[base_ptr].loc_field == 0) &&\r
+ (input_stack[base_ptr].state_field == token_list))\r
+ decr(base_ptr);\r
+\r
+ if ((input_stack[base_ptr].index_field != v_template) ||\r
+ (input_stack[base_ptr].loc_field != 0) ||\r
+ (input_stack[base_ptr].state_field != token_list))\r
+ fatal_error("(interwoven alignment preambles are not allowed)");\r
+\r
+ if (cur_group == align_group)\r
+ {\r
+ end_graf();\r
+\r
+ if (fin_col())\r
+ fin_row();\r
+ }\r
+ else\r
+ off_save();\r
+}\r
+/* sec 1135 */\r
+void cs_error (void)\r
+{\r
+ print_err("Extra ");\r
+ print_esc("endcsname");\r
+ help1("I'm ignoring this, since I wasn't doing a \\csname."); \r
+ error();\r
+}\r
+/* sec 1136 */\r
+void push_math (group_code c)\r
+{\r
+ push_nest();\r
+ mode = -mmode;\r
+ incompleat_noad = 0;\r
+ new_save_level(c);\r
+}\r
+/* sec 1138 */\r
+void init_math (void)\r
+{\r
+ scaled w;\r
+ scaled l;\r
+ scaled s;\r
+ pointer p;\r
+ pointer q;\r
+ internal_font_number f;\r
+ integer n;\r
+ scaled v;\r
+ scaled d;\r
+\r
+ get_token();\r
+\r
+ if ((cur_cmd == math_shift) && (mode > 0))\r
+ {\r
+ if (head == tail)\r
+ {\r
+ pop_nest();\r
+ w = -max_dimen;\r
+ }\r
+ else\r
+ {\r
+ line_break(display_widow_penalty);\r
+ v = shift_amount(just_box) + 2 * quad(cur_font);\r
+ w = -max_dimen;\r
+ p = list_ptr(just_box);\r
+\r
+ while (p != 0)\r
+ {\r
+reswitch:\r
+ if (is_char_node(p))\r
+ {\r
+ f = font(p);\r
+ d = char_width(f, char_info(f, character(p)));\r
+ goto found;\r
+ }\r
+\r
+ switch (type(p))\r
+ {\r
+ case hlist_node:\r
+ case vlist_node:\r
+ case rule_node:\r
+ {\r
+ d = width(p);\r
+ goto found;\r
+ }\r
+ break;\r
+\r
+ case ligature_node:\r
+ {\r
+ mem[lig_trick] = mem[lig_char(p)];\r
+ link(lig_trick) = link(p);\r
+ p = lig_trick;\r
+ goto reswitch;\r
+ }\r
+ break;\r
+\r
+ case kern_node:\r
+ case math_node:\r
+ d = width(p);\r
+ break;\r
+\r
+ case glue_node:\r
+ {\r
+ q = glue_ptr(p);\r
+ d = width(q);\r
+\r
+ if (glue_sign(just_box) == stretching)\r
+ {\r
+ if ((glue_order(just_box) == stretch_order(q)) && (stretch(q) != 0))\r
+ v = max_dimen;\r
+ }\r
+ else if (glue_sign(just_box) == shrinking)\r
+ {\r
+ if ((glue_order(just_box) == shrink_order(q)) && (shrink(q) != 0))\r
+ v = max_dimen;\r
+ }\r
+\r
+ if (subtype(p) >= a_leaders)\r
+ goto found;\r
+ }\r
+ break;\r
+\r
+ case whatsit_node:\r
+ d = 0;\r
+ break;\r
+\r
+ default:\r
+ d = 0;\r
+ break;\r
+ }\r
+\r
+ if (v < max_dimen)\r
+ v = v + d;\r
+\r
+ goto not_found;\r
+\r
+found:\r
+ if (v < max_dimen)\r
+ {\r
+ v = v + d;\r
+ w = v;\r
+ }\r
+ else\r
+ {\r
+ w = max_dimen;\r
+ goto done;\r
+ }\r
+\r
+not_found:\r
+ p = link(p);\r
+ }\r
+done:;\r
+ }\r
+\r
+ if (par_shape_ptr == 0)\r
+ if ((hang_indent != 0) && (((hang_after >= 0) &&\r
+ (prev_graf + 2 > hang_after)) || (prev_graf + 1 < - (integer) hang_after)))\r
+ {\r
+ l = hsize - abs(hang_indent);\r
+\r
+ if (hang_indent > 0)\r
+ s = hang_indent;\r
+ else\r
+ s = 0;\r
+ }\r
+ else\r
+ {\r
+ l = hsize;\r
+ s = 0;\r
+ }\r
+ else\r
+ {\r
+ n = info(par_shape_ptr);\r
+\r
+ if (prev_graf + 2 >= n)\r
+ p = par_shape_ptr + 2 * n;\r
+ else\r
+ p = par_shape_ptr + 2 * (prev_graf + 2);\r
+\r
+ s = mem[p - 1].cint;\r
+ l = mem[p].cint;\r
+ }\r
+\r
+ push_math(math_shift_group);\r
+ mode = mmode;\r
+ eq_word_define(int_base + cur_fam_code, -1);\r
+ eq_word_define(dimen_base + pre_display_size_code, w);\r
+ eq_word_define(dimen_base + display_width_code, l);\r
+ eq_word_define(dimen_base + display_indent_code, s);\r
+\r
+ if (every_display != 0)\r
+ begin_token_list(every_display, every_display_text);\r
+\r
+ if (nest_ptr == 1)\r
+ {\r
+ build_page();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ back_input();\r
+\r
+ {\r
+ push_math(math_shift_group);\r
+ eq_word_define(int_base + cur_fam_code, -1);\r
+\r
+ if (every_math != 0)\r
+ begin_token_list(every_math, every_math_text);\r
+ }\r
+ }\r
+}\r
+/* sec 1142 */\r
+void start_eq_no (void)\r
+{\r
+ saved(0) = cur_chr;\r
+ incr(save_ptr);\r
+\r
+ {\r
+ push_math(math_shift_group);\r
+ eq_word_define(int_base + cur_fam_code, -1);\r
+\r
+ if (every_math != 0)\r
+ begin_token_list(every_math, every_math_text);\r
+ }\r
+}\r
+/* sec 1151 */\r
+void scan_math (pointer p)\r
+{\r
+ integer c;\r
+\r
+restart:\r
+ do\r
+ {\r
+ get_x_token();\r
+ }\r
+ while (!((cur_cmd != spacer) && (cur_cmd != relax)));\r
+\r
+reswitch:\r
+ switch (cur_cmd)\r
+ {\r
+ case letter:\r
+ case other_char:\r
+ case char_given:\r
+ {\r
+ c = math_code(cur_chr);\r
+\r
+ if (c == 32768L)\r
+ {\r
+ {\r
+ cur_cs = cur_chr + active_base;\r
+ cur_cmd = eq_type(cur_cs);\r
+ cur_chr = equiv(cur_cs);\r
+ x_token();\r
+ back_input();\r
+ }\r
+\r
+ goto restart;\r
+ }\r
+ }\r
+ break;\r
+\r
+ case char_num:\r
+ {\r
+ scan_char_num();\r
+ cur_chr = cur_val;\r
+ cur_cmd = char_given;\r
+ goto reswitch;\r
+ }\r
+ break;\r
+\r
+ case math_char_num:\r
+ {\r
+ scan_fifteen_bit_int();\r
+ c = cur_val;\r
+ }\r
+ break;\r
+\r
+ case math_given:\r
+ c = cur_chr;\r
+ break;\r
+\r
+ case delim_num:\r
+ {\r
+ scan_twenty_seven_bit_int();\r
+ c = cur_val / 4096;\r
+ }\r
+ break;\r
+\r
+ default:\r
+ {\r
+ back_input();\r
+ scan_left_brace();\r
+ saved(0) = p;\r
+ incr(save_ptr);\r
+ push_math(math_group);\r
+ return;\r
+ }\r
+ break;\r
+ }\r
+\r
+ math_type(p) = math_char;\r
+ character(p) = c % 256;\r
+\r
+ if ((c >= var_code) && ((cur_fam >= 0) && (cur_fam < 16)))\r
+ fam(p) = cur_fam;\r
+ else\r
+ fam(p) = (c / 256) % 16;\r
+}\r
+/* sec 1155 */\r
+void set_math_char_(integer c)\r
+{\r
+ pointer p;\r
+\r
+ if (c >= 32768L)\r
+ {\r
+ cur_cs = cur_chr + active_base;\r
+ cur_cmd = eq_type(cur_cs);\r
+ cur_chr = equiv(cur_cs);\r
+ x_token();\r
+ back_input();\r
+ }\r
+ else\r
+ {\r
+ p = new_noad();\r
+ math_type(nucleus(p)) = math_char;\r
+ character(nucleus(p)) = c % 256;\r
+ fam(nucleus(p)) = (c / 256) % 16;\r
+\r
+ if (c >= var_code)\r
+ {\r
+ if (((cur_fam >= 0) && (cur_fam < 16)))\r
+ fam(nucleus(p)) = cur_fam;\r
+\r
+ type(p) = ord_noad;\r
+ }\r
+ else\r
+ type(p) = ord_noad + (c / 4096);\r
+\r
+ link(tail) = p;\r
+ tail = p;\r
+ }\r
+}\r
+/* sec 1159 */\r
+void math_limit_switch (void)\r
+{\r
+ if (head != tail)\r
+ if (type(tail) == op_noad)\r
+ {\r
+ subtype(tail) = cur_chr;\r
+ return;\r
+ }\r
+\r
+ print_err("Limit controls must follow a math operator");\r
+ help1("I'm ignoring this misplaced \\limits or \\nolimits command.");\r
+ error();\r
+}\r
+/* sec 1160 */\r
+void scan_delimiter_(pointer p, boolean r)\r
+{\r
+ if (r)\r
+ scan_twenty_seven_bit_int();\r
+ else\r
+ {\r
+ do\r
+ {\r
+ get_x_token();\r
+ }\r
+ while (!((cur_cmd != spacer) && (cur_cmd != relax)));\r
+\r
+ switch (cur_cmd)\r
+ {\r
+ case letter:\r
+ case other_char:\r
+ cur_val = del_code(cur_chr);\r
+ break;\r
+\r
+ case delim_num:\r
+ scan_twenty_seven_bit_int();\r
+ break;\r
+\r
+ default:\r
+ cur_val = -1;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (cur_val < 0)\r
+ {\r
+ print_err("Missing delimiter (. inserted)");\r
+ help6("I was expecting to see something like `(' or `\\{' or",\r
+ "`\\}' here. If you typed, e.g., `{' instead of `\\{', you",\r
+ "should probably delete the `{' by typing `1' now, so that",\r
+ "braces don't get unbalanced. Otherwise just proceed.",\r
+ "Acceptable delimiters are characters whose \\delcode is",\r
+ "nonnegative, or you can use `\\delimiter <delimiter code>'.");\r
+ back_error();\r
+ cur_val = 0;\r
+ }\r
+\r
+ small_fam(p) = (cur_val / 1048576L) % 16;\r
+ small_char(p) = (cur_val / 4096) % 256;\r
+ large_fam(p) = (cur_val / 256) % 16;\r
+ large_char(p) = cur_val % 256;\r
+}\r
+/* sec 1163 */\r
+void math_radical (void)\r
+{\r
+ tail_append(get_node(radical_noad_size));\r
+ type(tail) = radical_noad;\r
+ subtype(tail) = normal;\r
+ mem[nucleus(tail)].hh = empty_field;\r
+ mem[subscr(tail)].hh = empty_field;\r
+ mem[supscr(tail)].hh = empty_field;\r
+ scan_delimiter(left_delimiter(tail), true);\r
+ scan_math(nucleus(tail));\r
+}\r
+/* sec 1165 */\r
+void math_ac (void)\r
+{\r
+ if (cur_cmd == accent)\r
+ {\r
+ print_err("Please use ");\r
+ print_esc("mathaccent");\r
+ prints(" for accents in math mode");\r
+ help2("I'm changing \\accent to \\mathaccent here; wish me luck.",\r
+ "(Accents are not the same in formulas as they are in text.)");\r
+ error();\r
+ }\r
+\r
+ tail_append(get_node(accent_noad_size));\r
+ type(tail) = accent_noad;\r
+ subtype(tail) = normal;\r
+ mem[nucleus(tail)].hh = empty_field;\r
+ mem[subscr(tail)].hh = empty_field;\r
+ mem[supscr(tail)].hh = empty_field;\r
+ math_type(accent_chr(tail)) = math_char;\r
+ scan_fifteen_bit_int();\r
+ character(accent_chr(tail)) = cur_val % 256;\r
+\r
+ if ((cur_val >= var_code) && ((cur_fam >= 0) && (cur_fam < 16)))\r
+ fam(accent_chr(tail)) = cur_fam;\r
+ else\r
+ fam(accent_chr(tail)) = (cur_val / 256) % 16;\r
+\r
+ scan_math(nucleus(tail));\r
+}\r
+/* sec 1172 */\r
+void append_choices (void)\r
+{\r
+ tail_append(new_choice());\r
+ incr(save_ptr);\r
+ saved(-1) = 0;\r
+ push_math(math_choice_group);\r
+ scan_left_brace();\r
+}\r
+/* sec 1184 */\r
+pointer fin_mlist (pointer p)\r
+{\r
+ pointer q;\r
+\r
+ if (incompleat_noad != 0)\r
+ {\r
+ math_type(denominator(incompleat_noad)) = sub_mlist;\r
+ info(denominator(incompleat_noad)) = link(head);\r
+\r
+ if (p == 0)\r
+ q = incompleat_noad;\r
+ else\r
+ {\r
+ q = info(numerator(incompleat_noad));\r
+\r
+ if (type(q) != left_noad)\r
+ {\r
+ confusion("right");\r
+ return 0;\r
+ }\r
+\r
+ info(numerator(incompleat_noad)) = link(q);\r
+ link(q) = incompleat_noad;\r
+ link(incompleat_noad) = p;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ link(tail) = p;\r
+ q = link(head);\r
+ }\r
+\r
+ pop_nest();\r
+\r
+ return q;\r
+}\r
+/* sec 1174 */\r
+void build_choices (void)\r
+{\r
+ pointer p;\r
+\r
+ unsave();\r
+ p = fin_mlist(0);\r
+\r
+ switch (saved(-1))\r
+ {\r
+ case 0:\r
+ display_mlist(tail) = p;\r
+ break;\r
+\r
+ case 1:\r
+ text_mlist(tail) = p;\r
+ break;\r
+\r
+ case 2:\r
+ script_mlist(tail) = p;\r
+ break;\r
+\r
+ case 3:\r
+ {\r
+ script_script_mlist(tail) = p;\r
+ decr(save_ptr);\r
+ return;\r
+ }\r
+ break;\r
+ }\r
+\r
+ incr(saved(-1));\r
+ push_math(math_choice_group);\r
+ scan_left_brace();\r
+}\r
+/* sec 1176 */\r
+void sub_sup (void)\r
+{\r
+ /* small_number t; */\r
+ int t;\r
+ pointer p;\r
+\r
+ t = 0;\r
+ p = 0;\r
+\r
+ if (tail != head)\r
+ if (script_allowed(tail))\r
+ {\r
+ p = supscr(tail) + cur_cmd - sup_mark;\r
+ t = math_type(p);\r
+ }\r
+\r
+ if ((p == 0) || (t != 0))\r
+ {\r
+ tail_append(new_noad());\r
+ p = supscr(tail) + cur_cmd - sup_mark;\r
+\r
+ if (t != 0)\r
+ {\r
+ if (cur_cmd == sup_mark)\r
+ {\r
+ print_err("Double superscript");\r
+ help1("I treat `x^1^2' essentially like `x^1{}^2'.");\r
+ }\r
+ else\r
+ {\r
+ print_err("Double subscript");\r
+ help1("I treat `x_1_2' essentially like `x_1{}_2'.");\r
+ }\r
+\r
+ error();\r
+ }\r
+ }\r
+\r
+ scan_math(p);\r
+}\r
+/* sec 1086 */\r
+void package (small_number c)\r
+{\r
+ scaled h;\r
+ pointer p;\r
+ scaled d;\r
+\r
+ d = box_max_depth;\r
+ unsave();\r
+ save_ptr = save_ptr - 3;\r
+\r
+ if (mode == -hmode)\r
+ cur_box = hpack(link(head), saved(2), saved(1));\r
+ else\r
+ {\r
+ cur_box = vpackage(link(head), saved(2), saved(1), d);\r
+\r
+ if (c == vtop_code)\r
+ {\r
+ h = 0;\r
+ p = list_ptr(cur_box);\r
+\r
+ if (p != 0)\r
+ if (type(p) <= rule_node)\r
+ h = height(p);\r
+\r
+ depth(cur_box) = depth(cur_box) - h + height(cur_box);\r
+ height(cur_box) = h;\r
+ }\r
+ }\r
+\r
+ pop_nest();\r
+ box_end(saved(0));\r
+}
\ No newline at end of file