Hi Aditya, Thank you very much ! That's great indeed, you gave me an elegant solution. One more question, in order for me to understand a little more: when defining a new dotlabel as you do, might it not conflict with the internal definitions of dotlabel in Metafun in some other place? Maybe it is safer for me to call it something like « dotshapelabel » ? Best regards and agin many thanks: Otared
On 10 Dec 2020, at 18:44, 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:
\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).
Aditya
___________________________________________________________________________________ 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 ___________________________________________________________________________________