\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{practicas}[2006/02/10 Estilo para practicas]
\typeout{Estilo para practicas --- Mariano Suarez Alvarez (2006/02/10)}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{paralist}
\usepackage{mathtools}
\usepackage{color}
\usepackage[osf,noBBpl]{mathpazo}

\newif\if@emptyfoot
\@emptyfootfalse
\DeclareOption{emptyfoot}{\@emptyfoottrue}

\newif\if@uselastpage
\@uselastpagetrue
\DeclareOption{nolastpage}{\@uselastpagefalse}
\ProcessOptions\relax

\if@uselastpage
\usepackage{lastpage}
\fi

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

\global\let\@Materia\@empty
\global\let\@Cuatrimestre\@empty
\global\let\@Practica\@empty
\global\let\@Titulo\@empty

\def\Materia#1{\gdef\@Materia{#1}}
\def\Cuatrimestre#1{\gdef\@Cuatrimestre{#1}}
\def\Practica#1{\gdef\@Practica{#1}}
\def\Titulo#1{\gdef\@Titulo{#1}}

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

\def\maketitle{\@ifstar{\my@maketitle{\infoparcial}}{\my@maketitle{}}}

\def\my@maketitle#1{%
  \begingroup
    \global\@topnum\z@   % Prevents figures from going at top of page.
    \@maketitle{#1}
    \thispagestyle{plain}
  \endgroup
  \global\let\maketitle\relax
}

\def\@maketitle#1{%
  \begin{center}%
    {\LARGE\scshape \@Materia \par}%
    {\Large \@Cuatrimestre \par}%
    \vspace{1em}%
    {\Large 
      \ifx\@Practica\@empty\else Pr\'actica~\@Practica\fi
      \ifx\@Titulo\@empty\else
        \ifx\@Practica\@empty\else: \fi
        \@Titulo
      \fi
      \par}%
  \end{center}%
  \vskip 1em%
  \hrule\@height 0.2pt\@width\headwidth \vskip-\headrulewidth
  #1%
  \vskip 2.5em}

\def\infoparcial{%
\begingroup
\vskip 1.5em%
\parindent0pt%
\baselineskip1.25\baselineskip
\textsc{Apellido y nombre: }\dotfill\par
\textsc{Comisi\'on: }\dotfill
\ \textsc{L.U.: }\dotfill
\ \textsc{P\'aginas: }\dotfill\par
\vskip 1.5em%
\hrule\@height 0.2pt\@width\headwidth \vskip-\headrulewidth
\endgroup
}

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

\usepackage{fancyhdr}

\fancypagestyle{plain}{
  \fancyhf{}
  \if@emptyfoot
    \cfoot{}
  \else
    \if@uselastpage
      \cfoot{\thepage/\pageref{LastPage}}
    \else
      \cfoot{\thepage}
    \fi
  \fi
}
\lhead{\@Materia{} --- \@Cuatrimestre}
\ifx\@Practica\@empty
  \rhead{}
\else
  \rhead{Pr\'actica \@Practica}
\fi
\if@emptyfoot
  \cfoot{}
\else
  \if@uselastpage
    \cfoot{\thepage/\pageref{LastPage}}
  \else
    \cfoot{\thepage}
  \fi
\fi
\pagestyle{fancy}

% This is usually needed when there are diacritics on the header
\headheight=15pt

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

\usepackage[spanish]{babel}
\languageshorthands{none}

\renewcommand\theenumi{\arabic{enumi}}
\renewcommand\theenumii{\emph{\alph{enumii}}}
\renewcommand\theenumiii{\roman{enumiii}}

\renewcommand\labelenumi{\theenumi.}
\renewcommand\labelenumii{\theenumii)}
\renewcommand\labelenumiii{\theenumiii)}

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

% \foto{archivo}{leyenda}
%
% El archivo no tiene que tener extensión, y tiene que existir como .eps para 
% generar .dvi y después .ps, y como .pdf, para el .pdf...

\def\foto#1#2{%
  \vfill
  \begin{center}
  \includegraphics[height=2in]{#1}\par
  \vskip 1em%
  #2
  \end{center}
  \vfill
} 

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

\let\ejerciciosSetup\relax
\def\ejercicios{%
  \ifnum \@enumdepth >\thr@@\@toodeep\else
    \advance\@enumdepth\@ne
    \edef\@enumctr{enum\romannumeral\the\@enumdepth}%
      \expandafter
      \list
        \csname label\@enumctr\endcsname
        {\usecounter\@enumctr
         \def\makelabel##1{{\textbf{##1}}}%
         \leftmargin0pt%
         \itemindent0pt%
         \labelwidth-\labelsep
         \parsep0pt%
         \itemsep2em%
         \listparindent\parindent
         \ejerciciosSetup
         }%
 \fi}
\let\endejercicios\endlist

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Soluciones

\newenvironment{solucion}{% 
   \begin{list}{}{
    \topsep0pt %
    \itemsep\bigskipamount
    \leftmargin -\@totalleftmargin
    \listparindent\parindent
    \rightmargin 0pt%
    \parsep 0pt plus 1pt}%
  }{%
    \end{list}
  }

\newif\if@sol@seen
\@sol@seenfalse
\definecolor{mygray}{gray}{0.95}
\def\sol#1#2{%
  \message{<ejercicio #1>}%
  \par
  \goodbreak
  \if@sol@seen
    \bigskip
  \else\fi
  \@sol@seentrue
  \begin{center}
  \fboxsep1ex
  \colorbox{mygray}{
    \begin{minipage}{0.8\textwidth}
    \small
    \noindent\textbf{(#1)} #2
    \end{minipage}
    }
  \end{center}
  \unskip
  \nopagebreak
  \addvspace\bigskipamount
  }

\def\x@enumi#1{\@arabic{#1}}
\def\x@enumii#1{\theenumi.#1}
\def\x@enumiii#1{\theenumi.\theenumii.#1}
\def\x@equation#1{#1}

\def\refstepcounter#1{\stepcounter{#1}%
    \protected@edef\@currentlabel
       {\csname x@#1\expandafter\endcsname\csname the#1\endcsname}%
}

\newenvironment{note}
  {\list{}{\listparindent \parindent
           \itemindent    \z@
           \rightmargin   \z@
           \parsep        \z@ \@plus\p@}%
           \footnotesize
           \item\relax}
 {\endlist}

\DeclareRobustCommand{\textsquare}{%
  \begingroup \usefont{U}{msa}{m}{n}\thr@@\endgroup
  }
\newcommand{\qed}{\hfill\textsquare}

\def\eqref#1{(\ref{#1})}
