\ProvidesPackage{mathy}[mathier macros]

\usepackage{amsmath,amsthm,amssymb,amsfonts}    %general math
\usepackage[margin=1in]{geometry}               %no ridiculous margins
\usepackage{enumitem}                           
\usepackage{cancel}                             %\cancel? idk
\usepackage[T1]{fontenc}                        %inexact diff
\usepackage[utf8]{inputenc}
\usepackage{harpoon}                            %better vector arrow
\usepackage{esint}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage[version=4]{mhchem}                  %chem eqn
\usepackage{chemfig}				%benzene qed; chemical structures
\usepackage{pdfpages}                           %insert pdf
\usepackage{ifthen}
\usepackage{siunitx}                            %SI units
\usepackage{mathtools}
\usepackage{textcomp}
\usepackage{tensor}                             %indices galore
\usepackage{bbm}                                %more blackboard char
\usepackage{caption}                            %for multicol figs
\usepackage[bookmarksdepth=3]{hyperref}         %hyperlinks
\usepackage{booktabs}				%so my linter doesn't yell at me
\usepackage{mathrsfs}
\usepackage{multicol}
\usepackage{slashed}
\let\oldslash\slash
\renewcommand{\slash}{\slashed}
\newcommand{\s}{\slashed}
\usepackage{interval}
\intervalconfig{soft open fences}
\let\oi\ointerval
\let\li\linterval
\let\ri\rinterval
\let\ci\interval
\DeclareUnicodeCharacter{2212}{-}               %why is this never defined
\DeclareMathSymbol{*}{\mathbin}{symbols}{"01}   %asterisk is dot

\setlength{\parskip}{.5em}

\usepackage[normalem]{ulem}
\let\pd\partial%chktex 1
\newcommand{\tpd}[2]{\partial{#1}/\partial{#2}}
\let\tpder\tpd
%inexact differential
\newcommand{\dbar}[1]{\ensuremath{\operatorname{\text{\dj}}\!{#1}\,}}

\let\oldast\ast
\renewcommand{\ast}{^{\oldast}}
\newcommand{\adj}{\ensuremath{^{\dagger}}}

%math formatting
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{prop}[thm]{Proposition}
\newtheorem{cor}{Corollary}[thm]
\newtheorem{lemma}[thm]{Lemma}
\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\newtheorem*{notation}{Notation}
\newtheorem*{claim}{Claim}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}


\let\then\implies
\let\neth\impliedby
 
%number types
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\FF}{\mathbb{F}}
\let\mc\mathcal
\let\ms\mathscr
\let\bb\mathbb
%complex
\newcommand{\C}{\mathbb{C}}
\renewcommand{\Re}{\operatorname{Re}}
\renewcommand{\Im}{\operatorname{Im}}
\newcommand{\hc}{\text{h.c.}}

%hyperbolic trig
\newcommand{\arsinh}{\operatorname{arsinh}}
\newcommand{\arcosh}{\operatorname{arcosh}}
\newcommand{\artanh}{\operatorname{artanh}}
\newcommand{\arsech}{\operatorname{arsech}}
\newcommand{\arcsch}{\operatorname{arcsch}}
\newcommand{\arcoth}{\operatorname{arcoth}}


%linear map
\renewcommand{\L}{\mathcal{L}}
\newcommand{\im}{\operatorname{im}}

%derivatives at point
\newcommand\at[2]{\left.#1\right|_{#2}}
%integral bounds
\newcommand\eval[3]{\left[\left.#1\right|_{#2}^{#3}\right]}
\newcommand\deval[3]{\left.#1\right|_{#2}^{#3}}

%text formatting
\let\bf\textbf
\let\it\textit

%basic vectors
\newcommand{\vv}[1]{\vec{\ensuremath{#1}}}
\let\v\undefined
\newcommand{\v}[1]{\vv{\mathbf{#1}}}
\newcommand{\vb}[1]{\mathbf{#1}}
\newcommand{\vi}[1]{\vv{\mathit{#1}}}
\newcommand{\vk}[1]{\begin{bmatrix}#1\end{bmatrix}}
\newcommand{\vect}[1]{\left\langle \begin{matrix}#1\end{matrix} \right\rangle}
\newcommand{\ih}{\hat{\imath}}
\newcommand{\jh}{\hat{\jmath}}
\newcommand{\kh}{\hat{k}}
\newcommand{\e}[1]{\ensuremath{\,\hat{e}_{#1}}}

%vector functions
\let\cross\times
\let\x\times
\let\tp\otimes
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}

%group stuff
\let\actson\curvearrowright
\let\nsubg\trianglelefteq
\let\nsupg\trianglerighteq
\newcommand{\Hom}{\operatorname{Hom}}
\newcommand{\End}{\operatorname{End}}
\newcommand{\Aut}{\operatorname{Aut}}
\let\la\mathfrak
\newcommand{\ad}{\operatorname{ad}}

%polynomial stuff
\newcommand{\lt}{\operatorname{LT}}

%abs value
\newcommand{\abs}[1]{\left|#1\right|}

%augmented matrix; parameter is number of rows before augment
\newenvironment{amatrix}[1]{%
  \left[\begin{array}{@{}*{#1}{c}|c@{}}
}{%
  \end{array}\right]
}


%benzene as qed symbol
\usepackage{stackengine,wasysym,scalerel}

\def\smallbenz{\scalerel*{\kern-3pt%
\stackinset{c}{0.95pt}{b}{2.2pt}{-}{%
\rotatebox[origin=center]{120}{\stackinset{c}{-0.4pt}{b}{.3pt}{-}{%
\rotatebox[origin=center]{120}{\stackinset{c}{.24pt}{b}{-1.5pt}{-}{%
\hexagon}}}}}}{\rule[-0.75\baselineskip]{1pt}{1.5\baselineskip}}\kern-3pt}

\renewcommand{\qedsymbol}{\smallbenz}



\newcommand\pder[2]{\frac{\partial #1}{\partial #2}}
\let\pd\partial
\newcommand\cd{\mathrm D}

\newcommand\dder[2]{\frac{\delta #1}{\delta #2}}

\makeatletter
\newcommand\der[2]{%
    \begingroup
    \@temptokena{\@gobble}%
    \@tempcnta\z@
    \@for\var:=#2\do{%
        \expandafter\@der\var\relax
    }%
    \ensuremath{\frac{\text{d}
    \ifnum\@tempcnta>\@ne
        ^{\the\@tempcnta}%
    \fi
    #1}{\the\@temptokena}}%
    \endgroup
}

\def\@der#1#2\relax{%
    \ifx\relax#2\relax
        \advance\@tempcnta by \@ne
        \@temptokena\expandafter{\the\@temptokena\,\text{d}{#1}}%
    \else
        \advance\@tempcnta by #2\relax
        \@temptokena\expandafter{\the\@temptokena\,\text{d}{#1}^{#2}}%
    \fi
}

\makeatother

\newcommand\del\nabla


%differential

\renewcommand{\d}[2][]{%
   \ifthenelse{ \equal{#1}{} }
      {\ensuremath{\operatorname{d}\!{#2}}}
      {\ensuremath{\operatorname{d}^{#1}\!{#2}}}
}
\newcommand{\dm}[2][]{%
   \ifthenelse{ \equal{#1}{} }
      {\ensuremath{\operatorname{d}\!{#2}\,}}
      {\ensuremath{\operatorname{d}^{#1}\!{#2}\,}}
}

\newcommand{\dk}[2][]{%
   \ifthenelse{ \equal{#1}{} }
   {\ensuremath{\frac{\operatorname{d}\!{#2}}{(2\pi)}}}
   {\ensuremath{\frac{\operatorname{d}^{#1}\!{#2}}{(2\pi)^{#1}}}}
}
	
\newcommand{\D}[2][]{%
   \ifthenelse{ \equal{#1}{} }
      {\ensuremath{\operatorname{D}\!{#2}}}
      {\ensuremath{\operatorname{D #1}\!{#2}}}
}

\newcommand{\Dm}[2][]{%
   \ifthenelse{ \equal{#1}{} }
      {\ensuremath{\operatorname{D}\!{#2}\,}}
      {\ensuremath{\operatorname{D}^{#1}\!{#2}\,}}
}

%chapter epigraphs
\makeatletter
\newenvironment{epigraph}[2][2em]
  {\par\setlength{\@tempdima}{#1}%
   \def\epigraph@author{#2}%
   \parshape 1 \@tempdima \dimexpr\textwidth-2\@tempdima\relax%
   \itshape}
   {\ifthenelse{\equal{\epigraph@author}{}}{}{\par\normalfont\hfill--\ \epigraph@author\hspace*{\@tempdima}\par}
   }
\makeatother

%units

\sisetup{inter-unit-product =\ensuremath{\cdot}}
\setlength{\parindent}{0pt}

%quick greek
\let\p\psi
\let\P\Psi
\let\f\phi
\let\F\Phi
\let\vf\varphi
\let\ve\varepsilon
\let\ep\epsilon

%mathscript
\let\ms

%braket

\let\b\undefined
\let\k\undefined
\DeclarePairedDelimiter\b{\langle}{\rvert}
\DeclarePairedDelimiter\k{\lvert}{\rangle}
\DeclarePairedDelimiterX\bk[2]{\langle}{\rangle}{#1 \delimsize\vert #2}


\newcommand{\diagram}{\textcolor{red}{\{diagram\}}}

\allowdisplaybreaks


\DeclareMathOperator{\sgn}{sgn}

\let\to\rightarrow

\let\h\hat



\newcommand{\T}{^\intercal}

\let\up\uparrow
\let\dn\downarrow

\DeclareMathOperator{\tr}{tr}


%Boxed aside environment. Note: you cannot have a float (i.e. table or figure environment) inside the aside. Instead, use the \captionsetup{type=table}\captionof{table/float}{caption}\label{tab/fig:ref} macros
\newsavebox{\mybox}
\newenvironment{aside}[1][\unskip]
{\begin{center}\begin{lrbox}{\mybox}\centering\begin{minipage}{\textwidth-.6em}\begin{minipage}{.98\textwidth}\vspace{.5em}\begin{center}\underbar{#1}\end{center}\vspace{1em}}
{\vspace{.5em}\end{minipage}\end{minipage}\end{lrbox}\fbox{\usebox{\mybox}}\end{center}}


%nCr
\newcommand{\ncr}[2]{\begin{pmatrix}#1\\#2\end{pmatrix}}

%Griffiths r
\usepackage{calligra}
\DeclareMathAlphabet{\mathcalligra}{T1}{calligra}{m}{n}
\DeclareFontShape{T1}{calligra}{m}{n}{<->s*[2.2]callig15}{}

\newcommand{\sr}{\mathcalligra{r}\,}
\newcommand{\br}{\pmb{\mathcalligra{r}}\,}


\newcommand{\tb}[1]{\stackrel{\leftrightarrow}{\vb{#1}}}
