%% Copyright (C) 2011 by Martin Scharrer <martin@scharrer-online.de>
%% ---------------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% 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.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Martin Scharrer.
%%
%% This work consists of the files storebox.dtx and storebox.ins
%% and the derived filebase storebox.sty.
%%
\ProvidesPackage{storebox}[%
    2011/10/21
    v1.1
    Store and reuse boxes in a file size efficient way]
\DeclareOption{disable}{\let\ifstorebox\iffalse}
\DeclareOption{enable}{\let\ifstorebox\iftrue}
\ProcessOptions*
\edef\@tempa{\@ptionlist{\@currname.\@currext}}
\ifx\@tempa\empty
    \RequirePackage{ifpdf}
    \expandafter\let\csname ifstorebox\expandafter\endcsname\csname ifpdf\endcsname
\fi
\RequirePackage{collectbox}[2011/08/04]
\newcommand*\storebox{%
    \begingroup
        \def\@tempa{storebox}%
    \ifx\@currenvir\@tempa
        \endgroup
        \expandafter\@storebox@env
    \else
        \endgroup
        \expandafter\@storebox
    \fi
}
\ifstorebox
\def\@storebox#1{%
    \begingroup
    \@collectboxto\collectedbox{\pdfxform\collectedbox\endgroup\mathchardef#1=\pdflastxform}%
}
\def\@storebox@env#1{%
    \edef\@tempa{%
        \setbox\collectedbox\hbox\bgroup%
            \def\noexpand\the@storebox{\noexpand#1}%
    }%
    \@tempa
    \begingroup
    \aftergroup\@storebox@env@end
    \@endpefalse
    \color@setgroup
    \begingroup
    \def\@currenvir{storebox\empty}%
    \ignorespaces
}
\def\endstorebox{%
    \unskip
    \endgroup
    \color@endgroup
}
\def\@storebox@env@end{%
    \edef\@tempa{%
        \egroup
        \pdfxform\collectedbox
        \endgroup
        \mathchardef\expandafter\noexpand\the@storebox=\pdflastxform
    }%
    \@tempa
}
\newcommand*\newstorebox[1]{%
    \@ifdefinable{#1}{\let#1\relax}%
}
\newcommand*\usestorebox[1]{%
    \mbox{\pdfrefxform#1}%
}
\else
\def\@storebox#1{\@collectboxto{#1}{}}
\def\@storebox@env{%
  \edef\@currenvir{\@currenvir\noexpand\noexpand\noexpand\empty}%
  \lrbox
}
\def\endstorebox{%
    \endlrbox
    \edef\@currenvir{\@currenvir}%
}
\@ifdefinable\newstorebox{%
\let\newstorebox\newsavebox
}
\@ifdefinable\usestorebox{%
\let\usestorebox\usebox
}
\fi

\endinput
%%
%% End of file `storebox.sty'.
