# Revisiting producing structured PDFs from LaTeX

I am trying to produce a structured or 'tagged' PDF from pdftex (Tex Live 2013) that passes automated tests in Adobe Acrobat for tagging. These tests are the de facto indicator for a document accessibility, which are often required by universities, government agencies and others worldwide for published documents.

To test a document for accessibility / tagging, try this:

1. Open the PDF in Acrobat Reader
2. 'file -> 'document properties' -> 'Description'
3. under 'advanced', you'll see a field, 'tagged pdf'. Ideally it should say 'yes'. But it doesn't :(

Question: does anyone know of any way to create a PDF which passes Acrobat's 'Tagged PDF' test directly from LaTeX?

The ideal solution would be a package or two that can be called from the preamble of a latex document. I want something that is very low effort for the author, and can thus be very easily integrated with existing workflows.

Note: There has been discussion about this in the past (see tags and links on the right), but as of May 2014, there was no clear solution to this. Much of the existing discussion is from 2012 or earlier (see How to create tagged PDF?), and so I'd like to see if we can kick-start this discussion.

Why this isn't a duplicate question: When I first posted this question in July 2013, it was flagged as a duplicate of a question from 2010. The answer references a presentation given at at TUG 2010. That presentation basically says "we're working on it", and is not an answer that allows me to implement a solution.

Because it is now 2014, I think it reasonable to expect that:

1. There have been new developments in this field through new packages or updates to core LaTeX
2. Attempting to comply with Section 508 will have required that people figure out solutions. This is a relatively recent requirement and so solutions may have changed since 2010
3. The software that is typically used to judge compliance (Adobe Acrobat) has changed several times since the question was not answered
4. Packages that address accessibility have been proposed but not come in to widespread use or even disappeared (e.g. the accessibility package, http://www.babs.gmxhome.de/da_ergeb.htm), and it is therefore reasonable to revisit this issue with fresh eyes.
-
–  Werner Jul 16 '13 at 19:34
I can't recall any details, but there was some discussion about it on the ConTeXt mailing list - try searching its archives. How much are you attached to LaTeX? ConTeXt might be a better choice especially in non-academic setting. –  mbork Jul 16 '13 at 19:34
@Werner - thank you, very relevant, but from 2009, and it includes this comment: "This kind of coding, directly in pdfTEX primitives, is really only useful for testing and “proof of concept” examples". I was hoping that there would be a 2013 version of this called "How to produce ADA-compliant documents from LaTeX"... –  Andy Clifton Jul 16 '13 at 19:38
@LostBrit: There is not much new; certainly no working solution. There is a german computer science masters thesis from ca. 2007 which shows a fairly complete solution; some german people are looking into it. But no developer has stepped forward as of now. –  Martin Schröder Jul 22 '13 at 9:27
@MartinSchröder: Do you mean the accessibility package? That's available again at babs.gmxhome.de/download/da_pdftex/accessibility.sty with (german) documentation at babs.gmxhome.de/download/da_pdftex/dok_pdf.pdf. This is the closest thing I've seen to a solution (single package, transparent to authors and passes most of the PDF tests). I'm going to put some time into that as a possible solution. I understand that the package has also been submitted to CTAN, so there might be a "formal", licensed, release as well. –  Andy Clifton Aug 13 '13 at 20:20

## Experience with the Accessibility Package

I downloaded the accessibility style from Babette Schalitz's website. From emails I understand that she was going to post this at CTAN.org with a public license, so I think this should be "fair use".

Using \usepackage[tagged]{accessibility} in my preamble allowed me you to generate a basic tagged PDF file that passes tests in Adobe Acrobat. However, the package didn't work when I needed to use roman numerals for your first page. This error seems to be because accessibility uses displayed page numbers to build the document tag structure.

## Updating the Accessibility Package

To fix the numbering problem I added the count1to package and replaced a few of the \pageref with \count1 in accessibility.sty. I've called this modified file accessibility_meta.sty for now, and posted it to GitHub. The package now seems to compile both articles and reports, and the output shows up as "tagged" in Acrobat.

Make sure that \usepackage[tagged]{accessibility} or \usepackage[tagged]{accessibility_meta} are pretty much the last thing in your preamble. In the event of a 'tex counter overflow, try commenting out various bits of your code. I've found that the tagging blows up quite regularly, especially with complex documents. Compile the document several times so that the page numbering and position of text or floats settles down, and the tags are properly generated.

## Other Steps

I've also taken the steps that nbdb suggested:

2. Adding \pdfinterwordspaceon to the preamble to fix the loss of inter word spacing in text (requires TexLive-2014).
3. Adding the cmap package to fix mapping characters to unicode.

## Testing and Feedback

I produced a test PDF using TexLive 2014, the cmap package, \ pdfinterwordspaceon, and the modified accessibility class. This seems to be "tagged". The PDF is available here.

Because I don't work with tagged documents on a regular basis it's highly likely I may not be doing a detailed enough test of the resulting document. I'd be keen to know if this PDF passes pre-flight testing in Acrobat, and if the modified accessibility.sty file works on other documents. I'm particularly interested in feedback from anyone who deals with tagged publications professionally.

Babette Schalitz deserves all of the credit for having produced the original accessibility.sty class. I would not have had a chance without her work.

-
This is very interesing. However have you checked the resulting PDF with Acrobat Pro for accessibility? There are lots of errors. Most are due to not correctly mapping the characters to unicode, which can probably be overcome by using the cmap package. The biggest hurdle however is the lack of spaces. Text within tags looks like: <paragraph>"Mostareduetonotcorrectlymapping...</paragraph> –  ndbd Aug 5 '14 at 17:01
@ndbd thanks for the comments. This is exactly the kind of feedback I need. I don't have any experience of looking at PDFs from a publisher's perspective, and it wouldn't have occurred to me to look for this. –  Andy Clifton Aug 5 '14 at 17:06
I just checked and in the new TexLive 2014, there seems to be a new command \pdfinterwordspaceon, which does exactly this. Hadn't had time to tinker with yet, though –  ndbd Aug 5 '14 at 17:08

This question has a lot of votes, but hasn't received an answer. So I am giving a ConTeXt solution. To create a tagged pdf, simply add:

\setuptagging[state=start]


at the top of your document. For example:

\setuptagging[state=start]

\starttext
\startsection
[title={A section title}]
\input ward
\stopsection
\stoptext


Then, pdfinfo test.pdf gives:

Title:          test
Creator:        ConTeXt - 2014.04.24 09:39
Producer:       LuaTeX-0.79.1
CreationDate:   Fri May 30 11:58:32 2014
ModDate:        Fri May 30 11:58:32 2014
Tagged:         yes
Form:           none
Pages:          1
Encrypted:      no
Page size:      595.276 x 841.89 pts (A4)
Page rot:       0
File size:      10992 bytes
Optimized:      no