Difference between revisions of "MetaObj and Labels"

From Wiki
Jump to navigation Jump to search
(Added how to use MetaObj together with text labels in ConTeXt)
 
m
Line 43: Line 43:
  
 
Just use "if not flag" constructions around anything that might cause trouble. Sometimes even the definition of relations (bindings) between objects will require precautions.
 
Just use "if not flag" constructions around anything that might cause trouble. Sometimes even the definition of relations (bindings) between objects will require precautions.
 +
 +
[[Category:Graphics]]
 +
[[Category:Programming and Databases]]

Revision as of 15:03, 8 June 2020

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.

\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

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