# Commenting in Latex

I am sure you know how to comment lines out in Latex using “%”. Usually Latex editors even provide functions to comment/uncomment larger sections of your document.Now what if you are using a simple text editor or simply are not used to use editor functions. The package “comment” might be useful:

\usepackage{comment} \begin{comment} ... \end{comment}

Make sure you use the commands at the beginning of a new line.

#### 7 Responses to “Commenting in Latex”

• Petern

You could also use

\iffalse

\fi

although I suppose it might be a pure TeX command

• Jonathan Dursi

I’ve grown quite fond of the comment environment, as it allows you to turn on and turn off the commented text. In particular, I now use it for assignments to generate the version with and without solution sets. I put the answers in section blocks like this

\begin{answer}
...
\end{answer}

and for the version without the solutions, I just include the line

\excludecomment{answer}

To be fancier, and show the answers set off in shaded boxes, I also use the color and framed packages:

\usepackage{color}
\usepackage{framed}
\usepackage{comment}
\definecolor{shadecolor}{gray}{0.875}

as comment allows you to, when showing the commented block, set it in any environment:

• tom

Hi Jonathan,

Nice, thanks for your comment. Great stuff!

Tom

• Maria

Another way is to define a new command

\newcommand{\commentOut}[1]{}
.
.
.
\commentOut{

}
• Kristian Sørensen

Yeah, it definately rocks. I use

%\begin{comment}
Section that isn't quite done
%\end{comment}

A lot, commenting the \begin{comment} and \end{comment} out (by adding % before them) to disable them. Easily switch on/off bits of text that way.

• Christian Bach

you can also use

\usepackage{comment}
%comment out either the first or second line
\end{comment}