summaryrefslogtreecommitdiff
path: root/tex/context/base/mkii/page-mak.mkii
blob: 3a513137fe82938ba99b4b17351121216dc0c331 (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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
%D \module
%D   [       file=page-mak, % copied from main-001,
%D        version=1997.03.31,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Simple MakeUp,
%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 / MakeUp}

\unprotect

%D \macros
%D   {definemakeup, setupmakeup, startmakeup}
%D
%D A makeup is a separate page, like a title page or colofon.
%D There is one standard makeup page, but you can define more
%D if needed.
%D
%D \starttyping
%D \startstandardmakeup
%D   My Fancy Title
%D \stopstandardmakeup
%D \stoptyping
%D
%D The associated commands are:
%D
%D \showsetup{definemakeup}
%D \showsetup{setupmakeup}
%D \showsetup{startmakeup}

\def\definemakeup
  {\dodoubleargument\dodefinemakeup}

\def\dodefinemakeup[#1][#2]%
  {\getparameters
     [\??do#1]%
     [\c!width=\innermakeupwidth,  % example in manual / was \makeupwidth
      \c!height=\textheight,       % example in manual
      \c!commands=,
      \c!setups=,
      \c!page=\v!right,
      \c!doublesided=\v!empty,
      \c!before=,
      \c!top=\vss,
      \c!bottom=\vss,
      \c!after=,
      \c!bottomstate=\v!normal,
      \c!topstate=\v!normal,
      \c!textstate=\v!normal,
      \c!headerstate=\v!stop,
      \c!footerstate=\v!stop,
      \c!pagestate=\v!stop, % in manual ! ! !
      \c!color=,
      \c!align=,
      #2]%
   \setvalue{\e!start#1\e!makeup}{\startmakeup[#1]}%
   \setvalue{\e!stop #1\e!makeup}{\stopmakeup}}

\def\setupmakeup
  {\dodoubleargument\dosetupmakeup}

\def\dosetupmakeup[#1]%
  {\getparameters[\??do#1]}

%D This will save us some 375 bytes in the format file.

\def\makeupparameter#1{\getvalue{\??do\currentmakeup#1}}

%D The \type{\start}||\type{\stop} macros are used for both
%D the direct and indirect way. The parameterless call will
%D build a simple box.

\newtoks\everymakeup

\appendtoks \postponemarks \to \everymakeup

\let\currentmakeup\empty

\def\startmakeup
  {\dodoubleempty\dostartmakeup}

\def\dostartmakeup[#1][#2]%
  {\bgroup
   \edef\currentmakeup{#1}%
   \the\everymakeup
   \iffirstargument
     \setupmakeup[\currentmakeup][#2]%
     \let\stopmakeup\dodostopmakeup
     \expandafter   \dodostartmakeup
   \else
     \let\stopmakeup\donostopmakeup
     \expandafter   \donostartmakeup
   \fi}

%D The simple case:

\def\donostartmakeup % textwidth ?
  {\page
   \setupheader[\c!state=\v!empty]%
   \setupfooter[\c!state=\v!empty]%
   \setsystemmode\v!makeup
   \vbox to \textheight\bgroup\hsize\textwidth}

\def\donostopmakeup
  {\egroup
   \flushmarks % new, here, else empty pages
   \page
   \egroup}

%D The normal one:

\newbox\makeupbox

\def\dodostartmakeup
  {\doifvaluesomething{\??do\currentmakeup\c!page}
     {\ExpandFirstAfter\page[\makeupparameter\c!page]}%
   \pagetype[\currentmakeup]%
   \setsystemmode\v!makeup
   \setupmakeuplayout
   \makeupparameter\c!commands % hm, what is this one doing here ?
   \startregistercolor[\makeupparameter\c!color]%
   \forgetall % else indented flush
   \global\setbox\makeupbox\vbox to \makeupparameter\c!height
     \bgroup
%        \forgetall
       \setups[\makeupparameter\c!setups]%
       \hsize\makeupparameter\c!width
       \doifsomething{\makeupparameter\c!align}
         {\setupalign[\makeupparameter\c!align]}%
       \makeupparameter\c!top}

\def\dodostopmakeup
  {\endgraf
   \makeupparameter\c!bottom
   \egroup
   \flushmarks % new, here, else empty pages
   \stopregistercolor
   \doflushmakeup
   \egroup
   \calculatehsizes
   \calculatevsizes}

%D Selective page processing is handled here. (Why?)

\def\doflushmakeup
  {\ifprocessingpages
     \ifpageselected
       \doshipoutmakeup
     \fi
   \else
     \ifpageselected \else
       \doshipoutmakeup
     \fi
   \fi
   \ifselectingpages
     \global\pageselectedfalse
   \fi}

% \def\pushpagestate{\globalpushmacro\@@pnstate}
% \def\poppagestate {\globalpopmacro \@@pnstate}

\def\doshipoutmakeup
  {\pushpagestate % new
   \makeupparameter\c!before
   \setbox\makeupbox\vbox{\hbox{\color[\makeupparameter\c!color]{\box\makeupbox}}}%
   % \ifgridsnapping
   % new per 22/6/2006
     \ifdim\ht\makeupbox>\vsize
       \ht\makeupbox\vsize
     \fi
   % \fi
   \box\makeupbox
   \setuppagenumber[\c!state=\makeupparameter\c!pagestate]%
   \setupmakeuplayout
   \page
   \makeupparameter\c!after
   \relax % voor fi
   \ifdoublesided \ifodd\realpageno\else
     \processaction
       [\makeupparameter\c!doublesided]
       [  \v!yes=>\null
                  \page,
        \v!empty=>{\setupmakeuplayout
                  \page[\v!blank]%
                  \null
                  \page}]%
   \fi \fi
   \poppagestate} % new

%D The text surrounding the main body text can be influenced
%D by setting their associated status variables. The
%D connection between them is made by the following macro

\def\setupmakeuplayout
  {\setupfooter[\c!state=\makeupparameter\c!footerstate]%
   \setupheader[\c!state=\makeupparameter\c!headerstate]%
   \setuptext  [\c!state=\makeupparameter\c!textstate]%
   \setupbottom[\c!state=\makeupparameter\c!bottomstate]%
   \setuptop   [\c!state=\makeupparameter\c!topstate]%
   % this is needed, but no \setuplayout here; fails in texexec --fig=c
   \recalculatelayout}

%D The standard page template is defined as follows:

\definemakeup
  [\v!standard]
  [\c!width=\innermakeupwidth,
   \c!height=\textheight,
   \c!page=\v!right,
   \c!doublesided=\v!empty]

\definemakeup
  [\v!text]
  [\c!topstate=\v!start,
   \c!headerstate=\v!start,
   \c!textstate=\v!start,
   \c!footerstate=\v!start,
   \c!bottomstate=\v!start,
   \c!doublesided=\v!no,
   \c!page=\v!yes,
   \c!top=\pseudostrut\ignorespaces,
   \c!bottom=\obeydepth\vss]

\protect \endinput