1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
%D \module
%D [ file=page-inj,
%D version=2013.02.10,
%D title=\CONTEXT\ Page Module,
%D subtitle=Injections,
%D author=Wolfgang Schuster \& Hans Hagen,
%D date=\currentdate,
%D copyright=Wolfgang Schuster \& Hans Hagen,
%D license=see context related readme files (gpl)]
%D This module is based on an idea and prototype by Wolfgang but instead of
%D injectioning into a page constructor we injection it into the regular shipout
%D handler because that way we get page numbering. It's a sort of variation
%D on postponing but the content does not end up in the regular page flow, so
%D it's closer to page figures but without the usual page builder.
%D
%D This module is following the mkvi way of rendering setups and configuration
%D and is somewhat experimental. Probably more alternatives will be added. This
%D could become a delayed loaded module at some point (no real consequences).
\unprotect
\registerctxluafile{page-inj}{}
\installcorenamespace {pageinjection}
\installcorenamespace {pageinjectionalternative}
\installcorenamespace {pageinjectionrenderings}
\installframedcommandhandler \??pageinjection {pageinjection} \??pageinjection
\installcommandhandler \??pageinjectionalternative {pageinjectionalternative} \??pageinjectionalternative
\let\page_boxes_flush_before\clf_flushpageinjectionsbefore
\let\page_boxes_flush_after \clf_flushpageinjectionsafter
\def\page_injections_flush_indeed
{\scrn_canvas_synchronize_set{\pageinjectionparameter\c!width}{\pageinjectionparameter\c!height}%
\invokepagehandler\v!normal{\inheritedpageinjectionframed{\texsetup\p_page_injectionalternative_rederingsetup}}%
\scrn_canvas_synchronize_reset}
\def\page_injections_flush_saved#name#parameters%
{\begingroup
\edef\currentpageinjection{#name}%
\getdummyparameters[#parameters]%
\edef\currentpageinjectionalternative {\pageinjectionparameter \c!alternative }%
\edef\p_page_injectionalternative_rederingsetup{\pageinjectionalternativeparameter\c!renderingsetup}%
\page_injections_nextpage
\page_injections_flush_indeed
\endgroup}
\unexpanded\def\pageinjection
{\begingroup
\dodoubleempty\page_injections_direct}
\def\page_injections_direct[#1][#2]% name parameters | settings parameters | name | parameters
{\doifelseassignment{#1}
{\doifelseassignment{#2}
{\page_injections_direct_settings_parameters{#1}{#2}}
{\page_injections_direct_parameters {#1}}}
{\doifelseassignment{#2}
{\page_injections_direct_name_parameters {#1}{#2}}
{\page_injections_direct_name {#1}}}}
\def\page_injections_direct_settings_parameters#settings% #parameters%
{\let\currentpageinjection\empty
\checkpageinjectionparent
\setupcurrentpageinjection[#settings]%
\page_injections_direct_indeed}
\def\page_injections_direct_parameters% #parameters%
{\let\currentpageinjection\empty
\checkpageinjectionparent
\page_injections_direct_indeed}
\def\page_injections_direct_name_parameters#name% #parameters%
{\edef\currentpageinjection{#name}%
\checkpageinjectionparent
\page_injections_direct_indeed}
\def\page_injections_direct_name#name%
{\edef\currentpageinjection{#name}%
\checkpageinjectionparent
\page_injections_direct_indeed{}}
\def\page_injections_direct_indeed% #parameters%
{\edef\p_page_injections_state{\pageinjectionparameter\c!state}%
\edef\p_page_injections_delay{\pageinjectionparameter\c!delay}%
\edef\p_page_injections_page {\pageinjectionparameter\c!page }%
\ifx\p_page_injections_delay\v!yes
\expandafter\page_injections_direct_indeed_yes
\else
\expandafter\page_injections_direct_indeed_nop
\fi}
\def\page_injections_direct_indeed_yes#parameters%
{\clf_savepageinjections
name {\currentpageinjection}%
state {\p_page_injections_state}%
userdata {\normalunexpanded{#parameters}}%
\relax
\endgroup}
\def\page_injections_direct_indeed_nop#parameters%
{\ifx\p_page_injections_page\empty
\page
\else
\page[\p_page_injections_page]%
\fi
\getdummyparameters[#parameters]%
\page_injections_place
\endgroup}
% \def\page_injections_place
% {\edef\currentpageinjectionalternative {\pageinjectionparameter \c!alternative }%
% \edef\p_page_injectionalternative_rederingsetup{\pageinjectionalternativeparameter\c!renderingsetup}%
% \page_injections_nextpage
% \ifx\currentpageinjectionalternative\v!none \else % increment counter but don’t generate output
% \invokepagehandler\v!normal{\inheritedpageinjectionframed{\texsetup\p_page_injectionalternative_rederingsetup}}%
% \fi}
\def\page_injections_place
{\edef\currentpageinjectionalternative {\pageinjectionparameter \c!alternative }%
\edef\p_page_injectionalternative_rederingsetup{\pageinjectionalternativeparameter\c!renderingsetup}%
\page_injections_nextpage
\ifx\currentpageinjectionalternative\v!none \else % increment counter but don’t generate output
\forgetparindent
\dontcomplain
\setconstant\shipoutfinalizemethod\zerocount % this is messy
\page_injections_flush_indeed
\fi}
\def\page_injections_nextpage
{\edef\p_page_injections_pagestate{\pageinjectionparameter\c!pagestate}%
\ifx\p_page_injections_pagestate\v!stop \else
\edef\p_page_injections_n{\pageinjectionparameter\c!n}%
\ifx\p_page_injections_n\empty
\let\p_page_injections_n\plusone
\fi
\dorecurse\p_page_injections_n
{\incrementcounter[\s!realpage]%
\incrementcounter[\s!userpage]}%
\fi}
\definepageinjectionalternative[\v!figure][\c!renderingsetup=\??pageinjectionrenderings:\v!figure]
\definepageinjectionalternative[\v!buffer][\c!renderingsetup=\??pageinjectionrenderings:\v!buffer]
\definepageinjectionalternative[\v!setups][\c!renderingsetup=\??pageinjectionrenderings:\s!setup ]
\startsetups[\??pageinjectionrenderings:\v!figure]
\dontleavehmode\externalfigure[\dummyparameter\c!name][\c!factor=\v!max]
\stopsetups
\startsetups[\??pageinjectionrenderings:\s!setup]
\setups[\dummyparameter\c!setup]% kind of redundant but fits in
\stopsetups
\startsetups[\??pageinjectionrenderings:\v!buffer]
\getbuffer[\dummyparameter\c!name]%
\stopsetups
% \setuppaper
% [\c!method=\v!pageinjection]
\setuppageinjection
[ \c!width=\paperwidth,
\c!height=\paperheight,
\c!frame=\v!off,
\c!offset=\v!overlay,
\c!delay=\v!no,
\c!state=\v!next,
\c!alternative=\v!figure]
\definepageinjection[\v!previouspage][\c!delay=\v!yes,\c!state=\v!previous]
\definepageinjection[\v!nextpage] [\c!delay=\v!yes,\c!state=\v!next]
\definepageinjection[\v!here] % direct
\definepageinjection[\v!empty] [\c!alternative=\v!none]
%definepageinjection[\v!chapter] [\v!previouspage][\c!pagestate=\v!stop]
\protect \endinput
% \enabletrackers[pagebuilder.injections]
%
% \setuppageinjection[offset=2em]
%
% \definepageinjection[chapter][previouspage][pagestate=stop]
% \definepageinjection[later] [delay=yes,state=+2]
%
% \useMPlibrary[dum]
%
% \starttext
%
% \startchapter[title={Insert pages before/after the current page}]
%
% \dorecurse{10}{one: \input ward\par}
%
% \pageinjection[previouspage][name=dummy-1]
%
% \dorecurse{20}{two: \input ward\par} \page
%
% \pageinjection[nextpage][name=dummy-2]
% \pageinjection[later] [name=dummy-4]
% \pageinjection[delay=yes,state=+2][name=dummy-5]
%
% \dorecurse{100}{three: \input ward\par}
%
% \stopchapter
%
% \startbuffer[whatever]
% \dorecurse{10}{whatever #1 }
% \stopbuffer
%
% \startchapter[title={Insert pages at the current location}]
%
% \dorecurse{10}{\input ward\par}
%
% \pageinjection[direct][name=dummy-3]
% \pageinjection[direct][alternative=buffer,name=whatever]
%
% \dorecurse{10}{\input ward\par}
%
% \stopchapter
%
% \setuphead
% [chapter]
% [beforesection={\pageinjection[empty]},
% insidesection={\pageinjection[chapter][name=\structureuservariable{image}]}]
%
% \startchapter[title={Combine both mechanism}][name=dummy-4]
%
% \dorecurse{10}{\input ward\par}
%
% \stopchapter
%
% \stoptext
|