WSL's Emacs, screenshots, org-download, mathpix
As a continuation of my previous post (WSL’s Emacs and windows clipboard) I wanted to be able to take screenshots in windows and paste them in emacs with org-download or convert to math using mathpix.el. Unfortunately this does not work with emacs running on WSL2.
The solution that I have seen involves replacing org-download by a custom function that uses powershell’s command Get-Clipboard to save the image in the windows clipboard to a file (see powershell). However, I wanted to continue using org-download because it organizes the images in subfolders based on the subtree. Besides I also wanted to be able to use mathpix.el to extract latex equations from images.
The solution is to use extract the image from the clipboard using the command: "powershell.exe -Command \"(Get-Clipboard -Format image).Save('$(wslpath -w %s)')\""
.
This works for both org-download and mathpix.el:
(use-package org-download
:after org
:bind
(:map org-mode-map
(("C-M-S-Y" . org-download-screenshot)
("s-y" . org-download-yank)))
:custom
(org-download-screenshot-method "powershell.exe -Command \"(Get-Clipboard -Format image).Save('$(wslpath -w %s)')\"")
)
(setq mathpix-screenshot-method "powershell.exe -Command \"(Get-Clipboard -Format image).Save('$(wslpath -w %s)')\"")
Next thing to investigate: can we drag and drop images to emacs from windows?