[texhax] passing arguments as a delimited list

Joseph Wright joseph.wright at morningstar2.co.uk
Sun Apr 12 15:05:41 CEST 2009


Yo Sato wrote:
> Hi all,
>
> I wonder if any of you knows how to implement (if this is possible) a
> TeX or LaTeX macro that passes multiple (optional) arguments as a
> single list (with delimiters), i.e. as executable as below
>
> \somecommand[item1, item2, item3,...]{...}
>
> As I see this style a lot for class specification (e.g.
> \documentclass[a4paper,draft]{article}), I shouldn't think why this is
> not possible for macros. So far however I can't find how to do this in
> a documentation, although there are discussions on how to 'increase'
> the number of arguments with keyval package etc. What I'd rather is a
> listed single argument, whether optional or obligatory, as it is
> cleaner and structurable.
>
> Any advice???

Hello Yo,

If you simply want to parse a comma-separated list then the internal
macro \@for should help.

\documentclass{article}
\makeatletter
\newcommand*{\MyMacro}[2][]{%
  \@for\my at temp:=#1\do{%
    Option seen: \my at temp \\
  }%
  Main argument: #2
}
\makeatother
\begin{document}
\MyMacro[option1,option2,option3]{Content}
\end{document}

You can of course do what you like with the temporary variable (in this
case \my at temp).
-- 
Joseph Wright


More information about the texhax mailing list