# [metapost] MetaPost and XeTeX

Nicola nvitacolonna at gmail.com
Tue Jun 8 12:38:11 CEST 2010

In article <4C0640E0.5040808 at fc.up.pt>,
José Carlos Santos <jcsantos at fc.up.pt> wrote:

> On 02-06-2010 12:03, Taco Hoekwater wrote:
>
> >> Yesterday, Taco Hoekwater made a reference to MetaPost 2.0. I would like
> >> to know if this new version will be able to work with XeTeX. [...] and I
> >> wanted to be able to use within the graphics the same fonts that were
> >> used within the text.

If it's ok for you to create stand-alone PDF graphics and include that
in your document, XeConTeXt has the ability to to what you want. This is
a minimal document:

\definetypeface [myface][rm][serif][hoefler][default][encoding=uc]
\setupbodyfont[myface,12pt]

\startMPenvironment
\switchtobodyfont[myface,12pt]
\stopMPenvironment

\starttext
\setupcolors[state=start]

\startMPpage
fill fullcircle scaled 3cm withcolor .7red;
label.bot(\sometxt{Hoefler text},(0,2mm));
\stopMPpage

\stoptext
\end

The code in \startMPpage-\stopMPpage is plain MetaPost code, with labels
drawn by \sometxt rather than btex.. etex (there is also \textext, but
for unknown reasons I've never been able to use it with XeTeX). If the
code above is saved as myfig.tex then you can compile it with

texexex --xtx myfig.tex

to generate myfig.pdf. More details are provided in ConTeXt Wiki, in
particular:

http://wiki.contextgarden.net/Mpgraphic
http://wiki.contextgarden.net/Fonts_in_XeTeX

Nicola