Sorry the code below for my minimal example is a bit long. In this code I defined two macros : the first macro \SC
draws semi-circle and the second macro \ARC
draws arcs. The first macro uses the second one.
\SC
uses some options like radius
and diameter
. I need to use /SCopt/.search also={/tikz}
if I want some keys from tikz.
\ARC
uses some options too like through
and angle
but here only through
is used.
My english is not perfect so I don't understand the subtleties of the pgfkeys section in the pfgmanual. My problem is how to manage the keys and the paths of \pgfkeys{/ARCopt/.cd,...
.
If I do not use
/ARCopt/.unknown/.code = {\let\searchname=\pgfkeyscurrentname
\pgfkeysalso{\searchname/.try=#1,
/tikz/\searchname/.retry=#1}},
I can't use the key diameter
and I get
Error: I do not know the key '/tikz/diameter'.
It's normal this is a key of the first macro \SC
but in this case I can use blue
and not color=blue
with /ARCopt/.search also={/tikz}
(thanks to Paul Gaborit)
The question is : it is possible to get the two possibilities : unknown keys in the second macro and keys from pgf/tikz ?
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\makeatletter
\def\SCR(#1,#2){% semi circle with radius defined by 2 pts
\coordinate (LastPT) at (barycentric cs:#2=1,#1=-2) ;
\coordinate (CenterPT) at (#1);
\coordinate (StartPT) at (#2);
}
%-----------------------------------------------------
\def\SCD(#1,#2){% semi circle with diameter defined by 2 pts
\coordinate (CenterPT) at (barycentric cs:#1=1,#2=1) ;
\coordinate (StartPT) at (#1);
\coordinate (LastPT) at (#2);}
%-----------------------------------------------------
\pgfkeys{/SCopt/.cd,
opt/.is choice,
opt/diameter/.code =\def\num{1},
opt/radius/.code =\def\num{0},
opt/.default =radius,
opt,
diameter/.style={opt=diameter},
radius/.style={opt=radius},
/SCopt/.search also={/tikz}
}
%-----------------------------------------------------
\def\SC{\@ifnextchar[{\SCb}{\SCb[]}}
\def\SCb[#1](#2){%
\pgfqkeys{/SCopt}{#1}
\ifcase\num%
\SCR(#2) % semi circle with radius defined by 2 pts
\or% 1
\SCD(#2) % semi circle with diameter defined by 2 pts
\fi
\ARC[#1](CenterPT,StartPT,LastPT)}%
%-----------------------------------------------------
\pgfkeys{/ARCopt/.cd,
type/.is choice,
type/through/.code = \def\numa{0},
type/angle/.code = \def\numa{1},
type/.default = through,
type,
through/.style = {type=through},% to avoid "type ="
angle/.style = {type=angle},
/ARCopt/.unknown/.code = {\let\searchname=\pgfkeyscurrentname
\pgfkeysalso{\searchname/.try=#1,
/tikz/\searchname/.retry=#1}},
%/ARCopt/.search also={/tikz},
}
%-----------------------------------------------------
\def\ARC{\@ifnextchar[{\ARCb}{\ARCb[]}}
\def\ARCb[#1](#2){%
\pgfqkeys{/ARCopt}{#1}
\ifcase\numa%
\ARCT[#1](#2) % arc with only pts
\or% 1
\ARCA[#1](#2) % arc with 2 pts and one angle
\fi}
\def\ARCT[#1](#2,#3,#4){%
\pgfpointdiff{\pgfpointanchor{#2}{center}}{\pgfpointanchor{#3}{center}}
\pgfmathparse{veclen(\pgf@x,\pgf@y)}
\let\ra\pgfmathresult %it's the radius
\pgfmathanglebetweenpoints{\pgfpointanchor{#2}{center}}{%
\pgfpointanchor{#3}{center}} %first angle
\let\fa\pgfmathresult
\pgfmathanglebetweenpoints{\pgfpointanchor{#2}{center}}{%
\pgfpointanchor{#4}{center}} %last angle
\let\la\pgfmathresult
\draw[shift = {(#2)},/ARCopt/.cd,#1] (\fa:\ra pt) arc (\fa:\la:\ra pt);}
\def\ARCA[#1](#2,#3,#4){%
% not defined
}
%-----------------------------------------------------
\makeatother
\begin{document}
\begin{tikzpicture}[point/.style={circle,minimum size=4pt,
inner sep=0pt,outer sep=0pt,fill=black}]
\path coordinate[point] (A) at (0,0)
coordinate[point] (B) at (6,0)
coordinate[point] (C) at (4,0);
\SC[color=red,thick](A,B)
\SC[blue,thick](A,C)
\SC[diameter](A,B)
%\SC[diameter](B,C)
\end{tikzpicture}
\end{document}
\pgfkeys{/ARCopt/.cd, ...
I added a fake key withtype/diameter/.code ={},diameter/.style={type=diameter},
and at the end I used only/ARCopt/.search also={/tikz}
. The problem is that I need to do this for all the keys of\SC
not used in\ARC
.type/.unknown/.style = {} ,
The code compiles but I need an explanation or the good way to do this