Single line or multi-line comments in LaTeX

Commenting is an important part of any language in the programming world. Although latex is not a programming language, it is a markup language.

If you are creating a complex latex document, it is very important to use comments, because this document can easily be understood by others.

If you make a document for someone else, then with the help of comments you can express your thoughts.

There are two types of comments in Latex such as single line and multiline. In both cases the syntax is different.

Single line comment in latex

In case of single-line comment, you need to use percent symbol.

\documentclass{article}
\begin{document}
   % Diffrent symbols in latex 
   \[ \alpha \] % Alpha symbol
   \[ \omega \] % Omega symbol
   \[ \pi \] % pi symbol
   \[ \sigma \] % sigma symbol
\end{document}

Output :

Use single line comment in latex.

In the case of multiline, you can convert a multiline comment using a percent symbol before each line.

Of course, if you use Texmaker software then pressing ctrl+T will leave the multiline comment out at the same time.

\documentclass{article}
\begin{document}
 %------------------------------------------------------------
 % physicread package
 % This material is subject to the LaTeX Project Public License.
 % See https://www.physicsread.com/ for the details of that license.
 %
 %  Different commands have been created for different specific symbols of physics
 % Requires xparse package, which comes bundled with l3packages and l3kernel
 % This package loads amsmath, which comes standard with most latex distributions
 % The commands defined in this package will silently overwrite previous commands with the same name,  if such commands exist
 %
 % Created by admin
 % Updated on april 03, 2022
 % Uploaded on april 8, 2022
 %----------------------------------------------------------
 \[ \sigma \]  % for sigma symbol
 \[ \omega \]  % for omega symbol
 \[ \Omega \]  % for pi symbol
\end{document}

Output :

Use percent symbol for multi-line comments

Multiline or large section comment in latex

The environment has been created in comment package for the purpose of a large section. Same environment is also defined in the verbatim package.

\documentclass{article}
\usepackage{comment}
\begin{document}
  Use Comment environment for multi-line comments!
 \begin{comment}
   when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
   It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
   It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, 
   and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
 \end{comment}
\end{document}

Output :

Use comment package and environment,

Second, the same task can be accomplished using \iffalse....\fi syntax.

\documentclass{article}
\begin{document}
  Use Comment environment for multi-line comments!
 \iffalse
  when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
  It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
  It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, 
  and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
 \fi
\end{document}

Output :

Use \iffalse....\fi syntax for multi-line.

Md Jidan Mondal

LaTeX expert with over 10 years of experience in document preparation and typesetting. Specializes in creating professional documents, reports, and presentations using LaTeX.

Leave a Comment

Your email address will not be published. Required fields are marked *