Commenting out large sections

You can use \iffalse ... \fi to make (La)TeX not compile everything between it. However, this might not work properly if you have unmatched \ifxxx ... \fi pairs inside them or do something else special with if-switches. It should be fine for normal user text.

There is also the comment package which gives you the comment environment which ignores everything in it verbatim. It allows you to define own environments and to switch them on and off. You would use it by placing \usepackage{comment} in the preamble. Below is an example:

\usepackage{comment}
\begin{document}
\section{Multi-line comments}}
\begin{comment}
This is a comment,
a multi-line comment,
indeed.
\end{comment}
\end{document}


You can use \iffalse:

\iffalse
One morning, as Gregor Samsa was waking up from anxious dreams, he discovered
that in his bed he had been changed into a monstrous verminous bug. He lay on
his armour-hard back and saw, as he lifted his head up a little, his brown,
arched abdomen divided up into rigid bow-like sections.
\fi

Of course, this has to align with other syntactical TeX structures in you document whereas you can use % much more freely. The good news is that you can introduce your own switch to make this optional:

\newif\ifdraft
\drafttrue % or \draftfalse

\ifdraft
<only shown in draft mode>
\else 
<only shown in non-draft mode>
\fi

The \else part is optional and you could use \ifdraft ... \fi if you don't need it.


The verbatim package provides a comment environment:

\documentclass{article}
\usepackage{verbatim}
\begin{document}
    This text will be displayed
\begin{comment}
    This text will not be displayed.
\end{comment}
\end{document}

The Not So Short Introduction to LaTeX2e mentions this option on page 6 and remarks: "Note that this won’t work inside complex environments, like math for example."

Tags:

Comments