\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mkessler-mathop}[2021-04-27 - Operator Package]
%%%%%%%%%%%%%%%%%
%Provides some commonly used Operators used in the write-ups of my lecture notes

\newif\if@mkessler@operators@english\@mkessler@operators@englishtrue
\DeclareOption{german}{\@mkessler@operators@englishfalse}
\DeclareOption{english}{\@mkessler@operators@englishtrue}
\DeclareOption*{\PackageWarning{mkessler-operators}{Unknown '\CurrentOption'}}
\ProcessOptions\relax

%%%%%Package dependencies
\RequirePackage{amsmath}
\RequirePackage{bbm}
\RequirePackage{mathtools}

%%%%Different types of operator wrappers:

% For simple math operators that are just to be printed as their name
\newcommand\DeclareSimpleMathOperator[1]{
    \expandafter\providecommand\csname #1\endcsname{\operatorname{#1}}
}

%%%For distributions
%Introduce synonym for \operatorname
\newcommand\mkessler@operators@distribution[1]{\operatorname{#1}}
%Easily declare new distributions
\newcommand\DeclareDistribution[1]{\expandafter\def\csname #1\endcsname{\mkessler@operators@distribution{#1}}}

%%%For categories
%Introduce synonym for \operatorname
\newcommand\mkessler@operators@category[1]{\operatorname{\textbf{#1}}}
%Easily declare new categories
\newcommand\DeclareCategory[1]{\expandafter\def\csname #1\endcsname{\mkessler@operators@category{#1}}}


%%%%%%%%%%% Operators
%Basic commands
\DeclareSimpleMathOperator{id}
\DeclareSimpleMathOperator{im}
\DeclareSimpleMathOperator{Bild}
\DeclareSimpleMathOperator{dom}
\DeclareSimpleMathOperator{Span}
\DeclareSimpleMathOperator{Aut}
\DeclareMathOperator{\rhs}{RHS} %Right hand side of equation
\DeclareMathOperator{\lhs}{LHS} %Left hand side of equation

%%Provide \ggT \gcd \kgV \lcm for 'greatest common denominator' and 'least common multiple'
% \ggT und \gcd, as well as \kgV and \lcm are synonyms and language-aware, so that
% e.g. when the german language option is loaded, even
% \lcm would print 'kgV'
% The starred versions of the four commands will ignore the language option and print their
% exact names (without the *, of course)
\DeclareMathOperator{\@mkessler@operators@ggT}{ggT}
\DeclareMathOperator{\@@mkessler@operators@ggT}{\if@mkessler@operators@english gcd\else ggT\fi}
\def\ggT{\@ifstar\@mkessler@operators@ggT\@@mkessler@operators@ggT}

\DeclareMathOperator{\@mkessler@operators@gcd}{gcd}
\DeclareMathOperator{\@@mkessler@operators@gcd}{\if@mkessler@operators@english gcd\else ggT\fi}
\def\gcd{\@ifstar\@mkessler@operators@gcd\@@mkessler@operators@gcd}

\DeclareMathOperator{\@mkessler@operators@kgV}{kgV}
\DeclareMathOperator{\@@mkessler@operators@kgV}{\if@mkessler@operators@english lcm\else kgV\fi}
\def\kgV{\@ifstar\@mkessler@operators@kgV\@@mkessler@operators@kgV}

\DeclareMathOperator{\@mkessler@operators@lcm}{lcm}
\DeclareMathOperator{\@@mkessler@operators@lcm}{\if@mkessler@operators@english lcm\else kgV\fi}
\def\lcm{\@ifstar\@mkessler@operators@lcm\@@mkessler@operators@lcm}

%Complex numbers
\DeclareMathOperator{\mkessler@impart}{Im}
\renewcommand\Im\mkessler@impart
\DeclareMathOperator{\mkessler@repart}{Re}
\renewcommand\Re\mkessler@impart

%Linear Algebra
\DeclareSimpleMathOperator{Sym}
\DeclareSimpleMathOperator{supp}
\DeclareSimpleMathOperator{sgn}
\DeclareSimpleMathOperator{coker}
\DeclareSimpleMathOperator{rank}
\DeclareSimpleMathOperator{Mat}
\DeclareSimpleMathOperator{ev}

%Algebra
\DeclareSimpleMathOperator{Quot}
\DeclareSimpleMathOperator{Gal}
\DeclareSimpleMathOperator{Ext}
\DeclareSimpleMathOperator{Tor}
\DeclareSimpleMathOperator{MaxSpec}
\DeclareSimpleMathOperator{Sh}
\DeclareSimpleMathOperator{Proj}
\DeclareSimpleMathOperator{QCoh}
\DeclareSimpleMathOperator{MaxSpec}
\DeclareSimpleMathOperator{Fun}
\DeclareMathOperator{\PreSh}{Pre-Sh}
\newcommand{\tensor}{\otimes} %Synonym for tensoring

%Analysis
\DeclareSimpleMathOperator{dx}
\DeclareSimpleMathOperator{dy}
\DeclareSimpleMathOperator{dz}
\DeclareSimpleMathOperator{dt}

%Sets
\DeclareSimpleMathOperator{conv}
\DeclareSimpleMathOperator{dist}
\DeclareSimpleMathOperator{diam}

%%Stochastic (Algorithmische Mathematik II)
\DeclareDistribution{Bin}
\DeclareDistribution{Ber}
\DeclareDistribution{Geo}
\DeclareDistribution{Poi}
\DeclareDistribution{Unif}
\DeclareDistribution{Var}
\DeclareDistribution{Cov}

%Topology
\DeclareSimpleMathOperator{pr}
\def\twedge{\vee} % Semantically correct macros for wedge product
\def\tsmash{\wedge} % Semantically correct macro for smash product

%Category Theory
\DeclareSimpleMathOperator{Ob}
\DeclareSimpleMathOperator{Hom}
\DeclareSimpleMathOperator{Mor}
\DeclareSimpleMathOperator{End}
\DeclareSimpleMathOperator{colim}

%Categories
\DeclareCategory{Top}
\DeclareCategory{hTop}
\DeclareCategory{Set}
\DeclareCategory{CHaus}
\DeclareCategory{Grp}
\DeclareCategory{Ab}
\DeclareCategory{CRing}
\DeclareCategory{Vect}
\DeclareCategory{Fin}
\DeclareCategory{Ab}
\DeclareCategory{Cat}

%Set theory
\DeclareSimpleMathOperator{card}
\DeclareSimpleMathOperator{Cd}
\DeclareSimpleMathOperator{Ord}
\DeclareSimpleMathOperator{otp}
\DeclareSimpleMathOperator{Card}

%%Galoiskohomologie
\DeclareSimpleMathOperator{Br}
\DeclareSimpleMathOperator{EXT}
\DeclareSimpleMathOperator{Ind}
\DeclareSimpleMathOperator{char}
\DeclareSimpleMathOperator{res}
\DeclareSimpleMathOperator{inf}
\DeclareSimpleMathOperator{cov}
\newcommand{\del}{\partial} % Semantically correct operator for boundary maps

% Characteristic function
\newcommand*{\cfun}{\ensuremath{\mathbbm{1}}}
\newcommand*{\One}{\cfun}

%Paired Delimiters
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}

%Norm and absolute value
%Make them scaling by default and have \abs*{} as the non-scaling version of the command
\DeclarePairedDelimiter\abs{\lvert}{\rvert}
\let\oldabs\abs
\def\abs{\@ifstar{\oldabs}{\oldabs*}}

\DeclarePairedDelimiter\norm{\lVert}{\rVert}
\let\oldnorm\norm
\def\norm{\@ifstar{\oldnorm}{\oldnorm*}}

\DeclareMathOperator{\amalgprod}{\star}
