4

I am using latexmk to compile my document, and have written a custom dependency rule to generate some files to include. The processing involves creating some intermediate files which I'd like to clean with -c. However, these intermediate files are only removed if I set $cleanup_includes_generated = 1; which results in the output PDF being deleted also.

For a minimal working example, use the following latexmkrc file which simply copies a file to an intermediate and then final destination. It uses the rdb_add_generated() routine mentioned by John Collins in this answer about cleaning custom dependencies.

$pdf_mode = 1;
$cleanup_includes_cusdep_generated = 1;

add_cus_dep('txt', 'inc', 0, 'test_dep');
sub test_dep {
    system("cp $_[0].txt $_[0].tmp");
    system("cp $_[0].tmp $_[0].inc");
    rdb_add_generated("$_[0].tmp");
}

Use a simple TeX document main.tex:

\documentclass{article}
\begin{document}
  \input{message.inc}
\end{document}

And an even simpler file message.txt to process:

Hello world!

Running latexmk -interaction=nonstopmode creates a file database main.fdb_latexmk which includes the message.tmp intermediate file. However, latexmk -c and latexmk -C only remove the message.inc file and leave the intermediate one.

Changing $cleanup_includes_cusdep_generated = 1; to $cleanup_includes_generated = 1; in the latexmk config results in the intermediate file being deleted. However, this results in latexmk -c behaving the same as latexmk -C and removing the output PDF, which is not ideal.

I suspect rdb_add_generated() is adding the intermediate file to the general list of generated files rather than a list of files generated by custom dependencies. Is there some way to mark it as a custom generated file, or am I stuck with choosing between leaving the intermediate files uncleaned or deleting all generated files?

1
  • This doesn't directly answer the question, but personally I would do something like this using make, and call latexmk from make to do the things that make can't do - in particular, automatically re-running LaTeX enough times for cross references etc to stabilize.
    – alephzero
    Commented Dec 30, 2018 at 10:29

1 Answer 1

3

This behavior is actually due to a couple of bugs in latexmk. (a) If you specify $cleanup_includes_cusdep_generated = 1;, then latexmk fails to delete the extra generated file that you specified. (b) If you specify $cleanup_includes_generated = 1;, then latexmk deletes files that it shouldn't (e.g., a .pdf file) when you use latexmk -c.

I've corrected this for the next release of latexmk.

2
  • Thanks! Just to clarify (b), did you mean $cleanup_includes_generated = 1;? With $cleanup_includes_cusdep_generated = 1; latexmk leaves the PDF for me.
    – Blair
    Commented Dec 31, 2018 at 21:57
  • 1
    Yes. I've corrected the answer. Commented Jan 1, 2019 at 1:29

You must log in to answer this question.

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