ox-latex: Handle preamble temp-ness explicitly

* lisp/ox-latex.el (org-latex--precompile, org-latex-make-preamble):
Instead of detecting relative file includes within
`org-latex--precompile', have an optional argument to signal a file can
be safely compile in the tempdir.  Move the check to
`org-latex-make-preamble' when calling `org-latex--precompile'.
This commit is contained in:
TEC 2023-03-12 16:08:17 +08:00
parent 52fd5cabea
commit 96dc874f91
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 14 additions and 7 deletions

View File

@ -2130,7 +2130,9 @@ specified in `org-latex-default-packages-alist' or
"\n"))
(format-file
(and org-latex-precompile
(org-latex--precompile info preamble))))
(org-latex--precompile
info preamble
(string-match-p "\\(?:\\\\input{\\|\\\\include{\\)[^/]" preamble)))))
(when (and format-file (not snippet?))
(let ((preamble-parts (split-string preamble (regexp-quote header-split))))
(setq preamble (car preamble-parts)
@ -2236,12 +2238,16 @@ This requires the LaTeX package \"mylatexformat\" to be installed.")
("xelatex" . "xelatex -no-pdf")
("lualatex" . "dvilualatex")))
(defun org-latex--precompile (info preamble)
(defun org-latex--precompile (info preamble &optional tempfile-p)
"Precompile/dump LaTeX PREAMBLE text.
The path to the format file (.fmt) is returned. If the format
file could not be found in the persist cache, it is generated
according to PROCESSING-INFO and stored.
according to PROCESSING-INFO and stored. INFO is a plist used as
a communication channel.
If TEMPFILE-P is non-nil, then it is assumed the preamble does
not contain any relative references to other files.
This is intended to speed up Org's LaTeX preview generation
process."
@ -2250,10 +2256,11 @@ process."
preamble
(concat
(plist-get info :latex-compiler)
(and (string-match-p "\\(?:\\\\input{\\|\\\\include{\\)"
preamble)
default-directory))
(sha1))))
(if tempfile-p "-temp"
default-directory))
(sha1)))
(default-directory
(if tempfile-p temporary-file-directory default-directory)))
(or (cadr
(org-persist-read "LaTeX format file cache"
(list :key preamble-hash)