MetaPost
外觀
編程範型 | 指令式,排版 |
---|---|
設計者 | John D. Hobby |
實作者 | Taco Hoekwater |
型態系統 | 推斷類型, 動態類型, 強類型 |
作業系統 | 跨平台 |
許可證 | 公有領域 |
網站 | Development website |
啟發語言 | |
Metafont |
MetaPost是一個程序語言和它的編譯器的名字,衍生於高德納的Metafont。MetaPost擅長通過數學描述製作矢量圖,生成的圖片為PostScript格式。它的語法來自Metafont。
實例
[編輯]這個文件example.mp通過MetaPost的編譯器編譯(在Linux系統中使用mpost
命令)之後產生了3個EPS文件: example.1, example.2, example.3。這三個文件就是右邊的三張圖
transform pagecoords;
pagecoords:=identity scaled 10mm shifted (100mm,150mm);
beginfig (1)
fill ((0,0)--(2,0)--(2,1)--(1,1)--(1,2)--(0,2)--cycle)
transformed pagecoords withcolor green;
draw ((2,0)..(2,1)..(1,1)..(1,2)..(0,2))
transformed pagecoords;
drawarrow ((0,0)--(2,2)) transformed pagecoords;
endfig;
beginfig (2)
draw (for i=0 up to 7: dir (135i)-- endfor cycle)
transformed pagecoords;
endfig;
pagecoords:=identity scaled 15mm shifted (100mm,150mm);
beginfig (3);
% declare paths to be used
path p[],p[]t;
% set up points by defining relationships
z1=(0,0); z2=z1+2up;
z3=z1+whatever*dir (60)=z2+whatever*dir (-50);
z4=z3+(-1.5,-.5);
z5=z1+dir (135);
z0=whatever[z1,z2]=whatever[z3,z4];
% set up paths
p0=fullcircle yscaled .5 rotated 45 shifted z0 ;
p1=z2—z4..z0..z3---z1;
p2=p1 cutbefore p0 cutafter p0;
p3=p0 cutbefore p1 cutafter p1;
p4=p2—p3—cycle;
% define transformed versions of paths and points
for i=0 up to 4: p[i]t=p[i] transformed pagecoords; endfor
for i=0 up to 5: z[i]t=z[i] transformed pagecoords; endfor
% do some drawing
fill p4t withcolor (1,1,0.2);
draw z1t—z2t withcolor .5white;
draw z3t—z4t withcolor .5white;
pickup pencircle;
draw p0t dashed withdots scaled .3;
draw p1t dashed evenly;
draw p2t withcolor blue;
draw p3t withcolor red;
label.lrt (btex $z_0$ etex, z0t);
label.llft (btex $z_1$ etex, z1t);
label.top (btex $z_2$ etex, z2t);
label.rt (btex $z_3$ etex, z3t);
label.llft (btex $z_4$ etex, z4t);
for i=0 up to 4:
drawdot z[i]t withpen pencircle scaled 2;
endfor
endfig;
bye
產生的3個eps文件可以直接用在TeX中(通過LaTeX的\includegraphics
命令、ConTeXt的\externalfigure
命令、Plain TeX的\epsfbox
命令,或者Plain pdftex中來自supp-pdf.tex的\convertMPtoPDF
命令。為了看或者列印這三張圖片,這些引用是必須的,因為TeX的字體(Metafont)並不包含在MetaPost產生的eps文件中。
參見
[編輯]參考
[編輯]- MetaFun (modules for Metapost) by Hans Hagen, [1] (頁面存檔備份,存於網際網路檔案館)
- Donald Knuth: The METAFONTbook, (Computers and Typesetting Volume C) Addison-Wesley 1986. ISBN 0-201-13444-6
- Comprehensive TEX Archive Network (CTAN): http://www.ctan.org/ Archive.is的存檔,存檔日期2012-12-09. Repository of the TEX source and hundreds of add-ons and style files.
- (La)TeX Navigator provides 305 simple MetaPost examples: https://web.archive.org/web/20130727021112/http://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html
- Taco Hoekwater: MetaPost developments—autumn 2006 (頁面存檔備份,存於網際網路檔案館). TUGboat 27:1 (2006).
外部連結
[編輯]- The TeX users group (TUG) http://www.tug.org/ (頁面存檔備份,存於網際網路檔案館) has a page devoted to MetaPost: http://www.tug.org/metapost.html(頁面存檔備份,存於網際網路檔案館)
- Active development of MetaPost continues at https://web.archive.org/web/20070929092912/http://foundry.supelec.fr/projects/metapost/
- Functional MetaPost allows MetaPost to be used from the functional programming language Haskell
- John D. Hobby has a homepage at https://web.archive.org/web/20131003040005/http://ect.bell-labs.com/who/hobby/index.shtml and some other pages and publications devoted to MetaPost, though these are now a little dated
- Historic MetaPost homepage: https://web.archive.org/web/20081212090123/http://ect.bell-labs.com/who/hobby/MetaPost.shtml
- A User's Manual for MetaPost John D. Hobby. Available as a file mpman.ps distributed with MetaPost, or from the Bell Labs web site. Also available in PDF format (頁面存檔備份,存於網際網路檔案館) from CTAN.