Comments in LaTeX source (percent sign, comment environment)
A percent sign % starts a comment: LaTeX ignores everything from it to the end of the line. For several lines, the verbatim package has the comment environment.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{verbatim}Comment to the end of the line
Everything after % in the same line is dropped, including the line break. A percent sign that should be printed is written \%.
This text is printed. % This note is not.
% A whole line as a comment.
The price rose by 5\%.Comment out several lines
The comment environment from the verbatim package skips everything between \begin{comment} and \end{comment}. Put \end{comment} on a line of its own: text after it on the same line is dropped with a warning.
Visible text.
\begin{comment}
None of these lines
appears in the PDF.
\end{comment}
More visible text.Without a package
\iffalse skips everything up to the matching \fi. This works without a package, also in the middle of a line.
Visible text.
\iffalse
This part is skipped.
\fi
More visible text.Percent sign at the end of a line
A line break in the source counts as a space. A % at the end of the line hides it. In a definition that runs over several lines, this keeps unwanted spaces out of the output.
\newcommand{\important}[1]{%
\textbf{#1}%
}
A word in \important{bold} without extra spaces.Pitfalls
- The text skipped by
\iffalsemust not contain an unmatched\fior\else: the first\fiends the skipping. A missing\fistops with Incomplete \iffalse; all text was ignored after line 4. - For notes that should be visible in the PDF while you work on a document, see the
todonotespackage.
Compiled with pdfLaTeX from TeX Live 2023.