-
Notifications
You must be signed in to change notification settings - Fork 26
/
tikz-auto-mark-nodes.tex
77 lines (69 loc) · 1.97 KB
/
tikz-auto-mark-nodes.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
% similar to https://tex.stackexchange.com/q/327269
\RequirePackage{tikz}
\RequirePackage{etoolbox}
\makeatletter
\def\tikz@splitNameAndShape#1,#2\tikz@stop{%
\def\tikzNodeName{#1}%
\def\tikzNodeShape{#2}%
}
\newif\iftikz@lib@automark@on
\global\let\tikzNodeList\pgfutil@empty
\patchcmd\tikz@node@finish
{\endgroup\endgroup}
{\tikz@lib@automark@record \endgroup\endgroup}
{}{\fail}
\def\tikz@lib@automark@record{%
\iftikz@lib@automark@on
% ignore unnamed nodes
\edef\tikz@lib@automark@temp{tikz@f@\the\tikz@fig@count}%
\unless\ifx\tikz@lib@automark@temp\tikz@last@fig@name
% similar to \xappto from `etoolbox`
\xappto\tikzNodeList{%
\ifx\tikzNodeList\pgfutil@empty\else,\fi
{\tikz@last@fig@name,\tikz@shape}}%
% \PackageWarning{tikz}{after app: \tikzNodeList}%
\fi
\fi
}
\def\tikz@lib@automark@atbegin@scope{%
\tikz@lib@automark@ontrue
}
\def\tikz@lib@automark@atend@picture{%
\tikz@lib@automark@onfalse
% \PackageWarning{tikz}{end: \tikzNodeList}%
\unless\ifx\tikzNodeList\pgfutil@empty
\foreach \i in \tikzNodeList {
\unless\ifx\i\@empty
\expandafter\tikz@splitNameAndShape\i\tikz@stop
\unless\ifx\tikzNodeName\@empty
\node also[pin={[every auto mark/.try, every auto \tikzNodeShape\space mark/.try]{\tikzAutoMarkText}}] (\tikzNodeName);
\fi
\fi
}
\global\let\tikzNodeList\pgfutil@empty
\fi
}
\tikzset{
auto mark/.style={
execute at begin scope={\tikz@lib@automark@atbegin@scope},
% TODO: use `\tikz@after@path` (internal of `execute after path`)
execute at end picture={\tikz@lib@automark@atend@picture}
},
no auto mark/.style={%
execute at begin scope={\tikz@lib@automark@onfalse}
},
every auto mark/.style={
font=\ttfamily,
rotate=45,
red,
anchor=west,
pin position=45,
},
every auto coordinate mark/.style={
blue,
anchor=east,
pin position=180+45,
},
}
\newcommand\tikzAutoMarkText{\tikzNodeName}
\makeatother