TeX Frequently Asked Questions

Brought to you by the UK TeX Users Group

Welcome to the WWW version of the UK TeX Users Group TeX Frequently Asked Questions list.

Searching

The index of Frequently Asked Questions about TeX is searchable.
Please enter your keyword here:
then press here: .

Conditional compilation

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

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 \included 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 macros/latex209/contrib/misc/askinclude.sty

If you want to select particular pages of your document, use Heiko Oberdiek's pagesel (in macros/latex/contrib/supported/oberdiek.tar.gz), or macros/latex/contrib/other/misc/selectp.sty

If you want flexible facilities for including or excluding small portions of a file, consider macros/latex/contrib/other/comment.tar.gz, macros/latex/contrib/other/misc/version.sty or macros/latex/contrib/other/misc/optional.sty

comment.sty allows you to declare areas of a document to be included or excluded; you make these declarations in the preamble of your file. Its exclusion method is pretty robust, and can cope with ill-formed bunches of text (e.g., with unbalanced braces or \if commands).

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

optional.sty 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.sty (part of macros/latex/required/tools.tar.gz, which should be 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.

The TeX FAQ is maintained for the UK TeX Users Group (UKTUG-Enquiries@tex.ac.uk) by Robin Fairbairns.

Comments, suggestions, or error reports may reported direct to the FAQ maintainer. This is NOT a help address.

This is FAQ version 2.5.1a, last modified on 2000/12/18.