6

Exporting to Beamer from org-mode creates a myriad of temporary files (the .tex file + files ending in .aux, .log, .toc, .fls, .nav, .vrb, etc.).

Most LaTeX implementations now have an option (-outdir) to keep all these temporary files outside from the current directory.

How can the export to Beamer be modified to use this facility?

Many thanks!

4
  • I didn't try it, but this is how'd I go about it: try setting org-latex-pdf-process to something like "latexmk -pdflatex='pdflatex -shell-escape -interaction nonstopmode' -pdf -bibtex -outdir <some-directory> -f %f".
    – wvxvw
    Commented Dec 2, 2014 at 6:16
  • Thank you for your reply, @wvxvw. This is a good starting point, but it has two problems: (1) the .tex is still generated in the local directory and (2) the PDF viewer does not open the generated PDF (as it does not know where it was created). Commented Dec 2, 2014 at 14:21
  • Sorry, it's taking so long... I tried to follow Org export procedure and I think that you want to look into C-h f org-export-output-file-name, it talks about setting name for the file being exported (this would be the TeX file), this function also happens to return this name to whoever called it, which, I guess, would be the function which will try to open the PDF. Sorry, I didn't have the time to actually try it.
    – wvxvw
    Commented Dec 3, 2014 at 17:22
  • To automatically remove the temporary files after export, see emacs.stackexchange.com/a/24000/8541
    – Mark
    Commented Jan 3, 2017 at 16:30

1 Answer 1

7

I came up with this recently to solve the problem of export cluttering the current directory, although it is not the solution asked for, I think it belongs here, plus it fixes it for any files org-export generates.

(defvar org-export-output-directory-prefix "export_" "prefix of directory used for org-mode export")

(defadvice org-export-output-file-name (before org-add-export-dir activate)
  "Modifies org-export to place exported files in a different directory"
  (when (not pub-dir)
      (setq pub-dir (concat org-export-output-directory-prefix (substring extension 1)))
      (when (not (file-directory-p pub-dir))
       (make-directory pub-dir))))

change org-export-output-directory-prefix to something of your liking. Let me know if it works with beamer.

4
  • This works well, but only if pdflatex is not called with an -output-directory argument in the org-latex-pdf-process list.
    – Mark
    Commented Jan 3, 2017 at 16:22
  • @Mark, that seems like it would override it and use output-directory, does it?
    – user2699
    Commented Jan 7, 2017 at 2:39
  • 1
    in org-mode version 9.0-elpa, the default org-latex-pdf-process variable executes the following 3 times: %latex -interaction nonstopmode -output-directory %o %f. Unless the -output-directory %o is removed, an error is produced when exporting to LaTeX, where LaTeX complains that it can't write on file filename.log.
    – Mark
    Commented Jan 10, 2017 at 4:03
  • 1
    Also, when using biber in org-latex-pdf-process, I needed to modify the command to be biber --output-directory .. %b so that any .bib files are visible to biber. An alternative to this is (cd .. ; biber %o/%b) which may also work for bibtex, and assumes that emacs is using a POSIX shell to execute commands.
    – Mark
    Commented Jan 25, 2017 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.