14 Comments

  1. 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:

    \specialcomment{answer}{\begin{shaded}}{\end{shaded}}

  2. 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
      \includecomment{comment} %show comments
      %\excludecomment{comment}  %do not show comments
      ...
      \begin{comment}
      Section that isn't quite done
      \end{comment}

      to globally show or hide comments.

      • Hi Christian,

        Thanks for your comment with the example. That’s a nice way to include/exclude the comments.

        Best, Tom.

  3. I tried to compile the following code and it does not seem to run. I used exactly the same code as yours.

    \documentclass[11pt]{article}
    \usepackage{comment}
    \begin{document}
      \begin{comment}
        Something will go wrong!
      \end{comment}
    \end{document}

    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.

      • 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.

  4. Manuel Flores

    Is it possible to make a comment within another comment?
    Something like:

    \documentclass[11pt,a4paper,twoside]{article}
    \usepackage{comment}
    \begin{document}
    \includecomment{commentA}
    \includecomment{commentB}
    some text
    \begin{commentA}
    some text
    \begin{commentB}
    some text
    \end{commentB}
    \end{commentA} 
    \end{document}

Leave a Reply