3

I am trying to create a latex document that has a graphic: temp.pdf

\begin{figure}
\centering 
\includegraphics[width=30cm,scale=1]{temp.pdf}
\end{figure}

This works fine if the graphic file is present, however if it is not, I get the text:

temp.pdf in the document.

How can I switch this off so that if temp.pdf is not present, then latex simply ignores the includegraphics command.

1
1

Redefine the command:

\documentclass{article}
\usepackage{graphicx}
\let\IG\includegraphics
\renewcommand\includegraphics[2][]{\IfFileExists{#2}{\IG[#1]{#2}}{\ignorespaces}}
\begin{document}

    \includegraphics[width=3cm]{example-image.pdf}
    \includegraphics[width=5cm]{somefile.pdf}
    \includegraphics[width=3cm]{example-image-a.pdf}    

\end{document}
2
  • Thank you very much. I tried this, but I now get a blank page if there is no graphic. How can I remove this blank page? – adam.888 Nov 28 '15 at 20:43
  • How should I know what you did? As you can see in my example there is no blank page, if you run it. – user2478 Nov 28 '15 at 20:47

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