summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/version/version.sty
blob: 2f5868e8a7bca9afc5ab32c2e21990c81fae5a78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 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.