page-app.mkxl /size: 6596 b    last modification: 2025-02-21 11:03
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\newdimension\d_page_fitting_width
25\newdimension\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]#*[#S#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   \cdef\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   \ifempty{\fittingpageparameter\c!command}%
62     \expandafter\page_fitting_start_normal
63   \else
64     \expandafter\page_fitting_start_command
65   \fi}
66
67\def\page_fitting_start_command
68  {\grabuntil{\e!stop\currentfittingpage}\page_fitting_stop_command}
69
70\def\page_fitting_stop_command#1%
71  {\page_fitting_start_normal
72   \fittingpageparameter\c!command{#1}%
73   \page_fitting_stop_normal}
74
75\def\page_fitting_start_normal
76   {\setbox\b_page_fitting\hbox
77      \bgroup
78      \inheritedfittingpageframed
79      \bgroup
80      \ignorepars}
81
82\protected\def\page_fitting_stop_normal % todo: figure out why a small mp image gets shifted
83  {\removeunwantedspaces
84   \egroup
85   \egroup
86   % finalize
87   \ifcstok{\fittingpageparameter\c!margin}\v!page
88     \setbox\b_page_fitting\hpack\bgroup
89       \offsetbox
90         [\c!leftoffset=\backspace,
91          \c!rightoffset=\cutspace,
92          \c!topoffset=\topspace,
93          \c!bottomoffset=\bottomspace]
94         {\box\b_page_fitting}%
95     \egroup
96   \fi
97   \ifempty{\fittingpageparameter\c!scale}\else
98     \setbox\b_page_fitting\hpack\bgroup
99       \scale[\c!scale=\fittingpageparameter\c!scale]{\box\b_page_fitting}%
100     \egroup
101   \fi
102   \ifzeropt\ht\b_page_fitting
103     \ht\b_page_fitting\onepoint
104   \fi
105   \ifzeropt\wd\b_page_fitting
106     \wd\b_page_fitting\onepoint
107   \fi
108   \d_page_fitting_width \wd\b_page_fitting
109 % \d_page_fitting_height\ht\b_page_fitting
110   % a change if plan ...
111   \d_page_fitting_height\htdp\b_page_fitting
112   \startlocallayout % hm, we change the papersize so we still need it
113   \enforced\let\checkcurrentlayout\relax % else interference with odd/even layout
114   \processaction
115     [\fittingpageparameter\c!paper]
116     [   \v!auto=>\let\scratchstringone\printpapersize,
117      \s!unknown=>\let\scratchstringone\commalistelement,
118      \s!default=>\def\scratchstringone{fittingpage}]%
119   \normalexpanded{\setuppapersize[fittingpage][\scratchstringone]}%
120   %
121   \edef\p_label{\fittingpageparameter\c!label}%
122   \ifempty\p_label\else
123     \normalexpanded{\setuppagenumber[\c!label=\p_label]}%
124   \fi
125   %
126   \startmakeup[fittingpage]%
127     \box\b_page_fitting
128   \stopmakeup
129   \stoplocallayout % we need to get rid of this and use the built-in
130   \egroup
131   \autostoptext}
132
133\permanent\let\stopfittingpage\page_fitting_stop_normal
134
135\setupfittingpage
136  [%\c!scale=1000,
137   %\c!pagestate=,
138   \c!strut=\v!none, % was no, but we get a noindent then (with the danger of a lineskip)
139   \c!align=\v!normal,
140   \c!offset=\v!overlay,
141   \c!width=\v!fit,
142   \c!height=\v!fit,
143   \c!frame=\v!off]
144
145%D \TEX\ pages (for \METAPOST\ pages, see \type {meta-fig}):
146
147%D \starttyping
148%D \startTEXpage[align=normal,width=900pt,autowidth=force]
149%D     \framed[width=800pt,frame=off]{\number\dimexpr800pt}\par
150%D     \input tufte\par
151%D \stopTEXpage
152%D \stoptyping
153%D
154%D Beware: the width is the textwidth!
155
156\definefittingpage
157  [TEXpage]
158  [\c!align=\v!normal] % needed, else problems !
159
160\permanent\protected\def\setupTEXpage
161  {\setupfittingpage[TEXpage]}
162
163%D For Mojca:
164%D
165%D \starttyping
166%D \startTEXstream \chapter{Bla} Hello world!\crlf Hello world! \stopTEXstream
167%D \startTEXpage   \chapter{Bla} Hello world!\crlf Hello world! \stopTEXpage
168%D \stoptyping
169%D
170%D maybe I should support stream=yes in framed.
171
172\permanent\tolerant\protected\def\startTEXstream[#1]% old code, to be redone
173  {\page
174   \enableoutputstream[tex]}
175
176\permanent\protected\def\stopTEXstream
177  {\disableoutputstream
178   \startTEXpage % [\c!align=\v!normal]
179     \outputstreamunvbox[tex]%
180   \stopTEXpage}
181
182%D Application pages, a quick \MKIV\ hack:
183
184\definetypesetting[TEXapplication]
185\definebuffer[TEXapplication]
186
187% we could use a counter and saves runs on numbering them.
188
189\permanent\def\TEXapplicationfilename{\jobname-texapplication.tex}
190
191\permanent\protected\def\stopTEXapplication
192  {\savebuffer[\thedefinedbuffer{TEXapplication}][\TEXapplicationfilename]%
193   \typesetfile[TEXapplication][\TEXapplicationfilename]\relax}
194
195%D \macros
196%D   {startpagefigure}
197%D
198%D \starttyping
199%D \starttext \pagefigure[two.1] \stoptext
200%D \stoptyping
201
202\defineexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay] % we force a parent
203
204\permanent\tolerant\protected\def\startpagefigure[#1]#*[#S#2]%
205  {\bgroup
206   \setupexternalfigure[\v!page:\v!figure][\c!offset=\v!overlay,#2]%
207   \startTEXpage[\c!offset=\namedexternalfigureparameter{\v!page:\v!figure}\c!offset,\c!align=\v!normal]%
208     \externalfigure[#1][\v!page:\v!figure]\ignorespaces} % so we can put some text below the graphic
209
210\permanent\protected\def\stoppagefigure
211  {\stopTEXpage
212   \egroup}
213
214\permanent\tolerant\protected\def\pagefigure[#1]#*[#S#2]%
215  {\startpagefigure[#1][#2]\stoppagefigure}
216
217\protect \endinput
218