5

The comment package allows you to comment out blocks of code like this:

\documentclass{article}

\usepackage{comment}

\begin{document}
\section{Comments}
    \subsection{How this package works}
        Create block comments thus:
\begin{comment}
        +++++This will be commented out+++++
\end{comment}

%%%%%
    \subsection{My issue}
        I'm in the habit of using plenty of white space to make my latex a little more readable.
        Most of my code looks approximately like how I have set this out.
        Therefore, I would really prefer to comment out large sections like this

        \begin{comment}
            This will cause an error because there is white space before \verb+\end+
        \end{comment}
\end{document}

I have two questions:

  1. Why does this package require this?
  2. Are there any alternatives (other than using % for every line), workarounds etc?
2
  • Welcome to TeX.SE.
    – Mico
    Commented May 19, 2020 at 17:51
  • 1
    @Mico Thanks! To be honest I don't think it has any effect other than making my .tex files uglier to my innocent eyes. It's just one of those silly issues that aren't really an issue but you'll always find an otherwise normal person making themselves look like an idiot for caring.
    – SCM
    Commented May 20, 2020 at 8:45

1 Answer 1

3

You see similar restrictions in most verbatim packages/environments.

comment is a verbatim environment so within its scope all normal processing is disabled, this allows you to comment out mis-matched constructs like unmatched { or \begin{zzz} with no \end. So in particular \end{comment} does not invoke the usual \end processing automatically, the environment has to check each line for the literal string \end{comment} so depending on how complicated the package author wants to make this string processing, it's rather natural to place restrictions on the positioning such as not allowing other text on the same line.

Placing or removing % at the beginning of every line is a viable alternative, many TeX editors will comment/uncomment a region that way in a couple of keystrokes so possibly less typing than the comment environment.

Or in some circumstances you could use \iffalse .....\fi but you can not comment out an unmatched \if in that way.

1
  • Excellent answer
    – SCM
    Commented May 20, 2020 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .