org-latex-preview: Compile previews in default-dir

* lisp/org-latex-preview.el (org-latex-preview--generic-callback,
org-latex-preview--tex-compile-async,
org-latex-preview--create-tex-file): Compile latex fragments in
`default-directory', with output placed in `temporary-file-directory'.
This is to ensure that relative paths in fragments (such as paths to
figures) are parsed correctly.  Note that relative paths in the header
are handled during precompilation instead.
This commit is contained in:
Karthik Chikmagalur 2023-01-08 19:31:33 -08:00 committed by TEC
parent 2b6b8605f7
commit 7b6f8f4562
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 9 additions and 10 deletions

View File

@ -1285,8 +1285,7 @@ FRAGMENTS will be placed in order, wrapped within a
The path of the created LaTeX file is returned."
(let ((tex-temp-name
(expand-file-name (concat (make-temp-name "org-tex-") ".tex")
default-directory))
(expand-file-name (concat (make-temp-name "org-tex-") ".tex")))
(header
(concat
(or (plist-get processing-info :latex-header)
@ -1330,7 +1329,6 @@ The path of the created LaTeX file is returned."
(tex-command-spec
`((?o . ,(shell-quote-argument temporary-file-directory))
(?b . ,(shell-quote-argument (file-name-base texfile)))
(?B . ,(shell-quote-argument (file-name-sans-extension texfile)))
(?f . ,(shell-quote-argument texfile))))
(tex-formatted-command
(split-string-shell-command
@ -1338,7 +1336,6 @@ The path of the created LaTeX file is returned."
(list 'org-async-task
tex-formatted-command
:buffer tex-process-buffer
:dir temporary-file-directory
:info extended-info
:filter #'org-latex-preview--latex-preview-filter
:failure "LaTeX compilation for preview failed! (error code %d)")))
@ -1422,7 +1419,9 @@ The path of the created LaTeX file is returned."
(defun org-latex-preview--generic-callback (_exit-code _stdout extended-info)
"Move and delete files after image creation, in accords with EXTENDED-INFO."
(let* ((basename (file-name-sans-extension (plist-get extended-info :texfile)))
(let* ((texfile (plist-get extended-info :texfile))
(outputs-no-ext (expand-file-name (file-name-base texfile)
temporary-file-directory))
(images
(file-expand-wildcards
(concat outputs-no-ext "*." (plist-get extended-info :image-output-type))
@ -1645,8 +1644,10 @@ reported values in pt (8.899pt).")
Any matches found will be matched against the fragments recorded in
EXTENDED-INFO, and displayed in the buffer."
(let ((dvipng-depth-height-re "depth=\\([0-9]+\\) height=\\([0-9]+\\)")
(texfile-no-ext (file-name-sans-extension
(plist-get extended-info :texfile)))
(outputs-no-ext (expand-file-name
(file-name-base
(plist-get extended-info :texfile))
temporary-file-directory))
(fragments (plist-get extended-info :fragments))
fragments-to-show page-info-end)
(while (search-forward "]" nil t)
@ -1657,9 +1658,7 @@ EXTENDED-INFO, and displayed in the buffer."
(let* ((page (string-to-number (match-string 1)))
(fragment-info (nth (1- page) fragments)))
(plist-put fragment-info :path
(format "%s-%09d.png"
texfile-no-ext
page))
(format "%s-%09d.png" outputs-no-ext page))
(when (re-search-forward dvipng-depth-height-re page-info-end t)
(let ((depth (* (string-to-number (match-string 1))
org-latex-preview--dvipng-dpi-pt-factor))