### Conditional compilation and "comments"

While LaTeX (or any other TeX-derived package) isn't really like a compiler, people regularly want to do compiler-like things using it. Common requirements are conditional 'compilation' and 'block comments', and several LaTeX-specific means to this end are available.

The simple `\newcommand{`\gobble`}[1]``{``}` and `\iffalse``...` `\fi` aren't really satisfactory (as a general solution) for comments, since the matter being skipped is nevertheless scanned by TeX. The scanning imposes restrictions one what you're allowed to skip; this may not be a problem in today's job, but could return to bite you tomorrow. Furthermore, `\gobble` is pretty inefficient for any but trivial arguments, since all the matter to be skipped is copied to the argument stack before being ignored.

If your requirement is for a document from which whole chapters (or the like) are missing, consider the LaTeX `\include`/`\includeonly` system. If you '`\include`' your files (rather than `\input` them - see What's going on in my `\include` commands?), LaTeX writes macro traces of what's going on at the end of each chapter to the `.aux` file; by using `\includeonly`, you can give LaTeX an exhaustive list of the files that are needed. Files that don't get `\include`d are skipped entirely, but the document processing continues as if they were there, and page, footnote, and other numbers are not disturbed. Note that you can choose which sections you want included interactively, using the askinclude package.

The inverse can be done using the excludeonly package: this allows you to exclude a (list of) `\include`d files from your document, by means of an `\excludeonly` command.

If you want to select particular pages of your document, use Heiko Oberdiek's pagesel or the selectp packages. You can do something similar with an existing PDF document (which you may have compiled using pdflatex in the first place), using the pdfpages package. The job is then done with a document looking like:

      \documentclass{article}
      \usepackage[final]{pdfpages}
      \begin{document}
      \includepdf[pages=30-40]{yoursource.pdf}
      \end{document}

(To include all of the document, you write

      \includepdf[pages=-]{yoursource.pdf}

omitting the start and end pages in the optional argument.)

If you want flexible facilities for including or excluding small portions of a file, consider the comment, version or optional packages.

comment allows you to declare areas of a document to be included or excluded; you make these declarations in the preamble of your file. The command `\includeversion{`version-name`}` declares an environment `version-name` whose content will be included in your document, while `\excludeversion{`version-name`}` defines an environment whose content will be excluded from the document. The package uses a method for exclusion that is pretty robust, and can cope with ill-formed bunches of text (e.g., with unbalanced braces or `\if` commands).

version offers similar facilities to comment.sty (i.e., `\includeversion` and `\excludeversion` commands); it's far "lighter weight", but is less robust (and in particular, cannot deal with very large areas of text being included/excluded).

A significant development of version, confusingly called versions (i.e., merely a plural of the old package name). Versions adds a command `\markversion{`version-name`}` which defines an environment that prints the included text, with a clear printed mark around it.

optional defines a command `\opt`; its first argument is an 'inclusion flag', and its second is text to be included or excluded. Text to be included or excluded must be well-formed (nothing mismatched), and should not be too big - if a large body of text is needed, `\input` should be used in the argument. The documentation (in the package file itself) tells you how to declare which sections are to be included: this can be done in the document preamble, but the documentation also suggests ways in which it can be done on the command line that invokes LaTeX, or interactively.

Finally, verbatim (which should be available in any distribution) defines a `comment` environment, which enables the dedicated user of the source text editor to suppress bits of a LaTeX source file.

`askinclude.sty`
  macros/latex/contrib/misc/askinclude.sty
`comment.sty`
  macros/latex/contrib/comment (zip, browse)
`excludeonly.sty`
  macros/latex/contrib/misc/excludeonly.sty
`optional.sty`
  macros/latex/contrib/misc/optional.sty
`pagesel.sty`
  Distributed with Heiko Oberdiek's packages macros/latex/contrib/oberdiek (zip, browse)
`pdfpages.sty`
  macros/latex/contrib/pdfpages (zip, browse)
`selectp.sty`
  macros/latex/contrib/misc/selectp.sty
`verbatim.sty`
  Distributed as part of macros/latex/required/tools (zip, browse)
`version.sty`
  macros/latex/contrib/misc/version.sty
`versions.sty`
  macros/latex/contrib/versions/versions.sty

This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=conditional