How can I include source code in LaTeX documents?
A program called "lgrind" is available in the newtex locker to help you convert program listings to a form easily includable in a LaTeX document. To use this program, type the following at your athena% prompt:
athena% add newtex athena% lgrind -i -llanguage filename > filename.tex
This will generate a file (filename.tex) of code (-llanguage) formatted for inclusion in a LaTeX file (-latex). For example, to format a C program called mycode.c:
athena% lgrind -i -lc mycode.c > mycode.c.tex
at the bottom of it. You can also format languages other than C:
Ada MLisp (ml, Emacs Mock Lisp) Asm model Asm68 Modula2 (mod2, m2) BASIC Pascal (pas, p, bp) Batch (bat) PERL (pl) C PROLOG C++ (CC) PostScript (ps) csh RATFOR FORTRAN (f77, f) RLaB Gnuplot Russell Icon sh ISP src Java SQL LaTeX Tcl/Tk (tcl, tk) LDL VisualBasic (vbasic) Linda VMSasm MASM yacc (y) MATLAB SAS
To include the encoded file in your document:
- Include a line in your document preamble:
\usepackage{lgrind}
or, if you want the code to include function labels on the right hand side,
\usepackage[procnames,noindent]{lgrind}
- Place the lines
\begin{lgrind} \input mycode.tex \end{lgrind}
in your .tex file where you want to insert the formatted code.