[metapost] More consistent and configurable label suffixes

Dan Luecking luecking at uark.edu
Mon Jul 30 21:07:58 CEST 2007

At 09:21 AM 7/30/2007, you wrote:

>I've added a tracker item:

One wonders where to stop adding new directions. Is it not
sufficient that one can say
   label.urt (...) shifted ...
for special adjustments?

To get new suffixes (nne, for example) it suffices to define variables
labxf.nne, labyf.nne and laboff.nne. The first two determine which point
of the label is nearest the point in question, the last is a unit vector
in the appropriate compass direction. Thus
   labxf.nne := 0; % 0=left, .5=center, 1=right
   labyf.nne := 0; % 0=bottom, .5=center, 1=right
   laboff.nne:= dir(67.5); % halfway between 45 and 90

After that, label.nne should work.

Is easy to go all the way and define a system where any direction
is possible. Probably it would have to be given a different name
than "label" for compatibility. Further flexibility could be had
by adding a parameter that determined which part of the label is
placed at the given point.

def tag = draw thetag enddef
% s is label, a is angle, xf, yf are fractions used to select
% a point on the label: 0 = left- or bottommost, 1 is right- or
% topmost. In between: any point within the label.
vardef thetag (expr s, z, a, xf, yf) =
   save p_; picture p_;
   if picture s:  p_ = s;
   else:    p_ = s infont defaultfont scaled defaultscale;
   p shifted
     (z + labeloffset*dir(a)
        -(xf*lrcorner p + yf*ulcorner p + (1-xf-yf)*llcorner p)

Then label.urt(s,z) is equivalent to
   tag(s, z)(angle(labeloff.urt), labxf.urt, labyf.urt)
which is
   tag (s, z)(45, 0, 0)

In the past, some folks have requested placement relative to the
baseline of the text. This would be obtained by changing "llcorner p"
to "(xpart llcorner p, 0)". The metapost interface to the mfpic
package provides this level of flexibility (plus a parameter to
rotate the label about the point z).


Daniel H. Luecking
Department of Mathematical Sciences
University of Arkansas
"Dubito ergo cogito, cogito ergo sum" --Descarte

More information about the metapost mailing list