Debian Codegraph @

texmf-dist/doc/generic/multiexpand/multiexpand002.lvt

raw
1 %%
2 %% This is file `multiexpand002.lvt',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% multiexpand.dtx (with options: `lvt,lvt002')
8 %% ----------------------------------------------------------------
9 %% multiexpand --- trigger multiple expansions in one expansion step.
10 %% E-mail: [email protected]
11 %% Released under the LaTeX Project Public License v1.3c or later
12 %% See http://www.latex-project.org/lppl.txt
13 %% ----------------------------------------------------------------
14 %%
15 \input regression-test.tex\relax
16 \START
17 \LONGTYPEOUT{Author: Bruno Le Floch}
18 \let\numexpr\relax
19 \input multiexpand.sty\relax
20
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 % Introduce commands that expand to each other, to count how many times
23 % things were expanded.
24 \OMIT
25 \def\i{}
26 \def\v{\i\i\i\i}
27 \def\x{\i\i\i\i\v}
28 \def\l{\i\i\i\i\v\x\x\x\x}
29 \def\c{\i\i\i\i\v\x\x\x\x\l}
30 \def\d{\i\i\i\i\v\x\x\x\x\l\c\c\c\c}
31 \def\m{\i\i\i\i\v\x\x\x\x\l\c\c\c\c\d}
32 \TIMO
33
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 % We test |\MultiExpand|, which needs two expansions. In particular, we see
36 % that the implementation is reasonably quick, and we get the $2345$-th
37 % expansion of |\m\m\m\m|.
38 % 4000-2345 = 1655 = mdclv
39 \TEST{MultiExpand many times (vlcdm)}{%
40 \toks0\expandafter\expandafter\expandafter{\MultiExpand{2345}\m\m\m\m}%
41 \TYPE{\the\toks0.}%
42 }
43
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 % Test |\MultiExpandAfter|, two expansions to get the specified expansion.
46 % The results indirectly show that expansions happen in the expected order.
47 % 100 = c
48 % 100-(27-2) = 75 = lxxv
49 % 100-(14-2) = 88 = lxxxviii
50 % 100-38 = 62 = lxii
51 \TEST{MultiExpandAfter chain (c vxxl iiivxxxl iixl)}{%
52 \toks0\expandafter\expandafter\expandafter{%
53 \MultiExpandAfter{27}\c
54 \MultiExpandAfter{14}\c
55 \MultiExpandAfter{38}\c\c}%
56 \TYPE{\the\toks0.}%
57 }
58
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 % Test the order of expansion. The example was given in the original
61 % question that led to writing this package. For the record, this
62 % package (at some point) used 32 |\expandafter| to do the expansion
63 % in the right order, which was better than other approaches; however
64 % this counting ignores the large overheads due to other primitives.
65 \OMIT
66 \def\a#1.{#1}
67 \def\b#1:{#1.}
68 \def\c#1,{#1:}
69 \def\d{Hello world!,}
70 \TIMO
71 %
72 \TEST{MultiExpandAfter order}{%
73 \toks0\MultiExpandAfter{3}{%
74 \MultiExpandAfter{3}\a
75 \MultiExpandAfter{3}\b
76 \MultiExpandAfter{1}\c
77 \d}%
78 \TYPE{\the\toks0}%
79 }
80
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % The other example from the same question (expanding seven tokens once
83 % each in the reverse order) takes 74 \expandafter.
84 \OMIT
85 \def\b.{.b} \def\c.{.c} \def\d.{.d}
86 \def\e.{.e} \def\f.{.f} \def\g.{.g}
87 \TIMO
88 %
89 \TEST{MultiExpandAfter order (2)}{%
90 \toks0\MultiExpandAfter{2}{%
91 \MultiExpandAfter3\a \MultiExpandAfter3\b
92 \MultiExpandAfter3\c \MultiExpandAfter3\d
93 \MultiExpandAfter3\e \MultiExpandAfter1\f\g.}%
94 \TYPE{\the\toks0}%
95 }
96
97 \END
98 %%
99 %% Copyright (C) 2011-2017 by Bruno Le Floch <[email protected]>
100 %%
101 %% This work may be distributed and/or modified under the
102 %% conditions of the LaTeX Project Public License (LPPL), either
103 %% version 1.3c of this license or (at your option) any later
104 %% version. The latest version of this license is in the file:
105 %%
106 %% http://www.latex-project.org/lppl.txt
107 %%
108 %% This work is "maintained" (as per LPPL maintenance status) by
109 %% Bruno Le Floch.
110 %%
111 %% This work consists of the file multiexpand.dtx
112 %% and the derived files multiexpand.ins,
113 %% multiexpand.pdf and
114 %% multiexpand.sty.
115 %%
116 %%
117 %% End of file `multiexpand002.lvt'.