summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/namespc/namespc.dtx
blob: 108682aeb205373eb8500a3f801cf84d27274386 (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
% \iffalse meta-comment
%
% Copyright (C) 2003 by Alexander Dreyer <adreyer@web.de>
% --------------------------------------------------
% 
% This file may be distributed and/or modified 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.
%
% \fi
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1998/12/01]
%<package>\ProvidesPackage{namespc}
%<package>   [2003/10/03 namespace environment] 
%
%<*batchfile>
\begingroup
\input docstrip.tex
\keepsilent

\usedir{tex/latex/namespc}

\preamble

\iffalse meta-comment

This is a generated file.

Copyright (C) 2003 by  Alexander Dreyer <adreyer@web.de>

This file may be distributed and/or modified 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.

\fi

\endpreamble
\askforoverwritefalse
\generate{\usepreamble\empty
          \usepostamble\empty
          \file{namespc.ind}{\from{namespc.dtx}{indexfile}}}
\generate{\file{namespc.sty}{\from{namespc.dtx}{package}}}

\obeyspaces
\Msg{*************************************************************}
\Msg{*                                                           *}
\Msg{* To finish the installation you have to move the following *}
\Msg{* file into a directory searched by TeX:                    *}
\Msg{*                                                           *}
\Msg{*     namespc.sty                                           *}
\Msg{*                                                           *}
\Msg{* To produce the documentation run the file namespc.dtx     *}
\Msg{* through LaTeX.                                            *}
\Msg{*                                                           *}
\Msg{* Happy TeXing!                                             *}
\Msg{*                                                           *}
\Msg{*************************************************************}
\endgroup
%</batchfile>
%<*driver>
\documentclass{ltxdoc}
\usepackage{namespc}
\usepackage{a4}
\WideMargins
\EnableCrossrefs         
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{namespc.dtx}
\end{document}
%</driver>
%
%<*package>
% \fi
%
% \CheckSum{46}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v1.0}{2003/10/03}{Initial version}
%
% \GetFileInfo{namespc.sty}
%
% \DoNotIndex{\newcommand,\newenvironment,\def,\csname,\endcsname,
% \endcsname,\expandafter,\long,\relax,\:}
% 
%
% \title{The \textsf{namespc} package\thanks{This document
%   corresponds to \textsf{namespc}~\fileversion, dated \filedate.}}
% \author{Alexander Dreyer \\ \texttt{adreyer@web.de}}
%
% \maketitle
%
% \begin{abstract}
%
% The \textsf{namespc} package adds rudimentary \emph{c++}-like namespace
% functionality to \LaTeX. It may be used to declare local \LaTeX{} commands,
% which can be made accessible in a later contexts without defining them 
% globally.
%
% \end{abstract}
%
% \section{Introduction}
% This package can be used to declare local \LaTeX{} commands,
% which may be reused in a later context without polluting the global
% namespace, as an equivalent to \emph{c++}-like namespaces.
%
% \section{Usage}
%
% \DescribeMacro{\namespace}
% This command is used to instantiate and reuse a certain namespace. 
% The |\namespace| command has the following syntax:
%
% |\namespace{|\emph{spcname}|}{|\emph{before}|}{|\emph{body}|}|
%\\
% The first parameter corresponds to the name of the namespace 
% to be started or used.
% The \emph{before} arguments of the current call of |\namespace| are appended 
% to the preamble of namespace \emph{spcname}, which is processed
% before the text in \emph{body} gets processed.
%
% \DescribeEnv{\emph{spcname}}
% With the first call of
% |\namespace{|\emph{spcname}|}{|\ldots|}{|\emph{\ldots}|}| the
% corresponding environment \emph{spcname} is defined which processes 
% all \emph{before} arguments within its preamble.
%
% \DescribeMacro{\namespace*}
% Essentially the same as the |\namespace| command but without generation 
% of the corresponding environment.
%
% \DescribeMacro{\usingnamespace}
% By using |\usingnamespace{|\emph{spcname}|}| one can force \LaTeX{} to 
% process the namespace preamble of \emph{spcname}.
%
% \StopEventually{\PrintChanges\PrintIndex}
%
% \section{Implementation}
%
% We first make |@| to a character in order to use and define internal 
% commands:
%
%    \begin{macrocode}
\makeatletter
%    \end{macrocode}
%
% \begin{macro}{\@defnamespace@ifundef}
%
% First we define an internal macro which will be used to instatiate the 
% (internal) namespace preamble macro |\@namespace@|\emph{spcname} 
%
%    \begin{macrocode}
\def\@defnamespace@ifundef#1{
  \@ifundefined{#1}{
    \long\expandafter\def\csname#1\endcsname{}
  }{}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@n@mesp@cestar}
% Now we are able to define the internal version of the starred |\namespace|
% command.
%
%    \begin{macrocode}
\newcommand{\@n@mesp@cestar}[3]{
  \@defnamespace@ifundef{@namespace@#1}
  \expandafter\g@addto@macro\csname @namespace@#1\endcsname{#2}%
  {
    \expandafter\relax\csname @namespace@#1\endcsname
    #3
  }
}
%    \end{macrocode}
%    \end{macro}
%
% \begin{macro}{\usingnamespace}
% The user command |\usingnamespace| just forces initiatiation and processing 
% of the namespace preamble.
%
%    \begin{macrocode}
\newcommand{\usingnamespace}[1]{
  \@defnamespace@ifundef{@namespace@#1}
  \csname @namespace@#1\endcsname
}
%    \end{macrocode}
%    \end{macro}
%
% \begin{macro}{\@provide@namespace@env}
% This is an internal command which provides the corresponding environment.
%
%    \begin{macrocode}
\def\@provide@namespace@env#1{
  \@ifundefined{#1} {
   \newenvironment{#1}{\usingnamespace{#1}}{}  
  }{}
}
%    \end{macrocode}
%    \end{macro}
%
% \begin{macro}{\::}
% The double colon notation may be used to access commands defined within a
% namespace preamble once. Note that the command's arguments have to be
% surrounded by colons:
%    \begin{macrocode}
\def\::#1::#2:#3:{%
  {\csname @namespace@#1\endcsname
   \csname#2\endcsname#3}
}
%    \end{macrocode}
%    \end{macro}
%
% \begin{macro}{\@n@mesp@ce}
% Next we just add the definition of the respective environment to |\namespace*|
% in order to obtain the internal version of |\namespace|:
%
%    \begin{macrocode}
\newcommand{\@n@mesp@ce}[3]{
  \@provide@namespace@env{#1}
  \@n@mesp@cestar{#1}{#2}{#3}
}
%    \end{macrocode}
%    \end{macro}
%
% \begin{macro}{\namespace}
% Finally we use the |\@ifstar| macro to define the user commands
% |\namespace| and |\namespace*|:
%
%    \begin{macrocode}
\newcommand*{\namespace}{\@ifstar\@n@mesp@cestar\@n@mesp@ce}
%    \end{macrocode}
%    \end{macro}
% |@| is made special character again:
%    \begin{macrocode}
\makeatother
%    \end{macrocode}
%
% \section{Example}
%
% This is example code for the use of the \textsf{namespc}~package:
%
%\begin{verbatim}
%\namespace{spcname}
%{\newcommand{\spcwidecmd}{\emph{command}\xspace}}{
% Using \spcwidecmd for the first time.
%} % end of namespace
%
% % not defined here: \spcwidecmd
%
%\namespace{spcname}{}{
%  \spcwidecmd may be used again later.
%} % end of namespace
%
%\begin{spcname}
%  We can also use \spcwidecmd within the corresponding environment\ldots
%\end{spcname}
%
%  Alternatively we may use the double colon notation: \::spcname::spcwidecmd::
%
%\usingnamespace{spcname}
%\ldots{} or globally: \spcwidecmd.
%
%\end{verbatim}
%
% And here's the corresponding \LaTeX{} output:
% \\
%\namespace{spcname}
%{\newcommand{\spcwidecmd}{\emph{command}\ }}{
%
% Using \spcwidecmd for the first time.
%} 
%
%
%\namespace{spcname}{}{
%  \spcwidecmd may be used again later.
%} 
%
%\begin{spcname}
%  We can also use \spcwidecmd within the corresponding environment\ldots
%\end{spcname}
%
%  Alternatively we may use the double colon notation: \::spcname::spcwidecmd::
%
%\usingnamespace{spcname}
%\ldots{} or globally: \spcwidecmd
%
% \Finale
% 
% \endinput
%</package>
%
%<*indexfile>

 \begin{theindex} 
 \makeatletter\scan@allowedfalse
{\bfseries\hfil Symbols\hfil}\nopagebreak

  \item \verb*+\::+\pfill \main{24}
  \item \verb*+\@defnamespace@ifundef+\pfill \main{2}, 8, 16
  \item \verb*+\@ifstar+\pfill 32
  \item \verb*+\@ifundefined+\pfill 3, 20
  \item \verb*+\@n@mesp@ce+\pfill \main{28}, 32
  \item \verb*+\@n@mesp@cestar+\pfill \main{7}, 30, 32
  \item \verb*+\@provide@namespace@env+\pfill \main{19}, 29
  \item {\ttfamily \emph  {spcname}} (environment)\pfill \usage{1}

  \indexspace
{\bfseries\hfil E\hfil}\nopagebreak

  \item environments:\efill 
 \subitem {\ttfamily \emph  {spcname}}\pfill \usage{1}

  \indexspace
{\bfseries\hfil G\hfil}\nopagebreak

  \item \verb*+\g@addto@macro+\pfill 9

  \indexspace
{\bfseries\hfil M\hfil}\nopagebreak

  \item \verb*+\makeatletter+\pfill 1
  \item \verb*+\makeatother+\pfill 33

  \indexspace
{\bfseries\hfil N\hfil}\nopagebreak

  \item \verb*+\namespace+\pfill \usage{1}, \main{32}
  \item \verb*+\namespace*+\pfill \usage{1}

  \indexspace
{\bfseries\hfil U\hfil}\nopagebreak

  \item \verb*+\usingnamespace+\pfill \usage{1}, \main{15}, 21

 \end{theindex}


%</indexfile>