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

7
  • 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, 2013 at 12:22
  • That doesn't seem to work, I'll add a MNWE. Aug 11, 2013 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. Aug 11, 2013 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. Aug 11, 2013 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. Aug 11, 2013 at 13:22

4 Answers 4

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}
3
  • Good you cite Ethan. I would suggest you add further text so this answer is solution can read without having to try and track down the comment, but still retaining credit to Ethan. Aug 12, 2013 at 10:18
  • @AndrewSwann - Sure. I just quoted the original comment. Aug 12, 2013 at 13:19
  • Much more helpful. Aug 12, 2013 at 13:22
1
\documentclass{article}
\usepackage{versions}
\includeversion{v1}
\excludeversion{v2}
\begin{document}
\begin{v1}
hello
\end{v1}
\begin{v2}
goodbye
\end{v2}
\end{document}
0

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

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.

1
  • 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! Aug 14, 2013 at 16:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .