Selectively ignoring some pgfkeys based on the existence of a tikz style
up vote
2
down vote
favorite
I want to be able to modify the style of some parts of a complex picture depending on a tag on nodes or pathes (precisely, I have a complex architecture schematic and I want to selectively highlight some datapathes). And I to facilitate maintenance of the picture, I prefer a single source.
One way to do that is:
- to declare the
tagsas emptypgfkeysstyles - and to modify their value on demand.
documentclass{article}
usepackage{tikz}
begin{document}
pgfkeys{/tikz/.cd,<slide 1>/.style={}}
pgfkeys{/tikz/.cd,<slide 2>/.style={}}
pgfkeys{/tikz/.cd,<slide 3>/.style={}}
pgfkeys{/tikz/.cd,<slide 4>/.style={}}
newcommand{complexpicture}{
node[draw, <slide 1>] at (0,0) {box 1};
node[draw, <slide 2>] at (2,0) {box 2};
node[draw, <slide 3>] at (4,0) {box 3};
node[draw, <slide 4>] at (6,0) {box 4};
}
General overview (all tags are ignored)
begin{tikzpicture}
complexpicture
end{tikzpicture}
Highlight first item
begin{tikzpicture}[<slide 1>/.style={very thick}]
complexpicture
end{tikzpicture}
Highlight second item
begin{tikzpicture}[<slide 2>/.style={very thick}]
complexpicture
end{tikzpicture}
end{document}

Of course, it works, but the need to previously declare tags is unflexible and inelegant.
So I tried to filter out < tags > with pgfkeys, except when a style exists. I used first char syntax to detect an initial <.
I did not succeed to declare styles starting with a <. So tikzpicture styles are in /tag/name/.style and I filter out < name > pgfkey, unless /tag/name exist.
documentclass{article}
usepackage{tikz}
begin{document}
newcommand{complexpicture}{
node[draw, <slide 1>] at (0,0) {box 1};
node[draw, <slide 2>] at (2,0) {box 2};
node[draw, <slide 3>] at (4,0) {box 3};
node[draw, <slide 4>] at (6,0) {box 4};
}
pgfkeys{
/handlers/first char syntax=true,
/handlers/first char syntax/the character </.initial=mykeymacro
}
defmykeymacro#1{mykeyparser#1someendtext}
defmykeyparser<#1>someendtext{
pgfkeysifdefined{/tag/#1}{pgfkeysvalueof{/tag/#1}}{}
}
General overview (all tags are ignored)\
begin{tikzpicture}
complexpicture
end{tikzpicture}
Highlight first item\
begin{tikzpicture}[/tag/slide 1/.style={very thick}]
complexpicture
end{tikzpicture}
Highlight second item\
begin{tikzpicture}[/tag/slide 2/.style={very thick}]
complexpicture
end{tikzpicture}
end{document}

Actually, it does not work. < tags > are properly filtered out and there is no pgfkeys error, but all theses keys are suppressed and the styles declared in the tikzpicture are never activated. I tried some variations on this scheme, but none did work.
Probably I am missing something...
tikz-pgf pgfkeys
New contributor
Alain Merigot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
2
down vote
favorite
I want to be able to modify the style of some parts of a complex picture depending on a tag on nodes or pathes (precisely, I have a complex architecture schematic and I want to selectively highlight some datapathes). And I to facilitate maintenance of the picture, I prefer a single source.
One way to do that is:
- to declare the
tagsas emptypgfkeysstyles - and to modify their value on demand.
documentclass{article}
usepackage{tikz}
begin{document}
pgfkeys{/tikz/.cd,<slide 1>/.style={}}
pgfkeys{/tikz/.cd,<slide 2>/.style={}}
pgfkeys{/tikz/.cd,<slide 3>/.style={}}
pgfkeys{/tikz/.cd,<slide 4>/.style={}}
newcommand{complexpicture}{
node[draw, <slide 1>] at (0,0) {box 1};
node[draw, <slide 2>] at (2,0) {box 2};
node[draw, <slide 3>] at (4,0) {box 3};
node[draw, <slide 4>] at (6,0) {box 4};
}
General overview (all tags are ignored)
begin{tikzpicture}
complexpicture
end{tikzpicture}
Highlight first item
begin{tikzpicture}[<slide 1>/.style={very thick}]
complexpicture
end{tikzpicture}
Highlight second item
begin{tikzpicture}[<slide 2>/.style={very thick}]
complexpicture
end{tikzpicture}
end{document}

Of course, it works, but the need to previously declare tags is unflexible and inelegant.
So I tried to filter out < tags > with pgfkeys, except when a style exists. I used first char syntax to detect an initial <.
I did not succeed to declare styles starting with a <. So tikzpicture styles are in /tag/name/.style and I filter out < name > pgfkey, unless /tag/name exist.
documentclass{article}
usepackage{tikz}
begin{document}
newcommand{complexpicture}{
node[draw, <slide 1>] at (0,0) {box 1};
node[draw, <slide 2>] at (2,0) {box 2};
node[draw, <slide 3>] at (4,0) {box 3};
node[draw, <slide 4>] at (6,0) {box 4};
}
pgfkeys{
/handlers/first char syntax=true,
/handlers/first char syntax/the character </.initial=mykeymacro
}
defmykeymacro#1{mykeyparser#1someendtext}
defmykeyparser<#1>someendtext{
pgfkeysifdefined{/tag/#1}{pgfkeysvalueof{/tag/#1}}{}
}
General overview (all tags are ignored)\
begin{tikzpicture}
complexpicture
end{tikzpicture}
Highlight first item\
begin{tikzpicture}[/tag/slide 1/.style={very thick}]
complexpicture
end{tikzpicture}
Highlight second item\
begin{tikzpicture}[/tag/slide 2/.style={very thick}]
complexpicture
end{tikzpicture}
end{document}

Actually, it does not work. < tags > are properly filtered out and there is no pgfkeys error, but all theses keys are suppressed and the styles declared in the tikzpicture are never activated. I tried some variations on this scheme, but none did work.
Probably I am missing something...
tikz-pgf pgfkeys
New contributor
Alain Merigot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Welcome to TeX.SE! Could you please elaborate a tiny bit more on what you are trying to achieve, and, in particular, why? The current output can easily be achieved by putting the nodes in amatrixand sayingcolumn 2/.style={thick}, say. (Most likely I just do not understand the purpose of that exercise.)
– marmot
3 hours ago
Does How do I pass an unknown value to a choice key in pgfkeys? or How to define a style of undefined key choice? (duplicate) answer help?
– Peter Grill
2 hours ago
This is a MWE. Actually, the picture is ~200 lines and describes the architecture of a processor, with registers, operators and busses. What I want to do is to have several versions. The regular one and others where the path used to implement some instructions is highlighted in red. The picture is fairly complex and can be largely improved,so I want a unique version and a way to easily modify styles of some parts of the picture with a unique code..
– Alain Merigot
15 mins ago
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I want to be able to modify the style of some parts of a complex picture depending on a tag on nodes or pathes (precisely, I have a complex architecture schematic and I want to selectively highlight some datapathes). And I to facilitate maintenance of the picture, I prefer a single source.
One way to do that is:
- to declare the
tagsas emptypgfkeysstyles - and to modify their value on demand.
documentclass{article}
usepackage{tikz}
begin{document}
pgfkeys{/tikz/.cd,<slide 1>/.style={}}
pgfkeys{/tikz/.cd,<slide 2>/.style={}}
pgfkeys{/tikz/.cd,<slide 3>/.style={}}
pgfkeys{/tikz/.cd,<slide 4>/.style={}}
newcommand{complexpicture}{
node[draw, <slide 1>] at (0,0) {box 1};
node[draw, <slide 2>] at (2,0) {box 2};
node[draw, <slide 3>] at (4,0) {box 3};
node[draw, <slide 4>] at (6,0) {box 4};
}
General overview (all tags are ignored)
begin{tikzpicture}
complexpicture
end{tikzpicture}
Highlight first item
begin{tikzpicture}[<slide 1>/.style={very thick}]
complexpicture
end{tikzpicture}
Highlight second item
begin{tikzpicture}[<slide 2>/.style={very thick}]
complexpicture
end{tikzpicture}
end{document}

Of course, it works, but the need to previously declare tags is unflexible and inelegant.
So I tried to filter out < tags > with pgfkeys, except when a style exists. I used first char syntax to detect an initial <.
I did not succeed to declare styles starting with a <. So tikzpicture styles are in /tag/name/.style and I filter out < name > pgfkey, unless /tag/name exist.
documentclass{article}
usepackage{tikz}
begin{document}
newcommand{complexpicture}{
node[draw, <slide 1>] at (0,0) {box 1};
node[draw, <slide 2>] at (2,0) {box 2};
node[draw, <slide 3>] at (4,0) {box 3};
node[draw, <slide 4>] at (6,0) {box 4};
}
pgfkeys{
/handlers/first char syntax=true,
/handlers/first char syntax/the character </.initial=mykeymacro
}
defmykeymacro#1{mykeyparser#1someendtext}
defmykeyparser<#1>someendtext{
pgfkeysifdefined{/tag/#1}{pgfkeysvalueof{/tag/#1}}{}
}
General overview (all tags are ignored)\
begin{tikzpicture}
complexpicture
end{tikzpicture}
Highlight first item\
begin{tikzpicture}[/tag/slide 1/.style={very thick}]
complexpicture
end{tikzpicture}
Highlight second item\
begin{tikzpicture}[/tag/slide 2/.style={very thick}]
complexpicture
end{tikzpicture}
end{document}

Actually, it does not work. < tags > are properly filtered out and there is no pgfkeys error, but all theses keys are suppressed and the styles declared in the tikzpicture are never activated. I tried some variations on this scheme, but none did work.
Probably I am missing something...
tikz-pgf pgfkeys
New contributor
Alain Merigot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I want to be able to modify the style of some parts of a complex picture depending on a tag on nodes or pathes (precisely, I have a complex architecture schematic and I want to selectively highlight some datapathes). And I to facilitate maintenance of the picture, I prefer a single source.
One way to do that is:
- to declare the
tagsas emptypgfkeysstyles - and to modify their value on demand.
documentclass{article}
usepackage{tikz}
begin{document}
pgfkeys{/tikz/.cd,<slide 1>/.style={}}
pgfkeys{/tikz/.cd,<slide 2>/.style={}}
pgfkeys{/tikz/.cd,<slide 3>/.style={}}
pgfkeys{/tikz/.cd,<slide 4>/.style={}}
newcommand{complexpicture}{
node[draw, <slide 1>] at (0,0) {box 1};
node[draw, <slide 2>] at (2,0) {box 2};
node[draw, <slide 3>] at (4,0) {box 3};
node[draw, <slide 4>] at (6,0) {box 4};
}
General overview (all tags are ignored)
begin{tikzpicture}
complexpicture
end{tikzpicture}
Highlight first item
begin{tikzpicture}[<slide 1>/.style={very thick}]
complexpicture
end{tikzpicture}
Highlight second item
begin{tikzpicture}[<slide 2>/.style={very thick}]
complexpicture
end{tikzpicture}
end{document}

Of course, it works, but the need to previously declare tags is unflexible and inelegant.
So I tried to filter out < tags > with pgfkeys, except when a style exists. I used first char syntax to detect an initial <.
I did not succeed to declare styles starting with a <. So tikzpicture styles are in /tag/name/.style and I filter out < name > pgfkey, unless /tag/name exist.
documentclass{article}
usepackage{tikz}
begin{document}
newcommand{complexpicture}{
node[draw, <slide 1>] at (0,0) {box 1};
node[draw, <slide 2>] at (2,0) {box 2};
node[draw, <slide 3>] at (4,0) {box 3};
node[draw, <slide 4>] at (6,0) {box 4};
}
pgfkeys{
/handlers/first char syntax=true,
/handlers/first char syntax/the character </.initial=mykeymacro
}
defmykeymacro#1{mykeyparser#1someendtext}
defmykeyparser<#1>someendtext{
pgfkeysifdefined{/tag/#1}{pgfkeysvalueof{/tag/#1}}{}
}
General overview (all tags are ignored)\
begin{tikzpicture}
complexpicture
end{tikzpicture}
Highlight first item\
begin{tikzpicture}[/tag/slide 1/.style={very thick}]
complexpicture
end{tikzpicture}
Highlight second item\
begin{tikzpicture}[/tag/slide 2/.style={very thick}]
complexpicture
end{tikzpicture}
end{document}

Actually, it does not work. < tags > are properly filtered out and there is no pgfkeys error, but all theses keys are suppressed and the styles declared in the tikzpicture are never activated. I tried some variations on this scheme, but none did work.
Probably I am missing something...
tikz-pgf pgfkeys
tikz-pgf pgfkeys
New contributor
Alain Merigot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Alain Merigot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 1 hour ago
AndréC
6,98211140
6,98211140
New contributor
Alain Merigot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 3 hours ago
Alain Merigot
111
111
New contributor
Alain Merigot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Alain Merigot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Alain Merigot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Welcome to TeX.SE! Could you please elaborate a tiny bit more on what you are trying to achieve, and, in particular, why? The current output can easily be achieved by putting the nodes in amatrixand sayingcolumn 2/.style={thick}, say. (Most likely I just do not understand the purpose of that exercise.)
– marmot
3 hours ago
Does How do I pass an unknown value to a choice key in pgfkeys? or How to define a style of undefined key choice? (duplicate) answer help?
– Peter Grill
2 hours ago
This is a MWE. Actually, the picture is ~200 lines and describes the architecture of a processor, with registers, operators and busses. What I want to do is to have several versions. The regular one and others where the path used to implement some instructions is highlighted in red. The picture is fairly complex and can be largely improved,so I want a unique version and a way to easily modify styles of some parts of the picture with a unique code..
– Alain Merigot
15 mins ago
add a comment |
Welcome to TeX.SE! Could you please elaborate a tiny bit more on what you are trying to achieve, and, in particular, why? The current output can easily be achieved by putting the nodes in amatrixand sayingcolumn 2/.style={thick}, say. (Most likely I just do not understand the purpose of that exercise.)
– marmot
3 hours ago
Does How do I pass an unknown value to a choice key in pgfkeys? or How to define a style of undefined key choice? (duplicate) answer help?
– Peter Grill
2 hours ago
This is a MWE. Actually, the picture is ~200 lines and describes the architecture of a processor, with registers, operators and busses. What I want to do is to have several versions. The regular one and others where the path used to implement some instructions is highlighted in red. The picture is fairly complex and can be largely improved,so I want a unique version and a way to easily modify styles of some parts of the picture with a unique code..
– Alain Merigot
15 mins ago
Welcome to TeX.SE! Could you please elaborate a tiny bit more on what you are trying to achieve, and, in particular, why? The current output can easily be achieved by putting the nodes in a
matrix and saying column 2/.style={thick}, say. (Most likely I just do not understand the purpose of that exercise.)– marmot
3 hours ago
Welcome to TeX.SE! Could you please elaborate a tiny bit more on what you are trying to achieve, and, in particular, why? The current output can easily be achieved by putting the nodes in a
matrix and saying column 2/.style={thick}, say. (Most likely I just do not understand the purpose of that exercise.)– marmot
3 hours ago
Does How do I pass an unknown value to a choice key in pgfkeys? or How to define a style of undefined key choice? (duplicate) answer help?
– Peter Grill
2 hours ago
Does How do I pass an unknown value to a choice key in pgfkeys? or How to define a style of undefined key choice? (duplicate) answer help?
– Peter Grill
2 hours ago
This is a MWE. Actually, the picture is ~200 lines and describes the architecture of a processor, with registers, operators and busses. What I want to do is to have several versions. The regular one and others where the path used to implement some instructions is highlighted in red. The picture is fairly complex and can be largely improved,so I want a unique version and a way to easily modify styles of some parts of the picture with a unique code..
– Alain Merigot
15 mins ago
This is a MWE. Actually, the picture is ~200 lines and describes the architecture of a processor, with registers, operators and busses. What I want to do is to have several versions. The regular one and others where the path used to implement some instructions is highlighted in red. The picture is fairly complex and can be largely improved,so I want a unique version and a way to easily modify styles of some parts of the picture with a unique code..
– Alain Merigot
15 mins ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Alain Merigot is a new contributor. Be nice, and check out our Code of Conduct.
Alain Merigot is a new contributor. Be nice, and check out our Code of Conduct.
Alain Merigot is a new contributor. Be nice, and check out our Code of Conduct.
Alain Merigot is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464571%2fselectively-ignoring-some-pgfkeys-based-on-the-existence-of-a-tikz-style%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to TeX.SE! Could you please elaborate a tiny bit more on what you are trying to achieve, and, in particular, why? The current output can easily be achieved by putting the nodes in a
matrixand sayingcolumn 2/.style={thick}, say. (Most likely I just do not understand the purpose of that exercise.)– marmot
3 hours ago
Does How do I pass an unknown value to a choice key in pgfkeys? or How to define a style of undefined key choice? (duplicate) answer help?
– Peter Grill
2 hours ago
This is a MWE. Actually, the picture is ~200 lines and describes the architecture of a processor, with registers, operators and busses. What I want to do is to have several versions. The regular one and others where the path used to implement some instructions is highlighted in red. The picture is fairly complex and can be largely improved,so I want a unique version and a way to easily modify styles of some parts of the picture with a unique code..
– Alain Merigot
15 mins ago