From 2fc2609488764102ce43194e9288b7bd8e25f17f Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sun, 16 May 2021 03:00:44 +0000 Subject: CTAN sync 202105160300 --- macros/latex/contrib/tagpdf/tagpdf.tex | 1352 +++++++++++++++++++------------- 1 file changed, 824 insertions(+), 528 deletions(-) (limited to 'macros/latex/contrib/tagpdf/tagpdf.tex') diff --git a/macros/latex/contrib/tagpdf/tagpdf.tex b/macros/latex/contrib/tagpdf/tagpdf.tex index 3c9085df9b..6baa8b13a0 100644 --- a/macros/latex/contrib/tagpdf/tagpdf.tex +++ b/macros/latex/contrib/tagpdf/tagpdf.tex @@ -1,46 +1,44 @@ % !Mode:: "TeX:DE:UTF-8:Main" +\RequirePackage{pdfmanagement-testphase} +\DeclareDocumentMetadata{pdfversion=2.0,lang=en-UK} + + \makeatletter -\def\UlrikeFischer@package@version{0.80} -\def\UlrikeFischer@package@date{2021-02-23} +\def\UlrikeFischer@package@version{0.81} +\def\UlrikeFischer@package@date{2021-05-14} \makeatother -\RequirePackage{pdfmanagement-testphase} -\DeclareDocumentMetadata{pdfversion=1.7,lang=en-UK} + \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{unicode-math} +\setmainfont{Heuristica} \usepackage{microtype} -%\DisableLigatures{encoding = TU, family = tt* } + +\usepackage{scrlayer-scrpage} + +\usepackage[autostyle]{csquotes} \usepackage[style=numeric,hyperref=false]{biblatex} \addbibresource{tagpdf.bib} -\usepackage{tcolorbox} - -\usepackage{tabularx} \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,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{enumitem,xpatch} + \usepackage{listings} \lstset{basicstyle=\ttfamily, columns=fullflexible,language=[LaTeX]TeX, escapechar=*, @@ -55,327 +53,396 @@ interwordspace=true, %log=v %show-spaces + global-mc } + \usepackage{hyperxmp} - \usepackage[pdfdisplaydoctitle=true,hyperfootnotes=false, +\usepackage[pdfdisplaydoctitle=true,hyperfootnotes=false, ]{hyperref} + \hypersetup{ - pdftitle={The \pkg{tagpdf} package, v\csname UlrikeFischer@package@version\endcsname}, + pdftitle={The tagpdf package, v\csname UlrikeFischer@package@version\endcsname}, pdfauthor=Ulrike Fischer, pdfaconformance=a, - pdfuapart=1} -%\usepackage[ocgcolorlinks]{ocgx2} -\usepackage{ydoc-desc} %hm hyperref ist ein Problem ... + 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} -\hypersetup{colorlinks,} + +%header and footer. This still needs some sorting, the first page does't work correctly \cfoot*{\leavevmode\tagmcbegin{artifact=pagination}\pagemark\tagmcend} -\newcommand\PDF{PDF} +\makeatletter +\patchcmd\@oddfoot{\begingroup}{\begingroup\tagpdfparaOff}{}{} +\patchcmd\@oddhead{\begingroup}{\begingroup\tagpdfparaOff}{}{} +\makeatother -\ExplSyntaxOn -\newcounter{paracnt} -\bool_new:N \l__tag_paratagging_bool -\AddToHook{para/begin} - { - \stepcounter{paracnt} - \bool_if:NT \l__tag_paratagging_bool - { - \tagstructbegin{tag=P}\tagmcbegin{tag=P} - \llap{\color{red}\tiny\arabic{paracnt}\ } - } - } -\AddToHook{para/end} - { - \bool_if:NT \l__tag_paratagging_bool - { - \rlap{\color{red}\tiny\ \arabic{paracnt}} - \tagmcend\tagstructend} - } -\newcommand\parataggingON {\bool_set_true:N \l__tag_paratagging_bool} -\newcommand\parataggingOff{\bool_set_false:N \l__tag_paratagging_bool} +\newcommand\PDF{PDF} -\ExplSyntaxOff +\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}} -\makeatletter -\patchcmd\@oddfoot{\begingroup}{\begingroup\parataggingOff}{}{} -\patchcmd\@oddhead{\begingroup}{\begingroup\parataggingOff}{}{} +\tagpdfsetup{paratagging,paratagging-show} \begin{document} + \tagstructbegin{tag=Document} + \tagstructbegin{tag=Title} - \tagmcbegin{tag=P} - \maketitle +\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 -\begin{tcolorbox}[colframe=red] -\tagstructbegin{tag=Div} %\booltrue{paratagging} -\TagP^ This package is not meant for normal document production. -\TagP You need a very current \LaTeX{} format. + + + +\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. -\TagP This package is incomplete, experimental and quite probably contains bugs. +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. -\TagP This package can change in an incompatible way. +This package can change in an incompatible way. -\TagP You need some knowledge about \TeX, \PDF{} and perhaps even lua to use it. +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 +Issues, comments, suggestions should be added as issues to the github tracker: \medskip -\centering \url{https://github.com/u-fischer/tagpdf} - +\centering +\url{https://github.com/u-fischer/tagpdf} -\tagstructend \end{tcolorbox} +\tagstructend -\begin{NoHyper} %combination of link and other struct is to complicated for now ... \tableofcontents -\end{NoHyper} - -\section{Preface to version 0.8} -\parataggingON +\section{Preface to version 0.8 and newer} -%\TagP^ -With this version one major step towards integration of the code into the \LaTeX{} has been done: +Starting with version 0.8 one major step towards integration of the code into the \LaTeX{} has been done: The code now relies on the new \LaTeX{} PDF management. This management, which is for a testphase provided as an external package, \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/} -%\TagPend While this is a major improvement---it will for example allow to use tagpdf with more engines as the new PDF management supports all major engines and allowed to add support for associated files---it also means that this version requires a special setup of the document and is incompatible with a number of packages, see the documentation of \texttt{pdfmanagement-testphase} for details. -Another important step are the new hook management in \LaTeX: the newest development version has hooks for paragraphs which should at the end allow to tag many paragraphs automatically. The small red numbers in this section 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. - - -\parataggingOff +Another important step is the new hook management in \LaTeX: the newest development version has hooks for paragraphs which should at the end allow to tag 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. \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. -\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. +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 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. -\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.} +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 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. -\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 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. -\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. +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 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 +Please also check the github site for new examples and improvements. \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. +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. -\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. 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 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. -\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. +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. -\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. +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. -\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 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. -\subsection{References} +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. -\TagP^ My main reference was the free reference for \PDF{} 1.7. \parencite{pdfreference}. This document is from 2006. +The packages 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. -\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 +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} -\TagP^ \PDF{}'s created with the commands of this package must be validated:\TagPend +\PDF{}'s created with the commands of this package must be validated: \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 + 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 -\TagP^ One must check how good the requirements of the PDF/UA standard are followed \emph{formally}. - \Pmeti +One must check how good the requirements of the PDF/UA standard are followed \emph{formally}. + \item -\TagP^ One must check how good the accessibility is \emph{practically}.\Pmeti +One must check how good the accessibility is \emph{practically}. \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 +There is also the validator veraPDF \parencite{verapdf}. +A rather new 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} -\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 +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!} -\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 + +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} -\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 + +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.% + \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 +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} -\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 + +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} -\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 +\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. + -\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 +\item internal code adaptions to expl3 changes. +\item dropped the compresslevel key -- probably not needed. \end{itemize} + + + \subsection{Changes in version 0.8} -\TagP^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 \verb|\uftag| will stay valid for some time but then be deprecated.\TagPend -\TagP^\textbf{Breaking change!} The argument of \texttt{newattribute} option should no longer add the dictionary bracket \verb+<<..>>+, they are added by the code.\TagPend +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 \verb|\uftag| will stay valid for some time but then be deprecated. + +\textbf{Breaking change!} The argument of \texttt{newattribute} option should no longer add the dictionary bracket \verb+<<..>>+, they are added by the code. + + +\textbf{Breaking change!} The package now requires the new PDF management as provided for now by the package \texttt{pdfmanagement-testphase} +Support to add associated files to structures has been added with new keys \texttt{AF}, \texttt{AFinline} and \texttt{AFinline-o}. -\TagP^\textbf{Breaking change!} The package now requires the new PDF management as provided for now by the package \texttt{pdfmanagement-testphase}\TagPend +\textbf{Breaking change!} The support for other 8-bit input encodings has been removed. +utf8 is now the required encoding. -\TagP^Support to add associated files to structures has been added with new keys \texttt{AF}, \texttt{AFinline} and \texttt{AFinline-o}.\TagPend +The keys |lang|, |ref| and |E| have been added for structures. -\TagP^\textbf{Breaking change!} The support for other 8-bit input encodings has been removed. -utf8 is now the required encoding. \TagPend +\subsection{Changes in version 0.81} -\TagP^The keys |lang|, |ref| and |E| have been added for structures.\TagPend +Hook code to tag links (URI and GoTo type) have been added. So normally they should simply work if tagging +is activated. + +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. + +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. + +New commands to store and reset mc-tags. + +PDF 2.0 namespace are now supported. + +\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} + \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 + + +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+, see below. (At least that's the theory, I'm not quite sure, if really the tests are done always as planed\ldots.) \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} +%TODO think about tagging of the keys. Aside? Header? -\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} +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} -\TagP This will force the generic mode for all engines. \TagPend +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} -\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). +\begin{docCommand}{tagpdfsetup}{\marg{key-val-list}}\end{docCommand} -\DescribeMacro\tagpdfsetup{} +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: -\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 + Boolean, initially false. Activates everything, that's normally the sensible thing to do. \item[\PrintKeyName{activate-mc}] - \TagP^Boolean, initially false. Activates the code related to marked content.\Pmeti + Boolean, initially false. Activates the code related to marked content. \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 + Boolean, initially false. Activates the code related to structures. Should be used only if \PrintKeyName{activate-mc} has been used too. \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 +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}] - \TagP^Allows to define new tag names, see section \ref{sec:new-tag} for a description.\Pmeti + Allows to define new tag names, see section \ref{sec:new-tag} for a description. \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 + Boolean, initially true. Activates some safety checks (but doesn't do very much currently. It will perhaps be merged with the log-level key). \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 + 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}] - \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 + 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}] - \TagP^This key takes two arguments and declares an attribute. See \ref{sec:attributes}.\Pmeti + This key takes two arguments and declares an attribute. See \ref{sec:attributes}. \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 + +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}] - \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 + 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}] - \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 + 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}] - \TagP^Sets both the \PDF{} compresslevel and the \PDF{} objcompresslevel to 0 and so allows to inspect the \PDF{}.\Pmeti + Sets both the \PDF{} compresslevel and the \PDF{} objcompresslevel to 0 and so allows to inspect the \PDF{}. + +\item[\PrintKeyName{global-mc}] + Only relevant for luatex and luamode and can only be used in the preamble. If used the attributes used for the mc-tags are set globally. This key is temporary! It is there to allow to test if global or local setting is more sensible. See section~\ref{sec:global-local} for more info. \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} +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 @@ -390,38 +457,45 @@ stream 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 +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} -\TagP^To tag a \PDF{} three tasks must be carried out:\TagPend + + + +To tag a \PDF{} three tasks must be carried out: \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 + \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 - \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 + \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 - \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 + \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} + + +\begin{tcolorbox}[before upper=\tagpdfparaOn] \minisec{Page stream with marked content} -\tagstructbegin{tag=Figure,alttext={Illustration of 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}; @@ -433,11 +507,15 @@ endstream \end{tikzpicture} \tagmcend\tagstructend +\tagpdfparaOn + \minisec{Structure} +\tagpdfparaOff + \newlength\ydistance\setlength\ydistance{-0.8cm} -\tagstructbegin{tag=Figure,alttext={Illustration of structure}}% +\tagstructbegin{tag=Figure,alttext={Illustration of structure},attribute=bbox}% \tagmcbegin{tag=Figure}% \begin{tikzpicture}[remember picture,baseline=(root.north)] @@ -461,272 +539,358 @@ endstream \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} -\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 + + +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] \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 +\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. + -\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} + +\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} -\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.} + + +\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} (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 +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: + -\tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} -/H <> BDC +/H1 <> 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{ + +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.). -\TagP It is possible to add more entries to the property dictionary, e.g. a title, alternative text or a local language setting.\Pmeti +It is possible to add more entries to the property dictionary, e.g. a title, alternative text or a local language setting. \end{description} -\TagP^The needed markers can be added with low level code e.g. like this (in pdftex syntax):\TagPend +The needed markers can be added with low level code e.g. like this (in pdftex syntax): + -\tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} -\pdfliteral page {/H <> BDC}% +\pdfliteral page {/H1 <> 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 + +This sounds easy. But there are quite a number of traps, mostly with pdfLaTeX: \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 + \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: + -\tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} -\pdfliteral page {/H <> BDC} %problem: possible pagebreak here +\pdfliteral page {/H1 <> 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 + + 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 - \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 + 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 - \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 + 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 - \TagP^The \texttt{/MCID}-chunks are leaf nodes in the structure tree, so they shouldn't be nested.\Pmeti + The \texttt{/MCID}-chunks are leaf nodes in the structure tree, so they shouldn't be nested. \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 + 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 - \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 + 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). \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 + 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 - \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 + \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} -\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. +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 +This means that quite a number of problems mentioned above are not relevant for the lua mode: \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 +\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} -\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\tag_mc_begin:n{} -\ExplSyntaxOff +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}. -\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. +\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}. 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. +The key-val list understands the following keys: -\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 + 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}] - \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}. + 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. + 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. + 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 + 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}] - \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 + 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}] - \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 + 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}] - \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 + 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. + \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 + 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 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-o=\myalttext} + \end{lstlisting} + + - \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 + 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. \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 + 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 in the following listing and and it will insert \verb+X+ (hex encoded) in the \PDF{}. - \TagP^and it will insert \verb+X+ (hex encoded) in the \PDF{}.\Pmeti + \begin{lstlisting} + \newcommand\myactualtext{X} + \tagmcbegin{tag=P,alttext-o=\myactualtext} + \end{lstlisting} \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 + 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} -\ExplSyntaxOn -\DescribeMacro\tagmcend -\DescribeMacro\tag_mc_end: -\ExplSyntaxOff +\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 in generic mode it doesn't matter if they are in another group as the starting commands. The user command also issues in hmode 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. -\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 +\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: + -\tagstructbegin{tag=Code}\tagmcbegin{tag=Code} \begin{lstlisting} -\tagmcbegin{tag=P} Block 1 {\tagmcbegin{tag=P Block 2}} Block 3 \tagmcend +\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 + +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} -\ExplSyntaxOn -\DescribeMacro\tagmcuse{