Search code examples
shelllatex

Automatically remove generated latex (junk) files after compilation?


I was wondering whether there is simple command to delete all unnecessary files generated during the latex compilation process, e.g. .aux, .log, etc.

It would be great to chain it to the regular Latex build commands, so that after I hit "Compile", the junk files are deleted.

As an editing tool, I'm using TeXstudio.


Solution

  • I created a shell script that does exactly what you want. It will work on Mac and Linux; with some adjustments Windows should be possible too. Download the file "cleanlatexjunk.sh" from my repository and follow the instructions:

    https://github.com/cgraumann/LatexUtils

    1. Open Preferences/Build in TexStudio
    2. Select Advanced options at the bottom
    3. Add a new user command with the name cleanjunk
    4. As the command, enter: "/PATH/TO/SCRIPT/cleanlatexjunk.sh" -fp ?me ?a) and change /PATH/TO/SCRIPT/ accordingly
    5. In the meta-command for Build & View add | txs:///compile | txs:///compile | txs:///cleanjunk at the end

    Now every build & view execution should result in a clean workspace :-)

    Edit: As mentioned by Werner in the comment, the "junk" files are of course needed during the build process. Therefore the suggested command in step 5 includes two additional compile runs. This assures that all TOCs and links are rendered correctly.