Including a Program Source File in LaTeX [Tip]

2009 June 8

This is a command within LaTeX that I forget constantly and I always lose the resource from where I learned about it. So, I’m documenting it here so that I can find it later on when I need it. I also figured it might help somebody else out there looking for the same thing.

\lstset{language=[ISO]C++,tabsize=3}
\lstinputlisting{Lab6.cpp}

Basically, what this little code snippit does is import a source code file and inserts it into the final document. It’s a lot easier than copy/paste and it has a lot of formatting options associated with it. Just check out the \lstset command manual or this guide here or this guide here (LaTeX wikibook). Be sure to include the listings package with this declaration before the main document: \usepackage{listings}.

Feel free to buy me a soda if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that I hope you'll be interested in:


Here are some similar posts that you may be interested in:


No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS