% !Mode:: "TeX:DE:UTF-8:Main" \makeatletter \def\UlrikeFischer@package@version{0.61} \def\UlrikeFischer@package@date{2019-07-02} \makeatother \pdfvariable majorversion = 1 \pdfvariable minorversion = 7 \documentclass[DIV=12,parskip=half-,bibliography=totoc]{scrartcl} \usepackage{scrlayer-scrpage} \usepackage{fontspec} \setmainfont{Heuristica} \usepackage{unicode-math} \usepackage[english]{babel} \usepackage[autostyle]{csquotes} \usepackage{microtype} %\DisableLigatures{encoding = TU, family = tt* } \usepackage[style=numeric,hyperref=false]{biblatex} \addbibresource{tagpdf.bib} \usepackage{tcolorbox} \usepackage{tabularx} \usepackage[noparboxrestore]{marginnote} \reversemarginpar \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,needspace,xpatch} \makeatletter \enitkv@key{enumitem}{compactsep}[true]{% \divide\partopsep by 2\relax \divide\topsep by 2\relax \divide\itemsep by 2\relax \divide\parsep by 2\relax} \makeatother \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}} \usepackage{listings} \lstset{basicstyle=\ttfamily, columns=fullflexible,language=[LaTeX]TeX, escapechar=*, commentstyle=\color{green!50!black}\bfseries} \usepackage{tagpdf} \tagpdfsetup{ activate-all, uncompress, tabsorder=structure, interwordspace=true, %log=v %show-spaces } %metadata \pdfextension catalog{/Lang (en-UK)} \IfFileExists{pdfresources.sty} { \usepackage{pdfresources} \usepackage[customdriver=hluatex-experimental, pdfdisplaydoctitle=true,pdfusetitle,hyperfootnotes=false, ]{hyperref} }{} %\usepackage[ocgcolorlinks]{ocgx2} \usepackage{ydoc-desc} %hm hyperref ist ein Problem ... \usepackage{tagpdfdocu-patches} \hypersetup{colorlinks,} \cfoot*{\leavevmode\tagmcbegin{artifact=pagination}\pagemark\tagmcend} \begin{document} \tagstructbegin{tag=Document} \tagstructbegin{tag=Title} \tagmcbegin{tag=P} \maketitle \tagmcend \tagstructend \begin{tcolorbox}[colframe=red] \tagstructbegin{tag=Div} \TagP^ This package is not meant for normal document production. \TagP You need a current expl3 version to use it, you even need the (experimental) \texttt{l3str-convert}. \TagP This package is incomplete, experimental and quite probably contains bugs. \TagP You need some knowledge about \TeX, pdf and perhaps even lua to use it. \medskip \TagP Issues, comments, suggestions should be added as issues to the github tracker:\TagPend \medskip \centering \url{https://github.com/u-fischer/tagpdf} \tagstructend \end{tcolorbox} \begin{NoHyper} %combination of link and other struct is to complicated for now ... \tableofcontents \end{NoHyper} \section{Introduction} \TagP^ 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. \TagP 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. \TagP This package tries to close this gap by offering \emph{core} commands to tag a pdf.\footnote{In case you don't know what this means: there will be some explanations later on.} \TagP 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. \TagP 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 accompaigning 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. \TagP 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. \TagP 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}. \TagP Please also check the github site for new examples and improvements. \TagPend \subsection{Tagging and accessibility} \TagP^ 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. \TagP So the name of the package is a bit wrong. As excuse I can only say that it is shorter and easier to pronounce. \TagPend \subsection{Engines and modes} \TagP^ The package works currently with pdflatex and lualatex. \TagP 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. \TagP 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. \TagP 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 main problem with luatex is how to insert \enquote{fake spaces} between words.% \TagPend \subsection{References} \TagP^ My main reference was the free reference for pdf 1.7. \parencite{pdfreference}. This document is from 2006. \TagP In the meantime pdf 2.0. has been released. I know that it contains also for accessibility relevant changes. As I got now the specification and luatex can set with \verb+\pdfmajorversion+ the version to 2.0 I will start to check to look into it too.% \TagPend \subsection{Validation} \TagP^ pdf's created with the commands of this package must be validated:\TagPend \begin{itemize} \item \TagP^ 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. \Pmeti \item \TagP^ One must check how good the requirements of the PDF/UA standard are followed \emph{formally}. \Pmeti \item \TagP^ One must check how good the accessibility is \emph{practically}.\Pmeti \end{itemize} \TagP^ 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}. \TagP 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}. But I didn't try it yet and have no idea if it is useful here. \TagP 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.\TagPend \minisec{Preflight woes} \TagP^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.\TagPend \subsection{Examples wanted!} \TagP^ To make the package usable examples are needed: example that demonstrates how various structures can be tagged and which patches are needed, examples for the test suite, examples that demonstrates problems.\TagPend \begin{tcolorbox}[] \TagP^ Feedback, contribuations and corrections are welcome!\TagPend \end{tcolorbox} \TagP^ All examples should use the 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.% \TagPend \subsection{Changes in 0.3} \TagP^ In this version I improved the handling of alternative and actual text. See section~\ref{sec:alttext}. This change means that the package now relies on the experimental expl3 package \texttt{l3str-convert}. \TagP 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.\TagPend \subsection{Changes in 0.5} \TagP^I added code to handle attributes and attribute classes, see section~\ref{sec:attributes} and corrected a small number of code errors. \TagP I added code to add \enquote{real} space glyphs to the pdf, see section \ref{sec:spacechars}.\TagPend \subsection{Changes in 0.6} \TagP^\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.\TagPend \subsection{Proof of concept: the tagging of the documentation itself} \TagP^With version 0.6 the documentation itself has been tagged. The tagging is in no way perfect. The validator from Adobe doesn'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 footnote 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 are probably simply wrong \ldots\TagPend \TagP^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 rather crude. So there is lot space for improvement.\TagPend \begin{tcolorbox} \TagP^Be aware that to create the tagged version a very experimental package and a experimental hyperref driver was needed for the links. This files are not in the package!\TagPend \end{tcolorbox} \tagstructbegin{tag=Figure,alttext=PAC3 report}\tagmcbegin{tag=Figure} \includegraphics{pac3} \tagmcend\tagstructend \subsection{Changes in version 0.61} \begin{itemize} \item \TagP^internal code adaptions to expl3 changes.\Pmeti \item \TagP^dropped the compresslevel key -- probably not needed\Pmeti \end{itemize} \section{Setup} \minisec{Activation needed!} \TagP^When the package is loaded it will -- apart from loading more packages and defining a lot of things -- not do anything. You will have to activate it with \verb+\tagpdfsetup+, see below. (At least that's the theory, I'm not quite sure, if really the tests are done always as planed\ldots.) \TagPend \subsection{Modes and package options} \TagP^The package has two different modes: The \textbf{generic mode} works (in theory, currently only 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} \TagP 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} \TagP This will force the generic mode for all engines. \TagPend \subsection{Setup and activation}\label{ssec:setup} \TagP^The following 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). \DescribeMacro\tagpdfsetup{} \TagP The key-val list understands the following keys:\TagPend \begin{description} \item[\PrintKeyName{activate-all}] \TagP^Boolean, initially false. Activates everything, that's normally the sensible thing to do.\Pmeti \item[\PrintKeyName{activate-mc}] \TagP^Boolean, initially false. Activates the code related to marked content.\Pmeti \item[\PrintKeyName{activate-struct}] \TagP^Boolean, initially false. Activates the code related to structures. Should be used only if \PrintKeyName{activate-mc} has been used too.\Pmeti \item[\PrintKeyName{activate-tree}] \TagP^ Boolean, initially false. Activates the code related to trees. Should be used only if the two other keys has been used too.\Pmeti \item[\PrintKeyName{add-new-tag}] \TagP^Allows to define new tag names, see section \ref{sec:new-tag} for a description.\Pmeti \item[\PrintKeyName{check-tags}] \TagP^Boolean, initially true. Activates some safety checks (but doesn't do very much currently. It will perhaps be merged with the log-level key).\Pmeti \item[\PrintKeyName{inputencoding}] \TagP^Some keys convert their value and so need to know the encoding of the file. The default encoding is utf8. When using pdflatex you can switch to another encoding with this key. The value should be one of names allowed by \texttt{l3str}. There is no checking that the name is valid (I don't think that it sensible to use something else than utf8). \Pmeti \item[\PrintKeyName{interwordspace}] \TagP^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.\Pmeti \item[\PrintKeyName{log}] \TagP^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.\Pmeti \item[\PrintKeyName{newattribute}] \TagP^This key takes two arguments and declares an attribute. See \ref{sec:attributes}.\Pmeti \item[\PrintKeyName{show-spaces}] \TagP^Boolean.\marginnote{luamode} That's a debug option, it helps to see where space glyph will be inserted if \PrintKeyName{interwordspace} is activated.\Pmeti \item[\PrintKeyName{tabsorder}] \TagP^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.\Pmeti \item[\PrintKeyName{tagunmarked}] \TagP^Boolean,\marginnote{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.\Pmeti \item[\PrintKeyName{uncompress}] \TagP^Sets both the pdf compresslevel and the pdf objcompresslevel to 0 and so allows to inspect the pdf.\Pmeti \end{description} \section{Tagging} \TagP^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\footnote{The appendix contains some remarks about the syntax of a pdf file}: \TagPend \tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \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} \tagmcend\tagstructend \TagP^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. \TagP 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.)\TagPend \subsection{Three tasks} \TagP^To tag a pdf three tasks must be carried out:\TagPend \begin{enumerate} \item \TagP^\textbf{The mark-content-task}:\marginnote{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.\Pmeti \item \TagP^\textbf{The structure-task}:\marginnote{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. \Pmeti \item \TagP^\textbf{The tree management}:\marginnote{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. \Pmeti \end{enumerate} \begin{figure}[t!] \begin{tcolorbox} \minisec{Page stream with marked content} \tagstructbegin{tag=Figure,alttext={Illustration of page stream with marked content}}% \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 \minisec{Structure} \newlength\ydistance\setlength\ydistance{-0.8cm} \tagstructbegin{tag=Figure,alttext={Illustration of structure}}% \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 \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} \TagP^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:\TagPend \begin{description} \item[Artifacts] \TagP^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.\TagPend \tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} /Artifact BMC text to be marked /EMC \end{lstlisting} \tagmcend\tagstructend\meti \item[Artifacts with a type] \TagP^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:\TagPend \tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} /Artifact <> BDC text to be marked /EMC \end{lstlisting} \tagmcend\tagstructend\meti \item[Content] \TagP^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\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.} Examples are \texttt{/P} (paragraph), \texttt{/H2} (header), \texttt{/TD} (table cell). The reference mentions a number of standard types but it is possible to add more or to use different names. \TagP 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:\TagPend \tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} /H <> BDC text to be marked /EMC \end{lstlisting} \tagmcend\tagstructend \TagP^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 %\footnote{ (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.). \TagP It is possible to add more entries to the property dictionary, e.g. a title, alternative text or a local language setting.\Pmeti \end{description} \TagP^The needed markers can be added with low level code e.g. like this (in pdftex syntax):\TagPend \tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} \pdfliteral page {/H <> BDC}% text to be marked \pdfliteral page {EMC}% \end{lstlisting} \tagmcend\tagstructend \TagP^This sounds easy. But there are quite a number of traps.\TagPend \begin{enumerate}[beginpenalty=10000] \item \TagP^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:\TagPend \tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} \pdfliteral page {/H <> BDC} %problem: possible pagebreak here \section{mysection} \pdfliteral page {EMC}% \end{lstlisting} \tagmcend\tagstructend \TagP^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.\Pmeti \item \TagP^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.\Pmeti \item \TagP^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.\Pmeti \item \TagP^The \texttt{/MCID}-chunks are leaf nodes in the structure tree, so they shouldn't be nested.\Pmeti \item \TagP^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.\Pmeti \item \TagP^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 three compilations are needed until everything has settled down).\Pmeti \item \TagP^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.\Pmeti \item \TagP^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}.\Pmeti \end{enumerate} \subsubsection{Generic mode versus lua mode in the mc-task} \TagP^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. \TagP This means that quite a number of problems mentioned above are not relevant for the lua mode:\TagPend \begin{enumerate} \item \TagP^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).\Pmeti \item \TagP^The commands don't insert literals directly and so affect line and page breaking much less.\Pmeti \item \TagP^The numbering of the MCID are done at shipout, so no label/ref system is needed.\Pmeti \item \TagP^The code can do some marking automatically. Currently everything that has not been marked up by the document is marked as artifact.\Pmeti \end{enumerate} \subsubsection{Commands to mark content and chunks} \TagP^It\marginnote{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}.\TagPend \ExplSyntaxOn \DescribeMacro\tagmcbegin{} \DescribeMacro\uftag_mc_begin:n{} \ExplSyntaxOff \TagP^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}. The user command additionally issues an \verb+\ignorespaces+ to suppress spaces after itself. Such markers should not be nested. The command will warn you if this happens. \TagP The key-val list understands the following keys:\TagPend \begin{description} \item[\PrintKeyName{tag}] \TagP^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).\Pmeti \item[\PrintKeyName{artifact}] \TagP^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{layout}, \PrintKeyName{page}, \PrintKeyName{background} and \PrintKeyName{notype} (this is the default). Text in the header and footer should be marked with \PrintKeyName{artifact=pagination}. \TagP 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. \TagP The validators complain if some text is not marked up, but it is not quite clear if this is a serious problem. \TagP The\marginnote{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}.\Pmeti \item[\PrintKeyName{stash}] \TagP^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.\Pmeti \item[\PrintKeyName{label}] \TagP^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-}.\Pmeti \item[\PrintKeyName{alttext}] \TagP^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.\Pmeti \item[\PrintKeyName{alttext-o}] \TagP^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 like the key \PrintKeyName{alttext} but expanded once (the \texttt{o} refers to the \texttt{o} type in expl3). That means that you can do something like this: \TagPend \tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} \newcommand\myalttext{\frac{a}{b}} \tagmcbegin{tag=P,alttext-o=\myalttext} \end{lstlisting} \tagmcend\tagstructend \TagP^ and it will insert \verb+\frac{a}{b}+ (hex encoded) in the pdf.\Pmeti \item[\PrintKeyName{actualtext}] \TagP^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.\Pmeti \item[\PrintKeyName{actualtext-o}] \TagP^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 like the key \PrintKeyName{actualtext} but expanded once (the \texttt{o} refers to the \texttt{o} type in expl3). That means that you can do something like this:\TagPend \tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} \newcommand\myactualtext{X} \tagmcbegin{tag=P,alttext-o=\myactualtext} \end{lstlisting} \tagmcend\tagstructend \TagP^and it will insert \verb+X+ (hex encoded) in the pdf.\Pmeti \item[\PrintKeyName{raw}] \TagP^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.\Pmeti \end{description} \ExplSyntaxOn \DescribeMacro\tagmcend \DescribeMacro\uftag_mc_end: \ExplSyntaxOff \TagP^These commands insert the end code of the marked content. They don't end a group and in generic mode it doesn't matter if they are in another group as the starting commands. The user command also issues at first an \verb+\unskip+. 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 the current group or with a new \verb+\tagmcbegin+ anyway.\TagPend \begin{tcolorbox} \minisec{About nesting mc-commands} \TagP^\textbf{Attention!}\marginnote{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. \TagP Consider a code like this:\TagPend \tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} \tagmcbegin{tag=P} Block 1 {\tagmcbegin{tag=P Block 2}} Block 3 \tagmcend \end{lstlisting} \tagmcend\tagstructend \TagP^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}. \TagPend \end{tcolorbox} \ExplSyntaxOn \DescribeMacro\tagmcuse{