Access Keys:
Skip to content (Access Key - 0)
 
More about this article
Created: 11/07/2008 10:33
Modified: 02/25/2009 10:44

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:

  1. 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}
  2. Place the lines
       \begin{lgrind}
       \input mycode.tex
       \end{lgrind}
    

    in your .tex file where you want to insert the formatted code.

Your Rating: Results: PatheticBadOKGoodOutstanding! 0 rates

Adaptavist Theme Builder Powered by Atlassian Confluence