# Selectively suppress generation of typeset output

Is it possible put TeX into a "mute" mode in which all typesetting is suppressed?

\documentclass{article}
\pagestyle{empty}
\begin{document}
\suppress
This text will not be seen in the generated document.
\enable
But this text will.
\suppress
And this text won't again.
\end{document}


The input should be processed "as usual" (maintaining counters, etc.), just without outputting anything.

EDIT: The current application is the creation of a document, in PDF format, that contains only the figures contained in a given source. However, in the end I'm interested if it's possible to mute output in a generic fashion, just the way I asked. If I wanted just to solve the problem, I would simply open the PDF in Acrobat and extract the figures.

-
I once had the same question. I tried a comment environment, but unfortunately it didn't work inside document environment. –  Thanos Feb 8 '13 at 13:08
You can extract the figures directly if it's really what you want. This seems a bit like an XY problem to me... –  tohecz Feb 8 '13 at 13:09
You can do it with the endfloat package, which writes out a file with extension .fff that contains the figure environments. If you don't number the figures by section, this should be enough. Please, try to better specify your aim. –  egreg Feb 8 '13 at 13:12
Deferred writes (the ones used for labels, for instance) require the page where they are to be shipped out. This is a big limitation for the "generic" problem. –  egreg Feb 8 '13 at 13:37
The answers to the following question might solve your problem: How to replace a large block of text by an empty block of the same size? (possible duplicate –  Hendrik Vogt Feb 8 '13 at 13:42

Taking inspiration from syntonly.sty:

\documentclass{article}
\makeatletter
\font\dummyft@=dummy \relax
\def\suppress{%
\begingroup\par
\parskip\z@
\offinterlineskip
\baselineskip=\z@skip
\lineskip=\z@skip
\lineskiplimit=\maxdimen
\dummyft@
\count@\sixt@@n
\loop\ifnum\count@ >\z@
\textfont\count@\dummyft@
\scriptfont\count@\dummyft@
\scriptscriptfont\count@\dummyft@
\repeat
\let\selectfont\relax
\let\mathversion\@gobble
\let\getanddefine@fonts\@gobbletwo
\tracinglostchars\z@
\frenchspacing
\def\endsuppress{\par\endgroup}
\makeatother

\begin{document}
Some text.
\suppress
This text \emph{will} not be seen in the generated document.
\endsuppress
But this text will.
\suppress
And this text won't again.
\endsuppress
This will show.
\end{document}


However rules, radical bars, fraction bars and some other things (mostly math) can escape.

-
Ah, yes, maths! I totally forgot about maths! –  morbusg Feb 8 '13 at 14:16

One idea that occured to me was to use \nullfont:

\documentclass{article}
\long\def\suppress#1\endsuppress{%
\begingroup%
\tracinglostchars=0%
\let\selectfont=\nullfont
\nullfont #1\endgroup}
\pagestyle{empty}
\begin{document}
\suppress
This text will not be seen in the generated document.
\endsuppress
But this text will.
\suppress
And this text won't again.
\endsuppress
\end{document}


### Super-Caveats

1. Maths are not hidden
2. I don’t know LaTeX well enough to tell if I’m doing something really silly in the above.
-
haha just a few seconds late :) –  percusse Feb 8 '13 at 13:55
@percuße: Ouch, I know the feeling; I’m sorry O:-). But feel free to improve this answer! –  morbusg Feb 8 '13 at 13:57
At least add \tracinglostchars=0 in order not to fill the log file with Missing character messages. –  egreg Feb 8 '13 at 14:49
Nope much better than what I intended. –  percusse Feb 8 '13 at 14:51
@tohecz: absolutely! I just love to delete lines of code! Thanks! :-D –  morbusg Feb 8 '13 at 20:08

The comment package should do what you want:

...
\comment
This text will not be seen
\endcomment
But this text will!
...

-
Will the commented text be processed (counters, macro definitions, ...)? –  krlmlr Mar 22 '13 at 10:41

A different solution just for the figure problems.

Here's the main file, where some additions to endfloat are made; let's assume it's called main.tex:

\documentclass{book}
\usepackage{endfloat,etoolbox}
\makeatletter
\pretocmd{\@chapter}{\efloat@iwrite{fff}{\noexpand\fakestepcounter{chapter}}}{}{}
\AtBeginDocument{
\efloat@openpost{fff}
\efloat@iwrite{fff}{\noexpand\fakesetcounter{chapter}{0}}
}
\let\fakestepcounter\stepcounter
\let\fakesetcounter\setcounter
\makeatother

\begin{document}

\mainmatter
\chapter{A}
\section{SA1}

aaa

\begin{figure}
\caption{abc}\label{abc}
\end{figure}

aaa

\section{SA2}

aaa

\begin{figure}
\caption{def}\label{def}
\end{figure}

aaa

\chapter{B}
\section{SA1}

aaa

\begin{figure}
\caption{ghi}\label{ghi}
\end{figure}

aaa

\section{SA2}

aaa

\begin{figure}
\caption{jkl}\label{jkl}
\end{figure}

aaa

\end{document}


Now the auxiliary file, say doonlyfigures.tex

\documentclass{article}
\usepackage{xr,refcount,environ}

\externaldocument{main}

\makeatletter
\let\latexfigure\figure
\let\latexendfigure\endfigure
\let\figure\relax
\let\endfigure\relax
\NewEnviron{figure}{%
\vbox{
\def\label##1{\xdef\thefigure{\getrefnumber{##1}}}
\def\caption{\@dblarg\fake@caption}
\BODY
}
\let\label\@gobble
\latexfigure
\BODY
\latexendfigure}
\def\fake@caption[#1]#2{}
\let\efloatseparator\relax
\let\fakesetcounter\@gobbletwo
\let\fakestepcounter\@gobble
\makeatother

\begin{document}
\input{main.fff}
\end{document}


Similar adjustments to main.tex should be made for supporting tables as well.

-