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';
add_cus_dep('mp', '1', 0, 'mpost');
sub mpost {
my $file = $_[0];
my ($name, $path) = fileparse( $file );
pushd( $path );
my $return = system "mpost $name" ;
popd();
return $return;
}
which is to be put in a
latexmkrc
file.
The above code solves the problem of persuading mpost
to put its output files in the appropriate directory. The new version of latexmk
solves the other problem that on a first run, when the .1
file does not exist, latexmk
needed to detect the missing file condition and run mpost
.
As far as I can tell, it does not cause a problem that if there are multiple images, mpost
generates files with extensions like .NNN
, where NNN
is an integer. In this situation, there is still a file with extension .1
, and this is sufficient to trigger the correct use of mpost
.
The CVS version of TikZ contains a graph layout library, which works surprisingly well for this. Here are a couple of your examples. The syntax could be shortened (f
instead of fermion
, for example), this is just to show the idea:
\graph [spring layout, nodes=coordinate, horizontal'=c to d]
{
c -- [fermion] a,
b --[fermion] c -- [photon] d,
e -- [fermion] d -- [fermion] f;
};
\graph [spring layout, nodes=coordinate, horizontal'=c to d]
{
c -- [fermion] a,
b --[fermion] c -- [gluon] d,
e -- [fermion] d -- [fermion] f;
};
\graph [spring layout, anchor at={(0,-4)}, nodes=coordinate, horizontal'= b to d]
{
a -- [fermion] b -- [fermion] c,
b -- [photon] d -- [left, fermion] e -- [left, fermion] d,
e -- [photon] f -- [fermion] g,
h -- [fermion] f;
};
\graph [spring layout, anchor at={(0,-5)}, nodes=coordinate, vertical= e to f]
{
a -- [fermion] b -- [photon] c -- [fermion] d,
b -- [fermion] e -- [fermion] c,
e -- [gluon] f,
h -- [fermion] f -- [fermion] i
};
There are some issues with decorating curved paths using waves, and the coils decoration sometimes ends with a straight path segment, but that could be fixed.
Here's the complete code (requires lualatex
).
\documentclass[a4paper,12pt, border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations, decorations.markings, decorations.pathmorphing, arrows, graphs, graphdrawing, shapes.geometric, snakes}
\usegdlibrary{trees,force, layered}
\pgfdeclaredecoration{complete sines}{initial}
{
\state{initial}[
width=+0pt,
next state=sine,
persistent precomputation={\pgfmathsetmacro\matchinglength{
\pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
\setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
}] {}
\state{sine}[width=\pgfdecorationsegmentlength]{
\pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
\pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
}
\state{final}{}
}
\tikzset{
photon/.style={
decoration={complete sines, amplitude=0.15cm, segment length=0.2cm},
decorate
},
fermion/.style={
decoration={
markings,
mark=at position 0.5 with {\node[transform shape, xshift=-0.5mm, fill=black, inner sep=1pt, draw, isosceles triangle]{};}
},
postaction=decorate
},
gluon/.style={
decoration={coil, aspect=0.75, mirror, segment length=1.5mm},
decorate
},
left/.style={
bend left=90,
looseness=1.75
}
}
\begin{document}%
\begin{tikzpicture}
\graph [spring layout, nodes=coordinate, horizontal'=c to d]
{
c -- [fermion] a,
b --[fermion] c -- [photon] d,
e -- [fermion] d -- [fermion] f;
};
\graph [spring layout, anchor at={(0,-2)}, nodes=coordinate, horizontal'=c to d]
{
c -- [fermion] a,
b --[fermion] c -- [gluon] d,
e -- [fermion] d -- [fermion] f;
};
\graph [spring layout, anchor at={(0,-4)}, nodes=coordinate, horizontal'= b to d]
{
a -- [fermion] b -- [fermion] c,
b -- [photon] d -- [left, fermion] e -- [left, fermion] d,
e -- [photon] f -- [fermion] g,
h -- [fermion] f;
};
\graph [spring layout, anchor at={(0,-5)}, nodes=coordinate, vertical= e to f]
{
a -- [fermion] b -- [photon] c -- [fermion] d,
b -- [fermion] e -- [fermion] c,
e -- [gluon] f,
h -- [fermion] f -- [fermion] i
};
\end{tikzpicture}
\end{document}
Best Answer
The following works with
pdflatex
and feynmp:If you now call
pdflatex
with the-shell-escape
option (-enable-write18
for MiKTeX), the Metapost file is compiled right after the end of the environment and will be used at the next compilation.NOTE TeX Live 2012 lists
mpost
among the programs that can be run with "restricted shell escape", so the test above can beand
-shell-escape
is not needed any more. Note though that MiKTeX 2.9 doesn't allowmpost
in restricted shell escape.For feynmf it's just the same:
Adding
-shell-escape
to the call of (pdf)latex should be easy in Kile.I advise to use feynmp that's easier to manage and produces resolution independent output. Moreover it supports color.
Another way, for older systems, is to open an output stream where to write the necessary shell commands.
At the end of the LaTeX run you'll have a file called as your main file, with extension
.out
that contains the necessary shell commands to run. If the file ismain.tex
all you have to do is to run from the shell