Debian Codegraph @

texmf-dist/source/latex-dev/tools/longtable.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: longtable.dtx Copyright (C) 1990-2020 David Carlisle
25 %
26 %<*dtx>
27 \ProvidesFile{longtable.dtx}
28 %</dtx>
29 %<package>\NeedsTeXFormat{LaTeX2e}[1995/06/01]
30 %<package>
31 % Try the 2020 version for any rollback before that date:
32 %<package>\DeclareRelease{}{1994-06-01}{longtable-2020-01-07.sty}
33 %<package>
34 %<package>\DeclareRelease{v4.13}{2020-01-02}{longtable-2020-01-07.sty}
35 %<package>\DeclareCurrentRelease{}{2020-02-07}
36 %<package>
37 %<package>\ProvidesPackage{longtable}
38 %<driver> \ProvidesFile{longtable.drv}
39 % \fi
40 % \ProvidesFile{longtable.dtx}
41 [2026-01-28 v4.27 Multi-page Table package (DPC)]
42 %
43 % \iffalse
44 %<*driver>
45 \documentclass{ltxdoc}
46 \usepackage{longtable}
47 \begin{document}
48 \DocInput{longtable.dtx}
49 \end{document}
50 %</driver>
51 % \fi
52 %
53 % \GetFileInfo{longtable.dtx}
54 % \title{The \textsf{longtable} package\thanks{This file
55 % has version number \fileversion, last
56 % revised \filedate.}}
57 % \author{David Carlisle\thanks{The new algorithm for aligning `chunks'
58 % of a table used in version 4 of this package was devised, coded
59 % and documented by David Kastrup.}}
60 % \date{\filedate}
61 %
62 % \let\package\textsf
63 % \let\env\textsf
64 % \providecommand\finalclearpage{\clearpage}
65 %
66 % \MaintainedByLaTeXTeam{tools}
67 % \maketitle
68 %
69 % \begin{abstract}
70 % This package defines the \env{longtable} environment, a multi-page
71 % version of \env{tabular}.
72 % \end{abstract}
73 %
74 % \DeleteShortVerb{\|}
75 % \MakeShortVerb{\"}
76 %
77 % \changes{v0.00}{1989/11/06}
78 % {`Version 0' distributed as longtab.sty
79 % always used just one chunk for the whole table}
80 %
81 % \changes{v1.00}{1990/12/20}
82 % {Initial version}
83 %
84 % \changes{v2.00}{1991/06/17}
85 % {Support NFSS and array.sty}
86 %
87 % \changes{v3.00}{1992/03/16}
88 % {New implementation. tables may now start anywhere on the page.}
89 %
90 % \changes{v3.01}{1992/04/06}
91 % {(Michel Goossens) If a chunk ends on a line in which the first
92 % entry is empty, weird errors occur. Added special begin and end
93 % groups, (\cs{ifnum}0 ) stuff as explained in Appendix D.}
94 %
95 % \changes{v3.02}{1992/04/09}
96 % {(Michel Goossens) Longtable fails if the table counter is reset
97 % during a document. Now use an internal counter, but still
98 % increment table so \cs{caption} and \cs{label} work out right.}
99 %
100 % \changes{v3.03}{1992/06/25}
101 % {Add \cs{@ifundefined\{reset@font\}} so that the documentation may
102 % be processed with old versions of \LaTeX.}
103 % \changes{v3.03}{1992/06/25}
104 % {Modify the treatment of \cs{d@llar} to match the new versions of
105 % Mittelbach's array.sty (array.sty v2.0h)}
106 %
107 % \changes{v3.04}{1992/11/12}
108 % {(Jean-Pierre Drucbert) Longtable failed when used with
109 % \cs{includeonly}.}
110 % \changes{v3.04}{1992/11/12}
111 % {Fix bug which stopped \cs{kill} working correctly in headings.}
112 % \changes{v3.04}{1992/11/12}
113 % {(Graham Gough) Made \cs{setlongtables} issue a warning message.}
114 % \changes{v3.04}{1992/11/12}
115 % {(Sebastian Rahtz) longtable ran out of memory on really long
116 % tables. Another bug introduced in V3.}
117 %
118 % \changes{v3.05}{1992/11/20}
119 % {(Juergen Peus) Table was hard coded into the captions, Now the
120 % captions use \cs{fnum@table}, so \cs{tablename} will be used.}
121 %
122 % \changes{v3.06}{1993/01/21}
123 % {(Ingo Hoffmann) longtable fails with letter style.
124 % The table counter is not defined, and the .aux file is not used in
125 % the same way. This version will use a .lta file for letter style.}
126 %
127 % \changes{v3.07}{1993/06/09}
128 % {Allow the \LaTeX\ syntax \cs{setcounter}\{LTchunksize\}\{10\}}
129 %
130 % \changes{v3.08}{1993/06/09}
131 % {Update for \LaTeXe}
132 %
133 % \changes{v3.09}{1994/03/15}
134 % {New ltxdoc style}
135 %
136 % \changes{v3.11}{1994/05/22}
137 % {Option handling added, new style errors and warnings}
138 %
139 % \changes{v3.12}{1994/06/30}
140 % {Remove special letter class handling from v3.06, not needed for
141 % new letter class}
142 %
143 % \changes{v4.00}{1996/04/08}
144 % {(DK) New algorithm to align chunks devised and coded by David
145 % Kastrup}
146 %
147 % \changes{v4.02}{1996/04/16}
148 % {(DPC/DK) documentation improvements}
149 %
150 % \changes{v4.06}{1997/06/28}
151 % {(DK) new email address}
152 %
153 %
154 %
155 % \makeatletter
156 % \def\@oddfoot{\normalfont\rmfamily\dotfill Page \thepage\dotfill}
157 % \def\@oddhead{\dotfill{\normalfont\ttfamily longtable.sty}\dotfill}
158 % \def\ps@titlepage{\let\@oddhead\@empty}
159 % \makeatother
160 %
161 %
162 % \setlength\LTleft\parindent
163 % \setlength\LTright\fill
164 % \setcounter{LTchunksize}{10}
165 %
166 % \def\v{\char`}
167 %
168 % ^^A \vbox to 100pt makes the page breaks the same on the first run.
169 % \changes{v3.08}{1993/06/09}
170 % {No need to use \cs{vbox} with \LaTeXe\ minipage}
171 % \noindent\begin{minipage}[t][130pt]{\textwidth}
172 % \listoftables
173 % \end{minipage}
174 %
175 % \section{Introduction}
176 %
177 % The \package{longtable} package defines a new environment,
178 % \DescribeEnv{longtable}
179 % \env{longtable}, which has most of the features of the \env{tabular}
180 % environment, but produces tables which may be broken by \TeX's
181 % standard page-breaking algorithm. It also shares some features with
182 % the \env{table} environment. In particular it uses by default the same counter,
183 % \texttt{table}, and has a similar "\caption" command. Also, the
184 % standard "\listoftables" command lists tables produced by either the
185 % \env{table} or \env{longtable} environments.
186 %
187 % The following example uses most of the features of the \env{longtable}
188 % environment. An edited listing of the input for this example appears
189 % in Section~\ref{listing}.
190 %
191 % \textbf{Note:} Various parts of the following table will
192 % \textbf{not} line up correctly until this document has been run
193 % through \LaTeX\ several times. This is a characteristic feature of
194 % this package, as described below.
195 %
196 % \begin{longtable}{@{*}r||p{1in}@{*}}
197 % KILLED & LINE!!!! \kill
198 % \caption
199 % [An optional table caption (used in the list of tables)]
200 % {A long table\label{long}}\\
201 % \hline\hline
202 % \multicolumn{2}{@{*}c@{*}}%
203 % {This part appears at the top of the table}\\
204 % \textsc{First}&\textsc{Second}\\
205 % \hline\hline
206 % \endfirsthead
207 % \caption[]{(continued)}\\
208 % \hline\hline
209 % \multicolumn{2}{@{*}c@{*}}%
210 % {This part appears at the top of every other page}\\
211 % \textbf{First}&\textbf{Second}\\
212 % \hline\hline
213 % \endhead
214 % \hline
215 % This goes at the&bottom.\\
216 % \hline
217 % \endfoot
218 % \hline
219 % These lines will&appear\\
220 % in place of the & usual foot\\
221 % at the end& of the table\\
222 % \hline
223 % \endlastfoot
224 % \env{longtable} columns are specified& in the \\
225 % same way as in the \env{tabular}& environment.\\
226 % "@{*}r||p{1in}@{*}"& in this case.\\
227 % Each row ends with a& "\\" command.\\
228 % The "\\" command has an& optional\\
229 % argument, just as in& the\\
230 % \env{tabular}&environment.\\[10pt]
231 % See the effect of "\\[10pt]"&?\\
232 % Lots of lines& like this.\\
233 % Lots of lines& like this.\\
234 % Lots of lines& like this.\\
235 % Lots of lines& like this.\\
236 % Also "\hline" may be used,& as in \env{tabular}.\\
237 % \hline
238 % That was a "\hline"&.\\
239 % \hline\hline
240 % That was "\hline\hline"&.\\
241 % \multicolumn{2}{||c||}%
242 % {This is a \ttfamily\v\\multicolumn\v{2\v}\v{||c||\v}}\\
243 % If a page break occurs at a "\hline" then& a line is drawn\\
244 % at the bottom of one page and at the& top of the next.\\
245 % \hline
246 % The "[t] [b] [c]" argument of \env{tabular}& can not be used.\\
247 % The optional argument may be one of& "[l] [r] [c]"\\
248 % to specify whether the table should be& adjusted\\
249 % to the left, right& or centrally.\\
250 % \hline\hline
251 % Lots of lines& like this.\\
252 % Lots of lines& like this.\\
253 % Lots of lines& like this.\\
254 % Lots of lines& like this.\\
255 % Lots of lines& like this.\\
256 % Lots of lines& like this.\\
257 % Lots of lines& like this.\\
258 % Lots of lines& like this.\\
259 % Lots of lines& like this.\\
260 % Lots of lines& like this.\\
261 % Lots of lines& like this.\\
262 % Lots of lines& like this.\\
263 % Lots of lines& like this.\\
264 % Lots of lines& like this.\\
265 % Lots of lines& like this.\\
266 % Lots of lines& like this.\\
267 % Lots of lines& like this.\\
268 % Lots of lines& like this.\\
269 % Lots of lines& like this.\\
270 % Lots of lines& like this.\\
271 % Some lines may take up a lot of space, like this: &
272 % \raggedleft This last column is a ``p'' column so this
273 % ``row'' of the table can take up several lines. Note however that
274 % \TeX\ will never break a page within such a row. Page breaks only
275 % occur between rows of the table or at "\hline" commands.
276 % \tabularnewline
277 % Lots of lines& like this.\\
278 % Lots of lines& like this.\\
279 % Lots of lines& like this.\\
280 % Lots of lines& like this.\\
281 % Lots of lines& like this.\\
282 % Lots of lines& like this.\\
283 % Lots of lines& like this.\\
284 % \hline
285 % Lots\footnote{This is a footnote.} of lines& like this.\\
286 % Lots of lines& like this\footnote{\env{longtable} takes special
287 % precautions, so that footnotes may also be used in `p' columns.}\\
288 % \hline
289 % Lots of lines& like this.\\
290 % Lots of lines& like this.
291 % \end{longtable}
292 %
293 % \section{Chunk Size}
294 %
295 % \DescribeMacro{LTchunksize}
296 % In order to \TeX\ multi-page tables, it is necessary to break up the
297 % table into smaller chunks, so that \TeX\ does not have to keep
298 % everything in memory at one time. By default \env{longtable} uses 20
299 % rows per chunk, but this can be set by the user, with e.g.,
300 % "\setcounter{LTchunksize}{10}".\footnote
301 % {You can also use the plain \TeX\ syntax
302 % {\ttfamily\v\\LTchunksize=10.}}
303 % These chunks do not affect page breaking,
304 % thus if you are using a \TeX\ with a lot of memory, you can set
305 % "LTchunksize" to be several pages of the table. \TeX\ will run
306 % faster with a large "LTchunksize". However, if necessary,
307 % \env{longtable} can work with "LTchunksize" set to 1, in which case
308 % the memory taken up is negligible.
309 % Note that if you use the commands for setting the table head or foot
310 % (see below), the "LTchunksize" must be at least as large as the
311 % number of rows in each of the head or foot sections.
312 %
313 % This document specifies "\setcounter{LTchunksize}{200}". If you look
314 % at the previous table, after the \emph{first} run of \LaTeX\ you will
315 % see that various parts of the table do not line up.
316 % \LaTeX\ will also have printed a warning that the column
317 % widths had changed. \env{longtable} writes information onto the
318 % ".aux" file, so that it can line up the different chunks.
319 % Prior to version~4 of this package, this information was not used
320 % unless a "\setlongtables" command was issued, however, now the
321 % information is always used, via a new algorithm,\footnote{Due to
322 % David Kastrup.} and so "\setlongtables" is no longer needed. It is
323 % defined (but does nothing) for the benefit of old documents that
324 % use it.
325 %
326 % \begin{table}
327 % \centering
328 % \begin{tabular}{||l|l|l||}
329 % \hline\hline
330 % A&\env{tabular}& environment\\
331 % \hline
332 % within&a floating&\env{table}\\
333 % \hline\hline
334 % \end{tabular}
335 % \caption{A floating table}
336 % \end{table}
337 %
338 % \section{Counter and Caption Types}
339 %
340 % As mentioned in the introduction \env{longtable} uses and updates by default
341 % the \texttt{table} counter, the "\caption" command creates a table caption
342 % which is added to the list of tables.
343 % Packages like \pkg{ltcaption} added more flexibility here by adding the
344 % command "\LTcaptype" which allowed to change the type, e.g. to a listing.
345 % Starting with version 4.21 \pkg{longtable} supports this command directly.
346 % \DescribeMacro{\LTcaptype}%
347 % By redefining this command it is possible to change the counter and caption type.
348 % After "\renewcommand\LTcaptype{"\meta{counter}"}" \env{longtable} will update
349 % the counter \meta{counter}, use "\fnum@"\meta{counter} in the caption (which
350 % typically will make use of "\"\meta{counter}"name" and "\the"\meta{counter}), and
351 % write content line entries into the file with the extension stored in the
352 % command "\ext@"\meta{counter}. When \pkg{hyperref} is loaded the name of
353 % the anchor will use \meta{counter} too. Packages or documents that change
354 % "\LTcaptype" to some nonstandard value must ensure that the counter
355 % \meta{counter} and the commands "\fnum@"\meta{counter}
356 % and "\ext@"\meta{counter} exist and do not error.
357 % If "\LTcaptype" is empty no counter is advanced and "\"\meta{counter}"name" in
358 % the caption is suppressed.
359 %
360 %
361 % \section{Captions and Headings}
362 %
363 % At the start of the table one may specify lines which are to appear at
364 % the top of every page (under the headline, but before the other lines
365 % of the table).
366 % \DescribeMacro{\endhead}
367 % The lines are entered as normal, but the last "\\" command is
368 % replaced by a "\endhead" command.
369 % \DescribeMacro{\endfirsthead}
370 % If the first page should have a different heading, then this should be
371 % entered in the same way, and terminated with the "\endfirsthead"
372 % command. The "LTchunksize" should be at least as large as the
373 % number of rows in the heading.
374 % \DescribeMacro{\endfoot}
375 % There are also "\endfoot" and "\endlastfoot"
376 %\DescribeMacro{\endlastfoot}
377 % commands which are used in the same way (at the \emph{start} of the
378 % table) to specify rows (or an "\hline") to appear at the bottom of
379 % each page. In certain situations, you may want to place lines which
380 % logically belong in the table body at the end of the \env{firsthead},
381 % or the beginning of the \env{lastfoot}. This helps to control which
382 % lines appear on the first and last page of the table.
383 %
384 % \DescribeMacro{\caption}%
385 % The "\caption{...}" command is essentially equivalent to\\
386 % "\multicolumn{n}{c}{\parbox{\LTcapwidth}{...}}"\\
387 % where \texttt{n} is the number of columns of the table. You may set
388 % the width of the caption with a command such as
389 % "\setlength{\LTcapwidth}{2in}"
390 % in the preamble of your document. The default is 4in. "\caption" also
391 % writes the information to produce an entry in the list of tables. As
392 % with the "\caption" command in the \env{figure} and \env{table}
393 % environments, an optional argument specifies the text to appear in the
394 % list of tables if this is different from the text to appear in the
395 % caption. Thus the caption for table \ref{long} was specified as
396 % {\ttfamily
397 % "\caption"[An optional table caption
398 % (used in the list of tables)]\v{A long
399 % table"\label{long}"\v}}.
400 %
401 % You may wish the caption on later pages to be different to that on the
402 % first page. In this case put the "\caption" command in the first
403 % heading, and put a subsidiary caption in a "\caption[]" command in
404 % the main heading. If the optional argument to "\caption" is empty,
405 % no entry is made in the list of tables. Alternatively, if you do not
406 % want the table number to be printed each time, use the "\caption*"
407 % command.
408 %
409 % The captions are set based on the code for the \package{article}
410 % class.
411 % If you have redefined the standard "\@makecaption" command to produce
412 % a different format for the captions, you may
413 % need to make similar changes to the \package{longtable} version,
414 % "\LT@makecaption". See the code section for more details.
415 %
416 % A more convenient method of customising captions is given by the
417 % \package{caption(2)} package, which provides commands for customising
418 % captions, and arranges that the captions in standard environments, and
419 % many environments provided by packages (including \package{longtable})
420 % are modified in a compatible manner.
421 %
422 % You may use the "\label" command so that you can cross reference
423 % \env{longtable}s with "\ref". Note, however, that the "\label" command
424 % should not be used in a heading that may appear more than once. Place
425 % it either in the \env{firsthead}, or in the body of the table. It
426 % should not be the \emph{first} command in any entry.
427 %
428 % \section{Multicolumn entries}
429 %
430 % The "\multicolumn" command may be used in \env{longtable} in exactly
431 % the same way as for \env{tabular}. So you may want to skip this
432 % section, which is rather technical, however coping with "\multicolumn"
433 % is one of the main problems for an environment such as
434 % \env{longtable}. The main effect that a user will see is that
435 % certain combinations of "\multicolumn" entries will result in a
436 % document needing more runs of \LaTeX\ before the various `chunks' of
437 % a table align.
438 %
439 % The examples in this section are set with "LTchunksize" set to the
440 % minimum value of one, to demonstrate the effects when "\multicolumn"
441 % entries occur in different chunks.
442 %
443 % \begin{table}[!htp]
444 % \begin{center}
445 % \LTchunksize=1
446 % \makeatletter
447 %
448 % \global\let\LT@save@row\relax
449 % \let\LT@warn\@gobble
450 % \let\LT@final@warn\relax
451 %
452 % \newcommand\ltexample[1]{
453 % \stepcounter{LT@tables}
454 % \expandafter\let\csname LT@\romannumeral\c@LT@tables\endcsname
455 % \LT@save@row
456 % \addtocounter{LT@tables}{-1}
457 % \begin{longtable}{|c|c|c|}
458 % \caption{A difficult {\cs{multicolumn}} combination:
459 % pass #1\label{pass#1}}\\
460 % \hline
461 % 1&2&3\\
462 % \multicolumn{3}{|c|}{wide multicolumn spanning 1--3}\\
463 % \multicolumn{2}{|c|}{multicolumn 1--2}&3\\
464 % wide 1&2&3\\
465 % \hline
466 % \end{longtable}
467 % }
468 %
469 % \ltexample{1}
470 %
471 % \ltexample{2}
472 %
473 % \ltexample{3}
474 %
475 % \ltexample{4}
476 %
477 % \end{center}
478 % \end{table}
479 %
480 % Consider Table~\ref{pass1}.
481 % In the second chunk, \env{longtable} sees the wide
482 % multicolumn entry. At this point it thinks that the first two
483 % columns are very narrow. All
484 % the width of the multicolumn entry is assumed to be in the
485 % third column. (This is a `feature' of \TeX's primitive "\halign"
486 % command.) \env{longtable} then passes the information that there
487 % is a wide third column to the later chunks, with the result that the
488 % first pass over the table is too wide.
489 %
490 % If the `saved row' from this first pass was re-inserted into the
491 % table on the next pass, the table would line up in two passes, but
492 % would be much two wide.
493 %
494 % \DescribeMacro{\kill}%
495 % The solution to this problem used in Versions 1~and~2, was to use a
496 % "\kill" line. If a line is "\kill"ed, by using "\kill" rather than
497 % "\\" at the end of the line, it is used in calculating
498 % column widths, but removed from the final table. Thus entering
499 % "\kill"ed copies of the last two rows before the wide multicolumn
500 % entry would mean that "\halign" `saw' the wide entries in the first
501 % two columns, and so would not widen the third column by so much to
502 % make room for the multicolumn entry.
503 %
504 % In Version~3, a new solution was introduced. If the saved row in
505 % the ".aux" file was not being used, \env{longtable} used a special
506 % `draft' form of "\multicolumn", this modified the definition, so the
507 % spanning entry was never considered to be wider than the columns it
508 % spanned. So after the first pass, the ".aux" file stored the
509 % widest normal entry for each column, no column was widened due to
510 % "\span"ned columns. By default \env{longtable} ignored the ".aux"
511 % file, and so each run of \LaTeX\ was considered a first pass. Once the
512 % "\setlongtables" declaration was given, the saved row in the ".aux"
513 % file, and the proper definition of "\multicolumn" were used. If any
514 % "\multicolumn" entry caused one of the columns to be widened, this
515 % information could not be passed back to earlier chunks, and so the
516 % table would not correctly line up until the third pass. This algorithm
517 % always converged in three passes as described above, but in examples
518 % such as the ones in Tables \ref{pass1}--\ref{pass4}, the final
519 % widths were not optimal as the width of column~2, which is
520 % determined by a "\multicolumn" entry, was not known when the final
521 % width for column~3 was fixed, due to the fact that \emph{both}
522 % "\multicolumn" commands were switched from `draft' mode to `normal'
523 % mode at the same time.
524 %
525 % Version~4 alleviates the problem considerably.
526 % The first pass of the table will
527 % indeed have the third column much too wide. However, on the next pass
528 % \env{longtable} will notice the error and reduce the column width
529 % accordingly. If this has to propagate to chunks before the
530 % "\multicolumn" one, an additional pass will, of course, be
531 % needed. It is possible to construct tables where this rippling up of
532 % the correct widths takes several passes to `converge' and produce a
533 % table with all chunks aligned. However in
534 % order to need many passes one needs to construct a table with
535 % many overlapping "\multicolumn" entries, all being wider than the
536 % natural widths of the columns they span, and all occurring in
537 % different chunks. In the typical case the algorithm will converge
538 % after three or four passes, and the benefits of not needing to edit
539 % the document before the final run to add "\setlongtables", and the
540 % better choice of final column widths in the case of multiple
541 % "\multicolumn" entries will hopefully more than pay for the extra
542 % passes that may possibly be needed.
543 %
544 % So Table~\ref{pass1} converges after 4~passes, as seen in
545 % Table~\ref{pass4}.
546 %
547 % You can still speed the convergence by introducing judicious "\kill"
548 % lines, if you happen to have constellations like the above.
549 %
550 % If you object even to \LaTeX-ing a file twice, you should
551 % make the first line of
552 % every \env{longtable} a "\kill" line that contains the widest entry
553 % to be used in each column. All chunks will then line up on the first
554 % pass.
555 %
556 % \section{Adjustment}
557 %
558 % The optional argument of \env{longtable} controls the
559 % horizontal alignment of the table. The possible options are "[c]",
560 % "[r]" and "[l]", for centring,
561 % right and left adjustment, respectively.
562 % \DescribeMacro{\LTleft}
563 % Normally centring is the default, but this document specifies
564 % \DescribeMacro{\LTright}
565 %\begin{verbatim}
566 % \setlength\LTleft\parindent
567 % \setlength\LTright\fill
568 %\end{verbatim}
569 % in the preamble,
570 % which means that the tables are set flush left, but
571 % indented by the usual paragraph indentation. Any lengths can be
572 % specified for these two parameters, but at least one of them should be
573 % a rubber length so that it fills up the width of the page, unless
574 % rubber lengths are added between the columns using the
575 % "\extracolsep" command.
576 % For instance
577 %\begin{verbatim}
578 % \begin{tabular*}{\textwidth}{@{\extracolsep{...}}...}
579 %\end{verbatim}
580 % produces a full width table, to get a similar effect with
581 % \env{longtable} specify
582 %\begin{verbatim}
583 % \setlength\LTleft{0pt}
584 % \setlength\LTright{0pt}
585 % \begin{longtable}{@{\extracolsep{...}}...}
586 %\end{verbatim}
587 %
588 % \section{Changes}
589 %
590 % This section highlights the major changes since version~2. A more
591 % detailed change log may be produced at the end of the code listing
592 % if the "ltxdoc.cfg" file specifies
593 %\begin{verbatim}
594 % \AtBeginDocument{\RecordChanges}
595 % \AtEndDocument{\PrintChanges}
596 %\end{verbatim}
597 %
598 % Changes made between versions 2 and 3.
599 % \begin{itemize}
600 % \item The mechanism for adding the head and foot of the table has been
601 % completely rewritten. With this new mechanism, \env{longtable} does
602 % not need to issue a "\clearpage" at the start of the table, and so the
603 % table may start half way down a page. Also the "\endlastfoot" command,
604 % which could not safely be implemented under the old scheme, has been
605 % added.
606 % \item \env{longtable} now issues an error if started in the scope of
607 % "\twocolumn", or the \env{multicols} environment.
608 % \item The separate documentation file "longtable.tex" has been
609 % merged with the package file, "longtable.dtx" using Mittelbach's
610 % \package{doc} package.
611 % \item Support for footnotes has been added. Note however that
612 % "\footnote" will not work in the `head' or `foot' sections of the
613 % table. In order to put a footnote in those sections (e.g., inside a
614 % caption), use "\footnotemark" at that point, and "\footnotetext"
615 % anywhere in the table \emph{body} that will fall on the same page.
616 % \item The treatment of "\multicolumn" has changed, making
617 % "\kill" lines unnecessary, at the price of sometimes requiring a
618 % third pass through \LaTeX.
619 % \item The "\newpage" command now works inside a \env{longtable}.
620 % \end{itemize}
621 %
622 % Changes made between versions 3 and 4.
623 % \begin{itemize}
624 % \item A new algorithm is used for aligning chunks. As well as the
625 % widest width in each column, \package{longtable} remembers which
626 % chunk produced this maximum. This allows it to check that the
627 % maximum is still achieved in later runs. As \package{longtable} can
628 % now deal with columns shrinking as the file is edited, the
629 % "\setlongtables" system is no longer needed and is disabled.
630 %
631 % \item An extra benefit of the new algorithm's ability to deal with
632 % `shrinking' columns is that it can give better (narrower) column
633 % widths in the case of overlapping "\multicolumn" entries in
634 % different chunks than the previous algorithm produced.
635 %
636 % \item The `draft' multicolumn system has been removed, along with
637 % related commands such as "\LTmulticolumn".
638 %
639 % \item The disadvantage of the new algorithm is that it can take more
640 % passes. The theoretical maximum is approximately twice the length
641 % of a `chain' of columns with overlapping "\multicolumn" entries,
642 % although in practice it usually converges as fast as the old
643 % version. (Which always converged in three passes once
644 % "\setlongtables" was activated.)
645 %
646 % \item "\\*" and "\nopagebreak" commands may be used to control page
647 % breaking.
648 %
649 % \end{itemize}
650 %
651 %
652 % \section{Summary}
653 %
654 % ^^A Allow the table to stick into the left margin.
655 % \setlength{\LTleft}{0pt plus 1fill minus 1fill}
656 % \setlength{\LTright}{0pt}
657 %
658 % \begin{longtable}{@{}l@{\hspace{10pt}}p{.8\linewidth}@{}}
659 % \caption[A summary of \env{longtable} commands]%
660 % {\normalsize A summary of \env{longtable} commands}\\
661 % \multicolumn{2}{c}{\textbf{Parameters}}\\*
662 % \hline
663 % "\LTleft"&
664 % Glue to the left of the table. \hfill("\fill")\\
665 % "\LTright"&
666 % Glue to the right of the table. \hfill("\fill")\\
667 % "\LTpre"&
668 % Glue before the table. \hfill("\bigskipamount")\\
669 % "\LTpost"&
670 % Glue after the table. \hfill("\bigskipamount")\\
671 % "\LTcapwidth"&
672 % The width of a parbox containing the caption.\hfill(4in)\\
673 % "LTchunksize"&
674 % The number of rows per chunk. \hfill(20)\\[5pt]
675 % \multicolumn{2}{c}{\textbf{Optional
676 % arguments to} \ttfamily\v\\begin\v{longtable\v}}\\*
677 % \hline
678 % \it none& Position as specified by "\LTleft" and "\LTright".\\
679 % "[c]"& Centre the table.\\
680 % "[l]"& Place the table flush left.\\
681 % "[r]"& Place the table flush right.\\[5pt]
682 % \pagebreak[2]
683 % \multicolumn{2}{c}{\textbf{Commands
684 % to end table rows}}\\*
685 % \hline
686 % "\\"&
687 % Specifies the end of a row\\
688 % "\\"\oarg{dim}& Ends row, then adds vertical space
689 % (as in the \env{tabular} environment).\\
690 % "\\*"&
691 % The same as "\\" but disallows a page break after the row.\\
692 % "\tabularnewline"&
693 % Alternative to "\\" for use in the scope of "\raggedright" and
694 % similar commands that redefine "\\".\\
695 % "\kill"&
696 % Row is `killed', but is used in calculating widths.\\
697 % "\endhead"&
698 % Specifies rows to appear at the top of every page.\\
699 % "\endfirsthead"&
700 % Specifies rows to appear at the top of the first page.\\
701 % "\endfoot"&
702 % Specifies rows to appear at the bottom of every page.\\
703 % "\endlastfoot"&
704 % Specifies rows to appear at the bottom of the last page.\\[5pt]
705 % \multicolumn{2}{c}{\textbf{\env{longtable} caption commands}}\\*
706 % \hline
707 % "\caption"\marg{caption}&
708 % Caption `Table ?: \meta{caption}', and a `\meta{caption}'
709 % entry in the list of tables.\\
710 % "\caption"\oarg{lot}\marg{caption}&
711 % Caption `Table ?: \meta{caption}', and a `\meta{lot}'
712 % entry in the list of tables.\\
713 % "\caption[]"\marg{caption}&
714 % Caption `Table ?: \meta{caption}',
715 % but no entry in the list of tables.\\
716 % "\caption*"\marg{caption}&
717 % Caption `\meta{caption}', but no entry in the list of tables.\\[5pt]
718 % \multicolumn{2}{c}{%^^A
719 % \textbf{Commands available at the start of a row}}\\*
720 % \hline
721 % "\pagebreak"&
722 % Force a page break.\\*
723 % "\pagebreak"\oarg{val}& A `hint' between 0 and 4
724 % of the desirability of a break.\\
725 % "\nopagebreak"& Prohibit a page break.\\*
726 % "\nopagebreak"\oarg{val}& A `hint' between 0 and 4 of the undesirability
727 % of a break.\\
728 % "\newpage"&
729 % Force a page break.\\[5pt]
730 % \multicolumn{2}{c}{\textbf{Footnote commands
731 % available inside \env{longtable}}}\\*
732 % \hline
733 % "\footnote"&
734 % Footnotes, but may not be used in the table head \& foot.\\*
735 % "\footnotemark"&
736 % Footnotemark, may be used in the table head \& foot.\\*
737 % "\footnotetext"&
738 % Footnote text, use in the table body.\\[5pt]
739 % \multicolumn{2}{c}{\textbf{Setlongtables}}\\
740 % \hline
741 % "\setlongtables"& Obsolete command. Does nothing now.
742 % \end{longtable}
743 %
744 %
745 % \finalclearpage
746 % \section{Verbatim highlights from Table \protect\ref{long}}
747 % \label{listing}
748 % \begingroup\catcode`\/=0
749 % \begin{verbatim}
750 % \begin{longtable}{@{*}r||p{1in}@{*}}
751 % KILLED & LINE!!!! \kill
752 % \caption[An optional table caption /ldots]{A long table\label{long}}\\
753 % \hline\hline
754 % \multicolumn{2}{@{*}c@{*}}%
755 % {This part appears at the top of the table}\\
756 % \textsc{First}&\textsc{Second}\\
757 % \hline\hline
758 % \endfirsthead
759 % \caption[]{(continued)}\\
760 % \hline\hline
761 % \multicolumn{2}{@{*}c@{*}}%
762 % {This part appears at the top of every other page}\\
763 % \textbf{First}&\textbf{Second}\\
764 % \hline\hline
765 % \endhead
766 % \hline
767 % This goes at the&bottom.\\
768 % \hline
769 % \endfoot
770 % \hline
771 % These lines will&appear\\
772 % in place of the & usual foot\\
773 % at the end& of the table\\
774 % \hline
775 % \endlastfoot
776 % \env{longtable} columns are specified& in the \\
777 % same way as in the \env{tabular}& environment.\\
778 % /ldots
779 % \multicolumn{2}{||c||}{This is a /ldots}\\
780 % /ldots
781 % Some lines may take/ldots&
782 % \raggedleft This last column is a ``p'' column/ldots
783 % \tabularnewline
784 % /ldots
785 % Lots of lines& like this.\\
786 % /ldots
787 % \hline
788 % Lots\footnote{/ldots} of lines& like this.\\
789 % Lots of lines& like this\footnote{/ldots}\\
790 % \hline
791 % Lots of lines& like this.\\
792 % /ldots
793 % \end{longtable}
794 % \end{verbatim}
795 % \endgroup
796 %
797 % \MaybeStop{}
798 %
799 % \finalclearpage
800 % \section{The Macros}
801 %
802 % \begin{macrocode}
803 %<*package>
804 % \end{macrocode}
805 %
806 % \subsection{Initial code}
807 %
808 % Before declaring the package options, we must define some defaults
809 % here.
810 %
811 % \begin{macro}{\LT@err}
812 % The error generating command
813 % \begin{macrocode}
814 \def\LT@err{\PackageError{longtable}}
815 % \end{macrocode}
816 % \end{macro}
817 %
818 % \begin{macro}{\LT@warn}
819 % The warning generating command
820 % \begin{macrocode}
821 \def\LT@warn{\PackageWarning{longtable}}
822 % \end{macrocode}
823 % \end{macro}
824 %
825 % \begin{macro}{\LT@final@warn}
826 % \changes{v4.04}{1996/05/24}
827 % {Macro added}
828 % If any \env{longtable}s have not aligned, generate a warning at the
829 % end of the run at "\AtEndDocument".
830 % \begin{macrocode}
831 \def\LT@final@warn{%
832 \AtEndDocument{%
833 \LT@warn{Table \@width s have changed. Rerun LaTeX.\@gobbletwo}}%
834 \global\let\LT@final@warn\relax}
835 % \end{macrocode}
836 % \end{macro}
837 %
838 % \subsection{Options}
839 %
840 % The first two options deal with error handling. They are compatible
841 % with the options used by the \texttt{tracefnt} package.
842 %
843 % \begin{macro}{errorshow}
844 % \emph{Only} show errors on the terminal. `warnings' are just sent to
845 % the log file.
846 % \changes{v3.14}{1995/04/25}
847 % {Change string from LT to longtable}
848 % \begin{macrocode}
849 \DeclareOption{errorshow}{%
850 \def\LT@warn{\PackageInfo{longtable}}}
851 % \end{macrocode}
852 % \end{macro}
853 %
854 % \begin{macro}{pausing}
855 % \changes{v3.14}{1995/04/25}
856 % {Change string from LT to longtable}
857 % \changes{v3.15}{1995/06/15}
858 % {Use single hash for latex/1557}
859 % Make every warning message into an error so \TeX\ stops.
860 % May be useful for debugging.
861 % \begin{macrocode}
862 \DeclareOption{pausing}{%
863 \def\LT@warn#1{%
864 \LT@err{#1}{This is not really an error}}}
865 % \end{macrocode}
866 % \end{macro}
867 %
868 % \begin{macro}{set}
869 % \begin{macro}{final}
870 % \changes{v4.01}{1996/04/11}
871 % {(DPC) make set and final options no op}
872 % The next options are just alternative syntax for the
873 % "\setlongtables" declaration.
874 % \begin{macrocode}
875 \DeclareOption{set}{}
876 \DeclareOption{final}{}
877 % \end{macrocode}
878 % \end{macro}
879 % \end{macro}
880 %
881 %
882 % \begin{macrocode}
883 \ProcessOptions
884 % \end{macrocode}
885 %
886 % \subsection{User Settable Parameters}
887 %
888 % \begin{macro}{\LTleft}
889 % \begin{macro}{\LTright}
890 % Glue to the left and right of the table, default "\fill" (ie
891 % centred).
892 % \begin{macrocode}
893 \newskip\LTleft \LTleft=\fill
894 \newskip\LTright \LTright=\fill
895 % \end{macrocode}
896 % \end{macro}
897 % \end{macro}
898 %
899 % \begin{macro}{\LTpre}
900 % \begin{macro}{\LTpost}
901 % Glue before and after the \env{longtable}. "\bigskip" by default.
902 % \begin{macrocode}
903 \newskip\LTpre \LTpre=\bigskipamount
904 \newskip\LTpost \LTpost=\bigskipamount
905 % \end{macrocode}
906 % \end{macro}
907 % \end{macro}
908 %
909 % \begin{macro}{\LTchunksize}
910 % \changes{v4.14}{2020/02/07}
911 % {Increase default chunksize from 20 to 200}
912 % Chunk size (the number of rows taken per "\halign"). Default 200.
913 % \begin{macrocode}
914 \newcount\LTchunksize \LTchunksize=200
915 % \end{macrocode}
916 % \end{macro}
917 %
918 % \begin{macro}{\c@LTchunksize}
919 % Added in V3.07 to allow the \LaTeX\ syntax
920 % "\setcounter{LTchunksize}{10}".
921 % \begin{macrocode}
922 \let\c@LTchunksize\LTchunksize
923 % \end{macrocode}
924 % \end{macro}
925 %
926 % \begin{macro}{\LTcapwidth}
927 % Width of the "\parbox" containing the caption. Default 4in.
928 % \begin{macrocode}
929 \newdimen\LTcapwidth \LTcapwidth=4in
930 % \end{macrocode}
931 % \end{macro}
932 %
933 % \begin{macro}{\LTcaptype}
934 % The name used as counter, in caption, "\addcontentsline" and in targets.
935 % "\providecommand" is used for compability with \pkg{ltcaption}
936 % \changes{v4.21}{2024/07/04}
937 % {Added \cs{LTcaptype} to support other types beside table.}
938 % \begin{macrocode}
939 \providecommand\LTcaptype{table}
940 % \end{macrocode}
941 % \end{macro}
942 % \subsection{Internal Parameters}
943 %
944 % \begin{macro}{\LT@head}
945 % \begin{macro}{\LT@firsthead}
946 % \begin{macro}{\LT@foot}
947 % \begin{macro}{\LT@lastfoot}
948 % Boxes for the table head and foot.
949 % \begin{macrocode}
950 \newbox\LT@head
951 \newbox\LT@firsthead
952 \newbox\LT@foot
953 \newbox\LT@lastfoot
954 % \end{macrocode}
955 % \end{macro}
956 % \end{macro}
957 % \end{macro}
958 % \end{macro}
959 %
960 % \begin{macro}{\LT@gbox}
961 % \changes{v4.14}{2020/02/07}
962 % {global box added (tools/2914)}
963 % \begin{macrocode}
964 \newbox\LT@gbox
965 % \end{macrocode}
966 % \end{macro}
967 %
968 % \begin{macro}{\LT@cols}
969 % Counter for number of columns.
970 % \begin{macrocode}
971 \newcount\LT@cols
972 % \end{macrocode}
973 % \end{macro}
974 %
975 % \begin{macro}{\LT@rows}
976 % Counter for rows up to chunksize.
977 % \begin{macrocode}
978 \newcount\LT@rows
979 % \end{macrocode}
980 % \end{macro}
981 %
982 % \begin{macro}{\c@LT@tables}
983 % Counter for the tables, added in V3.02. Previous versions just used
984 % the \LaTeX\ counter "table", but this fails if "table" is
985 % reset during a document, eg \package{report} class resets it every
986 % chapter.
987 %
988 % This was changed from "\newcount\LT@tables" in V3.04. \LaTeX\ counters
989 % are preserved correctly when "\includeonly" is used. In the rest of
990 % the file "\LT@tables" has been replaced by "\c@LT@tables" without
991 % further comment.
992 % \changes{v4.21}{2024/07/04}
993 % {Provide a \cs{theH}-representation for targets.}
994 % \begin{macrocode}
995 \newcounter{LT@tables}
996 \providecommand\theHLT@tables{\theLT@tables}
997 % \end{macrocode}
998 % \end{macro}
999 %
1000 % \begin{macro}{\c@LT@chunks}
1001 % \changes{v4.00}{1996/04/08}
1002 % {(DK) Chunk counter added}
1003 % We need to count through the chunks of our tables from Version~4 on.
1004 % \begin{macrocode}
1005 \newcounter{LT@chunks}[LT@tables]
1006 % \end{macrocode}
1007 % \end{macro}
1008 %
1009 % \begin{macro}{\c@table}
1010 % \begin{macro}{\fnum@table}
1011 % \begin{macro}{\tablename}
1012 % \begin{macro}{\ext@table}
1013 % \changes{v4.17}{2021/09/01}
1014 % {ensure \cs{ext@table} is defined gh/637}
1015 % If the "table" counter is not defined (eg in "letter" style), define
1016 % it. (Added in V3.06.)
1017 % \begin{macrocode}
1018 \ifx\c@table\undefined
1019 \newcounter{table}
1020 \def\fnum@table{\tablename~\thetable}
1021 \fi
1022 \ifx\tablename\undefined
1023 \def\tablename{Table}
1024 \fi
1025 \ifx\ext@table\undefined
1026 \def\ext@table{lot}
1027 \fi
1028 % \end{macrocode}
1029 % \end{macro}
1030 % \end{macro}
1031 % \end{macro}
1032 % \end{macro}
1033 %
1034 % \begin{macro}{\LT@out}
1035 % In a normal style, "longtable" uses the ".aux" file to record the
1036 % column widths. With "letter.sty", use a separate ".lta" file.
1037 % (Added in V3.06.)
1038 %
1039 % Not needed for new letter class.
1040 %\begin{verbatim}
1041 %\ifx\startlabels\undefined
1042 % \let\@auxout\@auxout
1043 %\else
1044 % {\@input{\jobname.lta}}%
1045 % \newwrite\@auxout
1046 % \immediate\openout\@auxout=\jobname.lta
1047 %\fi
1048 %\end{verbatim}
1049 % \end{macro}
1050 %
1051 % \begin{macro}{\LT@p@ftn}
1052 % Temporary storage for footnote text in a `p' column.
1053 % \begin{macrocode}
1054 \newtoks\LT@p@ftn
1055 % \end{macrocode}
1056 % \end{macro}
1057 %
1058 % \begin{macro}{\LT@end@pen}
1059 % Special penalty for the end of the table. Done this way to save using
1060 % up a count register.
1061 % \begin{macrocode}
1062 \mathchardef\LT@end@pen=30000
1063 % \end{macrocode}
1064 % \end{macro}
1065 %
1066 % \subsection{The \env{longtable} environment}
1067 %
1068 % \begin{macro}{\longtable}
1069 % \changes{v4.17}{2021/09/01}
1070 % {\cs{@nobreakfalse} gh/173 \cs{ifnoskipsec} test for gh/131}
1071 % Called by "\begin{longtable}". This implementation does not work in
1072 % multiple column formats. "\par" added at V3.04.
1073 % \begin{macrocode}
1074 \def\longtable{%
1075 \par
1076 \if@noskipsec\mbox{}\par\fi
1077 \@nobreakfalse
1078 \ifx\multicols\@undefined
1079 \else
1080 \ifnum\col@number>\@ne
1081 \@twocolumntrue
1082 \fi
1083 \fi
1084 \if@twocolumn
1085 \LT@err{longtable not in 1-column mode}\@ehc
1086 \fi
1087 % \end{macrocode}
1088 %
1089 % \changes{v4.19}{2023/12/16}{Support for tagged PDF}
1090 % \begin{macrocode}
1091 \UseTaggingSocket{tbl/vmode/begin}%
1092 % \end{macrocode}
1093 %
1094 % \begin{macrocode}
1095 \begingroup
1096 % \end{macrocode}
1097 % Check for an optional argument.
1098 % \begin{macrocode}
1099 \@ifnextchar[\LT@array{\LT@array[x]}}
1100 % \end{macrocode}
1101 % \end{macro}
1102 %
1103 %
1104 %
1105 % \begin{macro}{\LT@array}
1106 % \begin{macrocode}
1107 %<@@=tbl>
1108 \ExplSyntaxOn
1109 % \end{macrocode}
1110 %
1111 % Start setting the alignment.
1112 % Based on "\@array" from the \LaTeX\ kernel
1113 % and the \package{array} package.
1114 %
1115 % Since Version 3.02, \package{longtable} has used the internal counter
1116 % "\c@LT@tables". The \LaTeX\ counter "table" is still incremented
1117 % so that "\caption" works correctly.
1118 % \changes{v4.21}{2024/07/04}
1119 % {Use \cs{LTcaptype} instead of \texttt{table} in various places
1120 % to support other types beside table.}
1121 % \begin{macrocode}
1122 \def\LT@array[#1]#2{%
1123 % \end{macrocode}
1124 %
1125 % With respect to tagging we have a complicated situation with
1126 % longtable. When at the begin the \cs{endhead},
1127 % \cs{endfirsthead}, \cs{endfoot} and \cs{endlastfoot} are used to
1128 % setup head and foot they create each a structure subtree with one or
1129 % more rows. From these structures we want to keep at most two (head
1130 % and foot) and move the foot to the end of the table. When the head
1131 % and foot boxes are (re)inserted on following pages we want to mark
1132 % them up as artifact with the exception of the head at the begin and
1133 % the foot box at the end.
1134 %
1135 % TODO: When a line is killed the structure subtree is there already
1136 % too and must be removed. If hard to do, then maybe at first warn if the
1137 % construction is used.
1138 %
1139 % \cs{LT@array} is executed in a group, so we can disable para-tagging here.
1140 % \changes{v4.19}{2023/12/16}{Support for tagged PDF}
1141 % \begin{macrocode}
1142 \UseTaggingSocket{tbl/init}
1143 \tl_if_empty:eTF { \LTcaptype }
1144 {
1145 \tl_gset:Ne \@currentHref {LT@tables.\theHLT@tables}
1146 }
1147 {
1148 \@kernel@refstepcounter{\LTcaptype}\stepcounter{LT@tables}
1149 % \end{macrocode}
1150 % The target is created rather late and a \cs{label} can come earlier,
1151 % so we have to define \cs{@currentHref} explicitly. We can't currently
1152 % assume that \cs{theHtable} is defined always.
1153 % \begin{macrocode}
1154 \tl_gset:Ne \@currentHref {\LTcaptype.\cs_if_exist_use:c {theH\LTcaptype}}
1155 }
1156 % \end{macrocode}
1157 %
1158 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
1159 % \begin{macrocode}
1160 \tbl_gzero_row_count:
1161 % \end{macrocode}
1162 %
1163 % \changes{v4.19}{2023/12/16}{Support for tagged PDF}
1164 % \begin{macrocode}
1165 \UseTaggingSocket{tbl/longtable/init}
1166 % \end{macrocode}
1167 % Set up the glue around the table if an optional argument given.
1168 % \begin{macrocode}
1169 \if l#1%
1170 \LTleft\z@ \LTright\fill
1171 \else\if r#1%
1172 \LTleft\fill \LTright\z@
1173 \else\if c#1%
1174 \LTleft\fill \LTright\fill
1175 \fi\fi\fi
1176 % \end{macrocode}
1177 % Set up these internal commands for \env{longtable}.
1178 % \changes{v3.13}{1994/12/08}
1179 % {add \cs{tabularnewline}}
1180 % \changes{v3.14}{1995/04/25}
1181 % {(Mike Van Geest) rename \cs{LT@mc} to
1182 % \cs{LT@mcol} to allow 1100 tables}
1183 % \changes{v4.01}{1996/04/11}
1184 % {(DPC) don't need multicolumn warning}
1185 %\begin{verbatim}
1186 % \global\let\LT@mcw@rn\relax
1187 %\end{verbatim}
1188 % \begin{macrocode}
1189 \let\LT@mcol\multicolumn
1190 % \end{macrocode}
1191 % \changes{v3.17}{1996/01/31}
1192 % {Reset \cs{hline} and \cs{multicolumn} in nested tabular
1193 % and array, for tools/2068}
1194 % Now redefine "\@tabarray" to restore "\hline" and "\multicolumn" so
1195 % that arrays and tabulars nested in longtable (or in page headings on
1196 % longtable pages) work out OK. Saving the original definitions done
1197 % here so that you can load the \package{array} package before or after
1198 % \package{longtable}.
1199 % \begin{macrocode}
1200 \let\LT@@@@tabarray\@tabarray
1201 \let\LT@@@@hl\hline
1202 \def\@tabarray{%
1203 \let\hline\LT@@@@hl
1204 % \end{macrocode}
1205 %\begin{verbatim}
1206 % \let\multicolumn\LT@mcol
1207 %\end{verbatim}
1208 % \begin{macrocode}
1209 \LT@@@@tabarray}%
1210 \let\\\LT@tabularcr
1211 \let\tabularnewline\\%
1212 \def\newpage{\noalign{\break}}%
1213 % \end{macrocode}
1214 % \changes{v4.05}{1996/11/12}
1215 % {\cs{nopagebreak} and \cs{pagebreak} added}
1216 % More or less standard definitions, but first start a "\noalign".
1217 % \begin{macrocode}
1218 \def\pagebreak{\noalign{\ifnum`}=0\fi\@testopt{\LT@no@pgbk-}4}%
1219 \def\nopagebreak{\noalign{\ifnum`}=0\fi\@testopt\LT@no@pgbk4}%
1220 % \end{macrocode}
1221 %
1222 % \begin{macrocode}
1223 \let\hline\LT@hline \let\kill\LT@kill\let\caption\LT@caption
1224 \@tempdima\ht\strutbox
1225 % \end{macrocode}
1226 %
1227 % \changes{v4.08}{1998/01/20}
1228 % {Move \cs{@endpbox} definition earlier and define \cs{@@@@endpbox}
1229 % and \cs{@@@@startpbox} for non-array case. tools/2736}
1230 % \begin{macrocode}
1231 \let\@endpbox\LT@endpbox
1232 % \end{macrocode}
1233 % Set up internal commands according to Lamport or Mittelbach.
1234 % \begin{macrocode}
1235 \ifx\extrarowheight\@undefined
1236 % \end{macrocode}
1237 % Initialise these commands as in \env{tabular} from the \LaTeX\ kernel.
1238 % \begin{macrocode}
1239 \let\@acol\@tabacol
1240 \let\@classz\@tabclassz \let\@classiv\@tabclassiv
1241 \def\@startpbox{\vtop\LT@startpbox}%
1242 \let\@@@@startpbox\@startpbox
1243 \let\@@@@endpbox\@endpbox
1244 \let\LT@LL@FM@cr\@tabularcr
1245 \else
1246 % \end{macrocode}
1247 % Initialise these commands as in \package{array}. "\d@llar"
1248 % replaced by "\d@llarbegin" "\d@llarend" in V3.03 to match
1249 % \package{array} V2.0h. We do not need to set "\d@llarbegin" and
1250 % "\d@llarend" as the \package{array} package gives them the correct
1251 % values at the top level.
1252 % \changes{v4.23}{2024/12/17}{Initialize \cs{@startpbox@action} instead
1253 % of \cs{@startpbox} to match array change (gh/1585)}
1254 % \begin{macrocode}
1255 \advance\@tempdima\extrarowheight
1256 \col@sep\tabcolsep
1257 \let\@startpbox@action\LT@startpbox
1258 \let\LT@LL@FM@cr\@arraycr
1259 \fi
1260 % \end{macrocode}
1261 % The rest of this macro is mainly based on \package{array} package, but
1262 % should work for the standard \env{tabular} too.
1263 % \begin{macrocode}
1264 \setbox\@arstrutbox\hbox{\vrule
1265 \@height \arraystretch \@tempdima
1266 \@depth \arraystretch \dp \strutbox
1267 \@width \z@}%
1268 \let\@sharp##\let\protect\relax
1269 % \end{macrocode}
1270 % Interpret the preamble argument.
1271 % \begin{macrocode}
1272 \begingroup
1273 \@mkpream{#2}%
1274 % \end{macrocode}
1275 %
1276 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
1277 % \begin{macrocode}
1278 \tbl_count_table_cols:
1279 % \end{macrocode}
1280 % We need to rename "\@preamble" here as F.M.'s scheme uses
1281 % "\global", and we may need to nest "\@mkpream", eg for
1282 % "\multicolumn"
1283 % or an \env{array}.
1284 % We do not need to worry about nested \env{longtable}s though!
1285 % \begin{macrocode}
1286 \xdef\LT@bchunk{%
1287 % \end{macrocode}
1288 % We aren't inside any row when a chunk starts.
1289 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
1290 % \begin{macrocode}
1291 \tbl_inbetween_rows:
1292 % \end{macrocode}
1293 % \changes{v4.00}{1996/04/08}
1294 % {(DK) Increment Chunk counter}
1295 % \begin{macrocode}
1296 \global\advance\c@LT@chunks\@ne
1297 \global\LT@rows\z@\setbox\z@\vbox\bgroup
1298 % \end{macrocode}
1299 % \changes{v4.05}{1996/11/12}
1300 % {\cs{LT@setprevdepth} added}
1301 % The following line was added in v4.05.
1302 % In order to get the "\penalties" to work at chunk boundaries,
1303 % we need to take more care about where and when "\lineskip" glue
1304 % is added. The following does nothing at top of table, and in
1305 % header chunks, but in normal body chunks it sets "\prevdepth"
1306 % (to 0pt, but any value would do) so that "\lineskip" glue will
1307 % be added. The important thing to note is that the glue will be
1308 % added \emph{after} any vertical material coming from "\noalign".
1309 % \begin{macrocode}
1310 \LT@setprevdepth
1311 % \end{macrocode}
1312 %
1313 % \changes{v4.10}{2000/10/22}
1314 % {\cs{noexpand} added (as in array.sty) for mathtext.sty, CAR}
1315 % \begin{macrocode}
1316 \tabskip\LTleft \noexpand\halign to\hsize\bgroup
1317 % \tabskip\LTleft\halign to\hsize\bgroup
1318 \tabskip\z@ \@arstrut
1319 % \end{macrocode}
1320 %
1321 % Insert the tagging socket to start the row and initialize the cell
1322 % data for the row.
1323 % \changes{v4.19}{2023/12/16}{Support for tagged PDF}
1324 % \begin{macrocode}
1325 \UseTaggingSocket{tbl/row/begin}%
1326 \ArrayLoadedT { \@@_hook_use_protected:nV {tbl/row/begin} \g_@@_row_int }
1327 % \end{macrocode}
1328 %
1329 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
1330 % \begin{macrocode}
1331 \tbl_init_cell_data_for_row:
1332 % \end{macrocode}
1333 % \begin{macrocode}
1334 \@preamble \tabskip\LTright \cr}%
1335 \endgroup
1336 % \end{macrocode}
1337 % Find out how many columns we have (store in "\LT@cols").
1338 % \begin{macrocode}
1339 \expandafter\LT@nofcols\LT@bchunk&\LT@nofcols
1340 % \end{macrocode}
1341 % This is the point at which other packages can add some initializations. Not
1342 % 100\% sure this is the best place---usage will have to decide if
1343 % this needs moving earlier or later.
1344 % \changes{v4.26}{2026-01-15}{Add support hook}
1345 % \begin{macrocode}
1346 \ArrayLoadedT {
1347 \exp_args:Nnno \hook_use:nnw {tbl/init} {2}
1348 \g_@@_table_cols_tl {#2}
1349 }
1350 % \end{macrocode}
1351 % Get the saved row from "\LT@i"\ldots"\LT@ix" (from the
1352 % ".aux" file), or make a new blank row.
1353 % \begin{macrocode}
1354 \LT@make@row
1355 % \end{macrocode}
1356 % A few more internal commands for \env{longtable}.
1357 % Don't use \cs{m@th} here as that signals to the math tagging
1358 % code that this is fake math that should not be tagged.
1359 % \changes{v4.27}{2026/01/29}{Support for tagged PDF, tagging/1192}
1360 % \begin{macrocode}
1361 \mathsurround \z@\let\par\@empty
1362 % \end{macrocode}
1363 % Tagging socket and conditional
1364 % \begin{macrocode}
1365 \everycr{%
1366 \noalign{%
1367 % \end{macrocode}
1368 % In \pkg{longtable} we have a bunch of extra \cs{cr}s that are
1369 % executed whenever a chunk ends. In that case they should not
1370 % increment the main row counter, sigh.
1371 %
1372 % TODO: At the moment this tracing still exposes the internal row counter!
1373 % \begin{macrocode}
1374 \@@_trace:n {--longtable-->~chunk~row:~ \the\LT@rows \space
1375 row:~ \the\g_@@_row_int \space
1376 column:~ \the\g_@@_col_int
1377 }
1378 % \end{macrocode}
1379 %
1380 % \changes{v4.19}{2023/12/16}{Support for tagged PDF}
1381 % \changes{v4.26}{2026-01-15}{Add support hook}
1382 % \begin{macrocode}
1383 \tbl_if_row_was_started:T
1384 {
1385 \ArrayLoadedT
1386 { \@@_hook_use_protected:nV {tbl/row/end}
1387 \g_@@_row_int }
1388 \UseTaggingSocket{tbl/row/end}
1389 % \end{macrocode}
1390 % The next setting prevents any of the additional \cs{cr}s at the end of the
1391 % chunk to add another /TR. Then once we really start a new chunk
1392 % it gets incremented so\ldots
1393 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
1394 % \begin{macrocode}
1395 \tbl_inbetween_rows:
1396 }
1397 % \end{macrocode}
1398 % And for the same reason such \cs{cr}s should not increment the
1399 % main row counter (but it has to be incremented after the preamble
1400 % of a chunk), so here we test against \cs{LT@rows} which is
1401 % \cs{LTchunksize} at the end of a chunk.
1402 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
1403 % \begin{macrocode}
1404 \int_compare:nNnT \LT@rows < \LTchunksize
1405 { \tbl_gincr_row_count: % next is row about to start
1406 % \end{macrocode}
1407 %
1408 % Finally, we call the hook the makes any initializations for a
1409 % possibly upcoming row (there may not be any, but we don't know
1410 % that at this point). As we are stil inside the \cs{noalign} but
1411 % may want to issue a \cs{cline} or \cs{rowcolor} from within this
1412 % hook we temporarily render \cs{noalign} a no-op.
1413 % \changes{v4.26}{2026-01-15}{Add support hook}
1414 % \begin{macrocode}
1415 \ArrayLoadedT
1416 {
1417 \cs_set_eq:NN \noalign \prg_do_nothing:
1418 \@@_hook_use_protected:nV {tbl/row/init} \g_@@_row_int
1419 }
1420 }
1421 }%
1422 }%
1423 % \end{macrocode}
1424 % \begin{macrocode}
1425 \lineskip\z@\baselineskip\z@
1426 % \end{macrocode}
1427 % Start the first chunk.
1428 % \begin{macrocode}
1429 \LT@bchunk}
1430 \ExplSyntaxOff
1431 %<@@=>
1432 % \end{macrocode}
1433 % \end{macro}
1434 %
1435 % \begin{macro}{\LT@no@pgbk}
1436 % \changes{v4.05}{1996/11/12}
1437 % {Macro added}
1438 % Can simplify the standard "\@no@pgbk" as this is vmode only
1439 % but then need to close the "\noalign".
1440 % \begin{macrocode}
1441 \def\LT@no@pgbk#1[#2]{\penalty #1\@getpen{#2}\ifnum`{=0\fi}}
1442 % \end{macrocode}
1443 % \end{macro}
1444 %
1445 % \begin{macro}{\LT@start}
1446 % \changes{v4.13}{2020/01/07}
1447 % {fix issue https://github.com/davidcarlisle/dpctex/issues/8}
1448 % This macro starts the process of putting the table on the current
1449 % page. It is not called until either a "\\" or "\endlongtable" command
1450 % ends a chunk, as we do not know until that point which of the four
1451 % possible head or foot sections have been specified.
1452 %
1453 % It begins by redefining itself, so that the table is only started
1454 % once! Until V3.04, was redefined to "\relax", now use "\endgraf" to
1455 % force the page-breaker to wake up. The second "\endgraf" is there so
1456 % that "\pagetotal" is updated and so takes "\LTpre" into account.
1457 % \begin{macrocode}
1458 %<@@=tbl>
1459 \ExplSyntaxOn
1460 % \end{macrocode}
1461 %
1462 % \begin{macrocode}
1463 \def\LT@start{%
1464 \let\LT@start\endgraf
1465 \endgraf\penalty\z@\vskip\LTpre\endgraf
1466 % \end{macrocode}
1467 % \changes{v4.14}{2020/02/07}
1468 % {Guard against shrink glue on current page tools/3396 and github 183}
1469 % This next block was suggested by Lars Hellström in pr tools/3396.
1470 % He documents it as:
1471 %
1472 % The original problem occurs because TeX has not yet found an awfully bad
1473 % "(b=*)" breakpoint and is therefore still collecting material to see if there
1474 % is a really good break somewhere just ahead. As we know there aren't, we
1475 % want to make it stop looking and break the page, so that "\pagetotal" will be
1476 % for the page where the table will actually end up. To achieve this, we
1477 % need to give \TeX\ an awfully bad, but legal, breakpoint. The simplest way of
1478 % doing this seems to be to insert a "\kern" that counters the "\pageshrink" for
1479 % the page, followed by a "\penalty" and a "\par" (to exercise the page builder).
1480 % We also have to make sure that this breakpoint doesn't affect how the next
1481 % page is broken, so we make the penalty 9999 (10000 is infinite and thus not
1482 % a legal breakpoint) and cancel out the "\kern" with a new "\kern".
1483 %
1484 % I don't think this is the \emph{right} solution to the problem (that would be
1485 % that the standard output routine has a feature for syncronizing with
1486 % typesetting, as part of the preparations for switching output routine), but
1487 % it's OK. Perhaps XOR will make it better.
1488 % \begin{macrocode}
1489 \ifdim \pagetotal<\pagegoal \else
1490 \dimen@=\pageshrink
1491 \advance \dimen@ 1sp %
1492 \kern\dimen@\penalty 9999\endgraf \kern-\dimen@
1493 \fi
1494 % \end{macrocode}
1495 % Start a new page if there is not enough room for the table head, foot,
1496 % and one extra line.
1497 % \begin{macrocode}
1498 \dimen@\pagetotal
1499 \advance\dimen@ \ht\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
1500 \advance\dimen@ \dp\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
1501 \advance\dimen@ \ht\LT@foot
1502 % \end{macrocode}
1503 % \changes{v3.16}{1995/11/09}
1504 % {Measure the first line of the table}
1505 % \changes{v4.15}{2021/04/18}
1506 % {silence \cs{vbadness}}
1507 % At this point I used to add "\ht\@arstrutbox" and "\dp\@arstrutbox"
1508 % as a measure of a row size. However this can fail spectacularly
1509 % for "p" columns which might be much larger. Previous versions could
1510 % end up with the table starting with a foot, then a page break then
1511 % a head \emph{then} a `first head'! So now measure the first line of
1512 % the table accurately by "\vsplit"ting it out of the first chunk.
1513 % \begin{macrocode}
1514 \edef\LT@reset@vfuzz{\vfuzz\the\vfuzz\vbadness\the\vbadness\relax}%
1515 \vfuzz\maxdimen
1516 \vbadness\@M
1517 \setbox\tw@\copy\z@
1518 \setbox\tw@\vsplit\tw@ to \ht\@arstrutbox
1519 \setbox\tw@\vbox{\unvbox\tw@}%
1520 \LT@reset@vfuzz
1521 \advance\dimen@ \ht
1522 \ifdim\ht\@arstrutbox>\ht\tw@\@arstrutbox\else\tw@\fi
1523 \advance\dimen@\dp
1524 \ifdim\dp\@arstrutbox>\dp\tw@\@arstrutbox\else\tw@\fi
1525 % \end{macrocode}
1526 %
1527 % \begin{macrocode}
1528 \advance\dimen@ -\pagegoal
1529 \ifdim \dimen@>\z@
1530 \vfil\break
1531 \else
1532 % \end{macrocode}
1533 %
1534 % \changes{v4.14}{2020/02/07}
1535 % {Guard against shrink glue on current page see github 183}
1536 % The LT output routine does not handle shrink on the page, which can cause
1537 % the first page to be over-long, so forget it is there.
1538 % \begin{macrocode}
1539 \ifdim\pageshrink>\z@\pageshrink\z@\fi
1540 \fi
1541 % \end{macrocode}
1542 % Store height of page minus table foot in "\@colroom".
1543 % \changes{v3.14}{1995/05/02}
1544 % {Set \cs{@colroom}, for tools/1584}
1545 % \begin{macrocode}
1546 \global\@colroom\@colht
1547 % \end{macrocode}
1548 % If the foot is non empty, reduce the "\vsize" and "\@colroom"
1549 % accordingly.
1550 % \changes{v4.14}{2020/02/07}
1551 % {Rearrange vertical space tests for tools/3512 (floats on same page)}
1552 % \begin{macrocode}
1553 \ifvoid\LT@foot\else
1554 \global\advance\vsize-\ht\LT@foot
1555 \global\advance\@colroom-\ht\LT@foot
1556 \dimen@\pagegoal\advance\dimen@-\ht\LT@foot\pagegoal\dimen@
1557 \maxdepth\z@
1558 \fi
1559 % \end{macrocode}
1560 % \changes{v4.21}{2024/07/04}
1561 % {Use \cs{LTcaptype} to support other types beside table and handle
1562 % the case if it is empty.}
1563 % \begin{macrocode}
1564 \tl_if_empty:eTF{\LTcaptype}
1565 {
1566 \MakeLinkTarget{LT@tables}
1567 }
1568 {
1569 \MakeLinkTarget{\LTcaptype}
1570 }
1571 % \end{macrocode}
1572 % Put the table head on the page, and then switch to the new output
1573 % routine.
1574 % \changes{v4.11}{2004/02/01}
1575 % {\cs{nobreak}, for tools/3484}
1576 % \begin{macrocode}
1577 \ifvoid\LT@firsthead\copy\LT@head\else\box\LT@firsthead\fi\nobreak
1578 % \end{macrocode}
1579 %
1580 % \changes{v4.19}{2023/12/16}{Support for tagged PDF}
1581 % \begin{macrocode}
1582 \UseTaggingSocket{tbl/longtable/head}
1583 % \end{macrocode}
1584 %
1585 % \begin{macrocode}
1586 \output{\LT@output}}
1587 \ExplSyntaxOff
1588 %<@@=>
1589 % \end{macrocode}
1590 % \end{macro}
1591 %
1592 %
1593 %
1594 %
1595 % \begin{macro}{\endlongtable}
1596 %
1597 % \begin{macrocode}
1598 %<@@=tbl>
1599 \ExplSyntaxOn
1600 % \end{macrocode}
1601 %
1602 % Called by "\end{longtable}".
1603 % \begin{macrocode}
1604 \def\endlongtable{%
1605 % \end{macrocode}
1606 % Essentially add a final "\\". But as we now know the number of
1607 % actual chunks, we first strip away all entries referring to a
1608 % maximum entry beyond the table (this can only happen if a table has
1609 % been shortened, or the table numbering has gone awry). In that case
1610 % we at least start collecting valid new information with the last
1611 % chunk of this table, by removing the width constraint.
1612 % \changes{v4.19}{2023/12/16}{Support for tagged PDF}
1613 % \begin{macrocode}
1614 \tbl_crcr:n {endlongtable}
1615 % \end{macrocode}
1616 %
1617 % \changes{v4.01}{1996/04/11}
1618 % {(DPC) use \cs{noalign} to sneak in \cs{LT@entry@chop}}
1619 % \begin{macrocode}
1620 \noalign{%
1621 % \end{macrocode}
1622 %
1623 % \changes{v4.19}{2023/12/16}{Support for tagged PDF}
1624 % \begin{macrocode}
1625 \UseTaggingSocket{tbl/longtable/finalize}
1626 % \end{macrocode}
1627 %
1628 % \begin{macrocode}
1629 \let\LT@entry\LT@entry@chop
1630 \xdef\LT@save@row{\LT@save@row}}%
1631 \LT@echunk
1632 \LT@start
1633 \unvbox\z@
1634 \LT@get@widths
1635 % \end{macrocode}
1636 % Write the dummy row to the ".aux" file.
1637 % Since V3.06, use ".lta" for "letter.sty".
1638 % \changes{v3.12}{1994/06/30}
1639 % {Do not write if \cs{nofiles} in operation.}
1640 % \begin{macrocode}
1641 \if@filesw
1642 {\let\LT@entry\LT@entry@write\immediate\write\@auxout{%
1643 % \end{macrocode}
1644 % Since Version 3.02, \package{longtable} has used the internal counter
1645 % "\c@LT@tables" rather than the \LaTeX\ counter \textsf{table}. This
1646 % information looks entirely different from version~3
1647 % information. Still, we don't need to rename the macro name because
1648 % later code will consider the information to have no columns, and
1649 % thus will throw the old data away.
1650 % \begin{macrocode}
1651 \gdef\expandafter\noexpand
1652 \csname LT@\romannumeral\c@LT@tables\endcsname
1653 {\LT@save@row}}}%
1654 \fi
1655 % \end{macrocode}
1656 % At this point used to
1657 % issue a warning if a "\multicolumn" has been set in draft mode.
1658 % \changes{v4.01}{1996/04/11}
1659 % {(DPC) No need for multicolumn warnings}
1660 %\begin{verbatim}
1661 % \LT@mcw@rn
1662 %\end{verbatim}
1663 % If the last chunk has different widths than the first, warn the user.
1664 % Also trigger a warning to rerun \LaTeX\ at the end of the document.
1665 % \changes{v4.04}{1996/05/24}
1666 % {Use \cs{LT@final@warn}}
1667 % \begin{macrocode}
1668 \ifx\LT@save@row\LT@@@@save@row
1669 \else
1670 \LT@warn{Column~ widths~ have~ changed\MessageBreak
1671 in~
1672 \tl_if_empty:eTF{\LTcaptype}
1673 {longtable~ \theLT@tables}
1674 {\LTcaptype\c_space_tl\use:c{the\LTcaptype}}
1675 }
1676 \LT@final@warn
1677 \fi
1678 % \end{macrocode}
1679 % Force one more go with the \env{longtable} output routine.
1680 % Guard the special start of page value of "\pagegoal".
1681 % \changes{v4.14}{2020/02/07}
1682 % {Rearrange vertical space tests for tools/3512 (floats on same page)}
1683 % \changes{v4.22}{2024/10/27}
1684 % {Keep \cs{pagegoal} below \cs{maxdimen} gh1495}
1685 % \begin{macrocode}
1686 \endgraf\penalty -\LT@end@pen
1687 \ifvoid\LT@foot\else
1688 \global\advance\vsize\ht\LT@foot
1689 \global\advance\@colroom\ht\LT@foot
1690 \ifdim\pagegoal<\maxdimen
1691 \dimen@\pagegoal\advance\dimen@\ht\LT@foot\pagegoal\dimen@
1692 \fi
1693 \fi
1694 % \end{macrocode}
1695 % Now close the group to return to the standard routine.
1696 % \begin{macrocode}
1697 \endgroup
1698 % \end{macrocode}
1699 % Reset "\@mparbottom" to allow marginpars close to the end of the
1700 % table.\footnote{This can not be the correct. However if it is omitted,
1701 % there is a problem with marginpars, for example on page~3 of this
1702 % document. Any Output Routine Gurus out there?}
1703 % \changes{v4.14}{2020/02/07}
1704 % {Rearrange vertical space tests for tools/3512 (floats on same page)}
1705 % \begin{macrocode}
1706 \global\@mparbottom\z@
1707 % \pagegoal\vsize
1708 \endgraf\penalty\z@\addvspace\LTpost
1709 % \end{macrocode}
1710 % Footnotes. As done in the \package{multicol} package.
1711 % \begin{macrocode}
1712 \ifvoid\footins\else\insert\footins{}\fi
1713 % \end{macrocode}
1714 %
1715 % \changes{v4.19}{2023/12/16}{Support for tagged PDF}
1716 % \begin{macrocode}
1717 \UseTaggingSocket{tbl/vmode/end}%
1718 }
1719 \ExplSyntaxOff
1720 %<@@=>
1721 % \end{macrocode}
1722 % \end{macro}
1723 %
1724 % \subsection{Counting Columns}
1725 %
1726 % Columns are counted by examining "\@preamble", rather than simply
1727 % getting "\@mkpream" to increment the counter as it builds the
1728 % preamble so that this package works with many of the packages which
1729 % add extra column specifiers to \LaTeX's standard ones.
1730 %
1731 % Version~1 counted "\@sharp"'s to calculate the number of columns,
1732 % this was changed for Version~2 as it does not work with the NFSS. Now
1733 % count "&"'s. ("lfonts.new" (and now the Standard \LaTeX\ definition)
1734 % defines "\@tabclassz" so that "\@sharp" is inside a group.)
1735 %
1736 % \begin{macro}{\LT@nofcols}
1737 % Find the next "&", then look ahead to see what is next.
1738 % \begin{macrocode}
1739 \def\LT@nofcols#1&{%
1740 \futurelet\@let@token\LT@n@fcols}
1741 % \end{macrocode}
1742 % \end{macro}
1743 %
1744 % \begin{macro}{\LT@n@fcols}
1745 % Add one, then stop at an "\LT@nofcols" or look for the next
1746 % "&". The "\expandafter" trick was added in Version~3, also the
1747 % name changed from "\@LT@nofcols" to preserve the "\LT@" naming
1748 % convention.
1749 % \begin{macrocode}
1750 \def\LT@n@fcols{%
1751 \advance\LT@cols\@ne
1752 \ifx\@let@token\LT@nofcols
1753 \expandafter\@gobble
1754 \else
1755 \expandafter\LT@nofcols
1756 \fi}
1757 % \end{macrocode}
1758 % \end{macro}
1759 %
1760 % \subsection{The {\ttfamily\bslash\bslash} and \cs{kill} Commands}
1761 %
1762 % \begin{macro}{\LT@tabularcr}
1763 % \changes{v4.05}{1996/11/12}
1764 % {Code re-organised for the *-form processing.}
1765 % The internal definition of "\\".
1766 % In the "*" form, insert a "\nobreak" after the next "\cr" (or "\crcr").
1767 %
1768 % This star form processing was finally added in v4.05. For the previous
1769 % six or seven years the comment at this point said
1770 % \begin{quote}\small
1771 % This definition also accepts "\\*", which acts in the same way as
1772 % "\\". \env{tabular} does this, but \env{longtable} probably ought to
1773 % make "\\*" prevent page breaking.
1774 % \end{quote}
1775 %
1776 % "{\ifnum0=`}\fi" added in version 3.01, required if the first entry
1777 % is empty.
1778 % The above in fact is not good enough, as with \package{array} package
1779 % it can introduce a "{}" group in math mode, which changes the spacing.
1780 % So use the following variant. Added in v3.14.
1781 % \changes{v3.14}{1995/04/25}
1782 % {More fun with \cs{ifnum} cf tools/1571}
1783 % \changes{v4.15}{2021/04/21}
1784 % {protected (gh/584)}
1785 % \begin{macrocode}
1786 \protected\def\LT@tabularcr{%
1787 \relax\iffalse{\fi\ifnum0=`}\fi
1788 \@ifstar
1789 % \end{macrocode}
1790 % TODO: as we replace crcr later in one case, we probably have to
1791 % implement some further logic there!
1792 % \begin{macrocode}
1793 {\def\crcr{\LT@crcr\noalign{\nobreak}}\let\cr\crcr
1794 \LT@t@bularcr}%
1795 {\LT@t@bularcr}}
1796 % \end{macrocode}
1797 % \end{macro}
1798 %
1799 % \begin{macro}{\LT@crcr}
1800 % \changes{v4.05}{1996/11/12}
1801 % {Macro added}
1802 % \begin{macrocode}
1803 \let\LT@crcr\crcr
1804 % \end{macrocode}
1805 % \end{macro}
1806 %
1807 % \begin{macro}{\LT@setprevdepth}
1808 % \changes{v4.05}{1996/11/12}
1809 % {Macro added}
1810 % \changes{v4.14}{2020/02/07}
1811 % {spurious \cs{global} removed}
1812 % This will be redefined to set the "\prevdepth"
1813 % at the start of a chunk.
1814 % \begin{macrocode}
1815 \let\LT@setprevdepth\relax
1816 % \end{macrocode}
1817 % \end{macro}
1818 %
1819 %
1820 %
1821 %
1822 % \begin{macro}{\LT@t@bularcr}
1823 % \begin{macrocode}
1824 %<@@=tbl>
1825 \ExplSyntaxOn
1826 \def\LT@t@bularcr{%
1827 % \end{macrocode}
1828 % Increment the counter, and do \env{tabular}'s "\\" or finish the
1829 % chunk.\\ The "\expandafter" trick was added in Version~3.
1830 % Set the "\prevdepth" at the start of a new chunk. (Done here
1831 % so not set in header chunks.)
1832 % \begin{macrocode}
1833 \global\advance\LT@rows\@ne
1834 \ifnum\LT@rows=\LTchunksize
1835 % \end{macrocode}
1836 % At the end of the chunk \verb=\\= is doing something special and
1837 % so we lose \verb=\tbl_count_missing_cells:n=. Below is about the
1838 % right place to add it do this code branch.
1839 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
1840 % \begin{macrocode}
1841 \tbl_count_missing_cells:n {echunk}
1842 \gdef\LT@setprevdepth{%
1843 \prevdepth\z@
1844 \global\let\LT@setprevdepth\relax}%
1845 \expandafter\LT@xtabularcr
1846 \else
1847 \ifnum0=`{}\fi
1848 \expandafter\LT@LL@FM@cr
1849 \fi}
1850 \ExplSyntaxOff
1851 %<@@=>
1852 % \end{macrocode}
1853 % \end{macro}
1854 %
1855 % \begin{macro}{\LT@xtabularcr}
1856 % This just looks for an optional argument.
1857 % \begin{macrocode}
1858 \def\LT@xtabularcr{%
1859 \@ifnextchar[\LT@argtabularcr\LT@ntabularcr}
1860 % \end{macrocode}
1861 % \end{macro}
1862 %
1863 % \begin{macro}{\LT@ntabularcr}
1864 % The version with no optional argument.
1865 % "\ifnum0=`{\fi}" added in version 3.01. Changed in 3.14.
1866 % \begin{macrocode}
1867 \def\LT@ntabularcr{%
1868 \ifnum0=`{}\fi
1869 \LT@echunk
1870 \LT@start
1871 \unvbox\z@
1872 \LT@get@widths
1873 \LT@bchunk}
1874 % \end{macrocode}
1875 % \end{macro}
1876 %
1877 % \begin{macro}{\LT@argtabularcr}
1878 % The version with an optional argument.
1879 % "\ifnum0=`{\fi}" added in version 3.01. Changed in 3.14.
1880 % \begin{macrocode}
1881 \def\LT@argtabularcr[#1]{%
1882 \ifnum0=`{}\fi
1883 \ifdim #1>\z@
1884 \unskip\@xargarraycr{#1}%
1885 \else
1886 \@yargarraycr{#1}%
1887 \fi
1888 % \end{macrocode}
1889 % Add the dummy row, and finish the "\halign".
1890 % \begin{macrocode}
1891 \LT@echunk
1892 \LT@start
1893 \unvbox\z@
1894 \LT@get@widths
1895 \LT@bchunk}
1896 % \end{macrocode}
1897 % \end{macro}
1898 %
1899 % \begin{macro}{\LT@echunk}
1900 % \changes{v4.05}{1996/11/12}
1901 % {\cs{unskip} added for pagebreak support}
1902 % \changes{v4.14}{2020/02/07}
1903 % {allocated global box (tools/2914)}
1904 % This ends the current chunk, and removes the dummy row.
1905 % \begin{macrocode}
1906 \def\LT@echunk{%
1907 \crcr\LT@save@row\cr\egroup
1908 \global\setbox\LT@gbox\lastbox
1909 % \end{macrocode}
1910 % The following line was added in v4.05.
1911 % \package{longtable} relies on "\lineskip" glue (which is 0pt) to
1912 % provide break points between each row so the table may be split
1913 % into pages.
1914 %
1915 % Previous releases left the "\lineskip" glue at the end of each chunk
1916 % that had been added when the dummy row was added. There was no glue
1917 % at the start of the next chunk as \TeX\ normally does not put
1918 % "\lineskip" glue at the top of a box. This meant that normally the
1919 % chunks fitted together perfectly, however "\noalign" material at a
1920 % chunk boundary came before the first row of the next chunk
1921 % but after the lineskip glue at the end of this chunk. This is the
1922 % wrong place, e.g., it means even a "\penalty10000" does not stop a
1923 % break as the "\lineskip" glue in the previous item on the list
1924 % provides a legal breakpoint. So now remove the "\lineskip" glue that
1925 % was before the dummy row and introduce "\LT@setprevdepth" to set the
1926 % "\prevdepth" at the start of the next chunk, to make sure "\lineskip"
1927 % glue is added later.
1928 % \begin{macrocode}
1929 \unskip
1930 \egroup}
1931 % \end{macrocode}
1932 % \end{macro}
1933 %
1934 % \begin{macro}{\LT@entry}
1935 % \changes{v4.00}{1996/04/08}
1936 % {(DK) Macro added}
1937 % \changes{v4.01}{1996/04/11}
1938 % {(DPC) Use \cs{ifhmode} trick to determine first entry}
1939 % We here give the `basic' definition of "\LT@entry", namely that used
1940 % in alignment templates. It has a "\kern" only if the maximum is
1941 % imposed from a different chunk.
1942 % The "\ifhmode" test reveals the first entry, when we don't want to add
1943 % an "&".
1944 % \begin{macrocode}
1945 \def\LT@entry#1#2{%
1946 \ifhmode\@firstofone{&}\fi\omit
1947 \ifnum#1=\c@LT@chunks
1948 \else
1949 \kern#2\relax
1950 \fi}
1951 % \end{macrocode}
1952 % \end{macro}
1953 %
1954 % \begin{macro}{\LT@entry@chop}
1955 % \changes{v4.00}{1996/04/08}
1956 % {(DK) Macro added}
1957 % This definition for the argument of "\LT@save@row" is used to scrap
1958 % all those maxima which could not be verified because they occur
1959 % after the end of the table. This can happen only if a table has been
1960 % shortened (or the sequencing got mixed up) since the
1961 % previous run.
1962 % Note that this is premature: the last chunk still is going to be
1963 % set, and with the chopped limits.
1964 % \begin{macrocode}
1965 \def\LT@entry@chop#1#2{%
1966 \noexpand\LT@entry
1967 {\ifnum#1>\c@LT@chunks
1968 1}{0pt%
1969 \else
1970 #1}{#2%
1971 \fi}}
1972 % \end{macrocode}
1973 % \end{macro}
1974 %
1975 % \begin{macro}{\LT@entry@write}
1976 % \changes{v4.07}{1997/10/16}
1977 % {Avoid use of percent. tools/2631}
1978 % To write an entry for the "aux" file, we use a slightly
1979 % surprising definition which has the sole purpose of avoiding
1980 % overfull lines (which might break \TeX{}'s limits when reading the
1981 % "aux" file, probably you'd need to have a few hundred columns before
1982 % this happened but\ldots).
1983 % \begin{macrocode}
1984 \def\LT@entry@write{%
1985 \noexpand\LT@entry^^J%
1986 \@spaces}
1987 % \end{macrocode}
1988 % \end{macro}
1989 %
1990 % \begin{macro}{\LT@kill}
1991 % This ends the current chunk as above, but strips off two rows, the
1992 % `dummy row' and the `killed row' before starting the next chunk.
1993 % Since V3.04, the old chunk is reboxed at the start of the box
1994 % containing the next chunk. This allows "\kill" to be used in headers,
1995 % which must be processed in a single box.
1996 % \begin{macrocode}
1997 \def\LT@kill{%
1998 \LT@echunk
1999 \LT@get@widths
2000 \expandafter\LT@rebox\LT@bchunk}
2001 % \end{macrocode}
2002 % \end{macro}
2003 %
2004 % \begin{macro}{\LT@rebox}
2005 % Drop the old chunk (box0) back at the top of the new chunk, removing
2006 % the killed row. This macro added at V3.04.
2007 % \begin{macrocode}
2008 \def\LT@rebox#1\bgroup{%
2009 #1\bgroup
2010 \unvbox\z@
2011 \unskip
2012 \setbox\z@\lastbox}
2013 % \end{macrocode}
2014 % \end{macro}
2015 %
2016 % \subsection{The Dummy Row}
2017 %
2018 % The dummy row is kept inside of the macro "\LT@save@row".
2019 %
2020 % \begin{macro}{\LT@blank@row}
2021 % \begin{macro}{\LT@build@blank}
2022 % \changes{v4.00}{1996/04/08}
2023 % {(DK) Macro added}
2024 % \changes{v4.01}{1996/04/11}
2025 % {(DPC) Don't mess with \cs{multicolumn} on draft passes}
2026 % Create a blank row if we are not using the info in the ".aux" file.
2027 % \begin{macrocode}
2028 \def\LT@blank@row{%
2029 \xdef\LT@save@row{\expandafter\LT@build@blank
2030 \romannumeral\number\LT@cols 001 }}
2031 % \end{macrocode}
2032 % Whoops! What's that supposed to be? A drop-in replacement for the
2033 % first task of Appendix~D in the \TeX book. The "\romannumeral"
2034 % produces "\LT@cols" instances of "m" followed by "i". The below
2035 % macro then replaces the "m"s by appropriate entries.
2036 % \begin{macrocode}
2037 \def\LT@build@blank#1{%
2038 \if#1m%
2039 \noexpand\LT@entry{1}{0pt}%
2040 \expandafter\LT@build@blank
2041 \fi}
2042 % \end{macrocode}
2043 % \end{macro}
2044 % \end{macro}
2045 %
2046 % \begin{macro}{\LT@make@row}
2047 % \changes{v4.00}{1996/04/08}
2048 % {(DK) New implementation}
2049 % \changes{v4.01}{1996/04/11}
2050 % {(DPC) Make this the default behaviour, not needing
2051 % \cs{setlongtables}}
2052 %
2053 % Prior to version 4, by default did not use information in the
2054 % ".aux" file but now we can define "\LT@make@row" to use the ".aux"
2055 % file, even on the `draft' passes.
2056 % \begin{macrocode}
2057 \def\LT@make@row{%
2058 \global\expandafter\let\expandafter\LT@save@row
2059 \csname LT@\romannumeral\c@LT@tables\endcsname
2060 \ifx\LT@save@row\relax
2061 \LT@blank@row
2062 % \end{macrocode}
2063 % Now a slightly difficult part comes. Before we decide making the
2064 % template from the ".aux" file info we check that the number of
2065 % fields has remained the same. If it hasn't, either the table format
2066 % has changed, or we have the wrong table altogether. In both cases,
2067 % we decide to better drop all gathered information and start over.
2068 % \changes{v4.01}{1996/04/11}
2069 % {(DPC) Use \cs{if} test rather than \cs{ifx}\cs{@empty}}
2070 %
2071 % The expansion between "!"\ldots"!" below will be empty if the number
2072 % of "\LT@entry" macros
2073 % including arguments in "\LT@save@row" is equal to "\LT@cols". If it
2074 % is not empty, we throw the row away and start from scratch.
2075 % \begin{macrocode}
2076 \else
2077 {\let\LT@entry\or
2078 \if!%
2079 \ifcase\expandafter\expandafter\expandafter\LT@cols
2080 \expandafter\@gobble\LT@save@row
2081 \or
2082 \else
2083 \relax
2084 \fi
2085 !%
2086 \else
2087 \aftergroup\LT@blank@row
2088 \fi}%
2089 \fi}
2090 % \end{macrocode}
2091 % \end{macro}
2092 %
2093 % \begin{macro}{\setlongtables}
2094 % Redefine "\LT@make@row" to use information in the ".aux" file,
2095 % if there is a saved row for this table with the right number of
2096 % columns.
2097 %
2098 % Since Version 3.02, \package{longtable} has used the internal counter
2099 % "\c@LT@tables" rather than the \LaTeX\ counter \textsf{table}.
2100 % The warning message was added at V3.04, as was the "\global", to stop
2101 % save-stack overflow.
2102 %
2103 % Since Version 4.01 "\setlongtables" does nothing as it is not
2104 % needed, but is defined as "\relax" for the benefit of old documents.
2105 % \changes{v3.12}{1994/06/30}
2106 % {Warning altered to fit line on terminal.}
2107 % \changes{v4.01}{1996/04/11}
2108 % {(DPC) make into no op}
2109 % \begin{macrocode}
2110 \let\setlongtables\relax
2111 % \end{macrocode}
2112 % \end{macro}
2113 %
2114 % \begin{macro}{\LT@get@widths}
2115 % This is the heart of \package{longtable}. If it were not for the table
2116 % head and foot, this macro together with the modified "\\" command
2117 % would form the basis of quite a simple little package file for long
2118 % tables. It is closely modelled on the "\endvrulealign" macro of
2119 % appendix D of the \TeX book.
2120 % \begin{macrocode}
2121 \def\LT@get@widths{%
2122 % \end{macrocode}
2123 % "\global" added at V3.04, to stop save-stack overflow.
2124 % \begin{macrocode}
2125 % \end{macrocode}
2126 % Loop through the last row, discarding glue, and saving box widths. At
2127 % V3.04 changed the scratch box to 2, as the new "\kill" requires that
2128 % "\box0" be preserved.
2129 % \changes{v4.14}{2020/02/07}
2130 % {allocated global box (tools/2914)}
2131 % \begin{macrocode}
2132 \setbox\tw@\hbox{%
2133 \unhbox\LT@gbox
2134 \let\LT@old@row\LT@save@row
2135 \global\let\LT@save@row\@empty
2136 \count@\LT@cols
2137 \loop
2138 \unskip
2139 \setbox\tw@\lastbox
2140 \ifhbox\tw@
2141 \LT@def@row
2142 \advance\count@\m@ne
2143 \repeat}%
2144 % \end{macrocode}
2145 % Remember the widths if we are in the first chunk.
2146 % \begin{macrocode}
2147 \ifx\LT@@save@row\@undefined
2148 \let\LT@@save@row\LT@save@row
2149 \fi}
2150 % \end{macrocode}
2151 % \end{macro}
2152 %
2153 % \begin{macro}{\LT@def@row}
2154 % \changes{v4.00}{1996/04/08}
2155 % {(DK) New implementation}
2156 % Add a column to the dummy row. Name changed from "\defLT@save@row"
2157 % in Version~3, to preserve the "\LT@" naming convention.
2158 % \begin{macrocode}
2159 \def\LT@def@row{%
2160 % \end{macrocode}
2161 % We start by picking the respective entry from our old row.
2162 % These redefinitions of "\LT@entry" are local to the group started
2163 % in "\LT@get@widths".
2164 % \begin{macrocode}
2165 \let\LT@entry\or
2166 \edef\@tempa{%
2167 \ifcase\expandafter\count@\LT@old@row
2168 \else
2169 {1}{0pt}%
2170 \fi}%
2171 % \end{macrocode}
2172 % Now we tack the right combination in front of "\LT@save@row":
2173 % \begin{macrocode}
2174 \let\LT@entry\relax
2175 \xdef\LT@save@row{%
2176 \LT@entry
2177 \expandafter\LT@max@sel\@tempa
2178 \LT@save@row}}
2179 % \end{macrocode}
2180 % \end{macro}
2181 %
2182 % \begin{macro}{\LT@max@sel}
2183 % \changes{v4.00}{1996/04/08}
2184 % {(DK) macro added}
2185 % \changes{v4.01}{1996/04/11}
2186 % {(DPC) minor modifications}
2187 % And this is how to select the right combination. Note that we take
2188 % the old maximum information only if the size does not change in
2189 % \emph{either} direction. If the size has grown, we of course have a
2190 % new maximum. If the size has shrunk, the old maximum (which was
2191 % explicitly not enforced because of being in the current chunk) is
2192 % invalid, and we start with this chunk as the new size. Note that
2193 % even in the case of equality we \emph{must} use the "\the\wd\tw@"
2194 % construct instead of "#2" because "#2" might be read in from the
2195 % file, and so could have "\catcode"~11 versions of "p" and~"t" in~it
2196 % which we want to be replaced by their `proper' "\catcode"~12 versions.
2197 % \begin{macrocode}
2198 \def\LT@max@sel#1#2{%
2199 {\ifdim#2=\wd\tw@
2200 #1%
2201 \else
2202 \number\c@LT@chunks
2203 \fi}%
2204 {\the\wd\tw@}}
2205 % \end{macrocode}
2206 % \end{macro}
2207 %
2208 % \subsection{The \cs{hline} Command}
2209 %
2210 % \begin{macro}{\LT@hline}
2211 % "\hline" and "\hline\hline" both produce \emph{two} lines.
2212 % The only difference being the glue and penalties between them.
2213 % This is so that a page break at a "\hline" produces a line on both
2214 % pages.\footnote
2215 % {\env{longtable} has always done this, but perhaps it would be
2216 % better if hlines were \emph{omitted} at a page break, as the head and
2217 % foot usually put a hline here anyway.}
2218 % Also this "\hline" is more like a "\cline{1-\LT@cols}".
2219 % \env{tabular}'s "\hline" would draw lines the full width of the page.
2220 % \begin{macrocode}
2221 \def\LT@hline{%
2222 \noalign{\ifnum0=`}\fi
2223 \penalty\@M
2224 \futurelet\@let@token\LT@@hline}
2225 % \end{macrocode}
2226 % \end{macro}
2227 %
2228 % \begin{macro}{\LT@@hline}
2229 % This code is based on "\cline". Two copies of the line are produced,
2230 % as described above.
2231 % \begin{macrocode}
2232 %<@@=tbl>
2233 \ExplSyntaxOn
2234 \def\LT@@@@hline{%
2235 \ifx\@let@token\hline
2236 \global\let\@gtempa\@gobble
2237 \gdef\LT@sep{\penalty-\@medpenalty\vskip\doublerulesep}%
2238 \else
2239 \global\let\@gtempa\@empty
2240 \gdef\LT@sep{\penalty-\@lowpenalty\vskip-\arrayrulewidth}%
2241 \fi
2242 \ifnum0=`{\fi}%
2243 \multispan\LT@cols
2244 \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
2245 % \end{macrocode}
2246 % Don't update the row counter, or rather undo the update done in \cs{everycr}:
2247 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
2248 % \begin{macrocode}
2249 \noalign{
2250 \tbl_gdecr_row_count:
2251 \LT@sep}
2252 \multispan\LT@cols
2253 \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
2254 % \end{macrocode}
2255 % Same here.
2256 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
2257 % \begin{macrocode}
2258 \noalign{
2259 \tbl_gdecr_row_count:
2260 \penalty\@M}
2261 \@gtempa}
2262 %<@@=>
2263 % \end{macrocode}
2264 % \end{macro}
2265 %
2266 % \subsection{Captions}
2267 %
2268 % \begin{macro}{\LT@caption}
2269 % The caption is "\multicolumn{\LT@cols}{c}{"\meta{a parbox with the
2270 % table's caption}"}"
2271 % \begin{macrocode}
2272 \def\LT@caption{%
2273 \noalign\bgroup
2274 \@ifnextchar[{\egroup\LT@c@ption\@firstofone}\LT@capti@n}
2275 % \end{macrocode}
2276 % \end{macro}
2277 %
2278 % \begin{macro}{\LT@c@ption}
2279 % Caption command (with [optional argument]). "\protect" added in
2280 % Version~3. "\fnum@table" added at V3.05.
2281 % \changes{v3.14}{1995/05/02}
2282 % {Call \cs{LT@makecaption} not \cs{LT@mkcaption}}
2283 % \changes{v3.14}{1995/05/24}
2284 % {Add new control argument}
2285 % \changes{v4.16}{2021/05/07}
2286 % {use \cs{ext@table} gh/561}
2287 % \changes{v4.21}{2024/07/04}
2288 % {Use \cs{LTcaptype} to support other types beside table.}
2289 % \begin{macrocode}
2290 \def\LT@c@ption#1[#2]#3{
2291 \tl_if_empty:eTF{\LTcaptype}
2292 {\LT@makecaption\@gobble{}{#3}}
2293 {\LT@makecaption#1{\csname fnum@\LTcaptype\endcsname}{#3}
2294 \def\@tempa{#2}
2295 \ifx\@tempa\@empty\else
2296 {\let\\\space
2297 \addcontentsline
2298 {\@nameuse{ext@\LTcaptype}}
2299 {\LTcaptype}
2300 {\protect\numberline{\@nameuse{the\LTcaptype}}{#2}}}
2301 \fi}}
2302 \ExplSyntaxOff
2303 % \end{macrocode}
2304 % \end{macro}
2305 %
2306 % \begin{macro}{\LT@capti@n}
2307 % Caption command (no [optional argument])
2308 % \changes{v3.14}{1995/05/02}
2309 % {Call \cs{LT@makecaptionx} not \cs{LT@mkcaption}}
2310 % \changes{v3.14}{1995/05/24}
2311 % {Call \cs{LT@makecaption} with \cs{@gobble} or \cs{@firstofone}}
2312 % \begin{macrocode}
2313 \def\LT@capti@n{%
2314 \@ifstar
2315 {\egroup\LT@c@ption\@gobble[]}%
2316 {\egroup\@xdblarg{\LT@c@ption\@firstofone}}}
2317 % \end{macrocode}
2318 % \end{macro}
2319 %
2320 %
2321 % \begin{macro}{\LT@makecaption}
2322 % Put the caption in a box of width 0pt, so that it never affects the
2323 % column widths. Inside that is a "\parbox" of width
2324 % "\LTcapwidth".
2325 % \changes{v3.14}{1995/05/02}
2326 % {Renamed from \cs{LT@mkcaption},
2327 % and modified to call \cs{@makecaption}}
2328 % \changes{v3.14}{1995/05/02}
2329 % {Use the first arg to remove counter for star form}
2330 % \changes{v4.15}{2021/03/28}
2331 % {\cs{reset@font} for gh/133}
2332 % \begin{macrocode}
2333 \def\LT@makecaption#1#2#3{%
2334 \LT@mcol\LT@cols c{\hbox to\z@{\hss\parbox[t]\LTcapwidth{%
2335 % \end{macrocode}
2336 % Based on article class "\@makecaption", "#1" is "\@gobble" in star
2337 % form, and "\@firstofone" otherwise.
2338 % \begin{macrocode}
2339 \reset@font
2340 \sbox\@tempboxa{#1{#2: }#3}%
2341 \ifdim\wd\@tempboxa>\hsize
2342 #1{#2: }#3%
2343 \else
2344 \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
2345 \fi
2346 \endgraf\vskip\baselineskip}%
2347 \hss}}}
2348 % \end{macrocode}
2349 % \end{macro}
2350 %
2351 %
2352 % \subsection{The Output Routine}
2353 %
2354 % The method used here for interfacing a special purpose output routine
2355 % to the standard \LaTeX\ routine is lifted straight out of
2356 % F.~Mittelbach's \package{multicol} package.
2357 %
2358 % \begin{macro}{\LT@output}
2359 % Actually this is not so bad, with FM leading the way.
2360 % \begin{macrocode}
2361 \ExplSyntaxOn
2362 \def\LT@output{%
2363 \ifnum\outputpenalty <-\@Mi
2364 \ifnum\outputpenalty > -\LT@end@pen
2365 % \end{macrocode}
2366 % If this was a float or a marginpar we complain.
2367 % \begin{macrocode}
2368 \LT@err{floats~ and~ marginpars~ not~ allowed~ in~ a~ longtable}\@ehc
2369 \else
2370 % \end{macrocode}
2371 % We have reached the end of the table, on the scroll at least,
2372 % \begin{macrocode}
2373 \setbox\z@\vbox{\unvbox\@cclv}%
2374 \ifdim \ht\LT@lastfoot>\ht\LT@foot
2375 % \end{macrocode}
2376 % The last foot might not fit, so:\footnote{An alternative would be to
2377 % vsplit off a bit of the last chunk, so that the last page did not just
2378 % have head and foot sections, but it is hard to do this in a consistent
2379 % manner.}
2380 % \changes{v4.14}{2020/02/07}
2381 % {Rearrange vertical space tests for tools/3512 (floats on same page)}
2382 % \changes{v4.24}{2024-10-13}
2383 % {New mark update call gh/1814}
2384 % \changes{v4.25}{2025-12-23}
2385 % {Use Finite shrink gh/1907}
2386 % \begin{macrocode}
2387 \dimen@\pagegoal
2388 \advance\dimen@\ht\LT@foot
2389 \advance\dimen@-\ht\LT@lastfoot
2390 \ifdim\dimen@<\ht\z@
2391 \setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vskip\z@\@plus1fil\@minus\normalbaselineskip}%
2392 \@makecol
2393 \@expl@@@mark@update@singlecol@structures@@
2394 \@outputpage
2395 \global\vsize\@colroom
2396 \setbox\z@\vbox{\box\LT@head}%
2397 % \end{macrocode}
2398 % End of "\ifdim\dimen@<\ht\@cclc".
2399 % \begin{macrocode}
2400 \fi
2401 % \end{macrocode}
2402 % End of "\ifdim \ht\LT@lastfoot > \ht\LT@foot".
2403 % \begin{macrocode}
2404 \fi
2405 % \end{macrocode}
2406 % Reset "\@colroom".
2407 % \changes{v3.14}{1995/05/02}
2408 % {Reset \cs{@colroom}, for tools/1584}
2409 % \changes{v4.14}{2020/02/07}
2410 % {Rearrange vertical space tests for tools/3512 (floats on same page)}
2411 % \begin{macrocode}
2412 % \global\@colroom\@colht
2413 % \global\vsize\@colht
2414 % \end{macrocode}
2415 % Put the last page of the table on to the main vertical list.
2416 % \changes{v4.14}{2020/02/07}
2417 % {Remove box from final page tools/3512}
2418 % \begin{macrocode}
2419 \unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi
2420 % \end{macrocode}
2421 % Handle foot box when tagging:
2422 %
2423 % \changes{v4.19}{2023/12/16}{Support for tagged PDF}
2424 % \begin{macrocode}
2425 \UseTaggingSocket{tbl/longtable/foot}
2426 % \end{macrocode}
2427 %
2428 % End of "\ifnum\outputpenalty > -\LT@end@pen".
2429 % \begin{macrocode}
2430 \fi
2431 % \end{macrocode}
2432 % Else "\outputpenalty > -\@Mi".
2433 % \begin{macrocode}
2434 \else
2435 % \end{macrocode}
2436 % If we have not reached the end of the table,
2437 % \begin{macrocode}
2438 \setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vskip\z@\@plus1fil\@minus\normalbaselineskip}%
2439 % \end{macrocode}
2440 %
2441 % Handle foot box when tagging:
2442 % \changes{v4.19}{2023/12/16}{Support for tagged PDF}
2443 % \begin{macrocode}
2444 \UseTaggingSocket{tbl/longtable/foot}
2445 % \end{macrocode}
2446 %
2447 % \begin{macrocode}
2448 \@makecol
2449 \@expl@@@mark@update@singlecol@structures@@
2450 \@outputpage
2451 % \end{macrocode}
2452 % Reset "\vsize".
2453 % \changes{v3.14}{1995/05/02}
2454 % {Reset \cs{vsize}, for tools/1584}
2455 % \begin{macrocode}
2456 \global\vsize\@colroom
2457 % \end{macrocode}
2458 % Put the head at the top of the next page.
2459 % \changes{v4.11}{2004/02/01}
2460 % {\cs{nobreak}, for tools/3484}
2461 % \begin{macrocode}
2462 \copy\LT@head\nobreak
2463 % \end{macrocode}
2464 % End of "\ifnum\outputpenalty <-\@Mi".
2465 % \begin{macrocode}
2466 \fi}
2467 % \end{macrocode}
2468 %
2469 % \begin{macrocode}
2470 \ExplSyntaxOff
2471 %<@@=>
2472 % \end{macrocode}
2473 % \end{macro}
2474 %
2475 %
2476 %
2477 % \subsection{Commands for the table head and foot}
2478 %
2479 % \begin{macro}{\LT@end@hd@ft}
2480 % The core of "\endhead" and friends. Store the current chunk in the
2481 % box specified by "#1". Issue an error if the table has already
2482 % started. Then start a new chunk.
2483 % \begin{macrocode}
2484 %<@@=tbl>
2485 \ExplSyntaxOn
2486 \def\LT@end@hd@ft#1{%
2487 % \end{macrocode}
2488 %
2489 % This command is used to store the head and foot boxes.
2490 % We need to retrieve and store the row so that we can clean
2491 % up the structure in the finalize code.
2492 %
2493 % To handle missing columns in the header we need this:
2494 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
2495 % \begin{macrocode}
2496 \tbl_if_row_was_started:TF
2497 {
2498 % \end{macrocode}
2499 % TODO: This is exposing internal counters, so it should be encapsulated
2500 % in some interface command (but I'm not sure what that should be
2501 % called, so not done yet.
2502 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
2503 % \begin{macrocode}
2504 \tbl_count_missing_cells:n {head/foot}
2505 \int_step_inline:nn
2506 { \LT@rows + 1 }
2507 {
2508 \seq_gput_left:ce
2509 {g_@@_\cs_to_str:N #1 _rows_seq }
2510 { \int_eval:n {\g_@@_row_int + 1 - ##1 } }
2511 }
2512 % \end{macrocode}
2513 % We also have to set the chunk rows to its max value before
2514 % calling \cs{LTechunk} so that we don't get extra increments of
2515 % the main row counter due to \cs{everycr}.
2516 % \begin{macrocode}
2517 \int_gset:Nn \LT@rows { \LTchunksize }
2518 }
2519 % \end{macrocode}
2520
2521 % If we are still in column zero then we had an empty \cs{endhead}
2522 % and so making any assignment, etc., would start a row --- something we don't want.
2523 % To get out of this trap we run \cs{crcr} (which would normally
2524 % come inside \cs{LT@echunk}. That will then trigger \cs{everycr}
2525 % and update row counter unnecessarily, but now we have a defined state, so
2526 % we can use \cs{noalign} to undo that.
2527 % We also change \cs{LT@rows} so that further \cs{cr}s do not do
2528 % any harm (as explained above.
2529 %
2530 % The \cs{crcr} inside \cs{LT@echunk} will be bypassed in that case
2531 % as we have just executed a \cs{crcr} and are still in scanning modus for
2532 % \cs{omit} or \cs{noalign}.
2533 % \begin{macrocode}
2534 {
2535 \crcr
2536 \noalign{
2537 % \end{macrocode}
2538 % \changes{v4.22}{2024/08/13}{Store header row numbers}
2539 % \begin{macrocode}
2540 \int_step_inline:nn
2541 { \LT@rows }
2542 {
2543 \seq_gput_left:ce
2544 {g_@@_\cs_to_str:N #1 _rows_seq }
2545 { \int_eval:n {\g_@@_row_int - ##1 } }
2546 }
2547 % \end{macrocode}
2548 % \changes{v4.19}{2023/12/16}{Managing cell indexes}
2549 % \begin{macrocode}
2550 \tbl_gdecr_row_count: % undo the increment
2551 \int_gset:Nn \LT@rows { \LTchunksize }
2552 }
2553 }
2554 \LT@echunk
2555 % \end{macrocode}
2556 % Changed from "\relax" to "\endgraf" at V3.04, see "\LT@start".
2557 % \begin{macrocode}
2558 \ifx\LT@start\endgraf
2559 \LT@err
2560 {Longtable~ head~ or~ foot~ not~ at~ start~ of~ table}%
2561 {Increase~ LTchunksize}%
2562 \fi
2563 \setbox#1\box\z@
2564 \@@_trace:n {-->>~ Saving~\noexpand#1}
2565 \LT@get@widths
2566 \LT@bchunk}
2567 % \end{macrocode}
2568 %
2569 % \begin{macrocode}
2570 \ExplSyntaxOff
2571 %<@@=>
2572 % \end{macrocode}
2573 % \end{macro}
2574 %
2575 % \begin{macro}{\endfirsthead}
2576 % \begin{macro}{\endhead}
2577 % \begin{macro}{\endfoot}
2578 % \begin{macro}{\endlastfoot}
2579 % Call "\LT@end@hd@ft" with the appropriate box.
2580 % \begin{macrocode}
2581 \def\endfirsthead{\LT@end@hd@ft\LT@firsthead}
2582 \def\endhead{\LT@end@hd@ft\LT@head}
2583 \def\endfoot{\LT@end@hd@ft\LT@foot}
2584 \def\endlastfoot{\LT@end@hd@ft\LT@lastfoot}
2585 % \end{macrocode}
2586 % \end{macro}
2587 % \end{macro}
2588 % \end{macro}
2589 % \end{macro}
2590 %
2591 % \subsection{The \cs{multicolumn} command}
2592 %
2593 % Earlier versions needed a special `draft' form of "\multicolumn".
2594 % This is not needed in version~4, and so these commands have been
2595 % removed.
2596 %
2597 % \begin{macro}{\LTmulticolumn}
2598 % \changes{v4.01}{1996/04/11}
2599 % {(DPC) macro removed}
2600 % \end{macro}
2601 %
2602 % \begin{macro}{\LT@mcwarn}
2603 % \changes{v4.01}{1996/04/11}
2604 % {(DPC) macro removed}
2605 % \end{macro}
2606 %
2607 % \subsection{Footnotes}
2608 %
2609 % The standard "\footnote" command works in a "c" column, but we
2610 % need to modify the definition in a "p" column to overcome the
2611 % extra level of boxing. These macros are based on the \package{array}
2612 % package, but should be OK for the standard \env{tabular}.
2613 %
2614 % \begin{macro}{\LT@startpbox}
2615 % \changes{v4.09}{1998/05/13}
2616 % {Use \cs{setlength}, so that calc extensions apply. tools/2793}
2617 % Add extra code to switch the definition of "\@footnotetext".
2618 % \begin{macrocode}
2619 \def\LT@startpbox#1{%
2620 \bgroup
2621 % \end{macrocode}
2622 % \changes{v4.12}{2019/02/06}{Color group to match array package}
2623 % \changes{v4.18}{2023/08/25}{Use \cs{everypar} to match array package, github 1128}
2624 % \begin{macrocode}
2625 \color@begingroup
2626 \let\@footnotetext\LT@p@ftntext
2627 \setlength\hsize{#1}%
2628 \@arrayparboxrestore
2629 \everypar{%
2630 \vrule \@height \ht\@arstrutbox \@width \z@
2631 \everypar{}}%
2632 }
2633 % \end{macrocode}
2634 % \end{macro}
2635 %
2636 % \begin{macro}{\LT@endpbox}
2637 % After the parbox is closed, expand "\LT@p@ftn" which will execute a
2638 % series of\\
2639 % "\footnotetext["\meta{num}"]{"\meta{note}"}"\\
2640 % commands. After being lifted out of the parbox, they can migrate on
2641 % their own from here.
2642 % \changes{v3.10}{1994/05/15}
2643 % {Use \cs{@finalstrut}}
2644 % \changes{v4.03}{1996/05/07}
2645 % {Use \cs{hfil} for tools/2120}
2646 % \begin{macrocode}
2647 \def\LT@endpbox{%
2648 \@finalstrut\@arstrutbox
2649 % \end{macrocode}
2650 % \changes{v4.12}{2019/02/06}{Color group to match array package}
2651 % \begin{macrocode}
2652 \color@endgroup
2653 \egroup
2654 \the\LT@p@ftn
2655 \global\LT@p@ftn{}%
2656 \hfil}
2657 % \end{macrocode}
2658 % \end{macro}
2659 %
2660 % \begin{macro}{\LT@p@ftntext}
2661 % \changes{v4.15}{2021/03/28}
2662 % {make long for gh/364}
2663 % Inside the `p' column, just save up the footnote text in a token
2664 % register.
2665 % \begin{macrocode}
2666 \long\def\LT@p@ftntext#1{%
2667 \edef\@tempa{\the\LT@p@ftn\noexpand\footnotetext[\the\c@footnote]}%
2668 \global\LT@p@ftn\expandafter{\@tempa{#1}}}%
2669 % \end{macrocode}
2670 % \end{macro}
2671 %
2672 %
2673 % \subsection{Supporting hooks}
2674 %
2675 % Since \pkg{longtable} is supposed to work without loading
2676 % \pkg{array}, i.e., just with the \env{tabular} code from the
2677 % kernel and that code has no hooks. We therefore do not run any
2678 % hook if \pkg{array} is not loaded, because otherwise those
2679 % explicitly used in the \pkg{longtable} code would run, but the
2680 % corresponding ones that are only in the \pkg{array} code are not.
2681 % By default we assume \pkg{array} is not loaded.
2682 % \begin{macrocode}
2683 \let \ArrayLoadedT \@gobble
2684 % \end{macrocode}
2685 % If it is we change and the hooks get executed.
2686 % \begin{macrocode}
2687 \AddToHook{package/array/after}{\let \ArrayLoadedT \@firstofone}
2688 % \end{macrocode}
2689 %
2690 %
2691 %
2692 %
2693 % \subsection{Tagging support}
2694 %
2695 % Some variables need for the tagging support.
2696 % \begin{macrocode}
2697 %<@@=tbl>
2698 \ExplSyntaxOn
2699 \seq_new:N \g_@@_LT@firsthead_rows_seq
2700 \seq_new:N \g_@@_LT@head_rows_seq
2701 \seq_new:N \g_@@_LT@lastfoot_rows_seq
2702 \seq_new:N \g_@@_LT@foot_rows_seq
2703 \ExplSyntaxOff
2704 %<@@=>
2705 % \end{macrocode}
2706 %
2707 %
2708 %
2709 % \begin{macrocode}
2710 %</package>
2711 % \end{macrocode}
2712 %
2713 % \Finale
2714 \endinput