Re: Support alt text in LaTeX output

David Carlisle <[email protected]>
Newsgroups gmane.comp.tex.texinfo.bugs
Message-ID <CAEW6iOhZ2X6YCUx0RsD5gCJiLU4O3-moJ9cNTncxnYzXMBkJQw@mail.gmail.com>
On Wed, 5 Aug 2026 at 08:50, Patrice Dumas <[email protected]> wrote:

> On Sat, Jul 25, 2026 at 08:46:56PM +0100, David Carlisle wrote:
> > the pdftitle and  alt text in includegraphics in the end have to be a PDF
> > encoded string with no markup, so
> > over the years latex has got better at "cleaning up text" basically now
> any
> > unicode text should work, the only characters that you need to quote are
> %
> > { }
>
> Seems like _ needs to be quoted too.  Maybe general text protection
> needs to be done, so also protecting $#, or even ~.
>

_ does not need to be quoted as you are making a string not typesetting

\DocumentMetadata{tagging=on}
\documentclass{article}

\usepackage{graphicx}

\begin{document}

\includegraphics[alt={some_underscore_text worth 50$}]{example-image}

\end{document}



runs without error giving the expected alt text on the figure

     <Figure xmlns="http://iso.org/pdf2/ssn"
        id="ID.08"
        alt="some_underscore_text worth 50$"
        xmlns:Layout="http://iso.org/pdf/ssn/Layout"
        Layout:BBox="{ 148.71233, 427.19861, 468.71155, 667.19801 }"
       >

 although if the string may be used in multiple contexts so might be
typeset as well as being used as a pdf string
and you want to be safe it's OK to quote them

\includegraphics[alt={some\_underscore\_text worth 50\$}]{example-image}

produces the same output here.



> --
> Pat
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.