The spacing can be exactly preserved (at least I think this answer does it), with page breaks allowed, and equations. There may be problems with color, and other tools which insert "whatsits" in vertical mode; figures and footnotes are probably not supported either.
Inspired in part by egreg's answer. The idea is to typeset the content that you want to hide inside a vertical box, then go through the box and convert every item in the box to an equivalent transparent item, with the same page-breaking properties.
Namely, there are four main types of objects that can appear in vertical mode (this is a convenient lie!): a skip, a kern, a penalty, or a box. Skips are stretchable (and shrinkable) spaces, they are converted to a skip of the same amount. Kerns are non-stretchable spaces, they are converted to kerns of the same amount. Penalties give TeX incentives to break the page; again, we leave them unchanged. Finally, boxes are what contains material to be typeset. We convert them to vertical boxes with the same exact height+depth, but no contents.
To avoid spurious spaces when stacking \vboxes, I had to set \baselineskip, \lineskip, and \lineskiplimit to zero; there are probably better ways. The integer \l_mypkg_cleanup_int, which is the first (optional) argument of \hideit, takes care of removing skips, kerns, and penalties of size 0, which otherwise make the rest of the code choke. This integer may need to be increased if for some reason the text to hide contains several skips/kerns/penalties of size 0 in a row.
\documentclass{article}
\usepackage{expl3,xparse}
\ExplSyntaxOn
\box_new:N \l_mypkg_box
\int_new:N \l_mypkg_cleanup_int
\DeclareDocumentCommand{\hideit}{O{1}+m}
{
\tex_setbox:D \l_mypkg_box \tex_vbox:D
{
#2\par
\dim_zero:N \tex_baselineskip:D
\dim_zero:N \tex_lineskip:D
\dim_zero:N \tex_lineskiplimit:D
\int_set:Nn \l_mypkg_cleanup_int {#1}
\mypkg_dismantle_loop:
}
\tex_unvbox:D \l_mypkg_box
}
\cs_new_protected:Npn \mypkg_dismantle_loop:
{
\prg_replicate:nn { \l_mypkg_cleanup_int }
{
\skip_if_eq:nnT { \tex_lastskip:D } { \c_zero_skip } { \tex_unskip:D }
\dim_compare:nT { \tex_lastkern:D = \c_zero_dim } { \tex_unkern:D }
\int_compare:nT { \tex_lastpenalty:D = \c_zero } { \tex_unpenalty:D }
}
\skip_if_eq:nnTF { \tex_lastskip:D } { \c_zero_skip }
{
\dim_compare:nTF { \tex_lastkern:D = \c_zero_dim }
{
\int_compare:nTF { \tex_lastpenalty:D = \c_zero }
{
\box_set_to_last:N \l_mypkg_box
\box_if_empty:NF \l_mypkg_box
{ \mypkg_dismantle_box: }
}
{ \mypkg_dismantle_penalty: }
}
{ \mypkg_dismantle_kern: }
}
{ \mypkg_dismantle_skip: }
}
\cs_new_protected:Npn \mypkg_dismantle_skip:
{ \mypkg_dismantle_aux:nN { \tex_vskip:D \skip_use:N \tex_lastskip:D } \tex_unskip:D }
\cs_new_protected:Npn \mypkg_dismantle_kern:
{ \mypkg_dismantle_aux:nN { \tex_kern:D \dim_use:N \tex_lastkern:D } \tex_unkern:D }
\cs_new_protected:Npn \mypkg_dismantle_penalty:
{ \mypkg_dismantle_aux:nN { \tex_penalty:D \int_use:N \tex_lastpenalty:D } \tex_unpenalty:D }
\cs_new_protected:Npn \mypkg_dismantle_box:
{ \mypkg_dismantle_aux:nN { \tex_vbox:D to \dim_eval:n { \box_ht:N \l_mypkg_box + \box_dp:N \l_mypkg_box } { } } \scan_stop: }
\cs_new_protected:Npn \mypkg_dismantle_aux:nN #1#2
{
\use:x
{
#2
\mypkg_dismantle_loop:
#1 \scan_stop:
}
}
\ExplSyntaxOff
\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\hideit[2]
{
\lipsum[4-5]
\begin{equation}
x^2+y^2 = z^2
\end{equation}
\lipsum[6-7]
}
\lipsum[8-10]
\end{document}
\iffalse..\fiwould not generate an empty block as requested in the question. – Martin Scharrer Apr 18 '12 at 08:08\usepackage{xcolor}and\textcolor{background_color}{your text}to make your font have the same color as the background. Of course text could be copied without problems, but if you plan to print the document it would probably be ok. – pmav99 Sep 25 '12 at 15:13