summaryrefslogtreecommitdiff
path: root/graphics/pgf/base/tex/tikzlibrarymatrix.code.tex
blob: 507ac7a40d86c24eec252c01b3a8c3520a829cc3 (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
% Copyright 2018 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesFileRCS{tikzlibrarymatrix.code.tex}


% A matrix of nodes contains a node in each cell.

\tikzset{matrix of nodes/.style={%
   matrix,%
   cells={anchor=base},%
   execute at begin cell=\tikz@lib@matrix@start@cell,%
   execute at end cell=\tikz@lib@matrix@end@cell,%
   execute at empty cell=\tikz@lib@matrix@empty@cell,
   execute at begin matrix=\iftikz@handle@active@code\tikz@orig@shorthands\fi,%
}}%

\def\tikz@lib@matrix@empty@cell{\iftikz@lib@matrix@empty\node[name=\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn]{};\fi}%

\newif\iftikz@lib@matrix@plain

\def\tikz@lib@matrix@start@cell{%
  \pgfutil@ifnextchar|{\tikz@lib@matrix@with@options}{\tikz@lib@matrix@normal@start@cell}}%

\def\tikz@lib@matrix@with@options|#1|{\tikz@lib@matrix@plainfalse\node%
  [name=\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn]#1\bgroup\tikz@lib@matrix@startup}%


\def\tikz@lib@matrix@normal@start@cell{\pgfutil@ifnextchar\let{\tikz@lib@matrix@check}{\tikz@lib@matrix@plainfalse\node
  [name=\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn]\bgroup\tikz@lib@matrix@startup}}%

\def\tikz@lib@matrix@check#1{% evil hackery to find out about start of path
  \pgfutil@ifnextchar\tikz@signal@path{\tikz@lib@matrix@plaintrue\let}{\tikz@lib@matrix@plainfalse\node
  [name=\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn]\bgroup\tikz@lib@matrix@startup\let}%
}%

\def\tikz@lib@matrix@end@cell{%
  \iftikz@lib@matrix@plain%
  \else%
    \expandafter\egroup\expandafter;%
  \fi%
}%

\def\tikz@lib@matrix@startup{%
  \pgfutil@ifnextchar\bgroup{%
    % Save meaning of \\:
    \let\tikz@lib@matrix@saved@eol=\\%
    % Now smuggle meaning inside following group.
    \let\\=\pgfmatrixendrow%
    \afterassignment\tikz@lib@matrix@smuggle%
    \let\tikz@next}
  {\let\\=\pgfmatrixendrow}%
}%
\def\tikz@lib@matrix@smuggle{%
  \bgroup%
  \let\\=\tikz@lib@matrix@saved@eol%
}%


% Fill empty nodes in a matrix of nodes

\newif\iftikz@lib@matrix@empty

\tikzoption{nodes in empty cells}[true]{\csname tikz@lib@matrix@empty#1\endcsname}%


% Same as a matrix of nodes, but switch on math mode in each cell
\tikzset{matrix of math nodes/.style={%
  matrix of nodes,
  nodes={%
   execute at begin node=$,%
   execute at end node=$%
  }%
}}%



% Provide a delimiter

\tikzoption{left delimiter}{\tikzset{append after command={\tikz@delimiter%
    {south east}%
    {south west}%
    {every delimiter,every left delimiter}%
    {south}%
    {north}%
    {#1}%
    {.}%
    {\pgf@y}}}}%

\tikzoption{right delimiter}{\tikzset{append after command={\tikz@delimiter%
    {south west}%
    {south east}%
    {every delimiter,every right delimiter}%
    {south}%
    {north}%
    {.}%
    {#1}%
    {\pgf@y}}}}%

\tikzoption{above delimiter}{\tikzset{append after command={\tikz@delimiter%
    {south east}%
    {north west}%
    {every delimiter,every above delimiter,rotate=-90}%
    {west}%
    {east}%
    {#1}%
    {.}%
    {\pgf@x}}}}%

\tikzoption{below delimiter}{\tikzset{append after command={\tikz@delimiter%
    {south west}%
    {south west}%
    {every delimiter,every below delimiter,rotate=-90}%
    {west}%
    {east}%
    {.}%
    {#1}%
    {\pgf@x}}}}%

\def\tikz@delimiter#1#2#3#4#5#6#7#8{%
  \bgroup
    \pgfextra{\let\tikz@save@last@fig@name=\tikz@last@fig@name}%
    node[outer sep=0pt,inner sep=0pt,draw=none,fill=none,anchor=#1,at=(\tikz@last@fig@name.#2),#3]
    {%
      {\nullfont\pgf@process{\pgfpointdiff{\pgfpointanchor{\tikz@last@fig@name}{#4}}{\pgfpointanchor{\tikz@last@fig@name}{#5}}}}%
      $\left#6\vcenter{\hrule height .5#8 depth .5#8 width0pt}\right#7$%
    }
    \pgfextra{\global\let\tikz@last@fig@name=\tikz@save@last@fig@name}%
  \egroup%
}%

\tikzset{every delimiter/.style={}}%
\tikzset{every left delimiter/.style={}}%
\tikzset{every right delimiter/.style={}}%
\tikzset{every above delimiter/.style={}}%
\tikzset{every below delimiter/.style={}}%

\endinput