% !Mode:: "TeX:DE:UTF-8:Main" %\PassOptionsToPackage{check-declarations,enable-debug}{expl3} %\RequirePackage{pdfmanagement-testphase} \DocumentMetadata{pdfversion=2.0,lang=en-UK,testphase=phase-II} \makeatletter \def\UlrikeFischer@package@version{0.93} \def\UlrikeFischer@package@date{2022-01-13} \makeatother \documentclass[DIV=12,parskip=half-,bibliography=totoc]{scrartcl} \usepackage[english]{babel} \usepackage{unicode-math} \setmainfont{Heuristica} \usepackage{microtype} \makeatletter % see https://github.com/schlcht/microtype/issues/8 \patchcmd{\MT@get@prot}{\noindent}{\RawNoindent}{}{\fail} \makeatother \usepackage{scrlayer-scrpage} \usepackage[autostyle]{csquotes} \usepackage[style=numeric,hyperref=false]{biblatex} \addbibresource{tagpdf.bib} \usepackage[noparboxrestore]{marginnote} \makeatletter \renewcommand*{\mn@parboxrestore}{\tagpdfparaOff}% \reversemarginpar \usepackage{tcolorbox} %think later ... \usepackage{tikz} \usetikzlibrary{positioning} \usetikzlibrary{fit,tikzmark} \usetikzlibrary{arrows.meta} \tikzset{arg/.style = {font=\footnotesize\ttfamily, anchor=base,draw, rounded corners,node distance=2mm and 2mm}} \tikzset{operator/.style = {font=\footnotesize\ttfamily, anchor=base,draw, rounded corners,node distance=4mm and 4mm}} \usepackage{enumitem,xpatch} \usepackage{listings} \lstset{basicstyle=\ttfamily, columns=fullflexible,language=[LaTeX]TeX, escapechar=*, commentstyle=\color{green!50!black}\bfseries} \tagpdfsetup{ tabsorder=structure, %log=v %show-spaces } \usepackage{hyperxmp} \usepackage[pdfdisplaydoctitle=true,hyperfootnotes=false, ]{hyperref} \hypersetup{ pdftitle={The tagpdf package, v\csname UlrikeFischer@package@version\endcsname}, pdfauthor=Ulrike Fischer, pdfaconformance=a, pdfuapart=1, colorlinks} \tcbuselibrary{documentation} \definecolor{Definition}{rgb}{0,0.2,0.6} \newcommand\PrintKeyName[1]{\textsf{#1}} \newcommand\pkg[1]{\texttt{#1}} \newcommand\DescribeKey[1]{\texttt{#1}} %\newcommand\cs[1]{\texttt{\textbackslash #1}} %\usepackage{ydoc-desc} %hm hyperref ist ein Problem ... \usepackage{tagpdfdocu-patches} \cfoot*{\pagemark} % \newcommand\PDF{PDF} \title{The \pkg{tagpdf} package, v\csname UlrikeFischer@package@version\endcsname} \date{\csname UlrikeFischer@package@date\endcsname} \author{Ulrike Fischer\thanks{fischer@troubleshooting-tex.de}} \tagpdfsetup{paratagging,paratagging-show} \usepackage{shortvrb} \MakeShortVerb| \begin{document} \tagstructbegin{tag=Document} \tagstructbegin{tag=Title} \tagmcbegin{tag=Title} \begin{center}\let\thanks\par \makeatletter \usekomafont{title}{\huge \@title \par} \vskip .5em \usekomafont{author}{\@author \par} \vskip 1em% \usekomafont{date}{\@date \par}% \end{center}% \tagmcend \tagstructend \tagstructbegin{tag=Div} \begin{tcolorbox}[colframe=red,before upper=\tagpdfparaOn] This package is not meant for normal document production. It is mainly a tool to \emph{research} tagging. You need a very current \LaTeX{} format. You need a very current L3 programming layer. You need the new \LaTeX{} PDF management bundle. This package is incomplete, experimental and quite probably contains bugs. At some time it will disappear when the code has been integrated into the \LaTeX{} format. This package can change in an incompatible way. You need some knowledge about \TeX, \PDF{} and perhaps even lua to use it. \medskip Issues, comments, suggestions should be added as issues to the github tracker: \medskip \centering \url{https://github.com/u-fischer/tagpdf} \end{tcolorbox} \tagstructend \tableofcontents \section{Preface to version 0.93} The main change in the package itself in this version is the support for structure destinations. This is a new type of destinations in \PDF~2.0. For pdftex and luatex this requires new binaries. They will be included in texlive 2022, miktex already has the new pdftex, the new luatex will probably follow soon. Beside this mostly some clean up and bug fixes has been done. A more important step will be done in \LaTeX{} itself in the next dev-release: The command \cs{DocumentMetadata} will be added to the format and will take over the role of \cs{DeclareDocumentMetadata} from \pkg{pdfmanagement-testphase} and additionally will also load the pdf management code. This will simplify the documents as it will no longer be needed to load a package. \section{Preface to version 0.92} In this version support for page breaks in pdftex has been added. As described in section~\ref{sec:splitpara}, tagging markers must be added by \emph{page}. That means that a paragraph that goes over two pages must get an end marker at the end on the first page and a new begin marker on the next page. With lualatex that is rather easy to ensure, with pdflatex it requires quite sophisticated code. The method is described in Frank Mittelbach's talk at TUG~2021 \enquote{Taming the beast — Advances in paragraph tagging with pdfTeX and XeTeX} \url{https://youtu.be/SZHIeevyo3U?t=19551}. The new code requires a new version of the pdfmanagement-testphase package. Please check also section~\ref{sec:splitpara} for possible pitfalls. Also new in this version is the handling of header and footer: they will now be tagged as artifacts automatically. See section~\ref{sec:header-footer}. \section{Introduction} Since many year the creation of accessible \PDF{}-files with \LaTeX\ which conform to the PDF/UA standard has been on the agenda of \TeX-meetings. Many people agree that this is important and Ross Moore has done quite some work on it. There is also a TUG-mailing list and a webpage \parencite{tugaccess} dedicated to this theme. But in my opinion missing are means to \emph{experiment} with tagging and accessibility. Means to try out, how difficult it is to tag some structures, means to try out, how much tagging is really needed (standards and validators don't need to be right \ldots), means to test what else is needed so that a \PDF{} works e.g. with a screen reader. Without such experiments it is imho quite difficult to get a feeling about what has to be done, which kernel changes are needed, how packages should be adapted. This package tries to close this gap by offering \emph{core} commands to tag a \PDF{}% \tagpdfparaOff\footnote{In case you don't know what this means: there will be some explanations later on.}\tagpdfparaOn. My hope is that the knowledge gained by the use of this package will at the end allow to decide if and how code to do tagging should be part of the \LaTeX\ kernel. The package does not patch commands from other packages. It is also not an aim of the package to develop such patches. While at the end changes to various commands in many classes and packages will be needed to get tagged \PDF{} files -- and the examples accompanying the package try (or will try) to show various strategies -- these changes should in my opinion be done by the class, package and document writers themselves using a sensible API provided by the kernel and not by some external package that adds patches everywhere and would need constant maintenance -- one only need to look at packages like tex4ht or bidi or hyperref to see how difficult and sometimes fragile this is. So this package deliberately concentrates on the basics -- and this already quite a lot, there are much more details involved as I expected when I started. I'm sure that it has bugs. Bugs reports, suggestions and comments can be added to the issue tracker on github. \url{https://github.com/u-fischer/tagpdf}. Please also check the github site for new examples and improvements. \subsection{Tagging and accessibility} While the package is named \texttt{tagpdf} the goal is actually \emph{accessible} \PDF{}-files. Tagging is \emph{one} requirement for accessibility but there are others. I will mention some later on in this documentation, and -- if sensible -- I will also try to add code, keys or tips for them. So the name of the package is a bit wrong. As excuse I can only say that it is shorter and easier to pronounce. \subsection{Engines and modes} The package works currently with pdflatex and lualatex. First steps have been done to also enable support for xelatex and the latex-dvips-route; but this isn't yet much tested. The package has two modes: the \emph{generic mode} which should work in theory with every engine and the \emph{lua mode} which works only with lualatex. I implemented the generic mode first. Mostly because my tex skills are much better than my lua skills and I wanted to get the tex side right before starting to fight with attributes and node traversing. While the generic mode is not bad and I spent quite some time to get it working I nevertheless think that the lua mode is the future and the only one that will be usable for larger documents. \PDF{} is a page orientated format and so the ability of luatex to manipulate pages and nodes after the \TeX-processing is really useful here. Also with luatex characters are normally already given as unicode. The package uses quite a lot labels (in generic mode more than with luamode). At the begin it relied on the \pkg{zref} package, but switched now to a new experimental implementation for labels. The drawback of the new method is that they don't give yet good rerun messages if they have changed. I advise to use the \pkg{rerunfilecheck} package as a intermediate work-around. \subsection{References and target PDF version} My main reference for the first versions of this package was the free reference for \PDF{} 1.7. \parencite{pdfreference} and so the package also targetted this version. In 2018 \PDF{} 2.0. has been released, and since 2020 all engines can set the version to 2.0. So the package will now target \PDF{} 2.0. This doesn't mean that 2.0 will be required, but that the code and the options will be extended to support \PDF{} 2.0. One example is the support for associated files, another the support for name spaces in version 0.82. The package doesn't try to suppress all 2.0 features if an older \PDF{} version is produced. It normally doesn't harm if a \PDF{} contains keys unknown in its version and it makes the code faster and easier to maintain if there aren't too many tests and code pathes; so for example associated files will always be added. But tests could be added in case this leads to incompabilities. It should be noted that some tools don't like \PDF{}~2.0. PAC3 for example simply crashes, and pdftk will create a \PDF{}~1.0 from it. This makes testing \PDF{}~2.0 files a bit of a challenge. \subsection{Validation} \PDF{}'s created with the commands of this package must be validated: \begin{itemize} \item One must check that the \PDF{} is \emph{syntactically} correct. It is rather easy to create broken \PDF{}: e.g. if a chunk is opened on one page but closed on the next page or if the document isn't compiled often enough. \item One must check how good the requirements of the PDF/UA standard are followed \emph{formally}. \item One must check how good the accessibility is \emph{practically}. \end{itemize} Syntax validation and formal standard validation can be done with preflight of the (non-free) adobe acrobat. It can also be done also with the free \PDF{} Accessibility Checker (PAC~3) \parencite{pac3}. There is also the validator veraPDF \parencite{verapdf}. A rather new and quite useful tool is \enquote{Next Generation PDF} \parencite{ngpdf}, a browser application which converts a tagged PDF to html, allows to inspect its structure and also to edit the structure. Practical validation is naturally the more complicated part. It needs screen reader, users which actually knows how to handle them, can test documents and can report where a \PDF{} has real accessibility problems. \minisec{Preflight woes} Sadly validators can not be always trusted. As an example for an reason that I don't understand the adobe preflight don't like the list structure \texttt{L}. It is also possible that validators contradict: that the one says everything is okay, while the other complains. \subsection{Examples wanted!} To make the package usable examples are needed: examples that demonstrate how various structures can be tagged and which patches are needed, examples for the test suite, examples that demonstrates problems. \begin{tcolorbox}[before upper=\tagpdfparaOn] Feedback, contribuations and corrections are welcome! \end{tcolorbox} All examples should use the \cs{tagpdfsetup} key \PrintKeyName{uncompress} described in the next section so that uncompressed \PDF{} are created and the internal objects and structures can be inspected and -- hopefully soon -- be compared by the l3build checks.% \section{Changes} \subsection{Changes in 0.3} In this version I improved the handling of alternative and actual text. See section~\ref{sec:alttext}. This change meant that the package relied on the module \texttt{l3str-convert}. I no longer try to (pdf-)escape the tag names: it is a bit unclear how to do it at best with luatex. This will perhaps later change again. \subsection{Changes in 0.5} I added code to handle attributes and attribute classes, see section~\ref{sec:attributes} and corrected a small number of code errors. I added code to add \enquote{real} space glyphs to the \PDF{}, see section \ref{sec:spacechars}. \subsection{Changes in 0.6} \textbf{Breaking change!} The attributes used in luamode to mark the MC-chunks are no longer set globally. I thought that global attribute would make it easier to tag, but it only leads to problem when e.g. header and footer are inserted. So from this version on the attributes are set locally and the effect of a \verb+\tagmcbegin+ ends with the current group. This means that in some cases more \verb+\tagmcbegin+ are needed and this affected some of the examples, e.g. the patching commands for sections with KOMA. On the other side it means that quite often one can omit the \verb+\tagmcend+ command. \subsection{Changes in version 0.61} \begin{itemize} \item internal code adaptions to expl3 changes. \item dropped the compresslevel key -- probably not needed. \end{itemize} \subsection{Changes in version 0.8} \begin{itemize} \item As a first step to include the code proper in the \LaTeX\ kernel the module name has changed from \texttt{uftag} to \texttt{tag}. The commands starting with |\uftag| will stay valid for some time but then be deprecated. \item \textbf{Breaking change!} The argument of \texttt{newattribute} option should no longer add the dictionary bracket \verb+<<..>>+, they are added by the code. \item \textbf{Breaking change!} The package now requires the new PDF management as provided for now by the package \texttt{pdfmanagement-testphase}. \texttt{pdfmanagement-testphase}, prepares the ground for better support for tagged PDF in \LaTeX{}. It is part of a larger project to automatically generate tagged PDF \url{https://www.latex-project.org/news/2020/11/30/tagged-pdf-FS-study/} \item Support to add associated files to structures has been added with new keys \texttt{AF}, \texttt{AFinline} and \texttt{AFinline-o}. \item \textbf{Breaking change!} The support for other 8-bit input encodings has been removed. utf8 is now the required encoding. \item The keys |lang|, |ref| and |E| have been added for structures. \item The new hooks of LaTeX are used to tagged many paragraphs automatically. The small red numbers around paragraphs in the documentation show them in action. The main problem here is not to tag a paragraph, but to avoid to tag too many: paragraphs pop up in many places. \end{itemize} \subsection{Changes in version 0.81} \begin{itemize} \item Hook code to tag links (URI and GoTo type) have been added. So normally they should simply work if tagging is activated. \item Commands and keys to allow automatic paragraph tagging have been added. See section~\ref{sec:paratagging}. As can be seen in this documentation the code works quite good already, but one should be aware that \enquote{paragraphs} can appear in many places and sometimes there are even more paragraph begin than ends. \item A key to test if local or global setting of the mc-attributes in luamode is more sensible, see \ref{sec:global-local} for more details. \item New commands to store and reset mc-tags. \item PDF 2.0 namespaces are now supported. \end{itemize} \subsection{Changes in version 0.82} A command |\tag_if_active:TF| to test if tagging is active has been added. This allow external packages to write conditional code. The commands |\tag_struct_parent_int:| and |\tag_struct_insert_annot:nn| have been added. They allow to add annotations to the structure. \subsection{Changes in version 0.83} |\tag_finish_structure:| has been removed, it is no longer a public command. \subsection{Changes in version 0.90} \begin{itemize} \item Code has been cleaned up and better documented. \item \textbf{More engines supported} The generic mode of \pkg{tagpdf} now works (theoretically, it is not much tested) with all engines supported by the pdfmanagement. So compilations with Xe\LaTeX{} or with dvips should work. But it should be noted that these engines and backends don't support the |interspaceword| option. With Xe\LaTeX{} it is perhaps possible implement something with |\XeTeXinterchartoks|, but for the dvips route I don't see an option (apart from lots of manual macros everywhere). \item \textbf{MC-attributes are global again} In\sidenote{Breaking change!} version 0.6 the attributes used in luamode to mark the MC-chunks were no longer set globally. This avoided a number of problems with header and footer and background material, but further tests showed that it makes it difficult to correctly mark things like links which have to interrupt the current marking code---the attributes couldn't easily escape groups added by users. See section~\ref{sec:global-local} for more details. \item \textbf{key global-mc removed:} Due to the changes in the attribute keys this key is not longer needed. \item \textbf{key check-tags removed:} It doesn't fit. Checks are handled over the logging level. \item |\tagpdfget| has been removed, use the expl3 version if needed. \item The show commands |\showtagpdfmcdata|, |\showtagpdfattributes|, |\showtagstack| have been removed and replaced by a more flexible command |\ShowTagging|. \item The commands |\tagmcbegin| and |\tagmcend| no longer ignore following spaces or remove earlier one. While this is nice in some places, it also ate spaces in places where this wasn't expected. From now on both commands behave exactly like the expl3 versions. \item The lua-code to add real space glyphs has been separated from the tagging code. This means that |interwordspace| now works also if tagging is not active. \item The key |activate| has been added, it open the first structure, see below. \end{itemize} \subsection{Changes in version 0.92} \begin{itemize} \item support for page breaks in pdftex has been added, see section~\ref{sec:splitpara}, This requires a new version of the pdfmanagement-testphase package. \item header and footer are tagged as artifacts automatically, see section~\ref{sec:header-footer}. \item keys \texttt{alttext-o} and \texttt{actualtext-o} has been removed. \texttt{alttext} and \texttt{actualtext} will now expand once. \end{itemize} \subsection{Changes in version 0.93} \begin{itemize} \item Support for associated files in the root element (key \texttt{root-AF}) has been added. This allow e.g. to add a css-file which is be used if the \PDF\ is converted to html. \item First steps have been done to adapt the package to planed changes in \LaTeX{}: The command \cs{DocumentMetadata} will be added to the format and will take over the role of \cs{DeclareDocumentMetadata} from \pkg{pdfmanagement-testphase}. \item The package has now support for \enquote{structure destinations}. This is a new type of destinations in \PDF~2.0. For pdftex and luatex this requires new binaries. They will be included in texlive 2022, miktex already has the new pdftex, the new luatex will probably follow soon. \item The commands \cs{tagpdfifluatexT}, \cs{tagpdfifluatexTF} has been removed \cs{tagpdfifpdftexT}, \end{itemize} \subsection{Proof of concept: the tagging of the documentation itself} Starting with version 0.6 the documentation itself has been tagged. The tagging wasn't (and isn't) in no way perfect. The validator from Adobe didn't complain, but PAX3 wanted alternative text for all links (no idea why) and so I put everywhere simple text like \enquote{link} and \enquote{ref}. The links to footnotes gave warnings, so I disabled them. I used types from the \PDF{} version 1.7, mostly as I have no idea what should be used for code in 2.0. Margin notes were simply wrong \ldots The tagging has been improved and automated over time in sync with improvements and new features in the LaTeX kernel and the pdfmanagement code. But even if the documentation passed the tests of the validators: as mentioned above passing a formal test doesn't mean that the content is really good and usable. I have a lot doubts that the code parts are really readable. The bibliography and the references must be improved. The user commands used for the tagging and also some of the patches used are still rather crude. So there is lot space for improvement. \begin{tcolorbox}[before upper=\tagpdfparaOn] Be aware that to create the tagged version a current lualatex-dev and a current version of the pdfmanagment-testphase package is needed. \end{tcolorbox} \tagpdfparaOff \tagstructbegin{tag=Figure,alttext=PAC3 report,attribute=bbox}\tagmcbegin{tag=Figure} \includegraphics{pac3} \tagmcend\tagstructend \tagpdfparaOn \section{Setup} The package requires the new PDF management. With a current version of \pkg{pdfmanagement-testphase} it can be loaded and activated like this: \begin{lstlisting} \RequirePackage{pdfmanagement-testphase} \DeclareDocumentMetadata { testphase = tagpdf, % load activate = tagging % activate and create the document structure } \documentclass{article} \begin{document} some text \end{document} \end{lstlisting} With \LaTeX{} 2022-06-01 (or a current \LaTeX-dev) the call will be simpler \begin{lstlisting} \DocumentMetadata { testphase = tagpdf, % load + activate } \documentclass{article} \begin{document} some text \end{document} \end{lstlisting} \minisec{Activation needed!} When the package is loaded it will -- apart from loading more packages and defining a lot of things -- not do much. You will have to activate it with \verb+\tagpdfsetup+ or as shown above in \verb+\DeclareDocumentMetadata+/\verb+\DocumentMetadata+. Most commands do nothing if tagging is not activated, but in case a test is needed a command (with the usual p,T,F variants) is provided: \begin{docCommand}{tag_if_active:TF}{}\end{docCommand} The check is true only if \emph{everything} is activated. In all other cases (also if tagging has been stopped locally) it will be false. \subsection{Modes and package options} %TODO think about tagging of the keys. Aside? Header? The package has two different modes: The \textbf{generic mode} works (in theory, currently only tested with pdftex and luatex) probably with all engines, the \textbf{lua mode} only with luatex. The differences between both modes will be described later. The mode can be set with package options: \DescribeKey{luamode} This is the default mode. It will use the generic mode if the document is processed with pdflatex and the lua mode with lualatex. \DescribeKey{genericmode} This will force the generic mode for all engines. \subsection{Setup and activation}\label{ssec:setup} \begin{docCommand}{tagpdfsetup}{\marg{key-val-list}}\end{docCommand} This command setups the general behaviour of the package. The command should be normally used only in the preamble (for a few keys it could also make sense to change them in the document). The key-val list understands the following keys: \begin{description} \item[\PrintKeyName{activate-all}] Boolean, initially false. Activates everything, that's normally the sensible thing to do. \item [\PrintKeyName{activate}] Like |activate-all|, \emph{additionally} is opens at begin document a structure with |\tagstructbegin| and closes it at end document. The key accepts as value a tag name which is used as the tag of the structure. The default value is |Document|. \item[\PrintKeyName{activate-mc}] Boolean, initially false. Activates the code related to marked content. \item[\PrintKeyName{activate-struct}] Boolean, initially false. Activates the code related to structures. Should be used only if \PrintKeyName{activate-mc} has been used too. \item[\PrintKeyName{no-struct-dest}] Starting with version 0.93 \pkg{tagpdf} will create automatically structure destinations (see section~\ref{sec:struct-dest} if \pkg{hyperref} is used, if the engine supports it and if the pdf version is 2.0. With this key this can be suppressed. \item[\PrintKeyName{activate-tree}] Boolean, initially false. Activates the code related to trees. Should be used only if the two other keys has been used too. \item[\PrintKeyName{add-new-tag}] Allows to define new tag names, see section \ref{sec:new-tag} for a description. \item[\PrintKeyName{interwordspace}] Choice key, possible values are \PrintKeyName{true}/""\PrintKeyName{on} and \PrintKeyName{false}/\PrintKeyName{off}. The key activates/deactivates the insertion of space glyphs, see section~\ref{sec:spacechars}. In the luamode it only works if at least \PrintKeyName{activate-mc} has been used. \item[\PrintKeyName{log}] Choice key, possible values \PrintKeyName{none}, \PrintKeyName{v}, \PrintKeyName{vv}, \PrintKeyName{vvv}, \PrintKeyName{all}. Setups the log level. Changing the value affects currently mostly the luamode: \enquote{higher} values gives more messages in the log. The current levels and messages have been setup in a quite ad-hoc manner and will need improvement. \item[\PrintKeyName{newattribute}] This key takes two arguments and declares an attribute. See \ref{sec:attributes}. \item[\PrintKeyName{show-spaces}] Boolean.\sidenote{luamode} That's a debug option, it helps in lua mode to see where space glyph will be inserted if \PrintKeyName{interwordspace} is activated. \item[\PrintKeyName{paratagging}] Boolean. This activate/deactivates the automatic tagging of paragraphs. It uses the \texttt{para/begin} and \texttt{para/end} hooks of the newest \LaTeX{} version (2021-05-01). This is a first try to use this hooks, and the code is bound to change. Paragraphs can appear in many unexpected places and the code can easily break, so there is also an option to see where such paragraphs are: \item[\PrintKeyName{paratagging-show}] Boolean. This activate/deactivates small red numbers in the places where the paratagging hook code is used. \item[\PrintKeyName{tabsorder}] Choice key, possible values are \PrintKeyName{row}, \PrintKeyName{column}, \PrintKeyName{structure}, \PrintKeyName{none}. This decides if a \verb+/Tabs+ value is written to the dictionary of the page objects. Not really needed for tagging itself, but one of the things you probably need for accessibility checks. So I added it. Currently the tabsorder is the same for all pages. Perhaps this should be changed \ldots. \item[\PrintKeyName{tagunmarked}] Boolean,\sidenote{luamode} initially true. When this boolean is true, the lua code will try to mark everything that has not been marked yet as an artifact. The benefit is that one doesn't have to mark up every deco rule oneself. The danger is that it perhaps marks things that shouldn't be marked -- it hasn't been tested yet with complicated documents containing annotations etc. See also section~\ref{sec:lazy} for a discussion about automatic tagging. \item[\PrintKeyName{uncompress}] Sets both the \PDF{} compresslevel and the \PDF{} objcompresslevel to 0 and so allows to inspect the \PDF{}. \end{description} \section{Tagging} pdf is a page orientated graphic format. It simply puts ink and glyphs at various coordinates on a page. A simple stream of a page can look like this\tagpdfparaOff\footnote{The appendix contains some remarks about the syntax of a \PDF{} file}\tagpdfparaOn: \begin{lstlisting}[columns=fixed] stream BT /F27 14.3462 Tf %select font 89.291 746.742 Td %move point [(1)-574(Intro)-32(duction)]TJ %print text /F24 10.9091 Tf %select font 0 -24.35 Td %move point [(Let's)-331(start)]TJ %print text 205.635 -605.688 Td %move point [(1)]TJ %print text ET endstream \end{lstlisting} From this stream one can extract the characters and their placement on the page but not their semantic meaning (the first line is actually a section heading, the last the page number). And while in the example the order is correct there is actually no guaranty that the stream contains the text in the order it should be read. Tagging means to enrich the \PDF{} with information about the \emph{semantic} meaning and the \emph{reading order}. (Tagging can do more, one can also store all sorts of layout information like font properties and indentation with tags. But as I already wrote this package concentrates on the part of tagging that is needed to improve accessibility.) \subsection{Three tasks} To tag a \PDF{} three tasks must be carried out: \begin{enumerate} \item \textbf{The mark-content-task}:\sidenote{mc-task} The document must add \enquote{labels} to the page stream which allows to identify and reference the various chunks of text and other content. This is the most difficult part of tagging -- both for the document writer but also for the package code. At first there can be quite many chunks as every one is a leaf node of the structure and so often a rather small unit. At second the chunks must be defined page-wise -- and this is not easy when you don't know where the page breaks are. Also in a standard document a lot text is created automatically, e.g. the toc, references, citations, list numbers etc and it is not always easy to mark them correctly. \item \textbf{The structure-task}:\sidenote{struct-task} The document must declare the structure. This means marking the start and end of semantically connected portions of the document (correctly nested as a tree). This too means some work for the document writer, but less than for the mc-task: at first quite often the mc-task and the structure-task can be combined, e.g. when you mark up a list number or a tabular cell or a section header; at second one doesn't have to worry about page breaks so quite often one can patch standard environments to declare the structure. On the other side a number of structures end in \LaTeX\ only implicitly -- e.g. an item ends at the next item, so getting the \PDF{} structure right still means that additional mark up must be added. \item \textbf{The tree management}:\sidenote{tree-task} At last the structure must be written into the \PDF{}. For every structure an object of type \texttt{StructElem} must be created and flushed with keys for the parents and the kids. A parenttree must be created to get a reference from the mc-chunks to the parent structure. A rolemap must be written. And a number of dictionary entries. All this is hopefully done automatically and correctly by the package \ldots. \end{enumerate} \begin{figure}[t!] \begin{tcolorbox}[before upper=\tagpdfparaOn] \minisec{Page stream with marked content} \tagpdfparaOff \tagstructbegin{tag=Figure,alttext={Illustration of page stream with marked content},attribute=bbox}% \tagmcbegin{tag=Figure}% \begin{tikzpicture}[baseline=(a.north),node distance=2pt,remember picture] \node(start){\ldots~\ldots~\ldots}; \node[draw,base right = of start](a) {mc-chunk 1}; \node[draw,base right = of a](b) {mc-chunk 2}; \node[draw,base right = of b](c) {mc-chunk 3}; \node[draw,base right = of c](d) {mc-chunk 3}; \node[base right = of d] {\ldots~\ldots}; \end{tikzpicture} \tagmcend\tagstructend \tagpdfparaOn \minisec{Structure} \tagpdfparaOff \newlength\ydistance\setlength\ydistance{-0.8cm} \tagstructbegin{tag=Figure,alttext={Illustration of structure},attribute=bbox}% \tagmcbegin{tag=Figure}% \begin{tikzpicture}[remember picture,baseline=(root.north)] \node[draw,anchor=base west] (root) at (0,0) {Sect (start section)}; \node[draw,anchor=base west] at (0.3,\ydistance) {H (header section)}; \node[draw,anchor=base west](aref) at (0.6,2\ydistance){mc-chunk 1}; \node[draw,anchor=base west](bref) at (0.6,3\ydistance){mc-chunk 2}; \node[draw,anchor=base west] at (0.3,4\ydistance){/H (end header)}; \node[draw,anchor=base west] at (0.3,5\ydistance){P (start paragraph)}; \node[draw,anchor=base west](cref) at (0.6,6\ydistance){mc-chunk 3}; \node[draw,anchor=base west](dref) at (0.6,7\ydistance){mc-chunk 4}; \node[draw,anchor=base west] at (0.3,8\ydistance){/P (end paragraph)}; \node[draw,anchor=base west] at (0,9\ydistance){/Sect (end section)}; \end{tikzpicture} \begin{tikzpicture}[remember picture, overlay] \draw[->,red](aref)-|(a); \draw[->,red](bref)-|(b); \draw[->,red](cref)-|(c); \draw[->,red](dref)-|(d); \end{tikzpicture} \tagmcend\tagstructend \tagpdfparaOn \end{tcolorbox} \tagstructbegin{tag=Caption}\tagmcbegin{tag=Caption} \caption{Schematical description of the relation between marked content in the page stream and the structure} \tagmcend\tagstructend \end{figure} \subsection{Task 1: Marking the chunks: the mark-content-step} To be able to refer to parts of the text in the structure, the text in the page stream must get \enquote{labels}. In the \PDF{} reference they are called \enquote{marked content}. The three main variants needed here are: \begin{description} \item[Artifacts] They are marked with of a pair of keywords, \texttt{BMC} and \texttt{EMC} which surrounds the text. \texttt{BMC} has a single prefix argument, the fix tag name \texttt{/Artifact}. Artifacts should be used for irrelevant text and page content that should be ignored in the structure. Sadly it is often not possible to leave such text simply unmarked -- the accessibility tests in Acrobat and other validators complain. \begin{lstlisting} /Artifact BMC text to be marked /EMC \end{lstlisting} \item[Artifacts with a type] They are marked with of a pair of keywords, \texttt{BDC} and \texttt{EMC} which surrounds the text. \texttt{BDC} has two arguments: again the tag name \texttt{/Artifact} and a following dictionary which allows to specify the suppressed info. Text in header and footer can e.g. be declared as pagination like this: \begin{lstlisting} /Artifact <> BDC text to be marked /EMC \end{lstlisting} \item[Content] Content is marked also with of a pair of keywords, \texttt{BDC} and \texttt{EMC}. The first argument of \texttt{BDC} is a tag name which describes the structural type of the text\tagpdfparaOff\footnote{There is quite some redundancy in the specification here. The structural type is also set in the structure tree. One wonders if it isn't enough to use always \texttt{/SPAN} here.}\tagpdfparaOn Examples are \texttt{/P} (paragraph), \texttt{/H2} (heading), \texttt{/TD} (table cell). The reference mentions a number of standard types but it is possible to add more or to use different names. In the second argument of \texttt{BDC} -- in the property dictionary -- more data can be stored. \emph{Required} is an \texttt{/MCID}-key which takes an integer as a value: \begin{lstlisting} /H1 <> BDC text to be marked /EMC \end{lstlisting} This integer is used to identify the chunk when building the structure tree. The chunks are numbered by page starting with 0. As the numbers are also used as an index in an array they shouldn't be \enquote{holes} in the numbering system (It is perhaps possible to handle a numbering scheme not starting by 0 and having holes, but it will enlarge the \PDF{} as one would need dummy objects.). It is possible to add more entries to the property dictionary, e.g. a title, alternative text or a local language setting. \end{description} The needed markers can be added with low level code e.g. like this (in pdftex syntax): \begin{lstlisting} \pdfliteral page {/H1 <> BDC}% text to be marked \pdfliteral page {EMC}% \end{lstlisting} This sounds easy. But there are quite a number of traps, mostly with pdfLaTeX: \begin{enumerate}[beginpenalty=10000] \item \PDF{} is a page oriented format. And this means that the start \texttt{BDC}/\texttt{BMC} and the corresponding end \texttt{EMC} must be on the same page. So marking e.g. a section title like in the following example won't always work as the literal before the section could end on the previous page: \begin{lstlisting} \pdfliteral page {/H1 <> BDC} %problem: possible pagebreak here \section{mysection} \pdfliteral page {EMC}% \end{lstlisting} Using the literals \emph{inside} the section argument is better, but then one has to take care that they don't wander into the header and the toc. \item Literals are \enquote{whatsits} nodes and can change spacing, page and line breaking. The literal \emph{behind} the section in the previous example could e.g. lead to a lonely section title at the end of the page. \item The \texttt{/MCID} numbers must be unique on a page. So you can't use the literal in a saved box that you reuse in various places. This is e.\,g. a problem with \texttt{longtable} as it saves the table header and footer in a box. \item The \texttt{/MCID}-chunks are leaf nodes in the structure tree, so they shouldn't be nested. \item Often text in a document is created automatically or moved around: entries in the table of contents, index, bibliography and more. To mark these text chunks correctly one has to analyze the code creating such content to find suitable places to inject the literals. \item The literals are inserted directly and not at shipout. This means that due to the asynchronous page breaking of \TeX\ the MCID-number can be wrong even if the counter is reset at every page. This package uses in generic mode a label-ref-system to get around this problem. This sadly means that often at least three compilations are needed until everything has settled down. It can actually be worse: If the text is changed after the MCID-numbers have been assigned, and a new mc-chunk is inserted in the middle of the page, then all the numbers have to be recalculated and that requires again a number of compilations until it really settles down again. Internal references are especially problematic here, as the first compilation typically creates a non-link |??|, and only the second inserts the structure and the new mc. When the reference system in LaTeX will be extended, care will be taken to ensure that already the dummy text builds a chunk. Until then the advice is to first compile the document and resolve all cross-reference and to activate tagging only at the end. \item There exist environments which process their content more than once -- examples are \texttt{align} and \texttt{tabularx}. So one has to check for doublettes and holes in the counting system. \item \PDF{} is a page oriented format. And this means that the start and the end marker must be on the same page \ldots\ \emph{so what to do with normal paragraphs that split over pages??}. This question will be discussed in subsection~\ref{sec:splitpara}. \end{enumerate} \subsubsection{Generic mode versus lua mode in the mc-task} While in generic mode the commands insert the literals directly and so have all the problems described above the lua mode works quite differently: The tagging commands don't insert literals but set some \emph{attributes} which are attached to all the following nodes. When the page is shipped out some lua code is called which wanders through the shipout box and injects the literals at the places where the attributes changes. This means that quite a number of problems mentioned above are not relevant for the lua mode: \begin{enumerate} \item Pagebreaks between start and end of the marker are \emph{not} a problem. So you can mark a complete paragraph. If a pagebreak occur directly after an start marker or before an end marker this can lead to empty chunks in the \PDF{} and so bloat up \PDF{} a bit, but this is imho not really a problem (compared to the size increase by the rest of the tagging). \item The commands don't insert literals directly and so affect line and page breaking much less. \item The numbering of the MCID are done at shipout, so no label/ref system is needed. \item The code can do some marking automatically. Currently everything that has not been marked up by the document is marked as artifact. \end{enumerate} \subsubsection{Commands to mark content and chunks} In generic mode\sidenote{Generic mode only} is vital that the end command is executed on the same page as the begin command. So think carefully how to place them. For strategies how to handle paragraphs that split over pages see subsection~\ref{sec:splitpara}. \begin{docCommand}{tagmcbegin}{\marg{key-val-list}}\end{docCommand} \begin{docCommand}{tag_mc_begin:n}{\marg{key-val-list}}\end{docCommand} These commands insert the begin of the marked content code in the \PDF{}. They don't start a paragraph. \emph{They don't start a group}. Such markers should not be nested. The command will warn you if this happens. The key-val list understands the following keys: \begin{description} \item[\PrintKeyName{tag}] This is required, unless you use the \PrintKeyName{artifact} key. The value of the key is normally one of the standard type listed in section \ref{sec:new-tag} (without a slash at the begin, this is added by the code). It is possible to setup new tags, see the same section. The value of the key is expanded, so it can be a command. The expansion is passed unchanged to the \PDF{}, so it should with a starting slash give a valid \PDF{} name (some ascii with numbers like \texttt{H4} is fine). \item[\PrintKeyName{artifact}] This will setup the marked content as an artifact. The key should be used for content that should be ignored. The key can take one of the values \PrintKeyName{pagination}, \PrintKeyName{pagination/header}, \PrintKeyName{pagination/footer}, \PrintKeyName{layout}, \PrintKeyName{page}, \PrintKeyName{background} and \PrintKeyName{notype} (this is the default). Text in the header and footer should normally be marked with \PrintKeyName{artifact=pagination} or \PrintKeyName{pagination/header}, \PrintKeyName{pagination/footer} but simply artifact (as it is now done automatically) should be ok too. It is not quite clear if rules and other decorative graphical objects needs to be marked up as artifacts. Acrobat seems not to mind if not, but PAC~3 complained. The validators complain if some text is not marked up, but it is not quite clear if this is a serious problem. The\sidenote{lua mode only} lua mode will mark up everything unmarked as \texttt{artifact=notype}. You can suppress this behaviour by setting the tagpdfsetup key \texttt{tagunmarked} to false. See section \ref{ssec:setup}. \item[\PrintKeyName{stash}] Normally marked content will be stored in the \enquote{current} structure. This may not be what you want. As an example you may perhaps want to put a marginnote behind or before the paragraph it is in the tex-code. With this boolean key the content is marked but not stored in the kid-key of the current structure. \item[\PrintKeyName{label}] This key sets a label by which you can call the marked content later in another structure (if it has been stashed with the previous key). Internally the label name will start with \texttt{tagpdf-}. \item[\PrintKeyName{alttext}] This key inserts an \texttt{/Alt} value in the property dictionary of the BDC operator. See section~\ref{sec:alttext}. The value is handled as verbatim string, commands are not expanded but the value will be expanded first once (so works like the key \texttt{alttext-o} in previous versions which has been removed). That means that you can do something like in the following listing and it will insert \verb+\frac{a}{b}+ (hex encoded) in the \PDF{}. \begin{lstlisting} \newcommand\myalttext{\frac{a}{b}} \tagmcbegin{tag=P,alttext=\myalttext} \end{lstlisting} \item[\PrintKeyName{actualtext}] This key inserts an \texttt{/ActualText} value in the property dictionary of the BDC operator. See section~\ref{sec:alttext}. The value is handled as verbatim string, commands are not expanded but the value will be expanded first once (so works like the key \texttt{actualtext-o} in previous versions which has been removed). That means that you can do something like in the following listing and and it will insert \verb+X+ (hex encoded) in the \PDF{}. \begin{lstlisting} \newcommand\myactualtext{X} \tagmcbegin{tag=Span,actualtext=\myactualtext} \end{lstlisting} According to the PDF reference, \texttt{/ActualText} should only be used on marked content sequence of type Span. This is not enforced by the code currently. \item[\PrintKeyName{raw}] This key allows you to add more entries to the properties dictionary. The value must be correct, low-level \PDF{}. E.g. \verb+raw=/Alt (Hello)+ will insert an alternative Text. \end{description} \begin{docCommand}{tagmcend}{}\end{docCommand} \begin{docCommand}{tag_mc:end}{}\end{docCommand} These commands insert the end code of the marked content. They don't end a group and it doesn't matter if they are in another group as the starting commands. In generic mode both commands check if there has been a begin marker and issue a warning if not. In luamode it is often possible to omit the command, as the effect of the begin command ends with a new \verb+\tagmcbegin+ anyway. % no longer relevant %\begin{tcolorbox}[before upper=\tagpdfparaOn] %\minisec{About nesting mc-commands}\label{mc-nesting} % %\textbf{Attention!}\sidenote{luamode} As mentioned above in luamode it is often possible to omit the \verb+\tagmcend+ command. This basically means that mc-chunks can be nested. But be aware that this can have surprising side effects on the order in the structure. % %Consider a code like this: % % %\begin{lstlisting} %\tagmcbegin{tag=P} Block 1 {\tagmcbegin{tag=P} Block 2} Block 3 \tagmcend %\end{lstlisting} % % %Block 3 will here get the same id number as Block 1 and be stored in the structure \emph{before} Block 2. The \PDF{} will record the chunks in the order \texttt{Block 1 -- Block 3 -- Block 2}. See also section~\ref{sec:global-local}. % %\end{tcolorbox} \begin{docCommand}{tagmcuse}{}\end{docCommand} \begin{docCommand}{tag_mc_use:n}{}\end{docCommand} These commands allow you to record a marked content that you stashed away into the current structure. Be aware that a marked content can be used only once -- the command will warn you if you try to use it a second time. \begin{docCommand}{tag_mc_end_push:}{}\end{docCommand} \begin{docCommand}{tag_mc_begin_pop:n}{\marg{key-val-list}}\end{docCommand} If there is an open mc chunk, the first command ends it and pushes its tag on a stack. If there is no open chunk, it puts $-1$ on the stack (for debugging). The second command removes a value from the stack. If it is different from $-1$ it opens a tag with it. The command is mainly meant to be used inside hooks and command definitions so there is only an expl3 version. Perhaps other content of the mc-dictionary (for example the Lang) needs to be saved on the stacked too. \begin{docCommand}{tagmcifinTF}{\marg{true code}\marg{false code}}\end{docCommand} \begin{docCommand}{tag_mc_if_in:TF}{\marg{true code}\marg{false code}}\end{docCommand} These commands check if a marked content is currently open and allows you to e.g. add the end marker if yes. In \emph{generic mode}, where marked content command shouldn't be nested, it works with a global boolean. In \emph{lua mode} it tests if the mc-attribute is currently unset. You can't test the nesting level with it! \begin{docCommand}{tag_get:n}{\marg{key word}}\end{docCommand} This command give back some variables. Currently the only working key words are \verb+mc\_tag+ and \verb+struct\_tag+. \subsubsection{Luamode: global or not global -- that is the question}\label{sec:global-local} In\sidenote{Luamode mode only} luamode the mc-commands set and unset an attribute to mark the nodes. One can view such an attribute like a font change or a color: they affect all following chars and glue nodes until stopped. From version 0.6 to 0.82 the attributes were set locally. This had the advantage that the attributes didn't spill over in area where they are not wanted like the header and footer or the background pictures. But it had the disadvantage that it was difficult for an inner structure to correctly interrupt the outer mc-chunk if it can't control the group level. For example this didn't work due to the grouping inserted by the user: \begin{lstlisting} \tagstructbegin{tag=P} \tagmcbegin{tag=P} Start paragraph {% user grouping \tag_mc_end_push: \tagstructbegin{tag=Em} \tagmcbegin{tag=Em} \emph{Emphasized test} \tagmcend \tagstructend \tag_mc_begin_pop:n{} }% user grouping Continuation of paragraph \tagmcend \tagstructend \end{lstlisting} The reading order was then wrong, and the \emph{emphasized text} moved in the structure at the end. So starting with version 0.9 this has been reverted. The attribute is now global again. This solves the \enquote{interruption} problem, but has its price: Material inserted by the output routine must be properly guarded. For example \begin{lstlisting} \RequirePackage{pdfmanagement-testphase} \DeclareDocumentMetadata{uncompress} \documentclass{article} \usepackage{tagpdf} \tagpdfsetup{activate,interwordspace=true} \pagestyle{headings} \begin{document} \tagstructbegin{tag=Document} \sectionmark{HEADER} \AddToHook{shipout/background}{\put(5cm,-5cm){BACKGROUND}} \tagmcbegin{tag=P}Page 1\newpage Page 2\tagmcend \tagstructend \end{document} \end{lstlisting} Here the header and the background code on the \emph{first} page will be marked up as paragraph and added as chunk to the document structure. The header and the background code on the \emph{second} page will be marked as artifact. The following figure shows how the tags looks like. \tagpdfparaOff \tagstructbegin{tag=Figure,alttext=Show tags of examples,attribute=bbox}\tagmcbegin{tag=Figure} \includegraphics{global-ex} \tagmcend\tagstructend \tagpdfparaOn It is therefore from now on important to correctly markup such code. Header and footer typically should be artifacts. The LaTeX kernel hasn't yet suitable hooks around header and footer to allow to automate this, but a first draft has been added with \pkg{pdfmanagement-testphase}. Starting with version 0.92 header and footer are marked as (simple) artifacts. If they contain code which needs a different markup it still must be added explicitly. With packages like \pkg{fancyhdr} or \pkg{scrlayer-scrpage} it is quite easy to add the needed code. \subsubsection{Tips} \begin{itemize} \item Mark commands inside floats should work fine (but need perhaps some compilation rounds in generic mode). \item In case you want to use it inside a \verb+\savebox+ (or some command that saves the text internally in a box): If the box is used directly, there is probably no problem. If the use is later, stash the marked content and add the needed \verb+\tagmcuse+ directly before oder after the box when you use it. \item Don't use a saved box with markers twice. \item If boxes are unboxed you will have to analyze the \PDF{} to check if everything is ok. \item If you use complicated structures and commands (breakable boxes like the one from tcolorbox, multicol, many footnotes) you will have to check the \PDF{}. \end{itemize} \begin{figure} \tagpdfparaOff \tagstructbegin{tag=Figure,alttext={Illustration of link annotation structure},attribute=bbox}\tagmcbegin{tag=Figure} \ExplSyntaxOn \tag_stop_group_begin: \ExplSyntaxOff \input{link-figure-input} \ExplSyntaxOn \tag_stop_group_end: \ExplSyntaxOff \tagmcend\tagstructend \tagstructbegin{tag=Caption}\tagmcbegin{tag=Caption} \caption{Structure needed for a link annotation}\label{fig:linkannot} \tagmcend\tagstructend \end{figure} \subsubsection{Header and Footer}\label{sec:header-footer} Tagging header and footer is not trivial. At first on the technical side header and footer are typeset and attached to the page during the output routine and the exact timing is not really under control of the user. That means that when adding tagging there one has to be careful not to disturb the tagging of the main text---this is mostly important in luamode where the attributes are global and can easily spill over. At second one has to decide about how to tag: in many cases header and footer can simply be ignored, they only contain information which are meant to visually guide the reader and so are not relevant for the structure. This means that normally they should be tagged as artifacts. The PDF reference offers here a rather large number of options here to describe different versions of \enquote{ignore this}. Typically the header and footer should get the type \texttt{Pagination} and this types has a number of subtypes like Header, Footer, PageNum. It is not yet known if any technology actually make use of this info. But they can also contain meaningful content, for example an address. In such cases the content should be added to the structure (where?) but even if this address is repeated on every page at best only once. All this need some thoughts both from the users and the packages and code providing support for header and footers. For now tagpdf added some first support for automatically tagging: Starting with version 0.92 header and footer are by default automatically marked up as (simple) artifacts. With the key \PrintKeyName{exclude-header-footer} the behaviour can be changed: The value \texttt{false} disables the automatic tagging, the value \texttt{pagination} add additionally an \texttt{/Artifact} structure with the attribute \texttt{/Pagination}. If some additional markup (or even a structure) is wanted, something like this should be used (here with the syntax of the \pkg{fancyhdr} package) to close the open mc-chunk and restart if after the content: \begin{lstlisting} \ExplSyntaxOn \cfoot{\leavevmode \tag_mc_end_push: \tagmcbegin{artifact=pagination/footer} \thepage \tagmcend \tag_mc_begin_pop:n{artifact}} \ExplSyntaxOff \end{lstlisting} \subsubsection{Links and other annotations}\label{sec:link+annot} Annotations (like links or form field annotations) are objects associated with a geometric region of the page rather than with a particular object in its content stream. Any connection between a link or a form field and the text is based solely on visual appearance (the link text is in the same region, or there is empty space for the form field annotation) rather than on an explicitly specified association. To connect such a annotation with the structure and so with surrounding or underlying text a specific structure has to be added, see \ref{fig:linkannot}: The annotation is added to a structure element as an object reference. It is not referenced directly but through an intermediate object of type OBJR. To the dictionary of the annotation a \texttt{/StructParent} entry must be added, the value is a number which is then used in the ParentTree to define a relationship between the annotation and the parent structure element. To support this, \pkg{tagpdf} offers currently two commands \begin{docCommand}{tag_struct_parent_int:}{}\end{docCommand} This insert the current value of a global counter used to track such objects. It can be used to add the \texttt{/StructParent} value to the annotation dictionary. \begin{docCommand}{tag_struct_insert_annot:nn}{\marg{object reference}\marg{struct parent number}}\end{docCommand} This will insert the annotation described by the object reference into the current structure by creating the OBJR object. It will also add the necessary entry to the parent tree and increase the global counter referred to by |\tag_struct_parent_int:|. It does nothing if (structure) tagging is not activated. Attention! As the second command increases the global counter at the end it changes the value given back by the first. That means that if nesting is involved care must be taken that the correct numbers is used. This should be easy to fulfil for most annotations, as there are boxes. There the second command should at best be used directly behind the annotation and it can make use of |\tag_struct_parent_int:|. For links nesting is theoretically possible, and it could be that future versions need more sophisticated handling here. In environments which process their content twice like tabularx or align it would be the best to exclude the second command from the trial step, but this will need better support from these environments. Typically using this commands is not often needed: Since version 0.81 \pkg{tagpdf} already handles (unnested) links, and form fields created with the \pkg{l3pdffield-testphase} package will be handle by this package. The following listing shows low-level to create link where the two commands are used: \begin{lstlisting} \pdfextension startlink attr { /StructParent \tag_struct_parent_int: %<---- } user { /Subtype/Link /A << /Type/Action /S/URI /URI(http://www.dante.de) >> } This is a link. \pdfextension endlink \tag_struct_insert_annot:xx {\pdfannot_link_ref_last:}{\tag_struct_parent_int:} \end{lstlisting} \subsubsection{Math} Math is a problem. I have seen an example where \emph{every single symbol} has been marked up with tags from MathML along with an \texttt{/ActualText} entry and an entry with alternate text which describes how to read the symbol. The \PDF{} then looked like this \begin{lstlisting} /mn </Alt( : open bracket: four )>>BDC ... /mn </Alt( third s )>>BDC ... /mo </Alt( times )>>BDC \end{lstlisting} If this is really the way to go one would need some script to add the mark-up as doing it manually is too much work and would make the source unreadable -- at least with pdflatex and the generic mode. In lua mode is it possible to hook into the \texttt{mlist\_to\_hlist} callback and add marker automatically. Some first implementation is done by Marcel Krüger in the luamml project. But I'm not sure that this is the best way to do math. It looks rather odd that a document should have to tell a screen reader in such detail how to read an equation. It would be much more efficient, sensible and flexible if a complete representation of the equation in mathML could be stored in the \PDF{} and the task how to read this aloud delegated to the screen reader. As \PDF{}~2.0 introduced associated files it is probable that this will be the way to go but more investigations are needed here. See also section~\ref{sec:alttext} for some more remarks and tests. \subsubsection{Split paragraphs}\label{sec:splitpara} %TODO: think about marginnote! Aside? A\sidenote{Generic mode only} problem in generic mode are paragraphs with page breaks. As already mentioned the end marker \texttt{EMC} must be added on the same page as the begin marker. But it is in pdflatex \emph{very} difficult to inject something at the page break automatically. One can manipulate the shipout box to some extend in the output routine, but this is not easy and it gets even more difficult if inserts like footnotes and floats are involved: the end of the paragraph is then somewhere in the middle of the box. So with pdflatex in generic mode one until now had to do the splitting manually. The example \texttt{mc-manual-para-split} demonstrates how this can be done. The general idea was to use \verb+\vadjust+ in the right place: \begin{lstlisting} \tagmcbegin{tag=P} ... fringilla, ligula wisi commodo felis, ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante.% page break \vadjust{\tagmcend\pagebreak\tagmcbegin{tag=P}} Pellentesque scelerisque ... sit amet, lacus.\tagmcend \end{lstlisting} Starting with version 0.91 there is code which tries to resolve this problem. Basically it works like this: every mc-command issues a mark command (actually two slightly different). When the page is built in the output routine this mark commands are inspected and from them \LaTeX{} can deduce if there is a mc-chunk which must be closed or reopened. Please note \begin{itemize} \item The code requires the pdfmanagement-testphase version v0.95i. \item Typically you will need more compilations than previously, don't rely on the rerun messages, but if something looks wrong rerun. \item The code relies on that related |\tagmcbegin| and |\tagmcend| are in the same boxing level. If one is in a box (which hides the marks) and the other in the main galley, things will go wrong. \end{itemize} \subsubsection{Automatic tagging of paragraphs}\label{sec:paratagging} \begin{docCommand}{tagpdfparaOn}{}\end{docCommand} \begin{docCommand}{tagpdfparaOff}{}\end{docCommand} Another feature that emerged from the \LaTeX{} tagged PDF project are hooks at the begin and end of paragraphs. \pkg{tagpdf} makes use of these hooks to tag paragraphs. This can be activated/deactivated (also locally) with options of \cs{tagpdfsetup} or with the two commands above. \emph{This is very experimental and it requires a new \LaTeX!} The automatic tagging require that for every begin of a paragraph with the begin hook code there a corresponding end with the closing hook code. This can fail, e.g if a |vbox| doesn't correctly issue a |\par| at the end. If this happens the tagging structure can get every confused. It is therefore needed to check the structure carefully as currently no checks are implemented to check this automatically. \subsection{Task 2: Marking the structure} The structure is represented in the \PDF{} with a number of objects of type \texttt{StructElem} which build a tree: each of this objects points back to its parent and normally has a number of kid elements, which are either again structure elements or -- as leafs of the tree -- the marked contents chunks marked up with the \verb+tagmc+-commands. The root of the tree is the \texttt{StructTreeRoot}. \subsubsection{Structure types} The tree should reflect the \emph{semantic} meaning of the text. That means that the text should be marked as section, list, table head, table cell and so on. A number of standard structure types is predefined, see section \ref{sec:new-tag} but it is allowed to create more. If you want to use types of your own you must declare them. E.g. this declares two new types \texttt{TAB} and {FIG} and bases them on \texttt{P}: \begin{lstlisting} \tagpdfsetup{ add-new-tag = TAB/P, add-new-tag = FIG/P, } \end{lstlisting} \subsubsection{Sectioning} The sectioning units can be structured in two ways: a flat, html-like and a more (in pdf/UA2 basically deprecated) xml-like version. The flat version creates a structure like this: \begin{lstlisting}
text
text