# Writing a macro with parameters

I'm trying to write a macro which should be able to do several different yet somewhat similar things. I thought that instead of writing different macros for every thing, I should be able to write just one macro and let me choose when I'm writing the document, which option to choose. I think an example is the best way to describe what I want: suppose I have a macro `\mark[2]` which can mark things. I want to be able to use it like this: `\mark[direction=up]{a}{b}` if I want it to mark the object above it, `\mark[arrow=yes, direction=right]{a}{b}` if I want an arrow (and the mark to be to the right of it), and so on. Obviously I'd want to be able to set what's the default, so in the first example, no arrow will show up.

I'll be glad for any help.

-
–  Ryan Reich Feb 25 '12 at 18:20

Try the keyval package, or the xkeyval package.

-
Thanks, that seems to be the answer. Looks a bit too complicated for me right now, but I'll have a look. –  Jon Feb 25 '12 at 13:56

There is also the pgfkeys which are easy to use.

-
I'll have a look, thanks! –  Jon Feb 25 '12 at 14:17