\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{practicas}[2009/03/18 Estilo para practicas]
\typeout{Estilo para practicas --- Mariano Suarez Alvarez (2009/03/18), modificado,
probablemente para peor, por Pablo Zadunaisky (2015/03/01)}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{paralist}
\usepackage{mathtools}
\usepackage{ntheorem}
\usepackage{enumitem}
\usepackage{comment}
\usepackage{xifthen}
\usepackage{xcolor}
\usepackage{colonequals}
\usepackage[osf,noBBpl]{mathpazo}
\usepackage{stmaryrd}
%\usepackage[T1]{fontenc}

\addtolength{\oddsidemargin}{-.5in}
\addtolength{\evensidemargin}{-.5in}
\addtolength{\textwidth}{1in}
\addtolength{\topmargin}{-.5in}
\addtolength{\textheight}{1in}



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

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

\newif\if@solutions
\@solutionsfalse
\DeclareOption{solutions}{\@solutionstrue}
\DeclareOption{nosolutions}{\@solutionsfalse}

\ProcessOptions\relax

\if@uselastpage
\usepackage{lastpage}
\fi

\if@solutions
\def\SOLUTIONS{}
\fi

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

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

\newcommand\Materia[2][]{%
  \gdef\@Materia{#2}%
  \ifthenelse{\isempty{#1}}{\global\let\@MateriaRunning\@Materia}{\gdef\@MateriaRunning{#1}}%
  }
\def\Cuatrimestre#1{\gdef\@Cuatrimestre{#1}}
\def\Practica#1{\gdef\@Practica{#1}}
\def\Titulo#1{\gdef\@Titulo{#1}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\maketitle{\my@maketitle{}}
\def\maketitleParcial{\my@maketitle{\infoparcial}}

\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\textwidth \vskip-\headrulewidth
  #1%
  \vskip 2.5em}

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

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

\usepackage{fancyhdr}

\fancypagestyle{plain}{
  \fancyhf{}
  \if@emptyfoot
    \cfoot{}
  \else
    \if@uselastpage
      \cfoot{\thepage/\pageref{LastPage}}
    \else
      \cfoot{\thepage}
    \fi
  \fi
}
\lhead{\@MateriaRunning{} --- \@Cuatrimestre}
\rhead{\ifx\@Practica\@empty\else 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[medium]{titlesec}

% no ponemos los números de las secciones, pero no usamos \section*
% para que los ejercicios se numeren dentro de cada sección
\titleformat{\section}
  {\normalfont\large\bfseries}{}{0em}{}
\titlespacing*{\section}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}

\titleformat{\subsection}
  {\normalfont\normalsize\bfseries}{}{0em}{}
\titlespacing*{\subsection}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\usepackage[spanish, es-minimal, es-sloppy]{babel}
%\renewcommand{\shorthandsspanish}{}

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

% \foto[height]{archivo}{leyenda}{texto}
%
% 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{\@ifnextchar[{\@foto}{\@foto[2in]}}

\long\def\@foto[#1]#2#3#4{%
  \vspace*{\stretch{1}}
  \begin{center}
  \begin{minipage}{.9\textwidth}
  \begin{center}
  \includegraphics[height=#1]{#2}\par
  \small
  \vskip 1em%
  #3\par
  \vspace*{1pc}
  \begin{minipage}{0.8\textwidth}
  \CenterLastLine{#4}
  \end{minipage}
  \end{center}
  \end{minipage}
  \end{center}
  \vspace*{\stretch{1}}
} 

% Sacado de <http://groups.google.com/group/comp.text.tex/msg/975ea0e06792bb5b>
\newsavebox{\TextBox}
\newsavebox{\LastLine}
\newcommand{\CenterLastLine}[1]{%
  \savebox{\TextBox}{%
    \begin{minipage}{\linewidth}%
      #1\par
      \setbox\LastLine=\lastbox
      \unskip
      \centerline{\unhbox\LastLine\hfilneg}%
    \end{minipage}%
  }%
  \usebox{\TextBox}%
} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \qed

\chardef\three3
\newcommand{\textsquare}{%
  \begingroup \usefont{U}{msa}{m}{n}\three\endgroup}
\newcommand{\qed}{%
  \leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
  \quad\hbox{\textsquare}%
}

\let\operator@font\sf

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ejercicios, subitems

\let\oldsection\section
\let\oldsubsection\subsection
\def\section{\let\theinnersection\thesection\oldsection}
\def\subsection{\let\theinnersection\thesubsection\oldsubsection}


\newlist{ejercicios}{enumerate}{1}
\setlist[ejercicios]{
     fullwidth,
     itemsep=1.25ex plus 0.5ex minus 0.25ex,
     topsep=\medskipamount,
     font=\bfseries,
     label={\arabic*.},
     ref={\textbf{\arabic*}}
}

\newlist{ejitems}{enumerate}{3}
\setlist[ejitems,1]{
  label=(\emph{\alph*}),
  ref={\theejerciciosi(\emph{\alph*})},
  align=left,
  labelwidth=\parindent,
  itemsep=2pt plus 1pt minus 1pt,
  before=\advance\mathindent-\leftmargin
}
\setlist[ejitems,2]{
  label=(\emph{\roman*}),
  ref={\theejitemsi(\emph{\roman*})},
  align=left,
  labelwidth=\parindent,
  itemsep=2pt plus 1pt minus 1pt,
  before=\advance\mathindent\leftmargin
}

\setlist{listparindent=\parindent,parsep=0pt,partopsep=0pt}

\def\ejitem#1{\textup{(\textit{\@alph#1})}}

\newlist{tfae}{enumerate}{1}
\setlist[tfae]{
     itemsep=0.25ex plus 0.5ex minus 0.25ex,
     topsep=\medskipamount,
     font=\normalfont,
     label={(\emph{\roman*})},
     ref={(\emph{\roman*})},
}
\newcommand\tfaeitem[1]{(\emph{\romannumeral#1})}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \item* pone una estrella en el número de ejercicio

\let\myolditem\item
\def\item{\@ifnextchar*\starreditem\myolditem}
\sbox\@tempboxa{$^\dagger$}
\newdimen\starwidth
\starwidth\wd\@tempboxa
\def\starreditem*{%
  \let\myoldmakelabel\makelabel
  \def\makelabel##1{\myoldmakelabel{\hskip-\starwidth$^\dagger$##1}}%
  \myolditem\let\makelabel\myoldmakelabel
  }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Esto hace que en ejitems podamos usar el hook para alinear con las
% ecuaciones que no estan en ejercicios.
% NOTA: esto depende de que se esté usando fleqn como opcion a la clase...
\AtBeginDocument{%
  \newdimen\oldmathindent
  \oldmathindent\mathindent
  \advance\mathindent\leftmargini
}

\newcommand\header[1]{\textit{#1.}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% soluciones
\ifthenelse{\isundefined{\SOLUTIONS}}{%
  \specialcomment{Solucion}{}{}
  \excludecomment{Solucion}
}{%
 \usepackage{framed}
 \definecolor{shadecolor}{gray}{0.85}
  \newenvironment{Solucion}[1][Soluci\'on]{
    \begingroup
    \begin{shaded}
    \mathindent\oldmathindent%
    \noindent\small\textit{#1. }%
    \ignorespaces}%
   {\end{shaded}
   \endgroup
   }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% indicaciones

\newenvironment{Indicacion}%
  {\par
   \smallskip
   \noindent\footnotesize\textit{Sugerencia. }%
   \ignorespaces}%
  {}

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

\def\xycenter#1{\xy*[c]\xybox{#1}\endxy}

\usepackage[
  colorlinks,
  breaklinks,
  linkcolor=black
  ]{hyperref}

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