diff options
Diffstat (limited to 'macros/latex-dev/required/tools/longtable.dtx')
-rw-r--r-- | macros/latex-dev/required/tools/longtable.dtx | 366 |
1 files changed, 339 insertions, 27 deletions
diff --git a/macros/latex-dev/required/tools/longtable.dtx b/macros/latex-dev/required/tools/longtable.dtx index 2a61ab0c87..5a23f3ecb3 100644 --- a/macros/latex-dev/required/tools/longtable.dtx +++ b/macros/latex-dev/required/tools/longtable.dtx @@ -1,6 +1,6 @@ % \iffalse meta-comment % -% Copyright (C) 1993-2023 +% Copyright (C) 1993-2024 % % The LaTeX Project and any individual authors listed elsewhere % in this file. @@ -37,7 +37,7 @@ %<driver> \ProvidesFile{longtable.drv} % \fi % \ProvidesFile{longtable.dtx} - [2023-11-01 v4.19 Multi-page Table package (DPC)] + [2023-12-16 v4.19 Multi-page Table package (DPC)] % % \iffalse %<*driver> @@ -1048,6 +1048,14 @@ \if@twocolumn \LT@err{longtable not in 1-column mode}\@ehc \fi +% \end{macrocode} +% +% \changes{v4.19}{2023/12/16}{Support for tagged PDF} +% \begin{macrocode} + \UseTaggingSocket{tbl/vmode/begin}% +% \end{macrocode} +% +% \begin{macrocode} \begingroup % \end{macrocode} % Check for an optional argument. @@ -1056,7 +1064,14 @@ % \end{macrocode} % \end{macro} % +% +% % \begin{macro}{\LT@array} +% \begin{macrocode} +%<@@=tbl> +\ExplSyntaxOn +% \end{macrocode} +% % Start setting the alignment. % Based on "\@array" from the \LaTeX\ kernel % and the \package{array} package. @@ -1066,7 +1081,43 @@ % so that "\caption" works correctly. % \begin{macrocode} \def\LT@array[#1]#2{% - \refstepcounter{table}\stepcounter{LT@tables}% +% \end{macrocode} +% +% With respect to tagging we have a complicated situation with +% longtable. When at the begin the \cs{endhead}, +% \cs{endfirsthead}, \cs{endfoot} and \cs{endlastfoot} are used to +% setup head and foot they create each a structure subtree with one or +% more rows. From these structures we want to keep at most two (head +% and foot) and move the foot to the end of the table. When the head +% and foot boxes are (re)inserted on following pages we want to mark +% them up as artifact with the exception of the head at the begin and +% the foot box at the end. +% +% TODO: When a line is killed the structure subtree is there already +% too and must be removed. If hard to do, then maybe at first warn if the +% construction is used. +% +% \cs{LT@array} is executed in a group, so we can disable para-tagging here. +% \changes{v4.19}{2023/12/16}{Support for tagged PDF} +% \begin{macrocode} + \UseTaggingSocket{tbl/init} + \@kernel@refstepcounter{table}\stepcounter{LT@tables} +% \end{macrocode} +% The target is created rather late and a \cs{label} can come earlier, +% so we have to define \cs{@currentHref} explicitly. We can't currently +% assume that \cs{theHtable} is defined always. +% \begin{macrocode} + \tl_gset:Ne \@currentHref {table.\cs_if_exist_use:N\theHtable} +% \end{macrocode} +% +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \tbl_gzero_row_count: +% \end{macrocode} +% +% \changes{v4.19}{2023/12/16}{Support for tagged PDF} +% \begin{macrocode} + \UseTaggingSocket{tbl/longtable/init} % \end{macrocode} % Set up the glue around the table if an optional argument given. % \begin{macrocode} @@ -1101,17 +1152,18 @@ % here so that you can load the \package{array} package before or after % \package{longtable}. % \begin{macrocode} - \let\LT@@tabarray\@tabarray - \let\LT@@hl\hline + \let\LT@@@@tabarray\@tabarray + \let\LT@@@@hl\hline \def\@tabarray{% - \let\hline\LT@@hl + \let\hline\LT@@@@hl % \end{macrocode} %\begin{verbatim} % \let\multicolumn\LT@mcol %\end{verbatim} % \begin{macrocode} - \LT@@tabarray}% - \let\\\LT@tabularcr\let\tabularnewline\\% + \LT@@@@tabarray}% + \let\\\LT@tabularcr + \let\tabularnewline\\% \def\newpage{\noalign{\break}}% % \end{macrocode} % \changes{v4.05}{1996/11/12} @@ -1128,8 +1180,8 @@ % \end{macrocode} % % \changes{v4.08}{1998/01/20} -% {Move \cs{@endpbox} definition earlier and define \cs{@@endpbox} -% and \cs{@@startpbox} for non-array case. tools/2736} +% {Move \cs{@endpbox} definition earlier and define \cs{@@@@endpbox} +% and \cs{@@@@startpbox} for non-array case. tools/2736} % \begin{macrocode} \let\@endpbox\LT@endpbox % \end{macrocode} @@ -1142,8 +1194,8 @@ \let\@acol\@tabacol \let\@classz\@tabclassz \let\@classiv\@tabclassiv \def\@startpbox{\vtop\LT@startpbox}% - \let\@@startpbox\@startpbox - \let\@@endpbox\@endpbox + \let\@@@@startpbox\@startpbox + \let\@@@@endpbox\@endpbox \let\LT@LL@FM@cr\@tabularcr \else % \end{macrocode} @@ -1172,6 +1224,11 @@ \begingroup \@mkpream{#2}% % \end{macrocode} +% +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \tbl_count_table_cols: +% \end{macrocode} % We need to rename "\@preamble" here as F.M.'s scheme uses % "\global", and we may need to nest "\@mkpream", eg for % "\multicolumn" @@ -1180,6 +1237,11 @@ % \begin{macrocode} \xdef\LT@bchunk{% % \end{macrocode} +% We aren't inside any row when a chunk starts. +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \tbl_inbetween_rows: +% \end{macrocode} % \changes{v4.00}{1996/04/08} % {(DK) Increment Chunk counter} % \begin{macrocode} @@ -1205,7 +1267,21 @@ % \begin{macrocode} \tabskip\LTleft \noexpand\halign to\hsize\bgroup % \tabskip\LTleft\halign to\hsize\bgroup - \tabskip\z@ \@arstrut \@preamble \tabskip\LTright \cr}% + \tabskip\z@ \@arstrut +% \end{macrocode} +% Insert the tagging socket to start the row and initialize the cell +% data for the row. +% \changes{v4.19}{2023/12/16}{Support for tagged PDF} +% \begin{macrocode} + \UseTaggingSocket{tbl/row/begin}% +% \end{macrocode} +% +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \tbl_init_cell_data_for_row: +% \end{macrocode} +% \begin{macrocode} + \@preamble \tabskip\LTright \cr}% \endgroup % \end{macrocode} % Find out how many columns we have (store in "\LT@cols"). @@ -1220,11 +1296,57 @@ % A few more internal commands for \env{longtable}. % \begin{macrocode} \m@th\let\par\@empty - \everycr{}\lineskip\z@\baselineskip\z@ +% \end{macrocode} +% Tagging socket and conditional +% \begin{macrocode} + \everycr{% + \noalign{% +% \end{macrocode} +% In \pkg{longtable} we have a bunch of extra \cs{cr}s that are +% executed whenever a chunk ends. In that case they should not +% increment the main row counter, sigh. +% +% TODO: At the moment this tracing still exposes the internal row counter! +% \begin{macrocode} + \@@_trace:n {--longtable-->~chunk~row:~ \the\LT@rows \space + row:~ \the\g_@@_row_int \space + column:~ \the\g_@@_col_int + } +% \end{macrocode} +% +% \changes{v4.19}{2023/12/16}{Support for tagged PDF} +% \begin{macrocode} + \tbl_if_row_was_started:T + { + \UseTaggingSocket{tbl/row/end} +% \end{macrocode} +% The next setting prevents any of the additional \cs{cr}s at the end of the +% chunk to add another /TR. Then once we really start a new chunk +% it gets incremented so\ldots +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \tbl_inbetween_rows: + } +% \end{macrocode} +% And for the same reason such \cs{cr}s should not increment the +% main row counter (but it has to be incremented after the preamble +% of a chunk), so here we test against \cs{LT@rows} which is +% \cs{LTchunksize} at the end of a chunk. +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \int_compare:nNnT \LT@rows < \LTchunksize + { \tbl_gincr_row_count: } % next is row about to start + }% + }% +% \end{macrocode} +% \begin{macrocode} + \lineskip\z@\baselineskip\z@ % \end{macrocode} % Start the first chunk. % \begin{macrocode} \LT@bchunk} +\ExplSyntaxOff +%<@@=> % \end{macrocode} % \end{macro} % @@ -1251,6 +1373,11 @@ % force the page-breaker to wake up. The second "\endgraf" is there so % that "\pagetotal" is updated and so takes "\LTpre" into account. % \begin{macrocode} +%<@@=tbl> +\ExplSyntaxOn +% \end{macrocode} +% +% \begin{macrocode} \def\LT@start{% \let\LT@start\endgraf \endgraf\penalty\z@\vskip\LTpre\endgraf @@ -1334,7 +1461,7 @@ % \changes{v3.14}{1995/05/02} % {Set \cs{@colroom}, for tools/1584} % \begin{macrocode} - \global\@colroom\@colht + \global\@colroom\@colht % \end{macrocode} % If the foot is non empty, reduce the "\vsize" and "\@colroom" % accordingly. @@ -1342,24 +1469,46 @@ % {Rearrange vertical space tests for tools/3512 (floats on same page)} % \begin{macrocode} \ifvoid\LT@foot\else -% \advance\vsize-\ht\LT@foot \global\advance\vsize-\ht\LT@foot \global\advance\@colroom-\ht\LT@foot \dimen@\pagegoal\advance\dimen@-\ht\LT@foot\pagegoal\dimen@ \maxdepth\z@ \fi % \end{macrocode} +% +% \begin{macrocode} + \MakeLinkTarget{table} +% \end{macrocode} % Put the table head on the page, and then switch to the new output % routine. % \changes{v4.11}{2004/02/01} % {\cs{nobreak}, for tools/3484} % \begin{macrocode} \ifvoid\LT@firsthead\copy\LT@head\else\box\LT@firsthead\fi\nobreak +% \end{macrocode} +% +% \changes{v4.19}{2023/12/16}{Support for tagged PDF} +% \begin{macrocode} + \UseTaggingSocket{tbl/longtable/head} +% \end{macrocode} +% +% \begin{macrocode} \output{\LT@output}} +\ExplSyntaxOff +%<@@=> % \end{macrocode} % \end{macro} % +% +% +% % \begin{macro}{\endlongtable} +% +% \begin{macrocode} +%<@@=tbl> +\ExplSyntaxOn +% \end{macrocode} +% % Called by "\end{longtable}". % \begin{macrocode} \def\endlongtable{% @@ -1370,11 +1519,23 @@ % been shortened, or the table numbering has gone awry). In that case % we at least start collecting valid new information with the last % chunk of this table, by removing the width constraint. +% \changes{v4.19}{2023/12/16}{Support for tagged PDF} +% \begin{macrocode} + \tbl_crcr:n {endlongtable} +% \end{macrocode} +% % \changes{v4.01}{1996/04/11} % {(DPC) use \cs{noalign} to sneak in \cs{LT@entry@chop}} % \begin{macrocode} - \crcr \noalign{% +% \end{macrocode} +% +% \changes{v4.19}{2023/12/16}{Support for tagged PDF} +% \begin{macrocode} + \UseTaggingSocket{tbl/longtable/finalize} +% \end{macrocode} +% +% \begin{macrocode} \let\LT@entry\LT@entry@chop \xdef\LT@save@row{\LT@save@row}}% \LT@echunk @@ -1414,10 +1575,10 @@ % \changes{v4.04}{1996/05/24} % {Use \cs{LT@final@warn}} % \begin{macrocode} - \ifx\LT@save@row\LT@@save@row + \ifx\LT@save@row\LT@@@@save@row \else - \LT@warn{Column \@width s have changed\MessageBreak - in table \thetable}% + \LT@warn{Column~ widths~ have~ changed\MessageBreak + in~ table~ \thetable}% \LT@final@warn \fi % \end{macrocode} @@ -1449,7 +1610,15 @@ % \end{macrocode} % Footnotes. As done in the \package{multicol} package. % \begin{macrocode} - \ifvoid\footins\else\insert\footins{}\fi} + \ifvoid\footins\else\insert\footins{}\fi +% \end{macrocode} +% +% \changes{v4.19}{2023/12/16}{Support for tagged PDF} +% \begin{macrocode} + \UseTaggingSocket{tbl/vmode/end}% +} +\ExplSyntaxOff +%<@@=> % \end{macrocode} % \end{macro} % @@ -1518,6 +1687,10 @@ \protected\def\LT@tabularcr{% \relax\iffalse{\fi\ifnum0=`}\fi \@ifstar +% \end{macrocode} +% TODO: as we replace crcr later in one case, we probably have to +% implement some further logic there! +% \begin{macrocode} {\def\crcr{\LT@crcr\noalign{\nobreak}}\let\cr\crcr \LT@t@bularcr}% {\LT@t@bularcr}} @@ -1544,8 +1717,13 @@ % \end{macrocode} % \end{macro} % +% +% +% % \begin{macro}{\LT@t@bularcr} % \begin{macrocode} +%<@@=tbl> +\ExplSyntaxOn \def\LT@t@bularcr{% % \end{macrocode} % Increment the counter, and do \env{tabular}'s "\\" or finish the @@ -1555,6 +1733,13 @@ % \begin{macrocode} \global\advance\LT@rows\@ne \ifnum\LT@rows=\LTchunksize +% \end{macrocode} +% At the end of the chunk \verb=\\= is doing something special and +% so we lose \verb=\tbl_count_missing_cells:n=. Below is about the +% right place to add it do this code branch. +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \tbl_count_missing_cells:n {echunk} \gdef\LT@setprevdepth{% \prevdepth\z@ \global\let\LT@setprevdepth\relax}% @@ -1563,6 +1748,8 @@ \ifnum0=`{}\fi \expandafter\LT@LL@FM@cr \fi} +\ExplSyntaxOff +%<@@=> % \end{macrocode} % \end{macro} % @@ -1943,7 +2130,9 @@ % This code is based on "\cline". Two copies of the line are produced, % as described above. % \begin{macrocode} -\def\LT@@hline{% +%<@@=tbl> +\ExplSyntaxOn +\def\LT@@@@hline{% \ifx\@let@token\hline \global\let\@gtempa\@gobble \gdef\LT@sep{\penalty-\@medpenalty\vskip\doublerulesep}% @@ -1954,11 +2143,25 @@ \ifnum0=`{\fi}% \multispan\LT@cols \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr - \noalign{\LT@sep}% +% \end{macrocode} +% Don't update the row counter, or rather undo the update done in \cs{everycr}: +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \noalign{ + \tbl_gdecr_row_count: + \LT@sep} \multispan\LT@cols \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr - \noalign{\penalty\@M}% +% \end{macrocode} +% Same here. +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \noalign{ + \tbl_gdecr_row_count: + \penalty\@M} \@gtempa} +\ExplSyntaxOff +%<@@=> % \end{macrocode} % \end{macro} % @@ -2049,13 +2252,15 @@ % \begin{macro}{\LT@output} % Actually this is not so bad, with FM leading the way. % \begin{macrocode} +%<@@=tbl> +\ExplSyntaxOn \def\LT@output{% \ifnum\outputpenalty <-\@Mi \ifnum\outputpenalty > -\LT@end@pen % \end{macrocode} % If this was a float or a marginpar we complain. % \begin{macrocode} - \LT@err{floats and marginpars not allowed in a longtable}\@ehc + \LT@err{floats~ and~ marginpars~ not~ allowed~ in~ a~ longtable}\@ehc \else % \end{macrocode} % We have reached the end of the table, on the scroll at least, @@ -2103,6 +2308,13 @@ % \begin{macrocode} \unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi % \end{macrocode} +% Handle foot box when tagging: +% +% \changes{v4.19}{2023/12/16}{Support for tagged PDF} +% \begin{macrocode} + \UseTaggingSocket{tbl/longtable/foot} +% \end{macrocode} +% % End of "\ifnum\outputpenalty > -\LT@end@pen". % \begin{macrocode} \fi @@ -2114,6 +2326,15 @@ % If we have not reached the end of the table, % \begin{macrocode} \setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}% +% \end{macrocode} +% +% Handle foot box when tagging: +% \changes{v4.19}{2023/12/16}{Support for tagged PDF} +% \begin{macrocode} + \UseTaggingSocket{tbl/longtable/foot} +% \end{macrocode} +% +% \begin{macrocode} \@makecol \@outputpage % \end{macrocode} @@ -2133,8 +2354,15 @@ % \begin{macrocode} \fi} % \end{macrocode} +% +% \begin{macrocode} +\ExplSyntaxOff +%<@@=> +% \end{macrocode} % \end{macro} % +% +% % \subsection{Commands for the table head and foot} % % \begin{macro}{\LT@end@hd@ft} @@ -2142,20 +2370,86 @@ % box specified by "#1". Issue an error if the table has already % started. Then start a new chunk. % \begin{macrocode} +%<@@=tbl> +\ExplSyntaxOn \def\LT@end@hd@ft#1{% +% \end{macrocode} +% +% This command is used to store the head and foot boxes. +% We need to retrieve and store the row so that we can clean +% up the structure in the finalize code. +% +% To handle missing columns in the header we need this: +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \tbl_if_row_was_started:TF + { +% \end{macrocode} +% TODO: This is exposing internal counters, so it should be encapsulated +% in some interface command (but I'm not sure what that should be +% called, so not done yet. +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \tbl_count_missing_cells:n {head/foot} + \int_step_inline:nn + { \LT@rows + 1 } + { + \seq_gput_left:ce + {g_@@_\cs_to_str:N #1 _rows_seq } + { \int_eval:n {\g_@@_row_int + 1 - ##1 } } + } +% \end{macrocode} +% We also have to set the chunk rows to its max value before +% calling \cs{LTechunk} so that we don't get extra increments of +% the main row counter due to \cs{everycr}. +% \begin{macrocode} + \int_gset:Nn \LT@rows { \LTchunksize } + } +% \end{macrocode} + +% If we are still in column zero then we had an empty \cs{endhead} +% and so making any assignment, etc., would start a row --- something we don't want. +% To get out of this trap we run \cs{crcr} (which would normally +% come inside \cs{LT@echunk}. That will then trigger \cs{everycr} +% and update row counter unnecessarily, but now we have a defined state, so +% we can use \cs{noalign} to undo that. +% We also change \cs{LT@rows} so that further \cs{cr}s do not do +% any harm (as explained above. +% +% The \cs{crcr} inside \cs{LT@echunk} will be bypassed in that case +% as we have just executed a \cs{crcr} and are still in scanning modus for +% \cs{omit} or \cs{noalign}. +% \begin{macrocode} + { + \crcr + \noalign{ +% \end{macrocode} +% +% \changes{v4.19}{2023/12/16}{Managing cell indexes} +% \begin{macrocode} + \tbl_gdecr_row_count: % undo the increment + \int_gset:Nn \LT@rows { \LTchunksize } + } + } \LT@echunk % \end{macrocode} % Changed from "\relax" to "\endgraf" at V3.04, see "\LT@start". % \begin{macrocode} \ifx\LT@start\endgraf \LT@err - {Longtable head or foot not at start of table}% - {Increase LTchunksize}% + {Longtable~ head~ or~ foot~ not~ at~ start~ of~ table}% + {Increase~ LTchunksize}% \fi \setbox#1\box\z@ + \@@_trace:n {-->>~ Saving~\noexpand#1} \LT@get@widths \LT@bchunk} % \end{macrocode} +% +% \begin{macrocode} +\ExplSyntaxOff +%<@@=> +% \end{macrocode} % \end{macro} % % \begin{macro}{\endfirsthead} @@ -2255,6 +2549,24 @@ % \end{macrocode} % \end{macro} % +% +% +% +% +% Some variables need for the tagging support. +% \begin{macrocode} +%<@@=tbl> +\ExplSyntaxOn + \seq_new:N \g_@@_LT@firsthead_rows_seq + \seq_new:N \g_@@_LT@head_rows_seq + \seq_new:N \g_@@_LT@lastfoot_rows_seq + \seq_new:N \g_@@_LT@foot_rows_seq +\ExplSyntaxOff +%<@@=> +% \end{macrocode} +% +% +% % \begin{macrocode} %</package> % \end{macrocode} |