summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/tabl-mis.mkxl
blob: 383ff22dd1c97a597df563a74c027382b13908fa (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
%D \module
%D   [       file=tabl-mis,
%D        version=2012.06.28,
%D          title=\CONTEXT\ Table Macros,
%D       subtitle=Miscellaneous,
%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 Table Macros / Miscellaneous}

\unprotect

%D \macros
%D   {somekindoftab,kindoftabposition}
%D
%D This macro can be used to create tabs:
%D
%D \starttyping
%D \setupheadertexts[{\somekindoftab[alternative=horizontal]{\framed{\kindoftabposition}}}]
%D \setuptexttexts  [{\somekindoftab[alternative=vertical]  {\framed{\kindoftabposition}}}]
%D
%D \starttext
%D     \showframe \dorecurse{10}{test\page}
%D \stoptext
%D \stoptyping
%D
%D (This rather old but updated code used to be in \type {core-mis.mkiv}.)

\mutable\let\kindoftabposition\!!zerocount

\permanent\tolerant\protected\def\somekindoftab[#1]%
  {\bgroup
   \getdummyparameters
     [\c!alternative=\v!vertical,
      \c!width=\textwidth,\c!height=\textheight,
      \c!n=\lastpage,\c!m=\realpageno,
      #1]%
   \doifelse{\directdummyparameter\c!alternative}\v!vertical
     {\typo_kindoftab_indeed\vbox\vskip\c!height}
     {\typo_kindoftab_indeed\hbox\hskip\c!width }}

\def\typo_kindoftab_indeed#1#2#3#4%
  {#1 to \directdummyparameter#3 \bgroup
     \forgetall
     \scratchnx\directdummyparameter\c!n\relax
     \scratchmx\directdummyparameter\c!m\relax
     \edef\kindoftabposition{\the\scratchmx}%
     \ifnum\scratchmx>\plusone
       #2\zeropoint \s!plus \the\numexpr\scratchmx-\plusone  \relax\s!fill\relax
     \fi
     #4% can use \kindoftabposition
     \ifnum\scratchmx<\scratchnx\relax
       #2\zeropoint \s!plus \the\numexpr\scratchnx-\scratchmx\relax\s!fill\relax
     \fi
   \egroup
   \egroup}

%D The following paragraphs mechanism is probably one of the oldest of \CONTEXT\ and
%D mostly served as a table mechanism capable of dealing with paragraphs. Nowadays
%D one can also use tabulate or natural tables.
%D
%D \startbuffer
%D \defineparagraphs[sample][n=2,rule=on]
%D
%D \startsample
%D     first  \nextsample
%D     second \nextsample
%D     third
%D \stopsample
%D
%D \startsample
%D     \input tufte \nextsample
%D     \input ward  \nextsample
%D     \input davis \nextsample
%D     \input zapf
%D \stopsample
%D
%D \startparagraphs[sample]
%D     first  \nextsample
%D     second \nextsample
%D     third
%D \stopparagraphs
%D
%D \startparagraphs[sample]
%D     \startparagraphscell
%D         first
%D     \stopparagraphscell
%D     \startparagraphscell
%D         second
%D     \stopparagraphscell
%D     \startparagraphscell
%D         third
%D     \stopparagraphscell
%D \stopparagraphs
%D \stopbuffer
%D
%D \typebuffer \getbuffer

\installcorenamespace{paragraphs}

\installframedcommandhandler \??paragraphs {paragraphs} \??paragraphs

\setupparagraphs
  [\c!n=3,
   \c!offset=\zeropoint,
   \c!before=\blank,
   \c!after=\blank,
   \c!distance=\emwidth,
   \c!height=\v!fit,
   \c!width=\availablehsize,
   \c!rule=\v!off,
   \c!command=,
   \c!align=,
   \c!tolerance=\v!tolerant, % obsolete
   \c!rulethickness=\linewidth,
   \c!rulecolor=,
   \c!style=,
   \c!color=,
   \c!frame=\v!off,
   \c!top=\vss,
   \c!bottom=\vfill]

\aliased\let\typo_paragraphs_setup_saved\setupparagraphs

\let\typo_paragraphs_setup_step\gobbleoneargument

\overloaded\permanent\tolerant\protected\def\setupparagraphs[#1]#*[#2]#*[#3]% we are downward compatible with [each] and [1,3]
  {\ifarguments\or
      \typo_paragraphs_setup_saved[#1]%
   \or
      \typo_paragraphs_setup_saved[#1][#2]%
   \or
     \doifelse{#2}\v!each
       {\dorecurse{\namedparagraphsparameter{#1}\c!n}%
          {\normalexpanded{\typo_paragraphs_setup_saved[#1:\recurselevel]}[#3]}}%
       {\def\typo_paragraphs_setup_step##1{\typo_paragraphs_setup_saved[#1:##1][#3]}%
        \processcommalist[#2]\typo_paragraphs_setup_step}%
   \fi}

\appendtoks
    \frozen\instance\letcsname\e!next\currentparagraphs\endcsname\nextparagraphs
    \frozen\instance\letcsname\currentparagraphs\endcsname\nextparagraphs
    \frozen\instance\protected\edefcsname\e!start\currentparagraphs\endcsname{\startparagraphs[\currentparagraphs]}%
    \frozen\instance\letcsname\e!stop\currentparagraphs\endcsname\stopparagraphs
    %frozen\instance\setuevalue{\e!setup\currentparagraph\e!endsetup}{\typo_paragraphs_setup_saved[\currentparagraphs]}%
    \dorecurse{\paragraphsparameter\c!n}%
      {\normalexpanded{\typo_paragraphs_setup_saved[\currentparagraphs:\recurselevel][\c!width=,\s!parent=\??paragraphs\currentparagraphs]}}%
    \typo_paragraphs_setup_saved[\currentparagraphs:1][\c!distance=\zeropoint]%
\to \everydefineparagraphs

\newinteger  \c_typo_paragraphs_n
\newinteger  \c_typo_paragraphs_max
\newdimension\d_typo_paragraphs_width
\newdimension\d_typo_paragraphs_auto

\let\typo_paragraphs_start_cell\relax
\let\typo_paragraphs_stop_cell \relax

\permanent\protected\def\startparagraphs[#1]% quite slow
  {\bgroup % (1)
   \cdef\currentparagraphs{#1}%
 % \paragraphsparameter\c!before
   \edef\p_width{\paragraphsparameter\c!width}%
   \ifempty\p_width
     \d_typo_paragraphs_width\availablehsize
   \else
     \d_typo_paragraphs_width\p_width\relax
   \fi
   \advanceby\d_typo_paragraphs_width-2\dimexpr\paragraphsparameter\c!offset\relax
   \c_typo_paragraphs_max\paragraphsparameter\c!n\relax
   \d_typo_paragraphs_auto\d_typo_paragraphs_width\relax
   \scratchcounter\zerocount
   \dorecurse\c_typo_paragraphs_max
     {\edef\p_width{\namedparagraphsparameter{\currentparagraphs:\recurselevel}\c!width}%
      \ifempty\p_width
        \advanceby\scratchcounter\plusone
      \else
        \advanceby\d_typo_paragraphs_auto-\p_width\relax
      \fi
      \ifnum\recurselevel>\plusone
        \advanceby\d_typo_paragraphs_auto-\namedparagraphsparameter{\currentparagraphs:\recurselevel}\c!distance\relax
      \fi}%
   \ifnum\scratchcounter>\zerocount
     \divideby\d_typo_paragraphs_auto\scratchcounter
   \else
     \d_typo_paragraphs_auto\zeropoint
   \fi
   \parindent\zeropoint
   \c_typo_paragraphs_n\zerocount
   \enforced\let\\\nextparagraphs % downward compatible
   \edef\p_offset{\paragraphsparameter\c!offset}%
   \doifelsedimension\p_offset
     {\scratchoffset\p_offset}%
     {\scratchoffset\zeropoint}%
   \setbox\scratchbox\hpack
   \bgroup % (2)
   \forgetall
   \advanceby\hsize-2\scratchoffset
   \let\typo_paragraphs_start_cell\typo_paragraphs_start_cell_indeed
   \let\typo_paragraphs_stop_cell \typo_paragraphs_stop_cell_indeed
   \typo_paragraphs_start_cell_indeed}

\permanent\protected\def\stopparagraphs
  {\stopparagraphscell
   \egroup  % (2)
   \letparagraphsparameter\c!align\v!flushleft % normal
   \paragraphsparameter\c!before
   \dontleavehmode\inheritedparagraphsframed{\box\scratchbox}%
   \paragraphsparameter\c!after
   \egroup} % (1)

\permanent\protected\def\nextparagraphs
  {\stopparagraphscell
   \startparagraphscell}

\permanent\protected\def\startparagraphscell
  {\typo_paragraphs_start_cell}

\def\typo_paragraphs_start_cell_indeed
  {\removeunwantedspaces
   \advanceby\c_typo_paragraphs_n\plusone
   \ifnum\c_typo_paragraphs_n>\c_typo_paragraphs_max
     \expandafter\typo_paragraphs_start_cell_nop
   \else
     \expandafter\typo_paragraphs_start_cell_yes
   \fi}

\def\typo_paragraphs_start_cell_nop
  {\begingroup
   % message: too many cells in paragraphs
   \let\typo_paragraphs_start_cell\relax
   \let\typo_paragraphs_stop_cell\typo_paragraphs_stop_cell_indeed
   \setbox\scratchbox\vbox\bgroup}

\def\typo_paragraphs_start_cell_yes
  {\begingroup
   \let\typo_paragraphs_start_cell\relax
   \let\typo_paragraphs_stop_cell\typo_paragraphs_stop_cell_indeed
   \cdef\currentparagraphs{\currentparagraphs:\the\c_typo_paragraphs_n}%
   \ifnum\c_typo_paragraphs_n>\plusone
     \typo_paragraphs_separator
   \fi
   \edef\p_height{\paragraphsparameter\c!height}%
   \edef\p_width {\paragraphsparameter\c!width }%
   \useparagraphsstyleandcolor\c!style\c!color
   \setbox\scratchbox\vtop \ifempty\p_height \orelse\ifx\p_height\v!fit \else to \p_height \fi
   \bgroup % (2)
   \blank[\v!disable]%
   \paragraphsparameter\c!top
   \hsize\ifempty\p_width \d_typo_paragraphs_auto \else \p_width \fi \relax
   \usealignparameter\paragraphsparameter
   \paragraphsparameter\c!inner
   \everypar{\begstrut\everypar\emptytoks}%
   \ignorespaces
   \paragraphsparameter\c!command}

\permanent\protected\def\stopparagraphscell
  {\typo_paragraphs_stop_cell
   \let\typo_paragraphs_stop_cell\relax}

\def\typo_paragraphs_stop_cell_indeed
  {\ifnum\c_typo_paragraphs_n>\c_typo_paragraphs_max
     \expandafter\typo_paragraphs_stop_cell_nop
   \else
     \expandafter\typo_paragraphs_stop_cell_yes
   \fi}

\def\typo_paragraphs_stop_cell_nop
  {\egroup
   \endgroup}

\def\typo_paragraphs_stop_cell_yes
  {\ifvmode
     \removelastskip
   \else
     \removeunwantedspaces
     \endstrut
     \endgraf
   \fi
   \paragraphsparameter\c!bottom
   \egroup % (2)
   \dontleavehmode\hpack{\raise\strutheight\box\scratchbox}%
   \endgroup}

\def\typo_paragraphs_separator
  {\scratchdistance\paragraphsparameter\c!distance
   \doif{\paragraphsparameter\c!rule}\v!on
     {\scratchwidth\paragraphsparameter\c!rulethickness
      \scratchdistance\dimexpr(\scratchdistance-\scratchwidth)/2\relax
      \hskip\scratchdistance
      \color[\paragraphsparameter\c!rulecolor]{\vrule\s!width\scratchwidth}}%
   \hskip\scratchdistance}

\protect \endinput