[texhax] passing arguments as a delimited list

Uwe Lück uwe.lueck at web.de
Mon Apr 13 21:54:55 CEST 2009


At 19:19 13.04.09, Yo Sato wrote:
 > Hi Joseph, Thanks for your response, which is very useful.
 > But as it happens it's not quite what I wanted.
 > I'd rather apply different actions on the items in a list,
 > or pass them to different commands or different arguments of a command.

Just making clear that this works along Joseph's lines:

     \newcommand{\MyMacro}[2][]{%
         \@for\my at temp:=#1\do{%
             \@usename{MyMacroOption:\my at temp}%
         #2}

... with some

     \newcommand{\DeclareMyMacroOption}[2]{%
         \@namedef{MyMacroOption:#1}{#2}}

     \DeclareMyMacroOption{item-1}{<item-1-stuff>}
     ...

So \DeclareMyMacroOption is just like \newcommand -- without guarding, 
without macro parameters, without backslash, similar to the commands that 
\label and \ref generate.

HTH -- Uwe.

 >2009/4/12 Joseph Wright <joseph.wright at morningstar2.co.uk>: >
 > 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).



More information about the texhax mailing list