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?
- 1,363
1 Answers
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;
fi
endfor
end
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
beginfig(1)
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;
endfor);
draw out shifted o;
o := o + (xpart lrcorner out, 0);
endfor
fi
endfor
endfig;
end
but I am not sure I have quite understood the spacing and scaling information. The documentation is a bit sparse...
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.
- 42,268

pdflatex>pdf2ps>pstoeditorlatex>dvips>pstoeditto get a MetaPost file, perhaps? – Jan 23 '21 at 20:41