How-to

How to Comment Out Lines in LaTeX

The fix

To comment out a line in LaTeX, put a percent sign % at the start, everything after % on that line is ignored. To comment out a whole block, load \usepackage{comment} and wrap the block in \begin{comment} ... \end{comment}.

Example

% This whole line is a comment.
Visible text % trailing comment after code

\usepackage{comment}
% ...
\begin{comment}
These lines are all
ignored by LaTeX.
\end{comment}

Frequently asked questions

How do I print a literal percent sign?

Escape it: write \% to show an actual % in the output, since a bare % starts a comment.

Is there a multi-line comment without a package?

You can use \iffalse ... \fi to skip a block, but the comment package (\begin{comment}...\end{comment}) is clearer and handles edge cases better.

Does a % comment also remove the line break?

Yes. A % at the end of a line eats the newline too. That is why macro definitions often end lines with % on purpose, to avoid spurious spaces in the output.

How do I comment out part of a math equation?

The same % works inside math mode: it comments out the rest of that source line. For alternatives in a derivation, copy the equation and comment out the whole old block.

Is there a keyboard shortcut to comment a block?

In most LaTeX editors (including LetX) select the lines and press Ctrl+/ (Cmd+/ on Mac) to toggle % on every selected line.

Related LaTeX fixes

Browse all LaTeX problems & fixes, or start with the LaTeX guide.

Try the fix in LetX

Open the editor, paste your code, and compile in seconds to see the error clear. Free, in your browser.

Open LetX Free