annotate thesis/mitthesis/lgrind.sty @ 421:c2c28c3e27c4

get mit thesis template file.
author Robert McIntyre <rlm@mit.edu>
date Fri, 21 Mar 2014 00:08:49 -0400
parents
children
rev   line source
rlm@421 1 %%
rlm@421 2 %% This is file `lgrind.sty',
rlm@421 3 %% generated with the docstrip utility.
rlm@421 4 %%
rlm@421 5 %% The original source files were:
rlm@421 6 %%
rlm@421 7 %% lgrind.dtx (with options: `package')
rlm@421 8 %%
rlm@421 9 %% LGrind is used to format source code of different programming
rlm@421 10 %% languages for LaTeX.
rlm@421 11 %%
rlm@421 12 %% LGrind is a minor adaptation of Jerry Leichter's tgrind for LaTeX,
rlm@421 13 %% which was a notable improvement upon Van Jacobsen's tgrind for
rlm@421 14 %% plain TeX, which was adapted from vgrind, a troff prettyprinter.
rlm@421 15 %%
rlm@421 16 %% Based on Van Jacobson's ``tgrindmac'', a macro package for TeX.
rlm@421 17 %% Modified, 1987 by Jerry Leichter. Put '@' in all internal names.
rlm@421 18 %% Modified, 1991 by George Reilly. Changed name from tgrind to lgrind.
rlm@421 19 %% Modified, 1995 by Michael Piefel. Made it work with \LaTeXe.
rlm@421 20 \NeedsTeXFormat{LaTeX2e}[1995/06/01]
rlm@421 21 \ProvidesPackage{lgrind}
rlm@421 22 [1997/01/30 v3.4 LGrind environment and supporting stuff]
rlm@421 23 \newcount\lc@unt
rlm@421 24 \newcount\ln@xt
rlm@421 25 \newcount\LGnuminterval
rlm@421 26 \LGnuminterval=10
rlm@421 27 \DeclareOption{nolineno}{\LGnuminterval=50000}
rlm@421 28 \DeclareOption{lineno5}{\LGnuminterval=5}
rlm@421 29 \newif\ifLGleftnum
rlm@421 30 \DeclareOption{leftnum}{\LGleftnumtrue}
rlm@421 31 \newskip\LGindent
rlm@421 32 \LGindent=1.6667\parindent
rlm@421 33 \DeclareOption{noindent}{\LGindent=0pt}
rlm@421 34 \newif\ifLGnorules
rlm@421 35 \DeclareOption{norules}{\LGnorulestrue}
rlm@421 36 \newlength{\LGsloppy}
rlm@421 37 \setlength{\LGsloppy}{7.2pt}
rlm@421 38 \DeclareOption{fussy}{\LGsloppy=0pt}
rlm@421 39 \newcommand{\DefaultProc}{\@gobble}
rlm@421 40 \newcommand{\DefaultProcCont}{\@gobble}
rlm@421 41 \DeclareOption{procnames}{
rlm@421 42 \renewcommand{\DefaultProc}[1]{\renewcommand{\Procname}{#1}%
rlm@421 43 \global\setbox\procbox=\hbox{\PNsize #1}}
rlm@421 44 \renewcommand{\DefaultProcCont}[1]{\renewcommand\Procname{#1}
rlm@421 45 \global\setbox\procbox=\hbox{\PNsize\dots #1}}}
rlm@421 46 \newbox\procbox
rlm@421 47 \newcommand{\Procname}{}
rlm@421 48 \ProcessOptions
rlm@421 49 \def\BGfont{\sffamily}
rlm@421 50 \def\CMfont{\rmfamily\itshape}
rlm@421 51 \def\NOfont{\sffamily}
rlm@421 52 \def\KWfont{\rmfamily\bfseries}
rlm@421 53 \def\STfont{\ttfamily}
rlm@421 54 \def\VRfont{\rmfamily}
rlm@421 55 \def\PNsize{\BGfont\small}
rlm@421 56 \def\LGsize{\small}
rlm@421 57 \def\LGfsize{\footnotesize}
rlm@421 58 \newif\ifLGinline
rlm@421 59 \newif\ifLGd@fault
rlm@421 60 \def\LGbegin{\ifLGinline$\hbox\else$$\vbox\fi\bgroup\LGd@faulttrue}
rlm@421 61 \def\LGend{\ifLGd@fault\egroup\ifLGinline$\else$$\fi\LGd@faultfalse\fi}
rlm@421 62 \newif\ifc@mment
rlm@421 63 \newif\ifstr@ng
rlm@421 64 \newif\ifright@
rlm@421 65 \newbox\ls@far
rlm@421 66 \newbox\tb@x
rlm@421 67 \newdimen\TBw@d
rlm@421 68 \newdimen\@ts
rlm@421 69 {\catcode`\_=\active \gdef\@setunder{\let_=\sp@ce}}
rlm@421 70 \newcommand{\lgrindheader}{}
rlm@421 71 \newcommand{\lgrindfilename}{}\newcommand{\lgrindfilesize}{}
rlm@421 72 \newcommand{\lgrindmodyear}{}\newcommand{\lgrindmodmonth}{}
rlm@421 73 \newcommand{\lgrindmodday}{}\newcommand{\lgrindmodtime}{}
rlm@421 74 \newenvironment{lgrind}[1][1]{%
rlm@421 75 \def\Line##1{\L{\LB{##1}}}%
rlm@421 76 \newcommand{\Head}[1]{\gdef\lgrindhead{##1}}%
rlm@421 77 \newcommand{\File}[6]{\gdef\lgrindfilename{##1}\message{(LGround: ##1)}%
rlm@421 78 \gdef\lgrindmodyear{##2}\gdef\lgrindmodmonth{##3}%
rlm@421 79 \gdef\lgrindmodday{##4}\gdef\lgrindmodtime{##5}%
rlm@421 80 \gdef\lgrindfilesize{##6}}%
rlm@421 81 \let\Proc=\DefaultProc%
rlm@421 82 \let\ProcCont=\DefaultProcCont%
rlm@421 83 \hfuzz=\LGsloppy
rlm@421 84 \def\NewPage{\filbreak\bigskip}%
rlm@421 85 \ifLGinline
rlm@421 86 \def\L##1{\setbox\ls@far\null{\CF\strut##1}\ignorespaces}%
rlm@421 87 \else
rlm@421 88 \let\r@ghtlno\relax\let\l@ftlno\relax
rlm@421 89 \ifnum\LGnuminterval>\z@
rlm@421 90 \ifLGleftnum
rlm@421 91 \def\l@ftlno{\ifvoid\procbox\ifnum\lc@unt>\ln@xt
rlm@421 92 \global\advance\ln@xt by\LGnuminterval
rlm@421 93 \llap{{\normalfont\scriptsize\the\lc@unt\quad}}\fi
rlm@421 94 \else\llap{\box\procbox\quad}\fi}%
rlm@421 95 \else
rlm@421 96 \def\r@ghtlno{\ifvoid\procbox\ifnum\lc@unt>\ln@xt
rlm@421 97 \global\advance\ln@xt by\LGnuminterval
rlm@421 98 \rlap{{\normalfont\scriptsize\enspace\the\lc@unt}}\fi
rlm@421 99 \else\rlap{\enspace\box\procbox}\fi}%
rlm@421 100 \fi
rlm@421 101 \fi
rlm@421 102 \def\L##1{\@@par\setbox\ls@far=\null\strut
rlm@421 103 \global\advance\lc@unt by1%
rlm@421 104 \hbox to \hsize{\hskip\LGindent\l@ftlno ##1\egroup%
rlm@421 105 \hfil\r@ghtlno}%
rlm@421 106 \ignorespaces}%
rlm@421 107 \fi
rlm@421 108 \lc@unt=#1\advance\lc@unt by-1%
rlm@421 109 \ln@xt=\LGnuminterval\advance\ln@xt by-1%
rlm@421 110 \loop\ifnum\lc@unt>\ln@xt\advance\ln@xt by\LGnuminterval\repeat%
rlm@421 111 \def\LB{\hbox\bgroup\bgroup\box\ls@far\CF\let\next=}%
rlm@421 112 \def\Tab##1{\egroup\setbox\tb@x=\lastbox\TBw@d=\wd\tb@x%
rlm@421 113 \advance\TBw@d by 1\@ts\ifdim\TBw@d>##1\@ts
rlm@421 114 \setbox\ls@far=\hbox{\box\ls@far \box\tb@x \sp@ce}\else
rlm@421 115 \setbox\ls@far=\hbox to ##1\@ts{\box\ls@far \box\tb@x \hfil}\fi\LB}%
rlm@421 116 \ifLGinline\def\sp@ce{\hskip .3333em}%
rlm@421 117 \else \setbox\tb@x=\hbox{\texttt{0}}%
rlm@421 118 \@ts=0.8\wd\tb@x \def\sp@ce{\hskip 1\@ts}\fi
rlm@421 119 \catcode`\_=\active \@setunder
rlm@421 120 \def\CF{\ifc@mment\CMfont\else\ifstr@ng\STfont\fi\fi}
rlm@421 121 \def\N##1{{\NOfont ##1}\global\futurelet\next\ic@r}%
rlm@421 122 \def\K##1{{\KWfont ##1}\global\futurelet\next\ic@r}%
rlm@421 123 \def\V##1{{\VRfont ##1}\global\futurelet\next\ic@r}%
rlm@421 124 \def\ic@r{\let\@tempa\/\ifx.\next\let\@tempa\relax%
rlm@421 125 \else\ifx,\next\let\@tempa\relax\fi\fi\@tempa}%
rlm@421 126 \def\C{\egroup\bgroup\CMfont \global\c@mmenttrue \global\right@false}%
rlm@421 127 \def\CE{\egroup\bgroup \global\c@mmentfalse}%
rlm@421 128 \def\S{\egroup\bgroup\STfont \global\str@ngtrue}%
rlm@421 129 \def\SE{\egroup\bgroup \global\str@ngfalse}%
rlm@421 130 \def\,{\relax \ifmmode\mskip\thinmuskip \else\thinspace \fi}%
rlm@421 131 \def\!{\relax \ifmmode\mskip-\thinmuskip \else\negthinspace \fi}%
rlm@421 132 \def\CH##1##2##3{\relax\ifmmode ##1\relax
rlm@421 133 \else\ifstr@ng ##2\relax\else$##3$\fi\fi }%
rlm@421 134 \def\{{\CH\lbrace {\char'173}\lbrace }%
rlm@421 135 \def\}{\CH\rbrace {\char'175}\rbrace }%
rlm@421 136 \def\1{\CH///}% % /
rlm@421 137 \def\2{\CH\backslash {\char'134}\backslash }% % \
rlm@421 138 \def\|{\CH|{\char'174}|}%
rlm@421 139 \def\<{\CH<<<}%
rlm@421 140 \def\>{\CH>>>}%
rlm@421 141 \def\*{\CH***}\relax %\relax for DOCSTY
rlm@421 142 \def\-{\CH---}%
rlm@421 143 \def\_{\ifstr@ng {\char'137}\else
rlm@421 144 \leavevmode \kern.06em \vbox{\hrule width.35em}%
rlm@421 145 \ifdim\fontdimen\@ne\font=\z@ \kern.06em \fi\fi }%
rlm@421 146 \def\&{\textsf{\char'046}}%
rlm@421 147 \def\#{{\STfont\char'043}}%
rlm@421 148 \def\%{{\char'045}}%
rlm@421 149 \def\~{{\char'176}}%
rlm@421 150 \def\3{\ifc@mment\ifright@ ''\global\right@false%
rlm@421 151 \else``\global\right@true \fi
rlm@421 152 \else{\texttt{\char'042}}\fi}%
rlm@421 153 \def\4{\ifc@mment'\else {\texttt{\char'015}}\fi}%
rlm@421 154 \def\5{{\texttt{\char'136}}}%
rlm@421 155 \def\${{\ifmmode\slshape\else\ifdim\fontdimen\@ne\font>\z@\slshape\fi\fi
rlm@421 156 \char'044}}% %No $ in \it, use \sl
rlm@421 157 \parindent\z@\parskip\z@ plus 1pt\hsize\linewidth%
rlm@421 158 \bgroup\BGfont
rlm@421 159 }
rlm@421 160 {\egroup\@@par} % end of environment lgrind
rlm@421 161 \def\lgrinde{\ifLGinline\else\LGsize\fi\begin{lgrind}}
rlm@421 162 \def\endlgrinde{\end{lgrind}}
rlm@421 163 \def\lagrind{\@ifstar{\@slagrind}{\@lagrind}}
rlm@421 164
rlm@421 165 \def\@lagrind{\@ifnextchar[{\@@lagrind}{\@@lagrind[t]}}
rlm@421 166 \def\@slagrind{\@ifnextchar[{\@@slagrind}{\@@slagrind[t]}}
rlm@421 167 \def\@@lagrind[#1]#2#3#4{%
rlm@421 168 \begin{figure}[#1]
rlm@421 169 \ifLGnorules\else\hrule\fi
rlm@421 170 \vskip .5\baselineskip
rlm@421 171 \begin{minipage}\columnwidth\LGsize\LGindent\z@
rlm@421 172 \begin{lgrind}
rlm@421 173 \input #2\relax
rlm@421 174 \end{lgrind}
rlm@421 175 \end{minipage}
rlm@421 176 \vskip .5\baselineskip plus .5\baselineskip
rlm@421 177 \ifLGnorules\else\hrule\fi\vskip .5\baselineskip
rlm@421 178 \begingroup
rlm@421 179 \setbox\z@=\hbox{#4}%
rlm@421 180 \ifdim\wd\z@>\z@
rlm@421 181 \caption{#3}%
rlm@421 182 \label{#4}%
rlm@421 183 \else
rlm@421 184 \captcont{#3}%
rlm@421 185 \fi
rlm@421 186 \endgroup
rlm@421 187 \vskip 2pt
rlm@421 188 \end{figure}
rlm@421 189 }
rlm@421 190 \def\@@slagrind[#1]#2#3#4{%
rlm@421 191 \begin{figure*}[#1]
rlm@421 192 \ifLGnorules\else\hrule\fi
rlm@421 193 \vskip .5\baselineskip
rlm@421 194 \begin{minipage}\linewidth\LGsize\LGindent\z@
rlm@421 195 \begin{lgrind}
rlm@421 196 \input #2\relax
rlm@421 197 \end{lgrind}
rlm@421 198 \end{minipage}
rlm@421 199 \vskip .5\baselineskip plus .5\baselineskip
rlm@421 200 \ifLGnorules\else\hrule\fi\vskip .5\baselineskip
rlm@421 201 \begingroup
rlm@421 202 \setbox\z@=\hbox{#4}%
rlm@421 203 \ifdim\wd\z@>\z@
rlm@421 204 \caption{#3}%
rlm@421 205 \label{#4}%
rlm@421 206 \else
rlm@421 207 \captcont{#3}%
rlm@421 208 \fi
rlm@421 209 \endgroup
rlm@421 210 \vskip 2pt
rlm@421 211 \end{figure*}
rlm@421 212 }
rlm@421 213 \def\lgrindfile#1{%
rlm@421 214 \par\addvspace{0.1in}
rlm@421 215 \ifLGnorules\else\hrule\fi
rlm@421 216 \vskip .5\baselineskip
rlm@421 217 \begingroup\LGfsize\LGindent\z@
rlm@421 218 \begin{lgrind}
rlm@421 219 \input #1\relax
rlm@421 220 \end{lgrind}
rlm@421 221 \endgroup
rlm@421 222 \vskip .5\baselineskip
rlm@421 223 \ifLGnorules\else\hrule\fi
rlm@421 224 \addvspace{0.1in}
rlm@421 225 }
rlm@421 226 \endinput
rlm@421 227 %%
rlm@421 228 %% End of file `lgrind.sty'.