14

According to the PDF tagging project, I can tag graphics included using \includegraphics via the alt key. What about graphics generated with TikZ?

In general, what is the recommended approach to getting tagging for the cases where this cannot be automated? And where can I find documentation for these tagging commands? The tagpdf manual explicitly states that it is “not meant for direct use in (normal) documents”.

\DocumentMetadata{pdfstandard=A-2b,lang=en}

\documentclass{article}

\usepackage{graphicx, tikz}

\begin{document}

\includegraphics[alt={Example}]{example-image-a}

\bigskip

\begin{tikzpicture}
    \draw (0,0) circle (1cm);
\end{tikzpicture}

\end{document}
6
  • see github.com/pgf-tikz/pgf/issues/1370 Commented Jan 21, 2025 at 10:08
  • @DavidCarlisle And until this gets implemented in TikZ, are there any lower-level commands that I can use instead? Commented Jan 21, 2025 at 10:43
  • 6
    I wouldn't possibly dare answer while Ulrike might be watching, I guess she will provide a tick-worthy answer when she passes by:-) Commented Jan 21, 2025 at 10:48
  • 1
    @DavidCarlisle You are good at predicting the future! Commented Jan 21, 2025 at 11:16
  • @DavidCarlisle Nice of you to reward the answer, but what's the occasion? The answer is almost two months old. 😏 Commented Mar 8, 2025 at 19:28

1 Answer 1

13
+50

You are not activating tagging in your example, so the alt key does nothing sensible; be aware that tagging is always for the whole document, so you can not tag only one part!

In your example you could tag your graphic like this (you can use tagpdf commands, the package is no longer only an experiment but the core of the tagging code of LaTeX, but you should know what you are doing ...):

\DocumentMetadata{pdfstandard=A-2b,lang=en,testphase=latest} % latest key is new and needs latex-dev

\documentclass{article}

\usepackage{graphicx, tikz}

\begin{document}

\includegraphics[alt={Example}]{example-image-a}

\bigskip

\tagstructbegin{tag=Figure,alt=a circle}\tagmcbegin{}%
\SuspendTagging{tikz}%
\begin{tikzpicture}
    \draw (0,0) circle (1cm);
\end{tikzpicture}%
\par
\ResumeTagging{tikz}%
\tagmcend\tagstructend

\end{document}

It needs a bit fiddling to get the commands and their order right depending on if you are in a paragraph or not but generally it is not so hard. I do have a branch which automates that and which works reasonably well (and also adds a BBox which is missing here).

This is currently not in LaTeX oder LaTeX-dev as on one side I'm hoping for some better support on the tikz side (https://github.com/pgf-tikz/pgf/issues/1370) so that I can avoid too many patches.

The other problem is that I'm unsure how to handle examples like this:

Tomorrow is rubber ducky day 
\begin{tikzpicture}
\node[draw=red]{Don't forget this, see \ref{sec:drawing}!}
\end{tikzpicture}

\todonotes{Don't forget this, see \ref{sec:drawing}!}

\begin{picture}(20,10) %
\put(0,0){Don't forget this, see \ref{sec:drawing}!}
\end{picture}

In such case the pictures are not illustrations and they should not be tagged as Figure. Writing the correct tagging code is not so difficult, but how should the interfaces for users and package writer like todonotes look like?

\begin{tikzpicture}[tag-nodes-as-text] %?
\begin{tikzpicture}[tagging-recipe=text] %?

And what should happen if one node in the picture is such a text but other nodes not?

8
  • 4
    +1 for acting as predicted Commented Jan 21, 2025 at 11:26
  • And when will it not require latex-dev? Commented Jan 21, 2025 at 11:26
  • 1
    @Gaussler mostly the tagging code doesn't require latex-dev although obviously at times the -dev code is ahead of the main branch so best to use lualatex-dev for tagging unless there is a strong reason not to do so. Commented Jan 21, 2025 at 11:29
  • 1
    The latest key? At the next release. We just added that. In normal latex you have to use testphase= {phase-III,table,title,firstaid,math}, which is longer but does the same. Commented Jan 21, 2025 at 11:29
  • 2
    I suspend tagging before the paragraph, so I need to resume it after the paragraph to get symmetric tagging. Inside a paragraph the code would be slightly different: as I wrote these details need a bit fiddling. Commented Jan 21, 2025 at 12:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.