From the documentation of the graphicx
package:
Most of the
keyval
keys used in thegraphicx
package may also be set using the command\setkeys
provided by thekeyval
package.For instance, suppose you wanted all the files to be included in the current document to be scaled to 75% of the width of the lines of text, then one could issue the following command:
\setkeys{Gin}{width=0.75\textwidth}
Here
‘Gin’
is the name used for thekeyval
keys associated with ‘Graphics inclusion’. All following\includegraphics
commands (within the same group or environment) will act as if[width=0.75\textwidth]
had been specified, in addition to any other key settings actually given in the optional argument.
I am trying to use this to create an argument that accepts keys using the pgfkeys
package and passes the ones it does not recognize on to an \includegraphics
command. Here's a toy working example:
\documentclass[convert]{standalone}
\usepackage{graphicx,pgfkeys}
\newcommand{\mykeyset}[1]{\pgfqkeys{/me}{#1}}
\mykeyset{graphic options/.code={}}
\mykeyset{set graphic option/.style={graphic options/.append code=#1}}
%Set up a handler for unknown keys
\mykeyset{.unknown/.code = %
{%
\edef\unknownkey{\pgfkeyscurrentname}%
\mykeyset{set graphic option/.expand once = {\expandafter\setkeys\expandafter{\expandafter G\expandafter i\expandafter n\expandafter}\expandafter{\unknownkey=#1}}}%
}%
}
\newcommand{\myincludegraphics}[2][]{\begingroup%
\mykeyset{#1}%
\mykeyset{graphic options}%
\includegraphics{#2}%
\endgroup%
}
\begin{document}
\myincludegraphics[width = 5cm, height = 8cm]{example-image}
\myincludegraphics[scale=0.5]{example-image}
\myincludegraphics{example-image}
\end{document}
with output
Note that this works for the width
and height
keys, but that not for the scale
key. This is not a problem in itself--I have a method for handling the scale
key separately--but I would like to know which other keys require special treatment. Hence, my question:
Which keys to the \includegraphics
command cannot be set globally?
scale
seems to be set and required on-the-fly. Same goes forangle
...