[Tex/LaTex] Deleting external/auxiliary files

auxiliary-filesexternal files

Is there a way to make TeX delete files?

In my document a lot of auxiliary files are created and it would be wonderful to have them removed after their content has been used.

Best Answer

if you want get rid of those files in your document directory then use the optional argument -output-directory=whatever. Then all auxiliary files and the pdf are saved in that directory. For example what I use:

pdflatex -output-directory=target <file>

then my <file>.pdf is also in target, but I always use a softlink ln -s target/<file>.pdf then I have it in my documents directory, too. But as Martin already pointed out, deleting the auxiliary files makes only sense when you are really sure that your pdf file is finished.

If you want to copy the created pdf then use

\usepackage{shellesc}
\AtEndDocument{\ShellEscape{cp /<target>/\jobname.pdf /home/voss/}}

replace /home/voss/ with the directory where the pdf should be copied to. Then run the document with

pdflatex --shell-escape -output-directory=<target> <file>

However, writing a small script seems to be easier.

Related Question