0

I have the following code in order to create a UML diagram with MetaUML:

\begin{mpost}[mpsettings=input metauml;]

Class.Task("Task")
    (
        "-id: long",
        "-name: String"
    )
    (
        "+Task(name: String)",
        "+Task(id: long, name: String)",
        "+getId(): long",
        "+getName(): String",
        "+setName(name: String): void"
    );

drawObjects(Task);

\end{mpost}

Technically, the UML diagram is displayed correctly, but it's using some kind of default serif font (Times New Roman I think). I'd like it to have the same sans-serif font as the rest of the document, which I have defined via

\renewcommand{\familydefault}{\sfdefault}
\usepackage{sourcesanspro}

This works fine for the rest of the document, but sadly not for the mbox section. Two more things:

2
  • 1
    Welcome to TeX.SE! Could you extend your code snippets into an example that can be compiled please? Starting with your \documentclass{} and ending with \end{document}, just so people can copy, paste and experiment with possible solutions
    – JamesT
    Feb 27, 2023 at 12:32
  • 1
    I would recommend switching to lualatex as my answer suggests. Is that a possibility for you?
    – Thruston
    Feb 27, 2023 at 12:34

1 Answer 1

1

Just in case you are able to switch to lualatex, here is one way to get what you want:

\documentclass{article}
\usepackage{sourcesanspro}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{luamplib}
\everymplib{input metauml; beginfig(0);}
\everyendmplib{endfig;}
\mplibtextextlabel{enable}
\begin{document}

Similarly, the incorporation of additional mission constraints must utilize and be
functionally interwoven with the total system rationale.  In theory, the
interrelation of system and/or subsystem technologies must utilize and be
functionally interwoven with the preliminary qualification limit.  
\[\begin{mplibcode}
Class.Task("Task")
    (
        "-id: long",
        "-name: String"
    )
    (
        "+Task(name: String)",
        "+Task(id: long, name: String)",
        "+getId(): long",
        "+getName(): String",
        "+setName(name: String): void"
    );

drawObjects(Task);
\end{mplibcode}\]
In particular, any associated supporting element necessitates that urgent
consideration be applied to possible bidirectional logical relationship approaches.
Conversely, any associated supporting element recognizes other systems' importance
and the necessity for possible bidirectional logical relationship approaches.
However, a service-oriented paradigm is further compounded when taking into account
the evolution of specifications over a given time period.  

\end{document}

Compile this with lualatex to get a PDF that looks like this:

enter image description here

For more on luamplib see here.

To make the font size smaller there might be some metauml settings you can tweak but it might be simpler just to scale the current picture at the end. So you could make the whole thing smaller by adding

currentpicture := currentpicture scaled 0.8;

just before the end of the environment. If you want to do this for every diagram then you could update the preamble to say:

\everyendmplib{currentpicture := currentpicture scaled 0.8; endfig;}

Alternatively, since the mplibcode environment inherits from the surrounding LaTeX environment, you could just enclose each picture in a group with a smaller font:

\[{\small\begin{mplibcode}
...
\end{mplibcode}}\]
4
  • Interesting approach to put the MetaPost stuff into a displayed formula.
    – mickep
    Feb 27, 2023 at 13:13
  • @mickep just for the spacing and centering...
    – Thruston
    Feb 27, 2023 at 13:40
  • @Thruston Thank you, this works! Is there any way I can reduce the font size used in the UML diagram?
    – imaginny
    Feb 27, 2023 at 15:55
  • on scaling the font, see edits.
    – Thruston
    Feb 27, 2023 at 20:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .