You probably know how to add comments in Latex using the reserved character %
.
% A comment line in LaTeX
Many LaTeX editors provide functionality to comment/uncomment entire paragraphs of your document. However, what if you are using a basic text editor or prefer not to use a menu button?
The comment package solves this by defining the comment
environment. Any content within the opening and closing statements is not displayed in the final document.
\documentclass{article} \usepackage{blindtext, xcolor} \usepackage{comment} \begin{document} \blindtext \begin{comment} \textcolor{red}{\blindtext} \end{comment} \blindtext \end{document}
It is important that the opening and closing commands appear on a separate line without whitespace characters. You might get the following error otherwise:
Runaway argument? ! File ended while scanning use of \next.
Petern
You could also use
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
and for the version without the solutions, I just include the line
To be fancier, and show the answers set off in shaded boxes, I also use the color and framed packages:
as comment allows you to, when showing the commented block, set it in any environment:
\specialcomment{answer}{\begin{shaded}}{\end{shaded}}
tom
Hi Jonathan,
Nice, thanks for your comment. Great stuff!
Tom
Maria
Another way is to define a new command
Kristian Sørensen
Yeah, it definately rocks. I use
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
to globally show or hide comments.
tom
Hi Christian,
Thanks for your comment with the example. That’s a nice way to include/exclude the comments.
Best, Tom.
lee1900cema
I tried to compile the following code and it does not seem to run. I used exactly the same code as yours.
Be cautious. This bug caught me 20 minutes. I have no idea what lead to this.
All the best,
– Linfeng
tom
Thanks for your comment. The problem is with the whitespace/tab character in front of the opening and closing statement of your comment environment. I updated the post to make this clearer.
Thanks, Tom.
lee1900cema
Hi Tom,
I also found out that, the problem only exists when I was trying to compile the tex file using WinEdt. I switched to Vim-Latex Suite lately and the issue no longer occur in the new setting. Quite strange.
All the best,
– Linfeng
tom
That’s strange indeed. Anyway, it seems you found a solution that works for you. Best, Tom.
Vs
Maria, thank you very much!
Manuel Flores
Is it possible to make a comment within another comment?
Something like:
tom
Hi Manuel,
What sort of behavior would you expect? Could you be more specific?
Thanks, Tom