Conditionals within tikz node specification

Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I would like to specify custom hierarchies of tikz nodes where I do a few geometry calculations related to text depth, text width, text height, and so on.
In the process of writing custom commands to automate some of these calculations, I end up wanting to use TeX conditionals mixed in with tikz code. I read in another question that pgfextra can be used for this. However, it seems that this only works at the level of the tikzpicture environment.
A minimal example of what I would like to do is the following:
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
%Debugtrue
Debugfalse
newcommandMyNode
node[anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
pgfextraifDebug opacity=0.2,fi
] at (current page.north west)
begindocument
begintikzpicture
MyNode;
endtikzpicture
enddocument
The line containing pgfextra is giving me trouble. What should I do to conditionally change arguments to node?
Thanks!
tikz-pgf
add a comment |Â
up vote
4
down vote
favorite
I would like to specify custom hierarchies of tikz nodes where I do a few geometry calculations related to text depth, text width, text height, and so on.
In the process of writing custom commands to automate some of these calculations, I end up wanting to use TeX conditionals mixed in with tikz code. I read in another question that pgfextra can be used for this. However, it seems that this only works at the level of the tikzpicture environment.
A minimal example of what I would like to do is the following:
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
%Debugtrue
Debugfalse
newcommandMyNode
node[anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
pgfextraifDebug opacity=0.2,fi
] at (current page.north west)
begindocument
begintikzpicture
MyNode;
endtikzpicture
enddocument
The line containing pgfextra is giving me trouble. What should I do to conditionally change arguments to node?
Thanks!
tikz-pgf
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I would like to specify custom hierarchies of tikz nodes where I do a few geometry calculations related to text depth, text width, text height, and so on.
In the process of writing custom commands to automate some of these calculations, I end up wanting to use TeX conditionals mixed in with tikz code. I read in another question that pgfextra can be used for this. However, it seems that this only works at the level of the tikzpicture environment.
A minimal example of what I would like to do is the following:
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
%Debugtrue
Debugfalse
newcommandMyNode
node[anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
pgfextraifDebug opacity=0.2,fi
] at (current page.north west)
begindocument
begintikzpicture
MyNode;
endtikzpicture
enddocument
The line containing pgfextra is giving me trouble. What should I do to conditionally change arguments to node?
Thanks!
tikz-pgf
I would like to specify custom hierarchies of tikz nodes where I do a few geometry calculations related to text depth, text width, text height, and so on.
In the process of writing custom commands to automate some of these calculations, I end up wanting to use TeX conditionals mixed in with tikz code. I read in another question that pgfextra can be used for this. However, it seems that this only works at the level of the tikzpicture environment.
A minimal example of what I would like to do is the following:
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
%Debugtrue
Debugfalse
newcommandMyNode
node[anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
pgfextraifDebug opacity=0.2,fi
] at (current page.north west)
begindocument
begintikzpicture
MyNode;
endtikzpicture
enddocument
The line containing pgfextra is giving me trouble. What should I do to conditionally change arguments to node?
Thanks!
tikz-pgf
tikz-pgf
asked Sep 10 at 12:15
sblatt
333
333
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
5
down vote
accepted
Welcome to TeX.SE! Please try to avoid all pgfextra stuff. You can achieve almost everything with pgfkeys, also here.
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
%Debugtrue
Debugfalse
tikzsetDebug/.code=ifDebugpgfkeysalsoopacity=0.2fi
newcommandMyNode
node[anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
Debug,
] at (current page.north west)
begindocument
begintikzpicture
Debugtrue
MyNode;
endtikzpicture
enddocument

If I comment out Debugtrue, I get.

add a comment |Â
up vote
4
down vote
With a Tikz style (implemented with the /.code handler) this is rather straightforward:
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
Debugtrue
%Debugfalse
tikzset
my node/.code=
tikzset
anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
ifDebug
tikzsetopacity=0.2
fi
begindocument
begintikzpicture
node[my node];
Debugfalse
node[my node] at (6,0);
endtikzpicture
enddocument

As mentioned by marmot in his answer you should stay away from pgfextra in general. My personal preference is also to stay away from custom commands where styles can do the same, but that really is personal.
1
You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
â marmot
Sep 10 at 12:29
@marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
â Max
Sep 10 at 12:33
Thanks to both of you for the quick replies!
â sblatt
Sep 10 at 12:34
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
Welcome to TeX.SE! Please try to avoid all pgfextra stuff. You can achieve almost everything with pgfkeys, also here.
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
%Debugtrue
Debugfalse
tikzsetDebug/.code=ifDebugpgfkeysalsoopacity=0.2fi
newcommandMyNode
node[anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
Debug,
] at (current page.north west)
begindocument
begintikzpicture
Debugtrue
MyNode;
endtikzpicture
enddocument

If I comment out Debugtrue, I get.

add a comment |Â
up vote
5
down vote
accepted
Welcome to TeX.SE! Please try to avoid all pgfextra stuff. You can achieve almost everything with pgfkeys, also here.
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
%Debugtrue
Debugfalse
tikzsetDebug/.code=ifDebugpgfkeysalsoopacity=0.2fi
newcommandMyNode
node[anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
Debug,
] at (current page.north west)
begindocument
begintikzpicture
Debugtrue
MyNode;
endtikzpicture
enddocument

If I comment out Debugtrue, I get.

add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
Welcome to TeX.SE! Please try to avoid all pgfextra stuff. You can achieve almost everything with pgfkeys, also here.
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
%Debugtrue
Debugfalse
tikzsetDebug/.code=ifDebugpgfkeysalsoopacity=0.2fi
newcommandMyNode
node[anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
Debug,
] at (current page.north west)
begindocument
begintikzpicture
Debugtrue
MyNode;
endtikzpicture
enddocument

If I comment out Debugtrue, I get.

Welcome to TeX.SE! Please try to avoid all pgfextra stuff. You can achieve almost everything with pgfkeys, also here.
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
%Debugtrue
Debugfalse
tikzsetDebug/.code=ifDebugpgfkeysalsoopacity=0.2fi
newcommandMyNode
node[anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
Debug,
] at (current page.north west)
begindocument
begintikzpicture
Debugtrue
MyNode;
endtikzpicture
enddocument

If I comment out Debugtrue, I get.

answered Sep 10 at 12:23
marmot
59.7k463128
59.7k463128
add a comment |Â
add a comment |Â
up vote
4
down vote
With a Tikz style (implemented with the /.code handler) this is rather straightforward:
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
Debugtrue
%Debugfalse
tikzset
my node/.code=
tikzset
anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
ifDebug
tikzsetopacity=0.2
fi
begindocument
begintikzpicture
node[my node];
Debugfalse
node[my node] at (6,0);
endtikzpicture
enddocument

As mentioned by marmot in his answer you should stay away from pgfextra in general. My personal preference is also to stay away from custom commands where styles can do the same, but that really is personal.
1
You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
â marmot
Sep 10 at 12:29
@marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
â Max
Sep 10 at 12:33
Thanks to both of you for the quick replies!
â sblatt
Sep 10 at 12:34
add a comment |Â
up vote
4
down vote
With a Tikz style (implemented with the /.code handler) this is rather straightforward:
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
Debugtrue
%Debugfalse
tikzset
my node/.code=
tikzset
anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
ifDebug
tikzsetopacity=0.2
fi
begindocument
begintikzpicture
node[my node];
Debugfalse
node[my node] at (6,0);
endtikzpicture
enddocument

As mentioned by marmot in his answer you should stay away from pgfextra in general. My personal preference is also to stay away from custom commands where styles can do the same, but that really is personal.
1
You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
â marmot
Sep 10 at 12:29
@marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
â Max
Sep 10 at 12:33
Thanks to both of you for the quick replies!
â sblatt
Sep 10 at 12:34
add a comment |Â
up vote
4
down vote
up vote
4
down vote
With a Tikz style (implemented with the /.code handler) this is rather straightforward:
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
Debugtrue
%Debugfalse
tikzset
my node/.code=
tikzset
anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
ifDebug
tikzsetopacity=0.2
fi
begindocument
begintikzpicture
node[my node];
Debugfalse
node[my node] at (6,0);
endtikzpicture
enddocument

As mentioned by marmot in his answer you should stay away from pgfextra in general. My personal preference is also to stay away from custom commands where styles can do the same, but that really is personal.
With a Tikz style (implemented with the /.code handler) this is rather straightforward:
documentclass[class=minimal, border=0pt]standalone
usepackagetikz
newififDebug
Debugtrue
%Debugfalse
tikzset
my node/.code=
tikzset
anchor=north west,
minimum width=5cm,
minimum height=5cm,
fill=green,
ifDebug
tikzsetopacity=0.2
fi
begindocument
begintikzpicture
node[my node];
Debugfalse
node[my node] at (6,0);
endtikzpicture
enddocument

As mentioned by marmot in his answer you should stay away from pgfextra in general. My personal preference is also to stay away from custom commands where styles can do the same, but that really is personal.
edited Sep 10 at 12:35
answered Sep 10 at 12:22
Max
6,21311728
6,21311728
1
You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
â marmot
Sep 10 at 12:29
@marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
â Max
Sep 10 at 12:33
Thanks to both of you for the quick replies!
â sblatt
Sep 10 at 12:34
add a comment |Â
1
You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
â marmot
Sep 10 at 12:29
@marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
â Max
Sep 10 at 12:33
Thanks to both of you for the quick replies!
â sblatt
Sep 10 at 12:34
1
1
You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
â marmot
Sep 10 at 12:29
You were faster, +1. I don't know why someone would upvote only my answer, but not yours. Sad.
â marmot
Sep 10 at 12:29
@marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
â Max
Sep 10 at 12:33
@marmot Well if someone thinks your solution is cleaner (which I could agree with) then it's a normal reaction :)
â Max
Sep 10 at 12:33
Thanks to both of you for the quick replies!
â sblatt
Sep 10 at 12:34
Thanks to both of you for the quick replies!
â sblatt
Sep 10 at 12:34
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f450236%2fconditionals-within-tikz-node-specification%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password