2 %% This is file `lgrind.sty',
3 %% generated with the docstrip utility.
5 %% The original source files were:
7 %% lgrind.dtx (with options: `package')
9 %% LGrind is used to format source code of different programming
10 %% languages for LaTeX.
12 %% LGrind is a major adaptation of Jerry Leichter's tgrind for LaTeX,
13 %% which was a notable improvement upon Van Jacobsen's tgrind for
14 %% plain TeX, which was adapted from vgrind, a troff prettyprinter.
16 %% Author: Michael Piefel, piefel@cs.tu-berlin.de
17 %% Based on Van Jacobson's ``tgrindmac'', a macro package for TeX.
18 %% Modified, 1987 by Jerry Leichter. Put '@' in all internal names.
19 %% Modified, 1991 by George Reilly. Changed name from tgrind to lgrind.
20 %% Modified, 1995 by Michael Piefel. Made it work with \LaTeXe.
21 %% -1999 Hundreds of bells and whistles. No changelog here.
22 \NeedsTeXFormat{LaTeX2e}[1996/06/01]
23 \ProvidesPackage{lgrind}
24 [1999/05/28 v3.6 LGrind environment and supporting stuff]
25 %%stopzone % VIM syncing
28 \newcount\LGnuminterval
30 \DeclareOption{nolineno}{\LGnuminterval=50000}
31 \DeclareOption{lineno5}{\LGnuminterval=5}
32 \DeclareOption{lineno1}{\LGnuminterval=1}
34 \DeclareOption{leftno}{\LGleftnumtrue}
36 \LGindent=1.0\parindent
37 \DeclareOption{noindent}{\LGindent=0pt}
39 \DeclareOption{norules}{\LGnorulestrue}
41 \setlength{\LGsloppy}{7.2pt}
42 \DeclareOption{fussy}{\LGsloppy=0pt}
43 \newcommand{\DefaultProc}{\@gobble}
44 \newcommand{\DefaultProcCont}{\@gobble}
45 \DeclareOption{procnames}{
46 \renewcommand{\DefaultProc}[1]{\renewcommand{\Procname}{#1}%
47 \global\setbox\procbox=\hbox{\PNsize #1}}
48 \renewcommand{\DefaultProcCont}[1]{\renewcommand\Procname{#1}
49 \global\setbox\procbox=\hbox{\PNsize\dots #1}}}
51 \newcommand{\Procname}{}
52 \newif\ifLGnoprocindex
53 \DeclareOption{noprocindex}{\LGnoprocindextrue}
55 %\def\BGfont{\sffamily}
56 \def\BGfont{\ttfamily\bfseries}
57 \def\CMfont{\rmfamily\itshape}
58 \def\NOfont{\sffamily}
59 %\def\NOfont{\ttfamily}
60 %\def\KWfont{\rmfamily\bfseries}
61 \def\KWfont{\rmfamily\itshape\bfseries}
62 %\def\KWfont{\ttfamily}
63 %\def\STfont{\ttfamily}
64 \def\STfont{\rmfamily\itshape\bfseries}
65 %\def\TTfont{\ttfamily\upshape}
66 \def\TTfont{\rmfamily\itshape\bfseries}
67 %\def\VRfont{\ttfamily}
68 \def\VRfont{\rmfamily\itshape\bfseries}
69 \def\PNsize{\BGfont\small}
71 \def\LGfsize{\footnotesize}
74 \def\LGbegin{\ifLGinline$\hbox\else$$\vbox\fi\bgroup\LGd@faulttrue}
75 \def\LGend{\ifLGd@fault\egroup\ifLGinline$\else$$\fi\LGd@faultfalse\fi}
76 %%stopzone % VIM syncing
84 {\catcode`\_=\active \gdef\@setunder{\let_=\sp@ce}}
85 \newcommand{\lgrindhead}{}
86 \newcommand{\lgrindfilename}{}\newcommand{\lgrindfilesize}{}
87 \newcommand{\lgrindmodyear}{}\newcommand{\lgrindmodmonth}{}
88 \newcommand{\lgrindmodday}{}\newcommand{\lgrindmodtime}{}
89 \newenvironment{lgrind}[1][1]{%
90 \def\Line##1{\L{\LB{##1}}}%
91 \newcommand{\Head}[1]{\gdef\lgrindhead{##1}}%
92 \newcommand{\File}[6]{\gdef\lgrindfilename{##1}\message{(LGround: ##1)}%
93 \gdef\lgrindmodyear{##2}\gdef\lgrindmodmonth{##3}%
94 \gdef\lgrindmodday{##4}\gdef\lgrindmodtime{##5}%
95 \gdef\lgrindfilesize{##6}}%
96 \let\Proc=\DefaultProc%
97 \let\ProcCont=\DefaultProcCont%
102 \def\NewPage{\filbreak\bigskip}%
104 \def\L##1{\setbox\ls@far\null{\CF\strut##1}\ignorespaces}%
106 \let\r@ghtlno\relax\let\l@ftlno\relax
107 \ifnum\LGnuminterval>\z@
109 \def\l@ftlno{\ifnum\lc@unt>\ln@xt
110 \global\advance\ln@xt by\LGnuminterval
111 \llap{{\normalfont\scriptsize\the\lc@unt\quad}}\fi}
112 \def\r@ghtlno{\rlap{\enspace\box\procbox}}%
114 \def\r@ghtlno{\ifnum\lc@unt>\ln@xt
115 \global\advance\ln@xt by\LGnuminterval
116 \rlap{{\normalfont\scriptsize\enspace\the\lc@unt%
117 \enspace\box\procbox}}
118 \else\rlap{\enspace\box\procbox}\fi}%
121 \def\L##1{\@@par\setbox\ls@far=\null\strut
122 \global\advance\lc@unt by1%
123 \hbox to \linewidth{\hskip\LGindent\l@ftlno ##1\egroup%
127 \lc@unt=#1\advance\lc@unt by-1%
128 \ln@xt=\LGnuminterval\advance\ln@xt by-1%
129 \loop\ifnum\lc@unt>\ln@xt\advance\ln@xt by\LGnuminterval\repeat%
130 \def\LB{\hbox\bgroup\bgroup\box\ls@far\CF\let\next=}%
131 \def\Tab##1{\egroup\setbox\tb@x=\lastbox\TBw@d=\wd\tb@x%
132 \advance\TBw@d by 1\@ts\ifdim\TBw@d>##1\@ts
133 \setbox\ls@far=\hbox{\box\ls@far \box\tb@x \sp@ce}\else
134 \setbox\ls@far=\hbox to ##1\@ts{\box\ls@far \box\tb@x \hfil}\fi\LB}%
135 \ifLGinline\def\sp@ce{{\hskip .3333em}}%
136 \else \setbox\tb@x=\hbox{\texttt{0}}%
137 \@ts=0.8\wd\tb@x \def\sp@ce{{\hskip 1\@ts}}\fi
138 \catcode`\_=\active \@setunder
139 \def\CF{\ifc@mment\CMfont\else\ifstr@ng\STfont\fi\fi}
140 \def\N##1{{\NOfont ##1}\global\futurelet\next\ic@r}%
141 \def\K##1{{\KWfont ##1}\global\futurelet\next\ic@r}%
142 \def\V##1{{\VRfont ##1}\global\futurelet\next\ic@r}%
143 \def\ic@r{\let\@tempa\/\ifx.\next\let\@tempa\relax%
144 \else\ifx,\next\let\@tempa\relax\fi\fi\@tempa}%
145 \def\C{\egroup\bgroup\CMfont \global\c@mmenttrue \global\right@false}%
146 \def\CE{\egroup\bgroup \global\c@mmentfalse}%
147 \def\S{\egroup\bgroup\STfont \global\str@ngtrue}%
148 \def\SE{\egroup\bgroup \global\str@ngfalse}%
149 \def\,{\relax \ifmmode\mskip\thinmuskip \else\thinspace \fi}%
150 \def\!{\relax \ifmmode\mskip-\thinmuskip \else\negthinspace \fi}%
151 %%stopzone % VIM syncing
152 \def\CH##1##2##3{\relax\ifmmode ##1\relax
153 \else\ifstr@ng ##2\relax\else$##3$\fi\fi }%
154 \def\|{\CH|||}% not necessary for T1
157 \def\-{\CH---}% minus sign nicer than hyphen
158 \def\_{\ifstr@ng {\char'137}\else
159 \leavevmode \kern.06em \vbox{\hrule width.35em}%
160 \ifdim\fontdimen\@ne\font=\z@ \kern.06em \fi\fi }%
161 \def\#{{\STfont\char'043}}%
162 \def\2{\CH\backslash {\char'134}\backslash }% % \
163 \def\3{\ifc@mment\ifright@ ''\global\right@false%
164 \else``\global\right@true \fi
165 \else{\texttt{\char'042}}\fi}% % "
166 \def\5{{\texttt{\char'136}}}% % ^
167 \parindent\z@\parskip\z@ plus 1pt%
170 {\egroup\@@par} % end of environment lgrind
171 \def\lgrinde{\ifLGinline\else\LGsize\fi\begin{lgrind}}
172 \def\endlgrinde{\end{lgrind}}
173 \def\lagrind{\@ifstar{\@slagrind}{\@lagrind}}
175 \def\@lagrind{\@ifnextchar[{\@@lagrind}{\@@lagrind[t]}}
176 \def\@slagrind{\@ifnextchar[{\@@slagrind}{\@@slagrind[t]}}
177 \def\@@lagrind[#1]#2#3#4{%
179 \ifLGnorules\else\hrule\fi
180 \vskip .5\baselineskip
181 \begin{minipage}\columnwidth\LGsize\LGindent\z@
186 \vskip .5\baselineskip plus .5\baselineskip
187 \ifLGnorules\else\hrule\fi\vskip .5\baselineskip
189 \setbox\z@=\hbox{#4}%
200 \def\@@slagrind[#1]#2#3#4{%
202 \ifLGnorules\else\hrule\fi
203 \vskip .5\baselineskip
204 \begin{minipage}\linewidth\LGsize\LGindent\z@
209 \vskip .5\baselineskip plus .5\baselineskip
210 \ifLGnorules\else\hrule\fi\vskip .5\baselineskip
212 \setbox\z@=\hbox{#4}%
224 \par\addvspace{0.1in}
225 \ifLGnorules\else\hrule\fi
226 \vskip .5\baselineskip
227 \begingroup\LGfsize\LGindent\z@
232 \vskip .5\baselineskip
233 \ifLGnorules\else\hrule\fi
238 %% End of file `lgrind.sty'.