I am using textext to draw text from inside a metapost program. The drawoptions macro is used by metapost to set drawing options such as color. As I understand, the textext call is handled by the tex-side of the metapost-context system, initiated of course from the metapost side. My impression is that this occurs asynchronously, judging by the problem I encountered.

On the metapost side I have:

drawoptions(withcolor blue);
pic := textext(labeltext);
drawoptions();
% the pic is output later


Deleting the reset implied by the second drawoptions does honor the coloring: 
drawoptions(withcolor blue); 
pic := textext(labeltext);


I am inclined to conclude that the calling environment containing the drawoptions setting is not captured the moment the textext call is placed, but somewhat later. Because so it can be explained why the latter has the blue color but the former does not (drawoptions has already been reset before it is taken into account).

The following code variation seems to corroborate this conclusion:
drawoptions(withcolor blue);
pic := textext(labeltext);
drawoptions(withcolor darkgreen);


If the conclusion is correct, I have a serious problem, because it then becomes impossible to predictably change the drawoptions used by textext. The result then might be dependent on timing conditions in the system. In my opinion, calling textext should capture all relevant data at the precise moment of the call in metapost.

I might be wrong, of course, but otherwise I am in need of a repair.

Hans van der Meer