latex3 / tagpdf

Tagging support code for LaTeX
60 stars 7 forks source link

Add "Scope" attribute to table headers #10

Closed ckelley-air closed 5 years ago

ckelley-air commented 5 years ago

For tables to be compliant with accessibility standards (specifically American 508 compliance standards) the table headers need to have the "scope" attribute set to being either "None", "Both" or "Columns" or "Rows" to indicate which dimension the header refers to.

For example in the raw pdf this appears for a header cell as attribute "A" of the header cell with attributes {'/O': '/Table', '/Scope': 'Both'}.

I cant quite figure out how to create this tag in tagpdf. MWE is below

\documentclass{scrartcl} \usepackage[english]{babel} \usepackage{tagpdf}

\begin{document} \pagestyle{empty} % \tagstructbegin{tag=Document}

\tagstructbegin{tag=Table} \begin{center} \begin{tabular}{ l | c | } \hline \tagstructbegin{tag=TR} \tagstructbegin{tag=TH} \tagmcbegin{tag=TH,raw=/Scope (Both)} h1 \tagmcend \tagstructend & \tagstructbegin{tag=TH} \tagmcbegin{tag=TH} h2 \tagmcend \tagstructend \ \hline \tagstructbegin{tag=TR} \tagstructbegin{tag=TH} \tagmcbegin{tag=TH} r1 \tagmcend \tagstructend & \tagstructbegin{tag=TD} \tagmcbegin{tag=TD} h2 \tagmcend \tagstructend \tagstructend
\ \hline \end{tabular} \end{center} \tagstructend

\tagstructend \end{document}

If you could find a way to add this is it would be SO incredibly helpful- tagpdf is an amazing package and has gotten me so so close to the fully accessible PDF I need.

ckelley-air commented 5 years ago

Here is the full (tiny) example that shows how i get a fully tagged text, image and table. Everything works great except the alt text for the image and the scope tags for the table headers. I am building this into a bigger project and would be super happy to share the final product/contribute examples to the repo when i get the kinks ironed out.

\documentclass{scrartcl} \usepackage[english]{babel} \usepackage{tagpdf} \usepackage{graphicx} \usepackage[a-1b]{pdfx}

\begin{filecontents}{\jobname.xmpdata} \Title{Test PDF/A-1b} \Author{Claire Kelley} \Subject{subject here} \Keywords{keyword, compliance} \end{filecontents}

\tagpdfifpdftexT { \pdfcatalog{/Lang (en-UK)} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} }

\tagpdfifluatexT { \pdfextension catalog{/Lang (en-UK)} \usepackage{fontspec} }

\tagpdfsetup { tabsorder=structure, activate-all, uncompress }

\begin{document} \pagestyle{empty} % \tagstructbegin{tag=Document}

\tagstructbegin{tag=P} \tagmcbegin{tag=P} Test Paragraph \newline \tagmcend \tagstructend

\tagstructbegin{tag=Table} \begin{center} \begin{tabular}{ l | c | r } \hline \tagstructbegin{tag=TR} \tagstructbegin{tag=TH} \tagmcbegin{tag=TH,raw=/Scope (Both)} h1 \tagmcend \tagstructend & \tagstructbegin{tag=TH} \tagmcbegin{tag=TH} h2 \tagmcend \tagstructend & \tagstructbegin{tag=TH} \tagmcbegin{tag=TH} h3 \tagmcend \tagstructend \tagstructend \ \hline \tagstructbegin{tag=TR} \tagstructbegin{tag=TH} \tagmcbegin{tag=TH} r1 \tagmcend \tagstructend & \tagstructbegin{tag=TD} \tagmcbegin{tag=TD} 2 \tagmcend \tagstructend & \tagstructbegin{tag=TD} \tagmcbegin{tag=TD} 3 \tagmcend \tagstructend \tagstructend
\ \hline \end{tabular} \end{center} \tagstructend

\tagstructbegin{tag=Figure} \tagmcbegin{tag=Figure} \includegraphics{District.pdf} \tagmcend \tagstructend

\tagstructend \end{document}

u-fischer commented 5 years ago

I added a key "attribute" for \tagstructbegin. The new files are in https://github.com/u-fischer/tagpdf/tree/master/source/texmf/tex/latex/tagpdf. An example is in https://github.com/u-fischer/tagpdf/blob/master/source/examples/structure/ex-attribute.tex.

Be aware that the values of owner and scope are names not strings. So the input should be

\tagstructbegin{tag=TH,attribute= /O/Table /Scope/Row}
u-fischer commented 5 years ago

attribute can imho also be references to objects (which would allow for more than one structelem to share the same settings . So this should be possible too. And it should also be possible to add and use a classmap. I will have to think about a sensible interface. It could be that the name of the key will change in the feature.

ckelley-air commented 5 years ago

Wow thank you so much!

u-fischer commented 5 years ago

I'm currently working on a better interface. So wait a bit before actually using it.

ckelley-air commented 5 years ago

Thank you! Will do!

u-fischer commented 5 years ago

I pushed a new version. The documentation describes how to use attributes. In short you must at first declare an attribute:

\tagpdfsetup
{
 newattribute = {TH-col} { <</Owner /Table /Scope /Column>> },
 newattribute = {TH-row} { <</Owner /Table /Scope /Row>> },
....
}

and then you can add one or more attributes with either attribute={TH-col,TH-row, ....} or attribute-class={TH-col,TH-row.,...} (the second variant adds a class) in the \tagpdfstructbegin argument.

u-fischer commented 5 years ago

Resolved with https://github.com/u-fischer/tagpdf/commit/64d8057660f105a6c973f4aadad40258777c7d5d