never try to do tricky stuff like definitions inside MPenvironement, because it is parsed and changed slightly.
I'm learning that lesson too. Another one: "don't use btex..etex instead use \sometxt". So I now try to use the MPenvironment only for font and size switching (e.g. if I want the figures to be in a smaller font). I wikified a small example of converting to \sometxt: http://wiki.contextgarden.net/Mpgraphic#startMPenvironment. It's probably not in the right place on the wiki though.
\def\a{abc}
\starttext \startMPcode label(\sometxt{\a},origin); \stopMPcode \stoptext
Would that kind of approach satisfy your needs?
It would. I've used this sed script to help me convert my standalone metapost files: sed 's/btex (.*) etex/\\sometxt{\1}/' < standalone.mp But for the next chapter's figures, I'll write a python script that will do the other transformations: e.g. turn each beginfig into \startstaticMPfigure -- or is it \startstaticMPgraphic? I always have to check, hence I'll put it in a script and have *it* remember. I know that metafun was made for integrating backgrounds and the like, not for standalone figures, so it may seem strange to convert all of one's standalone figures into metafun figures and place them in the .tex source file. But I like having the source for the standalone figures in the same file near their use: it's figure--text integration (one theme of Tufte's books), done in the source file. -Sanjoy `Never underestimate the evil of which men of power are capable.' --Bertrand Russell, _War Crimes in Vietnam_, chapter 1.