summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/drawmatrix/drawmatrix.sty
blob: bdadb90799f447a82c91fffef9d05cceac1963ed (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
%%
%% This is file `drawmatrix.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% drawmatrix.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2016 by Elmar Peise
%% 
%% This package is distributed under the MIT license.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{drawmatrix}[2016/12/20 v1.4.0 drawmatrix package]
\RequirePackage{tikz}
\newif\ifdrawmatrix@externalize
\pgfkeys{
    drawmatrix/.is family,
    drawmatrix/.cd,
    picture/.style={},
    path/.style={},
    baseline/.style={picture/.append style={baseline=(drawmatrix #1)}},
    scale/.style={path/.append style={scale=#1}},
    x/.style={path/.append style={x=#1}},
    y/.style={path/.append style={y=#1}},
    baseline=label.base,
    bbox/.style={},
    bbox style/.style={bbox/.append style={#1}},
    bbox height/.initial,
    bbox width/.initial,
    bbox size/.style={bbox height=#1, bbox width=#1},
    offset height/.initial=0,
    offset width/.initial=0,
    offset/.style={offset height=#1, offset width=#1},
    height/.initial=1,
    width/.initial=1,
    size/.style={height=#1, width=#1},
    lower bandwidth/.initial,
    upper bandwidth/.initial,
    bandwidth/.style={lower bandwidth=#1, upper bandwidth=#1},
    lower banded/.style={lower bandwidth=.3},
    upper banded/.style={upper bandwidth=.3},
    banded/.style={lower banded, upper banded},
    lower/.style={upper bandwidth=0},
    upper/.style={lower bandwidth=0},
    diag/.style={lower, upper},
    label text/.initial,
    label/.style={},
    label pos/.style={label/.append style={at=(drawmatrix #1)}},
    label pos=bbox.center,
    label anchor/.style={label/.append style={anchor=#1}},
    label anchor=mid,
    label base/.initial,
    label outer/.style={},
    label base anchor/.style={label outer/.append style={
        anchor=#1, at=(drawmatrix label.#1)
    }},
    label base anchor=base west,
    exponent/.style={
        label base/.expanded=\pgfkeysvalueof{/drawmatrix/label text},
        label text/.append=^{#1}
    },
    drawmatrix/.style={},
    .unknown/.code={%
        \let\dm@currname\pgfkeyscurrentname%
        \let\dm@currval\pgfkeyscurrentvalue%
        \ifx#1\pgfkeysnovalue\pgfkeysalso{
            drawmatrix/.append style/.expand once={\dm@currname}
        }\else\pgfkeysalso{
            drawmatrix/.append style/.expand twice={%
                \expandafter\dm@currname\expandafter=\dm@currval%
            }
        }\fi%
    },
    every picture/.style={},
    every bbox/.style={
        name=drawmatrix bbox,
        inner sep=0
    },
    every drawmatrix/.style={
        fill=white,
        draw=gray
    },
    every label/.style={
        name=drawmatrix label,
        outer sep=0,
        inner sep=0
    },
    every node/.style={
        name=drawmatrix matrix,
        outer sep=0,
        inner sep=0,
        anchor=north west,
        at=(drawmatrix north west)
    },
    externalize/.is if=drawmatrix@externalize,
    externalize=true
}
\newcommand\drawmatrixset[1]{\pgfqkeys{/drawmatrix}{#1}}
\newcommand\drawmatrix[2][]{{%
    \drawmatrixset{
        label text={#2},
        #1,
        label text/.get=\dm@labeltext,
        height/.get=\dm@height,
        width/.get=\dm@width,
        lower bandwidth/.get=\dm@lowerbandwidth,
        upper bandwidth/.get=\dm@upperbandwidth,
        offset height/.get=\dm@offsetheight,
        offset width/.get=\dm@offsetwidth,
        bbox height/.get=\dm@bboxheight,
        bbox width/.get=\dm@bboxwidth,
        label base/.get=\dm@labelbase
    }%
    \ifmmode\edef\dm@labeltext{$\dm@labeltext$}\fi%
    \expandafter\ifx\dm@labelbase\pgfkeysnovalue\else%
        \let\dm@labeltextouter\dm@labeltext%
        \edef\dm@labelbase{%
            \ifmmode$\dm@labelbase$\else\dm@labelbase\fi%
        }%
        \def\dm@labeltext{\phantom{\dm@labelbase}}%
    \fi%
    \ifdrawmatrix@externalize\else%
        \ifx\tikz@library@external@loaded\undefined\else%
            \tikzset{external/export=false}%
        \fi%
    \fi%
    \begin{tikzpicture}[/drawmatrix/every picture, /drawmatrix/picture]
        \path[/drawmatrix/path] (\dm@width, \dm@height);
        \pgfgetlastxy\dm@width\dm@height
        \path[/drawmatrix/path] (\dm@offsetwidth, \dm@offsetheight);
        \pgfgetlastxy\dm@offsetwidth\dm@offsetheight
        \pgfmathsetlengthmacro\dm@minsize{min(\dm@width, \dm@height)}
        \pgfmathsetlengthmacro\dm@zero{0.0}
        \expandafter\ifx\dm@lowerbandwidth\pgfkeysnovalue
            \def\dm@lowerbandwidth{\dm@minsize}
        \else
            \path[/drawmatrix/path] (\dm@lowerbandwidth, 0);
            \pgfgetlastxy\dm@lowerbandwidth\dm@zero
        \fi
        \expandafter\ifx\dm@upperbandwidth\pgfkeysnovalue
            \def\dm@upperbandwidth{\dm@minsize}
        \else
            \path[/drawmatrix/path] (0, \dm@upperbandwidth);
            \pgfgetlastxy\dm@zero\dm@upperbandwidth
        \fi
        \pgfmathsetlengthmacro\dm@lowerbandwidth{
            min(\dm@minsize, \dm@lowerbandwidth)
        }
        \pgfmathsetlengthmacro\dm@upperbandwidth{
            min(\dm@minsize, \dm@upperbandwidth)
        }
        \expandafter\ifx\dm@bboxheight\pgfkeysnovalue
            \pgfmathsetlengthmacro\dm@bboxheight{
                \dm@height + \dm@offsetheight
            }
        \else
            \path[/drawmatrix/path] (0, \dm@bboxheight);
            \pgfgetlastxy\dm@zero\dm@bboxheight
        \fi
        \expandafter\ifx\dm@bboxwidth\pgfkeysnovalue
            \pgfmathsetlengthmacro\dm@bboxwidth{
                \dm@width + \dm@offsetwidth
            }
        \else
            \path[/drawmatrix/path] (\dm@bboxwidth, 0);
            \pgfgetlastxy\dm@bboxwidth\dm@zero
        \fi
        \pgfresetboundingbox
        \node[/drawmatrix/every bbox, /drawmatrix/bbox,
            minimum height=\dm@bboxheight,
            minimum width=\dm@bboxwidth] {};
        \path (drawmatrix bbox.north west)
            ++(\dm@offsetwidth, -\dm@offsetheight)
            ++(.5\pgflinewidth, -.5\pgflinewidth)
            coordinate (drawmatrix north west)
            ++(\dm@width, 0)
            +(-\dm@minsize + \dm@upperbandwidth, 0)
            coordinate (drawmatrix north)
            +(0, -\dm@minsize + \dm@upperbandwidth)
            coordinate (drawmatrix east)
            ++(0, -\dm@height)
            coordinate (drawmatrix south east)
            ++(-\dm@width, 0)
            +(\dm@minsize - \dm@lowerbandwidth, 0)
            coordinate (drawmatrix south)
            +(0, \dm@minsize - \dm@lowerbandwidth)
            coordinate (drawmatrix west);
        \node[/drawmatrix/every node,
            minimum height=\dm@height,
            minimum width=\dm@width] {};
        \filldraw[/drawmatrix/every drawmatrix, /drawmatrix/drawmatrix]
            (drawmatrix north west)
            \ifx\dm@upperbandwidth\dm@zero
                \ifx\dm@width\dm@minsize\else -- (drawmatrix north) \fi
                \ifx\dm@height\dm@minsize\else -- (drawmatrix east) \fi
            \else
                -- (drawmatrix north)
                \ifx\dm@upperbandwidth\dm@minsize\else
                    -- (drawmatrix east)
                \fi
            \fi
            -- (drawmatrix south east)
            \ifx\dm@lowerbandwidth\dm@zero
                \ifx\dm@width\dm@minsize\else -- (drawmatrix south) \fi
                \ifx\dm@height\dm@minsize\else -- (drawmatrix west) \fi
            \else
                -- (drawmatrix south)
                \ifx\dm@lowerbandwidth\dm@minsize\else
                    -- (drawmatrix west)
                \fi
            \fi
            -- cycle;
        \node[/drawmatrix/every label, /drawmatrix/label]
            {\dm@labeltext};
        \expandafter\ifx\dm@labelbase\pgfkeysnovalue\else
            \node[/drawmatrix/every label, /drawmatrix/label,
                  /drawmatrix/label outer] {\dm@labeltextouter};
        \fi
    \end{tikzpicture}%
}}
\endinput
%%
%% End of file `drawmatrix.sty'.