Debian Codegraph @

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

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