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