I use latexmk 4.77. The following is my .latexmkrc file

$pdf_mode = 4;# specifies creation of pdf via lualatex 
$bibtex_use = "2";# to configure bibtex 

$cleanup_includes_cusdep_generated = 1;
push @generated_exts, "lol";
$clean_ext .= " %R.synctex.gz";

# graphics by metapost 
add_cus_dep('mp', 'mps', 0, 'mpost');

# sub mpost {
#     #return system("mptopdf $_[0].mp");
#     return system("mpost $_[0].mp");
# }

# metapost rule from http://tex.stackexchange.com/questions/37134
#add_cus_dep('mp', '1', 0, 'mpost');
sub mpost {
  my $file = $_[0];
  my ($name, $path) = fileparse($file);
  my $return = system("mpost $name");
  return $return;

In my mp file i configured

prologues := 2;
outputtemplate := "%j.mps";

so that really an mps file is created. In a tex file i just included the mps with \includegraphics, but this is immaterial in this context.

The behavior of latexmk is quite strange: Running latexmk directly complains about missing graphic file. But then if i run latexmk -pvc and command scrollmode and interrupt, at the end, the files are compiled correctly.

I also tried add_cus_dep('mp', '1', 1, 'mpost');, no change. What am I doing wrong? Is possibly a general problem that latexmk cannot compile in situations where before the first latex run some files must be generated already???

This would be a considerable gap since this applies to various kinds of graphics.

  • In the meantime i found out that also graphics created from xfig dont work. I used the config given in latexmk documentation. Maybe something changed since this has been written. I suspect, that formerly, the rules were applied before tex was converted (which is necessary for graphics), whereas now only after the first latex run this is done. This behavior is only appropriate for bibliographies, indices and that like. Maybe this is due to an optimization based on the fls file. Mar 12, 2023 at 10:56
  • I see also another possible fix: what if the package graphicx has a parameter treatment of missing file: either warning or error. If set to warning, the problem is also resolved. I think even better because then only graphics are created which are really needed. Mar 12, 2023 at 12:07
  • In my examples, graphics from both mpost and xfig work. So you first need to show the full contents of a minimal tex file and mp file, so we can try your example for ourselves. Mar 12, 2023 at 15:01
  • The error message about the missing graphics file is expected on a first run: The message is from lualatex. Just respond to the message with 'r' followed by return. Latexmk has no way of knowing what files are needed until after the first run of *latex. After the first run, latexmk finds out about the missing file(s), and creates them. Mar 12, 2023 at 15:10
  • OT but (a) I'd strongly recommend that you get everything working "by hand" before trying to automate it (hey, but maybe you have..) and (b) since you are using lualatex then you have an option of including your MP graphics in line with luamplib which is about 20,000 times easier than all this.
    – Thruston
    Mar 13, 2023 at 11:14

1 Answer 1


This is in fact a stolen answer: John Collins gave the decisive hint:

in .latexmkrc insert set_tex_cmds('-interaction=nonstopmode %O %S');

If a graphic file is not yet present, then a warning is given and the file is created. In the next latex run, all is ok.

There is nevertheless one special point with metapost: use

mpost -interaction=nonstopmode -recorder -s prologues=2 

The prologue will cause creation of an mps file. I found that when including with \includegraphics, the ending must be given.

That way also other graphic files seem to work. I tried with xfig files, works fine.

You must log in to answer this question.

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