%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Misc

\newcommand{\BoxFormula}[1]{\begin{center}\fbox{#1}\end{center}}

\newcommand{\bigfrac}[2]{\displaystyle{\frac{#1}{#2}}}
\newcommand{\half}{\textstyle{\frac{1}{2}}} % a small half, even in displays
\newcommand{\arc}[1]{\stackrel{\frown}{#1}}
  % for things like: $\arc{AB}$ has measure $180\degrees$
\DeclareMathOperator{\arcsec}{arcsec}
\DeclareMathOperator{\arccot}{arccot}
\DeclareMathOperator{\arccsc}{arccsc}

\DeclareMathOperator{\Fix}{Fix}
\DeclareMathOperator{\Stab}{Stab}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\nsubset{\not\subset}   % I should get rid of this,
                            % and make a noeq option, which
                            % should be default.
\newcommand{\nequiv}{\not\equiv}

\newcommand{\Ddots}{\mathinner{\mkern1mu\raise\p@\vbox{\kern7\p@\hbox{.}}%
        \mkern2mu\raise4\p@\hbox{.}\mkern2mu\raise7\p@\hbox{.}\mkern1mu}}
        % Diagonal dots going in the other direction

\newcommand{\floor}[1]{\left\lfloor#1\right\rfloor}
\newcommand{\Langle}{\left<}
\newcommand{\Rangle}{\right>}
\newcommand{\Lvert}{\left\lvert}
\newcommand{\Rvert}{\right\rvert}
\newcommand{\LVert}{\left\lVert}
\newcommand{\RVert}{\right\rVert}

%% Reminder
\newcommand{\remind}[1]{\marginpar{\raggedright\tiny{\emph{#1}}}\typeout{#1}}

%% Map commands, so you can write
% \map f:X->Y,
% instead of
% f\colon X\to Y,
% the result being more readable TeX
\def\map#1:#2->#3{#1\colon #2\to #3}
\def\maps#1->#2{#1 \to #2}
\def\mapssurj#1->>#2{#1 \twoheadrightarrow #2}
\def\lmap#1:#2<-#3{#1\colon #2\leftarrow #3}
\def\mapo#1-#2->#3{#1\overset{#2}{\to}#3}
\def\mapinj#1:#2(->#3{#1\colon #2\hookrightarrow #3}
\def\mapsur#1:#2->>#3{#1\colon #2\twoheadrightarrow #3}
\def\mapbij#1:#2<->#3{#1\colon #2\leftrightarrow #3}
\def\mapiso#1:#2-~->#3{#1\colon #2\overset{\sim}{\to} #3}

\def\iso={\cong}

\def\degrees{^{\circ}}
\newcommand{\restrict}[1]{\vert_{#1}}
\newcommand{\evaluate}[1]{\vert_{#1}}

% Indexing
\newcommand{\Index}[1]{#1\index{#1}}    % In general, you can index thus
\newcommand{\Def}[2][0]{\emph{#2}}
%\ifthenelse{#1=0}{\index{#2|textbf}}{\index{#1|textbf}}}

\newcommand{\injects}{\hookrightarrow}
\newcommand{\surjects}{\twoheadrightarrow}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sets, sequences, logic

\def\emptyset{\varnothing}              % I prefer this emptyset
%%%%% Fix all my \Null!!!!!

\newcommand{\completion}[1]{{\widehat #1}}
\newcommand{\compliment}[1]{{#1}^c}
\newcommand{\closure}[1]{\overline{#1}}
\newcommand{\interior}[1]{{#1^\circ}}
\newcommand{\varinterior}[1]{\overset{\circ}{#1}}

\DeclareMathOperator{\ostar}{star}
\DeclareMathOperator{\cstar}{\overline{\ostar}}

% Cardinality
\DeclareMathOperator{\card}{card}
%\newcommand{\card}[1]{\left|#1\right|}

%% Such that
% \newcommand{\st}{\mid} % too confusingly like absolute value
\newcommand{\st}{\,:\,}

\newcommand{\compose}{\circ}
\newcommand{\from}{\colon}
\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\seq}[1]{\left\langle#1\right\rangle}
\newcommand{\abs}[1]{\left\lvert#1\right\rvert}
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
\newcommand{\Norm}{\norm{\,\cdot\,}}
\newcommand{\lparen}{\left(}
\newcommand{\rparen}{\right)}
\newcommand{\Lfloor}{\left\lfloor}
\newcommand{\Rfloor}{\right\rfloor}
\newcommand{\power}{\cP}
\newcommand{\OR}{\vee}
\newcommand{\AND}{\wedge}
% \newcommand{\OR}{\text{ or }}
% \newcommand{\AND}{\text{ and }}
\newcommand{\NOT}{\neg}
% \newcommand{\NOT}{\sim}
\newcommand{\nin}{\notin}
\newcommand{\nni}{\notni}
\newcommand{\nimplies}{\notimplies}
% \newcommand{\nexists}{\not\exists}
% \newcommand{\seilpmi}{\Leftarrow}

\newcommand{\pto}{\rightharpoonup}      % Partial function
\newcommand{\RP}{{\bR\bP}}
\newcommand{\CP}{{\bC\bP}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Arrays and matrices
\RequirePackage{array}

%%% Small matricies
\newcommand{\psmallmatrix}[1]{\left(\begin{smallmatrix}#1\end{smallmatrix}\right)}
\newcommand{\bsmallmatrix}[1]{\left[\begin{smallmatrix}#1\end{smallmatrix}\right]}
\newcommand{\Bsmallmatrix}[1]{\left\{\begin{smallmatrix}#1\end{smallmatrix}\right\}}
\newcommand{\vsmallmatrix}[1]{\left\lvert\begin{smallmatrix}#1\end{smallmatrix}\right\rvert}
\newcommand{\Vsmallmatrix}[1]{\left\lVert\begin{smallmatrix}#1\end{smallmatrix}\right\rVert}

%%% New column types
\newcolumntype{C}{>{$}c<{$}}
\newcolumntype{L}{>{$}l<{$}}
\newcolumntype{R}{>{$}r<{$}}
%\newcolumn{C}{>{$}c<{$}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Algebra

%%% Algebraic Topology ---------------------------------------------
\DeclareMathOperator{\HE}{HE} % homotopy equivalences
\DeclareMathOperator{\Homeo}{Homeo} % homeomorphisms

%%% Algebraic Geometry ---------------------------------------------
\DeclareMathOperator{\Spec}{Spec}       % Spectrum
\DeclareMathOperator{\Proj}{Proj}       % 
\DeclareMathOperator{\MSpec}{MSpec}     % Maximum Spectrum
\DeclareMathOperator{\Pic}{Pic}         % Picard Group

\DeclareMathOperator{\height}{height}   % height
\DeclareMathOperator{\depth}{depth}     % depth

%%% Category Theory ------------------------------------------------
\DeclareMathOperator{\Hom}{Hom}         % Homomorphisms
\DeclareMathOperator{\Aut}{Aut}         % Automorphisms
\DeclareMathOperator{\End}{End}         % Endomorphisms

%\DeclareMathOperator{\Id}{Id}           % The Identity Map
\DeclareMathOperator{\id}{id}           % The Identity Map
\DeclareMathOperator{\Obj}{Obj}         % Objects
\DeclareMathOperator{\Mor}{Mor}         % Morphisms
% \DeclareMathOperator{\ker}{ker}       % Kernal -- already in AMS-LaTeX
\DeclareMathOperator{\coker}{coker}     % Cokernal
\DeclareMathOperator{\im}{im}           % Image
\def\invlim{\varprojlim}
\def\dirlim{\varinjlim}

%%% Field Theory ----------------------------------------------------
\DeclareMathOperator{\Gal}{Gal}         % Galois Group

%%% Group Theory ----------------------------------------------------
\DeclareMathOperator{\Out}{Out}         % Outer Automorphisms
\DeclareMathOperator{\Inn}{Inn}         % Inner Automorphisms

\def\GrpGen<#1>{\left<#1\right>}        % Group by generators
\def\order{\abs}
% Normal subgroup
\newcommand{\normsub}{\vartriangleleft}
\newcommand{\subnorm}{\vartriangleright}

%%% Homological Algebra  --------------------------------------------
\DeclareMathOperator{\Ext}{Ext}         % Ext
\DeclareMathOperator{\Tor}{Tor}         % Tor

%%% Linear Algebra --------------------------------------------------
\DeclareMathOperator{\ann}{ann}         % Annihilator
%\DeclareMathOperator{\dim}{dim}        % Dimension -- already \def'ined
\DeclareMathOperator{\rank}{rank}       % Rank
\DeclareMathOperator{\Span}{span}       % Span -- note that \span
                                          % already means something
\newcommand{\transpose}[1]{{{#1}^{\text{\textsf{T}}}}}           % Transpose
\DeclareMathOperator{\tr}{tr}           % Trace
%\DeclareMathOperator{\det}{det}        % Determinant -- already \def'ined

%%%%% FIXME:Replaced by \ip[]{}{}
% \def\ip<#1,#2>{\left<#1, #2\right>}

\newcommand{\ip}[3][0]{			% Inner Product (or any
					% bilinear form)
\ifthenelse{#1=0}{\left<#2,#3\right>}{
\ifthenelse{#1=1}{\left(#2,#3\right)}{
\ifthenelse{#1=2}{\left(#2\vert #3\right)}{
\typeout{Delimiter size too big} % I should make this an error
}}}}


%% Linear Groups
% For consistency, so I don't get GL_n and Gl_n mixed up
%%%%% In fact, I should really make this
%%%%% \newcommand{\GL}[2][]{GL_{#1}\left(#2\right)}
%%%%% or
%%%%% \newcommand{\GL}[2][]{GL\left(#1, #2\right)}
%%%%% with suitable dealing with the case \GL{V}
%%%%% (and a nicer TeX way would be to have \GL(V) -- ha!)
\newcommand{\GL}{GL}
\newcommand{\PGL}{PGL}
\newcommand{\SL}{SL}
\newcommand{\PSL}{PSL}
\newcommand{\SO}{SO}
\newcommand{\Sp}{Sp}
\newcommand{\Mp}{Mp}
\newcommand{\SU}{SU}

% Linear algebras
\DeclareMathOperator{\gl}{\mathfrak{gl}}
\DeclareMathOperator{\ssl}{\mathfrak{sl}}
\DeclareMathOperator{\so}{\mathfrak{so}}
\DeclareMathOperator{\ssp}{\mathfrak{sp}}
\DeclareMathOperator{\su}{\mathfrak{su}}

%%% Number Theory ---------------------------------------------------
\DeclareMathOperator{\lcm}{lcm}         % Least Common Multiple
%\DeclareMathOperator{\gcd}{gcd}        % Greatest Common Divisor
                                        %   -- already in AMS-LaTeX
\DeclareMathSymbol{\divides}{\mathbin}{symbols}{"6A}
\DeclareMathSymbol{\ndivides}{\mathbin}{AMSb}{"2D}
\newcommand{\residue}[1]{\overline{#1}}

%%% Representation Theory -------------------------------------------
\DeclareMathOperator{\Res}{Res}         % Restriction
\DeclareMathOperator{\Ind}{Ind}         % Induced

%% Character tables
\RequirePackage{float}    % Standard; for nice character tables
\floatstyle{plain}
\newfloat{CharTable}{ht}{aux}
\floatname{CharTable}{\textsc{Character Table}}
\newfloat{PCharTable}{ht}{aux}
\floatname{PCharTable}{\textsc{Partial Character Table}}
\newfloat{Char}{ht}{aux}
\floatname{Char}{\textsc{Character}}
\newfloat{Chars}{ht}{aux}
\floatname{Char}{\textsc{Characters}}
% Use \SP to get correct spacing for negative signs
\newlength{\negativesign}
\settowidth{\negativesign}{$-$}
\newcommand{\SP}{\hspace{\negativesign}}

%%% Ring Theory -----------------------------------------------------
\DeclareMathOperator{\charstc}{char}    % Characteristic -- note that \char
                                          % (and, it seems, \Char)
                                          % already means something
\DeclareMathOperator{\Supp}{Supp}       % Support
%\DeclareMathOperator{\deg}{deg}        % Degree -- already in AMS-LaTeX

%%% Common
%% Opposite (ring, group)
\newcommand{\op}[1]{#1^{\text{op}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Alphabets

%%% Bold Face
% \H \L \O \P \S are already defined,
% which is why we don't use \Z for bold Z, etc.
\newcommand{\bA}{{\mathbf A}}
\newcommand{\bB}{{\mathbf B}}
\newcommand{\bC}{{\mathbf C}}
\newcommand{\bD}{{\mathbf D}}
\newcommand{\bE}{{\mathbf E}}
\newcommand{\bF}{{\mathbf F}}
\newcommand{\bG}{{\mathbf G}}
\newcommand{\bH}{{\mathbf H}}
\newcommand{\bI}{{\mathbf I}}
\newcommand{\bJ}{{\mathbf J}}
\newcommand{\bK}{{\mathbf K}}
\newcommand{\bL}{{\mathbf L}}
\newcommand{\bM}{{\mathbf M}}
\newcommand{\bN}{{\mathbf N}}
\newcommand{\bO}{{\mathbf O}}
\newcommand{\bP}{{\mathbf P}}
\newcommand{\bQ}{{\mathbf Q}}
\newcommand{\bR}{{\mathbf R}}
\newcommand{\bS}{{\mathbf S}}
\newcommand{\bT}{{\mathbf T}}
\newcommand{\bU}{{\mathbf U}}
\newcommand{\bV}{{\mathbf V}}
\newcommand{\bW}{{\mathbf W}}
\newcommand{\bX}{{\mathbf X}}
\newcommand{\bY}{{\mathbf Y}}
\newcommand{\bZ}{{\mathbf Z}}

%%% Caligraphic
\newcommand{\cA}{{\mathcal A}}
\newcommand{\cB}{{\mathcal B}}
\newcommand{\cC}{{\mathcal C}}
\newcommand{\caD}{{\mathcal D}}  % XY-pic
\newcommand{\cE}{{\mathcal E}}
\newcommand{\cF}{{\mathcal F}}
\newcommand{\cG}{{\mathcal G}}
\newcommand{\caH}{{\mathcal H}}  % XY-pic
\newcommand{\cI}{{\mathcal I}}
\newcommand{\cJ}{{\mathcal J}}
\newcommand{\cK}{{\mathcal K}}
\newcommand{\caL}{{\mathcal L}}  % XY-pic
\newcommand{\cM}{{\mathcal M}}
\newcommand{\cN}{{\mathcal N}}
\newcommand{\cO}{{\mathcal O}}
\newcommand{\cP}{{\mathcal P}}
\newcommand{\cQ}{{\mathcal Q}}
\newcommand{\caR}{{\mathcal R}}  % XY-pic
\newcommand{\cS}{{\mathcal S}}
\newcommand{\cT}{{\mathcal T}}
\newcommand{\cU}{{\mathcal U}}
\newcommand{\cV}{{\mathcal V}}
\newcommand{\cW}{{\mathcal W}}
\newcommand{\cX}{{\mathcal X}}
\newcommand{\cY}{{\mathcal Y}}
\newcommand{\cZ}{{\mathcal Z}}

%%% Fraktur
\newcommand{\fA}{{\mathfrak A}}
\newcommand{\fB}{{\mathfrak B}}
\newcommand{\fC}{{\mathfrak C}}
\newcommand{\fD}{{\mathfrak D}}
\newcommand{\fE}{{\mathfrak E}}
\newcommand{\fF}{{\mathfrak F}}
\newcommand{\fG}{{\mathfrak G}}
\newcommand{\fH}{{\mathfrak H}}
\newcommand{\fI}{{\mathfrak I}}
\newcommand{\fJ}{{\mathfrak J}}
\newcommand{\fK}{{\mathfrak K}}
\newcommand{\fL}{{\mathfrak L}}
\newcommand{\fM}{{\mathfrak M}}
\newcommand{\fN}{{\mathfrak N}}
\newcommand{\fO}{{\mathfrak O}}
\newcommand{\fP}{{\mathfrak P}}
\newcommand{\fQ}{{\mathfrak Q}}
\newcommand{\fR}{{\mathfrak R}}
\newcommand{\fS}{{\mathfrak S}}
\newcommand{\fT}{{\mathfrak T}}
\newcommand{\fU}{{\mathfrak U}}
\newcommand{\fV}{{\mathfrak V}}
\newcommand{\fW}{{\mathfrak W}}
\newcommand{\fX}{{\mathfrak X}}
\newcommand{\fY}{{\mathfrak Y}}
\newcommand{\fZ}{{\mathfrak Z}}

\newcommand{\fa}{{\mathfrak a}}
\newcommand{\fb}{{\mathfrak b}}
\newcommand{\fc}{{\mathfrak c}}
\newcommand{\fd}{{\mathfrak d}}
\newcommand{\fe}{{\mathfrak e}}
\newcommand{\ff}{{\mathfrak f}}
\newcommand{\fg}{{\mathfrak g}}
\newcommand{\fh}{{\mathfrak h}}
\newcommand{\Fi}{{\mathfrak i}} % \fi closes \if clauses
\newcommand{\fj}{{\mathfrak j}}
\newcommand{\fk}{{\mathfrak k}}
\newcommand{\fl}{{\mathfrak l}}
\newcommand{\fm}{{\mathfrak m}}
\newcommand{\fn}{{\mathfrak n}}
\newcommand{\fo}{{\mathfrak o}}
\newcommand{\fp}{{\mathfrak p}}
\newcommand{\fq}{{\mathfrak q}}
\newcommand{\fr}{{\mathfrak r}}
\newcommand{\fs}{{\mathfrak s}}
\newcommand{\ft}{{\mathfrak t}}
\newcommand{\fu}{{\mathfrak u}}
\newcommand{\fv}{{\mathfrak v}}
\newcommand{\fw}{{\mathfrak w}}
\newcommand{\fx}{{\mathfrak x}}
\newcommand{\fy}{{\mathfrak y}}
\newcommand{\fz}{{\mathfrak z}}
