%%
%% 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) 2015 by Elmar Peise
%% 
%% This package is distributed under the MIT license.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{drawmatrix}[2015/11/26 v1.1.0 drawmatrix package]
\RequirePackage{tikz}
\newif\ifdrawmatrix@externalize
\pgfkeys{
    drawmatrix/.is family,
    drawmatrix/.cd,
    picture/.style={},
    baseline/.style={picture/.append style={baseline=(drawmatrix #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},
    externalize/.is if=drawmatrix@externalize,
    externalize=true,
    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,
    drawmatrix/.style={},
    .unknown/.code={%
        \let\@currname\pgfkeyscurrentname%
        \let\@currval\pgfkeyscurrentvalue%
        \ifx#1\pgfkeysnovalue\pgfkeysalso{
            drawmatrix/.append style/.expand once={\@currname}
        }\else\pgfkeysalso{
            drawmatrix/.append style/.expand twice={%
                \expandafter\@currname\expandafter=\@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,
    }
}
\newcommand\drawmatrixset[1]{\pgfqkeys{/drawmatrix}{#1}}
\newcommand\drawmatrix[2][]{{%
    \ifmmode\def\@labeltext{$#2$}\else\def\@labeltext{#2}\fi%
    \drawmatrixset{#1}%
    \ifdrawmatrix@externalize\else%
        \ifx\tikz@library@external@loaded\undefined\else%
            \tikzset{external/export=false}%
        \fi%
    \fi%
    \pgfqkeys{/drawmatrix}{
        height/.get=\@height,
        width/.get=\@width,
        lower bandwidth/.get=\@lowerbandwidth,
        upper bandwidth/.get=\@upperbandwidth,
        offset height/.get=\@offsetheight,
        offset width/.get=\@offsetwidth,
        bbox height/.get=\@bboxheight,
        bbox width/.get=\@bboxwidth,
    }%
    \pgfmathsetmacro\@height{\@height + 0.0}%
    \pgfmathsetmacro\@width{\@width + 0.0}%
    \pgfmathsetmacro\@minsize{min(\@width, \@height)}%
    \pgfmathsetmacro\@zero{0.0}%
    \expandafter\ifx\@lowerbandwidth\pgfkeysnovalue%
        \edef\@lowerbandwidth{\@minsize}%
    \fi%
    \expandafter\ifx\@upperbandwidth\pgfkeysnovalue%
        \edef\@upperbandwidth{\@minsize}%
    \fi%
    \pgfmathsetmacro\@lowerbandwidth{min(\@minsize, \@lowerbandwidth)}%
    \pgfmathsetmacro\@upperbandwidth{min(\@minsize, \@upperbandwidth)}%
    \expandafter\ifx\@bboxheight\pgfkeysnovalue%
        \pgfmathsetmacro\@bboxheight{\@height + \@offsetheight}%
    \fi%
    \expandafter\ifx\@bboxwidth\pgfkeysnovalue%
        \pgfmathsetmacro\@bboxwidth{\@width + \@offsetwidth}%
    \fi%
    \begin{tikzpicture}[/drawmatrix/every picture, /drawmatrix/picture]
        \node[/drawmatrix/every bbox, /drawmatrix/bbox,
            minimum height=\@bboxheight cm,
            minimum width=\@bboxwidth cm] {};
        \path (drawmatrix bbox.north west)
            ++(\@offsetwidth, -\@offsetheight)
            ++(.5\pgflinewidth, -.5\pgflinewidth)
            coordinate (drawmatrix north west)
            ++(\@width, 0)
            +(-\@minsize + \@upperbandwidth, 0)
            coordinate (drawmatrix north)
            +(0, -\@minsize + \@upperbandwidth)
            coordinate (drawmatrix east)
            ++(0, -\@height)
            coordinate (drawmatrix south east)
            ++(-\@width, 0)
            +(\@minsize - \@lowerbandwidth, 0)
            coordinate (drawmatrix south)
            +(0, \@minsize - \@lowerbandwidth)
            coordinate (drawmatrix west);
        \filldraw[/drawmatrix/every drawmatrix, /drawmatrix/drawmatrix]
            (drawmatrix north west)
            \ifx\@upperbandwidth\@zero
                \ifx\@width\@minsize\else -- (drawmatrix north) \fi
                \ifx\@height\@minsize\else -- (drawmatrix east) \fi
            \else
                -- (drawmatrix north)
                \ifx\@upperbandwidth\@minsize\else -- (drawmatrix east) \fi
            \fi
            -- (drawmatrix south east)
            \ifx\@lowerbandwidth\@zero
                \ifx\@width\@minsize\else -- (drawmatrix south) \fi
                \ifx\@height\@minsize\else -- (drawmatrix west) \fi
            \else
                -- (drawmatrix south)
                \ifx\@lowerbandwidth\@minsize\else -- (drawmatrix west) \fi
            \fi
            -- cycle;
        \node[minimum height=\@height cm, minimum width=\@width cm,
            anchor=north west] at (drawmatrix north west)
            (drawmatrix matrix) {};
        \node[/drawmatrix/every label, /drawmatrix/label] {\@labeltext};
    \end{tikzpicture}%
}}
\endinput
%%
%% End of file `drawmatrix.sty'.
