emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: emacs--- via "General discussions about Org-mode." <emacs-orgmode@gnu.org>
To: Emacs Orgmode <emacs-orgmode@gnu.org>
Subject: [PATCH] ob-latex: Added support for including files with a relative path
Date: Mon, 4 Jul 2022 21:15:55 +0200 (CEST)	[thread overview]
Message-ID: <N69d-2V--3-2@vergauwen.me> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1340 bytes --]

 Dear list, 

in the attachment you find a proposed patch to support including external files
when exporting a latex source block. Currently this was only possible by using a
:header argument. The problem with this approach is that, files needed to be
included with their absolute path.


My proposed change adds support for a :inputs header argument, which expands te
provided file paths to an absolute path before including them.


Example: 
#+HEADER: :file example.pdf
#+HEADER: :inputs '("./input/preamble.tex")
#+BEGIN_src latex
\begin{tikzpicture}
  \draw[->,custom-style] (-3,0) -- (-2,0)
    arc[radius=0.5cm,start angle=-180,endangle=0] (-1,0) -- (1,0)
    arc[radius=0.5cm,start angle=180,end angle=0] (2,0) -- (3,0);
    \filldraw (-1.5,0) circle[radius=1mm];
    \filldraw (1.5,0)circle[radius=1mm];
\end{tikzpicture}
#+END_src

Expands to 

\documentclass[article]...
\input{absolute/path/to/input/preamble.tex}
\begin{document}
\begin{tikzpicture}
  \draw[->,custom-style] (-3,0) -- (-2,0)
    arc[radius=0.5cm,start angle=-180,endangle=0] (-1,0) -- (1,0)
    arc[radius=0.5cm,start angle=180,end angle=0] (2,0) -- (3,0);
    \filldraw (-1.5,0) circle[radius=1mm];
    \filldraw (1.5,0)circle[radius=1mm];
\end{tikzpicture}
\end{document}
Kind regards,
Bob 

[-- Attachment #1.2: Type: text/html, Size: 2610 bytes --]

[-- Attachment #2: 0001-lisp-ob-latex.el-Added-latex-inputs.patch --]
[-- Type: application/octet-stream, Size: 1619 bytes --]

From 42da47c55106e6bf55f46333c7c50daa48b1a67f Mon Sep 17 00:00:00 2001
From: Bob Vergauwen <bob@vergauwen.me>
Date: Mon, 4 Jul 2022 20:46:25 +0200
Subject: [PATCH] lisp/ob-latex.el: Added latex inputs

* lisp/ob-latex.el (org-babel-execute:latex): Added support for
including external latex files. Using the :inputs header, external files
can be specified to be included at the top of the produced tex
file. All relative file paths are resolved before including the files.
(org-babel-header-args:latex): Added the inputs as a possible header argument

TINYCHANGE
---
 lisp/ob-latex.el | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el
index 54816bdc5..f0b466d6d 100644
--- a/lisp/ob-latex.el
+++ b/lisp/ob-latex.el
@@ -65,6 +65,7 @@
     (pdfwidth     . :any)
     (headers      . :any)
     (packages     . :any)
+    (inputs       . :any)
     (buffer       . ((yes no))))
   "LaTeX-specific header arguments.")
 
@@ -146,6 +147,10 @@ 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)))
+	     (inputs (mapcar (lambda (file)
+                           (concat "\\input{" (expand-file-name file) "}"))
+                         (cdr (assq :inputs params))))
+             (headers (append headers inputs))
 	     (in-buffer (not (string= "no" (cdr (assq :buffer params)))))
 	     (org-latex-packages-alist
 	      (append (cdr (assq :packages params)) org-latex-packages-alist)))
-- 
2.30.1 (Apple Git-130)


             reply	other threads:[~2022-07-04 19:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-04 19:15 emacs--- via General discussions about Org-mode. [this message]
2022-07-05 10:43 ` [PATCH] ob-latex: Added support for including files with a relative path Daniel Fleischer
2022-07-05 10:52   ` emacs--- via General discussions about Org-mode.
2022-07-05 11:05     ` Ihor Radchenko
2022-07-05 13:29       ` Daniel Fleischer
2022-07-05 13:50         ` Ihor Radchenko
  -- strict thread matches above, loose matches on Subject: below --
2022-07-06  7:49 emacs--- via General discussions about Org-mode.
2022-07-06 10:18 ` Pedro Andres Aranda Gutierrez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=N69d-2V--3-2@vergauwen.me \
    --to=emacs-orgmode@gnu.org \
    --cc=emacs@vergauwen.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).