Let's say I am working with "file_name.org" file. When I use C-c C-x C-l
to generate a LaTeX preview, it creates a png image and store in ltximg/ directory by default.
I would store the preview images per file. So I want C-c C-x C-l
to create a directory (if there isn't one) ltximg/file_name/ and store the image there.
I know that I have to manipulate org-preview-latex-image-directory
variable, but I am not sure how. Could someone help me with this?
Update
I defined the following function. This works changes the org-preview-latex-image-directory
whenever an org file is opened. So if I am working with multiple org files, it gets confused. So I am trying to write a wrapper for org-toggle-latex-fragment
function so that whenever org-toggle-latex-fragment
is called, latex-image-directory
function is called. But I am having some trouble implementing the argument, e.g., C-u C-c C-x C-l
.
(defun latex-image-directory ()
(require 'cl-lib)
(setq file-name (nth 0 (last (split-string (buffer-file-name) "/"))))
;; slice the last 4 characters: ".org"
(setq org-preview-latex-image-directory (concat "ltximg/"
(cl-subseq file-name 0 -4) "/"))
)