6

Suppose I have an environment redacted which I wanted to declare in such a manner:

\begin{redacted}
This is some secret content.
\end{redacted}

Which, I wanted the result to be equivalent to passing the text inside the environment inside minipage and \phantom{}

\begin{minipage}[1.0\textwidth]
\phantom{This is some secret content.}
\end{minipage}

The following declaration gives me error since the curly parenthesis doesn't match up

\newenvironment{redacted}
    {
        \begin{minipage}[1.0\textwidth]
        \phantom{
    }
    {
        }
        \end{minipage}
    }

Are there any ways to achieve this?

3
  • 3
    Are you familiar with the comment package and its comment environment?
    – Mico
    Jul 24, 2019 at 5:40
  • I'm aware of the comment environment. However, phantom, to my understanding, leaves empty spaces in the text area while comment doesn't.
    – srakrn
    Jul 24, 2019 at 5:42
  • 3
    You have to extract the contents first and then add it to phantom. For example save the minipage in a box (lrbox env, wrapped around the minipage), then use the box inside phantom in the end of the env definition. Generally you cannot span a macro over a begin end env
    – daleif
    Jul 24, 2019 at 5:50

2 Answers 2

9

I believe you want something like this. Note that I put the minipage inside \phantom and not the other way around, because when called in a non-math mode, \phantom typesets its argument in restricted horizontal mode (LR-mode in LaTeX terms), therefore using \phantom{\BODY} would always get you one (possibly extremely long) line.

\BODY collects the body of the environment declared with \NewEnviron. This macro comes from the very convenient environ package.

\documentclass{article}
\usepackage{environ}
\usepackage{lipsum}

\NewEnviron{redacted}{%
  \par\noindent
  \phantom{%
    \begin{minipage}{\linewidth}
      \BODY
    \end{minipage}%
  }%
  \par
}

\begin{document}

Before.

\begin{redacted}
  \lipsum[1]
\end{redacted}

After.

\end{document}

Screenshot

7

Similar to frougon's answer, another option is to use the xparse package with its b argument type, which first scans the environment body such that it can be used as a normal parameter in the environment definition:

\documentclass{article}
\usepackage{xparse}
\usepackage{lipsum}

\NewDocumentEnvironment{redacted}{b}{%
}{%
    \phantom{%
        \begin{minipage}{1.0\textwidth}%
        #1%
        \end{minipage}%
    }%
}

\begin{document}
\lipsum[1]
\begin{redacted}
This is\\
some\\
secret content.
\end{redacted}
\lipsum[2]
\end{document}

enter image description here

You must log in to answer this question.

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