\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{lecture}[1/19/98]
\RequirePackage{amstext}
\RequirePackage{amsfonts}
\RequirePackage{amssymb}
\RequirePackage{theorem}
\RequirePackage{xspace}
\RequirePackage{ifthen}

\DeclareOption{theorems}{
% Etiquetas para los diversos entornos
\newcommand{\theoremname}{Theorem}
\newcommand{\lemmaname}{Lemma}
\newcommand{\corollaryname}{Corollary}
\newcommand{\propositionname}{Proposition}
\newcommand{\definitionname}{Definition}
\newcommand{\conjecturename}{Conjecture}
\newcommand{\claimname}{Claim}
\newcommand{\of}{of\ }

% Entornos para demostraciones
% \begin{proof} ... \end{proof} 


\@ifpackageloaded{amsthm}%
%then
{%
\renewenvironment{proof}[1][\proofname]{\begin{trivlist} 
\item[\hskip \labelsep{\bfseries #1.}]\setlength{\parindent}{0pt}}
{\qed\end{trivlist}}}
%else
{\newcommand{\proofname}{Proof}
\newenvironment{proof}[1][\proofname]{\begin{trivlist} \item[\hskip 
\labelsep{\bfseries #1.}]\setlength{\parindent}{0pt}}{\qed\end{trivlist}}}

% Definicion de varios entornos theorem-like: theorem, lemma,
% corollary, proposition, ... todos ellos de estilo 'plain'
% Shape por defecto: slshape

\theorembodyfont{\slshape}

\newcommand{\definetheorems}{
\newtheorem{theorem}{\theoremname}[chapter]
\newtheorem{lemma}{\lemmaname}[chapter]
\newtheorem{corollary}{\corollaryname}[chapter]
\newtheorem{proposition}{\propositionname}[chapter]
\newtheorem{defn}{\definitionname}[chapter]
\newtheorem{conjecture}{\conjecturename}[chapter]
\newtheorem{claim}{\claimname}[chapter]
}
\AtBeginDocument{%
\definetheorems
}
}

\DeclareOption{amssections}{
% if amsart is not loaded then ...
\renewcommand{\section}{\@startsection{section}{1}%
  \z@{.7\baselineskip\@plus\baselineskip}{.5\baselineskip}%
  {\normalfont\scshape\centering}}
\renewcommand{\subsection}{\@startsection{subsection}{2}%
  \z@{.5\baselineskip\@plus.7\baselineskip}{-.5em}%
  {\normalfont\bfseries}}
\renewcommand{\@seccntformat}[1]{\csname the#1\endcsname.\quad}

\renewcommand{\appendix}{\par
  \setcounter{section}{0}%
  \setcounter{subsection}{0}%
  \renewcommand\thesection{\@Alph\c@section}
\renewcommand{\section}{\@startsection{section}{1}%
  \z@{.7\baselineskip\@plus\baselineskip}{.5\baselineskip}%
  {\normalfont\scshape\centering Appendix\ }}
}
}

\DeclareOption{runningheads}{
% if amsart is not loaded then do nothing; otherwise ...

\input{fancyheadings.sty}
\pagestyle{fancy}
\lhead[]{\thepage}
\chead[\scshape\@rtitle]{\scshape\@rtitle}
\rhead[\thepage]{}
\lfoot{} \cfoot{} \rfoot{}
\setlength{\headrulewidth}{0 pt}
\setlength{\footrulewidth}{0pt}
}

\DeclareOption{english}{
\renewcommand{\chaptername}{Lecture}
\newcommand{\lecturer}{Lecturer:}
\newcommand{\notesby}{Notes by:}
\newcommand{\datelec}{Date:}
\newcommand{\acknoname}{Acknowledgements}
\renewcommand{\th}[1]{\ensuremath{#1^{\text{th}}}}
}

\DeclareOption{catalan}{
\renewcommand{\chaptername}{Lli\c{c}\'o}
\renewcommand{\lecturer}{Lector:}
\renewcommand{\notesby}{Notes de:}
\renewcommand{\datelec}{Data:}
\renewcommand{\theoremname}{Teorema}
\renewcommand{\lemmaname}{Lema}
\renewcommand{\corollaryname}{Coro{\lgem}ari}
\renewcommand{\propositionname}{Proposici\'o}
\renewcommand{\definitionname}{Definici\'o}
\renewcommand{\conjecturename}{Conjectura}
\renewcommand{\claimname}{Fet}
\renewcommand{\proofname}{Demostraci\'o}
\renewcommand{\of}{del\ }
\renewcommand{\th}[1]{\ensuremath{#1-\text{\'essim}}}
\renewcommand{\acknoname}{Agra\"{\i}ments}
}

\DeclareOption{spanish}{
\renewcommand{\lecturer}{Lector:}
\renewcommand{\notesby}{Notas de:}
\renewcommand{\datelec}{Fecha:}
\renewcommand{\chaptername}{Lecci\'on}
\renewcommand{\theoremname}{Teorema}
\renewcommand{\lemmaname}{Lema}
\renewcommand{\corollaryname}{Corolario}
\renewcommand{\propositionname}{Proposici\'on}
\renewcommand{\definitionname}{Definici\'on}
\renewcommand{\conjecturename}{Conjetura}
\renewcommand{\claimname}{Hecho}
\renewcommand{\proofname}{Demostraci\'on}
\renewcommand{\of}{del\ }
\renewcommand{\th}[1]{\ensuremath{#1-\text{\'esimo}}}
\renewcommand{\acknoname}{Agradecimientos}
}


\DeclareOption*{\AtBeginDocument{\incimages}}

\ExecuteOptions{english}
\ProcessOptions



% \hierchenumerate tiene como efecto que los entornos 
% \begin{enumerate} ... \end{enumerate} de 2o y 3r nivel usen 
% etiquetas del tipo 1.3 o 2.1.5

\newcommand{\hierchenumerate}{
\renewcommand{\theenumii}{\arabic{enumii}}
\renewcommand{\theenumiii}{\arabic{enumiii}}
\renewcommand{\labelenumii}{\theenumi.\theenumii}
\renewcommand{\labelenumiii}{\theenumi.\theenumii.\theenumiii}}


% Acknowledgements
% Entorno para escribir agradecimientos; similar al entorno abstract
% \begin{ackno} We thank Menganito Smith for ... \end{ackno}

\newcommand{\ackno}{\section*{\acknoname}}
\def\endackno{\par}


% Entorno para ``excursiones'': comentarios, material de tipo
% marginal o avanzado, etc. (idea original de J.L. Balcazar, en su
% libro ``Programacion Metodica'')
% \begin{excursion} ... \end{excursion} escribe el texto en una fuente
% menor (footnotesize), con margenes mas amplios (quotation) y
% delimitado por corchetes dobles [[ ... ]]

\newcommand{\bcomm}{\ensuremath{[\![}}
\newcommand{\ecomm}{\ensuremath{]\!]}}
\newenvironment{excursion}{%
\begin{quotation}\bcomm\footnotesize}{\ecomm\end{quotation}}


% Inclusion condicional de figuras, tablas, etc. (p.e. figuras en PiCTeX). 
% Hay otros mecanismos posibles que
% son en muchos casos mas adecuados de usar que este.
%
% El mecanismo se basa en tres macros:
% 1- \includeimage{<fichero>}{<longitud>} sirve para incluir el
% fichero cuyo nombre se da o dejar el espacio vertical 
% indicado por el segundo parametro
% 2- \incimages activa las inclusiones de ficheros
% 3- \dontincimages inactiva las inclusiones y en cada \includeimage
% se deja un espacio vertical de la longitud especificada

\newif\ifinclimage
\newcommand{\incimages}{\inclimagetrue}
\newcommand{\dontincimages}{\inclimagefalse}
\newcommand{\includeimage}[2]{\ifinclimage
{\begin{center}
\mbox{\input{#1}}
 \end{center}
}
\else
\vspace{#2}\fi}


% Simbolos matematicos: abreviaturas, operadores frecuentes, etc.
%
% 
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\Z}{\mathbb{Z}}

\newcommand{\bydef}{\mathbin\overset{\text{def}}{=}}       % por definicion
\newcommand{\img}{\text{i}}                                % i = (-1)^(1/2)

% numeros de Stirling de 1era (\stirfk) y 2a especie (\stirsk)
\@ifpackageloaded{amsmath}{%then
\newcommand{\stirfk}{\genfrac[]\z@{}}                    
\newcommand{\stirsk}{\genfrac\{\}\z@{}}}
{%else                   
\providecommand{\binom}[2]{{{#1}\atopwithdelims(){#2}}}
\newcommand{\stirfk}[2]{{{#1}\atopwithdelims[]{#2}}}      
\newcommand{\stirsk}[2]{{{#1}\atopwithdelims\{\}{#2}}}       
}

\newcommand{\ffact}[2]{#1^{\underline{#2}}}                % falling factorial
\newcommand{\rfact}[2]{#1^{\overline{#2}}}                 % raising factorial

\newcommand{\Kron}[1]{\bcomm{#1}\ecomm}            % Generalizacion delta Kronecker

\newcommand{\@ldlm}{[}
\newcommand{\@rdlm}{]}
\newcommand{\Res}[1]{\mathop{\textrm{Res}}\nolimits\left\@ldlm#1\right\@rdlm}
                                                   % Residuo
\newcommand{\Exp}[1]{\mathop{\mathbb{E}}\nolimits\left\@ldlm#1\right\@rdlm}
                                                   % E(X)
\newcommand{\Var}[1]{\mathop{\mathbb{V}}\nolimits\left\@ldlm#1\right\@rdlm}
                                                   % Var(X)
\newcommand{\Prob}[1]{\mathop{\mathbb{P}}\nolimits\left\@ldlm#1\right\@rdlm}
                                                   % Prob

\newcommand{\bigOh}{\mathop{\mathcal{O}}\nolimits}  % O-grande
\newcommand{\hypergeom}[6]{{}_{#1}#2_{#3}           %
\left(\left.\fracwithdelims..[0pt]{#4}{#5}\right| #6\right)} % hipergeometrica

\newcommand{\almostall}{\hbox{\rlap{$_{\thinspace\forall}$}{$^{^\infty}$}}}
\newcommand{\infoften}{\hbox{\rlap{$_{\thinspace\exists}$}{$^{^\infty}$}}}
\newcommand{\convdist}{\mathbin{\overset{\mathcal{D}}{\longrightarrow}}}
\providecommand{\implies}{\Longrightarrow}

\providecommand{\qed}{%
  \ifmmode % if math mode, assume display: omit penalty etc.
  \else \leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
  \fi
  \quad\hbox{\@qed}}
\newcommand{\@qed}{\leavevmode
  \hbox to.77778em{%
  \hfil\vrule
  \vbox to.675em{\hrule width.6em\vfil\hrule}%
  \vrule\hfil}}

% Miscelanea

\newcommand{\Leaf}{\qed}                                    % nodo externo

\providecommand{\trademark}{\ensuremath{^{%                 % trademark
\ooalign{\hfil\raise.05ex\hbox{\footnotesize R}\hfil\crcr\mathhexbox20D}}}}

\providecommand{\email}[1]{E-mail: \texttt{#1}}
\newcommand{\etal}{\emph{et al\@.}\xspace}

% Sustitutos de los entornos cases y align de 'amsmath'
\@ifpackageloaded{amsmath}{}{%
 \renewenvironment{cases}{\left\{\begin{array}{ll}}{\end{array}\right.}
 \newenvironment{align}%
 {\setlength{\arraycolsep}{2pt}%
 \begin{array}{rl}}%
 {\end{array}}
}

% SetFigFont == \relax (da problemas incluso con LaTeX2e)
\def\SetFigFont#1#2#3{\relax}


% Lecture


\newcommand{\lecture}[3]{
\def\@rauthor{#1}
\medskip
{\normalfont
\begin{flushleft}
\lecturer\ \textsc{\@rauthor}\\
\notesby\ \textsc{#2}\\
\datelec\ \textsc{#3}
\end{flushleft}
}\medskip
}



\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
        \huge\bfseries \@chapapp{} \thechapter
        \par\nobreak
        \vskip 20\p@
    \fi
    \interlinepenalty\@M
    \huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}
\def\@makeschapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright
    \normalfont
    \interlinepenalty\@M
    \huge \bfseries  #1\par\nobreak
    \vskip 40\p@
  }}
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{chapter}%
                                   {\protect\numberline{\thechapter}#1}%
                    \else
                      \addcontentsline{toc}{chapter}{#1}%
                    \fi
                    \chaptermark{#1}%
                    \def\@rtitle{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}
