page-col.mkxl /size: 6569 b    last modification: 2023-12-21 09:44
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%D DO WE STILL NEED THESE?
21
22\unprotect
23
24%D We reserve a counter for the number of columns as well as the current
25%D column. Both are not to be changed by users!
26
27%newinteger    \nofcolumns \nofcolumns\plusone % already in core-ini.mkiv
28\newinteger    \mofcolumns \mofcolumns\plusone
29\newdimension  \columnwidth
30\newdimension  \columndistance
31\newconstant   \columndirection % 0:lr 1:rl
32
33\pushoverloadmode
34    \newuserunit \columnwidth    cw % column width
35    \newuserunit \columndistance cd % column distance
36\popoverloadmode
37
38\setnewconstant\maxnofcolumns       50
39\setnewconstant\allocatednofcolumns  0
40
41%D During initialization the temporary boxes are allocated. This enables us to
42%D use as much columns as we want, without exhausting the pool of boxes too
43%D fast. We could have packed them in one box, but we've got enough boxes.
44%D
45%D Two sets of boxes are declared, the txtboxes are used for the text, the
46%D topboxes are for moved column floats.
47
48\installcorenamespace{columntext}
49\installcorenamespace{columnfooter}
50\installcorenamespace{columntop}
51\installcorenamespace{columnbottom}
52
53\permanent\protected\def\initializecolumns#1%
54  {\ifnum#1>\maxnofcolumns
55     \showmessage\m!columns1\maxnofcolumns
56     \nofcolumns\maxnofcolumns
57   \else
58     \nofcolumns#1\relax
59   \fi
60   \ifnum\nofcolumns>\allocatednofcolumns
61     \page_columns_allocate
62   \fi}
63
64\def\page_columns_allocate
65  {\dorecurse\nofcolumns
66     {\ifnum\recurselevel>\allocatednofcolumns\relax
67        \ifcsname\??columntext\recurselevel\endcsname \else
68          \expandafter\newbox\csname\??columntext  \recurselevel\endcsname % text
69          \expandafter\newbox\csname\??columnfooter\recurselevel\endcsname % footer
70          \expandafter\newbox\csname\??columntop   \recurselevel\endcsname % top insert
71          \expandafter\newbox\csname\??columnbottom\recurselevel\endcsname % bottom insert
72        \fi
73      \fi}%
74   \global\allocatednofcolumns\nofcolumns}
75
76\mutable\def\currentcolumn{1}
77
78\immutable\def\firstcolumnbox  {\columntextbox\plusone}
79\immutable\def\currentcolumnbox{\columntextbox\mofcolumns}
80\immutable\def\lastcolumnbox   {\columntextbox\nofcolumns}
81
82\immutable\def\firsttopcolumnbox  {\columntopbox \plusone}
83\immutable\def\currenttopcolumnbox{\columntopbox \mofcolumns}
84\immutable\def\lasttopcolumnbox   {\columntopbox \nofcolumns}
85
86\permanent\def\columntextbox#1{\csname\??columntext  \number#1\endcsname}
87\permanent\def\columnfootbox#1{\csname\??columnfooter\number#1\endcsname}
88\permanent\def\columntopbox #1{\csname\??columntop   \number#1\endcsname}
89\permanent\def\columnbotbox #1{\csname\??columnbottom\number#1\endcsname}
90
91\permanent\protected\def\columnsettextbox{\global\setbox\columntextbox}
92\permanent\protected\def\columnsetfootbox{\global\setbox\columnfootbox}
93\permanent\protected\def\columnsettopbox {\global\setbox\columntopbox}
94\permanent\protected\def\columnsetbotbox {\global\setbox\columnbotbox}
95
96\permanent\protected\def\columngettextbox    {\copy\columntextbox}
97\permanent\protected\def\columngetfootbox    {\copy\columnfootbox}
98\permanent\protected\def\columngettopbox     {\copy\columntopbox}
99\permanent\protected\def\columngetbotbox     {\copy\columnbotbox}
100
101\permanent\protected\def\columnerasetextboxes{\dorecurse\allocatednofcolumns{\columnsettextbox\recurselevel\emptybox}}
102\permanent\protected\def\columnerasefootboxes{\dorecurse\allocatednofcolumns{\columnsetfootbox\recurselevel\emptybox}}
103\permanent\protected\def\columnerasetopboxes {\dorecurse\allocatednofcolumns{\columnsettopbox \recurselevel\emptybox}}
104\permanent\protected\def\columnerasebotboxes {\dorecurse\allocatednofcolumns{\columnsetbotbox \recurselevel\emptybox}}
105
106%D Without going in details we present two macro's which handle the columns. The
107%D action which is transfered by the the first and only parameter can do something
108%D with \type {\currentcolumnbox}. In case of the mid columns, \type
109%D {\firstcolumnbox} and \type {\lastcolumnbox} are handled outside these macro's.
110
111\let\page_columns_action\relax
112
113\permanent\protected\def\dohandleallcolumnscs#1{\let\page_columns_action  #1\page_columns_all_indeed}
114\permanent\protected\def\dohandleallcolumns  #1{\def\page_columns_action{#1}\page_columns_all_indeed}
115
116\permanent\protected\def\dohandlerevcolumnscs#1{\let\page_columns_action  #1\page_columns_rev_indeed}
117\permanent\protected\def\dohandlerevcolumns  #1{\def\page_columns_action{#1}\page_columns_rev_indeed}
118
119\permanent\protected\def\dohandlemidcolumnscs#1{\let\page_columns_action  #1\page_columns_mid_indeed}
120\permanent\protected\def\dohandlemidcolumns  #1{\def\page_columns_action{#1}\page_columns_mid_indeed}
121
122\protected\def\page_columns_all_indeed
123  {\mofcolumns\plusone
124   \edef\currentcolumn{\the\mofcolumns}%
125   \page_columns_action\relax
126   \ifnum\mofcolumns<\nofcolumns
127     \expandafter\page_columns_all_next
128   \fi}
129
130\protected\def\page_columns_all_next
131  {\advanceby\mofcolumns\plusone
132   \edef\currentcolumn{\the\mofcolumns}%
133   \page_columns_action\relax
134   \ifnum\mofcolumns<\nofcolumns
135     \expandafter\page_columns_all_next
136   \fi}
137
138\protected\def\page_columns_rev_indeed
139  {\mofcolumns\nofcolumns
140   \edef\currentcolumn{\the\mofcolumns}%
141   \page_columns_action\relax
142   \ifnum\mofcolumns>\plusone
143     \expandafter\page_columns_rev_prev
144   \fi}
145
146\protected\def\page_columns_rev_prev
147  {\advanceby\mofcolumns\minusone
148   \edef\currentcolumn{\the\mofcolumns}%
149   \page_columns_action\relax
150   \ifnum\mofcolumns>\plusone
151     \expandafter\page_columns_rev_prev
152   \fi}
153
154\protected\def\page_columns_mid_indeed
155  {\mofcolumns\plustwo
156   \ifnum\mofcolumns<\nofcolumns
157     \expandafter\page_columns_mid_next
158   \fi}
159
160\protected\def\page_columns_mid_next
161  {\edef\currentcolumn{\the\mofcolumns}%
162   \page_columns_action\relax
163   \advanceby\mofcolumns\plusone
164   \ifnum\mofcolumns<\nofcolumns
165     \expandafter\page_columns_mid_next
166   \fi}
167
168\protect \endinput
169