Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

|-mainDocument.tex
|-createPDF.sh
|
|\styles
| |-myStyle.sty
| 
|\images
| |-strategyPattern.mp
| 
|\output
| |-generated PDF and fls file
| 
|\tmp
| |-generated aux etc.

This is the content of myStyle.sty:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{myStyle}[2014/02/27]

\RequirePackage[a4paper]{geometry}
\RequirePackage[utf8]{inputenc}
\RequirePackage{graphicx}
\graphicspath{{./images/}}

this is the content of mainDocument.tex:

\documentclass[a4paper,10pt]{report}
\RequirePackage{./styles/myStyle}
\DeclareGraphicsRule{.1}{mps}{*}{}

\begin{document}
    \begin{figure}
      \centering
        \includegraphics[width=\textwidth]{images/strategyPattern.1}
      \caption{A picture of a uml.}
    \end{figure}
\end{document}

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

Update

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

share|improve this question
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  Christian Hupfer Feb 27 at 17:42
1  
Did you look at the Latexmk documentation? It includes some examples for running metapost. –  Thruston Feb 27 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. –  Corstiaan Hol Feb 27 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. –  John Collins Mar 3 at 22:26

1 Answer 1

up vote 0 down vote accepted

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;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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