9

Not that big a deal, but why does putting a %-type comment in the same line after \end{comment} cause problems?

\documentclass[12pt]{article}  

\usepackage{comment}
% \usepackage{thmtools, thm-restate}
 
\begin{document}
asdfasdf

\begin{comment}
dsdf
\end{comment}  %comment begins line 46



\end{document}  
16

Assuming the tex file is called main.tex, the input lines

...
\end{comment}  %comment begins
...
\end{document}

generate the following, somewhat incomprehensible prompt:

Runaway argument?
! File ended while scanning use of \next.
<inserted text> 
                \par 
<*> main.tex
            
?

What has happened is that LaTeX has gotten to the end of the file without ever "seeing" \end{comment} and , by extension, \end{document}. What's going on?

By design, a comment environment is allowed to contain pretty much any arbitrary material, including code that could change the meaning, i.e., the so-called category code, of \ (backslash), %, (whitespace), {, }, and all other characters, whether or not these characters are "TeX-special" by default. Thus, in order to determine when and where the comment material ends, one mustn't rely on TeX's usual input processing subsystem, which does assume that \, {, }, %, etc have certain meanings. Instead, some fairly stringent formal requirements have to be imposed on the literal contents of the input string. The author of the comment package has decided that the termination marker must consist of the literal string

\end{comment}

and nothing else; i.e., nothing else is allowed to be on that input line, either before or after \end{comment}.

I suppose that one could point out that this requirement represents a sufficient condition for deciding where the comment material ends, and that a necessary condition could be formulated in a less stringent way, e.g., to allow a %-type comment to occur on the same line as \end{comment}. It's quite likely that one could come up with such a weaker necessary condition. Clearly, though, the author of the comment package decided that this wasn't necessary (pun intended).

| improve this answer | |
-1

If the \end{comment} is on the \begin{comment} line, it is considered as a comment. So the \begin{comment} have no end.

| improve this answer | |
  • 2
    Could you please rephrase and explain, how your answer relates to the code the OP posted? – DG' Oct 24 at 7:25
  • 5
    The OP's question was why \end{comment} %comment fails, not why \begin{comment} \end{comment} fails. – Mico Oct 24 at 7:46
  • '\end {comment}% comment' is a comment and therefore inactive. So \begin {comment} at the beginning of the line has no corresponding \end {comment}. All code that follow is comment, \end{document} is comment and the compilation fail because the document has no \end. – gigiair Oct 24 at 10:50
  • texdoc comment Usage: The ‘comment’ environment is defined by default: all text included between \begin{comment} ... \end{comment} is discarded. The opening and closing commands should appear on a line of their own. No starting spaces, nothing after it. – gigiair Oct 24 at 12:04
  • 1
    So it's not that \end{comment} on the \begin{comment} line is the problem. The problem is something else on the \end{comment} line. – Teepeemm Oct 24 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.