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