summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/page-pst.mkxl
blob: 45d049760fd401b5d89dbf94fb761d1ea190bf98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
%D \module
%D   [       file=page-mis,
%D        version=2008.11.17, % was part of page-flt.tex / 2000.10.20
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Postponing,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Page Macros / Postponing}

\registerctxluafile{page-pst}{}

\unprotect

% postponing

\newevery\everytopofpage\relax

\appendtoks
    \the\everytopofpage
\to \everystarttext

\appendtoks
    \global\everytopofpage\emptytoks
\to \everystoptext

% \startpostponing [pagenumber] [+pageoffset]
%
% \startpostponing[2]
%   PAGE 2 \blank
% \stoppostponing
%
% \startpostponing[+1]
%   PAGE +1 \blank
% \stoppostponing
%
% \startpostponing[+2]
%   PAGE +2 \blank
% \stoppostponing
%
% \starttext \dorecurse{4}{\input tufte \page} \stoptext

%D There is no real need to use \LUA\ here but the bookkeeping is somewhat easier
%D and we also can erase buffers easier when we keep a local cache, especially as we
%D can flush per page.

\newinteger    \c_page_postponed_blocks_next_page % set at the lua end
\newconditional\c_page_postponed_busy

\mutable\lettonothing\currentpostponedpage

\permanent\protected\defcsname\e!start\v!postponing\endcsname
  {\bgroup
   \obeylines
   \doifelsenextoptional{\egroup\page_postponed_blocks_start}{\egroup\page_postponed_blocks_start[0]}}

\permanent\protected\defcsname\e!stop\v!postponing\endcsname
  {\clf_registerpostponedblock{\currentpostponedpage}\relax}

\def\page_postponed_blocks_start[#1]%
  {\edef\currentpostponedpage{#1}%
   \grabbufferdatadirect{postponedblock}{\e!start\v!postponing}{\e!stop\v!postponing}}

%D Officially we should flush again after a flush as there can be new future pages
%D but that will be looked into when we run into it.

\c_page_postponed_mode\plusone

\protected\def\page_postponed_blocks_flush_indeed
  {\begingroup
   \setsystemmode\v!postponing
   \settrue\c_page_postponed_busy
   \ifnum\c_page_postponed_mode=\plusone
     \savepagecontent
   \fi
   \pagetotal\zeropoint        % here? still needed? (was after flush pagefloats)
   \the\everytopofpage\relax
  %\flushrestfloats
   \page_floats_flush_page_floats
   \setnormalcatcodes                 % postponing in verbatim
   \uncatcodespacetokens              % postponing in startlines
   \restoreglobalbodyfont             % otherwise problems inside split verbatim
   \clf_flushpostponedblocks
     % page {123}
   \relax
   \page_otr_command_flush_floats     % new but potential dangerous, maybe we need a classification
   \ifnum\c_page_postponed_mode=\plusone
     \flushpagecontent
   \fi
   \endgroup}                         % of blocks: with and without flush

\protected\def\page_postponed_blocks_flush
  {\ifconditional\c_page_postponed_busy
     % probably a nested flush
   \orelse\ifnum\c_page_postponed_blocks_next_page=\zerocount
     % nothing in cache
   \orelse\ifnum\c_page_postponed_blocks_next_page<\zerocount
     % generic cache
     \page_postponed_blocks_flush_indeed
   \orelse\ifnum\c_page_postponed_blocks_next_page>\realpageno
     % future content
   \else
     % pending content
     \page_postponed_blocks_flush_indeed
   \fi}

\protect \endinput