I have a command essentially like this:

\newcommand\cl[2]{\tikz{\filldraw[fill=#1,...#2] (0,0) circle [radius=0.1cm];}}

  \cl{blue}{dotted,minimum size=1mm}

Wondering how to take the options like fill=blue,dotted,minimum size=1mm and to pass them to a nested function inside \newcommand:


Update Essentially I'm wondering how to make better use of the options. So from a programming perspective the options are a map like HTML attributes, so fill=blue,dotted,minimum size=1mm is really more like:

minimum size=1mm

And I wonder two things:

  1. How to pass all of them in in bulk, \filldraw[...#3] pass in all the options in bulk
  2. How to reference an option by key and passing it in. So: \filldraw[minimum size=#3], when there is no '#3' defined. How to accomplish that.
  • 1
    I'm having trouble understanding your question. Could you post a MWE of what you currently have, and a minimal example of what you would like to have? – Teepeemm Mar 17 '18 at 1:40
  • I essentially just want a find/replace where \filldraw[fill=#1,...#2] becomes \filldraw[fill=blue,dotted,minimum size=1mm], without having to specify all the options individually. – Lance Pollard Mar 17 '18 at 1:43
  • Just have one argument and pass them all within that. – Alan Munn Mar 17 '18 at 1:47

As Alan Munn noted, you can use something like

  \tikz{\filldraw[fill=#1,#2] (0,0) circle [radius=0.1cm];}%

If you find yourself using the same options frequently, it may be worth defining a new style using \tikzset, but it's not entirely clear that's what you're after.

As a metacomment, with some exceptions, TeX's macro replacement is essentially replacing the parameters #1, #2, ..., #9 with the arguments to the macro verbatim. Commas aren't special to TeX in any way (by default). So code like \cl{blue}{dotted,minimum size=1mm} becomes

\tikz{\filldraw[fill=blue,dotted,minimum size=1mm] (0,0) circle [radius=0.1cm];}

pgfkeys, the mechanism underlying TikZ's option parsing, treats commas as special in that it is looking for a comma-separated list of keys and (optionally) values.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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