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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 10 down vote accepted

Use the listings package with the firstline option:

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

Your Answer


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.