| 1 |
% P L A C E I N S . T E X ver 2.0 Mar 3, 1995 |
| 2 |
% |
| 3 |
% Insertions that keep their place. |
| 4 |
% |
| 5 |
% Copyright 1995 Donald Arseneau <[email protected]> |
| 6 |
% These macros may be freely used, transmitted, reproduced, or modified |
| 7 |
% provided that this notice is left intact. |
| 8 |
% |
| 9 |
% This TeX file provides various mechanisms (for plain TeX and close |
| 10 |
% relatives) to let insertions (footnotes, topins, pageins, etc.) float |
| 11 |
% within their appropriate section, but to prevent them from intruding |
| 12 |
% into the following section, even when sections do not normally begin |
| 13 |
% a new page. (If your sections normally begin a new page, just use |
| 14 |
% \supereject to flush out insertions.) |
| 15 |
% |
| 16 |
% Different combinations of insertions can be controlled with different |
| 17 |
% commands: |
| 18 |
% |
| 19 |
% \par\penalty-20029 |
| 20 |
% If there are any insertions that will not fit on the current page, |
| 21 |
% a \supereject is performed and the following text will continue at |
| 22 |
% the top of a page after all insertions. If all insertions do fit |
| 23 |
% on the current page, then the following text will continue |
| 24 |
% immediately on this page. |
| 25 |
% \par\penalty-20030 |
| 26 |
% Like above, except that if there are any footnotes at all on the |
| 27 |
% current page, the section must begin on the next page. (This is so |
| 28 |
% no footnote text from section 1 will appear beneath the beginning |
| 29 |
% of section 2.) |
| 30 |
% \par\penalty-10029 |
| 31 |
% If any insertions cannot fit on the current page, eject them, and |
| 32 |
% then allow the following section to begin immediately on the same |
| 33 |
% page as the last insert. If all insertions do fit on the current |
| 34 |
% page, then the following text will continue immediately on this |
| 35 |
% page. |
| 36 |
% \barrier{\eject}{\topins} |
| 37 |
% If there are any pageinserts or topinserts that do not fit on the |
| 38 |
% current page, eject them, and then allow the following section to |
| 39 |
% begin immediately on the same page as the last insert. Split |
| 40 |
% footnotes or other insertions are allowed to intrude into the next |
| 41 |
% section. |
| 42 |
% \barrier{\supereject}{\topins} |
| 43 |
% Like the \barrier command above, but if any inserts are ejected |
| 44 |
% the following section will begin at the top of a new page (like |
| 45 |
% \supereject). |
| 46 |
% \barrier{...}{\footins} |
| 47 |
% *** NOT ALLOWED *** You will get spurious space and footnote-rules |
| 48 |
% at the bottom of pages! |
| 49 |
% \barrier{...}{\margins} |
| 50 |
% If you define other insertion classes, such as marginal notes, you |
| 51 |
% can use \barrier for them too. But only if \skip\margins=0pt. |
| 52 |
% You must also add any new insertion classes to the definition of |
| 53 |
% \placerestoreoutput |
| 54 |
% |
| 55 |
% How to use: First, \input this file (of course!). Then, at the beginning |
| 56 |
% of a new section, or at any boundary that insertions should not cross, put |
| 57 |
% one of the commands listed above. Presumably, you will actually put these |
| 58 |
% commands at the start of your own \section or \startsection macro; that is |
| 59 |
% why they are non mnemonic! |
| 60 |
% |
| 61 |
% There is a slight chance that a footnote may be separated from its reference |
| 62 |
% in the text after \penalty-xxxxx when there are no split insertions. (LaTeX |
| 63 |
% has the same possibility at every float!) |
| 64 |
|
| 65 |
\chardef\noplaceoutput\catcode`\@ |
| 66 |
\catcode`\@=11 |
| 67 |
|
| 68 |
\edef\zero@skip{\the\z@skip} |
| 69 |
|
| 70 |
\def\barrier#1#2{\par\begingroup |
| 71 |
\ifdim\skip#2>\z@{\newlinechar10\errhelp{\barrier#2may produce some spurious |
| 72 |
extra material on the page, ^^J but I will try anyway.}\errmessage{Bad use |
| 73 |
of \string\barrier}}% |
| 74 |
\fi |
| 75 |
\skip@\lastskip \edef\next{\the\skip@}\ifx\next\zero@skip\else\vskip-\skip@\fi |
| 76 |
\penalty\z@ % update page parameters |
| 77 |
\fam-\insertpenalties |
| 78 |
\insert#2{\floatingpenalty\@ne}% |
| 79 |
\ifx\next\zero@skip\else\vskip\skip@\fi |
| 80 |
\advance\fam\insertpenalties % 0: no held; 1: held over |
| 81 |
\expandafter\endgroup |
| 82 |
\ifnum\fam=\@ne % then do eject |
| 83 |
% \message{There are held-over \string#2 inserts; performing \string#1. }% |
| 84 |
\ifdim\pagetotal<\topskip \leftline{}\kern-\topskip\fi % avoid empty list |
| 85 |
{\dimen@\pagetotal \advance\dimen@\pagedepth |
| 86 |
\ifdim\dimen@<\pagegoal\vfill\fi}% |
| 87 |
#1\@barrier{#1}{#2}\else |
| 88 |
% \message{There are no held-over \string#2 inserts. \space}% |
| 89 |
\fi |
| 90 |
} |
| 91 |
|
| 92 |
\def\placeinsoutput{% |
| 93 |
\ifnum\outputpenalty=-20030\relax % eject if any footnotes |
| 94 |
\ifvoid\footins\else |
| 95 |
\fam\insertpenalties \advance\fam\@ne \insertpenalties\fam |
| 96 |
\fi \outputpenalty=-20029\relax |
| 97 |
\fi |
| 98 |
\ifnum\outputpenalty=-20029\relax % Check for `supereject' flag |
| 99 |
\ifnum\insertpenalties>\z@ % something is being held over, must get it out |
| 100 |
% \message{Forcing insertions on their own pages. \space}% |
| 101 |
\ifvoid\footins \r@ggedbottomtrue \else \advance\skip\footins 0ptplus1fil\fi |
| 102 |
\noplaceoutput % performs \supereject |
| 103 |
\else % must rejoin seamlessly: |
| 104 |
\placerestoreoutput |
| 105 |
\fi |
| 106 |
\else % check for other flag... |
| 107 |
\ifnum\outputpenalty=-10028 % in the middle of ejecting |
| 108 |
\ifnum\insertpenalties=\z@ \global\setbox\@cclv\vbox{}\fi |
| 109 |
\outputpenalty=-10029 |
| 110 |
\fi |
| 111 |
\ifnum\outputpenalty=-10029\relax % section start |
| 112 |
\ifnum\insertpenalties>\z@ % something is being held over, must get it out |
| 113 |
% \message{Forcing insertions. \space}% |
| 114 |
\ifvoid\footins \r@ggedbottomtrue \else \advance\skip\footins 0ptplus1fil\fi |
| 115 |
\noplaceoutput % performs \eject, perhaps repeatedly: |
| 116 |
\leftline{}\kern-\topskip \penalty-10028\relax % (like \dosupereject) |
| 117 |
\else % must rejoin seamlessly: |
| 118 |
\placerestoreoutput |
| 119 |
\fi |
| 120 |
\else % just a regular page break |
| 121 |
\noplaceoutput |
| 122 |
\fi |
| 123 |
\fi |
| 124 |
} |
| 125 |
|
| 126 |
% there is a slim chance that footnotes may lose their place. |
| 127 |
\def\placerestoreoutput{% |
| 128 |
\ifvoid\footins\else\insert\footins{\unvbox\footins}\fi |
| 129 |
\ifvoid\topins\else\insert\topins{\unvbox\topins}\fi |
| 130 |
% If you have other floating insertion classes, do the same here. |
| 131 |
\unvbox\@cclv |
| 132 |
} |
| 133 |
|
| 134 |
\catcode`\@=\noplaceoutput |
| 135 |
|
| 136 |
\edef\noplaceoutput{\the\output} |
| 137 |
\output{\placeinsoutput} |