| 1 |
% \iffalse |
| 2 |
% |
| 3 |
% inlinedef.dtx |
| 4 |
% Copyright 2008 Stephen D. Hicks |
| 5 |
% |
| 6 |
% This work may be distributed and/or modified under the |
| 7 |
% conditions of the LaTeX Project Public License, either version 1.3 |
| 8 |
% of this license or (at your option) any later version. |
| 9 |
% The latest version of this license is in |
| 10 |
% http://www.latex-project.org/lppl.txt |
| 11 |
% and version 1.3 or later is part of all distributions of LaTeX |
| 12 |
% version 2005/12/01 or later. |
| 13 |
% |
| 14 |
% This work has the LPPL maintenance status `maintained'. |
| 15 |
% |
| 16 |
% The Current Maintainer of this work is Stephen D. Hicks |
| 17 |
% |
| 18 |
% This work consists of the files |
| 19 |
% README |
| 20 |
% inlinedef.dtx (this file) |
| 21 |
% inlinedef.ins |
| 22 |
% inlinedef.pdf |
| 23 |
% and the derived files |
| 24 |
% inlinedef.sty |
| 25 |
% inlinetest.tex |
| 26 |
% |
| 27 |
% Run LaTeX on this file to produce documentation. |
| 28 |
% Run LaTeX on the .ins file to produce the package. |
| 29 |
%<*driver> |
| 30 |
\ProvidesFile{inlinedef.dtx} |
| 31 |
%</driver> |
| 32 |
% |
| 33 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 34 |
%<package>\ProvidesPackage{inlinedef}% |
| 35 |
%<testsuite>\documentclass{minimal} |
| 36 |
%<testsuite>\usepackage{inlinedef}% |
| 37 |
[2008/07/10 v1.0 Inlined expansions within definitions] |
| 38 |
%<*driver> |
| 39 |
\documentclass{ltxdoc} |
| 40 |
\CheckSum{1876} |
| 41 |
%\OnlyDescription % (un)comment this line to show (hide) source code |
| 42 |
\RecordChanges |
| 43 |
\EnableCrossrefs |
| 44 |
\CodelineIndex % (un)comment this line to index source by page (line) |
| 45 |
\begin{document} |
| 46 |
\newcommand*{\Lopt}[1]{\textsf {#1}} |
| 47 |
\parindent0pt |
| 48 |
\def\*#1{\texttt{\string#1}} %% sdh - |...| doesn't work in headings |
| 49 |
\makeatletter |
| 50 |
% |
| 51 |
\newcount\mac@depth\mac@depth\z@ |
| 52 |
\newcommand\@macros{}\newcommand\@endmacros{} |
| 53 |
\catcode`&3 %% we use a funny catcode to ensure never used. |
| 54 |
\def\@macros#1,{\macro{#1}\global\advance\mac@depth\@ne\relax |
| 55 |
\@ifnextchar&\@gobble\@macros} |
| 56 |
\def\@endmacros{\let\mac@next\relax\ifnum\mac@depth>\z@ |
| 57 |
\endmacro\let\mac@next\@endmacros |
| 58 |
\global\advance\mac@depth\m@ne\fi\mac@next} |
| 59 |
\newenvironment{macros}[1]{\@macros#1,&}{\@endmacros} |
| 60 |
\catcode`&4 %% put it back |
| 61 |
% Stop indexing at a certain point |
| 62 |
\newcommand\StopIndexing{\let\special@index\@gobble} |
| 63 |
% done... |
| 64 |
\makeatother %% must be balanced for character table to work properly |
| 65 |
% |
| 66 |
% Don't index unimportant names... |
| 67 |
\DoNotIndex{\@ne,\@whilesw,\@gobble,\@eha,\@ehd,\@empty,\xa} |
| 68 |
\DoNotIndex{\advance,\begin,\begingroup,\xdef} |
| 69 |
\DoNotIndex{\catcode,\DeclareRobustCommand,\def,\detokenize,\edef} |
| 70 |
\DoNotIndex{\end,\endgroup,\errorcontextlines,\expandafter,\foo} |
| 71 |
\DoNotIndex{\futurelet,\gdef,\global,\let,\long} |
| 72 |
\DoNotIndex{\m@ne,\makeatletter,\makeatother,\meaning,\message} |
| 73 |
\DoNotIndex{\MessageBreak,\newcommand,\newcount,\newif,\newtoks} |
| 74 |
\DoNotIndex{\noexpand,\outer,\PackageError,\protect,\protected@edef} |
| 75 |
\DoNotIndex{\relax,\renewcommand,\space,\string,\the\toks,\undefined} |
| 76 |
\DoNotIndex{\ifcat,\ifnum,\ifx,\else,\fi,\fi,\fi} |
| 77 |
% Do the stuff |
| 78 |
\DocInput{inlinedef.dtx} |
| 79 |
\setcounter{IndexColumns}{2} |
| 80 |
\def\bang{\texttt{!}} |
| 81 |
\PrintIndex |
| 82 |
%\PrintChanges |
| 83 |
\end{document} |
| 84 |
%</driver> |
| 85 |
% \fi |
| 86 |
% \changes{v1.0}{2008/07/05} |
| 87 |
% {(SDH) Initial version.} |
| 88 |
% |
| 89 |
% \GetFileInfo{inlinedef.dtx} |
| 90 |
% \title{The \textsf{inlinedef}% |
| 91 |
% \iffalse - don't include this for now... |
| 92 |
% \thanks{\textsf{darcs} repository at |
| 93 |
% \texttt{http://www.physics.cornell.edu/$\sim$shicks/darcs/latex/inlinedef/}. |
| 94 |
% Patch submissions welcome.}\fi |
| 95 |
% package} |
| 96 |
% \author{Stephen Hicks\thanks{email: \texttt{[email protected]}}} |
| 97 |
% \date{\fileversion{} -- \filedate} |
| 98 |
% \maketitle |
| 99 |
% |
| 100 |
% \section{Usage} |
| 101 |
% |
| 102 |
% \subsection{The problem} |
| 103 |
% Often package writers want to redefine certain macros to do slightly |
| 104 |
% more than what they did previously, adding a control sequence or two |
| 105 |
% to the beginning or the end of the definition. The easiest way to |
| 106 |
% accomplish this is to use something like |
| 107 |
% \begin{verbatim} |
| 108 |
% \let\old@macro\macro |
| 109 |
% \def\macro{...\old@macro...}\end{verbatim} |
| 110 |
% But this sort of construction can cause problems if another package |
| 111 |
% also wants to redefine the same macro and happens to choose the same |
| 112 |
% name to save it to. It's also an ugly solution in that it pollutes |
| 113 |
% the global namespace with extra macro names. A much cleaner solution |
| 114 |
% is to define the new macro with the old macro expanded inline, as in |
| 115 |
% |\edef\macro{...\macro...}|. This is generally problemmatic because |
| 116 |
% there are often undefined control sequences and macros that we don't |
| 117 |
% want to expand quite yet. A compromise is to use |\expandafter|, but |
| 118 |
% this leads to error-prone and unreadable code: |
| 119 |
% \begin{verbatim} |
| 120 |
% \expandafter\def\expandafter\macro\expandafter{\expandafter |
| 121 |
% ...\macro...}\end{verbatim} |
| 122 |
% |
| 123 |
% \subsection{The solution} |
| 124 |
% What we really want is a way to expand just a few |
| 125 |
% tokens in the definition and leave the rest untouched. |
| 126 |
% \iffalse - not ready yet... |
| 127 |
% The package |expansions| provides a way to do this more |
| 128 |
% generally, but in the case of definitions, this package is more |
| 129 |
% expressive and simpler. |
| 130 |
% \fi |
| 131 |
% We provide a command \DescribeMacro\Inline|\Inline| |
| 132 |
% that can be inserted before a |\def| or |\gdef| (optionally prefixed |
| 133 |
% by |\long|, |\outer|, and/or |\global|, as in |
| 134 |
% |\Inline\long\outer\gdef...|). Within |\Inline| definitions, |
| 135 |
% only tokens preceded by \DescribeMacro\Expand|\Expand| are expanded. |
| 136 |
% Thus, the previous example becomes |
| 137 |
% \begin{verbatim} |
| 138 |
% \Inline\def\macro{...\Expand\macro...}\end{verbatim} |
| 139 |
% |
| 140 |
% \subsection{Special commands} |
| 141 |
% While nearly everything can be done with |\Expand| alone, we provide |
| 142 |
% a few more keywords for completeness and convenience. |
| 143 |
% \begin{itemize} |
| 144 |
% \item\DescribeMacro\Expand|\Expand| - Performs a single expansion |
| 145 |
% on the token or group |
| 146 |
% immediately following and places the result directly into the |
| 147 |
% definition without further processing. In the case of a group, |
| 148 |
% only the first token is expanded (although |\expandafter|s may |
| 149 |
% be used to expand a different token), and |
| 150 |
% the outermost grouping braces are discarded. |
| 151 |
% \item\DescribeMacro\MultiExpand|\MultiExpand|\marg{number} - |
| 152 |
% Expands the following token or group the given number of times. |
| 153 |
% For example, |
| 154 |
% \begin{verbatim} |
| 155 |
% \MultiExpand{3}{\expandafter\expandafter\expandafter\a |
| 156 |
% \expandafter\b\c}\end{verbatim} |
| 157 |
% expands first |\c|, then |\b|, then |\a|, and inserts the whole |
| 158 |
% expansion into the definition with no braces. Note that the braces |
| 159 |
% are important. Otherwise it will just try to expand the first |
| 160 |
% |\expandafter| three times, which is clearly wrong. |
| 161 |
% \item\DescribeMacro\UnsafeExpand|\UnsafeExpand| - This version simply |
| 162 |
% inserts an |\expandafter|, performing the expansion as in |\Expand| |
| 163 |
% above, but reinserting the result back |
| 164 |
% into the stream to be processed. Thus, any tokens like |\Expand| or |
| 165 |
% |\Super| in the expansion will be acted on. Unlike the previous two |
| 166 |
% commands, groups are \emph{not\/} treated differently. |
| 167 |
% \item\DescribeMacro\NoExpand|\NoExpand| - If a token is preceeded |
| 168 |
% by |\NoExpand| then it is inserted in the definition exactly as-is. |
| 169 |
% This is required to insert any of the special tokens |\Expand|, |
| 170 |
% |\NoExpand|, etc, as well as the internal token |\Q@END|, into a |
| 171 |
% definition. If the token immediately following |\NoExpand| is |
| 172 |
% an open-brace then the entire text of the group will be inserted |
| 173 |
% without expansion, and the outer level of grouping will be lost. |
| 174 |
% \item\DescribeMacro\Super|\Super| - When redefining an already |
| 175 |
% existing macro, |\Super| will expand to the previous definition of |
| 176 |
% the macro. Any macro parameters are automatically substituted. |
| 177 |
% If the macro is undefined, or if the new parameter text doesn't match |
| 178 |
% with the old text, then this will cause an error. |
| 179 |
% \item\DescribeMacro\Recurse|\Recurse| - This is complementary to |
| 180 |
% |\Super| and, while not strictly necessary, is included for clarity. |
| 181 |
% |\Recurse| is equivalent to |
| 182 |
% |\NoExpand\macro| when defining |\macro|. However, since |\macro| |
| 183 |
% is, by default, not expanded anyway, this is a bit redundant. |
| 184 |
% \end{itemize} |
| 185 |
% |
| 186 |
% \goodbreak |
| 187 |
% \subsection{Calling options} |
| 188 |
% When the name of the macro we're defining is encountered, there are |
| 189 |
% three different ways we might proceed: leave it alone (|\NoExpand|), |
| 190 |
% expand it with implicit parameters (|\Super|), or expand it with |
| 191 |
% explicit parameters (|\UnsafeExpand|). |
| 192 |
% We therefore allow zero, one, or two stars to come after |\Inline| to |
| 193 |
% change this behavior. |
| 194 |
% \begin{itemize} |
| 195 |
% \item\DescribeMacro\Inline|\Inline| - Without any stars, we default |
| 196 |
% to leaving the macro name alone, as in |\NoExpand\macro|. |
| 197 |
% This is the most consistent behavior with the rest of the package and |
| 198 |
% works regardless of whether the macro is being defined or redefined. |
| 199 |
% \item\DescribeMacro{\Inline*}|\Inline*| - With a single star, we treat |
| 200 |
% the macro name as a |
| 201 |
% call to |\Super| and expand it with parameters inserted automatically. |
| 202 |
% This is preferred over |\Expand| because it doesn't lead to the possible |
| 203 |
% surprises in the case of recursively-defined macros. |
| 204 |
% \item\DescribeMacro{\Inline**}|\Inline**| - Finally, with two stars, |
| 205 |
% the macro name is treated as if it were preceeded by |\UnsafeExpand|. |
| 206 |
% Any parameters must be inserted explicitly, and the expansion is |
| 207 |
% itself subject to inline processing. Note that this form is the most |
| 208 |
% dangerous. |
| 209 |
% \end{itemize} |
| 210 |
% |
| 211 |
% \index{Inline\bang=\verb!*+\Inline+\bang|usage} |
| 212 |
% \begingroup\def\index#1{}%\iffalse - index by hand! - \fi |
| 213 |
% \DescribeMacro{\Inline!}\endgroup |
| 214 |
% One final option applies only in the case of redefining an already-existing |
| 215 |
% macro. In this case, if the parameter text of the new definition differs |
| 216 |
% from the parameter text of the old definition, we will produce an error. |
| 217 |
% This error can be suppressed by adding a bang to the end of |\Inline| |
| 218 |
% (either before or after the stars), acknowledging that any ill consequences |
| 219 |
% that result are your own fault. |
| 220 |
% |
| 221 |
% \iffalse - this part not yet implemented! |
| 222 |
% The last special |
| 223 |
% token is \DescribeMacro\Args|\Args|. |\Args| inserts a protected |
| 224 |
% version of the argument text, that can be used when recursing, as |
| 225 |
% in |\Recurse\Args|, to make the exact same call again. Otherwise, |
| 226 |
% when using |\Recurse|, you are responsible for passing the arguments |
| 227 |
% yourself, unlike |\Super|, which behaves like a hypothetical |
| 228 |
% |\ExpandAfter\ExpandAfter\ExpandAfter\Expand\ExpandAfter\Recurse\Args| |
| 229 |
% (though |\ExpandAfter| doesn't currently |
| 230 |
% exist). |
| 231 |
% \fi |
| 232 |
% |
| 233 |
% \subsection{Known issues} |
| 234 |
% \begin{itemize} |
| 235 |
% \item If a macro is defined with a character other than |#| catcoded to |
| 236 |
% 6, then |\Super| will fail unless the same character is used in the |
| 237 |
% redefinition. |
| 238 |
% \end{itemize} |
| 239 |
% |
| 240 |
% \subsection{Related packages} |
| 241 |
% \begin{description} |
| 242 |
% \item[moredefs] The \textsf{moredefs} package in the \textsf{frankenstein} |
| 243 |
% collection provides some similar syntactic sugar, but is not as |
| 244 |
% expressive. |
| 245 |
% \end{description} |
| 246 |
% |
| 247 |
% \StopEventually{} |
| 248 |
% |
| 249 |
% \filbreak |
| 250 |
% \makeatletter |
| 251 |
% \section{Implementation} |
| 252 |
% \begin{macro}{\xa} |
| 253 |
% Make the |@|-sign into a letter for use in macro names. As long as the |
| 254 |
% packages are well-behaved, we can put this here and not later. We also |
| 255 |
% define |\xa| to be |\expandafter| for convenience. |
| 256 |
% \begin{macrocode} |
| 257 |
%<*package> |
| 258 |
\makeatletter |
| 259 |
\let\xa\expandafter |
| 260 |
% \end{macrocode} |
| 261 |
% \end{macro} |
| 262 |
% |
| 263 |
% \begin{macros}{\ifID@aborted,\ifID@star,\ifID@starstar,\ifID@bang} |
| 264 |
% We define a conditional so that we can gracefully abort in case of an error. |
| 265 |
% \begin{macrocode} |
| 266 |
\newif\ifID@aborted |
| 267 |
\newif\ifID@star |
| 268 |
\newif\ifID@starstar |
| 269 |
\newif\ifID@bang |
| 270 |
% \end{macrocode} |
| 271 |
% \end{macros} |
| 272 |
% |
| 273 |
% \begin{macros}{\ID@toks,\ID@count} |
| 274 |
% At some point we need to stop using the internal toks registers and allocate |
| 275 |
% our own, because somebody might want to |\Expand{\the\toks@}| and expect |
| 276 |
% something else. We can get by with a single one though by defining a |
| 277 |
% |\ID@pdef| that doubles all the |#| signs and then does a regular def, so that |
| 278 |
% |\ID@pdef\cs\ID@toks ... \cs| will be the same as |\the\ID@toks|. |
| 279 |
% \begin{macrocode} |
| 280 |
\newtoks\ID@toks |
| 281 |
\newcount\ID@count |
| 282 |
% \end{macrocode} |
| 283 |
% \end{macros} |
| 284 |
% |
| 285 |
% \begin{macros}{\Inline,\ID@scandef} |
| 286 |
% These are the macros that get it all started. |\Inline| opens up |
| 287 |
% a group (which is closed at the end of |\ID@def|) and initializes a |
| 288 |
% toks register (we don't bother allocating it since we're in a group |
| 289 |
% and don't call any \LaTeX{} or \TeX{} macros that make use of allocated |
| 290 |
% toks registers. Then we scan the tokens until we |
| 291 |
% find either an |\edef| or an |\xdef|. If it's anything else, we just |
| 292 |
% add it to the toks register. We also have a list of bad tokens that |
| 293 |
% will cause an error message, so that we don't go too far before figuring |
| 294 |
% out what went wrong. Should |\Inline| be |\outer|? |
| 295 |
% \begin{macrocode} |
| 296 |
\DeclareRobustCommand\Inline{% |
| 297 |
\begingroup |
| 298 |
% Define a few ``quarks'' |
| 299 |
\def\Expand{\Expand}\def\Super{\Super}% |
| 300 |
\def\UnsafeExpand{\UnsafeExpand}\def\MultiExpand{\MultiExpand}% |
| 301 |
\def\Recurse{\Recurse}\def\NoExpand{\NoExpand}% |
| 302 |
\def\Q@END{\Q@END}% |
| 303 |
% Define a toks register |
| 304 |
\ID@toks{}% |
| 305 |
% Signal that we need to look for a star |
| 306 |
\@testtrue\ID@starfalse\ID@starstarfalse\ID@bangfalse |
| 307 |
% Start scanning for \def or \gdef |
| 308 |
\futurelet\@foo\ID@scandef |
| 309 |
} |
| 310 |
\newcommand\ID@scandef{% |
| 311 |
\let\next\ID@saveprefix % Default behavior |
| 312 |
% If this is the first few tokens after the \Inline, check for * or ! |
| 313 |
\if@test |
| 314 |
\ifx\@foo*% |
| 315 |
\ifID@star |
| 316 |
\ifID@bang\let\next\ID@sd@lastcheck\else\let\next\ID@sd@checkagain\fi |
| 317 |
\ID@starstartrue |
| 318 |
\else |
| 319 |
\let\next\ID@sd@checkagain |
| 320 |
\ID@startrue |
| 321 |
\fi |
| 322 |
\fi |
| 323 |
\ifx\@foo!% |
| 324 |
\ifID@bang\else % two bangs - can this be anything but an error? |
| 325 |
\ID@bangtrue |
| 326 |
\xa\let\xa\next\ifID@starstar\ID@sd@lastcheck\else\ID@sd@checkagain\fi |
| 327 |
\fi |
| 328 |
\fi |
| 329 |
\fi |
| 330 |
% Now look for a \def or \gdef |
| 331 |
\ifx\@foo\def |
| 332 |
\def\next{\ID@start\def}% |
| 333 |
\fi |
| 334 |
\ifx\@foo\gdef |
| 335 |
\def\next{\ID@start\gdef}% |
| 336 |
\fi |
| 337 |
\ifcat\noexpand\@foo\space |
| 338 |
\def\next{\ID@toks\xa\xa\xa{\xa\the\xa\ID@toks\space}% |
| 339 |
\xa\futurelet\xa\@foo\xa\ID@scandef\ID@unspace}% copied from ID@space |
| 340 |
\fi |
| 341 |
% Error checking (minimal) |
| 342 |
\@testfalse |
| 343 |
\ifx\@foo\edef\@testtrue\fi\ifx\@foo\xdef\@testtrue\fi |
| 344 |
\ifx\@foo\newcommand\@testtrue\fi\ifx\@foo\renewcommand\@testtrue\fi |
| 345 |
\ifx\@foo\DeclareRobustCommand\@testtrue\fi |
| 346 |
\if@test\PackageError{inlinedef}{Only \protect\def\space and \protect\gdef\space are |
| 347 |
allowed after \protect\Inline,\MessageBreak but some other type of |
| 348 |
definition was found}\@eha\let\next\ID@abort\fi |
| 349 |
\@testfalse |
| 350 |
\ifx\@foo\bgroup\@testtrue\fi\ifx\@foo\let\@testtrue\fi |
| 351 |
\if@test\PackageError{inlinedef}{No \protect\def\space or \protect\gdef\space found |
| 352 |
after \protect\Inline}\@ehd\def\next{\ID@abort{}}\fi |
| 353 |
\next |
| 354 |
} |
| 355 |
% \end{macrocode} |
| 356 |
% \end{macros} |
| 357 |
% |
| 358 |
% \begin{macros}{\ID@sd@checkagain,\ID@sd@lastcheck} |
| 359 |
% These just get the scandef loop started again and set |\@testtrue| if we're |
| 360 |
% still looking for stars and/or bangs. |
| 361 |
% \begin{macrocode} |
| 362 |
\def\ID@sd@checkagain#1{\@testtrue\futurelet\@foo\ID@scandef} |
| 363 |
\def\ID@sd@lastcheck#1{\futurelet\@foo\ID@scandef} |
| 364 |
% \end{macrocode} |
| 365 |
% \end{macros} |
| 366 |
% |
| 367 |
% \begin{macros}{\ID@saveprefix,\ID@abort,\ID@start} |
| 368 |
% These are the three macros called by |\ID@scandef| to either save the |
| 369 |
% prefix (|\long|, |\outer|, etc) to a token register, (attempt to) abort |
| 370 |
% the procedure in case of an error, or else get the definition started |
| 371 |
% once we find the |\edef| or |\xdef|. |
| 372 |
% \begin{macrocode} |
| 373 |
\newcommand*\ID@saveprefix[1]{% |
| 374 |
\ID@toks\xa{\the\ID@toks#1}% |
| 375 |
\futurelet\@foo\ID@scandef |
| 376 |
} |
| 377 |
% \end{macrocode} |
| 378 |
% In case the error was just the wrong type of |\def|, we consume up to and |
| 379 |
% including the first explicit group. |
| 380 |
% \begin{macrocode} |
| 381 |
\newcommand\ID@abort{}\def\ID@abort#1#{\endgroup\@gobble} |
| 382 |
% \end{macrocode} |
| 383 |
% To get the definition process started, we take |#1| as the definition |
| 384 |
% command to save (either |\def| or |\gdef|), |#2| as the command that |
| 385 |
% was provided (which we discard), |#3| is the name of the macro to define, |
| 386 |
% and |#4| is the parameter text, delimited by a begin-group character. |
| 387 |
% \begin{macrocode} |
| 388 |
\newcommand\ID@start{}\def\ID@start#1#2#3#4#{% |
| 389 |
\xa\def\xa\ID@prefix\xa{\the\ID@toks#1}% |
| 390 |
\ID@def#3{#4}% |
| 391 |
} |
| 392 |
% \end{macrocode} |
| 393 |
% \end{macros} |
| 394 |
% |
| 395 |
% \begin{macros}{\ID@fixparams,\ID@fp@start} |
| 396 |
% In order for |\Super| to work properly, we need to fix the parameter |
| 397 |
% list to put the |#1| in braces, since it actually consists of two tokens. |
| 398 |
% Therefore, |\ID@fixparams| takes everything between it and |\Q@END| |
| 399 |
% and puts it in |\toks@fixedparams|. If it finds a |#|, then it checks |
| 400 |
% whether the argument is delimited or not, and if not, it inserts |
| 401 |
% a pair of braces. We currently define these with |\newcommand*|, though |
| 402 |
% if there were a reason we could conceivably make them |\long|. |
| 403 |
% Update: we now use |\ID@toks| and then define |\ID@fixedparams| from there. |
| 404 |
% \begin{macrocode} |
| 405 |
\newcommand*\ID@fixparams{\begingroup\ID@toks{}\futurelet\@foo\ID@fp@start} |
| 406 |
\newcommand*\ID@fp@start{% |
| 407 |
\let\next\ID@fp@normal |
| 408 |
\ifx\@foo\Q@END\let\next\ID@fp@end\fi |
| 409 |
\ifcat\noexpand\@foo##\let\next\ID@fp@param\fi % was \ifx\@foo - broken? |
| 410 |
\ifcat\noexpand\@foo\space |
| 411 |
\def\next{\ID@toks\xa\xa\xa{\xa\the\xa\ID@toks\space}% |
| 412 |
\xa\futurelet\xa\@foo\xa\ID@fp@start\ID@unspace}% copied from ID@space |
| 413 |
\fi |
| 414 |
\next |
| 415 |
} |
| 416 |
% \end{macrocode} |
| 417 |
% \end{macros} |
| 418 |
% |
| 419 |
% \begin{macros}{\ID@fp@normal,\ID@fp@param,\ID@fp@end} |
| 420 |
% These are the two commands that |\ID@fixparams| calls to actually |
| 421 |
% consume each token, depending on whether it was a parameter. |
| 422 |
% \begin{macrocode} |
| 423 |
\newcommand*\ID@fp@normal[1]{% |
| 424 |
\ID@toks\xa{\the\ID@toks#1}\futurelet\@foo\ID@fp@start |
| 425 |
} |
| 426 |
\newcommand*\ID@fp@param[2]{% |
| 427 |
% We used to just use ###2 but need two more now... |
| 428 |
% Need another doubling because we're now using it inside a def... |
| 429 |
\def\@arg{#########2}% assume delimited unless we find # or \Q@END |
| 430 |
\ifcat\noexpand\@foo##\def\@arg{{#########2}}\fi |
| 431 |
\ifx\@foo\Q@END\def\@arg{{#########2}}\fi |
| 432 |
\ID@toks\xa\xa\xa{\xa\the\xa\ID@toks\@arg}% |
| 433 |
\futurelet\@foo\ID@fp@start |
| 434 |
} |
| 435 |
\newcommand*\ID@fp@end[1]{% |
| 436 |
\xa\endgroup\xa\def\xa\ID@fixedparams\xa{\the\ID@toks}% |
| 437 |
} |
| 438 |
% \end{macrocode} |
| 439 |
% This should deal with everything \emph{except} a single |#|, |
| 440 |
% but that's a hairy situation in the first place and we really don't |
| 441 |
% want to allow using |\Super| in that case. We could probably make |
| 442 |
% an error message to say so. The only other alternative would be to |
| 443 |
% ``go back in time'' and change the last |{#1}| to a |#1{}| and even |
| 444 |
% then we end up with an extra |{}| on the input stream. I can't actually |
| 445 |
% figure out how to test if this has happened in |...@insertp|, anyway. |
| 446 |
% \end{macros} |
| 447 |
% |
| 448 |
% \begin{macros}{\ID@def} |
| 449 |
% Here is where the ``main loop'' is initiated. We start by |
| 450 |
% pretending to allocate another token register (though we actually |
| 451 |
% just |\toksdef| it), and then define a number of quarks which we |
| 452 |
% use as delimiters for various purposes. Finally, we start scanning. |
| 453 |
% Afterwards, we test if there was an error and if not, we expand the |
| 454 |
% definition command \emph{after} the |\endgroup| so that we can clean |
| 455 |
% up all the local variables. |
| 456 |
% \begin{macrocode} |
| 457 |
\newcommand\ID@def[3]{% |
| 458 |
% Other definitions |
| 459 |
\global\ID@abortedfalse |
| 460 |
\let\@reservedc#1% |
| 461 |
\def\@macroname{#1}% for error message |
| 462 |
\ID@fixparams#2\Q@END |
| 463 |
% These are used by \Super but easier to define here |
| 464 |
\def\@reservedb#2{}% |
| 465 |
\edef\@reservedb{\xa\ID@getprefix\meaning\@reservedb\Q@END}% |
| 466 |
\ifx#1\undefined % hopefully nobody's going around defining \undefined |
| 467 |
\let\@reserveda\undefined |
| 468 |
\else |
| 469 |
\edef\@reserveda{\xa\ID@getprefix\meaning#1\Q@END}% |
| 470 |
\fi |
| 471 |
% Scan it all into \ID@toks |
| 472 |
\ifID@bang\else\ID@checkusage\fi |
| 473 |
\ifID@aborted\else |
| 474 |
\ID@toks{}\ID@scan#3\Q@END{}% we need the {} so that the the #1# works... |
| 475 |
\fi |
| 476 |
\ifID@aborted |
| 477 |
\def\command{}% gracefully ignore |
| 478 |
\else |
| 479 |
\let#1\relax % don't want it expanded in the |\edef| below |
| 480 |
% We don't need to worry about scope anymore |
| 481 |
\toks0\ID@toks % likely redundant, but what if ID@toks=1 or 2? |
| 482 |
\toks1\xa{\ID@prefix}% (easiest way to avoid expansion...) |
| 483 |
\toks2{#2}% |
| 484 |
\edef\command{\the\toks1#1\the\toks2{\the\toks0}}% |
| 485 |
% We could also write this with 3 levels of \xa... |
| 486 |
\fi |
| 487 |
\global\ID@toks\xa{\ID@fixedparams}% just to test... |
| 488 |
\expandafter\endgroup\command |
| 489 |
} |
| 490 |
% \end{macrocode} |
| 491 |
% \end{macros} |
| 492 |
% |
| 493 |
% \begin{macros}{\ID@scan,\ID@switch} |
| 494 |
% This is the main loop. We look at each token in turn and deal with it, |
| 495 |
% mostly by inserting it into |\ID@toks|. If it's a |\Q@END| then we're done. |
| 496 |
% If it's |\Super| or |\Expand| then we need to do something special. |
| 497 |
% If it's a space, then we need to add the space to |
| 498 |
% |\ID@toks|. Finally, if it's a |\bgroup| then we need to figure out whether |
| 499 |
% it's an explicit or an implicit group. In the former case, we descend into |
| 500 |
% it (writing |{...}| to |\ID@toks|) and in the latter, we just pick it up like |
| 501 |
% normal. |
| 502 |
% \begin{macrocode} |
| 503 |
\newcommand\ID@scan{\futurelet\@foo\ID@switch} |
| 504 |
\newcommand\ID@switch{% |
| 505 |
\let\next\ID@normal |
| 506 |
\ifx\@foo\Q@END |
| 507 |
\let\next\@gobble |
| 508 |
\fi |
| 509 |
\ifx\@foo\@reservedc % macro name... what to do? |
| 510 |
\ifID@star |
| 511 |
\ifID@starstar |
| 512 |
\let\next\ID@expandmacro |
| 513 |
\else |
| 514 |
\let\next\ID@expandsuper |
| 515 |
\fi |
| 516 |
\fi |
| 517 |
\fi |
| 518 |
\ifx\@foo\Super |
| 519 |
\let\next\ID@expandsuper |
| 520 |
\fi |
| 521 |
\ifx\@foo\Expand |
| 522 |
\let\next\ID@expandnext |
| 523 |
\fi |
| 524 |
\ifx\@foo\UnsafeExpand |
| 525 |
\let\next\ID@expandunsafe |
| 526 |
\fi |
| 527 |
\ifx\@foo\MultiExpand |
| 528 |
\let\next\ID@expandmulti |
| 529 |
\fi |
| 530 |
\ifx\@foo\NoExpand |
| 531 |
\let\next\ID@noexpandnext |
| 532 |
\fi |
| 533 |
\ifx\@foo\Recurse |
| 534 |
\def\next{\xa\xa\xa\ID@scan\xa\xa\xa\NoExpand\xa\@macroname\@gobble}% |
| 535 |
\fi |
| 536 |
\ifcat\noexpand\@foo\space |
| 537 |
\let\next\ID@space |
| 538 |
\fi |
| 539 |
\ifcat\noexpand\@foo\bgroup |
| 540 |
\let\next\ID@trygroup |
| 541 |
\fi |
| 542 |
\next |
| 543 |
} |
| 544 |
% \end{macrocode} |
| 545 |
% \end{macros} |
| 546 |
% \begin{macros}{\ID@space,\ID@unspace} |
| 547 |
% It's a bit tricky to deal with spaces properly. In particular, |
| 548 |
% picking up just a space from the token list takes some doing. We |
| 549 |
% need a fully-expandable macro so that the whole thing disappears. |
| 550 |
% |\ID@space| then adds a space to |\ID@toks| and then expands |
| 551 |
% |\ID@unspace| after |\ID@scan| so that the |\futurelet| sees the |
| 552 |
% next token after the space and can deal with it properly. |
| 553 |
% We need the |\expandafter| in defining |\ID@unspace| to actually get the |
| 554 |
% space token into the parameter text; otherwise, it gets |
| 555 |
% gobbled up by the lexer after reading the control sequence name. |
| 556 |
% \begin{macrocode} |
| 557 |
\newcommand\ID@space{% |
| 558 |
\ID@toks\xa\xa\xa{\xa\the\xa\ID@toks\space}% |
| 559 |
\xa\ID@scan\ID@unspace |
| 560 |
} |
| 561 |
\newcommand\ID@unspace{} |
| 562 |
\xa\def\xa\ID@unspace\space{} |
| 563 |
% \end{macrocode} |
| 564 |
% \end{macros} |
| 565 |
% |
| 566 |
% \begin{macros}{\ID@trygroup,\ID@recurse} |
| 567 |
% The next two macros are used to check if the |\bgroup| token was an |
| 568 |
% explicit or an implicit grouping character. If it's explicit then |
| 569 |
% the next macro that takes an argument will scoop the whole thing up |
| 570 |
% at once, and so we need to be aware of this to deal with it. |
| 571 |
% |\ID@trygroup| uses the special |#| delimiter and compares the argument |
| 572 |
% with |\@empty| to see if anything comes before the next |{}|. If it |
| 573 |
% doesn't find anything then it was an explicit group and we recurse. |
| 574 |
% One consequence of this is that we always need to put a |{}| after |
| 575 |
% |\Q@END| so that we don't get an error here. |
| 576 |
% \begin{macrocode} |
| 577 |
\newcommand\ID@trygroup{} |
| 578 |
\long\def\ID@trygroup#1#{% check for explicit/implicit grouping! |
| 579 |
\def\@reservedd{#1}% |
| 580 |
\xa\let\xa\next |
| 581 |
\ifx\@reservedd\@empty\ID@recurse\else\ID@normal\fi |
| 582 |
\next#1% |
| 583 |
} |
| 584 |
% \end{macrocode} |
| 585 |
% Here we need to do some gymnastics to get the |{| and |}| tokens into |
| 586 |
% the toks register. It would be easiest if we could just add them one |
| 587 |
% at a time, but we can only add \emph{balanced text}, so we need to |
| 588 |
% expand the whole thing \emph{first} and then add it back to the register |
| 589 |
% we expanded it into. Thus, we enter a new level of grouping to save |
| 590 |
% the contents of |\ID@toks|, expand the inner group, and use |\expandafter| |
| 591 |
% across an |\endgroup| to get the correct tokens in the right place in |
| 592 |
% |\ID@toks|. |
| 593 |
% \begin{macrocode} |
| 594 |
\newcommand\ID@recurse[1]{% |
| 595 |
\begingroup\ID@toks{}% start a new level of grouping and empty \ID@toks |
| 596 |
\ID@scan#1\Q@END{}% % parse... |
| 597 |
\xa\endgroup\xa % this fiasco should get the job done...! |
| 598 |
\ID@toks\xa\xa\xa{\xa\the\xa\ID@toks\xa{\the\ID@toks}}% |
| 599 |
\ID@scan |
| 600 |
} |
| 601 |
% \end{macrocode} |
| 602 |
% \end{macros} |
| 603 |
% |
| 604 |
% \begin{macros}{\ID@normal,ID@noexpandnext} |
| 605 |
% This is what we do when it's not anything special. |
| 606 |
% \begin{macrocode} |
| 607 |
\newcommand\ID@normal[1]{\ID@toks\xa{\the\ID@toks#1}\ID@scan} |
| 608 |
\newcommand\ID@noexpandnext[2]{\ID@toks\xa{\the\ID@toks#2}\ID@scan} |
| 609 |
% \end{macrocode} |
| 610 |
% \end{macros} |
| 611 |
% |
| 612 |
% \begin{macros}{\ID@checkusage,\ID@checkredef} |
| 613 |
% Here we define tests that will issue errors if the parameter |
| 614 |
% texts aren't the same, or the original function isn't defined. |
| 615 |
% \begin{macrocode} |
| 616 |
\newcommand*\ID@checkusage{% |
| 617 |
% Make sure parameter lists are the same, does nothing if undefined |
| 618 |
\ifx\@reserveda\@reservedb |
| 619 |
\else |
| 620 |
% Error messages |
| 621 |
\ifx\@reserveda\undefined % undefined - okay |
| 622 |
\else |
| 623 |
\global\ID@abortedtrue |
| 624 |
\ifx\@foo\Super |
| 625 |
\PackageError{inlinedef}{Cannot use \protect\Super\space in \expandafter |
| 626 |
\protect\@macroname\space because\MessageBreak |
| 627 |
parameter lists don't match:\MessageBreak |
| 628 |
`\@reservedb' (new) != `\@reserveda' (old)}\@eha |
| 629 |
\else |
| 630 |
\ifID@bang % auto-expansion forbidden |
| 631 |
\PackageError{inlinedef}{Cannot use \protect\Inline* auto-expansion in |
| 632 |
\expandafter\protect\@macroname\MessageBreak |
| 633 |
because parameter lists don't match:\MessageBreak |
| 634 |
`\@reservedb' (new) != `\@reserveda' (old)}\@eha |
| 635 |
\else |
| 636 |
\PackageError{inlinedef}{Parameter lists for |
| 637 |
\expandafter\protect\@macroname\space don't match:\MessageBreak |
| 638 |
`\@reservedb' (new) != `\@reserveda' (old)\MessageBreak |
| 639 |
Use !-form of \protect\Inline\space to ignore this}\@eha |
| 640 |
\fi |
| 641 |
\fi |
| 642 |
\fi |
| 643 |
\fi |
| 644 |
} |
| 645 |
\newcommand*\ID@checkredef{% |
| 646 |
\ifx\@reserveda\undefined % undefined - okay |
| 647 |
\PackageError{inlinedef}{Cannot use \ifx\@foo\Super\protect\Super\space |
| 648 |
\else\protect\Inline** \fi in \expandafter\protect\@macroname\space |
| 649 |
because \MessageBreak it hasn't been defined yet}% |
| 650 |
\@eha |
| 651 |
\global\ID@abortedtrue |
| 652 |
\fi |
| 653 |
} |
| 654 |
% \end{macrocode} |
| 655 |
% \end{macros} |
| 656 |
% |
| 657 |
% \begin{macros}{\ID@expandsuper,\ID@expandnext,\ID@expandmulti,% |
| 658 |
% \ID@expandunsafe,\ID@expandmacro} |
| 659 |
% These correspond to the two special tokens, |\Super| and |\Expand|. |
| 660 |
% The first one tests that the parameter list is alright and that the |
| 661 |
% original command wasn't undefined. If all is well, it expands everything |
| 662 |
% in the right order. The second one is simpler, just inserting an |
| 663 |
% |\expandafter| before the continuation (|\ID@scan|) to expand whatever |
| 664 |
% comes next once. There is (yet) no way to fully-expand, although several |
| 665 |
% |\Expand|s and |\expandafter|s can be stacked cleverly to expand several |
| 666 |
% things in a specific order. |
| 667 |
% \begin{macrocode} |
| 668 |
\newcommand*\ID@expandsuper[1]{% |
| 669 |
\ID@checkusage\ID@checkredef |
| 670 |
\ifID@aborted\else |
| 671 |
\ID@toks\xa\xa\xa\xa\xa\xa\xa |
| 672 |
{\xa\xa\xa\the\xa\xa\xa\ID@toks\xa\@reservedc\ID@fixedparams}% |
| 673 |
\fi |
| 674 |
\ID@scan |
| 675 |
} |
| 676 |
\newcommand\ID@expandnext[2]{% |
| 677 |
\ID@toks\xa\xa\xa{\xa\the\xa\ID@toks#2}\ID@scan |
| 678 |
} |
| 679 |
\newcommand\ID@expandmulti[3]{% |
| 680 |
\begingroup % #1 is the \MultiExpand... |
| 681 |
\ID@count#2\relax % this will need to be allocated too! |
| 682 |
\ID@toks{#3}% |
| 683 |
\@testtrue\ifnum\ID@count<\@ne\@testfalse\fi |
| 684 |
\@whilesw\if@test\fi{% |
| 685 |
\ID@toks\xa\xa\xa{\the\ID@toks}% one expansion... |
| 686 |
\advance\ID@count\m@ne\ifnum\ID@count<\@ne\@testfalse\fi |
| 687 |
}% |
| 688 |
\xa\endgroup\xa\ID@toks\xa\xa\xa{\xa\the\xa\ID@toks\the\ID@toks}\ID@scan |
| 689 |
} |
| 690 |
|
| 691 |
\newcommand*\ID@expandunsafe[1]{\expandafter\ID@scan} |
| 692 |
\newcommand*\ID@expandmacro[1]{\expandafter\ID@scan\@reservedc} |
| 693 |
% \end{macrocode} |
| 694 |
% \end{macros} |
| 695 |
% |
| 696 |
% \begin{macros}{\ID@getprefix} |
| 697 |
% This is used to compare argument lists. |
| 698 |
% \begin{macrocode} |
| 699 |
\newcommand\ID@getprefix{}\long\def\ID@getprefix#1:#2->#3\Q@END{\detokenize{#2}} |
| 700 |
% \end{macrocode} |
| 701 |
% \end{macros} |
| 702 |
% |
| 703 |
% Finally we clean up by restoring |@|'s catcode. |
| 704 |
% \begin{macrocode} |
| 705 |
\makeatother |
| 706 |
%</package> |
| 707 |
% \end{macrocode} |
| 708 |
% |
| 709 |
% \StopIndexing |
| 710 |
% \filbreak |
| 711 |
% \section{Test suite} |
| 712 |
% We include a somewhat-comprehensive test suite to make sure that everything |
| 713 |
% is working. If it works properly, it should output nothing. |
| 714 |
% |
| 715 |
% First we define a few helper-functions to test for errors, etc. |
| 716 |
% \begin{macrocode} |
| 717 |
%<*testsuite> |
| 718 |
\makeatletter |
| 719 |
\errorcontextlines=10 |
| 720 |
\def\WantError#1#2#3{% |
| 721 |
\let\WE@packageerror\PackageError |
| 722 |
\def\PackageError##1##2##3{% |
| 723 |
\protected@edef\@goterror{##2}\protected@edef\@wanterror{#2}% |
| 724 |
\edef\@goterror{\xa\detokenize\xa{\@goterror}}% |
| 725 |
\edef\@wanterror{\xa\detokenize\xa{\@wanterror}}% |
| 726 |
\protected@edef\@gotpackage{##1}\protected@edef\@wantpackage{#1}% |
| 727 |
\edef\@gotpackage{\xa\detokenize\xa{\@gotpackage}}% |
| 728 |
\edef\@wantpackage{\xa\detokenize\xa{\@wantpackage}}% |
| 729 |
\global\let\PackageError\WE@packageerror |
| 730 |
\@tempswafalse |
| 731 |
\ifx\@gotpackage\@wantpackage\else\message{^^J(arg 1 differs)^^J}\@tempswatrue\fi |
| 732 |
\ifx\@goterror\@wanterror\else\message{^^J(arg 2 differs)^^J}\@tempswatrue\fi |
| 733 |
\ifx#3##3\else\message{^^J(arg 3 differs)^^J}\@tempswatrue\fi |
| 734 |
\if@tempswa\PackageError{inlinedef (test)}{wrong error}\@eha\PackageError{##1}{##2}##3\fi |
| 735 |
}% |
| 736 |
} |
| 737 |
|
| 738 |
\def\CheckError{% |
| 739 |
\ifx\PackageError\WE@packageerror\else |
| 740 |
\PackageError{inlinedef (test)}{expected error not thrown}\@eha\fi |
| 741 |
\global\let\PackageError\WE@packageerror |
| 742 |
} |
| 743 |
\newcommand\CheckDefinition[1][]{\@CheckDefinition{#1}} |
| 744 |
\def\@CheckDefinition#1#2#3#{\@checkdefn{#1}#2{#3}} |
| 745 |
\def\@checkdefn#1#2#3#4{#1\def\@reserveda#3{#4}\ifx#2\@reserveda\else |
| 746 |
\message{^^J^^J\meaning#2^^J(got)vs(wanted)^^J\meaning\@reserveda^^J^^J} |
| 747 |
\PackageError{inlinedef (test)}{definition of \detokenize{#2}didn't match}\@eha\fi |
| 748 |
} |
| 749 |
\let\eha\@eha\let\ehd\@ehd |
| 750 |
\makeatother |
| 751 |
% \end{macrocode} |
| 752 |
% |
| 753 |
% Here we predefine copies of the errors so that we can look for them easily |
| 754 |
% \begin{macrocode} |
| 755 |
\catcode`\#=12 |
| 756 |
\def\pound{#} |
| 757 |
\catcode`\#=6 |
| 758 |
|
| 759 |
\def\WantSuperNoMatch#1#2#3{% |
| 760 |
\WantError{inlinedef}{Cannot use \protect\Super\space in |
| 761 |
\protect#1\space because\MessageBreak |
| 762 |
parameter lists don't match:\MessageBreak |
| 763 |
`#3' (new) != `#2' (old)}\eha |
| 764 |
} |
| 765 |
\def\WantStarNoMatch#1#2#3{% |
| 766 |
\WantError{inlinedef}{Cannot use \protect\Inline* auto-expansion in |
| 767 |
\protect#1\MessageBreak because |
| 768 |
parameter lists don't match:\MessageBreak |
| 769 |
`#3' (new) != `#2' (old)}\eha |
| 770 |
} |
| 771 |
\def\WantNoMatchBang#1#2#3{% |
| 772 |
\WantError{inlinedef}{Parameter lists for |
| 773 |
\protect#1\space don't match:\MessageBreak |
| 774 |
`#3' (new) != `#2' (old)\MessageBreak |
| 775 |
Use !-form of \protect\Inline\space to ignore this}\eha |
| 776 |
} |
| 777 |
\def\WantOnlyDefGdef{% |
| 778 |
\WantError{inlinedef}{Only \protect\def\space and \protect\gdef\space are |
| 779 |
allowed after \protect\Inline,\MessageBreak but some other type of |
| 780 |
definition was found}\eha |
| 781 |
} |
| 782 |
\def\WantNoDefGdef{% |
| 783 |
\WantError{inlinedef}{No \protect\def\space or \protect\gdef\space found |
| 784 |
after \protect\Inline}\ehd |
| 785 |
} |
| 786 |
\def\WantSuperNoRedef#1{% |
| 787 |
\WantError{inlinedef}{Cannot use \protect\Super\space in \protect#1\space |
| 788 |
because \MessageBreak it hasn't been defined yet}\eha |
| 789 |
} |
| 790 |
% \end{macrocode} |
| 791 |
% |
| 792 |
% Now we start the actual tests. |
| 793 |
% \begin{macrocode} |
| 794 |
% I. Basic stuff |
| 795 |
% A. Simple definition |
| 796 |
\let\a\undefined |
| 797 |
\Inline\def\a{b} |
| 798 |
\CheckDefinition\a{b} |
| 799 |
|
| 800 |
% B. Simple redefinition |
| 801 |
\def\a{b} |
| 802 |
\Inline\def\a{d} |
| 803 |
\CheckDefinition\a{d} |
| 804 |
|
| 805 |
% C. Erroneous redefinition (needs !) |
| 806 |
\def\a{b} |
| 807 |
\WantNoMatchBang\a{}{\pound1} |
| 808 |
\Inline\def\a#1{c} |
| 809 |
\CheckError |
| 810 |
\CheckDefinition\a{b} % shouldn't have changed |
| 811 |
|
| 812 |
\def\a{b} |
| 813 |
\Inline!\def\a#1{c} |
| 814 |
\CheckDefinition\a#1{c} |
| 815 |
|
| 816 |
% D. Local/global definition |
| 817 |
\def\a{b} |
| 818 |
\begingroup |
| 819 |
\Inline\def\a{c} |
| 820 |
\endgroup |
| 821 |
\CheckDefinition\a{b} |
| 822 |
|
| 823 |
\begingroup |
| 824 |
\Inline\gdef\a{c} |
| 825 |
\endgroup |
| 826 |
\CheckDefinition\a{c} |
| 827 |
|
| 828 |
{\Inline\global\def\a{d}} |
| 829 |
\CheckDefinition\a{d} |
| 830 |
|
| 831 |
% E. Collecting arguments |
| 832 |
\Inline\long\def\a{e} |
| 833 |
\CheckDefinition[\long]\a{e} |
| 834 |
|
| 835 |
\Inline\outer\def\a{f} |
| 836 |
\edef\a{\meaning\a} |
| 837 |
\edef\b{\detokenize{\outer macro:->f}} |
| 838 |
\xa\CheckDefinition\xa\a\xa{\b} |
| 839 |
|
| 840 |
\Inline\long\outer\def\a{g} |
| 841 |
\edef\a{\meaning\a} |
| 842 |
\edef\b{\string\long\string\outer\space\detokenize{macro:->g}} |
| 843 |
\xa\CheckDefinition\xa\a\xa{\b} |
| 844 |
|
| 845 |
\def\a{g} |
| 846 |
\Inline!\long\def\a#1{h} |
| 847 |
\CheckDefinition[\long]\a#1{h} |
| 848 |
|
| 849 |
% II. Special tokens |
| 850 |
% A. Recursion |
| 851 |
\def\a{b} |
| 852 |
\Inline\def\a{a\a c} |
| 853 |
\CheckDefinition\a{a\a c} |
| 854 |
|
| 855 |
% B. Expansion |
| 856 |
\def\a{b} |
| 857 |
\Inline\def\a{a\Expand\a c} |
| 858 |
\CheckDefinition\a{abc} |
| 859 |
|
| 860 |
\def\a{b} |
| 861 |
\Inline\def\a{\Expand a\Expand\a\Expand c} |
| 862 |
\CheckDefinition\a{abc} |
| 863 |
|
| 864 |
\def\a{\b} |
| 865 |
\def\b{c} |
| 866 |
\Inline\def\a{a\Expand\a c} |
| 867 |
\CheckDefinition\a{a\b c} |
| 868 |
|
| 869 |
\toks0{b}\toks1{d} |
| 870 |
\Inline\def\a{a\the\toks0c\the\toks1e} |
| 871 |
\CheckDefinition\a{a\the\toks0c\the\toks1e} |
| 872 |
|
| 873 |
\Inline\def\a{a\Expand{\the\toks0}c\Expand{\the\toks1}e} |
| 874 |
\CheckDefinition\a{abcde} |
| 875 |
|
| 876 |
\Inline\def\a{\Expand{a\the\toks0}c\Expand{\the\toks1}e} |
| 877 |
\CheckDefinition\a{a\the\toks0cde} |
| 878 |
|
| 879 |
\Inline\def\a{\Expand{\expandafter a\the\toks0}c\Expand{\the\toks1e}} |
| 880 |
\CheckDefinition\a{abcde} |
| 881 |
|
| 882 |
% C. MultiExpand |
| 883 |
\def\x{\y} |
| 884 |
\def\y{\z} |
| 885 |
\def\z{0} |
| 886 |
\Inline\def\a{a\MultiExpand0\x b} |
| 887 |
\CheckDefinition\a{a\x b} |
| 888 |
|
| 889 |
\Inline\def\a{a\MultiExpand1\x b} |
| 890 |
\CheckDefinition\a{a\y b} |
| 891 |
|
| 892 |
\Inline\def\a{a\MultiExpand2\x b} |
| 893 |
\CheckDefinition\a{a\z b} |
| 894 |
|
| 895 |
\Inline\def\a{a\MultiExpand3\x b} |
| 896 |
\CheckDefinition\a{a0b} |
| 897 |
|
| 898 |
\Inline\def\a{a\MultiExpand{10}\x b} |
| 899 |
\CheckDefinition\a{a0b} |
| 900 |
|
| 901 |
% i. use with \expandafter |
| 902 |
\Inline\def\a{a\MultiExpand2{\expandafter\expandafter\x\x}b} |
| 903 |
\CheckDefinition\a{a\y\y b} |
| 904 |
|
| 905 |
\Inline\def\a{a\MultiExpand1{\expandafter\expandafter\x\x}b} |
| 906 |
\CheckDefinition\a{a\expandafter\y\x b} |
| 907 |
|
| 908 |
\Inline\def\a{a\MultiExpand2{\expandafter\expandafter\expandafter\x\x}b} |
| 909 |
\CheckDefinition\a{a\x\z b} |
| 910 |
|
| 911 |
\Inline\def\a{a\MultiExpand3{\expandafter\expandafter\expandafter\x\x}b} |
| 912 |
\CheckDefinition\a{a\y\z b} |
| 913 |
|
| 914 |
\Inline\def\a{a\MultiExpand4{\expandafter\expandafter\expandafter\x\x}b} |
| 915 |
\CheckDefinition\a{a\z\z b} |
| 916 |
|
| 917 |
\Inline\def\a{a\MultiExpand5{\expandafter\expandafter\expandafter\x\x}b} |
| 918 |
\CheckDefinition\a{a0\z b} |
| 919 |
|
| 920 |
% D. UnsafeExpand |
| 921 |
\def\x{b\Super c} |
| 922 |
\Inline\def\a{a\Expand\x d} |
| 923 |
\CheckDefinition\a{ab\Super cd} |
| 924 |
|
| 925 |
\def\a{0} |
| 926 |
\Inline\def\a{a\UnsafeExpand\x d} |
| 927 |
\CheckDefinition\a{ab0cd} |
| 928 |
|
| 929 |
\def\a{b\Super d} |
| 930 |
\Inline\def\a{a\UnsafeExpand\a e} |
| 931 |
\CheckDefinition\a{abb\Super dde} |
| 932 |
|
| 933 |
\def\a{b\Super d} |
| 934 |
\Inline**\def\a{a\a e} |
| 935 |
\CheckDefinition\a{abb\Super dde} |
| 936 |
|
| 937 |
% Would be nice if we could catch TeX capacity exceeded errors... |
| 938 |
% Then try \def\a{b\a d}\Inline**\def\a{a\a e} |
| 939 |
|
| 940 |
\def\x#1{b#1d} |
| 941 |
\Inline\def\a{a\x ce} |
| 942 |
\CheckDefinition\a{a\x ce} |
| 943 |
|
| 944 |
\Inline\def\a{a\UnsafeExpand\x ce} |
| 945 |
\CheckDefinition\a{abcde} |
| 946 |
|
| 947 |
% E. NoExpand |
| 948 |
\Inline\def\a{a\NoExpand\Expand\x b} |
| 949 |
\CheckDefinition\a{a\Expand\x b} |
| 950 |
|
| 951 |
\Inline*\def\a{a\NoExpand\a b} |
| 952 |
\CheckDefinition\a{a\a b} |
| 953 |
|
| 954 |
\Inline**\def\a{a\NoExpand\a b} |
| 955 |
\CheckDefinition\a{a\a b} |
| 956 |
|
| 957 |
\Inline\def\a{a\NoExpand{\Expand\x\Expand\y}b} |
| 958 |
\CheckDefinition\a{a\Expand\x\Expand\y b} |
| 959 |
|
| 960 |
% F. Super |
| 961 |
\def\a{bcd} |
| 962 |
\Inline\def\a{a\Super e} |
| 963 |
\CheckDefinition\a{abcde} |
| 964 |
|
| 965 |
\def\a#1{b#1d} |
| 966 |
\Inline\def\a#1{a\Super e} |
| 967 |
\CheckDefinition\a#1{ab#1de} |
| 968 |
|
| 969 |
\def\a#1{b#1d} |
| 970 |
\Inline*\def\a#1{a\Super e} |
| 971 |
\CheckDefinition\a#1{ab#1de} |
| 972 |
|
| 973 |
\def\a#1{b#1d} |
| 974 |
\Inline**\def\a#1{a\Super e} |
| 975 |
\CheckDefinition\a#1{ab#1de} |
| 976 |
|
| 977 |
% G. Recurse |
| 978 |
\def\a{q} |
| 979 |
\Inline\def\a{a\Recurse b} |
| 980 |
\CheckDefinition\a{a\a b} |
| 981 |
|
| 982 |
\Inline*\def\a{a\Recurse b} |
| 983 |
\CheckDefinition\a{a\a b} |
| 984 |
|
| 985 |
\Inline**\def\a{a\Recurse b} |
| 986 |
\CheckDefinition\a{a\a b} |
| 987 |
|
| 988 |
% III. Tricky parsing |
| 989 |
% A. Spaces |
| 990 |
\def\a{b c d} |
| 991 |
\Inline\def\a{a \Super e} |
| 992 |
\CheckDefinition\a{a b c de} |
| 993 |
|
| 994 |
\def\a{b c d} |
| 995 |
\Inline\def\a{a \Expand\a e} |
| 996 |
\CheckDefinition\a{a b c de} |
| 997 |
|
| 998 |
\def\a{b c d} |
| 999 |
\Inline\def\a{a \Expand{\a} e} |
| 1000 |
\CheckDefinition\a{a b c d e} |
| 1001 |
|
| 1002 |
\Inline\def\a{a\NoExpand{\Expand\x\Expand\y} b} |
| 1003 |
\xa\CheckDefinition\xa\a\xa{\xa a\xa\Expand\xa\x\xa\Expand\xa\y\space b} |
| 1004 |
|
| 1005 |
% B. Grouping |
| 1006 |
\def\a{b{c d}e} |
| 1007 |
\Inline\def\a{{a\Super}f\Super} |
| 1008 |
\CheckDefinition\a{{ab{c d}e}fb{c d}e} |
| 1009 |
|
| 1010 |
\Inline\def\a{{ }{}} |
| 1011 |
\Inline\def\a{{\Expand\a\a}{} {{\Super}{}}} |
| 1012 |
\CheckDefinition\a{{{ }{}\a}{} {{{ }{}}{}}} |
| 1013 |
|
| 1014 |
% C. Parameters |
| 1015 |
\def\a#1bcd#2{[#1...#2]} |
| 1016 |
\Inline\def\a#1bcd#2{a\Super b} |
| 1017 |
\CheckDefinition\a#1bcd#2{a[#1...#2]b} |
| 1018 |
|
| 1019 |
\def\a#1\##2{y} |
| 1020 |
\Inline\def\a#1\##2{x\UnsafeExpand\a{#1}\#{#2}z} |
| 1021 |
\CheckDefinition\a#1\##2{xyz} |
| 1022 |
|
| 1023 |
\def\a#1\##2{#1y#2} |
| 1024 |
\Inline\def\a#1\##2{x\UnsafeExpand\a{#1}\#{#2}z} |
| 1025 |
\CheckDefinition\a#1\##2{x#1y#2z} |
| 1026 |
|
| 1027 |
% i. spaces! |
| 1028 |
\def\a #1 {y} |
| 1029 |
\Inline\def\a#1 {x\Super z} |
| 1030 |
\CheckDefinition\a#1 {xyz} |
| 1031 |
|
| 1032 |
\xa\def\xa\a\space{y} |
| 1033 |
\xa\Inline\xa\def\xa\a\space{x\Super z} |
| 1034 |
\xa\CheckDefinition\xa\a\space{xyz} |
| 1035 |
|
| 1036 |
% ii. funky catcodes |
| 1037 |
%%%% This test fails. |
| 1038 |
%\begingroup |
| 1039 |
% \catcode`&=6 |
| 1040 |
% \def\a&1{b#1d} |
| 1041 |
% \Inline\def\a#1{a\Super e} |
| 1042 |
% \CheckDefinition\a#1{b&1d} |
| 1043 |
%\endgroup |
| 1044 |
|
| 1045 |
% D. Active characters |
| 1046 |
\begingroup |
| 1047 |
\catcode`A=13 |
| 1048 |
\defA#1{b#1d} |
| 1049 |
\Inline\defA#1{aAe} |
| 1050 |
\CheckDefinitionA#1{aAe} |
| 1051 |
|
| 1052 |
\defA#1{b#1d} |
| 1053 |
\Inline*\defA#1{aAe} |
| 1054 |
\CheckDefinitionA#1{ab#1de} |
| 1055 |
\endgroup |
| 1056 |
|
| 1057 |
% IV. Auto-expansion |
| 1058 |
|
| 1059 |
\def\a#1{y} |
| 1060 |
\Inline\def\a#1{x\a z} |
| 1061 |
\CheckDefinition\a#1{x\a z} |
| 1062 |
|
| 1063 |
\def\a#1{y} |
| 1064 |
\Inline*\def\a#1{x\a z} |
| 1065 |
\CheckDefinition\a#1{xyz} |
| 1066 |
|
| 1067 |
\def\a#1{y} |
| 1068 |
\Inline**\def\a#1{x\a{#1}z} |
| 1069 |
\CheckDefinition\a#1{xyz} |
| 1070 |
|
| 1071 |
% A. With delimited arguments |
| 1072 |
\def\a[#1]#2{#1y#2} |
| 1073 |
\Inline*\def\a[#1]#2{x\a z} |
| 1074 |
\CheckDefinition\a[#1]#2{x#1y#2z} |
| 1075 |
|
| 1076 |
\def\a[#1]#2{#1y#2} |
| 1077 |
\Inline**\def\a[#1]#2{x\a[#1]{#2}z} |
| 1078 |
\CheckDefinition\a[#1]#2{x#1y#2z} |
| 1079 |
|
| 1080 |
% V. Errors |
| 1081 |
|
| 1082 |
\def\bar#1{d #1 f} |
| 1083 |
\def\x{b} |
| 1084 |
|
| 1085 |
\WantSuperNoMatch\a{\pound1}{.\pound1} |
| 1086 |
\def\a#1{x} |
| 1087 |
\Inline!\def\a.#1{y\Super} |
| 1088 |
\CheckError |
| 1089 |
\CheckDefinition\a#1{x} |
| 1090 |
|
| 1091 |
\WantStarNoMatch\a{\pound1}{.\pound1} |
| 1092 |
\def\a#1{x} |
| 1093 |
\Inline*!\def\a.#1{y\a} |
| 1094 |
\CheckError |
| 1095 |
\CheckDefinition\a#1{x} |
| 1096 |
|
| 1097 |
\def\a#1{x} |
| 1098 |
\Inline!\def\a.#1{y} % ok |
| 1099 |
\CheckDefinition\a.#1{y} |
| 1100 |
|
| 1101 |
\WantOnlyDefGdef |
| 1102 |
\def\foo{a} |
| 1103 |
\Inline\edef\foo{b} |
| 1104 |
\CheckError |
| 1105 |
\CheckDefinition\foo{a} |
| 1106 |
\let\foo\undefined |
| 1107 |
|
| 1108 |
\WantOnlyDefGdef |
| 1109 |
\Inline\global\outer\xdef{} |
| 1110 |
\CheckError |
| 1111 |
|
| 1112 |
\WantOnlyDefGdef |
| 1113 |
\Inline\global\outer\abc\space vbcda s \newcommand{} |
| 1114 |
\CheckError |
| 1115 |
|
| 1116 |
\WantNoDefGdef |
| 1117 |
\Inline\let\relax\relax |
| 1118 |
\CheckError |
| 1119 |
|
| 1120 |
\WantNoDefGdef |
| 1121 |
\Inline{} |
| 1122 |
\CheckError |
| 1123 |
|
| 1124 |
\WantSuperNoRedef\foo |
| 1125 |
\Inline\def\foo#1{a \Expand\x\space cd #1 fg \x\space i\Super} |
| 1126 |
\CheckError |
| 1127 |
|
| 1128 |
\WantNoMatchBang\a{}{\pound1} |
| 1129 |
\def\a{b} |
| 1130 |
\Inline\def\a#1{a\a c} |
| 1131 |
\CheckError |
| 1132 |
|
| 1133 |
% Miscellaneous (read: "old") tests |
| 1134 |
|
| 1135 |
\def\test#1{d #1 f} |
| 1136 |
\Inline\def\test#1{a \Expand\x\space c\Super g \x\space i} |
| 1137 |
\CheckDefinition\test#1{a b\space cd #1 fg \x\space i} |
| 1138 |
|
| 1139 |
\Inline*\def\bar#1{a \Expand\x\space c\bar g \x\space i} |
| 1140 |
\CheckDefinition\bar#1{a b\space cd #1 fg \x\space i} |
| 1141 |
|
| 1142 |
\def\bar#1{d #1 f} |
| 1143 |
\Inline**\def\bar#1{a \Expand\x\space c\bar{#1}g \x\space i} |
| 1144 |
\CheckDefinition\bar#1{a b\space cd #1 fg \x\space i} |
| 1145 |
|
| 1146 |
\Inline\def\foo#1{a \Expand\x\space cd #1 fg \x\space i} |
| 1147 |
\CheckDefinition\foo#1{a b\space cd #1 fg \x\space i} |
| 1148 |
|
| 1149 |
\def\a{b} |
| 1150 |
\Inline!\def\a#1{a\Expand\a c} |
| 1151 |
\CheckDefinition\a#1{abc} |
| 1152 |
|
| 1153 |
\def\a{b} |
| 1154 |
\Inline!**\def\a#1{a\a c} |
| 1155 |
\CheckDefinition\a#1{abc} |
| 1156 |
|
| 1157 |
\Inline\def\a#1{a\a c} |
| 1158 |
\CheckDefinition\a#1{a\a c} |
| 1159 |
|
| 1160 |
\Inline\def\a#1{a\Recurse c} |
| 1161 |
\CheckDefinition\a#1{a\a c} |
| 1162 |
|
| 1163 |
\Inline!\def\a{a\NoExpand{b\Super c}d} |
| 1164 |
\CheckDefinition\a{ab\Super cd} |
| 1165 |
|
| 1166 |
\Inline*\def\a{gh\a jk} |
| 1167 |
\CheckDefinition\a{ghab\Super cdjk} |
| 1168 |
|
| 1169 |
% SURPRISE! unsafe expansion... |
| 1170 |
\def\a{ab\Super cd} |
| 1171 |
\Inline**\def\a{gh\a jk} |
| 1172 |
\CheckDefinition\a{ghabab\Super cdcdjk} |
| 1173 |
|
| 1174 |
\def\a{ab\Super cd} |
| 1175 |
\Inline\def\a{gh\UnsafeExpand\a jk} |
| 1176 |
\CheckDefinition\a{ghabab\Super cdcdjk} |
| 1177 |
|
| 1178 |
\def\x{\x a} % This is a fun one...! |
| 1179 |
\Inline\def\a{\MultiExpand{5}\x} |
| 1180 |
\CheckDefinition\a{\x aaaaa} |
| 1181 |
|
| 1182 |
\message{^^JAll tests completed.^^J} |
| 1183 |
|
| 1184 |
\begin{document} |
| 1185 |
\end{document} |
| 1186 |
%</testsuite> |
| 1187 |
% \end{macrocode} |
| 1188 |
% |
| 1189 |
% \makeatother |
| 1190 |
% \eject |
| 1191 |
% \Finale |
| 1192 |
% |
| 1193 |
% |
| 1194 |
% \iffalse |
| 1195 |
% |
| 1196 |
% The next line of code prevents DocStrip from adding the |
| 1197 |
% character table to the generated files(s). |
| 1198 |
|
| 1199 |
% Removed stuff |
| 1200 |
|
| 1201 |
\endinput |
| 1202 |
% |
| 1203 |
% \fi |
| 1204 |
% |
| 1205 |
%% \CharacterTable |
| 1206 |
%% {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 |
| 1207 |
%% 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 |
| 1208 |
%% Digits \0\1\2\3\4\5\6\7\8\9 |
| 1209 |
%% Exclamation \! Double quote \" Hash (number) \# |
| 1210 |
%% Dollar \$ Percent \% Ampersand \& |
| 1211 |
%% Acute accent \' Left paren \( Right paren \) |
| 1212 |
%% Asterisk \* Plus \+ Comma \, |
| 1213 |
%% Minus \- Point \. Solidus \/ |
| 1214 |
%% Colon \: Semicolon \; Less than \< |
| 1215 |
%% Equals \= Greater than \> Question mark \? |
| 1216 |
%% Commercial at \@ Left bracket \[ Backslash \\ |
| 1217 |
%% Right bracket \] Circumflex \^ Underscore \_ |
| 1218 |
%% Grave accent \` Left brace \{ Vertical bar \| |
| 1219 |
%% Right brace \} Tilde \~} |
| 1220 |
%% |