1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Core Macros Insertions}
15
16
17
18
19
20\registerctxluafile{pageins}{}
21
22\unprotect
23
24
25
26
27\installcorenamespace{insertion}
28\installcorenamespace{insertionnumber}
29
30\installcommandhandler \??insertion {insertion} \??insertion
31
32\setupinsertion
33 [
34
35
36
37 \c!location=\v!page]
38
39\newconstant\insertionmigrationmode
40
41\def\page_inserts_check_anchoring
42 {\edef\p_anchoring{\namedinsertionparameter\empty\c!anchoring}
43 \insertionmigrationmode\ifx\p_anchoring\v!auto\plusone\else\zerocount\fi
44 \clf_setinsertmigration{\p_anchoring}}
45
46\appendtoks
47 \ifempty\currentinsertionparent
48 \page_inserts_check_anchoring
49 \fi
50\to \everysetupinsertion
51
52\setupinsertion
53 [\c!anchoring=\v!auto]
54
55\appendtoks
56 \page_inserts_check_anchoring
57\to \everystarttext
58
59\newinteger\currentinsertionnumber
60
61\newtoks\t_page_inserts_list
62
63\mutable\let\doprocessinsert\gobbleoneargument
64
65
66
67\permanent\protected\def\setcurrentinsertion#1
68 {\cdef\currentinsertion{#1}
69 \currentinsertionnumber\csname\??insertionnumber\currentinsertion\endcsname}
70
71\permanent\def\namedinsertionnumber#1{\csname\??insertionnumber#1\endcsname}
72
73\protected\def\page_inserts_synchronize_registers
74 {\currentinsertionnumber\csname\??insertionnumber\currentinsertion\endcsname}
75
76\appendtoks
77 \ifempty\currentinsertionparent \else
78 \page_inserts_synchronize_registers
79 \fi
80\to \everysetupinsertion
81
82\protected\def\page_inserts_process#1
83 {\cdef\currentinsertion{#1}
84 \currentinsertionnumber\csname\??insertionnumber\currentinsertion\endcsname
85 \doprocessinsert\currentinsertionnumber}
86
87\permanent\protected\def\processinsertions
88 {\expand\t_page_inserts_list}
89
90
91
92
93
94
95
96
97
98
99\permanent\protected\def\doifelseinsertion#1
100 {\ifcsname\??insertionnumber#1\endcsname
101 \expandafter\firstoftwoarguments
102 \else
103 \expandafter\secondoftwoarguments
104 \fi}
105
106\aliased\let\doifinsertionelse\doifelseinsertion
107
108
109
110
111
112
113
114
115
116
117
118
119
120\insertmode\plustwo
121
122
123
124 \protected\def\page_inserts_inject {\insert}
125
126 \protected\def\page_inserts_set_limit {\insertlimit}
127 \protected\def\page_inserts_set_distance {\insertdistance}
128 \protected\def\page_inserts_set_multiplier{\insertmultiplier}
129 \protected\def\page_inserts_set_penalty {\insertpenalty}
130 \protected\def\page_inserts_set_maxdepth {\insertmaxdepth}
131
132 \protected\def\page_inserts_get_limit {\insertlimit}
133 \protected\def\page_inserts_get_distance {\insertdistance}
134 \protected\def\page_inserts_get_multiplier{\insertmultiplier}
135 \protected\def\page_inserts_get_penalty {\insertpenalty}
136 \protected\def\page_inserts_get_maxdepth {\insertmaxdepth}
137
138 \protected\def\page_inserts_get_boxed {\insertbox}
139 \protected\def\page_inserts_get_copied {\insertcopy}
140 \protected\def\page_inserts_get_unboxed {\insertunbox}
141 \protected\def\page_inserts_get_uncopied {\insertuncopy}
142
143 \protected\def\page_inserts_get_height {\insertheight}
144 \protected\def\page_inserts_get_depth {\insertdepth}
145 \protected\def\page_inserts_get_width {\insertwidth}
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170\newinteger\c_page_inserts_last_allocated
171
172\appendtoks
173 \ifempty\currentinsertionparent
174 \ifcsname\??insertionnumber\currentinsertion\endcsname
175
176 \else
177
178 \global\advanceby\c_page_inserts_last_allocated\plusone
179 \global\expandafter\integerdef\csname\??insertionnumber\currentinsertion\endcsname\c_page_inserts_last_allocated
180 \page_inserts_synchronize_registers
181 \clf_defineinsertion
182 {\currentinsertion}
183 {
184 number \currentinsertionnumber
185 }
186 \relax
187
188
189
190 \xtoksapp\t_page_inserts_list{\page_inserts_process{\currentinsertion}}
191 \page_inserts_set_multiplier\currentinsertionnumber\plusthousand
192 \page_inserts_set_distance \currentinsertionnumber\zeropoint
193 \page_inserts_set_limit \currentinsertionnumber\maxdimen
194 \fi
195 \else
196 \letcsname\??insertionnumber\currentinsertion\expandafter\endcsname
197 \csname\??insertionnumber\currentinsertionparent\endcsname
198 \fi
199\to \everydefineinsertion
200
201\appendtoks
202 \ifempty\currentinsertionparent \else
203 \clf_setupinsertion
204 {\currentinsertion}
205 {
206 location {\insertionparameter\c!location}
207 }
208 \relax
209 \fi
210\to \everysetupinsertion
211
212\protected\def\page_inserts_set_location#1#2
213 {\clf_setinsertionlocation{#1}{#2}}
214
215
216
217\def\page_insert_insertion_height#1
218 {\dimexpr\expandafter\page_insert_insertion_height_indeed\csname\??insertionnumber#1\endcsname\relax}
219
220
221
222
223\def\page_insert_insertion_height_indeed#1
224 {\ifzeropt\page_inserts_get_height#1\zeropoint\else\dimexpr\page_inserts_get_distance#1\relax\page_inserts_get_height#1\fi}
225
226\protect \endinput
227 |