When I do latexmk -c foo.tex, latexmk cleans up as expected. I tried to configure latexmkrc so that this would happen automatically. Here's my latexmkrc file:

$pdf_mode = 1;
$silent = 1;
$cleanup_mode = 2;

However, when I run latexmk, all of the other files (foo.log, foo.aux, etc) are still there. What am I doing wrong?

  • May I ask why you want to do this? This means that next time you compile it has to run several times to get references etc up to date. While leaving the aux files it might only take one compilation. – daleif Jan 28 '15 at 16:23
  • @daleif my use of latex is not as sophisticated. I use it to take notes, not write papers. – jchun Jan 29 '15 at 2:46
  • I still do not see any reason to delete those files all the time – daleif Jan 29 '15 at 7:21
  • I used the command suggested by agent-gotse and worked perfectly. However i wonder if this could affect the performance of an application that can run this command multiple times. Could someone answer me? – Antonio Oliveira Sep 9 '15 at 4:30

The documentation is out-of-date and wrong. Currently, when you specify $cleanup_mode=2, the cleanup action is done first, and then a regular run is done. That's different from what happens when you run latexmk -c foo.tex, which only does the cleanup.

The documentation wasn't updated to reflect a code change many versions ago. I need to correct the documentation (and probably improve the code).

Perhaps you actually want latexmk to do an automatic cleanup after compiling your document. That is a sensible idea, but it's not currently implemented.

| improve this answer | |
  • 1
    thanks for the info. Is there some sort of quick hack that I can put together, like making an alias latexmk which executes latexmk -c or something? – jchun Jan 29 '15 at 2:49
  • In my opinion, cleaning up only makes sense when the document has reached its no-more-edits-this-is-final form. Doing it at the end of a latexmk run just increases the length of the next run. – egreg Jan 30 '15 at 10:36

The following command

latexmk -pdf foo.tex && latexmk -c foo.tex

will make latexmk build foo.tex and produce a pdf file. If this is successful, then the cleanup will be executed and you will be left with just the pdf file. You can create an alias for this in your shell if you wish.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.