summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/xcomment/xcomment.tex
blob: e8888f904aa874e5d760cb771c38efbde9f65e45 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
%% $Id: xcomment.tex 316 2010-05-14 21:32:34Z herbert $
%%
%% COPYRIGHT 1993/2010, by Timothy Van Zandt, tvz@Princeton.EDU
%% COPYRIGHT 2010, by Herbert Voss, hvoss@tug.org
%%
%% DESCRIPTION:
%%
%% This program 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.
%%
\def\fileversion{1.3}
\def\filedate{10/05/14}
%%
\@ifundefined{xcomment@@@}{}{\endinput}
\typeout{Style-Option: `xcomment' v\fileversion \space <\filedate> (tvz) }
\def\newxcomment{\@ifnextchar [{\@newxcommentwitharg}{\@newxcomment}}
\def\@newxcomment#1{%
  \expandafter\def\csname #1\endcsname##1{\@xcomment{#1}{##1}}}%
\def\@newxcommentwitharg[#1]#2{%
  \expandafter\def\csname #2\endcsname{\@xcomment{#2}{#1}}}
\newxcomment{xcomment}
\def\envirsep{\par}
\def\rescanfile#1{\def\@rescanfile{#1}}
\rescanfile{\jobname.tmp}
\def\norescanfile{\let\@rescanfile\relax}
\def\@nofloat#1{\hrule height\z@\nobreak\vfill\vbox\bgroup\def\@captype{#1}}
\def\end@nofloat{\egroup\nobreak\vfill\nobreak\hrule height\z@\medbreak}
\def\nofloat#1{\@for\@tempa:=#1\do{\@namedef{#1}{\@nofloat{#1}}%
  \@namedef{end#1}{\end@nofloat}}}
\def\xc@makeother#1{%
  \ifnum\the\catcode`#1=0\catcode`#112%
  \else \ifnum\the\catcode`#1=1\catcode`#112%
    \else \ifnum\the\catcode`#1=2\catcode`#112%
      \else \ifnum\the\catcode`#1=6\catcode`#112%
  \fi\fi\fi\fi\relax}
\newwrite\tokout
\newread\tokin
\def\rescan#1{%
  \ifx\@rescanfile\relax\else
    \ifx\@rescanfile\@empty #1{}\else
      \immediate\openout\tokout=\@rescanfile
      \immediate\write\tokout{{\the#1}\relax}%
      \immediate\closeout\tokout
      \openin\tokin=\@rescanfile
      \read\tokin to\@tempd
      \closein\tokin
      \expandafter#1\@tempd%
  \fi\fi}
\def\@xcomment#1#2{%
  \ifx\@preamblecmds\@notprerr
    \def\xc@csname{#1}%
    \edef\xc@envirlist{#2}%
    \ifx\xc@envirlist\@empty \@bsphack \else
      \begingroup
      \def\@envirsep{}%
      \@ifundefined{normal@begin}{\let\normal@begin\begin}{}%
      \@ifundefined{normal@end}{\let\normal@end\end}{}%
      \def\begin##1{\do@begin{##1}\normal@begin{##1}}%
      \def\end##1{\normal@end{##1}\do@end}%
      \def\do@begin##1{\@ifundefined{##1}{}{\def\do@end{}}}%
      \let\do@end\xc@begin
    \fi
    \let\next\xc@begin
  \else
    \expandafter\@temptokena\expandafter{\document\@xcomment{@@@}{#2}}%
    \edef\document{\the\@temptokena}%
    \let\next\relax
  \fi
  \next}
\def\end@xcomment{\ifx\xc@envirlist\@empty \@esphack \else \endgroup \fi}%
\def\xc@begin{%
  \begingroup
    \let\do\xc@makeother
    \dospecials
    \ifx\xcommentchar\@empty\else
      \expandafter\catcode\expandafter`\xcommentchar=14
    \fi
    \catcode`\^^M\active
    \xcomment@}
\def\xcommentchar{\%}
\begingroup
\catcode`\!=12
\catcode`\[=12
\catcode`\]=12
\catcode`\"=12
\lccode`\!=`\\
\lccode`\[=`\{
\lccode`\]=`\}
\lccode`\"=`\%
\catcode`\~=\active
\lccode`\~=`\^^M
\lowercase{
  \gdef\xcomment@#1~{\xcomment@@#1\@nnil!\@nil}
  \gdef\xcomment@@#1!{\xcomment@@@}
  \gdef\xcomment@@@#1\@nil{%
    \def\@tempa{#1}%
    \ifx\@tempa\@empty
      \let\next\xcomment@
    \else
      \def\next{\xcomment@@#1\@nil}%
      \@testtrue
      \xc@checkbegin#1\relax begin[]\relax\relax
      \if@test
        \xc@checkend#1\relax end[]\relax\relax
        \if@test
          \xc@checkinput#1\relax input[]\relax\relax
          \if@test
            \xc@checkinclude#1\relax include[]\relax\relax
            \if@test
              \xc@checkendinput#1\relax endinputss\relax\relax
    \fi\fi\fi\fi\fi
    \next}
  \gdef\xc@checkbegin#1begin[#2]#3\relax#4\relax{%
    \def\@tempa{#1}%
    \ifx\@tempa\@empty
      \def\@tempa{#2}%
      \@for\@tempb:=\xc@envirlist\do{%
        \ifx\@tempa\@tempb\def\next{\xc@end{#2}#3\@nil}\fi}%
    \fi}
  \gdef\xc@checkend#1end[#2]#3\relax#4\relax{%
    \def\@tempa{#1}%
    \ifx\@tempa\@empty
      \@testfalse
      \def\@tempa{#2}\def\@tempb{document}%
      \ifx\@tempa\@tempb
        \def\next{\endgroup\end@xcomment\end{document}}%
      \else
        \ifx\@tempa\xc@csname
          \def\next{\end@@xcomment{#2}#3\@nil}%
    \fi\fi\fi}
  \gdef\xc@checkinput#1input[#2]#3\relax#4\relax{%
    \def\@tempa{#1}%
    \ifx\@tempa\@empty
      \def\next{\expandafter\xcomment@\@@input #2 \xcomment@@#3\@nil}%
      \@testfalse
    \fi}
  \gdef\xc@checkendinput#1endinput#2#3\relax#4\relax{%
    \def\@tempa{#1}%
    \ifx\@tempa\@empty\ifcat\noexpand#2a\relax\else
      \let\next\endinput
    \fi\fi}
  \gdef\xc@checkinclude#1include[#2]#3\relax#4\relax{%
    \def\@tempa{#1}%
    \ifx\@tempa\@empty
      \def\next{%
        \global\let\xc@savedinput\@@input
        \def\@@input{%
          \global\let\@@input\xc@savedinput
          \expandafter\xcomment@\@@input}%
        \include{#2}%
        \global\let\@@input\xc@savedinput
        \xcomment@@#3\@nil}%
      \@testfalse
    \fi}
  \gdef\end@@xcomment#1#2\@nnil!\@nil{%
    \endgroup
    \toks@{#2 }\rescan{\toks@}%
    \edef\next{\noexpand\end@xcomment\noexpand\end{#1}\the\toks@}%
    \next}%
  \gdef\xc@end#1#2\@nnil!\@nil{%
    \endgroup
    \@envirsep \let\@envirsep\envirsep
    \toks@{#2 }\rescan{\toks@}%
    \edef\next{\noexpand\normal@begin{#1}\the\toks@}%
    \next}%
  }%  END OF LOWERCASE
\endgroup
\endinput
%%
%% End of file `xcomment.sty'.