Debian Codegraph @

texmf-dist/source/latex/tools/hhline.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1993-2025
4 %
5 % The LaTeX Project and any individual authors listed elsewhere
6 % in this file.
7 %
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
10 %
11 % It may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either version 1.3c
13 % of this license or (at your option) any later version.
14 % The latest version of this license is in
15 % https://www.latex-project.org/lppl.txt
16 % and version 1.3c or later is part of all distributions of LaTeX
17 % version 2005/12/01 or later.
18 %
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
21 %
22 % \fi
23 % \iffalse
24 %% File: hhline.dtx Copyright (C) 1991-1994 David Carlisle
25 %
26 %<package>\NeedsTeXFormat{LaTeX2e}
27 %<package>\ProvidesPackage{hhline}
28 %<package> [2020/01/04 v2.04 Table rule package (DPC)]
29 %
30 %<*driver>
31 \documentclass{ltxdoc}
32 \usepackage{hhline}
33 \GetFileInfo{hhline.sty}
34 \begin{document}
35 \title{The \textsf{hhline} package\thanks{This file
36 has version number \fileversion, last
37 revised \filedate.}}
38 \author{David Carlisle}
39 \date{\filedate}
40 \MaintainedByLaTeXTeam{tools}
41 \maketitle
42 \DeleteShortVerb{\|}
43 \DocInput{hhline.dtx}
44 \end{document}
45 %</driver>
46 % \fi
47 %
48 %
49 % \changes{v1.00}{1991/06/04}{Initial Version}
50 % \changes{v2.00}{1991/11/06}
51 % {Add tilde which allows \cmd\cline-like constructions.}
52 % \changes{v2.01}{1992/06/26}
53 % {Re-issue for the new doc and docstrip.}
54 % \changes{v2.02}{1994/03/14}
55 % {Update for LaTeX2e.}
56 % \changes{v2.03}{1994/05/23}
57 % {New style warning.}
58 % \changes{v2.04}{2020/01/04}
59 % {Ignore spaces.}
60 %
61 %
62 %
63 % \MakeShortVerb{\"}
64 %
65 % \begin{abstract}
66 % "\hhline" produces a line like "\hline", or a double line like
67 % "\hline\hline", except for its interaction with vertical lines.
68 % \end{abstract}
69 %
70 % \arrayrulewidth=1pt
71 % \doublerulesep=3pt
72 %
73 % \section{Introduction}
74 % The argument to "\hhline" is similar to the preamble of an {\tt
75 % array} or {\tt tabular}. It consists of a list of tokens with the
76 % following meanings:
77 % \[
78 % \begin{tabular}{cl}
79 % "=" & A double hline the width of a column.\\
80 % "-" & A single hline the width of a column.\\[10pt]
81 % "~" & A column with no hline.\\[10pt]
82 %
83 % "|" & A vline which `cuts' through a double (or single) hline.\\
84 % ":" & A vline which is broken by a double hline.\\[10pt]
85 %
86 % "#" & A double hline segment between two vlines.\\
87 % "t" & The top half of a double hline segment.\\
88 % "b" & The bottom half of a double hline segment.\\
89 %
90 % "*" & "*{3}{==#}" expands to "==#==#==#",
91 % as in the {\tt*}-form for the preamble.
92 % \end{tabular}
93 % \]
94 % If a double vline is specified ("||" or "::") then the hlines
95 % produced by "\hhline" are broken. To obtain the effect of an hline
96 % `cutting through' the double vline, use a "#" or omit the vline
97 % specifiers, depending on whether or not you wish the double vline to
98 % break.
99 %
100 % The tokens {\tt t} and {\tt b} must be used between two vertical
101 % rules. "|tb|" produces the same lines as "#", but is much less
102 % efficient. The main use for these are to make constructions like
103 % "|t:" (top left corner) and ":b|" (bottom right corner).
104 %
105 % If "\hhline" is used to make a single hline, then the argument
106 % should only contain the tokens "-", "~" and "|" (and
107 % {\tt*}-expressions).
108 %
109 % An example using most of these features is:
110 % \[
111 % \vcenter{\hsize=2in\begin{verbatim}
112 % \begin{tabular}{||cc||c|c||}
113 % \hhline{|t:==:t:==:t|}
114 % a&b&c&d\\
115 % \hhline{|:==:|~|~||}
116 % 1&2&3&4\\
117 % \hhline{#==#~|=#}
118 % i&j&k&l\\
119 % \hhline{||--||--||}
120 % w&x&y&z\\
121 % \hhline{|b:==:b:==:b|}
122 % \end{tabular}
123 % \end{verbatim}
124 % }
125 % \qquad
126 % \begin{tabular}{||cc||c|c||}
127 % \hhline{|t:==:t:==:t|}
128 % a&b&c&d\\
129 % \hhline{|:==:|~|~||}
130 % 1&2&3&4\\
131 % \hhline{#==#~|=#}
132 % i&j&k&l\\
133 % \hhline{||--||--||}
134 % w&x&y&z\\
135 % \hhline{|b:==:b:==:b|}
136 % \end{tabular}
137 % \]
138 %
139 % The lines produced by \LaTeX's "\hline" consist of a single (\TeX\
140 % primitive) "\hrule". The lines produced by "\hhline" are made
141 % up of lots of small line segments. \TeX\ will place these very
142 % accurately in the {\tt .dvi} file, but the program that you use to
143 % print the {\tt .dvi} file may not line up these segments exactly. (A
144 % similar problem can occur with diagonal lines in the {\tt picture}
145 % environment.)
146 %
147 % If this effect causes a problem, you could try a different driver
148 % program, or if this is not possible, increasing "\arrayrulewidth"
149 % may help to reduce the effect.
150 %
151 % \MaybeStop{}
152 %
153 % \section{The Macros}
154 %
155 % \begin{macrocode}
156 %<*package>
157 % \end{macrocode}
158 %
159 % \begin{macro}{\HH@box}
160 % Makes a box containing a double hline segment. The most common case,
161 % both rules of length "\doublerulesep" will be stored in "\box1", this
162 % is not initialised until "\hhline" is called as the user may change
163 % the parameters "\doublerulesep" and "\arrayrulewidth". The two
164 % arguments to "\HH@box" are the widths (ie lengths) of the top and
165 % bottom rules.
166 % \begin{macrocode}
167 \def\HH@box#1#2{\vbox{%
168 \hrule \@height \arrayrulewidth \@width #1
169 \vskip \doublerulesep
170 \hrule \@height \arrayrulewidth \@width #2}}
171 % \end{macrocode}
172 % \end{macro}
173 %
174 % \begin{macro}{\HH@add}
175 % Build up the preamble in the register "\toks@".
176 % \begin{macrocode}
177 \def\HH@add#1{\toks@\expandafter{\the\toks@#1}}
178 % \end{macrocode}
179 % \end{macro}
180
181 % \begin{macro}{\HH@xexpast}
182 % \begin{macro}{\HH@xexnoop}
183 % We `borrow' the version of "\@xexpast" from Mittelbach's array.sty,
184 % as this allows "#" to appear in the argument list.
185 % \begin{macrocode}
186 \def\HH@xexpast#1*#2#3#4\@@{%
187 \@tempcnta #2
188 \toks@={#1}\@temptokena={#3}%
189 \let\the@toksz\relax \let\the@toks\relax
190 \def\@tempa{\the@toksz}%
191 \ifnum\@tempcnta >0 \@whilenum\@tempcnta >0\do
192 {\edef\@tempa{\@tempa\the@toks}\advance \@tempcnta \m@ne}%
193 \let \@tempb \HH@xexpast \else
194 \let \@tempb \HH@xexnoop \fi
195 \def\the@toksz{\the\toks@}\def\the@toks{\the\@temptokena}%
196 \edef\@tempa{\@tempa}%
197 \expandafter \@tempb \@tempa #4\@@}
198
199 \def\HH@xexnoop#1\@@{}
200 % \end{macrocode}
201 % \end{macro}
202 % \end{macro}
203 %
204 % \begin{macro}{\hhline}
205 % Use a simplified version of "\@mkpream" to break apart the argument
206 % to "\hhline". Actually it is oversimplified, It assumes that the
207 % vertical rules are at the end of the column. If you were to specify
208 % "c|@{xx}|" in the array argument, then "\hhline" would not be
209 % able to access the first vertical rule. (It ought to have an "@"
210 % option, and add "\leaders" up to the width of a box containing the
211 % "@"-expression. We use a loop made with "\futurelet" rather
212 % than "\@tfor" so that we can use "#" to denote the crossing of
213 % a double hline with a double vline.\\
214 % "\if@firstamp" is true in the first column and false otherwise.\\
215 % "\if@tempswa" is true if the previous entry was a vline
216 % (":", "|" or "#").
217 % \begin{macrocode}
218 \def\hhline#1{\omit\@firstamptrue\@tempswafalse
219 % \end{macrocode}
220 % Put two rules of width "\doublerulesep" in "\box1"
221 % \begin{macrocode}
222 \global\setbox\@ne\HH@box\doublerulesep\doublerulesep
223 % \end{macrocode}
224 % If Mittelbach's {\tt array.sty} is loaded, we do not need the negative
225 % "\hskip"'s around vertical rules.
226 % \begin{macrocode}
227 \xdef\@tempc{\ifx\extrarowheight\HH@undef\hskip-.5\arrayrulewidth\fi}%
228 % \end{macrocode}
229 % Now expand the {\tt*}-forms and add dummy tokens ( "\relax" and
230 % "`" ) to either end of the token list. Call "\HH@let" to start
231 % processing the token list.
232 % \begin{macrocode}
233 \HH@xexpast\relax#1*0x\@@\toks@{}\expandafter\HH@let\@tempa`}
234 % \end{macrocode}
235 % \end{macro}
236
237 % \begin{macro}{\HH@let}
238 % Discard the last token, look at the next one.
239 % \begin{macrocode}
240 \def\HH@let#1{\futurelet\@tempb\HH@loop}
241 % \end{macrocode}
242 % \end{macro}
243
244 % \begin{macro}{\HH@loop}
245 % The main loop. Note we use "\ifx" rather than "\if" in
246 % version~2 as the new token "~" is active.
247 % \begin{macrocode}
248 \def\HH@loop{%
249 % \end{macrocode}
250 % If next token is "`", stop the loop and put the lines into this row
251 % of the alignment.
252 % \begin{macrocode}
253 \ifx\@tempb`\def\next##1{\the\toks@\cr}\else\let\next\HH@let
254 % \end{macrocode}
255 % "|", add a vertical rule (across either a double or
256 % single hline).
257 % \begin{macrocode}
258 \ifx\@tempb|\if@tempswa\HH@add{\hskip\doublerulesep}\fi\@tempswatrue
259 \HH@add{\@tempc\vline\@tempc}\else
260 % \end{macrocode}
261 % ":", add a broken vertical rule (across a double hline).
262 % \begin{macrocode}
263 \ifx\@tempb:\if@tempswa\HH@add{\hskip\doublerulesep}\fi\@tempswatrue
264 \HH@add{\@tempc\HH@box\arrayrulewidth\arrayrulewidth\@tempc}\else
265 % \end{macrocode}
266 % "#", add a double hline segment between two vlines.
267 % \begin{macrocode}
268 \ifx\@tempb##\if@tempswa\HH@add{\hskip\doublerulesep}\fi\@tempswatrue
269 \HH@add{\@tempc\vline\@tempc\copy\@ne\@tempc\vline\@tempc}\else
270 % \end{macrocode}
271 % "~", A column with no hline (this gives an effect similar to
272 % \verb+\cline+).
273 % \begin{macrocode}
274 \ifx\@tempb~\@tempswafalse
275 \if@firstamp\@firstampfalse\else\HH@add{&\omit}\fi
276 \HH@add{\hfil}\else
277 % \end{macrocode}
278 % "-", add a single hline across the column.
279 % \begin{macrocode}
280 \ifx\@tempb-\@tempswafalse
281 \if@firstamp\@firstampfalse\else\HH@add{&\omit}\fi
282 \HH@add{\leaders\hrule\@height\arrayrulewidth\hfil}\else
283 % \end{macrocode}
284 % "=", add a double hline across the column.
285 % \begin{macrocode}
286 \ifx\@tempb=\@tempswafalse
287 \if@firstamp\@firstampfalse\else\HH@add{&\omit}\fi
288 % \end{macrocode}
289 % Put in as many copies of "\box1" as possible with
290 % "\leaders", this may leave gaps at the ends, so put an extra box
291 % at each end, overlapping the "\leaders".
292 % \begin{macrocode}
293 \HH@add
294 {\rlap{\copy\@ne}\leaders\copy\@ne\hfil\llap{\copy\@ne}}\else
295 % \end{macrocode}
296 % "t", add the top half of a double hline segment, in a "\rlap"
297 % so that it may be used with {\tt b}.
298 % \begin{macrocode}
299 \ifx\@tempb t\HH@add{\rlap{\HH@box\doublerulesep\z@}}\else
300 % \end{macrocode}
301 % "b", add the bottom half of a double hline segment in a "\rlap"
302 % so that it may be used with {\tt t}.
303 % \begin{macrocode}
304 \ifx\@tempb b\HH@add{\rlap{\HH@box\z@\doublerulesep}}\else
305 % \end{macrocode}
306 % "space", Gobble the space and loop again.
307 % \begin{macrocode}
308 \ifx\@tempb\@sptoken\let\next\HH@spacelet\else
309 % \end{macrocode}
310 % Otherwise ignore the token, with a warning.
311 % \begin{macrocode}
312 \PackageWarning{hhline}%
313 {\meaning\@tempb\space ignored in \noexpand\hhline argument%
314 \MessageBreak}%
315 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
316 % \end{macrocode}
317 % Go around the loop again.
318 % \begin{macrocode}
319 \next}
320 % \end{macrocode}
321 % \end{macro}
322 %
323 % \begin{macro}{\HH@spacelet}
324 % Helper macro to gobble a space token and continue the loop.
325 % \begin{macrocode}
326 \lowercase{\def\HH@spacelet} {\futurelet\@tempb \HH@loop}
327 % \end{macrocode}
328 % \end{macro}
329 %
330 % \begin{macrocode}
331 %</package>
332 % \end{macrocode}
333 %
334 % \Finale
335 \endinput