I'm currently creating a personal LaTeX package and base .tex document that I can use to typeset my Computer Science reports at my university. One of the features I would like to have is to make UML diagrams in MetaUML.

I would like to to generate the .1 files from the .mp files every time I run latexmk instead of doing it manually. Beneath I have made a minimal example of the directory structure I am using.

Is it be possible to use latexmk to run mpost on the mp files in the images directory automatically or on demand? Or would I have to use an external makefile/script?

My directory structure looks like this:

| |-myStyle.sty
| |-strategyPattern.mp
| |-generated PDF and fls file
| |-generated aux etc.

This is the content of myStyle.sty:



this is the content of mainDocument.tex:


      \caption{A picture of a uml.}

strategyPattern.mp contains the content of this link and createPDF.sh is a wrapper around latexmk -pdf -shell-escape -auxdir=tmp -output-directory=output mainDocument.tex


After @Thruston comment I have been digging through the latexmk repository and found this file http://archive.cs.uu.nl/mirror/CTAN/support/latexmk/example_rcfiles/mpost_latexmkrc.

I have added this to my latexmkrc file, however it never seems to run the subroutine.

Update 2

strategyPattern.1 gets generated when I put strategyPattern.mp in the root directory, however it gives a error during the first pass of latexmk, the second pass is succesfull.

I'm closing in on the problem, but my LaTeX and Perl skills are not sufficient enough to get it working with the strategyPattern.mp file in /images

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – user31729
    Feb 27, 2014 at 17:42
  • 1
    Did you look at the Latexmk documentation? It includes some examples for running metapost.
    – Thruston
    Feb 27, 2014 at 17:51
  • @ChristianH. Thank you, I shall read the starter guide @Thruston I did grepped through the documentation with mpost and metapost as the word to search, but I was not able to find any reference to them. Feb 27, 2014 at 18:08
  • 1
    There's actually a bug in the latexmk documentation in the file mpost_latexmkrc. I've put a corrected version at mpost_latexmkrc. It'll appear in the next release of latexmk. Mar 3, 2014 at 22:26

1 Answer 1


By using the updated mpost_latexmkrc file I am able to get it to work. The other thing that had to be done was refer to my .mk files by path. This means I had to use images/strategyPattern.1 instead of just strategyPattern.1. I have updated the question to reflect this change.

Updated file

Here's the non-comment part of the updated mpost_latexmkrc file:

add_cus_dep( 'mp', '1', 0, 'mpost' );
sub mpost {
    my $file = $_[0];
    my ($name, $path) =  fileparse( $file );
    my $return = system "mpost \"$file\"";
    # Fix the problem that mpost puts its output and log files
    # in the current directory, not in the auxiliary directory
    # (which is often the same as the output directory):
    move "$name.1", $path;
    move "$name.log", $aux_dir;
    return $return;

You must log in to answer this question.

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