Skip to content
Timothy Cyrus edited this page Jun 30, 2017 · 4 revisions

How do I setup MetaUML?

MetaUML is bundled with TeX distributions such as TeX Live, so no additional setup steps are usually required.

How do I create a simple MetaUML diagram?

Create a file named example.mp, with the following contents:

input metauml;
beginfig(1);
    Class.A("A")()();
    drawObject(A);
endfig;
end

Obtain a PostScript file named example.1 by running:

mpost example.mp

If a PDF file is needed, run the following command instead:

mptopdf example.mp

How do I include MetaUML diagrams in my LaTeX article?

Create a file called example.tex with the following contents:

\documentclass{article}
\usepackage[pdftex]{graphicx}
\DeclareGraphicsRule{*}{mps}{*}{}

\title{A Simple MetaUML Example}
\author{John Hacker}

\begin{document}
\maketitle
\section{Example}
\includegraphics{example.1}

\end{document}

Build the MetaUML diagram and then the article:

mpost example.mp
pdflatex example.tex

Why do I get strange errors when defining multiple diagrams?

You might have used the same entity name in more than one diagram, as is the case with A below:

input metauml;

beginfig(1);
    Class.A("A")()();
    drawObject(A);
endfig;

beginfig(2);
    Class.A("AnotherClass")()();
    drawObject(A);
endfig;
end

The following workaround is recommended:

input metauml;

beginfig(1);
    Class.A("A")()();
    drawObject(A);
endfig;

beginfig(2);
    save A; % tell MetaPost to forget the old A
    
    Class.A("AnotherClass")()();
    drawObject(A);
endfig;
end

Clone this wiki locally