views:

125

answers:

4

Dear Stackoverflow,

I have a whole project in Java and I need to make a code listing in part of my documentation with all my classes and code. I was wondering, what is the best way to export the code? Is it simply just copy and paste, or is there a way to export the code properly to keep all the formatting etc?

Basically I need to put the code into LaTeX, which I'm using to write my report, and before you ask yes i have to do this its not my choice!

Hope you understand what I mean

Thanks

A: 

It's easy enough to do:

for d in `find <projectdir> -name '*.java'; do
    echo "$d" >> output.txt
    cat "$d" >> output.txt
done

...but what possible purpose could dumping all the code into a document serve?

Tomislav Nakic-Alfirevic
+1  A: 

If LaTeX is the target, I'd search for some formatting templates for code. It's easy enough to get text into LaTeX, but the formatting will be a different matter.

duffymo
+1  A: 

I found a way: http://texblog.wordpress.com/2008/04/02/include-source-code-in-latex-with-listings/

although, this way the code seems to run off the page..

KP65
+1  A: 

You can also try the package listings you mention directly within Eclipse with the TEXlipse plugin

alt text

You can then see if you reference the right Java files in your references.
Used in this tutorial slide 19.


You can also try :

  • GNU source-highlight, which can produce Latex output, and may be more appropriate for batch processing a all lot of files.
  • pygmentize, which needs Python, and should also produce Latex output.
VonC