From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
Aditya Mahajan <adityam@umich.edu>
Subject: Re: Metafun: is it possible to redefine dotlabel to draw a square ?
Date: Thu, 10 Dec 2020 19:07:23 +0100 [thread overview]
Message-ID: <e165b661-3ed0-57ac-63d5-44f7bcbc2083@xs4all.nl> (raw)
In-Reply-To: <nycvar.YAK.7.78.908.2012101240540.1732@nqv-guvaxcnq>
On 12/10/2020 6:44 PM, Aditya Mahajan wrote:
> On Thu, 10 Dec 2020, Otared Kavian wrote:
>
>> Hi all,
>>
>> In Metafun when representing a point I woul dlike to have some dots represented by a square (or even by another scalable symbol): for instance in the following I would like the dot at the point B to be a square:
>>
>> \starttext
>> \startMPcode
>> draw (2cm,3cm) -- (3cm,5cm) ;
>> dotlabel(textext("\switchtobodyfont[8pt]" & "A"), (2cm,3cm))
>> withpen pencircle scaled 12pt
>> withcolor transparent("exclusion",.5,red) ;
>>
>> dotlabel(textext("\switchtobodyfont[8pt]" & "B"), (3cm,5cm))
>> withpen pencircle scaled 12pt
>> withcolor transparent("exclusion",.5,red) ;
>> \stopMPcode
>> \stoptext
>>
>> I wonder whether it is possible to define something like « drawsquaredot » or « squaredotlabel » in order to do this.
>
> dotlabel uses a pen to draw the dot, and I am not sure why it uses that rather than a path. Here is a (to me) simpler definition, where you can change the shape:
just look in the pdf ... in your case the dot is a n point path while
otherwise it uses the default postscript pen (which is a dot)
actually fullcircle is pencircle so you can ponder why that is the case -)
> \startMPdefinitions
> newpath dotlabelshape;
>
> dotlabelshape := fullcircle;
>
> vardef dotlabel@#(expr s,z) text t_ =
> label@#(s,z) t_ ;
> fill (dotlabelshape scaled 2dotlabeldiam) shifted z t_;
> enddef ;
> \stopMPdefinitions
>
> \starttext
> \startMPcode
> newpath p ;
> p := (2cm, 3cm) -- (3cm, 5cm);
> dotlabeldiam := 12pt;
>
> % Default
> draw p;
> dotlabel(textext("\switchtobodyfont[8pt]" & "A"), point 0 of p)
> withcolor transparent("exclusion",.5,red) ;
>
> dotlabel(textext("\switchtobodyfont[8pt]" & "B"), point 1 of p)
> withcolor transparent("exclusion",.5,red) ;
>
> % Using a square "dot"
> p := p shifted (5cm, 0);
> dotlabelshape := fullsquare;
>
> draw p;
> dotlabel(textext("\switchtobodyfont[8pt]" & "A"), point 0 of p)
> withcolor transparent("exclusion",.5,red) ;
>
> dotlabel(textext("\switchtobodyfont[8pt]" & "B"), point 1 of p)
> withcolor transparent("exclusion",.5,red) ;
> \stopMPcode
> \stoptext
>
> These types of macros are also a good candidate for the new LMTX syntax, where we can make all components configurable via a key-value interface (labeldistance etc. as well).
it surprised me that a math guru like you doesn't do this:
vardef dotlabel@#(expr s,z) text t_ =
% draw textext("$\bullet$") scaled (1/2) shifted z ;
% draw textext("$\blacktriangle$") scaled (1/4) shifted z ;
draw textext("$\blacksquare$") scaled (1/4) shifted z ;
label@#(s,z) t_ ;
enddef ;
\stopMPdefinitions
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2020-12-10 18:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-10 17:30 Otared Kavian
2020-12-10 17:44 ` Aditya Mahajan
2020-12-10 17:57 ` Otared Kavian
2020-12-10 18:04 ` Aditya Mahajan
2020-12-10 18:50 ` Hans Hagen
2020-12-10 18:07 ` Hans Hagen [this message]
2020-12-10 19:37 ` Aditya Mahajan
2020-12-10 21:36 ` Hans Hagen
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=e165b661-3ed0-57ac-63d5-44f7bcbc2083@xs4all.nl \
--to=j.hagen@xs4all.nl \
--cc=adityam@umich.edu \
--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).