page-mak.mkvi /size: 8112 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=page-mak, % copied from main-001,
3%D        version=1997.03.31,
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Simple MakeUp,
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 / MakeUp}
15
16\unprotect
17
18%D \macros
19%D   {definemakeup, setupmakeup, startmakeup}
20%D
21%D A makeup is a separate page, like a title page or colofon.
22%D There is one standard makeup page, but you can define more
23%D if needed.
24%D
25%D \starttyping
26%D \startstandardmakeup
27%D   My Fancy Title
28%D \stopstandardmakeup
29%D \stoptyping
30%D
31%D The associated commands are:
32%D
33%D \showsetup{definemakeup}
34%D \showsetup{setupmakeup}
35%D \showsetup{startmakeup}
36
37%D New is that we have a layout with the same name so one can set
38%D up a special layout that then gets used.
39
40\installcorenamespace{makeup}
41\installcorenamespace{makeupdoublesided}
42
43\installcommandhandler \??makeup {makeup} \??makeup
44
45\appendtoks
46   \setuevalue{\e!start\currentmakeup\e!makeup}{\startmakeup[\currentmakeup]}%
47   \setuevalue{\e!stop \currentmakeup\e!makeup}{\stopmakeup}%
48   \doifelselayoutdefined\currentmakeup\donothing{\definelayout[\currentmakeup]}% new
49\to \everydefinemakeup
50
51%D The \type{\start}||\type{\stop} macros are used for both
52%D the direct and indirect way. The parameterless call will
53%D build a simple box.
54
55\unexpanded\def\startmakeup
56  {\dodoubleempty\page_makeup_start}
57
58\let\stopmakeup\relax
59
60\def\page_makeup_start
61  {\iffirstargument
62      \expandafter\page_makeup_start_yes
63   \else
64      \expandafter\page_makeup_start_nop
65   \fi}
66
67%D The simple case: just a box with text dimensions.
68
69\unexpanded\def\page_makeup_start_nop[#name][#settings]% dummies
70  {\page
71   \setupheader[\c!state=\v!empty]%
72   \setupfooter[\c!state=\v!empty]%
73   \bgroup
74   \forgetall % else indented flush
75   \dontcomplain
76   \vbox to \textheight \bgroup
77     \setsystemmode\v!makeup
78     \hsize\textwidth
79     \let\stopmakeup\page_makeup_stop_nop}
80
81\unexpanded\def\page_makeup_stop_nop
82  {\egroup
83   \egroup
84   \page}
85
86%D The normal variant.
87
88\newbox \b_page_makeup
89\newtoks\t_page_makeup_every_setup
90
91\def\page_makeup_start_yes[#name]% [#settings]%
92  {\doifelsecommandhandler\??makeup{#name}\page_makeup_start_indeed\page_makeup_start_nop[#name]}%
93
94% case 1:
95%
96% \setuplayout[height=5cm]
97%
98% case 2:
99%
100% \definelayout[crap][height=10cm]
101% \definelayout[standard][crap]
102%
103% case 3:
104%
105% \setuplayout[standard][height=15cm]
106%
107% case 4:
108%
109% \definelayout[whatever][height=2cm]
110% \setuplayout[whatever]
111
112\def\page_makeup_start_indeed[#name][#settings]%
113  {% the next grouping hack is somewhat messy:
114   \begingroup
115   % we need to figure out the current layout
116   \xdef\m_page_makeup_name{#name}%
117   \let\currentmakeup\m_page_makeup_name
118   \let\currentlayout\m_page_makeup_name
119   \xdef\m_page_makeup_layout_parent{\layoutparameter\s!parent}%
120   \setupcurrentmakeup[#settings]%
121   \edef\p_page{\makeupparameter\c!page}%
122   \ifx\p_page\empty
123     \endgroup
124     \page % new, so best not have dangling mess here like references (we could capture then and flush embedded)
125   \else\ifx\p_page\v!no
126     % nothing
127     \endgroup
128   \else
129     \normalexpanded{\endgroup\page[\p_page]}%
130   \fi\fi
131   % some dirty trickery (sorry) for determining if we have
132   %  - a layout definition at all
133   %  - inherit from the parent of that definition
134   %  - inherit from the current layout otherwise
135   \ifx\m_page_makeup_name\currentlayout
136      % we already use the layout
137   \else\ifx\m_page_makeup_layout_parent\??layout
138     % we inherit from the current layout
139     \normalexpanded{\setuplayout[#name][\s!parent=\??layout\currentlayout]}% is remembered but checked later anyway
140 % \else
141      % we have an inherited layout
142   \fi\fi
143   \startlayout[#name]% includes \page
144   \bgroup
145  %\edef\currentmakeup{#name}%
146   \let\currentmakeup\m_page_makeup_name
147   \setupcurrentmakeup[#settings]%
148   \setsystemmode\v!makeup
149   \the\t_page_makeup_every_setup
150   \makeupparameter\c!commands % hm, what is this one doing here ?
151   \forgetall % else indented flush
152   \dontcomplain
153   \global\setbox\b_page_makeup\vbox to \makeupparameter\c!height \bgroup
154     \usemakeupstyleandcolor\c!style\c!color
155     \hsize\makeupparameter\c!width
156     \usealignparameter\makeupparameter
157     \usesetupsparameter\makeupparameter % lua(..),xml(...,..),tex(..)
158     \makeupparameter\c!top
159     \let\stopmakeup\page_makeup_stop_yes}
160
161\unexpanded\def\page_makeup_stop_yes
162  {\endgraf
163   \makeupparameter\c!bottom
164   \egroup
165   \strc_pagenumbers_page_state_push % new
166   \makeupparameter\c!before\relax
167   \begingroup
168     \ifdim\ht\b_page_makeup>\vsize
169       \ht\b_page_makeup\vsize % is already set to \textheight (maybe set dp to 0)
170     \fi
171     \setuppagenumber[\c!state=\makeupparameter\c!pagestate]%
172     \doif{\makeupparameter\c!location}\v!top{\topskip\zeropoint}%
173     \edef\p_reference{\makeupparameter\c!reference}%
174     \dontleavehmode
175     \usereferenceparameter\makeupparameter
176     \box\b_page_makeup % could be whole box being destination
177     \the\t_page_makeup_every_setup
178     \page
179   \endgroup
180   \makeupparameter\c!after\relax
181   \ifdoublesided \ifodd\realpageno \else
182     \csname\??makeupdoublesided\makeupparameter\c!doublesided\endcsname
183   \fi \fi
184   \strc_pagenumbers_page_state_pop % new
185   \egroup
186   \stoplayout % includes \page
187   \ifx\m_page_makeup_name\currentlayout
188   \else\ifx\m_page_makeup_layout_parent\??layout
189     \normalexpanded{\setuplayout[\m_page_makeup_name][\s!parent=\??layout]}% is remembered but checked later anyway
190 % \else
191   \fi\fi}
192
193\setvalue{\??makeupdoublesided\v!yes}%
194  {\emptyhbox
195   \page}
196
197\setvalue{\??makeupdoublesided\v!empty}%
198  {\the\t_page_makeup_every_setup
199  % == \page[\v!dummy]
200   \page[\v!blank]%
201   \emptyhbox
202   \page}
203
204%D Probably obsolete (but used in one manual by Taco):
205
206\unexpanded\def\startcolumnmakeup % don't change
207  {\bgroup
208   \getrawnoflines\textheight % raw as we can have topskip
209   \setbox\scratchbox\vbox to \dimexpr\noflines\lineheight-\lineheight+\topskip\relax
210     \bgroup
211     \forgetall}
212
213\unexpanded\def\stopcolumnmakeup
214  {\egroup
215   \dp\scratchbox\zeropoint
216   \wd\scratchbox\textwidth
217   \box\scratchbox
218   \egroup
219   \page_otr_command_synchronize_hsize}
220
221%D The text surrounding the main body text can be influenced
222%D by setting their associated status variables. The
223%D connection between them is made by the following macro
224
225\appendtoks % this might need a revision
226    \setupfooter[\c!state=\makeupparameter\c!footerstate]%
227    \setupheader[\c!state=\makeupparameter\c!headerstate]%
228    \setuptext  [\c!state=\makeupparameter\c!textstate]%
229    \setupbottom[\c!state=\makeupparameter\c!bottomstate]%
230    \setuptop   [\c!state=\makeupparameter\c!topstate]%
231\to \t_page_makeup_every_setup
232
233%D The standard page template is defined as follows:
234
235\setupmakeup
236  [\c!width=\innermakeupwidth,  % example in manual / was \makeupwidth
237   \c!height=\textheight,       % example in manual
238  %\c!commands=,
239  %\c!setups=,
240  %\c!color=,
241  %\c!align=,
242  %\c!before=,
243  %\c!after=,
244  %\c!location=,
245   \c!page=\v!right,
246   \c!doublesided=\v!empty,
247   \c!top=\vss,
248   \c!bottom=\vss,
249   \c!bottomstate=\v!normal,
250   \c!topstate=\v!normal,
251   \c!textstate=\v!normal,
252   \c!headerstate=\v!stop,
253   \c!footerstate=\v!stop,
254   \c!pagestate=\v!stop] % in manual ! ! !
255%  \c!pagestate=\v!start]
256
257\definemakeup
258  [\v!standard]
259  [\c!width=\innermakeupwidth,
260   \c!height=\textheight,
261   \c!page=\v!right,
262   \c!doublesided=\v!empty]
263
264\definemakeup
265  [\v!text]
266  [\c!topstate=\v!start,
267   \c!headerstate=\v!start,
268   \c!textstate=\v!start,
269   \c!footerstate=\v!start,
270   \c!bottomstate=\v!start,
271   \c!doublesided=\v!no,
272   \c!page=\v!yes,
273   \c!top=\pseudostrut\ignorespaces,
274   \c!bottom=\obeydepth\vss]
275
276\definemakeup
277  [\v!page]
278
279\definemakeup
280  [\v!middle]
281  [\v!standard]
282
283% \definelayout[standard]
284% \definelayout[text]
285
286\protect
287