[metapost] problem with macro parameters
Stephan Hennig
mailing_list at arcor.de
Sat Aug 20 12:54:46 CEST 2005
Hi,
while working with metaobj I tried to define a short hand macro for a
call to
nccurve(a)(b) "angleA(ra)", "angleB(rb)";
However, ra and rb (entering and leaving angles at nodes a and b)
evaluate to zero when called inside my macro. I even tried with
scantokens. Although, the string looks ok to me, that gives a lot of
error messages. Any ideas?
Regards,
Stephan Hennig
input metaobj
prologues := 1;
% Alias macro for nccurve(a)(b) "angleA(ra)", "angleB(rb)";
def curve(suffix a,b)(expr ra,rb) =
%% ra and rb evaluate to zero here.
nccurve(a)(b) "angleA(ra)", "angleB(rb)";
enddef;
def curveS(suffix a,b)(expr ra,rb) =
%% Alternatively tried with scantokens, but this fails.
%% Do I have to expand a and b?
save s;
string s;
s = "nccurve(a)(b) " &
char(34) & "angleA(" & decimal ra & ")" & char(34) & ", " &
char(34) & "angleB(" & decimal rb & ")" & char(34) & ";";
show s;
scantokens(s);
endgroup
enddef;
beginfig(1);
newCircle.source("S");
newCircle.sink("T");
source.c = (0bp, 0bp);
sink.c = (100bp, 0bp);
drawObj(source, sink);
%% This works (red arc).
nccurve(source)(sink) "angleA(20)", "angleB(-20)", "linecolor(red)";
%% This draws only a simple line (black arc).
curve(source,sink, 20,-20);
endfig;
end
More information about the metapost
mailing list