2

When I export from org-mode to PDF via LaTeX, my jpg images export successfully, but my gif images do not appear. The gif images do export when I export to HTML.

I found a variable called org-export-html-inline-image-extensions, which is set to "png" "jpeg" "jpg" "gif" "svg" "tif" "gif". However, I don't find an analogous variable for LaTeX.

Closest thing I could find is org-latex-inline-image-rules, but adding gif to that had no effect on export.

How do I direct org-mode to include gif images in export?

5

LaTeX doesn't like .gifs: it needs the image in some other form.

Nevertheless, this can be done. But there's a bit of setting up that needs doing.

  1. You need imagemagick available to convert .gif to .png.

  2. You need to set org up so that it will use pdflatex with the --shell-escape enabled. This enables LaTeX to run shell programs while compiling, and is dis-enabled by default for security reasons. (setq org-latex-to-pdf-process "pdflatex --shell-escape --batch %f") Alternatively export to a latex file and run pdflatex --shell-escape [filename].tex at the command line.

  3. You need to tell ox-latex that a .gif file is to be treated as an image file: (setq org-latex-inline-image-rules '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\|tikz\\|pgf\\|svg\\|gif\\)\\'"))) (or customize that variable). Otherwise it will not include your file using as a graphics file but think it is a link, and just export the URL.

  4. You need to add these magical incantations (or some suitable variation) to your latex header -- they depend on the graphicx package, but that is included by default anyway.

    #+LATEX_HEADER: \DeclareGraphicsRule{.gif}{png}{.png}{`convert #1 `basename #1 .gif`-gif-converted-to.png}
    #+LATEX_HEADER: \DeclareGraphicsExtensions{.gif}
    

The key one is the first. See https://tex.stackexchange.com/a/4982/5404 for a much fuller explanation. The format I have given is assuming that your .gif files are in the same directory as your .org (or, strictly, as the .tex file it produces). If that isn't the case, you will need to do some more fiddling to make sure TeX can find the files. The answer I linked includes an example.

What this command does is use the --shell-escape to call out to imagemagick, converting foo.gif to foo-gif-converted-to.png i.e. effectively it converts the files on the fly. You end up of course with a load of .png files. Still, it means you can keep your gif for HTML export, so something is achieved I suppose.

  • But wouldn't you just get the same result if you'd just manually convert the gif into a png? And what about animated gif's? I off googling trying to find a way to include an animation into my beamer presentation. But thanks for the starting point – Emil Vatai Oct 12 '17 at 18:53

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.