Pass named arguments to macro

A slightly modified interface via the definition

\newcommand{\happygraphics}[2][,]{%
  \includegraphics[width=50,height=25,trim=1 2 3 4,clip,#1]{#2}}%

would allow to add options as needed to \happygraphics[<options>]{<file>}.

A similar interface is provided through xparse:

\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentCommand{\happygraphics}{O{,} m}{%
  \includegraphics[width=50,height=25,trim=1 2 3 4,clip,#1]{#2}}%

The above takes advantage of supplying empty (default) key-values as ,.

Since the key-value interface is comfortable with supplying empty options (or consecutive commas ,,,...), there's no need for extra testing of the existence of an optional argument. Unless, of course, you want to do more based on whether or not the use supplied an optional argument.


You don't need to define a new top level command, if you execute

\setkeys{Gin}{width=50,height=25,trim=1 2 3 4,clip}

then those keys will be automatically set for all \includegraphics in the scope of the \setkeys declaration.