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!

scaramouche
  • 1,772
  • 10
  • 24
  • 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 -f %f"`. – wvxvw Dec 02 '14 at 06: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). – scaramouche Dec 02 '14 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 Dec 03 '14 at 17:22
  • To automatically remove the temporary files after export, see http://emacs.stackexchange.com/a/24000/8541 – Mark Jan 03 '17 at 16:30

1 Answers1

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.

user2699
  • 2,181
  • 16
  • 32
  • This works well, but only if `pdflatex` is not called with an `-output-directory` argument in the `org-latex-pdf-process` list. – Mark Jan 03 '17 at 16:22
  • @Mark, that seems like it would override it and use `output-directory`, does it? – user2699 Jan 07 '17 at 02: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 Jan 10 '17 at 04: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 Jan 25 '17 at 14:36