page-app.mkxl /size: 6326 b    last modification: 2021-10-28 13:51
1
%D \module
2
%D [ file=page-app, % from meta-fig
3
%D version=1998.01.15,
4
%D title=\CONTEXT\ Page Macros,
5
%D subtitle=Independent page building,
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
/
Applications
}
15 16
%D This needs an update with a proper define and inheritance.
17 18
\unprotect
19 20
\installcorenamespace
{
fittingpage
}
21 22
\installframedcommandhandler
\??fittingpage
{
fittingpage
}
\??fittingpage
23 24
\newdimen
\d_page_fitting_width
25
\newdimen
\d_page_fitting_height
26
\newbox
\b_page_fitting
27 28
\definepapersize
29
[
fittingpage
]
30
[
\c!width
=
\d_page_fitting_width
,
31
\c!height
=
\d_page_fitting_height
]
32 33
\definemakeup
34
[
fittingpage
]
35
[
\c!textstate
=
\v!empty
,
36
\c!doublesided
=
\v!no
,
37
\c!location
=
\v!top
,
% no topskip
38
\c!pagestate
=
\fittingpageparameter
\c!pagestate
]
%
39 40
\definelayout
41
[
fittingpage
]
42
[
\v!page
]
43
[
\c!width
=
\d_page_fitting_width
,
44
\c!height
=
\d_page_fitting_height
,
45
\c!location
=
\v!middle
]
46 47
\appendtoks
48
\frozen
\instance
\protected
\edefcsname
\e!start
\currentfittingpage
\endcsname
{
\startfittingpage
[
\currentfittingpage
]
}
%
49
\frozen
\instance
\protected
\edefcsname
\e!stop
\currentfittingpage
\endcsname
{
\stopfittingpage
}
%
50
\to
\everydefinefittingpage
51 52
\permanent
\tolerant
\protected
\def
\startfittingpage
[
#
1
]
#
*
[
#
2
]
%
53
{
\page
% this is kind of tricky! there can be preceding page refs
54
\autostarttext
55
\bgroup
% resulting in a zero height page; test fig-make !
56
\setupinterlinespace
[
\v!top
=
0
]
% no topskip
57
\def
\currentfittingpage
{
#
1
}
%
58
\dontcomplain
59
% runs under current page regime, i.e. page variables passed to mp
60
\setupcurrentfittingpage
[
\c!paper
=
,
#
2
]
% auto or size or nothing
61
\doifelsenothing
{
\fittingpageparameter
\c!command
}
62
\page_fitting_start_normal
63
\page_fitting_start_command
}
64 65
\def
\page_fitting_start_command
66
{
\grabuntil
{
\e!stop
\currentfittingpage
}
\page_fitting_stop_command
}
67 68
\def
\page_fitting_stop_command
#
1
%
69
{
\page_fitting_start_normal
70
\fittingpageparameter
\c!command
{
#
1
}
%
71
\page_fitting_stop_normal
}
72 73
\def
\page_fitting_start_normal
74
{
\setbox
\b_page_fitting
\hbox
75
\bgroup
76
\inheritedfittingpageframed
77
\bgroup
78
\gobblespacetokens
}
79 80
\protected
\def
\page_fitting_stop_normal
% todo: figure out why a small mp image gets shifted
81
{
\removeunwantedspaces
82
\egroup
83
\egroup
84
% finalize
85
\doif
{
\fittingpageparameter
\c!margin
}
\v!page
86
{
\setbox
\b_page_fitting
\hpack
\bgroup
87
\offsetbox
88
[
\c!leftoffset
=
\backspace
,
89
\c!rightoffset
=
\cutspace
,
90
\c!topoffset
=
\topspace
,
91
\c!bottomoffset
=
\bottomspace
]
92
{
\box
\b_page_fitting
}
%
93
\egroup
}
%
94
\doifsomething
{
\fittingpageparameter
\c!scale
}
95
{
\setbox
\b_page_fitting
\hpack
\bgroup
96
\scale
[
\c!scale
=
\fittingpageparameter
\c!scale
]
{
\box
\b_page_fitting
}
%
97
\egroup
}
%
98
\ifdim
\ht
\b_page_fitting
=
\zeropoint
99
\ht
\b_page_fitting
\onepoint
100
\fi
101
\ifdim
\wd
\b_page_fitting
=
\zeropoint
102
\wd
\b_page_fitting
\onepoint
103
\fi
104
\d_page_fitting_width
\wd
\b_page_fitting
105
\d_page_fitting_height
\ht
\b_page_fitting
106
\startlocallayout
% hm, we change the papersize so we still need it
107
\enforced
\let
\checkcurrentlayout
\relax
% else interference with odd/even layout
108
\processaction
109
[
\fittingpageparameter
\c!paper
]
110
[
\v!auto
=
>
\let
\scratchstringone
\printpapersize
,
111
\s!unknown
=
>
\let
\scratchstringone
\commalistelement
,
112
\s!default
=
>
\def
\scratchstringone
{
fittingpage
}
]
%
113
\normalexpanded
{
\setuppapersize
[
fittingpage
]
[
\scratchstringone
]
}
%
114
\startmakeup
[
fittingpage
]
%
115
\box
\b_page_fitting
116
\stopmakeup
117
\stoplocallayout
% we need to get rid of this and use the built-in
118
\egroup
119
\autostoptext
}
120 121
\permanent
\let
\stopfittingpage
\page_fitting_stop_normal
122 123
\setupfittingpage
124
[
%\c!scale=1000,
125
%\c!pagestate=,
126
\c!strut
=
\v!none
,
% was no, but we get a noindent then (with the danger of a lineskip)
127
\c!align
=
\v!normal
,
128
\c!offset
=
\v!overlay
,
129
\c!width
=
\v!fit
,
130
\c!height
=
\v!fit
,
131
\c!frame
=
\v!off
]
132 133
%D \TEX\ pages (for \METAPOST\ pages, see \type {meta-fig}):
134 135
%D \starttyping
136
%D \startTEXpage[align=normal,width=900pt,autowidth=force]
137
%D \framed[width=800pt,frame=off]{\number\dimexpr800pt}\par
138
%D \input tufte\par
139
%D \stopTEXpage
140
%D \stoptyping
141
%D
142
%D Beware: the width is the textwidth!
143 144
\definefittingpage
145
[
TEXpage
]
146
[
\c!align
=
\v!normal
]
% needed, else problems !
147 148
\permanent
\protected
\def
\setupTEXpage
149
{
\setupfittingpage
[
TEXpage
]
}
150 151
%D For Mojca:
152
%D
153
%D \starttyping
154
%D \startTEXstream \chapter{Bla} Hello world!\crlf Hello world! \stopTEXstream
155
%D \startTEXpage \chapter{Bla} Hello world!\crlf Hello world! \stopTEXpage
156
%D \stoptyping
157
%D
158
%D maybe I should support stream=yes in framed.
159 160
\permanent
\tolerant
\protected
\def
\startTEXstream
[
#
1
]
% old code, to be redone
161
{
\page
162
\enableoutputstream
[
tex
]
}
163 164
\permanent
\protected
\def
\stopTEXstream
165
{
\disableoutputstream
166
\startTEXpage
% [\c!align=\v!normal]
167
\outputstreamunvbox
[
tex
]
%
168
\stopTEXpage
}
169 170
%D Application pages, a quick \MKIV\ hack:
171 172
\definetypesetting
[
TEXapplication
]
173
\definebuffer
[
TEXapplication
]
174 175
% we could use a counter and saves runs on numbering them.
176 177
\permanent
\def
\TEXapplicationfilename
{
\jobname
-
texapplication
.
tex
}
178 179
\permanent
\protected
\def
\stopTEXapplication
180
{
\savebuffer
[
\thedefinedbuffer
{
TEXapplication
}
]
[
\TEXapplicationfilename
]
%
181
\typesetfile
[
TEXapplication
]
[
\TEXapplicationfilename
]
\relax
}
182 183
%D \macros
184
%D {startpagefigure}
185
%D
186
%D \starttyping
187
%D \starttext \pagefigure[two.1] \stoptext
188
%D \stoptyping
189 190
\defineexternalfigure
[
\v!page
:
\v!figure
]
[
\c!offset
=
\v!overlay
]
% we force a parent
191 192
\permanent
\tolerant
\protected
\def
\startpagefigure
[
#
1
]
#
*
[
#
2
]
%
193
{
\bgroup
194
\setupexternalfigure
[
\v!page
:
\v!figure
]
[
\c!offset
=
\v!overlay
,
#
2
]
%
195
\startTEXpage
[
\c!offset
=
\namedexternalfigureparameter
{
\v!page
:
\v!figure
}
\c!offset
,
\c!align
=
\v!normal
]
%
196
\externalfigure
[
#
1
]
\ignorespaces
}
% so we can put some text below the graphic
197 198
\permanent
\protected
\def
\stoppagefigure
199
{
\stopTEXpage
200
\egroup
}
201 202
\permanent
\tolerant
\protected
\def
\pagefigure
[
#
1
]
#
*
[
#
2
]
%
203
{
\startpagefigure
[
#
1
]
[
#
2
]
\stoppagefigure
}
204 205
\protect
\endinput
206