I define a command with one optional key parameter. This command makes some calculations and them draws a tikzpicture. How can made my command to accept all the keys that a \draw command accept and pass them?

                   .store in = \gl@blgskip@macro


   % set length to optional parameter lineskip

  %%% Do some calculations ...

    \draw (0,0) -- (0,5cm);

Now I can call my commands as \baselinegrid[lineskip=3cm]. I want to do thing like \baselinegrid[lineskiip=3cm, color=red] and pass the option color to the \draw command.

1 Answer 1


I'm not sure what you want to do exactly but I would recommend building the length-setting code into the keys themselves so you can pass all the arguments to the tikzpicture environment directly. Such as

    \draw (0,0) grid (\gl@blgskip,\gl@blgskip);



sample code output

You don't need to put your keys in a separate namespace as long as you're not overwriting a tikz key. The .code key handler sets up a macro to handle the argument passed to it, so you don't have to .store in the argument and then call a separate macro later.

In situations such as these, I usually end up building all the code into keys such as the execute at begin/end picture so that your interface can be just \tikz[baselinegrid,lineskip=...]{}. If you explain more of what you want to see I can explain more.

  • This is what I needed! I have just a couple of things. First if the \tikzsetup is inside the \newcommand there is a compilation error, and second, if no lineskip option is given the value of \gl@blgskip is 0pt and not \baselineskip. (I fix this one with a \setlength command before the tikzpicture.
    – TeXtnik
    Apr 22, 2013 at 15:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .