On 3/3/2015 6:12 PM, Aditya Mahajan wrote:
On Tue, 3 Mar 2015, Jörg Weger wrote:
In the minimal working example below inside of a text two words should be printed inside of rounded TikZ rectangles and should be connected by an TikZ arrow pointing from the first word to the other.
TikZ offers the remember picture/overlay option for that.
I have seen a solution similar to what I want to achieve in the METAFUN manual but I don’t have a clue how to get that METAPOST alternative working.
Here is how to get the metafun alternative working.
1. I don't understand why I need to manually input the mp-abck file; that should be input automatically.
2. The metafun alternative is a bit inconvenient. Suppose you want to draw a bunch of such graphics (words connected by arrows). Then, you will need to ensure that node names are unique. (Is there a way to get around that?)
3. I did not bother to set the style of the boxes and arrows. So it looks a bit dry.
\startMPdefinitions % I don't know why this does not get loaded automatically. input mp-abck.mpiv; \stopMPdefinitions
\defineoverlay[highlight] [\positionoverlay{highlightoverlay}]
\startpositionoverlay{highlightoverlay} \setMPpositiongraphic{n1}{highlightgraphic}{from=n1,to=n2} \stoppositionoverlay
\startMPpositiongraphic{highlightgraphic} save n; path n[];
initialize_box(\MPpos{\MPvar{from}}); n[1] := pxy; initialize_box(\MPpos{\MPvar{to}}); n[2] := pxy;
draw n[1]; draw n[2];
drawarrow (center n[1]){dir 45} .. {dir -45}(center n[2]) cutbefore n[1] cutafter n[2];
anchor_box(\MPanchor{\MPvar{from}}); \stopMPpositiongraphic
\setuppapersize[A6]
\setupbackgrounds[page][background=highlight]
\starttext \hpos{n1}{this} belongs to \hpos{n2}{that} \stoptext
\startMPdefinitions % I don't know why this does not get loaded automatically. Answer: seldom needed. input mp-abck.mpiv; \stopMPdefinitions \defineoverlay[highlight] [\positionoverlay{highlightoverlay}] \startMPpositiongraphic{highlightgraphic} save n; path n[]; initialize_box(\MPpos{\MPvar{from}}); n[1] := pxy; initialize_box(\MPpos{\MPvar{to}}); n[2] := pxy; draw n[1]; draw n[2]; if ypart center n[1] > ypart center n[2] : drawarrow (center n[1]){dir 225} ... {dir -225}(center n[2]) cutbefore n[1] cutafter n[2] ; else : drawarrow (center n[1]){dir 45} ... {dir -45}(center n[2]) cutbefore n[1] cutafter n[2] ; fi ; anchor_box(\MPanchor{\MPvar{from}}); \stopMPpositiongraphic \newcounter\connectedwordcounter \starttexdefinition unexpanded fromword [#1]#2 \expandafter\pushmacro\csname cwc>#1\endcsname % nesting hack \doglobal\increment\connectedwordcounter \setxvalue{cwc>#1}{\connectedwordcounter}% \startpositionoverlay{highlightoverlay} \setMPpositiongraphic {\getvalue{cwc>#1}>f} {highlightgraphic} {from=\getvalue{cwc>#1}>f,to=\getvalue{cwc>#1}>t} \stoppositionoverlay \hpos{\getvalue{cwc>#1}>f}{#2}% \stoptexdefinition \starttexdefinition unexpanded toword [#1]#2 \hpos{\getvalue{cwc>#1}>t}{#2} \expandafter\popmacro\csname cwc>#1\endcsname % nesting hack \stoptexdefinition \setuppapersize[A6] \setupbackgrounds[page][background=highlight] \starttext \fromword[foo]{this} belongs to \toword[foo]{that} \fromword[bar]{this} belongs to \toword[bar]{that} \fromword[foo]{this} belongs to \toword[foo]{that} \fromword[bar]{this} belongs \fromword[bar]{this} belongs to \toword[bar]{that} to \toword[bar]{that} \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------