![metauml 安装使用错误](https://linux22.com/image/254045/metauml%20%E5%AE%89%E8%A3%85%E4%BD%BF%E7%94%A8%E9%94%99%E8%AF%AF.png)
这个问题有点宽泛,但我正在尝试安装 metauml(我使用的是 Mac 和 texlive)。我下载了软件包并运行了安装脚本,该脚本将 metauml 目录放在 metapost 目录下(这是我所期望的)。但是,我无法让它运行。我有以下代码:
\documentclass[a4paper,12pt]{article}
\usepackage{amssymb} % needed for math
\usepackage{amsmath} % needed for math
\usepackage[utf8]{inputenc} % this is needed for german umlauts
\usepackage[ngerman]{babel} % this is needed for german umlauts
\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
\usepackage[margin=1.5cm]{geometry} %layout
% this is needed for forms and links within the text
\usepackage{hyperref}
% The following is needed in order to make the code compatible
% with both latex/dvips and pdflatex.
\ifx\pdftexversion\undefined
\usepackage[dvips]{graphicx}
\else
\usepackage[pdftex]{graphicx}
\DeclareGraphicsRule{*}{mps}{*}{}
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% THE DOCUMENT BEGINS %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section{Class diagram}
\includegraphics{metadiagram.mp}
\end{document}
metadiagram.mp在同一个文件夹中,定义如下:
input metauml;
beginfig(1);
Class.World("World")
("-age: int",
"#ressources: List")
("+sayHello(): void");
Class.NoHuman("Human")
("-birthday: Date",
"-nickname: String",
"-secret: String")
("+code(language: Language): Program");
leftToRight(50)(World, NoHuman);
drawObjects(World, NoHuman);
link(aggregation)(NoHuman.w -- World.e);
item(iAssoc)("1")(obj.n = .2[World.e,NoHuman.w]);
item(iAssoc)("has >")(obj.n = .5[World.e,NoHuman.w]);
item(iAssoc)("0..*")(obj.n = .8[World.e,NoHuman.w]);
endfig;
end
我收到错误:无法确定 metadiagram.mp 中的图形大小(没有 BoundingBox)
有人可以帮忙吗?
答案1
您不能包含.mp
应事先由 Metapost 处理的文件。
如何运行 Metapost 取决于您的操作系统和 TeX 发行版;TeXShop 和 TeXworks 可能有菜单项。通常,您可以打开终端窗口,cd
进入包含该文件的目录并执行
mpost metadiagram.mp
这将生成一个文件metadiagram.1
,因为你说的beginfig(1)
是
\includegraphics{metadiagram.1}
会做。
请注意,您使用的加载方式graphicx
是错误的。应该是
\usepackage{ifpdf}
\usepackage{graphicx}
\ifpdf
\DeclareGraphicsRule{*}{mps}{*}{}
\fi
还有另一种方法可以继续,使用gmp
包。对于你的情况,输入应该是
\documentclass[a4paper,12pt]{article}
\usepackage{amssymb} % needed for math
\usepackage{amsmath} % needed for math
\usepackage[utf8]{inputenc} % this is needed for german umlauts
\usepackage[ngerman]{babel} % this is needed for german umlauts
\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
\usepackage[margin=1.5cm]{geometry} %layout
\usepackage[shellescape]{gmp}
\usepackage{ifpdf}
\ifpdf
\DeclareGraphicsRule{*}{mps}{*}{}
\fi
% this is needed for forms and links within the text
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% THE DOCUMENT BEGINS %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section{Class diagram}
\begin{mpost}[mpsettings={input metauml;},use]
Class.World("World")
("-age: int",
"#ressources: List")
("+sayHello(): void");
Class.NoHuman("Human")
("-birthday: Date",
"-nickname: String",
"-secret: String")
("+code(language: Language): Program");
leftToRight(50)(World, NoHuman);
drawObjects(World, NoHuman);
link(aggregation)(NoHuman.w -- World.e);
item(iAssoc)("1")(obj.n = .2[World.e,NoHuman.w]);
item(iAssoc)("has >")(obj.n = .5[World.e,NoHuman.w]);
item(iAssoc)("0..*")(obj.n = .8[World.e,NoHuman.w]);
\end{mpost}
\end{document}
如果您使用开关(TeXShop 中的首选项允许您启用它)处理此文档(请注意 Metapost 源嵌入其中)-shell-escape
,则 Metapost 运行将自动执行。