summaryrefslogtreecommitdiff
path: root/tex/context/base/page-flw.mkiv
blob: 56fe32e5b9e77773e0e1cb7202e9c94667373c44 (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
%D \module
%D   [       file=page-flw,
%D        version=2003.04.19, % from test-002 (1997) profile experiment
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Text Flows,
%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 / Text Flows}

%D This is high experimental and especially flushing may change (proper
%D spacing is the driving force here). It's an old mechanism used for
%D playing with stepping through document threads. As it's a simple and
%D effective mechanism we keep it around. It's not to be confused with
%D upcoming stream support.
%D
%D \starttyping
%D \setuppapersize [S6]
%D \setuptolerance [verytolerant,stretch]
%D \setupfooter    [strut=no]
%D \setupwhitespace[big]
%D
%D \setuplayout
%D   [rightedge=5cm,width=fit,margin=0pt,edgedistance=1cm,
%D    footer=4cm,footerdistance=1cm,header=0cm]
%D
%D \setuptexttexts  [edge][][\vbox{\flushtextflow{alpha}}]
%D \setupfootertexts[edge][][\vbox{\flushtextflow{beta}}]
%D \setupfootertexts        [\vbox{\flushtextflow{gamma}}][]
%D
%D \definetextflow [alfa]  [width=\rightedgewidth]
%D \definetextflow [beta]  [width=\rightedgewidth]
%D \definetextflow [gamma] [width=\footerheight]
%D
%D \starttext
%D
%D \dorecurse{50}
%D   {\getrandomnumber{\funny}{0}{8}
%D    \ifcase\funny \starttextflow[alfa]  \input tufte.tex   \stoptextflow
%D    \or           \starttextflow[beta]  \input knuth.tex   \stoptextflow
%D    \or           \starttextflow[gamma] \input materie.tex \stoptextflow
%D    \or          {\bf   TUFTE}\quad \input tufte   \par
%D    \or          {\bf   TUFTE}\quad \input tufte   \par
%D    \or          {\bf   KNUTH}\quad \input knuth   \par
%D    \or          {\bf   KNUTH}\quad \input knuth   \par
%D    \or          {\bf MATERIE}\quad \input materie \par
%D    \else        {\bf MATERIE}\quad \input materie \par
%D    \fi}
%D
%D \stoptext
%D \stoptyping

\unprotect

\installcorenamespace{textflow}
\installcorenamespace{textflowbox}

\installcommandhandler \??textflow {textflow} \??textflow

\setuptextflow
  [%c!style=,
   %c!color=,
   \c!width=\availablehsize]

\appendtoks
    \ifcsname\??textflowbox\currenttextflow\endcsname
       \setbox\csname\??textflowbox\currenttextflow\endcsname\emptybox
    \else
       \expandafter\newbox\csname\??textflowbox\currenttextflow\endcsname
    \fi
\to \everydefinetextflow

\let\b_page_textflow_box\zerocount

\def\textflowcollector#1%
  {\csname\??textflowbox#1\endcsname}

\unexpanded\def\doifelsetextflowcollector#1%
  {\ifcsname\??textflowbox#1\endcsname
     \expandafter\firstoftwoarguments
   \else
     \expandafter\secondoftwoarguments
   \fi}

\unexpanded\def\doifelsetextflow#1%
  {\ifcsname\??textflowbox#1\endcsname
     \ifvoid\csname\??textflowbox#1\endcsname
       \doubleexpandafter\secondoftwoarguments
     \else
       \doubleexpandafter\firstoftwoarguments
     \fi
   \else
     \expandafter\secondoftwoarguments
   \fi}

\let\doiftextflowcollectorelse\doifelsetextflowcollector
\let\doiftextflowelse         \doifelsetextflow

% \unexpanded\def\doiftextflow#1%
%   {\doiftextflowelse{#1}\firstofoneargument\gobbleoneargument}

\unexpanded\def\starttextflow[#1]%
  {\begingroup
   \edef\currenttextflow{#1}%
   \ifcsname\??textflowbox\currenttextflow\endcsname
     \b_page_textflow_box\csname\??textflowbox\currenttextflow\endcsname
     \global\setbox\b_page_textflow_box\vbox
       \bgroup
       \dontcomplain
       \ifvoid\b_page_textflow_box\else
         \unvbox\b_page_textflow_box
       \fi
       \hsize\textflowparameter\c!width\relax
       \usetextflowstyleandcolor\c!style\c!color
       \unexpanded\def\stoptextflow{\endgraf\egroup\endgroup}%
   \else
     \let\stoptextflow\endgroup
   \fi}

\unexpanded\def\flushtextflow#1%
  {\begingroup
   \edef\currenttextflow{#1}%
   \ifcsname\??textflowbox\currenttextflow\endcsname
     \b_page_textflow_box\csname\??textflowbox\currenttextflow\endcsname
     \ifvoid\b_page_textflow_box
       % sorry
     \else\ifdim\ht\b_page_textflow_box>\vsize
        \setbox\scratchbox\vsplit\b_page_textflow_box to \vsize
        \ifvoid\scratchbox\else
          \unvbox\scratchbox
        \fi
      \else
        \unvbox\b_page_textflow_box
      \fi\fi
   \fi
   \endgroup}

\protect \endinput