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.
You can put advice after the function to delete the intermediate file like this:
(advice-add 'org-latex-compile :after #'delete-file)
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:
and then put the following line in this file
~\.latexmkrc so as to cover all temp files, not just
@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
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-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.