Debian Codegraph @

texmf-dist/tex/plain/zztex/zzfloat.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %
3 % Module: ZzTeX Float Facilities
4 %
5 % Synopsis: This module contains the float and caption blocks, as well as
6 % all the code required to support the scheduling of floats.
7 %
8 % Notes: The broadside capability was implemented by Richard A. Wells and
9 % integrated into ZzTeX on 9/7/94.
10 %
11 % Author: Richard A. Wells & Paul C. Anagnostopoulos
12 % Created: 7 March 1990
13 %
14 % Copyright 1989--2020 by Paul C. Anagnostopoulos
15 % under The MIT License (opensource.org/licenses/MIT)
16 %
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18
19 % Data Structures
20 % ---- ----------
21
22
23 \definecount{\zfltcount}{0}
24 \def \zfloatfreeq {}
25 \def \zfloatpendq {}
26
27
28 \def \zdeffloat #1#2{% {\float}{\float-box}
29 \definebox{#2}%
30 \zfreefloat{#1}{#2}%
31 \global\increment \zfltcount}
32
33 \def \zgetfloat #1{% {\float}
34 \if \emptydefp{\zfloatfreeq}%
35 \error{toomanyflt}
36 {More than `\the\zfltcount' floats remain for page makeup}%
37 \else
38 \pop{#1}{\zfloatfreeq}%
39 \fi}
40
41 \def \zfreefloat #1#2{% {\float}{\float-box}
42 \gdef #1{\def \zcurfloatbox {#2}}%
43 \append{#1}{\zfloatfreeq}}
44
45 \zdeffloat{\zflta}{\zfltboxa}
46 \zdeffloat{\zfltb}{\zfltboxb}
47 \zdeffloat{\zfltc}{\zfltboxc}
48 \zdeffloat{\zfltd}{\zfltboxd}
49 \zdeffloat{\zflte}{\zfltboxe}
50 \zdeffloat{\zfltf}{\zfltboxf}
51 \zdeffloat{\zfltg}{\zfltboxg}
52 \zdeffloat{\zflth}{\zfltboxh}
53 \zdeffloat{\zflti}{\zfltboxi}
54 \zdeffloat{\zfltj}{\zfltboxj}
55 \zdeffloat{\zfltk}{\zfltboxk}
56 \zdeffloat{\zfltl}{\zfltboxl}
57 \zdeffloat{\zfltm}{\zfltboxm}
58 \zdeffloat{\zfltn}{\zfltboxn}
59 \zdeffloat{\zflto}{\zfltboxo}
60 \zdeffloat{\zfltp}{\zfltboxp}
61 \zdeffloat{\zfltq}{\zfltboxq}
62 \zdeffloat{\zfltr}{\zfltboxr}
63 \zdeffloat{\zflts}{\zfltboxs}
64 \zdeffloat{\zfltt}{\zfltboxt}
65 \zdeffloat{\zfltu}{\zfltboxu}
66 \zdeffloat{\zfltv}{\zfltboxv}
67 \zdeffloat{\zfltw}{\zfltboxw}
68 \zdeffloat{\zfltx}{\zfltboxx}
69 \zdeffloat{\zflty}{\zfltboxy}
70 \zdeffloat{\zfltz}{\zfltboxz}
71
72 % There is an insert class for each of the two places where floats
73 % can go.
74
75 \defineinsert{\ztopcolinsert} % Floats at top of column.
76 \count\ztopcolinsert = 1000
77 \dimen\ztopcolinsert = \maxdimen
78 \skip\ztopcolinsert = 0pt
79 \defineinsert{\zbotcolinsert} % Floats at bottom of column.
80 \count\zbotcolinsert = 1000
81 \dimen\zbotcolinsert = \maxdimen
82 \skip\zbotcolinsert = 0pt
83
84
85 % We need a dimension register to capture box depths.
86
87 \definedimen{\zfloatdp}{0pt}
88
89 % Float Types
90 % ----- -----
91
92
93 \setlist \zfloattypelist = {}
94
95
96 \def \definefloattype #1#2#3{% {type}{toc-level}{association}
97 \if \emptyargp{#3}%
98 \withname\definecount{\float#1number}{0}%
99 \withname\declaresnapitem{\float#1number}%
100 \else
101 \edef \znext {%
102 \global\withname\let{\float#1number}=\name{\float#3number}}%
103 \znext
104 \fi
105 \withname\gdef{\zflt#1lvl}{#2}%
106 \append{#1}{\zfloattypelist}}
107
108
109 \def \resetfloatnumbers {%
110 \maplist{\global\name{\float##1number}=0\relax}{\zfloattypelist}}
111
112
113 % Predefined float types (don't forget an index locator for each one).
114
115 \definefloattype{algorithm}{101}{}
116 \definefloattype{figure}{102}{}
117 \definefloattype{table}{103}{}
118 \definefloattype{listing}{104}{}
119 \definefloattype{sidebar}{105}{}
120
121 % Float Block
122 % ----- -----
123
124
125 \defineblock{\float}{\endfloat}{\false}{}
126
127 %~block float Type
128 % \aboveskip = glue % Space b/b above float.
129 % \def \beginformat {...} % Beginning of float formatter.
130 % \belowskip = glue % Space b/b below float.
131 % \def \comptextformat {...} % Composite number text formatter.
132 % \continue = integer % Continued or continuation.
133 % \def \endformat {...} % End of float formatter.
134 % \leftindent = dimen % Horizontal fudge for all floats.
135 % \pageplacement = {...} % Overriding page placement.
136 % \position = {...} % Position (see below).
137 % \runners = {style} % Runners for a page of floats.
138 % \topfloatfudge = dimen % Vertical fudge for topmost float.
139 % \width = dimen % Explicit width for float.
140 %~end
141
142 \definetoks{\pageplacement}
143 \definedimen{\topfloatfudge}{0pt}
144
145 % These derived parameters are needed here and by \caption. They may
146 % also be useful to the user.
147
148 \definecount{\floatpage}{0}
149 \definedimen{\floatshift}{0pt}
150 \definedimen{\floatwidth}{0pt}
151
152 \definecount{\zdivfltcounter}{0} % Count floats in each division.
153 \definebox{\zfltbroadbox}
154
155
156 % Floats are packaged up in a vbox using \vtop, so that the float box
157 % has the same height as the first thing inside. This improves the
158 % chances that a float at the top of a page will be positioned correctly.
159
160 \def \float #1{% {type}
161 \if \undefinedp{\float#1number}%
162 \error{undefflt}{Float type `#1' has not been defined}%
163 \fi
164 \endgraf
165 \blockcantbein{\float}{\float}%
166 \blockcantbein{\float}{\multicolumn}%
167 \beginblockscope{float}%
168 \global\increment \floatdepth
169 \global\increment \zdivfltcounter
170 \whichpage{\floatpage}{zF:\the\divisionname-\the\zdivfltcounter}%
171 \def \beginformat {}% %~default soft
172 \continue = 0 %~default with
173 \def \comptextformat {}% %~default soft
174 \setflag \continuation = \false % Deprecated
175 \def \endformat {}% %~default soft
176 \leftindent = 0pt %~default soft
177 \pageplacement = {}% %~default with
178 \runners = {normal}% %~default soft
179 \zoldrunners{\normalheader\normalfooter}%
180 \width = \naturalwidth %~default soft
181 \processdesign{\float}{#1}%
182 \zsetcontinue % Handle old \continuation.
183 \if \notp{\continuationp}\global\withname\increment{\float#1number}\fi
184 \global\withname\floatnumber{\float#1number}%
185 \setcomptext{\floatcomptext}%
186 \def \zcurflttype {#1}%
187 \edef \zcurfltlvl {\name{\zflt\zcurflttype lvl}}%
188 \parindent = 0pt
189 \parrag = 0pt
190 \parskip = 0pt
191 \zparsefltpos{\the\position}%
192 \if \notp{\emptytoksp{\pageplacement}}%
193 \zparsefltpagepos{\the\pageplacement}%
194 \fi
195 \if \zfltposhere
196 \penalty \breakallowed % Synchronize main list.
197 \zparsefltpos{\the\position}% % Recalculate global stuff.
198 \if \notp{\emptytoksp{\pageplacement}}
199 \zparsefltpagepos{\the\pageplacement}%
200 \fi
201 \fi
202 \zcalcfltparams
203 \zgetfloat{\zcurfloat}%
204 \zcurfloat
205 \global\setbox \zcurfloatbox = \vtop \bgroup
206 \zpushvcontext
207 \setindentation{0pt}{0pt}%
208 \settextwidth{\floatwidth}%
209 \settaginfo{\the\floatcomptext}{}% % Set tag info without title.
210 \setsubtagnumber{0}%
211 \beginformat}
212
213 \def \endfloat {%
214 \endgraf
215 \endformat
216 \global\zfloatdp = \prevdepth
217 \tagpageonly{\uniquetag{zF}{\the\zdivfltcounter}}%
218 \zpopvcontext
219 \egroup % \vtop
220 \expandafter\xdef \zcurfloat {%
221 \def \noexpand\zcurfloatid {\zcurflttype\space \the\floatnumber}%
222 \def \noexpand\zcurfloatbox {\zcurfloatbox}%
223 \zfloatdp = \the\zfloatdp
224 \aboveskip = \the\aboveskip
225 \belowskip = \the\belowskip
226 \leftindent = \the\leftindent
227 \position = {\the\position}%
228 \pageplacement = {\the\pageplacement}%
229 \runners = {\the\runners}%
230 \floatshift = \the\floatshift
231 \topfloatfudge = \the\topfloatfudge}%
232 \expandafter\append \zcurfloat{\zfloatpendq}%
233 \zschedulefloats{\znext}{\false}{\false}%
234 \if \gtrp{\znext}{99}%
235 \zfltpage{\zpenfloatpage}%
236 \fi
237 \global\decrement \floatdepth
238 \endblockscope{float}}
239
240 %~ This |\float| modifier forces an alone float.
241
242 \def \alonefloat {% %^modifier
243 \with{\pageplacement={\alone}}}
244
245 %~ This |\float| modifier forces a bottom float.
246
247 \def \bottomfloat {% %^modifier
248 \with{\pageplacement={\bottom}}}
249
250 %~ This |\float| modifier forces a broadside float.
251
252 \def \broadsidefloat {% %^modifier
253 \with{\pageplacement={\broadside}}}
254
255 %~ This |\float| modifier forces a here float.
256
257 \def \herefloat {% %^modifier
258 \with{\pageplacement={\here}}}
259
260 %~ This |\float| modifier forces a separate float.
261
262 \def \separatefloat {% %^modifier
263 \with{\pageplacement={\separate}}}
264
265 %~ This |\float| modifier allows the float to occupy the
266 %~ running head area. Any running head is deleted.
267
268 \def \userharea {% %^modifier
269 \with{\runners={blind}%
270 \advance \topfloatfudge by -\headerheight}}
271
272 \def \adjusttopfloatfudge #1{%
273 \global\advance \topfloatfudge by #1\relax}
274
275 \def \piggybackfloat {%
276 \edef \znext {\noexpand\global\noexpand\increment
277 \name{\float\zcurflttype number}}%
278 \znext
279 \edef \znext {\floatnumber = \name{\float\zcurflttype number}}%
280 \znext}
281
282 % Controlling Floats
283 % ----------- ------
284
285
286 % This macro is invoked at the beginning of each division.
287
288 \def \zfltdivinit {%
289 \global\zdivfltcounter = 0\relax}
290
291
292 \setflag \zschedflts = \true
293
294 \def \deferfloats #1{% {boolean}
295 \global\setflag \zschedflts = {\notp{#1}}}
296
297
298 % Scheduling Tools
299 % ---------- -----
300
301
302 % These counters keep track of the number of floats scheduled for the
303 % current page.
304
305 \definecount{\ztopcolfloats}{0} % Number of top column floats.
306 \definecount{\zbotcolfloats}{0} % Number of bottom column floats.
307 \definecount{\zfloatsinserted}{0} % Total number of floats.
308 \definetoks{\zfltrunners} % Runners for first float on page.
309
310 % This macro initializes for handling floats on a new page.
311
312 \def \zfloatinit {%
313 \global\setflag \zschedflts = \true
314 \global\ztopcolfloats = 0
315 \global\zbotcolfloats = 0
316 \zfltrunners = {}}
317
318 % These macros simply hide some of the details to make the \zsched*
319 % macros easier to read.
320
321 \def \ztallytopfloat {%
322 \if \orp{\notp{\zfltposmargonly}}{\posp{\ztopcolfloats}}%
323 \global\increment \ztopcolfloats
324 \fi}
325
326 \def \zforcenewpage{%
327 \global\zfloatsinserted = 101\relax}
328
329 \let \zquitscheding = \exitmaplist
330
331 \def \zsetfloattall{%
332 \zmakefloatalone
333 \setflag \zfloattall = \true
334 \tracepagemakeup{Float is too tall for column; positioning `alone'.}}
335
336 \def \zmakefloatalone{%
337 \setflag \zfltposalone = \true
338 \setflag \zfltposbottom = \false
339 \setflag \zfltposhereonly = \false
340 \setflag \zfltposhere = \false
341 \setflag \zfltposseparate = \false
342 \setflag \zfltpostop = \false}
343
344 \def \zmakefloattop{%
345 \setflag \zfltposalone = \false
346 \setflag \zfltposbottom = \false
347 \setflag \zfltposhereonly = \false
348 \setflag \zfltposhere = \false
349 \setflag \zfltposseparate = \false
350 \setflag \zfltpostop = \true}
351
352 % Float Scheduler
353 % ----- ---------
354
355
356 % return-count is a counter passed in by the caller that we should
357 % set at the end of \zschedulefloats to indicate how
358 % many floats were emitted during this call. A value
359 % greater than 99 indicates that a new page should be
360 % FORCED (e.g. for alone floats) by the output routine.
361 % during-output? is a flag indicating that the caller is
362 % part of the output routine.
363 % flushing? A flag indicating whether we are flushing floats.
364
365 \def \zschedulefloats #1#2#3{% {return-count}{during-output?}{flushing?}
366 \tracepagemakeup{[Scheduling \if #2floats during output%
367 \else float when encountered\fi.}%
368 \tracepagemakeup{Page total: \the\pagetotal; goal: \the\pagegoal.}%
369 % Reset our counter
370 \global\zfloatsinserted = 0
371 \if \zschedflts
372 \if \emptydefp{\zfloatpendq}%
373 \tracepagemakeup{There are no floats to be scheduled.}%
374 \else
375 \endgraf
376 \zinitfloatfit{#2}%
377 {\setflag \zschedfirstseparate = \true
378 \setflag \zschedseparateloop = \false
379 \maplist{\zschedone{#2}{#3}{##1}}{\zfloatpendq}}%
380 \fi
381 \else
382 \tracepagemakeup{Floats are deferred now.}%
383 \fi
384 \tracepagemakeup{Float scheduling complete;
385 floats inserted: \the\zfloatsinserted.]}%
386 \xdef #1{\the\zfloatsinserted}}
387
388
389 \def \zschedone #1#2#3{% {during-output?}{flushing?}{\float}
390 #3%
391 \zparsefltpos{\the\position}%
392 \if \notp{\emptytoksp{\pageplacement}}
393 \zparsefltpagepos{\the\pageplacement}%
394 \fi
395 \if #2% % If flushing floats, force float
396 \setflag \zfltposbottom = \false % to a `separate'.
397 \setflag \zfltpostop = \false
398 \setflag \zfltposseparate = \true
399 \fi
400 \tracepagemakeup{Trying to schedule \zcurfloatid;
401 size: \the\ht\zcurfloatbox+\the\dp\zcurfloatbox.}%
402 \if \orp{\andp{\zfltposeven}{\oddpagep}}%
403 {\andp{\zfltposodd}{\evenpagep}}%
404 \tracepagemakeup{Float is deferred until appropriate even/odd page.}%
405 \zquitscheding
406 \else
407 \setflag \zfloatunsched = \true
408 \setflag \zfloattall = \false
409 % The following macros attempt, in order of priority, to schedule
410 % the current float. Each macro may set up state that causes
411 % the subsequent macro(s) to do nothing.
412 \zschedhereonly{#1}%
413 \zschedhere{#1}%
414 \zschedalone{#1}%
415 \zschedbroadside{#1}%
416 \zschedseparate{#1}%
417 \zschedtop{#1}%
418 \zschedbottom{#1}%
419 \if \zfloattall % Schedule as `alone'.
420 \zschedalone{#1}%
421 \fi
422 \if \zfloatunsched
423 \tracepagemakeup{Float could not be scheduled.}%
424 % This exits a \maplist call to \zschedone.
425 \zquitscheding
426 \else
427 % Remove the current float from the queue...
428 \pop{\zcurfloat}{\zfloatpendq}%
429 % ...and free up the associated data structures.
430 \expandaftertwice\zfreefloat \expandafter\zcurfloat\zcurfloatbox
431 \fi
432 \fi}
433
434 % Fitting a Float
435 % ------- - -----
436
437
438 % These registers are used in float fitting. They contain,
439 % respectively, the amount of vertical space used up by floats for
440 % the current page and the maximum space available for floats.
441
442 \definedimen{\zfloatpageused}{0pt}
443 \definedimen{\zfloatmaxavail}{0pt}
444
445
446 % Macro to initialize the above parameters (called in \zschedulefloats).
447
448 \def\zinitfloatfit #1{% {during-output?}
449 \if #1
450 \zfloatpageused = 0pt
451 % Effectively: zfloatmaxavail = (100-mintextpercent) * vsize
452 \calculate \tcounta = {100,-,\mintextpercent}%
453 \calculate \zfloatmaxavail = {\vsize,P,\tcounta}%
454 \else
455 % Effectively: zfloatpageused = max(pagetotal, vsize * mintextpercent)
456 \calculate \zfloatpageused = {\vsize,P,\mintextpercent,X,\pagetotal}%
457 \zfloatmaxavail = \pagegoal
458 \fi}
459
460
461 % The spacing above and below a float is fairly complicated.
462 % In this table, h is the height of the float, d is the depth.
463 %
464 % Position Sequence Above Below
465 %
466 % \alone only \topskip - h + none
467 % \topfloatfudge
468 % \bottom first \aboveskip - h none
469 % rest min(\aboveskip, none
470 % \belowskip) - h
471 %
472 % \separate first \topskip - h + none
473 % \topfloatfudge
474 % rest min(\aboveskip, none
475 % \belowskip) - h
476 % \top first \topskip - h + \belowskip - \topskip - d
477 % \topfloatfudge
478 % rest min(\aboveskip, \belowskip - \topskip - d
479 % \belowskip) - h
480
481
482 % Here and broadside floats are handled differently, below in \zfitfloathere
483 % and \zfitfloatbroadside
484
485 \def \zfitfloat #1#2#3#4#5{% {result-flag}{top?}{aboveskip-first}
486 % {aboveskip-rest}{belowskip}
487 {\if \zfltposmargonly
488 \tcounta = 0 % Margin float should act as first one.
489 \else
490 \tcounta = \if #2\ztopcolfloats \else \zbotcolfloats \fi
491 \fi
492 \zskipa = \if \zerop{\tcounta}#3\else #4\fi
493 \advance \zskipa by -\ht\zcurfloatbox
494 \if \andp{#2}{\zerop{\tcounta}}\advance \zskipa by \topfloatfudge \fi
495 \tdimena = \zskipa
496 \advance \tdimena by \ht\zcurfloatbox
497 \advance \tdimena by \dp\zcurfloatbox
498 \tdimenb = #5\advance \tdimena by \tdimenb
499 \tdimenc = \zfloatpageused
500 \if \notp{\zfltposmargonly}\advance \tdimenc by \tdimena \fi
501 \tracepagemakeup{Requires: \the\tdimena;
502 available: \the\zfloatmaxavail;
503 used: \the\zfloatpageused.}%
504 \if \dimlssp{\tdimenc}{\zfloatmaxavail}%
505 \if \andp{\notp{#2}}{\zfltposmargonly}%
506 \insert \zbotcolinsert {%
507 \vbox to 0pt{%
508 \vss
509 \moveright \floatshift \box\zcurfloatbox
510 \vskip -\dp\zcurfloatbox}}%
511 \else
512 \insert \if #2\ztopcolinsert \else \zbotcolinsert \fi {%
513 \vskip \zskipa
514 \moveright \floatshift \box\zcurfloatbox
515 \nobreak
516 \if \zfltposmargonly
517 \vskip \tdimenb
518 \nobreak
519 \vskip -\tdimena
520 \else
521 \vskip #5\relax
522 \fi}%
523 \fi
524 \if \emptytoksp{\zfltrunners}%
525 \global\zfltrunners = \expandafter{\the\runners}%
526 \fi
527 \global\increment \zfloatsinserted
528 \global\zfloatpageused = \tdimenc
529 \global\setflag #1= \true
530 \else
531 \global\setflag #1= \false
532 \fi}}
533
534 \def \zfitfloathere #1#2#3{% {result-flag}{aboveskip}{belowskip}
535 {\tdimena = #2\relax
536 \advance \tdimena by \dp\zcurfloatbox
537 \advance \tdimena by #3\relax
538 \tracepagemakeup{Requires: \the\tdimena;
539 page total: \the\pagetotal;
540 page goal: \the\pagegoal.}%
541 \advance \tdimena by \pagetotal
542 \if \dimlssp{\tdimena}{\pagegoal}%
543 \bbskipabove{\breaknever}{#2}%
544 \fakepar
545 \moveright \floatshift \box\zcurfloatbox
546 \prevdepth = \zfloatdp
547 \bbskipbelow{\breakallowed}{#3}%
548 \global\increment \zfloatsinserted
549 \global\setflag #1= \true
550 \else
551 \global\setflag #1= \false
552 \fi}}
553
554 \def \zfitfloatbroadside {%
555 {% We know there are no other floats on the the topcolumn when
556 % this is called (by \zschedbroadside only) and we don't have to
557 % worry about fixing up the vertical position at the end of the
558 % page.
559 %
560 % Compute the space required
561 % Start with the topskip
562 \tdimena = \topfloatfudge
563 % Add the *width* (since the box will be rotated)
564 \advance \tdimena by \wd\zcurfloatbox
565 \tracepagemakeup{Requires: \the\tdimena;
566 broadside floats always fit.}%
567 \insert \ztopcolinsert {%
568 % vskip the top float fudge
569 \vskip \topfloatfudge
570 % save the width for unskipping later
571 \tdimenb = \wd\zcurfloatbox
572 % vskip the *width* of the box to do the position translation
573 % that we can't do with PostScript
574 \vskip \tdimenb
575 % Put our hbox in a vbox, so we can "lower" it rather than move
576 % it right (since it will be rotated)
577 \global\setbox\zfltbroadbox = \vbox{%
578 \vskip\floatshift % replaces \moveright in other floats
579 \box\zcurfloatbox}%
580 \rotatebox{\zfltbroadbox}{90}%
581 % Undo vertical skip so that insert doesn't cause additional page
582 \vskip -\tdimenb}%
583 \if \emptytoksp{\zfltrunners}%
584 \global\zfltrunners = \expandafter{\the\runners}%
585 \fi
586 \global\increment \zfloatsinserted
587 \global\zfloatpageused = \tdimena}}
588
589 % Individual Schedulers
590 % ---------- ----------
591
592
593 % This is a temporary register used in calls to \zfitfloat where the
594 % fit needs to take into account more than one skip value (such as
595 % both the \aboveskip and \belowskip). In that case this dimen is
596 % used as a temp to hold the sum of the skip values.
597
598 \defineskip{\zfloatabove}{0pt}
599 \defineskip{\zfloatbelow}{0pt}
600 \definedimen{\zfloatextraskip}{0pt}
601
602
603 % This scheduler is called for floats with position `here' and no others.
604
605 \def\zschedhereonly #1{% {during-output?}
606 \if \andp{\zfloatunsched}{\zfltposhereonly}%
607 \tracepagemakeup{Float is to be positioned `here' only.}%
608 \if \zschedseparateloop
609 \tracepagemakeup{Making up a page of separates; quit.}%
610 \zforcenewpage
611 \zquitscheding
612 \else
613 \if #1% during output:
614 \tracepagemakeup{Float moved to top of this page.}%
615 \zmakefloattop
616 \else % when encountered:
617 \if \posp{\zbotcolfloats}%
618 \error{hereonlybot}{Cannot position float `here'; already floats
619 at bottom.}%
620 \else\if \dimzerop{\pagetotal}%
621 \tracepagemakeup{Float at top of column: schedule as `top' float.}%
622 \zmakefloattop
623 \else
624 \zfitfloathere{\zfloatfits}{\aboveskip}{\belowskip}%
625 \if \zfloatfits
626 \tracepagemakeup{Float inserted here.}%
627 \setflag \zfloatunsched = \false
628 \else
629 \tracepagemakeup{Float does not fit here.}%
630 \zforcenewpage
631 \zquitscheding
632 \fi
633 \fi\fi
634 \fi
635 \fi
636 \fi}
637
638
639 % This scheduler is called for floats with position `here' along with at
640 % least one other page position.
641
642 \def\zschedhere #1{% {during-output?}
643 \if \andp{\zfloatunsched}{\zfltposhere}%
644 \tracepagemakeup{Float can be positioned `here'.}%
645 \if \zschedseparateloop
646 \tracepagemakeup{Making up a page of separates; quit.}%
647 \zforcenewpage
648 \zquitscheding
649 \else
650 \if #1% during output:
651 \relax
652 \else % when encountered:
653 \if \posp{\zbotcolfloats}%
654 \tracepagemakeup{There are already floats positioned `bottom'.}%
655 \else\if \dimzerop{\pagetotal}%
656 \tracepagemakeup{Float at top of column: schedule as `top' float.}%
657 \zmakefloattop
658 \else
659 \zfitfloathere{\zfloatfits}{\aboveskip}{\belowskip}%
660 \if \zfloatfits
661 \tracepagemakeup{Float inserted here.}%
662 \setflag \zfloatunsched = \false
663 \else
664 \tracepagemakeup{Float does not fit here.}%
665 \fi
666 \fi\fi
667 \fi
668 \fi
669 \fi}
670
671
672 \def \zschedalone #1{% {during-output?}
673 \if \andp{\zfloatunsched}{\zfltposalone}%
674 \tracepagemakeup{Float can be positioned `alone'.}%
675 \if \zschedseparateloop
676 \tracepagemakeup{Making up a page of separates; quit.}%
677 \zforcenewpage
678 \zquitscheding
679 \else
680 \if \orp{#1}{\dimzerop{\pagetotal}}%
681 \if \firstcolumnp % building new page
682 \if \zerop{\zfloatsinserted}% no floats on this page, yet
683 \dp\zcurfloatbox = 0pt % Make it fit.
684 \zfitfloat{\zfloatfits}{\true}{\topskip}{999pt}{0pt}%
685 \if \zfloatfits
686 \ztallytopfloat
687 \tracepagemakeup{Inserted on a page by itself.}%
688 \zforcenewpage
689 \setflag \zfloatunsched = \false
690 \zquitscheding
691 \fi
692 \else % wait for next time
693 \tracepagemakeup{Already floats in this column; quit.}%
694 \zquitscheding
695 \fi
696 \else% still in the middle of a page
697 \tracepagemakeup{Not in first column of page; quit.}%
698 \zquitscheding
699 \fi
700 \else % As encountered, and page not empty.
701 \tracepagemakeup{Must wait for new page; quit.}%
702 \zquitscheding
703 \fi
704 \fi
705 \fi}
706
707 \def \zschedbroadside #1{% {during-output?}
708 \if \andp{\zfloatunsched}{\zfltposbroadside}%
709 \tracepagemakeup{Float can be positioned `broadside'.}%
710 \if \zschedseparateloop
711 \tracepagemakeup{Making up a page of separates; quit.}%
712 \zforcenewpage
713 \zquitscheding
714 \else
715 \if \orp{#1}{\dimzerop{\pagetotal}}%
716 \if \firstcolumnp % building new page
717 \if \zerop{\zfloatsinserted}% no floats on this page, yet
718 % Broadside floats "always" fit. The output will have to be
719 % inspected.
720 \zfitfloatbroadside
721 \ztallytopfloat
722 \tracepagemakeup{Inserted on a page by itself.}%
723 \zforcenewpage
724 \setflag \zfloatunsched = \false
725 \zquitscheding
726 \else % wait for next time
727 \tracepagemakeup{Already floats on this page; quit.}%
728 \zquitscheding
729 \fi
730 \else% still in the middle of a page
731 \tracepagemakeup{Not in first column of page; quit.}%
732 \zquitscheding
733 \fi
734 \else % As encountered, and page not empty.
735 \tracepagemakeup{Must wait for new page; quit.}%
736 \zquitscheding
737 \fi
738 \fi
739 \fi}
740
741
742 \def\zschedseparate #1{% {during-output?}
743 \if \andp{\zfloatunsched}{\zfltposseparate}%
744 \tracepagemakeup{Float can be positioned `separate'.}%
745 % If a separate float is called when encountered, we don't do anything.
746 \if #1% during output
747 \if \firstcolumnp % building a new page
748 \if \zschedfirstseparate
749 \if \zerop{\zfloatsinserted}% no floats on this page, yet
750 \zfloatmaxavail = \vsize % Entire page is available now.
751 \zfitfloat{\zfloatfits}{\true}{\topskip}{999pt}{0pt}%
752 \if \zfloatfits
753 \ztallytopfloat
754 \setflag \zfloatunsched = \false
755 \zforcenewpage % This is a page of separates now.
756 \tracepagemakeup{Inserted at the top of a new page.}%
757 \setflag \zschedfirstseparate = \false
758 \setflag \zschedseparateloop = \true
759 \else
760 \zsetfloattall
761 \fi
762 \else % wait for next time
763 \tracepagemakeup{Page already has other floats on it.}%
764 \zquitscheding
765 \fi
766 \else % Subsequent separates.
767 \zfloatabove = \if \dimlssp{\aboveskip}{\belowskip}\aboveskip
768 \else \belowskip \fi
769 \zfitfloat{\zfloatfits}{\true}{999pt}{\zfloatabove}{0pt}%
770 \if \zfloatfits
771 \ztallytopfloat
772 \setflag \zfloatunsched = \false
773 \tracepagemakeup{Inserted on a page with other separates.}%
774 \else
775 \zquitscheding
776 \tracepagemakeup{Does not fit on this page; start new page.}%
777 \fi
778 \fi
779 \else% still in the middle of a page
780 \tracepagemakeup{Must wait for new page; quit;}%
781 \zquitscheding
782 \fi
783 \else% when encountered
784 \tracepagemakeup{Must wait for new page; quit.}%
785 \zquitscheding
786 \fi
787 \fi}
788
789
790 \def\zschedtop#1{% {during-output?}
791 \if \andp{\andp{\zfloatunsched}{\zfltpostop}}
792 {\orp{\notp{\zfltposfollow}}{#1}}%
793 \tracepagemakeup{Float can be positioned `top'.}%
794 \if \zschedseparateloop
795 \tracepagemakeup{Making up a page of separates; quit.}%
796 \zforcenewpage
797 \zquitscheding
798 \else
799 \if \lssp{\ztopcolfloats}{\maxtopcolumnfloats}%
800 \zfloatabove = \if \dimlssp{\aboveskip}{\belowskip}\aboveskip
801 \else \belowskip \fi
802 \advance \zfloatabove by -\belowskip
803 \advance \zfloatabove by \topskip
804 \zfloatbelow = \belowskip
805 \tdimena = \topskip
806 \advance \zfloatbelow by -\tdimena
807 \advance \zfloatbelow by -\zfloatdp
808 \zfitfloat{\zfloatfits}{\true}{\topskip}{\zfloatabove}{\zfloatbelow}%
809 \if \zfloatfits
810 \ztallytopfloat
811 \tracepagemakeup{Inserted at top of column.}%
812 \setflag \zfloatunsched = \false
813 \else
814 \if \andp{#1}{\zerop{\zfloatsinserted}}\zsetfloattall \fi
815 \fi
816 \fi
817 \fi
818 \fi}
819
820 \def \zschedbottom#1{% {during-output?}
821 \if \andp{\zfloatunsched}{\zfltposbottom}%
822 \tracepagemakeup{Float can be positioned `bottom'.}%
823 \if \zschedseparateloop
824 \tracepagemakeup{Making up a page of separates; quit.}%
825 \zforcenewpage
826 \zquitscheding
827 \else
828 \if \lssp{\zbotcolfloats}{\maxbottomcolumnfloats}%
829 \zfloatbelow = \if \dimlssp{\aboveskip}{\belowskip}\aboveskip
830 \else \belowskip \fi
831 \zfitfloat{\zfloatfits}{\false}{\aboveskip}{\zfloatbelow}{0pt}%
832 \if \zfloatfits
833 \if \notp{\zfltpostopafterbot}%
834 \global\ztopcolfloats = \maxtopcolumnfloats
835 \fi
836 \global\increment \zbotcolfloats
837 \tracepagemakeup{Inserted at bottom of column.}%
838 \setflag \zfloatunsched = \false
839 \else
840 \if \andp{#1}{\zerop{\zfloatsinserted}}\zsetfloattall \fi
841 \fi
842 \fi
843 \fi
844 \fi}
845
846 % Captions
847 % --------
848
849
850 \defineblock{\caption}{\endcaption}{\false}{}
851
852 %~block caption Type
853 % \aboveskip = glue % Space b/b above caption.
854 % \setflag \allowintoc = flag % Allow caption in ToC.
855 % \belowskip = glue % Space b/b below caption.
856 % \captionfudge = dimen % Fudge for \aboveskip.
857 % \def \comptextformat {...} % (No longer used with captions.)
858 % \difficulty = integer % Level of difficulty.
859 % \leftindent = glue % Left indentation.
860 % \legendfont = {...} % Font for optional legend.
861 % \def \legendformat ##1{...} % Legend formatter.
862 % \numberfont = {...} % Font for float number.
863 % \parindent = dimen % Paragraph indent.
864 % \parrag = dimen % Paragraph raggedness.
865 % \parskip = glue % Paragraph skip.
866 % \position = {...} % Position (see below).
867 % \rightindent = glue % Right indentation.
868 % \style = {...} % Heading style.
869 % \titlefont = {...} % Font for caption title.
870 % \def \titleformat ##1{...} % Title formatter.
871 % \width = dimen % Width of caption text.
872 %~end
873
874 \definedimen{\captionfudge}{0pt}
875 \definetoks{\legendfont}
876
877 \definebox{\zcapbox}
878 \definedimen{\zcapshift}{0pt}
879
880 %~ This marker indicates that the following text is the legend or
881 %~ credit for the caption.
882
883 \definemarker{\legend}
884
885
886 \def \caption #1{% {title with optional \legend}
887 \blockmustbein{\caption}{\float}%
888 \blockcantbein{\caption}{\caption}%
889 \beginblockscope{caption}%
890 \global\increment \captiondepth
891 \captionfudge = 0pt %~default with
892 \def \comptextformat {}% %~default hard
893 \style = {Initial cap/lowercase}% %~default soft
894 \difficulty = 0 %~default with
895 \processdesign{\caption}{\zcurflttype}%
896 \global\increment \captionnumber
897 \if \notp{\emptydefp{\comptextformat}}%
898 \error{capcomptext}{The \string\comptextformat\space parameter is no
899 longer used in captions}
900 \fi
901 \captionformat #1\legend\zmark
902 \if \andp{\allowintoc}{\notp{\continuationp}}\zcaptoc #1\legend\zmark \fi
903 \endcaption
904 \zcaptag #1\legend\zmark}% % Reset tag info with title.
905
906 \def \endcaption {%
907 \global\decrement \captiondepth
908 \endblockscope{caption}}
909
910 \def \captionformat #1\legend#2\zmark{%
911 \the\numberfont
912 \setbox\zcapbox = \vtop{%
913 \zpushvcontext
914 \setindentation{\leftindent}{\rightindent}%
915 \settextwidth{\width}%
916 \setparrag{\parrag}%
917 \if \emptyargp{#2}%
918 \titleformat{#1}%
919 \else
920 \let \legend = \relax % So it won't interfere with formatting.
921 \titleformat{#1\the\legendfont \legendformat{#2}}%
922 \fi
923 \endgraf
924 \global\zfloatdp = \prevdepth
925 \zpopvcontext}%
926 \zparsecappos{\the\position}%
927 \zcalccapitems
928 \bbskipabove{\breaknever}{\aboveskip}%
929 \noindent \kern \zcapshift \box\zcapbox \par
930 \prevdepth = \zfloatdp
931 \bbskipbelow{\breaknever}{\belowskip}}
932
933 \def \zcaptoc #1\legend#2\zmark{%
934 \tocentry{\the\floatcomptext}{#1}{\zcurfltlvl}}
935
936 \def \zcaptag #1\legend#2\zmark{%
937 \settaginfo{\the\floatcomptext}{#1}}
938
939 % Position Handling
940 % -------- --------
941
942
943 % This macro sets up variables that specify the position of a float,
944 % according to the \position design parameter:
945 %
946 % \alone Place float on a page by itself.
947 % \anypage Place float on any page.
948 % \any (synonym for \anypage)
949 % \bottom Place float at the bottom of a page.
950 % \broadside Place float broadside (alone, rotated 90 degrees).
951 % \evenpage Place float on an even page.
952 % \follow Float must follow its position in the text.
953 % \here Place float exactly where it appears.
954 % \ifevenpage Use next position only on even page.
955 % \ifoddpage Use next position only on odd page.
956 % \leftmargin Shift float to left margin.
957 % \margin Same as \leftmargin.
958 % \marginonly Float fits in the margin and does not occupy any
959 % vertical space on the page.
960 % \nofollow Float need not follow its position in the text.
961 % \oddpage Place float on an odd page.
962 % \outsidemargin Shift float to outside margin.
963 % \rightmargin Shift float to right margin.
964 % \separate Place float on a page with floats only.
965 % \textarea Leave float at left edge of text area.
966 % \text (synonym for \textarea)
967 % \top Place float at the top of a page.
968 % \topafterbottom Okay to schedule \top float after \bottom.
969
970
971 \definecount{\zfltposshift}{0}
972
973
974 \def \zparsefltpos #1{% {options...}
975 {\zclearfltpagepos
976 \global\setflag \zfltposmargonly = \false
977 \global\zfltposshift = 0\relax
978 \zsetupfltpageopts
979 \def \ifevenpage ##1{\if \evenp{\floatpage}##1\fi}%
980 \def \ifoddpage ##1{\if \oddp{\floatpage}##1\fi}%
981 \def \leftmargin {\global\zfltposshift=1\relax}%
982 \let \margin = \leftmargin
983 \def \marginonly {\global\setflag\zfltposmargonly=\true}%
984 \def \outsidemargin{\ifevenpage{\leftmargin}\ifoddpage{\rightmargin}}%
985 \def \rightmargin {\global\zfltposshift=2\relax}%
986 \def \textarea {\global\zfltposshift=0\relax}%
987 \let \text = \textarea
988 \global\floatpage = \floatpage
989 #1%
990 \global\setflag \zfltposhereonly = \zfltposhere
991 \global\setflag \zfltposok = \zfltposhere
992 \if \orp{\zfltposalone}
993 {\orp{\zfltposbottom}
994 {\orp{\zfltposbroadside}
995 {\orp{\zfltposseparate}
996 {\zfltpostop}}}}%
997 \global\setflag \zfltposhereonly = \false
998 \global\setflag \zfltposok = \true
999 \fi
1000 \if \zfltposhereonly \setflag \zfltposhere = \false \fi
1001 \if \notp{\zfltposok}%
1002 \warning{nofloatpos}{No page position has been specified for a float}%
1003 \global\setflag \zfltposalone = \true
1004 \fi}}
1005
1006 \def \zparsefltpagepos #1{% {options...}
1007 {\zclearfltpagepos
1008 \zsetupfltpageopts
1009 #1%
1010 \global\setflag \zfltposhereonly = \zfltposhere
1011 \if \orp{\zfltposalone}
1012 {\orp{\zfltposbottom}{\orp{\zfltposseparate}{\zfltpostop}}}%
1013 \global\setflag \zfltposhereonly = \false
1014 \fi
1015 \if \zfltposhereonly \global\setflag \zfltposhere = \false \fi}}
1016
1017 \def \zclearfltpagepos {%
1018 \global\setflag \zfltposalone = \false
1019 \global\setflag \zfltposbottom = \false
1020 \global\setflag \zfltposbroadside = \false
1021 \global\setflag \zfltposeven = \false
1022 \global\setflag \zfltposfollow = \false
1023 \global\setflag \zfltposhere = \false
1024 \global\setflag \zfltposodd = \false
1025 \global\setflag \zfltposseparate = \false
1026 \global\setflag \zfltpostop = \false
1027 \global\setflag \zfltpostopafterbot = \false}
1028
1029 \def \zsetupfltpageopts {%
1030 \def \alone {\global\setflag\zfltposalone=\true}%
1031 \def \anypage {\global\setflag\zfltposeven=\false
1032 \global\setflag\zfltposodd=\false}%
1033 \let \any = \anypage
1034 \def \bottom {\global\setflag\zfltposbottom=\true}%
1035 \def \broadside {\global\setflag\zfltposbroadside=\true}%
1036 \def \evenpage {\global\setflag\zfltposeven=\true}%
1037 \def \follow {\global\setflag\zfltposfollow=\true}%
1038 \def \here {\global\setflag\zfltposhere=\true}%
1039 \def \nofollow {\global\setflag\zfltposfollow=\false}%
1040 \def \oddpage {\global\setflag\zfltposodd=\true}%
1041 \def \separate {\global\setflag\zfltposseparate=\true}%
1042 \def \top {\global\setflag\zfltpostop=\true}%
1043 \def \topafterbottom {\global\setflag\zfltpostopafterbot=\true}}
1044
1045 \def \zcalcfltparams {%
1046 \floatshift = 0pt\relax
1047 % Set \floatshift
1048 \ifcase \zfltposshift
1049 \relax
1050 \or
1051 \floatshift = \if \evenp{\floatpage}-\evenlefttextmargin
1052 \else -\oddlefttextmargin \fi \relax
1053 \or
1054 \floatshift = \textmeasure
1055 \else
1056 \zzerror{Invalid value for float `\string\zfltposshift'}%
1057 \fi
1058 \advance \floatshift by \leftindent
1059
1060 % Set \floatwidth. Default of \naturalwidth is handled differently
1061 % for broadsides than for non-broadsides. If \width not default, use
1062 % it without modification.
1063
1064 \if \dimeqlp{\width}{\naturalwidth}%
1065 \if \zfltposbroadside
1066 \floatwidth = \textareaheight \relax
1067 \else
1068 \floatwidth = \textmeasure \relax
1069 \ifcase \zfltposshift
1070 \relax
1071 \or
1072 \advance \floatwidth by -\floatshift
1073 \or
1074 \floatwidth = \if \evenp{\floatpage}\evenrighttextmargin
1075 \else \oddrighttextmargin \fi \relax
1076 \else
1077 \zzerror{Invalid value for float `\string\zfltposshift'}%
1078 \fi
1079 \fi
1080 \else
1081 \floatwidth = \width \relax
1082 \fi}
1083
1084
1085 % This macro sets up variables that specify the position of a caption,
1086 % according to the \position design parameter:
1087 %
1088 % \above Caption is placed above the figure.
1089 % \below Caption is placed below the figure.
1090 % \follow Caption follows left edge of float.
1091 % \ifevenpage Use next position only on even page.
1092 % \ifoddpage Use next position only on odd page.
1093 % \leftmargin Force caption in left margin.
1094 % \margin Same as \leftmargin
1095 % \outsidemargin Shift caption to outside margin.
1096 % \rightmargin Force caption in right margin.
1097 % \rise Caption rises up from bottom of figure.
1098 % \separate Caption is separate from figure.
1099 % \sink Caption sinks down from top of figure.
1100 % \textarea Force caption at left edge of text area.
1101 % \text (synonym for \textarea)
1102 % \textarearight Force caption at right edge of text area.
1103 % \textright (synonym for \textarearight)
1104
1105
1106 \definecount{\zcapposshift}{0}
1107 \definecount{\zcapposvflow}{0}
1108
1109 \def \zparsecappos #1{% {options...}
1110 {\global\setflag \zcapposabove = \true
1111 \global\zcapposvflow = 0\relax
1112 \global\zcapposshift = 0\relax
1113 \def \above {\global\setflag\zcapposabove=\true}%
1114 \def \below {\global\setflag\zcapposabove=\false}%
1115 \def \follow {\global\zcapposshift=4\relax}%
1116 \def \ifevenpage ##1{\if \evenp{\floatpage}##1\fi}%
1117 \def \ifoddpage ##1{\if \oddp{\floatpage}##1\fi}%
1118 \def \leftmargin {\global\zcapposshift=1\relax}%
1119 \let \margin = \leftmargin
1120 \def \outsidemargin {\ifevenpage{\leftmargin}\ifoddpage{\rightmargin}}%
1121 \def \rightmargin {\global\zcapposshift=2\relax}%
1122 \def \rise {\global\zcapposvflow=1\relax}%
1123 \def \separate {\global\zcapposvflow=0\relax}%
1124 \def \sink {\global\zcapposvflow=2\relax}%
1125 \def \textarea {\global\zcapposshift=0\relax}%
1126 \let \text = \textarea
1127 \def \textarearight {\global\zcapposshift=3\relax}%
1128 \let \textright = \textarearight
1129 #1}}
1130
1131 \def \zcalccapitems {%
1132 \ifcase \zcapposshift
1133 \zcapshift = 0pt
1134 \or
1135 \zcapshift = \if \evenp{\floatpage}-\evenlefttextmargin
1136 \else -\oddlefttextmargin \fi \relax
1137 \or
1138 \zcapshift = \textmeasure
1139 \or
1140 \zcapshift = \textmeasure
1141 \advance \zcapshift by -\wd\zcapbox
1142 \or
1143 \zcapshift = \floatshift
1144 \else
1145 \zzerror{Invalid value for caption `\string\zcapposshift'}%
1146 \fi
1147 \advance \zcapshift by -\floatshift
1148 % Captions in broadsides *always* follow, i.e. \zcapshift is 0pt
1149 \if \zfltposbroadside
1150 \zcapshift = 0pt\relax
1151 \fi
1152 \ifcase \zcapposvflow
1153 \relax
1154 \or
1155 \forcenextbbskip
1156 \aboveskip = -\dp\zcapbox
1157 \advance \aboveskip by \zfloatdp
1158 \advance \aboveskip by \captionfudge
1159 \or
1160 \advance \belowskip by -\dp\zcapbox
1161 \advance \belowskip by -\captionfudge
1162 \else
1163 \zzerror{Invalid value for caption `\string\zcapposvflow'}%
1164 \fi}