\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{kb}[2009/01/05 private macros]
\RequirePackage{amsmath, amsthm, amssymb, amsopn}
\usepackage{xspace}
\usepackage{eurosym}
\usepackage{url}
\usepackage{array}
\usepackage[utf8]{inputenc}
\usepackage[OT2,T1]{fontenc}
\usepackage[english,francais]{babel}
\StandardLayout
%\frenchbsetup{StandardLayout}

% http://www.latex-project.org/cgi-bin/ltxbugs2html?pr=amslatex/3756

\def\markboth#1#2{%
\begingroup
  \@temptokena{{#1}{#2}}\xdef\@themark{\the\@temptokena}%
  \mark{\the\@temptokena}%
\endgroup
\if@nobreak\ifvmode\nobreak\fi\fi}

%\usepackage{pslatex}

\DeclareOption{french} {\AtBeginDocument{\selectlanguage{french}}}
\DeclareOption{english}{\AtBeginDocument{\selectlanguage{english}}}
\ProcessOptions

\textwidth 14.5cm
\@ifundefined{calclayout}{}{\calclayout}

\def\kbinitfrench{
  % «, » override (wrong spacing, stronger font)
  \def\ly{\usefont{U}{lasy}{m}{n}}
  \def\guillemotleft{\leavevmode\hbox{\ly(\kern-0.2em(\kern+0.2em}\unskip\penalty10000}
  \def\guillemotright{\unskip\penalty10000\leavevmode\hbox{\kern+0.2em\ly)\kern-0.2em)}}
  %
  \def\proofname{Preuve.}
  \def\exo@name{Exercice}
  \def\theo@name{Théorème}
  \def\rem@name{Remarque}
  \def\rems@name{Remarques}
  \def\guess@name{Conjecture}
  \def\assume@name{Hypothèse}
  \def\lemme@name{Lemme}
  \def\coro@name{Corollaire}
  \def\prop@name{Proposition}
  \def\defi@name{Définition}
  \def\axiom@name{Axiome}
  \def\algo@name{Algorithme}
  \def\subalgo@name{Sous-algorithme}
  \def\getitfrom{disponible sur\xspace}
  \def\toappear{à paraître\xspace}
  \def\submitted{soumis\xspace}
  \def\seealso{voir aussi\xspace}
  \def\prepare{en préparation\xspace}
  \def\ALG@name{Algorithme}
  \def\algorithmicrequire{\textbf{Entrées:}}
  \def\algorithmicensure{\textbf{Sorties:}}
  \def\algorithmicwhile{\textbf{tantque}}
  \def\algorithmicdo{\textbf{faire}}
  \def\algorithmicendwhile{\textbf{fin tantque}}
  \def\algorithmicend{\textbf{fin}}
  \def\algorithmicif{\textbf{si}}
  \def\algorithmicendif{\textbf{finsi}}
  \def\algorithmicelse{\textbf{sinon}}
  \def\algorithmicthen{\textbf{alors}}
  \def\algorithmicfor{\textbf{pour}}
  \def\algorithmicforall{\textbf{pour tout}}
  \def\algorithmicdo{\textbf{faire}}
  \def\algorithmicendfor{\textbf{fin pour}}
  \def\algorithmicloop{\textbf{boucler}}
  \def\algorithmicendloop{\textbf{fin boucle}}
  \def\algorithmicrepeat{\textbf{répéter}}
  \def\algorithmicuntil{\textbf{tant que}}
}
\addto\captionsfrench{\kbinitfrench}
\def\kbinitenglish{
  \def\proofname{Proof.} % append '.'
  \def\exo@name{Exercise}
  \def\theo@name{Theorem}
  \def\rem@name{Remark}
  \def\rems@name{Remarks}
  \def\guess@name{Conjecture}
  \def\assume@name{Assumption}
  \def\lemme@name{Lemma}
  \def\coro@name{Corollary}
  \def\prop@name{Proposition}
  \def\defi@name{Definition}
  \def\axiom@name{Axiom}
  \def\algo@name{Algorithm}
  \def\subalgo@name{Sub-Algorithm}
  \def\getitfrom{available from\xspace}
  \def\seealso{see also\xspace}
  \def\toappear{to appear\xspace}
  \def\submitted{submitted\xspace}
  \def\prepare{in preparation\xspace}
  \def\ALG@name{Algorithm}
  \def\algorithmicrequire{\textbf{Input:}}
  \def\algorithmicensure{\textbf{Output:}}}
\addto\captionsenglish{\kbinitenglish}

% BibTeX (kbplain.bst)
\def\andname{\&}
\def\bibsep{0cm}

% from thesis...
\newif\ifskip
%\def\@fnsymbol#1{\ifcase#1\or \dagger\or \ddagger\or \dagger\dagger\or
%\ddagger\ddagger \or \@warning{Too many footnotes in this page}\fi}

% Theorems & clones
% 1:name 2:begintext 3:endtext 4:num as
\def\misctitle#1{\smallskip\noindent{\bf#1.} }
\def\kbnewenv#1#2#3#4{
  \@ifundefined{c@#4}{\@latexerr{No theorem environment `#4' defined}\@eha}%
  \expandafter\@ifdefinable\csname #1\endcsname {
    \global\@namedef{c@#1}{\@nameuse{c@#4}}
    \global\@namedef{the#1}{\@nameuse{the#4}}
    \global\@namedef{#1}{\refstepcounter{#4}#2}
    \global\@namedef{end#1}{#3\@endtheorem}}}

\def\labelenumi{(\theenumi)\hskip 5pt}
\def\labelenumii{(\theenumii)\hskip 5pt}
\def\labelenumiii{(\theenumiii)\hskip 5pt}

\newtheoremstyle{myremark}
 {3pt}{3pt}% Space above / below
 {}%         Body font
 {}%         Indent amount
 {\itshape}% Thm head font
 {}%         Punctuation after thm head
 {.5em}%     Space after thm head
 {\thmname{#1}{\rm\thmnumber{ #2.}}}% Thm head spec

\newtheoremstyle{myalgo}
 {3pt}{3pt}% Space above / below
 {\sf}%      Body font
 {}%         Indent amount
 {\bf}%      Thm head font
 {}%         Punctuation after thm head
 {\newline}% Space after thm head
 {}% Thm head spec (empty means `normal')

\newtheoremstyle{mysubalgo}
 {3pt}{3pt}% Space above / below
 {\sf}%      Body font
 {}%         Indent amount
 {\bf}%      Thm head font
 {}%         Punctuation after thm head
 {.5em}% Space after thm head
 {}% Thm head spec (empty means `normal')

\newtheoremstyle{myexo}
 {3pt}{3pt}% Space above / below
 {\sf}%         Body font
 {}%         Indent amount
 {\bf}%      Thm head font
 {--}%         Punctuation after thm head
 {.5em}%     Space after thm head
 {}% Thm head spec (empty means `normal')

\theoremstyle{plain}
\@ifundefined{c@section}{}% if 'section' undefined, do nothing
{ % else
  \newtheorem{theo}{\theo@name}[section]
  \newtheorem*{theo*}{\theo@name}
  \newtheorem{lemme}[theo]{\lemme@name}
  \newtheorem*{lemme*}{\lemme@name}
  \newtheorem{coro}[theo]{\coro@name}
  \newtheorem*{coro*}{\coro@name}
  \newtheorem{prop}[theo]{\prop@name}
  \newtheorem*{prop*}{\prop@name}
  \newtheorem{axiom}[theo]{\axiom@name}
  \newtheorem{guess}[theo]{\guess@name}
  \newtheorem{assume}[theo]{\assume@name}

  \theoremstyle{definition}
  \newtheorem{defi}[theo]{\defi@name}

  \theoremstyle{myremark}
  \newtheorem{rem}[theo]{\rem@name}
  \newtheorem{rems}[theo]{\rems@name}

  \theoremstyle{myalgo}
  \newtheorem{algo}[theo]{\algo@name}
  \newtheorem*{algo*}{\algo@name}
  \theoremstyle{mysubalgo}
  \newtheorem{subalgo}[theo]{\subalgo@name}
  \kbnewenv{mytable}{\begin{center}}{\end{center}}{theo}
  \def\themytable{\thesection.\arabic{mytable}}
  \def\tabcap#1{\medskip\centerline{{\sc Table} \themytable.~#1}\medskip}
  \theoremstyle{myexo}
  \newtheorem{exo}[theo]{\exo@name}
  \newtheorem{exo*}[theo]{\llap{$\bigstar$\quad}\exo@name}
  \newtheorem{exo**}[theo]{\llap{$\bigstar\bigstar$\quad}\exo@name}
  \theoremstyle{plain}
}
\@ifundefined{tocsection}{}
{\renewcommand{\tocsection}[3]{%
  \indentlabel{\@ifnotempty{#2}{\ignorespaces#1 #2.\quad}}#3\dotfill}
\let\tocsubsection\tocsection
}

\def \ex{\par\smallskip \noindent {\sc Exemple. }}
\def \exs{\par\noindent {\sc Exemples.}\par\nopagebreak}

% Misc
% cancel \ignorespaces (introduced by \newtheorem. Ugly hack)
\def \noignorespaces{{\catcode`\ =11\ }}
% Legendre symbol
\def \leg#1#2{\genfrac{(}{)}{}{}{#1}{#2}}
%\def \dfrac#1#2{\frac{\displaystyle #1}{\displaystyle #2}}
% input file in sandbox
\def \cleaninput#1{\begingroup\input{#1}\endgroup}
% allow \over (compatibility, AMSTeX disables it)
\let \over=\@@over

\DeclareSymbolFont{cyrletters}{OT2}{wncyr}{m}{n}
\DeclareMathSymbol{\Sha}{\mathalpha}{cyrletters}{"58}

\def \normal{\vartriangleleft}
\def \inv#1{\frac{1}{#1}}
\def \restr#1#2{{#1} \left| {}_{#2} \right. }
% 'mod' with sensible spacing
\def \mymod#1{\mkern 6mu{\operator@font mod}\,#1}
\def \pod#1{\penalty50%
\mathchoice{\mkern18mu}{\mkern8mu}{\mkern4mu}{\mkern4mu}(#1)}

% matrices
\def \smallmat#1{\left(\begin{smallmatrix}#1\end{smallmatrix}\right)}
\def \mat#1{\begin{pmatrix}#1\end{pmatrix}}

% sums
\def \sumstack#1{\sum_{\substack{#1}}}
\def \prodstack#1{\prod_{\substack{#1}}}

% norms
\def \n@rm#1{\left\| {#1} \right\|}
\def \n@rm@sub[#1]#2{\n@rm{#2}_{#1}}
\def \norm{\@ifnextchar[{\n@rm@sub}{\n@rm}}

% parens
\def \paren#1{\left(      {#1}\right)}
\def \Paren#1{\bigl(      {#1}\bigr)}
\def   \gen#1{\left\langle{#1}\right\rangle}
\def   \set#1{\left\{     {#1}\right\}}
\def   \seg#1{\left[      {#1}\right]}
\def   \Seg#1{\big[       {#1}\big]}
\def   \abs#1{\left\lvert {#1}\right\rvert}
\def   \Abs#1{\bigl\lvert {#1}\bigr\rvert}
\def \floor#1{\left\lfloor{#1}\right\rfloor}
\def  \ceil#1{\left\lceil {#1}\right\rceil}
\def \round#1{\left\lceil {#1}\right\rfloor}
\def \tround#1{\lceil {#1}\rfloor}
\def   \tabs#1{\lvert {#1}\rvert}

%% Operators.
\def\tran#1{{}^t\!#1} %transpose
\DeclareMathOperator{\pgcd}{pgcd} 
\DeclareMathOperator{\ppcm}{ppcm} 

\DeclareMathOperator{\frob}{Frob} 
\DeclareMathOperator{\Aut}{Aut} 
\DeclareMathOperator{\Cl}{Cl} 
\DeclareMathOperator{\card}{card} 
\DeclareMathOperator{\Div}{Div} 
\DeclareMathOperator{\Frac}{Frac} 
\DeclareMathOperator{\Gal}{Gal} 
\DeclareMathOperator{\Gl}{GL} 
\DeclareMathOperator{\Hom}{Hom} 
\DeclareMathOperator{\Id}{Id} 
\DeclareMathOperator{\Ind}{Ind} 
\DeclareMathOperator{\Ker}{Ker} 
\DeclareMathOperator{\Coker}{Coker} 
\@ifundefined Li % defined in amstex
  \DeclareMathOperator{\Li}{Li}
  \relax
\DeclareMathOperator{\Nor}{Nor} 
\DeclareMathOperator{\N}{N} 
\DeclareMathOperator{\Pic}{Pic} 
\DeclareMathOperator{\Sl}{SL} 
\DeclareMathOperator{\Res}{Res} 
\DeclareMathOperator{\Stab}{Stab} 
\DeclareMathOperator{\Vect}{Vect} 
\DeclareMathOperator{\End}{End} 
\DeclareMathOperator{\OO}{O} 
\DeclareMathOperator{\SO}{SO} 
\DeclareMathOperator{\Tr}{Tr} 
\DeclareMathOperator{\ch}{ch} 
\DeclareMathOperator{\codim}{codim} 
\DeclareMathOperator{\disc}{disc} 
\DeclareMathOperator{\grad}{grad} 
\DeclareMathOperator{\lcm}{lcm} 
\DeclareMathOperator{\jac}{jac} 
\DeclareMathOperator{\mynorm}{Norm}
\DeclareMathOperator{\pgl}{PGL}
\DeclareMathOperator{\proj}{proj} 
\DeclareMathOperator{\psl}{PSL}
\DeclareMathOperator{\rg}{rg} 
\DeclareMathOperator{\sh}{sh} 
\DeclareMathOperator{\Sym}{Sym} 
\DeclareMathOperator{\spec}{spec} 
\DeclareMathOperator{\supp}{supp} 
\DeclareMathOperator{\vol}{Vol} 
\DeclareMathOperator{\im}{Im} 
\DeclareMathOperator{\re}{Re} 

% aliases
\let\id\Id
\let\cl\Cl 
\let\gal\Gal 
\let\ker\Ker 
\let\limind\varinjlim
\let\limpro\varprojlim
\let\leq\leqslant
\let\geq\geqslant

\def \AM{{\mathbb{A}}}
\def \CM{{\mathbb{C}}}
\def \EM{{\mathbb{E}}}
\def \FM{{\mathbb{F}}}
\def \NM{{\mathbb{N}}}
\def \PM{{\mathbb{P}}}
\def \QM{{\mathbb{Q}}}
\def \RM{{\mathbb{R}}}
\def \ZM{{\mathbb{Z}}}
\def \pM{{\mathfrak{p}}}
\def \mM{{\mathfrak{m}}}
\def\Ot{\widetilde{O}}

% abbreviations
\def \cad{c'est-à-dire\xspace}
\def \Cad{C'est-à-dire\xspace}
\def \etc{\emph{etc.}\xspace}
\def \ie{\emph{i.e.}\xspace}
\def \cf{\emph{cf.}\xspace}
\def \Cf{\emph{Cf.}\xspace}
\def \etal{\emph{et al.}\xspace}
% roman numbers
\def\bigroman#1{\expandafter\uppercase\expandafter{\romannumeral #1}}
% ordinals 
\def\@ieme#1#2{$#2^{\text{\ifcase#1\or er\or nd\else ème\fi}}$}
\def\ieme#1{\@ieme{#1}{#1}}
\def\rieme#1{\@ieme{#1}{\text{\bigroman{#1}}}}
\def\iemee#1{$#1^{\text{\ifcase#1\or ère\or nde\else ème\fi}}$}

\def\bxaddress{%
Univ. Bordeaux, IMB, UMR 5251, F-33400 Talence, France.\\
CNRS, IMB, UMR 5251, F-33400 Talence, France.\\
INRIA, F-33400 Talence, France.}
%    Karim {\sc Belabas}, Université de Bordeaux, IMB -- UMR 5251,
%    351 cours de la Libération,
%    F-33405 Talence (France)\quad $\bullet$\quad 
%    \emph{E-mail}: \url{Karim.Belabas@math.u-bordeaux.fr}
%}
\def\kbaddress{%
  \begin{tabular}{l}
    Karim {\sc Belabas}\\
    Universit\'e Paris-Sud\\
    D\'epartement de Math\'ematiques (b\^at.~425)\\
    F-91405 Orsay (France)\\
    \url{Karim.Belabas@math.u-psud.fr}
  \end{tabular}}
\def\my@ddress#1{\medskip\hrule width 80pt\medskip\noindent \normalfont\footnotesize#1}
\def\myaddress{\my@ddress{\bxaddress}}
