\ProvidesPackage{listofanswers}[06/11/2012]

% version 1.2

\newcounter{group}
\newcounter{exercise}[group]
\newcounter{subexercise}[exercise]


\newcommand{\group}{%
	\refstepcounter{group}
	\subsection*{\centering\exercisesname.\;\groupname\;\thegroup}
   \addcontentsline{loa}{group}{\groupname\;\thegroup}
}

\newcommand{\exercise}{%
    \refstepcounter{exercise}
    \@ifstar\exerciseStar\exerciseNoStar
}

\newcommand{\exerciseNoStar}[1]{%
    \@ifnextchar\bgroup{\exerciseNoStarTwo{#1}}{\exerciseNoStarOne{#1}}
}

\newcommand{\exerciseNoStarOne}[1]{%
	\textbf{\theexercise.} #1
}

\newcommand{\exerciseNoStarTwo}[2]{%
	\textbf{\theexercise.} #1
	\addcontentsline{loa}{exercise}{%
     \textbf{\theexercise.}~#2\quad
	}
}

\newcommand{\exerciseStar}[2]{%
	\textbf{\theexercise*.} #1
	\addcontentsline{loa}{exercise}{%
     \textbf{\theexercise.}~#2\quad
	}
}

\newcommand{\subexercise}[1]{%
    \refstepcounter{subexercise}
    \@ifnextchar\bgroup{\subexerciseTwo{#1}}{\subexerciseOne{#1}}
}

\newcommand{\subexerciseOne}[1]{%
	\@alph\thesubexercise) #1
}

\newcommand{\subexerciseTwo}[2]{%
	\@alph\thesubexercise) #1
   \addcontentsline{loa}{subexercise}{%
     \textbf{\theexercise.}~\@alph\thesubexercise)~#2\quad
	}
}

\newcommand*{\l@group}[2]{\subsection*{\centering #1, p. #2}}

\newcommand*{\l@exercise}[2]{\noindent #1}

\newcommand*{\l@subexercise}[2]{\noindent #1}

\newcommand{\listofanswers}{%
	\answershead
   \renewcommand{\thefootnote}{\fnsymbol{footnote}}	
	\@starttoc{loa}
	\addcontentsline{toc}{\answerstype}{\answersname}
}

\@ifclassloaded{book}
{\newcommand{\answershead}{\chapter*{\answersname}}
 \newcommand{\answerstype}{chapter}}
{\newcommand{\answershead}{\section*{\answersname}}
 \newcommand{\answerstype}{section}}

\newcommand{\answersname}{Respuestas}
\newcommand{\exercisesname}{EJERCICIOS}
\newcommand{\groupname}{Grupo}
