-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfccode.sty
More file actions
293 lines (249 loc) · 8.32 KB
/
fccode.sty
File metadata and controls
293 lines (249 loc) · 8.32 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
%%
%% This is file `fccode.sty'
%%
%% It includes most macros used for formatting code in the Fast Code
%% book.
\def\fileversion{1.0}
\def\filedate{2014/09/08}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{fccode}[\filedate{} Code-formatting macros for Fast Code book.]
\usepackage{codehilite}
\usepackage{fancyvrb}
\usepackage{calc}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Verbatim environment setup
% HACK: Macro for manually resetting line numbers in Verbatim environments
\def\resetLineNumbers{\setcounter{FancyVerbLine}{0}}
% HACK: Add left line numbers to BVerbatim environments.
% (Proper fix involves changing fancyvrb.)
\def\FV@BProcessLine#1{\hbox{\kern\leftmargin\hbox{\FV@LeftListNumber\FancyVerbFormatLine{#1}}}}
% Formatting the line numbers
\renewcommand{\theFancyVerbLine}{{\rm\tiny\ifnum\value{FancyVerbLine}<10 0\fi\arabic{FancyVerbLine}}}
\DefineVerbatimEnvironment%
{CodeFigVerbatim}{BVerbatim}
{%
baseline=t,%
%fontsize=\fontsize{8.5}{10.2},%
fontsize=\fontsize{7.5}{9},%
%fontsize=\scriptsize,%
numbers=left,%
firstnumber=last,%
stepnumber=1,%
numbersep=\cb@codefig@numbersep,%
baselinestretch=1,%
% bgcolor=codebgcolor,%
}
\DefineVerbatimEnvironment%
{InParCodeVerbatim}{Verbatim}
{%
baseline=t,%
%fontsize=\fontsize{8.5}{10.2},%
fontsize=\scriptsize,%
baselinestretch=1,%
}
\DefineInParCodeEnvironment%
{InParCodeVerbatim}
{%
baseline=t,%
%fontsize=\fontsize{8.5}{10.2},%
fontsize=\scriptsize,%
baselinestretch=1,%
}
% Set default parameters for codehilite
\codehiliteset{%
verbenvironment=InParCodeVerbatim,
inparcodeenvironment=InParCodeVerbatim,
%texcl,
reindent,
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Colors
\definecolor{terminalcolor}{HTML}{632618}
\colorlet{codebgcolor}{Cornsilk1!50!white}
\colorlet{codeheadcolor}{gray}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Spacing for inline code
%% Adjust spacing of inline code to match text spacing
% \newdimen\envwspc%
% \newdimen\envwstrt%
% \newdimen\envwshrk%
% \newdimen\ttwspc%
% \newdimen\ttwstrt%
% \newdimen\ttwshrk%
\let\oldeveryterminal\everyterminal
\def\everyterminal#1{%
% \envwspc=\the\fontdimen2\font%
% \envwstrt=\the\fontdimen3\font%
% \envwshrk=\the\fontdimen4\font%
\mbox{%
\oldeveryterminal{%
\color{terminalcolor}%
% \ifdim \f@size pt=\@default@fontsize pt \small \fi%
{%
% % Save terminal spacing parameters
% \ttwspc=\the\fontdimen2\font%
% \ttwstrt=\the\fontdimen3\font%
% \ttwshrk=\the\fontdimen4\font%
% % Set spacing
% \fontdimen2\font=\envwspc%
% \fontdimen3\font=\envwstrt%
% \fontdimen4\font=\envwshrk%
#1%
% \fontdimen2\font=\ttwspc%
% \fontdimen3\font=\ttwstrt%
% \fontdimen4\font=\ttwshrk%
}%
}%
}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Code pages and frames
% Spacing parameters
\newlength{\cb@codefig@numbersep}
\setlength{\cb@codefig@numbersep}{6pt}
\newlength{\cb@codefig@linenumlen}
\setlength{\cb@codefig@linenumlen}{\cb@codefig@numbersep + 6pt}
\newlength{\cb@codefig@figframerule}
\setlength{\cb@codefig@figframerule}{0.5pt}
\newcommand\codefigframe[1]{%
\fboxrule=\cb@codefig@figframerule\fcolorbox{codeheadcolor}{codebgcolor}{#1}}
\newlength{\cb@codefig@indent}
\setlength{\cb@codefig@indent}{\cb@codefig@linenumlen + 2pt}
\newlength{\cb@codefig@width}
\newlength{\belowcodepagesep}
\setlength{\belowcodepagesep}{-2pt}
\def\codepagetop{%
\arrayrulecolor{codeheadcolor}\specialrule{\cb@codefig@figframerule}{0pt}{\belowcodepagesep}}
\newlength{\@codepage@width}
\newlength{\@codepage@contents@width}
\newcommand{\codepage}[2]{%
\setlength{\@codepage@width}{#1}%
\setlength{\@codepage@contents@width}{\@codepage@width}%
\addtolength{\@codepage@width}{\cb@codefig@indent - 2\cb@codefig@figframerule}%
\addtolength{\@codepage@contents@width}{-1pt - 2\cb@codefig@figframerule}%
{\fboxsep=0pt\codefigframe{%
% \begin{minipage}[t]{#1 + \cb@codefig@indent}%
\begin{tabular*}{\@codepage@width}[t]{@{}l@{}}%
% \codepagetop%
% \@codepage@head{#1}{#2}\\%
% \addlinespace[2\defaultaddspace]%
\begin{minipage}[t]{\@codepage@contents@width}%
\hspace*{\cb@codefig@indent}%
%\vspace{-4pt}
\input{#2}%
\end{minipage}\\ %\vspace{3pt}\\%
\addlinespace[\defaultaddspace]%
\end{tabular*}%
% \end{minipage}%
}}%
}
\newcommand{\codefig}[2][\linewidth]{
%\resetLineNumbers
\setlength{\cb@codefig@width}{#1 - \cb@codefig@indent - 2\cb@codefig@figframerule}
\codepage{\cb@codefig@width}{#2-pyg}%
}
\newcommand{\vrbfig}[2][\linewidth]{
%\resetLineNumbers
\setlength{\cb@codefig@width}{#1 - \cb@codefig@indent - 2\cb@codefig@figframerule}
\codepage{\cb@codefig@width}{#2}%
}
\newcommand{\ccodefig}[2][\linewidth] {\codefig[#1]{#2.c}}
\newcommand{\cppcodefig}[2][\linewidth] {\codefig[#1]{#2.cpp}}
\newcommand{\javacodefig}[2][\linewidth]{\codefig[#1]{#2.java}}
\newcommand{\pycodefig}[2][\linewidth] {\codefig[#1]{#2.py}}
\newcommand{\llcodefig}[2][\linewidth] {\codefig[#1]{#2.ll}}
\newcommand{\consolecodefig}[2][\linewidth]{\codefig[#1]{#2.sh-session}}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% In-paragraph-code environments
% Environments for commonly used codehilite instances. Each takes the
% same optional arguments that codehilite accepts.
\newsavebox{\cb@inparcode}
\newlength{\cb@inparcode@width}
\newenvironment{inparcode}%
{\setlength{\cb@inparcode@width}{\linewidth - 2\cb@codefig@figframerule - 6pt}%
\begin{trivlist}%
% \setlength{\topsep}{-6pt}%
% \setlength{\parskip}{-16pt}%
% \setlength{\partopsep}{-6pt}%
\begin{lrbox}{\cb@inparcode}%
\begin{minipage}[t]{\cb@inparcode@width}}
{\end{minipage}%
\end{lrbox}%
\item{\fboxsep=3pt\codefigframe{%
% \begin{tabular}[t]{@{}l@{}}%
% \ipcodehead%
% \@codepage@head{#1}{#2}\\%
% \begin{minipage}[t]{\cb@inparcode@width}%
% \vspace{-6pt}\hspace{3pt}
\usebox{\cb@inparcode}%
% \end{minipage}%\vspace{3pt}%
% \end{tabular}%
}}%
\end{trivlist}%
\vspace{-0.75ex}%
}
% An environment for in-paragraph console code.
\newcodehiliteOut[chconsole]{console}{}
\newenvironment{console}
{\VerbatimEnvironment%
\begin{inparcode}%
\begin{chconsole}}
{\end{chconsole}%
\end{inparcode}}
% % An environment for in-paragraph bash code.
% \newcodehiliteOut[chbash]{bash}{}
% \newenvironment{bash}
% {\VerbatimEnvironment%
% \begin{inparcode}%
% \begin{chbash}}
% {\end{chbash}%
% \end{inparcode}}
% An environment for in-paragraph cilk code.
\newcodehiliteOut[chcilk]{cilk}{}
\newenvironment{cilk}
{\VerbatimEnvironment%
\begin{inparcode}%
\begin{chcilk}}
{\end{chcilk}%
\end{inparcode}}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Inline-code environments
% % Shorter macro to use default behavior of \codevrb||
% \newcommand\term[1]{\codevrb#1}
% % Verb-like command for inserting inlined syntax-colored code as
% % assembly.
% %
% % Arguments:
% % #1 - verbatim string
% %
% % If the verbatim string you're coloring is a complete line of
% % assembly, this command should correctly color it. If the verbatim
% % string is a portion of a line of assembly, however, then the GAS
% % lexer will not parse it correctly. In that case, use one of the
% % special macros
% \newcommand\asmvrb[1]{\codevrb[gascb]#1}
% % Verb-like command for inserting inlined syntax-colored code as
% % a bash console command.
% %
% % Arguments:
% % #1 - verbatim string
% %
% % If the verbatim string you're coloring is either a complete shell
% % command with the preceding "$" or ">" or the output from such a
% % shell command, this macro will color it correctly. If the verbatim
% % string is not one these but instead, for example, simply a command
% % name, argument, or flag, then this command will not color it
% % correctly.
% \newcommand\shvrb[1]{\codevrb[console]#1}
% % Verb-like command for inserting inlined syntax-colored code as
% % cilk.
% %
% % Arguments:
% % #1 - verbatim string
% \newcommand\cvrb[1]{\codevrb[cilk]#1}
% % Shortened form of \asmvrb command
% \newcommand\asm[1]{\asmvrb#1}
% % Shortened form of \shvrb command
% \newcommand\sh[1]{\shvrb#1}
% % Shortened form of \cvrb command
% \newcommand\cc[1]{\cvrb#1}