4

Possible Duplicate:
Use “default” figure if file is missing?

I use LaTeX to take notes during my math classes. When the professor draws an image, I jot it down quickly in a notebook and include it later.

Currently I add a \includegraphics{file} line and then comment it out. This way the code compiles, but I still remember where the image goes. Sometimes, however, I forget to comment the line out.

What I would prefer is a command that looks for a file, displays it if found, and if not displays a message instead ("Placeholder for file"), rather than halting compilation.

Is there any way to do this?

1 Answers1

3

You could use the [demo] option to the graphicx package which will allow you to use the \includegraphics{} command with files that do not yet exist -- this will save you form having to coment them out. Then once you have the graphic files you could simply remove the [demo] option.

Another option would be to use \IfFileExists to check that the file exists and use the \missingfigure from the todonotes package:

enter image description here

If you don't want to use an additional package you could just draw your own symbol to represent the missing figure.

Further Enhancements:

  • This does require that you specify the exact file name. This could be enhanced to duplicate the behavior of the \includegraphics package.

Code:

\documentclass{article}
\usepackage{graphicx}
\usepackage{todonotes}

\newcommand\MyIncludeGraphics[2][]{% \IfFileExists{#2}{% \includegraphics[#1]{#2}% }{% \missingfigure[figwidth=7.0cm]{Missing #2}% }% }%

\begin{document} \MyIncludeGraphics[width=5.0cm]{images/EiffelWide.jpg}% \MyIncludeGraphics{graphicFileName.jpg}% \end{document}

Peter Grill
  • 223,288