-
Notifications
You must be signed in to change notification settings - Fork 0
/
shellout.sty
81 lines (66 loc) · 1.86 KB
/
shellout.sty
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
\makeatletter
%\usepackage{newverbs}
\newwrite\shellout@out
\def\shellout@writeout@start#1{%
\begingroup
\immediate\openout\shellout@out#1%
\let\do\@makeother\dospecials%
\catcode`\^^M\active%
\def\verbatim@processline{%
\immediate\write\shellout@out{\the\verbatim@line}}%
}%
\def\shellout@writeout@end{%
\immediate\closeout\shellout@out\endgroup%
}%
\newcounter{shellout@shell@id}
\counterwithin{shellout@shell@id}{subsubsection}
\def\shellout@setup#1{%
\stepcounter{shellout@shell@id}%
\gdef\shellout@shell@cmd{#1}%
\gdef\shellout@shell@infile{\theshelloutcacheprefix.\theshellout@shell@id.shellin.tmp}%
\gdef\shellout@shell@outfile{\theshelloutcacheprefix.\theshellout@shell@id.shellout.tex}%
}
\def\shellout@shell@start#1{%
\shellout@setup{#1}%
\shellout@writeout@start{\shellout@shell@infile}%
}%
\def\shellout@shell@perform{%
\ifx\shellout@cachemode 0%
\immediate\write18{\theshelloutbin'' \shellout@shell@infile'' \shellout@shell@outfile'' \shellout@shell@cmd''}%
\fi%
\immediate\input{\shellout@shell@outfile}%
}
\def\shellout@shell@end{%
\shellout@writeout@end%
\noindent\obeyspaces\shellout@shell@perform%
}
\def\shelloutone#1{%
\stepcounter{shellout@shell@id}%
\gdef\shellout@shell@cmd{#1}%
\gdef\shellout@shell@infile{/dev/null}%
\gdef\shellout@shell@outfile{\theshelloutcacheprefix.\theshellout@shell@id.shellout.tex}%
\shellout@shell@perform%
}
\def\shelloutcacheprefix#1{
\gdef\theshelloutcacheprefix{#1}
}
\gdef\theshelloutbin{shellout}
\def\shelloutbin#1{
\gdef\theshelloutbin{#1}
}
\shelloutcacheprefix{\jobname}
\def\shelloutcachemode{\let\shellout@cachemode1}%
\def\shelloutnocachemode{\let\shellout@cachemode0}%
\shelloutnocachemode%
\newenvironment{shellout}[1]{
\begingroup
\@bsphack%
\shellout@shell@start{#1}%
\verbatim
}{
\endverbatim%
\@esphack
\shellout@shell@end%
\endgroup
}
\makeatother