Skip to content

Commit

Permalink
use ARIA role for presentation tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
u-fischer committed Jan 6, 2025
1 parent 10bccb5 commit 57787b7
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 220 deletions.
73 changes: 43 additions & 30 deletions required/latex-lab/latex-lab-table.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@
% as a layout to ensure that the content is properly aligned
% or because it is a not yet (fully) supported table structure,
% the tagging can be disabled with
% \verb|\tagpdfsetup{table/tagging=false}| or with \verb|\tagpdfsetup{table/tagging=presentation}|%
% \verb|\tagpdfsetup{table/tagging=false}| or changed with
% \verb|\tagpdfsetup{table/tagging=presentation}|%
% \footnote{The key has been renamed. The old name `table-tagging` still works but is
% deprecated. The value \texttt{presentation} refers to the ARIA role \enquote{presentation}.}
% The first option disables the table tagging code and the content of the tabular
% is then treated more or less like running text. This works ok for simple tables using
% only hmode-cells (l/c/r) with normal text content, but fails if the table uses vmode-cells
% (p/m/b). In such cases the second option works better: it keeps the tagging code active
% but changes the tag names to \texttt{Div} and the grouping structure \texttt{NonStruct}. It also
% (re)sets the \texttt{table/header-rows} key to empty.
% The key should currently only be used in a group as there is no key (yet) to reset to the default
% tag names.
% and adds an ARIA-role as attribute. It also
% (re)sets the \texttt{table/header-rows} and \texttt{table/header-columns} keys to empty.
% To reset to the normal tagging use \verb|\tagpdfsetup{table/tagging=true}.|
%
% \subsection{Header rows and columns}
% There is some basic support\footnote{This is not meant to be the
Expand Down Expand Up @@ -228,7 +228,7 @@
% \item Not every table should be tagged as a Table structure, often they are
% only used as layout help, e.g. to align authors in a title pages. In such uses
% the tagging of the table must be deactivated with \verb|\tagpdfsetup{table/tagging=false}|
% or \verb|\tagpdfsetup{table/tagging=presentation}|.
% or changed with \verb|\tagpdfsetup{table/tagging=presentation}|.
%
% \item Only simple header rows and columns are currently supported. Complex headers with
% subheaders will be handled later as that needs some syntax changes. Tables
Expand Down Expand Up @@ -827,9 +827,6 @@
% \end{macrocode}
% \end{plugdecl}
%
%
%
%
% \begin{plugdecl}{Table}
% \begin{macrocode}
\NewSocketPlug{tagsupport/tbl/hmode/begin}{Table}
Expand All @@ -847,6 +844,26 @@
}
% \end{macrocode}
% \end{plugdecl}
%
% \begin{plugdecl}{LayoutTable}
% \changes{v0.85p}{2025/01/05}{new plugs for layout tables (tagging/778)}
% This plug is meant for presentation tables, it sets the ARIA role.
% \begin{macrocode}
\NewSocketPlug{tagsupport/tbl/hmode/begin}{LayoutTable}
{
\tag_mc_end_push:
% \end{macrocode}
% Close the P-chunk. This assumes that para-tagging is active.
% For nested tables that is not necessarily true, so we test for it.
% \begin{macrocode}
\bool_lazy_and:nnT
{ \bool_if_exist_p:N \l__tag_para_bool } { \l__tag_para_bool }
{ \tag_struct_end:n { text } }
\tag_struct_begin:n {tag=\l_@@_tabletag_tl,attribute-class=ARIA-role-presentation}
\tl_gset:Ne \g_@@_struct_table_tl { \tag_get:n {struct_num} }
}
% \end{macrocode}
% \end{plugdecl}
%
% \begin{plugdecl}{Table}
% \begin{macrocode}
Expand Down Expand Up @@ -874,6 +891,17 @@
}
% \end{macrocode}
% \end{plugdecl}
%
% \begin{plugdecl}{Table}
% \begin{macrocode}
\NewSocketPlug{tagsupport/tbl/vmode/begin}{LayoutTable}
{
\tag_struct_begin:n {tag=\l_@@_tabletag_tl,attribute-class=ARIA-role-presentation}
\tl_gset:Ne \g_@@_struct_table_tl { \tag_get:n {struct_num} }
}
% \end{macrocode}
% \end{plugdecl}
%
%
% \begin{plugdecl}{Table}
% \begin{macrocode}
Expand Down Expand Up @@ -1015,41 +1043,23 @@
}
% \end{macrocode}
% \end{macro}
% \changes{v0.85p}{2025/01/05}{reset tag names when switching out of presentation mode (tagging/778)}
% \begin{macrocode}
\cs_new_protected:Npn\@@_init_tagnames_default:
{
\tl_set:Nn\l_@@_rowtag_tl {TR}
\tl_set:Nn\l_@@_pcelltag_tl {TD}
\tl_set:Nn\l_@@_celltag_tl {TD}
\tl_set:Nn\l_@@_tabletag_tl {Table}
}

\cs_new_protected:Npn\@@_init_tagnames_presentation:
{
\tl_set:Nn\l_@@_rowtag_tl {NonStruct}
\tl_set:Nn\l_@@_pcelltag_tl {NonStruct}
\tl_set:Nn\l_@@_celltag_tl {text}
\tl_set:Nn\l_@@_tabletag_tl {Div}
}
% \end{macrocode}

%
% \begin{macrocode}
% See tagpdfsetup-keys.md in tagpdf/doc for the naming scheme.
\keys_define:nn { __tag / setup }
{
table/tagging .choices:nn = { true, on }
{
\__tag_tbl_enable:
\@@_init_tagnames_default:
},
table/tagging .choices:nn = { false, off }
{ \__tag_tbl_disable: },
table/tagging .choice:,
table/tagging / presentation .code:n =
{
\__tag_tbl_enable:
\@@_init_tagnames_presentation:
\AssignSocketPlug{tagsupport/tbl/hmode/begin}{LayoutTable}
\AssignSocketPlug{tagsupport/tbl/vmode/begin}{LayoutTable}
\clist_clear:N \l_@@_header_rows_clist
\clist_clear:N \l_@@_header_columns_clist
},
Expand Down Expand Up @@ -1089,6 +1099,7 @@
% At first we define attributes for the three standard cases:
% We delay to begin document
% as we can't know if tagpdf is already loaded.
% \changes{v0.85p}{2025/01/05}{add ARIA-role for presentation (tagging/778)}
% \begin{macrocode}
\AddToHook{begindocument}
{
Expand All @@ -1102,6 +1113,8 @@
{TH-row}{/O /Table /Scope /Row},
role/new-attribute =
{TH-both}{/O /Table /Scope /Both},
role/new-attribute =
{ARIA-role-presentation}{/O /ARIA-1.1/role (presentation)}
}
% \end{macrocode}
%
Expand Down
Loading

0 comments on commit 57787b7

Please sign in to comment.