2

I want to define an environment to hide text, with warning about it before and after in the pdf-output. What is wrong with the following definition?

\newenvironment{foldit}
{NB! NB! FOLDED TEXT BELOW\\ NB! NB! FOLDED TEXT BELOW\\ \iffalse}
{\fi ~~\\ NB! NB! FOLDEDTEXTABOVE \\ NB! NB! FOLDEDTEXTABOVE}

When I try to enclose some texts with \begin{foldit} .... \end{foldit}, I get the error message: Incomplete \iffalse; all text was ignored after line 105.

2 Answers2

5

You might want to try package environ or comment:

\documentclass{article}
\usepackage{parskip}
\usepackage{comment}
\usepackage{environ}
\NewEnviron{foldit}{%
NB! NB! FOLDED TEXT BELOW\\
NB! NB! FOLDED TEXT BELOW\\
%\BODY
NB! NB! FOLDEDTEXTABOVE\\
NB! NB! FOLDEDTEXTABOVE\\
}

\NewEnviron{unfoldit}{% NB! NB! FOLDED TEXT BELOW\ NB! NB! FOLDED TEXT BELOW\ \BODY\ NB! NB! FOLDEDTEXTABOVE\ NB! NB! FOLDEDTEXTABOVE\ }

\begin{document} Line~1.

\begin{comment} Line~2. \end{comment}

Line~3.

\begin{foldit} Line~4. \end{foldit}

\begin{unfoldit} Line~5. \end{unfoldit} \end{document}

enter image description here

citsahcots
  • 7,992
5

Consider using environ to define foldit. It handles the environment definition in a similar way you'd expect from \newcommand, with the argument being \BODY - the body of the environment (between \begin{<env>}...\end{<env>}).

enter image description here

\documentclass{article}

\usepackage{environ,lipsum}

\NewEnviron{foldit}{% \par\noindent NB! NB! FOLDED TEXT BELOW \par\noindent NB! NB! FOLDED TEXT BELOW %\BODY \par\noindent NB! NB! FOLDED TEXT ABOVE \par\noindent NB! NB! FOLDED TEXT ABOVE } \begin{document}

1: \lipsum[1]

\begin{foldit} 2: \lipsum[1] \end{foldit}

3: \lipsum[3]

\end{document}

Werner
  • 603,163