5

How to write an environment such that

\begin{comment}
    Bla, bla.
\end{comment}

produces no output, and instead defines a macro \@comment whose replacement text is everything that is inside the comment environment?

6

The environ package collects the environment into a macro \BODY, which you can save as whatever macro name you like (note: must be a global definition, since the envrionment is inside a group).

\documentclass{article}
\usepackage{environ}
\makeatletter
\NewEnviron{comment}{
  \global\let\@comment\BODY
}
\makeatother
\begin{document}
\begin{comment}
  Bla, bla.
\end{comment}
\makeatletter\texttt{\meaning\@comment}\makeatother
\end{document}

Result

  • You were two minutes earlier with the same example file. I have added an image and \texttt (the only difference) to match the image of my file. – Heiko Oberdiek Aug 10 '13 at 16:10
  • An entertaining coincidence! – Ryan Reich Aug 10 '13 at 16:13
1
\documentclass{article}
\usepackage{comment}
\usepackage{etoolbox}
\appto\endcomment{replacement text}

\begin{document}

text

\begin{comment}
ignored
\end{comment}

\end{document}

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.