Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\somecommanddefinedbynewcommand[value1][value2]{value3}

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

\newcommand{\centeredfigure}[4]{
  \begin{figure}[htbp] 
    \begin{center} 
      \includegraphics[width=#1\textwidth]{#2} 
      \caption{#3} 
      \label{#4}
    \end{center} 
  \end{figure}
}
share|improve this question
    
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) –  David Carlisle Jul 5 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. –  David Carlisle Jul 5 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. –  nrs Jul 5 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. –  David Carlisle Jul 5 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. –  nrs Jul 5 at 14:41

1 Answer 1

up vote 11 down vote accepted

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.

share|improve this answer
4  
Oh.. My.. God.. You are the author of the package. I just love this site so much. –  nrs Jul 5 at 14:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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