summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/spac-flr.mkxl
blob: e6147facd9025debd6c9bb34061a21f9f68deb72 (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
%D \module
%D   [       file=spac-fil,
%D        version=2013.01.13,
%D          title=\CONTEXT\ Spacing Macros,
%D       subtitle=Fillers,
%D         author={Hans Hagen and Wolfgang Schuster},
%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 Spacing Macros / Fillers}

\unprotect

%D A bit more extensive variant of a prototype posted by Wolfgang to the development
%D list. Instead of dealing with a few leader types it makes sense to support them
%D all as well as simple rule fillers. Eventually we can also use in for the
%D mathfillers. We distinguish between alternatives and with them methods, and a
%D checker is provided for use in applying e.g.\ fillers in lists.

\installcorenamespace{filler}
\installcorenamespace{filleralternative}
\installcorenamespace{fillerleadermethod}

\installcommandhandler \??filler {filler} \??filler

\aliased\let\setupfillers\setupfiller

\permanent\protected\def\checkedfiller#1%
  {\ifcsname\namedfillerhash{#1}\s!parent\endcsname
     \filler[#1]%
     \expandafter\gobbleoneargument
   \else
     \expandafter\firstofoneargument
   \fi{#1}}

\permanent\tolerant\protected\def\filler[#1]%
  {\removeunwantedspaces
   \begingroup
   \edef\currentfiller{#1}%
   \usefillerstyleandcolor\c!style\c!color
   \scratchdimen\fillerparameter\c!leftmargin\relax
   \ifzeropt\scratchdimen\else
     \hskip\scratchdimen
   \fi
   \fillerparameter\c!left\relax
   \expandnamespaceparameter\??filleralternative\fillerparameter\c!alternative\s!unknown\relax
   \fillerparameter\c!right\relax
   \scratchdimen\fillerparameter\c!rightmargin\relax
   \ifzeropt\scratchdimen\else
     \hskip\scratchdimen
   \fi
   \endgroup
   \ignorespaces}

% \definefiller
%   [MyFiller]
%   [offset=.25\emwidth,
%    rightmargindistance=-\rightskip,
%    method=middle]
%
% \startitemize[packed,joinedup][rightmargin=5em]
%     \startitem
%         \input sapolsky \fillupto[MyFiller]{RS}
%     \stopitem
% \stopitemize

\permanent\tolerant\protected\def\fillupto[#1]#:#2%
  {\removeunwantedspaces
   \begingroup
   \edef\currentfiller{#1}%
   \scratchdimen\dimexpr\fillerparameter\c!rightmargindistance\relax
   \ifzeropt\scratchdimen\else
     \parfillskip \scratchdimen\s!plus \plusone\s!fil\relax
   \fi
   \filler[#1]%
   \doifsomething{#2}{\hbox{#2}}%
   \par
   \endgroup
   \ignorespaces}

\defcsname\??filleralternative\s!unknown\endcsname
  {}

\defcsname\??filleralternative\v!symbol\endcsname
  {\expandnamespaceparameter\??fillerleadermethod\fillerparameter\c!method\v!local
     \ifdim\fillerparameter\c!offset>\zeropoint
        \simplealignedspreadbox
          {2\dimexpr\fillerparameter\c!offset\relax}%
          {\fillerparameter\c!align}%
          {\fillerparameter\c!symbol}%
     \else
        \simplealignedbox
          {\fillerparameter\c!width}%
          {\fillerparameter\c!align}%
          {\fillerparameter\c!symbol}%
     \fi
   \hfill}

\defcsname\??filleralternative\v!stretch\endcsname
  {\hfill}

\defcsname\??filleralternative\v!space\endcsname
  {\hskip\fillerparameter\c!distance\relax}

\defcsname\??filleralternative\v!rule\endcsname
  {\expandnamespaceparameter\??fillerleadermethod\fillerparameter\c!method\v!local
     \hrule
       \s!height\fillerparameter\c!height
       \s!depth \fillerparameter\c!depth
   \hfill}

\letcsname\??fillerleadermethod\s!local \endcsname\normalleaders  % overflow ends up inbetween (current box)
\letcsname\??fillerleadermethod\v!global\endcsname\normalgleaders % overflow ends up inbetween (outermost box)
\letcsname\??fillerleadermethod\v!middle\endcsname\normalcleaders % overflow ends up before, after (current box)
\letcsname\??fillerleadermethod\v!broad \endcsname\normalxleaders % overflow ends up before, inbetween, after (current box)

\setupfillers
  [\c!width=\emwidth,
   \c!symbol=.,
   \c!distance=\emwidth,
   \c!offset=\zeropoint,
   \c!align=\v!middle,
   \c!height=.1\exheight,
   \c!depth=\zeropoint,
   \c!leftmargin=\zeropoint,
   \c!rightmargin=\zeropoint,
   \c!rightmargindistance=\zeropoint,
   \c!alternative=\v!symbol,
   \c!method=\s!local]

\definefiller
  [\v!sym]
  [\c!method=\v!global,
   \c!width=.5\emwidth,
   \c!leftmargin=.5\emwidth,
   \c!rightmargin=.5\emwidth]

\definefiller
  [\v!symbol]
  [\c!method=\v!global,
   \c!offset=.125\emwidth,
   \c!leftmargin=.5\emwidth,
   \c!rightmargin=.5\emwidth]

\definefiller
  [\v!rule]
  [\c!alternative=\v!rule,
   \c!leftmargin=.5\emwidth,
   \c!rightmargin=.5\emwidth]

\definefiller
  [\v!width]
  [\c!alternative=\v!stretch]

\definefiller
  [\v!space]
  [\c!alternative=\v!space,
   \c!distance=3\emwidth]

% bonus:

\definefiller
  [dotfill]
  [\c!symbol=\textperiod,
   \c!style=\v!normal,
   \c!method=\v!middle,
   \c!width=.5\emwidth,
   \c!leftmargin=.2\emwidth,
   \c!rightmargin=.2\emwidth]

% If users really want it:
%
% \permanent\protected\def\mathdotfill{\cleaders\hbox{$\mathsurround\zeropoint\mkern1.5mu.\mkern1.5mu$}\hfill} % plain
% \permanent\protected\def\textdotfill{\filler[dotfill]}
% \permanent\protected\def\dotfill    {\mathortext\mathdotfill\textdotfill}

\permanent\protected\def\dotfill{\filler[dotfill]}

% maybe box -> symbol

\protect \endinput

% \definefiller[test-a][alternative=stretch]
% \definefiller[test-b][alternative=symbol,symbol=!]
% \definefiller[test-c][alternative=rule,height=.1ex,leftmargin=.5em,rightmargin=.25em]

% \starttext
%     text\filler[test-a]text \par
%     text\filler[test-b]text \par
%     text\filler[test-c]text \par
%     text\checkedfiller{<nothing>}text \par
% \stoptext