Re: Support alt text in LaTeX output
David Carlisle <[email protected]> Sat, 25 Jul 2026 13:39:06 +0100
| Newsgroups | gmane.comp.tex.texinfo.bugs |
|---|---|
| Message-ID | <CAEW6iOjR9aXtiVCi9_Wb-pXf_EMw7hZnuAyazTjF5+54srEQNQ@mail.gmail.com> |
--00000000000028ca0b06576ec715 Content-Type: text/plain; charset="UTF-8" On Sat, 25 Jul 2026 at 13:19, Gavin Smith <[email protected]> wrote: > On Sat, Jul 25, 2026 at 08:58:35AM +0100, David Carlisle wrote: > > Sorry, replying to myself > > > > \makeatletter > > \providecommand\KV@Gin@alt{} > > \makeatother > > > > would be preferable to > > > > \makeatletter > > \define@key{Gin}{alt}{} > > \makeatother > > > > so that it only does something if alt processing is not already defined > > (otherwise the user would need to remove this if adding \DeclareMetada) > > > > David > > Thanks, it should be no problem to use this then and output the alt > information without any customization variable or option needing to be > added to texi2any. > > I looked at the documentation of the "graphicx" package (link at > https://ctan.org/pkg/graphicx?lang=en) and the manual does not appear to > contain the strings "providecommand" or "KV" anywhere. > \providecommand is a core latex definition command (that does nothing if the command is defined, otherwise is like \newcommand) see page 14 of https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/base/usrguide-historic.pdf (or texdoc usrguide-historic in a local tex installation) the \KV@Gin@alt macro is as you suggest the internal macro holding the definition of a defined alt key for the graphics package. "Gin" = "Graphics Inclusion" (although I'm not sure I ever wrote down anywhere it's just a unique prefix for the \includegraphics internals) The reason for patching at that level is that in current latex the default definition of the alt key is no-op but once tagging is enabled it is given a real definition, so here you need to "time" adding the no-op definition for old latex in a way that doesn't undo that patching. It is of course relying on internal definitions but as it is only needed at all for historic latex releases the internals are by definition fixed... > It would be good if we could reference some documentation explaining > why we use these commands. This could help people in the future coming > back to this code if they are wondering why it works. > > (Rant: In my experience I do not like seeing comments in source code like > "Information from David Carlisle, bug-texinfo 2026-07-26" - with people's > names. (We attribute in git commit messages and ChangeLog entries, but > reading these should be considered optional for future readers of the > code.) It doesn't actually add much useful information and actually makes > the code harder to modify - future hackers may think "If I change this am > I deleting some important historical information, or making the comment > incorrect?") > > I found references online to a "keyval" package. Would a comment like > the following be accurate? > yes keyval was written at same time as graphicx and distributed with it to add key=value parsing for latex2e, so it's part of the core latex release. > > "In the 'keyval' package, in "Gin" family, set "alt" to "", if not > already > set. This is used to support output of the "alt" attribute for images in > older versions of graphicx." > yes exactly. Or more explicitly you could say "This is used to provide a default no-ooperation definition of the alt key, so that it does not generate an error in older versions of graphicx" Incidentally rather than explicitly define \KV@Gin@alt you could use the form Ulrike suggested which is \usepackage{keyval} \makeatletter \define@key{alt}{} \makeatother \usepackage{graphicx} That similarly defines alt to do nothing without doing it after loading graphicx (which would undo the active definition for tagging case) But I think I'd use my version, with your description. David > That should give people enough pointers to research what keyval is and > how graphicx uses it. > --00000000000028ca0b06576ec715 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote g= mail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Sat, 25 Jul = 2026 at 13:19, Gavin Smith <<a href=3D"mailto:[email protected]">= [email protected]</a>> wrote:<br></div><blockquote class=3D"gmail= _quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204= ,204);padding-left:1ex">On Sat, Jul 25, 2026 at 08:58:35AM +0100, David Car= lisle wrote:<br> > Sorry, replying to myself<br> > <br> > \makeatletter<br> > \providecommand\KV@Gin@alt{}<br> > \makeatother<br> > <br> > would be preferable to<br> > <br> > \makeatletter<br> > \define@key{Gin}{alt}{}<br> > \makeatother<br> > <br> > so that it only does something if alt processing is not already define= d<br> > (otherwise the user would need to remove this if adding \DeclareMetada= )<br> > <br> > David<br> <br> Thanks, it should be no problem to use this then and output the alt<br> information without any customization variable or option needing to be<br> added to texi2any.<br> <br> I looked at the documentation of the "graphicx" package (link at<= br> <a href=3D"https://ctan.org/pkg/graphicx?lang=3Den" rel=3D"noreferrer" targ= et=3D"_blank">https://ctan.org/pkg/graphicx?lang=3Den</a>) and the manual d= oes not appear to<br> contain the strings "providecommand" or "KV" anywhere.<= br></blockquote><div><br></div><div>\providecommand is a core latex definit= ion command (that does nothing if the command is defined, otherwise is like= \newcommand) see page 14 of</div><div><br></div><div><a href=3D"https://mi= rror.ox.ac.uk/sites/ctan.org/macros/latex/base/usrguide-historic.pdf">https= ://mirror.ox.ac.uk/sites/ctan.org/macros/latex/base/usrguide-historic.pdf</= a></div><div><br></div><div>(or texdoc usrguide-historic=C2=A0 in a local t= ex installation)</div><div><br></div><div>the=C2=A0\KV@Gin@alt macro is as = you suggest the internal macro holding the definition of a defined alt key = for the graphics package. "Gin" =3D "Graphics Inclusion"= ; (although I'm not sure I ever wrote down anywhere it's just a uni= que prefix for the \includegraphics internals)</div><div><br></div><div><br= ></div><div>The reason for patching at that level is that in current latex = the default definition of the alt key is no-op but once tagging is enabled = it is given a real definition, so here you need to "time" adding = the no-op definition for old latex in a way that doesn't undo that patc= hing. It is of course relying on internal definitions but as it is only nee= ded at all for historic latex releases the internals are by definition fixe= d...</div><div><br></div><div><br></div><blockquote class=3D"gmail_quote" s= tyle=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pad= ding-left:1ex"> <br> It would be good if we could reference some documentation explaining<br> why we use these commands.=C2=A0 This could help people in the future comin= g<br> back to this code if they are wondering why it works.<br> <br> (Rant: In my experience I do not like seeing comments in source code like<b= r> "Information from David Carlisle, bug-texinfo 2026-07-26" - with = people's<br> names.=C2=A0 (We attribute in git commit messages and ChangeLog entries, bu= t<br> reading these should be considered optional for future readers of the<br> code.)=C2=A0 It doesn't actually add much useful information and actual= ly makes<br> the code harder to modify - future hackers may think "If I change this= am<br> I deleting some important historical information, or making the comment<br> incorrect?")<br> <br> I found references online to a "keyval" package.=C2=A0 Would a co= mment like<br> the following be accurate?<br></blockquote><div><br></div><div>yes keyval w= as written at same time as graphicx and distributed with it to add</div><di= v>key=3Dvalue parsing for latex2e, so it's part of the core latex relea= se.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin= :0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"= > <br> =C2=A0 "In the 'keyval' package, in "Gin" family, se= t "alt" to "", if not already<br> =C2=A0 set.=C2=A0 This is used to support output of the "alt" att= ribute for images in<br> =C2=A0 older versions of graphicx."<br></blockquote><div><br></div><di= v>yes exactly. Or more explicitly you could say=C2=A0</div><div><br></div><= div>"This is used to provide a default no-ooperation definition of the= alt key, so that it does not generate an error in older versions of graphi= cx"</div><div><br></div><div><br></div><div>Incidentally rather than e= xplicitly define \KV@Gin@alt=C2=A0 you could use the form Ulrike suggested = which is</div><div><br></div><div>\usepackage{keyval}</div><div>\makeatlett= er<br></div><div>\define@key{alt}{}</div><div>\makeatother<br></div><div>\u= sepackage{graphicx}</div><div><br></div><div>That similarly defines alt to = do nothing without doing it after loading graphicx (which would undo the ac= tive definition for tagging case)</div><div><br></div><div>But I think I= 9;d use my version, with your description.</div><div><br></div><div>David</= div><div><br></div><div><br></div><div><br></div><blockquote class=3D"gmail= _quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204= ,204);padding-left:1ex"> <br> That should give people enough pointers to research what keyval is and<br> how graphicx uses it.<br> </blockquote></div></div> --00000000000028ca0b06576ec715--