This question: Turning parts of text on and off deals with turning some portions of the text off and on completely -- but the method it uses (commenting) causes the labels in earlier parts of the text not to be defined. Is there a strategy for turning off only the printing, so that the text is processed (and labels defined), but not added to the PDF?
Update 1
Here's a MNWE following the idea from ted in a comment (this must be run with -interaction=nonstopmode
). It looks like the problem with this solution is that the savebox isn't robust to the \section
command. If the savebox can be made more robust, then this approach could work.
\documentclass{article}
\newsavebox{\mybox}
\usepackage{hyperref}
\begin{document}
\section{Bla} \label{one}
Text before the tests.
\section{More Bla} \label{two}
Text before the tests. See Section \ref{one}. (That's fine, everything normal...)
\savebox{\mybox}[0in][0in]{
You don't see this, do you? But you \emph{can} see Section \ref{one} and Section \ref{two}, of course.
\section{Still More Bla} \label{three}
But you shouldn't see this either...
}\usebox{\mybox}
So far, this isn't working... See Section \ref{three}.
\end{document}
savebox
, this might still causehyperref
targets to be missing. To solv ethe later you could try to squish the box by scaling it to 0 height and width and typesetting it once.PDFjam
to select pages but I was hoping for an elegant LaTeX solution.\includeonly
might work. If\includeonly
plays well with\filecontents
life might be even easier. I've no time to try these ideas out.