Debian Codegraph @

texmf-dist/source/latex-dev/latex-lab/latex-lab-table.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: latex-lab-table.dtx (C) Copyright 2023-2026 LaTeX Project
4 %
5 % It may be distributed and/or modified under the conditions of the
6 % LaTeX Project Public License (LPPL), either version 1.3c of this
7 % license or (at your option) any later version. The latest version
8 % of this license is in the file
9 %
10 % https://www.latex-project.org/lppl.txt
11 %
12 %
13 % The latex-lab bundle is developed in the LaTeX2e GitHub.
14 % Issues may be reported at
15 %
16 % https://github.com/latex3/latex2e/issues
17 %
18 \def\ltlabtbldate{2026-04-28}
19 \def\ltlabtblversion{0.85t}
20 %<*driver>
21 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
22 \documentclass[kernel]{l3in2edoc}
23
24 \EnableCrossrefs
25 \CodelineIndex
26 \begin{document}
27 \DocInput{latex-lab-table.dtx}
28 \end{document}
29 %</driver>
30 %
31 % \fi
32 %
33 %
34 %
35 %
36 % \title{The \textsf{latex-lab-table} package\\
37 % Changes related to the tagging of tables}
38 % \author{Frank \& Ulrike, \LaTeX{} Project\thanks{Initial implementation done by Frank Mittelbach}}
39 % \date{v\ltlabtblversion\ \ltlabtbldate}
40 %
41 % \maketitle
42 %
43 % \newcommand{\xt}[1]{\textsl{\textsf{#1}}}
44 % \newcommand{\TODO}[1]{\textbf{[TODO:} #1\textbf{]}}
45 % \newcommand{\docclass}{document class \marginpar{\raggedright document class
46 % customizations}}
47 %
48 %
49 % \begin{abstract}
50 % The following code implements a first draft for the tagging of
51 % tables. It still has a large number of limitations and restrictions!
52 % \end{abstract}
53 %
54 % \tableofcontents
55 %
56 % \section{Documentation}
57 %
58 % In \LaTeX{} the word \texttt{table} is used as the name of the float environment that can contain
59 % a data table\footnote{But it does not really have to, you can put
60 % other material into such environments.} along with a caption and some additional text. The environments for
61 % actual data tables have various names like \texttt{tabular}, \texttt{tabular*},
62 % \texttt{tabularx} and \texttt{longtable}---the last should not be used inside a float
63 % and supports its own caption command.
64 %
65 % In this documentation \enquote{table} always means such data tables and not the float
66 % environment.
67 %
68 % From a high level perspective the tagging of tables doesn't look very difficult: one only has to
69 % surround rows and cells by TR and TH or TD structures.
70 % But there are difficulties:
71 % \begin{itemize}
72 % \item
73 % One is that over the years various packages related to tables have
74 % been written that all change some of the internals. Inserting the
75 % tagging commands and testing all the variants and various nestings
76 % is not trivial.
77 %
78 % \item
79 % The other difficulty is that most of the existing environments to
80 % create tables do not know the concept of headers as a semantic
81 % structure.
82 % Headers are only produced through visual formatting, e.g., by
83 % making them bold or by underlying some color. But accessible
84 % tables should have properly marked up headers and
85 % this means that additional syntax to declare headers (when they
86 % can't be guessed) must be developed. This is still an area for
87 % research.
88 % \end{itemize}
89 %
90 % Right now, this module therefore implements only some basic
91 % support for the tagging of tables. A list of the known limitations
92 % is shown below.
93 %
94 % \subsection{Use}
95 % The module is loaded when you use \cs{DocumentMetadata} and if tagging is active
96 % it will automatically tag all already supported table environments
97 % the exception of tables in the header and footer of the page (where tagging is disabled).
98 % Such tables can be nested.
99 %
100 % Inside cells the automatic tagging of paragraphs is disabled with the exception of
101 % p/m/b-type cells.
102 %
103 % Rows do not need to contain a full number of \&, missing cells are automatically
104 % added with an empty TD-structure.
105 %
106 % You should not insert meaningful text with \verb+!{...}+ or \verb+@{...}+ or \cs{noalign}
107 % between the rows or columns of the table.
108 % With pdflatex such text will be unmarked, with lualatex it will be marked as artifact.
109 % Either case means that it will be currently ignored in the
110 % structure.\footnote{While it is theoretically possible
111 % to collect such text and move it into a structure it would require manual markup
112 % from the author to clarify where this text belongs too.}
113 %
114 % As mentioned below the \pkg{colortbl} doesn't work fully with the tagging,
115 % but when it does, colors inside the table are currently ignored by the tagging.
116 % If such a color has a semantic meaning (like \enquote{important value})
117 % this meaning will be lost.
118 %
119 % \subsection{Untagged and presentation tables}
120 % If a table should not be tagged as table, for example because it is merely used
121 % as a layout tool to ensure that the content is properly aligned
122 % or because it is a not yet (fully) supported table structure,
123 % the tagging can be disabled with
124 % \verb|\tagpdfsetup{table/tagging=false}| or changed with
125 % \verb|\tagpdfsetup{table/tagging=presentation}| or \verb|\tagpdfsetup{table/tagging=div}|%
126 % \footnote{The value \texttt{presentation} refers to the ARIA role \enquote{presentation}.}
127 % The first option disables the table tagging code and the content of the tabular
128 % is then treated more or less like running text. This works ok for simple tables using
129 % only hmode-cells (l/c/r) with normal text content, but fails if the table uses vmode-cells
130 % (p/m/b). In such cases the second option works better: it keeps the tagging code active,
131 % but adds an ARIA-role as attribute to indicate that this is a presentation table.
132 % When deriving to html this gives the best result
133 % as it keeps the layout.
134 % The last option changes the tag names and creates simply a number of DIV structures.
135 % Both options also
136 % (re)set the \texttt{table/header-rows} and \texttt{table/header-columns} keys to empty.
137 %
138 % To reset to the normal tagging in the current group (e.g. inside a presentation
139 % table) one can use \verb|\tagpdfsetup{table/tagging=true}| (and if needed reenable the headers).
140 %
141 %
142 % \subsection{Header rows and columns}
143 % There is some basic support\footnote{This is not meant to be the
144 % final interface, though.} for headers. With
145 % \begin{quote}
146 % \verb|\tagpdfsetup{table/header-rows={|\meta{list of row numbers}\verb|}}|\\
147 % \verb|\tagpdfsetup{table/header-columns={|\meta{list of column numbers}\verb|}}|
148 % \end{quote}
149 % you can
150 % declare which (absolute) row and column numbers should be tagged as header rows and header columns.
151 % It applies to all tables until it is changed to a different list of row or
152 % column numbers or undone by setting
153 % the keys to \meta{empty}.
154 % A row or column number can be
155 % negative, then the counting starts from the end of the table.
156 % In a \env{longtable} the code will currently use the \cs{endhead} or
157 % \cs{endfirsthead} rows as header if one of these commands has been
158 % used and in that case the code
159 % ignores a \texttt{table/header-rows} setting.
160 %
161 % \subsection{Spanning of cells}
162 %
163 % \cs{multicolumn} is supported out of the box and will create a structure with a
164 % suitable \texttt{ColSpan} attribute\footnote{The code uses actually an attribute \emph{class}.
165 % The validator PAC doesn't handle this correctly currently and complains about a missing attribute.}
166 %
167 % For cells spanning rows some preliminary support exists\footnote{The interface is bound to change!}:
168 % If you add
169 % \begin{quote}
170 % \verb|\tagpdfsetup{table/multirow={|\meta{number of rows}\verb|}|
171 % \end{quote}
172 % to a cell the code will add the suitable \texttt{RowSpan} attribute and suppress the tagging of affected
173 % cells in the following rows. This will also work if the current cell is a \cs{multicolumn}, then
174 % the cell will span both rows and columns. It is the duty of the author to
175 % ensure that all cells below and covered by a \texttt{RowSpan} are empty!
176 % The code neither checks that nor does
177 % it tries to suppress content.
178 %
179 % Feedback and problems with the code can be reported at
180 % \url{https://github.com/latex3/tagging-project} either in form of
181 % explicit issues or as a \enquote{discussion topic}, whatever works best.
182 %
183 %
184 % \section{Limitations}
185 %
186 % \begin{itemize}
187 % \item The code loads the \pkg{array} package and so does not work without it (that is
188 % not really a limitation, but can affect existing tables).
189 %
190 % \item It supports only a restricted number of tables types. Currently
191 % \env{tabular}, \env{tabular*}, \env{tabularx}, and \env{longtable}.
192 %
193 % \item The \env{array} environment is assumed to be part of math and tagging as a table is disabled for
194 % it.
195 %
196 % \item Row spans can only be added manually (the \pkg{multirow} package is untested).
197 %
198 % \item The \pkg{colortbl} package breaks tagging if there are nested tables.
199 %
200 % \item The \pkg{tabularray} package uses a completely different
201 % method to create tables and is not supported by this code.
202 %
203 % \item Tables in text mode made with \pkg{nicematrix} package are often correctly tagged,
204 % but should be carefully checked. In math mode they are currently not compatible with
205 % the MathML structure elements.
206 %
207 % \item Most other packages related to tables in \LaTeX{} are not fully tested;
208 % that includes packages that change rules like \pkg{booktabs}, \pkg{hhline},
209 % \pkg{arydshln}, \pkg{hvdashln}. Some problems have been resolved, either
210 % in the packages or through a firstaid.
211 %
212 % \item \env{longtable} currently only works with lualatex.
213 % With other engines it breaks as its output
214 % routine clashes with the code which closes open MC-chunks at pagebreaks and
215 % if this is resolved there will probably be problems with the head and foot boxes
216 % (but this can't be tested currently).
217 %
218 % \item Not every table should be tagged as a Table structure, often they are
219 % only used as layout help, e.g. to align authors in title pages. In such uses
220 % the tagging of the table must be deactivated with \verb|\tagpdfsetup{table/tagging=false}|
221 % or changed with \verb|\tagpdfsetup{table/tagging=presentation}| or
222 % \verb|\tagpdfsetup{table/tagging=div}|.
223 %
224 % \item Only simple header rows and columns are currently supported. Complex headers with
225 % subheaders will be handled later as that needs some syntax changes. Tables
226 % with more than one header row or column are probably not pdf/UA conformant as the headers array in
227 % the cells is missing.
228 %
229 % \item A \pkg{longtable} \cs{caption} is currently simply formatted as a multicolumn and
230 % not tagged as a \texttt{Caption} structure.
231 %
232 % \item The \pkg{caption} package will quite probably break the \pkg{longtable} caption.
233 %
234 % \item The setup for \pkg{longtable} requires lots of patches to internal \pkg{longtable}
235 % commands and so can easily break if other packages try to patch \pkg{longtable} too.
236 %
237 % \item The \env{longtable} environment supports footnotes in p-type columns, but it hasn't been
238 % tested yet if this works also with the tagging code.
239 %
240 % \item Vertical boxes (\cs{parbox}, \texttt{minipage}, \ldots) inside cells can be problematic.
241 %
242 % \item The code is quite noisy and fills the log with lots of
243 % messages.\footnote{Helpful for us at this stage.}
244 % \end{itemize}
245 %
246 %
247 %
248 % \section{Introduction}
249 %
250 %
251 % \section{Technical details and problems}
252 %
253 % The implementation has to take care of various details.
254 %
255 % \subsection{TODOs}
256 %
257 % \begin{itemize}
258 % \item
259 % Test \texttt{array-006-longtable.lvt} and
260 % \texttt{array-007-longtable.lvt} have errors with pdftex (para
261 % tagging)
262 %
263 % \item
264 % Instead of before/after hooks we should add sockets directly
265 % into the code.
266 %
267 % \item Debugging code and messages must be improved.
268 %
269 % \item Cells need an \texttt{Headers} array.
270 %
271 % \item Row spans should be supported (but perhaps need syntax support)
272 %
273 % \item Longtable captions should be properly supported.
274 %
275 %
276 % \item More packages must be tested.
277 % \end{itemize}
278 %
279 %
280 % \section{Implementation}
281 % \begin{macrocode}
282 %<@@=tbl>
283 %<*package>
284 % \end{macrocode}
285 % \begin{macrocode}
286 \ProvidesExplPackage {latex-lab-testphase-table} {\ltlabtbldate} {\ltlabtblversion}
287 {Code related to the tagging of tables}
288 % \end{macrocode}
289 % This builds on \pkg{array} so we load it by default:
290 % \begin{macrocode}
291 \RequirePackage{array}
292 % \end{macrocode}
293 %
294 %
295 % \subsection{Variables}
296 % \begin{macro}
297 % {
298 % \l_@@_celltag_tl
299 % \l_@@_pcelltag_tl
300 % ,\l_@@_rowtag_tl
301 % ,\l_@@_table_tl
302 % ,\l_@@_cellattribute_tl
303 % ,\l_@@_rowattribute_tl
304 % ,\l_@@_tmpa_clist
305 % ,\l_@@_tmpa_tl
306 % ,\l_@@_tmpa_str
307 % }
308 % This is for the celltag, e.g. TD or TH:
309 % \begin{macrocode}
310 \tl_new:N \l_@@_celltag_tl
311 \tl_set:Nn \l_@@_celltag_tl {\UseStructureName{table/cell}}
312 \tl_new:N \l_@@_pcelltag_tl
313 \tl_set:Nn \l_@@_pcelltag_tl {\UseStructureName{table/cell}}
314 % \end{macrocode}
315 % For the rowtag, probably always TR:
316 % \begin{macrocode}
317 \tl_new:N \l_@@_rowtag_tl
318 \tl_set:Nn \l_@@_rowtag_tl {\UseStructureName{table/row}}
319 % \end{macrocode}
320 % For the tabletag, probably always Table:
321 % \begin{macrocode}
322 \tl_new:N \l_@@_tabletag_tl
323 \tl_set:Nn \l_@@_tabletag_tl {\UseStructureName{table}}
324 % \end{macrocode}
325 % And here cell and row attributes:
326 % \begin{macrocode}
327 \tl_new:N \l_@@_cellattribute_tl
328 \tl_set:Nn \l_@@_cellattribute_tl {}
329 \tl_new:N \l_@@_rowattribute_tl
330 \tl_set:Nn \l_@@_rowattribute_tl {}
331 % \end{macrocode}
332 % Variable to store cell info like which cell must be skipped when tagging multirows.
333 % \begin{macrocode}
334 \prop_new:N\g_@@_untagged_cells_prop
335 \prop_new:N\l_@@_saved_untagged_cells_prop
336 % \end{macrocode}
337 % Temp variables
338 % \begin{macrocode}
339 \clist_new:N \l_@@_tmpa_clist
340 \tl_new:N \l_@@_tmpa_tl
341 \str_new:N \l_@@_tmpa_str
342 % \end{macrocode}
343 % \end{macro}
344 %
345 % \subsection{Tagging support sockets}
346 %
347 %
348 % These are the standard plugs for tagging of cells and rows.
349 %
350 % The \texttt{tbl/init/celldata} and
351 % \texttt{tbl/restore/celldata} are defined in lttagging.
352 % \begin{plugdecl}{default}
353 % This socket is used inside \cs{tbl_init_cell_data_for_table} for the
354 % case that this a nested table in a cell.
355 % \begin{macrocode}
356 \NewTaggingSocketPlug{tbl/init/celldata}{default}
357 {
358 \prop_set_eq:NN\l_@@_saved_untagged_cells_prop \g_@@_untagged_cells_prop
359 \prop_gclear:N \g_@@_untagged_cells_prop
360 }
361 \AssignTaggingSocketPlug{tbl/init/celldata}{default}
362 % \end{macrocode}
363 % \end{plugdecl}
364
365 % \begin{plugdecl}{default}
366 % This socket is used inside \cs{tbl_restore_outer_cell_data:} and restores
367 % values when a nested table is ended.
368 % \begin{macrocode}
369 \NewTaggingSocketPlug{tbl/restore/celldata}{default}
370 {
371 \prop_gset_eq:NN\g_@@_untagged_cells_prop \l_@@_saved_untagged_cells_prop
372 }
373 \AssignTaggingSocketPlug{tbl/restore/celldata}{default}
374 % \end{macrocode}
375 % \end{plugdecl}
376 %
377 % \begin{plugdecl}{TD}
378 % \begin{macrocode}
379 \NewTaggingSocketPlug{tbl/cell/begin}{TD}
380 {
381 % \end{macrocode}
382 % Next line was previously outside of the plug, so if we want to execute it
383 % always even if the noop plug is in force this needs a different solution.
384 % \begin{macrocode}
385 \@@_show_curr_cell_data:
386 % \end{macrocode}
387 % We test if the cell should be tagged at all.
388 % \begin{macrocode}
389 \@@_if_tag_cell:nnT {\g_@@_row_int } { \g_@@_col_int }
390 {
391 % \end{macrocode}
392 % this sets row headers
393 % \begin{macrocode}
394 \clist_if_in:NVT \l_@@_header_columns_clist\g_@@_col_int
395 {
396 \tl_set:Ne \l_@@_celltag_tl {\UseStructureName{table/headercell}}
397 \tl_set:Ne \l_@@_cellattribute_tl {\l_@@_cellattribute_tl,TH-row}
398 }
399 % \end{macrocode}
400 % Here we handle negative value for row headers:
401 % \begin{macrocode}
402 \tl_set:Ne \l_@@_tmpa_tl
403 {\int_eval:n { \g_@@_col_int - 1 - \g_@@_table_cols_tl }}
404 \clist_if_in:NoT \l_@@_header_columns_clist { \l_@@_tmpa_tl }
405 {
406 \tl_set:Ne \l_@@_celltag_tl {\UseStructureName{table/headercell}}
407 \tl_set:Ne \l_@@_cellattribute_tl {\l_@@_cellattribute_tl,TH-row}
408 }
409 \tag_struct_begin:n
410 {
411 tag =\l_@@_celltag_tl,
412 attribute-class ={\l_@@_cellattribute_tl}
413 }
414 \seq_gput_right:Ne \g_@@_struct_cur_seq { \tag_get:n {struct_num} }
415 % \end{macrocode}
416 % we store the cells of multicolumns as negative number. This allow to skip them
417 % or to use them as needed.
418 % \begin{macrocode}
419 \int_step_inline:nn { \g_@@_span_tl - 1 }
420 {
421 \seq_gput_right:Ne \g_@@_struct_cur_seq { -\tag_get:n {struct_num} }
422 }
423 \tag_mc_begin:n{}
424 }
425 }
426 % \end{macrocode}
427 % \end{plugdecl}
428 %
429 % \begin{plugdecl}{TD}
430 % \begin{macrocode}
431 \NewTaggingSocketPlug{tbl/cell/end}{TD}
432 {
433 \@@_if_tag_cell:nnT {\g__tbl_row_int } { \g__tbl_col_int }
434 {
435 \tag_mc_end:
436 \tag_struct_end:
437 }
438 }
439 % \end{macrocode}
440 % \end{plugdecl}
441 %
442 % In p-columns we need a slightly different plug which reactivates the
443 % paragraph tagging.
444 % \changes{0.85s}{2025-08-01}{fix typo celltag to pcelltag, tagging issue 965}
445 % \begin{plugdecl}{TDpbox}
446 % \begin{macrocode}
447 \NewTaggingSocketPlug{tbl/pcell/begin}{TDpbox}
448 {
449 \@@_show_curr_cell_data:
450 \@@_if_tag_cell:nnT {\g__tbl_row_int } { \g__tbl_col_int }
451 {
452 \clist_if_in:NVT \l_@@_header_columns_clist\g_@@_col_int
453 {
454 \tl_set:Ne \l_@@_pcelltag_tl {\UseStructureName{table/headercell}}
455 \tl_set:Ne \l_@@_cellattribute_tl {\l_@@_cellattribute_tl,TH-row}
456 }
457 \tag_struct_begin:n
458 {
459 tag =\l_@@_pcelltag_tl,
460 attribute-class ={\l_@@_cellattribute_tl}
461 }
462 \seq_gput_right:Ne \g_@@_struct_cur_seq { \tag_get:n {struct_num} }
463 \int_step_inline:nn { \g_@@_span_tl - 1 }
464 {
465 \seq_gput_right:Ne \g_@@_struct_cur_seq { -\tag_get:n {struct_num} }
466 }
467 \tagpdfparaOn
468 \tl_set:Nn \l__tag_para_main_tag_tl {\UseStructureName{table/para/semantic}}
469 }
470 }
471 % \end{macrocode}
472 % \end{plugdecl}
473 %
474 % \begin{plugdecl}{TDpbox}
475 % \begin{macrocode}
476 \NewTaggingSocketPlug{tbl/pcell/end}{TDpbox}
477 {
478 \@@_if_tag_cell:nnT {\g_@@_row_int } { \g_@@_col_int }
479 {
480 \tag_struct_end:
481 \legacy_if:nT {@endpe}{\par}
482 \mode_if_vertical:T{ \tagpdfparaOff }
483 }
484 }
485 % \end{macrocode}
486 % \end{plugdecl}
487 %
488 % \begin{plugdecl}{TR}
489 % \begin{macrocode}
490 \NewTaggingSocketPlug{tbl/row/begin}{TR}
491 {
492 \seq_gclear:N \g_@@_struct_cur_seq
493 \tag_struct_begin:n
494 {
495 tag =\l_@@_rowtag_tl,
496 attribute-class=\l_@@_rowattribute_tl
497 }
498 \seq_gput_right:Ne \g_@@_struct_rows_seq { \tag_get:n {struct_num} }
499 }
500 % \end{macrocode}
501 % \end{plugdecl}
502 %
503 % \begin{plugdecl}{TR}
504 % \changes{0.85t}{2025-07-02}{Removed unneeded \cs{tag_if_active:T}}
505 % \begin{macrocode}
506 \NewTaggingSocketPlug{tbl/row/end}{TR}
507 {
508 \@@_add_missing_cells:
509 \seq_gput_right:Ne \g_@@_struct_cells_seq
510 {
511 \seq_use:Nn \g_@@_struct_cur_seq {,}
512 }
513 \int_compare:nNnTF { \g_@@_row_int } =
514 { \seq_count:N \g_@@_struct_cells_seq }
515 {
516 \@@_trace:n
517 {==>~
518 structure~stored~for~row~\int_use:N\g_@@_row_int :~
519 \seq_use:Nn \g_@@_struct_cur_seq {,}
520 }
521 }
522 { \ERRORtbl/row } % should not happen ...
523 \tag_struct_end:
524 }
525 % \end{macrocode}
526 % \end{plugdecl}
527 %
528 % And the plugs for the table as whole. The code can be different for
529 % normal tables which can also be used inline and nested and
530 % \enquote{vmode} tables like longtable.
531 %
532 %
533 % \begin{plugdecl}{Table}
534 % Inside a TD or TR Part is not allowed as child. For structures that restore
535 % paragraph settings we therefore need a special plug that adjust the settings.
536 % Currently we set the para main tag to Div. This leads to double Div-structures
537 % but flattening the paragraph doesn't work, it errors if there is a list inside.
538 % \begin{macrocode}
539 \NewTaggingSocketPlug{para/restore}{Table}
540 {
541 \tl_set:Nn \l__tag_para_main_tag_tl {\UseStructureName{table/para/semantic}}
542 \tl_set_eq:NN \l__tag_para_tag_tl\l__tag_para_tag_default_tl
543 \bool_set_true:N \l__tag_para_bool
544 \bool_set_false:N \l__tag_para_flattened_bool
545 \int_zero:N \l__tag_block_flattened_level_int
546 }
547 % \end{macrocode}
548 % \end{plugdecl}
549 %
550 % \begin{plugdecl}{Table}
551 % Inside a table we currently only disable paratagging. We assume
552 % that these sockets are called in a group, so there is no
553 % need to reenable paratagging.
554 % \begin{macrocode}
555 \NewTaggingSocketPlug{tbl/init}{Table}
556 {
557 \bool_set_false:N \l__tag_para_bool
558 \AssignTaggingSocketPlug{para/restore}{Table}
559 % \end{macrocode}
560 % We also initialize the structure data variables a this point.
561 % \begin{macrocode}
562 \@@_init_struct_data:
563 }
564 % \end{macrocode}
565 % \end{plugdecl}
566 %
567 %
568 % \begin{plugdecl}{Table}
569 % This plug will fine tune the structure.
570 % \begin{macrocode}
571 \NewTaggingSocketPlug{tbl/finalize}{Table}
572 {
573 \@@_set_header_rows:
574 % \end{macrocode}
575 % Similarly, we restore the outer values of the structure data when
576 % we leave the table.
577 % \begin{macrocode}
578 \@@_restore_struct_data:
579 }
580 % \end{macrocode}
581 % \end{plugdecl}
582 %
583 %
584 %
585 %
586 % \begin{plugdecl}{Table}
587 % This plug will initialize the structure in longtable.
588 % \begin{macrocode}
589 \NewTaggingSocketPlug{tbl/longtable/init}{Table}
590 {
591 \seq_gclear:N\g_@@_struct_rows_seq
592 \seq_gclear:N\g_@@_struct_cells_seq
593 \seq_gclear:N\g_@@_struct_cur_seq
594 \seq_gclear:N\g_@@_LT@firsthead_rows_seq
595 \seq_gclear:N\g_@@_LT@head_rows_seq
596 \seq_gclear:N\g_@@_LT@lastfoot_rows_seq
597 \seq_gclear:N\g_@@_LT@foot_rows_seq
598 }
599 % \end{macrocode}
600 % \end{plugdecl}
601 %
602 %
603
604
605 % \begin{plugdecl}{Table}
606 % This plug will fine tune the structure in longtable.
607 % \begin{macrocode}
608 \NewTaggingSocketPlug{tbl/longtable/finalize}{Table}
609 {
610 % \end{macrocode}
611 % If neither \cs{endhead} nor \cs{endfirsthead} has been used
612 % we use the standard header command:
613 % \begin{macrocode}
614 \bool_lazy_and:nnTF
615 { \seq_if_empty_p:N \g_@@_LT@head_rows_seq }
616 { \seq_if_empty_p:N \g_@@_LT@firsthead_rows_seq }
617 { \@@_set_header_rows: }
618 % \end{macrocode}
619 % Otherwise, if firsthead has not been used we use head. For this
620 % we simple retrieve the row numbers and then call the header
621 % command.
622 % \begin{macrocode}
623 {
624 \seq_if_empty:NTF \g_@@_LT@firsthead_rows_seq
625 {
626 \clist_set:Ne \l_@@_header_rows_clist
627 {\seq_use:Nn \g_@@_LT@head_rows_seq {,}}
628 \@@_set_header_rows:
629 }
630 % \end{macrocode}
631 % In the other case we use firsthead.
632 % \begin{macrocode}
633 {
634 \clist_set:Ne \l_@@_header_rows_clist
635 { \seq_use:Nn \g_@@_LT@firsthead_rows_seq {,} }
636 \@@_set_header_rows:
637 % \end{macrocode}
638 % Additionally we have to remove the head to avoid duplication. The
639 % one option here is to remove the rows from the kid sequence of
640 % the table (which will lead to orphaned structure elements), the
641 % other to make them artifact. For now we use the first option for
642 % pdf 1.7 and the second for pdf 2.0.
643 % \begin{macrocode}
644 \pdf_version_compare:NnTF < {2.0}
645 {
646 \seq_map_inline:Nn \g_@@_LT@head_rows_seq
647 {
648 \seq_gset_item:cnn
649 {g__tag_struct_kids_ \g_@@_struct_table_tl _seq}
650 { ##1 }
651 {}
652 % \end{macrocode}
653 % Not sure if needed, but if needed we can remove also the P tag.
654 % This is currently disabled as it produce warnings. TODO: This
655 % needs also a tagpdf command which takes care of debug code.
656 % \begin{macrocode}
657 \tl_set:Ne \l_@@_tmpa_tl
658 { \seq_item:Nn\g_@@_struct_rows_seq {##1} }
659 \prop_if_exist:cT
660 { g__tag_struct_ \l_@@_tmpa_tl _prop }
661 {
662 %\prop_gremove:cn {g__tag_struct_ \l_@@_tmpa_tl _prop} {P}
663 }
664 }
665 }
666 {
667 \seq_map_inline:Nn \g_@@_LT@head_rows_seq
668 {
669 \tl_set:Ne \l_@@_tmpa_tl
670 { \seq_item:Nn\g_@@_struct_rows_seq {##1} }
671 \prop_if_exist:cT
672 { g__tag_struct_ \l_@@_tmpa_tl _prop }
673 {
674 \__tag_struct_prop_gput:onn { \l_@@_tmpa_tl } {S}{/Artifact}
675 }
676 }
677 }
678 }
679 }
680 % \end{macrocode}
681 % The foot is handled similar, the difference is
682 % that we have to move it to the end one of them
683 % is not empty, but do nothing if they aren't there.
684 % \begin{macrocode}
685 \bool_lazy_and:nnF
686 { \seq_if_empty_p:N \g_@@_LT@foot_rows_seq }
687 { \seq_if_empty_p:N \g_@@_LT@lastfoot_rows_seq }
688 {
689 % \end{macrocode}
690 % If lastfoot is empty move foot to the end.
691 % \begin{macrocode}
692 \seq_if_empty:NTF \g_@@_LT@lastfoot_rows_seq
693 {
694 \seq_map_inline:Nn \g_@@_LT@foot_rows_seq
695 {
696 \tl_set:Ne \l_@@_tmpa_tl
697 {
698 \seq_item:cn
699 {g__tag_struct_kids_ \g_@@_struct_table_tl _seq}
700 {##1}
701 }
702 \seq_gset_item:cnn
703 {g__tag_struct_kids_ \g_@@_struct_table_tl _seq}
704 { ##1 }
705 {}
706 \seq_gput_right:cV
707 {g__tag_struct_kids_ \g_@@_struct_table_tl _seq}
708 \l_@@_tmpa_tl
709 }
710 }
711 % \end{macrocode}
712 % If lastfoot is not empty we move that.
713 % \begin{macrocode}
714 {
715 \seq_map_inline:Nn \g_@@_LT@lastfoot_rows_seq
716 {
717 \tl_set:Ne \l_@@_tmpa_tl
718 {
719 \seq_item:cn
720 {g__tag_struct_kids_ \g_@@_struct_table_tl _seq}
721 {##1}
722 }
723 \seq_gset_item:cnn
724 {g__tag_struct_kids_ \g_@@_struct_table_tl _seq}
725 { ##1 }
726 {}
727 \seq_gput_right:cV
728 {g__tag_struct_kids_ \g_@@_struct_table_tl _seq}
729 \l_@@_tmpa_tl
730 }
731 % \end{macrocode}
732 % and we hide foot
733 % \begin{macrocode}
734 \pdf_version_compare:NnTF < {2.0}
735 {
736 \seq_map_inline:Nn \g_@@_LT@foot_rows_seq
737 {
738 \seq_gset_item:cnn
739 {g__tag_struct_kids_ \g_@@_struct_table_tl _seq}
740 { ##1 }
741 {}
742 % \end{macrocode}
743 % Not sure if needed, but if needed we can remove also the P tag.
744 % This is currently disabled as it produce warnings.
745 % TODO: This needs also
746 % a tagpdf command which takes care of debug code.
747 % \begin{macrocode}
748 \tl_set:Ne \l_@@_tmpa_tl
749 { \seq_item:Nn\g_@@_struct_rows_seq {##1} }
750 \prop_if_exist:cT
751 { g__tag_struct_ \l_@@_tmpa_tl _prop }
752 {
753 %\prop_gremove:cn {g__tag_struct_ \l_@@_tmpa_tl _prop} {P}
754 }
755 }
756 }
757 {
758 \seq_map_inline:Nn \g_@@_LT@foot_rows_seq
759 {
760 \tl_set:Ne \l_@@_tmpa_tl
761 { \seq_item:Nn\g_@@_struct_rows_seq {##1} }
762 \prop_if_exist:cT
763 { g__tag_struct_ \l_@@_tmpa_tl _prop }
764 {
765 \__tag_struct_prop_gput:onn {\l_@@_tmpa_tl} {S}{/Artifact}
766 }
767 }
768 }
769 }
770 }
771 }
772 % \end{macrocode}
773 % \end{plugdecl}
774 %
775 %
776 %
777 % \begin{plugdecl}{Table}
778 %
779 % We must avoid that the reuse of the header foot box leads to duplicated
780 % content, thus reset attribute of the box:
781 % \begin{macrocode}
782 \NewTaggingSocketPlug{tbl/longtable/head}{Table}
783 {
784 \tagmcbegin{artifact}
785 \tag_mc_reset_box:N\LT@head
786 \tagmcend
787 }
788 % \end{macrocode}
789 % \end{plugdecl}
790 %
791 % \begin{plugdecl}{Table}
792 % \begin{macrocode}
793 \NewTaggingSocketPlug{tbl/longtable/foot}{Table}
794 {
795 \tagmcbegin{artifact}
796 \tag_mc_reset_box:N \LT@foot
797 \tagmcend
798 }
799 % \end{macrocode}
800 % \end{plugdecl}
801 %
802 % \begin{plugdecl}{Table}
803 % \begin{macrocode}
804 \NewTaggingSocketPlug{tbl/hmode/begin}{Table}
805 {
806 \tag_mc_end_push:
807 % \end{macrocode}
808 % Close the P-chunk. This assumes that para-tagging is active.
809 % For nested tables that is not necessarily true, so we test for it.
810 % \begin{macrocode}
811 \bool_lazy_and:nnT
812 { \bool_if_exist_p:N \l__tag_para_bool } { \l__tag_para_bool }
813 { \tag_struct_end:n { text } }
814 \tag_struct_begin:n {tag=\l_@@_tabletag_tl}
815 \tl_gset:Ne \g_@@_struct_table_tl { \tag_get:n {struct_num} }
816 }
817 % \end{macrocode}
818 % \end{plugdecl}
819 %
820 % \begin{plugdecl}{LayoutTable}
821 % \changes{v0.85p}{2025/01/05}{new plugs for layout tables (tagging/778)}
822 % This plug is meant for presentation tables, it sets the ARIA role.
823 % \begin{macrocode}
824 \NewTaggingSocketPlug{tbl/hmode/begin}{LayoutTable}
825 {
826 \tag_mc_end_push:
827 % \end{macrocode}
828 % Close the P-chunk. This assumes that para-tagging is active.
829 % For nested tables that is not necessarily true, so we test for it.
830 % \begin{macrocode}
831 \bool_lazy_and:nnT
832 { \bool_if_exist_p:N \l__tag_para_bool } { \l__tag_para_bool }
833 { \tag_struct_end:n { text } }
834 \tag_struct_begin:n {tag=\l_@@_tabletag_tl,attribute-class=ARIA-role-presentation}
835 \tl_gset:Ne \g_@@_struct_table_tl { \tag_get:n {struct_num} }
836 }
837 % \end{macrocode}
838 % \end{plugdecl}
839 %
840 % \begin{plugdecl}{Table}
841 % \begin{macrocode}
842 \NewTaggingSocketPlug{tbl/hmode/end}{Table}
843 {
844 \tag_struct_end:
845 % \end{macrocode}
846 % reopen the P-chunk. This assumes that para-tagging is active.
847 % For nested tables that is not necessarily true, so we test for it.
848 % \begin{macrocode}
849 \bool_lazy_and:nnT
850 { \bool_if_exist_p:N \l__tag_para_bool } { \l__tag_para_bool }
851 { \tag_struct_begin:n { tag=\UseStructureName{para/textblock} } }
852 \tag_mc_begin_pop:n{}
853 }
854 % \end{macrocode}
855 % \end{plugdecl}
856 %
857 % \begin{plugdecl}{Table}
858 % \begin{macrocode}
859 \NewTaggingSocketPlug{tbl/vmode/begin}{Table}
860 {
861 \tag_struct_begin:n {tag=\l_@@_tabletag_tl}
862 \tl_gset:Ne \g_@@_struct_table_tl { \tag_get:n {struct_num} }
863 }
864 % \end{macrocode}
865 % \end{plugdecl}
866 %
867 % \begin{plugdecl}{Table}
868 % \begin{macrocode}
869 \NewTaggingSocketPlug{tbl/vmode/begin}{LayoutTable}
870 {
871 \tag_struct_begin:n {tag=\l_@@_tabletag_tl,attribute-class=ARIA-role-presentation}
872 \tl_gset:Ne \g_@@_struct_table_tl { \tag_get:n {struct_num} }
873 }
874 % \end{macrocode}
875 % \end{plugdecl}
876 %
877 %
878 % \begin{plugdecl}{Table}
879 % \begin{macrocode}
880 \NewTaggingSocketPlug{tbl/vmode/end}{Table}
881 {
882 \tag_struct_end:
883 \par
884 }
885 % \end{macrocode}
886 % \end{plugdecl}
887 %
888 %
889 % \begin{plugdecl}{code}
890 % This socket takes a number, checks if is larger than one,
891 % checks if the colspan attribute already exists (we can't predefine an
892 % arbitrary number), and updates \cs{l_@@_cellattribute_tl}.
893 % \begin{macrocode}
894 \NewTaggingSocketPlug{tbl/colspan}{code}
895 {
896 \int_compare:nNnT {#1}>{1}
897 {
898 \prop_get:NeNF \g__tag_attr_entries_prop
899 {colspan-\int_eval:n{#1}}
900 \l_@@_tmpa_tl
901 {
902 \__tag_attr_new_entry:ee
903 {colspan-\int_eval:n{#1}}
904 {/O /Table /ColSpan~\int_eval:n{#1}}
905 }
906 \tl_set:Ne \l_@@_cellattribute_tl
907 {\l_@@_cellattribute_tl,colspan-\int_eval:n{#1}}
908 }
909 }
910 % \end{macrocode}
911 % \end{plugdecl}
912 %
913 %
914 %
915 %
916 % \begin{plugdecl}{code}
917 % The sockets are declared in lttagging.dtx.
918 % \begin{macrocode}
919 \NewTaggingSocketPlug{tbl/leaders/begin}{code}
920 { \tag_mc_begin:n{artifact} }
921 \NewTaggingSocketPlug{tbl/leaders/end}{code}
922 { \tag_mc_end: }
923 % \end{macrocode}
924 % \end{plugdecl}
925 %
926 %
927 %
928 %\subsection{Environments}
929 %
930 % Currently we support only \env{tabular}, \env{tabular*}, \env{tabularx} and \env{longtable}
931 % (and possibly environments build directly on top of them).
932 %
933 % The \env{array} environment is math. So we disable table tagging for now.
934 % We use the command hook to catch also cases where \cs{array} is used directly
935 % in other environments like matrix environments.
936 % Perhaps table tagging should be disable for math generally, but then
937 % we have to handle text insertions.
938 % \begin{macrocode}
939 \AddToHook{cmd/array/before}{\__tag_tbl_disable:}
940 % \end{macrocode}
941 %
942 %
943 % \subsection{Interfaces to tagging}
944 %
945 % \subsubsection{Tagging helper commands}
946
947 % \subsubsection{Disabling/enabling}
948 %
949 % For now we have only the option true/false but this will probably be extended
950 % to allow different setups like first row header etc.
951
952 % \begin{macro}{\__tag_tbl_disable:}
953 %
954 % \begin{macrocode}
955 \cs_new_protected:Npn \__tag_tbl_disable:
956 {
957 \AssignTaggingSocketPlug{tbl/cell/begin}{noop}
958 \AssignTaggingSocketPlug{tbl/cell/end}{noop}
959 \AssignTaggingSocketPlug{tbl/pcell/begin}{noop}
960 \AssignTaggingSocketPlug{tbl/pcell/end}{noop}
961 \AssignTaggingSocketPlug{tbl/row/begin}{noop}
962 \AssignTaggingSocketPlug{tbl/row/end}{noop}
963 \AssignTaggingSocketPlug{tbl/init}{noop}
964 \AssignTaggingSocketPlug{tbl/finalize}{noop}
965 \AssignTaggingSocketPlug{tbl/longtable/init}{noop}
966 \AssignTaggingSocketPlug{tbl/longtable/head}{noop}
967 \AssignTaggingSocketPlug{tbl/longtable/foot}{noop}
968 \AssignTaggingSocketPlug{tbl/longtable/finalize}{noop}
969 \AssignTaggingSocketPlug{tbl/hmode/begin}{noop}
970 \AssignTaggingSocketPlug{tbl/hmode/end}{noop}
971 \AssignTaggingSocketPlug{tbl/vmode/begin}{noop}
972 \AssignTaggingSocketPlug{tbl/vmode/end}{noop}
973 \AssignTaggingSocketPlug{tbl/colspan}{noop}
974 \AssignTaggingSocketPlug{tbl/leaders/begin}{noop}
975 \AssignTaggingSocketPlug{tbl/leaders/end}{noop}
976 }
977 % \end{macrocode}
978 % \end{macro}
979
980
981 % \begin{macro}{\__tag_tbl_enable:}
982 %
983 % \begin{macrocode}
984 \cs_new_protected:Npn \__tag_tbl_enable:
985 {
986 \AssignTaggingSocketPlug{tbl/cell/begin}{TD}
987 \AssignTaggingSocketPlug{tbl/cell/end}{TD}
988 \AssignTaggingSocketPlug{tbl/pcell/begin}{TDpbox}
989 \AssignTaggingSocketPlug{tbl/pcell/end}{TDpbox}
990 \AssignTaggingSocketPlug{tbl/row/begin}{TR}
991 \AssignTaggingSocketPlug{tbl/row/end}{TR}
992 \AssignTaggingSocketPlug{tbl/init}{Table}
993 \AssignTaggingSocketPlug{tbl/finalize}{Table}
994 \AssignTaggingSocketPlug{tbl/longtable/head}{Table}
995 \AssignTaggingSocketPlug{tbl/longtable/foot}{Table}
996 \AssignTaggingSocketPlug{tbl/longtable/init}{Table}
997 \AssignTaggingSocketPlug{tbl/longtable/finalize}{Table}
998 \AssignTaggingSocketPlug{tbl/hmode/begin}{Table}
999 \AssignTaggingSocketPlug{tbl/hmode/end}{Table}
1000 \AssignTaggingSocketPlug{tbl/vmode/begin}{Table}
1001 \AssignTaggingSocketPlug{tbl/vmode/end}{Table}
1002 \AssignTaggingSocketPlug{tbl/colspan}{code}
1003 \AssignTaggingSocketPlug{tbl/leaders/begin}{code}
1004 \AssignTaggingSocketPlug{tbl/leaders/end}{code}
1005 }
1006 % \end{macrocode}
1007 % \end{macro}
1008 %
1009 % \begin{macro}{\@@_init_tagnames_default:,\@@_init_tagnames_div:}
1010 % These commands are used to switch the tagnames.
1011 % \begin{macrocode}
1012 \cs_new_protected:Npn\@@_init_tagnames_default:
1013 {
1014 \tl_set:Nn\l_@@_rowtag_tl {\UseStructureName{table/row}}
1015 \tl_set:Nn\l_@@_pcelltag_tl {\UseStructureName{table/cell}}
1016 \tl_set:Nn\l_@@_celltag_tl {\UseStructureName{table/cell}}
1017 \tl_set:Nn\l_@@_tabletag_tl {\UseStructureName{table}}
1018 }
1019
1020 \cs_new_protected:Npn\@@_init_tagnames_div:
1021 {
1022 \tl_set:Nn\l_@@_rowtag_tl {\UseStructureName{layouttable/row}}
1023 \tl_set:Nn\l_@@_pcelltag_tl {\UseStructureName{layouttable/pcell}}
1024 \tl_set:Nn\l_@@_celltag_tl {\UseStructureName{layouttable/cell}}
1025 \tl_set:Nn\l_@@_tabletag_tl {\UseStructureName{layouttable}}
1026 }
1027 % \end{macrocode}
1028 % \end{macro}
1029
1030 % \begin{macrocode}
1031 % See tagpdfsetup-keys.md in tagpdf/doc for the naming scheme.
1032 \keys_define:nn { __tag / setup }
1033 {
1034 table/tagging .choices:nn = { true, on }
1035 {
1036 \__tag_tbl_enable:
1037 \@@_init_tagnames_default:
1038 },
1039 table/tagging .choices:nn = { false, off }
1040 { \__tag_tbl_disable: },
1041 table/tagging .choice:,
1042 table/tagging / presentation .code:n =
1043 {
1044 \__tag_tbl_enable:
1045 \@@_init_tagnames_default:
1046 \AssignTaggingSocketPlug{tbl/hmode/begin}{LayoutTable}
1047 \AssignTaggingSocketPlug{tbl/vmode/begin}{LayoutTable}
1048 \clist_clear:N \l_@@_header_rows_clist
1049 \clist_clear:N \l_@@_header_columns_clist
1050 },
1051 table/tagging / div .code:n =
1052 {
1053 \__tag_tbl_enable:
1054 \@@_init_tagnames_div:
1055 \AssignTaggingSocketPlug{tbl/hmode/begin}{LayoutTable}
1056 \AssignTaggingSocketPlug{tbl/vmode/begin}{LayoutTable}
1057 \clist_clear:N \l_@@_header_rows_clist
1058 \clist_clear:N \l_@@_header_columns_clist
1059 },
1060 table/tagging .default:n = true,
1061 table/tagging .initial:n = true
1062 }
1063 % \end{macrocode}
1064 % This are the old key names kept for now for
1065 % compatibility. They will got at some time.
1066 % \begin{macrocode}
1067 \keys_define:nn { __tag / setup }
1068 {
1069 table-tagging .meta:n = {table/tagging={#1}}
1070 }
1071 % \end{macrocode}
1072 %
1073 %
1074 % \subsubsection{Header support}
1075 %
1076 % Accessible table must have header cells declaring the meaning of the
1077 % data in a row or column. To allow a data cell to find it header cell(s)
1078 % a number of things must be done:
1079 % \begin{itemize}
1080 % \item every cell meant as a header should use the tag \texttt{TH}.
1081 %
1082 % \item header cells should have a \texttt{Scope} attribute with the
1083 % value \texttt{Column}, \texttt{Row} or \texttt{Both}. This is not
1084 % needed in the first row or column of a table.
1085 %
1086 % \item For more complex cases both \texttt{TD} and \texttt{TH} cell
1087 % can contain a \texttt{Headers} attribute, that is an array of
1088 % \texttt{ID}s of \texttt{TH} cell.
1089 % \end{itemize}
1090 %
1091 % For now we support only header rows.
1092 %
1093 % The attributes \texttt{TH-col}, \texttt{TH-row} and \texttt{TH-both} (for the
1094 % scope of a header column) and \texttt{ARIA-role-presentation} are declared in
1095 % latex-lab-namespace.
1096 % \changes{v0.85p}{2025/01/05}{add ARIA-role for presentation (tagging/778)}
1097 % \changes{v0.85t}{2025-07-02}{Remove \cs{tag_if_active:}}
1098 %
1099 %
1100 % \begin{variable}{\l_@@_header_rows_clist,\l_@@_header_columns_clist}
1101 % This holds the numbers of the header rows and columns. Negative numbers are
1102 % possible and count from the last column backwards.
1103 % \begin{macrocode}
1104 \clist_new:N \l_@@_header_rows_clist
1105 \clist_new:N \l_@@_header_columns_clist
1106 % \end{macrocode}
1107 % \end{variable}
1108 %
1109 % \begin{macro}{\@@_set_header_rows:}
1110 % \begin{macrocode}
1111 \cs_new_protected:Npn \@@_set_header_rows:
1112 {
1113 \clist_map_inline:Nn \l_@@_header_rows_clist
1114 {
1115 \clist_set:Ne\l_@@_tmpa_clist
1116 {
1117 \seq_item:Nn \g_@@_struct_cells_seq {##1}
1118 }
1119 \clist_map_inline:Nn \l_@@_tmpa_clist
1120 {
1121 % \end{macrocode}
1122 % We can have negative numbers in the list from the multicolumn.
1123 % \begin{macrocode}
1124 \prop_if_exist:cT { g__tag_struct_####1_prop }
1125 {
1126 \__tag_struct_prop_gput:nne{ ####1 }{S}{/\UseStructureName{table/headercell}}
1127 % \end{macrocode}
1128 % This sets the scope class. If the header has already a row attribute
1129 % we replace by TH-both.
1130 % \begin{macrocode}
1131 \prop_get:cnNTF
1132 { g__tag_struct_####1_prop }
1133 { C }
1134 \l_@@_tmpa_tl
1135 {
1136 \str_set:Ne \l_@@_tmpa_str {\l_@@_tmpa_tl}
1137 \str_remove_once:Nn \l_@@_tmpa_str {[}
1138 \str_remove_once:Nn \l_@@_tmpa_str {]}
1139 \str_if_in:NnTF\l_@@_tmpa_str{/TH-row}
1140 {
1141 \str_replace_once:Nnn \l_@@_tmpa_str {/TH-row}{/TH-both}
1142 \__tag_struct_prop_gput:nne{ ####1 }{C}{[\l_@@_tmpa_str]}
1143 }
1144 {
1145 \__tag_struct_prop_gput:nne{ ####1 }{C}{[/TH-col~\l_@@_tmpa_str]}
1146 }
1147 }
1148 {\__tag_struct_prop_gput:nnn{ ####1 }{C}{/TH-col}}
1149 }
1150 }
1151 }
1152 }
1153 % \end{macrocode}
1154 % \end{macro}
1155 %
1156 % And some key support:
1157 % (See tagpdfsetup-keys.md for the naming scheme.)
1158 % \begin{macrocode}
1159 \keys_define:nn { __tag / setup }
1160 {
1161 table/header-rows .clist_set:N = \l_@@_header_rows_clist,
1162 table/header-columns .clist_set:N = \l_@@_header_columns_clist,
1163 % \end{macrocode}
1164 % obsolete older name:
1165 % \begin{macrocode}
1166 table-header-rows .meta:n = {table/header-rows={#1}}
1167 }
1168 % \end{macrocode}
1169 %
1170 % \subsection{Multirow support}
1171 %
1172 % \begin{macro}{\@@_multirow:n}
1173 % This command makes the current cell into a multirow cell:
1174 % it creates, if needed, an RowSpan-attribute, adds it to the attributes
1175 % of the cell structure, and marks all following cells spanned by the multirow
1176 % as cells that should not be tagged. The argument is the number of spanned row
1177 % (including the current row).
1178 % \begin{macrocode}
1179 \cs_if_exist:NT \__tag_struct_prop_gput:nnn
1180 {
1181 \cs_generate_variant:Nn \__tag_struct_prop_gput:nnn {one}
1182 }
1183 \cs_new_protected:Npn \@@_multirow:n #1
1184 {
1185 % \end{macrocode}
1186 % Create an attribute if needed:
1187 % \begin{macrocode}
1188 \prop_get:NeNF \g__tag_attr_entries_prop
1189 {rowspan-\int_eval:n{#1}}
1190 \l_@@_tmpa_tl
1191 {
1192 \__tag_attr_new_entry:ee
1193 {rowspan-\int_eval:n{#1}}
1194 {/O /Table /RowSpan~\int_eval:n{#1}}
1195 }
1196 % \end{macrocode}
1197 % ensure that the attribute is marked as used:
1198 % \begin{macrocode}
1199 \seq_gput_left:Ne\g__tag_attr_class_used_seq
1200 {\pdf_name_from_unicode_e:n{rowspan-\int_eval:n{#1}}}
1201 % \end{macrocode}
1202 % Get the structure number of the current cell
1203 % \begin{macrocode}
1204 \seq_get_right:NN\g_@@_struct_cur_seq \l_@@_tmpb_tl
1205 % \end{macrocode}
1206 % If we are in a multicolumn the number can be negative and
1207 % this must be changed
1208 % \begin{macrocode}
1209 \tl_set:Ne \l_@@_tmpb_tl { \int_abs:n{\l_@@_tmpb_tl} }
1210 % \end{macrocode}
1211 % no we must update an existing attribute.
1212 % TODO: simplify this ... (see also colspan handling).
1213 % \begin{macrocode}
1214 \prop_get:cnNTF
1215 { g__tag_struct_\l_@@_tmpb_tl _prop }
1216 { C }
1217 \l_@@_tmpa_tl
1218 {
1219 \tl_remove_once:Nn \l_@@_tmpa_tl {[}
1220 \tl_remove_once:Nn \l_@@_tmpa_tl {]}
1221 \__tag_struct_prop_gput:one{ \l_@@_tmpb_tl }
1222 {C}
1223 {[/rowspan-\int_eval:n{#1}~\l_@@_tmpa_tl]}
1224 }
1225 {
1226 \__tag_struct_prop_gput:one{ \l_@@_tmpb_tl }
1227 {C}
1228 {[/rowspan-\int_eval:n{#1}]}
1229 }
1230 % \end{macrocode}
1231 % Now mark the spanned cells that should be ignored.
1232 % \begin{macrocode}
1233 \@@_gset_untagged_row_cells:nn {#1-1}{\g_@@_span_tl}
1234 }
1235 % \end{macrocode}
1236 % \end{macro}
1237 %
1238 % \begin{macrocode}
1239 \keys_define:nn{ __tag / setup }
1240 { table/multirow .code:n = {\@@_multirow:n {#1} }
1241 ,table/multirow .default:n = 1
1242 }
1243 % \end{macrocode}
1244 %
1245 % \begin{macro}{\@@_gset_untagged_row_cells:nn}
1246 % This command stores the row and column numbers of the cells in the following row(s)
1247 % that should not be tagged as they are a part of a rowspan.
1248 % \begin{macrocode}
1249 \cs_new_protected:Npn \@@_gset_untagged_row_cells:nn #1 #2
1250 % #1 number of rows, #2 number of columns
1251 {
1252 \int_step_inline:nn {#1}
1253 {
1254 \int_step_inline:nn {#2}
1255 {
1256 \prop_gput:Nee \g_@@_untagged_cells_prop
1257 {
1258 \int_eval:n {\g_@@_row_int + ##1},
1259 \int_eval:n{\g_@@_col_int + ####1 -1 }
1260 }{}
1261 }
1262 }
1263 }
1264 % \end{macrocode}
1265 % \end{macro}
1266 %
1267 % \begin{macro}{\@@_if_tag_cell:nn}
1268 % We must be able to detect if a cell should be tagged. For this
1269 % we define a conditional --- if more options are needed it can be extended.
1270 % \begin{macrocode}
1271 \prg_new_protected_conditional:Npnn\@@_if_tag_cell:nn #1 #2 %#1 row, #2 col
1272 { T,TF }
1273 {
1274 \prop_get:NeNTF \g_@@_untagged_cells_prop
1275 {\int_eval:n{#1},\int_eval:n{#2}}\l__tbl_tmpa_tl
1276 { \prg_return_false:}
1277 { \prg_return_true: }
1278 }
1279 % \end{macrocode}
1280 % \end{macro}
1281 %
1282 % \subsection{Misc stuff}
1283 %
1284 % \begin{macro}{\@@_show_curr_cell_data:}
1285 % Show the row/column index and span count for current table cell
1286 % for debugging.
1287 % \begin{macrocode}
1288 \cs_new_protected:Npn \@@_show_curr_cell_data: {
1289 \@@_trace:n { ==>~ current~cell~data:~
1290 \int_use:N \g_@@_row_int ,
1291 \int_use:N \g_@@_col_int ,
1292 \g_@@_span_tl
1293 }
1294 }
1295 % \end{macrocode}
1296 % \end{macro}
1297 %
1298 %
1299 %
1300 % \begin{macro}{\@@_add_missing_cells:}
1301 % The storing and use of the number of missing cells must happen at
1302 % different places as the testing happens at the end of the last
1303 % cell of a row, but still inside that cell, so we use two
1304 % commands. The one adding is used in the row/end socket.
1305 % \begin{macrocode}
1306 \cs_new:Npn \@@_add_missing_cells:
1307 {
1308 % \end{macrocode}
1309 % The TD-socket messages are issued after the message about the
1310 % end-row socket, but the structure is ok, so better issue a
1311 % message for now to avoid confusion:
1312 % \begin{macrocode}
1313 \int_compare:nNnT \g_@@_missing_cells_int > 0
1314 {
1315 \@@_trace:n {==>~
1316 ~Inserting~\int_use:N \g_@@_missing_cells_int \space
1317 additional~cell(s)~into~previous~row:}
1318 \int_step_inline:nn { \g_@@_missing_cells_int }
1319 {
1320 \int_gincr:N\g_@@_col_int
1321 \UseTaggingSocket{tbl/cell/begin}
1322 \UseTaggingSocket{tbl/cell/end}
1323 }
1324 }
1325 }
1326 % \end{macrocode}
1327 % \end{macro}
1328 %
1329 %
1330 %
1331 %
1332 %
1333 %
1334 % \begin{macro}
1335 % {
1336 % \g_@@_struct_table_tl, \l_@@_saved_struct_table_tl,
1337 % \g_@@_struct_rows_seq,\l_@@_saved_struct_rows_seq,
1338 % \g_@@_struct_cells_seq,\l_@@_saved_struct_cells_seq,
1339 % \g_@@_struct_cur_seq,\l_@@_saved_struct_cur_seq
1340 % }
1341 % We need to store the structure numbers for the fine tuning in the
1342 % finalize socket. For now we use a rather simple system: A
1343 % sequence that hold the numbers for the row structures, and one
1344 % that holds comma lists for the cells.
1345 %
1346 % \cs{g_@@_struct_table_tl} will hold the structure number of the
1347 % table, \cs{g_@@_struct_rows_seq} will hold at index i the
1348 % structure number of row i, \cs{g_@@_struct_cells_seq} will hold
1349 % at index i a comma list of the cell structure numbers of row i.
1350 % \cs{g_@@_struct_cur_seq} is used as a temporary store for the
1351 % cell structures of the current row. We need also local version
1352 % to store and restore the values.
1353 %
1354 % \begin{macrocode}
1355 \tl_new:N \g_@@_struct_table_tl
1356 \tl_new:N \l_@@_saved_struct_table_tl
1357 \seq_new:N \g_@@_struct_rows_seq
1358 \seq_new:N \l_@@_saved_struct_rows_seq
1359 \seq_new:N \g_@@_struct_cells_seq
1360 \seq_new:N \l_@@_saved_struct_cells_seq
1361 \seq_new:N \g_@@_struct_cur_seq
1362 \seq_new:N \l_@@_saved_struct_cur_seq
1363 % \end{macrocode}
1364 % \end{macro}
1365
1366
1367
1368 % \begin{macro}{\@@_init_struct_data:}
1369 % Save the global structure data variables locally so the we can
1370 % restore them when the table ends (important in case of nested
1371 % tables).
1372 %
1373 % This is also the right point to initialize
1374 % them. \cs{g_@@_struct_table_tl} is set elsewhere.
1375 % \begin{macrocode}
1376 \cs_new_protected:Npn \@@_init_struct_data: {
1377 \tl_set_eq:NN \l_@@_saved_struct_table_tl \g_@@_struct_table_tl
1378 \seq_set_eq:NN \l_@@_saved_struct_rows_seq \g_@@_struct_rows_seq
1379 \seq_set_eq:NN \l_@@_saved_struct_cells_seq \g_@@_struct_cells_seq
1380 \seq_set_eq:NN \l_@@_saved_struct_cur_seq \g_@@_struct_cur_seq
1381 %
1382 \seq_gclear:N\g_@@_struct_rows_seq
1383 \seq_gclear:N\g_@@_struct_cells_seq
1384 \seq_gclear:N\g_@@_struct_cur_seq
1385 }
1386 % \end{macrocode}
1387 % \end{macro}
1388
1389
1390
1391
1392 % \begin{macro}{\@@_restore_struct_data:}
1393 %
1394 % \begin{macrocode}
1395 \cs_new_protected:Npn \@@_restore_struct_data: {
1396 \tl_gset_eq:NN \g_@@_struct_table_tl \l_@@_saved_struct_table_tl
1397 \seq_gset_eq:NN \g_@@_struct_rows_seq \l_@@_saved_struct_rows_seq
1398 \seq_gset_eq:NN \g_@@_struct_cells_seq\l_@@_saved_struct_cells_seq
1399 \seq_gset_eq:NN \g_@@_struct_cur_seq \l_@@_saved_struct_cur_seq
1400 }
1401 % \end{macrocode}
1402 % \end{macro}
1403
1404
1405 %
1406 %
1407 % \subsection{longtable}
1408 %
1409 %
1410 %
1411 %
1412 %
1413 % \begin{macro}{\@@_patch_\LT@makecaption}
1414 % This patch is quite similar to the one for LaTeX's \cs{@makecaption}
1415 % we also have to change the parbox sockets.
1416 % \begin{macrocode}
1417 \def\@@_patch_LT@makecaption#1#2#3{%
1418 \LT@mcol\LT@cols c{%
1419 \AssignTaggingSocketPlug{parbox/before}{noop}
1420 \AssignTaggingSocketPlug{parbox/after}{noop}
1421 \hbox to\z@{\hss\parbox[t]\LTcapwidth{%
1422 \reset@font
1423 \tag_suspend:n{caption}
1424 \sbox\@tempboxa{#1{#2:~}#3}%
1425 \tag_resume:n{caption}
1426 \ifdim\wd\@tempboxa>\hsize
1427 #1{#2:~}#3%
1428 \else
1429 \hbox to\hsize{\hfil#1{#2:~}#3\hfil}%
1430 \fi
1431 \endgraf\vskip\baselineskip}%
1432 \hss}}}
1433 % \end{macrocode}
1434 % \end{macro}
1435 %
1436 %
1437 %
1438 % Overwrite the longtable definition. That will probably break somewhere as
1439 % they are various package which patch too.
1440 % \begin{macrocode}
1441 \AddToHook{package/longtable/after}
1442 {
1443 \cs_set_eq:NN \LT@makecaption\@@_patch_LT@makecaption
1444 }
1445 % \end{macrocode}
1446
1447
1448 % \begin{macrocode}
1449 %</package>
1450 % \end{macrocode}