[XeTeX] MetaPost with XeTeX

Robert Spence spence at saar.de
Mon Apr 10 19:53:12 CEST 2006

Dear Jonathan,

You must be online all the time!  Posting my question and receiving  
your answer were separated by just 11 minutes!

On 10 Apr 2006, at 18:47 , Jonathan Kew wrote:

> On 10 Apr 2006, at 5:36 pm, Robert Spence wrote:
>> Dear List Members,
>> Just two quick questions concerning MetaPost:
>> 1) Is it possible to get MetaPost to call XeTeX, instead of normal  
>> TeX, to typeset labels within diagrams using some of the fonts  
>> that XeTeX can access?
>> 2) Is it possible to call MetaPost from within XeTeX (using  
>> something like mfpic.sty or emp.sty)?
> I don't really know anything about (1), but my guess is probably  
> not.... if it calls TeX and then uses the output, it probably does  
> so by interpreting the DVI output from TeX, and won't understand  
> XeTeX's extended DVI (.xdv). That's if MP calls TeX at all.... are  
> you sure it doesn't "typeset" labels itself, using the TFM files  
> directly? (See, I really don't know anything about it, just  
> speculating!)

It says on page 20 of John D. Hobby's "A User's Manual for MetaPost":

"TeX may be used to format complex labels.  If you say

     btex <typesetting commands> etex

in a MetaPost file, the <typesetting commands> get processed by TeX  
and translated into a picture expression (actually a <picture  
primary>) that can be used in a label or dotlabel  
statement."  (That's the sum total of everything I know...)

You can even do complex LaTeXy things in one of these btex ... etex  
environments, like
and so on.  But I have no idea what's actually going on in the  

> The answer to (2) is probably "yes, in principle", as XeTeX can use  
> the \write18 mechanism to execute shell commands (provided you  
> enable this option in your configuration or via the command line).  
> I assume this is how such things are done. But if the result is a  
> Postscript or EPS drawing, it'll need to be converted to PDF in  
> order to use it within XeTeX, so some adaptation is likely to be  
> needed. Someone familiar with these packages might have a clearer  
> idea of how the pieces work together.

I know that the filenames involved can get a bit tricky with  
extensions and suffixes, due to the fact that each MetaFont file  
typically contains the instructions for producing more than one  
figure, each of which then has to be automatically given a  filename  
that distinguishes it from the others the moment it's generated, but  
I think there have been some discussions of similar problems on the  
OS X TeX list that could help me on that point. (From memory, it's  
just finicky and a bit counterintuitive, but not really impossibly  
difficult.)  I know that in TeXShop Preferences you can switch  
between getting MetaPost to generate just PostScript, and getting it  
to convert the result automatically to PDF, so it looks like it would  
work (even though my first couple of attempts failed).  I'll try it  
via the command line, as I'm not really sure whether \write18 was  
enabled;  I know that it's enabled when I'm using pdfelatex, but  
don't know whether that also applies to XeTeX.  (I believe Gerben  
Wierda ships everything with \write18 disabled by default, due to  
possible security concerns, and you have to enable it yourself.  I've  
forgotten how I did it last time and whether it was global, but can  
probably look it up or work it out by trial and error.)

Just by the way:  I tried inserting a page of a pre-existing PDF  
document into a new one I was generating with XeTeX, and found I had  
to put a small horizontal space before the PDF-insertion command  
before it would work.  I figured that it had something to do with the  
way XeTeX treats graphics, i.e. as being just big character glyphs,  
and that after a \newpage command XeTeX had to be explicitly put into  
horizontal mode.  (But I'm just guessing; I don't really know that  
much plain TeX off the top of my head.)

Having loads of fun experimenting with your wonderful programme,

-- Rob Spence

More information about the XeTeX mailing list