Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\includegraphics comma in alt key using xkeyval #1652

Open
lstonys opened this issue Feb 4, 2025 · 11 comments
Open

\includegraphics comma in alt key using xkeyval #1652

lstonys opened this issue Feb 4, 2025 · 11 comments

Comments

@lstonys
Copy link

lstonys commented Feb 4, 2025

Brief outline of the bug

xkeyval package redefines \setkeys and then it breaks \includegraphics alt key having comma inside. Image is not shown.
If I run \setkeys{Gin}{alt={Alternative, text for image.}} outside of \includegraphics I can get alt text.
graphicx loads keyval so maybe it could copy \setkeys and use it inside \includegraphics to be sure that other packages will not spoil this command:

...
\RequirePackage{keyval,graphics}
\let\keyval@setkeys\setkeys
...
\def\Gin@ii[#1]#2{%
       ...
       %\setkeys{Gin}{#1}%
       \keyval@setkeys{Gin}{#1}%
       ...
     \fi}
\long\def\Grot@box@kv[#1]#2#3{%
     ...
    %\setkeys{Grot}{#1}%
    \keyval@setkeys{Grot}{#1}%
    ...
  \@end@tempboxa}
...

Minimal example showing the bug

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}
\usepackage{graphicx}
\usepackage{xkeyval}

\makeatletter
\define@key{Gin}{alt}{\def\MyText{#1}}
\makeatother

\begin{document}
\setkeys{Gin}{alt={Alternative, text for image.}}
\show\MyText

\includegraphics[alt={Alternative, text for image.}]{hand}
\end{document}
@josephwright
Copy link
Member

If reproducible, this would be a bug in a third-party piece of code: as such, it should be reported to the appropriate maintainer. This is flagged up by latexbug.

@josephwright josephwright closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2025
@lstonys
Copy link
Author

lstonys commented Feb 4, 2025

I see that other issues for graphicx was written here in this repository so I just have a suggestion for @davidcarlisle how to make graphicx it a bit safer.

@davidcarlisle
Copy link
Member

@lstonys This is the correct repository for graphicx issues but as the latexbug log would have warned you, you should make an example not using third party packages. In this case, keyval was written at the same time as graphicx and explicitly extracted to a separate package to make the code shareable. It can not be right to copy small fragments back 30 years later because some contributed package breaks the code. The core code would become unmaintainable if we adopted a policy of working around such bugs. Please report this to the maintainer of xkeyval

@u-fischer
Copy link
Member

I think that is something that could be fixed in graphicx. It uses \toks@ to store \Ginclude@graphics{#2} and then calls \setkeys which somewhere changes \toks@.

If I use a dedicated toks register, the document compiles as expected:

\documentclass{article}

\usepackage{xkeyval}
\usepackage{graphicx}

\begin{document}

\makeatletter
\newtoks\Gin@toks@

\def\Gin@ii[#1]#2{%
    \def\@tempa{[}\def\@tempb{#2}%
    \ifx\@tempa\@tempb
      \def\@tempa{\Gin@iii[#1][}%
      \expandafter\@tempa
    \else
     \begingroup
       \@tempswafalse
       \Gin@toks@{\Ginclude@graphics{#2}}%
       \setkeys{Gin}{#1}%
       \Gin@esetsize
       \the\Gin@toks@
     \endgroup
     \fi}
\makeatother     
\includegraphics[alt={blub,blub}]{hand}

\end{document}

@lstonys Unreladed but be aware that the tagging code (re)defines the alt-key to set alternative text, so please do not overwrite it when tagging is active.

@lstonys
Copy link
Author

lstonys commented Feb 4, 2025

@u-fischer, I was adding alt-text to tagged pdf that's why I got this bug

@davidcarlisle
Copy link
Member

@u-fischer arguably true, but you'd have to change the register everywhere not just there \Gin@resize, the scale and other keys, also epsfig package. I worry something would break, it would seem safer to assert that \toks@ is part of the interface here.

@u-fischer
Copy link
Member

@davidcarlisle well yes, but I don't think we can leave it as it is. It wouldn't be good if with tagging graphics suddenly disappear. Something like this seems to fix at least this issue, so perhaps we should add an firstaid?

\documentclass{article}
\usepackage{xkeyval}
\usepackage{graphicx}

\begin{document}

\makeatletter
\newtoks\XKV@TEMPFIX@toks
\def\@s@lective@sanitize[#1]#2#3{%
  \begingroup
    \count@#1\relax\advance\count@\@ne
    \XKV@toks\expandafter{#3}%
    \def#3{#2}\@onelevel@sanitize#3%
    \edef#3{{#3}{\the\XKV@toks}}%
    \expandafter\@s@l@ctive@sanitize\expandafter#3#3%
    \expandafter\XKV@tempa@toks\expandafter{#3}%
  \expandafter\endgroup\expandafter\XKV@TEMPFIX@toks\expandafter{\the\XKV@tempa@toks}%
  \edef#3{\the\XKV@TEMPFIX@toks}%
}
\makeatother     

\makeatletter
\includegraphics[alt={blub,blub}]{hand}

\end{document}

@davidcarlisle
Copy link
Member

I've re-opened.

This should be fixed in\xkeyval (to not change \toks@) but as @u-fischer says we could change (all uses of) \toks@ in graphics to a declared register, if that doesn't break other contrib packages, to be checked....

@lstonys
Copy link
Author

lstonys commented Feb 25, 2025

Maybe you already have any solution?

@davidcarlisle
Copy link
Member

@lstonys there are solutions in the comments above which we may add but fundamentally this is a xkeyval issue, did you report it there?

@lstonys
Copy link
Author

lstonys commented Feb 25, 2025

No, I couldn't find Hendri Adriaens email.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants