Expanding macro defined by csdef to define a style via tikzset
Clash Royale CLAN TAG#URR8PPP
up vote
7
down vote
favorite
I need to store tikz
option in a csdef
:
csdefMy Node Optiondraw=red, thick, fill=yellow
How do I use this definition to define a style via tikzset
?
I attempted to use .expand once
as per How do I define tikz styles with a xkeyval command?:
tikzsetNode Options/.style/.expand once=csuseMy Node Option
but that leads to a
Package pgfkeys Error: I do not know the key '/tikz/draw=red, thick, fill=yellow' and I am going to ignore it. Perhaps you misspelled it.
The desired result is to modify only the tikzset
in the MWE and obtain:
Notes:
- As egreg commented, spaces in names of commands should be avoided. However, in my actual use case, the command names defined by the
csdef
are named after file names with paths which include spaces, slashes, numbers, periods.
Code:
documentclassarticle
usepackagetikz
usepackageetoolbox
begindocument
csdefMy Node Optiondraw=red, thick, fill=yellow
noindent
begintikzpicture
tikzsetNode Options/.style/.expand once=csuseMy Node Option%% ????
node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument
tikz-pgf tikz-styles expansion etoolbox
add a comment |Â
up vote
7
down vote
favorite
I need to store tikz
option in a csdef
:
csdefMy Node Optiondraw=red, thick, fill=yellow
How do I use this definition to define a style via tikzset
?
I attempted to use .expand once
as per How do I define tikz styles with a xkeyval command?:
tikzsetNode Options/.style/.expand once=csuseMy Node Option
but that leads to a
Package pgfkeys Error: I do not know the key '/tikz/draw=red, thick, fill=yellow' and I am going to ignore it. Perhaps you misspelled it.
The desired result is to modify only the tikzset
in the MWE and obtain:
Notes:
- As egreg commented, spaces in names of commands should be avoided. However, in my actual use case, the command names defined by the
csdef
are named after file names with paths which include spaces, slashes, numbers, periods.
Code:
documentclassarticle
usepackagetikz
usepackageetoolbox
begindocument
csdefMy Node Optiondraw=red, thick, fill=yellow
noindent
begintikzpicture
tikzsetNode Options/.style/.expand once=csuseMy Node Option%% ????
node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument
tikz-pgf tikz-styles expansion etoolbox
2
You'd need/.expand thrice
, which doesn't exist. But/.expand twice=csname My Node Optionendcsname
works. I know that spaces in names of commands and options is bad.;-)
– egreg
8 hours ago
add a comment |Â
up vote
7
down vote
favorite
up vote
7
down vote
favorite
I need to store tikz
option in a csdef
:
csdefMy Node Optiondraw=red, thick, fill=yellow
How do I use this definition to define a style via tikzset
?
I attempted to use .expand once
as per How do I define tikz styles with a xkeyval command?:
tikzsetNode Options/.style/.expand once=csuseMy Node Option
but that leads to a
Package pgfkeys Error: I do not know the key '/tikz/draw=red, thick, fill=yellow' and I am going to ignore it. Perhaps you misspelled it.
The desired result is to modify only the tikzset
in the MWE and obtain:
Notes:
- As egreg commented, spaces in names of commands should be avoided. However, in my actual use case, the command names defined by the
csdef
are named after file names with paths which include spaces, slashes, numbers, periods.
Code:
documentclassarticle
usepackagetikz
usepackageetoolbox
begindocument
csdefMy Node Optiondraw=red, thick, fill=yellow
noindent
begintikzpicture
tikzsetNode Options/.style/.expand once=csuseMy Node Option%% ????
node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument
tikz-pgf tikz-styles expansion etoolbox
I need to store tikz
option in a csdef
:
csdefMy Node Optiondraw=red, thick, fill=yellow
How do I use this definition to define a style via tikzset
?
I attempted to use .expand once
as per How do I define tikz styles with a xkeyval command?:
tikzsetNode Options/.style/.expand once=csuseMy Node Option
but that leads to a
Package pgfkeys Error: I do not know the key '/tikz/draw=red, thick, fill=yellow' and I am going to ignore it. Perhaps you misspelled it.
The desired result is to modify only the tikzset
in the MWE and obtain:
Notes:
- As egreg commented, spaces in names of commands should be avoided. However, in my actual use case, the command names defined by the
csdef
are named after file names with paths which include spaces, slashes, numbers, periods.
Code:
documentclassarticle
usepackagetikz
usepackageetoolbox
begindocument
csdefMy Node Optiondraw=red, thick, fill=yellow
noindent
begintikzpicture
tikzsetNode Options/.style/.expand once=csuseMy Node Option%% ????
node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument
tikz-pgf tikz-styles expansion etoolbox
tikz-pgf tikz-styles expansion etoolbox
edited 10 mins ago
asked 9 hours ago
Peter Grill
162k24430736
162k24430736
2
You'd need/.expand thrice
, which doesn't exist. But/.expand twice=csname My Node Optionendcsname
works. I know that spaces in names of commands and options is bad.;-)
– egreg
8 hours ago
add a comment |Â
2
You'd need/.expand thrice
, which doesn't exist. But/.expand twice=csname My Node Optionendcsname
works. I know that spaces in names of commands and options is bad.;-)
– egreg
8 hours ago
2
2
You'd need
/.expand thrice
, which doesn't exist. But /.expand twice=csname My Node Optionendcsname
works. I know that spaces in names of commands and options is bad. ;-)
– egreg
8 hours ago
You'd need
/.expand thrice
, which doesn't exist. But /.expand twice=csname My Node Optionendcsname
works. I know that spaces in names of commands and options is bad. ;-)
– egreg
8 hours ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
8
down vote
accepted
You can use expanded
instead of expand once
in your MWE:
tikzsetNode Options/.style/.expanded=csuseMy Node Option%% ????
2
+1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
– Andrew
8 hours ago
add a comment |Â
up vote
6
down vote
csuse...
is not quite the same as csname...endcsname
:
% etoolbox.sty, line 883:
newcommand*csuse[1]%
ifcsname#1endcsname
csname#1expandafterendcsname
fi
If you expand once in your context you get
ifcsname My Node Optionendcsnamecsname My Node Optionendcsnamefi
A further expansion step will remove the conditional, leaving
csname My Node Optionendcsnamefi
which requires two expansion steps in order to deliver
draw=red, thick, fill=yellowfi
but then the fi
kicks in, because it is shuffled around at the wrong place.
You can do
tikzsetNode Options/.style/.expand twice=csname My Node Optionendcsname
that avoids the problem of the dangling if
.
However, the best strategy, in my opinion, is to use styles all around:
documentclassarticle
usepackagetikz
begindocument
tikzsetMy Node Option/.style=draw=red, thick, fill=yellow
begintikzpicture
tikzsetNode Options/.style=My Node Option
node [Node Options] at (0,0) Node Text;
endtikzpicture
enddocument
add a comment |Â
up vote
5
down vote
You can use the begingroupedefxendgroup <stuff to expand>x
expansion trick:
documentclassarticle
usepackagetikz
usepackageetoolbox
begindocument
csdefMy Node Optiondraw=red, thick, fill=yellow
noindent
begintikzpicture
begingroupedefxendgroup
noexpandtikzsetNode Options/.style=csuseMy Node Option%
x
node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument
Note the additional braces around the csuse
.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
You can use expanded
instead of expand once
in your MWE:
tikzsetNode Options/.style/.expanded=csuseMy Node Option%% ????
2
+1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
– Andrew
8 hours ago
add a comment |Â
up vote
8
down vote
accepted
You can use expanded
instead of expand once
in your MWE:
tikzsetNode Options/.style/.expanded=csuseMy Node Option%% ????
2
+1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
– Andrew
8 hours ago
add a comment |Â
up vote
8
down vote
accepted
up vote
8
down vote
accepted
You can use expanded
instead of expand once
in your MWE:
tikzsetNode Options/.style/.expanded=csuseMy Node Option%% ????
You can use expanded
instead of expand once
in your MWE:
tikzsetNode Options/.style/.expanded=csuseMy Node Option%% ????
answered 8 hours ago
corporal
64135
64135
2
+1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
– Andrew
8 hours ago
add a comment |Â
2
+1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
– Andrew
8 hours ago
2
2
+1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
– Andrew
8 hours ago
+1 It's better to give a complete minimal working example as an answer to show that your solution works, but I agree that this does work and hence that this is probably the preferred tikz solution.
– Andrew
8 hours ago
add a comment |Â
up vote
6
down vote
csuse...
is not quite the same as csname...endcsname
:
% etoolbox.sty, line 883:
newcommand*csuse[1]%
ifcsname#1endcsname
csname#1expandafterendcsname
fi
If you expand once in your context you get
ifcsname My Node Optionendcsnamecsname My Node Optionendcsnamefi
A further expansion step will remove the conditional, leaving
csname My Node Optionendcsnamefi
which requires two expansion steps in order to deliver
draw=red, thick, fill=yellowfi
but then the fi
kicks in, because it is shuffled around at the wrong place.
You can do
tikzsetNode Options/.style/.expand twice=csname My Node Optionendcsname
that avoids the problem of the dangling if
.
However, the best strategy, in my opinion, is to use styles all around:
documentclassarticle
usepackagetikz
begindocument
tikzsetMy Node Option/.style=draw=red, thick, fill=yellow
begintikzpicture
tikzsetNode Options/.style=My Node Option
node [Node Options] at (0,0) Node Text;
endtikzpicture
enddocument
add a comment |Â
up vote
6
down vote
csuse...
is not quite the same as csname...endcsname
:
% etoolbox.sty, line 883:
newcommand*csuse[1]%
ifcsname#1endcsname
csname#1expandafterendcsname
fi
If you expand once in your context you get
ifcsname My Node Optionendcsnamecsname My Node Optionendcsnamefi
A further expansion step will remove the conditional, leaving
csname My Node Optionendcsnamefi
which requires two expansion steps in order to deliver
draw=red, thick, fill=yellowfi
but then the fi
kicks in, because it is shuffled around at the wrong place.
You can do
tikzsetNode Options/.style/.expand twice=csname My Node Optionendcsname
that avoids the problem of the dangling if
.
However, the best strategy, in my opinion, is to use styles all around:
documentclassarticle
usepackagetikz
begindocument
tikzsetMy Node Option/.style=draw=red, thick, fill=yellow
begintikzpicture
tikzsetNode Options/.style=My Node Option
node [Node Options] at (0,0) Node Text;
endtikzpicture
enddocument
add a comment |Â
up vote
6
down vote
up vote
6
down vote
csuse...
is not quite the same as csname...endcsname
:
% etoolbox.sty, line 883:
newcommand*csuse[1]%
ifcsname#1endcsname
csname#1expandafterendcsname
fi
If you expand once in your context you get
ifcsname My Node Optionendcsnamecsname My Node Optionendcsnamefi
A further expansion step will remove the conditional, leaving
csname My Node Optionendcsnamefi
which requires two expansion steps in order to deliver
draw=red, thick, fill=yellowfi
but then the fi
kicks in, because it is shuffled around at the wrong place.
You can do
tikzsetNode Options/.style/.expand twice=csname My Node Optionendcsname
that avoids the problem of the dangling if
.
However, the best strategy, in my opinion, is to use styles all around:
documentclassarticle
usepackagetikz
begindocument
tikzsetMy Node Option/.style=draw=red, thick, fill=yellow
begintikzpicture
tikzsetNode Options/.style=My Node Option
node [Node Options] at (0,0) Node Text;
endtikzpicture
enddocument
csuse...
is not quite the same as csname...endcsname
:
% etoolbox.sty, line 883:
newcommand*csuse[1]%
ifcsname#1endcsname
csname#1expandafterendcsname
fi
If you expand once in your context you get
ifcsname My Node Optionendcsnamecsname My Node Optionendcsnamefi
A further expansion step will remove the conditional, leaving
csname My Node Optionendcsnamefi
which requires two expansion steps in order to deliver
draw=red, thick, fill=yellowfi
but then the fi
kicks in, because it is shuffled around at the wrong place.
You can do
tikzsetNode Options/.style/.expand twice=csname My Node Optionendcsname
that avoids the problem of the dangling if
.
However, the best strategy, in my opinion, is to use styles all around:
documentclassarticle
usepackagetikz
begindocument
tikzsetMy Node Option/.style=draw=red, thick, fill=yellow
begintikzpicture
tikzsetNode Options/.style=My Node Option
node [Node Options] at (0,0) Node Text;
endtikzpicture
enddocument
answered 7 hours ago


egreg
693k8518443094
693k8518443094
add a comment |Â
add a comment |Â
up vote
5
down vote
You can use the begingroupedefxendgroup <stuff to expand>x
expansion trick:
documentclassarticle
usepackagetikz
usepackageetoolbox
begindocument
csdefMy Node Optiondraw=red, thick, fill=yellow
noindent
begintikzpicture
begingroupedefxendgroup
noexpandtikzsetNode Options/.style=csuseMy Node Option%
x
node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument
Note the additional braces around the csuse
.
add a comment |Â
up vote
5
down vote
You can use the begingroupedefxendgroup <stuff to expand>x
expansion trick:
documentclassarticle
usepackagetikz
usepackageetoolbox
begindocument
csdefMy Node Optiondraw=red, thick, fill=yellow
noindent
begintikzpicture
begingroupedefxendgroup
noexpandtikzsetNode Options/.style=csuseMy Node Option%
x
node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument
Note the additional braces around the csuse
.
add a comment |Â
up vote
5
down vote
up vote
5
down vote
You can use the begingroupedefxendgroup <stuff to expand>x
expansion trick:
documentclassarticle
usepackagetikz
usepackageetoolbox
begindocument
csdefMy Node Optiondraw=red, thick, fill=yellow
noindent
begintikzpicture
begingroupedefxendgroup
noexpandtikzsetNode Options/.style=csuseMy Node Option%
x
node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument
Note the additional braces around the csuse
.
You can use the begingroupedefxendgroup <stuff to expand>x
expansion trick:
documentclassarticle
usepackagetikz
usepackageetoolbox
begindocument
csdefMy Node Optiondraw=red, thick, fill=yellow
noindent
begintikzpicture
begingroupedefxendgroup
noexpandtikzsetNode Options/.style=csuseMy Node Option%
x
node [Node Options] at (0,0) Node Text;
endtikzpicture%
enddocument
Note the additional braces around the csuse
.
answered 8 hours ago


Werner
427k589361610
427k589361610
add a comment |Â
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%2f457429%2fexpanding-macro-defined-by-csdef-to-define-a-style-via-tikzset%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
2
You'd need
/.expand thrice
, which doesn't exist. But/.expand twice=csname My Node Optionendcsname
works. I know that spaces in names of commands and options is bad.;-)
– egreg
8 hours ago