| 1 |
% $Id: expanded.tex 47741 2018-05-17 21:37:18Z karl $ |
| 2 |
% Public domain. |
| 3 |
% Originally written 2018 by David Carlisle, Bruno Le Floch. |
| 4 |
|
| 5 |
\catcode`\{=1 \catcode`\}=2 \catcode`\#=6 |
| 6 |
\def\typ#1{\immediate\write-1 {#1}} |
| 7 |
\def\space{ } |
| 8 |
\let\bgroup{ \let\egroup} |
| 9 |
|
| 10 |
\typ{START} |
| 11 |
\typ{EXPANDED TEST 1} |
| 12 |
% Check the primitive exists |
| 13 |
\show\expanded |
| 14 |
|
| 15 |
\typ{EXPANDED TEST 2} |
| 16 |
% Simple expansion test |
| 17 |
\def\aaa{x} |
| 18 |
\def\bbb{\aaa\aaa} |
| 19 |
\expandafter\def\expandafter\ccc\expandafter{\expanded{\bbb,\aaa}} |
| 20 |
\show\ccc |
| 21 |
|
| 22 |
\typ{EXPANDED TEST 3: the} |
| 23 |
% Expanding \the |
| 24 |
\typ{\expanded{\bbb,\the\numexpr100+20+3\relax}} |
| 25 |
|
| 26 |
\typ{EXPANDED TEST 4: macro param} |
| 27 |
% Constructed #1 is still #1 |
| 28 |
\expandafter\def\expandafter\ddd\expandafter#\expanded{1{#\number--1}} |
| 29 |
\show\ddd |
| 30 |
|
| 31 |
\typ{EXPANDED TEST 5: torture} |
| 32 |
% Torture test from Bruno Le Floch testing various tricky interactions |
| 33 |
\expanded\relax\space\ifincsname \BOOM\fi{\ifincsname \BOOM\fi} |
| 34 |
\showtokens\expandafter{\expanded{#,\noexpand\aaa,\unexpanded{\aaa}}} |
| 35 |
\showtokens\expandafter{\expanded{#,\unexpanded{#}}} |
| 36 |
\showtokens\expandafter{\expanded\expandafter{\noexpand\aaa}} |
| 37 |
\showtokens\expandafter{\expanded\expandafter{\unexpanded{\aaa}}} |
| 38 |
\showtokens\expanded{{\expanded{\aaa\noexpand\aaa\noexpand\noexpand\noexpand\aaa}}} |
| 39 |
\toks0{\aaa} |
| 40 |
\showtokens\expanded{{\the\toks0}} |
| 41 |
\expanded\bgroup\show\egroup} |
| 42 |
\edef\foo{\expanded{##}} |
| 43 |
\show\foo |
| 44 |
|
| 45 |
\typ{END} |
| 46 |
\end |