1
2
3
4
5
6
7
8
9
10
11
12
13
14
15\writestatus{loading}{ConTeXt Spacing Macros Column Swapping}
16
17\registerctxluafile{typoswp}{autosuffix}
18
19\unprotect
20
21\installcorenamespace {rows}
22
23\installcommandhandler \??rows {rows} \??rows
24
25\definesystemattribute[swapping][global,public]
26
27\setuprows
28 [\c!n=2,
29
30
31
32
33 \c!before=,
34 \c!after=,
35 \c!order=\v!vertical,
36 \c!distance=2\emwidth]
37
38\newinteger\c_swapping_index
39
40\appendtoks
41 \ifcstok{\rowsparameter\c!define}\v!yes
42 \frozen\protected\instance\edefcsname\e!start\currentrows\endcsname{\startrows[\currentrows]}
43 \frozen\protected\instance\defcsname \e!stop \currentrows\endcsname{\stoprows}
44 \fi
45\to \everydefinerows
46
47\permanent\tolerant\protected\def\startrows[#1]#*[#2]
48 {\begingroup
49 \clf_enableswapping
50 \ifhastok={#1}
51 \setupcurrentrows[#1]
52 \orelse\ifparameter#1\or
53 \cdef\currentrows{#1}
54 \ifparameter#2\or
55 \setupcurrentrows[#2]
56 \fi
57 \fi
58 \scratchcountertwo{\rowsparameter\c!n}
59 \scratchdistance{\rowsparameter\c!distance}
60 \setbox\scratchboxone\vbox\bgroup
61 \holdingmigrations\maxcount
62 \ifempty{\rowsparameter\c!width}
63
64 \orelse\ifcstok{\lastnamedcs}\v!fit
65 \hsize\distributedhsize\hsize\scratchdistance\scratchcountertwo
66 \usealignparameter\rowsparameter
67 \orelse\ifchkdimexpr\lastnamedcs\or
68 \hsize{\lastchkdimension}
69 \usealignparameter\rowsparameter
70 \fi}
71
72\permanent\protected\def\stoprows
73 {\egroup
74 \ifvoid\scratchboxone\else
75 \rowsparameter\c!before
76 \forgetall
77 \scratchwidth{
78 \ifcstok{\rowsparameter\c!alternative}\v!tight
79 \zeropoint
80 \orelse\ifcstok{\rowsparameter\c!width}\v!fit
81 \zeropoint
82 \else
83 \hsize\scratchcountertwo
84 \fi
85 }
86 \scratchcounterone{
87 \ifcstok{\rowsparameter\c!order}\v!vertical
88 \c_swapping_index * "10000
89 \scratchcountertwo
90 \else
91 \attributeunsetvalue
92 \fi
93 }
94 \global\advance\c_swapping_index\plusone
95 \ifempty{\rowsparameter\c!height}
96 \scratchheight\zeropoint
97 \orelse\ifcstok{\lastnamedcs}\v!max
98 \scratchheight\boxlinemaxht\scratchboxone\relax
99 \ifdim\scratchheight<\strutht
100 \scratchheight\zeropoint
101 \fi
102 \orelse\ifchkdimexpr\lastnamedcs\or
103 \scratchheight\lastchkdimension
104 \else
105 \scratchheight\zeropoint
106 \fi
107 \ifempty{\rowsparameter\c!depth}
108 \scratchheight\zeropoint
109 \orelse\ifcstok{\lastnamedcs}\v!max
110 \scratchdepth\boxlinemaxdp\scratchboxone\relax
111 \ifdim\scratchdepth<\strutdp
112 \scratchdepth\zeropoint
113 \fi
114 \orelse\ifchkdimexpr\lastnamedcs\or
115 \scratchdepth\lastchkdimension
116 \else
117 \scratchdepth\zeropoint
118 \fi
119 \dorecurse {\boxlines \scratchboxone} {
120 \ifzero\scratchheight\else
121 \boxlineht\scratchboxone ##1 \scratchheight
122 \fi
123 \ifzero\scratchdepth\else
124 \boxlinedp\scratchboxone ##1 \scratchdepth
125 \fi
126 \ifnum##1=\plusone
127 \dontleavehmode
128 \hbox \bgroup
129 \global\globalscratchcounterone\plustwo
130 \orelse\ifnum\globalscratchcounterone>\scratchcountertwo
131 \boundary\zerocount
132 \egroup\par
133 \dontleavehmode
134 \hbox \bgroup
135 \global\globalscratchcounterone\plustwo
136 \else
137 \global\advance\globalscratchcounterone\plusone
138 \fi
139 \ifzero\scratchwidth
140 \ifnum\globalscratchcounterone>\plustwo
141 \hskip\scratchdistance
142 \fi
143
144 \setbox\scratchbox\boxline \scratchboxone ##1\relax
145 \boxmigrate\scratchbox\maxcount
146 \ifnum\scratchcounterone=\attributeunsetvalue
147 \box\scratchbox
148 \else
149 \boxattribute \scratchbox \swappingattribute \scratchcounterone
150 \boundary\zerocount
151 \box\scratchbox
152 \boundary\zerocount
153 \fi
154 \else
155
156 \setbox\scratchbox\hpack \s!to \scratchwidth \bgroup
157 \boxline \scratchboxone ##1\relax
158 \hss
159 \egroup
160 \boxmigrate\scratchbox\maxcount
161 \ifnum\scratchcounterone=\attributeunsetvalue
162 \box\scratchbox
163 \else
164 \boxattribute \scratchbox \swappingattribute \scratchcounterone
165 \boundary\zerocount
166 \box\scratchbox
167 \boundary\zerocount
168 \fi
169 \fi
170 }
171 \ifnum\globalscratchcounterone>\plusone
172 \ifnum\scratchcounterone=\attributeunsetvalue
173
174 \else
175
176 \dostepwiserecurse {\globalscratchcounterone} \scratchcountertwo {\plusone} {
177 \ifzero\scratchwidth
178 \hskip{\rowsparameter\c!distance}
179 \fi
180 \hpack \s!attr \swappingattribute \scratchcounterone \bgroup
181 \null
182 \egroup
183 \boundary\zerocount}
184 \fi
185 \hss
186 \egroup\par
187 \fi
188 \rowsparameter\c!after
189 \fi
190 \endgroup}
191
192\protect
193 |