blob: 252f1d358b14a897b4f999b08b171586ec721a31 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
% SPLIT.TEX
% Marek Ry\'cko
% Macro \split (and auxiliary macros)
% for splitting token sequences
% Macro \hdtl
% version 0.0 24.07.1993
% version 0.1 31.12.94
% version 0.2 1.5.1996
% -- english description
\def\hdtl
#1% inp. t.s. (nonempty, poss blanks)
#2% outp. -- head
#3% outp. -- tail
{\let\reshead=#2% synonims for token-register names
\let\restail=#3%
\expandafter\gethead\the#1\endoftokens}
\def\gethead
{\futurelet\thehead\analysehead}
\def\analysehead
{\ifcat \noexpand\thehead \space
\let\followby=\followbyspace
\else
\let\followby=\followbynospace
\fi
\followby}
\def\followbyspace
{\reshead={ }% space token
\afterassignment\gettail
\let\swallow= }% swallowing the head-space
\def\gettail
#1\endoftokens
{\restail={#1}}
\def\followbynospace
#1#2\endoftokens
{\reshead={#1}%
\restail={#2}}
\def\split
#1% input macro name (should expand to nonemty token sequence)
#2% macro head (name)
#3% macro tail (name)
{%
% define
% #2 as the first token (with nested braces) of #1
% #3 as the tail (with nested braces) of #1
\expandafter\splithdtl\expandafter{#1}%
\expandafter\def\expandafter\splittest\expandafter{\the\splithdtl}%
\ifx\splittest\empty
\gdef#2{}%
\gdef#3{}%
\else
\hdtl\splithdtl\splithd\splittl
\expandafter\gdef\expandafter#2\expandafter{\the\splithd}%
\expandafter\gdef\expandafter#3\expandafter{\the\splittl}%
\fi
}
\newtoks\splithdtl
\newtoks\splithd
\newtoks\splittl
|