page-col.mkiv /size: 6703 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=page-col,   % moved from page-ini
3%D        version=2011.12.07, % 2000.10.20,
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Column Helpers,
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 / Column Helpers}
15
16%D Here we implement a couple of helpers for dealing with columns. For
17%D the moment we keep the names. When the mul and set modules are redone
18%D these can be adapted or disappear.
19
20\unprotect
21
22%D We reserve a counter for the number of columns as well as the current
23%D column. Both are not to be changed by users!
24
25%newcount\nofcolumns \nofcolumns\plusone % already in core-ini.mkiv
26\newcount\mofcolumns \mofcolumns\plusone
27
28\newconstant\columndirection % 0:lr 1:rl
29
30\setnewconstant\maxnofcolumns       50
31\setnewconstant\allocatednofcolumns  0
32
33\newdimen\columnwidth
34\newdimen\columndistance
35
36%D During initialization the temporary boxes are allocated. This enables us to
37%D use as much columns as we want, without exhausting the pool of boxes too
38%D fast. We could have packed them in one box, but we've got enough boxes.
39%D
40%D Two sets of boxes are declared, the txtboxes are used for the text, the
41%D topboxes are for moved column floats.
42
43\installcorenamespace{columntext}
44\installcorenamespace{columnfooter}
45\installcorenamespace{columntop}
46\installcorenamespace{columnbottom}
47
48\unexpanded\def\initializecolumns#1%
49  {\ifnum#1>\maxnofcolumns
50     \showmessage\m!columns1\maxnofcolumns
51     \nofcolumns\maxnofcolumns
52   \else
53     \nofcolumns#1\relax
54   \fi
55   \ifnum\nofcolumns>\allocatednofcolumns
56     \page_columns_allocate
57   \fi}
58
59\def\page_columns_allocate
60  {\dorecurse\nofcolumns
61     {\ifnum\recurselevel>\allocatednofcolumns\relax
62        \ifcsname\??columntext\recurselevel\endcsname \else
63          \expandafter\newbox\csname\??columntext  \recurselevel\endcsname % text
64          \expandafter\newbox\csname\??columnfooter\recurselevel\endcsname % footer
65          \expandafter\newbox\csname\??columntop   \recurselevel\endcsname % top insert
66          \expandafter\newbox\csname\??columnbottom\recurselevel\endcsname % bottom insert
67        \fi
68      \fi}%
69   \global\allocatednofcolumns\nofcolumns}
70
71\def\currentcolumn       {1}
72
73\def\firstcolumnbox      {\columntextbox\plusone}
74\def\currentcolumnbox    {\columntextbox\mofcolumns}
75\def\lastcolumnbox       {\columntextbox\nofcolumns}
76
77\def\firsttopcolumnbox   {\columntopbox \plusone}
78\def\currenttopcolumnbox {\columntopbox \mofcolumns}
79\def\lasttopcolumnbox    {\columntopbox \nofcolumns}
80
81\def\columntextbox     #1{\csname\??columntext  \number#1\endcsname}
82\def\columnfootbox     #1{\csname\??columnfooter\number#1\endcsname}
83\def\columntopbox      #1{\csname\??columntop   \number#1\endcsname}
84\def\columnbotbox      #1{\csname\??columnbottom\number#1\endcsname}
85
86\unexpanded\def\columnsettextbox    {\global\setbox\columntextbox}
87\unexpanded\def\columnsetfootbox    {\global\setbox\columnfootbox}
88\unexpanded\def\columnsettopbox     {\global\setbox\columntopbox}
89\unexpanded\def\columnsetbotbox     {\global\setbox\columnbotbox}
90
91\unexpanded\def\columngettextbox    {\copy\columntextbox}
92\unexpanded\def\columngetfootbox    {\copy\columnfootbox}
93\unexpanded\def\columngettopbox     {\copy\columntopbox}
94\unexpanded\def\columngetbotbox     {\copy\columnbotbox}
95
96\unexpanded\def\columnerasetextboxes{\dorecurse\allocatednofcolumns{\columnsettextbox\recurselevel\emptybox}}
97\unexpanded\def\columnerasefootboxes{\dorecurse\allocatednofcolumns{\columnsetfootbox\recurselevel\emptybox}}
98\unexpanded\def\columnerasetopboxes {\dorecurse\allocatednofcolumns{\columnsettopbox \recurselevel\emptybox}}
99\unexpanded\def\columnerasebotboxes {\dorecurse\allocatednofcolumns{\columnsetbotbox \recurselevel\emptybox}}
100
101%D Without going in details we present two macro's which handle the columns. The
102%D action which is transfered by the the first and only parameter can do something
103%D with \type {\currentcolumnbox}. In case of the mid columns, \type
104%D {\firstcolumnbox} and \type {\lastcolumnbox} are handled outside these macro's.
105
106% \unexpanded\def\dohandlecolumn#1%
107%   {\mofcolumns\recurselevel
108%    \let\currentcolumn\recurselevel
109%    #1\relax}
110%
111% \unexpanded\def\dohandleallcolumns#1%
112%   {\dorecurse\nofcolumns{\dohandlecolumn{#1}}}
113%
114% \unexpanded\def\dohandlerevcolumns#1%
115%   {\dostepwiserecurse\nofcolumns\plusone\minusone{\dohandlecolumn{#1}}}
116%
117% \unexpanded\def\dohandlemidcolumns#1%
118%   {\dohandleallcolumns
119%      {\ifnum\recurselevel>\plusone
120%         \ifnum\recurselevel<\nofcolumns
121%           \dohandlecolumn{#1}%
122%         \fi
123%       \fi}}
124%
125% As we don't nest we can use a fast variant:
126
127\unexpanded\def\dohandleallcolumnscs#1{\let\page_columns_action  #1\page_columns_all_indeed}
128\unexpanded\def\dohandleallcolumns  #1{\def\page_columns_action{#1}\page_columns_all_indeed}
129
130\unexpanded\def\dohandlerevcolumnscs#1{\let\page_columns_action  #1\page_columns_rev_indeed}
131\unexpanded\def\dohandlerevcolumns  #1{\def\page_columns_action{#1}\page_columns_rev_indeed}
132
133\unexpanded\def\dohandlemidcolumnscs#1{\let\page_columns_action  #1\page_columns_mid_indeed}
134\unexpanded\def\dohandlemidcolumns  #1{\def\page_columns_action{#1}\page_columns_mid_indeed}
135
136\unexpanded\def\page_columns_all_indeed
137  {\mofcolumns\plusone
138   \edef\currentcolumn{\the\mofcolumns}%
139   \page_columns_action\relax
140   \ifnum\mofcolumns<\nofcolumns
141     \expandafter\page_columns_all_next
142   \fi}
143
144\unexpanded\def\page_columns_all_next
145  {\advance\mofcolumns\plusone
146   \edef\currentcolumn{\the\mofcolumns}%
147   \page_columns_action\relax
148   \ifnum\mofcolumns<\nofcolumns
149     \expandafter\page_columns_all_next
150   \fi}
151
152\unexpanded\def\page_columns_rev_indeed
153  {\mofcolumns\nofcolumns
154   \edef\currentcolumn{\the\mofcolumns}%
155   \page_columns_action\relax
156   \ifnum\mofcolumns>\plusone
157     \expandafter\page_columns_rev_prev
158   \fi}
159
160\unexpanded\def\page_columns_rev_prev
161  {\advance\mofcolumns\minusone
162   \edef\currentcolumn{\the\mofcolumns}%
163   \page_columns_action\relax
164   \ifnum\mofcolumns>\plusone
165     \expandafter\page_columns_rev_prev
166   \fi}
167
168\unexpanded\def\page_columns_mid_indeed
169  {\mofcolumns\plustwo
170   \ifnum\mofcolumns<\nofcolumns
171     \expandafter\page_columns_mid_next
172   \fi}
173
174\unexpanded\def\page_columns_mid_next
175  {\edef\currentcolumn{\the\mofcolumns}%
176   \page_columns_action\relax
177   \advance\mofcolumns\plusone
178   \ifnum\mofcolumns<\nofcolumns
179     \expandafter\page_columns_mid_next
180   \fi}
181
182\protect \endinput
183