How to define a comma separated list of arguments for includegraphics
Just define new keys:
\documentclass{article}
\usepackage{graphicx}
\makeatletter
\define@key{Gin}{settingsA}[]{\setkeys{Gin}{width=\textwidth, angle=90}}
\define@key{Gin}{settingsB}[]{\setkeys{Gin}{page=1, scale=.1}}
\define@key{Gin}{settingsC}[]{\setkeys{Gin}{angle=-90, scale=.5}}
\makeatother
\begin{document}
\includegraphics[settingsA]{example-image-a}
\includegraphics[settingsB]{example-image-b}
\includegraphics[settingsC]{example-image-c}
\end{document}
A bit of explanation. The graphicx
package relies on keyval
provided key-value syntax and reserves Gin
(Graphic inclusion) as the family name of the keys for \includegraphics
. A new key is simply added by
\define@key{Gin}{<name>}[<default value>]{<code>}
The \includegraphics[<options>]{file}
command will do
\setkeys{Gin}{<options>}
and every known key will be processed. The default empty value given for settingsA
and so on is so that you can simply type settingsA
without =something
.
One could even improve it; say that in settingsC
you want to be able to vary the angle; with
\define@key{Gin}{settingsC}[-90]{\setkeys{Gin}{angle=#1, scale=.5}}
you can specify settingsC
for the angle to be -90
or
settingsC=45
for the angle to be 45
.
Caveat Be sure not to define an already existing key: \define@key
would silently overwrite it.
Make your own include graphics command. Something like the following:
\newcommand\myincludegraphics[2]{%%
\expandafter\includegraphics\expandafter[#1]{#2}}
The problem with your code is that in the construction
\includegraphics[\settingsA]{filehandle}
The unexpanded \settingsA
is getting passed to the key parser where it will fail to match any keys. By using the above command, you can write something like,
\myincludegraphics{\settingsA}{filehandle}
By using \expandafter
, \settingsA
will be expanded by the time \includegraphics
has a chance to pass the optional arguments to its parser.