# How to use latekmk with feynmf/feynmp?

## Background

The latexmk tool can be used to automatically process your LaTeX files enough times to generate the output. As discussed here and here, latexmk now supports setting out_dir which passes the -output-directory to pdflatex and places build products in this alternate location. Unfortunately, this makes it difficult to use latexmk with feynmp.

# Question

How can I configure latexmk to call mpost for processing Feynman diagrams generated by feynmp? Especially using the new out_dir configuration?

One can try to add a custom rule to the latexmkrc file like

sub mpost {
$pdflatex="pdflatex -shell-escape -interaction=nonstopmode %O %S"; ### tst.tex \documentclass{scrbook} \usepackage{feynmp} \usepackage{etoolbox} \DeclareGraphicsRule{*}{mps}{*}{} \makeatletter \show\endfmffile \preto{\endfmffile}{\let\the@fmffile\thefmffile} \appto{\endfmffile}{ \ifnum\pdfshellescape=\@ne \immediate\write18{mpost \the@fmffile}% \else \message{ Run pdf(la)tex with -shell-escape to generate feynmp diagrams} \fi \let\the@fmffile\relax } \makeatother \begin{document} \begin{fmffile}{title} \begin{fmfgraph}(40,25) \fmfleft{i1,i2} \fmfright{o1,o2} \fmf{fermion}{i1,v1,o1} \fmf{fermion}{i2,v2,o2} \fmf{photon}{v1,v2} \end{fmfgraph} \end{fmffile} \end{document} • mpost ignores the --output-directory option. – egreg Dec 4 '11 at 23:11 • @egreg This works \write18{cd _build;mpost \the@fmffile}. Is there any way to get the argument to --output-directory programatically? – mforbes Dec 4 '11 at 23:21 • Not that I know. You can try using "\def\outdir{_build}\input{%S}" instead of %S (possibly escaping backslashes and braces) and saying \write18{cd \outdir;mpost \the@fmffile}. – egreg Dec 4 '11 at 23:36 ## 1 Answer There's an update to latexmk, v. 4.30a, that solves some problems with using the -output-directory option. I'd recommend upgrading. Here's a solution that works with v. 4.30a of latexmk:$out_dir = 'output';
my $file =$_[0];
my ($name,$path) =  fileparse( $file ); pushd($path );
my $return = system "mpost$name" ;