How to “Export” code the right way?
-
01-10-2019 - |
Question
I have a project in Java and I need to make a code listing in part of my LaTeX documentation with all my classes and code. 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?
Solution 3
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..
OTHER TIPS
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?
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.
You can also try the package listings you mention directly within Eclipse with the TEXlipse plugin
(source: sourceforge.net)
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.