I'd like to add a code appendix to my LyX document. There are a few options I already considered, but they all have their problems.
I know a bit about listings, but one problem with those is that, if I copy & paste my code into them, I lose all enters/newlines. Since the code is too large to correct by hand, I was wondering if there is an alternative.
In LyX there is the possibility of inserting child documents, but that seems to be only for .tex files. Would have been ideal if I could just insert my .java file as a child document.
I could print the code to PDF, but it will include margins that mess up the final document, since the PDF is placed on the left margin of the final document and then there is the margin of the PDF. Also, this PDF always contains the entire code and white areas where not the entire page has been filled.
Does anyone have good alternative?
Go to the end of the document where the appendices are to appear. Choose Document → Start appendix here. Sections, etc. can be created and references as usual.
Referencing an appendix in LaTeX is as easy as any other chapter or object. You just have to put an anchor to it using \label{name} and then you can reference the appendix using \ref{name} .
Use the command \appendix instead of \begin{appendix}... \end{appendix} . Then follow the command with the text of your appendices. All following \section commands will be labeled with capital letters instead of numbers.
LaTeX provides an exceedingly simple mechanism for appendixes: the command \appendix switches the document from generating sections (in article class) or chapters (in report or book classes) to producing appendixes. Section or chapter numbering is restarted and the representation of the counter switches to alphabetic.
The listings package found here
http://www.ctan.org/tex-archive/macros/latex/contrib/listings/
allows the include of external source code files (look into the reference for \lstinputlisting
).
EDIT: here you find some samples how to use it:
http://en.wikibooks.org/wiki/LaTeX/Packages/Listings
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With