I'm making a command called \seal that uses the \includegraphics function. The command \seal has some key=value options of its own (color, beamer, trimz) and it must accept all options of \includegraphics so that it directly passes them to it. We may use \seal for a picture called theimage as follows:

\seal[width=2cm, color=red]{theimage}

which calls:


Although I want to use all options in \includegraphics, the following code does it well for the height and width options.

% Declaring options for "seal"
/seal/.is family, /seal,
% "seal" options
color/.estore in = \sealColor,
beamer/.estore in = \sealBeamer,
trimz/.estore in = \sealTrimz,
% "\includegraphics" options
height/.estore in = \sealHeight,
width/.estore in = \sealWidth,

% Declaring variables for the left side of "key=value"

% Declaring a command for storing the image

% Defining the \seal command
    \pgfkeys{/seal, #1}%
    % Makes the left side of "key=value" empty
    % if there's no value
    % The \includegraphics command
    % The other command (pay no attention to this)

The basic idea of this code is to make \seal[width=2cm, color=red]{theimage} call \includegraphics[width=2cm, =]{theimage}, and \seal[color=red]{theimage} call \includegraphics[=, =]{theimage}. This works because neither \includegraphics[width=2cm, =]{theimage} nor \includegraphics[=, =]{theimage} produce error messages. The last one is equivalent to calling \includegraphics[]{theimage}.

Now, although this code does the work very well, it returns two error messages when calling \seal[height=2cm]{theimage}:

Undefined control sequence. \seal[height=2cm]{theimage}
Package keyval Error: undefined. \seal[height=2cm]{theimage}

When calling \seal{theimage}, it returns the following messages repeated twice.

Undefined control sequence. \seal{theimage}
Package keyval Error: undefined. \seal{theimage}

I suppose this happens for the same reason that \includegraphics[\empty = \empty,]{theimage}, where \newcommand{\empty}{}, returns the following error message:

Package keyval Error: undefined. \includegraphics[\empty = \empty]{theimage}

Using an \ifthenelse command inside the (square) brackets of \includegraphics doesn't seem to work. It also seems to be mandatory that = be directly written inside the brackets, and not inside a command that is inside the brackets. I can think of the following strategies for addressing this problem:

  1. Devising a completely different approach for passing options from \seal to \includegraphics. Currently, I don't have a clue as to what that approach might be.
  2. Letting LaTeX know that this is not an error. Since I am new in LaTeX, I don't know how to do this. I also feel this cannot be a proper solution: if there is an error message something must be not in place. It could have actual consequences for the other options. However, I am open to be persuaded otherwise on this.
  3. Defining \seal so that it uses two brackets for key=value options: one for its own options and the other for the \includegraphics options. In this way, it will pass the whole string of one of those brackets to \includegraphics. In this case, we would call \seal[width=2cm][color=red]{theimage} instead of \seal[width=2cm, color=red]{theimage}. I think this might be the most straightforward solution. The first version of \seal was a command of the form \seal[includegraphicsOptions]{colorValue}{beamerValue}{trimzValue}{theimage}, which passed the whole includegraphicsOptions string to \includegraphics returning no error whatsoever. Nevertheless, I don't know how to define \seal so that it has two brackets and, although I more than welcome a solution along these lines, I consider it a bit sub-optimal to my taste. (I'm more likely to be persuaded otherwise on this one.)

But ultimately, I am here because I do not know how to properly address this. I hope someone can suggest a solution.

Note: The only packages I am using/requiring for this command are graphicx, pgfkeys and ifthenelse. (Also tikz, which is not important for this question, and optionally the class beamer.)

PS: I'm sorry I couldn't make this question shorter.


You can use the .unknown feature:


% Declaring options for "seal"
  /seal/.is family, /seal,
  % "seal" options
  color/.estore in = \sealColor,
  beamer/.estore in = \sealBeamer,
  trimz/.estore in = \sealTrimz,

% Defining the \seal command
  % The other command (pay no attention to this)



\seal[width=2cm, color=red]{theimage}



For inserting the image you issue \thesealimage, I guess in \othercommand.

With the definition in the example, you get

imagecommand=\includegraphics [,width=2cm]{theimage}


imagecommand=\includegraphics [,width=2cm,height=1cm]{theimage}
| improve this answer | |
  • Thanks, I'm studying your answer. – lfba Aug 26 '19 at 10:48
  • I tested your answer and it seems to be the right answer. Really thanks. I think I'll become a fan of the .unknown feature. – lfba Aug 26 '19 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.