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

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.

share|improve this question

marked as duplicate by Werner, Andrey Vihrov, lockstep, Caramdir, Jake Oct 4 '11 at 1:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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 '11 at 3:48
up vote 9 down vote accepted

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.

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

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