summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/page-blk.mkxl
blob: 9553ea643b618696bc0025f8ae8ef4e120ec01c7 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
%D \module
%D   [       file=page-blk,
%D        version=2022.06.04,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Shuffling Pages,
%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 / Shuffling pages}

%D This is a somewhat tricky module and although we have a somewhat abstract
%D interface we are pretty much bound to \PDF\ output here. When large amounts of
%D documents are to be generated and|/|or when saving a run makes sense the table
%D of contents can be typeset at the end and moved to the beginning. However, it
%D assumes a rather stable and predictable rendering. Don't use this without
%D checking it really works out well.
%D
%D The low level backend code has been around for quite a while but we never had
%D a real (need and therefore) interface for it. There actually is not that much
%D code involved anyway. There is no need to backport it to \MKIV.

\registerctxluafile{page-blk}{autosuffix}

% Musical timestamp: end May 2022 xpropaganda (in loop mode to keep the pace).

% pitfalls: we need to keep the toc in order (or generate it 'manually' based on
% deltas but even then we get the numbers wrong)

\unprotect

\newinteger\c_pages_prerolled

\permanent\protected\def\startpageblock[#1]%
  {\page
   \clf_startpageblock{#1}}

\permanent\protected\def\stoppageblock
  {\page
   \clf_stoppageblock}

\permanent\protected\def\flushpageblocks[#1]%
  {\page
   \clf_flushpageblocks{#1}}

\permanent\def\pageblockrealpage#1%
  {\clf_pageblockrealpage{#1}}

\tolerant\permanent\protected\def\startprerollpageblock[#1]%
  {\page
   \clf_startprerollpageblock{#1}%
   \global\c_pages_prerolled\realpageno % hack
   \setuppaper[\c!method=\v!none]}

\permanent\protected\def\stopprerollpageblock
  {\page
   \clf_stopprerollpageblock
   \setcounter[realpage][\c_pages_prerolled]% hack
   \setuppaper[\c!method=\v!normal]}

\permanent\def\prerolledpages#1%
  {\clf_prerolledpages{#1}}

\protect \endinput

\usemodule[article-basic]

\setupinteraction[state=start]

% \enabletrackers[*reference*]
% \enabletrackers[*destination*]

\useMPlibrary[dum]

\starttext

\def\AlphaOffset{0}
\def\BetaOffset {0}

% the flexible ones (can come from files)

\startbuffer[alpha]
    \startchapter[title=Alpha]
        \dorecurse{20}{\samplefile{tufte}\par}
    \stopchapter
\stopbuffer

\startbuffer[beta]
    \startchapter[title=Beta]
        \dorecurse{6}{\samplefile{tufte}\par}
    \stopchapter
\stopbuffer

% the fixed ones

\startbuffer[gamma]
    \startchapter[title=Gamma]
        \externalfigure[whatever-dummy-3][width=\textwidth]
    \stopchapter
\stopbuffer

\startbuffer[rest]
    \startchapter[title=Rest A]
        \samplefile{tufte}
    \stopchapter
    \startchapter[title=Rest B]
        \samplefile{tufte}
        \blank
        Alpha : \goto{page \AlphaPages}[realpage(\AlphaPages)]\par
        Beta  : \goto{page \BetaPages }[realpage(\BetaPages )]
    \stopchapter
\stopbuffer

\startbuffer[contents]
    \starttitle[title=Contents]
        \placelist[chapter][criterium=text]
    \stoptitle
\stopbuffer

% Preroll.

\startprerollpageblock[alpha]
    \start
        \setuphead[chapter][incrementnumber=no]
        \getbuffer[alpha]
    \stop
\stopprerollpageblock

% \writestatus{!!!!!}{nofalphapages: \prerolledpages{alpha}}

\startprerollpageblock[beta]
    \start
        \setuphead[chapter][incrementnumber=no]
        \getbuffer[beta]
    \stop
\stopprerollpageblock

% \writestatus{!!!!!}{nofbetapages: \prerolledpages{beta}}

% Some titling.

\startpageblock[titlepage]
    \startstandardmakeup
        \externalfigure[whatever-dummy-1][height=\textheight,width=\textwidth]
    \stopstandardmakeup
\stoppageblock

\startpageblock[boguspage]
    \startstandardmakeup
        \externalfigure[whatever-dummy-2][height=\textheight,width=\textwidth]
    \stopstandardmakeup
\stoppageblock

% The contents will end up here.

% page 1

% The main document.

\setuppagenumber[number=2]

\startpageblock[chapters]
    % we have a predictable rest:

    \edef\AlphaPages{\the\numexpr 4 \relax}
    \edef\BetaPages {\the\numexpr 4 + \prerolledpages{alpha} \relax}

    \getbuffer[rest]
    \getbuffer[alpha]
    \getbuffer[beta]
    \getbuffer[gamma]
\stoppageblock

% This one will move:

\setuppagenumber[number=1]

\startpageblock[contents]
    \getbuffer[contents]
\stoppageblock

\flushpageblocks
  [titlepage,
   boguspage,
   contents,
   chapters]

\stoptext