在Latex中使用metapost画图的简单示例


发布日期 : 2025-12-29 05:37:01 UTC

访问量: 196 次浏览

Latex一直是断断续续地用着,很多用法都是原来用的时候查过,但现在用的时候又忘记了。学知识、做事情的时候慢下来很重要,通过Google,可能会很快解决问题,但毕竟不系统,体会东西不深,尤其是没有做笔记的时候,只能导致大量的重复工作。 下面通过一个简化的实例,记录一下在Latex中使用metapost画图的用法。

最近需要在Latex中画图,开始想用metapost,但最终选择了tikz。不管怎样,还是做下笔记比较好。 fig.mp文件

`beginfig(1);
path p; p = (0,1cm)..(1cm,0)...(0,-1cm); fill
p{dir(157)}..(0,0){dir(23)}..{dir(157)}cycle withcolor green; draw
p..(-1cm,0)..cycle; fill
(0,-0.6cm)..(0.1cm,-0.5cm)..(0,-0.4cm)..(-0.1cm,-0.5cm)..cycle withcolor
white; fill (0,0.6cm)..(0.1cm,0.5cm)..(0,0.4cm)..(-0.1cm,0.5cm)..cycle
withcolor red; endfig; beginfig(2); path p; p = (-1cm, 0)..(0, -1cm)..(1cm,
0); fill p{up}..(0,0){-1, -2}..{up}cycle; draw p..(0, 1cm)..cycle; fill
(0.4cm, 0)..(0.5cm, -0.1cm)..(0.6cm, 0cm)..(0.5cm, 0.1cm)..cycle withcolor
white; fill (-0.4cm, 0)..(-0.5cm, -0.1cm)..(-0.6cm, 0)..(-0.5cm,
0.1cm)..cycle; endfig; end; ` texfile.tex文件 `documentclass{article}
usepackage{amsmath,amssymb} usepackage[dvipdfm]{graphics} begin{document}
title{Article Title} author{Some One} maketitle tableofcontents section{First
Case} includegraphics{fig.1} includegraphics{fig.2} section{Second Case}
end{document} ` 

最后是一个脚本文件,来对latex文件进行编译,当然,我用的是xelatex命令。 mpost fig.mp xelatex texfile.tex