
% Functions with (optional) paranthesis
% 1: The function (like \exp, \sin etc.)
% 2: The argument (optional)
% If an argument is provided, it is wrapped in paranthesis.
\newcommand\CmdWithParenthesis[2]{
    \ifstrequal{#2}{\relax}{
        #1
    }{
        #1\left(#2\right)
    }
}
\newcommand\CmdInParenthesis[2]{
    \ifstrequal{#2}{\relax}{
        #1
    }{
        \left(#1 #2\right)
    }
}


% COMMON SYMBOLS WITH SUPER/SUBSCRIPTS, VECTOR ARROWS ETC.
% \def\laplace{\Delta} % Laplace operator
\newcommand\laplace{\bigtriangleup} % Laplace operator
% symbols
\newcommand\Grad{\vec{\nabla}}       
\newcommand\Div {\vec{\nabla} \cdot} 
\newcommand\Rot {\vec{\nabla} \times}
% symbols with parens
\newcommand\GradS[1][\relax]{\CmdInParenthesis{\Grad}{#1}}
\newcommand\DivS [1][\relax]{\CmdInParenthesis{\Div} {#1}}
\newcommand\RotS [1][\relax]{\CmdInParenthesis{\Rot} {#1}}
% text with parens
\newcommand\GradT[1][\relax]{\CmdWithParenthesis{\text{grad}\,}{#1}}
\newcommand\DivT[1][\relax] {\CmdWithParenthesis{\text{div}\,} {#1}}
\newcommand\RotT[1][\relax] {\CmdWithParenthesis{\text{rot}\,} {#1}}
\newcommand\kB{k_\text{B}}         % boltzmann
\newcommand\NA{N_\text{A}}         % avogadro
\newcommand\EFermi{E_\text{F}}     % fermi energy
\newcommand\Efermi{E_\text{F}}     % fermi energy
\newcommand\Evalence{E_\text{v}}   % val vand energy
\newcommand\Econd{E_\text{c}}      % cond. band nergy
\newcommand\Egap{E_\text{gap}}     % band gap energy
\newcommand\Evac{E_\text{vac}}     % vacuum energy
\newcommand\masse{m_\text{e}}      % electron mass
\newcommand\Four{\mathcal{F}}      % Fourier transform
\newcommand\Lebesgue{\mathcal{L}}  % Lebesgue
% \newcommand\O{\mathcal{O}}         % order
\newcommand\PhiB{\Phi_\text{B}}    % mag. flux
\newcommand\PhiE{\Phi_\text{E}}    % electric flux
\newcommand\nreal{n^{\prime}}            % refraction real part
\newcommand\ncomplex{n^{\prime\prime}}        % refraction index complex part
\newcommand\I{i}                   % complex/imaginary unit
\newcommand\crit{\text{crit}}      % crit (for subscripts)
\newcommand\muecp{\overline{\mu}}  % electrochemical potential
% \newcommand\pH{\text{pH}}          % pH, already defined by one of the chem packages
\newcommand\rfactor{\text{rf}}     % rf roughness_factor


% SYMBOLS
\newcommand\R{\mathbb{R}}
\newcommand\C{\mathbb{C}}
\newcommand\Z{\mathbb{Z}}
\newcommand\N{\mathbb{N}}
\newcommand\id{\mathbb{1}}
% caligraphic
\newcommand\E{\mathcal{E}}  % electric field
% upright, vector
\newcommand\txA{\text{A}}  \newcommand\vecA{\vec{A}}  \newcommand\matA{\mat{A}}  \newcommand\tenA{\ten{A}}  
\newcommand\txB{\text{B}}  \newcommand\vecB{\vec{B}}  \newcommand\matB{\mat{B}}  \newcommand\tenB{\ten{B}}
\newcommand\txC{\text{C}}  \newcommand\vecC{\vec{C}}  \newcommand\matC{\mat{C}}  \newcommand\tenC{\ten{C}}
\newcommand\txD{\text{D}}  \newcommand\vecD{\vec{D}}  \newcommand\matD{\mat{D}}  \newcommand\tenD{\ten{D}}
\newcommand\txE{\text{E}}  \newcommand\vecE{\vec{E}}  \newcommand\matE{\mat{E}}  \newcommand\tenE{\ten{E}}
\newcommand\txF{\text{F}}  \newcommand\vecF{\vec{F}}  \newcommand\matF{\mat{F}}  \newcommand\tenF{\ten{F}}
\newcommand\txG{\text{G}}  \newcommand\vecG{\vec{G}}  \newcommand\matG{\mat{G}}  \newcommand\tenG{\ten{G}}
\newcommand\txH{\text{H}}  \newcommand\vecH{\vec{H}}  \newcommand\matH{\mat{H}}  \newcommand\tenH{\ten{H}}
\newcommand\txI{\text{I}}  \newcommand\vecI{\vec{I}}  \newcommand\matI{\mat{I}}  \newcommand\tenI{\ten{I}}
\newcommand\txJ{\text{J}}  \newcommand\vecJ{\vec{J}}  \newcommand\matJ{\mat{J}}  \newcommand\tenJ{\ten{J}}
\newcommand\txK{\text{K}}  \newcommand\vecK{\vec{K}}  \newcommand\matK{\mat{K}}  \newcommand\tenK{\ten{K}}
\newcommand\txL{\text{L}}  \newcommand\vecL{\vec{L}}  \newcommand\matL{\mat{L}}  \newcommand\tenL{\ten{L}}
\newcommand\txM{\text{M}}  \newcommand\vecM{\vec{M}}  \newcommand\matM{\mat{M}}  \newcommand\tenM{\ten{M}}
\newcommand\txN{\text{N}}  \newcommand\vecN{\vec{N}}  \newcommand\matN{\mat{N}}  \newcommand\tenN{\ten{N}}
\newcommand\txO{\text{O}}  \newcommand\vecO{\vec{O}}  \newcommand\matO{\mat{O}}  \newcommand\tenO{\ten{O}}
\newcommand\txP{\text{P}}  \newcommand\vecP{\vec{P}}  \newcommand\matP{\mat{P}}  \newcommand\tenP{\ten{P}}
\newcommand\txQ{\text{Q}}  \newcommand\vecQ{\vec{Q}}  \newcommand\matQ{\mat{Q}}  \newcommand\tenQ{\ten{Q}}
\newcommand\txR{\text{R}}  \newcommand\vecR{\vec{R}}  \newcommand\matR{\mat{R}}  \newcommand\tenR{\ten{R}}
\newcommand\txS{\text{S}}  \newcommand\vecS{\vec{S}}  \newcommand\matS{\mat{S}}  \newcommand\tenS{\ten{S}}
\newcommand\txT{\text{T}}  \newcommand\vecT{\vec{T}}  \newcommand\matT{\mat{T}}  \newcommand\tenT{\ten{T}}
\newcommand\txU{\text{U}}  \newcommand\vecU{\vec{U}}  \newcommand\matU{\mat{U}}  \newcommand\tenU{\ten{U}}
\newcommand\txV{\text{V}}  \newcommand\vecV{\vec{V}}  \newcommand\matV{\mat{V}}  \newcommand\tenV{\ten{V}}
\newcommand\txW{\text{W}}  \newcommand\vecW{\vec{W}}  \newcommand\matW{\mat{W}}  \newcommand\tenW{\ten{W}}
\newcommand\txX{\text{X}}  \newcommand\vecX{\vec{X}}  \newcommand\matX{\mat{X}}  \newcommand\tenX{\ten{X}}
\newcommand\txY{\text{Y}}  \newcommand\vecY{\vec{Y}}  \newcommand\matY{\mat{Y}}  \newcommand\tenY{\ten{Y}}
\newcommand\txZ{\text{Z}}  \newcommand\vecZ{\vec{Z}}  \newcommand\matZ{\mat{Z}}  \newcommand\tenZ{\ten{Z}}

\newcommand\txa{\text{a}}  \newcommand\veca{\vec{a}}  \newcommand\mata{\mat{a}}  \newcommand\tena{\ten{a}}
\newcommand\txb{\text{b}}  \newcommand\vecb{\vec{b}}  \newcommand\matb{\mat{b}}  \newcommand\tenb{\ten{b}}
\newcommand\txc{\text{c}}  \newcommand\vecc{\vec{c}}  \newcommand\matc{\mat{c}}  \newcommand\tenc{\ten{c}}
\newcommand\txd{\text{d}}  \newcommand\vecd{\vec{d}}  \newcommand\matd{\mat{d}}  \newcommand\tend{\ten{d}}
\newcommand\txe{\text{e}}  \newcommand\vece{\vec{e}}  \newcommand\mate{\mat{e}}  \newcommand\tene{\ten{e}}
\newcommand\txf{\text{f}}  \newcommand\vecf{\vec{f}}  \newcommand\matf{\mat{f}}  \newcommand\tenf{\ten{f}}
\newcommand\txg{\text{g}}  \newcommand\vecg{\vec{g}}  \newcommand\matg{\mat{g}}  \newcommand\teng{\ten{g}}
\newcommand\txh{\text{h}}  \newcommand\vech{\vec{h}}  \newcommand\mtxh{\mat{h}}  \newcommand\tenh{\ten{h}}
\newcommand\txi{\text{i}}  \newcommand\veci{\vec{i}}  \newcommand\mati{\mat{i}}  \newcommand\teni{\ten{i}}
\newcommand\txj{\text{j}}  \newcommand\vecj{\vec{j}}  \newcommand\matj{\mat{j}}  \newcommand\tenj{\ten{j}}
\newcommand\txk{\text{k}}  \newcommand\veck{\vec{k}}  \newcommand\matk{\mat{k}}  \newcommand\tenk{\ten{k}}
\newcommand\txl{\text{l}}  \newcommand\vecl{\vec{l}}  \newcommand\matl{\mat{l}}  \newcommand\tenl{\ten{l}}
\newcommand\txm{\text{m}}  \newcommand\vecm{\vec{m}}  \newcommand\matm{\mat{m}}  \newcommand\tenm{\ten{m}}
\newcommand\txn{\text{n}}  \newcommand\vecn{\vec{n}}  \newcommand\matn{\mat{n}}  \newcommand\tenn{\ten{n}}
\newcommand\txo{\text{o}}  \newcommand\veco{\vec{o}}  \newcommand\mato{\mat{o}}  \newcommand\teno{\ten{o}}
\newcommand\txp{\text{p}}  \newcommand\vecp{\vec{p}}  \newcommand\matp{\mat{p}}  \newcommand\tenp{\ten{p}}
\newcommand\txq{\text{q}}  \newcommand\vecq{\vec{q}}  \newcommand\matq{\mat{q}}  \newcommand\tenq{\ten{q}}
\newcommand\txr{\text{r}}  \newcommand\vecr{\vec{r}}  \newcommand\matr{\mat{r}}  \newcommand\tenr{\ten{r}}
\newcommand\txs{\text{s}}  \newcommand\vecs{\vec{s}}  \newcommand\mats{\mat{s}}  \newcommand\tens{\ten{s}}
\newcommand\txt{\text{t}}  \newcommand\vect{\vec{t}}  \newcommand\matt{\mat{t}}  \newcommand\tent{\ten{t}}
\newcommand\txu{\text{u}}  \newcommand\vecu{\vec{u}}  \newcommand\matu{\mat{u}}  \newcommand\tenu{\ten{u}}
\newcommand\txv{\text{v}}  \newcommand\vecv{\vec{v}}  \newcommand\matv{\mat{v}}  \newcommand\tenv{\ten{v}}
\newcommand\txw{\text{w}}  \newcommand\vecw{\vec{w}}  \newcommand\matw{\mat{w}}  \newcommand\tenw{\ten{w}}
\newcommand\txx{\text{x}}  \newcommand\vecx{\vec{x}}  \newcommand\matx{\mat{x}}  \newcommand\tenx{\ten{x}}
\newcommand\txy{\text{y}}  \newcommand\vecy{\vec{y}}  \newcommand\maty{\mat{y}}  \newcommand\teny{\ten{y}}
\newcommand\txz{\text{z}}  \newcommand\vecz{\vec{z}}  \newcommand\matz{\mat{z}}  \newcommand\tenz{\ten{z}}

% SPACES
\newcommand\sdots{\,\dots\,}
\newcommand\qdots{\quad\dots\quad}
\newcommand\qRarrow{\quad\Rightarrow\quad}

% ANNOTATIONS
% put an explanation above an equal sign
% [1]: equality sign (or anything else)
% 2: text (not in math mode!)
\newcommand{\explUnderEq}[2][=]{%
    \underset{\substack{\uparrow\\\mathrlap{\text{\hspace{-1em}#2}}}}{#1}}
\newcommand{\explOverEq}[2][=]{%
    \overset{\substack{\mathrlap{\text{\hspace{-1em}#2}}\\\downarrow}}{#1}}
\newcommand{\eqnote}[1]{
    \text{\color{fg2}#1}
}


% DELIMITERS
% not using DeclarePairedDelmiter to always get scaling
\newcommand{\norm}[1]{\left\lVert #1 \right\rVert}
\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
\newcommand{\floor}[1]{\left\lfloor#1\right\rfloor}
\newcommand{\ceil}[1]{\left\lceil#1\right\rceil}

% OPERATORS
% * places subset under the word instead of next to it
\DeclareMathOperator{\e}{e}
\def\T{\text{T}}  % transposed
\DeclareMathOperator{\sgn}{sgn}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\const}{const}
\DeclareMathOperator{\erf}{erf}
\DeclareMathOperator{\erfc}{erfc}
\DeclareMathOperator{\cov}{cov}

\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator*{\argmax}{arg\,max}
% \DeclareMathOperator{\div}{div}
% \DeclareMathOperator{\grad}{grad}
% \DeclareMathOperator{\rot}{rot}
% \DeclareMathOperator{\arcsin}{arcsin}
% \DeclareMathOperator{\arccos}{arccos}
% \DeclareMathOperator{\arctan}{arctan}
\DeclareMathOperator{\arccot}{arccot}
\DeclareMathOperator{\arsinh}{arsinh}
\DeclareMathOperator{\arcosh}{arcosh}
\DeclareMathOperator{\artanh}{artanh}
\DeclareMathOperator{\arcoth}{arcoth}
% diff, for integrals and stuff
% \DeclareMathOperator{\dd}{d}
\renewcommand*\d{\mathop{}\!\mathrm{d}}
% times 10^{x}
\newcommand\xE[1]{\cdot 10^{#1}}
\newcommand\Exp[1]{\CmdWithParenthesis{\exp}{#1}}
\newcommand\Sin[1]{\CmdWithParenthesis{\sin}{#1}}
\newcommand\Cos[1]{\CmdWithParenthesis{\cos}{#1}}
\newcommand\Ln[1]{\CmdWithParenthesis{\ln}{#1}}
\newcommand\Log[1]{\CmdWithParenthesis{\log}{#1}}
\newcommand\Order[1]{\CmdWithParenthesis{\mathcal{O}}{#1}}

% VECTOR, MATRIX and TENSOR
% use vecAr to force an arrow
\NewCommandCopy{\vecAr}{\vec}
% extra {} assure they can b directly used after _
%% arrow/underline
\newcommand\mat[1]{{\ensuremath{\underline{#1}}}}
\renewcommand\vec[1]{{\ensuremath{\vecAr{#1}}}}
\newcommand\ten[1]{{\ensuremath{[#1]}}}
\newcommand\complex[1]{{\ensuremath{\tilde{#1}}}}
%% bold
% \newcommand\mat[1]{{\ensuremath{\bm{#1}}}}
% \renewcommand\vec[1]{{\ensuremath{\bm{#1}}}}
