16

I can't find a pdf figure that goes into a latex document that I am trying to edit. Obviously with the file missing, the document can't compile. Is there some way to edit the file without recompiling, or otherwise without relying on each of the figures being in the same directory (or whatever specified path)?

The figures are included via \includegraphics

6
  • 1
    If you don't have the file and need the document, you can comment out the line, which includes the pdf. Simply add a % at the beginning of the relevant line.
    – Chris
    Oct 26 '13 at 9:28
  • I had the latex'd pdf with the figure included. I want to edit the latex'd pdf, and keep the figure in it, but I don't have the file for the figure. Oct 26 '13 at 9:38
  • 1
    In that case why not use some tool like gimp or pdfimages and extract it from the pdf?
    – Max
    Oct 26 '13 at 9:44
  • Yeah, that's the last resort. Thanks anyway for your comment! Oct 26 '13 at 9:53
  • You could also use the latex'd PDF and only include the page you need using the options.
    – Chris
    Oct 26 '13 at 10:39
17

There a few options to compile a LaTeX where a image is not available, each with some advantages and disadvantages:

  1. Comment the line of the \includegraphics command. With this option the format of the text obviously change to fill the space left by the deleted (commented) image. Need manual editing of the body text. But is is easy restore the deleted command.

  2. Use \usepackage[demo]{graphicx}. Without editing the body of the document, all the images are black boxes, but if they have a defined absolute size (e.g. width=2cm,height=3cm) the format of text is well maintained. Useful for draft versions were the focus is the text distribution or when a faster compiling is needed. When you obtain the lost image all you need is remove the demo option. In response to luchonacho comments: Using the beamer class or other that load automatically graphicx, you can always provide that option to the document class, and you can do this also when is load manually in more standard classes (e.g, \documentclass[demo]{article}) and in fact is somewhat more practical in this way as you can see this option in first line of code.

  3. Notwithstanding these comments point to another interesting option: draft. You can use also the option in the package graphicx or the document class. Instead of a black block show a framed box with the name of the file image. If the image is available in the hard disk, the box will have the correct size even if this is not showed in \includegraphics. Otherwise, please apply what has been said before for demo, but for save printer the ink of the printer is indeed better.

  4. Replace the image with a obvious fake image always available until obtain the original. the mwe package provides a few figures as example-image-a that should be availables even without load that package and without specifying the path. Run texdoc mwe for more information.

If you are asking to compile the document without having the image but render it anyway from PDF, the obvious solution is extract the image from the PDF, for example editing the pdf with Gimp, or making a screen capture, but you can also do that with a pure LaTeX solution with the page,trim and clim options of \includegraphics, with some like:

\includegraphics[trim=2cm 2cm 2cm 2cm,clip,page=23]{myfigure.pdf} 

(The trim sizes are at left, bottom, right and top, respectively)

5
  • Option 2 does not work with beamer. I get Option clash for package graphicx. \setbeamertemplate
    – luchonacho
    Feb 5 '18 at 15:11
  • Solution for beamer is here.
    – luchonacho
    Feb 5 '18 at 15:36
  • Option 3 doesn't work unless you include the file extension is included. See my answer below for details.
    – Paul Wintz
    Jun 30 at 23:36
  • @PaulWintz You are wrong. Maybe you have some local problem in your computer or in your image file, but it should work equally with and without extension.
    – Fran
    Jul 1 at 4:30
  • @Fran, OK, "Option 3 doesn't work on my machine." Is it a bug in graphicx? Is it a configuration issue? I don't know, but I do know that it definitely doesn't work and that other users might have the same issue.
    – Paul Wintz
    Jul 1 at 8:07
4

First of all, editing should always be possible. The problems start with compiling the file. Normally you should be able to compile and ignore the error output, for example with pdflatex --interaction=nonstopmode. If you want a more general solution either comment them out by hand as Michael suggests or use

\usepackage{comment}
\excludecomment{figure}
1
  • Thanks, but commenting out the figure will mean that compiled pdf will not have the figure in it. I want to have the missing figure in the pdf output. I have a pdf output that includes the figure, but I can't recompile it after editing it, because it is missing the figure. Oct 26 '13 at 9:45
0

The easist way is compile when you are missing images to use the draft flag in the \documentclass command. Here is a minimum working example:

\documentclass[draft]{article}
\usepackage{graphicx} 
\begin{document}
\includegraphics[width=0.6\linewidth]{some_image.png}    
\end{document}

One caveat, however, is that this fails if you do not include the extension for the image. So

\includegraphics[width=0.6\linewidth]{some_image}

produces an error in draft mode, even though this works fine if the image some_image.png exists.

5
  • That is not the expected. I suggest you ask in another thread why that happens in your case, if you do not discover why yourself, but explaining what kind of error is is (and for the example, better if you use example-image.pdf so that others can compile it as is, to check if the problem is reproducible).
    – Fran
    Jul 1 at 4:47
  • @Fran, The whole point of the question is that the image is missing, so I don't see how using a different file name matters 😂
    – Paul Wintz
    Jul 1 at 8:09
  • Well it is important, because (1) the image must be read anyway to show the frame with the correct size, but we do not have your some_image.png and (2) therefore they cannot check if your example really produce any kind of error. Of course, we can use any other image, but then there are no errors (already tested in my computer and Overleaf), so what is the next? Using an image that all we have, you still must have the same error, and we must see the same problem, Otherwise, the problem is only in your side.
    – Fran
    Jul 1 at 8:50
  • Please reread the question. The point is that the image is unavailable, so the file some_image.png should not exist.
    – Paul Wintz
    Jul 1 at 19:47
  • 1
    Ah, the case of no extension and no file ... in the rush I did not understand you, sorry. Then the problem is that without the extension, LaTeX is forced to search for a file with the extension .pdf, .jpg or .png in the hard disk, and obviously that search will fail. The draft mode no fail but the search. The search could seem inconvenient in the draft mode, but it is necessary when the extension is omitted, but the image exists, to know where to obtain the default image dimensions.
    – Fran
    Jul 2 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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