% These are some files for providing matrices etc.
%\usepackage{amsmath,amssymb}
\usepackage{mathtools} % provides a few more useful * formed of matrices.
% The following adds the ability to add array formatting (bars etc) in
% matrices.  To understand it see
% http://tex.stackexchange.com/questions/36757/how-does-this-macro-for-augmented-matrices-work
\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\makeatother
%
% The following defines a zero matrix symbol (to distinguish it from
% a zero number we make it slanted)
\newcommand\zeromat{\ensuremath{\mathit{0}}}
% The following symbol is for matrix rank
\newcommand\rank[1]{\ensuremath{\mathrm{rank}({#1})}}
% The following symbol is for the determinant of a matrix with no parentheses.
% It is already defined in one of the included packages.
%\newcommand\det[1]{\ensuremath{\mathrm{det}{#1}}}
% The following symbol is for the determinant of a matrix (in functional form)
\newcommand\detf[1]{\ensuremath{\mathrm{det}\left({#1}\right)}}
%
% The following symbol is for the adjugate (adjunct or classical adjoint) of A
% in both a basic and functional form
\newcommand\adj[1]{\ensuremath{\mathrm{adj\,}{#1}}}
\newcommand\adjf[1]{\ensuremath{\mathrm{adj}\left({#1}\right)}}
%
% The following allows one to circle entries
\usepackage{tikz}
% This package allows drawing lines conveniently in a matrix
\usetikzlibrary{matrix}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
% Define vector to be bold math.  We'll use lvec for ``local vec''
% to distinguish from \vec which occurs elsewhere and is used at one
% point to represent a handwritten vector.
\newcommand\lvec[1]{\ensuremath{\bm{#1}}}

% Define the a local norm (length) for vectors
\newcommand\lnorm[1]{\ensuremath{\left\lVert{#1}\right\rVert}}
% The following provides the ability to put slashes through arguments.
\usepackage{cancel}
%Used for projection notation
\newcommand{\vectorproj}[2]{\ensuremath{\mathrm{proj}_{\lvec{#1}}\lvec{#2}}}
% The following is for vector projection when the arguments are more
% complicated and we do not want to vectorize everything.
\newcommand{\vectorprojplain}[2]{\ensuremath{\mathrm{proj}_{#1}#2}}
%
% Used for span of vectors.
\newcommand{\lspan}{\ensuremath{\mathrm{span}}}
\newcommand\lspanf[1]{\ensuremath{\mathrm{span}\left({#1}\right)}}
% Used for trace of vectors
\newcommand{\ltrace}{\ensuremath{\mathrm{tr}}}
\newcommand\ltracef[1]{\ensuremath{\mathrm{tr}\left({#1}\right)}}
% The following allows for fancy 1 to be used as linear operators.
% Unfortunately it does not allow for a fancy 0.
% While the bbold package allows for 0 it messes up the fonts for mathset
% Upshot is to use \mathset{0} for our 0 operator.  This should be changed.
% Also dsfont could have been used here but it does not provide 0 either.
\usepackage{bbm}
%
% Define symbols for real and imaginary.  Note these do occur in the physics
% package.
\renewcommand{\Re}{\ensuremath{\operatorname{Re}}}
\renewcommand{\Im}{\ensuremath{\operatorname{Im}}}
%
% Complex conjugate and complex conjugate over a long expression
\newcommand\cc[1]{\ensuremath{\overline{#1}}}
%
% Defines a symbol for a row operation involving addition of a multiple of a
% row to another or multiplication of a row by a constant.
% The first argument is the row being changed and the second is the row
% operation.  The convention used here is to put the row being changed first
% and then what it becomes.  Others use the convention where this is flipped
% around.  By defining an operation this is easily changed everywhere.  As an
% example
% \rowop{R_2}{R_2+3R_1}
% \rowop{R_2}{3R_2}
\newcommand\rowop[2]{\ensuremath{{#1}\rightarrow{#2}}}
% The next command is for a row operation involving a swapping of rows
% As an example
% \rowswap{R_2}{R_1}
\newcommand\rowswap[2]{\ensuremath{{#1}\leftrightarrow{#2}}}

% The \rowopmatrix command is for placing row operations beside a
% matrix.  The first argument is the list of row operations separated
% by \\ (include an empty space if there is none for the row).  The
% second argument is the matrix.  As an example
%\rowopmatrix{\rowswap{R_1}{R_2}\\ \\ \rowop{R_3}{R_3+3R_1}}{\begin{bmatrix}[rrr|r] 2&-1&-1&3\\0&3&2&6\\0&6&9&-3 \end{bmatrix}}
% An optional first argument is a space length (like 15em) which forces the
% space of the box surrounding the row operations to be of a fixed length
% rather than calculated.  This is convenient if one wishes to align
% subsequent matrices vertically on the page as one can force any
% necessary space padding by just specifying the same length for all
% the rowopmatrix commands.  One can use $ ... $ in this case on a separate
% line to get the necessary left-justification, but for proper equation
% spacing the construction
% \begin{falign*}& ... &\end{falign*}
% works better.
% See https://tex.stackexchange.com/questions/59214/left-align-math
% The rowopmatrix command requires the calc package to calculate the widths
% of the arguments and xifthen to determine whether the optional argument is
% given. The hspace command is required otherwise the final \\ is not
% recognized if not followed by something.
\usepackage{calc}
\usepackage{xifthen}
\newcommand\rowopmatrix[3][]{%
\ifthenelse{\isempty{#1}}{%No width specified
\parbox{\widthof{{\ensuremath{\begin{matrix}[r]#2\hspace{0em}\end{matrix}}}}}{\hfill\ensuremath{\begin{matrix}[r]#2\hspace{0em}\end{matrix}}}~\parbox{\widthof{\ensuremath{#3}}}{\ensuremath{#3}}%
}{%width specified
\parbox{#1}{\hfill\ensuremath{\begin{matrix}[r]#2\hspace{0em}\end{matrix}}}~\parbox{\widthof{\ensuremath{#3}}}{\ensuremath{#3}}%
}}
%
% The following commands change the location of equation numbering to
% either the left or right in amsmath.  See
% https://tex.stackexchange.com/questions/212085/tag-placing-with-amsmath/212099#212099
\makeatletter
\newcommand{\leqnomode}{\tagsleft@true\let\veqno\@@leqno}
\newcommand{\reqnomode}{\tagsleft@false\let\veqno\@@eqno}
\makeatother
