org-latex-preview: Use the conditional preamble

* lisp/org-latex-preview.el (org-latex-preview--create-tex-file,
org-latex-preview--clear-preamble-cache): Instead using a minimal info
export plist, populate it with buffer-specific values so that the
conditional preamble can be appropriately generated, and cache the
result.
This commit is contained in:
TEC 2023-02-05 16:24:19 +08:00
parent b9f937bb2d
commit 444583f0e6
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 41 additions and 5 deletions

View File

@ -1400,6 +1400,44 @@ previews."
;; ;Note: ov has buffer extended-info, no need to set current-buffer
(delete-overlay ov)))
(defvar-local org-latex-preview--preamble-content nil
"Cache of the LaTeX preamble for snippet preview.")
(defun org-latex-preview--clear-preamble-cache ()
"Set `org-latex-preview--preamble-content' to nil."
(setq org-latex-preview--preamble-content nil))
(add-hook 'org-mode-hook #'org-latex-preview--clear-preamble-cache)
(defun org-latex-preview--get-preamble (&optional buf)
"Obtain the LaTeX preview for snippet preview in BUF."
(with-current-buffer (or buf (current-buffer))
(org-fold-core-ignore-modifications
(let ((info (org-combine-plists
(org-export--get-export-attributes
(org-export-get-backend 'latex))
(org-export--get-buffer-attributes)
'(:time-stamp-file nil)))
org-export-use-babel
(org-latex-conditional-features
(cl-remove-if
(lambda (feat)
(plist-get (alist-get (cdr feat)
org-latex-feature-implementations)
:not-preview))
org-latex-conditional-features)))
(org-export-with-buffer-copy
:drop-narrowing t
(font-lock-mode -1)
(setq info
(org-export--annotate-info (org-export-get-backend 'latex) info))
(org-latex-make-preamble
(org-combine-plists
(org-export-get-environment
(org-export-get-backend 'latex))
'(:time-stamp-file nil))
org-latex-preview-preamble 'snippet))))))
(defun org-latex-preview--create-tex-file (processing-info fragments)
"Create a LaTeX file based on PROCESSING-INFO and FRAGMENTS.
@ -1418,11 +1456,9 @@ The path of the created LaTeX file is returned."
(header
(concat
(or (plist-get processing-info :latex-header)
(org-latex-make-preamble
(org-combine-plists
(org-export-get-environment (org-export-get-backend 'latex))
'(:time-stamp-file nil))
org-latex-preview-preamble 'snippet))
org-latex-preview--preamble-content
(setq org-latex-preview--preamble-content
(org-latex-preview--get-preamble)))
(let ((w org-latex-preview-width))
(cond
((stringp w)