[Tex/LaTex] How to NOT render a part of a document (pure LaTeX)

rendering

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.

Best Answer

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.

enter image description here enter image description here

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}
Related Question