I am using latexmk with a custom dependency that is used to create .tex files from .svg files.

The problem that arises is, that the conversion actually creates two files, the .tex file and a .pdf file that is included in the .tex file.

From my understanding of latexmk it is not aware of the existence of the additional .pdf files and thus does not remove them during a cleanup.

I tried circumventing this problem by giving the extra files generated a special extension .gen.pdf and

  • (a) adding this extension to the list of generated extensions using push @generated_exts, "gen.pdf"; or
  • (b) adding this extension to the list of extra extensions to remove in a cleanup $clean_ext = "gen.pdf";

but neither of these worked.

Is there any way make latexmk aware of these files so that they can be removed during cleanup?

  • Could you send me a very simple test case (to my address in the latexmk documentation), with both the source files and the definition of your custom dependency. I see a possibility for a simple solution, but I would like to test it before posting it. Mar 16, 2018 at 21:13
  • @JohnCollins I just emailed you the minimal example. Thanks for your help!
    – timmbob
    Mar 19, 2018 at 8:32

1 Answer 1


Here's a solution for defining the custom dependency. It contains a one-line addition to the OP's code:

$cleanup_includes_cusdep_generated = 1; 
$cleanup_includes_generated = 1;

add_cus_dep('gnplt', 'tex', 0, 'gnplt2tex');
sub gnplt2tex {
   $abs_path = File::Spec->rel2abs( $_[0] );
   rdb_add_generated( "$_[0].tex", "$_[0].gen.pdf" );
   ($vol, $dir, $fname) = File::Spec->splitpath($abs_path);
   system( "cd $dir && " .
    "gnuplot -e \"set output \'$fname.gen.tex\'\" \"$fname.gnplt\"" );
   system( "mv \"$abs_path.gen.tex\" \"$abs_path.tex\"" );
   system( "epstopdf \"$abs_path.gen.eps\" && rm \"$abs_path.gen.eps\"" );

The critical parts are

  1. Setting $cleanup_includes_generated = 1, which the OP had already done. This ensures that a clean up deletes files in a list of generated files that is held internally by latexmk.
  2. Using (the not-currently documented) rdb_add_generated subroutine to add a specific file to the list of generated files. This is my only change to the OP's code.

The setting of $cleanup_includes_cusdep_generated = 1 is actually unnecessary in the current version of latexmk, but that could change in the future.


  1. The use of $cleanup_includes_generated = 1 is potentially a little dangerous, since it also implies that a cleanup also includes deletion of all the files that latexmk finds in \openout lines in the .log file from latex runs and also any found from OUTPUT lines in the .fls file. This is a slight potential for mis-parsed lines etc. But you can see from the relevant lines in the .fdb_latexmk file that the detection of generated files is normally reliable.

  2. With the current version (4.55e) of latexmk, the use of $cleanup_includes_generated = 1 implies that a cleanup using -c option of latexmk deletes some files that should be preserved, i.e., the .dvi file generated by latex or the .pdf file generated by pdflatex (etc). This doesn't matter for the -C option, which is documented to cause deletion of these files.

  • As I already wrote in my mails: Thank you very much, John, for your quick and perfect help!
    – timmbob
    Mar 27, 2018 at 17:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .