Skip to content Accesskey=4Skip to sub-navigation Accesskey=3View our Accessibility Options MIT Information Systems Home About IS&T Contact IS&T Site Map Search Advanced Search
Getting StartedGetting Services by Topic or Alphabetically Getting Help

On This Page

[Help]

  

Quick Links

Top Level

Related Links

Ask OLC a question

Athena Consulting Homepage

Helpdesk Stock Answers (for Mac/PC questions)


How to include SOURCE CODE in 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:

o 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}

o Place the lines

   \begin{lgrind}
   \input mycode.tex
   \end{lgrind}

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

MIT Home | Getting Started | Getting Services | Getting Help | About IS&T | Accessibility
Ask a technology question or send a comment about this web page.