pack-mrl.mkxl /size: 24 Kb    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=pack-mrl, % was pack-rul/core-rul,
3%D        version=1998.10.16,
4%D          title=\CONTEXT\ Packaging Macros,
5%D       subtitle=More Rules,
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 Packaging Macros / More Rules}
15
16%D The (re)implementation of margin rules has been moved elsewhere.
17
18\unprotect
19
20%D \macros
21%D   {setupblackrules,blackrule}
22%D
23%D The graphic capabilities of \TEX\ do not go beyond simple filled rules, except of
24%D course when using specials or, in \MKIV, manipulate node lists. Let's start with
25%D a warning: using this commands is far more slower than using the \TEX\ primitives
26%D \type {\hrule} and \type {\vrule}, but they save us some tokens. The
27%D characteristics of these rule drawing command can be set by:
28%D
29%D \showsetup{setupblackrules}
30%D
31%D The simple command draws only one rule. Its optional argument can be used to
32%D specify the dimensions. By setting the width, height or depth to \type {max}, one
33%D gets the natural dimensions.
34%D
35%D \showsetup{blackrule}
36
37\installcorenamespace{blackrules}
38
39\installsimplecommandhandler \??blackrules {blackrules} \??blackrules
40
41\permanent\protected\def\blackrule
42  {% this was \hpack\bgroup\dontleavehmode but we want leader support
43   \begingroup
44   \doifelsenextoptionalcs\pack_black_rule_pickup\pack_black_rule_indeed}
45
46\def\pack_black_rule_pickup[#S#1]%
47  {\setupcurrentblackrules[#1]%
48   \pack_black_rule_indeed}
49
50% \def\pack_black_rule_indeed
51%   {\edef\p_width {\directblackrulesparameter\c!width }%
52%    \edef\p_height{\directblackrulesparameter\c!height}%
53%    \edef\p_depth {\directblackrulesparameter\c!depth }%
54%    \ifx\p_height\v!max
55%      \setstrut
56%    \orelse\ifx\p_depth\v!max
57%      \setstrut
58%    \fi
59%    \useblackrulesstyleandcolor\c!style\c!color
60%    \ifcsname\??blackruletype\directblackrulesparameter\c!type\endcsname
61%      \lastnamedcs
62%    \else
63%      \vrule
64%    \fi
65%    \ifx\p_width \v!max\s!width \emwidth\orelse\ifempty\p_width \else\s!width \p_width \fi
66%    \ifx\p_height\v!max\s!height\strutht\orelse\ifempty\p_height\else\s!height\p_height\fi
67%    \ifx\p_depth \v!max\s!depth \strutdp\orelse\ifempty\p_depth \else\s!depth \p_depth \fi
68%    \egroup}
69
70\def\pack_black_rule_indeed
71  {\edef\p_width  {\directblackrulesparameter\c!width}%
72   \edef\p_height {\directblackrulesparameter\c!height}%
73   \edef\p_depth  {\directblackrulesparameter\c!depth}%
74   \edef\p_stretch{\directblackrulesparameter\c!stretch}%
75   \edef\p_shrink {\directblackrulesparameter\c!shrink}%
76   \ifx\p_height\v!max
77     \setstrut
78     \let\p_height\strutdp
79   \orelse\ifx\p_depth\v!max
80     \setstrut
81   \fi
82 % \ifx\p_height\v!max
83 %   \let\p_height\strutdp
84 % \fi
85   \ifx\p_depth\v!max
86     \let\p_depth\strutdp
87   \fi
88   \ifx\p_width\v!max
89     \let\p_width\emwidth
90   \fi
91   \useblackrulesstyleandcolor\c!style\c!color
92   \ifempty\p_stretch
93     \ifempty\p_shrink
94        \donefalse
95     \else
96        \donetrue
97        \leaders
98     \fi
99   \else
100      \donetrue
101      \leaders
102   \fi
103   \ifcsname\??blackruletype\directblackrulesparameter\c!type\endcsname
104     \lastnamedcs
105   \else
106     \vrule
107   \fi
108   \ifempty\p_height\else\s!height\p_height\fi
109   \ifempty\p_depth\else\s!depth\p_depth\fi
110   \ifdone
111     \hskip\ifempty\p_width\zeropoint\else\p_width\fi
112     \ifempty\p_stretch\else\s!plus\p_stretch\fi
113     \ifempty\p_shrink\else\s!minus\p_shrink\fi
114   \else
115     \ifempty\p_width\else\s!width\p_width\fi
116   \fi
117   \endgroup}
118
119\setupblackrules
120  [\c!width=\emwidth,
121   \c!height=\exheight,
122   \c!depth=\zeropoint,
123   \c!color=]
124
125%D \macros
126%D   {blackrules}
127%D
128%D One can call for a sequence of black rules, if needed equally spaced over the
129%D given width.
130%D
131%D \showsetup{blackrules}
132%D
133%D The two alternative calls are therefore:
134%D
135%D \startbuffer
136%D Tell me, is this according to the \blackrules[n=6]?
137%D These \blackrules[alternativevariant=b,n=10,distance=.2em,width=4cm] are quite clear.
138%D \stopbuffer
139%D
140%D \typebuffer
141%D
142%D or:
143%D
144%D \startlines
145%D \getbuffer
146%D \stoplines
147%D
148%D We could of course have implemented this macro using \type {\leaders}, but this
149%D would probably have taken more tokens.
150
151\permanent\tolerant\protected\def\blackrules[#S#1]% probably never used
152  {\hpack\bgroup % we keep this because breaking into lines breaks compatibility
153   \ifarguments\or\setupcurrentblackrules[#1]\fi
154   \scratchwidth   \directblackrulesparameter\c!width
155   \scratchheight  \directblackrulesparameter\c!height
156   \scratchdepth   \directblackrulesparameter\c!depth
157   \scratchdistance\directblackrulesparameter\c!distance
158   \scratchcounter \directblackrulesparameter\c!n
159   \edef\p_alternative{\blackrulesparameter\c!alternative}%
160   \ifx\p_alternative\c!b % why not just check distance
161     \ifnum\scratchcounter=\plusone
162       \scratchdistance\zeropoint
163     \else
164       \scratchwidth\dimexpr(\scratchwidth-\scratchcounter\scratchdistance+\scratchdistance)/\scratchcounter\relax
165     \fi
166   \fi
167   \useblackrulesstyleandcolor\c!style\c!color
168   % a typical case of where we can use a simple loop or even a leaders
169   \dorecurse\scratchcounter\pack_black_rules_step
170   \unskip
171   \egroup}
172
173\def\pack_black_rules_step
174  {\ifcsname\??blackruletype\directblackrulesparameter\c!type\endcsname
175     \lastnamedcs
176   \else
177     \vrule
178   \fi
179   \s!width \scratchwidth
180   \s!height\scratchheight
181   \s!depth \scratchdepth
182   \relax
183   \ifzeropt\scratchdistance\else
184     \kern\scratchdistance % hskip
185   \fi}
186
187\installcorenamespace{blackruletype}
188
189\defcsname\??blackruletype mp\endcsname
190  {\frule
191     type {mp}%
192     data {\includeMPgraphic{\directblackrulesparameter\c!mp}}
193     line \dimexpr\directblackrulesparameter\c!rulethickness\relax
194   }
195
196\letcsname\??blackruletype\s!no \endcsname\novrule
197%letcsname\??blackruletype\s!yes\endcsname\vrule
198
199\setupblackrules
200  [\c!n=3,
201   \c!rulethickness=\linewidth,
202   \c!alternative=\c!a,
203   \c!distance=.25\emwidth,
204   \c!color=]
205
206%D \macros
207%D   {vl, hl}
208%D
209%D The command \type {\vl} draws a vertical rule \vl\ with strut dimensions,
210%D multiplied with the factor specified in the optional argument. The height and
211%D depth are clipped \vl [3] to the baselinedistance. Its horizontal counterpart
212%D \type {\hl} draws a horizontal rule \hl\ with a width of 1em, multiplied with the
213%D optional factor. The horizontal rule is drawn on top of the baseline.
214%D
215%D \showsetup{vl}
216%D \showsetup{hl}
217
218\protected\def\pack_rule_vl_indeed#1#2#3%
219  {\dontleavehmode
220   \begingroup
221   \setbox\scratchbox\hbox
222     {\vrule
223        \s!width #1\linewidth
224        \s!height#2\strutht
225        \s!depth #3\strutdp}%
226   \dp\scratchbox\strutdp
227   \ht\scratchbox\strutht
228   \box\scratchbox
229   \endgroup}
230
231\permanent\tolerant\protected\def\vl[#1]%
232  {\pack_rule_vl_indeed{#1}{#1}{#1}}
233
234\permanent\tolerant\protected\def\hl[#1]%
235  {\dontleavehmode
236   \hbox
237     {\vrule
238        \s!width #1\emwidth
239        \s!height\linewidth
240        \s!depth \zeropoint}}
241
242\let\dovlwdhtdp\pack_rule_vl_indeed % used elsewhere .. in font manual
243
244%D \macros
245%D   {hairline, thinrule, thinrules, setupthinrules}
246%D
247%D Drawing thin lines can of course easily be accomplished by the \TEX\
248%D primitives \type{\hrule} and \type{\vrule}. The next few macros however
249%D free us from some specifications.
250%D
251%D \startbuffer
252%D some text
253%D
254%D \hairline
255%D
256%D some more text
257%D
258%D \thinrule
259%D
260%D more and more text
261%D
262%D hi \thinrule\ there
263%D
264%D and then the final text
265%D \stopbuffer
266%D
267%D \typebuffer
268%D
269%D becomes
270%D
271%D \startexample
272%D \getbuffer
273%D \stopexample
274%D
275%D So we've got
276%D
277%D \showsetup{hairline}
278%D \showsetup{thinrule}
279%D
280%D Both can be set up with:
281%D
282%D \showsetup{setupthinrules}
283%D
284%D We also have
285%D
286%D \showsetup{thinrules}
287%D
288%D which looks like: \thinrules[n=2]
289
290\installcorenamespace{thinrules}
291\installcorenamespace{thinrulealternatives}
292
293\installdirectcommandhandler \??thinrules {thinrules}
294
295\setupthinrules
296  [\c!interlinespace=\v!small,
297   \c!n=3,
298   \c!before=,
299   \c!inbetween={\blank[\v!white]},
300   \c!after=,
301   \c!color=,
302   \c!height=.5\linewidth,
303   \c!depth=.5\linewidth,
304   \c!frame=\v!on, % compatible with textbackgrounds
305   \c!alternative=\v!b,
306   \c!backgroundcolor=,
307   \c!background=,
308   \c!rulethickness=\linewidth]
309
310\letcsname\??thinrulealternatives\v!a   \endcsname\zerocount
311\letcsname\??thinrulealternatives\v!b   \endcsname\plusone
312\letcsname\??thinrulealternatives\v!c   \endcsname\plustwo
313\letcsname\??thinrulealternatives\v!none\endcsname\zerocount
314
315\newconstant\c_pack_thinrules_type
316
317\permanent\protected\def\thinrule
318  {\strut
319   \bgroup
320   \edef\p_height    {\directthinrulesparameter\c!height}%
321   \edef\p_depth     {\directthinrulesparameter\c!depth}%
322   \edef\p_background{\directthinrulesparameter\c!background}%
323   \edef\p_frame     {\directthinrulesparameter\c!frame}%
324   \linewidth\dimexpr\directthinrulesparameter\c!rulethickness/\plustwo\relax
325   \ifzeropt\linewidth
326     \c_pack_thinrules_type\zerocount
327   \orelse\ifx\p_frame\v!on
328     \c_pack_thinrules_type\expandnamespaceparameter\??thinrulealternatives\directthinrulesparameter\c!alternative\v!b\relax
329   \else
330     \c_pack_thinrules_type\zerocount
331   \fi
332   \ifnum\c_pack_thinrules_type=\plusone
333     \ifx\p_height\v!max
334       \scratchheight\strutht
335     \else
336       \setdimensionwithunit\scratchheight\p_height\strutht
337     \fi
338     \ifx\p_depth\v!max
339        \scratchdepth\strutdp
340     \else
341        \setdimensionwithunit\scratchdepth\p_depth\strutdp
342     \fi
343   \else
344     \scratchheight\strutht
345     \scratchdepth \strutdp
346   \fi
347   \ifx\p_background\v!color
348     \startcolor[\directthinrulesparameter\c!backgroundcolor]%
349       \ifnum\c_pack_thinrules_type=\plustwo % prevent overshoot due to rounding
350         \leaders
351           \hrule
352             \s!height\dimexpr\scratchheight-\linewidth\relax
353             \s!depth \dimexpr\scratchdepth -\linewidth\relax
354           \hfill
355       \else
356         \leaders
357           \hrule
358             \s!height\scratchheight
359             \s!depth \scratchdepth
360           \hfill
361       \fi
362     \stopcolor
363     \ifcase\c_pack_thinrules_type
364       % no rule
365     \or
366       \startcolor[\directthinrulesparameter\c!color]%
367         \hfillneg
368         \leaders
369           \hrule
370             \s!height\linewidth
371             \s!depth \linewidth
372           \hfill
373       \stopcolor
374     \or
375       \startcolor[\directthinrulesparameter\c!color]%
376         \hfillneg
377         \leaders
378           \hrule
379             \s!height\dimexpr-\scratchdepth+\linewidth\relax
380             \s!depth \scratchdepth
381           \hfill
382         \hfillneg
383         \leaders
384           \hrule
385             \s!height\scratchheight
386             \s!depth \dimexpr-\scratchheight+\linewidth\relax
387           \hfill
388       \stopcolor
389     \fi
390   \else
391     \ifcase\c_pack_thinrules_type
392       % no rule
393     \else
394       \startcolor[\directthinrulesparameter\c!color]%
395         \leaders
396           \hrule
397             \s!height\scratchheight
398             \s!depth \scratchdepth
399           \hfill
400       \stopcolor
401     \fi
402   \fi
403   \strut
404   \carryoverpar\egroup}
405
406\permanent\protected\def\hairline % can be overloaded
407  {\endgraf
408   \thinrule
409   \endgraf}
410
411\permanent\tolerant\protected\def\thinrules[#S#1]%
412  {\bgroup
413   \setupcurrentthinrules[#1]%
414   \scratchcounter\directthinrulesparameter\c!n\relax
415   \ifcase\scratchcounter
416     % nothing, not even before/after
417     \let\p_after\relax
418   \else
419     \assignvalue{\directthinrulesparameter\c!interlinespace}\m_pack_thinrules_interlinespace{1.0}{1.5}{2.0}%
420     \spacing\m_pack_thinrules_interlinespace
421     \edef\p_after    {\directthinrulesparameter\c!after}%
422     \edef\p_inbetween{\directthinrulesparameter\c!inbetween}%
423     \directthinrulesparameter\c!before
424     \ifcase\scratchcounter\or
425       \thinrule
426     \else
427       \dorecurse\scratchcounter
428         {\ifnum\recurselevel=\scratchcounter \directvspacing\v!samepage \else   % \penalty500
429          \ifnum\recurselevel=\plustwo        \directvspacing\v!samepage \fi\fi  % \penalty500
430          \thinrule
431          \ifnum\recurselevel<\scratchcounter\relax
432            % test needed, else messed up whitespace
433            \ifempty\p_inbetween
434              \softbreak % \ifhmode \hskip \parfillskip \break \fi
435            \else
436              \endgraf
437              \nowhitespace
438              \p_inbetween
439            \fi
440          \fi}%
441     \fi
442   \fi
443   \ifempty\p_after
444     \carryoverpar\egroup
445   \else
446     \p_after\egroup
447   \fi{}}
448
449%D A couple of examples are given below.
450%D
451%D \startbuffer
452%D \setupthinrules[n=3,inbetween=,color=gray]
453%D
454%D test test \thinrules\ test test \par
455%D test test \thinrules [color=green] test test \par
456%D test test \thinrules [height=max, depth=max] test test \par
457%D
458%D \setupthinrules[height=.9,depth=.9]
459%D
460%D test test \thinrules\ test test \par
461%D test test \thinrules [alternativevariant=b] test test \par
462%D test test \thinrules [alternativevariant=c] test test \par
463%D test test \thinrules [alternativevariant=c,inbetween=\vskip2ex] test test \par
464%D \stopbuffer
465%D
466%D \typebuffer {\getbuffer}
467%D
468%D There are a couple of alternative ways to visualize rules using backgrounds. At
469%D first sight these may look strange, but they make sense in educational settings.
470%D The alternatives are more or less compatible with the more advanced \METAPOST\
471%D based implementation.
472%D
473%D \startbuffer[a]
474%D \setupthinrules
475%D   [n=2,
476%D    backgroundcolor=gray  ,
477%D    rulethickness=1pt,
478%D    colorkleur=donkerblauw,
479%D    after=\blank,
480%D    before=\blank]
481%D \stopbuffer
482%D
483%D \typebuffer[a]
484%D
485%D \startbuffer[b]
486%D \thinrules[alternativevariant=a]
487%D \thinrules[alternativevariant=b]
488%D \thinrules[alternativevariant=c]
489%D \stopbuffer
490%D
491%D \typebuffer[b] \getbuffer[a,b]
492%D
493%D \startbuffer[b]
494%D \thinrules[alternativevariant=a,background=color]
495%D \thinrules[alternativevariant=b,background=color]
496%D \thinrules[alternativevariant=c,background=color]
497%D \stopbuffer
498%D
499%D \typebuffer[b] \getbuffer[a,b]
500%D
501%D \startbuffer[b]
502%D \thinrules[alternativevariant=a,height=.8,depth=.8,background=color]
503%D \thinrules[alternativevariant=b,height=.8,depth=.8,background=color]
504%D \thinrules[alternativevariant=c,height=.8,depth=.8,background=color]
505%D \stopbuffer
506%D
507%D \typebuffer[b] \getbuffer[a,b]
508
509%D \macros
510%D   {textrule, starttextrule, setuptextrules}
511%D
512%D Putting rules before and after a paragraph is very space sensitive, but the
513%D next command handles that quite well. It comes in two disguises:
514%D
515%D \startbuffer
516%D \textrule[top]{fragments}
517%D   \input reich
518%D \textrule
519%D \stopbuffer
520%D
521%D \start \typebuffer \getbuffer \stop
522%D
523%D \startbuffer
524%D \setuptextrules
525%D   [width=90pt,distance=12pt,rulecolor=blue,
526%D    bodyfont=small,style=\sc,color=red]
527%D
528%D \starttextrule{Ship Building Tools}
529%D   \nl \setuptolerance[tolerant] \input materie
530%D \stoptextrule
531%D \stopbuffer
532%D
533%D \bgroup \typebuffer \getbuffer \egroup
534%D
535%D \startbuffer
536%D \setuptextrules
537%D   [location=inmargin,
538%D    bodyfont=small,style=slantedbold]
539%D
540%D \starttextrule{wonderful}
541%D   \input tufte
542%D \stoptextrule
543%D \stopbuffer
544%D
545%D \bgroup \typebuffer \getbuffer \egroup
546%D
547%D The formal definition of these commands is:
548%D
549%D \showsetup{textrule}
550%D \showsetup{starttextrule}
551%D \showsetup{setuptextrules}
552%D
553%D The implementation looks a bit complicated due to the optional arguments.
554
555\installcorenamespace{textrules}
556\installcorenamespace{textrulealternatives}
557
558\installdirectcommandhandler \??textrules {textrules}
559
560\setuptextrules
561  [\c!location=\v!left,
562   \c!before=\blank,
563   \c!after=\blank,
564   \c!inbetween=,
565   \c!width=2\emwidth,
566   \c!style=\v!bold,
567   \c!color=,
568   \c!rulecolor=,
569   \c!bodyfont=,
570   \c!depthcorrection=\v!on,
571   \c!rulethickness=\linewidth,
572   \c!distance=.5\emwidth]
573
574% can be done nicer with futureexpandis
575
576\permanent\tolerant\protected\def\textrule[#1]%
577  {\ifarguments
578     \expandafter\pack_textrule_nop
579   \else
580     \expandafter\pack_textrule_yes
581   \fi[#1]}
582
583\def\pack_textrule_yes[#1]%
584  {\expandnamespacevalue\??textrulealternatives{#1}\v!bottom}
585
586% \tolerant\def\pack_textrule_nop[#1]#:#=%
587%   {\ifparameter#2\or
588%      \expandafter\pack_textrule_nop_indeed_yes
589%    \else
590%      \expandafter\pack_textrule_nop_indeed_nop
591%    \fi[#1]{#2}}
592
593\def\pack_textrule_nop[#1]%
594  {\doifelsenextbgroupcs\pack_textrule_nop_indeed_yes\pack_textrule_nop_indeed_nop}
595
596\def\pack_textrule_nop_indeed_yes{\csname\??textrulealternatives\v!top   \endcsname}
597\def\pack_textrule_nop_indeed_nop{\csname\??textrulealternatives\v!bottom\endcsname\empty}
598
599%D\startbuffer
600%D\showstruts
601%D
602%D\setupwhitespace[none]
603%D
604%D\textrule[top]{test} xxxxx\smash{\strut} \textrule[bottom]{test}
605%D\textrule[top]{test} xxxxx\strut         \textrule[bottom]{test}
606%D
607%D\setupwhitespace[big]
608%D
609%D\textrule[top]{test} xxxxx\smash{\strut} \textrule[bottom]{test}
610%D\textrule[top]{test} xxxxx\strut         \textrule[bottom]{test}
611%D\stoptyping
612%D
613%D \typebuffer \start \getbuffer \stop
614
615\defcsname\??textrulealternatives\v!top\endcsname#1%
616  {\page[\v!preference] % interferes
617   \directtextrulesparameter\c!before\relax
618   \blank[\v!samepage,\v!nowhite]%
619   \pack_textrule_with_text_yes{#1}%
620   \blank[\v!samepage,\v!nowhite]%
621   \directtextrulesparameter\c!inbetween\relax
622   \endgraf}
623
624\defcsname\??textrulealternatives\v!bottom\endcsname#1%
625  {\blank[\v!samepage,\v!nowhite]%
626   \pack_textrule_following{#1}%
627   \blank[\v!samepage,\v!nowhite]%
628   \directtextrulesparameter\c!after\relax
629   \page[\v!preference]}
630
631\defcsname\??textrulealternatives\v!middle\endcsname#1%
632  {\blank[\v!samepage,\v!nowhite]%
633   \directtextrulesparameter\c!inbetween\relax
634   \pack_textrule_following{#1}%
635   \blank[\v!samepage,\v!nowhite]%
636   \directtextrulesparameter\c!inbetween\relax
637   \page[\v!preference]}
638
639\def\pack_textrule_with_text_yes#1%
640  {\noindent % this will force side floats to be calculated
641   \bgroup
642   \setbox\scratchbox\hpack to \availablehsize
643     {\scratchwidth \directtextrulesparameter\c!rulethickness\relax
644      \scratchheight\dimexpr .5\exheight+.5\scratchwidth\relax
645      \scratchdepth \dimexpr-.5\exheight+.5\scratchwidth\relax
646      \ifempty{#1}%
647        % nothing
648      \orelse\ifcstok{\directtextrulesparameter\c!location}\v!inmargin
649        \llap
650          {\usetextrulesstyleandcolor\c!style\c!color
651           #1%
652           \kern\leftmargindistance}% hskip
653      \else
654        \color[\directtextrulesparameter\c!rulecolor]
655          {\vrule
656             \s!height\scratchheight
657             \s!depth \scratchdepth
658             \s!width \directtextrulesparameter\c!width}%
659        \hbox spread 2\dimexpr\directtextrulesparameter\c!distance\relax
660          {\hss
661           \usetextrulesstyleandcolor\c!style\c!color
662           \strut#1%
663           \hss}%
664      \fi
665      \color[\directtextrulesparameter\c!rulecolor]
666        {\leaders\hrule
667           \s!height\scratchheight
668           \s!depth \scratchdepth
669           \hfill}}%
670   \ht\scratchbox\strutht
671   \dp\scratchbox\strutdp
672   \box\scratchbox
673  %\carryoverpar
674   \egroup}
675
676\def\pack_textrule_with_text_nop#1%
677  {\ifhmode
678     \endgraf
679   \fi
680   \ifcstok{\directtextrulesparameter\c!depthcorrection}\v!on
681     \pack_textrule_correct_depth_yes
682   \else
683     \pack_textrule_correct_depth_nop
684   \fi
685   \nointerlineskip
686   \noindent\naturalvpack % was \dontleavehmode
687     {\color[\directtextrulesparameter\c!rulecolor]
688        {\hrule
689           \s!depth \directtextrulesparameter\c!rulethickness
690           \s!height\zeropoint
691           \s!width \availablehsize}}}
692
693\def\pack_textrule_correct_depth_yes
694  {\vskip\dimexpr
695     \strutdp +.5\exheight
696     \ifdim\prevdepth>\strutdp\else
697       \ifdim\prevdepth>\zeropoint
698         -\prevdepth
699       \fi
700     \fi
701   \relax
702   \relax}
703
704\def\pack_textrule_correct_depth_nop
705  {\vskip\dimexpr
706     \strutdp +.5\exheight
707   \relax
708   \relax}
709
710\def\pack_textrule_following#1%
711  {\ifempty{#1}
712     \expandafter\pack_textrule_with_text_nop
713   \else
714     \expandafter\pack_textrule_with_text_yes
715   \fi{#1}%
716   \ifvmode
717     \prevdepth\zeropoint
718   \fi}
719
720%D The grouped commands also supports bodyfont switching:
721
722\permanent\protected\def\starttextrule#1%
723  {\bgroup
724   \def\pack_textrule_nop_indeed_nop{\csname\??textrulealternatives\v!middle\endcsname}%
725  %\let\pack_textrule_nop_indeed_yes\pack_textrule_nop_indeed_nop % needs checking
726   \csname\??textrulealternatives\v!top\endcsname{#1}%
727   \bgroup
728   \usebodyfontparameter\directtextrulesparameter}
729
730\permanent\protected\def\stoptextrule
731  {\par
732   \egroup
733   \csname\??textrulealternatives\v!bottom\endcsname\empty
734   \egroup}
735
736%D \macros
737%D   {fillinrules, setupfillinrules}
738%D
739%D The next few commands do not really deserve a place in a core module, because
740%D they deal with specific typography. Nevertheless I decided to make them part of
741%D the core, because they permit us to make questionaires. Let's start with some
742%D examples.
743%D
744%D \fillinrules[n=2,width=fit]{first}
745%D \fillinrules[n=2,width=broad]{first}
746%D \fillinrules[n=2,width=3cm]{first}
747%D \fillinrules[n=2,width=3cm,distance=.5em,separator=:]{first}
748%D \fillinrules[n=2]{first}{last}
749%D \fillintext{first}{last} \input reich \par
750%D
751%D The main command is \type{\fillinrules}. This command takes one and an optional
752%D second argument and sets a paragraph with empty visualized lines.
753%D
754%D \showsetup{fillinrules}
755%D \showsetup{setupfillinrules}
756%D
757%D I NEED TO UPGRADE THIS!
758
759\installcorenamespace{fillinrules}
760
761\installdirectcommandhandler \??fillinrules {fillinrules}
762
763\setupfillinrules
764  [\c!width=\v!broad,
765   \c!distance=\emwidth,
766   \c!before=\blank,
767   \c!after=\blank,
768   \c!n=\plusone,
769   \c!interlinespace=\v!small,
770   \c!separator=,
771   \c!style=,
772   \c!color=]
773
774\def\pack_fillinrules_rule_indeed{\thinrules}
775
776\permanent\tolerant\protected\def\fillinrules[#S#1]#:#=#*#=%
777  {\endgraf
778   \begingroup
779   \setupcurrentfillinrules[#1]%
780   \directfillinrulesparameter\c!before
781   \setupcurrentthinrules
782     [\c!n=\directfillinrulesparameter\c!n,
783      \c!interlinespace=\directfillinrulesparameter\c!interlinespace,
784      \c!before=,
785      \c!after=]%
786   \scratchdistance\directfillinrulesparameter\c!distance\relax
787   \noindent
788   \ifempty{#2}\else
789     \edef\p_width{\directfillinrulesparameter\c!width}%
790     \ifx\p_width\v!fit
791       \scratchdistance\zeropoint
792       \hbox
793     \orelse\ifx\p_width\v!broad
794       \hbox
795     \else
796       \hbox to \directfillinrulesparameter\c!width
797     \fi
798     \bgroup
799       \usefillinrulesstyleandcolor\c!style\c!color
800       \strut
801       #2%
802       \hfill\directfillinrulesparameter\c!separator
803       \kern\scratchdistance % hskip
804     \egroup
805   \fi
806   \setupwhitespace[\v!big]%
807   \ignorespaces
808   \pack_fillinrules_rule_indeed
809   \ifempty{#3}\else
810     \kern\scratchdistance
811     \usefillinrulesstyleandcolor\c!style\c!color
812     #3%
813     \strut
814   \fi
815   \endgraf
816   \directfillinrulesparameter\c!after
817   \endgroup}
818
819%D \macros
820%D   {fillintext}
821%D
822%D To provide compatible layouts when texts and lines are mixed, one can typeset
823%D a paragraph by using the command \type {\fillintext}.
824%D
825%D \showsetup{fillintext}
826
827\permanent\tolerant\protected\def\fillintext[#S#1]#:#=#*#=%
828  {\endgraf
829   \begingroup
830   \def\pack_fillinrules_rule_indeed{\unhbox\nextbox\unskip}% hm, needs checking
831   \dowithnextbox{\fillinrules[#1]{#2}{\hfill#3}}%
832   \hbox\bgroup\enforced\let\par\egroup\ignorespaces} % bah, i will drop this compatibility hack
833
834%D \macros
835%D   {fillinline, setupfillinlines}
836%D
837%D Another member of the family takes care of putting a (often small) rule after
838%D a piece of text, like
839%D
840%D \startbuffer
841%D \fillinline \input reich \par
842%D \fillinline[margin=0cm] \input reich \par
843%D \stopbuffer
844%D
845%D \startexample
846%D \getbuffer
847%D \stopexample
848%D
849%D which was typeset by saying:
850%D
851%D \typebuffer
852%D
853%D The two commands that take care of this are:
854%D
855%D \showsetup{fillinline}
856%D \showsetup{setupfillinlines}
857%D
858%D Contrary to older implementations we now use the wrapper.
859
860\installcorenamespace{fillinlines}
861
862\installdirectcommandhandler \??fillinlines {fillinlines}
863
864\setupfillinlines
865  [\c!width=8\emwidth, % was 3cm
866   \c!margin=\directfillinlinesparameter\c!width,
867   \c!rulethickness=\linewidth,
868   \c!color=,
869   \c!distance=\emwidth,
870   \c!before=\blank,
871   \c!after=\blank]
872
873\protected\def\pack_fillinline_before#1%
874  {}
875
876\protected\def\pack_fillinline_after#1%
877  {\begingroup
878   \setupcurrentfillinlines[#1]%
879   \ifhmode\unskip\hfill\fi
880   \scratchdistance\directfillinlinesparameter\c!distance
881   \scratchheight\dimexpr\directfillinlinesparameter\c!rulethickness/\plustwo\relax
882   \scratchwidth \dimexpr\directfillinlinesparameter\c!width-\scratchdistance\relax
883   \ifdim\scratchwidth>\directfillinlinesparameter\c!margin\else
884     \expandafter\rlap
885   \fi
886   {\kern\scratchdistance
887    \blackrule
888      [\c!color=\directfillinlinesparameter\c!color,
889       \c!width=\scratchwidth,
890       \c!height=\scratchheight,
891       \c!depth=\scratchheight]}%
892   \frozen\advanceby\rightskip \directfillinlinesparameter\c!margin\relax
893   \frozen\parfillskip\zeroskip\relax
894   \endgroup}
895
896\permanent\tolerant\protected\def\fillinline[#S#1]%
897  {\dontleavehmode
898   \registerparwrapper
899     {fillinline}%
900     {\pack_fillinline_before{#1}}%
901     {\pack_fillinline_after {#1}%
902      \unregisterparwrapper{fillinline}}}
903
904\protect \endinput
905