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