summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/ncctools/mboxfill.dtx
blob: 1a4793b38d8f745dfbd735ec1c0b0ce29d0c3703 (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
% \iffalse
%%
%% File: mboxfill.dtx Copyright (C) 2005 by Alexander I. Rozhenko
%%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{mboxfill}
%<package>      [2005/05/13 v1.0 Fill space with mbox (NCC)]
%
% \changes{v1.0}{2005/05/13}{This version was uploaded to CTAN}
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{mboxfill}
\GetFileInfo{mboxfill.sty}
\begin{document}
\title{The \textsf{mboxfill} package\thanks{This file
        has version number \fileversion, last
        revised \filedate.}}
\author{Alexander I. Rozhenko\\rozhenko@oapmg.sscc.ru}
\date{\filedate}
\maketitle
\DocInput{mboxfill.dtx}
\end{document}
%</driver>
% \fi
%
% \section{User Interface}
%
% \DescribeMacro\mboxfill
% This package implements the command
% \begin{quote}
% |\mboxfill|\oarg{width}\oarg{leader-type}\marg{pattern}
% \end{quote}
% filling a free horizontal space with \meta{pattern}.
%
% The \meta{width} parameter specifies a width of box pattern
% to be used as leaders. If it is omitted, the pattern width is used.
% The |\width|, |\height|, |\depth|,
% and |\totalheight| macros can be used in this parameter.
% Length expressions are also allowed if the \textsf{calc}
% package is loaded.
%
% The \meta{leader-type} parameter specifies a type of leaders
% to be used: |c| means |\cleaders|, |x| means |\xleaders|, and
% empty value (default) means |\leaders|. Depending on type, an
% extra space is distributed between fill entries as follows:
% in |c| case, fill entries are centered, in |x| case, fill entries
% are uniformly distributed, and in other cases, fill entries are
% aligned to the multiple of their width counted from the
% left boundary of filled box.
%
% When the specified \meta{width} differs from the pattern
% width, the pattern is centered inside the box to fill with.
% As a consequence, when |x|-leaders are used, a bit of space
% will be left from both sides of fill area. To remove this
% space, use the special value of \meta{leader-type} parameter,
% namely |s|.
%
% Example:
% \begin{quote}
% |\noindent\mboxfill{*}\mbox{}\\|\\
% |\mbox{}\mboxfill[2\width]{+}\mbox{}\\|\\
% |\mbox{}\mboxfill[2\width]{\hfill+}\mbox{}\\|\\
% |\mbox{}\mboxfill[2\width]{+\hfill}\mbox{}\\|\\
% |A text\mboxfill[1.5\width]{*}\mbox{}\\|\\
% |\mbox{}\mboxfill[1.5\width]{*}\mbox{}\\|\\
% |\mbox{}\mboxfill[1.5\width][c]{*}\mbox{}\\|\\
% |\mbox{}\mboxfill[1.5\width][x]{*}\mbox{}\\|\\
% |\mbox{}\mboxfill[1.5\width][s]{*}\mbox{}\\[-2ex]|\\
% |\mbox{}\hrulefill|
% \end{quote}
% It produces the following:
%
% \noindent\mboxfill{*}\mbox{}\\
% \mbox{}\mboxfill[2\width]{+}\mbox{}\\
% \mbox{}\mboxfill[2\width]{\hfill+}\mbox{}\\
% \mbox{}\mboxfill[2\width]{+\hfill}\mbox{}\\
% A text\mboxfill[1.5\width]{*}\mbox{}\\
% \mbox{}\mboxfill[1.5\width]{*}\mbox{}\\
% \mbox{}\mboxfill[1.5\width][c]{*}\mbox{}\\
% \mbox{}\mboxfill[1.5\width][x]{*}\mbox{}\\
% \mbox{}\mboxfill[1.5\width][s]{*}\mbox{}\\[-2ex]
% \mbox{}\hrulefill
%
% \StopEventually{}
%
% \section{The Implementation}
%
%    \begin{macrocode}
%<*package>
\newcommand*\mboxfill[1][\width]{%
  \def\@tempa{\setlength\@tempdima{#1}}%
  \@ifnextchar[{\NCC@mboxfill}{\NCC@mboxfill[]}%
}
\def\NCC@mboxfill[#1]#2{%
  \@begin@tempboxa\hbox{#2}%
%    \end{macrocode}
% Set the required box width in |\@tempdima|:
%    \begin{macrocode}
    \@tempa
%    \end{macrocode}
% Test the case of |s|-leaders. They work like |x|-leaders,
% but a special kern is added to both sides of the fill area
% to compensate extra-space added in the box.
%    \begin{macrocode}
    \edef\@tempa{#1}\def\@tempb{s}%
    \ifx\@tempa\@tempb
      \@tempdimb\width
      \advance\@tempdimb -\@tempdima
      \let\@tempa\xleaders
      \def\@tempb{\kern.5\@tempdimb}%
    \else
%    \end{macrocode}
% Other cases: if leader-type is incorrect, we use |\leaders|.
%    \begin{macrocode}
      \@ifundefined{#1leaders}{\let\@tempa\leaders}%
      {\def\@tempa{\csname#1leaders\endcsname}}%
      \let\@tempb\@empty
    \fi
%    \end{macrocode}
% |\@tempa| contains required leaders, |\@tempb| is a kern or empty.
% Fill the space.
%    \begin{macrocode}
    \leavevmode\@tempb\@tempa
      \hb@xt@\@tempdima{\hss\unhbox\@tempboxa\hss}\hfill\@tempb
  \@end@tempboxa
}
%</package>
%    \end{macrocode}
\endinput