-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvisualtoks.tex
More file actions
92 lines (77 loc) · 2.31 KB
/
visualtoks.tex
File metadata and controls
92 lines (77 loc) · 2.31 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
% visualtoks.tex, version 1.1b
% Copyright (C) 2025 plante
% This package is released under the LaTeX Project Public License (LPPL) 1.3c.
% visualtoks: typeset TeXbook-style visualisations of token lists.
% This package may be used in LaTeX by `\usepackage{visualtoks}`, or
% in plain TeX and other formats by `\input{visualtoks}`.
% See the documentation for typeset examples and caveats.
\ifdefined\visualtoks
\expandafter\endinput
\fi
\edef\next{\catcode`\noexpand\@=\the\catcode`\@\space}
\catcode`\@=11
\input tokmap
\newdimen\visualtokssep \visualtokssep=1em
\protected\long\def\visualtoks#1{%
\begingroup
\leavevmode
\ifcsname ttfamily\endcsname \ttfamily \else \tt \fi \m@th
\hskip-\visualtokssep \tokmap\visualtoksA{#1}%
\endgroup
}
\long\def\visualtoksA#1{%
\hskip\visualtokssep
\ifx\tokmap@space#1%
\char`\ $_{10}$%
\else\ifx\tokmap@bgroup#1%
\char`\{$_1$%
\else\ifx\tokmap@egroup#1%
\char`\}$_2$%
\else
\escapechar`\\%
\edef\tempa{\string#1}%
\escapechar\m@ne
\edef\tempb{\string#1}%
\ifx\tempa\tempb \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi
{\ifnum`\ =`#1 \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi
{\char`\ }{\string#1}%
$_{%
\let~\empty
\lccode`~=`#1\lowercase{\let~}\empty
\ifcat$\noexpand#13\fi
\ifcat &\noexpand#14\fi
\ifcat##\noexpand#16\fi
\ifcat ^\noexpand#17\fi
\ifcat _\noexpand#18\fi
\ifcat\space\noexpand#110\fi
\ifcat a\noexpand#111\fi
\ifcat !\noexpand#112\fi
\ifcat\noexpand~\noexpand#113\fi
}$}%
{\ifx\visualtoks@emptycs\tempb \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi
{\visualtoksB{}}%
{\expandafter\visualtoksB\expanded{{\string#1}}%
\long\expandafter\def\expandafter\tempa\expandafter##\expandafter1\csname\string#1\endcsname{}%
\if\relax\detokenize\expandafter\expandafter\expandafter
{\expandafter\tempa\expandafter#1\csname\string#1\endcsname}\relax *\fi}}%
\fi\fi\fi
}
\long\def\visualtoksB#1{%
\hbox{%
\vrule
\vtop{%
\vbox{%
\hrule \kern\p@
\hbox{\vphantom/\thinspace \tokmap\visualtoksC{#1}\thinspace}%
}%
\kern\p@ \hrule
}%
\vrule
}%
}
\long\def\visualtoksC#1{\ifx\tokmap@space#1\char`\ \else#1\fi}
\begingroup \escapechar=\m@ne
\xdef\visualtoks@emptycs{\expandafter\string \csname\endcsname}
\endgroup
\next
\endinput