I'm trying to create some TikZ commands that use key value options. Using the following link: How to create a command with key values? I was able to declare some commands, but now I'm stuck.
As a MWE consider:
\documentclass{article}
\usepackage{keyval}
\usepackage{tikz}
\usepackage{pgfkeys}
\makeatletter
% using keyval package
\define@key{cutkv}{label}{\def\cutkv@label{#1}}
\define@key{cutkv}{bend}{\def\cutkv@bend{#1}}
\setkeys{cutkv}{label={},bend={}}
\newcommand{\cutkv}[3][]{
\begingroup
\setkeys{cutkv}{#1}
\draw[->] (#2) to[\cutkv@bend] node{\cutkv@label} (#3);
\endgroup
}
% using pgfkeys package
\pgfkeys{
/cutpgf/.is family, /cutpgf,
default/.style =
{label = ,
bend = },
label/.estore in = \cutpgf@label,
bend/.estore in = \cutpgf@bend,
}
\newcommand{\cutpgf}[3][]{
\pgfkeys{/cutpgf, default, #1}
\draw[->] (#2) to[\cutpgf@bend] node{\cutpgf@label} (#3);
}
\makeatother
\begin{document}
\begin{tikzpicture}
\cutkv[label=1]{0,0}{3,5}
\cutkv[label=2,bend={bend right}]{1,4}{7,2}
\cutkv[label=3,bend={bend right=10}]{6,0}{5,4}
\end{tikzpicture}
\begin{tikzpicture}
\cutpgf[label=1]{0,0}{3,5}
\cutpgf[label=2,bend={bend right}]{1,4}{7,2}
\cutpgf[label=3,bend={bend right=10}]{6,0}{5,4}
\end{tikzpicture}
\end{document}
The first and the second call of the \cut command work fine, but in the third call the option bend right=10
is not passed correctly. At least, I don't understand the problem there.
I also tried the approach with pgfkeys
, as mentioned in the first answer of the above post, but that didn't change anything.
edit: I added the version with pgfkeys
to the MWE.
Any help is very much appreciated. Thanks.
pgfkeys
approach is different tokeyval
orxkeyval
package, they do not co-operate, unfortunately. – user31729 Feb 26 '14 at 14:50pgfkeys
instead ofkeyval
, but ended up with the same problem. – stephan boehme Feb 26 '14 at 14:53key
(sic!) to the problem: <tex.stackexchange.com/questions/152020/…> -- in my point of view the source of the error lies in the double '=' characters, one as the outer key assignment, the other one as the inner key assignment of thepgfkeys
– user31729 Feb 26 '14 at 15:43{...}
would take care of that, but you might be right, adding a list of options likeopt={thick,dashed}
is not working neither. – stephan boehme Feb 26 '14 at 16:06\expandafter
is tricky so I've used\edef
in an answer – Joseph Wright♦ Feb 26 '14 at 16:52