TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The command \displaygraphics[width-1in]{figure=some_fig.pdf} will display a graphic. Sometimes I want to typeset when I do not have the graphics files available, so I want to do something like:


The intention is that it will simply display the name of the file to be used, rather than try to display the graphic. Note graphics names have underscores, which is the reason I would want something like verbatim. So the command \renewcommand{\includegraphics}[1][]{#2} does not work.

Of course the solution above does not work either, since \verb cannot be used like this inside a \renewcommand. How do I do this?

share|improve this question
Hi and welcome to TeX.SX. You can format code inline by enclosing it in back-ticks, or by selecting it and clicking on the {} icon. Larger chunks of code can be similarly selected and will be marked up with a preceding 4 spaces. (BTW, do you mean \includegraphics? – Alan Munn Feb 14 at 23:05
Apart from the macro name and the error in the number of arguments, \verb cannot be used in the argument to another macro, even \newcommand. – egreg Feb 15 at 0:44

The reason your redefinition doesn't work is that you are specifying the wrong number of arguments in the \renewcommand. If I understand your question correctly you just want filename placeholders for your images. Here's an example:

\caption{When I finally get the file this will be a cool image}

output of code

Alternatively, you can use the [demo] option of graphicx which will replace any \includegraphics command with a black box as below. In this case, of course, you don't get the filenames printed out, but you also don't need to redefine \includegraphics.

output of demo

share|improve this answer
I've seen a draft document that doesn't add the black box but the name of the file; I don't remember how that was done, though. – Manuel Feb 15 at 0:21
@Manuel draft mode only prints the name of the file if it exists, otherwise it throws an error. demo mode ignores files altogether. – Alan Munn Feb 15 at 0:24

There are a number of errors in your code:

  1. The first argument to \renewcommand must be a macro name (with the backslash (fixed in the question).

  2. The command to redefine is \includegraphics (fixed in the question)

  3. The number of arguments should be 2, not 1: when another pair of brackets follows, the contents is the default value of the optional argument, which is denoted by #1 in the replacement text; you also want a mandatory argument, which makes two.

  4. \verb cannot be used in the argument to another macro.



This will also allow underscores.

share|improve this answer
Wouldn't it be more helpful to leave \detokenize out? If there's any macro it would expand. – Manuel Feb 15 at 8:34
@Manuel The OP says that underscores are expected. – egreg Feb 15 at 8:42

What about first check \IfFileExists and if already there, simply \includegraphics or otherwise, for underscores and long paths as well, in teletype style, better use an \url?





Some already made image:


Some image to do:


share|improve this answer
Thanks for all the suggestions. detokenize was the thing that I was missing. All the other suggestions are very useful as well. – Richard Hartley Feb 16 at 0:57
@RichardHartley You are welcome. Then, please accept the best detokenizing answer in your opinion (i.e., click in the gray checkmark under the votes of that answer). But note that these only fix your original approach that do not allow check what images are missing, and you need re-edit the source to remove your macro after providing the images. Then, if you do not already have all the images, you will get a "nice" error message in the log instead of a preliminary draft. – Fran Feb 16 at 4:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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