How to add (large) code application in LaTeX / LyX?

I would like to add an appendix to my LyX document. There are several options that I have already considered, but they all have their own problems.

I am a little versed in lists, but one of the problems is that if I copy and paste my code into them, I lose all incoming / new lines. Since the code is too large to fix manually, I was wondering if there was an alternative.

LyX has the ability to insert child documents, but it only looks like .tex files. It would be ideal if I could just insert my .java file as a child document.

I can print the code in PDF format, but it will include the fields that messed up the final document, since the PDF file is placed on the left margin of the final document, and then there is a PDF field. In addition, this PDF file always contains all the code and white areas where the entire page is not filled.

Does anyone have a good alternative?

+5
source share
4 answers

Listing package found here

http://www.ctan.org/tex-archive/macros/latex/contrib/listings/

allows you to include external source code files (see link for \lstinputlisting).

EDIT: here you will find some examples of how to use it:

http://en.wikibooks.org/wiki/LaTeX/Packages/Listings

+6
source

LyX, Edit → Paste Special → Seletion Ctrl + Alt + V.

+3

, , 2.0 LyX . Insert, File, Child Document " ". listings .

, - highlight source-highlight, , ""

+2

Yes, if you copy the code and paste the code into the list of faces, you will lose all new lines, but you can pre-process your code (insert an additional line of a new line under each line):

$ cat foo.java | sed -e 's/$/\n/' > bar.java

Then you can copy and paste the new bar.java file and everything will be fine.

+1
source

All Articles