# Image placeholder as in \includegraphics[draft], but without path appearing

I want to upload a talk slides to a repository where all material submitted shall be under a certain license. For this, I need to exclude certain images present in the actually sued slides for which the license does not apply, adn have a placeholder instead. \includegraphics[draft,.. pretty much does what I want, only that the actual command in my document is something like

\includegraphics[draft,widht=0.7\textwidth]{../../../talks/1999/acapulco/filename}


which results in the full path being displayed in, and exceeding the placeholder box.

Can I somehow prevent the path from being displayed? It is both ugly and contains more information than I want to convey. Filename alone would be ok, but is not required. If I remove \includegraphics entirely, the layout changes and/or I would have to manually size and place the placeholder.

Here's a solution that adds a noincl key:

\documentclass{article}

\usepackage{graphicx,etoolbox}

\makeatletter
\define@key{Gin}{noincl}[true]{%
\lowercase{\Gin@boolkey{#1}}{draft}%
\lowercase{\Gin@boolkey{#1}}{noincl}%
}
\newif\ifGin@noincl

\patchcmd{\Gin@setfile}{\hb@xt@}{\noinc@box{#3}}{}{}

\def\noinc@box#1#2#3{%
\ifGin@noincl
\do@noinc@box{#1}{#2}{#3}%
\else
\hb@xt@#2{#3}
\fi
}

\def\do@noinc@box#1#2#3{%
\hb@xt@\Gin@req@width{%
\vrule\hss
\vbox to \Gin@req@height{%
\hrule \@width \Gin@req@width
\vss
\edef\@tempa{#1}%
\expandafter\filename@parse\expandafter{\@tempa}%
\rlap{%
\kern3\p@
\parbox{\dimexpr\Gin@req@width-6\p@}{
\raggedright\footnotesize Not included for copyright reasons
}%
}%
\vss
\rlap{\kern3\p@ \tiny\ttfamily\filename@base.\filename@ext}%
\vss
\hrule}%
\hss\vrule}%
}
\makeatother

\begin{document}

\includegraphics[noincl,width=4cm]{/usr/local/texlive/2014/texmf-dist/tex/latex/mwe/example-image.pdf}

\end{document}


todonotes has a facility to show missing figures.

\documentclass{article}
\usepackage{todonotes}
\begin{document}
\begin{figure}[htb]
\missingfigure[figwidth=0.7\textwidth]{My first figure}
\missingfigure[figheight=6cm]{}
\end{figure}
\end{document}


Like todonotes does, you could just include some TikZ rectangle. I made some macro for you, which gets the dimensions of the actual picture and sets them to the dummy node:

% arara: pdflatex

\documentclass{article}
\usepackage{graphicx}
\newif\ifdraft
\drafttrue
%\draftfalse
\newsavebox\imagebox
\usepackage{xparse}
\DeclareDocumentCommand \includedraftpic { o m }{%
\sbox\imagebox{\includegraphics[#1]{#2}}%
\ifdraft
\begin{tikzpicture}
\node[draw, text width=\the\wd\imagebox,minimum height=\the\ht\imagebox, align=center, inner sep=0]{removed for copy right reasons};
\end{tikzpicture}
\else
\usebox\imagebox
\fi
}

\begin{document}
\begin{figure}
\centering
\includedraftpic[widht=0.7\textwidth]{../../../talks/1999/acapulco/filename}
\end{figure}
\end{document}


All you have to do now is to toggle the conditionals draftfalse or drafttrue.

• "...toggle the conditionals" would set it for the whole document, right? – arne.b Nov 25 '14 at 10:08
• Yes, but you can change it during the document. – Juri Robl Nov 25 '14 at 10:11
• @arne.b yes, correct. But it will only be recognized by my new macro. If you like, you can put other stuff between \ifdraft .. \else ... \fi anywhere in your document. Like this, you have your own draft mode and can include/exclude anything you please. – LaRiFaRi Nov 25 '14 at 10:11
• you load the image three times. I think something like \newsavebox\imagebox and then \savebox\imagebox{\includegraphics{imagefile}}\ifdraft\missingfigure[figwidth=\the\wd\imagebox,figheight=\the\ht\imagebox]{removed}\else\usebox\imagebox\fi should be possible (not tested). – yo' Nov 25 '14 at 10:12
• @tohecz Yes, thats much more efficient. Thank you. I added that. – LaRiFaRi Nov 25 '14 at 10:21
\documentclass{book}
\usepackage{graphicx}
\makeatletter
\def\Demo{%
\def\Ginclude@graphics##1{%
\rule{\@ifundefined{Gin@@ewidth}{150pt}{\Gin@@ewidth}}%
{\@ifundefined{Gin@@eheight}{100pt}{\Gin@@eheight}}}}
\makeatother
\begin{document}

\begin{figure}
\centering\Demo
\includegraphics[width=8cm,height=5cm]{Koala_whatever}%
\caption{My Picture}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=8cm,height=5cm]{tiger}%
\caption{My Picture}
\end{figure}

\end{document}


You can slightly change this answer to not display the filename and use it as a command:

\documentclass{book}
\usepackage{picins}
\usepackage{graphicx}

\makeatletter
\newcommand{\imagedraftmode}{
\def\Ginclude@graphics##1{%
\parpic(\Gin@@ewidth,\Gin@@eheight)[d]{}\picskip{0}}%
}
\makeatother

\begin{document}
\begin{figure}
\centering
\imagedraftmode
\includegraphics[width=8cm,height=5cm]{Koala}%
\caption{My Picture}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=8cm,height=5cm]{Koala}%
\caption{My Picture}
\end{figure}
\end{document}

• Thank you, but this just gives me ! Undefined control sequence. \Ginclude@graphics #1->\parpic (\Gin@@ewidth ,\Gin@@eheight )[d]{}\picskip {0}. – arne.b Nov 25 '14 at 12:42
• @arne.b do you have the picins package installed? – Juri Robl Nov 25 '14 at 13:20