| 1 |
% \iffalse |
| 2 |
%% |
| 3 |
%% File: nccrules.dtx Copyright (C) 2005 by Alexander I. Rozhenko |
| 4 |
%% |
| 5 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 6 |
%<package>\ProvidesPackage{nccrules} |
| 7 |
%<package> [2005/05/13 v1.0 More rules (NCC)] |
| 8 |
% |
| 9 |
% \changes{v1.0}{2005/05/13}{This version was uploaded to CTAN} |
| 10 |
% |
| 11 |
%<*driver> |
| 12 |
\let\makeindex\relax |
| 13 |
\documentclass{ltxdoc} |
| 14 |
\usepackage{nccrules} |
| 15 |
\newfootnoterule{starred}{\mboxfill[1.5\width][s]{$*$}} |
| 16 |
\newfootnoterule{dotted}{\mboxfill[2\width][s]{.}} |
| 17 |
\newfootnotedashrule{double}{}{.4 1 .4} |
| 18 |
\newfootnotedashrule{dashed}{3 3}{.4} |
| 19 |
\newfootnotedashrule{dotdashed}{4 2 1 2 4 -4}{.6} |
| 20 |
\newfootnotedashrule{ddotdashed}{6 2 1 2 1 2 6 -6}{.6} |
| 21 |
\GetFileInfo{nccrules.sty} |
| 22 |
\begin{document} |
| 23 |
\title{The \textsf{nccrules} package\thanks{This file |
| 24 |
has version number \fileversion, last |
| 25 |
revised \filedate.}} |
| 26 |
\author{Alexander I. Rozhenko\\[email protected]} |
| 27 |
\date{\filedate} |
| 28 |
\maketitle |
| 29 |
\DocInput{nccrules.dtx} |
| 30 |
\end{document} |
| 31 |
%</driver> |
| 32 |
% \fi |
| 33 |
% This package implements |
| 34 |
% |\dashrule| and |\dashrulefill| commands, |
| 35 |
% that simplify composing of dashed |
| 36 |
% lines and dashed multilines. Two kinds of footnote rule generation |
| 37 |
% commands are also introduced: |\newfootnoterule| creates a footnote |
| 38 |
% rule with an arbitrary contents and |\newfootnotedashrule| creates |
| 39 |
% a footnote rule based on dash rule. |
| 40 |
% |
| 41 |
% \tableofcontents |
| 42 |
% |
| 43 |
% \section{User Interface} |
| 44 |
% |
| 45 |
% \subsection{Dash Rules} |
| 46 |
% |
| 47 |
% \DescribeMacro\dashrule |
| 48 |
% The command |
| 49 |
% \begin{quote} |
| 50 |
% |\dashrule|\oarg{raise}\marg{h-pattern}\marg{v-pattern} |
| 51 |
% \end{quote} |
| 52 |
% prepares a dash rule. Its syntax is quite similar to the |\rule| command |
| 53 |
% except that \meta{h-pattern} and \meta{v-pattern} can contain a list of |
| 54 |
% sizes delimited with spaces. List sizes are interpreted as follows: |
| 55 |
% size, space, size, space, etc. In other words, every odd size is a |
| 56 |
% size of rule part and every even size is a space between neighbour parts. |
| 57 |
% If the last size in the list is even |
| 58 |
% (means a space), its space value is divided by two and |
| 59 |
% is added before the first rule part and after the last rule part. |
| 60 |
% Units in sizes can be omitted. In this case, pt-units are supposed. |
| 61 |
% Examples: |
| 62 |
% \begin{center} |
| 63 |
% \begin{tabular}{@{}l@{\qquad\qquad}l@{}} |
| 64 |
% x\dashrule[.5ex]{10mm}{1pt}x & |
| 65 |
% |x\dashrule[.5ex]{10mm}{1pt}x| \\ |
| 66 |
% x\dashrule{5mm 3 3 3 5mm}{.4}x & |
| 67 |
% |x\dashrule{5mm 3 3 3 5mm}{.4}x| \\ |
| 68 |
% x\dashrule{1}{3 2 3}x& |
| 69 |
% |x\dashrule{1}{3 2 3}x|\\ |
| 70 |
% x\dashrule{2 2}{2 2}x & |
| 71 |
% |x\dashrule{2 2}{2 2}x|\\ |
| 72 |
% x\dashrule{5 3 1 3 5 10}{1 1 0.4 1 1}x & |
| 73 |
% |x\dashrule{5 3 1 3 5 10}{1 1 0.4 1 1}x| |
| 74 |
% \end{tabular} |
| 75 |
% \end{center} |
| 76 |
% |
| 77 |
% \DescribeMacro\dashrulefill |
| 78 |
% The command |
| 79 |
% \begin{quote} |
| 80 |
% |\dashrulefill|\oarg{raise}\oarg{leader-type}\marg{h-pattern}\marg{v-pattern} |
| 81 |
% \end{quote} |
| 82 |
% fills a free space with a dash rule. The rule is composed from the 1st, |
| 83 |
% 3rd, and 4th arguments of the command and is repeated as more times as |
| 84 |
% necessary to fill a free horizontal space. The rest of space after filling is |
| 85 |
% stored depending on \meta{leader-type} used. Default leader type |
| 86 |
% is ``aligned leaders'': every rule is aligned to the multiple of its width |
| 87 |
% counted from the left boundary of filled box. Other cases are: |c| means |
| 88 |
% centered leaders (all extra spaces are collected at both ends of fill |
| 89 |
% area), |x| means distributed leaders (extra spaces are uniformly |
| 90 |
% distributed between every dash rule), and |s| means stretched leaders |
| 91 |
% (the space in h-pattern going after the last rule size is considered as |
| 92 |
% stretchable space and rules are stretched to the whole width of the |
| 93 |
% fill area). |
| 94 |
% |
| 95 |
% Example: |
| 96 |
% \begin{flushleft} |
| 97 |
% |\noindent x\dashrulefill{2 2}{2}\mbox{}\\|\\ |
| 98 |
% |xxxxx\dashrulefill[.4ex]{2 2}{2}\mbox{}\\|\\ |
| 99 |
% |\mbox{}\dashrulefill[.4ex]{4 4}{2}\mbox{}\\|\\ |
| 100 |
% |\mbox{}\dashrulefill[.4ex][c]{4 4}{2}\mbox{}\\|\\ |
| 101 |
% |\mbox{}\dashrulefill[.4ex][x]{4 4}{2}\mbox{}\\|\\ |
| 102 |
% |\mbox{}\dashrulefill[.4ex][s]{4 4}{2}\mbox{}\\|\\ |
| 103 |
% |\mbox{}\dashrulefill[.4ex][s]{4 2 1 2 4 -4}{1}\mbox{}\\[1ex]|\\ |
| 104 |
% |\mbox{}\dashrulefill[0mm][c]{2 3}{2 3 2 3 2}\mbox{}\\|\\ |
| 105 |
% |\mbox{}\dashrulefill{5 3 1 3 5}{1 1 0.4 1 1}\mbox{}\\|\\ |
| 106 |
% |\mbox{}\dashrulefill[0mm][c]{5 3 1 3 5}{1 1 0.4 1 1}\mbox{}\\[-2ex]|\\ |
| 107 |
% |\mbox{}\hrulefill| |
| 108 |
% \end{flushleft} |
| 109 |
% |
| 110 |
% It produces the following: |
| 111 |
% |
| 112 |
% \noindent x\dashrulefill{2 2}{2}\mbox{}\\ |
| 113 |
% xxxxx\dashrulefill[.4ex]{2 2}{2}\mbox{}\\ |
| 114 |
% \mbox{}\dashrulefill[.4ex]{4 4}{2}\mbox{}\\ |
| 115 |
% \mbox{}\dashrulefill[.4ex][c]{4 4}{2}\mbox{}\\ |
| 116 |
% \mbox{}\dashrulefill[.4ex][x]{4 4}{2}\mbox{}\\ |
| 117 |
% \mbox{}\dashrulefill[.4ex][s]{4 4}{2}\mbox{}\\ |
| 118 |
% \mbox{}\dashrulefill[.4ex][s]{4 2 1 2 4 -4}{1}\mbox{}\\[1ex] |
| 119 |
% \mbox{}\dashrulefill[0mm][c]{2 3}{2 3 2 3 2}\mbox{}\\ |
| 120 |
% \mbox{}\dashrulefill{5 3 1 3 5}{1 1 0.4 1 1}\mbox{}\\ |
| 121 |
% \mbox{}\dashrulefill[0mm][c]{5 3 1 3 5}{1 1 0.4 1 1}\mbox{}\\[-2ex] |
| 122 |
% \mbox{}\hrulefill |
| 123 |
% |
| 124 |
% \subsection{Custom Footnote Rules} |
| 125 |
% |
| 126 |
% In |manyfoot| package, you can separate footnote levels |
| 127 |
% with custom footnote rules. In this package we provide two ways for |
| 128 |
% creation such rules. All footnote rules should follow the following |
| 129 |
% contract: they must be prepared as |\hrule| or |\hbox|; the total height |
| 130 |
% of rule or box must be compensated with kerns. Usually a negative |
| 131 |
% kern is inserted before a footnote rule and a nonnegative kern is |
| 132 |
% inserted after the rule. The sum of both kerns and of total height of |
| 133 |
% rule must be equal to zero. We follow this contract in footnote rules |
| 134 |
% created with this package. |
| 135 |
% |
| 136 |
% In |manyfoot| package, every footnote rule must have a name |
| 137 |
% |\|\meta{prefix}|footnoterule|. So, we need to specify the prefix only |
| 138 |
% when a new footnote rule is constructed. Next that we need to specify is |
| 139 |
% a rule width. If width is omitted, the default width of |0.4\columnwidth| |
| 140 |
% is used. The footnote rule generation commands described below |
| 141 |
% are used in the preamble only. |
| 142 |
% |
| 143 |
% \DescribeMacro\newfootnoterule |
| 144 |
% The command |
| 145 |
% \begin{quote} |
| 146 |
% |\newfootnoterule|\marg{prefix}\oarg{width}\marg{rule code} |
| 147 |
% \end{quote} |
| 148 |
% produces a custom user-defined rule. |
| 149 |
% The \meta{rule code} must be stretchable to the given width. |
| 150 |
% The |\mboxfill| command from the |mboxfill| package is useful in it. |
| 151 |
% Examples: |
| 152 |
% \begin{quote} |
| 153 |
% |\newfootnoterule{starred}{\mboxfill[1.5\width][s]{$*$}}|\\ |
| 154 |
% |\newfootnoterule{dotted}{\mboxfill[2\width][s]{.}}| |
| 155 |
% \end{quote} |
| 156 |
% The |\starredfootnoterule| and |\dottedfootnoterule| commands |
| 157 |
% are created here. They produce the following rules: |
| 158 |
% |
| 159 |
% \vspace{3mm} |
| 160 |
% \starredfootnoterule |
| 161 |
% \dottedfootnoterule |
| 162 |
% |
| 163 |
% \DescribeMacro\newfootnotedashrule |
| 164 |
% The command |
| 165 |
% \begin{quote} |
| 166 |
% |\newfootnotedashrule|\marg{prefix}\oarg{width}\marg{h-pattern}\marg{v-pattern} |
| 167 |
% \end{quote} |
| 168 |
% produces a dash footnote rule. The special case, when \meta{h-pattern} |
| 169 |
% is empty means the solid rule. Examples: |
| 170 |
% \begin{quote} |
| 171 |
% |\newfootnotedashrule{double}{}{.4 1 .4}|\\ |
| 172 |
% |\newfootnotedashrule{dashed}{3 3}{.4}|\\ |
| 173 |
% |\newfootnotedashrule{dotdashed}{4 2 1 2 4 -4}{.6}|\\ |
| 174 |
% |\newfootnotedashrule{ddotdashed}{6 2 1 2 1 2 6 -6}{.6}| |
| 175 |
% \end{quote} |
| 176 |
% The following rules are created here: |
| 177 |
% |\doublefootnoterule|, |\dashedfootnoterule|, |
| 178 |
% |\dotdashedfootnoterule|, and |\ddotdashedfootnoterule|. |
| 179 |
% They produce the following rules: |
| 180 |
% |
| 181 |
% \vspace{2mm}% |
| 182 |
% \doublefootnoterule |
| 183 |
% \dashedfootnoterule |
| 184 |
% \dotdashedfootnoterule |
| 185 |
% \ddotdashedfootnoterule |
| 186 |
% |
| 187 |
% \StopEventually{} |
| 188 |
% |
| 189 |
% \section{The Implementation} |
| 190 |
% |
| 191 |
% The |mboxfill| package is required here: |
| 192 |
% \begin{macrocode} |
| 193 |
%<*package> |
| 194 |
\RequirePackage{mboxfill} |
| 195 |
% \end{macrocode} |
| 196 |
% |
| 197 |
% \begin{macro}{\dashrule} |
| 198 |
% |\dashrule|\oarg{raise}\marg{h-pattern}\marg{v-pattern} |
| 199 |
% \begin{macrocode} |
| 200 |
\newcommand\dashrule{} |
| 201 |
\DeclareRobustCommand*\dashrule[3][\z@]{% |
| 202 |
\setbox\@tempboxa\vbox{}% |
| 203 |
\NCC@composedash{\NCC@vdash{#2}}{#3}% |
| 204 |
\setlength\@tempdima{#1}\leavevmode |
| 205 |
\raise\@tempdima\hbox{% |
| 206 |
\vbox to\@tempdimc{\vss\unvbox\@tempboxa\vss}}% |
| 207 |
} |
| 208 |
% \end{macrocode} |
| 209 |
% \end{macro} |
| 210 |
% |
| 211 |
% \begin{macro}{\dashrulefill} |
| 212 |
% |\dashrulefill|\oarg{raise}\oarg{leader-type}\marg{h-pattern}\marg{v-pattern}\\ |
| 213 |
% This command is a composition of the |\mboxfill| and |
| 214 |
% |\dashrule| commands. A trick is applied here: |
| 215 |
% we decrease dash rule width on the value of last space |
| 216 |
% in it and then apply |\mboxfill|. |
| 217 |
% \begin{macrocode} |
| 218 |
\newcommand*\dashrulefill[1][\z@]{% |
| 219 |
\@ifnextchar[{\NCC@dashfill{#1}}{\NCC@dashfill{#1}[]}% |
| 220 |
} |
| 221 |
\def\NCC@dashfill#1[#2]#3#4{% |
| 222 |
\NCC@composedash{}{#3}% |
| 223 |
\advance\@tempdimb-\@tempdimc |
| 224 |
\setbox\@tempboxa\hb@xt@-\@tempdimb |
| 225 |
{\hss\dashrule[#1]{#3}{#4}\hss}% |
| 226 |
\mboxfill[\@tempdimc][#2]{\box\@tempboxa}% |
| 227 |
} |
| 228 |
% \end{macrocode} |
| 229 |
% \end{macro} |
| 230 |
% |
| 231 |
% \begin{macro}{\NCC@composedash} |
| 232 |
% |\NCC@composedash|\marg{action}\marg{pattern} parses the pattern |
| 233 |
% and calls the action when a rule size is parsed. At this point, |
| 234 |
% the |\@tempdima| contains a size parsed and |\@tempdimb| contains |
| 235 |
% the previous space. In |\@tempdimc|, the whole rule size is calculated. |
| 236 |
% \begin{macrocode} |
| 237 |
\def\NCC@composedash#1#2{% |
| 238 |
\@tempdimb\z@ % Last space |
| 239 |
\@tempdimc\z@ % Accumulator |
| 240 |
\@tempswatrue % True value means producing an entry |
| 241 |
\NCC@parsedash#2 ! !\@nil{% |
| 242 |
\advance\@tempdimc\@tempdima |
| 243 |
\if@tempswa #1\@tempswafalse \else |
| 244 |
\@tempdimb\@tempdima \@tempswatrue |
| 245 |
\fi |
| 246 |
}% |
| 247 |
} |
| 248 |
% \end{macrocode} |
| 249 |
% \end{macro} |
| 250 |
% |
| 251 |
% \begin{macro}{\NCC@parsedash} |
| 252 |
% Pattern parser: |
| 253 |
% \begin{macrocode} |
| 254 |
\def\NCC@parsedash#1 #2\@nil#3{% |
| 255 |
\if/#1/\else % Empty arg. ignored |
| 256 |
\ifx#1!\else % Exclamation mark ends the list |
| 257 |
\@defaultunits\@tempdima#1pt\relax\@nnil |
| 258 |
#3\NCC@parsedash#2\@nil{#3}% |
| 259 |
\fi |
| 260 |
\fi |
| 261 |
} |
| 262 |
% \end{macrocode} |
| 263 |
% \end{macro} |
| 264 |
% |
| 265 |
% \begin{macro}{\NCC@vdash} |
| 266 |
% |\NCC@vdash|\marg{h-pattern} is |
| 267 |
% applied when a vertical dash is composed. |
| 268 |
% |\@tempdimb| contains the required skip, |
| 269 |
% |\@tempdima| contains the rule height. |
| 270 |
% \begin{macrocode} |
| 271 |
\def\NCC@vdash#1{% |
| 272 |
\setbox\@tempboxa\vbox{% |
| 273 |
\unvbox\@tempboxa \vskip\@tempdimb |
| 274 |
\setbox\@tempboxa\hbox{}% |
| 275 |
\@tempskipa\@tempdima % Save rule height in \@tempskipa |
| 276 |
\NCC@composedash{\NCC@hdash}{#1}% |
| 277 |
\hb@xt@\@tempdimc{\hss\unhbox\@tempboxa\hss}% |
| 278 |
}% |
| 279 |
} |
| 280 |
% \end{macrocode} |
| 281 |
% \end{macro} |
| 282 |
% |
| 283 |
% \begin{macro}{\NCC@hdash} |
| 284 |
% This action is applied when a horizontal dash is composed. |
| 285 |
% |\@tempdimb| contains the required skip, |
| 286 |
% |\@tempdima| contains the rule width, |
| 287 |
% |\@tempskipa| contains the rule height. |
| 288 |
% \begin{macrocode} |
| 289 |
\def\NCC@hdash{% |
| 290 |
\setbox\@tempboxa\hbox{% |
| 291 |
\unhbox\@tempboxa \kern\@tempdimb |
| 292 |
\vrule \@width\@tempdima \@height\@tempskipa |
| 293 |
}% |
| 294 |
} |
| 295 |
% \end{macrocode} |
| 296 |
% \end{macro} |
| 297 |
% |
| 298 |
% \begin{macro}{\NCC@fnoterule} |
| 299 |
% |\NCC@fnoterule|\marg{width}\marg{rule code}\\ |
| 300 |
% This is the footnote rule producing command. |
| 301 |
% As usual, two kerns must be inserted surround the rule: a negative |
| 302 |
% kern before the rule and a nonnegative kern after the rule. |
| 303 |
% The sum of kern values and of the total rule height must |
| 304 |
% vanish. Kerns are calculated in such a way to vertically center |
| 305 |
% the rule relative to 2.8pt distance top to the current position. |
| 306 |
% If the total height of rule is greater than 5.6pt, the rule is moved |
| 307 |
% up on the total rule height (the kern after the rule is zero in this case). |
| 308 |
% \begin{macrocode} |
| 309 |
\def\NCC@fnoterule#1#2{% |
| 310 |
\setlength\@tempdima{#1}% |
| 311 |
\setbox\@tempboxa\hb@xt@\@tempdima{#2}% |
| 312 |
\@tempdima\ht\@tempboxa \advance\@tempdima\dp\@tempboxa |
| 313 |
\@tempdimb 2.8\p@ \@tempdimc .5\@tempdima |
| 314 |
\ifdim\@tempdimc>\@tempdimb \@tempdimb\@tempdimc \fi |
| 315 |
\advance\@tempdimb\@tempdimc |
| 316 |
\kern-\@tempdimb |
| 317 |
\box\@tempboxa |
| 318 |
\advance\@tempdimb -\@tempdima |
| 319 |
\kern\@tempdimb |
| 320 |
} |
| 321 |
% \end{macrocode} |
| 322 |
% \end{macro} |
| 323 |
% |
| 324 |
% \begin{macro}{\NCC@fnotedashrule} |
| 325 |
% |\NCC@fnotedashrule|\marg{width}\marg{h-pattern}\marg{v-pattern}\\ |
| 326 |
% Produces the rule based on |\dashrulefill|. A special case of empty |
| 327 |
% \meta{h-pattern} means the solid (maybe multi-line) rule. |
| 328 |
% \begin{macrocode} |
| 329 |
\def\NCC@fnotedashrule#1#2#3{% |
| 330 |
\NCC@fnoterule{#1}{\def\@tempa{#2}% |
| 331 |
\ifx\@tempa\@empty |
| 332 |
\@tempskipb\@tempdima \dashrule{\@tempskipb}{#3}% |
| 333 |
\else |
| 334 |
\dashrulefill[\z@][s]{#2}{#3}% |
| 335 |
\fi |
| 336 |
}% |
| 337 |
} |
| 338 |
% \end{macrocode} |
| 339 |
% \end{macro} |
| 340 |
% |
| 341 |
% \begin{macro}{\NCC@fnotecreate} |
| 342 |
% |\NCC@fnotecreate|\marg{prefix}\marg{body}\\ |
| 343 |
% Creates a footnote rule whose name is composed from the |
| 344 |
% given \meta{prefix} and |footnoterule|. For example if the prefix |
| 345 |
% is |dashed|, the |\dashedfootnoterule| command will be created. |
| 346 |
% \begin{macrocode} |
| 347 |
\def\NCC@fnotecreate#1{% |
| 348 |
\edef\@tempa{\noexpand\newcommand*% |
| 349 |
\expandafter\noexpand\csname #1footnoterule\endcsname}% |
| 350 |
\@tempa |
| 351 |
} |
| 352 |
\@onlypreamble\NCC@fnotecreate |
| 353 |
% \end{macrocode} |
| 354 |
% \end{macro} |
| 355 |
% |
| 356 |
% \begin{macro}{\NCC@fnoteprepare} |
| 357 |
% |\NCC@fnoteprepare|\marg{driver}\marg{prefix}\oarg{width}\\ |
| 358 |
% Prepares a footnote rule command. The \meta{driver} is a command |
| 359 |
% that will be called for collecting rule code (it gets more arguments |
| 360 |
% from the input). When a driver prepares the code, it calls the |
| 361 |
% |\NCC@fnotecreate| command. If \meta{width} is omitted, the standard |
| 362 |
% width of |0.4\columnwidth| is used. |
| 363 |
% \begin{macrocode} |
| 364 |
\def\NCC@fnoteprepare#1#2{% |
| 365 |
\@ifnextchar[{#1{#2}}{#1{#2}[.4\columnwidth]}% |
| 366 |
} |
| 367 |
\@onlypreamble\NCC@fnoteprepare |
| 368 |
% \end{macrocode} |
| 369 |
% \end{macro} |
| 370 |
% |
| 371 |
% Footnote rule creation driver has the following syntax: |
| 372 |
% \begin{quote} |
| 373 |
% |\|\meta{driver}\marg{prefix}\oarg{width}\meta{more arguments} |
| 374 |
% \end{quote} |
| 375 |
% |
| 376 |
% \begin{macro}{\newfootnoterule} |
| 377 |
% |\newfootnoterule|\marg{prefix}\oarg{width}\marg{rule code} |
| 378 |
% \begin{macrocode} |
| 379 |
\newcommand\newfootnoterule{\NCC@fnoteprepare\NCC@fnotedriver} |
| 380 |
\def\NCC@fnotedriver#1[#2]#3{% |
| 381 |
\NCC@fnotecreate{#1}{\NCC@fnoterule{#2}{#3}}% |
| 382 |
} |
| 383 |
\@onlypreamble\newfootnoterule |
| 384 |
\@onlypreamble\NCC@fnotedriver |
| 385 |
% \end{macrocode} |
| 386 |
% \end{macro} |
| 387 |
% |
| 388 |
% \begin{macro}{\newfootnotedashrule} |
| 389 |
% |\newfootnotedashrule|\marg{prefix}\oarg{width}\marg{h-pattern}\marg{v-pattern} |
| 390 |
% \begin{macrocode} |
| 391 |
\newcommand\newfootnotedashrule{\NCC@fnoteprepare\NCC@fnotedashdriver} |
| 392 |
\def\NCC@fnotedashdriver#1[#2]#3#4{% |
| 393 |
\NCC@fnotecreate{#1}{\NCC@fnotedashrule{#2}{#3}{#4}}% |
| 394 |
} |
| 395 |
\@onlypreamble\newfootnotedashrule |
| 396 |
\@onlypreamble\NCC@fnotedashdriver |
| 397 |
%</package> |
| 398 |
% \end{macrocode} |
| 399 |
% \end{macro} |
| 400 |
\endinput |