Org LaTeX image export from URLs was upstreamed
This commit is contained in:
parent
a49f7512b1
commit
0d94ccdf3e
40
config.org
40
config.org
|
@ -9682,46 +9682,6 @@ I'd quite like to also recognise =->= and =<-=, so let's set come up with some a
|
||||||
output))
|
output))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
**** Support images from URLs
|
|
||||||
You can link to remote images easily, and they work nicely with HTML-based
|
|
||||||
exports. However, LaTeX can only include local files, and so the current
|
|
||||||
behaviour of =org-latex-link= is just to insert a URL to the image.
|
|
||||||
|
|
||||||
We can do better than that by downloading the image to a predictable location,
|
|
||||||
and using that. By making the filename predictable as opposed to just another
|
|
||||||
tempfile, this can provide a caching mechanism.
|
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
|
||||||
(defadvice! +org-latex-link (orig-fn link desc info)
|
|
||||||
"Acts as `org-latex-link', but supports remote images."
|
|
||||||
:around #'org-latex-link
|
|
||||||
(setq o-link link
|
|
||||||
o-desc desc
|
|
||||||
o-info info)
|
|
||||||
(if (and (member (plist-get (cadr link) :type) '("http" "https"))
|
|
||||||
(member (file-name-extension (plist-get (cadr link) :path))
|
|
||||||
'("png" "jpg" "jpeg" "pdf" "svg")))
|
|
||||||
(org-latex-link--remote link desc info)
|
|
||||||
(funcall orig-fn link desc info)))
|
|
||||||
|
|
||||||
(defun org-latex-link--remote (link _desc info)
|
|
||||||
(let* ((url (plist-get (cadr link) :raw-link))
|
|
||||||
(ext (file-name-extension url))
|
|
||||||
(target (format "%s%s.%s"
|
|
||||||
(temporary-file-directory)
|
|
||||||
(replace-regexp-in-string "[./]" "-"
|
|
||||||
(file-name-sans-extension (substring (plist-get (cadr link) :path) 2)))
|
|
||||||
ext)))
|
|
||||||
(unless (file-exists-p target)
|
|
||||||
(url-copy-file url target))
|
|
||||||
(setcdr link (--> (cadr link)
|
|
||||||
(plist-put it :type "file")
|
|
||||||
(plist-put it :path target)
|
|
||||||
(plist-put it :raw-link (concat "file:" target))
|
|
||||||
(list it)))
|
|
||||||
(concat "% fetched from " url "\n"
|
|
||||||
(org-latex--inline-image link info))))
|
|
||||||
#+end_src
|
|
||||||
**** Chameleon --- aka. match theme
|
**** Chameleon --- aka. match theme
|
||||||
|
|
||||||
Once I had the idea of having the look of the LaTeX document produced match the
|
Once I had the idea of having the look of the LaTeX document produced match the
|
||||||
|
|
Loading…
Reference in a new issue