LaTeX Comments: Single-Line, Multi-Line and Block Comments

Use % to comment out the rest of a line in LaTeX. To hide several lines, put % at the start of each line or load the comment package and wrap the block in a comment environment. To print a percent sign instead, write \%. Comments stay in your source file but normally do not appear in the compiled PDF.

Updated November 16, 2026

Single-line comments and literal percent signs

A percent sign starts a comment wherever TeX is reading ordinary document input. Everything after it on that physical line is discarded, including the line ending. You can leave a note after a sentence or disable a whole source line. No package is needed. A comment is not a PDF annotation: it is an instruction to ignore source text.

Place the comment after any commands that still need to run. In particular, closing braces, math delimiters, and table row endings must come before the percent sign. If you comment out a closing brace, TeX may keep reading later paragraphs while looking for it. The error can appear far below the line that caused the problem.

Write \% for a percentage in ordinary text or math. A value such as 95% without the backslash does not print a percentage: it prints 95 and discards everything else on that line. This can remove a citation or even the end of the document. Check literal percent signs first when a sentence mysteriously ends early.

\documentclass{article}
\begin{document}
The accuracy is 95\%. % Verify against the final results.
% This sentence is not printed.
The next sentence is printed.
\end{document}

What a comment does to spaces and paragraphs

A normal line ending inside a paragraph usually behaves like a space. A percent sign removes that line ending, so adjacent text can join across lines. For example, super% followed immediately by script on the next line produces superscript. Any space already present before the percent sign remains; the comment does not reach backward to remove it.

This matters in macro definitions and side-by-side boxes, where an accidental space can change the output. End a source line with % only when you intend to suppress that space. It is not true that every line break in every macro automatically introduces a space: TeX also ignores spaces after control words and in certain input states.

A line containing only a comment is not a blank line and does not end a paragraph. Leave a genuinely empty line, or use \par, when you want a paragraph break. Conversely, deleting a comment line should not be your method for controlling paragraph spacing; keep the paragraph structure explicit so another editor can understand it.

\documentclass{article}
\newcommand{\brand}{%
  \textbf{Oc}%
  \textit{tree}%
}
\begin{document}
super%
script

\brand{} keeps its two parts together.
\end{document}

Multi-line and block comments with the comment package

For a long discarded passage, load comment in the preamble, before \begin{document}. The package supplies a comment environment that skips lines without executing the commands inside them. This is useful for an unfinished derivation or an alternative paragraph, including material with unmatched braces that would fail if LaTeX tried to typeset it.

Keep both environment delimiters alone on their own lines, with no indentation or trailing text. In particular, the closing line must be recognized by the package's line-oriented scanner. A space, extra command, or misspelled environment name on that line can make the scanner continue to the end of the file and report a runaway argument.

Do not nest comment environments. The first matching closing line ends the discarded block; the scanner does not maintain a stack of nested environments. Also, do not put this line-scanning environment inside a command argument such as a caption or footnote. Use percent signs on source lines, or remove the unwanted argument text, in those contexts.

\documentclass{article}
\usepackage{comment}
\begin{document}
This paragraph is included.
\begin{comment}
This unfinished paragraph has an unmatched {
and an undefined \unfinishedcommand.
\end{comment}
This paragraph is also included.
\end{document}

Switch named blocks on or off

The same package can create a named environment for solutions, internal notes, or optional explanations. Use \excludecomment{solution} to hide solution blocks, or replace it with \includecomment{solution} to include them. Choose the setting once in the preamble rather than changing every occurrence throughout a long document.

Included blocks must contain valid LaTeX; excluded blocks can contain unfinished source. Keep the delimiter lines in the same strict format for both settings so switching versions does not require editing their contents. Choose an environment name that is not already supplied by your class or another package.

After changing the setting, compile and inspect the resulting PDF. Removing whole sections can change numbering, references, pagination, and the table of contents. A second compilation updates many cross-references, but references to labels inside excluded material remain undefined and need to be removed or redirected.

\documentclass{article}
\usepackage{comment}
\excludecomment{solution}
\begin{document}
Question: What is two plus two?
\begin{solution}
The answer is four.
\end{solution}
\end{document}

When to use a no-package alternative

For a few lines, prefixing every line with % is the simplest and most predictable option. Most source editors offer a toggle-line-comment action that inserts or removes those prefixes on the selection. Search the editor's command menu or keyboard settings for that action; shortcuts depend on the editor, operating system, and keyboard layout.

TeX also skips material between \iffalse and \fi. This can be convenient for a small, controlled block, but it is conditional processing rather than a general-purpose comment environment. TeX still scans conditional tokens while skipping: nested conditionals must balance, and a stray \else or \fi can expose text or terminate the skipped region unexpectedly.

Do not treat \iffalse as safe storage for arbitrary code samples containing conditional commands. For unknown or broken source, percent-prefix the lines or use the comment package instead. Likewise, a custom command that discards its argument still requires balanced argument braces; it does not turn the argument into raw, unread text.

\documentclass{article}
\begin{document}
Visible before.
\iffalse
This alternative paragraph is omitted.
\fi
Visible after.
\end{document}

Tables, equations, and verbatim text

In tables and aligned equations, put an explanatory comment after the row terminator, not before it. Otherwise the percent sign can swallow the two backslashes and merge the next row into the current one. To remove a whole row, comment out its entire source, including the terminator; check that surrounding rules and alignment separators still make sense.

Inside a verbatim environment or a \verb command, percent signs are literal characters and are printed rather than treated as comments. Listings packages can have additional language-specific highlighting rules, so colored source text does not necessarily mean LaTeX is discarding it. Decide whether you are editing executable document source or a displayed code sample.

The verbatim package also defines an environment named comment. If you use that implementation, follow its documentation rather than assuming every detail matches the separate comment package. Avoid loading both merely to get block comments: they share a name, and mixing implementations makes behavior depend on package order.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{tabular}{lr}
Item & Count \\ % End the row before the comment.
A & 12 \\
B & 7
\end{tabular}
\begin{align}
f(x) &= x^2 + 1 \\ % A complete first row.
f'(x) &= 2x
\end{align}
\verb|95% is literal here|
\end{document}

Visible review notes are different from comments

If a co-author needs to see a note in the PDF, a source comment is the wrong tool. A package such as todonotes produces visible review notes; its inline option avoids the narrow-margin problems of margin notes. Add the disable package option when producing a clean copy, then inspect the PDF rather than assuming that every kind of draft markup disappeared.

Neither hidden blocks nor disabled notes are a privacy boundary for the source file. Anyone receiving the .tex file or a project archive can read the omitted material. Delete confidential notes before sharing source, and remember that a clean PDF does not prove that attachments or source bundles are clean.

When debugging a missing passage, inspect the first percent sign on its line, then check nearby block delimiters and conditional switches. Restore a small region at a time and compile after each change. This separates genuine syntax errors from content that you deliberately excluded and avoids introducing several new problems at once.

\documentclass{article}
\usepackage[disable]{todonotes}
\begin{document}
The reported result is 95\%.
\todo[inline]{Check the final sample count before submission.}
\end{document}

Frequently asked questions

How do I comment out multiple lines in LaTeX?

Put % at the start of each selected line, or load the comment package and wrap the block in a comment environment. Keep the opening and closing delimiters alone on unindented lines. Do not nest comment environments.

Why does a percent sign hide the rest of my sentence?

An unescaped % begins a source comment and discards the rest of that line. Write \% to print a percent sign. Check whether the comment also removed a closing brace or math delimiter.

Can I put a comment inside a comment block?

Ordinary percent-sign comments can appear in an excluded block, but nested comment environments are not supported. The first matching closing delimiter ends the block, even if you intended it to close an inner environment.

Do LaTeX comments appear in the PDF?

Ordinary source comments do not appear in the PDF. They remain readable in the .tex file. For visible review notes use a note package; for confidential material, remove it before sharing the source.

Related guides

Test the example in your own document

Open a small project in Octree, paste a complete example, and compile it before moving the changes into your main document. Check the PDF as well as the error log.

Try Octree Free →