1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Anchoring Macros Positioning}
15
16
17
18
19
20\registerctxluafile{anchpos}{}
21
22\unprotect
23
24
25
26
27
28
29
30
31
32
33
34
35\def\dosaveposition #1#2#3#4{\clf_dosaveposition {#1}#2 #3 #4\relax}
36\def\dosavepositionwhd #1#2#3#4#5#6#7{\clf_dosavepositionwhd {#1}#2 #3 #4 #5 #6 #7\relax}
37\def\dosavepositionplus#1#2#3#4#5#6#7#8{\clf_dosavepositionplus{#1}#2 #3 #4 #5 #6 #7{#8}}
38
39\def\dosetposition #1{\clf_dosetposition {#1}}
40\def\dosetpositionwhd #1#2#3#4{\clf_dosetpositionwhd {#1}#2 #3 #4\relax}
41\def\dosetpositionplus#1#2#3#4#5{\clf_dosetpositionplus {#1}#2 #3 #4{#5}}
42\def\dosetpositionbox #1#2{\clf_dosetpositionbox {#1}#2\relax}
43\def\dosetpositionstrut #1{\clf_dosetpositionstrut {#1}}
44\def\dosetpositionstrutkind #1#2{\clf_dosetpositionstrutkind{#1}#2\relax}
45
46\newbox\b_anch_position
47\newif \ifpositioning
48
49
50
51\def\replacepospxywhd#1#2#3#4#5#6#7
52 {\clf_replacepospxywhd{#1}#2 #3 #4 #5 #6 #7\relax}
53
54
55
56
57
58
59
60\def\MPp #1{\clf_MPp {#1}}
61\def\MPr #1{\clf_MPr {#1}}
62\def\MPc #1{\clf_MPc {#1}}
63\def\MPn #1{\clf_MPn {#1}}
64\def\MPx #1{\clf_MPx {#1}}
65\def\MPy #1{\clf_MPy {#1}}
66\def\MPw #1{\clf_MPw {#1}}
67\def\MPh #1{\clf_MPh {#1}}
68\def\MPd #1{\clf_MPd {#1}}
69\def\MPxy #1{\clf_MPxy {#1}}
70\def\MPwhd #1{\clf_MPwhd {#1}}
71\def\MPll #1{\clf_MPll {#1}}
72\def\MPlr #1{\clf_MPlr {#1}}
73\def\MPur #1{\clf_MPur {#1}}
74\def\MPul #1{\clf_MPul {#1}}
75\def\MPpos #1{\clf_MPpos {#1}}
76\def\MPls #1{\clf_MPls {#1}}
77\def\MPrs #1{\clf_MPrs {#1}}
78\def\MPpardata#1{\clf_MPpardata{#1}}
79\def\MPxywhd #1{\clf_MPxywhd {#1}}
80\def\MPposset #1{\clf_MPposset {#1}}
81
82\let\MPpage \MPp
83\let\MPregion \MPr
84\let\MPcolumn \MPc
85\let\MPparagraph\MPn
86
87\let\MPanchor \MPpos
88\let\MPleftskip \MPls
89\let\MPrightkip \MPrs
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110\def\MPplus#1#2#3{\clf_MPplus{#1}#2{#3}} \let\MPv \MPplus
111\def\MPrest #1#2{\clf_MPrest{#1}{#2}} \let\MPvv\MPrest
112
113
114
115
116\let\dopositionaction\gobbleoneargument
117
118\def\anch_positions_initialize
119 {\ifpositioning \else
120 \global\positioningtrue
121 \fi}
122
123\unexpanded\def\setpositiononly
124 {\iftrialtypesetting
125 \expandafter\gobbleoneargument
126 \else
127 \expandafter\anch_positions_set_only_indeed
128 \fi}
129
130\def\anch_positions_set_only_indeed#1
131 {\anch_positions_initialize
132 \edef\currentposition{#1}
133 \dosetposition\currentposition}
134
135\unexpanded\def\setposition
136 {\iftrialtypesetting
137 \expandafter\gobbleoneargument
138 \else
139 \expandafter\anch_positions_set_indeed
140 \fi}
141
142\def\anch_positions_set_indeed#1
143 {\anch_positions_initialize
144 \edef\currentposition{#1}
145 \dosetposition\currentposition
146 \anch_positions_trace_left
147 \dopositionaction\currentposition}
148
149\unexpanded\def\setpositiondata
150 {\iftrialtypesetting
151 \expandafter\gobblefourarguments
152 \else
153 \expandafter\anch_positions_set_data_indeed
154 \fi}
155
156\def\anch_positions_set_data_indeed#1#2#3#4
157 {\anch_positions_initialize
158 \hbox
159 {\edef\currentposition{#1}
160 \dosetpositionwhd\currentposition{#2}{#3}{#4}
161 \anch_positions_trace_left
162 \dopositionaction\currentposition
163 \hss}}
164
165\unexpanded\def\setpositionbox
166 {\iftrialtypesetting
167 \expandafter\anch_positions_set_box_nop
168 \else
169 \expandafter\anch_positions_set_box_yes
170 \fi}
171
172\def\anch_positions_set_box_nop#1
173 {\dowithnextboxcs\flushnextbox}
174
175\def\anch_positions_set_box_yes#1
176 {\dowithnextbox{\anch_positions_set_box_finish{#1}}}
177
178\def\anch_positions_set_box_finish#1
179 {\anch_positions_initialize
180 \hbox to \wd\nextbox
181 {\edef\currentposition{#1}
182 \dosetpositionbox\currentposition\nextbox
183 \anch_positions_trace_left
184 \setbox\b_anch_position\box\nextbox
185 \dopositionaction\currentposition
186 \box\b_anch_position
187 \hss}}
188
189\unexpanded\def\setpositionstrut
190 {\iftrialtypesetting
191 \expandafter\anch_positions_set_strut_nop
192 \else
193 \expandafter\anch_positions_set_strut_yes
194 \fi}
195
196\def\anch_positions_set_strut_nop#1
197 {\strut}
198
199\def\anch_positions_set_strut_yes#1
200 {\anch_positions_initialize
201 \hbox to \zeropoint
202 {\edef\currentposition{#1}
203 \dosetpositionstrut\currentposition
204 \anch_positions_trace_left
205 \dopositionaction\currentposition
206 \strut
207 \hss}}
208
209\unexpanded\def\setpositionstrutkind
210 {\iftrialtypesetting
211 \expandafter\anch_positions_set_strut_kind_nop
212 \else
213 \expandafter\anch_positions_set_strut_kind_yes
214 \fi}
215
216\def\anch_positions_set_strut_kind_yes#1#2
217 {\anch_positions_initialize
218 \hbox to \zeropoint
219 {\edef\currentposition{#1}
220 \dosetpositionstrutkind\currentposition{#2}
221 \anch_positions_trace_left
222 \dopositionaction\currentposition
223 \strut
224 \hss}}
225
226\def\anch_positions_set_strut_kind_nop#1#2
227 {\strut}
228
229\unexpanded\def\setpositiondataplus
230 {\iftrialtypesetting
231 \expandafter\gobblefivearguments
232 \else
233 \expandafter\anch_positions_set_plus_indeed
234 \fi}
235
236\def\anch_positions_set_plus_indeed#1#2#3#4#5
237 {\anch_positions_initialize
238 \hbox
239 {\edef\currentposition{#1}
240 \dosetpositionplus\currentposition{#2}{#3}{#4}{#5}
241 \anch_positions_trace_right
242 \dopositionaction\currentposition
243 \hss}}
244
245\unexpanded\def\setpositionplus
246 {\iftrialtypesetting
247 \expandafter\anch_positions_set_plus_nop
248 \else
249 \expandafter\anch_positions_set_plus_yes
250 \fi}
251
252\def\anch_positions_set_plus_nop#1#2
253 {\dowithnextboxcs\flushnextbox}
254
255\def\anch_positions_set_plus_yes#1#2
256 {\dowithnextbox{\anch_positions_set_plus_yes_finish{#1}{#2}}}
257
258\def\anch_positions_set_plus_yes_finish#1#2
259 {\anch_positions_initialize
260 \hbox to \nextboxwd
261 {\edef\currentposition{#1}
262 \dosetpositionplus\currentposition{\wd\nextbox}{\ht\nextbox}{\dp\nextbox}{#2}
263 \anch_positions_trace_right
264 \setbox\b_anch_position\flushnextbox
265 \dopositionaction\currentposition
266 \box\b_anch_position
267 \hss}}
268
269\let\currentposition\s!unknown
270
271
272
273\def\pageanchor {page:\the\realpageno}
274\def\textanchor {text:\the\realpageno}
275\def\regionanchor{region:0}
276
277\newcount\c_anch_column
278\newcount\c_anch_text
279
280
281
282\unexpanded\def\anch_mark_column_box#1#2
283 {\global\advance\c_anch_column\plusone
284 \clf_markregionboxtaggedn#1{columnarea:\the\c_anch_column}#2\relax}
285
286\unexpanded\def\anch_mark_region_box
287 {\iftrialtypesetting
288 \singleexpandafter\gobbleoneargument
289 \else\ifpositioning
290 \doubleexpandafter\anch_mark_region_box_indeed
291 \else
292 \doubleexpandafter\gobbleoneargument
293 \fi\fi}
294
295\unexpanded\def\anch_mark_region_box_indeed#1
296 {\clf_markregionbox#1\relax}
297
298\unexpanded\def\anch_mark_flow_box#1
299 {\hpack\bgroup
300 \global\advance\c_anch_text\plusone
301 \clf_markregionboxtagged#1{textarea:\the\c_anch_text}
302 \box#1
303 \egroup}
304
305\unexpanded\def\anch_mark_tagged_box#1#2
306 {\clf_markregionboxtagged#1{#2}}
307
308\unexpanded\def\anch_mark_flow_only#1
309 {\global\advance\c_anch_text\plusone
310 \clf_markregionboxcorrected#1{textarea:\the\c_anch_text}}
311
312\unexpanded\def\anch_make_page_box#1
313 {\clf_setregionboxtagged#1{page:\the\realpageno}}
314
315\unexpanded\def\anch_mark_text_box#1
316 {\clf_markregionboxtagged#1{text:\the\realpageno}}
317
318\newcount\c_anch_free
319
320\unexpanded\def\anch_mark_tagged_box_free#1#2#3#4#5#6
321 {\ifpositioning
322 \global\advance\c_anch_free\plusone
323 \clf_markregionboxtaggedkind
324 #1
325 {free:\number\c_anch_free}
326 #2\space
327 #3\space
328 #4\space
329 #5\space
330 #6\relax
331 \fi}
332
333\def\reservedautoregiontag{\clf_reservedautoregiontag}
334
335
336
337
338
339
340
341
342
343\unexpanded\def\copyposition#1#2
344 {\clf_copyposition{#1}{#2}}
345
346
347
348
349
350
351
352
353\unexpanded\def\doifposition #1{\clf_doifposition {#1}}
354\unexpanded\def\doifelseposition #1{\clf_doifelseposition {#1}}
355\unexpanded\def\doifelsepositiononpage#1#2{\clf_doifelsepositiononpage{#1}#2\relax}
356
357\let\doifpositionelse \doifelseposition
358\let\doifpositiononpageelse\doifelsepositiononpage
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377\let\xypos\setpositiononly
378
379\unexpanded\def\hpos #1{\dontleavehmode\setpositionbox{#1}\hbox}
380\unexpanded\def\vpos #1{\setpositionbox{#1}\vbox}
381\unexpanded\def\bpos #1{\dontleavehmode\setpositionstrut{b:#1}\ignorespaces}
382\unexpanded\def\epos #1{\removeunwantedspaces\setpositionstrut{e:#1}}
383\unexpanded\def\bposkind#1#2{\dontleavehmode\setpositionstrutkind{b:#1}{#2}\ignorespaces}
384\unexpanded\def\eposkind#1#2{\removeunwantedspaces\setpositionstrutkind{e:#1}{#2}}
385
386
387
388
389
390
391\newtoks \t_anch_positions_tracers
392\newcount\c_anch_positions_paragraph
393
394\unexpanded\def\tracepositions
395 {\the\t_anch_positions_tracers}
396
397\unexpanded\def\enableparpositions
398 {\glet\registerparoptions\doregisterparoptions
399 \global\positioningtrue}
400
401\let\disableparpositions\relax
402
403\let\registerparoptions\relax
404
405\unexpanded\def\doregisterparoptions
406 {\iftrialtypesetting \else
407 \ifinpagebody \else \ifmmode \else \ifinformula \else
408 \anch_positions_register_par_options
409 \fi \fi \fi
410 \fi}
411
412\def\anch_positions_register_par_options_normal
413 {\dontleavehmode\clf_parpos}
414
415\def\anch_positions_register_par_options_traced
416 {\anch_positions_register_par_options_normal
417 \smashedhbox to \zeropoint
418 {\hss
419 \startcolor[blue]
420 \llap{\infofont\number\c_anch_positions_paragraph}
421 \vrule
422 \s!width 4\onepoint
423 \s!height2\onepoint
424 \s!depth 2\onepoint
425 \stopcolor
426 \hss}}
427
428\let\anch_positions_register_par_options\anch_positions_register_par_options_normal
429
430\appendtoks
431 \let\anch_positions_register_par_options\anch_positions_register_par_options_traced
432\to \t_anch_positions_tracers
433
434\unexpanded\def\anch_positions_trace#1#2#3
435 {\smashedhbox
436 {#1{\infofont#2#3}
437 \kern\onepoint
438 \vrule\s!width2\onepoint\s!height\halfapoint\s!depth\halfapoint}}
439
440\unexpanded\def\anch_positions_trace_left_indeed
441 {\anch_positions_trace\llap\darkmagenta{\currentposition>}}
442
443\unexpanded\def\anch_positions_trace_right_indeed
444 {\anch_positions_trace\rlap\darkcyan{<\currentposition}}
445
446\let\anch_positions_trace_left \relax
447\let\anch_positions_trace_right\relax
448
449\appendtoks
450 \let\anch_positions_trace_left \anch_positions_trace_left_indeed
451 \let\anch_positions_trace_right \anch_positions_trace_right_indeed
452\to \t_anch_positions_tracers
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468\unexpanded\def\doifelseoverlapping#1#2{\clf_doifelseoverlapping{#1}{#2}}
469
470\let\doifoverlappingelse\doifelseoverlapping
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488\unexpanded\def\doifelsepositionsonsamepage#1{\clf_doifelsepositionsonsamepage{#1}}
489\unexpanded\def\doifelsepositionsonthispage#1{\clf_doifelsepositionsonthispage{#1}}
490
491\let\doifpositionsonsamepageelse\doifelsepositionsonsamepage
492\let\doifpositionsonthispageelse\doifelsepositionsonthispage
493
494
495
496\unexpanded\def\doifelsepositionsused{\clf_doifelsepositionsused}
497
498\let\doifpositionsusedelse\doifelsepositionsused
499
500
501
502\unexpanded\def\savepos {\clf_savepos}
503\unexpanded\def\lastxpos{\numexpr\clf_lastxpos\relax}
504\unexpanded\def\lastypos{\numexpr\clf_lastypos\relax}
505
506\protect \endinput
507 |