Changes

Jump to navigation Jump to search
1,619 bytes added ,  15:34, 24 January 2011
Added how to use MetaObj together with text labels in ConTeXt
[http://www.ctan.org/tex-archive/graphics/metapost/contrib/macros/metaobj/ MetaObj] is a system for high-level object-oriented drawing based on [[MetaPost]] (from the [http://mirror.ctan.org/graphics/metapost/contrib/macros/metaobj/doc/momanual.pdf manual]).

When using text labels in embedded MetaPost code within ConTeXt, the whole MetaPost code is processed in two runs. This causes problems with MetaObj, because it doesn't expect this. See [http://archive.contextgarden.net/thread/20110118.121745.612f819e.en.html#20110118.121745.612f819e this mailing list thread] for details. The following example (from the manual, modified by Aditya Mahajan) shows how to avoid those problems.

<texcode>
\startMPinclusions[+]
input metaobj;
boolean flag; flag := false; % flag is false in the first run
\stopMPinclusions

\startMPdefinitions
vardef newSegment@# =
if not flag:
assignObj(@#, "Segment"); % this should be called only once
ObjPoint a, b;
ObjCode "@#b - @#a = (1cm, 2cm)";
fi;
enddef;

def drawSegment(suffix n) =
draw n.a -- n.b;
draw btex E etex shifted n.a;
enddef;
\stopMPdefinitions

\starttext
\startMPpage
newSegment.s;
s.a = origin;
drawObj(s);

newSegment.t;
if not flag:
rotateObj(t, 180); % we don't want the object rotated twice
fi;
t.a = s.a + (4cm, 1cm);
drawObj(t);

flag := true; % flag will be true after the first run
\stopMPpage
\stoptext
</texcode>

Just use "if not flag" constructions around anything that might cause trouble. Sometimes even the definition of relations (bindings) between objects will require precautions.
18

edits

Navigation menu