I am using \externalfigure[filename.png] to display PNG files in my document in ConTeXt, e.g.:


Sometimes the file is not found. In this case, ConTeXt compiles, but displays a large gray space on the page where the image would be.

How can I get ConTeXt to print absolutely nothing there in the place where an image should be, in the event that the image file is missing?

2 Answers 2


I could not find an option for that, so the only alternative is to just delete the low-level command's body.



Output is empty page (as expected).

You can also use \doifelsefigure. The advantage over \doiffileexistselse is that this honours the resolver settings for images.



  • Ah nice, I didn't realise \doifelsefigure existed! That is a significant improvement over \doifelsefileexists here.
    – 9tTn9B
    Apr 7, 2017 at 15:47

You could use the \doiffileexistselse command (or \doifelsefileexists which does exactly the same thing), which has the syntax

\doiffileexistselse{file name}{true code}{false code}

Thus your MWE becomes


\doiffileexistselse {001.png} {\externalfigure[001.png]} {}


You could define a wrapper around it, for example I've defined a \tryexternalfigure command which seems to work alright. Then in the main text you can use it with the same syntax as \externalfigure, and it is smart enough to handle the 1 to 3 arguments \externalfigure expects.

\def \tryexternalfigure {\dotripleempty \dotryexternalfigure}
\def \dotryexternalfigure [#1][#2][#3]{%
    \doiffileexistselse{#1} {\externalfigure[#1][#2][#3]} {}%





You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .