# How to change the font for metauml?

I am using the emp package in order to use metauml for drawing UML-models. So far so good.

this is a minimal example:

\documentclass{scrartcl}

\usepackage{emp}

\ifx\pdftexversion\undefined
\usepackage[dvips]{graphicx}
\else
\usepackage[pdftex]{graphicx}
\DeclareGraphicsRule{*}{mps}{*}{}
\fi

\begin{document}
\begin{empfile}
\begin{empcmds}
input metauml;
\end{empcmds}

\begin{figure}
\centering
\begin{emp}[classdiag](20, 20)
Class.A("A")()();
Class.B("B")()();
B.e = A.w + (-20, 0);
drawObjects(A, B);
\end{emp}
\caption{A class diagram}
\end{figure}

\end{empfile}
\end{document}


It looks like the text in the graph is using Time New Roman.

How can I change the font to something else?

I already tried something like \empaddtoTeX{\usepackage[default]{lato}} but it didn't change anything.

-

MetaUML uses a very low level text management. The font used is defined in the file metauml_defaults.mp which contains

if known _metauml_defaults_mp:
expandafter endinput
fi;
_metauml_defaults_mp:=1;

% txbtt

if not known metauml_defaultFont:
string metauml_defaultFont;
metauml_defaultFont  := "ptmr8r";
fi;

if not known metauml_defaultFontOblique:
string metauml_defaultFontOblique;
metauml_defaultFontOblique  := "ptmro8r";
fi;

if not known metauml_defaultFontBold:
string metauml_defaultFontBold;
metauml_defaultFontBold  := "ptmb8r";
fi;

if not known metauml_defaultFontBoldOblique:
string metauml_defaultFontBoldOblique;
metauml_defaultFontBoldOblique  := "ptmbo8r";
fi;


You can find it in your system, copy it in the current directory and modify the font names. Notice that support for encodings is inexistent, so for accented characters you're out of luck. What fonts are really supported depends, I believe, on the Metapost version you're using.

A different way to set the fonts is to write

\begin{empcmds}
string metauml_defaultFont;
metauml_defaultFont  := "cmr10";
string metauml_defaultFontOblique;
metauml_defaultFontOblique  := "cmti10";
string metauml_defaultFontBold;
metauml_defaultFontBold  := "cmbx10";
string metauml_defaultFontBoldOblique;
metauml_defaultFontBoldOblique  := "cmbxti10";
input metauml;
\end{empcmds}


where I've used the usual Computer Modern fonts.

A complete version using the Lato fonts would be:

\documentclass{scrartcl}

\usepackage{emp}

\usepackage{graphicx}
\usepackage{ifpdf}
\ifpdf
\DeclareGraphicsRule{*}{mps}{*}{}
\fi

\begin{document}
\begin{empfile}
\begin{empcmds}
_metauml_defaults_mp:=1;
string metauml_defaultFont;
metauml_defaultFont:="Lato-Reg-t1";
string metauml_defaultFontOblique;
metauml_defaultFontOblique  := "Lato-RegIta-t1";
string metauml_defaultFontBold;
metauml_defaultFontBold  := "Lato-Bol-t1";
string metauml_defaultFontBoldOblique;
metauml_defaultFontBoldOblique  := "Lato-BolIta-t1";
input metauml;
\end{empcmds}

\begin{figure}
\centering
\begin{emp}[classdiag](20, 20)
Class.A("Abcde")()();
Class.B("Bmno")()();
B.e = A.w + (-20, 0);
drawObjects(A, B);
\end{emp}
\caption{A class diagram}
\end{figure}

\end{empfile}
\end{document}


(I've changed the way you declare the extensions for the PDF setting.)

There's a final note to be made. MetaUML font management relies on printing strings, not on interaction between Metapost and TeX. So the choice of fonts is somewhat restricted and has important limitations.

Fonts in OT1 encoding, such as cmr10 have a "lslashslash" in the position of the space, so a MetaUML label with a space ("ABC DEF") would result in something like

ABC-DEF

Fonts in T1 encoding have a "visible space" in that position, and the string above would become

ABC└┘DEF

(with the symbol at the baseline).

So the choice, in case spaces are needed, is limited to fonts in 8r encoding (which is why the default font is ptmr8r).

-
Thanks that works nicely! The only problem is when I use whitespaces, then I get a skewed hyphen instead. Is there a way to find out the possible codes for the fonts? – pklip Sep 28 '12 at 8:46
It can be worse than that! With the Lato fonts, you'd get a "visible space". I don't think there's much to do about this, sorry: the way MetaUML manages text is really too primitive. – egreg Sep 28 '12 at 9:11
Thank you very much! Nice explanation. – pklip Sep 28 '12 at 14:33