2

My code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{verbatim}
\begin{document}
    \begin{align}
        1 + 1 & = 2 \\
        e^{i \pi} + 1 & = 0
        \begin{comment}
            comment
        \end{comment}
    \end{align}
\end{document}

Error I get:

$ pdflatex foo.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./foo.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>
(/usr/local/texlive/2020basic/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/usr/local/texlive/2020basic/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2020basic/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020basic/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2020basic/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2020basic/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2020basic/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2020basic/texmf-dist/tex/latex/tools/verbatim.sty)
(/usr/local/texlive/2020basic/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.
def) (./foo.aux)
! Argument of \verbatim@ has an extra }.
<inserted text>
                \par
l.11     \end{align}

?
  • Why can't I use the comment environment inside the align environment?
  • How can I put a multi-line comment block inside align environment?
Lone Learner
  • 3,226
  • 24
  • 44
  • align and other multi-line displaymath environments operate in a two-stage process: Stage 1 serves to measure various things and to figure out which alignment points fit together across rows. Only in stage 2 do all things come together in the form of typeset output. Processing of non-math material during stage 1 is very limited. The presence of \begin{comment} completely wrecks align's stage-1 operations, mainly because it doesn't process \end{comment} meaningfully and hence never gets to "see" \end{align}. – Mico May 10 '20 at 09:18

3 Answers3

3

You can try with an xparse environment which grabs its body:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\NewDocumentEnvironment{mycomment}{b}
 {}{}

\begin{document} \begin{align} 1 + 1 & = 2 \ e^{i \pi} + 1 & = 0 \begin{mycomment} comment comment \end{mycomment} \end{align} \end{document}

enter image description here

Ulrike Fischer
  • 327,261
0

Give up the comment environment and use a falsified condition \iffalse ... \fi as in this answer

\documentclass{article}
\usepackage{amsmath}
%\usepackage{verbatim} %for the MWE no more 'verbatim' needed

\begin{document} \begin{align} 1 + 1 & = 2 \ e^{i \pi} + 1 & = 0 \iffalse comment comment \fi \end{align} \end{document}

-2

To put multiple-line comments inside align environment, one way is to use the \intertext (or \shortintertext, for shorter vertical spacing) from the mathtools.

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}

\begin{align}
1 + 1 &= 2   \\
e^{i \pi} + 1 &= 0 \\
\intertext{This is a multiple line comment so it is not short. This is a multiple line comment so it is not short. This is a multiple line comment so it is not short. This is a multiple line comment so it is not short.}
\sin x &= 1 
\end{align}    

\end{document}

enter image description here

bingung
  • 531
  • Sorry, @bingung, I had to vote down, because your answer does not answer the question. Using \intertext you get a visible text in the .pdf output, which is opposite of what the question requires. Please modify your code and I will withdraw my negative vote. – loved.by.Jesus Jun 25 '20 at 07:21
  • The comment environment is used to leave comments in the tex source code, whereas intertext is used to leave comments in the pdf output. – Teepeemm Jun 25 '20 at 15:59