Commenting out single line and multi-line in LaTeX
It is a good habit to use comments in your LaTeX documents to explain what certain parts of your code are doing or to temporarily disable certain parts of your code while you are working on it.
In this tutorial, I will show you how to comment out single-line and multi-line in LaTeX. Let me see the topics.
- Single-line comment out (
%
) - Multi-line command out (
\iffalse
and\fi
) - Commenting out using
\begin{comment}...\end{comment}
Single-line comment out
In order to comment out a single line you can use %
before that line. Anything on a line after the %
symbol will be ignored by the compiler.
Also, you can select that line and press ctrl
+ /
(for mac command
+ /
) to comment out the line.
\documentclass{article} \begin{document} This line will be visible in the output.\\ %This text will be ignored by the compiler. This line also be visible in the output. \end{document}
Output:
Multi-line comment out
If you want to comment out a block of text or multiple lines together. So, in this case, you can use \iffalse
and \fi
commands, anything you pass between these commands will be ignored by the compiler. Take a look.
\documentclass{article} \begin{document} This line will be visible in the output.\\ %This text will be ignored by the compiler. \iffalse This text will be ignored by the compiler. This text will also be ignored by the compiler. \fi This line also be visible in the output. \end{document}
Output:
Use comment environment
You can also use the comment environment to comment out a large section of text or block of text. In order to use this environment you have to load comment
or verbatim
package. Anything you pass inside the comment
environment will be ignored by the compiler.
\documentclass{article} \usepackage{comment} \begin{document} This line will be visible in the output.\\ %This text will be ignored by the compiler. \begin{comment} This text will be ignored by the compiler. This text will also be ignored by the compiler. \end{comment} This line also be visible in the output. \end{document}
Output:
Leave a Reply