| 1 | %% |
|---|
| 2 | %% This is file `lgrind.sty', |
|---|
| 3 | %% generated with the docstrip utility. |
|---|
| 4 | %% |
|---|
| 5 | %% The original source files were: |
|---|
| 6 | %% |
|---|
| 7 | %% lgrind.dtx (with options: `package') |
|---|
| 8 | %% |
|---|
| 9 | %% LGrind is used to format source code of different programming |
|---|
| 10 | %% languages for LaTeX. |
|---|
| 11 | %% |
|---|
| 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. |
|---|
| 15 | %% |
|---|
| 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 |
|---|
| 26 | \newcount\lc@unt |
|---|
| 27 | \newcount\ln@xt |
|---|
| 28 | \newcount\LGnuminterval |
|---|
| 29 | \LGnuminterval=10 |
|---|
| 30 | \DeclareOption{nolineno}{\LGnuminterval=50000} |
|---|
| 31 | \DeclareOption{lineno5}{\LGnuminterval=5} |
|---|
| 32 | \DeclareOption{lineno1}{\LGnuminterval=1} |
|---|
| 33 | \newif\ifLGleftnum |
|---|
| 34 | \DeclareOption{leftno}{\LGleftnumtrue} |
|---|
| 35 | \newskip\LGindent |
|---|
| 36 | \LGindent=1.0\parindent |
|---|
| 37 | \DeclareOption{noindent}{\LGindent=0pt} |
|---|
| 38 | \newif\ifLGnorules |
|---|
| 39 | \DeclareOption{norules}{\LGnorulestrue} |
|---|
| 40 | \newlength{\LGsloppy} |
|---|
| 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}}} |
|---|
| 50 | \newbox\procbox |
|---|
| 51 | \newcommand{\Procname}{} |
|---|
| 52 | \newif\ifLGnoprocindex |
|---|
| 53 | \DeclareOption{noprocindex}{\LGnoprocindextrue} |
|---|
| 54 | \ProcessOptions |
|---|
| 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} |
|---|
| 70 | \def\LGsize{\small} |
|---|
| 71 | \def\LGfsize{\footnotesize} |
|---|
| 72 | \newif\ifLGinline |
|---|
| 73 | \newif\ifLGd@fault |
|---|
| 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 |
|---|
| 77 | \newif\ifc@mment |
|---|
| 78 | \newif\ifstr@ng |
|---|
| 79 | \newif\ifright@ |
|---|
| 80 | \newbox\ls@far |
|---|
| 81 | \newbox\tb@x |
|---|
| 82 | \newdimen\TBw@d |
|---|
| 83 | \newdimen\@ts |
|---|
| 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% |
|---|
| 98 | \ifLGnoprocindex% |
|---|
| 99 | \let\index\@gobble% |
|---|
| 100 | \fi% |
|---|
| 101 | \hfuzz=\LGsloppy |
|---|
| 102 | \def\NewPage{\filbreak\bigskip}% |
|---|
| 103 | \ifLGinline |
|---|
| 104 | \def\L##1{\setbox\ls@far\null{\CF\strut##1}\ignorespaces}% |
|---|
| 105 | \else |
|---|
| 106 | \let\r@ghtlno\relax\let\l@ftlno\relax |
|---|
| 107 | \ifnum\LGnuminterval>\z@ |
|---|
| 108 | \ifLGleftnum |
|---|
| 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}}% |
|---|
| 113 | \else |
|---|
| 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}% |
|---|
| 119 | \fi |
|---|
| 120 | \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% |
|---|
| 124 | \hfil\r@ghtlno}% |
|---|
| 125 | \ignorespaces}% |
|---|
| 126 | \fi |
|---|
| 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 |
|---|
| 155 | \def\<{\CH<<<}% dto. |
|---|
| 156 | \def\>{\CH>>>}% dto. |
|---|
| 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% |
|---|
| 168 | \bgroup\BGfont |
|---|
| 169 | } |
|---|
| 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}} |
|---|
| 174 | |
|---|
| 175 | \def\@lagrind{\@ifnextchar[{\@@lagrind}{\@@lagrind[t]}} |
|---|
| 176 | \def\@slagrind{\@ifnextchar[{\@@slagrind}{\@@slagrind[t]}} |
|---|
| 177 | \def\@@lagrind[#1]#2#3#4{% |
|---|
| 178 | \begin{figure}[#1] |
|---|
| 179 | \ifLGnorules\else\hrule\fi |
|---|
| 180 | \vskip .5\baselineskip |
|---|
| 181 | \begin{minipage}\columnwidth\LGsize\LGindent\z@ |
|---|
| 182 | \begin{lgrind} |
|---|
| 183 | \input #2\relax |
|---|
| 184 | \end{lgrind} |
|---|
| 185 | \end{minipage} |
|---|
| 186 | \vskip .5\baselineskip plus .5\baselineskip |
|---|
| 187 | \ifLGnorules\else\hrule\fi\vskip .5\baselineskip |
|---|
| 188 | \begingroup |
|---|
| 189 | \setbox\z@=\hbox{#4}% |
|---|
| 190 | \ifdim\wd\z@>\z@ |
|---|
| 191 | \caption{#3}% |
|---|
| 192 | \label{#4}% |
|---|
| 193 | \else |
|---|
| 194 | \captcont{#3}% |
|---|
| 195 | \fi |
|---|
| 196 | \endgroup |
|---|
| 197 | \vskip 2pt |
|---|
| 198 | \end{figure} |
|---|
| 199 | } |
|---|
| 200 | \def\@@slagrind[#1]#2#3#4{% |
|---|
| 201 | \begin{figure*}[#1] |
|---|
| 202 | \ifLGnorules\else\hrule\fi |
|---|
| 203 | \vskip .5\baselineskip |
|---|
| 204 | \begin{minipage}\linewidth\LGsize\LGindent\z@ |
|---|
| 205 | \begin{lgrind} |
|---|
| 206 | \input #2\relax |
|---|
| 207 | \end{lgrind} |
|---|
| 208 | \end{minipage} |
|---|
| 209 | \vskip .5\baselineskip plus .5\baselineskip |
|---|
| 210 | \ifLGnorules\else\hrule\fi\vskip .5\baselineskip |
|---|
| 211 | \begingroup |
|---|
| 212 | \setbox\z@=\hbox{#4}% |
|---|
| 213 | \ifdim\wd\z@>\z@ |
|---|
| 214 | \caption{#3}% |
|---|
| 215 | \label{#4}% |
|---|
| 216 | \else |
|---|
| 217 | \captcont{#3}% |
|---|
| 218 | \fi |
|---|
| 219 | \endgroup |
|---|
| 220 | \vskip 2pt |
|---|
| 221 | \end{figure*} |
|---|
| 222 | } |
|---|
| 223 | \def\lgrindfile#1{% |
|---|
| 224 | \par\addvspace{0.1in} |
|---|
| 225 | \ifLGnorules\else\hrule\fi |
|---|
| 226 | \vskip .5\baselineskip |
|---|
| 227 | \begingroup\LGfsize\LGindent\z@ |
|---|
| 228 | \begin{lgrind} |
|---|
| 229 | \input #1\relax |
|---|
| 230 | \end{lgrind} |
|---|
| 231 | \endgroup |
|---|
| 232 | \vskip .5\baselineskip |
|---|
| 233 | \ifLGnorules\else\hrule\fi |
|---|
| 234 | \addvspace{0.1in} |
|---|
| 235 | } |
|---|
| 236 | \endinput |
|---|
| 237 | %% |
|---|
| 238 | %% End of file `lgrind.sty'. |
|---|