I want to define a macro to insert pictures in figures, called \centeredfigure, which I am hoping to use the same way as \includegraphics. In \includegraphics, all optional arguments are given in the form

\includegraphics[scale=, width=, height=, ...]{path_to_graphics}

What I want to define is is:

\centeredfigure[scale=, width=, height=, caption=, ref=, placing=]{path_to_graphics}

In contrast, the optional argument functionality LateX's \newcommand provides is like this:


So \newcommand cannot be used to obtain what I want.

I have previously defined plain TeX macros before, but none with optional arguments of such kind. I am currently looking at the definition of \includegraphics defined in combinedgraphics.sty and am a bit baffled. I am trying to discover an underlying pattern. I would appreciate any help, like a minimal example that demonstrates a single optional argument.

The macro is going to be used in LaTeX, but is going to be defined plain TeX style.

Edit - the original macro using \newcommand

  • do you want a plain tex macro or latex, your title and tag is plain but your examples use \includegraphics which is latex (but can be loaded into plain) Commented Jul 5, 2014 at 14:30
  • the key=val syntax as used in graphicx is defined in the keyval package which can be used with plain tex (although there are later packages such as xkeyva, l3keys and pgf with similar syntax) you can also load graphicx into plain, using the miniltx macros for plain tex. Commented Jul 5, 2014 at 14:34
  • It will be used in LaTeX, but the definition style is plain TeX, that is why I said plain TeX, sorry about the confusion.
    – osolmaz
    Commented Jul 5, 2014 at 14:36
  • why do you want a "definition style" like plain if you are not using plain? why not simply use \includegraphics (or add additional keys to \includegraphics as adjustbox does, your question is totally unclear. plain tex is a completely different format to latex. Commented Jul 5, 2014 at 14:38
  • The \includegraphics used in the macro will be embedded in a figure environment, also with a caption and reference, which will all be passed using optional arguments of the macro.
    – osolmaz
    Commented Jul 5, 2014 at 14:41

1 Answer 1


The [a=b] syntax used by graphicx package is defined by the keyval package which you can use to define similar commands. (xkeyval, pstricks, pgf, l3keys aslo define similar argument parsers, but it probably makes sense to use keyval if you want to fit in with graphix. See texdoc keyval for more details.

  • 4
    Oh.. My.. God.. You are the author of the package. I just love this site so much.
    – osolmaz
    Commented Jul 5, 2014 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .