17

I have a document, that contains critical parts. Now two documents should be generated. One version that is "balcked out" and one version that is all readable.

For pure text I found some hints using the soul package. See http://latex-community.org/forum/viewtopic.php?f=44&t=18190

Now I have the problem, that there are also some figures (drawn with tikz) that should be hidden. Is there a way to handle this?

Edit: I got two very good answers how to do it. Unfortunately I use the externalization library of tikz. The criticat pictures I of course do not export to avoid problems with the file numbers. But the on compiling the other pictures (after one in a Btikzpicture or a ctikzpicture) have problems to compile as latex finds the \tikzpicture but it seems not to see the \enttikzpicture and therefor runs into trouble. Have you here also a solution. I tried using \NewEnviron but this did not solve the problem as I think.

Example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\usepackage{adjustbox}
\newif\ifblackOut
% \blackOuttrue
\ifblackOut
\newenvironment{ctikzpicture}
    {\tikzset{external/export next=false}
    \adjustbox{precode=\phantom,bgcolor=black!10}
    \bgroup\tikzpicture}
    {\endtikzpicture\egroup}
\else
\newenvironment{ctikzpicture}
    {\tikzset{external/export next=false}
    \tikzpicture}
    {\endtikzpicture}
\fi
\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\draw (0,0) circle (1cm);
\end{tikzpicture}
\end{figure}
% 
\begin{figure}[htbp]
\centering
\begin{ctikzpicture}
\draw (0,0) rectangle (1,1);
\end{ctikzpicture}
\caption{}
\end{figure}
% Uncomment next lines for other error
% \begin{figure}[htbp]
% \centering
% \begin{tikzpicture}
% \draw (0,0) circle (2cm);
% \end{tikzpicture}
% \end{figure}
\end{document}
5
  • 5
    The solution depends on what you call "document". "Blacking out" for the printed version is quite simpler than "blacking out" for the PDF file in a manner where the information is reliably absent from the file.
    – user9588
    Jun 5, 2012 at 13:32
  • It would be optimal if it backs out even for the pdf file. But if you have an idea for only printing, that would also be very welcome. Jun 5, 2012 at 13:45
  • Does it keep the text in the PDF when you use the phantom option? If not, you could try something like tex.stackexchange.com/questions/43069/… and just make the box black. (This is only for the text part, though, not for the figure.) Jun 5, 2012 at 13:50
  • 1
    For plain text there is the censor, which has facilities for censoring either the output PDF or the source .tex file.
    – Alan Munn
    Jun 5, 2012 at 15:42
  • Would you please make a code example?
    – egreg
    Jun 5, 2012 at 15:42

5 Answers 5

14

Just define a Btikzpicture environment that can behave differently under a set conditional and use it for the pictures that you want to selectively omit:

\documentclass{article}
\usepackage{tikz}

\newif\ifsecret
% \secrettrue % uncomment for the hidden version

\ifsecret
%%% code for blanking TikZ pictures
\newsavebox{\Btpbox}
\newenvironment{Btikzpicture}
  {\begin{lrbox}{\Btpbox}\begin{tikzpicture}}
  {\end{tikzpicture}\end{lrbox}%
   \fboxsep=-\fboxrule\fbox{\omission\phantom{\usebox{\Btpbox}}}}

\newcommand{\omission}{\makebox[0pt][l]{\,\tiny OMITTED\strut}}
%%%
\else
%%% code for normal printing
\newenvironment{Btikzpicture}{\tikzpicture}{\endtikzpicture}
%%%
\fi    

\begin{document}
\tikzset{
    every node/.style={
        circle,
        draw,
        solid,
        fill=black!50,
        inner sep=0pt,
        minimum width=4pt
    }
}
\begin{Btikzpicture}[thick,scale=0.8,->,shorten >=2pt]
    \draw (0,0) node {} -- (1,1) node {};
    \draw (1,1) node {} -- (2,1) node {};
    \draw (2,1) node {} -- (3,2) node {};
    \draw (3,2) node {} -- (4,1) node {};

    \draw  (0,2) node {} -- (1,1) node {};
    \draw (1,2) node {} -- (2,1) [dashed] node {};
    \draw (2,1) node {} -- (3,2) node {};
    \draw (3,2) node {} -- (4,1) node {};

    \draw (2,1) node {} -- (3,0) [dashed] node {};
    \draw (2,1) node {} -- (2,0) [dashed] node {};
    \draw (3,0) node {} -- (4,0) [dashed] node {};
    \draw (3,0) node {} -- (4,-1) [dashed] node {};
    \draw (1,1) node {} -- (1,0) [dashed] node {};
\end{Btikzpicture}

\end{document}

(The picture code is taken from an answer by Jake.)

When \secrettrue is uncommented, only a frame of the correct size will be drawn; only the metric information will be in the final output.

0
11

You can use adjustbox to replace the content with a black (or gray, to save ink) rectangle.

Note that this solution will not write the censored content into the PDF.

\documentclass{article}

\usepackage{adjustbox}
\usepackage{tikz}

\iffalse
\newenvironment{ctikzpicture}{%
    \tikzpicture
}{%
    \endtikzpicture
}
\else
\newenvironment{ctikzpicture}{%
    \adjustbox{precode=\phantom,bgcolor=black!10}\bgroup
    \tikzpicture
}{%
    \endtikzpicture
    \egroup
}
\fi

\begin{document}

\begin{ctikzpicture}[thick]
    \draw (0,0) -- (10,10);
    \node at (5,5) {Secret information};
\end{ctikzpicture}

\end{document}

With recent version of adjustbox (i.e. v1.1 2018/04/08) you can just write phantom as a key and also add some "Censored" text on top of it.

\documentclass{article}

\usepackage{adjustbox}[2018/04/08]
\usepackage{tikz}

\iffalse
\newenvironment{ctikzpicture}{%
    \tikzpicture
}{%
    \endtikzpicture
}
\else
\newenvironment{ctikzpicture}{%
    \adjustbox{phantom,bgcolor=black!10,foreground={rotate=45}{\sffamily Censored!}}\bgroup
    \tikzpicture
}{%
    \endtikzpicture
    \egroup
}
\fi

\usepackage{blindtext}
\begin{document}
\blindtext

\begin{ctikzpicture}[thick]
    \draw (0,0) -- (10,10);
    \node at (5,5) {Secret information};
\end{ctikzpicture}

\blindtext
\end{document}

enter image description here

0
5

The \censorbox command from my censor package can block out boxed material like figures, tables, etc. Here is an excerpt from the docs:

enter image description here enter image description here

3

Here is a tikz solution, set the scale to a low value and use color to blank it out (there are possibly more solutions, such as xshift=-2000pt).

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{every picture/.style={color=white,scale=0.0001}}
\begin{document}
abcd

\begin{tikzpicture}
\coordinate (1) at (0.1,0.2);
\coordinate (2) at (0.2,0.7);
\coordinate (3) at (0.4,-0.3);

\draw let \p1 = (1),
          \p2 = (2),
          \p3 = (3),
          \n{denom} = {(\x1 - \x2)*(\x1 - \x3)*(\x2-\x3)},
          \n{A} = {(\x3*(\y2-\y1) + \x2*(\y1-\y3) + \x1*(\y3-\y2))/\n{denom}},
          \n{B} = {(\x3*\x3*(\y1-\y2) + \x2*\x2*(\y3-\y1)+\x1*\x1*(\y2-\y3))/\n{denom}},
          \n{C} = {(\x2*\x3*(\x2-\x3)*\y1 + \x3*\x1*(\x3-\x1)*\y2 + \x1*\x2*(\x1-\x2)*\y3)/\n{denom}} in
          plot[domain=\x1:\x3] (\x,{\n{A}*\x*\x+\n{B}*\x + \n{C}});
\end{tikzpicture}

abcd
\end{document}

As mentioned in the comments though, you need to decide if you sending the original file or not. Other strategies would include importing the figures from files, which you do not include in the final draft you sending out.

3

As you are using externalization anyway, you could also delegate the blackening to some external program that is invoked for the image to externalize via the external/system call key. The amazing thing (I have learned it from Andrew Stacey in the process of answering this question) about this key is that you can pass an arbitrary sequence of commands as long as the final output is a PDF.

In the following, I use ImageMagick's convert utility to replace the generated PDF by one with a simply filled canvas immediately after it has been generated by pdflatex. By defining own styles, the confidential mode can be activated/deactivated with \tikzset globally or on a per-picture base.

\documentclass[a4paper, 11pt]{article}

\usepackage[T1]{fontenc}
\usepackage{tikz}

% setup externalization
\usetikzlibrary{external}
\tikzexternalize
\tikzset{
  confidential tikz/.style={
    external/system call={%
      pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"; 
      convert "\image".pdf -fill Tan -draw 'color 0,0 reset' "\image".pdf}
  },
  public tikz/.style={
    external/system call={%
      pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}
  }
}


\tikzset{confidential tikz}

\begin{document}

\begin{tikzpicture}
  \draw[thick,rounded corners=8pt] 
  (0,0) -- (0,2) -- (1,3.25) -- (2,2) -- (2,0) -- (0,2) -- (2,2) -- (0,0) -- (2,0); 
\end{tikzpicture}

\tikzset{public tikz}

\begin{tikzpicture}
  \draw[thick,rounded corners=8pt] 
  (0,0) -- (0,2) -- (1,3.25) -- (2,2) -- (2,0) -- (0,2) -- (2,2) -- (0,0) -- (2,0); 
\end{tikzpicture}

\end{document}

enter image description here

3
  • This is based on Image Magic right? Jun 5, 2012 at 17:18
  • @ChristianWolf: Right. I have now explained this in detail.
    – Daniel
    Jun 5, 2012 at 19:00
  • @ChristianWolf: Note also, that with this solution there is no need to disable externalization for the confidential images, as the generated image file itself is overwritten by the convert-generated one.
    – Daniel
    Jun 5, 2012 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.