# How to NOT render a part of a document (pure LaTeX)

I have a large LaTeX file and want to hide most of its contents in the PDF, but preserve the original numbering of theorems, etc. Something similar to display:none in CSS.

The comment environment doesn't help, because it does not process the content at all. It can only be used to hide text outside the theorems.

\hphantom or \vphantom do not wrap environments like \begin{theorem}.

To be more precise, suppose I have the following:

% I want to hide from here ...
\section{Section 1}
\subsection{Subsection 1.1}
\begin{theorem}
First
\end{theorem}
% ... to here
\begin{theorem}
Second
\end{theorem}


I want to see only the second theorem with the original numbering in PDF: Theorem 1.1.2.

My question is very similar to this one, but the author of that question works with Sage and the accepted answer, as far as I understand, is Sage-specific.

If there is no generic way to achieve this effect, I'd be happy if there are ways to hide the following objects:

• Section/subsection titles
• Theorems/lemmas, etc.
• Figures

I also thought about "redirecting" the output to another file (not the PDF), but I couldn't find a solution.

The final alternative would be to "hardcode" the numbers of theorems, but I want to avoid that.

• if the sections that you want can always start a new page then you can use \includeonly which is designed to do exactly this. – David Carlisle Apr 20 '17 at 18:53
• Are you okay with inserting start/end markers in the file of the content you wish to hide? Something like \begin{hidestuff}...\end{hidestuff} (where you define what should be hidden inside hidestuff but still counted)? – Werner Apr 20 '17 at 18:59
• @Werner yes, that would be great! – Hrant Khachatrian Apr 20 '17 at 19:02
• I suppose the hidden stuff should not occupy space, should it? Otherwise you might just switch the font color to white or transparent. – gernot Apr 20 '17 at 19:04

Just an attempt which may work if everything you want to exclude is within the argument of a command or wrapped in an environment. And if you know exactly what you want to exclude.

The left image is without hiding, the right one is with.

The idea is to redefine all commands and environments to swallow the contents of the arguments but still do the counter arithmetic.

\documentclass{article}
\usepackage{environ}
\newtheorem{theorem}{Theorem}
\newenvironment{hide}%
{\renewcommand\section[1]{\refstepcounter{section}}%
\renewcommand\subsection[1]{\refstepcounter{subsection}}%
\RenewEnviron{theorem}{\refstepcounter{theorem}}%
}%
{}
\begin{document}
% i want to hide from here ...
\begin{hide}
\section{Section 1}
\subsection{Subsection 1.1}
\begin{theorem}
First
\end{theorem}
\end{hide}
% ... to here
\begin{theorem}
Second
\end{theorem}
\subsection{Subsection 1.2}
\section{Section 2}
\begin{theorem}
Third
\end{theorem}
\end{document}


If you run this document then uncomment the includeonly and run it again, you get a single page document with (just) theorem 2 on page 2.

\begin{filecontents}{zzzz1.tex}
\section{Section 1}
\subsection{Subsection 1.1}
\begin{theorem}
First
\end{theorem}

\end{filecontents}
\begin{filecontents}{zzzz2.tex}
\begin{theorem}
Second
\end{theorem}
\end{filecontents}

\documentclass{article}
\newtheorem{theorem}{Theorem}

%\includeonly{zzzz2}

\begin{document}
% i want to hide from here ...
\include{zzzz1}
% ... to here
\include{zzzz2}
\end{document}


I like gernot's answer, but I'd already started on this before seeing his, so might as well post it:

\documentclass{article}
\newif\ifskipstuff

\skipstufffalse
%\skipstufftrue

\usepackage{amsmath}
\begin{document}

\ifskipstuff
\refstepcounter{section}
\refstepcounter{subsection}
\refstepcounter{equation}
\else
\section{Section 1}
\subsection{Subsection 1.1}
$$First$$
\fi

\section{A Section}
\subsection{Subsection}
$$Second$$

\end{document}


The drawback is that you need to increase all counters manually, always. Not very nice (particularly if you have a lot of things in the \else clause. Maybe that could be further refined (by including the \ifskipstuff checks inside redefined environments, mayhaps, so that they do their own checking). The upside is that you can globally set if you want to include your material or not by changing between \skipstufffalse and \skipstufftrue, respectively. Well, it might be an upside, depending on your use case.

\skipstufftrue:

\skipstufffalse: