TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In tikz, the macro \draw accept a optical argument of parameters separated with comma, e.g.

\draw[->, red] (0, 0) -- (1, 1)

I have a self defined macro, in which I want to pass a macro as this optional parameter, i.e. sth like

\def\p{->, red}
\draw[\p] (0, 0) -- (1, 1)

However, I get a ERROR: Package pgf Error: Arrow end type ``>, red'' unknown. which is the same error with

\draw[{{->, red}}] (0, 0) -- (1, 1)

I think it is because the argument is passed as a single character and failed to be separated.

Is there a way to do it correctly? (i.e. "unquote" the curly bracket before passing it to the \draw macro.)

In my particular case, I use xkeyval package to define my macro according to this. Therefore I have to pass the argument through a macro.

(Any tikz specific work around is also helpful. THX)

share|improve this question
THX, all the solutions works for me. I have chosen the answer that is the best for my case, although other answers were actually what I was planning to look for. =D – yuyichao Mar 27 '12 at 22:08
up vote 10 down vote accepted

You should use \tikzset{MyStyle/.style={->, red}} instead of a \def to define your own custom style to be applied:


\tikzset{MyStyle/.style={->, red}}

    \draw[MyStyle] (0, 0) -- (1, 1);
share|improve this answer

 \def\p{->, red}
\draw\expandafter[\p] (0, 0) -- (1, 1);


or with etex

   \def\p{->, red}   
   \noexpand \draw[\p] (0, 0) -- (1, 1);}\tmp  
share|improve this answer
I guess that defining a new arrow style might be better. – egreg Mar 27 '12 at 21:53
@egreg I agree with you but \protected@edef\tmp{ saves me in a lot of painful situations and if OP writes a package it's perhaps very useful. – Alain Matthes Mar 27 '12 at 22:00
Oh, yes: I've suggested a few times something of the kind. – egreg Mar 27 '12 at 22:02
@egreg It's difficult to understand that OP wants to use tikz with a macro and he doesn't know what is a style ! – Alain Matthes Mar 27 '12 at 22:16

An immediate solution to your problem is


But if you want to use this systematically, it will become awkward.

Anyway, whatever you do you need to make sure the content of [] is expanded before \draw is executed.

share|improve this answer
Yes, this (order of expansion) is what I was confusing about. THX. – yuyichao Mar 27 '12 at 22:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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