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?

2 Answers 2

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

2
  • 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. Aug 10, 2013 at 16:10
  • An entertaining coincidence!
    – Ryan Reich
    Aug 10, 2013 at 16:13
1
\documentclass{article}
\usepackage{comment}
\usepackage{etoolbox}
\appto\endcomment{replacement text}

\begin{document}

text

\begin{comment}
ignored
\end{comment}

\end{document}

You must log in to answer this question.

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