3

In the next example, I don't understand /tikz/Cote/aspect keys is not defined by the pgfkeys command and why it is not modified by the \draw argument. How access at the same definition of the key ?

\documentclass{article}
\usepackage{tikz}

\pgfkeys{/tikz/Cote/.cd,
    aspect/.default=o,
    aspect/.store in=\aspect,
    aspect=o
} 

\begin{document}

\begin{tikzpicture}
\draw[/tikz/Cote/aspect=(F)] (0,2) -- (5,2) node {\pgfkeysifdefined{/tikz/Cote/aspect}{yes}{no}};
\draw[/tikz/Cote/aspect=F,red] (0,0) -- (5,0) node {\pgfkeysvalueof{/tikz/Cote/aspect}};
\end{tikzpicture}

\pgfkeyssetvalue{/tikz/Cote/aspect}{Hello, world!}

\begin{tikzpicture}
\draw[/tikz/Cote/aspect=(F)] (0,2) -- (5,2) node {\pgfkeysifdefined{/tikz/Cote/aspect}{yes}{no}};
\draw[/tikz/Cote/aspect=F,red] (0,0) -- (5,0) node {\pgfkeysvalueof{/tikz/Cote/aspect}};
\end{tikzpicture}

\end{document}
  • 2
    .store in and .default and .initial are basically three different things. Did you read the manual? – Symbol 1 Feb 28 '18 at 21:53
  • @Symbol1 The manual is rather confusing. At least, I find it much more confusing than, say, the L3 documentation of that key-value handling. – cfr Feb 28 '18 at 23:11
  • @cfr I cannot disagree. – Symbol 1 Feb 28 '18 at 23:22
3

I think what you want is

\pgfkeys{/tikz/Cote/.cd,
    aspect/.default=o,
    aspect/.store in=\aspect,
    aspect=\relax
}
\begin{tikzpicture}
\draw[Cote/aspect=(F)] (0,2) -- (5,2) node {\if\aspect\relax no \else yes \fi};
\draw[Cote/aspect=F,red] (0,0) -- (5,0) node {\aspect};
\end{tikzpicture}

Basically, you are misusing the key/val mechanism: if you use the store in=\macro mechanism, to get the value you should just use \macro. Therefore, you need to setup some way to check if \macro has been set to something meaningful to detect if aspect was set. Above I choose to use \relax as an indication that the key was not set.

If you want to use the \pgfkeysifdefined and \pgfkeysvalueof macros you should not use .store in but more primitive pgfkeys settings. For that, read the manual carefully.

Minor note: in \draw[keys] the path for keys is already /tikz so you can set your key by just writing \draw[Cote/aspect=bla].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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