[Tex/LaTex] How to pass optional arguments to command

argumentsmacrosoptional arguments

I'm trying to write my own command that wraps the \VerbatimInput command. I'd like my command to take optional arguments (those given inside [...]) and pass those directly to \VerbatimInput[...]. Of course, if the optional arguments to my command are not given, then nothing should be passed to \VerbatimInput.

How can I do this? I'm a relative novice to creating custom commands in LaTeX.

Best Answer

If a macro argument is supposed to be a set of key-value pairs, making use of standard packages to the purpose (keyval, xkeyval and others), it is generally harmless to pass it the empty list.

So

\newcommand{\foo}[2][]{%
  <actions to be performed before>%
  \VerbatimInput[#1]{#2}%
  <actions to be performed after>%
}

is the method you're looking for, because fancyvrb does use keyval.

Related Question