1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Page Macros Margin Floats}
15
16\unprotect
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40\installcorenamespace{marginblock}
41\installcorenamespace{marginblocklocation}
42
43\installcommandhandler \??marginblock {marginblock} \??marginblock
44
45\let\setupmarginblocks\setupmarginblock
46
47\newconditional\c_page_margin_blocks_enabled
48\newconditional\c_page_margin_blocks_present
49
50\newbox \b_page_margin_blocks
51\newbox \b_page_margin_blocks_prepared
52
53\appendtoks
54 \doifelse{\rootmarginblockparameter\c!state}\v!start
55 \settrue\setfalse\c_page_margin_blocks_enabled
56\to \everysetupmarginblock
57
58\setupmarginblocks
59 [\c!state=\v!start,
60 \c!location=\v!inmargin,
61 \c!width=\rightmarginwidth,
62
63
64
65
66
67
68
69
70 \c!inbetween=\blank,
71 \c!bottom=\vfill]
72
73\unexpanded\def\startmarginblock
74 {\dosingleempty\page_margin_blocks_start_block}
75
76\unexpanded\def\stopmarginblock
77 {\page_margin_blocks_stop_block}
78
79\def\page_margin_blocks_start_block[#tag]
80 {\begingroup
81 \edef\currentmarginblock{#tag}
82 \doifelse{\marginblockparameter\c!state}\v!start
83 \page_margin_blocks_start_block_yes
84 \page_margin_blocks_start_block_nop}
85
86\def\page_margin_blocks_stop_block
87 {\doifelse{\marginblockparameter\c!state}\v!start
88 \page_margin_blocks_stop_block_yes
89 \page_margin_blocks_stop_block_nop
90 \endgroup}
91
92\def\page_margin_blocks_start_block_yes
93 {\showmessage\m!layouts4\empty
94 \global\settrue\c_page_margin_blocks_present
95 \global\setbox\b_page_margin_blocks\vtop\bgroup\vbox\bgroup
96 \hsize\marginblockparameter\c!width
97 \ifvoid\b_page_margin_blocks\else
98 \unvbox\b_page_margin_blocks
99 \marginblockparameter\c!inbetween
100 \fi
101 \usealignparameter\marginblockparameter
102 \usemarginblockstyleandcolor\c!style\c!color
103 \begstrut
104 \ignorespaces}
105
106\def\page_margin_blocks_stop_block_yes
107 {\removeunwantedspaces
108 \endstrut
109 \egroup
110 \egroup}
111
112\def\page_margin_blocks_start_block_nop
113 {\showmessage\m!layouts5\empty
114 \marginblockparameter\c!before
115 \bgroup
116 \usemarginblockstyleandcolor\c!style\c!color}
117
118\def\page_margin_blocks_stop_block_nop
119 {\egroup
120 \marginblockparameter\c!after}
121
122\def\page_margin_blocks_reshape
123 {\ifdim\ht\b_page_margin_blocks_prepared>\zeropoint
124 \beginofshapebox
125 \unvbox\b_page_margin_blocks_prepared
126 \endofshapebox
127 \reshapebox
128 {\box\shapebox}
129 \setbox\b_page_margin_blocks_prepared\vbox to \textheight
130 {\marginblockparameter\c!top
131 \flushshapebox
132 \marginblockparameter\c!bottom}
133 \fi}
134
135\unexpanded\def\checkmarginblocks
136 {\ifvoid\b_page_margin_blocks
137 \global\setfalse\c_page_margin_blocks_present
138 \else
139 \page_margin_blocks_check_indeed
140 \fi}
141
142\def\page_margin_blocks_check_indeed
143 {\ifcsname\??marginblocklocation\marginblockparameter\c!location\endcsname
144 \page_margin_blocks_prepare_box
145 \csname\??marginblocklocation\marginblockparameter\c!location\endcsname
146 \else
147 \global\setbox\b_page_margin_blocks\emptybox
148 \global\setfalse\c_page_margin_blocks_present
149 \fi}
150
151\def\page_margin_blocks_prepare_box
152 {\setbox\b_page_margin_blocks_prepared\vbox
153 {\forgetall
154 \splittopskip\topskip
155 \ifvoid\b_page_margin_blocks\else
156 \ifdim\ht\b_page_margin_blocks>\textheight
157 \vsplit\b_page_margin_blocks to \textheight
158 \else
159 \unvbox\b_page_margin_blocks
160 \fi
161 \fi}
162 \page_margin_blocks_reshape
163 \setbox\b_page_margin_blocks_prepared\vbox
164 {\marginblockparameter\c!before
165 \box\b_page_margin_blocks_prepared
166 \marginblockparameter\c!after}}
167
168
169
170\setvalue{\??marginblocklocation\v!left }{\page_margin_blocks_set_l_box}
171\setvalue{\??marginblocklocation\v!right }{\page_margin_blocks_set_r_box}
172\setvalue{\??marginblocklocation\v!inmargin}{\doifbothsidesoverruled
173 \page_margin_blocks_set_r_box
174 \page_margin_blocks_set_r_box
175 \page_margin_blocks_set_l_box}
176\setvalue{\??marginblocklocation\v!middle }{\doifbothsidesoverruled
177 \page_margin_blocks_set_r_box
178 \page_margin_blocks_set_l_box
179 \page_margin_blocks_set_r_box}
180
181\unexpanded\def\page_margin_blocks_place_r_yes
182 {\setbox\b_page_margin_blocks_prepared\hbox to \rightmarginwidth
183 {\marginblockparameter\c!left
184 \box\b_page_margin_blocks_prepared
185 \marginblockparameter\c!right}
186 \vsmashbox\b_page_margin_blocks_prepared
187 \box\b_page_margin_blocks_prepared}
188
189\unexpanded\def\page_margin_blocks_place_l_yes
190 {\setbox\b_page_margin_blocks_prepared\hbox to \leftmarginwidth
191 {\marginblockparameter\c!right
192 \box\b_page_margin_blocks_prepared
193 \marginblockparameter\c!left}
194 \vsmashbox\b_page_margin_blocks_prepared
195 \box\b_page_margin_blocks_prepared}
196
197\unexpanded\def\page_margin_blocks_place_r_nop{\hskip\rightmarginwidth}
198\unexpanded\def\page_margin_blocks_place_l_nop{\hskip\leftmarginwidth}
199
200\let\placerightmarginblock\page_margin_blocks_place_r_nop
201\let\placeleftmarginblock \page_margin_blocks_place_l_nop
202
203\def\page_margin_blocks_set_r_box{\let\placerightmarginblock\page_margin_blocks_place_r_yes}
204\def\page_margin_blocks_set_l_box{\let\placeleftmarginblock \page_margin_blocks_place_l_yes}
205
206
207
208\unexpanded\def\page_margin_blocks_process_float
209 {\doifelse{\marginblockparameter\c!state}\v!start
210 \page_margin_blocks_process_float_yes
211 \page_margin_blocks_process_float_nop}
212
213\def\page_margin_blocks_process_float_yes
214 {\global\setbox\b_page_margin_blocks\vbox
215 {\hsize\marginblockparameter\c!width
216 \unvcopy\b_page_margin_blocks
217 \ifvoid\b_page_margin_blocks\else
218 \expandafter\marginblockparameter\expandafter\c!inbetween
219 \fi
220 \box\floatbox
221 \filbreak}
222 \ifdim\ht\b_page_margin_blocks>\textheight
223
224 \else
225 \page_floats_report_total
226 \fi}
227
228\def\page_margin_blocks_process_float_nop
229 {\handlefloatmethod\v!here}
230
231\def\page_margin_blocks_float_before
232 {\ifconditional\c_page_margin_blocks_enabled
233 \doifinset\v!margin\floatlocation\endgraf
234 \fi}
235
236\def\page_margin_blocks_float_set_hsize
237 {\ifconditional\c_page_margin_blocks_enabled
238 \doifinset\v!margin\floatlocation{\hsize\rootmarginblockparameter\c!width}
239 \fi}
240
241\appendtoks
242 \ifvoid\b_page_margin_blocks \else
243 \writestatus\m!layouts{beware: there are leftover margin floats!}
244 \fi
245\to \everystoptext
246
247\unexpanded\def\flushmarginblocks
248 {\page_otr_command_flush_margin_blocks}
249
250\protect \endinput
251 |