% Package robustglossary.sty, Wilberd van der Kallen Feb 2005.
%
% This package is similar to robustindex.sty, but it is much simpler, as it
% does not try to get makeindex to do anything. You are expected to convert
% filename.glo into something usable yourself. This converted file should
% have a different name, so that it can be \input while filename.glo is
% being rewritten. Or you can actually paste entries into the main file, as we
% did in robustsample.tex.
%
% Copyright 2005 Wilberd van der Kallen
%
% This file may be distributed under the conditions of the LaTeX Project Public
% License, either version 1.2 of this license or (at your option) any
% later version.  The latest version of this license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.2 or later is part of all distributions of LaTeX
% version 1999/12/01 or later.

\ProvidesPackage{robustglossary}
  [2005/02/23
  glossary entries with pagerefs]

\newcounter{gloctr}%

\newcounter{maxgloctr}% To check if number of \glossary commands has changed.

\newcommand{\glostring}{glo.}%

\def\@wrglossary#1{%
  \stepcounter{gloctr}%
  \stepcounter{gloctr}%
  \@bsphack \protected@write \@auxout {}{%
     \string \newlabel {\glostring\thegloctr}{{\relax }{\thepage }%
     \ifx\ifHy@bookmarks\undefined\else{\relax }{page.\thepage }{}\fi%
     }%
  }%
  \@esphack
  \protected@write
    \@glossaryfile {}{\string \glossaryentry
    {#1}{\string\glopageref{\thegloctr}}}%
  \endgroup
  \@esphack
}%

\newcommand{\glopageref}[1]{%
   \ifnum\c@maxgloctr<#1\relax\setcounter{maxgloctr}{#1}\fi
   \pageref{\glostring#1}%
}%

\AtEndDocument{%
   \ifnum\c@gloctr=\c@maxgloctr
   \else
      \ifnum\c@gloctr=0%
         \PackageWarning{robustglossary}{%
	    Package needs \string\make glossary in preamble. Detected%
	 }%
      \else
         \PackageWarning{robustglossary}{%
            Glossary not up to date. Detected%
         }%
      \fi
   \fi
}%

\relax
