Debian Codegraph @

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

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