8

Is there a way I can use \phantom to hide the contents of an environment, such as itemize?

This does not execute:

\phantom{\begin{itemize}
          \item Hi!
         \end{itemize}}

I'm specifically not looking to just change the text white, because I don't want the contents highlightable in the output.

Gonzalo Medina
  • 505,128
Kyle
  • 391
  • 1
    Does http://tex.stackexchange.com/questions/135453/hiding-part-of-text-leaving-blank-space help? – egreg Feb 21 '15 at 17:56
  • @egreg Wow! Not only is that relevant because it's working to leave the space open, I also want this functionality for student versions of my lecture notes. Wild! Nice find! – Kyle Feb 21 '15 at 21:48

1 Answers1

10

No, you can't use \phantom like that. You can use a \parbox inside \phantom to hide the contents, but reserving the space it occupied, or you could use the comment environment from the comment package to hide the contents suppressing the space altogether:

\documentclass[draft]{article}
\usepackage{comment}

\begin{document}

a
\begin{comment}
\begin{itemize}
\item First.
\item Second.
\end{itemize}
\end{comment}
b

a\par
\noindent\phantom{\parbox{\linewidth}{%
\begin{itemize}
\item First.
\item Second.
\end{itemize}}}\par
b

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • This is perfect! I need to get more used to using parboxes to turn "block" elements into "inline" elements. (I'm guessing at terms here.) Thank you! – Kyle Feb 21 '15 at 21:59