如何更改 MetaPost 的字体?

如何更改 MetaPost 的字体?

我有以下代码来使用 MetaUML 创建 UML 图:

\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}

从技术上讲,UML 图显示正确,但它使用某种默认衬线字体(我认为是 Times New Roman)。我希望它具有与文档其余部分相同的无衬线字体,我已通过以下方式定义

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

这对于文档的其余部分来说很好,但遗憾的是不适用于该mbox部分。还有两件事:

答案1

万一您能够切换到lualatex,这里有一种方法可以获取您想要的东西:

\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}

编译此文件lualatex可获得如下 PDF:

在此处输入图片描述

更多信息请luamplib参见这里

要缩小字体,您可以metauml调整一些设置,但最后缩放当前图片可能更简单。因此,您可以通过添加

currentpicture := currentpicture scaled 0.8;

在环境结束之前。如果您想对每个图表都执行此操作,那么您可以更新序言以说明:

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

或者,由于mplibcode环境继承自周围的 LaTeX 环境,您可以将每张图片括在一个具有较小字体的组中:

\[{\small\begin{mplibcode}
...
\end{mplibcode}}\]

相关内容