Currently, most KOMA-Script packages and KOMA-Script classes are not prepared for tagging or the use of \DocumentMetadata. This is largely because, over the years, KOMA-Script has had to replace many of the internal commands that LaTeX provides for class and package authors with custom implementations in order to offer such a wide range of features. When using \DocumentMetadata—now a prerequisite for tagging—many LaTeX internals are replaced by latex-lab. Much of this is not yet set in stone. In the past, this half-finished state has repeatedly led to situations where development efforts that had already begun were largely a waste of time. At the same time, simply loading latex-lab overrides many KOMA-Script definitions, so some things certainly no longer work as documented in the manual.
Nevertheless, Marei Peischl is already working on tagging support in KOMA-Script. In addition, KOMA-Script offers various hooks through which tagging can be achieved for individual documents and individual elements.
The example shown here for tagging headings in KOMA-Script classes is based on code provided by Ulrike Fischer during discussions with the KOMA-Script developers. It is based on the latest versions of the LaTeX kernel and latex-lab. Therefore, the use of lualatex-dev for compilation is recommended. Of course, there is no guarantee that this will continue to work in the same way with future versions of KOMA-Script, the LaTeX kernel, or latex-lab. On the contrary, once KOMA-Script itself begins to provide tagging for headings, it is more likely that this will no longer work.
\DocumentMetadata{uncompress,tagging=on}
\documentclass{scrbook}
% See https://sourceforge.net/p/koma-script/wiki-de/HowTo_Tagging for more information an up-to-date code.
\ExplSyntaxOn\makeatletter
\int_new:N\l__scr_sec_level_int
\NewTaggingSocket{scr/heading/init}{1}
\NewTaggingSocketPlug{scr/heading/init}{default}
{
\int_set:Nn\l__scr_sec_level_int{\use:c{toclevel@#1}}
\UseTaggingSocket{sec/end}{\int_use:N\l__scr_sec_level_int}
\UseTaggingSocket{sec/begin}
{{\int_use:N\l__scr_sec_level_int}{tag=\UseStructureName{sec/\int_use:N\l__scr_sec_level_int}}}
\if@startsection@runin
\UseTaggingSocket{sec/title/init}{\int_use:N\l__scr_sec_level_int}
\fi
}
\AssignTaggingSocketPlug{scr/heading/init}{default}
\NewTaggingSocket{scr/heading/begin}{1}
\NewTaggingSocketPlug{scr/heading/begin}{default}
{
\pdf_purify:nN{\@currenttocentry}\l__scr_sec_tmpa_tl
\int_set:Nn\l__scr_sec_level_int{\use:c{toclevel@#1}}
\if@startsection@runin
\else
\tagstructbegin{tag=\UseStructureName{sec/\int_use:N\l__scr_sec_level_int/title},title-o=\l__scr_sec_tmpa_tl}%
\tagmcbegin{}\tagpdfparaOff
\fi
}
\AssignTaggingSocketPlug{scr/heading/begin}{default}
\NewTaggingSocket{scr/heading/end}{1}
\NewTaggingSocketPlug{scr/heading/end}{default}
{
\if@startsection@runin
\UseTaggingSocket{sec/title/split}
\else
\tagmcend\tagstructend
\fi
}
\AssignTaggingSocketPlug{scr/heading/end}{default}
\AddtoDoHook{heading/preinit}{\@startsection@runinfalse\@gobble}% because styles chapter and part do not use \scr@startsection
\AddtoDoHook{heading/postinit} {\UseTaggingSocket{scr/heading/init}}
\AddtoDoHook{heading/begingroup}{\UseTaggingSocket{scr/heading/begin}}
\AddtoDoHook{heading/endgroup} {\UseTaggingSocket{scr/heading/end}}
%\AddtoDoHook{heading/postinit} {\__scr_sec_show_runin:n}
\cs_new:Nn \__scr_sec_show_runin:n
{
\if@startsection@runin \tl_show:n{#1:~runin}\else \tl_show:n{#1:~display}\fi
}
\ExplSyntaxOff
\begin{document}
\tableofcontents
\part{Part}
\chapter{blub}
\section{section}
some text
\subsection{subsection}
some text\footnote{hallo}
\section{section}
some text
\paragraph{bla} hallo world
\paragraph{blub}\begin{itemize}\item a \end{itemize}
blbl
\part*{Part}
\chapter*{blub}
\section*{section}
some text
\subsection*{subsection}
some text\footnote{hallo}
\section*{section}
some text
\paragraph*{bla} hallo world
\paragraph*{blub}\begin{itemize}\item a \end{itemize}
blbl
\end{document}
The example shown has a few limitations, such as:
\part starts with an empty structure that doesn't actually belong there.sect structures, but this only becomes a problem if someone suppresses the sect structures.\DocumentMetadata and activated tagging.scraddr (There is nothing to tag here.)scrbase (There is nothing to tag here.)scrdate (NOTE: No longer included in KOMA-Script as of version 3.49.3.)scrfontsize (There is nothing to tag here.)scrlfile (Does not generate any output, so there is nothing to tag.)scrlogo (There is nothing to tag here; at most, an ALT text could be generated.)scrtime (NOTE: No longer included in KOMA-Script as of version 3.49.3.)typearea (There is nothing to tag here.)
Issues: #59
Issues: #89
Wiki (English): HowTo_CompatibilityIssues