* [PATCH] ob-latex: Added support for including files with a relative path
@ 2022-07-04 19:15 emacs--- via General discussions about Org-mode.
2022-07-05 10:43 ` Daniel Fleischer
0 siblings, 1 reply; 7+ messages in thread
From: emacs--- via General discussions about Org-mode. @ 2022-07-04 19:15 UTC (permalink / raw)
To: Emacs Orgmode
[-- 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)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] ob-latex: Added support for including files with a relative path
2022-07-04 19:15 [PATCH] ob-latex: Added support for including files with a relative path emacs--- via General discussions about Org-mode.
@ 2022-07-05 10:43 ` Daniel Fleischer
2022-07-05 10:52 ` emacs--- via General discussions about Org-mode.
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Fleischer @ 2022-07-05 10:43 UTC (permalink / raw)
To: emacs--- via General discussions about Org-mode.; +Cc: emacs
emacs--- via "General discussions about Org-mode." [2022-07-04 Mon 21:15] wrote:
> 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.
Hi, adding an "input" type of header is one option. What about adding a
call to resolve relative file names instead, thus solving maybe other
needs in addition?
--
Daniel Fleischer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ob-latex: Added support for including files with a relative path
2022-07-05 10:43 ` Daniel Fleischer
@ 2022-07-05 10:52 ` emacs--- via General discussions about Org-mode.
2022-07-05 11:05 ` Ihor Radchenko
0 siblings, 1 reply; 7+ messages in thread
From: emacs--- via General discussions about Org-mode. @ 2022-07-05 10:52 UTC (permalink / raw)
To: Daniel Fleischer; +Cc: emacs--- viaGeneral discussions about Org-mode.
[-- Attachment #1: Type: text/plain, Size: 892 bytes --]
Hi Daniel,
>> 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.
>>
>
> Hi, adding an "input" type of header is one option. What about adding a
> call to resolve relative file names instead, thus solving maybe other
> needs in addition?
>
That was my second approach. I was concerned that forcing all imports with
an absolute path could break existing exports? Correct me if I'm wrong.
Using the :header syntax external files can be loaded in via the old way,
whereas using :inputs all relative paths are resolved.
The downside of course is that we clutter the export settings with a new
parameter.
Kind regards,
Bob
[-- Attachment #2: Type: text/html, Size: 1609 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ob-latex: Added support for including files with a relative path
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
0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2022-07-05 11:05 UTC (permalink / raw)
To: emacs; +Cc: Daniel Fleischer, emacs--- viaGeneral discussions about Org-mode.
emacs--- via "General discussions about Org-mode."
<emacs-orgmode@gnu.org> writes:
>> Hi, adding an "input" type of header is one option. What about adding a
>> call to resolve relative file names instead, thus solving maybe other
>> needs in addition?
>>
> That was my second approach. I was concerned that forcing all imports with
> an absolute path could break existing exports? Correct me if I'm wrong.
> Using the :header syntax external files can be loaded in via the old way,
> whereas using :inputs all relative paths are resolved.
> The downside of course is that we clutter the export settings with a new
> parameter.
Rather than changing paths to absolute, we can simply play with the
working directly for latex process and set it to the directory of the
.org file (unless :dir argument is passed to the latex source block).
This is probably the most expected behavior.
Best,
Ihor
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ob-latex: Added support for including files with a relative path
2022-07-05 11:05 ` Ihor Radchenko
@ 2022-07-05 13:29 ` Daniel Fleischer
2022-07-05 13:50 ` Ihor Radchenko
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Fleischer @ 2022-07-05 13:29 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs, emacs--- viaGeneral discussions about Org-mode.
Ihor Radchenko [2022-07-05 Tue 19:05] wrote:
> Rather than changing paths to absolute, we can simply play with the
> working directly for latex process and set it to the directory of the
> .org file (unless :dir argument is passed to the latex source block).
> This is probably the most expected behavior.
If I understand you correctly, changing the latex processing directory
enables you to use relative paths in macros such as \input{}. If so,
it's as trivial as adding `-cd' flag to `org-latex-pdf-process` when
using `latexmk`.
--
Daniel Fleischer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ob-latex: Added support for including files with a relative path
2022-07-05 13:29 ` Daniel Fleischer
@ 2022-07-05 13:50 ` Ihor Radchenko
0 siblings, 0 replies; 7+ messages in thread
From: Ihor Radchenko @ 2022-07-05 13:50 UTC (permalink / raw)
To: Daniel Fleischer; +Cc: emacs, emacs--- viaGeneral discussions about Org-mode.
Daniel Fleischer <danflscr@gmail.com> writes:
> Ihor Radchenko [2022-07-05 Tue 19:05] wrote:
>
>> Rather than changing paths to absolute, we can simply play with the
>> working directly for latex process and set it to the directory of the
>> .org file (unless :dir argument is passed to the latex source block).
>> This is probably the most expected behavior.
>
> If I understand you correctly, changing the latex processing directory
> enables you to use relative paths in macros such as \input{}. If so,
> it's as trivial as adding `-cd' flag to `org-latex-pdf-process` when
> using `latexmk`.
It would be trivial if org-latex-pdf-process were not a custom variable.
I suspect that we may need to use something similar to what export does.
However, setting the right working directory is what other babel
backends do. The fact that ob-latex is not doing the same is an
unfortunate inconsistency and causes the input issue and can potentially
cause other problems.
Best,
Ihor
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ob-latex: Added support for including files with a relative path
2022-07-06 7:49 emacs--- via General discussions about Org-mode.
@ 2022-07-06 10:18 ` Pedro Andres Aranda Gutierrez
0 siblings, 0 replies; 7+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2022-07-06 10:18 UTC (permalink / raw)
To: emacs; +Cc: Org Mode List, yantar92
[-- Attachment #1: Type: text/plain, Size: 2212 bytes --]
First time to hear that.
I wasn’t aware of it 8-0.
Will need to recheck my projects and settings to see what I was accidentally doing right… in the sense that it was working as intended…
Thx/PA
PS: once again I’ll go to sleep and will have learnt something new (as the Spanish proverb goes)
Enviado desde mi iPhone
> El 6 jul 2022, a las 9:49, emacs@vergauwen.me escribió:
>
>
>
> >>> Hi, adding an "input" type of header is one option. What about adding a
> >>> call to resolve relative file names instead, thus solving maybe other
> >>> needs in addition?
> >>>
> >> That was my second approach. I was concerned that forcing all imports with
> >> an absolute path could break existing exports? Correct me if I'm wrong.
> >> Using the :header syntax external files can be loaded in via the old way,
> >> whereas using :inputs all relative paths are resolved.
> >> The downside of course is that we clutter the export settings with a new
> >> parameter.
> >
> >Rather than changing paths to absolute, we can simply play with the
> >working directly for latex process and set it to the directory of the
> >.org file (unless :dir argument is passed to the latex source block).
> >This is probably the most expected behavior.
> >
> >Best,
> >Ihor
>
> Just my .01 cents...
>
> For Latex stuff I'm using just
>
> #+HEADER: \input{preamble}
>
> and have my preamble.tex in the working directory. (For Beamer stuff it goes in a LATEX_HEADER).
>
> Changing that to
>
> #+HEADER :inputs '("preamble")
>
> well, would be a matter of taste.
> Ox-beamer (ox-latex) executes all latex commands at the current directory of
> your org file, whereas ob-latex uses a temporary file to do its thing.
> (with-temp-file FILE &rest BODY)
> I think this is mostly done to prent metafiles from cluttering your current
> directory.
>
> Different export types, or different user included packages, generate different
> metafiles. This makes an automated cleanup process afterwards a bit more
> complicated I think, if not impossible.
>
> The temporary file makes it hard to add files to the working directory.
>
>
>
>
>
>
>
[-- Attachment #2: Type: text/html, Size: 3668 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-07-06 10:22 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-04 19:15 [PATCH] ob-latex: Added support for including files with a relative path emacs--- via General discussions about Org-mode.
2022-07-05 10:43 ` 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
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.