\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{abdothms}


\newcommand{\theoremshook}{}

\DeclareOption{catalan}{
  \renewcommand{\theoremshook}{\theoremscatalan}
}

\DeclareOption{english}{
  \renewcommand{\theoremshook}{\theoremsenglish}
}

\DeclareOption{spanish}{
  \renewcommand{\theoremshook}{\theoremsspanish}
}


% Process options of the package.
\ProcessOptions


%% Package Loading
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\RequirePackage{amsthm}    % AMS theorem environments
\RequirePackage{ifthen}    % Make decisions inside latex


%% Theorems
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Creates a new theorem environment.
% Parameters: label, text, short text, thm style, enum style, enum param.
% Example: \maketheoremenv{thm}{Theorem}{plain}{counter}{section}
% Example: \maketheoremenv{dfn}{Definition}{definition}{copy}{thm}

\newcommand{\maketheoremenv}[6]{
  \theoremstyle{#4}%
  \ifthenelse{\equal{#5}{counter}}{%
    \newtheorem{#1}{#2}[#6]%
  }{}%
  \ifthenelse{\equal{#5}{copy}}{%
    \newtheorem{#1}[#6]{#2}%
  }{}%
}

\DeclareRobustCommand{\blackcircle}{\LARGE$\bullet$}

\newcommand{\makeproofenv}[4]{
  \newenvironment{#1}[1][]{\par%
    \renewcommand{\qedsymbol}{#4}%
    \pushQED{\qed}%
    \normalfont \topsep6\p@\@plus6\p@\relax%
    \trivlist
    \ifx @##1@%
      \item[\hskip\labelsep%
      {\bfseries #2\@addpunct{.}}]
    \else%
      \item[\hskip\labelsep%
      {\bfseries #2 (##1)\@addpunct{.}}]
    \fi%
    \ignorespaces%
  }{%
    \popQED\endtrivlist\@endpefalse%
    \aftergroup\ignorespaces%
  }
}

% Disable ams proof. Having both around might lead to inconsistent
% usage of the proof environment...

\renewenvironment{proof}[1][]{\errmessage{Proof environment disabled. Use prf instead !}}{}

\newcommand{\theoremscatalan}{
  \maketheoremenv{thm}{\color{thmcolor}Teorema}{Tma.}{definition}{counter}{section}
  \maketheoremenv{prp}{\color{thmcolor}Proposici\'o}{Prop.}{definition}{copy}{thm}
  \maketheoremenv{lem}{\color{thmcolor}Lema}{Lem.}{definition}{copy}{thm}
  \maketheoremenv{cor}{\color{thmcolor}Coro\l.lari}{Cor.}{definition}{copy}{thm}
  \maketheoremenv{con}{\color{thmcolor}Conjectura}{Conj.}{definition}{copy}{thm}

  \maketheoremenv{dfn}{\color{dfncolor}Definici\'o}{Def.}{definition}{copy}{thm}
  \maketheoremenv{rmk}{\color{dfncolor}Remarca}{Rem.}{definition}{copy}{thm}
  \maketheoremenv{obs}{\color{dfncolor}Observaci\'o}{Obs.}{definition}{copy}{thm}
  \maketheoremenv{nte}{\color{dfncolor}Nota}{Nota}{definition}{copy}{thm}
  \maketheoremenv{exm}{\color{dfncolor}Exemple}{Exm.}{definition}{copy}{thm}

  \maketheoremenv{exr}{Exercici}{Exr.}{definition}{counter}{section}
  \maketheoremenv{prb}{Problema}{Prob.}{definition}{copy}{exr}
  \maketheoremenv{que}{Q\"uesti\'o}{Q\"ue.}{definition}{copy}{exr}

  \maketheoremenv{blk}{}{}{definition}{counter}{section}

  \makeproofenv{sol}{Soluci\'o}{Sol.}{\blackcircle}
  \makeproofenv{ans}{Resposta}{Res.}{\blackcircle}
  \makeproofenv{prf}{Demostraci\'o}{Dem.}{\blackcircle}
}

\newcommand{\theoremsenglish}{
  \maketheoremenv{thm}{\color{thmcolor}Theorem}{Thm.}{definition}{counter}{section}
  \maketheoremenv{prp}{\color{thmcolor}Proposition}{Prop.}{definition}{copy}{thm}
  \maketheoremenv{lem}{\color{thmcolor}Lemma}{Lem.}{definition}{copy}{thm}
  \maketheoremenv{cor}{\color{thmcolor}Corollary}{Cor.}{definition}{copy}{thm}
  \maketheoremenv{con}{\color{thmcolor}Conjecture}{Conj.}{definition}{copy}{thm}

  \maketheoremenv{dfn}{\color{dfncolor}Definition}{Def.}{definition}{copy}{thm}
  \maketheoremenv{rmk}{\color{dfncolor}Remark}{Rem.}{definition}{copy}{thm}
  \maketheoremenv{obs}{\color{dfncolor}Observation}{Obs.}{definition}{copy}{thm}
  \maketheoremenv{nte}{\color{dfncolor}Note}{Note}{definition}{copy}{thm}
  \maketheoremenv{exm}{\color{dfncolor}Example}{Exm.}{definition}{copy}{thm}

  \maketheoremenv{exr}{Exercise}{Exr.}{definition}{counter}{section}
  \maketheoremenv{prb}{Problem}{Prb.}{definition}{copy}{exr}
  \maketheoremenv{que}{Question}{Que.}{definition}{copy}{exr}

  \maketheoremenv{blk}{}{}{definition}{counter}{section}

  \makeproofenv{sol}{Solution}{Sol.}{\blackcircle}
  \makeproofenv{ans}{Answer}{Ans.}{\blackcircle}
  \makeproofenv{prf}{Proof}{Prf.}{\blackcircle}
}

\newcommand{\theoremsspanish}{
  \maketheoremenv{thm}{\color{thmcolor}Teorema}{Tma.}{definition}{counter}{section}
  \maketheoremenv{prp}{\color{thmcolor}Proposici\'on}{Prop.}{definition}{copy}{thm}
  \maketheoremenv{lem}{\color{thmcolor}Lema}{Lem.}{definition}{copy}{thm}
  \maketheoremenv{cor}{\color{thmcolor}Corolario}{Cor.}{definition}{copy}{thm}
  \maketheoremenv{con}{\color{thmcolor}Conjetura}{Conj.}{definition}{copy}{thm}

  \maketheoremenv{dfn}{\color{dfncolor}Definici\'on}{Def.}{definition}{copy}{thm}
  \maketheoremenv{rmk}{\color{dfncolor}Remarca}{Rem.}{definition}{copy}{thm}
  \maketheoremenv{obs}{\color{dfncolor}Observaci\'on}{Obs.}{definition}{copy}{thm}
  \maketheoremenv{nte}{\color{dfncolor}Nota}{Nota}{definition}{copy}{thm}
  \maketheoremenv{exm}{\color{dfncolor}Ejemplo}{Ejm.}{definition}{copy}{thm}

  \maketheoremenv{exr}{Ejercicio}{Ejer.}{definition}{counter}{section}
  \maketheoremenv{prb}{Problema}{Prob.}{definition}{copy}{exr}
  \maketheoremenv{que}{Questi\'on}{Que.}{definition}{copy}{exr}

  \maketheoremenv{blk}{}{}{definition}{counter}{section}

  \makeproofenv{sol}{Soluci\'on}{Sol.}{\blackcircle}
  \makeproofenv{ans}{Respuesta}{Res.}{\blackcircle}
  \makeproofenv{prf}{Demostraci\'on}{Dem.}{\blackcircle}
}


% Mimic the numbering of an other theorem, to be used in introductions and such.
\newenvironment{thmref}[1]
{%
  \bgroup%
  \renewcommand{\thethm}{\ref*{#1}}%
  \thm%
}{%
  \endthm%
  \addtocounter{thm}{-1}%
  \egroup%
}


\theoremshook               % Creates all the theorems in the
                            % appropriate language.
