[Therion] Metapost variable macro suffixes

Tarquin Wilton-Jones tarquin.wilton-jones at ntlworld.com
Sun Mar 1 08:44:33 CET 2020


Hi folks,

hoping someone who really understands Metapost can give me a suggestion
since I cannot find it in any manuals.

In Therion's Metapost, there are a couple of wildcard suffixed macros
like this:

vardef p_label@#(expr txt,pos,rot,mode)

I have a need to call the different ones depending on the value of a
pair like this:

if A = (-1,1):
  p_label.ulft(thetext,P,R,style);
elseif A = (0,1):
  p_label.top(thetext,P,R,style);
... more ...

Based on the value of another variable, I need to run a different macro
instead, which also has its own suffixes, which match the suffixes above:

if A = (-1,1):
  if Foo = "a"
    thelabel.ulft(txt, pos);
    ... other stuff ...
  else:
    p_label.ulft(thetext,P,R,style);
  fi;
elseif A = (0,1):
  if Foo = "b"
    thelabel.ulft(txt, pos);
    ... other stuff ...
  else:
    p_label.top(thetext,P,R,style);
  fi;
... more ...

This quickly gets tedious, since the same code gets repeated over and
over again, just with a different suffix each time.

In Metapost, is it possible to store the suffix in a variable, then use
it when calling the macro like so?

if A = (-1,1): sfx:="ulft";
elseif A = (0,1): sfx:="top";
...
if Foo = "b"
  thelabel.<sfx>(txt, pos);
  ... other stuff ...
else:
  p_label.<sfx>(thetext,P,R,style);
fi;

Thanks for any advice.

Tarquin



More information about the Therion mailing list