org-latex-preview: Graceful precompile failure

* lisp/org-latex-preview.el (org-latex-preview-precompile,
org-latex-preview--create-tex-file): Fall back to compiling without
using a preamble format file if the preamble could not be precompiled
without error.  In such an event, alert the user that preamble
precompilation failed, and in particular let them know if mylatexformat
could not be found.
This commit is contained in:
TEC 2023-01-04 01:31:22 +08:00
parent b9e0db41ce
commit ab107da60e
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 35 additions and 9 deletions

View File

@ -946,10 +946,10 @@ The path of the created LaTeX file is returned."
org-latex-preview-preamble 'snippet)) org-latex-preview-preamble 'snippet))
"\n\\usepackage[active,tightpage,auctex]{preview}\n"))) "\n\\usepackage[active,tightpage,auctex]{preview}\n")))
(with-temp-file tex-temp-name (with-temp-file tex-temp-name
(insert (if org-latex-preview-use-precompilation (insert (if-let ((format-file
(concat "%&" (and org-latex-preview-use-precompilation
(org-latex-preview-precompile (org-latex-preview-precompile processing-info header))))
processing-info header)) (concat "%&" format-file)
header)) header))
(insert "\n\\begin{document}\n") (insert "\n\\begin{document}\n")
(dolist (fragment-info fragments) (dolist (fragment-info fragments)
@ -1379,15 +1379,41 @@ process."
(header-base-file (header-base-file
(expand-file-name header-hash temporary-file-directory)) (expand-file-name header-hash temporary-file-directory))
(dump-file (concat header-base-file ".fmt")) (dump-file (concat header-base-file ".fmt"))
(header-file (concat header-base-file ".tex"))) (header-file (concat header-base-file ".tex"))
(precompile-buffer
(with-current-buffer
(get-buffer-create "*Org Preview Preamble Precompilation*")
(erase-buffer)
(current-buffer))))
(if (file-exists-p dump-file) (if (file-exists-p dump-file)
(file-name-base header-base-file) (file-name-base header-base-file)
(with-temp-file header-file (with-temp-file header-file
(insert header "\n\\endofdump\n")) (insert header "\n\\endofdump\n"))
(file-name-base (message "Precompiling Org LaTeX Preview preamble...")
(org-compile-file (condition-case file
header-file (plist-get processing-info :latex-precompiler) (file-name-base
"fmt"))))) (org-compile-file
header-file (plist-get processing-info :latex-precompiler)
"fmt" nil precompile-buffer))
(:success (kill-buffer precompile-buffer)
file)
(error
(unless (= 0 (call-process "kpsewhich" nil nil nil "mylatexformat.ltx"))
(display-warning
'(org latex-preview preamble-precompilation)
"The LaTeX package \"mylatexformat\" is required for precompilation, but could not be found")
:warning)
(unless (= 0 (call-process "kpsewhich" nil nil nil "preview.sty"))
(display-warning
'(org latex-preview preamble-precompilation)
"The LaTeX package \"preview\" is required for precompilation, but could not be found")
:warning)
(display-warning
'(org latex-preview preamble-precompilation)
(format "Failed to precompile preamble, see the \"%s\" buffer."
precompile-buffer)
:warning)
nil)))))
(defun org-latex-preview--tex-styled (processing-type value options &optional html-p) (defun org-latex-preview--tex-styled (processing-type value options &optional html-p)
"Apply LaTeX style commands to VALUE based on OPTIONS. "Apply LaTeX style commands to VALUE based on OPTIONS.