Debian Codegraph @

texk/web2c/partoken.ch

raw
1 % $Id: partoken.ch 60088 2021-07-27 01:25:13Z karl $
2 % Implementation of |\partokenname| and |\partokencontext| primitives.
3 % Public domain. Originally written by Petr Olsak, 2021.
4
5 % TeX inserts (let's say) "par-token" at empty lines and in other situations.
6 % The primitive meaning of "par-token" is (let's say) "end-paragraph",
7 % but it can be changed by the macro programmer (by |\def\par|, for example).
8 % The name of the auto-emitted "par-token" is fixed as |\par| in
9 % classical TeX.
10 % The new |\partokenname| primitive defined here allows changing this cs name.
11 % After |\partokenname <control-sequence>| is given, the specified
12 % <control-sequence> will be emitted at empty lines, etc., not |\par|.
13 % Moreover, the given <control-sequence> plays the role of |\par| when
14 % processing not-\long macros ("runaway error").
15 % The setting of |\partokenname| is global.
16 %
17 % The integer register |\partokencontext| allows controlling the places where
18 % "par-token" is auto-emitted. The value of |\partokencontext| can be:
19 % 0 ... "par-token" is emitted as in classical TeX, i.e. at empty lines,
20 % before \end, \vskip, \hrule, \unvbox, and \halign (if horizontal mode
21 % is current) and in several error recovery situations.
22 % This is the default value.
23 % 1 ... "par-token" is emitted as before and at the end of \vbox,
24 % \vtop, and \vcenter if horizontal mode is current here.
25 % 2 ... "par-token" is emitted as before and at the end of \noalign,
26 % \vadjust, \output, \insert, and \valign items, if horizontal
27 % mode is current here.
28 % Classical TeX does a direct call of the "end-paragraph" routine at the
29 % places mentioned in cases 1 and 2.
30 %
31 % See the user documentation in the pdftex manual for more,
32 % the tests/partoken-test.tex file for basic examples,
33 % and the OpTeX format (eventually) for the practical case inspiring
34 % this idea.
35
36 % New internal constant for integer register |\partokencontext|
37 @x
38 @d web2c_int_pars=web2c_int_base+4 {total number of web2c's integer parameters}
39 @y
40 @d partoken_context_code=web2c_int_base+4 {controlling where |partoken| inserted}
41 @d web2c_int_pars=web2c_int_base+5 {total number of web2c's integer parameters}
42 @z
43
44 % Allocation of integer register |\partokencontext|
45 @x
46 @d tracing_stack_levels==int_par(tracing_stack_levels_code)
47 @y
48 @d tracing_stack_levels==int_par(tracing_stack_levels_code)
49 @d partoken_context==int_par(partoken_context_code)
50 @z
51
52 % Printing |\show\partokencontext|
53 @x
54 tracing_stack_levels_code:print_esc("tracingstacklevels");
55 @y
56 tracing_stack_levels_code:print_esc("tracingstacklevels");
57 partoken_context_code:print_esc("partokencontext");
58 @z
59
60 % Declaration of primitives |\partokenname| and |\partokencontext|
61 @x
62 primitive("tracingstacklevels",assign_int,int_base+tracing_stack_levels_code);@/
63 @!@:tracing_stack_levels_}{\.{\\tracingstacklevels} primitive@>
64 @y
65 primitive("tracingstacklevels",assign_int,int_base+tracing_stack_levels_code);@/
66 @!@:tracing_stack_levels_}{\.{\\tracingstacklevels} primitive@>
67 primitive("partokenname",partoken_name,0);@/
68 @!@:partoken_name_}{\.{\\partokenname} primitive@>
69 primitive("partokencontext",assign_int,int_base+partoken_context_code);@/
70 @!@:partoken_context_}{\.{\\partokencontext} primitive@>
71 @z
72
73 % Printing |\show\partokenname|
74 @x
75 vrule: print_esc("vrule");
76 @y
77 vrule: print_esc("vrule");
78 partoken_name: print_esc("partokenname");
79 @z
80
81 % End of |\vbox| and |\vtop|
82 @x
83 vbox_group: begin end_graf; package(0);
84 end;
85 vtop_group: begin end_graf; package(vtop_code);
86 end;
87 @y
88 vbox_group: if (partoken_context>0) and (mode=hmode) then
89 begin
90 back_input; cur_tok := par_token; back_input; token_type := inserted;
91 end
92 else begin end_graf; package(0); end;
93 vtop_group: if (partoken_context>0) and (mode=hmode) then
94 begin
95 back_input; cur_tok := par_token; back_input; token_type := inserted;
96 end
97 else begin end_graf; package(vtop_code); end;
98 @z
99
100 % End of |\insert| or |\vadjust|
101 @x
102 insert_group: begin end_graf; q:=split_top_skip; add_glue_ref(q);
103 @y
104 insert_group: if (partoken_context>1) and (mode=hmode) then
105 begin
106 back_input; cur_tok := par_token; back_input; token_type := inserted;
107 end
108 else begin end_graf; q:=split_top_skip; add_glue_ref(q);
109 @z
110
111 % End of |\output|
112 @x
113 output_group: @<Resume the page builder...@>;
114 @y
115 output_group: if (partoken_context>1) and (mode=hmode) then
116 begin
117 back_input; cur_tok := par_token; back_input; token_type := inserted;
118 end
119 else @<Resume the page builder...@>;
120 @z
121
122 % End of item in |\valign|
123 @x
124 vmode+endv,hmode+endv: do_endv;
125 @y
126 vmode+endv,hmode+endv: if (partoken_context>1) and (mode=hmode) then
127 begin
128 back_input; cur_tok := par_token; back_input; token_type := inserted;
129 end
130 else do_endv;
131 @z
132
133 % End of |\noalign| in |\halign|
134 @x
135 no_align_group: begin end_graf; unsave; align_peek;
136 end;
137 @y
138 no_align_group: if (partoken_context>1) and (mode=hmode) then
139 begin
140 back_input; cur_tok := par_token; back_input; token_type := inserted;
141 end
142 else begin end_graf; unsave; align_peek;
143 end;
144 @z
145
146 % End of |\vcenter|
147 @x
148 vcenter_group: begin end_graf; unsave; save_ptr:=save_ptr-2;
149 @y
150 vcenter_group: if (partoken_context>0) and (mode=hmode) then
151 begin
152 back_input; cur_tok := par_token; back_input; token_type := inserted;
153 end else begin end_graf; unsave; save_ptr:=save_ptr-2;
154 @z
155
156 % Setting new name of the |par-token|
157 @x
158 any_mode(after_group):begin get_token; save_for_after(cur_tok);
159 end;
160 @y
161 any_mode(after_group):begin get_token; save_for_after(cur_tok);
162 end;
163 any_mode(partoken_name):begin get_token;
164 if cur_cs > 0 then begin
165 par_loc := cur_cs; par_token := cur_tok;
166 end;
167 end;
168 @z
169
170 % Undump |par-token| from the format
171 @x
172 undump(hash_base)(hash_top)(par_loc);
173 @y
174 undump_int(par_loc);
175 @z