Faster Metapost SVG Output with TeX?

I am generating some diagrams with METAPOST. I need the output in SVG format. My labels are generated by calls to LaTeX via Tex.mp and its TEX METAPOST definition (also called a macro).

My complaint: it is pretty slow to constantly write stuff to a file and fire off an instance of latex.

Is there a faster way to achieve the same result? (As I recall, I can use METAPOST inside a TeX document with the package luamplib, which is fast, but it generates PDF, not SVG.)

Minimal example:

prologues:=3;
input TEX;

outputformat := "svg";
outputtemplate:="%j.%{outputformat}";

string texpre;
% texpre = "%&latex" & char(10) &
texpre =
"\documentclass{article}" & char(10) &
"\begin{document}  " & char(10);

TEXPRE(texpre);
TEXPOST("\end{document}");

beginfig(1)
draw fullcircle scaled 1in;
string l;
l = "Foo";
dotlabel.bot(TEX("Label is " & l), origin);
endfig;
end

-
Could you make a small example where you use TEX.mp? –  egreg Sep 23 '13 at 15:15
@egreg, better? –  Colin Fraizer Sep 23 '13 at 15:30
Well, the output I get is completely mangled. –  egreg Sep 23 '13 at 15:40
@egreg, I am using MetaPost 1.802 (TeX Live 2013/W32TeX) with command line: mpost --numbersystem=double --file-line-error --halt-on-error --tex=latex. –  Colin Fraizer Sep 23 '13 at 15:44
I too, but the output gets mangled, at least when opened with Firefox or Safari. Oh, and the same if I use PS output and convert to PDF –  egreg Sep 23 '13 at 15:51

Are you looking for the latexmp package? To quote:

The MetaPost pack­age la­texMP im­ple­ments a user-friendly in­ter­face to ac­cess LaTeX-based type­set­ting ca­pa­bil­i­ties in MetaPost. The text to be type­set is given as string. This al­lows even dy­namic text el­e­ments, for ex­am­ple coun­ters, to be used in la­bels. Com­pared to other im­ple­men­ta­tions it is much more flex­i­ble, since it can be used as di­rect re­place­ment for btex..etex, and much faster, com­pared for ex­am­ple to the so­lu­tion pro­vided by tex.mp

-
It seems not to work well with svg output, though. –  cfr May 2 at 1:02