Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

latex

lyx

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?

like image 838
RemiX Avatar asked Mar 15 '11 10:03

RemiX


People also ask

How do you add an appendix in LYX?

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.

How do you put an appendix code in LaTeX?

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

How do I make multiple appendixes in LaTeX?

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.

What is appendix in LaTeX?

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.


1 Answers

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

like image 79
Doc Brown Avatar answered Oct 15 '22 21:10

Doc Brown