page-flw.mkiv /size: 5387 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=page-flw,
3%D        version=2003.04.19, % from test-002 (1997) profile experiment
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Text Flows,
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 / Text Flows}
15
16%D This is high experimental and especially flushing may change (proper
17%D spacing is the driving force here). It's an old mechanism used for
18%D playing with stepping through document threads. As it's a simple and
19%D effective mechanism we keep it around. It's not to be confused with
20%D upcoming stream support.
21%D
22%D \starttyping
23%D \setuppapersize [S6]
24%D \setuptolerance [verytolerant,stretch]
25%D \setupfooter    [strut=no]
26%D \setupwhitespace[big]
27%D
28%D \setuplayout
29%D   [rightedge=5cm,width=fit,margin=0pt,edgedistance=1cm,
30%D    footer=4cm,footerdistance=1cm,header=0cm]
31%D
32%D \setuptexttexts  [edge][][\vbox{\flushtextflow{alpha}}]
33%D \setupfootertexts[edge][][\vbox{\flushtextflow{beta}}]
34%D \setupfootertexts        [\vbox{\flushtextflow{gamma}}][]
35%D
36%D \definetextflow [alfa]  [width=\rightedgewidth]
37%D \definetextflow [beta]  [width=\rightedgewidth]
38%D \definetextflow [gamma] [width=\footerheight]
39%D
40%D \starttext
41%D
42%D \dorecurse{50}
43%D   {\getrandomnumber{\funny}{0}{8}
44%D    \ifcase\funny \starttextflow[alfa]  \input tufte.tex   \stoptextflow
45%D    \or           \starttextflow[beta]  \input knuth.tex   \stoptextflow
46%D    \or           \starttextflow[gamma] \input materie.tex \stoptextflow
47%D    \or          {\bf   TUFTE}\quad \input tufte   \par
48%D    \or          {\bf   TUFTE}\quad \input tufte   \par
49%D    \or          {\bf   KNUTH}\quad \input knuth   \par
50%D    \or          {\bf   KNUTH}\quad \input knuth   \par
51%D    \or          {\bf MATERIE}\quad \input materie \par
52%D    \else        {\bf MATERIE}\quad \input materie \par
53%D    \fi}
54%D
55%D \stoptext
56%D \stoptyping
57
58\unprotect
59
60\installcorenamespace{textflow}
61\installcorenamespace{textflowbox}
62
63\installcommandhandler \??textflow {textflow} \??textflow
64
65\setuptextflow
66  [%c!style=,
67   %c!color=,
68   \c!width=\availablehsize]
69
70\appendtoks
71    \ifcsname\??textflowbox\currenttextflow\endcsname
72       \setbox\csname\??textflowbox\currenttextflow\endcsname\emptybox
73    \else
74       \expandafter\newbox\csname\??textflowbox\currenttextflow\endcsname
75    \fi
76\to \everydefinetextflow
77
78\newcount\b_page_textflow_box
79
80\def\textflowcollector#1%
81  {\csname\??textflowbox#1\endcsname}
82
83\unexpanded\def\doifelsetextflowcollector#1%
84  {\ifcsname\??textflowbox#1\endcsname
85     \expandafter\firstoftwoarguments
86   \else
87     \expandafter\secondoftwoarguments
88   \fi}
89
90\unexpanded\def\doifelsetextflow#1%
91  {\ifcsname\??textflowbox#1\endcsname
92     \ifvoid\csname\??textflowbox#1\endcsname
93       \doubleexpandafter\secondoftwoarguments
94     \else
95       \doubleexpandafter\firstoftwoarguments
96     \fi
97   \else
98     \expandafter\secondoftwoarguments
99   \fi}
100
101\let\doiftextflowcollectorelse\doifelsetextflowcollector
102\let\doiftextflowelse         \doifelsetextflow
103
104% \unexpanded\def\doiftextflow#1%
105%   {\doiftextflowelse{#1}\firstofoneargument\gobbleoneargument}
106
107\unexpanded\def\starttextflow[#1]%
108  {\begingroup
109   \edef\currenttextflow{#1}%
110   \ifcsname\??textflowbox\currenttextflow\endcsname
111     \b_page_textflow_box\csname\??textflowbox\currenttextflow\endcsname
112     \global\setbox\b_page_textflow_box\vbox
113       \bgroup
114       \dontcomplain
115       \ifvoid\b_page_textflow_box\else
116         \unvbox\b_page_textflow_box
117       \fi
118       \hsize\textflowparameter\c!width\relax
119       \usetextflowstyleandcolor\c!style\c!color
120       \unexpanded\def\stoptextflow{\endgraf\egroup\endgroup}%
121   \else
122     \let\stoptextflow\endgroup
123   \fi}
124
125\unexpanded\def\flushtextflow#1%
126  {\begingroup
127   \edef\currenttextflow{#1}%
128   \ifcsname\??textflowbox\currenttextflow\endcsname
129     \b_page_textflow_box\csname\??textflowbox\currenttextflow\endcsname
130     \ifvoid\b_page_textflow_box
131       % sorry
132     \else\ifdim\ht\b_page_textflow_box>\vsize
133        \setbox\scratchbox\vsplit\b_page_textflow_box to \vsize
134        \ifvoid\scratchbox\else
135          \unvbox\scratchbox
136        \fi
137      \else
138        \unvbox\b_page_textflow_box
139      \fi\fi
140   \fi
141   \endgroup}
142
143\protect \endinput
144
145% \setuppapersize [A6]
146% \setupbodyfont [pagella, 12pt]
147%
148% \definetextflow [even]  [width=\textwidth]
149% \definetextflow [odd]   [width=\textwidth]
150%
151% \starttextflow [even] \dorecurse{15}{\input bryson} \stoptextflow
152% \starttextflow [odd]  \dorecurse {5}{\input knuth } \stoptextflow
153%
154% \starttext
155%
156% \doloop {
157%     \ifodd\realpageno
158%         \doiftextflowelse{odd} {
159%             \bgroup
160%             \vsize\dimexpr\textheight-\strutdp\relax
161%             \flushtextflow{odd}
162%             \egroup
163%         } {
164%             \null
165%         }
166%         \page
167%     \else
168%         \doiftextflowelse{even} {
169%             \bgroup
170%             \vsize\dimexpr\textheight-\strutdp\relax
171%             \flushtextflow{even}
172%             \egroup
173%         } {
174%           \null
175%         }
176%         \page
177%     \fi
178%     \doiftextflowelse{even}\donothing{\doiftextflowelse{odd}\donothing\exitloop}
179% }
180%
181% \stoptext
182
183