Org LaTeX image export from URLs was upstreamed

This commit is contained in:
TEC 2022-06-19 00:13:49 +08:00
parent a49f7512b1
commit 0d94ccdf3e
Signed by: tec
GPG Key ID: 779591AFDB81F06C
1 changed files with 0 additions and 40 deletions

View File

@ -9682,46 +9682,6 @@ I'd quite like to also recognise =->= and =<-=, so let's set come up with some a
output))
#+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
Once I had the idea of having the look of the LaTeX document produced match the