summaryrefslogtreecommitdiff
path: root/tex/context/base/page-mak.mkvi
blob: 71af520a1966a6dbe68ba6058838a5085e76c48f (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
%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}

%D New is that we have a layout with the same name so one can set
%D up a special layout tthat then gets used.

\installcorenamespace{makeup}
\installcorenamespace{makeupdoublesided}

\installcommandhandler \??makeup {makeup} \??makeup

\appendtoks
   \setuevalue{\e!start\currentmakeup\e!makeup}{\startmakeup[\currentmakeup]}%
   \setuevalue{\e!stop \currentmakeup\e!makeup}{\stopmakeup}%
   \doiflayoutdefinedelse\currentmakeup\donothing{\definelayout[\currentmakeup]}% new
\to \everydefinemakeup

%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.

\unexpanded\def\startmakeup
  {\dodoubleempty\page_makeup_start}

\let\stopmakeup\relax

\def\page_makeup_start
  {\iffirstargument
      \expandafter\page_makeup_start_yes
   \else
      \expandafter\page_makeup_start_nop
   \fi}

%D The simple case: just a box with text dimensions.

\unexpanded\def\page_makeup_start_nop[#name][#settings]% dummies
  {\page
   \setupheader[\c!state=\v!empty]%
   \setupfooter[\c!state=\v!empty]%
   \bgroup
   \forgetall % else indented flush
   \dontcomplain
   \vbox to \textheight \bgroup
     \setsystemmode\v!makeup
     \hsize\textwidth
     \let\stopmakeup\page_makeup_stop_nop}

\unexpanded\def\page_makeup_stop_nop
  {\egroup
   \egroup
   \page}

%D The normal variant.

\newbox \b_page_makeup
\newtoks\t_page_makeup_every_setup

\def\page_makeup_start_yes[#name]% [#settings]%
  {\doifelsecommandhandler\??makeup{#name}\page_makeup_start_indeed\page_makeup_start_nop[#name]}%

\def\page_makeup_start_indeed[#name][#settings]%
  {\doifelsenothing{\namedmakeupparameter{#name}\c!page}
     {\page}% new, so best not have dangling mess here like references (we could capture then and flush embedded)
     {\page[\namedmakeupparameter{#name}\c!page]}%
   \startlayout[#name]% includes \page
   \bgroup
   \edef\currentmakeup{#name}%
   \setupcurrentmakeup[#settings]%
   \setsystemmode\v!makeup
   \the\t_page_makeup_every_setup
   \makeupparameter\c!commands % hm, what is this one doing here ?
   \forgetall % else indented flush
   \dontcomplain
   \global\setbox\b_page_makeup\vbox to \makeupparameter\c!height \bgroup
     \usemakeupstyleandcolor\c!style\c!color
     \hsize\makeupparameter\c!width
     \usealignparameter\makeupparameter
     \usesetupsparameter\makeupparameter % lua(..),xml(...,..),tex(..)
     \makeupparameter\c!top
     \let\stopmakeup\page_makeup_stop_yes}

\unexpanded\def\page_makeup_stop_yes
  {\endgraf
   \makeupparameter\c!bottom
   \egroup
   \strc_pagenumbers_page_state_push % new
   \makeupparameter\c!before\relax
   \begingroup
     \ifdim\ht\b_page_makeup>\vsize
       \ht\b_page_makeup\vsize % is already set to \textheight (maybe set dp to 0)
     \fi
     \setuppagenumber[\c!state=\makeupparameter\c!pagestate]%
     \doif{\makeupparameter\c!location}\v!top{\topskip\zeropoint}%
     \edef\p_reference{\makeupparameter\c!reference}%
     \dontleavehmode
     \usereferenceparameter\makeupparameter
     \box\b_page_makeup % could be whole box being destination
     \the\t_page_makeup_every_setup
     \page
   \endgroup
   \makeupparameter\c!after\relax
   \ifdoublesided \ifodd\realpageno \else
     \getvalue{\??makeupdoublesided\makeupparameter\c!doublesided}%
   \fi \fi
   \strc_pagenumbers_page_state_pop % new
   \egroup
   \stoplayout} % includes \page

\setvalue{\??makeupdoublesided\v!yes}%
  {\emptyhbox
   \page}

\setvalue{\??makeupdoublesided\v!empty}%
  {\the\t_page_makeup_every_setup
  % == \page[\v!dummy]
   \page[\v!blank]%
   \emptyhbox
   \page}

%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

\appendtoks % this might need a revision
    \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]%
\to \t_page_makeup_every_setup

%D The standard page template is defined as follows:

\setupmakeup
  [\c!width=\innermakeupwidth,  % example in manual / was \makeupwidth
   \c!height=\textheight,       % example in manual
  %\c!commands=,
  %\c!setups=,
  %\c!color=,
  %\c!align=,
  %\c!before=,
  %\c!after=,
  %\c!location=,
   \c!page=\v!right,
   \c!doublesided=\v!empty,
   \c!top=\vss,
   \c!bottom=\vss,
   \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 ! ! !

\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]

\definemakeup
  [\v!page]
  []

\definemakeup
  [\v!middle]
  [\v!standard]

% \definelayout[standard]
% \definelayout[text]

\protect