page-mbk.mkvi /size: 8152 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=page-mbk,   % was part of page-mis.mkiv / 2008.11.17
3%D        version=2011.11.23, % was part of page-flt.tex  / 2000.10.20
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Margin Floats,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Page Macros / Margin Floats}
15
16\unprotect
17
18%D This is an old mechanism that is quite independent of other
19%D floats. There is for instance no save/restore used here. When
20%D there is need (and demand) we can use the float cache and then
21%D flush them in the text when they are left over. On the other
22%D hand, margin float are somewhat manual so it does not make too
23%D much sense to complicate the code. As an alternative users can
24%D fall back on margin texts: they do stack but don't float.
25%D
26%D \starttyping
27%D \dorecurse{9} {
28%D   \placefigure[margin]{#1}{}
29%D   \input ward
30%D }
31%D \page \null % will flush them
32%D \stoptyping
33
34% status=start: in margin
35% status=stop : in text
36%
37% todo: flush margin floats at end of text
38% todo: separate boxes for left and right
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 % not really needed as we can check each time
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  %\c!style=,
63  %\c!color=,
64  %\c!align=,
65  %\c!left=,
66  %\c!right=,
67  %\c!top=,
68  %\c!before=,
69  %\c!after=,
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 % 2 maal \vbox ivm \unvbox elders
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% inner outer
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% margin floats (keyword 'margin' in option list)
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   % page_floats_report_saved % no saving done anyway
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 left-over margin floats!}%
244   \fi
245\to \everystoptext
246
247\unexpanded\def\flushmarginblocks
248  {\page_otr_command_flush_margin_blocks}
249
250\protect \endinput
251