From 43ba00b2b14adfb2670555f9a4a286bd4d1dc0d5 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Sun, 5 May 2024 13:39:43 +0300 Subject: [PATCH] ob-latex: New custom option `org-babel-latex-process-alist' * lisp/ob-latex.el (org-babel-latex-process-alist): New variable. (org-babel-execute:latex): Override `org-preview-latex-process-alist' when generating png output, making sure that the process yields an actual png image, even when `org-preview-latex-default-process' is non-default. * etc/ORG-NEWS (=ob-latex= now uses a new option ~org-babel-latex-process-alist~ to generate png output): Announce the change. Reported-by: Ihor Radchenko Link: https://orgmode.org/list/87cyretut7.fsf@localhost --- etc/ORG-NEWS | 13 +++++++++++++ lisp/ob-latex.el | 18 ++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 99dd8839c..3c597db40 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -710,6 +710,19 @@ any more. Run ~org-ctags-enable~ to setup hooks and advices: #+end_src ** New and changed options +*** =ob-latex= now uses a new option ~org-babel-latex-process-alist~ to generate png output + +Previously, =ob-latex= used ~org-preview-latex-default-process~ from +~org-preview-latex-process-alist~ to produce png output. Now, the +process settings are separated into a new dedicated option +~org-babel-latex-process-alist~. + +The default value is pulled from =dvipng= process type from +~org-preview-latex-process-alist~, preserving the existing behavior. +However, the output is now immune to changes in +~org-preview-latex-default-process~ and can be customized +independently of the image preview settings. + *** ~org-babel-lua-multiple-values-separator~ The string that separates the values of multi-valued results returned diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el index 866ae1ba1..58051fae1 100644 --- a/lisp/ob-latex.el +++ b/lisp/ob-latex.el @@ -52,6 +52,7 @@ (defvar org-format-latex-options) ; From org.el (defvar org-latex-default-packages-alist) ; From org.el (defvar org-latex-packages-alist) ; From org.el +(defvar org-preview-latex-process-alist) ; From org.el (defvar org-babel-default-header-args:latex '((:results . "latex") (:exports . "results")) @@ -128,6 +129,18 @@ exporting the literal LaTeX source." :group 'org-babel :type '(repeat (string))) +(defcustom org-babel-latex-process-alist + `(,(cons 'png (alist-get 'dvipng org-preview-latex-process-alist))) + "Definitions of external processes for LaTeX result generation. +See `org-preview-latex-process-alist' for more details. + +The following process symbols are recognized: +- `png' :: Process used to produce .png output." + :group 'org-babel + :package-version '(Org . "9.7") + :type '(alist :tag "LaTeX to image backends" + :value-type (plist))) + (defun org-babel-expand-body:latex (body params) "Expand BODY according to PARAMS, return the expanded body." (mapc (lambda (pair) ;; replace variables @@ -169,9 +182,10 @@ This function is called by `org-babel-execute-src-block'." ((and (string-suffix-p ".png" out-file) (not imagemagick)) (let ((org-format-latex-header (concat org-format-latex-header "\n" - (mapconcat #'identity headers "\n")))) + (mapconcat #'identity headers "\n"))) + (org-preview-latex-process-alist org-babel-latex-process-alist)) (org-create-formula-image - body out-file org-format-latex-options in-buffer))) + body out-file org-format-latex-options in-buffer 'png))) ((string= "svg" extension) (with-temp-file tex-file (insert (concat (funcall org-babel-latex-preamble params)