6

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}

I see some stuff I wouldn't expect to see

Joe Corneli
  • 4,340
  • 1
    You could try putting the text in a savebox, this might still cause hyperref 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. – ted Aug 11 '13 at 12:22
  • That doesn't seem to work, I'll add a MNWE. – Joe Corneli Aug 11 '13 at 12:52
  • there's a question dealing with redaction of multi-line text: Censor text spanning multiple lines. this will leave blank space of the size of the censored text, rather than "closing up" the gaps. – barbara beeton Aug 11 '13 at 13:01
  • @barbarabeeton that won't work for what I'm trying to do, which is roughly the opposite (excerpting some passages). For a non-LaTeX solution, I can just use PDFjam to select pages but I was hoping for an elegant LaTeX solution. – Joe Corneli Aug 11 '13 at 13:06
  • 3
    IF the parts to be turned off can be in separate files, \includeonly might work. If \includeonly plays well with \filecontents life might be even easier. I've no time to try these ideas out. – Ethan Bolker Aug 11 '13 at 13:22
  • @EthanBolker That seems to be the exactly right solution, per http://www.tex.ac.uk/cgi-bin/texfaq2html?label=include – Joe Corneli Aug 11 '13 at 14:19
  • @JoeCorneli: apparently using section inside saveboxes is troublesome, here is a solution how it could work, however it involves (la)tex knowledge way over my head, so I think it is best to look at the original awnser. – ted Aug 12 '13 at 10:51

4 Answers4

3

MWE (based on Ethan Bolker's comment):

IF the parts to be turned off can be in separate files, \includeonly might work. If \includeonly plays well with \filecontents life might be even easier. I've no time to try these ideas out. – Ethan Bolker

\documentclass{article}
\usepackage{filecontents}
\usepackage{hyperref}

\begin{filecontents}{part1.tex}
Hi,
\end{filecontents}
\begin{filecontents}{part2.tex}
how are you?
\end{filecontents}

% comment out the following line when you first run, then re-add
\includeonly{part2}

\begin{document}
\include{part1}
\include{part2}
\end{document}
Joe Corneli
  • 4,340
1
\documentclass{article}
\usepackage{versions}
\includeversion{v1}
\excludeversion{v2}
\begin{document}
\begin{v1}
hello
\end{v1}
\begin{v2}
goodbye
\end{v2}
\end{document}
carsten
  • 2,966
0

You could always set \color{white}, but they will still take up space.

Werner
  • 603,163
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
0

I don't think the below is the answer you are looking for. However, to answer the question

Is there a strategy for turning off only the printing, so that the text is processed (and labels defined)

you can set the print state to off using the ocg-p package:

\documentclass{article}
\usepackage{ocg-p}
\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...)

\begin{ocg}[%
    listintoolbar=always,
    printocg=never,
    exportocg=ifvisible
]{noprint}{1}{1}%
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...
\end{ocg}

So far, this isn't working... See Section \ref{three}.

\end{document}

This will add the text and labels to the pdf, but the section in the ocg environment will not print.

Martin Heller
  • 11,391
  • From the documentation: "Optional content (PDF 1.5) refers to sections of content in a PDF document that can be selectively viewed or hidden by document authors or consumers. This capability is useful in items such as CAD drawings, layered artwork, maps, and multi-language documents." -- using it for the purpose here seems a bit curious but... interesting! – Joe Corneli Aug 14 '13 at 16:48