This answer does not answer the question perfectly because not all input is processed as usual, which is what most of the other answers focus on.
However, it seems that none of the other answers is perfectly satisfying either, mentioning that in some cases (like math mode) they can not guarantee to suppress the output.
This answer takes a different approach, compromising on processing everything as usual but guaranteeing that all undesired output is suppressed.
This approach ignores everything between two macros which is not explicitly excluded.
I am not expanding not-excluded macros so if an excluded macro is hidden inside of a not-excluded macro it will not be executed.
I am looking ahead with \futurelet.
If the next token is the end token (\enable, as you called it) I do nothing.
Otherwise I gobble the next token and call \suppress again, which again checks and gobbles tokens until reaching \enable:
\documentclass{article}
\newcommand{\suppress}{\futurelet\nexttoken\doSuppress}
\newcommand{\doSuppress}{%
\ifx \nexttoken \enable
\let\do=\relax
\else
\let\do=\suppress
\fi
\GobbleOneTokenAndCall \do
}
% I am not using \expandafter\do\@gobble because that may cause trouble if
% the next token has catcode 1 (begin group), 2 (end group) or 10 (space).
\newcommand{\GobbleOneTokenAndCall}[1]{%
\afterassignment#1%
% The space after the equals is important if you want to gobble a space.
% Without it the next token after the space would be gobbled, too.
\let\gobbledToken= %
}
% The end token.
% This won't be expanded but the replacement text should be unique.
\newcommand*{\enable}{\PackageError{suppress}{\string\enable\space without \string\suppress}{}}
\begin{document}
\suppress
This text will not be seen in the generated document.
\enable
But this text will.
\end{document}
It is easy to extend this code to not suppress certain commands like \end{document} and \begin{figure}.
The following code does not suppress the content of the figure environment, independent of whether it is after a \suppress or not.
Consequently the counter for figures is increased as usual.
Other counters, like the section counter, are not implemented to be increased if a \section command is \suppressed.
\documentclass{article}
% Suppress code
% =============
\usepackage{etoolbox}
\newcommand{\suppress}{\futurelet\nexttoken\doSuppress}
\newcommand{\doSuppress}{%
\ifx \nexttoken \enable
\let\do=\relax
\else\ifx \nexttoken \begin
\let\do=\suppressCheckBegin
\else\ifx \nexttoken \end
\let\do=\suppressCheckEnd
\else
\let\do=\suppress
\fi \fi \fi
\GobbleOneTokenAndCall \do
}
\newcommand{\suppressCheckBegin}[1]{% #1: environment name
\def\envName{#1}%
\ifx \envName \envNameFigure
\def\do{\beginAndSuppressAfterEnd{#1}}%
\else
\let\do=\suppress
\fi
\do
}
\newcommand{\beginAndSuppressAfterEnd}[1]{%
\begin{#1}%
\csappto{end#1}{\endgroup\suppress}%
}
\newcommand{\suppressCheckEnd}[1]{% #1: environment name
\def\envName{#1}%
\ifx \envName \envNameDocument
\def\do{\end{document}}%
\else
\let\do=\suppress
\fi
\do
}
% Note the star, which means that this macro is not \long.
% Without this \ifx would always evaluate to false
% because it would compare a \long to a not \long macro.
\newcommand*{\envNameDocument}{document}
\newcommand*{\envNameFigure}{figure}
% I am not using \expandafter\do\@gobble because that may cause trouble if
% the next token has catcode 1 (begin group), 2 (end group) or 10 (space).
\newcommand{\GobbleOneTokenAndCall}[1]{%
\afterassignment#1%
% The space after the equals is important if you want to gobble a space.
% Without it the next token after the space would be gobbled, too.
\let\gobbledToken= %
}
% The end token.
% This won't be expanded but the replacement text should be unique.
\newcommand*{\enable}{\PackageError{suppress}{\string\enable\space without \string\suppress}{}}
% Test document
% =============
\usepackage{float}
\floatplacement{figure}{htbp}
% see https://www.ctan.org/pkg/latex2e-help-texinfo, section 5.6 "Floats"
\setcounter{topnumber}{10}
\setcounter{bottomnumber}{10}
\setcounter{totalnumber}{10}
\begin{document}
\suppress
suppressed~1.1
\begin{figure}
\centering
ABC
\caption{An example}
\label{fig:abc}
\end{figure}
suppressed~1.2
\enable
\emph{not} suppressed~1.1
\begin{figure}
\centering
DEF
\caption{Another example}
\label{fig:def}
\end{figure}
\emph{not} suppressed~1.2
\suppress
suppressed~2.1
\begin{minipage}{.5\linewidth}
Environments are not a problem.
\end{minipage}
suppressed~2.2
\begin{figure}
\centering
GHI
\caption{Yet another example}
\label{fig:ghi}
\end{figure}
suppressed~2.3
\end{document}
commentenvironment, but unfortunately it didn't work insidedocumentenvironment. – Thanos Feb 08 '13 at 13:08endfloatpackage, which writes out a file with extension.fffthat contains thefigureenvironments. If you don't number the figures by section, this should be enough. Please, try to better specify your aim. – egreg Feb 08 '13 at 13:12boxhandlerpackage does deferred printing of figures and tables. It does this by sticking the items into a box, until later called by the user. However, it would not work for arbitrary text, other than figures and tables. – Steven B. Segletes Mar 18 '13 at 12:44