Possible Duplicate:
Commenting out large sections

I have a long document where sometimes I need to omit some parts for the compilation, and sometimes other parts. I do it by just commenting with % the necessary lines, but sometimes it gets tedious. I wonder if there are some commands which, put at the start and end of the part I want to avoid, would skip the compilation of that part.

  • Flow: May I ask what editor are you using for your LaTeX writing? And I may have a solution for you. The reason being is that I don't know if this method works across all editors which I would think it doesn't.
    – night owl
    Oct 3, 2011 at 3:48

3 Answers 3


Another option is to restructure your document so that you have

  • one main file
  • many chapter/section files

You can then use \include or \input to link the chapter/section files to the main file.







This is in chapter 1


This is in chapter 2

See When should I use \input vs. \include? to compare \include to \input

There are many advantages to this approach- not least, that you can comment out the relevant \include line which will stop you from compiling that chapter.


You should look at the comment package. It is specifically meant for this purpose. It provides a comment environment (or a \comment...\endcomment command pair) that you need to encompass your don't-want-to-compile stuff with. It also allows a form of version control, versionA (say), which can be turned on/off using \includecommand{versionA}/\excludecomment{versionA}. Such version-specific comments have their own environment: \begin{versionA}...\end{versionA} or the \versionA...\endversionA command pair.

Here's a minimal working example (the second paragraph \lipsum[2], prefixed with 2., is not typeset):

\usepackage{comment}% http://ctan.org/pkg/comment
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
1.\ \lipsum[1]
  2.\ \lipsum[2]
3.\ \lipsum[3]

Commented paragraph using comment package


You might be interested by the tagging package (born on TeX.SX not long ago) which allows to set tags for the document and conditionally adapt the document depending on the set tags.

Combine it with \include statements like cmhughes recommended.

Not the answer you're looking for? Browse other questions tagged .