ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Problem with MkIV and TikZ picture remembering
Date: Tue, 03 Mar 2015 20:04:03 +0100	[thread overview]
Message-ID: <54F605A3.3080501@wxs.nl> (raw)
In-Reply-To: <alpine.OSX.2.02.1503031207140.44165@nqv-znpobbx>

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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2015-03-03 19:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-03  7:23 Jörg Weger
2015-03-03  7:25 ` Jörg Weger
2015-03-03  7:54   ` Wolfgang Schuster
2015-03-03 12:38     ` Ulrike Fischer
2015-03-03 13:11       ` Mojca Miklavec
2015-03-03 13:27         ` Ulrike Fischer
2015-03-03 15:29           ` Mojca Miklavec
2015-03-03 13:51         ` Ulrike Fischer
2015-03-03 17:12 ` Aditya Mahajan
2015-03-03 19:04   ` Hans Hagen [this message]
2015-03-03 19:28     ` Aditya Mahajan
2015-03-07 12:08       ` Jörg Weger
2015-03-07 14:52         ` Hans Hagen
2015-03-07 17:30           ` Jörg Weger
2015-03-07 18:22             ` Wolfgang Schuster
2015-03-08 10:11               ` Hans Hagen
2015-03-08 11:26                 ` Wolfgang Schuster
2015-03-08 11:55                   ` Hans Hagen
2015-03-08 12:04                     ` Wolfgang Schuster
2015-03-08 17:39                       ` Hans Hagen
2015-03-08 18:07                         ` Wolfgang Schuster
2015-03-08 19:04                           ` Hans Hagen
2015-03-08 22:17                           ` Hans Hagen
2015-03-13 13:17                             ` Jörg Weger
2015-03-13 13:32                               ` Wolfgang Schuster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54F605A3.3080501@wxs.nl \
    --to=pragma@wxs.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).