-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.sty
executable file
·111 lines (81 loc) · 3.72 KB
/
code.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
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
% Latex Macros for Lisp code in text.
% Based on macros found in C. Rich's library.
% JAR hacks, 18 April 88:
% -- Put code in small font
% RWH: update for LaTeX2e: June, 1996
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{code}
\makeatletter
% \vobeyspaces turns all spaces into non-breakable spaces.
% Note: this is like \@vobeyspaces except without spurious space in defn.
{\catcode`\ =\active\gdef\vobeyspaces{\catcode`\ =\active\let =\@xobeysp}}
% \def\vobeytabs turns all tabs into 8 non-breakable spaces
{\catcode`\^^I=\active\gdef\vobeytabs{\catcode`\^^I=\active\let^^I=\xvobeytabs}}
\def\xvobeytabs{\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp}
% \vobeylines turns all cr's into non-breakable \par's
{\catcode`\^^M=\active\gdef\vobeylines{\catcode`\^^M=\active\let^^M=\xvobeylines}}
\def\xvobeylines{\par\penalty10000}
% \obeycrsp turns cr's into non-breakable spaces
{\catcode`\^^M=\active\gdef\obeycrsp{\catcode`\^^M=\active\let^^M=\@xobeysp}}
%% \@noligs prevents ?` and !` from being treated as ligatures
%% added 19 April 86 [copied from Latex sources]
\begingroup
\catcode``=13
\gdef\@noligs{\let`=\@lquote}
\endgroup
% Set up code environment, in which most of the common special characters
% appearing in code are treated verbatim, namely: _ # & ^ $ ~ @ " %
% *** JAR NEEDED $ AND _ IN SOME CODE ***
% Note: \ { } are still enabled so that macros can be called in this
% environment. Use \\, \{ and \} to use these characters verbatim
% in this environment.
% Note: this environment allows no breaking of lines whatsoever; not
% at spaces or hypens. To arrange for a break use the standard \- macro,
% or the \= macro which breaks, but inserts nothing. This is useful,
% for example for allowing hypenated identifiers to be broken, e.g.
% FOO-\=BAR.
\def\setupcode{\parsep=0pt\parindent=0pt%\small% +++JAR HACK (removed. Olin)
\upshape\sffamily\frenchspacing\catcode``=13\@noligs%
\def\\{\char`\\}%
\def\_{\char95\relax}%
\def\{{\char123\relax}%
\def\}{\char125\relax}%
%\@makeother\#
\@makeother\&%\@makeother\^%\@makeother\_%\@makeother\$% rem.Olin
\@makeother\`\@makeother\'%
\@makeother\~\@makeother\@\@makeother\"\@makeother\%\vobeytabs\vobeyspaces}
% Code environment as described above. Note that blank lines are
% not preserved, and lines are not kept on one page. Code is
% indented by the same amount as quotes.
% Note: to increase left margin, use \leftmargini=1in.
% was {\list{}{\parsep=0pt}\item[]\setupcode\obeylines}%
% then {\list{\parsep=0pt\listparindent=0pt\leftmargin=0pt}{}\item[]\setupcode%
\newenvironment{bigcode}%
{\list{}{\parsep=0pt\leftmargin=0pt\labelwidth=0pt\itemindent=0pt%
\listparindent=0pt}\item[]\setupcode%
\obeylines}%
{\endlist}
% Code is just like bigcode, but everything inside is kept on one page
% Note: This actually works by setting a huge penalty for breaking
% between lines of code.
% was {\list{}{\parsep=0pt}\item[]\setupcode\vobeylines}%
\newenvironment{code}%
{\list{}{\parsep=0pt\labelwidth=0pt\itemindent=0pt\leftmargin=0pt%
\listparindent=0pt}\item[]\setupcode\vobeylines}%
{\endlist}
\newenvironment{tightcode}%
{\list{}{\parskip=0pt\topsep=0pt\parsep=0pt\labelwidth=0pt\itemindent=0pt%
\leftmargin=0pt%
\listparindent=0pt}\item[]\setupcode\vobeylines}%
{\endlist}
% Reasonable separation between lines of code
\newcommand{\codeskip}{\penalty0\vspace{2ex}}
% \cd is used to build a code environment in the middle of text.
% Note: only difference from display code is that cr's are taken
% as unbreakable spaces instead of \par's.
\def\cd{\begingroup\setupcode\obeycrsp\startcode}
\newcommand{\textcd}[1]{\cd{#1}}
\newcommand{\mathcd}[1]{\hbox{\textcd{#1}}}
%\newcommand{\startcode}[1]{#1\endgroup}
\def\startcode#1{#1\endgroup}
\makeatother