emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [patch] Add two new header args to LaTeX block
@ 2024-02-10  1:58 Juan Manuel Macías
  2024-02-10 14:37 ` Ihor Radchenko
  0 siblings, 1 reply; 16+ messages in thread
From: Juan Manuel Macías @ 2024-02-10  1:58 UTC (permalink / raw)
  To: orgmode

[-- Attachment #1: Type: text/plain, Size: 1796 bytes --]

The attached patch adds two new header args to the LaTeX block:

- `:pdf-process' allows modifying the value of `org-latex-pdf-process'
  locally to the block. This can be useful for evaluating a given block
  with another LaTeX compiler, or even using some custom script.
  Example:

  #+begin_src latex :pdf-process '("lualatex -shell-escape -interaction nonstopmode -output-directory %o %f")
  \textbf{hello world}
  #+end_src

- `:full-to-pdf' makes the block like a standalone LaTeX document, which
  should contain everything needed to be compiled, from \documentclass{}
  to \end{document}. Example:

  #+begin_src latex :full-to-pdf yes
  \documentclass{article}  
  \begin{document}
  \textbf{hello world}
  \end{document}
  #+end_src

  I think both arguments can have many practical uses. For example, to
  compile separately and load multiple subdocuments, with different
  preambles:

   #+NAME: doc1
   #+begin_src org :exports none :results latex
    ,#+include: some-document.org
   #+end_src

  #+begin_src latex :noweb yes :results silent file :file file.pdf :full-to-pdf yes
    \documentclass{article}
    \usepackage[spanish]{babel}
    \usepackage{fontspec}
    \setmainfont{Vollkorn}
    \begin{document}
    <<doc1()>>
    \end{document}
  #+end_src

  #+latex: \includepdf{file.pdf}
  
  Or even to evaluate ConTeXt code within a LaTeX block:

  #+begin_src latex :full-to-pdf yes :results raw file :file file.pdf :pdf-process '("cd %o && context %f")
  \starttext
  \startsection[title={Testing ConTeXt}]
  Lorem ipsum dolor.
  \stopsection
  \stoptext
  #+end_src


Best regards,

Juan Manuel 

-- 
Juan Manuel Macías -- Composición tipográfica, tratamiento de datos, diseño editorial y ortotipografía


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ob-latex.el-Add-two-new-header-args-to-LaTeX-bl.patch --]
[-- Type: text/x-patch, Size: 2148 bytes --]

From fe1b40e2b22e2c668440bea13feda0ab7923bdd8 Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@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): `:pdf-process' allows modifying the value
of `org-latex-pdf-process' in a specific block.  The `:full-to-pdf'
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 | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el
index acb83228b..118d81338 100644
--- a/lisp/ob-latex.el
+++ b/lisp/ob-latex.el
@@ -162,6 +162,9 @@ 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)))
+             (pdf-process (cdr (assq :pdf-process params)))
+	     (org-latex-pdf-process (if pdf-process pdf-process org-latex-pdf-process))
+	     (full-to-pdf (cdr (assq :full-to-pdf 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 +190,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) full-to-pdf)
+	  (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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-02-19 13:25 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-10  1:58 [patch] Add two new header args to LaTeX block Juan Manuel Macías
2024-02-10 14:37 ` Ihor Radchenko
2024-02-10 15:20   ` Juan Manuel Macías
2024-02-10 16:35     ` Ihor Radchenko
2024-02-10 17:48       ` Juan Manuel Macías
2024-02-10 19:35         ` Juan Manuel Macías
2024-02-10 21:07           ` Ihor Radchenko
2024-02-10 23:34             ` Juan Manuel Macías
2024-02-11 14:43               ` Ihor Radchenko
2024-02-11 20:01                 ` Juan Manuel Macías
2024-02-13 13:42                   ` Ihor Radchenko
2024-02-13 20:25                     ` Juan Manuel Macías
2024-02-18 14:20                       ` Ihor Radchenko
2024-02-18 13:43                         ` Juan Manuel Macías
2024-02-19 11:15                           ` Ihor Radchenko
2024-02-19 13:24                             ` Juan Manuel Macías

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).