2

I am trying to insert images into an org-file using absolute paths (which include spaces) and a description, and then export them to PDF via LaTeX.

I am entering the link using C-c C-l, which should deal with the spaces itself, and I have tried it with and without the file: prefix - although that shouldn't make a difference.

I have also tried inserting the link by selecting the file through emacs itself, using C-u C-c C-l, but the results is the same.

I have also tried changing the path to escape the spaces, and using a URL style path, all to no avail.

The closest thing I can get to a solution so far is to not include a description, e.g. [[[file:path/to/file.png]]], which does insert the image, however it also inserts the full path as text, wrapped around the image.

Attempts so far:

Base link: /Home/Images/Emojis once extracted/example.png

[[file:/Home/Images/Emojis once extracted/example.png][Test1]]

[[file:/Home/Images/Emojis\ once\ extracted/example.png][Test2]]

[[/Home/Images/Emojis\ once\ extracted/example.png][Test3]]

[[file:///Home/Images/Emojis%20once%20extracted/example.png][Test4]]

[[file:/Home/Images/Emojis\ once\ extracted/example.png]]    ## Test5

Here is a preview of the org buffer:

[preview of links in Emacs]

I have org-version 8.2.10 running in Emacs 24.5

Edit 1:

Using the org function C-u C-c C-l (universal add link), and with no description, the image is placed in the pdf. However, if there are any spaces in the link to that file, then all characters following that space are also inserted to the pdf alongside the image.

Here is an example of the PDF output from this line of code in the org file:

#CAPTION: A funny image
[[file:/path/to_file 4.png]]

enter image description here

Edit 2:

If I escape the spaces in the path, there is an error (found in buffer: *Org PDF LaTeX Output*, which is a package error, but says it cannot find the image and the following is produced in the PDF output:

enter image description here

Edit 3:

@John Kitchin 's answer below worked well for me. I also came across a customisation of his for drag-n-drop functionality that also solves this problem and adds even better functionality. I recommend people check out the full-description with code and the accompanying video!

1 Answer 1

4

I don't understand what you are hoping to get or expecting. I think if you have a description, you will get a hyperlink to the file, not the image itself.

Of these two links, the first turns into the word test which is hyperlinked to the file, and the second is shown as the image in the pdf for me.

#+latex_header: \usepackage[space]{grffile}

[[file:emoji with space/scientist.png][test]]

[[file:emoji with space/scientist.png]]

It might make sense to generate the links with something like this:

#+BEGIN_SRC emacs-lisp :results org raw
(require 'f)
(let ((dir "emoji with space"))
  (mapconcat 'identity
         (cl-loop for img in (f-files dir)
do (message img)
              if (f-ext? img "png")
              collect (format "#+caption: %s\n[[%s]]"
                      img (expand-file-name img dir)))
         "\n\n"))
#+END_SRC
8
  • Ideally I would like to have the description as a hyperlink in my org file, but the image once converted to PDF (I realise that isn't currently an option). Essentially I just want the image in the PDF. Your second example doesn't give me the image, just a blank box, so maybe I am missing a setting somewhere?
    – n1k31t4
    Commented Mar 12, 2016 at 15:59
  • Actually, I can't find the pattern, but sometimes it does show the image, sometimes it shows an empty box with black outline. In either case, a link with spaces means the link itself is added alongside the image in the PDF - everything after the first space in that file path. In your second exampe then, with space/scientist.png precedes the rendered image as italicised text (i.e. it isn't part of the image).
    – n1k31t4
    Commented Mar 12, 2016 at 16:10
  • 1
    You are right, I missed that earlier. Spaces in filenames are trouble in LaTeX, but it looks like you can add #+latex_header: \usepackage[space]{grffile} and it might work. Commented Mar 12, 2016 at 16:45
  • Interesting that this was actually picked up back in 2008 for org-mode, but still not addressed for exporting to PDF!
    – n1k31t4
    Commented Mar 12, 2016 at 16:53
  • 2
    Cool, thanks! My base setup is at github.com/jkitchin/jmax. We use that for all our scientific writing. You should also check out our bibliography/citation tool at github.com/jkitchin/org-ref. Commented Mar 16, 2016 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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