MetaObj and Labels

From Wiki
Revision as of 15:03, 8 June 2020 by Garulfo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

MetaObj is a system for high-level object-oriented drawing based on MetaPost (from the 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 this mailing list thread for details. The following example (from the manual, modified by Aditya Mahajan) shows how to avoid those problems.

  input metaobj;
  boolean flag; flag := false; % flag is false in the first run

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

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

  s.a = origin;

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

  flag := true; % flag will be true after the first run

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