From 96dc874f91ab03a2f6e849bd79d5bb6bdcd1f2c8 Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 12 Mar 2023 16:08:17 +0800 Subject: [PATCH] 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'. --- lisp/ox-latex.el | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index d0e884933..707869abb 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -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)