Juan Manuel Macías writes: >> Ihor Radchenko writes:
>> Would it make sense to make :pdf-process work for png previews as well? > > It would be ideal. The expected value for org-latex-pdf-process is a > command or a list of commands, but org-preview-latex-default-process > expects a plist of various processes and parameters. Maybe with some > conditional? If only the png extension is provided (without the > :imagemagick argument), then the expected value is for > org-preview-latex-default-process. In all other cases, the value is for > org-latex-pdf-process. The argument could then be called simply > :process. E.g.: > > Assuming the user has somewhere (add-to-list > org-preview-latex-process-alist my-process): > > :results file :file foo.png :process 'my-process [or :process '(a plist)] > > In other cases, like this: > > :imagemagick yes :results file :file foo.png :process '("lualatex > -interaction nonstopmode -output-directory %o %f") > > wdyt? I am attaching a new patch with this idea incorporated. I have also changed the name from full-to-pdf to standalone. Best regards, Juan Manuel
>From a7f72015007722e665338c39b9a02d675c31cd93 Mon Sep 17 00:00:00 2001 From: Juan Manuel Macias <maciasch...@posteo.net> Date: Sat, 10 Feb 2024 02:01:08 +0100 Subject: [PATCH] lisp/ob-latex.el: Add two new header args to LaTeX block. * (org-babel-execute:latex): `:process' allows modifying the value of `org-latex-pdf-process' or `org-preview-latex-default-process' in a specific block. If only the `png' extension is provided (without the `:imagemagick' argument), then the expected value is for `org-preview-latex-default-process'. In all other cases, the value is for `org-latex-pdf-process'. This argument has no effect if the conversion is to `HTML'. The `:standalone' argument requires that the LaTeX block contains all the code necessary to be compiled, as if it were an autonomous LaTeX document: the expected result will always be a PDF file. --- lisp/ob-latex.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el index acb83228b..8bec0c661 100644 --- a/lisp/ob-latex.el +++ b/lisp/ob-latex.el @@ -162,6 +162,14 @@ This function is called by `org-babel-execute-src-block'." (height (and fit (cdr (assq :pdfheight params)))) (width (and fit (cdr (assq :pdfwidth params)))) (headers (cdr (assq :headers params))) + (process (cdr (assq :process params))) + (org-preview-latex-default-process (if (and process + (string-suffix-p ".png" out-file) + (not imagemagick)) + process + org-preview-latex-default-process)) + (org-latex-pdf-process (if process process org-latex-pdf-process)) + (standalone (cdr (assq :standalone params))) (in-buffer (not (string= "no" (cdr (assq :buffer params))))) (org-latex-packages-alist (append (cdr (assq :packages params)) org-latex-packages-alist))) @@ -187,6 +195,14 @@ This function is called by `org-babel-execute-src-block'." (list org-babel-latex-pdf-svg-process) extension err-msg log-buf))) (rename-file img-out out-file t)))) + ((and (string= "pdf" extension) standalone) + (with-temp-file tex-file + (insert body)) + (when (file-exists-p out-file) (delete-file out-file)) + (let ((tmp-pdf (org-babel-latex-tex-to-pdf tex-file))) + (let* ((log-buf (get-buffer-create "*Org Babel LaTeX Output*")) + (err-msg "org babel latex failed")) + (rename-file tmp-pdf out-file t)))) ((string-suffix-p ".tikz" out-file) (when (file-exists-p out-file) (delete-file out-file)) (with-temp-file out-file -- 2.43.0