As said by others, it's not really a great idea to (automatically) remove
.log and similar files. Some of them provide important info in case things go wrong (for example
.log), others are needed for things to actually work when you compile your document multiple times (
.toc etc.). Deleting them can break things.
However, if this is related to a desire to have a cleaner working directory, there are a few ways to accomplish that (if not, then apologies for being presumptuous):
- For those who, like me, do things by hand, you can compile your document with the
- Or you can configure TeXMaker to use an output directory for your files. Other tools may have similar options; I'm no expert on TeX IDEs.
Note, however, that both of these solutions will also put the
.pdf file in the output/build directory.
The first option works thusly:
pdflatex -output-directory=build yourdocument
(or, instead of
build, whichever other output directory you want to use)
Before compilation, make sure the
build directory exists. Your working directory will look as follows:
After compilation, it will look like this:
│ ├── yourdocument.aux
│ ├── yourdocument.pdf
│ └── yourdocument.log
Texmaker (unsure on other IDEs)
In Texmaker, go to the menu option Configure Texmaker and select the highlighted option:
Note that texmaker will create the
build directory automatically, unlike
pdflatex in console mode.
If you want to have your
pdf and your
tex file in the same directory, but all the other files in the
build dir, manual intervention is required, as far as I'm aware. I usually use Makefiles to automate my process, but I'll admit that that might not necessarily be a solution for everyone.
Still, a short example for such a Makefile:
mkdir -p build
pdflatex -output-directory=build mydocument
mv build/mydocument.pdf ./
Then I can just type
make in the working directory on the terminal and it will do the right thing, giving me this situation:
│ ├── mydocument.aux
│ └── mydocument.log