home *** CD-ROM | disk | FTP | other *** search
/ Dream 45 / Amiga_Dream_45.iso / Amiga / Magazine / Dossier-LaTeX / lgrind-amiga.lha / lgrind / lgrind.sty < prev    next >
Text File  |  1996-08-09  |  7KB  |  227 lines

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