0

I am trying to use the metaflow macro set for metapost. It and its documentation can be obtained from:

https://personal.utdallas.edu/~hamlen/projects.html

The relevant definition that I'm having some trouble with is

538 vardef connector@#(suffix $,$$)(expr dsrc,ddst) =
539 if (str @#)="":
540 numeric x[]cp.tmp, y[]cp.tmp;
541 path cp.tmp;
542 _connector.tmp
543 else:
544 if known cp@#:
545 errmessage("redundant connector name: " & (str @#));
546 fi;
547 _connector@#
548 fi($,$$,dsrc,ddst)
549 enddef;

Which is expecting a pair of suffixes for the first two arguments. Is there any way that I can pass the values of some variables to this macro? I tried expandafters but failed.

\documentclass{article}
\usepackage{luamplib}
\begin{document}

\begin{mplibcode}
input metaflow.mp;
beginfig(0);
z1c=origin;
z2c=(5cm,0);
draw rrect1("1");
draw rrect2("2");
%draw connector(1,2,right,right);% <=====works
a:=1;
b:=2;
draw connector(a,b,right,right);
endfig;
\end{mplibcode}

\end{document}
3
  • 1
    Maybe scantokens("draw connector(" & decimal a & "," & decimal b & ",right,right);");? (untested) Jan 22, 2020 at 3:14
  • @henri oh, that's a good idea! I'll give it a shot when I'm by a computer.
    – Scott H.
    Jan 22, 2020 at 3:55
  • @HenriMenke That did indeed work. If you want to make it answer, I'll accept.
    – Scott H.
    Jan 22, 2020 at 6:04

1 Answer 1

1

You can build the command as a string where you can format the numbers using decimal and pipe it through scantokens which will read the supplied text as regular input.

\documentclass{article}
\pagestyle{empty}
\usepackage{luamplib}
\begin{document}

\begin{mplibcode}
input metaflow.mp;

beginfig(0);
    z1c = origin ;
    z2c = (5cm,0) ;
    draw rrect1("1") ;
    draw rrect2("2") ;
    a := 1 ;
    b := 2 ;
    scantokens("draw connector(" & decimal a & "," & decimal b & ",right,right) ;") ;
endfig;
\end{mplibcode}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .