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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
% verbments.sty v1.2 2011/08/20
%
% Copyright (C) 2011 by Dejan Zivkovic
% -----------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.2 or later is part of all distributions of LaTeX
% version 1999/12/01 or later.
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{verbments}[2011/08/20 v1.2 Pygments/fancyvrb source code highlighting for LaTeX]
\RequirePackage{xkeyval,fancyvrb,framed,xcolor,calc}
%
\newcommand{\@listofpyglistingsname}{Listings}%
\newcommand{\listofpyglistingsname}[1]{%
\renewcommand\@listofpyglistingsname{#1}
}
\newcommand{\listofpyglistings}{%
\begingroup
\let\contentsname\@listofpyglistingsname
\let\@pygtoc\@starttoc \def\@starttoc##1{\@pygtoc{pyg.lol}}%
\tableofcontents%
\endgroup
}
\newcommand{\lol@caption}[1]{%
\addcontentsline{pyg.lol}{pyglist}{#1}
}
\newcommand{\l@pyglist}[2]{%
\@dottedtocline{1}{1.5em}{2.3em}{#1}{#2}
}
%
\newlength{\@tmpwidth}
%
\newskip\@tmpvskip
\def\max@vskip #1{%
\@tmpvskip = #1\relax
\ifdim\lastskip < \@tmpvskip
\ifdim\lastskip = 0pt
\else \vskip -\lastskip
\fi
\vskip \@tmpvskip
\fi%
}
\setlength{\FrameSep}{0pt}
\setlength{\FrameRule}{0pt}
%
\define@cmdkey{pyglist}[pl@]{caption}{}
\define@cmdkey{pyglist}[pl@]{captionfont}[{}]{}
\define@cmdkey{pyglist}[pl@]{abovecaptionskip}[\bigskipamount]{}
\define@cmdkey{pyglist}[pl@]{belowcaptionskip}[0pt]{}
\define@cmdkey{pyglist}[pl@]{listingname}[Listing]{}
\define@cmdkey{pyglist}[pl@]{listingnamefont}[{}]{}
\define@cmdkey{pyglist}[pl@]{captionbgcolor}{}
\define@cmdkey{pyglist}[pl@]{label}{}
%
\define@cmdkey{pyglist}[pl@]{bgcolor}[white]{}
\define@cmdkey{pyglist}[pl@]{language}[text]{}
\define@cmdkey{pyglist}[pl@]{encoding}[latin1]{}
\define@boolkey{pyglist}[pl@]{mathescape}[false]{}
\define@boolkey{pyglist}[pl@]{texcl}[false]{}
\define@cmdkey{pyglist}[pl@]{style}[default]{}
\define@cmdkey{pyglist}[pl@]{gobble}[0]{}
%
\define@cmdkey{pyglist}[pl@]{fvset}{\fvset{#1}}
\define@cmdkey{pyglist}[pl@]{fontsize}{\fvset{fontsize=#1}}
\define@cmdkey{pyglist}[pl@]{numbers}{\fvset{numbers=#1}}
\define@cmdkey{pyglist}[pl@]{numbersep}{\fvset{numbersep=#1}}
\define@boolkey{pyglist}[pl@]{showspaces}{\fvset{showspaces=#1}}
\newcommand\plset[1]{%
\setkeys{pyglist}{#1}%
}
\newenvironment{pyglist}{%
\catcode`\^^M=\active
\@ifnextchar[%
{\catcode`\^^M=5 \pyglist@}
{\catcode`\^^M=5 \pyglist@[]}
}{%
\end{VerbatimOut}%
\immediate\write18{\pyg@cmd}
\immediate\write18{\pyg@style}
\input{\jobname.pyg.sty}%
%
\partopsep = 0pt\parskip = 0pt\parindent = 0pt%
\@ifundefined{pl@caption}%
{\setlength{\topsep}{0pt}}%
{\par%
\max@vskip{\pl@abovecaptionskip}%
\penalty -100% encourage page break
\refstepcounter{pllisting}%
\@ifundefined{pl@label}{}{\label{\pl@label}}%
\@tmpvskip=3\baselineskip%
\vskip \@tmpvskip\penalty 1000\vskip -\@tmpvskip\vskip \z@skip% prevent page break
\settowidth{\@tmpwidth}{\pl@listingnamefont\pl@listingname~\thepllisting:\space}%
\@ifundefined{pl@captionbgcolor}%
{\mbox{\pl@listingnamefont\pl@listingname~\thepllisting:\space}%
\parbox[t]{\linewidth-\@tmpwidth}%
{\leavevmode\pl@captionfont\pl@caption}%
}
{\setlength{\fboxrule}{0pt}\setlength{\fboxsep}{4pt}%
\colorbox{\pl@captionbgcolor}{%
\mbox{\pl@listingnamefont\pl@listingname~\thepllisting:\space}%
\parbox[t]{\linewidth-\@tmpwidth-2\fboxsep}%
{\leavevmode\pl@captionfont\pl@caption}%
}%
}%
\par\nobreak\vskip\pl@belowcaptionskip%
\setlength{\topsep}{\smallskipamount}%
\lol@caption{\rlap{\thepllisting}\hskip5ex \pl@caption}
}%
%
\definecolor{shadecolor}{named}{\pl@bgcolor}%
\begin{snugshade}
\input{\jobname.pyg.vrb}
\end{snugshade}
}
\def\pyglist@[#1]{%
\setkeys{pyglist}{#1}
\edef\pyg@cmd{pygmentize -P encoding=\pl@encoding\space -l \pl@language\space
-F tokenmerge \ifnum\pl@gobble=0\space \else -F gobble:n=\pl@gobble\space\fi
-f latex
\ifpl@texcl -P texcomments\space\fi
\ifpl@mathescape -P mathescape\space\fi
-o \jobname.pyg.vrb \jobname.pyg.lst}
\edef\pyg@style{pygmentize -S \pl@style\space -f latex > \jobname.pyg.sty}
\VerbatimEnvironment
\begin{VerbatimOut}{\jobname.pyg.lst}% NO char whatsoever to the next brace
}
\AtBeginDocument{
\@ifundefined{thechapter}{
\newcounter{pllisting}
\gdef\thepllisting{\@arabic\c@pllisting}
}{
\newcounter{pllisting}[chapter]
\gdef\thepllisting%
{\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@pllisting}
}
}
% Set default key values
\plset{captionfont,abovecaptionskip,belowcaptionskip,listingname,listingnamefont,%
bgcolor,language,encoding,mathescape,texcl,style,gobble%
}
\endinput
|