spac-flr.mkxl /size: 5742 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=spac-fil,
3%D        version=2013.01.13,
4%D          title=\CONTEXT\ Spacing Macros,
5%D       subtitle=Fillers,
6%D         author={Hans Hagen and Wolfgang Schuster},
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 Spacing Macros / Fillers}
15
16\unprotect
17
18%D A bit more extensive variant of a prototype posted by Wolfgang to the development
19%D list. Instead of dealing with a few leader types it makes sense to support them
20%D all as well as simple rule fillers. Eventually we can also use in for the
21%D mathfillers. We distinguish between alternatives and with them methods, and a
22%D checker is provided for use in applying e.g.\ fillers in lists.
23
24\installcorenamespace{filler}
25\installcorenamespace{filleralternative}
26\installcorenamespace{fillerleadermethod}
27
28\installcommandhandler \??filler {filler} \??filler
29
30\aliased\let\setupfillers\setupfiller
31
32\permanent\protected\def\checkedfiller#1%
33  {\ifcsname\namedfillerhash{#1}\s!parent\endcsname
34     \filler[#1]%
35     \expandafter\gobbleoneargument
36   \else
37     \expandafter\firstofoneargument
38   \fi{#1}}
39
40\permanent\tolerant\protected\def\filler[#1]%
41  {\removeunwantedspaces
42   \begingroup
43   \cdef\currentfiller{#1}%
44   \usefillerstyleandcolor\c!style\c!color
45   \scratchdimen\fillerparameter\c!leftmargin\relax
46   \ifzeropt\scratchdimen\else
47     \hskip\scratchdimen
48   \fi
49   \fillerparameter\c!left\relax
50   \expandnamespaceparameter\??filleralternative\fillerparameter\c!alternative\s!unknown\relax
51   \fillerparameter\c!right\relax
52   \scratchdimen\fillerparameter\c!rightmargin\relax
53   \ifzeropt\scratchdimen\else
54     \hskip\scratchdimen
55   \fi
56   \endgroup
57   \ignorespaces}
58
59% \definefiller
60%   [MyFiller]
61%   [offset=.25\emwidth,
62%    rightmargindistance=-\rightskip,
63%    method=middle]
64%
65% \startitemize[packed,joinedup][rightmargin=5em]
66%     \startitem
67%         \input sapolsky \fillupto[MyFiller]{RS}
68%     \stopitem
69% \stopitemize
70
71\permanent\tolerant\protected\def\fillupto[#1]#:#2%
72  {\removeunwantedspaces
73   \begingroup
74   \cdef\currentfiller{#1}%
75   \scratchdimen\dimexpr\fillerparameter\c!rightmargindistance\relax
76   \ifzeropt\scratchdimen\else
77     \parfillskip \scratchdimen\s!plus \plusone\s!fil\relax
78   \fi
79   \filler[#1]%
80   \ifempty{#2}\else
81     \hbox{#2}%
82   \fi
83   \par
84   \endgroup
85   \ignorespaces}
86
87\defcsname\??filleralternative\s!unknown\endcsname
88  {}
89
90\defcsname\??filleralternative\v!symbol\endcsname
91  {\expandnamespaceparameter\??fillerleadermethod\fillerparameter\c!method\v!local
92     \ifdim\fillerparameter\c!offset>\zeropoint
93        \simplealignedspreadbox
94          {2\dimexpr\fillerparameter\c!offset\relax}%
95          {\fillerparameter\c!align}%
96          {\fillerparameter\c!symbol}%
97     \else
98        \simplealignedbox
99          {\fillerparameter\c!width}%
100          {\fillerparameter\c!align}%
101          {\fillerparameter\c!symbol}%
102     \fi
103   \hfill}
104
105\defcsname\??filleralternative\v!stretch\endcsname
106  {\hfill}
107
108\defcsname\??filleralternative\v!space\endcsname
109  {\hskip\fillerparameter\c!distance\relax}
110
111\defcsname\??filleralternative\v!rule\endcsname
112  {\expandnamespaceparameter\??fillerleadermethod\fillerparameter\c!method\v!local
113     \hrule
114       \s!height\fillerparameter\c!height
115       \s!depth \fillerparameter\c!depth
116   \hfill}
117
118\letcsname\??fillerleadermethod\s!local \endcsname\normalleaders  % overflow ends up inbetween (current box)
119\letcsname\??fillerleadermethod\v!global\endcsname\normalgleaders % overflow ends up inbetween (outermost box)
120\letcsname\??fillerleadermethod\v!middle\endcsname\normalcleaders % overflow ends up before, after (current box)
121\letcsname\??fillerleadermethod\v!broad \endcsname\normalxleaders % overflow ends up before, inbetween, after (current box)
122
123\setupfillers
124  [\c!width=\emwidth,
125   \c!symbol=.,
126   \c!distance=\emwidth,
127   \c!offset=\zeropoint,
128   \c!align=\v!middle,
129   \c!height=.1\exheight,
130   \c!depth=\zeropoint,
131   \c!leftmargin=\zeropoint,
132   \c!rightmargin=\zeropoint,
133   \c!rightmargindistance=\zeropoint,
134   \c!alternative=\v!symbol,
135   \c!method=\s!local]
136
137\definefiller
138  [\v!sym]
139  [\c!method=\v!global,
140   \c!width=.5\emwidth,
141   \c!leftmargin=.5\emwidth,
142   \c!rightmargin=.5\emwidth]
143
144\definefiller
145  [\v!symbol]
146  [\c!method=\v!global,
147   \c!offset=.125\emwidth,
148   \c!leftmargin=.5\emwidth,
149   \c!rightmargin=.5\emwidth]
150
151\definefiller
152  [\v!rule]
153  [\c!alternative=\v!rule,
154   \c!leftmargin=.5\emwidth,
155   \c!rightmargin=.5\emwidth]
156
157\definefiller
158  [\v!width]
159  [\c!alternative=\v!stretch]
160
161\definefiller
162  [\v!space]
163  [\c!alternative=\v!space,
164   \c!distance=3\emwidth]
165
166% bonus:
167
168\definefiller
169  [dotfill]
170  [\c!symbol=\textperiod,
171   \c!style=\v!normal,
172   \c!method=\v!middle,
173   \c!width=.5\emwidth,
174   \c!leftmargin=.2\emwidth,
175   \c!rightmargin=.2\emwidth]
176
177% If users really want it:
178%
179% \permanent\protected\def\mathdotfill{\cleaders\hbox{$\mathsurround\zeropoint\mkern1.5mu.\mkern1.5mu$}\hfill} % plain
180% \permanent\protected\def\textdotfill{\filler[dotfill]}
181% \permanent\protected\def\dotfill    {\mathortext\mathdotfill\textdotfill}
182
183\permanent\protected\def\dotfill{\filler[dotfill]}
184
185% maybe box -> symbol
186
187\protect \endinput
188
189% \definefiller[test-a][alternative=stretch]
190% \definefiller[test-b][alternative=symbol,symbol=!]
191% \definefiller[test-c][alternative=rule,height=.1ex,leftmargin=.5em,rightmargin=.25em]
192
193% \starttext
194%     text\filler[test-a]text \par
195%     text\filler[test-b]text \par
196%     text\filler[test-c]text \par
197%     text\checkedfiller{<nothing>}text \par
198% \stoptext
199