-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfancyvrb-SaveVerb-and-UseVerb.tex
128 lines (91 loc) · 2.79 KB
/
fancyvrb-SaveVerb-and-UseVerb.tex
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
\SaveVerb[options]{name}|code|
\def\SaveVerb{\FV@Command{}{SaveVerb}}
% expand \SaveVerb
\FV@Command{}{SaveVerb}
[options]{name}|code|
\def\FV@Command#1#2{%
\@ifstar
{\def\FV@KeyValues{#1,showspaces}\FV@@Command{#2}}%
{\def\FV@KeyValues{#1}\FV@@Command{#2}}}
% expand \FV@Command, #1 = "", #2 = "SaveVerb"
% expand \@ifstar, false
\def\FV@KeyValues{}
\FV@@Command{SaveVerb}
[options]{name}|code|
\def\FV@@Command#1{%
\@ifnextchar[%
{\FV@GetKeyValues{\@nameuse{FVC@#1}}}%
{\@nameuse{FVC@#1}}}
% expand \FV@@Command, #1 = "SaveVerb"
% expand \@ifnextchar, true
Set \FV@KeyValues -> ""
\FV@GetKeyValues{\@nameuse{FVC@SaveVerb}}
[options]{name}|code|
\def\FV@GetKeyValues#1[#2]{%
\expandafter\def\expandafter\FV@KeyValues\expandafter{\FV@KeyValues,#2}#1}
% expand \FV@GetKeyValues, #1 = "\@nameuse{FVC@SaveVerb}", #2 = "options"
\def\FV@KeyValues{,options}
\@nameuse{FVC@SaveVerb}
{name}|code|
% expand \@nameuse
\def\FV@KeyValues{,options}
\FVC@SaveVerb
{name}|code|
\begingroup
\catcode`\^^M=\active%
\gdef\FVC@SaveVerb#1#2{%
\@namedef{FV@SV@#1}{}%
\begingroup%
\FV@UseKeyValues%
\FV@CatCodes%
\outer\def^^M{\FV@EOL}%
\global\let\@tempg\FancyVerbAfterSave%
\catcode`#2=12%
\def\@tempa{\def\FancyVerbGetVerb####1####2}%
\expandafter\@tempa\string#2{\endgroup\@namedef{FV@SV@#1}{##2}\@tempg}%
\FancyVerbGetVerb\FV@EOL}%
\endgroup
% expand \FVC@SaveVerb, #1 = "name", #2 = "|"
\@namedef{FV@SV@name}{}%
\begingroup%
\FV@UseKeyValues%
\FV@CatCodes%
\outer\def^^M{\FV@EOL}%
\global\let\@tempg\FancyVerbAfterSave%
\catcode`#2=12%
\def\@tempa{\def\FancyVerbGetVerb####1####2}%
\expandafter\@tempa\string#2{\endgroup\@namedef{FV@SV@#1}{##2}\@tempg}%
\FancyVerbGetVerb\FV@EOL
% by using \begingroup ... \global\let\@tempg\FancyVerbAfterSave ... \endgroup,
% every option passed by \FV@UseKeyValues, except "aftersave" is canceled
\UseVerb{name}
% expand \UseVerb
\FV@Command{}{UseVerb}
{name}
\def\FV@Command#1#2{%
\@ifstar
{\def\FV@KeyValues{#1,showspaces}\FV@@Command{#2}}%
{\def\FV@KeyValues{#1}\FV@@Command{#2}}}
% expand \FV@Command, #1 = "", #2 = "UseVerb"
% expand \@ifstar, false
\def\FV@KeyValues{}
\FV@@Command{UseVerb}
{name}
\def\FV@@Command#1{%
\@ifnextchar[%
{\FV@GetKeyValues{\@nameuse{FVC@#1}}}%
{\@nameuse{FVC@#1}}}
% expand \FV@@Command, #1 = "UseVerb"
% expand \@ifnextchar, false
\@nameuse{FVC@UseVerb}
{name}
\def\FVC@UseVerb#1{%
\@ifundefined{FV@SV@#1}%
{\FV@Error{Short verbatim text never saved to name `#1'}\FV@eha}%
{\FV@UseVerb{\@nameuse{FV@SV@#1}}}}
% expand \FVC@UseVerb, #1 = "name"
% expand \@ifundefined, false
\FV@UseVerb{\@nameuse{FV@SV@name}}
\def\FV@UseVerb#1{\mbox{\FV@UseKeyValues\FV@FormattingPrep#1}}
% expand \FV@UseVerb
\mbox{\FV@UseKeyValues\FV@FormattingPrep\@nameuse{FV@SV@name}}