page-pst.mkxl /size: 3393 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=page-mis,
3%D        version=2008.11.17, % was part of page-flt.tex / 2000.10.20
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Postponing,
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 / Postponing}
15
16\registerctxluafile{page-pst}{}
17
18\unprotect
19
20% postponing
21
22\newevery\everytopofpage\relax
23
24\appendtoks
25    \expand\everytopofpage
26\to \everystarttext
27
28\appendtoks
29    \global\everytopofpage\emptytoks
30\to \everystoptext
31
32% \startpostponing [pagenumber] [+pageoffset]
33%
34% \startpostponing[2]
35%   PAGE 2 \blank
36% \stoppostponing
37%
38% \startpostponing[+1]
39%   PAGE +1 \blank
40% \stoppostponing
41%
42% \startpostponing[+2]
43%   PAGE +2 \blank
44% \stoppostponing
45%
46% \starttext \dorecurse{4}{\input tufte \page} \stoptext
47
48%D There is no real need to use \LUA\ here but the bookkeeping is somewhat easier
49%D and we also can erase buffers easier when we keep a local cache, especially as we
50%D can flush per page.
51
52\newinteger    \c_page_postponed_blocks_next_page % set at the lua end
53\newconditional\c_page_postponed_busy
54
55\mutable\lettonothing\currentpostponedpage
56
57\permanent\protected\defcsname\e!start\v!postponing\endcsname
58  {\bgroup
59   \obeylines
60   \doifelsenextoptional{\egroup\page_postponed_blocks_start}{\egroup\page_postponed_blocks_start[0]}}
61
62\permanent\protected\defcsname\e!stop\v!postponing\endcsname
63  {\clf_registerpostponedblock{\currentpostponedpage}\relax}
64
65\def\page_postponed_blocks_start[#1]%
66  {\edef\currentpostponedpage{#1}%
67   \grabbufferdatadirect{postponedblock}{\e!start\v!postponing}{\e!stop\v!postponing}}
68
69%D Officially we should flush again after a flush as there can be new future pages
70%D but that will be looked into when we run into it.
71
72\c_page_postponed_mode\plusone
73
74\protected\def\page_postponed_blocks_flush_indeed
75  {\begingroup
76   \setsystemmode\v!postponing
77   \c_page_postponed_busy\conditionaltrue
78   \ifnum\c_page_postponed_mode=\plusone
79     \savepagecontent
80   \fi
81   \pagetotal\zeropoint        % here? still needed? (was after flush pagefloats)
82   \expand\everytopofpage\relax
83  %\flushrestfloats
84   \page_floats_flush_page_floats
85   \setnormalcatcodes                 % postponing in verbatim
86   \uncatcodespacetokens              % postponing in startlines
87   \restoreglobalbodyfont             % otherwise problems inside split verbatim
88   \clf_flushpostponedblocks
89     % page {123}
90   \relax
91   \page_otr_command_flush_floats     % new but potential dangerous, maybe we need a classification
92   \ifnum\c_page_postponed_mode=\plusone
93     \flushpagecontent
94   \fi
95   \endgroup}                         % of blocks: with and without flush
96
97\protected\def\page_postponed_blocks_flush
98  {\ifconditional\c_page_postponed_busy
99     % probably a nested flush
100   \orelse\ifnum\c_page_postponed_blocks_next_page=\zerocount
101     % nothing in cache
102   \orelse\ifnum\c_page_postponed_blocks_next_page<\zerocount
103     % generic cache
104     \page_postponed_blocks_flush_indeed
105   \orelse\ifnum\c_page_postponed_blocks_next_page>\realpageno
106     % future content
107   \else
108     % pending content
109     \page_postponed_blocks_flush_indeed
110   \fi}
111
112\protect \endinput
113