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