12

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

  • 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. – generic_user 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! – generic_user 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
15

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 lunonacho 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)

  • 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
2

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}
  • 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. – generic_user Oct 26 '13 at 9:45

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.