* how to export an org file, to 2 different locations (in to different formats)
@ 2022-05-27 16:23 Uwe Brauer
2022-05-27 18:42 ` Juan Manuel Macías
2022-05-31 15:10 ` how to export an org file, to 2 different locations (in to different formats) Nick Dokos
0 siblings, 2 replies; 11+ messages in thread
From: Uwe Brauer @ 2022-05-27 16:23 UTC (permalink / raw)
To: emacs-orgmode
Hi
Currently I use
#+EXPORT_FILE_NAME: /home/oub/Desktop/some-stuff.html
To export my org file in html format to that location.
But I would also like to export it as a latex file to a different
location, without modifying the above line, or to be more precise to add
a different location, like
1. if export to latex use that folder
2. If export to html use this folder
Anybody know about such a functionality?
Thanks and regards
Uwe Brauer
--
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military.
I support the ban of Russia from SWIFT.
I support the EU membership of the Ukraine.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to export an org file, to 2 different locations (in to different formats)
2022-05-27 16:23 how to export an org file, to 2 different locations (in to different formats) Uwe Brauer
@ 2022-05-27 18:42 ` Juan Manuel Macías
2022-05-28 0:18 ` Juan Manuel Macías
` (2 more replies)
2022-05-31 15:10 ` how to export an org file, to 2 different locations (in to different formats) Nick Dokos
1 sibling, 3 replies; 11+ messages in thread
From: Juan Manuel Macías @ 2022-05-27 18:42 UTC (permalink / raw)
To: Uwe Brauer; +Cc: orgmode
Hi Uwe,
Uwe Brauer writes:
> Hi
>
> Currently I use
> #+EXPORT_FILE_NAME: /home/oub/Desktop/some-stuff.html
>
> To export my org file in html format to that location.
>
> But I would also like to export it as a latex file to a different
> location, without modifying the above line, or to be more precise to add
> a different location, like
>
> 1. if export to latex use that folder
>
> 2. If export to html use this folder
>
> Anybody know about such a functionality?
>
> Thanks and regards
>
> Uwe Brauer
One (pedestrian) way to achieve it, with this function:
(defun my-org/export-to-path (backend export-path extension)
(org-element-map (org-element-parse-buffer) 'keyword
(lambda (k)
(when (string= (org-element-property :key k) "EXPORT_FILE_NAME")
(let ((value (org-element-property :value k)))
(org-export-to-file backend
(format
"%s%s.%s"
export-path
value extension)))))))
And then you could evaluate it inside a block in your document, with the
chosen arguments. For example:
#+EXPORT_FILE_NAME: myfile
#+begin_src emacs-lisp :exports none :eval never-export :results silent
(my-org/export-to-path 'html "~/Desktop/" "html")
#+end_src
Best regards,
Juan Manuel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to export an org file, to 2 different locations (in to different formats)
2022-05-27 18:42 ` Juan Manuel Macías
@ 2022-05-28 0:18 ` Juan Manuel Macías
2022-05-28 6:36 ` Uwe Brauer
2022-05-28 6:21 ` Uwe Brauer
2022-05-28 6:47 ` [ODT?] (was: how to export an org file, to 2 different locations (in to different formats)) Uwe Brauer
2 siblings, 1 reply; 11+ messages in thread
From: Juan Manuel Macías @ 2022-05-28 0:18 UTC (permalink / raw)
To: Uwe Brauer; +Cc: orgmode
Juan Manuel Macías writes:
> One (pedestrian) way to achieve it, with this function:
I think it can be done better this way, defining an advice around
'org-export-output-file-name'.
In your org file you should add these two local variables:
# my-latex-export-path: "~/path/to/myfile.tex"
# my-html-export-path "~/path/to/myfile.html"
And this is the define-advice code. It should export to one or another path/file every
time you export your document to LaTeX or html. I haven't tried it much:
(define-advice org-export-output-file-name (:around (old-func extension &rest args))
(setq old-func (lambda (extension &optional subtreep pub-dir)
(let* ((visited-file (buffer-file-name (buffer-base-buffer)))
(base-name
(concat
(file-name-sans-extension
(or
;; Check EXPORT_FILE_NAME subtree property.
(and subtreep (org-entry-get nil "EXPORT_FILE_NAME" 'selective))
;; Check #+EXPORT_FILE_NAME keyword.
(org-with-point-at (point-min)
(catch :found
(let ((case-fold-search t))
(while (re-search-forward
"^[ \t]*#\\+EXPORT_FILE_NAME:[ \t]+\\S-" nil t)
(let ((element (org-element-at-point)))
(when (eq 'keyword (org-element-type element))
(throw :found
(org-element-property :value element))))))))
;; Extract from buffer's associated file, if any.
(and visited-file
(file-name-nondirectory
;; For a .gpg visited file, remove the .gpg extension:
(replace-regexp-in-string "\\.gpg\\'" "" visited-file)))
;; Can't determine file name on our own: ask user.
(read-file-name
"Output file: " pub-dir nil nil nil
(lambda (n) (string= extension (file-name-extension n t))))))
extension))
(output-file
;; Build file name. Enforce EXTENSION over whatever user
;; may have come up with. PUB-DIR, if defined, always has
;; precedence over any provided path.
(cond
(pub-dir (concat (file-name-as-directory pub-dir)
(file-name-nondirectory base-name)))
((file-name-absolute-p base-name) base-name)
(t base-name))))
;; If writing to OUTPUT-FILE would overwrite original file, append
;; EXTENSION another time to final name.
(if (and visited-file (file-equal-p visited-file output-file))
(concat output-file extension)
output-file))))
(if (and my-latex-export-path my-html-export-path)
(cond ((equal extension ".tex")
my-latex-export-path)
((equal extension ".html")
my-html-export-path))
(apply old-func args)))
Best regards,
Juan Manuel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to export an org file, to 2 different locations (in to different formats)
2022-05-28 0:18 ` Juan Manuel Macías
@ 2022-05-28 6:36 ` Uwe Brauer
2022-05-28 7:23 ` Juan Manuel Macías
0 siblings, 1 reply; 11+ messages in thread
From: Uwe Brauer @ 2022-05-28 6:36 UTC (permalink / raw)
To: Juan Manuel Macías; +Cc: Uwe Brauer, orgmode
[-- Attachment #1: Type: text/plain, Size: 1353 bytes --]
>>> "JMM" == Juan Manuel Macías <maciaschain@posteo.net> writes:
> Juan Manuel Macías writes:
>> One (pedestrian) way to achieve it, with this function:
> I think it can be done better this way, defining an advice around
> 'org-export-output-file-name'.
> In your org file you should add these two local variables:
> # my-latex-export-path: "~/path/to/myfile.tex"
> # my-html-export-path "~/path/to/myfile.html"
> And this is the define-advice code. It should export to one or another path/file every
> time you export your document to LaTeX or html. I haven't tried it much:
Thanks, that looks even more convenient!
I tried to test it with
#+begin_example
# my-latex-export-path: "./myfile2.tex"
# my-html-export-path "~/Desktop/myfile2.html"
,#+begin_src emacs-lisp :exports none :eval never-export :results silent
(my-org/export-to-path 'html "~/Desktop/" "html")
,#+end_src
,#+begin_src emacs-lisp :exports none :eval never-export :results silent
(my-org/export-to-path 'latex "./" "tex")
,#+end_src
,* Excuses
Jim: Which was? Sir Humphrey:
#+end_example
When I run it I obtain
if: Symbol’s value as variable is void: my-latex-export-path
Another point is if I decide to export it to ods, I need to modify that
advice, but I agree the new function is more convenient.
Uwe
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to export an org file, to 2 different locations (in to different formats)
2022-05-28 6:36 ` Uwe Brauer
@ 2022-05-28 7:23 ` Juan Manuel Macías
2022-05-28 8:40 ` Uwe Brauer
0 siblings, 1 reply; 11+ messages in thread
From: Juan Manuel Macías @ 2022-05-28 7:23 UTC (permalink / raw)
To: Uwe Brauer; +Cc: orgmode
Uwe Brauer writes:
> When I run it I obtain
> if: Symbol’s value as variable is void: my-latex-export-path
>
> Another point is if I decide to export it to ods, I need to modify that
> advice, but I agree the new function is more convenient.
You must add the variables to the document as local variables, at the
end of the document, like this:
# Local Variables:
# my-latex-export-path: "~/path/myfile.tex"
# my-html-export-path: "~/path/myfile.html"
# End:
But (it's important, I didn't tell you, sorry) before you must globally
define the variables with nil value, so that you don't get an error in
other documents:
(setq my-latex-export-path nil
my-html-export-path nil)
With this 'define-advice' procedure you don't need the other code I gave
you. You can export in the usual way, using the dispatcher. The only
difference is that in any document where these variables exist, the
resulting file will be saved in the directory/name specified in the
variables, depending on whether you export to latex or html.
To add more cases, like odt, simply:
(1) you define a new variable:
(setq my-latex-export-path nil
my-html-export-path nil
my-odt-export-path nil)
and locally:
# Local Variables:
# my-latex-export-path: "~/path/myfile.tex"
# my-html-export-path: "~/path/myfile.html"
# my-odt-export-path: "~/path/myfile.html"
# End:
(2) And you add a new condition at the end of the define-advice:
[...]
(if (and my-latex-export-path
my-html-export-path
my-odt-export-path)
(cond ((equal extension ".tex")
my-latex-export-path)
((equal extension ".html")
my-html-export-path)
((equal extension ".odt")
my-odt-export-path))
(apply old-func args)))
It means that: if those variables exist, it returns as a result the
path/name that you have specified for each case. Otherwise, the
org-export-output-file-name function is executed normally.
Best regards,
Juan Manuel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to export an org file, to 2 different locations (in to different formats)
2022-05-28 7:23 ` Juan Manuel Macías
@ 2022-05-28 8:40 ` Uwe Brauer
2022-05-28 9:06 ` Juan Manuel Macías
2022-05-29 11:44 ` Ihor Radchenko
0 siblings, 2 replies; 11+ messages in thread
From: Uwe Brauer @ 2022-05-28 8:40 UTC (permalink / raw)
To: Juan Manuel Macías; +Cc: Uwe Brauer, orgmode
[-- Attachment #1: Type: text/plain, Size: 1275 bytes --]
>>> "JMM" == Juan Manuel Macías <maciaschain@posteo.net> writes:
> Uwe Brauer writes:
>> When I run it I obtain
>> if: Symbol’s value as variable is void: my-latex-export-path
>>
>> Another point is if I decide to export it to ods, I need to modify that
>> advice, but I agree the new function is more convenient.
> You must add the variables to the document as local variables, at the
> end of the document, like this:
> # Local Variables:
> # my-latex-export-path: "~/path/myfile.tex"
> # my-html-export-path: "~/path/myfile.html"
> # End:
Aha, I see, thanks
Just one observation, while this is more convenient your other method has the benefit that it allows me to export to 2 files in different locations having the *same* extension like
> # my-latex-export-path: "~/path/myfile1.tex"
> # my-latex-export-path: "~/path/myfile2.tex"
Which seems more complicated in the other approach.
I have also to confess, that I usually am I bit hesitant to use defadvice since it changes the vanilla function, and might cause problems, but maybe this is just me.
In any case thanks for both solution, that was very generous and helpful.
Developers: why to include some of this code in a addon file, if Juan agrees of course!
Uwe
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to export an org file, to 2 different locations (in to different formats)
2022-05-28 8:40 ` Uwe Brauer
@ 2022-05-28 9:06 ` Juan Manuel Macías
2022-05-29 11:44 ` Ihor Radchenko
1 sibling, 0 replies; 11+ messages in thread
From: Juan Manuel Macías @ 2022-05-28 9:06 UTC (permalink / raw)
To: Uwe Brauer; +Cc: orgmode
Uwe Brauer writes:
> I have also to confess, that I usually am I bit hesitant to use
> defadvice since it changes the vanilla function, and might cause
> problems, but maybe this is just me.
You are absolutely right, and I confess that I would have the same
precautions :-). Also, the defadvice code is very poorly tested, and is
likely to cause some collateral kills... If you need it for specific use
cases, you can try evaluating it only for specific sessions, instead of
leaving it in your init file. Or make a mode that turns it on or off.
Best regards,
Juan Manuel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to export an org file, to 2 different locations (in to different formats)
2022-05-28 8:40 ` Uwe Brauer
2022-05-28 9:06 ` Juan Manuel Macías
@ 2022-05-29 11:44 ` Ihor Radchenko
1 sibling, 0 replies; 11+ messages in thread
From: Ihor Radchenko @ 2022-05-29 11:44 UTC (permalink / raw)
To: Uwe Brauer; +Cc: Juan Manuel Macías, orgmode
Uwe Brauer <oub@mat.ucm.es> writes:
> In any case thanks for both solution, that was very generous and helpful.
>
> Developers: why to include some of this code in a addon file, if Juan agrees of course!
A more canonical solution would be writing
org-export-filter-options-functions that set :output-file export option
directly.
Best,
Ihor
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to export an org file, to 2 different locations (in to different formats)
2022-05-27 18:42 ` Juan Manuel Macías
2022-05-28 0:18 ` Juan Manuel Macías
@ 2022-05-28 6:21 ` Uwe Brauer
2022-05-28 6:47 ` [ODT?] (was: how to export an org file, to 2 different locations (in to different formats)) Uwe Brauer
2 siblings, 0 replies; 11+ messages in thread
From: Uwe Brauer @ 2022-05-28 6:21 UTC (permalink / raw)
To: Juan Manuel Macías; +Cc: Uwe Brauer, orgmode
[-- Attachment #1: Type: text/plain, Size: 1175 bytes --]
> Hi Uwe,
> Uwe Brauer writes:
> One (pedestrian) way to achieve it, with this function:
> (defun my-org/export-to-path (backend export-path extension)
> (org-element-map (org-element-parse-buffer) 'keyword
> (lambda (k)
> (when (string= (org-element-property :key k) "EXPORT_FILE_NAME")
> (let ((value (org-element-property :value k)))
> (org-export-to-file backend
> (format
> "%s%s.%s"
> export-path
> value extension)))))))
> And then you could evaluate it inside a block in your document, with the
> chosen arguments. For example:
> #+EXPORT_FILE_NAME: myfile
> #+begin_src emacs-lisp :exports none :eval never-export :results silent
> (my-org/export-to-path 'html "~/Desktop/" "html")
> #+end_src
Very nice I run a test with
#+begin_src emacs-lisp :exports none :eval never-export :results silent
(my-org/export-to-path 'html "~/Desktop/" "html")
#+end_src
#+begin_src emacs-lisp :exports none :eval never-export :results silent
(my-org/export-to-path 'latex "./" "tex")
#+end_src
And it works nicely, thanks a lot, simplifies my workflow quite a bit.
Uwe
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* [ODT?] (was: how to export an org file, to 2 different locations (in to different formats))
2022-05-27 18:42 ` Juan Manuel Macías
2022-05-28 0:18 ` Juan Manuel Macías
2022-05-28 6:21 ` Uwe Brauer
@ 2022-05-28 6:47 ` Uwe Brauer
2 siblings, 0 replies; 11+ messages in thread
From: Uwe Brauer @ 2022-05-28 6:47 UTC (permalink / raw)
To: Juan Manuel Macías; +Cc: Uwe Brauer, orgmode
[-- Attachment #1: Type: text/plain, Size: 799 bytes --]
> Hi Uwe,
> Uwe Brauer writes:
> One (pedestrian) way to achieve it, with this function:
I tried the following
#+begin_example
#+EXPORT_FILE_NAME: myfile-office
#+begin_src emacs-lisp :exports none :eval never-export :results silent
(my-org/export-to-path 'html "~/Desktop/" "html")
#+end_src
#+begin_src emacs-lisp :exports none :eval never-export :results silent
(my-org/export-to-path 'latex "./" "tex")
#+end_src
#+begin_src emacs-lisp :exports none :eval never-export :results silent
(my-org/export-to-path 'odt "./" "odt")
#+end_src
* Excuses
Jim: Which was? Sir Humphrey:
#+end_example
But then the export to odt, did not work as expected the file was too small, but maybe odt is not the right setting for the export to LO/OO.
Uwe
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: how to export an org file, to 2 different locations (in to different formats)
2022-05-27 16:23 how to export an org file, to 2 different locations (in to different formats) Uwe Brauer
2022-05-27 18:42 ` Juan Manuel Macías
@ 2022-05-31 15:10 ` Nick Dokos
1 sibling, 0 replies; 11+ messages in thread
From: Nick Dokos @ 2022-05-31 15:10 UTC (permalink / raw)
To: emacs-orgmode
Uwe Brauer <oub@mat.ucm.es> writes:
> Hi
>
> Currently I use
> #+EXPORT_FILE_NAME: /home/oub/Desktop/some-stuff.html
>
> To export my org file in html format to that location.
>
> But I would also like to export it as a latex file to a different
> location, without modifying the above line, or to be more precise to add
> a different location, like
>
> 1. if export to latex use that folder
>
> 2. If export to html use this folder
>
> Anybody know about such a functionality?
>
org-publish?
You should be able to write a simple publishing config file to do that.
> Thanks and regards
>
> Uwe Brauer
--
Nick
"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2022-05-31 15:12 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-27 16:23 how to export an org file, to 2 different locations (in to different formats) Uwe Brauer
2022-05-27 18:42 ` Juan Manuel Macías
2022-05-28 0:18 ` Juan Manuel Macías
2022-05-28 6:36 ` Uwe Brauer
2022-05-28 7:23 ` Juan Manuel Macías
2022-05-28 8:40 ` Uwe Brauer
2022-05-28 9:06 ` Juan Manuel Macías
2022-05-29 11:44 ` Ihor Radchenko
2022-05-28 6:21 ` Uwe Brauer
2022-05-28 6:47 ` [ODT?] (was: how to export an org file, to 2 different locations (in to different formats)) Uwe Brauer
2022-05-31 15:10 ` how to export an org file, to 2 different locations (in to different formats) Nick Dokos
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).