tabl-mis.mkxl /size: 9745 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=tabl-mis,
3%D        version=2012.06.28,
4%D          title=\CONTEXT\ Table Macros,
5%D       subtitle=Miscellaneous,
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 Table Macros / Miscellaneous}
15
16\unprotect
17
18%D \macros
19%D   {somekindoftab,kindoftabposition}
20%D
21%D This macro can be used to create tabs:
22%D
23%D \starttyping
24%D \setupheadertexts[{\somekindoftab[alternative=horizontal]{\framed{\kindoftabposition}}}]
25%D \setuptexttexts  [{\somekindoftab[alternative=vertical]  {\framed{\kindoftabposition}}}]
26%D
27%D \starttext
28%D     \showframe \dorecurse{10}{test\page}
29%D \stoptext
30%D \stoptyping
31%D
32%D (This rather old but updated code used to be in \type {core-mis.mkiv}.)
33
34\mutable\let\kindoftabposition\!!zerocount
35
36\permanent\tolerant\protected\def\somekindoftab[#S#1]%
37  {\bgroup
38   \getdummyparameters
39     [\c!alternative=\v!vertical,
40      \c!width=\textwidth,\c!height=\textheight,
41      \c!n=\lastpage,\c!m=\realpageno,
42      #1]%
43   \ifcstok{\directdummyparameter\c!alternative}\v!vertical
44     \expandafter\typo_kindoftab_indeed_v
45   \else
46     \expandafter\typo_kindoftab_indeed_h
47   \fi}
48
49\def\typo_kindoftab_indeed_v{\typo_kindoftab_indeed\vbox\vskip\c!height}
50\def\typo_kindoftab_indeed_h{\typo_kindoftab_indeed\hbox\hskip\c!width }
51
52\def\typo_kindoftab_indeed#1#2#3#4%
53  {#1 to \directdummyparameter#3 \bgroup
54     \forgetall
55     \scratchnx\directdummyparameter\c!n\relax
56     \scratchmx\directdummyparameter\c!m\relax
57     \edef\kindoftabposition{\the\scratchmx}%
58     \ifnum\scratchmx>\plusone
59       #2\zeropoint \s!plus \the\numexpr\scratchmx-\plusone  \relax\s!fill\relax
60     \fi
61     #4% can use \kindoftabposition
62     \ifnum\scratchmx<\scratchnx\relax
63       #2\zeropoint \s!plus \the\numexpr\scratchnx-\scratchmx\relax\s!fill\relax
64     \fi
65   \egroup
66   \egroup}
67
68%D The following paragraphs mechanism is probably one of the oldest of \CONTEXT\ and
69%D mostly served as a table mechanism capable of dealing with paragraphs. Nowadays
70%D one can also use tabulate or natural tables.
71%D
72%D \startbuffer
73%D \defineparagraphs[sample][n=2,rule=on]
74%D
75%D \startsample
76%D     first  \nextsample
77%D     second \nextsample
78%D     third
79%D \stopsample
80%D
81%D \startsample
82%D     \input tufte \nextsample
83%D     \input ward  \nextsample
84%D     \input davis \nextsample
85%D     \input zapf
86%D \stopsample
87%D
88%D \startparagraphs[sample]
89%D     first  \nextsample
90%D     second \nextsample
91%D     third
92%D \stopparagraphs
93%D
94%D \startparagraphs[sample]
95%D     \startparagraphscell
96%D         first
97%D     \stopparagraphscell
98%D     \startparagraphscell
99%D         second
100%D     \stopparagraphscell
101%D     \startparagraphscell
102%D         third
103%D     \stopparagraphscell
104%D \stopparagraphs
105%D \stopbuffer
106%D
107%D \typebuffer \getbuffer
108
109\installcorenamespace{paragraphs}
110
111\installframedcommandhandler \??paragraphs {paragraphs} \??paragraphs
112
113\setupparagraphs
114  [\c!n=3,
115   \c!offset=\zeropoint,
116   \c!before=\blank,
117   \c!after=\blank,
118   \c!distance=\emwidth,
119   \c!height=\v!fit,
120   \c!width=\availablehsize,
121   \c!rule=\v!off,
122   \c!command=,
123   \c!align=,
124   \c!tolerance=\v!tolerant, % obsolete
125   \c!rulethickness=\linewidth,
126   \c!rulecolor=,
127   \c!style=,
128   \c!color=,
129   \c!frame=\v!off,
130   \c!top=\vss,
131   \c!bottom=\vfill]
132
133\aliased\let\typo_paragraphs_setup_saved\setupparagraphs
134
135\let\typo_paragraphs_setup_step\gobbleoneargument
136
137\overloaded\permanent\tolerant\protected\def\setupparagraphs[#S#1]#*[#S#2]#*[#S#3]% we are downward compatible with [each] and [1,3]
138  {\ifarguments\or
139      \typo_paragraphs_setup_saved[#1]%
140   \or
141      \typo_paragraphs_setup_saved[#1][#2]%
142   \or
143     \ifcstok{#2}\v!each
144       \localcontrolledrepeat \namedparagraphsparameter{#1}\c!n
145         {\normalexpanded{\typo_paragraphs_setup_saved[#1:\the\currentloopiterator]}[#3]}%
146     \else
147       \def\typo_paragraphs_setup_step##1{\typo_paragraphs_setup_saved[#1:##1][#3]}%
148       \processcommalist[#2]\typo_paragraphs_setup_step
149     \fi
150   \fi}
151
152\appendtoks
153    \frozen\instance\letcsname\e!next\currentparagraphs\endcsname\nextparagraphs
154    \frozen\instance\letcsname\currentparagraphs\endcsname\nextparagraphs
155    \frozen\instance\protected\edefcsname\e!start\currentparagraphs\endcsname{\startparagraphs[\currentparagraphs]}%
156    \frozen\instance\letcsname\e!stop\currentparagraphs\endcsname\stopparagraphs
157    \localcontrolledrepeat \paragraphsparameter\c!n
158      {\normalexpanded
159         {\typo_paragraphs_setup_saved
160            [\currentparagraphs:\the\currentloopiterator]%
161            [\c!width=,\s!parent=\??paragraphs\currentparagraphs]}}%
162    \typo_paragraphs_setup_saved[\currentparagraphs:1][\c!distance=\zeropoint]%
163\to \everydefineparagraphs
164
165\newinteger  \c_typo_paragraphs_n
166\newinteger  \c_typo_paragraphs_max
167\newdimension\d_typo_paragraphs_width
168\newdimension\d_typo_paragraphs_auto
169
170\let\typo_paragraphs_start_cell\relax
171\let\typo_paragraphs_stop_cell \relax
172
173\permanent\protected\def\startparagraphs[#1]% quite slow
174  {\bgroup % (1)
175   \cdef\currentparagraphs{#1}%
176 % \paragraphsparameter\c!before
177   \edef\p_width{\paragraphsparameter\c!width}%
178   \ifempty\p_width
179     \d_typo_paragraphs_width\availablehsize
180   \else
181     \d_typo_paragraphs_width\p_width\relax
182   \fi
183   \advanceby\d_typo_paragraphs_width-2\dimexpr\paragraphsparameter\c!offset\relax
184   \c_typo_paragraphs_max\paragraphsparameter\c!n\relax
185   \d_typo_paragraphs_auto\d_typo_paragraphs_width\relax
186   \scratchcounter\zerocount
187   \localcontrolledrepeat \c_typo_paragraphs_max
188     {\edef\p_width{\namedparagraphsparameter{\currentparagraphs:\the\currentloopiterator}\c!width}%
189      \ifempty\p_width
190        \advanceby\scratchcounter\plusone
191      \else
192        \advanceby\d_typo_paragraphs_auto-\p_width\relax
193      \fi
194      \ifnum\currentloopiterator>\plusone
195        \advanceby\d_typo_paragraphs_auto-\namedparagraphsparameter{\currentparagraphs:\number\currentloopiterator}\c!distance\relax
196      \fi}%
197   \ifnum\scratchcounter>\zerocount
198     \divideby\d_typo_paragraphs_auto\scratchcounter
199   \else
200     \d_typo_paragraphs_auto\zeropoint
201   \fi
202   \parindent\zeropoint
203   \c_typo_paragraphs_n\zerocount
204   \enforced\let\\\nextparagraphs % downward compatible
205   \edef\p_offset{\paragraphsparameter\c!offset}%
206   \doifelsedimension\p_offset
207     {\scratchoffset\p_offset}%
208     {\scratchoffset\zeropoint}%
209   \setbox\scratchbox\hpack
210   \bgroup % (2)
211   \forgetall
212   \advanceby\hsize-2\scratchoffset
213   \let\typo_paragraphs_start_cell\typo_paragraphs_start_cell_indeed
214   \let\typo_paragraphs_stop_cell \typo_paragraphs_stop_cell_indeed
215   \typo_paragraphs_start_cell_indeed}
216
217\permanent\protected\def\stopparagraphs
218  {\stopparagraphscell
219   \egroup  % (2)
220   \letparagraphsparameter\c!align\v!flushleft % normal
221   \paragraphsparameter\c!before
222   \dontleavehmode\inheritedparagraphsframed{\box\scratchbox}%
223   \paragraphsparameter\c!after
224   \egroup} % (1)
225
226\permanent\protected\def\nextparagraphs
227  {\stopparagraphscell
228   \startparagraphscell}
229
230\permanent\protected\def\startparagraphscell
231  {\typo_paragraphs_start_cell}
232
233\def\typo_paragraphs_start_cell_indeed
234  {\removeunwantedspaces
235   \advanceby\c_typo_paragraphs_n\plusone
236   \ifnum\c_typo_paragraphs_n>\c_typo_paragraphs_max
237     \expandafter\typo_paragraphs_start_cell_nop
238   \else
239     \expandafter\typo_paragraphs_start_cell_yes
240   \fi}
241
242\def\typo_paragraphs_start_cell_nop
243  {\begingroup
244   % message: too many cells in paragraphs
245   \let\typo_paragraphs_start_cell\relax
246   \let\typo_paragraphs_stop_cell\typo_paragraphs_stop_cell_indeed
247   \setbox\scratchbox\vbox\bgroup}
248
249\def\typo_paragraphs_start_cell_yes
250  {\begingroup
251   \let\typo_paragraphs_start_cell\relax
252   \let\typo_paragraphs_stop_cell\typo_paragraphs_stop_cell_indeed
253   \cdef\currentparagraphs{\currentparagraphs:\the\c_typo_paragraphs_n}%
254   \ifnum\c_typo_paragraphs_n>\plusone
255     \typo_paragraphs_separator
256   \fi
257   \edef\p_height{\paragraphsparameter\c!height}%
258   \edef\p_width {\paragraphsparameter\c!width }%
259   \useparagraphsstyleandcolor\c!style\c!color
260   \setbox\scratchbox\vtop \ifempty\p_height \orelse\ifx\p_height\v!fit \else to \p_height \fi
261   \bgroup % (2)
262   \blank[\v!disable]%
263   \paragraphsparameter\c!top
264   \hsize\ifempty\p_width \d_typo_paragraphs_auto \else \p_width \fi \relax
265   \usealignparameter\paragraphsparameter
266   \paragraphsparameter\c!inner
267   \everypar{\begstrut\everypar\emptytoks}%
268   \ignorespaces
269   \paragraphsparameter\c!command}
270
271\permanent\protected\def\stopparagraphscell
272  {\typo_paragraphs_stop_cell
273   \let\typo_paragraphs_stop_cell\relax}
274
275\def\typo_paragraphs_stop_cell_indeed
276  {\ifnum\c_typo_paragraphs_n>\c_typo_paragraphs_max
277     \expandafter\typo_paragraphs_stop_cell_nop
278   \else
279     \expandafter\typo_paragraphs_stop_cell_yes
280   \fi}
281
282\def\typo_paragraphs_stop_cell_nop
283  {\egroup
284   \endgroup}
285
286\def\typo_paragraphs_stop_cell_yes
287  {\ifvmode
288     \removelastskip
289   \else
290     \removeunwantedspaces
291     \endstrut
292     \endgraf
293   \fi
294   \paragraphsparameter\c!bottom
295   \egroup % (2)
296   \dontleavehmode\hpack{\raise\strutheight\box\scratchbox}%
297   \endgroup}
298
299\def\typo_paragraphs_separator
300  {\scratchdistance\paragraphsparameter\c!distance
301   \ifcstok{\paragraphsparameter\c!rule}\v!on
302     \scratchwidth\paragraphsparameter\c!rulethickness
303     \scratchdistance\dimexpr(\scratchdistance-\scratchwidth)/2\relax
304     \hskip\scratchdistance
305     \color[\paragraphsparameter\c!rulecolor]{\vrule\s!width\scratchwidth}%
306   \fi
307   \hskip\scratchdistance}
308
309\protect \endinput
310