[texhax] tikz-options as macro

Philipp Stephani st_philipp at yahoo.de
Sun Jul 25 18:23:28 CEST 2010


Am 25.07.2010 um 17:38 schrieb Arno Trautmann:

> Hi all,
> 
> I have some problems using tikz: I try to pass some options in a macro,
> in the following way:
> 
> \documentclass{minimal}
> \usepackage{tikz}
> 
> \def\reddot{red,dotted}
> 
> \begin{document}
> \begin{tikzpicture}
> \draw[\reddot] (1,1) to (1,2);
> \end{tikzpicture}
> \end{document}
> 
> but this gives me:
> 
> ! Package pgfkeys Error: I do not know the key '/tikz/red,dotted' and I
> am goin
> g to ignore it. Perhaps you misspelled it.
> 
> See the pgfkeys package documentation for explanation.
> Type  H <return>  for immediate help.
> ...
> 
> l.18 \draw[\test]
>                  (1,1) to (1,2);
> ?
> 
> So pgf thinks I am passing “red,dotted” as one option. Is there any
> trick to avoid this behaviour? I would like to use this way of passing
> several options in a package – an alternative would be to pass
> \red,\dot, but that is not very nice …

Create a new style instead:

\documentclass{minimal}
\usepackage{tikz}

\tikzset{reddot/.style={red,dotted}}

\begin{document}
\begin{tikzpicture}
\draw[reddot] (1,1) to (1,2);
\end{tikzpicture}
\end{document}


More information about the texhax mailing list