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
}
\def\mykeymacro#1{\mykeyparser#1\someendtext}
\def\mykeyparser<#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...



matrixand sayingcolumn 2/.style={thick}, say. (Most likely I just do not understand the purpose of that exercise.) – Dec 12 '18 at 19:03standaloneclass). Each picture sets all the necessary styles required by the figure:\tikzset{Draw Style 1/.provide style={}}, ...,\tikzset{Node Style 1/.provide style={}}, etc (or those can be set to some default value if needed). That way, when I invoke this figure, I can override a select subset of the styles as desired. The handler.provide styleis defined in Is there something like \providetikzstyle similar to \providecommand?. – Peter Grill Dec 12 '18 at 22:20