# How to replace all pictures by white rectangles?

I have a long document (800 pages) with lots of pictures (300 pictures). I have to produce a version of this document without the pictures (for copyright reasons). The solution I have found so far is to use the draft mode of the graphicx package.

This solution is not fully satisfactory because it replaces the picture by a white rectangle with the name and location of the picture inside.

I would like to have only a white rectangle (of the same size as the picture, with a thin frame), but without any text inside.

Does anyone have a clue?

-

My attempt was to redefine \includegraphics:

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{letltxmacro}% http://ctan.org/pkg/letltxmacro
\usepackage{xparse}% http://ctan.org/pkg/xparse
\usepackage{graphicx}% http://ctan.org/pkg/graphicx

\LetLtxMacro{\oldincludegraphics}{\includegraphics}
\RenewDocumentCommand{\includegraphics}{O{} m}{% \includegraphics[..]{...}
\begingroup\setlength{\fboxsep}{-\fboxrule}%
\fbox{\phantom{\oldincludegraphics[#1]{#2}}}\endgroup%
}

\begin{document}

\lipsum[1-2]
\begin{figure}
\centering
\fbox{\phantom{\oldincludegraphics[height=3cm]{tiger}}}
\caption{This is a tiger}
\end{figure}
\lipsum[3-5]

\end{document}


In the above example, the three images use (i) the original \oldincludegraphics command, followed by (ii) the newly redefined \includegraphics command, followed by (iii) an \fbox{\phantom{\oldincludegraphics{...}}} without the proper \fboxsep set, merely as an illustration of what modification does. The grouping (via \begingroup and \endgroup) within \includegraphics makes sure that setting \fboxsep=-\fboxrule is only local.

letltxmacro provides an effective means to store (or copy) commands that have optional arguments (in this case, the original \includegraphics from the graphicx package), while xparse provides an easy means for specifying commands with (possibly intermixed) optional parameters through \RenewDocumentCommand.

-
You need to set \fboxsep to zero, or the frame will be slightly larger than the image. –  Andrey Vihrov Oct 2 '11 at 15:42
I just used \fbox as an illustration, nor do I use the draft option of graphicx. I don't think the OP will use \fbox. –  Werner Oct 2 '11 at 15:50
Very nice answer (I would have put the \fbox in the new command \includegraphics) ! Thanks a lot ! –  Colas Oct 3 '11 at 6:08
@Colas: So by "white rectangle" you mean \fbox filled with blank space equivalent to the original picture and not just a white rectangle with no border. Either way, I'll update my answer accordingly, for completeness. It actually makes more sense now. –  Werner Oct 3 '11 at 6:11
@Colas: \begingroup is the same as \bgroup or {. Similarly, \endgroup is the same as \egroup or }. These macros define the scope of certain changes within your code. For example, using \renewcommand within a group makes the change local, reverting back to the original definition after the end of the group. I've also updated my code to use a more appropriate \fboxsep; -\fboxrule in this case. –  Werner Oct 6 '11 at 17:59

Well then, just patch graphicx to not output the text:

\documentclass{article}

\usepackage[draft]{graphicx}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\Gin@setfile}{\rlap}{\@gobble}{}{%
\GenericWarning{}{Failed to patch \protect\Gin@setfile}}
\makeatother

\begin{document}

\noindent\includegraphics[width=\textwidth]{tiger}

\end{document}


This code makes use of the etoolbox package.

-
I'm not that familiar with the \patchcmd instruction: Does it matter for the command's operation that the command \Gin@setfile is located in the file graphics.sty rather than in graphicx.sty? (The former style file is loaded by the latter...) Separately, might it be safer to replace the assignment \edef\@tempa{#3}, in the preceding line of the code for the \Gin@setfile command, with \edef\@tempa{}? Please advise. –  Mico Oct 2 '11 at 15:48
Thanks, will do! –  Mico Oct 2 '11 at 15:52
@Mico: This command works at macro level, not package level. You can read the etoolbox manual entry on this command. The \@tempa line can be left as it is, as it won't produce any side effects. –  Andrey Vihrov Oct 2 '11 at 16:00
I guess my thought was that defining \@tempa to be empty, rather than have it contain the filename string, might be less intrusive than obliterating the next command. However, that's pure speculation on my part. –  Mico Oct 2 '11 at 16:12
Thanks so much, this additional explanation is most useful. –  Mico Oct 2 '11 at 16:31

For a quick hack, you can edit graphics.sty (in my case, it is /usr/share/texmf-texlive/tex/latex/graphics/graphics.sty) and find where is filename written inside the rectangle (here, it is line 223, containing \rlap{ \ttfamily\expandafter\strip@prefix\meaning\@tempa}%). Comment it out, that's it.

-
Always edit a copy of the original file, moved to a different location, rather than editing anything in the 'managed' TeX tree. –  Joseph Wright Oct 2 '11 at 15:38
Admittedly; I was thinking of someone who needs to send the file away quickly, and will revert the change back right afterwards. The answer with etoolbox is much better. –  eudoxos Oct 2 '11 at 15:41
Thank you for your answer ! –  Colas Oct 3 '11 at 6:06