emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: Uwe Brauer <oub@mat.ucm.es>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: how to export an org file, to 2 different locations (in to different formats)
Date: Sat, 28 May 2022 00:18:18 +0000	[thread overview]
Message-ID: <87y1ymqzlh.fsf@posteo.net> (raw)
In-Reply-To: <87a6b2stoy.fsf@posteo.net> ("Juan Manuel Macías"'s message of "Fri, 27 May 2022 18:42:53 +0000")

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

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)))
			      ;; 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
				    ;; 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.
			       "Output file: " pub-dir nil nil nil
			       (lambda (n) (string= extension (file-name-extension n t))))))
			   ;; Build file name.  Enforce EXTENSION over whatever user
			   ;; may have come up with.  PUB-DIR, if defined, always has
			   ;; precedence over any provided path.
			    (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)
  (if (and my-latex-export-path my-html-export-path)
      (cond ((equal extension ".tex")
	    ((equal extension ".html")
    (apply old-func args)))

Best regards,

Juan Manuel 

  reply	other threads:[~2022-05-28  0:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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:

  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=87y1ymqzlh.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=oub@mat.ucm.es \


* 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


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).