Is there a way to get outlines for a TeX label in MetaPost, containing something reasonably complex, say: $\sum_{x=0}^{10}x^2$? I know that I can get outlines for separate glyphs using glyph, but how to preserve a layout?

  • Are you using "pure" MetaPost or are variants allowed? ConTeXt has some outlining functions, but I'm not sure this answers your question.
    – user226564
    Commented Jan 23, 2021 at 19:32
  • In general I'm interested in a solution which would work with standalone MetaPost, but a ConTeXt solution would help too. Commented Jan 23, 2021 at 19:45
  • To be precise, I believe I know how to do it in ConTeXt, but it doesn't work in standalone MP. Commented Jan 23, 2021 at 19:57
  • Another way is going wild: pdflatex > pdf2ps > pstoedit or latex > dvips > pstoedit to get a MetaPost file, perhaps?
    – user226564
    Commented Jan 23, 2021 at 20:41
  • This would work for one-off tasks, for sure, but it would be quite inconvenient to do it from within MetaPost on larger scale. Commented Jan 23, 2021 at 20:49

1 Answer 1


This is what for e within p does, where p is a picture variable. Consider this small example:

input TEX
picture p; p = TEX("$\sum_{x=0}^{10}x^2$");
for e within p:
    if textual e:
        message "(" & decimal xpart e & "," & decimal ypart e & ") " 
                    & fontpart e & " " & textpart e;
    elseif stroked e:
        show pathpart e;

if you run this through plain mpost you should get this output:

(0,7.472) cmex10 P
(10.5162,5.0091) cmr7 10
(10.5162,-2.9888) cmmi7 x
(15.0339,-2.9888) cmr7 =0
(27.2797,0) cmmi10 x
(32.9736,3.6154) cmr7 2

which tells you the position, the font used, and the ASCII character used in that font. (Note that the sum symbol is "P" in cmex10). And from this you can use glyph to get the outlines for each character in the textpart string.

From my experiments, this only works with plain mpost. I do not get the same output from lualatex + luamplib -- I guess because the font management is so different.

Slightly more complete example

prologues := 3;
outputtemplate := "%j%c.eps";
input TEX
picture p; p = TEX("$\displaystyle\sum_{x=0}^{10}x^2$");
for e within p:
    if textual e:
        pair o; o = (xpart e, ypart e) scaled 100/8; 
        for i=1 upto length textpart e:
            string s; s = substring (i-1, i) of textpart e;
            picture g; g = glyph ASCII s of fontpart e scaled 1/8;
            picture out; out = image(
            for ee within g:
                draw pathpart ee;
            draw out shifted o;
            o := o + (xpart lrcorner out, 0);

but I am not sure I have quite understood the spacing and scaling information. The documentation is a bit sparse...

enter image description here

Compatibility with luamplib

Note that (at present) the ideas shown here only work with plain Metapost. The built-in TEX() macro that is provided by luamplib (for use with lualatex) returns a picture with just one "part" and that part has no "textual" elements in it, and the only "stroked" part is the bounding box of the typeset text.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .