I use org-mode to export PDF. It does it through LaTeX ; fine.
So I get .pdf file and .tex files.
Only the PDF is interesting to me. Any setting/way that org-mode cleanup the .tex files by itself (or store it in some temporary folder) ?
You can simply customize the variable org-latex-logfiles-extensions
to let org to delete those auxiliary files after export automatically. i.e.
(setq org-latex-logfiles-extensions (quote ("lof" "lot" "tex~" "aux" "idx" "log" "out" "toc" "nav" "snm" "vrb" "dvi" "fdb_latexmk" "blg" "brf" "fls" "entoc" "ps" "spl" "bbl")))
Add the extension which you want to delete to the variable.
Or, to avoid having to list all extensions (given that many may already be in there by default), use (add-to-list...)
instead of (setq...)
. For example:
(require 'ox-latex)
(add-to-list 'org-latex-logfiles-extensions "tex")
In the above, the (require 'ox-latex)
is there to ensure that variable org-latex-logfiles-extensions
exists before we try to add to it. (See comments to this answer below, in particular from @xeruf).
(add-hook 'org-mode-hook (lambda ()(add-to-list 'org-latex-logfiles-extensions "tex")))
Commented
Jun 21, 2016 at 15:03
add-to-list
, The var has to be pre-existent, which is only the case after org-mode has been initialized.
Commented
Jun 22, 2016 at 10:26
org-latex-remove-logfiles
is non-nil: it is t
by default, but if the files are not deleted, its value might have been changed. Also, this only cleans the various files that latex produces. It does not clean e.g. the subdirectories that org itself (or emacs) might produce.
This is a simple question but has not so simple answers. The temp files are used repeatedly in the production of pdf output. Neither AUCTeX nor ORG knows when it is safe to delete them. Hence they are left there for manual deletion after ascertaining if they are no longer needed.
Here are a few ways to speed up the manual deletion process. A simple shell command will do the job without too much fuss (add other extensions as needed):
(defun clear-latex-temp-files () (shell-command "rm -rf *.tex *.prv preview.fmt"))
Use latexmk (instead of pdflatex) for generating your pdf so you can use the -c
option to delete the temp files:
latexmk -c
and then put the following line in this file ~\.latexmkrc
so as to cover all temp files, not just *.tex
and *.prv
:
@generated_exts = qw(aux idx ind lof lot out toc acn acr alg glg glo gls ist);
You can add other temp files (.synctex .gz .nav .vrb .snm .blg -blx .bib .bbl .run .xml) depending on your needs. This is the most customizable option.
To avoid this complication for simple org files, you can use the builtin -output-directory
option of pdflatex.
pdflatex -output-directory=target <file>
Which will also put the pdf output there in the target directory. You can then move the pdf file out of there once you are satisfied it was generated properly. All the deletable files are all in one location that can be purged periodically.
Why not use a macro to delete-file
after org-latex-compile
? Because that may sometimes delete the temp files prematurely. You may end up with broken links, unlinked biblio entries, unlinked chapter headings in TOC, and unfinished indexes, list of tables, list of figures. See the org-mode documentation string for C-h f org-latex-compile
:
The reason why this is a list is that it usually takes several runs of ‘pdflatex’, maybe mixed with a call to ‘bibtex’. Org does not have a clever mechanism to detect which of these commands have to be run to get to a stable result, and it also does not do any error checking.
org-latex-remove-logfiles
doc) ; how could it still need the .tex ? I'd love to understand your point, but please sow me a problematic example.
Commented
Jun 23, 2016 at 22:40
I set org-latex-pdf-process
to something like:
latexmk -outdir=/tmp/latexmk -f -pdf %F; mv %f /tmp/latexmk; mv /tmp/latexmk/%b.pdf %o
This way I keep all the intermediate files in a "hidden" place to accelerate successive compilations but only the pdf is kept at the original place.
You can put advice after the function to delete the intermediate file like this:
(advice-add 'org-latex-compile :after #'delete-file)