\definecolor{darkgreen}{rgb}{0,.5,0}

\renewcommand{\t}{\mathsf T}
\newcommand{\conv}{*}
\newcommand{\adj}[1]{#1^*}
\newcommand{\bigo}[1]{\mathcal O(#1)}
\newcommand{\commut}[2]{[#1, #2]}
\newcommand{\correlation}[1]{\left< #1 \right>}
\newcommand{\dimensionless}[1]{\mathrm{#1}}
\newcommand{\dsurf}{\mathrm d \sigma}
\newcommand{\dummy}{{\,\cdot\,}}
% \newcommand{\dummy}{\mathord{\color{black!33}\bullet}}%
\newcommand{\eip}[2]{\left\langle\left\langle{#1,#2}\right\rangle\right\rangle}
\newcommand{\enorm}[1]{|||#1|||}
\newcommand{\expect}[0]{\mathbf{E}}
\newcommand{\var}[0]{\mathbf{V}}
\newcommand{\filtration}[0]{\mathcal}
\newcommand{\grad}[0]{\nabla}
\newcommand{\hermitef}[1]{\mathbf #1}
\newcommand{\hermite}[1]{\mathbf{#1}}
\newcommand{\iip}[2]{(\!(#1, #2)\!)}
\newcommand{\inter}{\, \cap \,}
\newcommand{\kron}[2]{\delta_{#1,#2}}
\newcommand{\laplacian}{\Delta}
\newcommand{\littleo}[1]{o(#1)}
\newcommand{\lploc}[2]{L_{loc}^{#1}\left(#2\right)}
\newcommand{\mat}[1]{\boldsymbol{\mathbf #1}}
\newcommand{\nat}[0]{\mathbf{N}}
\newcommand{\op}[0]{\mathcal}
\newcommand{\operator}[0]{\mathcal}
\newcommand{\orth}[1]{#1^\perp}
\newcommand{\poly}[1]{\mathbf{P}_{#1}}
\newcommand{\proba}[0]{\mathbf{P}}
% \newcommand{\proj}[2]{\pi\left(#1,#2\right)}
\newcommand{\proj}[2]{\Pi_d #1}
\newcommand{\real}[0]{\mathbf{R}}
\newcommand{\red}[1]{\textcolor{darkred}{#1}}
\newcommand{\schwartz}[1]{S (#1)}
\newcommand{\seq}[4]{{\left\{#1_{#2}\right\}}_{#2=#3}^{#4}}
\newcommand{\smooth}[1]{C^\infty(#1)}
\newcommand{\test}[1]{C^\infty_c (#1)}
\newcommand{\torus}[0]{\mathbf{T}}
\newcommand{\vect}[1]{\boldsymbol{\mathbf #1}}
\renewcommand{\det}[1]{\left| #1 \right|}
\renewcommand{\d}[0]{\mathrm{d}}
% \renewcommand{\alert}[1]{\textcolor{darkgreen}{#1}}

% Cahn-Hilliard
\newcommand{\energyA}[0]{\frac{1}{\varepsilon}}
\newcommand{\energyB}[0]{\varepsilon}

\DeclareMathOperator{\trace}{tr}
\DeclareMathOperator{\e}{e}
\DeclareMathOperator{\support}{supp}
\DeclareMathOperator{\sign}{sign}
\DeclareMathOperator{\id}{id}
\DeclareMathOperator{\Span}{span}
\DeclareMathOperator{\gateau}{Grad}
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator*{\argmax}{arg\,max}

\DeclareDocumentCommand\abs{s m} {\IfBooleanTF{#1}{|#2|}{\left|#2\right|}}
\DeclareDocumentCommand\cont{o m o} {C\IfNoValueF{#1}{^{#1}}(#2\IfNoValueF{#3}{;#3})}
\DeclareDocumentCommand\contc{o m o} {C_c\IfNoValueF{#1}{^{#1}}(#2\IfNoValueF{#3}{;#3})}
\DeclareDocumentCommand\sobolev{m m o} {H^{#1}(#2 \IfNoValueF{#3}{,#3})}
\DeclareDocumentCommand\lp{m m o} {L^{#1}\left(#2 \IfNoValueF{#3}{,#3}\right)}
\DeclareDocumentCommand\norm{s m o} {\IfBooleanTF{#1}{\|#2\|}{\left\|#2\right\|}\IfNoValueF{#3}{_{#3}}}
\DeclareDocumentCommand\seminorm{s m o} {\IfBooleanTF{#1}{\|#2\|}{\left\|#2\right\|}\IfNoValueF{#3}{_{#3}}}
\DeclareDocumentCommand\ip{m m o o} {\left\langle{#1,#2}\right\rangle\IfNoValueF{#3}{_{#3 \IfNoValueF{#4}{,#4}}}}
\DeclareDocumentCommand\dup{m m o} {\left\langle{#1,#2}\right\rangle\IfNoValueF{#3}{_{#3', #3}}}
\DeclareDocumentCommand\gaussian{O{0} O{I}} {g_{#1, #2}}

% Derivative
\makeatletter
\DeclareDocumentCommand \derivative{s m o m}{%
    \def\@der{\IfBooleanTF{#1}{\mathrm{d}}{\partial}}
    \def\@default{%
        \mathchoice{%
                \frac{%
                    \@der\ifnum\pdfstrcmp{#2}{1}=0\else^{#2}\fi {\IfNoValueTF{#3}{}{#3}}
                }{%
                    \@for\@token:={#4}\do{\@der \@token}
                }
            } {%
                \@for\@token:={#4}\do{\@der_\@token} \IfNoValueTF{#3}{}{#3}
            } {} {}
    }
    \IfBooleanTF{#1}{\IfNoValueTF{#3}{\@default}{%
                #3%
                \ifnum\pdfstrcmp{#2}{1}=0'\else%
                \ifnum\pdfstrcmp{#2}{2}=0''\else%
                \ifnum\pdfstrcmp{#2}{3}=0'''\else%
                \ifnum\pdfstrcmp{#2}{4}=0^{(iv)}\else^{(#2)}\fi\fi\fi\fi
            }
        }{\@default}
}
\makeatother
