# The graphicx package [closed]

The following may interest the LaTeX3 Team, but I would first like to hear the views of other people (especially that I haven't followed every line of implementation of graphicx).

The following function in the graphicx package has two points of worry, in my experience and view, anyway:

1. The local group found in it is perhaps meant to localize the contents of \toks0, but this can slow down \setkeys if xkeyval's \setkeys is used, which is often the case these days.

2. The contents of \toks0 may change (if by a novice programmer) from the time it is built in this macro and the time it is invoked later (after \setkeys). Another token register (or macro) would have been preferred. Moreover, the conditional in this macro is left open for too long, in my view, and TeX has to keep track of it. Because of pointers and possible re-entrance, xkeyval's \setkeys can be quite expensive.

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

-
I'm not sure I understand the concern. Why is \setkeys enough slower inside one group more to worry about? Where do you see \toks@ getting used incorrectly? Are you thinking that it could be misused in \setkeys somewhere? Can you give an example of the issue? Which conditional are you seeing here? The only thing related I see is \@tempswafalse which should just \let\if@tempswa\iffalse inside the group. – TH. Mar 18 '11 at 21:36
Um, where is the question here? – Joseph Wright Mar 18 '11 at 22:13
This code was written many years ago, and is unlikely to alter unless there is a clear bug. A bug is not likely to include 'a third-party package might behave badly and mess things up'. Getting any change to the core LaTeX2e stuff is very hard. – Joseph Wright Mar 18 '11 at 22:35
@Ahmed: Why don't you enlighten me. For example, explain what problems your version avoids. The only thing I see is what I mentioned before about \setkeys and then likely only if someone defines a new key via \define@key that uses \toks@ not in a group. – TH. Mar 19 '11 at 1:59
Please direct discussion of this kind to the latex-l mailing list. I don't think this site is the best place for it. – Will Robertson Mar 19 '11 at 4:07

## closed as not a real question by Will Robertson, lockstep, Matthew Leingang, Hendrik Vogt, CaramdirMar 19 '11 at 17:56

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

I had many gripes with xkeyval (see CTT among others). In the end I have reverted back to the original definition.

\def\origsetkeys#1#2{%    Original def
\def\KV@prefix{KV@#1@}%
\let\@tempc\relax
\KV@do#2,\relax,}

\def\Gin@ii[#1]#2{%
\def\@tempa{[}\def\@tempb{#2}%
\ifx\@tempa\@tempb
\def\@tempa{\Gin@iii[#1][}%
\expandafter\@tempa
\else
\begingroup
\@tempswafalse
\toks@{\Ginclude@graphics{#2}}%
\origsetkeys{Gin}{#1}%<----------
\Gin@esetsize
\the\toks@
\endgroup
\fi}

-
 Xkeyval is better than it used to be in this respect -- I remember talking about this with you years ago. I finally convinced Morten to write a patch that allowed this behaviour. – Will Robertson Mar 19 '11 at 4:06 @Will: Thanks, I did not know about that patch. I will revisit xkeyval again, because it is a very usefull package. – Danie Els Mar 19 '11 at 4:18

I have been using the following patch:

\newcommand*\@pdf@strcmp[2]{%
\@nameuse{@\ifnum\pdfstrcmp{\detokenize{#1}}%
{\detokenize{#2}}=\z@ first\else second\fi oftwo}%
}
\def\Gin@ii[#1]#2{%
\@pdf@strcmp[{#2}{%
\Gin@iii[#1][%
}{%
\begingroup
\@tempswafalse
\toks@{\Ginclude@graphics{#2}}%
\setkeys{Gin}{#1}%
\Gin@esetsize
\the\toks@
\endgroup
}%
}

-
This needs e-TeX - no good for graphicx, which only requires TeX82 (as for most of the LaTeX required and tools stuff). – Joseph Wright Mar 18 '11 at 22:33
Actually, it requires pdfTeX of a sufficiently new version: this won't work as-written with either XeTeX or LuaTeX, and will break with relatively-recent XeTeX versions (which don't have \strcmp). – Joseph Wright Mar 18 '11 at 22:47
@Joseph: As you know very well, we can avoid the use of pdfTeX here without difficulty but to the same effect. My concern comes from a personal experience. That was what took me into the code for graphicx. Eg, \@tempswa and \toks0 are used often by many codes and packages without being restricted to local groups. Relying on their previous states after setting keys is not, in my opinion, very safe. However, as suggested earlier, this is perhaps not the right place for this discussion. – Ahmed Musa Mar 21 '11 at 21:42