1

Sometimes, we want to replace a missing/forgot-to-upload figure with blanks or some placeholder

This can be done by changing the code and use the mwe package \includegraphics[width=\textwidth]{example-image-a}, see, Placeholder for figure/includegraphics

But, I want to achieve this feature without modifying the tex code. Because in many version control cases, I'm not allowed to change the code.

Instead, is it possible to add extra options to the pdflatex command so that the missing figure is replaced by some placeholder? I.e., I want to do this feature in the "compiler" level.

null
  • 373
  • The demo option of the graphicx package might be useful. Please note that it will replace all \includegraphics images with a black rectangle, regardless of wether the corresponding image is a vailalble or not. – leandriis Aug 09 '20 at 07:10

1 Answers1

2

Check if the image exists with \IfFileExists:

\documentclass[]{article}
\usepackage{graphicx,todonotes}
\def\imgcond#1{
\IfFileExists{#1}{\includegraphics[width=3cm]{#1}}{
\includegraphics[width=3cm]{example-image}}}
\parskip1em

\begin{document}

\imgcond{example-image-a}

\imgcond{whatever}

\imgcond{anything}

\end{document}

Fran
  • 80,769