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
219
220
221
222
223
224
225
|
%D \module
%D [ file=page-app, % from meta-fig
%D version=1998.01.15,
%D title=\CONTEXT\ Page Macros,
%D subtitle=Independent page building,
%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 / Applications}
%D The fitting page code is moved from \type {meta-fig} to
%D here.
\unprotect
\definepapersize
[\??fp\s!dummy]
[\c!width=\fittingwd,
\c!height=\fittinght]
\definelayout
[\??fp\s!dummy]
[\c!width=\fittingwd,\c!height=\fittinght,\c!location=\v!middle,
\c!topspace=\!!zeropoint,\c!backspace=\!!zeropoint,
\c!cutspace=\!!zeropoint,\c!bottomspace=\!!zeropoint,
\c!textdistance=\!!zeropoint,\c!lines=0,\c!grid=\v!no,
\c!top=\!!zeropoint,\c!bottom=\!!zeropoint,
\c!margin=\!!zeropoint,\c!edge=\!!zeropoint,
\c!leftmargin=\!!zeropoint,\c!leftedge=\!!zeropoint,
\c!rightmargin=\!!zeropoint,\c!rightedge=\!!zeropoint,
\c!header=\!!zeropoint,\c!footer=\!!zeropoint]
\def\dostartfittingpage[#1][#2]%
{\page % this is kind of tricky! there can be preceding page refs
\autostarttext
\bgroup % resulting in a zero height page; test fig-make !
\def\currentfittingpage{#1}%
\dontcomplain
% runs under current page regime, i.e. page variables passed to mp
\getparameters[\currentfittingpage][\c!paper=,#2]% auto or size or nothing
\setbox\scratchbox\hbox
\bgroup
% needed later \getparameters[\currentfittingpage][\c!paper=,#2]% auto or size or nothing
\doifvalue{\currentfittingpage\c!margin}\v!page % undocumented
{\offsetbox
[\c!leftoffset=\backspace,
\c!rightoffset=\cutspace,
\c!topoffset=\topspace,
\c!bottomoffset=\bottomspace]\hbox}%
\bgroup
\scale[\c!scale=\getvalue{\currentfittingpage\c!scale}]%
\bgroup\localframed[\currentfittingpage]%
\bgroup}
\def\dostopfittingpage
{\egroup % localframed
\egroup % scale
\egroup % offsetbox
\egroup % scratchbox
\edef\fittingwd{\the\wd\scratchbox}%
\edef\fittinght{\the\ht\scratchbox}%
\startlocallayout
\ifdim\fittinght<\lineheight
% write status : too small
\setbox\scratchbox\vbox to \lineheight{\vss\box\scratchbox\vss}%
\edef\fittinght{\the\lineheight}%
\fi
\let\checkcurrentlayout\relax % else interference with odd/even layout
\processaction
[\getvalue{\currentfittingpage\c!paper}]
[ \v!auto=>\let\fittingpapersize\printpapersize,
\s!unknown=>\let\fittingpapersize\commalistelement,
\s!default=>\def\fittingpapersize{\??fp\s!dummy}]%
\expanded{\setuppapersize[\??fp\s!dummy][\fittingpapersize]}%
\definelayout
[\v!page]%
[\c!location=\v!middle,
\c!width=\fittingwd,
\c!height=\fittinght]%
\setuplayout
[\v!page]%
\startmakeup[\v!standard][\c!textstate=\v!empty,\c!doublesided=\v!no,\c!page=]%
\centerbox{\box\scratchbox}%
\stopmakeup
\stoplocallayout
\egroup
\autostoptext}
%D \TEX\ pages (for \METAPOST\ pages, see \type {meta-fig}):
\presetlocalframed[\??tg]
\def\setupTEXpage
{\dodoubleargument\getparameters[\??tg]}
\def\startTEXpage
{\dosingleempty\dostartTEXpage}
\def\dostartTEXpage[#1]%
{\dostartfittingpage[\??tg][#1]\gobblespacetokens}
\def\stopTEXpage
{\removelastspace
\dostopfittingpage}
\setupTEXpage
[\c!scale=1000,
\c!strut=\v!no,
\c!align=\v!normal, % needed, else problems !
\c!offset=\v!overlay,
\c!width=\v!fit,
\c!height=\v!fit,
\c!frame=\v!off]
%D For Mojca:
%D
%D \starttyping
%D \startTEXstream \chapter{Bla} Hello world!\crlf Hello world! \stopTEXstream
%D \startTEXpage \chapter{Bla} Hello world!\crlf Hello world! \stopTEXpage
%D \stoptyping
%D
%D maybe I should support stream=yes in framed.
\def\startTEXstream
{\dosingleempty\dostartTEXstream}
\def\dostartTEXstream[#1]%
{\page
\defineoutputstream[tex]%
\enableoutputstream[tex]%
\def\stopTEXstream
{\disableoutputstream
\startTEXpage
\outputstreamunvbox[tex]%
\stopTEXpage}}
%D Application pages (for an example, see \type {m-pstric}):
\def\@@texapp{texapp}
\def\@@texdim{texdim}
\def\saveTEXapplication#1#2%
{\immediate\openout\scratchwrite=\bufferprefix\@@texdim.tmp
\immediate\write\scratchwrite{\dimen#1=\the\ht\scratchbox}%
\immediate\write\scratchwrite{\dimen#2=\the\wd\scratchbox}%
\immediate\closeout\scratchwrite}
\def\restoreTEXapplication
{\readlocfile{\bufferprefix\@@texdim.tmp}\donothing\donothing}
\def\startTEXapplication
{\dosingleempty\dostartTEXapplication}
\long\def\dostartTEXapplication[#1]#2#3\stopTEXapplication
{\bgroup
\bgroup
\let\f!temporaryextension\c!tex
\setbuffer[\@@texapp]%
\starttext
#2% preamble
\startTEXpage[#1]%
\topskip\zeropoint
\setbox\scratchbox\hbox{#3}%
\saveTEXapplication02% dimensions
\box\scratchbox
\stopTEXpage
\stoptext
\endbuffer
\egroup
\doifelse\jobsuffix{dvi}\donetrue\donefalse
\executesystemcommand{texexec \bufferprefix\@@texapp.tex --once --batch}%
\ifdone % eps
\executesystemcommand{dvips -E* -o \@@texapp.eps \@@texapp}%
\else % pdf
\executesystemcommand{dvips \bufferprefix\@@texapp}%
\executesystemcommand{ps2pdf \bufferprefix\@@texapp.ps \bufferprefix\@@texapp.pdf}%
% \executesystemcommand{texmfstart pstopdf \bufferprefix\@@texapp.ps \bufferprefix\@@texapp.pdf}%
\fi
\restoreTEXapplication % dimensions
\doifelse\jobsuffix{dvi}\donetrue\donefalse
\setbox\scratchbox\hbox
{\expanded{\externalfigure
[\bufferprefix\@@texapp.\ifdone eps\else pdf\fi]
[\c!object=\v!no]}}%
\setbox\scratchbox\hbox
{\lower\ht\scratchbox\hbox{\raise\dimen2\box\scratchbox}}%
\wd\scratchbox\dimen0
\ht\scratchbox\dimen2
\dp\scratchbox\zeropoint
\box\scratchbox
\egroup}
%D \macros
%D {startpagefigure}
%D
%D \starttyping
%D \starttext \pagefigure[two.1] \stoptext
%D \stoptyping
\def\startpagefigure
{\dodoubleempty\dostartpagefigure}
\def\dostartpagefigure[#1][#2]%
{\bgroup
\getparameters[\??ex][\c!offset=\v!overlay,#2]%
\startTEXpage[\c!offset=\@@exoffset]%
\externalfigure[#1][#2]\ignorespaces} % so we can put some text below the graphic
\def\stoppagefigure
{\stopTEXpage
\egroup}
\def\pagefigure
{\dodoubleempty\dopagefigure}
\def\dopagefigure[#1][#2]%
{\dostartpagefigure[#1][#2]\stoppagefigure}
\protect \endinput
|