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.

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
add comment

3 Answers 3

up vote 7 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.

mainfile.tex

\documentclass{article}

\begin{document}

\include{chapter1}
\include{chapter2}

\end{document}

chaper1.tex

This is in chapter 1

chapter2.tex

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
add comment

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):

\documentclass{article}
\usepackage{comment}% http://ctan.org/pkg/comment
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
1.\ \lipsum[1]
\begin{comment}
  2.\ \lipsum[2]
\end{comment}
3.\ \lipsum[3]
\end{document}

Commented paragraph using comment package

share|improve this answer
add comment

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
add comment

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