4

I would like access the variable that stores on grid option is activated or not, to calculate a few distances in my \pgfdeclareshape.

I did some research. I read How to extract the value from a pgfkeys style element and Accessing a style property in TikZ? . Then, I guess that the value of on grid is stored in tikz@lib@ignore@size. I tried to extract the value by an idea addressed in Accessing a style property in TikZ? .

My MWE is as below:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}

\makeatletter
\def\getongrid{\tikz@lib@ignore@size}
\makeatother

\begin{document}
\begin{tikzpicture}[node distance=3mm]
  \node [] (n1) {1};
  \node [right=of n1] (n2) {\getongrid};
\end{tikzpicture}
\end{document}

But I got an error:

Undefined control sequence.
\getongrid ->\tikz@lib@ignore@size 

l.17   \node [right=of n1] (n2) {\getongrid
                                           };

How can I fix this?

For your information, I got the following trace by trace-pgfkeys.sty.

[trace-pgfkeys]-+ \pgfkeysdefaultpath : /tikz
[trace-pgfkeys]-+ Key/value list: (on grid/.is if=tikz@lib@ignore@size)
[trace-pgfkeys]-+ Current key-value: (#1)
[trace-pgfkeys]-+ \pgfkeyscurrentkey (given): on grid/.is if
[trace-pgfkeys]-> \pgfkeyscurrentkey : /tikz/on grid/.is if
[trace-pgfkeys]-+ \pgfkeyscurrentvalue : (tikz@lib@ignore@size)
[trace-pgfkeys]-+ \pgfkeyscurrentpath (/tikz/on grid)
[trace-pgfkeys]-+ \pgfkeyscurrentname (.is if)
[trace-pgfkeys]-+ Executing all handlers.
[trace-pgfkeys]--+ Executing handler.
[trace-pgfkeys]--> Handler: /handlers/.is if
[trace-pgfkeys]--+ \pgfkeysdefaultpath : (/tikz/)
[trace-pgfkeys]--+ Key/value list: (\pgfkeyscurrentpath /.code=\pgfkeys@handle@
boolean {tikz@lib@ignore@size}{##1}, \pgfkeyscurrentpath /.default=true)
[trace-pgfkeys]---+ Current key-value: (#1)
[trace-pgfkeys]---+ \pgfkeyscurrentkey (given): /tikz/on grid/.code
[trace-pgfkeys]---> \pgfkeyscurrentkey : /tikz/on grid/.code
[trace-pgfkeys]---+ \pgfkeyscurrentvalue : (\pgfkeys@handle@boolean {tikz@lib@i
gnore@size}{##1})
[trace-pgfkeys]---+ \pgfkeyscurrentpath (/tikz/on grid)
[trace-pgfkeys]---+ \pgfkeyscurrentname (.code)
[trace-pgfkeys]---+ Executing all handlers.
[trace-pgfkeys]----+ Executing handler.
[trace-pgfkeys]----> Handler: /handlers/.code
[trace-pgfkeys]----+ Execution finished.
[trace-pgfkeys]---+ Current key-value: (#1)
[trace-pgfkeys]---+ \pgfkeyscurrentkey (given): /tikz/on grid/.default
[trace-pgfkeys]---> \pgfkeyscurrentkey : /tikz/on grid/.default
[trace-pgfkeys]---+ \pgfkeyscurrentvalue : (true)
[trace-pgfkeys]---+ \pgfkeyscurrentpath (/tikz/on grid)
[trace-pgfkeys]---+ \pgfkeyscurrentname (.default)
[trace-pgfkeys]---+ Executing all handlers.
[trace-pgfkeys]----+ Executing handler.
[trace-pgfkeys]----> Handler: /handlers/.default
[trace-pgfkeys]----+ Execution finished.
[trace-pgfkeys]---+ Last key processed.
[trace-pgfkeys]--+ Execution finished.
[trace-pgfkeys]-+ Last key processed.
Pengin
  • 345

1 Answers1

6

The internal variable is an \if... switch:

\iftikz@lib@ignore@size <true case> \else <false case> \fi

Example file:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}

\makeatletter
\def\getongrid{\iftikz@lib@ignore@size true\else false\fi}
\makeatother

\begin{document}
\begin{tikzpicture}[node distance=3mm]
  \node [] (n1) {1};
  \node [right=of n1] (n2) {\getongrid};
\end{tikzpicture}
\end{document}

Result

Heiko Oberdiek
  • 271,626