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?

  • You could use the [demo] option to the graphicx package. – Peter Grill Aug 29 '12 at 3:25
  • @PeterGrill sounds like the answer to me :) – cmhughes Aug 29 '12 at 3:27
  • Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Aug 29 '12 at 3:37

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.



        \missingfigure[figwidth=7.0cm]{Missing #2}%