%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% version.sty version 2.0
%
% Copyright 2009 by Donald Arseneau (asnd@triumf.ca)
% based on version.sty Copyright 1990 by Stephen Bellantoni,
% loosely based on "annotation.sty" by Tom Hofmann.
% 
% These macros may be freely used, transmitted, reproduced, or modified
% provided that the copyright notice and this permission is retained.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Version control macros. This package lets you define environments whose 
% contents will be optionally included in or excluded from the text when 
% you run LaTeX.
%
% Maybe you should be using one of versions.sty, comment.sty, or optional.sty. 
%
% Usage:
%     
%       \includeversion{NAME}
% After this declaration, contents of the environment "NAME", that is,
% text between \begin{NAME} and \end{NAME}, will be processed in the 
% normal way.  If an environment called NAME is already defined, that
% definition is retained; if no such environment exists a simple 
% definition is provided.
%
%       \excludeversion{NAME}
% This indicates that text between \begin{NAME} and \end{NAME} will
% be totally deleted. Very long sections of excluded text might cause 
% a `TeX capacity exceeded' error.  Exclusion ends with the first
% detected \end{NAME}, even if there are additional \begin{NAME} 
% declarations in the skipped text; that is, nesting of environments
% is not permitted.  Skipped text may have unbalanced braces, if
% they would also work in the \includeversion case.
%
%       \excludeversion[text]{NAME}
% This indicates that text between \begin{NAME} and \end{NAME} will
% be replaced by the specified text.
%
% You can define environments for as many versions as you want.
% A `comment' environment has already been pre-defined with
% \excludeversion{comment}; you can override this by declaring 
% \includeversion{comment}.
%
% Example:
%   \includeversion{abridged}\excludeversion{unabridged}
%   \excludeversion[(redacted)]{redact}
%   Text for the
%   \begin{abridged}
%      short
%   \end{abridged}
%   \begin{unabridged}
%      long and really longwinded, opaque and boring
%   \end{unabridged}
%   version of the paper. Punctuation works correctly\begin{unabridged}
%   because sphack is used\end{unabridged}.
%   \begin{comment} This is deleted by default. \end{comment}
%   \begin{redact}This information was withdrawn\end{redact}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
\ProvidesPackage{version}[2009/09/15 \space v 2.0]

\newcommand\includeversion[1]{%
  \def\@tempa{\@ifundefined{@Esphack}{\@esphack}{\@Esphack}}%
  \expandafter\ifx\csname #1\endcsname\@tempa % previously excluded ...
     \expandafter\let\csname #1\endcsname\@undefined 
  \fi % ... so do not retain existing definition
  \@ifundefined{#1}{% Undefined, define a stub
    \expandafter\gdef\csname #1\endcsname{}%
    \expandafter\gdef\csname end#1\endcsname{}%
    \PackageInfo{version}{Including #1 environments declared}
  }{% % defined, so retain meaning
    \PackageInfo{version}{Retain meaning of #1 environment declared}%
  }%
}%
%
\newcommand\excludeversion[2][]{%
  \expandafter\gdef\csname #2\endcsname{%
    #1% optional replacement text
    \@bsphack % avoid double spaces
    \catcode`\&=12\catcode`\{=12\catcode`\}=12\relax
    \@Vii@ExcludeToEnd % Do exclusion until \end{\@currenvir}
  }%
  \expandafter\gdef\csname end#2\endcsname{%
      \@ifundefined{@Esphack}{\@esphack}{\@Esphack}}%
  \PackageInfo{version}{Excluding #2 environments declared}%
}%
%
%  Consume text delimited by the token \end followed by
%  the current environment name.  Nesting is **NOT** followed
%
\long\def\@Vii@ExcludeToEnd#1\end#2{%
  \def\@tempa{#2}%
  \ifx\@tempa\@Vii@Brace
     \let\@tempa\@Vii@ReadEnd
  \else
    \ifx\@tempa\@currenvir
       \def\@tempa{\end{#2}}%
    \else
       \def\@tempa{\@Vii@ExcludeToEnd}%
    \fi
 \fi
 \@tempa
}
%
\edef\@Vii@Brace{\string{}%
%
\expandafter\def\expandafter\@Vii@ReadEnd\expandafter#\expandafter1\string}{%
  \@Vii@ExcludeToEnd \end{#1}%
}
%
\excludeversion{comment}
 
\endinput

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% version v. 2 based on version.sty by:
% Stephen Bellantoni 1990, loosely based on "annotation.sty" by Tom Hofmann.
%
% Donald Arseneau produced this version because Stephen Bellantoni had no 
% permissions explicitly stated in his version.  DA has tried to remain
% compatible but has indulged in "upgrades" (bloat) which might not be 
% proper.
%
% Although the code is entirely rewritten, there are a few principal 
% differences with version 2:
%
% Verbatim catcoding of braces (to scan over unbalanced braces) is
% still applied, but is not required to be effective: the \end{NAME}
% will be detected whether the catcode changes are effective or not.
%
% Verbatim catcode for & is set to allow skipping rows of a tabular.
%
% Definitions of existing environments are now retained by \includeversion,
% unless the existing definition is the one made by \excludeversion.
%
% Added optional argument for \excludeversion for a textual tag to 
% replace the excluded content.