23

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?

Colas
  • 6,772
  • 4
  • 46
  • 96

4 Answers4

18

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.

Andrey Vihrov
  • 22,325
  • 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 02 '11 at 15:48
  • @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 02 '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 02 '11 at 16:12
  • Thanks so much, this additional explanation is most useful. – Mico Oct 02 '11 at 16:31
  • @Mico: Sorry, my last statement was incorrect :-S Yes, defining \@tempa to an empty value would work. – Andrey Vihrov Oct 02 '11 at 16:34
6

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
  \oldincludegraphics[height=3cm]{tiger} \quad 
  \includegraphics[height=3cm]{tiger} \quad
  \fbox{\phantom{\oldincludegraphics[height=3cm]{tiger}}}
  \caption{This is a tiger}
\end{figure}
\lipsum[3-5]

\end{document}

Remove all figures

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.

Werner
  • 603,163
  • 1
    You need to set \fboxsep to zero, or the frame will be slightly larger than the image. – Andrey Vihrov Oct 02 '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 02 '11 at 15:50
  • Very nice answer (I would have put the \fbox in the new command \includegraphics) ! Thanks a lot ! – Colas Oct 03 '11 at 06: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 03 '11 at 06:11
  • What's the use of \begingroup and \endgroup ? – Colas Oct 06 '11 at 17:45
  • 1
    @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 06 '11 at 17:59
4

You can use the package draftfigure to get the same result and modify the display of the switched off figure:

\documentclass{article}

\usepackage{graphicx}
\usepackage[allfiguresdraft]{draftfigure}
\begin{document}
\includegraphics[width=50pt]{example-image-a}

\includegraphics[draft=false,width=50pt]{example-image-b}

\setdf{content={This figure is switched off.}}
\includegraphics[width=50pt]{example-image-c}

\end{document}

enter image description here

lukascbossert
  • 3,015
  • 1
  • 16
  • 37
  • @AndréC Thank you. For more options and modifications for the ›switched off‹-figures see the documentation http://mirrors.ctan.org/macros/latex/contrib/draftfigure/draftfigure.pdf – lukascbossert Sep 03 '17 at 08:51
3

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.

eudoxos
  • 2,973
  • 14
    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 02 '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 02 '11 at 15:41