ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Mikael Sundqvist <mickep@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: simplifying repeated macro calls in metafun
Date: Mon, 21 Jun 2021 14:21:00 +0200	[thread overview]
Message-ID: <CAHy-LL-5Q_XgDtkqtpzF0scZdLFSuEBskm_dJUibPHdGhzxwgA@mail.gmail.com> (raw)
In-Reply-To: <C1C20F16-2BA4-4954-9C13-A52419BC4EA1@gmail.com>

Hi,

As is written in the MetaPost manual: Whatever generates a new
anonymous variable each time it is used. It is very useful in cases
where you are not interested in the value of a variable, but want to
use it to (let MP) calculate something. Example

you have three points z0, z1, z2 forming a triangle, and you want to
find where the altitude from z0 is intersecting the line between z1
and z2. You can find that intersection z3 by writing

z3 = whatever[z1,z2] = z0+whatever*dir(angle(z1-z0)+90));

The first equality says only that z3 should be on the line between z1
and z2, the second one says that z3 should be on the line through z0,
perpendicular to the line between z1 and z2. Since MetaPost solves
linear equations, this defines z3, and we need not to think more about
the actual values of the "whatevers" (note that they are not in
general equal in this example!).

Hope it helps!

/Mikael


On Mon, Jun 21, 2021 at 2:07 PM Otared Kavian <otared@gmail.com> wrote:
>
> Hi Aditya,
>
> Thanks for the detailed file you sent to answer Dalyoung’s question and file. And going through both files I have a question.
> I see that both of you use a function « whatever » (but is it a function ?): what does this do and where can it be used (actually I have seen Hans using this expression, but I had always thought this is just a name…
>
> Best regards: Otared
>
> > On 21 Jun 2021, at 06:26, Aditya Mahajan <adityam@umich.edu> wrote:
> >
> > On Mon, 21 Jun 2021, Jeong Dal wrote:
> >
> >>
> >> Hi,
> >>
> >> I defined a macro definition in metafun, and draw figures using \startbuffer[] … \stopbuffer and \processMPbuffer[].
> >> As you see in the attached code, the same macro definition is used repeatedly by changing the numeric argument.
> >> Is there a better way to simplify the code, for example, using \dorecurse and recurselevel?
> >
> > See attached. The main idea is to store the repetitive bits in \startuseMPgraphic{...} and then reuse them using \includeMPgraphic.
> >
> > Aditya<mp-test.tex>___________________________________________________________________________________
> > 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://context.aanhet.net
> > archive  : https://bitbucket.org/phg/context-mirror/commits/
> > wiki     : http://contextgarden.net
> > ___________________________________________________________________________________
>
> ___________________________________________________________________________________
> 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2021-06-21 12:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1.1624183201.7245.ntg-context@ntg.nl>
2021-06-20 23:30 ` Jeong Dal
2021-06-21  4:26   ` Aditya Mahajan
2021-06-21 12:07     ` Otared Kavian
2021-06-21 12:21       ` Mikael Sundqvist [this message]
2021-06-21 14:31         ` Otared Kavian
2021-06-21 18:35           ` Mikael Sundqvist
2021-06-21 13:34 ` Jeong Dal
     [not found] <mailman.1069.1624285904.1130.ntg-context@ntg.nl>
2021-06-21 21:50 ` Jeong Dal
2021-06-22 13:49   ` Otared Kavian
2021-06-22 16:00     ` Wolfgang Schuster
     [not found] <mailman.1145.1624377609.1130.ntg-context@ntg.nl>
2021-06-23 20:26 ` Jeong Dal
2021-06-24  3:31   ` Aditya Mahajan
2021-06-24  3:42     ` Aditya Mahajan
2021-06-24  7:16       ` Hans Hagen
     [not found] <mailman.47.1624523134.1143.ntg-context@ntg.nl>
2021-06-25 19:14 ` Jeong Dal

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=CAHy-LL-5Q_XgDtkqtpzF0scZdLFSuEBskm_dJUibPHdGhzxwgA@mail.gmail.com \
    --to=mickep@gmail.com \
    --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).