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