From 3b7c6faf9ffe600673fe1d8d36ec5c23ef3d9674 Mon Sep 17 00:00:00 2001 From: Karthik Chikmagalur Date: Sat, 3 Jun 2023 15:28:14 -0700 Subject: [PATCH] ox-latex: Disable precompile for xelatex/lualatex * lisp/ox-latex.el (org-latex-make-preamble): If xelatex or lualatex are used for LaTeX export, disable LaTeX header precompilation (via the CTAN package mylatexformat) locally in the buffer and issue a warning. Xelatex does not support precompilation, and while Lualatex supports it in some cases, it is best left unsupported by the Org LaTeX export process until precompilation support for them improves upstream. * lisp/org-latex-preview.el (org-latex-preview--create-tex-file): Make the same changes as above when precompiling LaTeX headers for LaTeX preview purposes. --- lisp/org-latex-preview.el | 33 +++++++++++++++++++-------------- lisp/ox-latex.el | 17 ++++++++++++++--- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/lisp/org-latex-preview.el b/lisp/org-latex-preview.el index 19572e8af..c9afff8e3 100644 --- a/lisp/org-latex-preview.el +++ b/lisp/org-latex-preview.el @@ -1510,25 +1510,30 @@ The path of the created LaTeX file is returned." (concat (make-temp-name "org-tex-") ".tex") (and remote-file-p temporary-file-directory))) (write-region-inhibit-fsync t) - (coding-system-for-write buffer-file-coding-system)) + (coding-system-for-write buffer-file-coding-system) + (precompile-failed-msg)) (when (and relative-file-p remote-file-p) (error "Org LaTeX Preview does not currently support \\input/\\include in remote files")) (when org-latex-preview-precompile - (if-let ((format-file (org-latex-preview--precompile processing-info header))) - ;; Replace header with .fmt file path. - (setq header (concat "%& " (file-name-sans-extension format-file))) + (pcase (plist-get processing-info :latex-processor) + ("pdflatex" + (if-let ((format-file (org-latex-preview--precompile processing-info header + (not relative-file-p)))) + (setq header (concat "%& " (file-name-sans-extension format-file))) + (setq precompile-failed-msg + "Precompile failed."))) + ((or "xelatex" "lualatex") + (setq precompile-failed-msg + (concat + (plist-get processing-info :latex-processor) + " does not support precompilation.")))) + (when precompile-failed-msg (display-warning '(org latex-preview disable-local-precompile) - (concat "Precompile failed, disabling LaTeX preview precompile in this buffer." - "\n To renable, run `(setq-local org-latex-preview-use-precompilation t)' or reopen this buffer." - (pcase (plist-get processing-info :latex-processor) - ("lualatex" - "\n LuaLaTeX is known to be problematic, if you might be able to help please get in touch with emacs-orgmode@gnu.org.") - ("xelatex" - ;; Note: might be helpful. - "\n The current XeTeX approach does not support fontspec, if you might be able to help please get in touch with emacs-orgmode@gnu.org.")) - "\n ")) - (setq-local org-latex-preview-use-precompilation nil))) + (concat + precompile-failed-msg + " Disabling LaTeX preview precompile in this buffer.\n To re-enable, run `(setq-local org-latex-preview-precompile t)' or reopen this buffer.")) + (setq-local org-latex-preview-precompile nil))) (with-temp-file tex-temp-name (insert header) ;; The \abovedisplayskip length must be set after \begin{document} because diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 707869abb..f21356f94 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -2130,9 +2130,20 @@ specified in `org-latex-default-packages-alist' or "\n")) (format-file (and org-latex-precompile - (org-latex--precompile - info preamble - (string-match-p "\\(?:\\\\input{\\|\\\\include{\\)[^/]" preamble))))) + ;; Precompilation is disabled for xelatex/lualatex for now. + (if (member (plist-get info :latex-compiler) + '("xelatex" "lualatex")) + (progn + (display-warning + '(org latex-export disable-local-precompile) + (format "%s does not support precompilation, disabling LaTeX precompile in this buffer.\n To re-enable, run `(setq-local org-latex-precompile t)' or reopen this buffer." + (plist-get info :latex-compiler))) + (setf (buffer-local-value + 'org-latex-precompile (get-buffer (plist-get info :input-buffer))) + nil)) + (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)