The following minimal working example shows the problem. The mainmacro is an example of what I need; here I want to use my keys and keys from tikz (like draw,color,shape). The result is fine only if I use shape = circle
. circle
is not enough. Idem if I want the color red. color = red
is obligatory. What is wrong in my code ? Do you know a better way to achieve what I want ?
documentclass[a4paper]{article}
usepackage{tikz}
usetikzlibrary{calc}
makeatletter
pgfkeys{/mykeys/.cd,
d/.code = {defmacro@d{#1}},
a/.code = {defmacro@a{#1}},
/mykeys/.unknown/.code = {letsearchname=pgfkeyscurrentname
pgfkeysalso{searchname/.try=#1,
/tikz/searchname/.retry=#1}
}
}
defmainmacro{pgfutil@ifnextchar[{main@macro}{main@macro[]}}
defmain@macro[#1](#2)#3{%
begingroup
pgfkeys{mykeys/.cd,
d = 1,
a = 45}
pgfqkeys{/mykeys}{#1}
path (#2) --+(macro@a:macro@d) node[/mykeys/.cd,#1] {#3};
endgroup
}
makeatother
begin{document}
begin{tikzpicture}
draw (0,0) --( 1,1) coordinate (a) ;
mainmacro[a=0,d=12pt,draw,shape=circle](a){label 1}
mainmacro[d=2cm,draw,circle](a){label 2}
end{tikzpicture}
end{document}
Update
documentclass[a4paper]{article}
usepackage{tikz}
usetikzlibrary{calc}
makeatletter
pgfkeys{/mykeys/.cd,
d/.store in = {macro@d},
a/.store in = {macro@a},
/mykeys/.unknown/.code = {letsearchname=pgfkeyscurrentname
pgfkeysalso{searchname/.try=#1,
/tikz/searchname/.retry=#1,
/tikz/.cd,#1}}}
defmainmacro{pgfutil@ifnextchar[{main@macro}{main@macro[]}}
defmain@macro[#1](#2){%
begingroup
pgfkeys{mykeys/.cd,
d = 1,
a = 1}
pgfqkeys{/mykeys}{#1}
draw[/mykeys/.cd,#1] (macro@a,macro@a) circle (macro@d) --++(1,1) node[#1] {label};%
endgroup
}
makeatother
begin{document}
begin{tikzpicture}
draw (0,0) -- (5,0) ;
mainmacro[red,ultra thick](a)
end{tikzpicture}
end{document}
The trick works for the node but not with draw
perhaps I’m wrong somewhere in my code