[metapost] More consistent and configurable label suffixes

Hartmut Henkel hartmut_henkel at gmx.de
Sat Aug 4 00:44:13 CEST 2007


On Mon, 30 Jul 2007, Rasmus Villemoes wrote:

> When labelling intersection points between curves, I often find that
> the eight predefined directions are not quite sufficient; sometimes it
> seems that the most appropriate place for the label is somewhere
> between for instance .top and .urt.

the MetaFun package provides in mp-tool.mp some macro thefreelabel()
that positions a label around some anchor point depending on a given
direction vector. Found this only after i tried it myself:

prologues := 3;

vardef theannot(expr s, pos, dd) =
  clearxy; save p; picture p;
  if picture s:
    p = s;
  else:
    p = s infont defaultfont scaled defaultscale;
  fi;
  center p = pos + whatever * dd rotated 90 - z1;
  if (xpart dd > 0) and (ypart dd > 0):
    z2 = lrcorner p;
  elseif ypart dd > 0:
    z2 = urcorner p;
  elseif xpart dd < 0:
    z2 = ulcorner p;
  else:
    z2 = llcorner p;
  fi;
  z2 = pos + whatever * dd + labeloffset * unitvector dd rotated 90 - z1;
  (p shifted z1)
enddef;

beginfig(1)

for i = 0 step 30 until 359:
  save x,y;
  z0 = origin;
  z1 = (right * 10cm) rotated i;
  draw 0.45[z0,z1] -- 0.55[z0,z1];
  draw 0.5[z0,z1] withpen pencircle scaled 1mm;
  draw theannot(btex text etex, 0.5[z0,z1], z1-z0);
  draw theannot(btex $x^2$ etex, 0.5[z0,z1], z0-z1);
endfor;

endfig;
end

Regards, Hartmut


More information about the metapost mailing list