Typevia
Accessibility and Modern Features

Understanding Tagged PDFs in LaTeX

In the digital age, a document is more than just words on a page; it is data that needs to be understood by machines. A Tagged PDF contains hidden metadata that describes the logical structure and order of the document's content.

For a sighted user, a bold, large font at the top of a page is clearly a "Heading." However, for a screen reader used by someone with a visual impairment, that text is just another string of characters unless it is "tagged" as a header. Tagging is the foundation of digital accessibility, ensuring your documents are compliant with standards like PDF/UA (Universal Accessibility) and Section 508.

In this guide, we will explore how the LaTeX ecosystem has evolved to make creating tagged PDFs easier than ever before.


The New Era of LaTeX Accessibility

Historically, creating tagged PDFs in LaTeX was a complex, manual task requiring deep technical knowledge. However, the LaTeX Project team has recently introduced a "tagging project" that automates much of this process.

To follow this guide, you should ensure your LaTeX distribution (like TeX Live or MikTeX) is updated to a version from 2023 or later. The modern approach uses the \DocumentMetadata command, which must be placed at the very beginning of your file.

Why Tag Your PDF?

  1. Accessibility: Allows screen readers to navigate headings, read lists correctly, and describe images.
  2. Reflow: Enables mobile PDF viewers to reformat text to fit small screens.
  3. Search Engine Optimization (SEO): Helps search engines understand the hierarchy of your content.
  4. Archiving: Ensures long-term readability and structure.

Initializing a Tagged Document

The most critical step in creating a tagged PDF is the initialization. Unlike other LaTeX commands that go in the "preamble" (between \documentclass and \begin{document}), the accessibility settings must be declared before the \documentclass.

Basic Syntax

To enable the automated tagging features currently being developed by the LaTeX team, use the following structure:

\DocumentMetadata{
  testphase = {phase-III,table},
  uncompress
}
\documentclass{article}

\begin{document}
Hello, this is a tagged PDF!
\end{document}

Explanation of keys:

  • testphase = {phase-III}: This activates the latest automated tagging features for headings, paragraphs, and basic structure.
  • table: This specifically enables tagging for tabular environments (which are historically difficult to tag).
  • uncompress: While not strictly required for the final version, this makes the PDF code human-readable for debugging purposes.

Note: Because these features are part of an ongoing project (the "testphase"), you may notice subtle changes in updates. Always check the documentation for the tagpdf package if you encounter errors after updating your LaTeX distribution.


Adding Document Metadata

A tagged PDF should also include metadata like the title and author in the file's internal properties. This allows screen readers to announce the document name immediately upon opening.

We can expand the \DocumentMetadata command or use the hyperref package to handle this.

\DocumentMetadata{
  testphase = {phase-III},
  pdfstandard = A-2u, % Ensures PDF/A compliance
  lang = en-US        % Sets the base language for screen readers
}
\documentclass{article}
\usepackage{hyperref}

\hypersetup{
    pdftitle={A Beginner's Guide to Tagged PDFs},
    pdfauthor={Jane Doe},
    pdfsubject={LaTeX Accessibility},
    pdfkeywords={LaTeX, Tagging, PDF/UA, Accessibility}
}

\begin{document}
\maketitle
\section{Introduction}
This document is structured and contains metadata.
\end{document}

Structural Elements and Alt Text

For a PDF to be truly accessible, every structural element must be identified correctly. This includes headings, lists, and—most importantly—images.

Headings and Lists

When using testphase={phase-III}, LaTeX automatically tags your \section, \subsection, and enumerate or itemize environments. To maintain accessibility, never skip heading levels (e.g., don't jump from \section to \subsubsection).

Tagging Images with Alt Text

Images are "invisible" to screen readers. You must provide Alternative Text (Alt Text) to describe the content of the image. The modern accessibility phase allows you to add this directly to the \caption or via specific keys.

Currently, the most robust way to handle this is by using the tagpdf or graphicspath integration, but for beginners, the focus is on ensuring the description is available.

\begin{figure}[ht]
    \centering
    % The 'alt' key is being integrated into the standard graphics package
    \includegraphics[width=0.5\textwidth]{chart.png}
    \caption{Growth of LaTeX users over time. (Alt: A line graph showing a 20\% annual increase in LaTeX adoption from 2010 to 2024.)}
\end{figure}

Warning: Avoid using "Image of" or "Picture of" in your alt text. Screen readers already announce that the element is a graphic. Start directly with the description.


Creating Accessible Tables

Tables are one of the most significant challenges in PDF accessibility. A screen reader needs to know which cells are "Headers" (the top row) and which are "Data."

By using testphase={table} in your \DocumentMetadata, LaTeX begins the process of identifying these structures automatically.

\DocumentMetadata{testphase={phase-III,table}}
\documentclass{article}
\begin{document}

\section{Data Overview}
\begin{tabular}{|l|c|}
  \hline
  \textbf{Software} & \textbf{Ease of Use} \\ \hline
  LaTeX            & Moderate             \\
  Word             & High                 \\ \hline
\end{tabular}

\end{document}

Best Practices for Tables:

  • Keep tables simple. Avoid merged cells (\multicolumn or \multirow) whenever possible, as they often break the logical reading order for screen readers.
  • Always use the \textbf command for header rows to help the tagging engine identify them.

Common Pitfalls and Best Practices

Creating a perfectly tagged PDF is a journey. Here are some common mistakes to avoid:

  1. Using \\ for New Paragraphs: Never use the double backslash to start a new paragraph. Always use a blank line. The \\ command is for line breaks within a structure, while a blank line creates a proper <P> (Paragraph) tag.
  2. Floating Elements: Be careful with figures that "float" too far from their reference in the text. A screen reader reads the PDF in the order the elements appear in the code.
  3. Color Contrast: While not strictly a "tagging" issue, accessibility includes visibility. Ensure your text has a high contrast ratio against the background.
  4. Mathematical Formulas: Complex math is still a work in progress for automated tagging. For now, ensure your document has a clear text description of critical equations if they are central to the document's meaning.

Testing Your Tagged PDF

After compiling your document, you should verify if the tags are present:

  • Adobe Acrobat Pro: Use the "Accessibility Check" tool.
  • VeraPDF: An open-source tool for checking PDF/A and tagging standards.
  • Screen Readers: Use NVDA (Windows, free) or VoiceOver (macOS) to "listen" to your document and ensure the reading order makes sense.

Summary Checklist

  • Place \DocumentMetadata before \documentclass.
  • Set the document language (e.g., lang=en-US).
  • Use testphase={phase-III} to automate tagging.
  • Include a Title and Author via hyperref.
  • Use logical heading levels (don't skip \subsection).
  • Provide descriptive text for all figures.