Prevent pdflatex from writing a bunch of files

You might not care about these files, but pdflatex does quite a bit. These files hold information collected during the first run(s) and are needed to build the final PDF with correct ToC, references, PDF bookmarks, etc.

Your can delete these files afterwards, e.g. manually or using a front-end tool like latexmk (-c option). However, future compilations of the PDF would then need again several compiler runs.

You can define an output directory for all files using the -output-directory command line argument of pdflatex. After compilation you can then move the PDF in the current directory.

With MiKTeX, you can specify a directory in which all the auxiliary files are put (but not the PDF output) by using the -aux-directory command line argument. You can even combine -output-directory and -aux-directory.


In addition to Martin's answer, I thought it might be useful to explain why LaTeX creates all these extra files. Let's take the example of the .aux file.

Let's say you have a \label in your document and a reference to it somewhere above where the label occurs. When pdflatex reads your .tex file, it reads the \ref first. Now, it doesn't know what to do with this ref: it hasn't yet encountered what it's referring to. Now when pdflatex reaches the label, it makes a note of what the label is referring to. By "makes a note" I mean it writes something to the .aux file that says roughly "when you encounter references to this, this is what is meant".

Then, on a second pdflatex run, when it reaches the reference, it looks in the .aux file and it knows what it is supposed to refer to and can substitute in the relevant text.

Auxiliary files are used for lots of other similar things (like tables of contents, lists of figures and so on). They are annoying, but deleting them after each run would break things. A lot.


You already got lots of very good answers explaining why pdflatex needs all those auxiliary files. However you might still feel frustrated about having to live with all those files polluting a directory where (I'm guessing) you would like to keep all your LaTeX documents and their corresponding .pdf outputs.

The best solution is to keep one directory for each document you have.

You can keep, for example, a main Documents folder and then individual Paper1, Paper2, ... folders; each with their own main.tex file. Then you can happily let LaTeX store whatever auxiliary files it wants in their respective folders. The difference is that now, for you, there is a clear structure of where your documents are.