| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2003 by Alexander Dreyer <[email protected]> |
| 4 |
% -------------------------------------------------- |
| 5 |
% |
| 6 |
% This file may be distributed and/or modified under the |
| 7 |
% conditions of the LaTeX Project Public License, either version 1.2 |
| 8 |
% of this license or (at your option) any later version. |
| 9 |
% The latest version of this license is in: |
| 10 |
% |
| 11 |
% http://www.latex-project.org/lppl.txt |
| 12 |
% |
| 13 |
% and version 1.2 or later is part of all distributions of LaTeX |
| 14 |
% version 1999/12/01 or later. |
| 15 |
% |
| 16 |
% \fi |
| 17 |
% |
| 18 |
% \iffalse |
| 19 |
%<package>\NeedsTeXFormat{LaTeX2e}[1998/12/01] |
| 20 |
%<package>\ProvidesPackage{namespc} |
| 21 |
%<package> [2003/10/03 namespace environment] |
| 22 |
% |
| 23 |
%<*batchfile> |
| 24 |
\begingroup |
| 25 |
\input docstrip.tex |
| 26 |
\keepsilent |
| 27 |
|
| 28 |
\usedir{tex/latex/namespc} |
| 29 |
|
| 30 |
\preamble |
| 31 |
|
| 32 |
\iffalse meta-comment |
| 33 |
|
| 34 |
This is a generated file. |
| 35 |
|
| 36 |
Copyright (C) 2003 by Alexander Dreyer <[email protected]> |
| 37 |
|
| 38 |
This file may be distributed and/or modified under the conditions of |
| 39 |
the LaTeX Project Public License, either version 1.2 of this license |
| 40 |
or (at your option) any later version. The latest version of this |
| 41 |
license is in: |
| 42 |
|
| 43 |
http://www.latex-project.org/lppl.txt |
| 44 |
|
| 45 |
and version 1.2 or later is part of all distributions of LaTeX version |
| 46 |
1999/12/01 or later. |
| 47 |
|
| 48 |
\fi |
| 49 |
|
| 50 |
\endpreamble |
| 51 |
\askforoverwritefalse |
| 52 |
\generate{\usepreamble\empty |
| 53 |
\usepostamble\empty |
| 54 |
\file{namespc.ind}{\from{namespc.dtx}{indexfile}}} |
| 55 |
\generate{\file{namespc.sty}{\from{namespc.dtx}{package}}} |
| 56 |
|
| 57 |
\obeyspaces |
| 58 |
\Msg{*************************************************************} |
| 59 |
\Msg{* *} |
| 60 |
\Msg{* To finish the installation you have to move the following *} |
| 61 |
\Msg{* file into a directory searched by TeX: *} |
| 62 |
\Msg{* *} |
| 63 |
\Msg{* namespc.sty *} |
| 64 |
\Msg{* *} |
| 65 |
\Msg{* To produce the documentation run the file namespc.dtx *} |
| 66 |
\Msg{* through LaTeX. *} |
| 67 |
\Msg{* *} |
| 68 |
\Msg{* Happy TeXing! *} |
| 69 |
\Msg{* *} |
| 70 |
\Msg{*************************************************************} |
| 71 |
\endgroup |
| 72 |
%</batchfile> |
| 73 |
%<*driver> |
| 74 |
\documentclass{ltxdoc} |
| 75 |
\usepackage{namespc} |
| 76 |
\usepackage{a4} |
| 77 |
\WideMargins |
| 78 |
\EnableCrossrefs |
| 79 |
\CodelineIndex |
| 80 |
\RecordChanges |
| 81 |
\begin{document} |
| 82 |
\DocInput{namespc.dtx} |
| 83 |
\end{document} |
| 84 |
%</driver> |
| 85 |
% |
| 86 |
%<*package> |
| 87 |
% \fi |
| 88 |
% |
| 89 |
% \CheckSum{46} |
| 90 |
% |
| 91 |
% \CharacterTable |
| 92 |
% {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 |
| 93 |
% 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 |
| 94 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 95 |
% Exclamation \! Double quote \" Hash (number) \# |
| 96 |
% Dollar \$ Percent \% Ampersand \& |
| 97 |
% Acute accent \' Left paren \( Right paren \) |
| 98 |
% Asterisk \* Plus \+ Comma \, |
| 99 |
% Minus \- Point \. Solidus \/ |
| 100 |
% Colon \: Semicolon \; Less than \< |
| 101 |
% Equals \= Greater than \> Question mark \? |
| 102 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 103 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 104 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 105 |
% Right brace \} Tilde \~} |
| 106 |
% |
| 107 |
% \changes{v1.0}{2003/10/03}{Initial version} |
| 108 |
% |
| 109 |
% \GetFileInfo{namespc.sty} |
| 110 |
% |
| 111 |
% \DoNotIndex{\newcommand,\newenvironment,\def,\csname,\endcsname, |
| 112 |
% \endcsname,\expandafter,\long,\relax,\:} |
| 113 |
% |
| 114 |
% |
| 115 |
% \title{The \textsf{namespc} package\thanks{This document |
| 116 |
% corresponds to \textsf{namespc}~\fileversion, dated \filedate.}} |
| 117 |
% \author{Alexander Dreyer \\ \texttt{[email protected]}} |
| 118 |
% |
| 119 |
% \maketitle |
| 120 |
% |
| 121 |
% \begin{abstract} |
| 122 |
% |
| 123 |
% The \textsf{namespc} package adds rudimentary \emph{c++}-like namespace |
| 124 |
% functionality to \LaTeX. It may be used to declare local \LaTeX{} commands, |
| 125 |
% which can be made accessible in a later contexts without defining them |
| 126 |
% globally. |
| 127 |
% |
| 128 |
% \end{abstract} |
| 129 |
% |
| 130 |
% \section{Introduction} |
| 131 |
% This package can be used to declare local \LaTeX{} commands, |
| 132 |
% which may be reused in a later context without polluting the global |
| 133 |
% namespace, as an equivalent to \emph{c++}-like namespaces. |
| 134 |
% |
| 135 |
% \section{Usage} |
| 136 |
% |
| 137 |
% \DescribeMacro{\namespace} |
| 138 |
% This command is used to instantiate and reuse a certain namespace. |
| 139 |
% The |\namespace| command has the following syntax: |
| 140 |
% |
| 141 |
% |\namespace{|\emph{spcname}|}{|\emph{before}|}{|\emph{body}|}| |
| 142 |
%\\ |
| 143 |
% The first parameter corresponds to the name of the namespace |
| 144 |
% to be started or used. |
| 145 |
% The \emph{before} arguments of the current call of |\namespace| are appended |
| 146 |
% to the preamble of namespace \emph{spcname}, which is processed |
| 147 |
% before the text in \emph{body} gets processed. |
| 148 |
% |
| 149 |
% \DescribeEnv{\emph{spcname}} |
| 150 |
% With the first call of |
| 151 |
% |\namespace{|\emph{spcname}|}{|\ldots|}{|\emph{\ldots}|}| the |
| 152 |
% corresponding environment \emph{spcname} is defined which processes |
| 153 |
% all \emph{before} arguments within its preamble. |
| 154 |
% |
| 155 |
% \DescribeMacro{\namespace*} |
| 156 |
% Essentially the same as the |\namespace| command but without generation |
| 157 |
% of the corresponding environment. |
| 158 |
% |
| 159 |
% \DescribeMacro{\usingnamespace} |
| 160 |
% By using |\usingnamespace{|\emph{spcname}|}| one can force \LaTeX{} to |
| 161 |
% process the namespace preamble of \emph{spcname}. |
| 162 |
% |
| 163 |
% \StopEventually{\PrintChanges\PrintIndex} |
| 164 |
% |
| 165 |
% \section{Implementation} |
| 166 |
% |
| 167 |
% We first make |@| to a character in order to use and define internal |
| 168 |
% commands: |
| 169 |
% |
| 170 |
% \begin{macrocode} |
| 171 |
\makeatletter |
| 172 |
% \end{macrocode} |
| 173 |
% |
| 174 |
% \begin{macro}{\@defnamespace@ifundef} |
| 175 |
% |
| 176 |
% First we define an internal macro which will be used to instatiate the |
| 177 |
% (internal) namespace preamble macro |\@namespace@|\emph{spcname} |
| 178 |
% |
| 179 |
% \begin{macrocode} |
| 180 |
\def\@defnamespace@ifundef#1{ |
| 181 |
\@ifundefined{#1}{ |
| 182 |
\long\expandafter\def\csname#1\endcsname{} |
| 183 |
}{} |
| 184 |
} |
| 185 |
% \end{macrocode} |
| 186 |
% \end{macro} |
| 187 |
% |
| 188 |
% \begin{macro}{\@n@mesp@cestar} |
| 189 |
% Now we are able to define the internal version of the starred |\namespace| |
| 190 |
% command. |
| 191 |
% |
| 192 |
% \begin{macrocode} |
| 193 |
\newcommand{\@n@mesp@cestar}[3]{ |
| 194 |
\@defnamespace@ifundef{@namespace@#1} |
| 195 |
\expandafter\g@addto@macro\csname @namespace@#1\endcsname{#2}% |
| 196 |
{ |
| 197 |
\expandafter\relax\csname @namespace@#1\endcsname |
| 198 |
#3 |
| 199 |
} |
| 200 |
} |
| 201 |
% \end{macrocode} |
| 202 |
% \end{macro} |
| 203 |
% |
| 204 |
% \begin{macro}{\usingnamespace} |
| 205 |
% The user command |\usingnamespace| just forces initiatiation and processing |
| 206 |
% of the namespace preamble. |
| 207 |
% |
| 208 |
% \begin{macrocode} |
| 209 |
\newcommand{\usingnamespace}[1]{ |
| 210 |
\@defnamespace@ifundef{@namespace@#1} |
| 211 |
\csname @namespace@#1\endcsname |
| 212 |
} |
| 213 |
% \end{macrocode} |
| 214 |
% \end{macro} |
| 215 |
% |
| 216 |
% \begin{macro}{\@provide@namespace@env} |
| 217 |
% This is an internal command which provides the corresponding environment. |
| 218 |
% |
| 219 |
% \begin{macrocode} |
| 220 |
\def\@provide@namespace@env#1{ |
| 221 |
\@ifundefined{#1} { |
| 222 |
\newenvironment{#1}{\usingnamespace{#1}}{} |
| 223 |
}{} |
| 224 |
} |
| 225 |
% \end{macrocode} |
| 226 |
% \end{macro} |
| 227 |
% |
| 228 |
% \begin{macro}{\::} |
| 229 |
% The double colon notation may be used to access commands defined within a |
| 230 |
% namespace preamble once. Note that the command's arguments have to be |
| 231 |
% surrounded by colons: |
| 232 |
% \begin{macrocode} |
| 233 |
\def\::#1::#2:#3:{% |
| 234 |
{\csname @namespace@#1\endcsname |
| 235 |
\csname#2\endcsname#3} |
| 236 |
} |
| 237 |
% \end{macrocode} |
| 238 |
% \end{macro} |
| 239 |
% |
| 240 |
% \begin{macro}{\@n@mesp@ce} |
| 241 |
% Next we just add the definition of the respective environment to |\namespace*| |
| 242 |
% in order to obtain the internal version of |\namespace|: |
| 243 |
% |
| 244 |
% \begin{macrocode} |
| 245 |
\newcommand{\@n@mesp@ce}[3]{ |
| 246 |
\@provide@namespace@env{#1} |
| 247 |
\@n@mesp@cestar{#1}{#2}{#3} |
| 248 |
} |
| 249 |
% \end{macrocode} |
| 250 |
% \end{macro} |
| 251 |
% |
| 252 |
% \begin{macro}{\namespace} |
| 253 |
% Finally we use the |\@ifstar| macro to define the user commands |
| 254 |
% |\namespace| and |\namespace*|: |
| 255 |
% |
| 256 |
% \begin{macrocode} |
| 257 |
\newcommand*{\namespace}{\@ifstar\@n@mesp@cestar\@n@mesp@ce} |
| 258 |
% \end{macrocode} |
| 259 |
% \end{macro} |
| 260 |
% |@| is made special character again: |
| 261 |
% \begin{macrocode} |
| 262 |
\makeatother |
| 263 |
% \end{macrocode} |
| 264 |
% |
| 265 |
% \section{Example} |
| 266 |
% |
| 267 |
% This is example code for the use of the \textsf{namespc}~package: |
| 268 |
% |
| 269 |
%\begin{verbatim} |
| 270 |
%\namespace{spcname} |
| 271 |
%{\newcommand{\spcwidecmd}{\emph{command}\xspace}}{ |
| 272 |
% Using \spcwidecmd for the first time. |
| 273 |
%} % end of namespace |
| 274 |
% |
| 275 |
% % not defined here: \spcwidecmd |
| 276 |
% |
| 277 |
%\namespace{spcname}{}{ |
| 278 |
% \spcwidecmd may be used again later. |
| 279 |
%} % end of namespace |
| 280 |
% |
| 281 |
%\begin{spcname} |
| 282 |
% We can also use \spcwidecmd within the corresponding environment\ldots |
| 283 |
%\end{spcname} |
| 284 |
% |
| 285 |
% Alternatively we may use the double colon notation: \::spcname::spcwidecmd:: |
| 286 |
% |
| 287 |
%\usingnamespace{spcname} |
| 288 |
%\ldots{} or globally: \spcwidecmd. |
| 289 |
% |
| 290 |
%\end{verbatim} |
| 291 |
% |
| 292 |
% And here's the corresponding \LaTeX{} output: |
| 293 |
% \\ |
| 294 |
%\namespace{spcname} |
| 295 |
%{\newcommand{\spcwidecmd}{\emph{command}\ }}{ |
| 296 |
% |
| 297 |
% Using \spcwidecmd for the first time. |
| 298 |
%} |
| 299 |
% |
| 300 |
% |
| 301 |
%\namespace{spcname}{}{ |
| 302 |
% \spcwidecmd may be used again later. |
| 303 |
%} |
| 304 |
% |
| 305 |
%\begin{spcname} |
| 306 |
% We can also use \spcwidecmd within the corresponding environment\ldots |
| 307 |
%\end{spcname} |
| 308 |
% |
| 309 |
% Alternatively we may use the double colon notation: \::spcname::spcwidecmd:: |
| 310 |
% |
| 311 |
%\usingnamespace{spcname} |
| 312 |
%\ldots{} or globally: \spcwidecmd |
| 313 |
% |
| 314 |
% \Finale |
| 315 |
% |
| 316 |
% \endinput |
| 317 |
%</package> |
| 318 |
% |
| 319 |
%<*indexfile> |
| 320 |
|
| 321 |
\begin{theindex} |
| 322 |
\makeatletter\scan@allowedfalse |
| 323 |
{\bfseries\hfil Symbols\hfil}\nopagebreak |
| 324 |
|
| 325 |
\item \verb*+\::+\pfill \main{24} |
| 326 |
\item \verb*+\@defnamespace@ifundef+\pfill \main{2}, 8, 16 |
| 327 |
\item \verb*+\@ifstar+\pfill 32 |
| 328 |
\item \verb*+\@ifundefined+\pfill 3, 20 |
| 329 |
\item \verb*+\@n@mesp@ce+\pfill \main{28}, 32 |
| 330 |
\item \verb*+\@n@mesp@cestar+\pfill \main{7}, 30, 32 |
| 331 |
\item \verb*+\@provide@namespace@env+\pfill \main{19}, 29 |
| 332 |
\item {\ttfamily \emph {spcname}} (environment)\pfill \usage{1} |
| 333 |
|
| 334 |
\indexspace |
| 335 |
{\bfseries\hfil E\hfil}\nopagebreak |
| 336 |
|
| 337 |
\item environments:\efill |
| 338 |
\subitem {\ttfamily \emph {spcname}}\pfill \usage{1} |
| 339 |
|
| 340 |
\indexspace |
| 341 |
{\bfseries\hfil G\hfil}\nopagebreak |
| 342 |
|
| 343 |
\item \verb*+\g@addto@macro+\pfill 9 |
| 344 |
|
| 345 |
\indexspace |
| 346 |
{\bfseries\hfil M\hfil}\nopagebreak |
| 347 |
|
| 348 |
\item \verb*+\makeatletter+\pfill 1 |
| 349 |
\item \verb*+\makeatother+\pfill 33 |
| 350 |
|
| 351 |
\indexspace |
| 352 |
{\bfseries\hfil N\hfil}\nopagebreak |
| 353 |
|
| 354 |
\item \verb*+\namespace+\pfill \usage{1}, \main{32} |
| 355 |
\item \verb*+\namespace*+\pfill \usage{1} |
| 356 |
|
| 357 |
\indexspace |
| 358 |
{\bfseries\hfil U\hfil}\nopagebreak |
| 359 |
|
| 360 |
\item \verb*+\usingnamespace+\pfill \usage{1}, \main{15}, 21 |
| 361 |
|
| 362 |
\end{theindex} |
| 363 |
|
| 364 |
|
| 365 |
%</indexfile> |