Access Keys:
Skip to content (Access Key - 0)

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)

To include the encoded file in your document:

  1. Include a line in your document preamble:

    or, if you want the code to include function labels on the right hand side,

  2. Place the lines
       \input mycode.tex

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

IS&T Contributions

Documentation and information provided by IS&T staff members

Last Modified:

February 25, 2009

Get Help

Request help
from the Help Desk
Report a security incident
to the Security Team
olc-latex olc-latex Delete
latex latex Delete
source source Delete
code code Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
This product/service is:
Easy to use
Difficult to use

This article is:
Adaptavist Theme Builder (4.2.3) Powered by Atlassian Confluence 3.5.13, the Enterprise Wiki