summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/page-col.mkiv
blob: 14b5124210f9ab95e31fa91a439907d9d5107e0c (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
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
%D \module
%D   [       file=page-col,   % moved from page-ini
%D        version=2011.12.07, % 2000.10.20,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Column Helpers,
%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 / Column Helpers}

%D Here we implement a couple of helpers for dealing with columns. For
%D the moment we keep the names. When the mul and set modules are redone
%D these can be adapted or disappear.

\unprotect

%D We reserve a counter for the number of columns as well as the current
%D column. Both are not to be changed by users!

\newcount\nofcolumns \nofcolumns\plusone
\newcount\mofcolumns \mofcolumns\plusone

\newconstant\columndirection % 0:lr 1:rl

\setnewconstant\maxnofcolumns       50
\setnewconstant\allocatednofcolumns  0

%D During initialization the temporary boxes are allocated. This enables us to
%D use as much columns as we want, without exhausting the pool of boxes too
%D fast. We could have packed them in one box, but we've got enough boxes.
%D
%D Two sets of boxes are declared, the txtboxes are used for the text, the
%D topboxes are for moved column floats.

\installcorenamespace{columntext}
\installcorenamespace{columnfooter}
\installcorenamespace{columntop}
\installcorenamespace{columnbottom}

\unexpanded\def\initializecolumns#1%
  {\ifnum#1>\maxnofcolumns
     \showmessage\m!columns1\maxnofcolumns
     \nofcolumns\maxnofcolumns
   \else
     \nofcolumns#1\relax
   \fi
   \ifnum\nofcolumns>\allocatednofcolumns
     \page_columns_allocate
   \fi}

\def\page_columns_allocate
  {\dorecurse\nofcolumns
     {\ifnum\recurselevel>\allocatednofcolumns\relax
        \ifcsname\??columntext\recurselevel\endcsname \else
          \expandafter\newbox\csname\??columntext  \recurselevel\endcsname % text
          \expandafter\newbox\csname\??columnfooter\recurselevel\endcsname % footer
          \expandafter\newbox\csname\??columntop   \recurselevel\endcsname % top insert
          \expandafter\newbox\csname\??columnbottom\recurselevel\endcsname % bottom insert
        \fi
      \fi}%
   \global\allocatednofcolumns\nofcolumns}

\def\currentcolumn       {1}

\def\firstcolumnbox      {\columntextbox\plusone}
\def\currentcolumnbox    {\columntextbox\mofcolumns}
\def\lastcolumnbox       {\columntextbox\nofcolumns}

\def\firsttopcolumnbox   {\columntopbox \plusone}
\def\currenttopcolumnbox {\columntopbox \mofcolumns}
\def\lasttopcolumnbox    {\columntopbox \nofcolumns}

\def\columntextbox     #1{\csname\??columntext  \number#1\endcsname}
\def\columnfootbox     #1{\csname\??columnfooter\number#1\endcsname}
\def\columntopbox      #1{\csname\??columntop   \number#1\endcsname}
\def\columnbotbox      #1{\csname\??columnbottom\number#1\endcsname}

\unexpanded\def\columnsettextbox    {\global\setbox\columntextbox}
\unexpanded\def\columnsetfootbox    {\global\setbox\columnfootbox}
\unexpanded\def\columnsettopbox     {\global\setbox\columntopbox}
\unexpanded\def\columnsetbotbox     {\global\setbox\columnbotbox}

\unexpanded\def\columngettextbox    {\copy\columntextbox}
\unexpanded\def\columngetfootbox    {\copy\columnfootbox}
\unexpanded\def\columngettopbox     {\copy\columntopbox}
\unexpanded\def\columngetbotbox     {\copy\columnbotbox}

\unexpanded\def\columnerasetextboxes{\dorecurse\allocatednofcolumns{\columnsettextbox\recurselevel\emptybox}}
\unexpanded\def\columnerasefootboxes{\dorecurse\allocatednofcolumns{\columnsetfootbox\recurselevel\emptybox}}
\unexpanded\def\columnerasetopboxes {\dorecurse\allocatednofcolumns{\columnsettopbox \recurselevel\emptybox}}
\unexpanded\def\columnerasebotboxes {\dorecurse\allocatednofcolumns{\columnsetbotbox \recurselevel\emptybox}}

%D Without going in details we present two macro's which handle the columns. The
%D action which is transfered by the the first and only parameter can do something
%D with \type {\currentcolumnbox}. In case of the mid columns, \type
%D {\firstcolumnbox} and \type {\lastcolumnbox} are handled outside these macro's.

% \unexpanded\def\dohandlecolumn#1%
%   {\mofcolumns\recurselevel
%    \let\currentcolumn\recurselevel
%    #1\relax}
%
% \unexpanded\def\dohandleallcolumns#1%
%   {\dorecurse\nofcolumns{\dohandlecolumn{#1}}}
%
% \unexpanded\def\dohandlerevcolumns#1%
%   {\dostepwiserecurse\nofcolumns\plusone\minusone{\dohandlecolumn{#1}}}
%
% \unexpanded\def\dohandlemidcolumns#1%
%   {\dohandleallcolumns
%      {\ifnum\recurselevel>\plusone
%         \ifnum\recurselevel<\nofcolumns
%           \dohandlecolumn{#1}%
%         \fi
%       \fi}}
%
% As we don't nest we can use a fast variant:

\unexpanded\def\dohandleallcolumnscs#1{\let\page_columns_action  #1\page_columns_all_indeed}
\unexpanded\def\dohandleallcolumns  #1{\def\page_columns_action{#1}\page_columns_all_indeed}

\unexpanded\def\dohandlerevcolumnscs#1{\let\page_columns_action  #1\page_columns_rev_indeed}
\unexpanded\def\dohandlerevcolumns  #1{\def\page_columns_action{#1}\page_columns_rev_indeed}

\unexpanded\def\dohandlemidcolumnscs#1{\let\page_columns_action  #1\page_columns_mid_indeed}
\unexpanded\def\dohandlemidcolumns  #1{\def\page_columns_action{#1}\page_columns_mid_indeed}

\unexpanded\def\page_columns_all_indeed
  {\mofcolumns\plusone
   \edef\currentcolumn{\the\mofcolumns}%
   \page_columns_action\relax
   \ifnum\mofcolumns<\nofcolumns
     \expandafter\page_columns_all_next
   \fi}

\unexpanded\def\page_columns_all_next
  {\advance\mofcolumns\plusone
   \edef\currentcolumn{\the\mofcolumns}%
   \page_columns_action\relax
   \ifnum\mofcolumns<\nofcolumns
     \expandafter\page_columns_all_next
   \fi}

\unexpanded\def\page_columns_rev_indeed
  {\mofcolumns\nofcolumns
   \edef\currentcolumn{\the\mofcolumns}%
   \page_columns_action\relax
   \ifnum\mofcolumns>\plusone
     \expandafter\page_columns_rev_prev
   \fi}

\unexpanded\def\page_columns_rev_prev
  {\advance\mofcolumns\minusone
   \edef\currentcolumn{\the\mofcolumns}%
   \page_columns_action\relax
   \ifnum\mofcolumns>\plusone
     \expandafter\page_columns_rev_prev
   \fi}

\unexpanded\def\page_columns_mid_indeed
  {\mofcolumns\plustwo
   \ifnum\mofcolumns<\nofcolumns
     \expandafter\page_columns_mid_next
   \fi}

\unexpanded\def\page_columns_mid_next
  {\edef\currentcolumn{\the\mofcolumns}%
   \page_columns_action\relax
   \advance\mofcolumns\plusone
   \ifnum\mofcolumns<\nofcolumns
     \expandafter\page_columns_mid_next
   \fi}

\protect \endinput