Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm likely going to have to write a document that includes some portions of source code, which I'd rather keep in separate source files. I know that I can include the contents of those files in my document using \input{example.cpp}, and use various environments to pretty-print the code, but the source files will certainly start with a few commented lines explaining what the code does, whether it can be redistributed and so on, and this will be irrelevant in the main document.

Is there a package or a specific command that allows me to omit those lines when including an external file?

share|improve this question
add comment

1 Answer

up vote 10 down vote accepted

Use the listings package with the firstline option:

\lstinputlisting[firstline=2]{file}
share|improve this answer
    
Great, thanks a lot! –  Anthony Labarre Feb 1 '11 at 9:11
    
@Anthony: There is also a lastline option if you need it. –  Martin Scharrer Feb 1 '11 at 20:25
    
Yes, I've read the documentation, this will come in handy too. –  Anthony Labarre Feb 2 '11 at 8:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.