% +--------------------------------------------------+
% | Documentation in clear text follows              |
% +--------------------------------------------------+
%
% (c) 2002 Javier Bezos. All Rights Reserved.
%
% This file can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version.
% 
% 
% Usage
% ~~~~~
% When an environment is left open, LaTeX gives an error at the
% end of the document. However it only informs about the first
% of them, while the rest are shown with meaningless errors:
% 
% (\end occurred inside a group at level N)
% 
% This package replaces them with more useful messages
% which show which environments (in reverse order) were
% not closed.
% 
% That's all. There are no user macros. Just use the package.
%
% Code
% ~~~~

\def\fileversion{1.0}
\def\filedate{2002/04/20}

\ProvidesPackage{checkend}[2002/04/20 v1.0 Environment checking]

\def\chkend@checkend{%
  \def\@tempa{document}%
  \ifx\@currenvir\@tempa
  \else
    \count@\errorcontextlines
    \errorcontextlines\z@
    \PackageError{checkend}{%
      \@currenvir \@currenvline \space open at 
         \string\end{document}}%
      {The package has detected an open environment at the 
         end\MessageBreak
       of the document}%
    \errorcontextlines\count@
    \csname end\@currenvir\endcsname
    \endgroup
    \chkend@checkend
  \fi}

\AtEndDocument{\chkend@checkend}

\endinput