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